blob: c60a071c05528dd9e3a1c01d8b4099069336d23c [file] [log] [blame]
Shrenuj Bansala419c792016-10-20 14:05:11 -07001/* Copyright (c) 2008-2017, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13#ifndef __KGSL_H
14#define __KGSL_H
15
16#include <linux/types.h>
17#include <linux/slab.h>
18#include <linux/vmalloc.h>
19#include <linux/msm_kgsl.h>
20#include <linux/platform_device.h>
21#include <linux/clk.h>
22#include <linux/interrupt.h>
23#include <linux/mutex.h>
24#include <linux/cdev.h>
25#include <linux/regulator/consumer.h>
26#include <linux/mm.h>
27#include <linux/uaccess.h>
28#include <asm/cacheflush.h>
29
30/*
31 * --- kgsl drawobj flags ---
32 * These flags are same as --- drawobj flags ---
33 * but renamed to reflect that cmdbatch is renamed to drawobj.
34 */
35#define KGSL_DRAWOBJ_MEMLIST KGSL_CMDBATCH_MEMLIST
36#define KGSL_DRAWOBJ_MARKER KGSL_CMDBATCH_MARKER
37#define KGSL_DRAWOBJ_SUBMIT_IB_LIST KGSL_CMDBATCH_SUBMIT_IB_LIST
38#define KGSL_DRAWOBJ_CTX_SWITCH KGSL_CMDBATCH_CTX_SWITCH
39#define KGSL_DRAWOBJ_PROFILING KGSL_CMDBATCH_PROFILING
40#define KGSL_DRAWOBJ_PROFILING_KTIME KGSL_CMDBATCH_PROFILING_KTIME
41#define KGSL_DRAWOBJ_END_OF_FRAME KGSL_CMDBATCH_END_OF_FRAME
42#define KGSL_DRAWOBJ_SYNC KGSL_CMDBATCH_SYNC
43#define KGSL_DRAWOBJ_PWR_CONSTRAINT KGSL_CMDBATCH_PWR_CONSTRAINT
44#define KGSL_DRAWOBJ_SPARSE KGSL_CMDBATCH_SPARSE
45
46#define kgsl_drawobj_profiling_buffer kgsl_cmdbatch_profiling_buffer
47
48
49/* The number of memstore arrays limits the number of contexts allowed.
50 * If more contexts are needed, update multiple for MEMSTORE_SIZE
51 */
52#define KGSL_MEMSTORE_SIZE ((int)(PAGE_SIZE * 2))
53#define KGSL_MEMSTORE_GLOBAL (0)
54#define KGSL_PRIORITY_MAX_RB_LEVELS 4
55#define KGSL_MEMSTORE_MAX (KGSL_MEMSTORE_SIZE / \
56 sizeof(struct kgsl_devmemstore) - 1 - KGSL_PRIORITY_MAX_RB_LEVELS)
57
58#define MEMSTORE_RB_OFFSET(rb, field) \
59 KGSL_MEMSTORE_OFFSET(((rb)->id + KGSL_MEMSTORE_MAX), field)
60
61#define MEMSTORE_ID_GPU_ADDR(dev, iter, field) \
62 ((dev)->memstore.gpuaddr + KGSL_MEMSTORE_OFFSET(iter, field))
63
64#define MEMSTORE_RB_GPU_ADDR(dev, rb, field) \
65 ((dev)->memstore.gpuaddr + \
66 KGSL_MEMSTORE_OFFSET(((rb)->id + KGSL_MEMSTORE_MAX), field))
67
68/*
69 * SCRATCH MEMORY: The scratch memory is one page worth of data that
70 * is mapped into the GPU. This allows for some 'shared' data between
71 * the GPU and CPU. For example, it will be used by the GPU to write
72 * each updated RPTR for each RB.
73 *
74 * Used Data:
75 * Offset: Length(bytes): What
76 * 0x0: 4 * KGSL_PRIORITY_MAX_RB_LEVELS: RB0 RPTR
77 */
78
79/* Shadow global helpers */
80#define SCRATCH_RPTR_OFFSET(id) ((id) * sizeof(unsigned int))
81#define SCRATCH_RPTR_GPU_ADDR(dev, id) \
82 ((dev)->scratch.gpuaddr + SCRATCH_RPTR_OFFSET(id))
83
84/* Timestamp window used to detect rollovers (half of integer range) */
85#define KGSL_TIMESTAMP_WINDOW 0x80000000
86
87/*
88 * A macro for memory statistics - add the new size to the stat and if
89 * the statisic is greater then _max, set _max
90 */
91static inline void KGSL_STATS_ADD(uint64_t size, atomic_long_t *stat,
92 atomic_long_t *max)
93{
94 uint64_t ret = atomic_long_add_return(size, stat);
95
96 if (ret > atomic_long_read(max))
97 atomic_long_set(max, ret);
98}
99
100#define KGSL_MAX_NUMIBS 100000
101#define KGSL_MAX_SYNCPOINTS 32
102
103struct kgsl_device;
104struct kgsl_context;
105
106/**
107 * struct kgsl_driver - main container for global KGSL things
108 * @cdev: Character device struct
109 * @major: Major ID for the KGSL device
110 * @class: Pointer to the class struct for the core KGSL sysfs entries
111 * @virtdev: Virtual device for managing the core
112 * @ptkobj: kobject for storing the pagetable statistics
113 * @prockobj: kobject for storing the process statistics
114 * @devp: Array of pointers to the individual KGSL device structs
115 * @process_list: List of open processes
116 * @pagetable_list: LIst of open pagetables
117 * @ptlock: Lock for accessing the pagetable list
118 * @process_mutex: Mutex for accessing the process list
119 * @devlock: Mutex protecting the device list
120 * @stats: Struct containing atomic memory statistics
121 * @full_cache_threshold: the threshold that triggers a full cache flush
122 * @workqueue: Pointer to a single threaded workqueue
123 * @mem_workqueue: Pointer to a workqueue for deferring memory entries
124 */
125struct kgsl_driver {
126 struct cdev cdev;
127 dev_t major;
128 struct class *class;
129 struct device virtdev;
130 struct kobject *ptkobj;
131 struct kobject *prockobj;
132 struct kgsl_device *devp[KGSL_DEVICE_MAX];
133 struct list_head process_list;
134 struct list_head pagetable_list;
135 spinlock_t ptlock;
136 struct mutex process_mutex;
137 struct mutex devlock;
138 struct {
139 atomic_long_t vmalloc;
140 atomic_long_t vmalloc_max;
141 atomic_long_t page_alloc;
142 atomic_long_t page_alloc_max;
143 atomic_long_t coherent;
144 atomic_long_t coherent_max;
145 atomic_long_t secure;
146 atomic_long_t secure_max;
147 atomic_long_t mapped;
148 atomic_long_t mapped_max;
149 } stats;
150 unsigned int full_cache_threshold;
151 struct workqueue_struct *workqueue;
152 struct workqueue_struct *mem_workqueue;
153};
154
155extern struct kgsl_driver kgsl_driver;
156extern struct mutex kgsl_mmu_sync;
157
158struct kgsl_pagetable;
159struct kgsl_memdesc;
160
161struct kgsl_memdesc_ops {
162 unsigned int vmflags;
163 int (*vmfault)(struct kgsl_memdesc *, struct vm_area_struct *,
164 struct vm_fault *);
165 void (*free)(struct kgsl_memdesc *memdesc);
166 int (*map_kernel)(struct kgsl_memdesc *);
167 void (*unmap_kernel)(struct kgsl_memdesc *);
168};
169
170/* Internal definitions for memdesc->priv */
171#define KGSL_MEMDESC_GUARD_PAGE BIT(0)
172/* Set if the memdesc is mapped into all pagetables */
173#define KGSL_MEMDESC_GLOBAL BIT(1)
174/* The memdesc is frozen during a snapshot */
175#define KGSL_MEMDESC_FROZEN BIT(2)
176/* The memdesc is mapped into a pagetable */
177#define KGSL_MEMDESC_MAPPED BIT(3)
178/* The memdesc is secured for content protection */
179#define KGSL_MEMDESC_SECURE BIT(4)
180/* Memory is accessible in privileged mode */
181#define KGSL_MEMDESC_PRIVILEGED BIT(6)
182/* The memdesc is TZ locked content protection */
183#define KGSL_MEMDESC_TZ_LOCKED BIT(7)
184/* The memdesc is allocated through contiguous memory */
185#define KGSL_MEMDESC_CONTIG BIT(8)
186
187/**
188 * struct kgsl_memdesc - GPU memory object descriptor
189 * @pagetable: Pointer to the pagetable that the object is mapped in
190 * @hostptr: Kernel virtual address
191 * @hostptr_count: Number of threads using hostptr
192 * @useraddr: User virtual address (if applicable)
193 * @gpuaddr: GPU virtual address
194 * @physaddr: Physical address of the memory object
195 * @size: Size of the memory object
196 * @mapsize: Size of memory mapped in userspace
197 * @priv: Internal flags and settings
198 * @sgt: Scatter gather table for allocated pages
199 * @ops: Function hooks for the memdesc memory type
200 * @flags: Flags set from userspace
201 * @dev: Pointer to the struct device that owns this memory
202 * @attrs: dma attributes for this memory
203 * @pages: An array of pointers to allocated pages
204 * @page_count: Total number of pages allocated
205 * @cur_bindings: Number of sparse pages actively bound
206 */
207struct kgsl_memdesc {
208 struct kgsl_pagetable *pagetable;
209 void *hostptr;
210 unsigned int hostptr_count;
211 unsigned long useraddr;
212 uint64_t gpuaddr;
213 phys_addr_t physaddr;
214 uint64_t size;
215 uint64_t mapsize;
216 unsigned int priv;
217 struct sg_table *sgt;
218 struct kgsl_memdesc_ops *ops;
219 uint64_t flags;
220 struct device *dev;
221 unsigned long attrs;
222 struct page **pages;
223 unsigned int page_count;
224 unsigned int cur_bindings;
225};
226
227/*
228 * List of different memory entry types. The usermem enum
229 * starts at 0, which we use for allocated memory, so 1 is
230 * added to the enum values.
231 */
232#define KGSL_MEM_ENTRY_KERNEL 0
233#define KGSL_MEM_ENTRY_USER (KGSL_USER_MEM_TYPE_ADDR + 1)
234#define KGSL_MEM_ENTRY_ION (KGSL_USER_MEM_TYPE_ION + 1)
235#define KGSL_MEM_ENTRY_MAX (KGSL_USER_MEM_TYPE_MAX + 1)
236
237/* symbolic table for trace and debugfs */
238#define KGSL_MEM_TYPES \
239 { KGSL_MEM_ENTRY_KERNEL, "gpumem" }, \
240 { KGSL_MEM_ENTRY_USER, "usermem" }, \
241 { KGSL_MEM_ENTRY_ION, "ion" }
242
243/*
244 * struct kgsl_mem_entry - a userspace memory allocation
245 * @refcount: reference count. Currently userspace can only
246 * hold a single reference count, but the kernel may hold more.
247 * @memdesc: description of the memory
248 * @priv_data: type-specific data, such as the dma-buf attachment pointer.
249 * @node: rb_node for the gpu address lookup rb tree
250 * @id: idr index for this entry, can be used to find memory that does not have
251 * a valid GPU address.
252 * @priv: back pointer to the process that owns this memory
253 * @pending_free: if !0, userspace requested that his memory be freed, but there
254 * are still references to it.
255 * @dev_priv: back pointer to the device file that created this entry.
256 * @metadata: String containing user specified metadata for the entry
257 * @work: Work struct used to schedule a kgsl_mem_entry_put in atomic contexts
258 * @bind_lock: Lock for sparse memory bindings
259 * @bind_tree: RB Tree for sparse memory bindings
260 */
261struct kgsl_mem_entry {
262 struct kref refcount;
263 struct kgsl_memdesc memdesc;
264 void *priv_data;
265 struct rb_node node;
266 unsigned int id;
267 struct kgsl_process_private *priv;
268 int pending_free;
269 char metadata[KGSL_GPUOBJ_ALLOC_METADATA_MAX + 1];
270 struct work_struct work;
271 spinlock_t bind_lock;
272 struct rb_root bind_tree;
273};
274
275struct kgsl_device_private;
276struct kgsl_event_group;
277
278typedef void (*kgsl_event_func)(struct kgsl_device *, struct kgsl_event_group *,
279 void *, int);
280
281/**
282 * struct kgsl_event - KGSL GPU timestamp event
283 * @device: Pointer to the KGSL device that owns the event
284 * @context: Pointer to the context that owns the event
285 * @timestamp: Timestamp for the event to expire
286 * @func: Callback function for for the event when it expires
287 * @priv: Private data passed to the callback function
288 * @node: List node for the kgsl_event_group list
289 * @created: Jiffies when the event was created
290 * @work: Work struct for dispatching the callback
291 * @result: KGSL event result type to pass to the callback
292 * group: The event group this event belongs to
293 */
294struct kgsl_event {
295 struct kgsl_device *device;
296 struct kgsl_context *context;
297 unsigned int timestamp;
298 kgsl_event_func func;
299 void *priv;
300 struct list_head node;
301 unsigned int created;
302 struct work_struct work;
303 int result;
304 struct kgsl_event_group *group;
305};
306
307typedef int (*readtimestamp_func)(struct kgsl_device *, void *,
308 enum kgsl_timestamp_type, unsigned int *);
309
310/**
311 * struct event_group - A list of GPU events
312 * @context: Pointer to the active context for the events
313 * @lock: Spinlock for protecting the list
314 * @events: List of active GPU events
315 * @group: Node for the master group list
316 * @processed: Last processed timestamp
317 * @name: String name for the group (for the debugfs file)
318 * @readtimestamp: Function pointer to read a timestamp
319 * @priv: Priv member to pass to the readtimestamp function
320 */
321struct kgsl_event_group {
322 struct kgsl_context *context;
323 spinlock_t lock;
324 struct list_head events;
325 struct list_head group;
326 unsigned int processed;
327 char name[64];
328 readtimestamp_func readtimestamp;
329 void *priv;
330};
331
332/**
333 * struct kgsl_protected_registers - Protected register range
334 * @base: Offset of the range to be protected
335 * @range: Range (# of registers = 2 ** range)
336 */
337struct kgsl_protected_registers {
338 unsigned int base;
339 int range;
340};
341
342/**
343 * struct sparse_bind_object - Bind metadata
344 * @node: Node for the rb tree
345 * @p_memdesc: Physical memdesc bound to
346 * @v_off: Offset of bind in the virtual entry
347 * @p_off: Offset of bind in the physical memdesc
348 * @size: Size of the bind
349 * @flags: Flags for the bind
350 */
351struct sparse_bind_object {
352 struct rb_node node;
353 struct kgsl_memdesc *p_memdesc;
354 uint64_t v_off;
355 uint64_t p_off;
356 uint64_t size;
357 uint64_t flags;
358};
359
360long kgsl_ioctl_device_getproperty(struct kgsl_device_private *dev_priv,
361 unsigned int cmd, void *data);
362long kgsl_ioctl_device_setproperty(struct kgsl_device_private *dev_priv,
363 unsigned int cmd, void *data);
364long kgsl_ioctl_device_waittimestamp_ctxtid(struct kgsl_device_private
365 *dev_priv, unsigned int cmd, void *data);
366long kgsl_ioctl_rb_issueibcmds(struct kgsl_device_private *dev_priv,
367 unsigned int cmd, void *data);
368long kgsl_ioctl_submit_commands(struct kgsl_device_private *dev_priv,
369 unsigned int cmd, void *data);
370long kgsl_ioctl_cmdstream_readtimestamp_ctxtid(struct kgsl_device_private
371 *dev_priv, unsigned int cmd,
372 void *data);
373long kgsl_ioctl_cmdstream_freememontimestamp_ctxtid(
374 struct kgsl_device_private
375 *dev_priv, unsigned int cmd,
376 void *data);
377long kgsl_ioctl_drawctxt_create(struct kgsl_device_private *dev_priv,
378 unsigned int cmd, void *data);
379long kgsl_ioctl_drawctxt_destroy(struct kgsl_device_private *dev_priv,
380 unsigned int cmd, void *data);
381long kgsl_ioctl_sharedmem_free(struct kgsl_device_private *dev_priv,
382 unsigned int cmd, void *data);
383long kgsl_ioctl_gpumem_free_id(struct kgsl_device_private *dev_priv,
384 unsigned int cmd, void *data);
385long kgsl_ioctl_map_user_mem(struct kgsl_device_private *dev_priv,
386 unsigned int cmd, void *data);
387long kgsl_ioctl_gpumem_sync_cache(struct kgsl_device_private *dev_priv,
388 unsigned int cmd, void *data);
389long kgsl_ioctl_gpumem_sync_cache_bulk(struct kgsl_device_private *dev_priv,
390 unsigned int cmd, void *data);
391long kgsl_ioctl_sharedmem_flush_cache(struct kgsl_device_private *dev_priv,
392 unsigned int cmd, void *data);
393long kgsl_ioctl_gpumem_alloc(struct kgsl_device_private *dev_priv,
394 unsigned int cmd, void *data);
395long kgsl_ioctl_gpumem_alloc_id(struct kgsl_device_private *dev_priv,
396 unsigned int cmd, void *data);
397long kgsl_ioctl_gpumem_get_info(struct kgsl_device_private *dev_priv,
398 unsigned int cmd, void *data);
399long kgsl_ioctl_timestamp_event(struct kgsl_device_private *dev_priv,
400 unsigned int cmd, void *data);
401long kgsl_ioctl_gpuobj_alloc(struct kgsl_device_private *dev_priv,
402 unsigned int cmd, void *data);
403long kgsl_ioctl_gpuobj_free(struct kgsl_device_private *dev_priv,
404 unsigned int cmd, void *data);
405long kgsl_ioctl_gpuobj_info(struct kgsl_device_private *dev_priv,
406 unsigned int cmd, void *data);
407long kgsl_ioctl_gpuobj_import(struct kgsl_device_private *dev_priv,
408 unsigned int cmd, void *data);
409long kgsl_ioctl_gpuobj_sync(struct kgsl_device_private *dev_priv,
410 unsigned int cmd, void *data);
411long kgsl_ioctl_gpu_command(struct kgsl_device_private *dev_priv,
412 unsigned int cmd, void *data);
413long kgsl_ioctl_gpuobj_set_info(struct kgsl_device_private *dev_priv,
414 unsigned int cmd, void *data);
415
416long kgsl_ioctl_sparse_phys_alloc(struct kgsl_device_private *dev_priv,
417 unsigned int cmd, void *data);
418long kgsl_ioctl_sparse_phys_free(struct kgsl_device_private *dev_priv,
419 unsigned int cmd, void *data);
420long kgsl_ioctl_sparse_virt_alloc(struct kgsl_device_private *dev_priv,
421 unsigned int cmd, void *data);
422long kgsl_ioctl_sparse_virt_free(struct kgsl_device_private *dev_priv,
423 unsigned int cmd, void *data);
424long kgsl_ioctl_sparse_bind(struct kgsl_device_private *dev_priv,
425 unsigned int cmd, void *data);
426long kgsl_ioctl_sparse_unbind(struct kgsl_device_private *dev_priv,
427 unsigned int cmd, void *data);
428
429void kgsl_mem_entry_destroy(struct kref *kref);
430
431void kgsl_get_egl_counts(struct kgsl_mem_entry *entry,
432 int *egl_surface_count, int *egl_image_count);
433
434struct kgsl_mem_entry * __must_check
435kgsl_sharedmem_find(struct kgsl_process_private *private, uint64_t gpuaddr);
436
437struct kgsl_mem_entry * __must_check
438kgsl_sharedmem_find_id(struct kgsl_process_private *process, unsigned int id);
439
440extern const struct dev_pm_ops kgsl_pm_ops;
441
442int kgsl_suspend_driver(struct platform_device *pdev, pm_message_t state);
443int kgsl_resume_driver(struct platform_device *pdev);
444
445static inline int kgsl_gpuaddr_in_memdesc(const struct kgsl_memdesc *memdesc,
446 uint64_t gpuaddr, uint64_t size)
447{
448 /* set a minimum size to search for */
449 if (!size)
450 size = 1;
451
452 /* don't overflow */
453 if (size > U64_MAX - gpuaddr)
454 return 0;
455
456 if (gpuaddr >= memdesc->gpuaddr &&
457 ((gpuaddr + size) <= (memdesc->gpuaddr + memdesc->size))) {
458 return 1;
459 }
460 return 0;
461}
462
463static inline void *kgsl_memdesc_map(struct kgsl_memdesc *memdesc)
464{
465 if (memdesc->ops && memdesc->ops->map_kernel)
466 memdesc->ops->map_kernel(memdesc);
467
468 return memdesc->hostptr;
469}
470
471static inline void kgsl_memdesc_unmap(struct kgsl_memdesc *memdesc)
472{
473 if (memdesc->ops && memdesc->ops->unmap_kernel)
474 memdesc->ops->unmap_kernel(memdesc);
475}
476
477static inline void *kgsl_gpuaddr_to_vaddr(struct kgsl_memdesc *memdesc,
478 uint64_t gpuaddr)
479{
480 void *hostptr = NULL;
481
482 if ((gpuaddr >= memdesc->gpuaddr) &&
483 (gpuaddr < (memdesc->gpuaddr + memdesc->size)))
484 hostptr = kgsl_memdesc_map(memdesc);
485
486 return hostptr != NULL ? hostptr + (gpuaddr - memdesc->gpuaddr) : NULL;
487}
488
489static inline int timestamp_cmp(unsigned int a, unsigned int b)
490{
491 /* check for equal */
492 if (a == b)
493 return 0;
494
495 /* check for greater-than for non-rollover case */
496 if ((a > b) && (a - b < KGSL_TIMESTAMP_WINDOW))
497 return 1;
498
499 /* check for greater-than for rollover case
500 * note that <= is required to ensure that consistent
501 * results are returned for values whose difference is
502 * equal to the window size
503 */
504 a += KGSL_TIMESTAMP_WINDOW;
505 b += KGSL_TIMESTAMP_WINDOW;
506 return ((a > b) && (a - b <= KGSL_TIMESTAMP_WINDOW)) ? 1 : -1;
507}
508
509/**
510 * kgsl_schedule_work() - Schedule a work item on the KGSL workqueue
511 * @work: work item to schedule
512 */
513static inline void kgsl_schedule_work(struct work_struct *work)
514{
515 queue_work(kgsl_driver.workqueue, work);
516}
517
518static inline int
519kgsl_mem_entry_get(struct kgsl_mem_entry *entry)
520{
521 if (entry)
522 return kref_get_unless_zero(&entry->refcount);
523 return 0;
524}
525
526static inline void
527kgsl_mem_entry_put(struct kgsl_mem_entry *entry)
528{
529 if (entry)
530 kref_put(&entry->refcount, kgsl_mem_entry_destroy);
531}
532
533/*
534 * kgsl_addr_range_overlap() - Checks if 2 ranges overlap
535 * @gpuaddr1: Start of first address range
536 * @size1: Size of first address range
537 * @gpuaddr2: Start of second address range
538 * @size2: Size of second address range
539 *
540 * Function returns true if the 2 given address ranges overlap
541 * else false
542 */
543static inline bool kgsl_addr_range_overlap(uint64_t gpuaddr1,
544 uint64_t size1, uint64_t gpuaddr2, uint64_t size2)
545{
546 if ((size1 > (U64_MAX - gpuaddr1)) || (size2 > (U64_MAX - gpuaddr2)))
547 return false;
548 return !(((gpuaddr1 + size1) <= gpuaddr2) ||
549 (gpuaddr1 >= (gpuaddr2 + size2)));
550}
551
552/**
553 * kgsl_malloc() - Use either kzalloc or vmalloc to allocate memory
554 * @size: Size of the desired allocation
555 *
556 * Allocate a block of memory for the driver - if it is small try to allocate it
557 * from kmalloc (fast!) otherwise we need to go with vmalloc (safe!)
558 */
559static inline void *kgsl_malloc(size_t size)
560{
561 if (size <= PAGE_SIZE)
562 return kzalloc(size, GFP_KERNEL);
563
564 return vmalloc(size);
565}
566
567/**
568 * kgsl_free() - Free memory allocated by kgsl_malloc()
569 * @ptr: Pointer to the memory to free
570 *
571 * Free the memory be it in vmalloc or kmalloc space
572 */
573static inline void kgsl_free(void *ptr)
574{
575 if (ptr != NULL && is_vmalloc_addr(ptr))
576 return vfree(ptr);
577
578 kfree(ptr);
579}
580
581static inline int _copy_from_user(void *dest, void __user *src,
582 unsigned int ksize, unsigned int usize)
583{
584 unsigned int copy = ksize < usize ? ksize : usize;
585
586 if (copy == 0)
587 return -EINVAL;
588
589 return copy_from_user(dest, src, copy) ? -EFAULT : 0;
590}
591
592static inline void __user *to_user_ptr(uint64_t address)
593{
594 return (void __user *)(uintptr_t)address;
595}
596
597static inline void kgsl_gpu_sysfs_add_link(struct kobject *dst,
598 struct kobject *src, const char *src_name,
599 const char *dst_name)
600{
601 struct kernfs_node *old;
602
603 if (dst == NULL || src == NULL)
604 return;
605
606 old = sysfs_get_dirent(src->sd, src_name);
607 if (IS_ERR_OR_NULL(old))
608 return;
609
610 kernfs_create_link(dst->sd, dst_name, old);
611}
612#endif /* __KGSL_H */