blob: 697e113c576d30e203f5e8a457c52362426548f5 [file] [log] [blame]
Steve Kondikf7652b32013-11-26 15:20:51 -08001/* Copyright (c) 2002,2007-2013, The Linux Foundation. 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 * 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)
Steve Kondikf7652b32013-11-26 15:20:51 -080022
23/* CP timestamp register */
24#define REG_CP_TIMESTAMP REG_SCRATCH_REG0
25
26
27struct kgsl_device;
28struct kgsl_device_private;
29
Steve Kondikf7652b32013-11-26 15:20:51 -080030struct adreno_ringbuffer {
31 struct kgsl_device *device;
32 uint32_t flags;
33
34 struct kgsl_memdesc buffer_desc;
35
Steve Kondikf7652b32013-11-26 15:20:51 -080036 /*ringbuffer size */
37 unsigned int sizedwords;
38
39 unsigned int wptr; /* write pointer offset in dwords from baseaddr */
40
41 unsigned int global_ts;
42};
43
44
45#define GSL_RB_WRITE(device, ring, gpuaddr, data) \
46 do { \
47 *ring = data; \
48 wmb(); \
49 kgsl_cffdump_setmem(device, gpuaddr, data, 4); \
50 ring++; \
51 gpuaddr += sizeof(uint); \
52 } while (0)
53
54/* enable timestamp (...scratch0) memory shadowing */
55#define GSL_RB_MEMPTRS_SCRATCH_MASK 0x1
56
Steve Kondikf7652b32013-11-26 15:20:51 -080057/*
58 * protected mode error checking below register address 0x800
59 * note: if CP_INTERRUPT packet is used then checking needs
60 * to change to below register address 0x7C8
61 */
62#define GSL_RB_PROTECTED_MODE_CONTROL 0x200001F2
63
64int adreno_ringbuffer_issueibcmds(struct kgsl_device_private *dev_priv,
65 struct kgsl_context *context,
66 struct kgsl_cmdbatch *cmdbatch,
67 uint32_t *timestamp);
68
69int adreno_ringbuffer_submitcmd(struct adreno_device *adreno_dev,
70 struct kgsl_cmdbatch *cmdbatch);
71
72int adreno_ringbuffer_init(struct kgsl_device *device);
73
74int adreno_ringbuffer_warm_start(struct adreno_ringbuffer *rb);
75
Ethan Chen7b185902014-11-16 16:48:31 -080076int adreno_ringbuffer_cold_start(struct adreno_ringbuffer *rb);
Steve Kondikf7652b32013-11-26 15:20:51 -080077
78void adreno_ringbuffer_stop(struct adreno_ringbuffer *rb);
79
80void adreno_ringbuffer_close(struct adreno_ringbuffer *rb);
81
82unsigned int adreno_ringbuffer_issuecmds(struct kgsl_device *device,
83 struct adreno_context *drawctxt,
84 unsigned int flags,
85 unsigned int *cmdaddr,
86 int sizedwords);
87
88void adreno_ringbuffer_submit(struct adreno_ringbuffer *rb);
89
90void kgsl_cp_intrcallback(struct kgsl_device *device);
91
92unsigned int *adreno_ringbuffer_allocspace(struct adreno_ringbuffer *rb,
93 struct adreno_context *context,
94 unsigned int numcmds);
95
96int adreno_ringbuffer_read_pfp_ucode(struct kgsl_device *device);
97
98int adreno_ringbuffer_read_pm4_ucode(struct kgsl_device *device);
99
100static inline int adreno_ringbuffer_count(struct adreno_ringbuffer *rb,
101 unsigned int rptr)
102{
103 if (rb->wptr >= rptr)
104 return rb->wptr - rptr;
105 return rb->wptr + rb->sizedwords - rptr;
106}
107
108/* Increment a value by 4 bytes with wrap-around based on size */
109static inline unsigned int adreno_ringbuffer_inc_wrapped(unsigned int val,
110 unsigned int size)
111{
112 return (val + sizeof(unsigned int)) % size;
113}
114
115/* Decrement a value by 4 bytes with wrap-around based on size */
116static inline unsigned int adreno_ringbuffer_dec_wrapped(unsigned int val,
117 unsigned int size)
118{
119 return (val + size - sizeof(unsigned int)) % size;
120}
121
122#endif /* __ADRENO_RINGBUFFER_H */