| Tarun Karra | f8e5cd2 | 2012-01-09 14:10:09 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2008-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/fb.h> | 
 | 15 | #include <linux/file.h> | 
 | 16 | #include <linux/fs.h> | 
 | 17 | #include <linux/debugfs.h> | 
 | 18 | #include <linux/uaccess.h> | 
 | 19 | #include <linux/interrupt.h> | 
 | 20 | #include <linux/workqueue.h> | 
 | 21 | #include <linux/android_pmem.h> | 
 | 22 | #include <linux/vmalloc.h> | 
 | 23 | #include <linux/pm_runtime.h> | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 24 | #include <linux/genlock.h> | 
| Jordan Crouse | c9559e4 | 2012-04-05 16:55:56 -0600 | [diff] [blame] | 25 | #include <linux/rbtree.h> | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 26 | #include <linux/ashmem.h> | 
 | 27 | #include <linux/major.h> | 
| Mitchel Humpherys | 5304470 | 2012-09-06 10:36:51 -0700 | [diff] [blame] | 28 | #include <linux/msm_ion.h> | 
| Jeremy Gebben | 4204d0f | 2012-03-01 16:06:21 -0700 | [diff] [blame] | 29 | #include <linux/io.h> | 
 | 30 | #include <mach/socinfo.h> | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 31 |  | 
 | 32 | #include "kgsl.h" | 
 | 33 | #include "kgsl_debugfs.h" | 
 | 34 | #include "kgsl_cffdump.h" | 
 | 35 | #include "kgsl_log.h" | 
 | 36 | #include "kgsl_sharedmem.h" | 
 | 37 | #include "kgsl_device.h" | 
| Norman Gee | d7402ff | 2011-10-28 08:51:11 -0600 | [diff] [blame] | 38 | #include "kgsl_trace.h" | 
| Jeff Boody | fe6c39c | 2012-08-09 13:54:50 -0600 | [diff] [blame] | 39 | #include "kgsl_sync.h" | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 40 |  | 
 | 41 | #undef MODULE_PARAM_PREFIX | 
 | 42 | #define MODULE_PARAM_PREFIX "kgsl." | 
 | 43 |  | 
 | 44 | static int kgsl_pagetable_count = KGSL_PAGETABLE_COUNT; | 
| Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 45 | static char *ksgl_mmu_type; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 46 | module_param_named(ptcount, kgsl_pagetable_count, int, 0); | 
 | 47 | MODULE_PARM_DESC(kgsl_pagetable_count, | 
 | 48 | "Minimum number of pagetables for KGSL to allocate at initialization time"); | 
| Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 49 | module_param_named(mmutype, ksgl_mmu_type, charp, 0); | 
 | 50 | MODULE_PARM_DESC(ksgl_mmu_type, | 
 | 51 | "Type of MMU to be used for graphics. Valid values are 'iommu' or 'gpummu' or 'nommu'"); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 52 |  | 
| Jordan Crouse | 8eab35a | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 53 | static struct ion_client *kgsl_ion_client; | 
 | 54 |  | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 55 | /** | 
 | 56 |  * kgsl_add_event - Add a new timstamp event for the KGSL device | 
 | 57 |  * @device - KGSL device for the new event | 
 | 58 |  * @ts - the timestamp to trigger the event on | 
 | 59 |  * @cb - callback function to call when the timestamp expires | 
 | 60 |  * @priv - private data for the specific event type | 
| Jeremy Gebben | fd87f9a | 2012-02-10 07:06:09 -0700 | [diff] [blame] | 61 |  * @owner - driver instance that owns this event | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 62 |  * | 
 | 63 |  * @returns - 0 on success or error code on failure | 
 | 64 |  */ | 
 | 65 |  | 
| Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 66 | int kgsl_add_event(struct kgsl_device *device, u32 id, u32 ts, | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 67 | 	void (*cb)(struct kgsl_device *, void *, u32, u32), void *priv, | 
| Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 68 | 	void *owner) | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 69 | { | 
 | 70 | 	struct kgsl_event *event; | 
 | 71 | 	struct list_head *n; | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 72 | 	unsigned int cur_ts; | 
 | 73 | 	struct kgsl_context *context = NULL; | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 74 |  | 
 | 75 | 	if (cb == NULL) | 
 | 76 | 		return -EINVAL; | 
 | 77 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 78 | 	if (id != KGSL_MEMSTORE_GLOBAL) { | 
 | 79 | 		context = idr_find(&device->context_idr, id); | 
 | 80 | 		if (context == NULL) | 
 | 81 | 			return -EINVAL; | 
 | 82 | 	} | 
| Jeremy Gebben | 731dac5 | 2012-05-10 11:13:42 -0600 | [diff] [blame] | 83 | 	cur_ts = kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_RETIRED); | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 84 |  | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 85 | 	/* Check to see if the requested timestamp has already fired */ | 
 | 86 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 87 | 	if (timestamp_cmp(cur_ts, ts) >= 0) { | 
 | 88 | 		cb(device, priv, id, cur_ts); | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 89 | 		return 0; | 
 | 90 | 	} | 
 | 91 |  | 
 | 92 | 	event = kzalloc(sizeof(*event), GFP_KERNEL); | 
 | 93 | 	if (event == NULL) | 
 | 94 | 		return -ENOMEM; | 
 | 95 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 96 | 	event->context = context; | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 97 | 	event->timestamp = ts; | 
 | 98 | 	event->priv = priv; | 
 | 99 | 	event->func = cb; | 
| Jeremy Gebben | fd87f9a | 2012-02-10 07:06:09 -0700 | [diff] [blame] | 100 | 	event->owner = owner; | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 101 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 102 | 	/* | 
 | 103 | 	 * Add the event in order to the list.  Order is by context id | 
 | 104 | 	 * first and then by timestamp for that context. | 
 | 105 | 	 */ | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 106 |  | 
 | 107 | 	for (n = device->events.next ; n != &device->events; n = n->next) { | 
 | 108 | 		struct kgsl_event *e = | 
 | 109 | 			list_entry(n, struct kgsl_event, list); | 
 | 110 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 111 | 		if (e->context != context) | 
 | 112 | 			continue; | 
 | 113 |  | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 114 | 		if (timestamp_cmp(e->timestamp, ts) > 0) { | 
 | 115 | 			list_add(&event->list, n->prev); | 
 | 116 | 			break; | 
 | 117 | 		} | 
 | 118 | 	} | 
 | 119 |  | 
 | 120 | 	if (n == &device->events) | 
 | 121 | 		list_add_tail(&event->list, &device->events); | 
 | 122 |  | 
| Jeremy Gebben | 6390483 | 2012-02-07 16:10:55 -0700 | [diff] [blame] | 123 | 	queue_work(device->work_queue, &device->ts_expired_ws); | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 124 | 	return 0; | 
 | 125 | } | 
| Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 126 | EXPORT_SYMBOL(kgsl_add_event); | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 127 |  | 
| Jeremy Gebben | fd87f9a | 2012-02-10 07:06:09 -0700 | [diff] [blame] | 128 | /** | 
| Lynus Vaz | f519d2c | 2012-04-25 15:46:08 +0530 | [diff] [blame] | 129 |  * kgsl_cancel_events_ctxt - Cancel all events for a context | 
 | 130 |  * @device - KGSL device for the events to cancel | 
 | 131 |  * @ctxt - context whose events we want to cancel | 
 | 132 |  * | 
 | 133 |  */ | 
 | 134 | static void kgsl_cancel_events_ctxt(struct kgsl_device *device, | 
 | 135 | 	struct kgsl_context *context) | 
 | 136 | { | 
 | 137 | 	struct kgsl_event *event, *event_tmp; | 
 | 138 | 	unsigned int id, cur; | 
 | 139 |  | 
| Jeremy Gebben | 731dac5 | 2012-05-10 11:13:42 -0600 | [diff] [blame] | 140 | 	cur = kgsl_readtimestamp(device, context, KGSL_TIMESTAMP_RETIRED); | 
| Lynus Vaz | f519d2c | 2012-04-25 15:46:08 +0530 | [diff] [blame] | 141 | 	id = context->id; | 
 | 142 |  | 
 | 143 | 	list_for_each_entry_safe(event, event_tmp, &device->events, list) { | 
 | 144 | 		if (event->context != context) | 
 | 145 | 			continue; | 
 | 146 |  | 
 | 147 | 		/* | 
 | 148 | 		 * "cancel" the events by calling their callback. | 
 | 149 | 		 * Currently, events are used for lock and memory | 
 | 150 | 		 * management, so if the process is dying the right | 
 | 151 | 		 * thing to do is release or free. | 
 | 152 | 		 */ | 
 | 153 | 		if (event->func) | 
 | 154 | 			event->func(device, event->priv, id, cur); | 
 | 155 |  | 
 | 156 | 		list_del(&event->list); | 
 | 157 | 		kfree(event); | 
 | 158 | 	} | 
 | 159 | } | 
 | 160 |  | 
 | 161 | /** | 
| Jeremy Gebben | fd87f9a | 2012-02-10 07:06:09 -0700 | [diff] [blame] | 162 |  * kgsl_cancel_events - Cancel all events for a process | 
 | 163 |  * @device - KGSL device for the events to cancel | 
 | 164 |  * @owner - driver instance that owns the events to cancel | 
 | 165 |  * | 
 | 166 |  */ | 
| Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 167 | void kgsl_cancel_events(struct kgsl_device *device, | 
 | 168 | 	void *owner) | 
| Jeremy Gebben | fd87f9a | 2012-02-10 07:06:09 -0700 | [diff] [blame] | 169 | { | 
 | 170 | 	struct kgsl_event *event, *event_tmp; | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 171 | 	unsigned int id, cur; | 
| Jeremy Gebben | fd87f9a | 2012-02-10 07:06:09 -0700 | [diff] [blame] | 172 |  | 
 | 173 | 	list_for_each_entry_safe(event, event_tmp, &device->events, list) { | 
 | 174 | 		if (event->owner != owner) | 
 | 175 | 			continue; | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 176 |  | 
| Jeremy Gebben | 731dac5 | 2012-05-10 11:13:42 -0600 | [diff] [blame] | 177 | 		cur = kgsl_readtimestamp(device, event->context, | 
 | 178 | 					 KGSL_TIMESTAMP_RETIRED); | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 179 |  | 
 | 180 | 		id = event->context ? event->context->id : KGSL_MEMSTORE_GLOBAL; | 
| Jeremy Gebben | fd87f9a | 2012-02-10 07:06:09 -0700 | [diff] [blame] | 181 | 		/* | 
 | 182 | 		 * "cancel" the events by calling their callback. | 
 | 183 | 		 * Currently, events are used for lock and memory | 
 | 184 | 		 * management, so if the process is dying the right | 
 | 185 | 		 * thing to do is release or free. | 
 | 186 | 		 */ | 
 | 187 | 		if (event->func) | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 188 | 			event->func(device, event->priv, id, cur); | 
| Jeremy Gebben | fd87f9a | 2012-02-10 07:06:09 -0700 | [diff] [blame] | 189 |  | 
 | 190 | 		list_del(&event->list); | 
 | 191 | 		kfree(event); | 
 | 192 | 	} | 
 | 193 | } | 
| Shubhraprakash Das | cb06807 | 2012-06-07 17:52:41 -0600 | [diff] [blame] | 194 | EXPORT_SYMBOL(kgsl_cancel_events); | 
| Jeremy Gebben | fd87f9a | 2012-02-10 07:06:09 -0700 | [diff] [blame] | 195 |  | 
| Jordan Crouse | 0fdf3a0 | 2012-03-16 14:53:41 -0600 | [diff] [blame] | 196 | /* kgsl_get_mem_entry - get the mem_entry structure for the specified object | 
| Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame] | 197 |  * @device - Pointer to the device structure | 
| Jordan Crouse | 0fdf3a0 | 2012-03-16 14:53:41 -0600 | [diff] [blame] | 198 |  * @ptbase - the pagetable base of the object | 
 | 199 |  * @gpuaddr - the GPU address of the object | 
 | 200 |  * @size - Size of the region to search | 
 | 201 |  */ | 
 | 202 |  | 
| Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame] | 203 | struct kgsl_mem_entry *kgsl_get_mem_entry(struct kgsl_device *device, | 
 | 204 | 	unsigned int ptbase, unsigned int gpuaddr, unsigned int size) | 
| Jordan Crouse | 0fdf3a0 | 2012-03-16 14:53:41 -0600 | [diff] [blame] | 205 | { | 
 | 206 | 	struct kgsl_process_private *priv; | 
 | 207 | 	struct kgsl_mem_entry *entry; | 
 | 208 |  | 
 | 209 | 	mutex_lock(&kgsl_driver.process_mutex); | 
 | 210 |  | 
 | 211 | 	list_for_each_entry(priv, &kgsl_driver.process_list, list) { | 
| Shubhraprakash Das | 3cf33be | 2012-08-16 22:42:55 -0700 | [diff] [blame] | 212 | 		if (!kgsl_mmu_pt_equal(&device->mmu, priv->pagetable, ptbase)) | 
| Jordan Crouse | 0fdf3a0 | 2012-03-16 14:53:41 -0600 | [diff] [blame] | 213 | 			continue; | 
 | 214 | 		spin_lock(&priv->mem_lock); | 
 | 215 | 		entry = kgsl_sharedmem_find_region(priv, gpuaddr, size); | 
 | 216 |  | 
 | 217 | 		if (entry) { | 
 | 218 | 			spin_unlock(&priv->mem_lock); | 
 | 219 | 			mutex_unlock(&kgsl_driver.process_mutex); | 
 | 220 | 			return entry; | 
 | 221 | 		} | 
 | 222 | 		spin_unlock(&priv->mem_lock); | 
 | 223 | 	} | 
 | 224 | 	mutex_unlock(&kgsl_driver.process_mutex); | 
 | 225 |  | 
 | 226 | 	return NULL; | 
 | 227 | } | 
 | 228 | EXPORT_SYMBOL(kgsl_get_mem_entry); | 
 | 229 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 230 | static inline struct kgsl_mem_entry * | 
 | 231 | kgsl_mem_entry_create(void) | 
 | 232 | { | 
 | 233 | 	struct kgsl_mem_entry *entry = kzalloc(sizeof(*entry), GFP_KERNEL); | 
 | 234 |  | 
 | 235 | 	if (!entry) | 
 | 236 | 		KGSL_CORE_ERR("kzalloc(%d) failed\n", sizeof(*entry)); | 
 | 237 | 	else | 
 | 238 | 		kref_init(&entry->refcount); | 
 | 239 |  | 
 | 240 | 	return entry; | 
 | 241 | } | 
 | 242 |  | 
 | 243 | void | 
 | 244 | kgsl_mem_entry_destroy(struct kref *kref) | 
 | 245 | { | 
 | 246 | 	struct kgsl_mem_entry *entry = container_of(kref, | 
 | 247 | 						    struct kgsl_mem_entry, | 
 | 248 | 						    refcount); | 
| Jordan Crouse | 1b897cf | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 249 |  | 
| Jordan Crouse | 1b897cf | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 250 | 	if (entry->memtype != KGSL_MEM_ENTRY_KERNEL) | 
 | 251 | 		kgsl_driver.stats.mapped -= entry->memdesc.size; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 252 |  | 
| Jordan Crouse | 8eab35a | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 253 | 	/* | 
| Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 254 | 	 * Ion takes care of freeing the sglist for us so | 
 | 255 | 	 * clear the sg before freeing the sharedmem so kgsl_sharedmem_free | 
| Jordan Crouse | 8eab35a | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 256 | 	 * doesn't try to free it again | 
 | 257 | 	 */ | 
 | 258 |  | 
 | 259 | 	if (entry->memtype == KGSL_MEM_ENTRY_ION) { | 
| Jordan Crouse | 8eab35a | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 260 | 		entry->memdesc.sg = NULL; | 
 | 261 | 	} | 
 | 262 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 263 | 	kgsl_sharedmem_free(&entry->memdesc); | 
 | 264 |  | 
| Jordan Crouse | 1b897cf | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 265 | 	switch (entry->memtype) { | 
 | 266 | 	case KGSL_MEM_ENTRY_PMEM: | 
 | 267 | 	case KGSL_MEM_ENTRY_ASHMEM: | 
 | 268 | 		if (entry->priv_data) | 
 | 269 | 			fput(entry->priv_data); | 
 | 270 | 		break; | 
| Jordan Crouse | 8eab35a | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 271 | 	case KGSL_MEM_ENTRY_ION: | 
 | 272 | 		ion_free(kgsl_ion_client, entry->priv_data); | 
 | 273 | 		break; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 274 | 	} | 
 | 275 |  | 
 | 276 | 	kfree(entry); | 
 | 277 | } | 
 | 278 | EXPORT_SYMBOL(kgsl_mem_entry_destroy); | 
 | 279 |  | 
 | 280 | static | 
 | 281 | void kgsl_mem_entry_attach_process(struct kgsl_mem_entry *entry, | 
 | 282 | 				   struct kgsl_process_private *process) | 
 | 283 | { | 
| Jordan Crouse | c9559e4 | 2012-04-05 16:55:56 -0600 | [diff] [blame] | 284 | 	struct rb_node **node; | 
 | 285 | 	struct rb_node *parent = NULL; | 
 | 286 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 287 | 	spin_lock(&process->mem_lock); | 
| Jordan Crouse | c9559e4 | 2012-04-05 16:55:56 -0600 | [diff] [blame] | 288 |  | 
 | 289 | 	node = &process->mem_rb.rb_node; | 
 | 290 |  | 
 | 291 | 	while (*node) { | 
 | 292 | 		struct kgsl_mem_entry *cur; | 
 | 293 |  | 
 | 294 | 		parent = *node; | 
 | 295 | 		cur = rb_entry(parent, struct kgsl_mem_entry, node); | 
 | 296 |  | 
 | 297 | 		if (entry->memdesc.gpuaddr < cur->memdesc.gpuaddr) | 
 | 298 | 			node = &parent->rb_left; | 
 | 299 | 		else | 
 | 300 | 			node = &parent->rb_right; | 
 | 301 | 	} | 
 | 302 |  | 
 | 303 | 	rb_link_node(&entry->node, parent, node); | 
 | 304 | 	rb_insert_color(&entry->node, &process->mem_rb); | 
 | 305 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 306 | 	spin_unlock(&process->mem_lock); | 
 | 307 |  | 
 | 308 | 	entry->priv = process; | 
 | 309 | } | 
 | 310 |  | 
| Jordan Crouse | 0071401 | 2012-03-16 14:53:40 -0600 | [diff] [blame] | 311 | /* Detach a memory entry from a process and unmap it from the MMU */ | 
 | 312 |  | 
 | 313 | static void kgsl_mem_entry_detach_process(struct kgsl_mem_entry *entry) | 
 | 314 | { | 
 | 315 | 	if (entry == NULL) | 
 | 316 | 		return; | 
 | 317 |  | 
 | 318 | 	entry->priv->stats[entry->memtype].cur -= entry->memdesc.size; | 
 | 319 | 	entry->priv = NULL; | 
 | 320 |  | 
 | 321 | 	kgsl_mmu_unmap(entry->memdesc.pagetable, &entry->memdesc); | 
 | 322 |  | 
 | 323 | 	kgsl_mem_entry_put(entry); | 
 | 324 | } | 
 | 325 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 326 | /* Allocate a new context id */ | 
 | 327 |  | 
 | 328 | static struct kgsl_context * | 
 | 329 | kgsl_create_context(struct kgsl_device_private *dev_priv) | 
 | 330 | { | 
 | 331 | 	struct kgsl_context *context; | 
 | 332 | 	int ret, id; | 
 | 333 |  | 
 | 334 | 	context = kzalloc(sizeof(*context), GFP_KERNEL); | 
 | 335 |  | 
 | 336 | 	if (context == NULL) | 
 | 337 | 		return NULL; | 
 | 338 |  | 
 | 339 | 	while (1) { | 
 | 340 | 		if (idr_pre_get(&dev_priv->device->context_idr, | 
 | 341 | 				GFP_KERNEL) == 0) { | 
 | 342 | 			kfree(context); | 
 | 343 | 			return NULL; | 
 | 344 | 		} | 
 | 345 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 346 | 		ret = idr_get_new_above(&dev_priv->device->context_idr, | 
 | 347 | 				  context, 1, &id); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 348 |  | 
 | 349 | 		if (ret != -EAGAIN) | 
 | 350 | 			break; | 
 | 351 | 	} | 
 | 352 |  | 
 | 353 | 	if (ret) { | 
 | 354 | 		kfree(context); | 
 | 355 | 		return NULL; | 
 | 356 | 	} | 
 | 357 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 358 | 	/* MAX - 1, there is one memdesc in memstore for device info */ | 
 | 359 | 	if (id >= KGSL_MEMSTORE_MAX) { | 
 | 360 | 		KGSL_DRV_ERR(dev_priv->device, "cannot have more than %d " | 
 | 361 | 				"ctxts due to memstore limitation\n", | 
 | 362 | 				KGSL_MEMSTORE_MAX); | 
 | 363 | 		idr_remove(&dev_priv->device->context_idr, id); | 
 | 364 | 		kfree(context); | 
 | 365 | 		return NULL; | 
 | 366 | 	} | 
 | 367 |  | 
| Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 368 | 	kref_init(&context->refcount); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 369 | 	context->id = id; | 
 | 370 | 	context->dev_priv = dev_priv; | 
 | 371 |  | 
| Jeff Boody | fe6c39c | 2012-08-09 13:54:50 -0600 | [diff] [blame] | 372 | 	if (kgsl_sync_timeline_create(context)) { | 
 | 373 | 		idr_remove(&dev_priv->device->context_idr, id); | 
 | 374 | 		kfree(context); | 
 | 375 | 		return NULL; | 
 | 376 | 	} | 
 | 377 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 378 | 	return context; | 
 | 379 | } | 
 | 380 |  | 
| Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 381 | /** | 
 | 382 |  * kgsl_context_detach - Release the "master" context reference | 
 | 383 |  * @context - The context that will be detached | 
 | 384 |  * | 
 | 385 |  * This is called when a context becomes unusable, because userspace | 
 | 386 |  * has requested for it to be destroyed. The context itself may | 
 | 387 |  * exist a bit longer until its reference count goes to zero. | 
 | 388 |  * Other code referencing the context can detect that it has been | 
 | 389 |  * detached because the context id will be set to KGSL_CONTEXT_INVALID. | 
 | 390 |  */ | 
 | 391 | void | 
 | 392 | kgsl_context_detach(struct kgsl_context *context) | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 393 | { | 
 | 394 | 	int id; | 
| Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 395 | 	struct kgsl_device *device; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 396 | 	if (context == NULL) | 
 | 397 | 		return; | 
| Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 398 | 	device = context->dev_priv->device; | 
| Jeremy Gebben | 4a3756c | 2012-05-08 16:51:43 -0600 | [diff] [blame] | 399 | 	trace_kgsl_context_detach(device, context); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 400 | 	id = context->id; | 
| Jeremy Gebben | 1384a6a | 2012-05-17 14:34:17 -0600 | [diff] [blame] | 401 |  | 
| Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 402 | 	if (device->ftbl->drawctxt_destroy) | 
 | 403 | 		device->ftbl->drawctxt_destroy(device, context); | 
 | 404 | 	/*device specific drawctxt_destroy MUST clean up devctxt */ | 
 | 405 | 	BUG_ON(context->devctxt); | 
| Jeremy Gebben | 1384a6a | 2012-05-17 14:34:17 -0600 | [diff] [blame] | 406 | 	/* | 
 | 407 | 	 * Cancel events after the device-specific context is | 
 | 408 | 	 * destroyed, to avoid possibly freeing memory while | 
 | 409 | 	 * it is still in use by the GPU. | 
 | 410 | 	 */ | 
 | 411 | 	kgsl_cancel_events_ctxt(device, context); | 
| Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 412 | 	idr_remove(&device->context_idr, id); | 
 | 413 | 	context->id = KGSL_CONTEXT_INVALID; | 
 | 414 | 	kgsl_context_put(context); | 
 | 415 | } | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 416 |  | 
| Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 417 | void | 
 | 418 | kgsl_context_destroy(struct kref *kref) | 
 | 419 | { | 
 | 420 | 	struct kgsl_context *context = container_of(kref, struct kgsl_context, | 
 | 421 | 						    refcount); | 
| Jeff Boody | fe6c39c | 2012-08-09 13:54:50 -0600 | [diff] [blame] | 422 | 	kgsl_sync_timeline_destroy(context); | 
| Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 423 | 	kfree(context); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 424 | } | 
 | 425 |  | 
| Jeremy Gebben | 84d75d0 | 2012-03-01 14:47:45 -0700 | [diff] [blame] | 426 | void kgsl_timestamp_expired(struct work_struct *work) | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 427 | { | 
| Jordan Crouse | 1bf80aa | 2011-10-12 16:57:47 -0600 | [diff] [blame] | 428 | 	struct kgsl_device *device = container_of(work, struct kgsl_device, | 
 | 429 | 		ts_expired_ws); | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 430 | 	struct kgsl_event *event, *event_tmp; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 431 | 	uint32_t ts_processed; | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 432 | 	unsigned int id; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 433 |  | 
| Jordan Crouse | 1bf80aa | 2011-10-12 16:57:47 -0600 | [diff] [blame] | 434 | 	mutex_lock(&device->mutex); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 435 |  | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 436 | 	/* Process expired events */ | 
 | 437 | 	list_for_each_entry_safe(event, event_tmp, &device->events, list) { | 
| Jeremy Gebben | 731dac5 | 2012-05-10 11:13:42 -0600 | [diff] [blame] | 438 | 		ts_processed = kgsl_readtimestamp(device, event->context, | 
 | 439 | 						  KGSL_TIMESTAMP_RETIRED); | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 440 | 		if (timestamp_cmp(ts_processed, event->timestamp) < 0) | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 441 | 			continue; | 
 | 442 |  | 
 | 443 | 		id = event->context ? event->context->id : KGSL_MEMSTORE_GLOBAL; | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 444 |  | 
 | 445 | 		if (event->func) | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 446 | 			event->func(device, event->priv, id, ts_processed); | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 447 |  | 
 | 448 | 		list_del(&event->list); | 
 | 449 | 		kfree(event); | 
 | 450 | 	} | 
 | 451 |  | 
| Jordan Crouse | 313faf6 | 2012-11-20 15:12:28 -0700 | [diff] [blame] | 452 | 	/* Send the next pending event for each context to the device */ | 
 | 453 | 	if (device->ftbl->next_event) { | 
 | 454 | 		unsigned int id = KGSL_MEMSTORE_GLOBAL; | 
 | 455 |  | 
 | 456 | 		list_for_each_entry(event, &device->events, list) { | 
 | 457 |  | 
 | 458 | 			if (!event->context) | 
 | 459 | 				continue; | 
 | 460 |  | 
 | 461 | 			if (event->context->id != id) { | 
 | 462 | 				device->ftbl->next_event(device, event); | 
 | 463 | 				id = event->context->id; | 
 | 464 | 			} | 
 | 465 | 		} | 
 | 466 | 	} | 
 | 467 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 468 | 	mutex_unlock(&device->mutex); | 
 | 469 | } | 
| Jeremy Gebben | 84d75d0 | 2012-03-01 14:47:45 -0700 | [diff] [blame] | 470 | EXPORT_SYMBOL(kgsl_timestamp_expired); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 471 |  | 
 | 472 | static void kgsl_check_idle_locked(struct kgsl_device *device) | 
 | 473 | { | 
 | 474 | 	if (device->pwrctrl.nap_allowed == true && | 
 | 475 | 	    device->state == KGSL_STATE_ACTIVE && | 
 | 476 | 		device->requested_state == KGSL_STATE_NONE) { | 
| Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 477 | 		kgsl_pwrctrl_request_state(device, KGSL_STATE_NAP); | 
| Suman Tatiraju | 3de11cc | 2012-06-20 10:33:32 -0700 | [diff] [blame] | 478 | 		kgsl_pwrscale_idle(device, 1); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 479 | 		if (kgsl_pwrctrl_sleep(device) != 0) | 
 | 480 | 			mod_timer(&device->idle_timer, | 
 | 481 | 				  jiffies + | 
 | 482 | 				  device->pwrctrl.interval_timeout); | 
 | 483 | 	} | 
 | 484 | } | 
 | 485 |  | 
 | 486 | static void kgsl_check_idle(struct kgsl_device *device) | 
 | 487 | { | 
 | 488 | 	mutex_lock(&device->mutex); | 
 | 489 | 	kgsl_check_idle_locked(device); | 
 | 490 | 	mutex_unlock(&device->mutex); | 
 | 491 | } | 
 | 492 |  | 
 | 493 | struct kgsl_device *kgsl_get_device(int dev_idx) | 
 | 494 | { | 
 | 495 | 	int i; | 
 | 496 | 	struct kgsl_device *ret = NULL; | 
 | 497 |  | 
 | 498 | 	mutex_lock(&kgsl_driver.devlock); | 
 | 499 |  | 
 | 500 | 	for (i = 0; i < KGSL_DEVICE_MAX; i++) { | 
 | 501 | 		if (kgsl_driver.devp[i] && kgsl_driver.devp[i]->id == dev_idx) { | 
 | 502 | 			ret = kgsl_driver.devp[i]; | 
 | 503 | 			break; | 
 | 504 | 		} | 
 | 505 | 	} | 
 | 506 |  | 
 | 507 | 	mutex_unlock(&kgsl_driver.devlock); | 
 | 508 | 	return ret; | 
 | 509 | } | 
 | 510 | EXPORT_SYMBOL(kgsl_get_device); | 
 | 511 |  | 
 | 512 | static struct kgsl_device *kgsl_get_minor(int minor) | 
 | 513 | { | 
 | 514 | 	struct kgsl_device *ret = NULL; | 
 | 515 |  | 
 | 516 | 	if (minor < 0 || minor >= KGSL_DEVICE_MAX) | 
 | 517 | 		return NULL; | 
 | 518 |  | 
 | 519 | 	mutex_lock(&kgsl_driver.devlock); | 
 | 520 | 	ret = kgsl_driver.devp[minor]; | 
 | 521 | 	mutex_unlock(&kgsl_driver.devlock); | 
 | 522 |  | 
 | 523 | 	return ret; | 
 | 524 | } | 
 | 525 |  | 
 | 526 | int kgsl_register_ts_notifier(struct kgsl_device *device, | 
 | 527 | 			      struct notifier_block *nb) | 
 | 528 | { | 
 | 529 | 	BUG_ON(device == NULL); | 
 | 530 | 	return atomic_notifier_chain_register(&device->ts_notifier_list, | 
 | 531 | 					      nb); | 
 | 532 | } | 
 | 533 | EXPORT_SYMBOL(kgsl_register_ts_notifier); | 
 | 534 |  | 
 | 535 | int kgsl_unregister_ts_notifier(struct kgsl_device *device, | 
 | 536 | 				struct notifier_block *nb) | 
 | 537 | { | 
 | 538 | 	BUG_ON(device == NULL); | 
 | 539 | 	return atomic_notifier_chain_unregister(&device->ts_notifier_list, | 
 | 540 | 						nb); | 
 | 541 | } | 
 | 542 | EXPORT_SYMBOL(kgsl_unregister_ts_notifier); | 
 | 543 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 544 | int kgsl_check_timestamp(struct kgsl_device *device, | 
 | 545 | 	struct kgsl_context *context, unsigned int timestamp) | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 546 | { | 
 | 547 | 	unsigned int ts_processed; | 
 | 548 |  | 
| Jeremy Gebben | 731dac5 | 2012-05-10 11:13:42 -0600 | [diff] [blame] | 549 | 	ts_processed = kgsl_readtimestamp(device, context, | 
 | 550 | 					  KGSL_TIMESTAMP_RETIRED); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 551 |  | 
| Jordan Crouse | e6239dd | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 552 | 	return (timestamp_cmp(ts_processed, timestamp) >= 0); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 553 | } | 
 | 554 | EXPORT_SYMBOL(kgsl_check_timestamp); | 
 | 555 |  | 
 | 556 | static int kgsl_suspend_device(struct kgsl_device *device, pm_message_t state) | 
 | 557 | { | 
 | 558 | 	int status = -EINVAL; | 
 | 559 | 	unsigned int nap_allowed_saved; | 
 | 560 | 	struct kgsl_pwrscale_policy *policy_saved; | 
 | 561 |  | 
 | 562 | 	if (!device) | 
 | 563 | 		return -EINVAL; | 
 | 564 |  | 
 | 565 | 	KGSL_PWR_WARN(device, "suspend start\n"); | 
 | 566 |  | 
 | 567 | 	mutex_lock(&device->mutex); | 
 | 568 | 	nap_allowed_saved = device->pwrctrl.nap_allowed; | 
 | 569 | 	device->pwrctrl.nap_allowed = false; | 
 | 570 | 	policy_saved = device->pwrscale.policy; | 
 | 571 | 	device->pwrscale.policy = NULL; | 
| Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 572 | 	kgsl_pwrctrl_request_state(device, KGSL_STATE_SUSPEND); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 573 | 	/* Make sure no user process is waiting for a timestamp * | 
 | 574 | 	 * before supending */ | 
 | 575 | 	if (device->active_cnt != 0) { | 
 | 576 | 		mutex_unlock(&device->mutex); | 
 | 577 | 		wait_for_completion(&device->suspend_gate); | 
 | 578 | 		mutex_lock(&device->mutex); | 
 | 579 | 	} | 
| Suman Tatiraju | 4a32c65 | 2012-02-17 11:59:05 -0800 | [diff] [blame] | 580 | 	/* Don't let the timer wake us during suspended sleep. */ | 
 | 581 | 	del_timer_sync(&device->idle_timer); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 582 | 	switch (device->state) { | 
 | 583 | 		case KGSL_STATE_INIT: | 
 | 584 | 			break; | 
 | 585 | 		case KGSL_STATE_ACTIVE: | 
 | 586 | 			/* Wait for the device to become idle */ | 
| Jordan Crouse | a29a2e0 | 2012-08-14 09:09:23 -0600 | [diff] [blame] | 587 | 			device->ftbl->idle(device); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 588 | 		case KGSL_STATE_NAP: | 
 | 589 | 		case KGSL_STATE_SLEEP: | 
 | 590 | 			/* Get the completion ready to be waited upon. */ | 
 | 591 | 			INIT_COMPLETION(device->hwaccess_gate); | 
 | 592 | 			device->ftbl->suspend_context(device); | 
 | 593 | 			device->ftbl->stop(device); | 
| Suman Tatiraju | 48e7276 | 2012-05-03 11:12:03 -0700 | [diff] [blame] | 594 | 			pm_qos_update_request(&device->pm_qos_req_dma, | 
 | 595 | 						PM_QOS_DEFAULT_VALUE); | 
| Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 596 | 			kgsl_pwrctrl_set_state(device, KGSL_STATE_SUSPEND); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 597 | 			break; | 
| Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 598 | 		case KGSL_STATE_SLUMBER: | 
 | 599 | 			INIT_COMPLETION(device->hwaccess_gate); | 
| Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 600 | 			kgsl_pwrctrl_set_state(device, KGSL_STATE_SUSPEND); | 
| Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 601 | 			break; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 602 | 		default: | 
 | 603 | 			KGSL_PWR_ERR(device, "suspend fail, device %d\n", | 
 | 604 | 					device->id); | 
 | 605 | 			goto end; | 
 | 606 | 	} | 
| Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 607 | 	kgsl_pwrctrl_request_state(device, KGSL_STATE_NONE); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 608 | 	device->pwrctrl.nap_allowed = nap_allowed_saved; | 
 | 609 | 	device->pwrscale.policy = policy_saved; | 
 | 610 | 	status = 0; | 
 | 611 |  | 
 | 612 | end: | 
 | 613 | 	mutex_unlock(&device->mutex); | 
 | 614 | 	KGSL_PWR_WARN(device, "suspend end\n"); | 
 | 615 | 	return status; | 
 | 616 | } | 
 | 617 |  | 
 | 618 | static int kgsl_resume_device(struct kgsl_device *device) | 
 | 619 | { | 
 | 620 | 	int status = -EINVAL; | 
 | 621 |  | 
 | 622 | 	if (!device) | 
 | 623 | 		return -EINVAL; | 
 | 624 |  | 
 | 625 | 	KGSL_PWR_WARN(device, "resume start\n"); | 
 | 626 | 	mutex_lock(&device->mutex); | 
 | 627 | 	if (device->state == KGSL_STATE_SUSPEND) { | 
| Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 628 | 		kgsl_pwrctrl_set_state(device, KGSL_STATE_SLUMBER); | 
| Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 629 | 		status = 0; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 630 | 		complete_all(&device->hwaccess_gate); | 
 | 631 | 	} | 
| Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 632 | 	kgsl_pwrctrl_request_state(device, KGSL_STATE_NONE); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 633 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 634 | 	mutex_unlock(&device->mutex); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 635 | 	KGSL_PWR_WARN(device, "resume end\n"); | 
 | 636 | 	return status; | 
 | 637 | } | 
 | 638 |  | 
 | 639 | static int kgsl_suspend(struct device *dev) | 
 | 640 | { | 
 | 641 |  | 
 | 642 | 	pm_message_t arg = {0}; | 
 | 643 | 	struct kgsl_device *device = dev_get_drvdata(dev); | 
 | 644 | 	return kgsl_suspend_device(device, arg); | 
 | 645 | } | 
 | 646 |  | 
 | 647 | static int kgsl_resume(struct device *dev) | 
 | 648 | { | 
 | 649 | 	struct kgsl_device *device = dev_get_drvdata(dev); | 
 | 650 | 	return kgsl_resume_device(device); | 
 | 651 | } | 
 | 652 |  | 
 | 653 | static int kgsl_runtime_suspend(struct device *dev) | 
 | 654 | { | 
 | 655 | 	return 0; | 
 | 656 | } | 
 | 657 |  | 
 | 658 | static int kgsl_runtime_resume(struct device *dev) | 
 | 659 | { | 
 | 660 | 	return 0; | 
 | 661 | } | 
 | 662 |  | 
 | 663 | const struct dev_pm_ops kgsl_pm_ops = { | 
 | 664 | 	.suspend = kgsl_suspend, | 
 | 665 | 	.resume = kgsl_resume, | 
 | 666 | 	.runtime_suspend = kgsl_runtime_suspend, | 
 | 667 | 	.runtime_resume = kgsl_runtime_resume, | 
 | 668 | }; | 
 | 669 | EXPORT_SYMBOL(kgsl_pm_ops); | 
 | 670 |  | 
 | 671 | void kgsl_early_suspend_driver(struct early_suspend *h) | 
 | 672 | { | 
 | 673 | 	struct kgsl_device *device = container_of(h, | 
 | 674 | 					struct kgsl_device, display_off); | 
| Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 675 | 	KGSL_PWR_WARN(device, "early suspend start\n"); | 
| Ranjhith Kalisamy | 8b63695 | 2011-09-03 14:48:31 +0530 | [diff] [blame] | 676 | 	mutex_lock(&device->mutex); | 
| Lucille Sylvester | 4c889b7 | 2012-08-03 11:25:25 -0600 | [diff] [blame] | 677 | 	device->pwrctrl.restore_slumber = true; | 
| Lucille Sylvester | 344e462 | 2012-01-18 15:53:21 -0700 | [diff] [blame] | 678 | 	kgsl_pwrctrl_request_state(device, KGSL_STATE_SLUMBER); | 
| Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 679 | 	kgsl_pwrctrl_sleep(device); | 
| Ranjhith Kalisamy | 8b63695 | 2011-09-03 14:48:31 +0530 | [diff] [blame] | 680 | 	mutex_unlock(&device->mutex); | 
| Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 681 | 	KGSL_PWR_WARN(device, "early suspend end\n"); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 682 | } | 
 | 683 | EXPORT_SYMBOL(kgsl_early_suspend_driver); | 
 | 684 |  | 
 | 685 | int kgsl_suspend_driver(struct platform_device *pdev, | 
 | 686 | 					pm_message_t state) | 
 | 687 | { | 
 | 688 | 	struct kgsl_device *device = dev_get_drvdata(&pdev->dev); | 
 | 689 | 	return kgsl_suspend_device(device, state); | 
 | 690 | } | 
 | 691 | EXPORT_SYMBOL(kgsl_suspend_driver); | 
 | 692 |  | 
 | 693 | int kgsl_resume_driver(struct platform_device *pdev) | 
 | 694 | { | 
 | 695 | 	struct kgsl_device *device = dev_get_drvdata(&pdev->dev); | 
 | 696 | 	return kgsl_resume_device(device); | 
 | 697 | } | 
 | 698 | EXPORT_SYMBOL(kgsl_resume_driver); | 
 | 699 |  | 
 | 700 | void kgsl_late_resume_driver(struct early_suspend *h) | 
 | 701 | { | 
 | 702 | 	struct kgsl_device *device = container_of(h, | 
 | 703 | 					struct kgsl_device, display_off); | 
| Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 704 | 	KGSL_PWR_WARN(device, "late resume start\n"); | 
| Ranjhith Kalisamy | 8b63695 | 2011-09-03 14:48:31 +0530 | [diff] [blame] | 705 | 	mutex_lock(&device->mutex); | 
| Lucille Sylvester | 4c889b7 | 2012-08-03 11:25:25 -0600 | [diff] [blame] | 706 | 	device->pwrctrl.restore_slumber = false; | 
| Nilesh Shah | 94bdf2f | 2012-05-02 22:42:57 +0530 | [diff] [blame] | 707 | 	if (device->pwrscale.policy == NULL) | 
 | 708 | 		kgsl_pwrctrl_pwrlevel_change(device, KGSL_PWRLEVEL_TURBO); | 
| Suman Tatiraju | 3005cdd | 2012-03-19 14:38:11 -0700 | [diff] [blame] | 709 | 	kgsl_pwrctrl_wake(device); | 
| Ranjhith Kalisamy | 8b63695 | 2011-09-03 14:48:31 +0530 | [diff] [blame] | 710 | 	mutex_unlock(&device->mutex); | 
| Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 711 | 	kgsl_check_idle(device); | 
 | 712 | 	KGSL_PWR_WARN(device, "late resume end\n"); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 713 | } | 
 | 714 | EXPORT_SYMBOL(kgsl_late_resume_driver); | 
 | 715 |  | 
 | 716 | /* file operations */ | 
 | 717 | static struct kgsl_process_private * | 
 | 718 | kgsl_get_process_private(struct kgsl_device_private *cur_dev_priv) | 
 | 719 | { | 
 | 720 | 	struct kgsl_process_private *private; | 
 | 721 |  | 
 | 722 | 	mutex_lock(&kgsl_driver.process_mutex); | 
 | 723 | 	list_for_each_entry(private, &kgsl_driver.process_list, list) { | 
 | 724 | 		if (private->pid == task_tgid_nr(current)) { | 
 | 725 | 			private->refcnt++; | 
 | 726 | 			goto out; | 
 | 727 | 		} | 
 | 728 | 	} | 
 | 729 |  | 
 | 730 | 	/* no existing process private found for this dev_priv, create one */ | 
 | 731 | 	private = kzalloc(sizeof(struct kgsl_process_private), GFP_KERNEL); | 
 | 732 | 	if (private == NULL) { | 
 | 733 | 		KGSL_DRV_ERR(cur_dev_priv->device, "kzalloc(%d) failed\n", | 
 | 734 | 			sizeof(struct kgsl_process_private)); | 
 | 735 | 		goto out; | 
 | 736 | 	} | 
 | 737 |  | 
 | 738 | 	spin_lock_init(&private->mem_lock); | 
 | 739 | 	private->refcnt = 1; | 
 | 740 | 	private->pid = task_tgid_nr(current); | 
| Jordan Crouse | c9559e4 | 2012-04-05 16:55:56 -0600 | [diff] [blame] | 741 | 	private->mem_rb = RB_ROOT; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 742 |  | 
| Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 743 | 	if (kgsl_mmu_enabled()) | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 744 | 	{ | 
 | 745 | 		unsigned long pt_name; | 
 | 746 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 747 | 		pt_name = task_tgid_nr(current); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 748 | 		private->pagetable = kgsl_mmu_getpagetable(pt_name); | 
 | 749 | 		if (private->pagetable == NULL) { | 
 | 750 | 			kfree(private); | 
 | 751 | 			private = NULL; | 
 | 752 | 			goto out; | 
 | 753 | 		} | 
 | 754 | 	} | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 755 |  | 
 | 756 | 	list_add(&private->list, &kgsl_driver.process_list); | 
 | 757 |  | 
 | 758 | 	kgsl_process_init_sysfs(private); | 
| Jeremy Gebben | ddf9301 | 2012-09-25 10:57:38 -0600 | [diff] [blame] | 759 | 	kgsl_process_init_debugfs(private); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 760 |  | 
 | 761 | out: | 
 | 762 | 	mutex_unlock(&kgsl_driver.process_mutex); | 
 | 763 | 	return private; | 
 | 764 | } | 
 | 765 |  | 
 | 766 | static void | 
 | 767 | kgsl_put_process_private(struct kgsl_device *device, | 
 | 768 | 			 struct kgsl_process_private *private) | 
 | 769 | { | 
 | 770 | 	struct kgsl_mem_entry *entry = NULL; | 
| Jordan Crouse | c9559e4 | 2012-04-05 16:55:56 -0600 | [diff] [blame] | 771 | 	struct rb_node *node; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 772 |  | 
 | 773 | 	if (!private) | 
 | 774 | 		return; | 
 | 775 |  | 
 | 776 | 	mutex_lock(&kgsl_driver.process_mutex); | 
 | 777 |  | 
 | 778 | 	if (--private->refcnt) | 
 | 779 | 		goto unlock; | 
 | 780 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 781 | 	kgsl_process_uninit_sysfs(private); | 
| Jeremy Gebben | ddf9301 | 2012-09-25 10:57:38 -0600 | [diff] [blame] | 782 | 	debugfs_remove_recursive(private->debug_root); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 783 |  | 
 | 784 | 	list_del(&private->list); | 
 | 785 |  | 
| Jordan Crouse | c9559e4 | 2012-04-05 16:55:56 -0600 | [diff] [blame] | 786 | 	for (node = rb_first(&private->mem_rb); node; ) { | 
 | 787 | 		entry = rb_entry(node, struct kgsl_mem_entry, node); | 
 | 788 | 		node = rb_next(&entry->node); | 
 | 789 |  | 
 | 790 | 		rb_erase(&entry->node, &private->mem_rb); | 
| Jordan Crouse | 0071401 | 2012-03-16 14:53:40 -0600 | [diff] [blame] | 791 | 		kgsl_mem_entry_detach_process(entry); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 792 | 	} | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 793 | 	kgsl_mmu_putpagetable(private->pagetable); | 
 | 794 | 	kfree(private); | 
 | 795 | unlock: | 
 | 796 | 	mutex_unlock(&kgsl_driver.process_mutex); | 
 | 797 | } | 
 | 798 |  | 
 | 799 | static int kgsl_release(struct inode *inodep, struct file *filep) | 
 | 800 | { | 
 | 801 | 	int result = 0; | 
| Jordan Crouse | 2db0af9 | 2011-08-08 16:05:09 -0600 | [diff] [blame] | 802 | 	struct kgsl_device_private *dev_priv = filep->private_data; | 
 | 803 | 	struct kgsl_process_private *private = dev_priv->process_priv; | 
 | 804 | 	struct kgsl_device *device = dev_priv->device; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 805 | 	struct kgsl_context *context; | 
 | 806 | 	int next = 0; | 
 | 807 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 808 | 	filep->private_data = NULL; | 
 | 809 |  | 
 | 810 | 	mutex_lock(&device->mutex); | 
 | 811 | 	kgsl_check_suspended(device); | 
 | 812 |  | 
 | 813 | 	while (1) { | 
| Jordan Crouse | 2db0af9 | 2011-08-08 16:05:09 -0600 | [diff] [blame] | 814 | 		context = idr_get_next(&device->context_idr, &next); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 815 | 		if (context == NULL) | 
 | 816 | 			break; | 
 | 817 |  | 
| Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 818 | 		if (context->dev_priv == dev_priv) | 
 | 819 | 			kgsl_context_detach(context); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 820 |  | 
 | 821 | 		next = next + 1; | 
 | 822 | 	} | 
| Jeremy Gebben | 1384a6a | 2012-05-17 14:34:17 -0600 | [diff] [blame] | 823 | 	/* | 
 | 824 | 	 * Clean up any to-be-freed entries that belong to this | 
 | 825 | 	 * process and this device. This is done after the context | 
 | 826 | 	 * are destroyed to avoid possibly freeing memory while | 
 | 827 | 	 * it is still in use by the GPU. | 
 | 828 | 	 */ | 
 | 829 | 	kgsl_cancel_events(device, dev_priv); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 830 |  | 
 | 831 | 	device->open_count--; | 
 | 832 | 	if (device->open_count == 0) { | 
 | 833 | 		result = device->ftbl->stop(device); | 
| Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 834 | 		kgsl_pwrctrl_set_state(device, KGSL_STATE_INIT); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 835 | 	} | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 836 |  | 
 | 837 | 	mutex_unlock(&device->mutex); | 
 | 838 | 	kfree(dev_priv); | 
 | 839 |  | 
 | 840 | 	kgsl_put_process_private(device, private); | 
 | 841 |  | 
 | 842 | 	pm_runtime_put(device->parentdev); | 
 | 843 | 	return result; | 
 | 844 | } | 
 | 845 |  | 
 | 846 | static int kgsl_open(struct inode *inodep, struct file *filep) | 
 | 847 | { | 
 | 848 | 	int result; | 
 | 849 | 	struct kgsl_device_private *dev_priv; | 
 | 850 | 	struct kgsl_device *device; | 
 | 851 | 	unsigned int minor = iminor(inodep); | 
 | 852 |  | 
 | 853 | 	device = kgsl_get_minor(minor); | 
 | 854 | 	BUG_ON(device == NULL); | 
 | 855 |  | 
 | 856 | 	if (filep->f_flags & O_EXCL) { | 
 | 857 | 		KGSL_DRV_ERR(device, "O_EXCL not allowed\n"); | 
 | 858 | 		return -EBUSY; | 
 | 859 | 	} | 
 | 860 |  | 
 | 861 | 	result = pm_runtime_get_sync(device->parentdev); | 
 | 862 | 	if (result < 0) { | 
 | 863 | 		KGSL_DRV_ERR(device, | 
 | 864 | 			"Runtime PM: Unable to wake up the device, rc = %d\n", | 
 | 865 | 			result); | 
 | 866 | 		return result; | 
 | 867 | 	} | 
 | 868 | 	result = 0; | 
 | 869 |  | 
 | 870 | 	dev_priv = kzalloc(sizeof(struct kgsl_device_private), GFP_KERNEL); | 
 | 871 | 	if (dev_priv == NULL) { | 
 | 872 | 		KGSL_DRV_ERR(device, "kzalloc failed(%d)\n", | 
 | 873 | 			sizeof(struct kgsl_device_private)); | 
 | 874 | 		result = -ENOMEM; | 
 | 875 | 		goto err_pmruntime; | 
 | 876 | 	} | 
 | 877 |  | 
 | 878 | 	dev_priv->device = device; | 
 | 879 | 	filep->private_data = dev_priv; | 
 | 880 |  | 
 | 881 | 	/* Get file (per process) private struct */ | 
 | 882 | 	dev_priv->process_priv = kgsl_get_process_private(dev_priv); | 
 | 883 | 	if (dev_priv->process_priv ==  NULL) { | 
 | 884 | 		result = -ENOMEM; | 
 | 885 | 		goto err_freedevpriv; | 
 | 886 | 	} | 
 | 887 |  | 
 | 888 | 	mutex_lock(&device->mutex); | 
 | 889 | 	kgsl_check_suspended(device); | 
 | 890 |  | 
 | 891 | 	if (device->open_count == 0) { | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 892 | 		kgsl_sharedmem_set(&device->memstore, 0, 0, | 
 | 893 | 				device->memstore.size); | 
 | 894 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 895 | 		result = device->ftbl->start(device, true); | 
 | 896 |  | 
 | 897 | 		if (result) { | 
 | 898 | 			mutex_unlock(&device->mutex); | 
 | 899 | 			goto err_putprocess; | 
 | 900 | 		} | 
| Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 901 | 		kgsl_pwrctrl_set_state(device, KGSL_STATE_ACTIVE); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 902 | 	} | 
 | 903 | 	device->open_count++; | 
 | 904 | 	mutex_unlock(&device->mutex); | 
 | 905 |  | 
 | 906 | 	KGSL_DRV_INFO(device, "Initialized %s: mmu=%s pagetable_count=%d\n", | 
 | 907 | 		device->name, kgsl_mmu_enabled() ? "on" : "off", | 
 | 908 | 		kgsl_pagetable_count); | 
 | 909 |  | 
 | 910 | 	return result; | 
 | 911 |  | 
 | 912 | err_putprocess: | 
 | 913 | 	kgsl_put_process_private(device, dev_priv->process_priv); | 
 | 914 | err_freedevpriv: | 
 | 915 | 	filep->private_data = NULL; | 
 | 916 | 	kfree(dev_priv); | 
 | 917 | err_pmruntime: | 
 | 918 | 	pm_runtime_put(device->parentdev); | 
 | 919 | 	return result; | 
 | 920 | } | 
 | 921 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 922 | /*call with private->mem_lock locked */ | 
 | 923 | struct kgsl_mem_entry * | 
 | 924 | kgsl_sharedmem_find_region(struct kgsl_process_private *private, | 
| Jordan Crouse | c9559e4 | 2012-04-05 16:55:56 -0600 | [diff] [blame] | 925 | 	unsigned int gpuaddr, size_t size) | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 926 | { | 
| Jordan Crouse | c9559e4 | 2012-04-05 16:55:56 -0600 | [diff] [blame] | 927 | 	struct rb_node *node = private->mem_rb.rb_node; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 928 |  | 
| Jordan Crouse | e22e21d | 2012-07-23 14:34:06 -0600 | [diff] [blame] | 929 | 	if (!kgsl_mmu_gpuaddr_in_range(gpuaddr)) | 
 | 930 | 		return NULL; | 
 | 931 |  | 
| Jordan Crouse | c9559e4 | 2012-04-05 16:55:56 -0600 | [diff] [blame] | 932 | 	while (node != NULL) { | 
 | 933 | 		struct kgsl_mem_entry *entry; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 934 |  | 
| Jordan Crouse | c9559e4 | 2012-04-05 16:55:56 -0600 | [diff] [blame] | 935 | 		entry = rb_entry(node, struct kgsl_mem_entry, node); | 
 | 936 |  | 
 | 937 |  | 
 | 938 | 		if (kgsl_gpuaddr_in_memdesc(&entry->memdesc, gpuaddr, size)) | 
 | 939 | 			return entry; | 
 | 940 |  | 
 | 941 | 		if (gpuaddr < entry->memdesc.gpuaddr) | 
 | 942 | 			node = node->rb_left; | 
 | 943 | 		else if (gpuaddr >= | 
 | 944 | 			(entry->memdesc.gpuaddr + entry->memdesc.size)) | 
 | 945 | 			node = node->rb_right; | 
 | 946 | 		else { | 
 | 947 | 			return NULL; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 948 | 		} | 
 | 949 | 	} | 
 | 950 |  | 
| Jordan Crouse | c9559e4 | 2012-04-05 16:55:56 -0600 | [diff] [blame] | 951 | 	return NULL; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 952 | } | 
 | 953 | EXPORT_SYMBOL(kgsl_sharedmem_find_region); | 
 | 954 |  | 
