Jeremy Gebben | b7bc955 | 2012-01-09 13:32:49 -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 | #include <linux/uaccess.h> |
| 14 | |
| 15 | #include "kgsl.h" |
| 16 | #include "kgsl_cffdump.h" |
| 17 | #include "kgsl_sharedmem.h" |
| 18 | |
| 19 | #include "z180.h" |
| 20 | #include "z180_reg.h" |
Norman Gee | d7402ff | 2011-10-28 08:51:11 -0600 | [diff] [blame] | 21 | #include "z180_trace.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 22 | |
| 23 | #define DRIVER_VERSION_MAJOR 3 |
| 24 | #define DRIVER_VERSION_MINOR 1 |
| 25 | |
| 26 | #define Z180_DEVICE(device) \ |
| 27 | KGSL_CONTAINER_OF(device, struct z180_device, dev) |
| 28 | |
| 29 | #define GSL_VGC_INT_MASK \ |
| 30 | (REG_VGC_IRQSTATUS__MH_MASK | \ |
| 31 | REG_VGC_IRQSTATUS__G2D_MASK | \ |
| 32 | REG_VGC_IRQSTATUS__FIFO_MASK) |
| 33 | |
| 34 | #define VGV3_NEXTCMD_JUMP 0x01 |
| 35 | |
| 36 | #define VGV3_NEXTCMD_NEXTCMD_FSHIFT 12 |
| 37 | #define VGV3_NEXTCMD_NEXTCMD_FMASK 0x7 |
| 38 | |
| 39 | #define VGV3_CONTROL_MARKADD_FSHIFT 0 |
| 40 | #define VGV3_CONTROL_MARKADD_FMASK 0xfff |
| 41 | |
| 42 | #define Z180_PACKET_SIZE 15 |
| 43 | #define Z180_MARKER_SIZE 10 |
| 44 | #define Z180_CALL_CMD 0x1000 |
| 45 | #define Z180_MARKER_CMD 0x8000 |
| 46 | #define Z180_STREAM_END_CMD 0x9000 |
| 47 | #define Z180_STREAM_PACKET 0x7C000176 |
| 48 | #define Z180_STREAM_PACKET_CALL 0x7C000275 |
| 49 | #define Z180_PACKET_COUNT 8 |
| 50 | #define Z180_RB_SIZE (Z180_PACKET_SIZE*Z180_PACKET_COUNT \ |
| 51 | *sizeof(uint32_t)) |
| 52 | |
| 53 | #define NUMTEXUNITS 4 |
| 54 | #define TEXUNITREGCOUNT 25 |
| 55 | #define VG_REGCOUNT 0x39 |
| 56 | |
| 57 | #define PACKETSIZE_BEGIN 3 |
| 58 | #define PACKETSIZE_G2DCOLOR 2 |
| 59 | #define PACKETSIZE_TEXUNIT (TEXUNITREGCOUNT * 2) |
| 60 | #define PACKETSIZE_REG (VG_REGCOUNT * 2) |
| 61 | #define PACKETSIZE_STATE (PACKETSIZE_TEXUNIT * NUMTEXUNITS + \ |
| 62 | PACKETSIZE_REG + PACKETSIZE_BEGIN + \ |
| 63 | PACKETSIZE_G2DCOLOR) |
| 64 | #define PACKETSIZE_STATESTREAM (ALIGN((PACKETSIZE_STATE * \ |
| 65 | sizeof(unsigned int)), 32) / \ |
| 66 | sizeof(unsigned int)) |
| 67 | |
| 68 | #define Z180_INVALID_CONTEXT UINT_MAX |
| 69 | |
| 70 | /* z180 MH arbiter config*/ |
| 71 | #define Z180_CFG_MHARB \ |
| 72 | (0x10 \ |
| 73 | | (0 << MH_ARBITER_CONFIG__SAME_PAGE_GRANULARITY__SHIFT) \ |
| 74 | | (1 << MH_ARBITER_CONFIG__L1_ARB_ENABLE__SHIFT) \ |
| 75 | | (1 << MH_ARBITER_CONFIG__L1_ARB_HOLD_ENABLE__SHIFT) \ |
| 76 | | (0 << MH_ARBITER_CONFIG__L2_ARB_CONTROL__SHIFT) \ |
| 77 | | (1 << MH_ARBITER_CONFIG__PAGE_SIZE__SHIFT) \ |
| 78 | | (1 << MH_ARBITER_CONFIG__TC_REORDER_ENABLE__SHIFT) \ |
| 79 | | (1 << MH_ARBITER_CONFIG__TC_ARB_HOLD_ENABLE__SHIFT) \ |
| 80 | | (0 << MH_ARBITER_CONFIG__IN_FLIGHT_LIMIT_ENABLE__SHIFT) \ |
| 81 | | (0x8 << MH_ARBITER_CONFIG__IN_FLIGHT_LIMIT__SHIFT) \ |
| 82 | | (1 << MH_ARBITER_CONFIG__CP_CLNT_ENABLE__SHIFT) \ |
| 83 | | (1 << MH_ARBITER_CONFIG__VGT_CLNT_ENABLE__SHIFT) \ |
| 84 | | (1 << MH_ARBITER_CONFIG__TC_CLNT_ENABLE__SHIFT) \ |
| 85 | | (1 << MH_ARBITER_CONFIG__RB_CLNT_ENABLE__SHIFT) \ |
| 86 | | (1 << MH_ARBITER_CONFIG__PA_CLNT_ENABLE__SHIFT)) |
| 87 | |
| 88 | #define Z180_TIMESTAMP_EPSILON 20000 |
| 89 | #define Z180_IDLE_COUNT_MAX 1000000 |
| 90 | |
| 91 | enum z180_cmdwindow_type { |
| 92 | Z180_CMDWINDOW_2D = 0x00000000, |
| 93 | Z180_CMDWINDOW_MMU = 0x00000002, |
| 94 | }; |
| 95 | |
| 96 | #define Z180_CMDWINDOW_TARGET_MASK 0x000000FF |
| 97 | #define Z180_CMDWINDOW_ADDR_MASK 0x00FFFF00 |
| 98 | #define Z180_CMDWINDOW_TARGET_SHIFT 0 |
| 99 | #define Z180_CMDWINDOW_ADDR_SHIFT 8 |
| 100 | |
| 101 | static int z180_start(struct kgsl_device *device, unsigned int init_ram); |
| 102 | static int z180_stop(struct kgsl_device *device); |
| 103 | static int z180_wait(struct kgsl_device *device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 104 | struct kgsl_context *context, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 105 | unsigned int timestamp, |
| 106 | unsigned int msecs); |
| 107 | static void z180_regread(struct kgsl_device *device, |
| 108 | unsigned int offsetwords, |
| 109 | unsigned int *value); |
| 110 | static void z180_regwrite(struct kgsl_device *device, |
| 111 | unsigned int offsetwords, |
| 112 | unsigned int value); |
| 113 | static void z180_cmdwindow_write(struct kgsl_device *device, |
| 114 | unsigned int addr, |
| 115 | unsigned int data); |
| 116 | |
| 117 | #define Z180_MMU_CONFIG \ |
| 118 | (0x01 \ |
| 119 | | (MMU_CONFIG << MH_MMU_CONFIG__RB_W_CLNT_BEHAVIOR__SHIFT) \ |
| 120 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_W_CLNT_BEHAVIOR__SHIFT) \ |
| 121 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R0_CLNT_BEHAVIOR__SHIFT) \ |
| 122 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R1_CLNT_BEHAVIOR__SHIFT) \ |
| 123 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R2_CLNT_BEHAVIOR__SHIFT) \ |
| 124 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R3_CLNT_BEHAVIOR__SHIFT) \ |
| 125 | | (MMU_CONFIG << MH_MMU_CONFIG__CP_R4_CLNT_BEHAVIOR__SHIFT) \ |
| 126 | | (MMU_CONFIG << MH_MMU_CONFIG__VGT_R0_CLNT_BEHAVIOR__SHIFT) \ |
| 127 | | (MMU_CONFIG << MH_MMU_CONFIG__VGT_R1_CLNT_BEHAVIOR__SHIFT) \ |
| 128 | | (MMU_CONFIG << MH_MMU_CONFIG__TC_R_CLNT_BEHAVIOR__SHIFT) \ |
| 129 | | (MMU_CONFIG << MH_MMU_CONFIG__PA_W_CLNT_BEHAVIOR__SHIFT)) |
| 130 | |
| 131 | static const struct kgsl_functable z180_functable; |
| 132 | |
| 133 | static struct z180_device device_2d0 = { |
| 134 | .dev = { |
Jeremy Gebben | 84d75d0 | 2012-03-01 14:47:45 -0700 | [diff] [blame^] | 135 | KGSL_DEVICE_COMMON_INIT(device_2d0.dev), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 136 | .name = DEVICE_2D0_NAME, |
| 137 | .id = KGSL_DEVICE_2D0, |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 138 | .mh = { |
| 139 | .mharb = Z180_CFG_MHARB, |
| 140 | .mh_intf_cfg1 = 0x00032f07, |
| 141 | .mh_intf_cfg2 = 0x004b274f, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 142 | /* turn off memory protection unit by setting |
| 143 | acceptable physical address range to include |
| 144 | all pages. */ |
| 145 | .mpu_base = 0x00000000, |
| 146 | .mpu_range = 0xFFFFF000, |
| 147 | }, |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 148 | .mmu = { |
| 149 | .config = Z180_MMU_CONFIG, |
| 150 | }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 151 | .pwrctrl = { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 152 | .irq_name = KGSL_2D0_IRQ, |
| 153 | }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 154 | .iomemname = KGSL_2D0_REG_MEMORY, |
| 155 | .ftbl = &z180_functable, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 156 | }, |
Jeremy Gebben | 84d75d0 | 2012-03-01 14:47:45 -0700 | [diff] [blame^] | 157 | .cmdwin_lock = __SPIN_LOCK_INITIALIZER(device_2d1.cmdwin_lock), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | static struct z180_device device_2d1 = { |
| 161 | .dev = { |
Jeremy Gebben | 84d75d0 | 2012-03-01 14:47:45 -0700 | [diff] [blame^] | 162 | KGSL_DEVICE_COMMON_INIT(device_2d1.dev), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 163 | .name = DEVICE_2D1_NAME, |
| 164 | .id = KGSL_DEVICE_2D1, |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 165 | .mh = { |
| 166 | .mharb = Z180_CFG_MHARB, |
| 167 | .mh_intf_cfg1 = 0x00032f07, |
| 168 | .mh_intf_cfg2 = 0x004b274f, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 169 | /* turn off memory protection unit by setting |
| 170 | acceptable physical address range to include |
| 171 | all pages. */ |
| 172 | .mpu_base = 0x00000000, |
| 173 | .mpu_range = 0xFFFFF000, |
| 174 | }, |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 175 | .mmu = { |
| 176 | .config = Z180_MMU_CONFIG, |
| 177 | }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 178 | .pwrctrl = { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 179 | .irq_name = KGSL_2D1_IRQ, |
| 180 | }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 181 | .iomemname = KGSL_2D1_REG_MEMORY, |
| 182 | .ftbl = &z180_functable, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 183 | }, |
Jeremy Gebben | 84d75d0 | 2012-03-01 14:47:45 -0700 | [diff] [blame^] | 184 | .cmdwin_lock = __SPIN_LOCK_INITIALIZER(device_2d1.cmdwin_lock), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 185 | }; |
| 186 | |
Jordan Crouse | b368e9b | 2012-04-27 14:01:59 -0600 | [diff] [blame] | 187 | static irqreturn_t z180_irq_handler(struct kgsl_device *device) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 188 | { |
| 189 | irqreturn_t result = IRQ_NONE; |
| 190 | unsigned int status; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 191 | struct z180_device *z180_dev = Z180_DEVICE(device); |
| 192 | |
| 193 | z180_regread(device, ADDR_VGC_IRQSTATUS >> 2, &status); |
| 194 | |
Norman Gee | d7402ff | 2011-10-28 08:51:11 -0600 | [diff] [blame] | 195 | trace_kgsl_z180_irq_status(device, status); |
| 196 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 197 | if (status & GSL_VGC_INT_MASK) { |
| 198 | z180_regwrite(device, |
| 199 | ADDR_VGC_IRQSTATUS >> 2, status & GSL_VGC_INT_MASK); |
| 200 | |
| 201 | result = IRQ_HANDLED; |
| 202 | |
| 203 | if (status & REG_VGC_IRQSTATUS__FIFO_MASK) |
| 204 | KGSL_DRV_ERR(device, "z180 fifo interrupt\n"); |
| 205 | if (status & REG_VGC_IRQSTATUS__MH_MASK) |
| 206 | kgsl_mh_intrcallback(device); |
| 207 | if (status & REG_VGC_IRQSTATUS__G2D_MASK) { |
| 208 | int count; |
| 209 | |
| 210 | z180_regread(device, |
| 211 | ADDR_VGC_IRQ_ACTIVE_CNT >> 2, |
| 212 | &count); |
| 213 | |
| 214 | count >>= 8; |
| 215 | count &= 255; |
| 216 | z180_dev->timestamp += count; |
| 217 | |
Jordan Crouse | 1bf80aa | 2011-10-12 16:57:47 -0600 | [diff] [blame] | 218 | queue_work(device->work_queue, &device->ts_expired_ws); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 219 | wake_up_interruptible(&device->wait_queue); |
| 220 | |
| 221 | atomic_notifier_call_chain( |
| 222 | &(device->ts_notifier_list), |
| 223 | device->id, NULL); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | if ((device->pwrctrl.nap_allowed == true) && |
| 228 | (device->requested_state == KGSL_STATE_NONE)) { |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 229 | kgsl_pwrctrl_request_state(device, KGSL_STATE_NAP); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 230 | queue_work(device->work_queue, &device->idle_check_ws); |
| 231 | } |
Tarun Karra | 6875576 | 2012-01-12 16:07:09 -0800 | [diff] [blame] | 232 | mod_timer_pending(&device->idle_timer, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 233 | jiffies + device->pwrctrl.interval_timeout); |
| 234 | |
| 235 | return result; |
| 236 | } |
| 237 | |
Jordan Crouse | 9f73921 | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 238 | static void z180_cleanup_pt(struct kgsl_device *device, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 239 | struct kgsl_pagetable *pagetable) |
| 240 | { |
| 241 | struct z180_device *z180_dev = Z180_DEVICE(device); |
| 242 | |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 243 | kgsl_mmu_unmap(pagetable, &device->mmu.setstate_memory); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 244 | |
| 245 | kgsl_mmu_unmap(pagetable, &device->memstore); |
| 246 | |
| 247 | kgsl_mmu_unmap(pagetable, &z180_dev->ringbuffer.cmdbufdesc); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | static int z180_setup_pt(struct kgsl_device *device, |
| 251 | struct kgsl_pagetable *pagetable) |
| 252 | { |
| 253 | int result = 0; |
| 254 | struct z180_device *z180_dev = Z180_DEVICE(device); |
| 255 | |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 256 | result = kgsl_mmu_map_global(pagetable, &device->mmu.setstate_memory, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 257 | GSL_PT_PAGE_RV | GSL_PT_PAGE_WV); |
| 258 | |
| 259 | if (result) |
| 260 | goto error; |
| 261 | |
| 262 | result = kgsl_mmu_map_global(pagetable, &device->memstore, |
| 263 | GSL_PT_PAGE_RV | GSL_PT_PAGE_WV); |
| 264 | if (result) |
| 265 | goto error_unmap_dummy; |
| 266 | |
| 267 | result = kgsl_mmu_map_global(pagetable, |
| 268 | &z180_dev->ringbuffer.cmdbufdesc, |
| 269 | GSL_PT_PAGE_RV); |
| 270 | if (result) |
| 271 | goto error_unmap_memstore; |
| 272 | return result; |
| 273 | |
| 274 | error_unmap_dummy: |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 275 | kgsl_mmu_unmap(pagetable, &device->mmu.setstate_memory); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 276 | |
| 277 | error_unmap_memstore: |
| 278 | kgsl_mmu_unmap(pagetable, &device->memstore); |
| 279 | |
| 280 | error: |
| 281 | return result; |
| 282 | } |
| 283 | |
Jeremy Gebben | 8b253bf | 2012-04-23 16:02:47 -0600 | [diff] [blame] | 284 | static inline unsigned int rb_offset(unsigned int timestamp) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 285 | { |
Jeremy Gebben | 8b253bf | 2012-04-23 16:02:47 -0600 | [diff] [blame] | 286 | return (timestamp % Z180_PACKET_COUNT) |
| 287 | *sizeof(unsigned int)*(Z180_PACKET_SIZE); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Jeremy Gebben | 8b253bf | 2012-04-23 16:02:47 -0600 | [diff] [blame] | 290 | static inline unsigned int rb_gpuaddr(struct z180_device *z180_dev, |
| 291 | unsigned int timestamp) |
| 292 | { |
| 293 | return z180_dev->ringbuffer.cmdbufdesc.gpuaddr + rb_offset(timestamp); |
| 294 | } |
| 295 | |
| 296 | static void addmarker(struct z180_ringbuffer *rb, unsigned int timestamp) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 297 | { |
| 298 | char *ptr = (char *)(rb->cmdbufdesc.hostptr); |
Jeremy Gebben | 8b253bf | 2012-04-23 16:02:47 -0600 | [diff] [blame] | 299 | unsigned int *p = (unsigned int *)(ptr + rb_offset(timestamp)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 300 | |
| 301 | *p++ = Z180_STREAM_PACKET; |
| 302 | *p++ = (Z180_MARKER_CMD | 5); |
| 303 | *p++ = ADDR_VGV3_LAST << 24; |
| 304 | *p++ = ADDR_VGV3_LAST << 24; |
| 305 | *p++ = ADDR_VGV3_LAST << 24; |
| 306 | *p++ = Z180_STREAM_PACKET; |
| 307 | *p++ = 5; |
| 308 | *p++ = ADDR_VGV3_LAST << 24; |
| 309 | *p++ = ADDR_VGV3_LAST << 24; |
| 310 | *p++ = ADDR_VGV3_LAST << 24; |
| 311 | } |
| 312 | |
Jeremy Gebben | 8b253bf | 2012-04-23 16:02:47 -0600 | [diff] [blame] | 313 | static void addcmd(struct z180_ringbuffer *rb, unsigned int timestamp, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 314 | unsigned int cmd, unsigned int nextcnt) |
| 315 | { |
| 316 | char * ptr = (char *)(rb->cmdbufdesc.hostptr); |
Jeremy Gebben | 8b253bf | 2012-04-23 16:02:47 -0600 | [diff] [blame] | 317 | unsigned int *p = (unsigned int *)(ptr + (rb_offset(timestamp) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 318 | + (Z180_MARKER_SIZE * sizeof(unsigned int)))); |
| 319 | |
| 320 | *p++ = Z180_STREAM_PACKET_CALL; |
| 321 | *p++ = cmd; |
| 322 | *p++ = Z180_CALL_CMD | nextcnt; |
| 323 | *p++ = ADDR_VGV3_LAST << 24; |
| 324 | *p++ = ADDR_VGV3_LAST << 24; |
| 325 | } |
| 326 | |
Shubhraprakash Das | 8cbd232 | 2012-03-04 14:41:39 -0700 | [diff] [blame] | 327 | static void z180_cmdstream_start(struct kgsl_device *device, int init_ram) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 328 | { |
| 329 | struct z180_device *z180_dev = Z180_DEVICE(device); |
| 330 | unsigned int cmd = VGV3_NEXTCMD_JUMP << VGV3_NEXTCMD_NEXTCMD_FSHIFT; |
| 331 | |
Shubhraprakash Das | 8cbd232 | 2012-03-04 14:41:39 -0700 | [diff] [blame] | 332 | if (init_ram) { |
| 333 | z180_dev->timestamp = 0; |
| 334 | z180_dev->current_timestamp = 0; |
| 335 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 336 | |
| 337 | addmarker(&z180_dev->ringbuffer, 0); |
| 338 | |
| 339 | z180_cmdwindow_write(device, ADDR_VGV3_MODE, 4); |
| 340 | |
| 341 | z180_cmdwindow_write(device, ADDR_VGV3_NEXTADDR, |
Jeremy Gebben | 8b253bf | 2012-04-23 16:02:47 -0600 | [diff] [blame] | 342 | rb_gpuaddr(z180_dev, z180_dev->current_timestamp)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 343 | |
| 344 | z180_cmdwindow_write(device, ADDR_VGV3_NEXTCMD, cmd | 5); |
| 345 | |
| 346 | z180_cmdwindow_write(device, ADDR_VGV3_WRITEADDR, |
| 347 | device->memstore.gpuaddr); |
| 348 | |
| 349 | cmd = (int)(((1) & VGV3_CONTROL_MARKADD_FMASK) |
| 350 | << VGV3_CONTROL_MARKADD_FSHIFT); |
| 351 | |
| 352 | z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, cmd); |
| 353 | |
| 354 | z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, 0); |
| 355 | } |
| 356 | |
| 357 | static int room_in_rb(struct z180_device *device) |
| 358 | { |
| 359 | int ts_diff; |
| 360 | |
| 361 | ts_diff = device->current_timestamp - device->timestamp; |
| 362 | |
| 363 | return ts_diff < Z180_PACKET_COUNT; |
| 364 | } |
| 365 | |
| 366 | static int z180_idle(struct kgsl_device *device, unsigned int timeout) |
| 367 | { |
| 368 | int status = 0; |
| 369 | struct z180_device *z180_dev = Z180_DEVICE(device); |
| 370 | |
Jordan Crouse | e6239dd | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 371 | if (timestamp_cmp(z180_dev->current_timestamp, |
| 372 | z180_dev->timestamp) > 0) |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 373 | status = z180_wait(device, NULL, |
| 374 | z180_dev->current_timestamp, timeout); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 375 | |
| 376 | if (status) |
| 377 | KGSL_DRV_ERR(device, "z180_waittimestamp() timed out\n"); |
| 378 | |
| 379 | return status; |
| 380 | } |
| 381 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 382 | int |
| 383 | z180_cmdstream_issueibcmds(struct kgsl_device_private *dev_priv, |
| 384 | struct kgsl_context *context, |
| 385 | struct kgsl_ibdesc *ibdesc, |
| 386 | unsigned int numibs, |
| 387 | uint32_t *timestamp, |
| 388 | unsigned int ctrl) |
| 389 | { |
Tarun Karra | 9b92ccd | 2011-08-19 10:59:57 -0700 | [diff] [blame] | 390 | long result = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 391 | unsigned int ofs = PACKETSIZE_STATESTREAM * sizeof(unsigned int); |
| 392 | unsigned int cnt = 5; |
Jeremy Gebben | 8b253bf | 2012-04-23 16:02:47 -0600 | [diff] [blame] | 393 | unsigned int old_timestamp = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 394 | unsigned int nextcnt = Z180_STREAM_END_CMD | 5; |
Jeremy Gebben | d27b09f | 2012-04-06 16:09:13 -0600 | [diff] [blame] | 395 | struct kgsl_mem_entry *entry = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 396 | unsigned int cmd; |
| 397 | struct kgsl_device *device = dev_priv->device; |
| 398 | struct kgsl_pagetable *pagetable = dev_priv->process_priv->pagetable; |
| 399 | struct z180_device *z180_dev = Z180_DEVICE(device); |
| 400 | unsigned int sizedwords; |
| 401 | |
| 402 | if (device->state & KGSL_STATE_HUNG) { |
Carter Cooper | b90880d | 2011-10-26 14:38:02 -0600 | [diff] [blame] | 403 | result = -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 404 | goto error; |
| 405 | } |
| 406 | if (numibs != 1) { |
| 407 | KGSL_DRV_ERR(device, "Invalid number of ibs: %d\n", numibs); |
| 408 | result = -EINVAL; |
| 409 | goto error; |
| 410 | } |
| 411 | cmd = ibdesc[0].gpuaddr; |
| 412 | sizedwords = ibdesc[0].sizedwords; |
Jeremy Gebben | d27b09f | 2012-04-06 16:09:13 -0600 | [diff] [blame] | 413 | /* |
| 414 | * Get a kernel mapping to the IB for monkey patching. |
| 415 | * See the end of this function. |
| 416 | */ |
| 417 | entry = kgsl_sharedmem_find_region(dev_priv->process_priv, cmd, |
| 418 | sizedwords); |
| 419 | if (entry == NULL) { |
| 420 | KGSL_DRV_ERR(device, "Bad ibdesc: gpuaddr 0x%x size %d\n", |
| 421 | cmd, sizedwords); |
| 422 | result = -EINVAL; |
| 423 | goto error; |
| 424 | } |
| 425 | /* |
| 426 | * This will only map memory if it exists, otherwise it will reuse the |
| 427 | * mapping. And the 2d userspace reuses IBs so we likely won't create |
| 428 | * too many mappings. |
| 429 | */ |
| 430 | if (kgsl_gpuaddr_to_vaddr(&entry->memdesc, cmd) == NULL) { |
| 431 | KGSL_DRV_ERR(device, |
| 432 | "Cannot make kernel mapping for gpuaddr 0x%x\n", |
| 433 | cmd); |
| 434 | result = -EINVAL; |
| 435 | goto error; |
| 436 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 437 | |
| 438 | KGSL_CMD_INFO(device, "ctxt %d ibaddr 0x%08x sizedwords %d\n", |
| 439 | context->id, cmd, sizedwords); |
| 440 | /* context switch */ |
| 441 | if ((context->id != (int)z180_dev->ringbuffer.prevctx) || |
| 442 | (ctrl & KGSL_CONTEXT_CTX_SWITCH)) { |
| 443 | KGSL_CMD_INFO(device, "context switch %d -> %d\n", |
| 444 | context->id, z180_dev->ringbuffer.prevctx); |
Shubhraprakash Das | 7944795 | 2012-04-26 18:12:23 -0600 | [diff] [blame] | 445 | kgsl_mmu_setstate(&device->mmu, pagetable); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 446 | cnt = PACKETSIZE_STATESTREAM; |
| 447 | ofs = 0; |
| 448 | } |
Shubhraprakash Das | 1c52826 | 2012-04-26 17:38:13 -0600 | [diff] [blame] | 449 | kgsl_setstate(&device->mmu, |
| 450 | kgsl_mmu_pt_get_flags(device->mmu.hwpagetable, |
| 451 | device->id)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 452 | |
| 453 | result = wait_event_interruptible_timeout(device->wait_queue, |
| 454 | room_in_rb(z180_dev), |
| 455 | msecs_to_jiffies(KGSL_TIMEOUT_DEFAULT)); |
| 456 | if (result < 0) { |
| 457 | KGSL_CMD_ERR(device, "wait_event_interruptible_timeout " |
Tarun Karra | 9b92ccd | 2011-08-19 10:59:57 -0700 | [diff] [blame] | 458 | "failed: %ld\n", result); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 459 | goto error; |
| 460 | } |
| 461 | result = 0; |
| 462 | |
Jeremy Gebben | 8b253bf | 2012-04-23 16:02:47 -0600 | [diff] [blame] | 463 | old_timestamp = z180_dev->current_timestamp; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 464 | z180_dev->current_timestamp++; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 465 | *timestamp = z180_dev->current_timestamp; |
| 466 | |
| 467 | z180_dev->ringbuffer.prevctx = context->id; |
| 468 | |
Jeremy Gebben | 8b253bf | 2012-04-23 16:02:47 -0600 | [diff] [blame] | 469 | addcmd(&z180_dev->ringbuffer, old_timestamp, cmd + ofs, cnt); |
Lucille Sylvester | 808eca2 | 2011-11-03 10:26:29 -0700 | [diff] [blame] | 470 | kgsl_pwrscale_busy(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 471 | |
| 472 | /* Make sure the next ringbuffer entry has a marker */ |
Jeremy Gebben | 8b253bf | 2012-04-23 16:02:47 -0600 | [diff] [blame] | 473 | addmarker(&z180_dev->ringbuffer, z180_dev->current_timestamp); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 474 | |
Jeremy Gebben | d27b09f | 2012-04-06 16:09:13 -0600 | [diff] [blame] | 475 | /* monkey patch the IB so that it jumps back to the ringbuffer */ |
| 476 | kgsl_sharedmem_writel(&entry->memdesc, |
Jeremy Gebben | 8b253bf | 2012-04-23 16:02:47 -0600 | [diff] [blame] | 477 | ((sizedwords + 1) * sizeof(unsigned int)), |
| 478 | rb_gpuaddr(z180_dev, z180_dev->current_timestamp)); |
Jeremy Gebben | d27b09f | 2012-04-06 16:09:13 -0600 | [diff] [blame] | 479 | kgsl_sharedmem_writel(&entry->memdesc, |
| 480 | ((sizedwords + 2) * sizeof(unsigned int)), |
| 481 | nextcnt); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 482 | |
| 483 | /* sync memory before activating the hardware for the new command*/ |
| 484 | mb(); |
| 485 | |
| 486 | cmd = (int)(((2) & VGV3_CONTROL_MARKADD_FMASK) |
| 487 | << VGV3_CONTROL_MARKADD_FSHIFT); |
| 488 | |
| 489 | z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, cmd); |
| 490 | z180_cmdwindow_write(device, ADDR_VGV3_CONTROL, 0); |
| 491 | error: |
Tarun Karra | 9b92ccd | 2011-08-19 10:59:57 -0700 | [diff] [blame] | 492 | return (int)result; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | static int z180_ringbuffer_init(struct kgsl_device *device) |
| 496 | { |
| 497 | struct z180_device *z180_dev = Z180_DEVICE(device); |
| 498 | memset(&z180_dev->ringbuffer, 0, sizeof(struct z180_ringbuffer)); |
| 499 | z180_dev->ringbuffer.prevctx = Z180_INVALID_CONTEXT; |
| 500 | return kgsl_allocate_contiguous(&z180_dev->ringbuffer.cmdbufdesc, |
| 501 | Z180_RB_SIZE); |
| 502 | } |
| 503 | |
| 504 | static void z180_ringbuffer_close(struct kgsl_device *device) |
| 505 | { |
| 506 | struct z180_device *z180_dev = Z180_DEVICE(device); |
| 507 | kgsl_sharedmem_free(&z180_dev->ringbuffer.cmdbufdesc); |
| 508 | memset(&z180_dev->ringbuffer, 0, sizeof(struct z180_ringbuffer)); |
| 509 | } |
| 510 | |
| 511 | static int __devinit z180_probe(struct platform_device *pdev) |
| 512 | { |
| 513 | int status = -EINVAL; |
| 514 | struct kgsl_device *device = NULL; |
| 515 | struct z180_device *z180_dev; |
| 516 | |
| 517 | device = (struct kgsl_device *)pdev->id_entry->driver_data; |
| 518 | device->parentdev = &pdev->dev; |
| 519 | |
| 520 | z180_dev = Z180_DEVICE(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 521 | |
| 522 | status = z180_ringbuffer_init(device); |
| 523 | if (status != 0) |
| 524 | goto error; |
| 525 | |
Jordan Crouse | b368e9b | 2012-04-27 14:01:59 -0600 | [diff] [blame] | 526 | status = kgsl_device_platform_probe(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 527 | if (status) |
| 528 | goto error_close_ringbuffer; |
| 529 | |
Lucille Sylvester | 591ea03 | 2011-07-21 16:08:37 -0600 | [diff] [blame] | 530 | kgsl_pwrscale_init(device); |
Lucille Sylvester | 808eca2 | 2011-11-03 10:26:29 -0700 | [diff] [blame] | 531 | kgsl_pwrscale_attach_policy(device, Z180_DEFAULT_PWRSCALE_POLICY); |
Lucille Sylvester | 591ea03 | 2011-07-21 16:08:37 -0600 | [diff] [blame] | 532 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 533 | return status; |
| 534 | |
| 535 | error_close_ringbuffer: |
| 536 | z180_ringbuffer_close(device); |
| 537 | error: |
| 538 | device->parentdev = NULL; |
| 539 | return status; |
| 540 | } |
| 541 | |
| 542 | static int __devexit z180_remove(struct platform_device *pdev) |
| 543 | { |
| 544 | struct kgsl_device *device = NULL; |
| 545 | |
| 546 | device = (struct kgsl_device *)pdev->id_entry->driver_data; |
| 547 | |
Lucille Sylvester | 591ea03 | 2011-07-21 16:08:37 -0600 | [diff] [blame] | 548 | kgsl_pwrscale_close(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 549 | kgsl_device_platform_remove(device); |
| 550 | |
| 551 | z180_ringbuffer_close(device); |
| 552 | |
| 553 | return 0; |
| 554 | } |
| 555 | |
| 556 | static int z180_start(struct kgsl_device *device, unsigned int init_ram) |
| 557 | { |
| 558 | int status = 0; |
| 559 | |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 560 | kgsl_pwrctrl_set_state(device, KGSL_STATE_INIT); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 561 | |
| 562 | kgsl_pwrctrl_enable(device); |
| 563 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 564 | /* Set interrupts to 0 to ensure a good state */ |
| 565 | z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 0x0); |
| 566 | |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 567 | kgsl_mh_start(device); |
| 568 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 569 | status = kgsl_mmu_start(device); |
| 570 | if (status) |
| 571 | goto error_clk_off; |
| 572 | |
Shubhraprakash Das | 8cbd232 | 2012-03-04 14:41:39 -0700 | [diff] [blame] | 573 | z180_cmdstream_start(device, init_ram); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 574 | |
| 575 | mod_timer(&device->idle_timer, jiffies + FIRST_TIMEOUT); |
Jeremy Gebben | b46f415 | 2011-10-14 14:27:00 -0600 | [diff] [blame] | 576 | kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_ON); |
Jeremy Gebben | b7bc955 | 2012-01-09 13:32:49 -0700 | [diff] [blame] | 577 | device->ftbl->irqctrl(device, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 578 | return 0; |
| 579 | |
| 580 | error_clk_off: |
| 581 | z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 0); |
| 582 | kgsl_pwrctrl_disable(device); |
| 583 | return status; |
| 584 | } |
| 585 | |
| 586 | static int z180_stop(struct kgsl_device *device) |
| 587 | { |
Jeremy Gebben | b7bc955 | 2012-01-09 13:32:49 -0700 | [diff] [blame] | 588 | device->ftbl->irqctrl(device, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 589 | z180_idle(device, KGSL_TIMEOUT_DEFAULT); |
| 590 | |
Suman Tatiraju | 4a32c65 | 2012-02-17 11:59:05 -0800 | [diff] [blame] | 591 | del_timer_sync(&device->idle_timer); |
| 592 | |
Shubhraprakash Das | 7944795 | 2012-04-26 18:12:23 -0600 | [diff] [blame] | 593 | kgsl_mmu_stop(&device->mmu); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 594 | |
| 595 | /* Disable the clocks before the power rail. */ |
| 596 | kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF); |
| 597 | |
| 598 | kgsl_pwrctrl_disable(device); |
| 599 | |
| 600 | return 0; |
| 601 | } |
| 602 | |
| 603 | static int z180_getproperty(struct kgsl_device *device, |
| 604 | enum kgsl_property_type type, |
| 605 | void *value, |
| 606 | unsigned int sizebytes) |
| 607 | { |
| 608 | int status = -EINVAL; |
| 609 | |
| 610 | switch (type) { |
| 611 | case KGSL_PROP_DEVICE_INFO: |
| 612 | { |
| 613 | struct kgsl_devinfo devinfo; |
| 614 | |
| 615 | if (sizebytes != sizeof(devinfo)) { |
| 616 | status = -EINVAL; |
| 617 | break; |
| 618 | } |
| 619 | |
| 620 | memset(&devinfo, 0, sizeof(devinfo)); |
| 621 | devinfo.device_id = device->id+1; |
| 622 | devinfo.chip_id = 0; |
| 623 | devinfo.mmu_enabled = kgsl_mmu_enabled(); |
| 624 | |
| 625 | if (copy_to_user(value, &devinfo, sizeof(devinfo)) != |
| 626 | 0) { |
| 627 | status = -EFAULT; |
| 628 | break; |
| 629 | } |
| 630 | status = 0; |
| 631 | } |
| 632 | break; |
| 633 | case KGSL_PROP_MMU_ENABLE: |
| 634 | { |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 635 | int mmu_prop = kgsl_mmu_enabled(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 636 | if (sizebytes != sizeof(int)) { |
| 637 | status = -EINVAL; |
| 638 | break; |
| 639 | } |
Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 640 | if (copy_to_user(value, &mmu_prop, sizeof(mmu_prop))) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 641 | status = -EFAULT; |
| 642 | break; |
| 643 | } |
| 644 | status = 0; |
| 645 | } |
| 646 | break; |
| 647 | |
| 648 | default: |
| 649 | KGSL_DRV_ERR(device, "invalid property: %d\n", type); |
| 650 | status = -EINVAL; |
| 651 | } |
| 652 | return status; |
| 653 | } |
| 654 | |
| 655 | static unsigned int z180_isidle(struct kgsl_device *device) |
| 656 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 657 | struct z180_device *z180_dev = Z180_DEVICE(device); |
| 658 | |
Jordan Crouse | e6239dd | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 659 | return (timestamp_cmp(z180_dev->timestamp, |
| 660 | z180_dev->current_timestamp) == 0) ? true : false; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | static int z180_suspend_context(struct kgsl_device *device) |
| 664 | { |
| 665 | struct z180_device *z180_dev = Z180_DEVICE(device); |
| 666 | |
| 667 | z180_dev->ringbuffer.prevctx = Z180_INVALID_CONTEXT; |
| 668 | |
| 669 | return 0; |
| 670 | } |
| 671 | |
| 672 | /* Not all Z180 registers are directly accessible. |
| 673 | * The _z180_(read|write)_simple functions below handle the ones that are. |
| 674 | */ |
| 675 | static void _z180_regread_simple(struct kgsl_device *device, |
| 676 | unsigned int offsetwords, |
| 677 | unsigned int *value) |
| 678 | { |
| 679 | unsigned int *reg; |
| 680 | |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 681 | BUG_ON(offsetwords * sizeof(uint32_t) >= device->reg_len); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 682 | |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 683 | reg = (unsigned int *)(device->reg_virt + (offsetwords << 2)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 684 | |
| 685 | /*ensure this read finishes before the next one. |
| 686 | * i.e. act like normal readl() */ |
| 687 | *value = __raw_readl(reg); |
| 688 | rmb(); |
| 689 | |
| 690 | } |
| 691 | |
| 692 | static void _z180_regwrite_simple(struct kgsl_device *device, |
| 693 | unsigned int offsetwords, |
| 694 | unsigned int value) |
| 695 | { |
| 696 | unsigned int *reg; |
| 697 | |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 698 | BUG_ON(offsetwords*sizeof(uint32_t) >= device->reg_len); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 699 | |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 700 | reg = (unsigned int *)(device->reg_virt + (offsetwords << 2)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 701 | kgsl_cffdump_regwrite(device->id, offsetwords << 2, value); |
| 702 | /*ensure previous writes post before this one, |
| 703 | * i.e. act like normal writel() */ |
| 704 | wmb(); |
| 705 | __raw_writel(value, reg); |
| 706 | } |
| 707 | |
| 708 | |
| 709 | /* The MH registers must be accessed through via a 2 step write, (read|write) |
| 710 | * process. These registers may be accessed from interrupt context during |
| 711 | * the handling of MH or MMU error interrupts. Therefore a spin lock is used |
| 712 | * to ensure that the 2 step sequence is not interrupted. |
| 713 | */ |
| 714 | static void _z180_regread_mmu(struct kgsl_device *device, |
| 715 | unsigned int offsetwords, |
| 716 | unsigned int *value) |
| 717 | { |
| 718 | struct z180_device *z180_dev = Z180_DEVICE(device); |
| 719 | unsigned long flags; |
| 720 | |
| 721 | spin_lock_irqsave(&z180_dev->cmdwin_lock, flags); |
| 722 | _z180_regwrite_simple(device, (ADDR_VGC_MH_READ_ADDR >> 2), |
| 723 | offsetwords); |
| 724 | _z180_regread_simple(device, (ADDR_VGC_MH_DATA_ADDR >> 2), value); |
| 725 | spin_unlock_irqrestore(&z180_dev->cmdwin_lock, flags); |
| 726 | } |
| 727 | |
| 728 | |
| 729 | static void _z180_regwrite_mmu(struct kgsl_device *device, |
| 730 | unsigned int offsetwords, |
| 731 | unsigned int value) |
| 732 | { |
| 733 | struct z180_device *z180_dev = Z180_DEVICE(device); |
| 734 | unsigned int cmdwinaddr; |
| 735 | unsigned long flags; |
| 736 | |
| 737 | cmdwinaddr = ((Z180_CMDWINDOW_MMU << Z180_CMDWINDOW_TARGET_SHIFT) & |
| 738 | Z180_CMDWINDOW_TARGET_MASK); |
| 739 | cmdwinaddr |= ((offsetwords << Z180_CMDWINDOW_ADDR_SHIFT) & |
| 740 | Z180_CMDWINDOW_ADDR_MASK); |
| 741 | |
| 742 | spin_lock_irqsave(&z180_dev->cmdwin_lock, flags); |
| 743 | _z180_regwrite_simple(device, ADDR_VGC_MMUCOMMANDSTREAM >> 2, |
| 744 | cmdwinaddr); |
| 745 | _z180_regwrite_simple(device, ADDR_VGC_MMUCOMMANDSTREAM >> 2, value); |
| 746 | spin_unlock_irqrestore(&z180_dev->cmdwin_lock, flags); |
| 747 | } |
| 748 | |
| 749 | /* the rest of the code doesn't want to think about if it is writing mmu |
| 750 | * registers or normal registers so handle it here |
| 751 | */ |
| 752 | static void z180_regread(struct kgsl_device *device, |
| 753 | unsigned int offsetwords, |
| 754 | unsigned int *value) |
| 755 | { |
| 756 | if (!in_interrupt()) |
| 757 | kgsl_pre_hwaccess(device); |
| 758 | |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 759 | if ((offsetwords >= MH_ARBITER_CONFIG && |
| 760 | offsetwords <= MH_AXI_HALT_CONTROL) || |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 761 | (offsetwords >= MH_MMU_CONFIG && |
| 762 | offsetwords <= MH_MMU_MPU_END)) { |
| 763 | _z180_regread_mmu(device, offsetwords, value); |
| 764 | } else { |
| 765 | _z180_regread_simple(device, offsetwords, value); |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | static void z180_regwrite(struct kgsl_device *device, |
| 770 | unsigned int offsetwords, |
| 771 | unsigned int value) |
| 772 | { |
| 773 | if (!in_interrupt()) |
| 774 | kgsl_pre_hwaccess(device); |
| 775 | |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 776 | if ((offsetwords >= MH_ARBITER_CONFIG && |
| 777 | offsetwords <= MH_CLNT_INTF_CTRL_CONFIG2) || |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 778 | (offsetwords >= MH_MMU_CONFIG && |
| 779 | offsetwords <= MH_MMU_MPU_END)) { |
| 780 | _z180_regwrite_mmu(device, offsetwords, value); |
| 781 | } else { |
| 782 | _z180_regwrite_simple(device, offsetwords, value); |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | static void z180_cmdwindow_write(struct kgsl_device *device, |
| 787 | unsigned int addr, unsigned int data) |
| 788 | { |
| 789 | unsigned int cmdwinaddr; |
| 790 | |
| 791 | cmdwinaddr = ((Z180_CMDWINDOW_2D << Z180_CMDWINDOW_TARGET_SHIFT) & |
| 792 | Z180_CMDWINDOW_TARGET_MASK); |
| 793 | cmdwinaddr |= ((addr << Z180_CMDWINDOW_ADDR_SHIFT) & |
| 794 | Z180_CMDWINDOW_ADDR_MASK); |
| 795 | |
| 796 | z180_regwrite(device, ADDR_VGC_COMMANDSTREAM >> 2, cmdwinaddr); |
| 797 | z180_regwrite(device, ADDR_VGC_COMMANDSTREAM >> 2, data); |
| 798 | } |
| 799 | |
| 800 | static unsigned int z180_readtimestamp(struct kgsl_device *device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 801 | struct kgsl_context *context, enum kgsl_timestamp_type type) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 802 | { |
| 803 | struct z180_device *z180_dev = Z180_DEVICE(device); |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 804 | (void)context; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 805 | /* get current EOP timestamp */ |
| 806 | return z180_dev->timestamp; |
| 807 | } |
| 808 | |
| 809 | static int z180_waittimestamp(struct kgsl_device *device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 810 | struct kgsl_context *context, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 811 | unsigned int timestamp, |
| 812 | unsigned int msecs) |
| 813 | { |
| 814 | int status = -EINVAL; |
Ranjhith Kalisamy | 823c148 | 2011-09-05 20:31:07 +0530 | [diff] [blame] | 815 | |
| 816 | /* Don't wait forever, set a max (10 sec) value for now */ |
| 817 | if (msecs == -1) |
| 818 | msecs = 10 * MSEC_PER_SEC; |
| 819 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 820 | mutex_unlock(&device->mutex); |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 821 | status = z180_wait(device, context, timestamp, msecs); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 822 | mutex_lock(&device->mutex); |
| 823 | |
| 824 | return status; |
| 825 | } |
| 826 | |
| 827 | static int z180_wait(struct kgsl_device *device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 828 | struct kgsl_context *context, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 829 | unsigned int timestamp, |
| 830 | unsigned int msecs) |
| 831 | { |
| 832 | int status = -EINVAL; |
| 833 | long timeout = 0; |
| 834 | |
| 835 | timeout = wait_io_event_interruptible_timeout( |
| 836 | device->wait_queue, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 837 | kgsl_check_timestamp(device, context, timestamp), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 838 | msecs_to_jiffies(msecs)); |
| 839 | |
| 840 | if (timeout > 0) |
| 841 | status = 0; |
| 842 | else if (timeout == 0) { |
| 843 | status = -ETIMEDOUT; |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 844 | kgsl_pwrctrl_set_state(device, KGSL_STATE_HUNG); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 845 | } else |
| 846 | status = timeout; |
| 847 | |
| 848 | return status; |
| 849 | } |
| 850 | |
| 851 | static void |
| 852 | z180_drawctxt_destroy(struct kgsl_device *device, |
| 853 | struct kgsl_context *context) |
| 854 | { |
| 855 | struct z180_device *z180_dev = Z180_DEVICE(device); |
| 856 | |
| 857 | z180_idle(device, KGSL_TIMEOUT_DEFAULT); |
| 858 | |
| 859 | if (z180_dev->ringbuffer.prevctx == context->id) { |
| 860 | z180_dev->ringbuffer.prevctx = Z180_INVALID_CONTEXT; |
| 861 | device->mmu.hwpagetable = device->mmu.defaultpagetable; |
Shubhraprakash Das | 1c52826 | 2012-04-26 17:38:13 -0600 | [diff] [blame] | 862 | kgsl_setstate(&device->mmu, KGSL_MMUFLAGS_PTUPDATE); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 863 | } |
| 864 | } |
| 865 | |
| 866 | static void z180_power_stats(struct kgsl_device *device, |
| 867 | struct kgsl_power_stats *stats) |
| 868 | { |
Lucille Sylvester | 591ea03 | 2011-07-21 16:08:37 -0600 | [diff] [blame] | 869 | struct kgsl_pwrctrl *pwr = &device->pwrctrl; |
Lucille Sylvester | 808eca2 | 2011-11-03 10:26:29 -0700 | [diff] [blame] | 870 | s64 tmp = ktime_to_us(ktime_get()); |
Lucille Sylvester | 591ea03 | 2011-07-21 16:08:37 -0600 | [diff] [blame] | 871 | |
| 872 | if (pwr->time == 0) { |
Lucille Sylvester | 808eca2 | 2011-11-03 10:26:29 -0700 | [diff] [blame] | 873 | pwr->time = tmp; |
Lucille Sylvester | 591ea03 | 2011-07-21 16:08:37 -0600 | [diff] [blame] | 874 | stats->total_time = 0; |
| 875 | stats->busy_time = 0; |
| 876 | } else { |
Lucille Sylvester | 591ea03 | 2011-07-21 16:08:37 -0600 | [diff] [blame] | 877 | stats->total_time = tmp - pwr->time; |
Lucille Sylvester | 591ea03 | 2011-07-21 16:08:37 -0600 | [diff] [blame] | 878 | pwr->time = tmp; |
Lucille Sylvester | 808eca2 | 2011-11-03 10:26:29 -0700 | [diff] [blame] | 879 | stats->busy_time = tmp - device->on_time; |
| 880 | device->on_time = tmp; |
Lucille Sylvester | 591ea03 | 2011-07-21 16:08:37 -0600 | [diff] [blame] | 881 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | static void z180_irqctrl(struct kgsl_device *device, int state) |
| 885 | { |
| 886 | /* Control interrupts for Z180 and the Z180 MMU */ |
| 887 | |
| 888 | if (state) { |
| 889 | z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 3); |
| 890 | z180_regwrite(device, MH_INTERRUPT_MASK, KGSL_MMU_INT_MASK); |
| 891 | } else { |
| 892 | z180_regwrite(device, (ADDR_VGC_IRQENABLE >> 2), 0); |
| 893 | z180_regwrite(device, MH_INTERRUPT_MASK, 0); |
| 894 | } |
| 895 | } |
| 896 | |
Jordan Crouse | a0758f2 | 2011-12-07 11:19:22 -0700 | [diff] [blame] | 897 | static unsigned int z180_gpuid(struct kgsl_device *device) |
| 898 | { |
| 899 | /* Standard KGSL gpuid format: |
| 900 | * top word is 0x0002 for 2D or 0x0003 for 3D |
| 901 | * Bottom word is core specific identifer |
| 902 | */ |
| 903 | |
| 904 | return (0x0002 << 16) | 180; |
| 905 | } |
| 906 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 907 | static const struct kgsl_functable z180_functable = { |
| 908 | /* Mandatory functions */ |
| 909 | .regread = z180_regread, |
| 910 | .regwrite = z180_regwrite, |
| 911 | .idle = z180_idle, |
| 912 | .isidle = z180_isidle, |
| 913 | .suspend_context = z180_suspend_context, |
| 914 | .start = z180_start, |
| 915 | .stop = z180_stop, |
| 916 | .getproperty = z180_getproperty, |
| 917 | .waittimestamp = z180_waittimestamp, |
| 918 | .readtimestamp = z180_readtimestamp, |
| 919 | .issueibcmds = z180_cmdstream_issueibcmds, |
| 920 | .setup_pt = z180_setup_pt, |
| 921 | .cleanup_pt = z180_cleanup_pt, |
| 922 | .power_stats = z180_power_stats, |
| 923 | .irqctrl = z180_irqctrl, |
Jordan Crouse | a0758f2 | 2011-12-07 11:19:22 -0700 | [diff] [blame] | 924 | .gpuid = z180_gpuid, |
Jordan Crouse | b368e9b | 2012-04-27 14:01:59 -0600 | [diff] [blame] | 925 | .irq_handler = z180_irq_handler, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 926 | /* Optional functions */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 927 | .drawctxt_create = NULL, |
| 928 | .drawctxt_destroy = z180_drawctxt_destroy, |
| 929 | .ioctl = NULL, |
| 930 | }; |
| 931 | |
| 932 | static struct platform_device_id z180_id_table[] = { |
| 933 | { DEVICE_2D0_NAME, (kernel_ulong_t)&device_2d0.dev, }, |
| 934 | { DEVICE_2D1_NAME, (kernel_ulong_t)&device_2d1.dev, }, |
| 935 | { }, |
| 936 | }; |
| 937 | MODULE_DEVICE_TABLE(platform, z180_id_table); |
| 938 | |
| 939 | static struct platform_driver z180_platform_driver = { |
| 940 | .probe = z180_probe, |
| 941 | .remove = __devexit_p(z180_remove), |
| 942 | .suspend = kgsl_suspend_driver, |
| 943 | .resume = kgsl_resume_driver, |
| 944 | .id_table = z180_id_table, |
| 945 | .driver = { |
| 946 | .owner = THIS_MODULE, |
| 947 | .name = DEVICE_2D_NAME, |
| 948 | .pm = &kgsl_pm_ops, |
| 949 | } |
| 950 | }; |
| 951 | |
| 952 | static int __init kgsl_2d_init(void) |
| 953 | { |
| 954 | return platform_driver_register(&z180_platform_driver); |
| 955 | } |
| 956 | |
| 957 | static void __exit kgsl_2d_exit(void) |
| 958 | { |
| 959 | platform_driver_unregister(&z180_platform_driver); |
| 960 | } |
| 961 | |
| 962 | module_init(kgsl_2d_init); |
| 963 | module_exit(kgsl_2d_exit); |
| 964 | |
| 965 | MODULE_DESCRIPTION("2D Graphics driver"); |
| 966 | MODULE_VERSION("1.2"); |
| 967 | MODULE_LICENSE("GPL v2"); |
| 968 | MODULE_ALIAS("platform:kgsl_2d"); |