blob: 7560848c6ca38fd5620637f64792362d6402ceff [file] [log] [blame]
Nicholas Flintham1e3d3112013-04-10 10:48:38 +01001/* Copyright (c) 2002,2007-2012, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13#ifndef __ADRENO_RINGBUFFER_H
14#define __ADRENO_RINGBUFFER_H
15
16
17#define KGSL_RB_SIZE (32 * 1024)
18#define KGSL_RB_BLKSIZE 16
19
20#define REG_CP_TIMESTAMP REG_SCRATCH_REG0
21
22
23struct kgsl_device;
24struct kgsl_device_private;
25struct adreno_recovery_data;
26
27#define GSL_RB_MEMPTRS_SCRATCH_COUNT 8
28struct kgsl_rbmemptrs {
29 int rptr;
30 int wptr_poll;
31};
32
33#define GSL_RB_MEMPTRS_RPTR_OFFSET \
34 (offsetof(struct kgsl_rbmemptrs, rptr))
35
36#define GSL_RB_MEMPTRS_WPTRPOLL_OFFSET \
37 (offsetof(struct kgsl_rbmemptrs, wptr_poll))
38
39struct adreno_ringbuffer {
40 struct kgsl_device *device;
41 uint32_t flags;
42
43 struct kgsl_memdesc buffer_desc;
44
45 struct kgsl_memdesc memptrs_desc;
46 struct kgsl_rbmemptrs *memptrs;
47
48
49 unsigned int sizedwords;
50
51 unsigned int wptr;
52 unsigned int rptr;
53
54 unsigned int timestamp[KGSL_MEMSTORE_MAX];
55};
56
57
58#define GSL_RB_WRITE(ring, gpuaddr, data) \
59 do { \
60 *ring = data; \
61 wmb(); \
62 kgsl_cffdump_setmem(gpuaddr, data, 4); \
63 ring++; \
64 gpuaddr += sizeof(uint); \
65 } while (0)
66
67#define GSL_RB_MEMPTRS_SCRATCH_MASK 0x1
68
69#define GSL_RB_CNTL_NO_UPDATE 0x0
70#define GSL_RB_GET_READPTR(rb, data) \
71 do { \
72 *(data) = rb->memptrs->rptr; \
73 } while (0)
74
75#define GSL_RB_CNTL_POLL_EN 0x0
76
77#define GSL_RB_PROTECTED_MODE_CONTROL 0x200001F2
78
79int adreno_ringbuffer_issueibcmds(struct kgsl_device_private *dev_priv,
80 struct kgsl_context *context,
81 struct kgsl_ibdesc *ibdesc,
82 unsigned int numibs,
83 uint32_t *timestamp,
84 unsigned int flags);
85
86int adreno_ringbuffer_init(struct kgsl_device *device);
87
88int adreno_ringbuffer_start(struct adreno_ringbuffer *rb,
89 unsigned int init_ram);
90
91void adreno_ringbuffer_stop(struct adreno_ringbuffer *rb);
92
93void adreno_ringbuffer_close(struct adreno_ringbuffer *rb);
94
95unsigned int adreno_ringbuffer_issuecmds(struct kgsl_device *device,
96 struct adreno_context *drawctxt,
97 unsigned int flags,
98 unsigned int *cmdaddr,
99 int sizedwords);
100
101void adreno_ringbuffer_submit(struct adreno_ringbuffer *rb);
102
103void kgsl_cp_intrcallback(struct kgsl_device *device);
104
105int adreno_ringbuffer_extract(struct adreno_ringbuffer *rb,
106 struct adreno_recovery_data *rec_data);
107
108void
109adreno_ringbuffer_restore(struct adreno_ringbuffer *rb, unsigned int *rb_buff,
110 int num_rb_contents);
111
112unsigned int *adreno_ringbuffer_allocspace(struct adreno_ringbuffer *rb,
113 unsigned int numcmds);
114
115int adreno_ringbuffer_read_pfp_ucode(struct kgsl_device *device);
116
117int adreno_ringbuffer_read_pm4_ucode(struct kgsl_device *device);
118
119static inline int adreno_ringbuffer_count(struct adreno_ringbuffer *rb,
120 unsigned int rptr)
121{
122 if (rb->wptr >= rptr)
123 return rb->wptr - rptr;
124 return rb->wptr + rb->sizedwords - rptr;
125}
126
127static inline unsigned int adreno_ringbuffer_inc_wrapped(unsigned int val,
128 unsigned int size)
129{
130 return (val + sizeof(unsigned int)) % size;
131}
132
133static inline unsigned int adreno_ringbuffer_dec_wrapped(unsigned int val,
134 unsigned int size)
135{
136 return (val + size - sizeof(unsigned int)) % size;
137}
138
139#endif