| Jordan Crouse | c9559e4 | 2012-04-05 16:55:56 -0600 | [diff] [blame] | 955 | /*call with private->mem_lock locked */ | 
 | 956 | static inline struct kgsl_mem_entry * | 
 | 957 | kgsl_sharedmem_find(struct kgsl_process_private *private, unsigned int gpuaddr) | 
 | 958 | { | 
 | 959 | 	return kgsl_sharedmem_find_region(private, gpuaddr, 1); | 
 | 960 | } | 
 | 961 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 962 | /*call all ioctl sub functions with driver locked*/ | 
 | 963 | static long kgsl_ioctl_device_getproperty(struct kgsl_device_private *dev_priv, | 
 | 964 | 					  unsigned int cmd, void *data) | 
 | 965 | { | 
 | 966 | 	int result = 0; | 
 | 967 | 	struct kgsl_device_getproperty *param = data; | 
 | 968 |  | 
 | 969 | 	switch (param->type) { | 
 | 970 | 	case KGSL_PROP_VERSION: | 
 | 971 | 	{ | 
 | 972 | 		struct kgsl_version version; | 
 | 973 | 		if (param->sizebytes != sizeof(version)) { | 
 | 974 | 			result = -EINVAL; | 
 | 975 | 			break; | 
 | 976 | 		} | 
 | 977 |  | 
 | 978 | 		version.drv_major = KGSL_VERSION_MAJOR; | 
 | 979 | 		version.drv_minor = KGSL_VERSION_MINOR; | 
 | 980 | 		version.dev_major = dev_priv->device->ver_major; | 
 | 981 | 		version.dev_minor = dev_priv->device->ver_minor; | 
 | 982 |  | 
 | 983 | 		if (copy_to_user(param->value, &version, sizeof(version))) | 
 | 984 | 			result = -EFAULT; | 
 | 985 |  | 
 | 986 | 		break; | 
 | 987 | 	} | 
| Shubhraprakash Das | 2dfe5dd | 2012-02-10 13:49:53 -0700 | [diff] [blame] | 988 | 	case KGSL_PROP_GPU_RESET_STAT: | 
 | 989 | 	{ | 
 | 990 | 		/* Return reset status of given context and clear it */ | 
 | 991 | 		uint32_t id; | 
 | 992 | 		struct kgsl_context *context; | 
 | 993 |  | 
 | 994 | 		if (param->sizebytes != sizeof(unsigned int)) { | 
 | 995 | 			result = -EINVAL; | 
 | 996 | 			break; | 
 | 997 | 		} | 
 | 998 | 		/* We expect the value passed in to contain the context id */ | 
 | 999 | 		if (copy_from_user(&id, param->value, | 
 | 1000 | 			sizeof(unsigned int))) { | 
 | 1001 | 			result = -EFAULT; | 
 | 1002 | 			break; | 
 | 1003 | 		} | 
 | 1004 | 		context = kgsl_find_context(dev_priv, id); | 
 | 1005 | 		if (!context) { | 
 | 1006 | 			result = -EINVAL; | 
 | 1007 | 			break; | 
 | 1008 | 		} | 
 | 1009 | 		/* | 
 | 1010 | 		 * Copy the reset status to value which also serves as | 
 | 1011 | 		 * the out parameter | 
 | 1012 | 		 */ | 
 | 1013 | 		if (copy_to_user(param->value, &(context->reset_status), | 
 | 1014 | 			sizeof(unsigned int))) { | 
 | 1015 | 			result = -EFAULT; | 
 | 1016 | 			break; | 
 | 1017 | 		} | 
 | 1018 | 		/* Clear reset status once its been queried */ | 
 | 1019 | 		context->reset_status = KGSL_CTX_STAT_NO_ERROR; | 
 | 1020 | 		break; | 
 | 1021 | 	} | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1022 | 	default: | 
 | 1023 | 		result = dev_priv->device->ftbl->getproperty( | 
 | 1024 | 					dev_priv->device, param->type, | 
 | 1025 | 					param->value, param->sizebytes); | 
 | 1026 | 	} | 
 | 1027 |  | 
 | 1028 |  | 
 | 1029 | 	return result; | 
 | 1030 | } | 
 | 1031 |  | 
