blob: fa03c059c323d1da02d1da0c6f499ba57a2a31b1 [file] [log] [blame]
Flemmard9fc10142013-04-10 15:59:59 +02001/* Copyright (c) 2002,2007-2013, The Linux Foundation. All rights reserved.
Nicholas Flintham1e3d3112013-04-10 10:48:38 +01002 *
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
Flemmard9fc10142013-04-10 15:59:59 +020016/*
17 * Adreno ringbuffer sizes in bytes - these are converted to
18 * the appropriate log2 values in the code
19 */
Nicholas Flintham1e3d3112013-04-10 10:48:38 +010020
21#define KGSL_RB_SIZE (32 * 1024)
22#define KGSL_RB_BLKSIZE 16
23
Flemmard9fc10142013-04-10 15:59:59 +020024/* CP timestamp register */
Nicholas Flintham1e3d3112013-04-10 10:48:38 +010025#define REG_CP_TIMESTAMP REG_SCRATCH_REG0
26
27
28struct kgsl_device;
29struct kgsl_device_private;
Flemmard9fc10142013-04-10 15:59:59 +020030struct adreno_ft_data;
Nicholas Flintham1e3d3112013-04-10 10:48:38 +010031
32#define GSL_RB_MEMPTRS_SCRATCH_COUNT 8
33struct kgsl_rbmemptrs {
34 int rptr;
35 int wptr_poll;
36};
37
38#define GSL_RB_MEMPTRS_RPTR_OFFSET \
39 (offsetof(struct kgsl_rbmemptrs, rptr))
40
41#define GSL_RB_MEMPTRS_WPTRPOLL_OFFSET \
42 (offsetof(struct kgsl_rbmemptrs, wptr_poll))
43
44struct adreno_ringbuffer {
45 struct kgsl_device *device;
46 uint32_t flags;
47
48 struct kgsl_memdesc buffer_desc;
49
50 struct kgsl_memdesc memptrs_desc;
51 struct kgsl_rbmemptrs *memptrs;
52
Flemmard9fc10142013-04-10 15:59:59 +020053 /*ringbuffer size */
Nicholas Flintham1e3d3112013-04-10 10:48:38 +010054 unsigned int sizedwords;
55
Flemmard9fc10142013-04-10 15:59:59 +020056 unsigned int wptr; /* write pointer offset in dwords from baseaddr */
57 unsigned int rptr; /* read pointer offset in dwords from baseaddr */
Nicholas Flintham1e3d3112013-04-10 10:48:38 +010058
59 unsigned int timestamp[KGSL_MEMSTORE_MAX];
60};
61
62
63#define GSL_RB_WRITE(ring, gpuaddr, data) \
64 do { \
65 *ring = data; \
66 wmb(); \
67 kgsl_cffdump_setmem(gpuaddr, data, 4); \
68 ring++; \
69 gpuaddr += sizeof(uint); \
70 } while (0)
71
Flemmard9fc10142013-04-10 15:59:59 +020072/* enable timestamp (...scratch0) memory shadowing */
Nicholas Flintham1e3d3112013-04-10 10:48:38 +010073#define GSL_RB_MEMPTRS_SCRATCH_MASK 0x1
74
Flemmard9fc10142013-04-10 15:59:59 +020075/* mem rptr */
76#define GSL_RB_CNTL_NO_UPDATE 0x0 /* enable */
Nicholas Flintham1e3d3112013-04-10 10:48:38 +010077#define GSL_RB_GET_READPTR(rb, data) \
78 do { \
79 *(data) = rb->memptrs->rptr; \
80 } while (0)
81
Flemmard9fc10142013-04-10 15:59:59 +020082#define GSL_RB_CNTL_POLL_EN 0x0 /* disable */
Nicholas Flintham1e3d3112013-04-10 10:48:38 +010083
Flemmard9fc10142013-04-10 15:59:59 +020084/*
85 * protected mode error checking below register address 0x800
86 * note: if CP_INTERRUPT packet is used then checking needs
87 * to change to below register address 0x7C8
88 */
Nicholas Flintham1e3d3112013-04-10 10:48:38 +010089#define GSL_RB_PROTECTED_MODE_CONTROL 0x200001F2
90
91int adreno_ringbuffer_issueibcmds(struct kgsl_device_private *dev_priv,
92 struct kgsl_context *context,
93 struct kgsl_ibdesc *ibdesc,
94 unsigned int numibs,
95 uint32_t *timestamp,
96 unsigned int flags);
97
98int adreno_ringbuffer_init(struct kgsl_device *device);
99
100int adreno_ringbuffer_start(struct adreno_ringbuffer *rb,
101 unsigned int init_ram);
102
103void adreno_ringbuffer_stop(struct adreno_ringbuffer *rb);
104
105void adreno_ringbuffer_close(struct adreno_ringbuffer *rb);
106
107unsigned int adreno_ringbuffer_issuecmds(struct kgsl_device *device,
108 struct adreno_context *drawctxt,
109 unsigned int flags,
110 unsigned int *cmdaddr,
111 int sizedwords);
112
113void adreno_ringbuffer_submit(struct adreno_ringbuffer *rb);
114
115void kgsl_cp_intrcallback(struct kgsl_device *device);
116
Flemmard9fc10142013-04-10 15:59:59 +0200117void adreno_ringbuffer_extract(struct adreno_ringbuffer *rb,
118 struct adreno_ft_data *ft_data);
Nicholas Flintham1e3d3112013-04-10 10:48:38 +0100119
120void
121adreno_ringbuffer_restore(struct adreno_ringbuffer *rb, unsigned int *rb_buff,
122 int num_rb_contents);
123
124unsigned int *adreno_ringbuffer_allocspace(struct adreno_ringbuffer *rb,
Flemmard9fc10142013-04-10 15:59:59 +0200125 struct adreno_context *context,
126 unsigned int numcmds);
Nicholas Flintham1e3d3112013-04-10 10:48:38 +0100127
128int adreno_ringbuffer_read_pfp_ucode(struct kgsl_device *device);
129
130int adreno_ringbuffer_read_pm4_ucode(struct kgsl_device *device);
131
132static inline int adreno_ringbuffer_count(struct adreno_ringbuffer *rb,
133 unsigned int rptr)
134{
135 if (rb->wptr >= rptr)
136 return rb->wptr - rptr;
137 return rb->wptr + rb->sizedwords - rptr;
138}
139
Flemmard9fc10142013-04-10 15:59:59 +0200140/* Increment a value by 4 bytes with wrap-around based on size */
Nicholas Flintham1e3d3112013-04-10 10:48:38 +0100141static inline unsigned int adreno_ringbuffer_inc_wrapped(unsigned int val,
142 unsigned int size)
143{
144 return (val + sizeof(unsigned int)) % size;
145}
146
Flemmard9fc10142013-04-10 15:59:59 +0200147/* Decrement a value by 4 bytes with wrap-around based on size */
Nicholas Flintham1e3d3112013-04-10 10:48:38 +0100148static inline unsigned int adreno_ringbuffer_dec_wrapped(unsigned int val,
149 unsigned int size)
150{
151 return (val + size - sizeof(unsigned int)) % size;
152}
153
Flemmard9fc10142013-04-10 15:59:59 +0200154#endif /* __ADRENO_RINGBUFFER_H */