blob: 10e345aeeeaec361764377377fbeddd2ba1442fd [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2002,2007-2011, Code Aurora Forum. All rights reserved.
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>
17#include <linux/wakelock.h>
18#include <linux/pm_qos_params.h>
19#include <linux/earlysuspend.h>
20
21#include "kgsl.h"
22#include "kgsl_mmu.h"
23#include "kgsl_pwrctrl.h"
24#include "kgsl_log.h"
25#include "kgsl_pwrscale.h"
26
27#define KGSL_TIMEOUT_NONE 0
28#define KGSL_TIMEOUT_DEFAULT 0xFFFFFFFF
29
30#define FIRST_TIMEOUT (HZ / 2)
31
32
33/* KGSL device state is initialized to INIT when platform_probe *
34 * sucessfully initialized the device. Once a device has been opened *
35 * (started) it becomes active. NAP implies that only low latency *
36 * resources (for now clocks on some platforms) are off. SLEEP implies *
37 * that the KGSL module believes a device is idle (has been inactive *
38 * past its timer) and all system resources are released. SUSPEND is *
39 * requested by the kernel and will be enforced upon all open devices. */
40
41#define KGSL_STATE_NONE 0x00000000
42#define KGSL_STATE_INIT 0x00000001
43#define KGSL_STATE_ACTIVE 0x00000002
44#define KGSL_STATE_NAP 0x00000004
45#define KGSL_STATE_SLEEP 0x00000008
46#define KGSL_STATE_SUSPEND 0x00000010
47#define KGSL_STATE_HUNG 0x00000020
48#define KGSL_STATE_DUMP_AND_RECOVER 0x00000040
49
50#define KGSL_GRAPHICS_MEMORY_LOW_WATERMARK 0x1000000
51
52#define KGSL_IS_PAGE_ALIGNED(addr) (!((addr) & (~PAGE_MASK)))
53
54struct kgsl_device;
55struct platform_device;
56struct kgsl_device_private;
57struct kgsl_context;
58struct kgsl_power_stats;
59
60struct kgsl_functable {
61 /* Mandatory functions - these functions must be implemented
62 by the client device. The driver will not check for a NULL
63 pointer before calling the hook.
64 */
65 void (*regread) (struct kgsl_device *device,
66 unsigned int offsetwords, unsigned int *value);
67 void (*regwrite) (struct kgsl_device *device,
68 unsigned int offsetwords, unsigned int value);
69 int (*idle) (struct kgsl_device *device, unsigned int timeout);
70 unsigned int (*isidle) (struct kgsl_device *device);
71 int (*suspend_context) (struct kgsl_device *device);
72 int (*start) (struct kgsl_device *device, unsigned int init_ram);
73 int (*stop) (struct kgsl_device *device);
74 int (*getproperty) (struct kgsl_device *device,
75 enum kgsl_property_type type, void *value,
76 unsigned int sizebytes);
77 int (*waittimestamp) (struct kgsl_device *device,
78 unsigned int timestamp, unsigned int msecs);
79 unsigned int (*readtimestamp) (struct kgsl_device *device,
80 enum kgsl_timestamp_type type);
81 int (*issueibcmds) (struct kgsl_device_private *dev_priv,
82 struct kgsl_context *context, struct kgsl_ibdesc *ibdesc,
83 unsigned int sizedwords, uint32_t *timestamp,
84 unsigned int flags);
85 int (*setup_pt)(struct kgsl_device *device,
86 struct kgsl_pagetable *pagetable);
Jordan Crouse9f739212011-07-28 08:37:57 -060087 void (*cleanup_pt)(struct kgsl_device *device,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070088 struct kgsl_pagetable *pagetable);
89 void (*power_stats)(struct kgsl_device *device,
90 struct kgsl_power_stats *stats);
91 void (*irqctrl)(struct kgsl_device *device, int state);
92 /* Optional functions - these functions are not mandatory. The
93 driver will check that the function pointer is not NULL before
94 calling the hook */
95 void (*setstate) (struct kgsl_device *device, uint32_t flags);
96 int (*drawctxt_create) (struct kgsl_device *device,
97 struct kgsl_pagetable *pagetable, struct kgsl_context *context,
98 uint32_t flags);
99 void (*drawctxt_destroy) (struct kgsl_device *device,
100 struct kgsl_context *context);
101 long (*ioctl) (struct kgsl_device_private *dev_priv,
102 unsigned int cmd, void *data);
103};
104
105struct kgsl_memregion {
106 unsigned char *mmio_virt_base;
107 unsigned int mmio_phys_base;
108 uint32_t gpu_base;
109 unsigned int sizebytes;
110};
111
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600112/* MH register values */
113struct kgsl_mh {
114 unsigned int mharb;
115 unsigned int mh_intf_cfg1;
116 unsigned int mh_intf_cfg2;
117 uint32_t mpu_base;
118 int mpu_range;
119};
120
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700121struct kgsl_device {
122 struct device *dev;
123 const char *name;
124 unsigned int ver_major;
125 unsigned int ver_minor;
126 uint32_t flags;
127 enum kgsl_deviceid id;
128 struct kgsl_memregion regspace;
129 struct kgsl_memdesc memstore;
130 const char *iomemname;
131
Jeremy Gebben4e8aada2011-07-12 10:07:47 -0600132 struct kgsl_mh mh;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700133 struct kgsl_mmu mmu;
134 struct completion hwaccess_gate;
135 const struct kgsl_functable *ftbl;
136 struct work_struct idle_check_ws;
137 struct timer_list idle_timer;
138 struct kgsl_pwrctrl pwrctrl;
139 int open_count;
140
141 struct atomic_notifier_head ts_notifier_list;
142 struct mutex mutex;
143 uint32_t state;
144 uint32_t requested_state;
145
146 struct list_head memqueue;
147 unsigned int active_cnt;
148 struct completion suspend_gate;
149
150 wait_queue_head_t wait_queue;
151 struct workqueue_struct *work_queue;
152 struct device *parentdev;
153 struct completion recovery_gate;
154 struct dentry *d_debugfs;
155 struct idr context_idr;
156 struct early_suspend display_off;
157
158 /* Logging levels */
159 int cmd_log;
160 int ctxt_log;
161 int drv_log;
162 int mem_log;
163 int pwr_log;
164 struct wake_lock idle_wakelock;
165 struct kgsl_pwrscale pwrscale;
166 struct kobject pwrscale_kobj;
167 struct pm_qos_request_list pm_qos_req_dma;
168};
169
170struct kgsl_context {
171 uint32_t id;
172
173 /* Pointer to the owning device instance */
174 struct kgsl_device_private *dev_priv;
175
176 /* Pointer to the device specific context information */
177 void *devctxt;
178};
179
180struct kgsl_process_private {
181 unsigned int refcnt;
182 pid_t pid;
183 spinlock_t mem_lock;
184 struct list_head mem_list;
185 struct kgsl_pagetable *pagetable;
186 struct list_head list;
187 struct kobject *kobj;
188
189 struct {
190 unsigned int user;
191 unsigned int user_max;
192 unsigned int mapped;
193 unsigned int mapped_max;
194 unsigned int flushes;
195 } stats;
196};
197
198struct kgsl_device_private {
199 struct kgsl_device *device;
200 struct kgsl_process_private *process_priv;
201};
202
203struct kgsl_power_stats {
204 s64 total_time;
205 s64 busy_time;
206};
207
208struct kgsl_device *kgsl_get_device(int dev_idx);
209
210static inline void kgsl_regread(struct kgsl_device *device,
211 unsigned int offsetwords,
212 unsigned int *value)
213{
214 device->ftbl->regread(device, offsetwords, value);
215}
216
217static inline void kgsl_regwrite(struct kgsl_device *device,
218 unsigned int offsetwords,
219 unsigned int value)
220{
221 device->ftbl->regwrite(device, offsetwords, value);
222}
223
224static inline int kgsl_idle(struct kgsl_device *device, unsigned int timeout)
225{
226 return device->ftbl->idle(device, timeout);
227}
228
229static inline int kgsl_create_device_sysfs_files(struct device *root,
230 const struct device_attribute **list)
231{
232 int ret = 0, i;
233 for (i = 0; list[i] != NULL; i++)
234 ret |= device_create_file(root, list[i]);
235 return ret;
236}
237
238static inline void kgsl_remove_device_sysfs_files(struct device *root,
239 const struct device_attribute **list)
240{
241 int i;
242 for (i = 0; list[i] != NULL; i++)
243 device_remove_file(root, list[i]);
244}
245
246static inline struct kgsl_mmu *
247kgsl_get_mmu(struct kgsl_device *device)
248{
249 return (struct kgsl_mmu *) (device ? &device->mmu : NULL);
250}
251
252static inline struct kgsl_device *kgsl_device_from_dev(struct device *dev)
253{
254 int i;
255
256 for (i = 0; i < KGSL_DEVICE_MAX; i++) {
257 if (kgsl_driver.devp[i] && kgsl_driver.devp[i]->dev == dev)
258 return kgsl_driver.devp[i];
259 }
260
261 return NULL;
262}
263
264static inline int kgsl_create_device_workqueue(struct kgsl_device *device)
265{
266 device->work_queue = create_workqueue(device->name);
267 if (!device->work_queue) {
268 KGSL_DRV_ERR(device, "create_workqueue(%s) failed\n",
269 device->name);
270 return -EINVAL;
271 }
272 return 0;
273}
274
275static inline struct kgsl_context *
276kgsl_find_context(struct kgsl_device_private *dev_priv, uint32_t id)
277{
278 struct kgsl_context *ctxt =
279 idr_find(&dev_priv->device->context_idr, id);
280
281 /* Make sure that the context belongs to the current instance so
282 that other processes can't guess context IDs and mess things up */
283
284 return (ctxt && ctxt->dev_priv == dev_priv) ? ctxt : NULL;
285}
286
287int kgsl_check_timestamp(struct kgsl_device *device, unsigned int timestamp);
288
289int kgsl_register_ts_notifier(struct kgsl_device *device,
290 struct notifier_block *nb);
291
292int kgsl_unregister_ts_notifier(struct kgsl_device *device,
293 struct notifier_block *nb);
294
295int kgsl_device_platform_probe(struct kgsl_device *device,
296 irqreturn_t (*dev_isr) (int, void*));
297void kgsl_device_platform_remove(struct kgsl_device *device);
298
299#endif /* __KGSL_DEVICE_H */