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