| Jordan Crouse | ed7dd7f | 2012-03-29 13:16:02 -0600 | [diff] [blame] | 1032 | static long kgsl_ioctl_device_setproperty(struct kgsl_device_private *dev_priv, | 
 | 1033 | 					  unsigned int cmd, void *data) | 
 | 1034 | { | 
 | 1035 | 	int result = 0; | 
 | 1036 | 	/* The getproperty struct is reused for setproperty too */ | 
 | 1037 | 	struct kgsl_device_getproperty *param = data; | 
 | 1038 |  | 
 | 1039 | 	if (dev_priv->device->ftbl->setproperty) | 
 | 1040 | 		result = dev_priv->device->ftbl->setproperty( | 
 | 1041 | 			dev_priv->device, param->type, | 
 | 1042 | 			param->value, param->sizebytes); | 
 | 1043 |  | 
 | 1044 | 	return result; | 
 | 1045 | } | 
 | 1046 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1047 | static long _device_waittimestamp(struct kgsl_device_private *dev_priv, | 
 | 1048 | 		struct kgsl_context *context, | 
 | 1049 | 		unsigned int timestamp, | 
 | 1050 | 		unsigned int timeout) | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1051 | { | 
 | 1052 | 	int result = 0; | 
| Jeremy Gebben | 4a3756c | 2012-05-08 16:51:43 -0600 | [diff] [blame] | 1053 | 	struct kgsl_device *device = dev_priv->device; | 
 | 1054 | 	unsigned int context_id = context ? context->id : KGSL_MEMSTORE_GLOBAL; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1055 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1056 | 	/* Set the active count so that suspend doesn't do the wrong thing */ | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1057 |  | 
| Jeremy Gebben | 4a3756c | 2012-05-08 16:51:43 -0600 | [diff] [blame] | 1058 | 	device->active_cnt++; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1059 |  | 
| Jeremy Gebben | 4a3756c | 2012-05-08 16:51:43 -0600 | [diff] [blame] | 1060 | 	trace_kgsl_waittimestamp_entry(device, context_id, | 
 | 1061 | 				       kgsl_readtimestamp(device, context, | 
 | 1062 | 							KGSL_TIMESTAMP_RETIRED), | 
 | 1063 | 				       timestamp, timeout); | 
| Norman Gee | d7402ff | 2011-10-28 08:51:11 -0600 | [diff] [blame] | 1064 |  | 
| Jeremy Gebben | 4a3756c | 2012-05-08 16:51:43 -0600 | [diff] [blame] | 1065 | 	result = device->ftbl->waittimestamp(dev_priv->device, | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1066 | 					context, timestamp, timeout); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1067 |  | 
| Jeremy Gebben | 4a3756c | 2012-05-08 16:51:43 -0600 | [diff] [blame] | 1068 | 	trace_kgsl_waittimestamp_exit(device, | 
 | 1069 | 				      kgsl_readtimestamp(device, context, | 
 | 1070 | 							KGSL_TIMESTAMP_RETIRED), | 
 | 1071 | 				      result); | 
| Norman Gee | d7402ff | 2011-10-28 08:51:11 -0600 | [diff] [blame] | 1072 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1073 | 	/* Fire off any pending suspend operations that are in flight */ | 
 | 1074 |  | 
 | 1075 | 	INIT_COMPLETION(dev_priv->device->suspend_gate); | 
 | 1076 | 	dev_priv->device->active_cnt--; | 
 | 1077 | 	complete(&dev_priv->device->suspend_gate); | 
 | 1078 |  | 
 | 1079 | 	return result; | 
 | 1080 | } | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1081 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1082 | static long kgsl_ioctl_device_waittimestamp(struct kgsl_device_private | 
 | 1083 | 						*dev_priv, unsigned int cmd, | 
 | 1084 | 						void *data) | 
 | 1085 | { | 
 | 1086 | 	struct kgsl_device_waittimestamp *param = data; | 
 | 1087 |  | 
| Jeremy Gebben | 4a3756c | 2012-05-08 16:51:43 -0600 | [diff] [blame] | 1088 | 	return _device_waittimestamp(dev_priv, NULL, | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1089 | 			param->timestamp, param->timeout); | 
 | 1090 | } | 
 | 1091 |  | 
 | 1092 | static long kgsl_ioctl_device_waittimestamp_ctxtid(struct kgsl_device_private | 
 | 1093 | 						*dev_priv, unsigned int cmd, | 
 | 1094 | 						void *data) | 
 | 1095 | { | 
 | 1096 | 	struct kgsl_device_waittimestamp_ctxtid *param = data; | 
 | 1097 | 	struct kgsl_context *context; | 
| Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 1098 | 	int result; | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1099 |  | 
 | 1100 | 	context = kgsl_find_context(dev_priv, param->context_id); | 
 | 1101 | 	if (context == NULL) { | 
 | 1102 | 		KGSL_DRV_ERR(dev_priv->device, "invalid context_id %d\n", | 
 | 1103 | 			param->context_id); | 
 | 1104 | 		return -EINVAL; | 
 | 1105 | 	} | 
| Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 1106 | 	/* | 
 | 1107 | 	 * A reference count is needed here, because waittimestamp may | 
 | 1108 | 	 * block with the device mutex unlocked and userspace could | 
 | 1109 | 	 * request for the context to be destroyed during that time. | 
 | 1110 | 	 */ | 
 | 1111 | 	kgsl_context_get(context); | 
 | 1112 | 	result = _device_waittimestamp(dev_priv, context, | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1113 | 			param->timestamp, param->timeout); | 
| Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 1114 | 	kgsl_context_put(context); | 
 | 1115 | 	return result; | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1116 | } | 
 | 1117 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1118 | static long kgsl_ioctl_rb_issueibcmds(struct kgsl_device_private *dev_priv, | 
 | 1119 | 				      unsigned int cmd, void *data) | 
 | 1120 | { | 
 | 1121 | 	int result = 0; | 
 | 1122 | 	struct kgsl_ringbuffer_issueibcmds *param = data; | 
 | 1123 | 	struct kgsl_ibdesc *ibdesc; | 
 | 1124 | 	struct kgsl_context *context; | 
 | 1125 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1126 | 	context = kgsl_find_context(dev_priv, param->drawctxt_id); | 
 | 1127 | 	if (context == NULL) { | 
 | 1128 | 		result = -EINVAL; | 
 | 1129 | 		KGSL_DRV_ERR(dev_priv->device, | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1130 | 			"invalid context_id %d\n", | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1131 | 			param->drawctxt_id); | 
 | 1132 | 		goto done; | 
 | 1133 | 	} | 
 | 1134 |  | 
 | 1135 | 	if (param->flags & KGSL_CONTEXT_SUBMIT_IB_LIST) { | 
 | 1136 | 		KGSL_DRV_INFO(dev_priv->device, | 
 | 1137 | 			"Using IB list mode for ib submission, numibs: %d\n", | 
 | 1138 | 			param->numibs); | 
 | 1139 | 		if (!param->numibs) { | 
 | 1140 | 			KGSL_DRV_ERR(dev_priv->device, | 
 | 1141 | 				"Invalid numibs as parameter: %d\n", | 
 | 1142 | 				 param->numibs); | 
 | 1143 | 			result = -EINVAL; | 
 | 1144 | 			goto done; | 
 | 1145 | 		} | 
 | 1146 |  | 
| Jordan Crouse | 834c859 | 2012-07-24 10:06:35 -0600 | [diff] [blame] | 1147 | 		/* | 
 | 1148 | 		 * Put a reasonable upper limit on the number of IBs that can be | 
 | 1149 | 		 * submitted | 
 | 1150 | 		 */ | 
 | 1151 |  | 
 | 1152 | 		if (param->numibs > 10000) { | 
 | 1153 | 			KGSL_DRV_ERR(dev_priv->device, | 
 | 1154 | 				"Too many IBs submitted. count: %d max 10000\n", | 
 | 1155 | 				param->numibs); | 
 | 1156 | 			result = -EINVAL; | 
 | 1157 | 			goto done; | 
 | 1158 | 		} | 
 | 1159 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1160 | 		ibdesc = kzalloc(sizeof(struct kgsl_ibdesc) * param->numibs, | 
 | 1161 | 					GFP_KERNEL); | 
 | 1162 | 		if (!ibdesc) { | 
 | 1163 | 			KGSL_MEM_ERR(dev_priv->device, | 
 | 1164 | 				"kzalloc(%d) failed\n", | 
 | 1165 | 				sizeof(struct kgsl_ibdesc) * param->numibs); | 
 | 1166 | 			result = -ENOMEM; | 
 | 1167 | 			goto done; | 
 | 1168 | 		} | 
 | 1169 |  | 
 | 1170 | 		if (copy_from_user(ibdesc, (void *)param->ibdesc_addr, | 
 | 1171 | 				sizeof(struct kgsl_ibdesc) * param->numibs)) { | 
 | 1172 | 			result = -EFAULT; | 
 | 1173 | 			KGSL_DRV_ERR(dev_priv->device, | 
 | 1174 | 				"copy_from_user failed\n"); | 
 | 1175 | 			goto free_ibdesc; | 
 | 1176 | 		} | 
 | 1177 | 	} else { | 
 | 1178 | 		KGSL_DRV_INFO(dev_priv->device, | 
 | 1179 | 			"Using single IB submission mode for ib submission\n"); | 
 | 1180 | 		/* If user space driver is still using the old mode of | 
 | 1181 | 		 * submitting single ib then we need to support that as well */ | 
 | 1182 | 		ibdesc = kzalloc(sizeof(struct kgsl_ibdesc), GFP_KERNEL); | 
 | 1183 | 		if (!ibdesc) { | 
 | 1184 | 			KGSL_MEM_ERR(dev_priv->device, | 
 | 1185 | 				"kzalloc(%d) failed\n", | 
 | 1186 | 				sizeof(struct kgsl_ibdesc)); | 
 | 1187 | 			result = -ENOMEM; | 
 | 1188 | 			goto done; | 
 | 1189 | 		} | 
 | 1190 | 		ibdesc[0].gpuaddr = param->ibdesc_addr; | 
 | 1191 | 		ibdesc[0].sizedwords = param->numibs; | 
 | 1192 | 		param->numibs = 1; | 
 | 1193 | 	} | 
 | 1194 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1195 | 	result = dev_priv->device->ftbl->issueibcmds(dev_priv, | 
 | 1196 | 					     context, | 
 | 1197 | 					     ibdesc, | 
 | 1198 | 					     param->numibs, | 
 | 1199 | 					     ¶m->timestamp, | 
 | 1200 | 					     param->flags); | 
 | 1201 |  | 
| Jeremy Gebben | 4a3756c | 2012-05-08 16:51:43 -0600 | [diff] [blame] | 1202 | 	trace_kgsl_issueibcmds(dev_priv->device, param, ibdesc, result); | 
| Wei Zou | c8c0163 | 2012-03-24 17:27:26 -0700 | [diff] [blame] | 1203 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1204 | free_ibdesc: | 
 | 1205 | 	kfree(ibdesc); | 
 | 1206 | done: | 
 | 1207 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1208 | 	return result; | 
 | 1209 | } | 
 | 1210 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1211 | static long _cmdstream_readtimestamp(struct kgsl_device_private *dev_priv, | 
 | 1212 | 		struct kgsl_context *context, unsigned int type, | 
 | 1213 | 		unsigned int *timestamp) | 
 | 1214 | { | 
| Jeremy Gebben | 731dac5 | 2012-05-10 11:13:42 -0600 | [diff] [blame] | 1215 | 	*timestamp = kgsl_readtimestamp(dev_priv->device, context, type); | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1216 |  | 
 | 1217 | 	trace_kgsl_readtimestamp(dev_priv->device, | 
 | 1218 | 			context ? context->id : KGSL_MEMSTORE_GLOBAL, | 
 | 1219 | 			type, *timestamp); | 
 | 1220 |  | 
 | 1221 | 	return 0; | 
 | 1222 | } | 
 | 1223 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1224 | static long kgsl_ioctl_cmdstream_readtimestamp(struct kgsl_device_private | 
 | 1225 | 						*dev_priv, unsigned int cmd, | 
 | 1226 | 						void *data) | 
 | 1227 | { | 
 | 1228 | 	struct kgsl_cmdstream_readtimestamp *param = data; | 
 | 1229 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1230 | 	return _cmdstream_readtimestamp(dev_priv, NULL, | 
 | 1231 | 			param->type, ¶m->timestamp); | 
 | 1232 | } | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1233 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1234 | static long kgsl_ioctl_cmdstream_readtimestamp_ctxtid(struct kgsl_device_private | 
 | 1235 | 						*dev_priv, unsigned int cmd, | 
 | 1236 | 						void *data) | 
 | 1237 | { | 
 | 1238 | 	struct kgsl_cmdstream_readtimestamp_ctxtid *param = data; | 
 | 1239 | 	struct kgsl_context *context; | 
| Norman Gee | d7402ff | 2011-10-28 08:51:11 -0600 | [diff] [blame] | 1240 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1241 | 	context = kgsl_find_context(dev_priv, param->context_id); | 
 | 1242 | 	if (context == NULL) { | 
 | 1243 | 		KGSL_DRV_ERR(dev_priv->device, "invalid context_id %d\n", | 
 | 1244 | 			param->context_id); | 
 | 1245 | 		return -EINVAL; | 
 | 1246 | 	} | 
 | 1247 |  | 
 | 1248 | 	return _cmdstream_readtimestamp(dev_priv, context, | 
 | 1249 | 			param->type, ¶m->timestamp); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1250 | } | 
 | 1251 |  | 
| Jeremy Gebben | c81a3c6 | 2012-02-07 16:10:23 -0700 | [diff] [blame] | 1252 | static void kgsl_freemem_event_cb(struct kgsl_device *device, | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1253 | 	void *priv, u32 id, u32 timestamp) | 
| Jeremy Gebben | c81a3c6 | 2012-02-07 16:10:23 -0700 | [diff] [blame] | 1254 | { | 
 | 1255 | 	struct kgsl_mem_entry *entry = priv; | 
 | 1256 | 	spin_lock(&entry->priv->mem_lock); | 
| Jordan Crouse | c9559e4 | 2012-04-05 16:55:56 -0600 | [diff] [blame] | 1257 | 	rb_erase(&entry->node, &entry->priv->mem_rb); | 
| Jeremy Gebben | c81a3c6 | 2012-02-07 16:10:23 -0700 | [diff] [blame] | 1258 | 	spin_unlock(&entry->priv->mem_lock); | 
| Jeremy Gebben | 4a3756c | 2012-05-08 16:51:43 -0600 | [diff] [blame] | 1259 | 	trace_kgsl_mem_timestamp_free(device, entry, id, timestamp, 0); | 
| Jordan Crouse | 0071401 | 2012-03-16 14:53:40 -0600 | [diff] [blame] | 1260 | 	kgsl_mem_entry_detach_process(entry); | 
| Jeremy Gebben | c81a3c6 | 2012-02-07 16:10:23 -0700 | [diff] [blame] | 1261 | } | 
 | 1262 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1263 | static long _cmdstream_freememontimestamp(struct kgsl_device_private *dev_priv, | 
 | 1264 | 		unsigned int gpuaddr, struct kgsl_context *context, | 
 | 1265 | 		unsigned int timestamp, unsigned int type) | 
 | 1266 | { | 
 | 1267 | 	int result = 0; | 
 | 1268 | 	struct kgsl_mem_entry *entry = NULL; | 
 | 1269 | 	struct kgsl_device *device = dev_priv->device; | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1270 | 	unsigned int context_id = context ? context->id : KGSL_MEMSTORE_GLOBAL; | 
 | 1271 |  | 
 | 1272 | 	spin_lock(&dev_priv->process_priv->mem_lock); | 
 | 1273 | 	entry = kgsl_sharedmem_find(dev_priv->process_priv, gpuaddr); | 
 | 1274 | 	spin_unlock(&dev_priv->process_priv->mem_lock); | 
 | 1275 |  | 
| Jeremy Gebben | 4a3756c | 2012-05-08 16:51:43 -0600 | [diff] [blame] | 1276 | 	if (!entry) { | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1277 | 		KGSL_DRV_ERR(dev_priv->device, | 
| Jeremy Gebben | 4a3756c | 2012-05-08 16:51:43 -0600 | [diff] [blame] | 1278 | 				"invalid gpuaddr %08x\n", gpuaddr); | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1279 | 		result = -EINVAL; | 
| Jeremy Gebben | 4a3756c | 2012-05-08 16:51:43 -0600 | [diff] [blame] | 1280 | 		goto done; | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1281 | 	} | 
| Jeremy Gebben | 4a3756c | 2012-05-08 16:51:43 -0600 | [diff] [blame] | 1282 | 	trace_kgsl_mem_timestamp_queue(device, entry, context_id, | 
 | 1283 | 				       kgsl_readtimestamp(device, context, | 
 | 1284 | 						  KGSL_TIMESTAMP_RETIRED), | 
 | 1285 | 				       timestamp); | 
 | 1286 | 	result = kgsl_add_event(dev_priv->device, context_id, timestamp, | 
 | 1287 | 				kgsl_freemem_event_cb, entry, dev_priv); | 
 | 1288 | done: | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1289 | 	return result; | 
 | 1290 | } | 
 | 1291 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1292 | static long kgsl_ioctl_cmdstream_freememontimestamp(struct kgsl_device_private | 
 | 1293 | 						    *dev_priv, unsigned int cmd, | 
 | 1294 | 						    void *data) | 
 | 1295 | { | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1296 | 	struct kgsl_cmdstream_freememontimestamp *param = data; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1297 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1298 | 	return _cmdstream_freememontimestamp(dev_priv, param->gpuaddr, | 
 | 1299 | 			NULL, param->timestamp, param->type); | 
 | 1300 | } | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1301 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1302 | static long kgsl_ioctl_cmdstream_freememontimestamp_ctxtid( | 
 | 1303 | 						struct kgsl_device_private | 
 | 1304 | 						*dev_priv, unsigned int cmd, | 
 | 1305 | 						void *data) | 
 | 1306 | { | 
 | 1307 | 	struct kgsl_cmdstream_freememontimestamp_ctxtid *param = data; | 
 | 1308 | 	struct kgsl_context *context; | 
| Jeremy Gebben | a585927 | 2012-03-01 12:46:28 -0700 | [diff] [blame] | 1309 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1310 | 	context = kgsl_find_context(dev_priv, param->context_id); | 
 | 1311 | 	if (context == NULL) { | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1312 | 		KGSL_DRV_ERR(dev_priv->device, | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1313 | 			"invalid drawctxt context_id %d\n", param->context_id); | 
 | 1314 | 		return -EINVAL; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1315 | 	} | 
 | 1316 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 1317 | 	return _cmdstream_freememontimestamp(dev_priv, param->gpuaddr, | 
 | 1318 | 			context, param->timestamp, param->type); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1319 | } | 
 | 1320 |  | 
 | 1321 | static long kgsl_ioctl_drawctxt_create(struct kgsl_device_private *dev_priv, | 
 | 1322 | 					unsigned int cmd, void *data) | 
 | 1323 | { | 
 | 1324 | 	int result = 0; | 
 | 1325 | 	struct kgsl_drawctxt_create *param = data; | 
 | 1326 | 	struct kgsl_context *context = NULL; | 
 | 1327 |  | 
 | 1328 | 	context = kgsl_create_context(dev_priv); | 
 | 1329 |  | 
 | 1330 | 	if (context == NULL) { | 
 | 1331 | 		result = -ENOMEM; | 
 | 1332 | 		goto done; | 
 | 1333 | 	} | 
 | 1334 |  | 
| Jeremy Gebben | 4a3756c | 2012-05-08 16:51:43 -0600 | [diff] [blame] | 1335 | 	if (dev_priv->device->ftbl->drawctxt_create) { | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1336 | 		result = dev_priv->device->ftbl->drawctxt_create( | 
 | 1337 | 			dev_priv->device, dev_priv->process_priv->pagetable, | 
 | 1338 | 			context, param->flags); | 
| Jeremy Gebben | 4a3756c | 2012-05-08 16:51:43 -0600 | [diff] [blame] | 1339 | 		if (result) | 
 | 1340 | 			goto done; | 
 | 1341 | 	} | 
 | 1342 | 	trace_kgsl_context_create(dev_priv->device, context, param->flags); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1343 | 	param->drawctxt_id = context->id; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1344 | done: | 
 | 1345 | 	if (result && context) | 
| Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 1346 | 		kgsl_context_detach(context); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1347 |  | 
 | 1348 | 	return result; | 
 | 1349 | } | 
 | 1350 |  | 
 | 1351 | static long kgsl_ioctl_drawctxt_destroy(struct kgsl_device_private *dev_priv, | 
 | 1352 | 					unsigned int cmd, void *data) | 
 | 1353 | { | 
 | 1354 | 	int result = 0; | 
 | 1355 | 	struct kgsl_drawctxt_destroy *param = data; | 
 | 1356 | 	struct kgsl_context *context; | 
 | 1357 |  | 
 | 1358 | 	context = kgsl_find_context(dev_priv, param->drawctxt_id); | 
 | 1359 |  | 
 | 1360 | 	if (context == NULL) { | 
 | 1361 | 		result = -EINVAL; | 
 | 1362 | 		goto done; | 
 | 1363 | 	} | 
 | 1364 |  | 
| Jeremy Gebben | 9ad8692 | 2012-05-08 15:33:23 -0600 | [diff] [blame] | 1365 | 	kgsl_context_detach(context); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1366 | done: | 
 | 1367 | 	return result; | 
 | 1368 | } | 
 | 1369 |  | 
 | 1370 | static long kgsl_ioctl_sharedmem_free(struct kgsl_device_private *dev_priv, | 
 | 1371 | 					unsigned int cmd, void *data) | 
 | 1372 | { | 
 | 1373 | 	int result = 0; | 
 | 1374 | 	struct kgsl_sharedmem_free *param = data; | 
 | 1375 | 	struct kgsl_process_private *private = dev_priv->process_priv; | 
 | 1376 | 	struct kgsl_mem_entry *entry = NULL; | 
 | 1377 |  | 
 | 1378 | 	spin_lock(&private->mem_lock); | 
 | 1379 | 	entry = kgsl_sharedmem_find(private, param->gpuaddr); | 
 | 1380 | 	if (entry) | 
| Jordan Crouse | c9559e4 | 2012-04-05 16:55:56 -0600 | [diff] [blame] | 1381 | 		rb_erase(&entry->node, &private->mem_rb); | 
 | 1382 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1383 | 	spin_unlock(&private->mem_lock); | 
 | 1384 |  | 
 | 1385 | 	if (entry) { | 
| Jeremy Gebben | a585927 | 2012-03-01 12:46:28 -0700 | [diff] [blame] | 1386 | 		trace_kgsl_mem_free(entry); | 
| Jordan Crouse | 0071401 | 2012-03-16 14:53:40 -0600 | [diff] [blame] | 1387 | 		kgsl_mem_entry_detach_process(entry); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1388 | 	} else { | 
 | 1389 | 		KGSL_CORE_ERR("invalid gpuaddr %08x\n", param->gpuaddr); | 
 | 1390 | 		result = -EINVAL; | 
 | 1391 | 	} | 
 | 1392 |  | 
 | 1393 | 	return result; | 
 | 1394 | } | 
 | 1395 |  | 
 | 1396 | static struct vm_area_struct *kgsl_get_vma_from_start_addr(unsigned int addr) | 
 | 1397 | { | 
 | 1398 | 	struct vm_area_struct *vma; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1399 |  | 
 | 1400 | 	down_read(¤t->mm->mmap_sem); | 
 | 1401 | 	vma = find_vma(current->mm, addr); | 
 | 1402 | 	up_read(¤t->mm->mmap_sem); | 
| Jordan Crouse | 2c542b6 | 2011-07-26 08:30:20 -0600 | [diff] [blame] | 1403 | 	if (!vma) | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1404 | 		KGSL_CORE_ERR("find_vma(%x) failed\n", addr); | 
| Jordan Crouse | 2c542b6 | 2011-07-26 08:30:20 -0600 | [diff] [blame] | 1405 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1406 | 	return vma; | 
 | 1407 | } | 
 | 1408 |  | 
 | 1409 | static long | 
 | 1410 | kgsl_ioctl_sharedmem_from_vmalloc(struct kgsl_device_private *dev_priv, | 
 | 1411 | 				unsigned int cmd, void *data) | 
 | 1412 | { | 
 | 1413 | 	int result = 0, len = 0; | 
 | 1414 | 	struct kgsl_process_private *private = dev_priv->process_priv; | 
 | 1415 | 	struct kgsl_sharedmem_from_vmalloc *param = data; | 
 | 1416 | 	struct kgsl_mem_entry *entry = NULL; | 
 | 1417 | 	struct vm_area_struct *vma; | 
 | 1418 |  | 
| Harsh Vardhan Dwivedi | a9eb7cb | 2012-03-26 15:21:38 -0600 | [diff] [blame] | 1419 | 	KGSL_DEV_ERR_ONCE(dev_priv->device, "IOCTL_KGSL_SHAREDMEM_FROM_VMALLOC" | 
 | 1420 | 			" is deprecated\n"); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1421 | 	if (!kgsl_mmu_enabled()) | 
 | 1422 | 		return -ENODEV; | 
 | 1423 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1424 | 	if (!param->hostptr) { | 
 | 1425 | 		KGSL_CORE_ERR("invalid hostptr %x\n", param->hostptr); | 
 | 1426 | 		result = -EINVAL; | 
 | 1427 | 		goto error; | 
 | 1428 | 	} | 
 | 1429 |  | 
 | 1430 | 	vma = kgsl_get_vma_from_start_addr(param->hostptr); | 
 | 1431 | 	if (!vma) { | 
 | 1432 | 		result = -EINVAL; | 
 | 1433 | 		goto error; | 
 | 1434 | 	} | 
| Jordan Crouse | 2c542b6 | 2011-07-26 08:30:20 -0600 | [diff] [blame] | 1435 |  | 
 | 1436 | 	/* | 
 | 1437 | 	 * If the user specified a length, use it, otherwise try to | 
 | 1438 | 	 * infer the length if the vma region | 
 | 1439 | 	 */ | 
 | 1440 | 	if (param->gpuaddr != 0) { | 
 | 1441 | 		len = param->gpuaddr; | 
 | 1442 | 	} else { | 
 | 1443 | 		/* | 
 | 1444 | 		 * For this to work, we have to assume the VMA region is only | 
 | 1445 | 		 * for this single allocation.  If it isn't, then bail out | 
 | 1446 | 		 */ | 
 | 1447 | 		if (vma->vm_pgoff || (param->hostptr != vma->vm_start)) { | 
 | 1448 | 			KGSL_CORE_ERR("VMA region does not match hostaddr\n"); | 
 | 1449 | 			result = -EINVAL; | 
 | 1450 | 			goto error; | 
 | 1451 | 		} | 
 | 1452 |  | 
 | 1453 | 		len = vma->vm_end - vma->vm_start; | 
 | 1454 | 	} | 
 | 1455 |  | 
 | 1456 | 	/* Make sure it fits */ | 
 | 1457 | 	if (len == 0 || param->hostptr + len > vma->vm_end) { | 
 | 1458 | 		KGSL_CORE_ERR("Invalid memory allocation length %d\n", len); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1459 | 		result = -EINVAL; | 
 | 1460 | 		goto error; | 
 | 1461 | 	} | 
 | 1462 |  | 
 | 1463 | 	entry = kgsl_mem_entry_create(); | 
 | 1464 | 	if (entry == NULL) { | 
 | 1465 | 		result = -ENOMEM; | 
 | 1466 | 		goto error; | 
 | 1467 | 	} | 
 | 1468 |  | 
| Harsh Vardhan Dwivedi | f99c263 | 2012-03-15 14:17:11 -0600 | [diff] [blame] | 1469 | 	result = kgsl_sharedmem_page_alloc_user(&entry->memdesc, | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1470 | 					     private->pagetable, len, | 
 | 1471 | 					     param->flags); | 
 | 1472 | 	if (result != 0) | 
 | 1473 | 		goto error_free_entry; | 
 | 1474 |  | 
 | 1475 | 	vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); | 
 | 1476 |  | 
