blob: 692a9ec3f16915d63c39cc858fabcdebf40fa0ae [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);
87 int (*cleanup_pt)(struct kgsl_device *device,
88 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
112struct kgsl_device {
113 struct device *dev;
114 const char *name;
115 unsigned int ver_major;
116 unsigned int ver_minor;
117 uint32_t flags;
118 enum kgsl_deviceid id;
119 struct kgsl_memregion regspace;
120 struct kgsl_memdesc memstore;
121 const char *iomemname;
122
123 struct kgsl_mmu mmu;
124 struct completion hwaccess_gate;
125 const struct kgsl_functable *ftbl;
126 struct work_struct idle_check_ws;
127 struct timer_list idle_timer;
128 struct kgsl_pwrctrl pwrctrl;
129 int open_count;
130
131 struct atomic_notifier_head ts_notifier_list;
132 struct mutex mutex;
133 uint32_t state;
134 uint32_t requested_state;
135
136 struct list_head memqueue;
137 unsigned int active_cnt;
138 struct completion suspend_gate;
139
140 wait_queue_head_t wait_queue;
141 struct workqueue_struct *work_queue;
142 struct device *parentdev;
143 struct completion recovery_gate;
144 struct dentry *d_debugfs;
145 struct idr context_idr;
146 struct early_suspend display_off;
147
148 /* Logging levels */
149 int cmd_log;
150 int ctxt_log;
151 int drv_log;
152 int mem_log;
153 int pwr_log;
154 struct wake_lock idle_wakelock;
155 struct kgsl_pwrscale pwrscale;
156 struct kobject pwrscale_kobj;
157 struct pm_qos_request_list pm_qos_req_dma;
158};
159
160struct kgsl_context {
161 uint32_t id;
162
163 /* Pointer to the owning device instance */
164 struct kgsl_device_private *dev_priv;
165
166 /* Pointer to the device specific context information */
167 void *devctxt;
168};
169
170struct kgsl_process_private {
171 unsigned int refcnt;
172 pid_t pid;
173 spinlock_t mem_lock;
174 struct list_head mem_list;
175 struct kgsl_pagetable *pagetable;
176 struct list_head list;
177 struct kobject *kobj;
178
179 struct {
180 unsigned int user;
181 unsigned int user_max;
182 unsigned int mapped;
183 unsigned int mapped_max;
184 unsigned int flushes;
185 } stats;
186};
187
188struct kgsl_device_private {
189 struct kgsl_device *device;
190 struct kgsl_process_private *process_priv;
191};
192
193struct kgsl_power_stats {
194 s64 total_time;
195 s64 busy_time;
196};
197
198struct kgsl_device *kgsl_get_device(int dev_idx);
199
200static inline void kgsl_regread(struct kgsl_device *device,
201 unsigned int offsetwords,
202 unsigned int *value)
203{
204 device->ftbl->regread(device, offsetwords, value);
205}
206
207static inline void kgsl_regwrite(struct kgsl_device *device,
208 unsigned int offsetwords,
209 unsigned int value)
210{
211 device->ftbl->regwrite(device, offsetwords, value);
212}
213
214static inline int kgsl_idle(struct kgsl_device *device, unsigned int timeout)
215{
216 return device->ftbl->idle(device, timeout);
217}
218
219static inline int kgsl_create_device_sysfs_files(struct device *root,
220 const struct device_attribute **list)
221{
222 int ret = 0, i;
223 for (i = 0; list[i] != NULL; i++)
224 ret |= device_create_file(root, list[i]);
225 return ret;
226}
227
228static inline void kgsl_remove_device_sysfs_files(struct device *root,
229 const struct device_attribute **list)
230{
231 int i;
232 for (i = 0; list[i] != NULL; i++)
233 device_remove_file(root, list[i]);
234}
235
236static inline struct kgsl_mmu *
237kgsl_get_mmu(struct kgsl_device *device)
238{
239 return (struct kgsl_mmu *) (device ? &device->mmu : NULL);
240}
241
242static inline struct kgsl_device *kgsl_device_from_dev(struct device *dev)
243{
244 int i;
245
246 for (i = 0; i < KGSL_DEVICE_MAX; i++) {
247 if (kgsl_driver.devp[i] && kgsl_driver.devp[i]->dev == dev)
248 return kgsl_driver.devp[i];
249 }
250
251 return NULL;
252}
253
254static inline int kgsl_create_device_workqueue(struct kgsl_device *device)
255{
256 device->work_queue = create_workqueue(device->name);
257 if (!device->work_queue) {
258 KGSL_DRV_ERR(device, "create_workqueue(%s) failed\n",
259 device->name);
260 return -EINVAL;
261 }
262 return 0;
263}
264
265static inline struct kgsl_context *
266kgsl_find_context(struct kgsl_device_private *dev_priv, uint32_t id)
267{
268 struct kgsl_context *ctxt =
269 idr_find(&dev_priv->device->context_idr, id);
270
271 /* Make sure that the context belongs to the current instance so
272 that other processes can't guess context IDs and mess things up */
273
274 return (ctxt && ctxt->dev_priv == dev_priv) ? ctxt : NULL;
275}
276
277int kgsl_check_timestamp(struct kgsl_device *device, unsigned int timestamp);
278
279int kgsl_register_ts_notifier(struct kgsl_device *device,
280 struct notifier_block *nb);
281
282int kgsl_unregister_ts_notifier(struct kgsl_device *device,
283 struct notifier_block *nb);
284
285int kgsl_device_platform_probe(struct kgsl_device *device,
286 irqreturn_t (*dev_isr) (int, void*));
287void kgsl_device_platform_remove(struct kgsl_device *device);
288
289#endif /* __KGSL_DEVICE_H */