Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2002,2007-2012, Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 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 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 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 | unsigned int rptr; /* read pointer offset in dwords from baseaddr */ |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 57 | |
| 58 | unsigned int timestamp[KGSL_MEMSTORE_MAX]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 61 | |
| 62 | #define GSL_RB_WRITE(ring, gpuaddr, data) \ |
| 63 | do { \ |
Jeremy Gebben | aba1327 | 2012-01-31 17:31:23 -0700 | [diff] [blame] | 64 | *ring = data; \ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 65 | wmb(); \ |
| 66 | kgsl_cffdump_setmem(gpuaddr, data, 4); \ |
| 67 | ring++; \ |
| 68 | gpuaddr += sizeof(uint); \ |
| 69 | } while (0) |
| 70 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 71 | /* enable timestamp (...scratch0) memory shadowing */ |
| 72 | #define GSL_RB_MEMPTRS_SCRATCH_MASK 0x1 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 73 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 74 | /* mem rptr */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 75 | #define GSL_RB_CNTL_NO_UPDATE 0x0 /* enable */ |
| 76 | #define GSL_RB_GET_READPTR(rb, data) \ |
| 77 | do { \ |
Jeremy Gebben | aba1327 | 2012-01-31 17:31:23 -0700 | [diff] [blame] | 78 | *(data) = rb->memptrs->rptr; \ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 79 | } while (0) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 80 | |
| 81 | #define GSL_RB_CNTL_POLL_EN 0x0 /* disable */ |
| 82 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 83 | /* |
| 84 | * protected mode error checking below register address 0x800 |
| 85 | * note: if CP_INTERRUPT packet is used then checking needs |
| 86 | * to change to below register address 0x7C8 |
| 87 | */ |
| 88 | #define GSL_RB_PROTECTED_MODE_CONTROL 0x200001F2 |
| 89 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 90 | int adreno_ringbuffer_issueibcmds(struct kgsl_device_private *dev_priv, |
| 91 | struct kgsl_context *context, |
| 92 | struct kgsl_ibdesc *ibdesc, |
| 93 | unsigned int numibs, |
| 94 | uint32_t *timestamp, |
| 95 | unsigned int flags); |
| 96 | |
| 97 | int adreno_ringbuffer_init(struct kgsl_device *device); |
| 98 | |
| 99 | int adreno_ringbuffer_start(struct adreno_ringbuffer *rb, |
| 100 | unsigned int init_ram); |
| 101 | |
Carter Cooper | 6dd94c8 | 2011-10-13 14:43:53 -0600 | [diff] [blame] | 102 | void adreno_ringbuffer_stop(struct adreno_ringbuffer *rb); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 103 | |
Carter Cooper | 6dd94c8 | 2011-10-13 14:43:53 -0600 | [diff] [blame] | 104 | void adreno_ringbuffer_close(struct adreno_ringbuffer *rb); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 105 | |
Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 106 | unsigned int adreno_ringbuffer_issuecmds(struct kgsl_device *device, |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame^] | 107 | struct adreno_context *drawctxt, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 108 | unsigned int flags, |
| 109 | unsigned int *cmdaddr, |
| 110 | int sizedwords); |
| 111 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 112 | void adreno_ringbuffer_submit(struct adreno_ringbuffer *rb); |
| 113 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 114 | void kgsl_cp_intrcallback(struct kgsl_device *device); |
| 115 | |
| 116 | int adreno_ringbuffer_extract(struct adreno_ringbuffer *rb, |
| 117 | unsigned int *temp_rb_buffer, |
| 118 | int *rb_size); |
| 119 | |
| 120 | void |
| 121 | adreno_ringbuffer_restore(struct adreno_ringbuffer *rb, unsigned int *rb_buff, |
| 122 | int num_rb_contents); |
| 123 | |
Jordan Crouse | b4d31bd | 2012-02-01 22:11:12 -0700 | [diff] [blame] | 124 | unsigned int *adreno_ringbuffer_allocspace(struct adreno_ringbuffer *rb, |
| 125 | unsigned int numcmds); |
| 126 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 127 | static inline int adreno_ringbuffer_count(struct adreno_ringbuffer *rb, |
| 128 | unsigned int rptr) |
| 129 | { |
| 130 | if (rb->wptr >= rptr) |
| 131 | return rb->wptr - rptr; |
| 132 | return rb->wptr + rb->sizedwords - rptr; |
| 133 | } |
| 134 | |
| 135 | /* Increment a value by 4 bytes with wrap-around based on size */ |
| 136 | static inline unsigned int adreno_ringbuffer_inc_wrapped(unsigned int val, |
| 137 | unsigned int size) |
| 138 | { |
| 139 | return (val + sizeof(unsigned int)) % size; |
| 140 | } |
| 141 | |
| 142 | #endif /* __ADRENO_RINGBUFFER_H */ |