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