blob: 4f58a15dbe9eb7675341c905d8c266e2a8f1b631 [file] [log] [blame]
Jordan Crouseb4d31bd2012-02-01 22:11:12 -07001/* Copyright (c) 2002,2007-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070016/*
17 * Adreno ringbuffer sizes in bytes - these are converted to
18 * the appropriate log2 values in the code
19 */
20
21#define KGSL_RB_SIZE (32 * 1024)
22#define KGSL_RB_BLKSIZE 16
23
24/* CP timestamp register */
25#define REG_CP_TIMESTAMP REG_SCRATCH_REG0
26
27
28struct kgsl_device;
29struct kgsl_device_private;
Shubhraprakash Dasba6c70b2012-05-31 02:53:06 -060030struct adreno_recovery_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070031
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
53 /*ringbuffer size */
54 unsigned int sizedwords;
55
56 unsigned int wptr; /* write pointer offset in dwords from baseaddr */
57 unsigned int rptr; /* read pointer offset in dwords from baseaddr */
Carter Cooper7e7f02e2012-02-15 09:36:31 -070058
59 unsigned int timestamp[KGSL_MEMSTORE_MAX];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070060};
61
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070062
63#define GSL_RB_WRITE(ring, gpuaddr, data) \
64 do { \
Jeremy Gebbenaba13272012-01-31 17:31:23 -070065 *ring = data; \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070066 wmb(); \
67 kgsl_cffdump_setmem(gpuaddr, data, 4); \
68 ring++; \
69 gpuaddr += sizeof(uint); \
70 } while (0)
71
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070072/* enable timestamp (...scratch0) memory shadowing */
73#define GSL_RB_MEMPTRS_SCRATCH_MASK 0x1
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070074
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070075/* mem rptr */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070076#define GSL_RB_CNTL_NO_UPDATE 0x0 /* enable */
77#define GSL_RB_GET_READPTR(rb, data) \
78 do { \
Jeremy Gebbenaba13272012-01-31 17:31:23 -070079 *(data) = rb->memptrs->rptr; \
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070080 } while (0)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070081
82#define GSL_RB_CNTL_POLL_EN 0x0 /* disable */
83
Jordan Crouseb4d31bd2012-02-01 22:11:12 -070084/*
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 */
89#define GSL_RB_PROTECTED_MODE_CONTROL 0x200001F2
90
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070091int 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
Carter Cooper6dd94c82011-10-13 14:43:53 -0600103void adreno_ringbuffer_stop(struct adreno_ringbuffer *rb);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700104
Carter Cooper6dd94c82011-10-13 14:43:53 -0600105void adreno_ringbuffer_close(struct adreno_ringbuffer *rb);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700106
Shubhraprakash Dascb068072012-06-07 17:52:41 -0600107unsigned int adreno_ringbuffer_issuecmds(struct kgsl_device *device,
Shubhraprakash Dasb2abc452012-06-08 16:33:03 -0600108 struct adreno_context *drawctxt,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700109 unsigned int flags,
110 unsigned int *cmdaddr,
111 int sizedwords);
112
Carter Cooper7ffaba62012-05-24 13:59:53 -0600113void adreno_ringbuffer_issuecmds_intr(struct kgsl_device *device,
114 struct kgsl_context *k_ctxt,
115 unsigned int *cmdaddr,
116 int sizedwords);
117
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700118void adreno_ringbuffer_submit(struct adreno_ringbuffer *rb);
119
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700120void kgsl_cp_intrcallback(struct kgsl_device *device);
121
122int adreno_ringbuffer_extract(struct adreno_ringbuffer *rb,
Shubhraprakash Dasba6c70b2012-05-31 02:53:06 -0600123 struct adreno_recovery_data *rec_data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700124
125void
126adreno_ringbuffer_restore(struct adreno_ringbuffer *rb, unsigned int *rb_buff,
127 int num_rb_contents);
128
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700129unsigned int *adreno_ringbuffer_allocspace(struct adreno_ringbuffer *rb,
Shubhraprakash Dasd316ff82012-08-02 12:43:48 -0700130 struct adreno_context *context,
131 unsigned int numcmds);
Jordan Crouseb4d31bd2012-02-01 22:11:12 -0700132
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700133static inline int adreno_ringbuffer_count(struct adreno_ringbuffer *rb,
134 unsigned int rptr)
135{
136 if (rb->wptr >= rptr)
137 return rb->wptr - rptr;
138 return rb->wptr + rb->sizedwords - rptr;
139}
140
141/* Increment a value by 4 bytes with wrap-around based on size */
142static inline unsigned int adreno_ringbuffer_inc_wrapped(unsigned int val,
143 unsigned int size)
144{
145 return (val + sizeof(unsigned int)) % size;
146}
147
Shubhraprakash Dasbb7b32a2012-06-04 15:36:39 -0600148/* Decrement a value by 4 bytes with wrap-around based on size */
149static inline unsigned int adreno_ringbuffer_dec_wrapped(unsigned int val,
150 unsigned int size)
151{
152 return (val + size - sizeof(unsigned int)) % size;
153}
154
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700155#endif /* __ADRENO_RINGBUFFER_H */