| Harsh Vardhan Dwivedi | 8cb835b | 2012-03-29 17:23:11 -0600 | [diff] [blame] | 1477 | 	result = kgsl_sharedmem_map_vma(vma, &entry->memdesc); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1478 | 	if (result) { | 
| Harsh Vardhan Dwivedi | 8cb835b | 2012-03-29 17:23:11 -0600 | [diff] [blame] | 1479 | 		KGSL_CORE_ERR("kgsl_sharedmem_map_vma failed: %d\n", result); | 
| Harsh Vardhan Dwivedi | f99c263 | 2012-03-15 14:17:11 -0600 | [diff] [blame] | 1480 | 		goto error_free_alloc; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1481 | 	} | 
 | 1482 |  | 
 | 1483 | 	param->gpuaddr = entry->memdesc.gpuaddr; | 
 | 1484 |  | 
| Jordan Crouse | 1b897cf | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1485 | 	entry->memtype = KGSL_MEM_ENTRY_KERNEL; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1486 |  | 
 | 1487 | 	kgsl_mem_entry_attach_process(entry, private); | 
 | 1488 |  | 
| Jeremy Gebben | a585927 | 2012-03-01 12:46:28 -0700 | [diff] [blame] | 1489 | 	trace_kgsl_mem_alloc(entry); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1490 | 	/* Process specific statistics */ | 
| Jordan Crouse | 1b897cf | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1491 | 	kgsl_process_add_stats(private, entry->memtype, len); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1492 |  | 
 | 1493 | 	kgsl_check_idle(dev_priv->device); | 
 | 1494 | 	return 0; | 
 | 1495 |  | 
| Harsh Vardhan Dwivedi | f99c263 | 2012-03-15 14:17:11 -0600 | [diff] [blame] | 1496 | error_free_alloc: | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1497 | 	kgsl_sharedmem_free(&entry->memdesc); | 
 | 1498 |  | 
 | 1499 | error_free_entry: | 
 | 1500 | 	kfree(entry); | 
 | 1501 |  | 
 | 1502 | error: | 
 | 1503 | 	kgsl_check_idle(dev_priv->device); | 
 | 1504 | 	return result; | 
 | 1505 | } | 
 | 1506 |  | 
 | 1507 | static inline int _check_region(unsigned long start, unsigned long size, | 
 | 1508 | 				uint64_t len) | 
 | 1509 | { | 
 | 1510 | 	uint64_t end = ((uint64_t) start) + size; | 
 | 1511 | 	return (end > len); | 
 | 1512 | } | 
 | 1513 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1514 | static int kgsl_get_phys_file(int fd, unsigned long *start, unsigned long *len, | 
 | 1515 | 			      unsigned long *vstart, struct file **filep) | 
 | 1516 | { | 
 | 1517 | 	struct file *fbfile; | 
 | 1518 | 	int ret = 0; | 
 | 1519 | 	dev_t rdev; | 
 | 1520 | 	struct fb_info *info; | 
 | 1521 |  | 
 | 1522 | 	*filep = NULL; | 
| Jordan Crouse | fd97843 | 2011-09-02 14:34:32 -0600 | [diff] [blame] | 1523 | #ifdef CONFIG_ANDROID_PMEM | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1524 | 	if (!get_pmem_file(fd, start, vstart, len, filep)) | 
 | 1525 | 		return 0; | 
| Jordan Crouse | fd97843 | 2011-09-02 14:34:32 -0600 | [diff] [blame] | 1526 | #endif | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1527 |  | 
 | 1528 | 	fbfile = fget(fd); | 
 | 1529 | 	if (fbfile == NULL) { | 
 | 1530 | 		KGSL_CORE_ERR("fget_light failed\n"); | 
 | 1531 | 		return -1; | 
 | 1532 | 	} | 
 | 1533 |  | 
 | 1534 | 	rdev = fbfile->f_dentry->d_inode->i_rdev; | 
 | 1535 | 	info = MAJOR(rdev) == FB_MAJOR ? registered_fb[MINOR(rdev)] : NULL; | 
 | 1536 | 	if (info) { | 
 | 1537 | 		*start = info->fix.smem_start; | 
 | 1538 | 		*len = info->fix.smem_len; | 
 | 1539 | 		*vstart = (unsigned long)__va(info->fix.smem_start); | 
 | 1540 | 		ret = 0; | 
 | 1541 | 	} else { | 
 | 1542 | 		KGSL_CORE_ERR("framebuffer minor %d not found\n", | 
 | 1543 | 			      MINOR(rdev)); | 
 | 1544 | 		ret = -1; | 
 | 1545 | 	} | 
 | 1546 |  | 
 | 1547 | 	fput(fbfile); | 
 | 1548 |  | 
 | 1549 | 	return ret; | 
 | 1550 | } | 
 | 1551 |  | 
 | 1552 | static int kgsl_setup_phys_file(struct kgsl_mem_entry *entry, | 
 | 1553 | 				struct kgsl_pagetable *pagetable, | 
 | 1554 | 				unsigned int fd, unsigned int offset, | 
 | 1555 | 				size_t size) | 
 | 1556 | { | 
 | 1557 | 	int ret; | 
 | 1558 | 	unsigned long phys, virt, len; | 
 | 1559 | 	struct file *filep; | 
 | 1560 |  | 
 | 1561 | 	ret = kgsl_get_phys_file(fd, &phys, &len, &virt, &filep); | 
 | 1562 | 	if (ret) | 
 | 1563 | 		return ret; | 
 | 1564 |  | 
| Ajay Dudani | 62dd83e | 2012-09-11 16:38:13 -0600 | [diff] [blame] | 1565 | 	ret = -ERANGE; | 
 | 1566 |  | 
| Wei Zou | 4061c0b | 2011-07-08 10:24:22 -0700 | [diff] [blame] | 1567 | 	if (phys == 0) { | 
| Ajay Dudani | 62dd83e | 2012-09-11 16:38:13 -0600 | [diff] [blame] | 1568 | 		KGSL_CORE_ERR("kgsl_get_phys_file returned phys=0\n"); | 
| Wei Zou | 4061c0b | 2011-07-08 10:24:22 -0700 | [diff] [blame] | 1569 | 		goto err; | 
 | 1570 | 	} | 
 | 1571 |  | 
| Ajay Dudani | 62dd83e | 2012-09-11 16:38:13 -0600 | [diff] [blame] | 1572 | 	/* Make sure the length of the region, the offset and the desired | 
 | 1573 | 	 * size are all page aligned or bail | 
 | 1574 | 	 */ | 
 | 1575 | 	if ((len & ~PAGE_MASK) || | 
 | 1576 | 		(offset & ~PAGE_MASK) || | 
 | 1577 | 		(size & ~PAGE_MASK)) { | 
 | 1578 | 		KGSL_CORE_ERR("length %lu, offset %u or size %u " | 
 | 1579 | 				"is not page aligned\n", | 
 | 1580 | 				len, offset, size); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1581 | 		goto err; | 
 | 1582 | 	} | 
 | 1583 |  | 
| Ajay Dudani | 62dd83e | 2012-09-11 16:38:13 -0600 | [diff] [blame] | 1584 | 	/* The size or offset can never be greater than the PMEM length */ | 
 | 1585 | 	if (offset >= len || size > len) { | 
 | 1586 | 		KGSL_CORE_ERR("offset %u or size %u " | 
 | 1587 | 				"exceeds pmem length %lu\n", | 
 | 1588 | 				offset, size, len); | 
 | 1589 | 		goto err; | 
 | 1590 | 	} | 
 | 1591 |  | 
 | 1592 | 	/* If size is 0, then adjust it to default to the size of the region | 
 | 1593 | 	 * minus the offset.  If size isn't zero, then make sure that it will | 
 | 1594 | 	 * fit inside of the region. | 
 | 1595 | 	 */ | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1596 | 	if (size == 0) | 
| Ajay Dudani | 62dd83e | 2012-09-11 16:38:13 -0600 | [diff] [blame] | 1597 | 		size = len - offset; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1598 |  | 
| Ajay Dudani | 62dd83e | 2012-09-11 16:38:13 -0600 | [diff] [blame] | 1599 | 	else if (_check_region(offset, size, len)) | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1600 | 		goto err; | 
 | 1601 |  | 
| Jordan Crouse | 1b897cf | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1602 | 	entry->priv_data = filep; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1603 |  | 
 | 1604 | 	entry->memdesc.pagetable = pagetable; | 
 | 1605 | 	entry->memdesc.size = size; | 
| Ajay Dudani | 62dd83e | 2012-09-11 16:38:13 -0600 | [diff] [blame] | 1606 | 	entry->memdesc.physaddr = phys + offset; | 
 | 1607 | 	entry->memdesc.hostptr = (void *) (virt + offset); | 
| Jordan Crouse | d17e9aa | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1608 |  | 
| Ajay Dudani | 62dd83e | 2012-09-11 16:38:13 -0600 | [diff] [blame] | 1609 | 	ret = memdesc_sg_phys(&entry->memdesc, phys + offset, size); | 
| Jordan Crouse | d17e9aa | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1610 | 	if (ret) | 
 | 1611 | 		goto err; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1612 |  | 
 | 1613 | 	return 0; | 
 | 1614 | err: | 
| Jordan Crouse | fd97843 | 2011-09-02 14:34:32 -0600 | [diff] [blame] | 1615 | #ifdef CONFIG_ANDROID_PMEM | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1616 | 	put_pmem_file(filep); | 
| Jordan Crouse | fd97843 | 2011-09-02 14:34:32 -0600 | [diff] [blame] | 1617 | #endif | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1618 | 	return ret; | 
 | 1619 | } | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1620 |  | 
| Jordan Crouse | d17e9aa | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1621 | static int memdesc_sg_virt(struct kgsl_memdesc *memdesc, | 
 | 1622 | 	void *addr, int size) | 
 | 1623 | { | 
 | 1624 | 	int i; | 
 | 1625 | 	int sglen = PAGE_ALIGN(size) / PAGE_SIZE; | 
 | 1626 | 	unsigned long paddr = (unsigned long) addr; | 
 | 1627 |  | 
| Jordan Crouse | a652a07 | 2012-04-06 16:26:33 -0600 | [diff] [blame] | 1628 | 	memdesc->sg = kgsl_sg_alloc(sglen); | 
 | 1629 |  | 
| Jordan Crouse | d17e9aa | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1630 | 	if (memdesc->sg == NULL) | 
 | 1631 | 		return -ENOMEM; | 
 | 1632 |  | 
 | 1633 | 	memdesc->sglen = sglen; | 
| Rajeev Kulkarni | 8dfdc336 | 2012-11-22 00:22:32 -0800 | [diff] [blame] | 1634 | 	memdesc->sglen_alloc = sglen; | 
 | 1635 |  | 
| Jordan Crouse | d17e9aa | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1636 | 	sg_init_table(memdesc->sg, sglen); | 
 | 1637 |  | 
 | 1638 | 	spin_lock(¤t->mm->page_table_lock); | 
 | 1639 |  | 
 | 1640 | 	for (i = 0; i < sglen; i++, paddr += PAGE_SIZE) { | 
 | 1641 | 		struct page *page; | 
 | 1642 | 		pmd_t *ppmd; | 
 | 1643 | 		pte_t *ppte; | 
 | 1644 | 		pgd_t *ppgd = pgd_offset(current->mm, paddr); | 
 | 1645 |  | 
 | 1646 | 		if (pgd_none(*ppgd) || pgd_bad(*ppgd)) | 
 | 1647 | 			goto err; | 
 | 1648 |  | 
| Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1649 | 		ppmd = pmd_offset(pud_offset(ppgd, paddr), paddr); | 
| Jordan Crouse | d17e9aa | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1650 | 		if (pmd_none(*ppmd) || pmd_bad(*ppmd)) | 
 | 1651 | 			goto err; | 
 | 1652 |  | 
 | 1653 | 		ppte = pte_offset_map(ppmd, paddr); | 
 | 1654 | 		if (ppte == NULL) | 
 | 1655 | 			goto err; | 
 | 1656 |  | 
 | 1657 | 		page = pfn_to_page(pte_pfn(*ppte)); | 
 | 1658 | 		if (!page) | 
 | 1659 | 			goto err; | 
 | 1660 |  | 
 | 1661 | 		sg_set_page(&memdesc->sg[i], page, PAGE_SIZE, 0); | 
 | 1662 | 		pte_unmap(ppte); | 
 | 1663 | 	} | 
 | 1664 |  | 
 | 1665 | 	spin_unlock(¤t->mm->page_table_lock); | 
 | 1666 |  | 
 | 1667 | 	return 0; | 
 | 1668 |  | 
 | 1669 | err: | 
 | 1670 | 	spin_unlock(¤t->mm->page_table_lock); | 
| Jordan Crouse | a652a07 | 2012-04-06 16:26:33 -0600 | [diff] [blame] | 1671 | 	kgsl_sg_free(memdesc->sg,  sglen); | 
| Jordan Crouse | d17e9aa | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1672 | 	memdesc->sg = NULL; | 
 | 1673 |  | 
 | 1674 | 	return -EINVAL; | 
 | 1675 | } | 
 | 1676 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1677 | static int kgsl_setup_hostptr(struct kgsl_mem_entry *entry, | 
 | 1678 | 			      struct kgsl_pagetable *pagetable, | 
 | 1679 | 			      void *hostptr, unsigned int offset, | 
 | 1680 | 			      size_t size) | 
 | 1681 | { | 
 | 1682 | 	struct vm_area_struct *vma; | 
 | 1683 | 	unsigned int len; | 
 | 1684 |  | 
 | 1685 | 	down_read(¤t->mm->mmap_sem); | 
 | 1686 | 	vma = find_vma(current->mm, (unsigned int) hostptr); | 
 | 1687 | 	up_read(¤t->mm->mmap_sem); | 
 | 1688 |  | 
 | 1689 | 	if (!vma) { | 
 | 1690 | 		KGSL_CORE_ERR("find_vma(%p) failed\n", hostptr); | 
 | 1691 | 		return -EINVAL; | 
 | 1692 | 	} | 
 | 1693 |  | 
 | 1694 | 	/* We don't necessarily start at vma->vm_start */ | 
 | 1695 | 	len = vma->vm_end - (unsigned long) hostptr; | 
 | 1696 |  | 
 | 1697 | 	if (offset >= len) | 
 | 1698 | 		return -EINVAL; | 
 | 1699 |  | 
 | 1700 | 	if (!KGSL_IS_PAGE_ALIGNED((unsigned long) hostptr) || | 
 | 1701 | 	    !KGSL_IS_PAGE_ALIGNED(len)) { | 
 | 1702 | 		KGSL_CORE_ERR("user address len(%u)" | 
 | 1703 | 			      "and start(%p) must be page" | 
 | 1704 | 			      "aligned\n", len, hostptr); | 
 | 1705 | 		return -EINVAL; | 
 | 1706 | 	} | 
 | 1707 |  | 
 | 1708 | 	if (size == 0) | 
 | 1709 | 		size = len; | 
 | 1710 |  | 
 | 1711 | 	/* Adjust the size of the region to account for the offset */ | 
 | 1712 | 	size += offset & ~PAGE_MASK; | 
 | 1713 |  | 
 | 1714 | 	size = ALIGN(size, PAGE_SIZE); | 
 | 1715 |  | 
 | 1716 | 	if (_check_region(offset & PAGE_MASK, size, len)) { | 
 | 1717 | 		KGSL_CORE_ERR("Offset (%ld) + size (%d) is larger" | 
 | 1718 | 			      "than region length %d\n", | 
 | 1719 | 			      offset & PAGE_MASK, size, len); | 
 | 1720 | 		return -EINVAL; | 
 | 1721 | 	} | 
 | 1722 |  | 
 | 1723 | 	entry->memdesc.pagetable = pagetable; | 
 | 1724 | 	entry->memdesc.size = size; | 
 | 1725 | 	entry->memdesc.hostptr = hostptr + (offset & PAGE_MASK); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1726 |  | 
| Jordan Crouse | d17e9aa | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1727 | 	return memdesc_sg_virt(&entry->memdesc, | 
 | 1728 | 		hostptr + (offset & PAGE_MASK), size); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1729 | } | 
 | 1730 |  | 
 | 1731 | #ifdef CONFIG_ASHMEM | 
 | 1732 | static int kgsl_setup_ashmem(struct kgsl_mem_entry *entry, | 
 | 1733 | 			     struct kgsl_pagetable *pagetable, | 
 | 1734 | 			     int fd, void *hostptr, size_t size) | 
 | 1735 | { | 
 | 1736 | 	int ret; | 
 | 1737 | 	struct vm_area_struct *vma; | 
 | 1738 | 	struct file *filep, *vmfile; | 
 | 1739 | 	unsigned long len; | 
| Jordan Crouse | 2c542b6 | 2011-07-26 08:30:20 -0600 | [diff] [blame] | 1740 | 	unsigned int hostaddr = (unsigned int) hostptr; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1741 |  | 
| Jordan Crouse | 2c542b6 | 2011-07-26 08:30:20 -0600 | [diff] [blame] | 1742 | 	vma = kgsl_get_vma_from_start_addr(hostaddr); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1743 | 	if (vma == NULL) | 
 | 1744 | 		return -EINVAL; | 
 | 1745 |  | 
| Jordan Crouse | 2c542b6 | 2011-07-26 08:30:20 -0600 | [diff] [blame] | 1746 | 	if (vma->vm_pgoff || vma->vm_start != hostaddr) { | 
 | 1747 | 		KGSL_CORE_ERR("Invalid vma region\n"); | 
 | 1748 | 		return -EINVAL; | 
 | 1749 | 	} | 
 | 1750 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1751 | 	len = vma->vm_end - vma->vm_start; | 
 | 1752 |  | 
 | 1753 | 	if (size == 0) | 
 | 1754 | 		size = len; | 
 | 1755 |  | 
 | 1756 | 	if (size != len) { | 
 | 1757 | 		KGSL_CORE_ERR("Invalid size %d for vma region %p\n", | 
 | 1758 | 			      size, hostptr); | 
 | 1759 | 		return -EINVAL; | 
 | 1760 | 	} | 
 | 1761 |  | 
 | 1762 | 	ret = get_ashmem_file(fd, &filep, &vmfile, &len); | 
 | 1763 |  | 
 | 1764 | 	if (ret) { | 
 | 1765 | 		KGSL_CORE_ERR("get_ashmem_file failed\n"); | 
 | 1766 | 		return ret; | 
 | 1767 | 	} | 
 | 1768 |  | 
 | 1769 | 	if (vmfile != vma->vm_file) { | 
 | 1770 | 		KGSL_CORE_ERR("ashmem shmem file does not match vma\n"); | 
 | 1771 | 		ret = -EINVAL; | 
 | 1772 | 		goto err; | 
 | 1773 | 	} | 
 | 1774 |  | 
| Jordan Crouse | 1b897cf | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1775 | 	entry->priv_data = filep; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1776 | 	entry->memdesc.pagetable = pagetable; | 
 | 1777 | 	entry->memdesc.size = ALIGN(size, PAGE_SIZE); | 
 | 1778 | 	entry->memdesc.hostptr = hostptr; | 
| Jordan Crouse | d17e9aa | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1779 |  | 
 | 1780 | 	ret = memdesc_sg_virt(&entry->memdesc, hostptr, size); | 
 | 1781 | 	if (ret) | 
 | 1782 | 		goto err; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1783 |  | 
 | 1784 | 	return 0; | 
 | 1785 |  | 
 | 1786 | err: | 
 | 1787 | 	put_ashmem_file(filep); | 
 | 1788 | 	return ret; | 
 | 1789 | } | 
 | 1790 | #else | 
 | 1791 | static int kgsl_setup_ashmem(struct kgsl_mem_entry *entry, | 
 | 1792 | 			     struct kgsl_pagetable *pagetable, | 
 | 1793 | 			     int fd, void *hostptr, size_t size) | 
 | 1794 | { | 
 | 1795 | 	return -EINVAL; | 
 | 1796 | } | 
 | 1797 | #endif | 
 | 1798 |  | 
