Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame^] | 1 | /* 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) |
| 22 | #define KGSL_RB_BLKSIZE 16 |
| 23 | |
| 24 | /* CP timestamp register */ |
| 25 | #define REG_CP_TIMESTAMP REG_SCRATCH_REG0 |
| 26 | |
| 27 | |
| 28 | struct kgsl_device; |
| 29 | struct kgsl_device_private; |
| 30 | |
| 31 | #define GSL_RB_MEMPTRS_SCRATCH_COUNT 8 |
| 32 | struct kgsl_rbmemptrs { |
| 33 | int rptr; |
| 34 | int wptr_poll; |
| 35 | }; |
| 36 | |
| 37 | #define GSL_RB_MEMPTRS_RPTR_OFFSET \ |
| 38 | (offsetof(struct kgsl_rbmemptrs, rptr)) |
| 39 | |
| 40 | #define GSL_RB_MEMPTRS_WPTRPOLL_OFFSET \ |
| 41 | (offsetof(struct kgsl_rbmemptrs, wptr_poll)) |
| 42 | |
| 43 | struct adreno_ringbuffer { |
| 44 | struct kgsl_device *device; |
| 45 | uint32_t flags; |
| 46 | |
| 47 | struct kgsl_memdesc buffer_desc; |
| 48 | |
| 49 | struct kgsl_memdesc memptrs_desc; |
| 50 | struct kgsl_rbmemptrs *memptrs; |
| 51 | |
| 52 | /*ringbuffer size */ |
| 53 | unsigned int sizedwords; |
| 54 | |
| 55 | unsigned int wptr; /* write pointer offset in dwords from baseaddr */ |
| 56 | |
| 57 | unsigned int global_ts; |
| 58 | }; |
| 59 | |
| 60 | |
| 61 | #define GSL_RB_WRITE(device, ring, gpuaddr, data) \ |
| 62 | do { \ |
| 63 | *ring = data; \ |
| 64 | wmb(); \ |
| 65 | kgsl_cffdump_setmem(device, gpuaddr, data, 4); \ |
| 66 | ring++; \ |
| 67 | gpuaddr += sizeof(uint); \ |
| 68 | } while (0) |
| 69 | |
| 70 | /* enable timestamp (...scratch0) memory shadowing */ |
| 71 | #define GSL_RB_MEMPTRS_SCRATCH_MASK 0x1 |
| 72 | |
| 73 | /* mem rptr */ |
| 74 | #define GSL_RB_CNTL_NO_UPDATE 0x0 /* enable */ |
| 75 | |
| 76 | /** |
| 77 | * adreno_get_rptr - Get the current ringbuffer read pointer |
| 78 | * @rb - the ringbuffer |
| 79 | * |
| 80 | * Get the current read pointer, which is written by the GPU. |
| 81 | */ |
| 82 | static inline unsigned int |
| 83 | adreno_get_rptr(struct adreno_ringbuffer *rb) |
| 84 | { |
| 85 | unsigned int result = rb->memptrs->rptr; |
| 86 | rmb(); |
| 87 | return result; |
| 88 | } |
| 89 | |
| 90 | #define GSL_RB_CNTL_POLL_EN 0x0 /* disable */ |
| 91 | |
| 92 | /* |
| 93 | * protected mode error checking below register address 0x800 |
| 94 | * note: if CP_INTERRUPT packet is used then checking needs |
| 95 | * to change to below register address 0x7C8 |
| 96 | */ |
| 97 | #define GSL_RB_PROTECTED_MODE_CONTROL 0x200001F2 |
| 98 | |
| 99 | int adreno_ringbuffer_issueibcmds(struct kgsl_device_private *dev_priv, |
| 100 | struct kgsl_context *context, |
| 101 | struct kgsl_cmdbatch *cmdbatch, |
| 102 | uint32_t *timestamp); |
| 103 | |
| 104 | int adreno_ringbuffer_submitcmd(struct adreno_device *adreno_dev, |
| 105 | struct kgsl_cmdbatch *cmdbatch); |
| 106 | |
| 107 | int adreno_ringbuffer_init(struct kgsl_device *device); |
| 108 | |
| 109 | int adreno_ringbuffer_warm_start(struct adreno_ringbuffer *rb); |
| 110 | |
| 111 | int adreno_ringbuffer_start(struct adreno_ringbuffer *rb); |
| 112 | |
| 113 | void adreno_ringbuffer_stop(struct adreno_ringbuffer *rb); |
| 114 | |
| 115 | void adreno_ringbuffer_close(struct adreno_ringbuffer *rb); |
| 116 | |
| 117 | unsigned int adreno_ringbuffer_issuecmds(struct kgsl_device *device, |
| 118 | struct adreno_context *drawctxt, |
| 119 | unsigned int flags, |
| 120 | unsigned int *cmdaddr, |
| 121 | int sizedwords); |
| 122 | |
| 123 | void adreno_ringbuffer_submit(struct adreno_ringbuffer *rb); |
| 124 | |
| 125 | void kgsl_cp_intrcallback(struct kgsl_device *device); |
| 126 | |
| 127 | unsigned int *adreno_ringbuffer_allocspace(struct adreno_ringbuffer *rb, |
| 128 | struct adreno_context *context, |
| 129 | unsigned int numcmds); |
| 130 | |
| 131 | int adreno_ringbuffer_read_pfp_ucode(struct kgsl_device *device); |
| 132 | |
| 133 | int adreno_ringbuffer_read_pm4_ucode(struct kgsl_device *device); |
| 134 | |
| 135 | static inline int adreno_ringbuffer_count(struct adreno_ringbuffer *rb, |
| 136 | unsigned int rptr) |
| 137 | { |
| 138 | if (rb->wptr >= rptr) |
| 139 | return rb->wptr - rptr; |
| 140 | return rb->wptr + rb->sizedwords - rptr; |
| 141 | } |
| 142 | |
| 143 | /* Increment a value by 4 bytes with wrap-around based on size */ |
| 144 | static inline unsigned int adreno_ringbuffer_inc_wrapped(unsigned int val, |
| 145 | unsigned int size) |
| 146 | { |
| 147 | return (val + sizeof(unsigned int)) % size; |
| 148 | } |
| 149 | |
| 150 | /* Decrement a value by 4 bytes with wrap-around based on size */ |
| 151 | static inline unsigned int adreno_ringbuffer_dec_wrapped(unsigned int val, |
| 152 | unsigned int size) |
| 153 | { |
| 154 | return (val + size - sizeof(unsigned int)) % size; |
| 155 | } |
| 156 | |
| 157 | #endif /* __ADRENO_RINGBUFFER_H */ |