Duy Truong | e833aca | 2013-02-12 13:35:08 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2002,2007-2012, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | #ifndef __KGSL_DEVICE_H |
| 14 | #define __KGSL_DEVICE_H |
| 15 | |
| 16 | #include <linux/idr.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 17 | #include <linux/pm_qos.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 18 | #include <linux/earlysuspend.h> |
| 19 | |
| 20 | #include "kgsl.h" |
| 21 | #include "kgsl_mmu.h" |
| 22 | #include "kgsl_pwrctrl.h" |
| 23 | #include "kgsl_log.h" |
| 24 | #include "kgsl_pwrscale.h" |
Jeff Boody | fe6c39c | 2012-08-09 13:54:50 -0600 | [diff] [blame] | 25 | #include <linux/sync.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 26 | |
Tarun Karra | 696f89e | 2013-01-27 21:31:40 -0800 | [diff] [blame] | 27 | #define KGSL_TIMEOUT_NONE 0 |
| 28 | #define KGSL_TIMEOUT_DEFAULT 0xFFFFFFFF |
| 29 | #define KGSL_TIMEOUT_PART 50 /* 50 msec */ |
| 30 | #define KGSL_TIMEOUT_LONG_IB_DETECTION 2000 /* 2 sec*/ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 31 | |
| 32 | #define FIRST_TIMEOUT (HZ / 2) |
| 33 | |
| 34 | |
| 35 | /* KGSL device state is initialized to INIT when platform_probe * |
| 36 | * sucessfully initialized the device. Once a device has been opened * |
| 37 | * (started) it becomes active. NAP implies that only low latency * |
| 38 | * resources (for now clocks on some platforms) are off. SLEEP implies * |
| 39 | * that the KGSL module believes a device is idle (has been inactive * |
| 40 | * past its timer) and all system resources are released. SUSPEND is * |
| 41 | * requested by the kernel and will be enforced upon all open devices. */ |
| 42 | |
| 43 | #define KGSL_STATE_NONE 0x00000000 |
| 44 | #define KGSL_STATE_INIT 0x00000001 |
| 45 | #define KGSL_STATE_ACTIVE 0x00000002 |
| 46 | #define KGSL_STATE_NAP 0x00000004 |
| 47 | #define KGSL_STATE_SLEEP 0x00000008 |
| 48 | #define KGSL_STATE_SUSPEND 0x00000010 |
| 49 | #define KGSL_STATE_HUNG 0x00000020 |
Tarun Karra | d20d71a | 2013-01-25 15:38:57 -0800 | [diff] [blame] | 50 | #define KGSL_STATE_DUMP_AND_FT 0x00000040 |
Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 51 | #define KGSL_STATE_SLUMBER 0x00000080 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 52 | |
| 53 | #define KGSL_GRAPHICS_MEMORY_LOW_WATERMARK 0x1000000 |
| 54 | |
| 55 | #define KGSL_IS_PAGE_ALIGNED(addr) (!((addr) & (~PAGE_MASK))) |
| 56 | |
| 57 | struct kgsl_device; |
| 58 | struct platform_device; |
| 59 | struct kgsl_device_private; |
| 60 | struct kgsl_context; |
| 61 | struct kgsl_power_stats; |
Jordan Crouse | 313faf6 | 2012-11-20 15:12:28 -0700 | [diff] [blame] | 62 | struct kgsl_event; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 63 | |
| 64 | struct kgsl_functable { |
| 65 | /* Mandatory functions - these functions must be implemented |
| 66 | by the client device. The driver will not check for a NULL |
| 67 | pointer before calling the hook. |
| 68 | */ |
| 69 | void (*regread) (struct kgsl_device *device, |
| 70 | unsigned int offsetwords, unsigned int *value); |
| 71 | void (*regwrite) (struct kgsl_device *device, |
| 72 | unsigned int offsetwords, unsigned int value); |
Jordan Crouse | a29a2e0 | 2012-08-14 09:09:23 -0600 | [diff] [blame] | 73 | int (*idle) (struct kgsl_device *device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 74 | unsigned int (*isidle) (struct kgsl_device *device); |
| 75 | int (*suspend_context) (struct kgsl_device *device); |
| 76 | int (*start) (struct kgsl_device *device, unsigned int init_ram); |
| 77 | int (*stop) (struct kgsl_device *device); |
| 78 | int (*getproperty) (struct kgsl_device *device, |
| 79 | enum kgsl_property_type type, void *value, |
| 80 | unsigned int sizebytes); |
| 81 | int (*waittimestamp) (struct kgsl_device *device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 82 | struct kgsl_context *context, unsigned int timestamp, |
| 83 | unsigned int msecs); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 84 | unsigned int (*readtimestamp) (struct kgsl_device *device, |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 85 | struct kgsl_context *context, enum kgsl_timestamp_type type); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 86 | int (*issueibcmds) (struct kgsl_device_private *dev_priv, |
| 87 | struct kgsl_context *context, struct kgsl_ibdesc *ibdesc, |
| 88 | unsigned int sizedwords, uint32_t *timestamp, |
| 89 | unsigned int flags); |
| 90 | int (*setup_pt)(struct kgsl_device *device, |
| 91 | struct kgsl_pagetable *pagetable); |
Jordan Crouse | 9f73921 | 2011-07-28 08:37:57 -0600 | [diff] [blame] | 92 | void (*cleanup_pt)(struct kgsl_device *device, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 93 | struct kgsl_pagetable *pagetable); |
| 94 | void (*power_stats)(struct kgsl_device *device, |
| 95 | struct kgsl_power_stats *stats); |
| 96 | void (*irqctrl)(struct kgsl_device *device, int state); |
Jordan Crouse | d653588 | 2012-06-20 08:22:16 -0600 | [diff] [blame] | 97 | unsigned int (*gpuid)(struct kgsl_device *device, unsigned int *chipid); |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 98 | void * (*snapshot)(struct kgsl_device *device, void *snapshot, |
| 99 | int *remain, int hang); |
Jordan Crouse | b368e9b | 2012-04-27 14:01:59 -0600 | [diff] [blame] | 100 | irqreturn_t (*irq_handler)(struct kgsl_device *device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 101 | /* Optional functions - these functions are not mandatory. The |
| 102 | driver will check that the function pointer is not NULL before |
| 103 | calling the hook */ |
Shubhraprakash Das | b2abc45 | 2012-06-08 16:33:03 -0600 | [diff] [blame] | 104 | void (*setstate) (struct kgsl_device *device, unsigned int context_id, |
| 105 | uint32_t flags); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 106 | int (*drawctxt_create) (struct kgsl_device *device, |
| 107 | struct kgsl_pagetable *pagetable, struct kgsl_context *context, |
| 108 | uint32_t flags); |
| 109 | void (*drawctxt_destroy) (struct kgsl_device *device, |
| 110 | struct kgsl_context *context); |
| 111 | long (*ioctl) (struct kgsl_device_private *dev_priv, |
| 112 | unsigned int cmd, void *data); |
Jordan Crouse | ed7dd7f | 2012-03-29 13:16:02 -0600 | [diff] [blame] | 113 | int (*setproperty) (struct kgsl_device *device, |
| 114 | enum kgsl_property_type type, void *value, |
| 115 | unsigned int sizebytes); |
Harsh Vardhan Dwivedi | 715fb83 | 2012-05-18 00:24:18 -0600 | [diff] [blame] | 116 | int (*postmortem_dump) (struct kgsl_device *device, int manual); |
Jordan Crouse | 313faf6 | 2012-11-20 15:12:28 -0700 | [diff] [blame] | 117 | void (*next_event)(struct kgsl_device *device, |
| 118 | struct kgsl_event *event); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 119 | }; |
| 120 | |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 121 | /* MH register values */ |
| 122 | struct kgsl_mh { |
| 123 | unsigned int mharb; |
| 124 | unsigned int mh_intf_cfg1; |
| 125 | unsigned int mh_intf_cfg2; |
| 126 | uint32_t mpu_base; |
| 127 | int mpu_range; |
| 128 | }; |
| 129 | |
Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 130 | struct kgsl_event { |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 131 | struct kgsl_context *context; |
Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 132 | uint32_t timestamp; |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 133 | void (*func)(struct kgsl_device *, void *, u32, u32); |
Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 134 | void *priv; |
| 135 | struct list_head list; |
Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 136 | void *owner; |
Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 140 | struct kgsl_device { |
| 141 | struct device *dev; |
| 142 | const char *name; |
| 143 | unsigned int ver_major; |
| 144 | unsigned int ver_minor; |
| 145 | uint32_t flags; |
| 146 | enum kgsl_deviceid id; |
Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 147 | unsigned long reg_phys; |
| 148 | void *reg_virt; |
| 149 | unsigned int reg_len; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 150 | struct kgsl_memdesc memstore; |
| 151 | const char *iomemname; |
| 152 | |
Jeremy Gebben | 4e8aada | 2011-07-12 10:07:47 -0600 | [diff] [blame] | 153 | struct kgsl_mh mh; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 154 | struct kgsl_mmu mmu; |
| 155 | struct completion hwaccess_gate; |
| 156 | const struct kgsl_functable *ftbl; |
| 157 | struct work_struct idle_check_ws; |
| 158 | struct timer_list idle_timer; |
| 159 | struct kgsl_pwrctrl pwrctrl; |
| 160 | int open_count; |
| 161 | |
| 162 | struct atomic_notifier_head ts_notifier_list; |
| 163 | struct mutex mutex; |
| 164 | uint32_t state; |
| 165 | uint32_t requested_state; |
| 166 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 167 | unsigned int active_cnt; |
| 168 | struct completion suspend_gate; |
| 169 | |
| 170 | wait_queue_head_t wait_queue; |
| 171 | struct workqueue_struct *work_queue; |
| 172 | struct device *parentdev; |
Tarun Karra | d20d71a | 2013-01-25 15:38:57 -0800 | [diff] [blame] | 173 | struct completion ft_gate; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 174 | struct dentry *d_debugfs; |
| 175 | struct idr context_idr; |
| 176 | struct early_suspend display_off; |
| 177 | |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 178 | void *snapshot; /* Pointer to the snapshot memory region */ |
| 179 | int snapshot_maxsize; /* Max size of the snapshot region */ |
| 180 | int snapshot_size; /* Current size of the snapshot region */ |
| 181 | u32 snapshot_timestamp; /* Timestamp of the last valid snapshot */ |
| 182 | int snapshot_frozen; /* 1 if the snapshot output is frozen until |
| 183 | it gets read by the user. This avoids |
| 184 | losing the output on multiple hangs */ |
| 185 | struct kobject snapshot_kobj; |
| 186 | |
Jordan Crouse | 9610b6b | 2012-03-16 14:53:42 -0600 | [diff] [blame] | 187 | /* |
| 188 | * List of GPU buffers that have been frozen in memory until they can be |
| 189 | * dumped |
| 190 | */ |
| 191 | struct list_head snapshot_obj_list; |
| 192 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 193 | /* Logging levels */ |
| 194 | int cmd_log; |
| 195 | int ctxt_log; |
| 196 | int drv_log; |
| 197 | int mem_log; |
| 198 | int pwr_log; |
Tarun Karra | d20d71a | 2013-01-25 15:38:57 -0800 | [diff] [blame] | 199 | int ft_log; |
Tarun Karra | 45a50d6 | 2013-01-28 21:47:37 -0800 | [diff] [blame^] | 200 | int pm_dump_enable; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 201 | struct kgsl_pwrscale pwrscale; |
| 202 | struct kobject pwrscale_kobj; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 203 | struct pm_qos_request pm_qos_req_dma; |
Jordan Crouse | 1bf80aa | 2011-10-12 16:57:47 -0600 | [diff] [blame] | 204 | struct work_struct ts_expired_ws; |
Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 205 | struct list_head events; |
Lucille Sylvester | 808eca2 | 2011-11-03 10:26:29 -0700 | [diff] [blame] | 206 | s64 on_time; |
Harsh Vardhan Dwivedi | 715fb83 | 2012-05-18 00:24:18 -0600 | [diff] [blame] | 207 | |
| 208 | /* Postmortem Control switches */ |
| 209 | int pm_regs_enabled; |
| 210 | int pm_ib_enabled; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 211 | }; |
| 212 | |
Jeremy Gebben | 84d75d0 | 2012-03-01 14:47:45 -0700 | [diff] [blame] | 213 | void kgsl_timestamp_expired(struct work_struct *work); |
| 214 | |
| 215 | #define KGSL_DEVICE_COMMON_INIT(_dev) \ |
| 216 | .hwaccess_gate = COMPLETION_INITIALIZER((_dev).hwaccess_gate),\ |
| 217 | .suspend_gate = COMPLETION_INITIALIZER((_dev).suspend_gate),\ |
Tarun Karra | d20d71a | 2013-01-25 15:38:57 -0800 | [diff] [blame] | 218 | .ft_gate = COMPLETION_INITIALIZER((_dev).ft_gate),\ |
Jeremy Gebben | 84d75d0 | 2012-03-01 14:47:45 -0700 | [diff] [blame] | 219 | .ts_notifier_list = ATOMIC_NOTIFIER_INIT((_dev).ts_notifier_list),\ |
| 220 | .idle_check_ws = __WORK_INITIALIZER((_dev).idle_check_ws,\ |
| 221 | kgsl_idle_check),\ |
| 222 | .ts_expired_ws = __WORK_INITIALIZER((_dev).ts_expired_ws,\ |
| 223 | kgsl_timestamp_expired),\ |
| 224 | .context_idr = IDR_INIT((_dev).context_idr),\ |
| 225 | .events = LIST_HEAD_INIT((_dev).events),\ |
| 226 | .wait_queue = __WAIT_QUEUE_HEAD_INITIALIZER((_dev).wait_queue),\ |
| 227 | .mutex = __MUTEX_INITIALIZER((_dev).mutex),\ |
| 228 | .state = KGSL_STATE_INIT,\ |
| 229 | .ver_major = DRIVER_VERSION_MAJOR,\ |
Carter Cooper | 12481fd | 2012-06-05 11:18:34 -0600 | [diff] [blame] | 230 | .ver_minor = DRIVER_VERSION_MINOR |
Jeremy Gebben | 84d75d0 | 2012-03-01 14:47:45 -0700 | [diff] [blame] | 231 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 232 | struct kgsl_context { |
Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 233 | struct kref refcount; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 234 | uint32_t id; |
| 235 | |
| 236 | /* Pointer to the owning device instance */ |
| 237 | struct kgsl_device_private *dev_priv; |
| 238 | |
| 239 | /* Pointer to the device specific context information */ |
| 240 | void *devctxt; |
Shubhraprakash Das | 2dfe5dd | 2012-02-10 13:49:53 -0700 | [diff] [blame] | 241 | /* |
| 242 | * Status indicating whether a gpu reset occurred and whether this |
| 243 | * context was responsible for causing it |
| 244 | */ |
| 245 | unsigned int reset_status; |
Rajeev Kulkarni | 46ee109 | 2012-12-14 14:47:55 -0800 | [diff] [blame] | 246 | /* Flag indicating if we tried to wait for bad timestamp for this ctx */ |
| 247 | bool wait_on_invalid_ts; |
Jeff Boody | fe6c39c | 2012-08-09 13:54:50 -0600 | [diff] [blame] | 248 | /* |
| 249 | * Timeline used to create fences that can be signaled when a |
| 250 | * sync_pt timestamp expires. |
| 251 | */ |
| 252 | struct sync_timeline *timeline; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 253 | }; |
| 254 | |
| 255 | struct kgsl_process_private { |
| 256 | unsigned int refcnt; |
| 257 | pid_t pid; |
| 258 | spinlock_t mem_lock; |
Jordan Crouse | c9559e4 | 2012-04-05 16:55:56 -0600 | [diff] [blame] | 259 | struct rb_root mem_rb; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 260 | struct kgsl_pagetable *pagetable; |
| 261 | struct list_head list; |
Jordan Crouse | 1b897cf | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 262 | struct kobject kobj; |
Jeremy Gebben | ddf9301 | 2012-09-25 10:57:38 -0600 | [diff] [blame] | 263 | struct dentry *debug_root; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 264 | |
| 265 | struct { |
Jordan Crouse | 1b897cf | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 266 | unsigned int cur; |
| 267 | unsigned int max; |
| 268 | } stats[KGSL_MEM_ENTRY_MAX]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 269 | }; |
| 270 | |
| 271 | struct kgsl_device_private { |
| 272 | struct kgsl_device *device; |
| 273 | struct kgsl_process_private *process_priv; |
| 274 | }; |
| 275 | |
| 276 | struct kgsl_power_stats { |
| 277 | s64 total_time; |
| 278 | s64 busy_time; |
| 279 | }; |
| 280 | |
| 281 | struct kgsl_device *kgsl_get_device(int dev_idx); |
| 282 | |
Jordan Crouse | 1b897cf | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 283 | static inline void kgsl_process_add_stats(struct kgsl_process_private *priv, |
| 284 | unsigned int type, size_t size) |
| 285 | { |
| 286 | priv->stats[type].cur += size; |
| 287 | if (priv->stats[type].max < priv->stats[type].cur) |
| 288 | priv->stats[type].max = priv->stats[type].cur; |
| 289 | } |
| 290 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 291 | static inline void kgsl_regread(struct kgsl_device *device, |
| 292 | unsigned int offsetwords, |
| 293 | unsigned int *value) |
| 294 | { |
| 295 | device->ftbl->regread(device, offsetwords, value); |
| 296 | } |
| 297 | |
| 298 | static inline void kgsl_regwrite(struct kgsl_device *device, |
| 299 | unsigned int offsetwords, |
| 300 | unsigned int value) |
| 301 | { |
| 302 | device->ftbl->regwrite(device, offsetwords, value); |
| 303 | } |
| 304 | |
Jordan Crouse | a29a2e0 | 2012-08-14 09:09:23 -0600 | [diff] [blame] | 305 | static inline int kgsl_idle(struct kgsl_device *device) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 306 | { |
Jordan Crouse | a29a2e0 | 2012-08-14 09:09:23 -0600 | [diff] [blame] | 307 | return device->ftbl->idle(device); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Jordan Crouse | d653588 | 2012-06-20 08:22:16 -0600 | [diff] [blame] | 310 | static inline unsigned int kgsl_gpuid(struct kgsl_device *device, |
| 311 | unsigned int *chipid) |
Jordan Crouse | a0758f2 | 2011-12-07 11:19:22 -0700 | [diff] [blame] | 312 | { |
Jordan Crouse | d653588 | 2012-06-20 08:22:16 -0600 | [diff] [blame] | 313 | return device->ftbl->gpuid(device, chipid); |
Jordan Crouse | a0758f2 | 2011-12-07 11:19:22 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Jeremy Gebben | 731dac5 | 2012-05-10 11:13:42 -0600 | [diff] [blame] | 316 | static inline unsigned int kgsl_readtimestamp(struct kgsl_device *device, |
| 317 | struct kgsl_context *context, |
| 318 | enum kgsl_timestamp_type type) |
| 319 | { |
| 320 | return device->ftbl->readtimestamp(device, context, type); |
| 321 | } |
| 322 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 323 | static inline int kgsl_create_device_sysfs_files(struct device *root, |
| 324 | const struct device_attribute **list) |
| 325 | { |
| 326 | int ret = 0, i; |
| 327 | for (i = 0; list[i] != NULL; i++) |
| 328 | ret |= device_create_file(root, list[i]); |
| 329 | return ret; |
| 330 | } |
| 331 | |
| 332 | static inline void kgsl_remove_device_sysfs_files(struct device *root, |
| 333 | const struct device_attribute **list) |
| 334 | { |
| 335 | int i; |
| 336 | for (i = 0; list[i] != NULL; i++) |
| 337 | device_remove_file(root, list[i]); |
| 338 | } |
| 339 | |
| 340 | static inline struct kgsl_mmu * |
| 341 | kgsl_get_mmu(struct kgsl_device *device) |
| 342 | { |
| 343 | return (struct kgsl_mmu *) (device ? &device->mmu : NULL); |
| 344 | } |
| 345 | |
| 346 | static inline struct kgsl_device *kgsl_device_from_dev(struct device *dev) |
| 347 | { |
| 348 | int i; |
| 349 | |
| 350 | for (i = 0; i < KGSL_DEVICE_MAX; i++) { |
| 351 | if (kgsl_driver.devp[i] && kgsl_driver.devp[i]->dev == dev) |
| 352 | return kgsl_driver.devp[i]; |
| 353 | } |
| 354 | |
| 355 | return NULL; |
| 356 | } |
| 357 | |
| 358 | static inline int kgsl_create_device_workqueue(struct kgsl_device *device) |
| 359 | { |
Steve Muckle | 3e042df | 2011-11-18 11:25:04 -0800 | [diff] [blame] | 360 | device->work_queue = create_singlethread_workqueue(device->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 361 | if (!device->work_queue) { |
Steve Muckle | 3e042df | 2011-11-18 11:25:04 -0800 | [diff] [blame] | 362 | KGSL_DRV_ERR(device, |
| 363 | "create_singlethread_workqueue(%s) failed\n", |
| 364 | device->name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 365 | return -EINVAL; |
| 366 | } |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | static inline struct kgsl_context * |
| 371 | kgsl_find_context(struct kgsl_device_private *dev_priv, uint32_t id) |
| 372 | { |
| 373 | struct kgsl_context *ctxt = |
| 374 | idr_find(&dev_priv->device->context_idr, id); |
| 375 | |
| 376 | /* Make sure that the context belongs to the current instance so |
| 377 | that other processes can't guess context IDs and mess things up */ |
| 378 | |
| 379 | return (ctxt && ctxt->dev_priv == dev_priv) ? ctxt : NULL; |
| 380 | } |
| 381 | |
Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 382 | int kgsl_check_timestamp(struct kgsl_device *device, |
| 383 | struct kgsl_context *context, unsigned int timestamp); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 384 | |
| 385 | int kgsl_register_ts_notifier(struct kgsl_device *device, |
| 386 | struct notifier_block *nb); |
| 387 | |
| 388 | int kgsl_unregister_ts_notifier(struct kgsl_device *device, |
| 389 | struct notifier_block *nb); |
| 390 | |
Jordan Crouse | b368e9b | 2012-04-27 14:01:59 -0600 | [diff] [blame] | 391 | int kgsl_device_platform_probe(struct kgsl_device *device); |
| 392 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 393 | void kgsl_device_platform_remove(struct kgsl_device *device); |
| 394 | |
Jeremy Gebben | b50f331 | 2011-12-16 08:58:33 -0700 | [diff] [blame] | 395 | const char *kgsl_pwrstate_to_str(unsigned int state); |
| 396 | |
Jordan Crouse | 156cfbc | 2012-01-24 09:32:04 -0700 | [diff] [blame] | 397 | int kgsl_device_snapshot_init(struct kgsl_device *device); |
| 398 | int kgsl_device_snapshot(struct kgsl_device *device, int hang); |
| 399 | void kgsl_device_snapshot_close(struct kgsl_device *device); |
| 400 | |
Jordan Crouse | d8aa4be | 2012-04-18 09:31:07 -0600 | [diff] [blame] | 401 | static inline struct kgsl_device_platform_data * |
| 402 | kgsl_device_get_drvdata(struct kgsl_device *dev) |
| 403 | { |
| 404 | struct platform_device *pdev = |
| 405 | container_of(dev->parentdev, struct platform_device, dev); |
| 406 | |
| 407 | return pdev->dev.platform_data; |
| 408 | } |
| 409 | |
Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 410 | /** |
| 411 | * kgsl_context_get - Get context reference count |
| 412 | * @context |
| 413 | * |
| 414 | * Asynchronous code that holds a pointer to a context |
| 415 | * must hold a reference count on it. The kgsl device |
| 416 | * mutex must be held while the context reference count |
| 417 | * is changed. |
| 418 | */ |
| 419 | static inline void |
| 420 | kgsl_context_get(struct kgsl_context *context) |
| 421 | { |
| 422 | kref_get(&context->refcount); |
| 423 | } |
| 424 | |
| 425 | void kgsl_context_destroy(struct kref *kref); |
| 426 | |
| 427 | /** |
| 428 | * kgsl_context_put - Release context reference count |
| 429 | * @context |
| 430 | * |
| 431 | */ |
| 432 | static inline void |
| 433 | kgsl_context_put(struct kgsl_context *context) |
| 434 | { |
| 435 | kref_put(&context->refcount, kgsl_context_destroy); |
| 436 | } |
| 437 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 438 | #endif /* __KGSL_DEVICE_H */ |