| Jordan Crouse | 8eab35a | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1799 | static int kgsl_setup_ion(struct kgsl_mem_entry *entry, | 
 | 1800 | 		struct kgsl_pagetable *pagetable, int fd) | 
 | 1801 | { | 
 | 1802 | 	struct ion_handle *handle; | 
 | 1803 | 	struct scatterlist *s; | 
| Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 1804 | 	struct sg_table *sg_table; | 
| Jordan Crouse | 8eab35a | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1805 |  | 
| Harsh Vardhan Dwivedi | f48af7f | 2012-04-13 12:50:44 -0600 | [diff] [blame] | 1806 | 	if (IS_ERR_OR_NULL(kgsl_ion_client)) | 
 | 1807 | 		return -ENODEV; | 
| Jordan Crouse | 8eab35a | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1808 |  | 
| Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 1809 | 	handle = ion_import_dma_buf(kgsl_ion_client, fd); | 
| Ranjhith Kalisamy | 0d2e14f | 2012-08-14 19:49:39 +0530 | [diff] [blame] | 1810 | 	if (IS_ERR(handle)) | 
| Jordan Crouse | 8eab35a | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1811 | 		return PTR_ERR(handle); | 
| Ranjhith Kalisamy | 0d2e14f | 2012-08-14 19:49:39 +0530 | [diff] [blame] | 1812 | 	else if (!handle) | 
 | 1813 | 		return -EINVAL; | 
| Jordan Crouse | 8eab35a | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1814 |  | 
 | 1815 | 	entry->memtype = KGSL_MEM_ENTRY_ION; | 
 | 1816 | 	entry->priv_data = handle; | 
 | 1817 | 	entry->memdesc.pagetable = pagetable; | 
 | 1818 | 	entry->memdesc.size = 0; | 
 | 1819 |  | 
| Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 1820 | 	sg_table = ion_sg_table(kgsl_ion_client, handle); | 
 | 1821 |  | 
 | 1822 | 	if (IS_ERR_OR_NULL(sg_table)) | 
| Jordan Crouse | 8eab35a | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1823 | 		goto err; | 
 | 1824 |  | 
| Laura Abbott | b14ed96 | 2012-01-30 14:18:08 -0800 | [diff] [blame] | 1825 | 	entry->memdesc.sg = sg_table->sgl; | 
| Jordan Crouse | 8eab35a | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1826 |  | 
 | 1827 | 	/* Calculate the size of the memdesc from the sglist */ | 
 | 1828 |  | 
 | 1829 | 	entry->memdesc.sglen = 0; | 
 | 1830 |  | 
 | 1831 | 	for (s = entry->memdesc.sg; s != NULL; s = sg_next(s)) { | 
 | 1832 | 		entry->memdesc.size += s->length; | 
 | 1833 | 		entry->memdesc.sglen++; | 
 | 1834 | 	} | 
 | 1835 |  | 
 | 1836 | 	return 0; | 
 | 1837 | err: | 
 | 1838 | 	ion_free(kgsl_ion_client, handle); | 
 | 1839 | 	return -ENOMEM; | 
 | 1840 | } | 
 | 1841 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1842 | static long kgsl_ioctl_map_user_mem(struct kgsl_device_private *dev_priv, | 
 | 1843 | 				     unsigned int cmd, void *data) | 
 | 1844 | { | 
 | 1845 | 	int result = -EINVAL; | 
 | 1846 | 	struct kgsl_map_user_mem *param = data; | 
 | 1847 | 	struct kgsl_mem_entry *entry = NULL; | 
 | 1848 | 	struct kgsl_process_private *private = dev_priv->process_priv; | 
| Jason | 848741a | 2011-07-12 10:24:25 -0700 | [diff] [blame] | 1849 | 	enum kgsl_user_mem_type memtype; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1850 |  | 
 | 1851 | 	entry = kgsl_mem_entry_create(); | 
 | 1852 |  | 
 | 1853 | 	if (entry == NULL) | 
 | 1854 | 		return -ENOMEM; | 
 | 1855 |  | 
| Jason | 848741a | 2011-07-12 10:24:25 -0700 | [diff] [blame] | 1856 | 	if (_IOC_SIZE(cmd) == sizeof(struct kgsl_sharedmem_from_pmem)) | 
 | 1857 | 		memtype = KGSL_USER_MEM_TYPE_PMEM; | 
 | 1858 | 	else | 
 | 1859 | 		memtype = param->memtype; | 
 | 1860 |  | 
 | 1861 | 	switch (memtype) { | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1862 | 	case KGSL_USER_MEM_TYPE_PMEM: | 
 | 1863 | 		if (param->fd == 0 || param->len == 0) | 
 | 1864 | 			break; | 
 | 1865 |  | 
 | 1866 | 		result = kgsl_setup_phys_file(entry, private->pagetable, | 
 | 1867 | 					      param->fd, param->offset, | 
 | 1868 | 					      param->len); | 
| Jordan Crouse | 1b897cf | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1869 | 		entry->memtype = KGSL_MEM_ENTRY_PMEM; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1870 | 		break; | 
 | 1871 |  | 
 | 1872 | 	case KGSL_USER_MEM_TYPE_ADDR: | 
| Harsh Vardhan Dwivedi | a9eb7cb | 2012-03-26 15:21:38 -0600 | [diff] [blame] | 1873 | 		KGSL_DEV_ERR_ONCE(dev_priv->device, "User mem type " | 
 | 1874 | 				"KGSL_USER_MEM_TYPE_ADDR is deprecated\n"); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1875 | 		if (!kgsl_mmu_enabled()) { | 
 | 1876 | 			KGSL_DRV_ERR(dev_priv->device, | 
 | 1877 | 				"Cannot map paged memory with the " | 
 | 1878 | 				"MMU disabled\n"); | 
 | 1879 | 			break; | 
 | 1880 | 		} | 
 | 1881 |  | 
 | 1882 | 		if (param->hostptr == 0) | 
 | 1883 | 			break; | 
 | 1884 |  | 
 | 1885 | 		result = kgsl_setup_hostptr(entry, private->pagetable, | 
 | 1886 | 					    (void *) param->hostptr, | 
 | 1887 | 					    param->offset, param->len); | 
| Jordan Crouse | 1b897cf | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1888 | 		entry->memtype = KGSL_MEM_ENTRY_USER; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1889 | 		break; | 
 | 1890 |  | 
 | 1891 | 	case KGSL_USER_MEM_TYPE_ASHMEM: | 
 | 1892 | 		if (!kgsl_mmu_enabled()) { | 
 | 1893 | 			KGSL_DRV_ERR(dev_priv->device, | 
 | 1894 | 				"Cannot map paged memory with the " | 
 | 1895 | 				"MMU disabled\n"); | 
 | 1896 | 			break; | 
 | 1897 | 		} | 
 | 1898 |  | 
 | 1899 | 		if (param->hostptr == 0) | 
 | 1900 | 			break; | 
 | 1901 |  | 
 | 1902 | 		result = kgsl_setup_ashmem(entry, private->pagetable, | 
 | 1903 | 					   param->fd, (void *) param->hostptr, | 
 | 1904 | 					   param->len); | 
| Jordan Crouse | 1b897cf | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1905 |  | 
 | 1906 | 		entry->memtype = KGSL_MEM_ENTRY_ASHMEM; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1907 | 		break; | 
| Jordan Crouse | 8eab35a | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1908 | 	case KGSL_USER_MEM_TYPE_ION: | 
 | 1909 | 		result = kgsl_setup_ion(entry, private->pagetable, | 
 | 1910 | 			param->fd); | 
 | 1911 | 		break; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1912 | 	default: | 
| Jason | 848741a | 2011-07-12 10:24:25 -0700 | [diff] [blame] | 1913 | 		KGSL_CORE_ERR("Invalid memory type: %x\n", memtype); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1914 | 		break; | 
 | 1915 | 	} | 
 | 1916 |  | 
 | 1917 | 	if (result) | 
 | 1918 | 		goto error; | 
 | 1919 |  | 
| Jeremy Gebben | 3e626ff | 2012-09-24 13:05:39 -0600 | [diff] [blame] | 1920 | 	entry->memdesc.priv |= param->flags & KGSL_MEMTYPE_MASK; | 
 | 1921 |  | 
| Rajeev Kulkarni | 8dfdc336 | 2012-11-22 00:22:32 -0800 | [diff] [blame] | 1922 | 	if (entry->memdesc.size >= SZ_1M) | 
 | 1923 | 		entry->memdesc.priv |= ilog2(SZ_1M) << KGSL_MEMALIGN_SHIFT; | 
 | 1924 | 	else if (entry->memdesc.size >= SZ_64K) | 
 | 1925 | 		entry->memdesc.priv |= ilog2(SZ_64K) << KGSL_MEMALIGN_SHIFT; | 
 | 1926 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1927 | 	result = kgsl_mmu_map(private->pagetable, | 
 | 1928 | 			      &entry->memdesc, | 
 | 1929 | 			      GSL_PT_PAGE_RV | GSL_PT_PAGE_WV); | 
 | 1930 |  | 
 | 1931 | 	if (result) | 
 | 1932 | 		goto error_put_file_ptr; | 
 | 1933 |  | 
 | 1934 | 	/* Adjust the returned value for a non 4k aligned offset */ | 
 | 1935 | 	param->gpuaddr = entry->memdesc.gpuaddr + (param->offset & ~PAGE_MASK); | 
 | 1936 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1937 | 	KGSL_STATS_ADD(param->len, kgsl_driver.stats.mapped, | 
| Jordan Crouse | 1b897cf | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1938 | 		kgsl_driver.stats.mapped_max); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1939 |  | 
| Jordan Crouse | 1b897cf | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 1940 | 	kgsl_process_add_stats(private, entry->memtype, param->len); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1941 |  | 
 | 1942 | 	kgsl_mem_entry_attach_process(entry, private); | 
| Jeremy Gebben | a585927 | 2012-03-01 12:46:28 -0700 | [diff] [blame] | 1943 | 	trace_kgsl_mem_map(entry, param->fd); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1944 |  | 
 | 1945 | 	kgsl_check_idle(dev_priv->device); | 
 | 1946 | 	return result; | 
 | 1947 |  | 
| Jeremy Gebben | 53d4dd0 | 2012-05-07 15:42:00 -0600 | [diff] [blame] | 1948 | error_put_file_ptr: | 
 | 1949 | 	switch (entry->memtype) { | 
 | 1950 | 	case KGSL_MEM_ENTRY_PMEM: | 
 | 1951 | 	case KGSL_MEM_ENTRY_ASHMEM: | 
 | 1952 | 		if (entry->priv_data) | 
 | 1953 | 			fput(entry->priv_data); | 
 | 1954 | 		break; | 
 | 1955 | 	case KGSL_MEM_ENTRY_ION: | 
| Jeremy Gebben | 53d4dd0 | 2012-05-07 15:42:00 -0600 | [diff] [blame] | 1956 | 		ion_free(kgsl_ion_client, entry->priv_data); | 
 | 1957 | 		break; | 
 | 1958 | 	default: | 
 | 1959 | 		break; | 
 | 1960 | 	} | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1961 | error: | 
 | 1962 | 	kfree(entry); | 
 | 1963 | 	kgsl_check_idle(dev_priv->device); | 
 | 1964 | 	return result; | 
 | 1965 | } | 
 | 1966 |  | 
 | 1967 | /*This function flushes a graphics memory allocation from CPU cache | 
 | 1968 |  *when caching is enabled with MMU*/ | 
 | 1969 | static long | 
 | 1970 | kgsl_ioctl_sharedmem_flush_cache(struct kgsl_device_private *dev_priv, | 
 | 1971 | 				 unsigned int cmd, void *data) | 
 | 1972 | { | 
 | 1973 | 	int result = 0; | 
 | 1974 | 	struct kgsl_mem_entry *entry; | 
 | 1975 | 	struct kgsl_sharedmem_free *param = data; | 
 | 1976 | 	struct kgsl_process_private *private = dev_priv->process_priv; | 
 | 1977 |  | 
 | 1978 | 	spin_lock(&private->mem_lock); | 
 | 1979 | 	entry = kgsl_sharedmem_find(private, param->gpuaddr); | 
 | 1980 | 	if (!entry) { | 
 | 1981 | 		KGSL_CORE_ERR("invalid gpuaddr %08x\n", param->gpuaddr); | 
 | 1982 | 		result = -EINVAL; | 
| Jeremy Gebben | 690f9d1 | 2011-08-08 16:33:49 -0600 | [diff] [blame] | 1983 | 		goto done; | 
 | 1984 | 	} | 
| Jeremy Gebben | 690f9d1 | 2011-08-08 16:33:49 -0600 | [diff] [blame] | 1985 | 	if (!entry->memdesc.hostptr) { | 
 | 1986 | 		KGSL_CORE_ERR("invalid hostptr with gpuaddr %08x\n", | 
 | 1987 | 			param->gpuaddr); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1988 | 			goto done; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1989 | 	} | 
| Jeremy Gebben | 690f9d1 | 2011-08-08 16:33:49 -0600 | [diff] [blame] | 1990 |  | 
 | 1991 | 	kgsl_cache_range_op(&entry->memdesc, KGSL_CACHE_OP_CLEAN); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1992 | done: | 
| Jeremy Gebben | 690f9d1 | 2011-08-08 16:33:49 -0600 | [diff] [blame] | 1993 | 	spin_unlock(&private->mem_lock); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1994 | 	return result; | 
 | 1995 | } | 
 | 1996 |  | 
 | 1997 | static long | 
 | 1998 | kgsl_ioctl_gpumem_alloc(struct kgsl_device_private *dev_priv, | 
 | 1999 | 			unsigned int cmd, void *data) | 
 | 2000 | { | 
 | 2001 | 	struct kgsl_process_private *private = dev_priv->process_priv; | 
 | 2002 | 	struct kgsl_gpumem_alloc *param = data; | 
 | 2003 | 	struct kgsl_mem_entry *entry; | 
 | 2004 | 	int result; | 
 | 2005 |  | 
 | 2006 | 	entry = kgsl_mem_entry_create(); | 
 | 2007 | 	if (entry == NULL) | 
 | 2008 | 		return -ENOMEM; | 
 | 2009 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2010 | 	result = kgsl_allocate_user(&entry->memdesc, private->pagetable, | 
 | 2011 | 		param->size, param->flags); | 
 | 2012 |  | 
 | 2013 | 	if (result == 0) { | 
| Jordan Crouse | 1b897cf | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 2014 | 		entry->memtype = KGSL_MEM_ENTRY_KERNEL; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2015 | 		kgsl_mem_entry_attach_process(entry, private); | 
 | 2016 | 		param->gpuaddr = entry->memdesc.gpuaddr; | 
 | 2017 |  | 
| Jordan Crouse | 1b897cf | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 2018 | 		kgsl_process_add_stats(private, entry->memtype, param->size); | 
| Jeremy Gebben | a585927 | 2012-03-01 12:46:28 -0700 | [diff] [blame] | 2019 | 		trace_kgsl_mem_alloc(entry); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2020 | 	} else | 
 | 2021 | 		kfree(entry); | 
 | 2022 |  | 
 | 2023 | 	kgsl_check_idle(dev_priv->device); | 
 | 2024 | 	return result; | 
 | 2025 | } | 
| Jeremy Gebben | a7423e4 | 2011-04-18 15:11:21 -0600 | [diff] [blame] | 2026 | static long kgsl_ioctl_cff_syncmem(struct kgsl_device_private *dev_priv, | 
 | 2027 | 					unsigned int cmd, void *data) | 
 | 2028 | { | 
 | 2029 | 	int result = 0; | 
 | 2030 | 	struct kgsl_cff_syncmem *param = data; | 
 | 2031 | 	struct kgsl_process_private *private = dev_priv->process_priv; | 
 | 2032 | 	struct kgsl_mem_entry *entry = NULL; | 
 | 2033 |  | 
 | 2034 | 	spin_lock(&private->mem_lock); | 
 | 2035 | 	entry = kgsl_sharedmem_find_region(private, param->gpuaddr, param->len); | 
 | 2036 | 	if (entry) | 
 | 2037 | 		kgsl_cffdump_syncmem(dev_priv, &entry->memdesc, param->gpuaddr, | 
 | 2038 | 				     param->len, true); | 
 | 2039 | 	else | 
 | 2040 | 		result = -EINVAL; | 
 | 2041 | 	spin_unlock(&private->mem_lock); | 
 | 2042 | 	return result; | 
 | 2043 | } | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2044 |  | 
| Sushmita Susheelendra | 41f8fa3 | 2011-05-11 17:15:58 -0600 | [diff] [blame] | 2045 | static long kgsl_ioctl_cff_user_event(struct kgsl_device_private *dev_priv, | 
 | 2046 | 		unsigned int cmd, void *data) | 
 | 2047 | { | 
 | 2048 | 	int result = 0; | 
 | 2049 | 	struct kgsl_cff_user_event *param = data; | 
 | 2050 |  | 
 | 2051 | 	kgsl_cffdump_user_event(param->cff_opcode, param->op1, param->op2, | 
 | 2052 | 			param->op3, param->op4, param->op5); | 
 | 2053 |  | 
 | 2054 | 	return result; | 
 | 2055 | } | 
 | 2056 |  | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 2057 | #ifdef CONFIG_GENLOCK | 
 | 2058 | struct kgsl_genlock_event_priv { | 
 | 2059 | 	struct genlock_handle *handle; | 
 | 2060 | 	struct genlock *lock; | 
 | 2061 | }; | 
 | 2062 |  | 
 | 2063 | /** | 
 | 2064 |  * kgsl_genlock_event_cb - Event callback for a genlock timestamp event | 
 | 2065 |  * @device - The KGSL device that expired the timestamp | 
 | 2066 |  * @priv - private data for the event | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2067 |  * @context_id - the context id that goes with the timestamp | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 2068 |  * @timestamp - the timestamp that triggered the event | 
 | 2069 |  * | 
 | 2070 |  * Release a genlock lock following the expiration of a timestamp | 
 | 2071 |  */ | 
 | 2072 |  | 
 | 2073 | static void kgsl_genlock_event_cb(struct kgsl_device *device, | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2074 | 	void *priv, u32 context_id, u32 timestamp) | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 2075 | { | 
 | 2076 | 	struct kgsl_genlock_event_priv *ev = priv; | 
 | 2077 | 	int ret; | 
 | 2078 |  | 
 | 2079 | 	ret = genlock_lock(ev->handle, GENLOCK_UNLOCK, 0, 0); | 
 | 2080 | 	if (ret) | 
 | 2081 | 		KGSL_CORE_ERR("Error while unlocking genlock: %d\n", ret); | 
 | 2082 |  | 
 | 2083 | 	genlock_put_handle(ev->handle); | 
 | 2084 |  | 
 | 2085 | 	kfree(ev); | 
 | 2086 | } | 
 | 2087 |  | 
 | 2088 | /** | 
 | 2089 |  * kgsl_add_genlock-event - Create a new genlock event | 
 | 2090 |  * @device - KGSL device to create the event on | 
 | 2091 |  * @timestamp - Timestamp to trigger the event | 
 | 2092 |  * @data - User space buffer containing struct kgsl_genlock_event_priv | 
 | 2093 |  * @len - length of the userspace buffer | 
| Jeremy Gebben | fd87f9a | 2012-02-10 07:06:09 -0700 | [diff] [blame] | 2094 |  * @owner - driver instance that owns this event | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 2095 |  * @returns 0 on success or error code on error | 
 | 2096 |  * | 
 | 2097 |  * Attack to a genlock handle and register an event to release the | 
 | 2098 |  * genlock lock when the timestamp expires | 
 | 2099 |  */ | 
 | 2100 |  | 
 | 2101 | static int kgsl_add_genlock_event(struct kgsl_device *device, | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2102 | 	u32 context_id, u32 timestamp, void __user *data, int len, | 
| Jeremy Gebben | fd87f9a | 2012-02-10 07:06:09 -0700 | [diff] [blame] | 2103 | 	struct kgsl_device_private *owner) | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 2104 | { | 
 | 2105 | 	struct kgsl_genlock_event_priv *event; | 
 | 2106 | 	struct kgsl_timestamp_event_genlock priv; | 
 | 2107 | 	int ret; | 
 | 2108 |  | 
 | 2109 | 	if (len !=  sizeof(priv)) | 
 | 2110 | 		return -EINVAL; | 
 | 2111 |  | 
 | 2112 | 	if (copy_from_user(&priv, data, sizeof(priv))) | 
 | 2113 | 		return -EFAULT; | 
 | 2114 |  | 
 | 2115 | 	event = kzalloc(sizeof(*event), GFP_KERNEL); | 
 | 2116 |  | 
 | 2117 | 	if (event == NULL) | 
 | 2118 | 		return -ENOMEM; | 
 | 2119 |  | 
 | 2120 | 	event->handle = genlock_get_handle_fd(priv.handle); | 
 | 2121 |  | 
 | 2122 | 	if (IS_ERR(event->handle)) { | 
 | 2123 | 		int ret = PTR_ERR(event->handle); | 
 | 2124 | 		kfree(event); | 
 | 2125 | 		return ret; | 
 | 2126 | 	} | 
 | 2127 |  | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2128 | 	ret = kgsl_add_event(device, context_id, timestamp, | 
 | 2129 | 			kgsl_genlock_event_cb, event, owner); | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 2130 | 	if (ret) | 
 | 2131 | 		kfree(event); | 
 | 2132 |  | 
 | 2133 | 	return ret; | 
 | 2134 | } | 
 | 2135 | #else | 
 | 2136 | static long kgsl_add_genlock_event(struct kgsl_device *device, | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2137 | 	u32 context_id, u32 timestamp, void __user *data, int len, | 
| Jeremy Gebben | fd87f9a | 2012-02-10 07:06:09 -0700 | [diff] [blame] | 2138 | 	struct kgsl_device_private *owner) | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 2139 | { | 
 | 2140 | 	return -EINVAL; | 
 | 2141 | } | 
 | 2142 | #endif | 
 | 2143 |  | 
 | 2144 | /** | 
 | 2145 |  * kgsl_ioctl_timestamp_event - Register a new timestamp event from userspace | 
 | 2146 |  * @dev_priv - pointer to the private device structure | 
 | 2147 |  * @cmd - the ioctl cmd passed from kgsl_ioctl | 
 | 2148 |  * @data - the user data buffer from kgsl_ioctl | 
 | 2149 |  * @returns 0 on success or error code on failure | 
 | 2150 |  */ | 
 | 2151 |  | 
 | 2152 | static long kgsl_ioctl_timestamp_event(struct kgsl_device_private *dev_priv, | 
 | 2153 | 		unsigned int cmd, void *data) | 
 | 2154 | { | 
 | 2155 | 	struct kgsl_timestamp_event *param = data; | 
 | 2156 | 	int ret; | 
 | 2157 |  | 
 | 2158 | 	switch (param->type) { | 
 | 2159 | 	case KGSL_TIMESTAMP_EVENT_GENLOCK: | 
 | 2160 | 		ret = kgsl_add_genlock_event(dev_priv->device, | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2161 | 			param->context_id, param->timestamp, param->priv, | 
 | 2162 | 			param->len, dev_priv); | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 2163 | 		break; | 
| Jeff Boody | fe6c39c | 2012-08-09 13:54:50 -0600 | [diff] [blame] | 2164 | 	case KGSL_TIMESTAMP_EVENT_FENCE: | 
 | 2165 | 		ret = kgsl_add_fence_event(dev_priv->device, | 
 | 2166 | 			param->context_id, param->timestamp, param->priv, | 
 | 2167 | 			param->len, dev_priv); | 
 | 2168 | 		break; | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 2169 | 	default: | 
 | 2170 | 		ret = -EINVAL; | 
 | 2171 | 	} | 
 | 2172 |  | 
 | 2173 | 	return ret; | 
 | 2174 | } | 
 | 2175 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2176 | typedef long (*kgsl_ioctl_func_t)(struct kgsl_device_private *, | 
 | 2177 | 	unsigned int, void *); | 
 | 2178 |  | 
 | 2179 | #define KGSL_IOCTL_FUNC(_cmd, _func, _lock) \ | 
 | 2180 | 	[_IOC_NR(_cmd)] = { .cmd = _cmd, .func = _func, .lock = _lock } | 
 | 2181 |  | 
 | 2182 | static const struct { | 
 | 2183 | 	unsigned int cmd; | 
 | 2184 | 	kgsl_ioctl_func_t func; | 
 | 2185 | 	int lock; | 
 | 2186 | } kgsl_ioctl_funcs[] = { | 
 | 2187 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_DEVICE_GETPROPERTY, | 
 | 2188 | 			kgsl_ioctl_device_getproperty, 1), | 
 | 2189 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_DEVICE_WAITTIMESTAMP, | 
 | 2190 | 			kgsl_ioctl_device_waittimestamp, 1), | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2191 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID, | 
 | 2192 | 			kgsl_ioctl_device_waittimestamp_ctxtid, 1), | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2193 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_RINGBUFFER_ISSUEIBCMDS, | 
 | 2194 | 			kgsl_ioctl_rb_issueibcmds, 1), | 
 | 2195 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_CMDSTREAM_READTIMESTAMP, | 
 | 2196 | 			kgsl_ioctl_cmdstream_readtimestamp, 1), | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2197 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_CTXTID, | 
 | 2198 | 			kgsl_ioctl_cmdstream_readtimestamp_ctxtid, 1), | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2199 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP, | 
 | 2200 | 			kgsl_ioctl_cmdstream_freememontimestamp, 1), | 
| Carter Cooper | 7e7f02e | 2012-02-15 09:36:31 -0700 | [diff] [blame] | 2201 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_CTXTID, | 
 | 2202 | 			kgsl_ioctl_cmdstream_freememontimestamp_ctxtid, 1), | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2203 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_DRAWCTXT_CREATE, | 
 | 2204 | 			kgsl_ioctl_drawctxt_create, 1), | 
 | 2205 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_DRAWCTXT_DESTROY, | 
 | 2206 | 			kgsl_ioctl_drawctxt_destroy, 1), | 
 | 2207 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_MAP_USER_MEM, | 
 | 2208 | 			kgsl_ioctl_map_user_mem, 0), | 
 | 2209 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FROM_PMEM, | 
 | 2210 | 			kgsl_ioctl_map_user_mem, 0), | 
 | 2211 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FREE, | 
 | 2212 | 			kgsl_ioctl_sharedmem_free, 0), | 
 | 2213 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FROM_VMALLOC, | 
 | 2214 | 			kgsl_ioctl_sharedmem_from_vmalloc, 0), | 
 | 2215 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_SHAREDMEM_FLUSH_CACHE, | 
 | 2216 | 			kgsl_ioctl_sharedmem_flush_cache, 0), | 
 | 2217 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_GPUMEM_ALLOC, | 
 | 2218 | 			kgsl_ioctl_gpumem_alloc, 0), | 
| Jeremy Gebben | a7423e4 | 2011-04-18 15:11:21 -0600 | [diff] [blame] | 2219 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_CFF_SYNCMEM, | 
 | 2220 | 			kgsl_ioctl_cff_syncmem, 0), | 
| Sushmita Susheelendra | 41f8fa3 | 2011-05-11 17:15:58 -0600 | [diff] [blame] | 2221 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_CFF_USER_EVENT, | 
 | 2222 | 			kgsl_ioctl_cff_user_event, 0), | 
| Jordan Crouse | d4bc9d2 | 2011-11-17 13:39:21 -0700 | [diff] [blame] | 2223 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_TIMESTAMP_EVENT, | 
| Lucille Sylvester | 9329cf0 | 2011-12-02 14:30:41 -0700 | [diff] [blame] | 2224 | 			kgsl_ioctl_timestamp_event, 1), | 
| Jordan Crouse | ed7dd7f | 2012-03-29 13:16:02 -0600 | [diff] [blame] | 2225 | 	KGSL_IOCTL_FUNC(IOCTL_KGSL_SETPROPERTY, | 
 | 2226 | 			kgsl_ioctl_device_setproperty, 1), | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2227 | }; | 
 | 2228 |  | 
 | 2229 | static long kgsl_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) | 
 | 2230 | { | 
 | 2231 | 	struct kgsl_device_private *dev_priv = filep->private_data; | 
| Jordan Crouse | 1e76f61 | 2012-08-08 13:24:21 -0600 | [diff] [blame] | 2232 | 	unsigned int nr; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2233 | 	kgsl_ioctl_func_t func; | 
 | 2234 | 	int lock, ret; | 
 | 2235 | 	char ustack[64]; | 
 | 2236 | 	void *uptr = NULL; | 
 | 2237 |  | 
 | 2238 | 	BUG_ON(dev_priv == NULL); | 
 | 2239 |  | 
 | 2240 | 	/* Workaround for an previously incorrectly defined ioctl code. | 
 | 2241 | 	   This helps ensure binary compatability */ | 
 | 2242 |  | 
 | 2243 | 	if (cmd == IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP_OLD) | 
 | 2244 | 		cmd = IOCTL_KGSL_CMDSTREAM_FREEMEMONTIMESTAMP; | 
| Jason Varbedian | 80ba33d | 2011-07-11 17:29:05 -0700 | [diff] [blame] | 2245 | 	else if (cmd == IOCTL_KGSL_CMDSTREAM_READTIMESTAMP_OLD) | 
 | 2246 | 		cmd = IOCTL_KGSL_CMDSTREAM_READTIMESTAMP; | 
| Jeff Boody | fe6c39c | 2012-08-09 13:54:50 -0600 | [diff] [blame] | 2247 | 	else if (cmd == IOCTL_KGSL_TIMESTAMP_EVENT_OLD) | 
 | 2248 | 		cmd = IOCTL_KGSL_TIMESTAMP_EVENT; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2249 |  | 
| Jordan Crouse | 1e76f61 | 2012-08-08 13:24:21 -0600 | [diff] [blame] | 2250 | 	nr = _IOC_NR(cmd); | 
 | 2251 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2252 | 	if (cmd & (IOC_IN | IOC_OUT)) { | 
 | 2253 | 		if (_IOC_SIZE(cmd) < sizeof(ustack)) | 
 | 2254 | 			uptr = ustack; | 
 | 2255 | 		else { | 
 | 2256 | 			uptr = kzalloc(_IOC_SIZE(cmd), GFP_KERNEL); | 
 | 2257 | 			if (uptr == NULL) { | 
 | 2258 | 				KGSL_MEM_ERR(dev_priv->device, | 
 | 2259 | 					"kzalloc(%d) failed\n", _IOC_SIZE(cmd)); | 
 | 2260 | 				ret = -ENOMEM; | 
 | 2261 | 				goto done; | 
 | 2262 | 			} | 
 | 2263 | 		} | 
 | 2264 |  | 
 | 2265 | 		if (cmd & IOC_IN) { | 
 | 2266 | 			if (copy_from_user(uptr, (void __user *) arg, | 
 | 2267 | 				_IOC_SIZE(cmd))) { | 
 | 2268 | 				ret = -EFAULT; | 
 | 2269 | 				goto done; | 
 | 2270 | 			} | 
 | 2271 | 		} else | 
 | 2272 | 			memset(uptr, 0, _IOC_SIZE(cmd)); | 
 | 2273 | 	} | 
 | 2274 |  | 
 | 2275 | 	if (nr < ARRAY_SIZE(kgsl_ioctl_funcs) && | 
| Jordan Crouse | 1e76f61 | 2012-08-08 13:24:21 -0600 | [diff] [blame] | 2276 | 		kgsl_ioctl_funcs[nr].func != NULL) { | 
 | 2277 |  | 
 | 2278 | 		/* | 
 | 2279 | 		 * Make sure that nobody tried to send us a malformed ioctl code | 
 | 2280 | 		 * with a valid NR but bogus flags | 
 | 2281 | 		 */ | 
 | 2282 |  | 
 | 2283 | 		if (kgsl_ioctl_funcs[nr].cmd != cmd) { | 
 | 2284 | 			KGSL_DRV_ERR(dev_priv->device, | 
 | 2285 | 				"Malformed ioctl code %08x\n", cmd); | 
 | 2286 | 			ret = -ENOIOCTLCMD; | 
 | 2287 | 			goto done; | 
 | 2288 | 		} | 
 | 2289 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2290 | 		func = kgsl_ioctl_funcs[nr].func; | 
 | 2291 | 		lock = kgsl_ioctl_funcs[nr].lock; | 
 | 2292 | 	} else { | 
 | 2293 | 		func = dev_priv->device->ftbl->ioctl; | 
 | 2294 | 		if (!func) { | 
 | 2295 | 			KGSL_DRV_INFO(dev_priv->device, | 
 | 2296 | 				      "invalid ioctl code %08x\n", cmd); | 
| Jeremy Gebben | c15b461 | 2012-01-09 09:44:11 -0700 | [diff] [blame] | 2297 | 			ret = -ENOIOCTLCMD; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2298 | 			goto done; | 
 | 2299 | 		} | 
 | 2300 | 		lock = 1; | 
 | 2301 | 	} | 
 | 2302 |  | 
 | 2303 | 	if (lock) { | 
 | 2304 | 		mutex_lock(&dev_priv->device->mutex); | 
 | 2305 | 		kgsl_check_suspended(dev_priv->device); | 
 | 2306 | 	} | 
 | 2307 |  | 
 | 2308 | 	ret = func(dev_priv, cmd, uptr); | 
 | 2309 |  | 
 | 2310 | 	if (lock) { | 
 | 2311 | 		kgsl_check_idle_locked(dev_priv->device); | 
 | 2312 | 		mutex_unlock(&dev_priv->device->mutex); | 
 | 2313 | 	} | 
 | 2314 |  | 
 | 2315 | 	if (ret == 0 && (cmd & IOC_OUT)) { | 
 | 2316 | 		if (copy_to_user((void __user *) arg, uptr, _IOC_SIZE(cmd))) | 
 | 2317 | 			ret = -EFAULT; | 
 | 2318 | 	} | 
 | 2319 |  | 
 | 2320 | done: | 
 | 2321 | 	if (_IOC_SIZE(cmd) >= sizeof(ustack)) | 
 | 2322 | 		kfree(uptr); | 
 | 2323 |  | 
 | 2324 | 	return ret; | 
 | 2325 | } | 
 | 2326 |  | 
 | 2327 | static int | 
 | 2328 | kgsl_mmap_memstore(struct kgsl_device *device, struct vm_area_struct *vma) | 
 | 2329 | { | 
 | 2330 | 	struct kgsl_memdesc *memdesc = &device->memstore; | 
 | 2331 | 	int result; | 
 | 2332 | 	unsigned int vma_size = vma->vm_end - vma->vm_start; | 
 | 2333 |  | 
 | 2334 | 	/* The memstore can only be mapped as read only */ | 
 | 2335 |  | 
 | 2336 | 	if (vma->vm_flags & VM_WRITE) | 
 | 2337 | 		return -EPERM; | 
 | 2338 |  | 
 | 2339 | 	if (memdesc->size  !=  vma_size) { | 
 | 2340 | 		KGSL_MEM_ERR(device, "memstore bad size: %d should be %d\n", | 
 | 2341 | 			     vma_size, memdesc->size); | 
 | 2342 | 		return -EINVAL; | 
 | 2343 | 	} | 
 | 2344 |  | 
 | 2345 | 	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); | 
 | 2346 |  | 
| Shubhraprakash Das | 87f6813 | 2012-07-30 23:25:13 -0700 | [diff] [blame] | 2347 | 	result = remap_pfn_range(vma, vma->vm_start, | 
 | 2348 | 				device->memstore.physaddr >> PAGE_SHIFT, | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2349 | 				 vma_size, vma->vm_page_prot); | 
 | 2350 | 	if (result != 0) | 
 | 2351 | 		KGSL_MEM_ERR(device, "remap_pfn_range failed: %d\n", | 
 | 2352 | 			     result); | 
 | 2353 |  | 
 | 2354 | 	return result; | 
 | 2355 | } | 
 | 2356 |  | 
| Jordan Crouse | 4283e17 | 2011-09-26 14:45:47 -0600 | [diff] [blame] | 2357 | /* | 
 | 2358 |  * kgsl_gpumem_vm_open is called whenever a vma region is copied or split. | 
 | 2359 |  * Increase the refcount to make sure that the accounting stays correct | 
 | 2360 |  */ | 
 | 2361 |  | 
 | 2362 | static void kgsl_gpumem_vm_open(struct vm_area_struct *vma) | 
 | 2363 | { | 
 | 2364 | 	struct kgsl_mem_entry *entry = vma->vm_private_data; | 
 | 2365 | 	kgsl_mem_entry_get(entry); | 
 | 2366 | } | 
 | 2367 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2368 | static int | 
 | 2369 | kgsl_gpumem_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf) | 
 | 2370 | { | 
 | 2371 | 	struct kgsl_mem_entry *entry = vma->vm_private_data; | 
 | 2372 |  | 
| Jordan Crouse | d17e9aa | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 2373 | 	if (!entry->memdesc.ops || !entry->memdesc.ops->vmfault) | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2374 | 		return VM_FAULT_SIGBUS; | 
 | 2375 |  | 
 | 2376 | 	return entry->memdesc.ops->vmfault(&entry->memdesc, vma, vmf); | 
 | 2377 | } | 
 | 2378 |  | 
 | 2379 | static void | 
 | 2380 | kgsl_gpumem_vm_close(struct vm_area_struct *vma) | 
 | 2381 | { | 
 | 2382 | 	struct kgsl_mem_entry *entry  = vma->vm_private_data; | 
 | 2383 | 	kgsl_mem_entry_put(entry); | 
 | 2384 | } | 
 | 2385 |  | 
 | 2386 | static struct vm_operations_struct kgsl_gpumem_vm_ops = { | 
| Jordan Crouse | 4283e17 | 2011-09-26 14:45:47 -0600 | [diff] [blame] | 2387 | 	.open  = kgsl_gpumem_vm_open, | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2388 | 	.fault = kgsl_gpumem_vm_fault, | 
 | 2389 | 	.close = kgsl_gpumem_vm_close, | 
 | 2390 | }; | 
 | 2391 |  | 
 | 2392 | static int kgsl_mmap(struct file *file, struct vm_area_struct *vma) | 
 | 2393 | { | 
 | 2394 | 	unsigned long vma_offset = vma->vm_pgoff << PAGE_SHIFT; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2395 | 	struct kgsl_device_private *dev_priv = file->private_data; | 
 | 2396 | 	struct kgsl_process_private *private = dev_priv->process_priv; | 
| Jordan Crouse | c9559e4 | 2012-04-05 16:55:56 -0600 | [diff] [blame] | 2397 | 	struct kgsl_mem_entry *entry = NULL; | 
| Jordan Crouse | 2db0af9 | 2011-08-08 16:05:09 -0600 | [diff] [blame] | 2398 | 	struct kgsl_device *device = dev_priv->device; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2399 |  | 
 | 2400 | 	/* Handle leagacy behavior for memstore */ | 
 | 2401 |  | 
| Shubhraprakash Das | 87f6813 | 2012-07-30 23:25:13 -0700 | [diff] [blame] | 2402 | 	if (vma_offset == device->memstore.gpuaddr) | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2403 | 		return kgsl_mmap_memstore(device, vma); | 
 | 2404 |  | 
 | 2405 | 	/* Find a chunk of GPU memory */ | 
 | 2406 |  | 
 | 2407 | 	spin_lock(&private->mem_lock); | 
| Jordan Crouse | c9559e4 | 2012-04-05 16:55:56 -0600 | [diff] [blame] | 2408 | 	entry = kgsl_sharedmem_find(private, vma_offset); | 
 | 2409 |  | 
 | 2410 | 	if (entry) | 
 | 2411 | 		kgsl_mem_entry_get(entry); | 
 | 2412 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2413 | 	spin_unlock(&private->mem_lock); | 
 | 2414 |  | 
 | 2415 | 	if (entry == NULL) | 
 | 2416 | 		return -EINVAL; | 
 | 2417 |  | 
| Jordan Crouse | d17e9aa | 2011-10-12 16:57:48 -0600 | [diff] [blame] | 2418 | 	if (!entry->memdesc.ops || | 
 | 2419 | 		!entry->memdesc.ops->vmflags || | 
 | 2420 | 		!entry->memdesc.ops->vmfault) | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2421 | 		return -EINVAL; | 
 | 2422 |  | 
 | 2423 | 	vma->vm_flags |= entry->memdesc.ops->vmflags(&entry->memdesc); | 
 | 2424 |  | 
 | 2425 | 	vma->vm_private_data = entry; | 
 | 2426 | 	vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); | 
 | 2427 | 	vma->vm_ops = &kgsl_gpumem_vm_ops; | 
 | 2428 | 	vma->vm_file = file; | 
 | 2429 |  | 
 | 2430 | 	return 0; | 
 | 2431 | } | 
 | 2432 |  | 
| Jordan Crouse | b368e9b | 2012-04-27 14:01:59 -0600 | [diff] [blame] | 2433 | static irqreturn_t kgsl_irq_handler(int irq, void *data) | 
 | 2434 | { | 
 | 2435 | 	struct kgsl_device *device = data; | 
 | 2436 |  | 
 | 2437 | 	return device->ftbl->irq_handler(device); | 
 | 2438 |  | 
 | 2439 | } | 
 | 2440 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2441 | static const struct file_operations kgsl_fops = { | 
 | 2442 | 	.owner = THIS_MODULE, | 
 | 2443 | 	.release = kgsl_release, | 
 | 2444 | 	.open = kgsl_open, | 
 | 2445 | 	.mmap = kgsl_mmap, | 
 | 2446 | 	.unlocked_ioctl = kgsl_ioctl, | 
 | 2447 | }; | 
 | 2448 |  | 
 | 2449 | struct kgsl_driver kgsl_driver  = { | 
 | 2450 | 	.process_mutex = __MUTEX_INITIALIZER(kgsl_driver.process_mutex), | 
 | 2451 | 	.ptlock = __SPIN_LOCK_UNLOCKED(kgsl_driver.ptlock), | 
 | 2452 | 	.devlock = __MUTEX_INITIALIZER(kgsl_driver.devlock), | 
 | 2453 | }; | 
 | 2454 | EXPORT_SYMBOL(kgsl_driver); | 
 | 2455 |  | 
| Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 2456 | static void _unregister_device(struct kgsl_device *device) | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2457 | { | 
 | 2458 | 	int minor; | 
 | 2459 |  | 
 | 2460 | 	mutex_lock(&kgsl_driver.devlock); | 
 | 2461 | 	for (minor = 0; minor < KGSL_DEVICE_MAX; minor++) { | 
 | 2462 | 		if (device == kgsl_driver.devp[minor]) | 
 | 2463 | 			break; | 
 | 2464 | 	} | 
| Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 2465 | 	if (minor != KGSL_DEVICE_MAX) { | 
 | 2466 | 		device_destroy(kgsl_driver.class, | 
 | 2467 | 				MKDEV(MAJOR(kgsl_driver.major), minor)); | 
 | 2468 | 		kgsl_driver.devp[minor] = NULL; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2469 | 	} | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2470 | 	mutex_unlock(&kgsl_driver.devlock); | 
 | 2471 | } | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2472 |  | 
| Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 2473 | static int _register_device(struct kgsl_device *device) | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2474 | { | 
 | 2475 | 	int minor, ret; | 
 | 2476 | 	dev_t dev; | 
 | 2477 |  | 
 | 2478 | 	/* Find a minor for the device */ | 
 | 2479 |  | 
 | 2480 | 	mutex_lock(&kgsl_driver.devlock); | 
 | 2481 | 	for (minor = 0; minor < KGSL_DEVICE_MAX; minor++) { | 
 | 2482 | 		if (kgsl_driver.devp[minor] == NULL) { | 
 | 2483 | 			kgsl_driver.devp[minor] = device; | 
 | 2484 | 			break; | 
 | 2485 | 		} | 
 | 2486 | 	} | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2487 | 	mutex_unlock(&kgsl_driver.devlock); | 
 | 2488 |  | 
 | 2489 | 	if (minor == KGSL_DEVICE_MAX) { | 
 | 2490 | 		KGSL_CORE_ERR("minor devices exhausted\n"); | 
 | 2491 | 		return -ENODEV; | 
 | 2492 | 	} | 
 | 2493 |  | 
 | 2494 | 	/* Create the device */ | 
 | 2495 | 	dev = MKDEV(MAJOR(kgsl_driver.major), minor); | 
 | 2496 | 	device->dev = device_create(kgsl_driver.class, | 
 | 2497 | 				    device->parentdev, | 
 | 2498 | 				    dev, device, | 
 | 2499 | 				    device->name); | 
 | 2500 |  | 
 | 2501 | 	if (IS_ERR(device->dev)) { | 
| Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 2502 | 		mutex_lock(&kgsl_driver.devlock); | 
 | 2503 | 		kgsl_driver.devp[minor] = NULL; | 
 | 2504 | 		mutex_unlock(&kgsl_driver.devlock); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2505 | 		ret = PTR_ERR(device->dev); | 
 | 2506 | 		KGSL_CORE_ERR("device_create(%s): %d\n", device->name, ret); | 
| Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 2507 | 		return ret; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2508 | 	} | 
 | 2509 |  | 
 | 2510 | 	dev_set_drvdata(device->parentdev, device); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2511 | 	return 0; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2512 | } | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2513 |  | 
| Jordan Crouse | b368e9b | 2012-04-27 14:01:59 -0600 | [diff] [blame] | 2514 | int kgsl_device_platform_probe(struct kgsl_device *device) | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2515 | { | 
| Michael Street | 8bacdd0 | 2012-01-05 14:55:01 -0800 | [diff] [blame] | 2516 | 	int result; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2517 | 	int status = -EINVAL; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2518 | 	struct resource *res; | 
 | 2519 | 	struct platform_device *pdev = | 
 | 2520 | 		container_of(device->parentdev, struct platform_device, dev); | 
 | 2521 |  | 
| Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 2522 | 	status = _register_device(device); | 
 | 2523 | 	if (status) | 
 | 2524 | 		return status; | 
 | 2525 |  | 
 | 2526 | 	/* Initialize logging first, so that failures below actually print. */ | 
 | 2527 | 	kgsl_device_debugfs_init(device); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2528 |  | 
 | 2529 | 	status = kgsl_pwrctrl_init(device); | 
 | 2530 | 	if (status) | 
 | 2531 | 		goto error; | 
 | 2532 |  | 
| Harsh Vardhan Dwivedi | f48af7f | 2012-04-13 12:50:44 -0600 | [diff] [blame] | 2533 | 	kgsl_ion_client = msm_ion_client_create(UINT_MAX, KGSL_NAME); | 
 | 2534 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2535 | 	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, | 
 | 2536 | 					   device->iomemname); | 
 | 2537 | 	if (res == NULL) { | 
 | 2538 | 		KGSL_DRV_ERR(device, "platform_get_resource_byname failed\n"); | 
 | 2539 | 		status = -EINVAL; | 
 | 2540 | 		goto error_pwrctrl_close; | 
 | 2541 | 	} | 
 | 2542 | 	if (res->start == 0 || resource_size(res) == 0) { | 
| Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 2543 | 		KGSL_DRV_ERR(device, "dev %d invalid register region\n", | 
 | 2544 | 			device->id); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2545 | 		status = -EINVAL; | 
 | 2546 | 		goto error_pwrctrl_close; | 
 | 2547 | 	} | 
 | 2548 |  | 
| Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 2549 | 	device->reg_phys = res->start; | 
 | 2550 | 	device->reg_len = resource_size(res); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2551 |  | 
| Jeremy Gebben | 4204d0f | 2012-03-01 16:06:21 -0700 | [diff] [blame] | 2552 | 	if (!devm_request_mem_region(device->dev, device->reg_phys, | 
 | 2553 | 				device->reg_len, device->name)) { | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2554 | 		KGSL_DRV_ERR(device, "request_mem_region failed\n"); | 
 | 2555 | 		status = -ENODEV; | 
 | 2556 | 		goto error_pwrctrl_close; | 
 | 2557 | 	} | 
 | 2558 |  | 
| Jeremy Gebben | 4204d0f | 2012-03-01 16:06:21 -0700 | [diff] [blame] | 2559 | 	device->reg_virt = devm_ioremap(device->dev, device->reg_phys, | 
 | 2560 | 					device->reg_len); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2561 |  | 
| Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 2562 | 	if (device->reg_virt == NULL) { | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2563 | 		KGSL_DRV_ERR(device, "ioremap failed\n"); | 
 | 2564 | 		status = -ENODEV; | 
| Jeremy Gebben | 4204d0f | 2012-03-01 16:06:21 -0700 | [diff] [blame] | 2565 | 		goto error_pwrctrl_close; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2566 | 	} | 
| Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 2567 | 	/*acquire interrupt */ | 
 | 2568 | 	device->pwrctrl.interrupt_num = | 
 | 2569 | 		platform_get_irq_byname(pdev, device->pwrctrl.irq_name); | 
 | 2570 |  | 
 | 2571 | 	if (device->pwrctrl.interrupt_num <= 0) { | 
 | 2572 | 		KGSL_DRV_ERR(device, "platform_get_irq_byname failed: %d\n", | 
 | 2573 | 					 device->pwrctrl.interrupt_num); | 
 | 2574 | 		status = -EINVAL; | 
| Jeremy Gebben | 4204d0f | 2012-03-01 16:06:21 -0700 | [diff] [blame] | 2575 | 		goto error_pwrctrl_close; | 
| Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 2576 | 	} | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2577 |  | 
| Jeremy Gebben | 4204d0f | 2012-03-01 16:06:21 -0700 | [diff] [blame] | 2578 | 	status = devm_request_irq(device->dev, device->pwrctrl.interrupt_num, | 
 | 2579 | 				  kgsl_irq_handler, IRQF_TRIGGER_HIGH, | 
 | 2580 | 				  device->name, device); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2581 | 	if (status) { | 
 | 2582 | 		KGSL_DRV_ERR(device, "request_irq(%d) failed: %d\n", | 
 | 2583 | 			      device->pwrctrl.interrupt_num, status); | 
| Jeremy Gebben | 4204d0f | 2012-03-01 16:06:21 -0700 | [diff] [blame] | 2584 | 		goto error_pwrctrl_close; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2585 | 	} | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2586 | 	disable_irq(device->pwrctrl.interrupt_num); | 
 | 2587 |  | 
 | 2588 | 	KGSL_DRV_INFO(device, | 
| Jordan Crouse | 7501d45 | 2012-04-19 08:58:44 -0600 | [diff] [blame] | 2589 | 		"dev_id %d regs phys 0x%08lx size 0x%08x virt %p\n", | 
 | 2590 | 		device->id, device->reg_phys, device->reg_len, | 
 | 2591 | 		device->reg_virt); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2592 |  | 
| Michael Street | 8bacdd0 | 2012-01-05 14:55:01 -0800 | [diff] [blame] | 2593 | 	result = kgsl_drm_init(pdev); | 
 | 2594 | 	if (result) | 
| Jeremy Gebben | 4204d0f | 2012-03-01 16:06:21 -0700 | [diff] [blame] | 2595 | 		goto error_pwrctrl_close; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2596 |  | 
| Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 2597 | 	kgsl_cffdump_open(device->id); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2598 |  | 
| Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 2599 | 	setup_timer(&device->idle_timer, kgsl_timer, (unsigned long) device); | 
 | 2600 | 	status = kgsl_create_device_workqueue(device); | 
 | 2601 | 	if (status) | 
| Jeremy Gebben | 4204d0f | 2012-03-01 16:06:21 -0700 | [diff] [blame] | 2602 | 		goto error_pwrctrl_close; | 
| Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 2603 |  | 
 | 2604 | 	status = kgsl_mmu_init(device); | 
 | 2605 | 	if (status != 0) { | 
 | 2606 | 		KGSL_DRV_ERR(device, "kgsl_mmu_init failed %d\n", status); | 
 | 2607 | 		goto error_dest_work_q; | 
 | 2608 | 	} | 
 | 2609 |  | 
 | 2610 | 	status = kgsl_allocate_contiguous(&device->memstore, | 
| Richard Ruigrok | 2ad5e9d | 2012-06-14 14:22:05 -0700 | [diff] [blame] | 2611 | 		KGSL_MEMSTORE_SIZE); | 
| Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 2612 |  | 
 | 2613 | 	if (status != 0) { | 
 | 2614 | 		KGSL_DRV_ERR(device, "kgsl_allocate_contiguous failed %d\n", | 
 | 2615 | 				status); | 
 | 2616 | 		goto error_close_mmu; | 
 | 2617 | 	} | 
 | 2618 |  | 
| Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 2619 | 	pm_qos_add_request(&device->pm_qos_req_dma, PM_QOS_CPU_DMA_LATENCY, | 
 | 2620 | 				PM_QOS_DEFAULT_VALUE); | 
 | 2621 |  | 
 | 2622 | 	/* Initalize the snapshot engine */ | 
 | 2623 | 	kgsl_device_snapshot_init(device); | 
 | 2624 |  | 
 | 2625 | 	/* Initialize common sysfs entries */ | 
 | 2626 | 	kgsl_pwrctrl_init_sysfs(device); | 
 | 2627 |  | 
 | 2628 | 	return 0; | 
 | 2629 |  | 
 | 2630 | error_close_mmu: | 
 | 2631 | 	kgsl_mmu_close(device); | 
 | 2632 | error_dest_work_q: | 
 | 2633 | 	destroy_workqueue(device->work_queue); | 
 | 2634 | 	device->work_queue = NULL; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2635 | error_pwrctrl_close: | 
 | 2636 | 	kgsl_pwrctrl_close(device); | 
 | 2637 | error: | 
| Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 2638 | 	_unregister_device(device); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2639 | 	return status; | 
 | 2640 | } | 
 | 2641 | EXPORT_SYMBOL(kgsl_device_platform_probe); | 
 | 2642 |  | 
| Harsh Vardhan Dwivedi | 715fb83 | 2012-05-18 00:24:18 -0600 | [diff] [blame] | 2643 | int kgsl_postmortem_dump(struct kgsl_device *device, int manual) | 
 | 2644 | { | 
 | 2645 | 	bool saved_nap; | 
 | 2646 | 	struct kgsl_pwrctrl *pwr = &device->pwrctrl; | 
 | 2647 |  | 
 | 2648 | 	BUG_ON(device == NULL); | 
 | 2649 |  | 
 | 2650 | 	kgsl_cffdump_hang(device->id); | 
 | 2651 |  | 
 | 2652 | 	/* For a manual dump, make sure that the system is idle */ | 
 | 2653 |  | 
 | 2654 | 	if (manual) { | 
 | 2655 | 		if (device->active_cnt != 0) { | 
 | 2656 | 			mutex_unlock(&device->mutex); | 
 | 2657 | 			wait_for_completion(&device->suspend_gate); | 
 | 2658 | 			mutex_lock(&device->mutex); | 
 | 2659 | 		} | 
 | 2660 |  | 
 | 2661 | 		if (device->state == KGSL_STATE_ACTIVE) | 
| Jordan Crouse | a29a2e0 | 2012-08-14 09:09:23 -0600 | [diff] [blame] | 2662 | 			kgsl_idle(device); | 
| Harsh Vardhan Dwivedi | 715fb83 | 2012-05-18 00:24:18 -0600 | [diff] [blame] | 2663 |  | 
 | 2664 | 	} | 
 | 2665 | 	KGSL_LOG_DUMP(device, "|%s| Dump Started\n", device->name); | 
 | 2666 | 	KGSL_LOG_DUMP(device, "POWER: FLAGS = %08lX | ACTIVE POWERLEVEL = %08X", | 
 | 2667 | 			pwr->power_flags, pwr->active_pwrlevel); | 
 | 2668 |  | 
 | 2669 | 	KGSL_LOG_DUMP(device, "POWER: INTERVAL TIMEOUT = %08X ", | 
 | 2670 | 		pwr->interval_timeout); | 
 | 2671 |  | 
 | 2672 | 	KGSL_LOG_DUMP(device, "GRP_CLK = %lu ", | 
 | 2673 | 				  kgsl_get_clkrate(pwr->grp_clks[0])); | 
 | 2674 |  | 
 | 2675 | 	KGSL_LOG_DUMP(device, "BUS CLK = %lu ", | 
 | 2676 | 		kgsl_get_clkrate(pwr->ebi1_clk)); | 
 | 2677 |  | 
 | 2678 | 	/* Disable the idle timer so we don't get interrupted */ | 
 | 2679 | 	del_timer_sync(&device->idle_timer); | 
 | 2680 | 	mutex_unlock(&device->mutex); | 
 | 2681 | 	flush_workqueue(device->work_queue); | 
 | 2682 | 	mutex_lock(&device->mutex); | 
 | 2683 |  | 
 | 2684 | 	/* Turn off napping to make sure we have the clocks full | 
 | 2685 | 	   attention through the following process */ | 
 | 2686 | 	saved_nap = device->pwrctrl.nap_allowed; | 
 | 2687 | 	device->pwrctrl.nap_allowed = false; | 
 | 2688 |  | 
 | 2689 | 	/* Force on the clocks */ | 
 | 2690 | 	kgsl_pwrctrl_wake(device); | 
 | 2691 |  | 
 | 2692 | 	/* Disable the irq */ | 
 | 2693 | 	kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF); | 
 | 2694 |  | 
 | 2695 | 	/*Call the device specific postmortem dump function*/ | 
 | 2696 | 	device->ftbl->postmortem_dump(device, manual); | 
 | 2697 |  | 
 | 2698 | 	/* Restore nap mode */ | 
 | 2699 | 	device->pwrctrl.nap_allowed = saved_nap; | 
 | 2700 |  | 
 | 2701 | 	/* On a manual trigger, turn on the interrupts and put | 
 | 2702 | 	   the clocks to sleep.  They will recover themselves | 
 | 2703 | 	   on the next event.  For a hang, leave things as they | 
 | 2704 | 	   are until recovery kicks in. */ | 
 | 2705 |  | 
 | 2706 | 	if (manual) { | 
 | 2707 | 		kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_ON); | 
 | 2708 |  | 
 | 2709 | 		/* try to go into a sleep mode until the next event */ | 
 | 2710 | 		kgsl_pwrctrl_request_state(device, KGSL_STATE_SLEEP); | 
 | 2711 | 		kgsl_pwrctrl_sleep(device); | 
 | 2712 | 	} | 
 | 2713 |  | 
 | 2714 | 	KGSL_LOG_DUMP(device, "|%s| Dump Finished\n", device->name); | 
 | 2715 |  | 
 | 2716 | 	return 0; | 
 | 2717 | } | 
 | 2718 | EXPORT_SYMBOL(kgsl_postmortem_dump); | 
 | 2719 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2720 | void kgsl_device_platform_remove(struct kgsl_device *device) | 
 | 2721 | { | 
| Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 2722 | 	kgsl_device_snapshot_close(device); | 
 | 2723 |  | 
 | 2724 | 	kgsl_cffdump_close(device->id); | 
 | 2725 | 	kgsl_pwrctrl_uninit_sysfs(device); | 
 | 2726 |  | 
| Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 2727 | 	pm_qos_remove_request(&device->pm_qos_req_dma); | 
 | 2728 |  | 
 | 2729 | 	idr_destroy(&device->context_idr); | 
 | 2730 |  | 
 | 2731 | 	kgsl_sharedmem_free(&device->memstore); | 
 | 2732 |  | 
 | 2733 | 	kgsl_mmu_close(device); | 
 | 2734 |  | 
 | 2735 | 	if (device->work_queue) { | 
 | 2736 | 		destroy_workqueue(device->work_queue); | 
 | 2737 | 		device->work_queue = NULL; | 
 | 2738 | 	} | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2739 | 	kgsl_pwrctrl_close(device); | 
 | 2740 |  | 
| Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 2741 | 	_unregister_device(device); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2742 | } | 
 | 2743 | EXPORT_SYMBOL(kgsl_device_platform_remove); | 
 | 2744 |  | 
 | 2745 | static int __devinit | 
 | 2746 | kgsl_ptdata_init(void) | 
 | 2747 | { | 
| Jordan Crouse | 6d76c4d | 2012-03-26 09:50:43 -0600 | [diff] [blame] | 2748 | 	kgsl_driver.ptpool = kgsl_mmu_ptpool_init(kgsl_pagetable_count); | 
 | 2749 |  | 
| Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 2750 | 	if (!kgsl_driver.ptpool) | 
 | 2751 | 		return -ENOMEM; | 
 | 2752 | 	return 0; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2753 | } | 
 | 2754 |  | 
 | 2755 | static void kgsl_core_exit(void) | 
 | 2756 | { | 
| Ranjhith Kalisamy | 4ad59e9 | 2012-05-31 19:15:11 +0530 | [diff] [blame] | 2757 | 	kgsl_mmu_ptpool_destroy(kgsl_driver.ptpool); | 
| Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 2758 | 	kgsl_driver.ptpool = NULL; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2759 |  | 
| Ranjhith Kalisamy | dad9df5 | 2012-06-01 17:05:13 +0530 | [diff] [blame] | 2760 | 	kgsl_drm_exit(); | 
 | 2761 | 	kgsl_cffdump_destroy(); | 
 | 2762 | 	kgsl_core_debugfs_close(); | 
| Ranjhith Kalisamy | dad9df5 | 2012-06-01 17:05:13 +0530 | [diff] [blame] | 2763 |  | 
| Harsh Vardhan Dwivedi | efa6b01 | 2012-06-15 13:02:27 -0600 | [diff] [blame] | 2764 | 	/* | 
 | 2765 | 	 * We call kgsl_sharedmem_uninit_sysfs() and device_unregister() | 
 | 2766 | 	 * only if kgsl_driver.virtdev has been populated. | 
 | 2767 | 	 * We check at least one member of kgsl_driver.virtdev to | 
 | 2768 | 	 * see if it is not NULL (and thus, has been populated). | 
 | 2769 | 	 */ | 
 | 2770 | 	if (kgsl_driver.virtdev.class) { | 
 | 2771 | 		kgsl_sharedmem_uninit_sysfs(); | 
 | 2772 | 		device_unregister(&kgsl_driver.virtdev); | 
 | 2773 | 	} | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2774 |  | 
 | 2775 | 	if (kgsl_driver.class) { | 
 | 2776 | 		class_destroy(kgsl_driver.class); | 
 | 2777 | 		kgsl_driver.class = NULL; | 
 | 2778 | 	} | 
 | 2779 |  | 
| Ranjhith Kalisamy | dad9df5 | 2012-06-01 17:05:13 +0530 | [diff] [blame] | 2780 | 	unregister_chrdev_region(kgsl_driver.major, KGSL_DEVICE_MAX); | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2781 | } | 
 | 2782 |  | 
 | 2783 | static int __init kgsl_core_init(void) | 
 | 2784 | { | 
 | 2785 | 	int result = 0; | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2786 | 	/* alloc major and minor device numbers */ | 
 | 2787 | 	result = alloc_chrdev_region(&kgsl_driver.major, 0, KGSL_DEVICE_MAX, | 
 | 2788 | 				  KGSL_NAME); | 
 | 2789 | 	if (result < 0) { | 
 | 2790 | 		KGSL_CORE_ERR("alloc_chrdev_region failed err = %d\n", result); | 
 | 2791 | 		goto err; | 
 | 2792 | 	} | 
 | 2793 |  | 
 | 2794 | 	cdev_init(&kgsl_driver.cdev, &kgsl_fops); | 
 | 2795 | 	kgsl_driver.cdev.owner = THIS_MODULE; | 
 | 2796 | 	kgsl_driver.cdev.ops = &kgsl_fops; | 
 | 2797 | 	result = cdev_add(&kgsl_driver.cdev, MKDEV(MAJOR(kgsl_driver.major), 0), | 
 | 2798 | 		       KGSL_DEVICE_MAX); | 
 | 2799 |  | 
 | 2800 | 	if (result) { | 
 | 2801 | 		KGSL_CORE_ERR("kgsl: cdev_add() failed, dev_num= %d," | 
 | 2802 | 			     " result= %d\n", kgsl_driver.major, result); | 
 | 2803 | 		goto err; | 
 | 2804 | 	} | 
 | 2805 |  | 
 | 2806 | 	kgsl_driver.class = class_create(THIS_MODULE, KGSL_NAME); | 
 | 2807 |  | 
 | 2808 | 	if (IS_ERR(kgsl_driver.class)) { | 
 | 2809 | 		result = PTR_ERR(kgsl_driver.class); | 
 | 2810 | 		KGSL_CORE_ERR("failed to create class %s", KGSL_NAME); | 
 | 2811 | 		goto err; | 
 | 2812 | 	} | 
 | 2813 |  | 
 | 2814 | 	/* Make a virtual device for managing core related things | 
 | 2815 | 	   in sysfs */ | 
 | 2816 | 	kgsl_driver.virtdev.class = kgsl_driver.class; | 
 | 2817 | 	dev_set_name(&kgsl_driver.virtdev, "kgsl"); | 
 | 2818 | 	result = device_register(&kgsl_driver.virtdev); | 
 | 2819 | 	if (result) { | 
 | 2820 | 		KGSL_CORE_ERR("driver_register failed\n"); | 
 | 2821 | 		goto err; | 
 | 2822 | 	} | 
 | 2823 |  | 
 | 2824 | 	/* Make kobjects in the virtual device for storing statistics */ | 
 | 2825 |  | 
 | 2826 | 	kgsl_driver.ptkobj = | 
 | 2827 | 	  kobject_create_and_add("pagetables", | 
 | 2828 | 				 &kgsl_driver.virtdev.kobj); | 
 | 2829 |  | 
 | 2830 | 	kgsl_driver.prockobj = | 
 | 2831 | 		kobject_create_and_add("proc", | 
 | 2832 | 				       &kgsl_driver.virtdev.kobj); | 
 | 2833 |  | 
 | 2834 | 	kgsl_core_debugfs_init(); | 
 | 2835 |  | 
 | 2836 | 	kgsl_sharedmem_init_sysfs(); | 
 | 2837 | 	kgsl_cffdump_init(); | 
 | 2838 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2839 | 	INIT_LIST_HEAD(&kgsl_driver.process_list); | 
 | 2840 |  | 
| Shubhraprakash Das | 767fdda | 2011-08-15 15:49:45 -0600 | [diff] [blame] | 2841 | 	INIT_LIST_HEAD(&kgsl_driver.pagetable_list); | 
 | 2842 |  | 
 | 2843 | 	kgsl_mmu_set_mmutype(ksgl_mmu_type); | 
 | 2844 |  | 
 | 2845 | 	if (KGSL_MMU_TYPE_GPU == kgsl_mmu_get_mmutype()) { | 
 | 2846 | 		result = kgsl_ptdata_init(); | 
 | 2847 | 		if (result) | 
 | 2848 | 			goto err; | 
 | 2849 | 	} | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2850 |  | 
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2851 | 	return 0; | 
 | 2852 |  | 
 | 2853 | err: | 
 | 2854 | 	kgsl_core_exit(); | 
 | 2855 | 	return result; | 
 | 2856 | } | 
 | 2857 |  | 
 | 2858 | module_init(kgsl_core_init); | 
 | 2859 | module_exit(kgsl_core_exit); | 
 | 2860 |  | 
 | 2861 | MODULE_AUTHOR("Qualcomm Innovation Center, Inc."); | 
 | 2862 | MODULE_DESCRIPTION("MSM GPU driver"); | 
 | 2863 | MODULE_LICENSE("GPL"); |