Home | History | Annotate | Download | only in linux
      1 /*
      2  * drivers/staging/android/uapi/ion.h
      3  *
      4  * Copyright (C) 2011 Google, Inc.
      5  *
      6  * This software is licensed under the terms of the GNU General Public
      7  * License version 2, as published by the Free Software Foundation, and
      8  * may be copied, distributed, and modified under those terms.
      9  *
     10  * This program is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13  * GNU General Public License for more details.
     14  *
     15  */
     16 
     17 #ifndef _UAPI_LINUX_ION_H
     18 #define _UAPI_LINUX_ION_H
     19 
     20 #include <linux/ioctl.h>
     21 #include <linux/types.h>
     22 
     23 /**
     24  * enum ion_heap_types - list of all possible types of heaps
     25  * @ION_HEAP_TYPE_SYSTEM:	 memory allocated via vmalloc
     26  * @ION_HEAP_TYPE_SYSTEM_CONTIG: memory allocated via kmalloc
     27  * @ION_HEAP_TYPE_CARVEOUT:	 memory allocated from a prereserved
     28  *				 carveout heap, allocations are physically
     29  *				 contiguous
     30  * @ION_HEAP_TYPE_DMA:		 memory allocated via DMA API
     31  * @ION_NUM_HEAPS:		 helper for iterating over heaps, a bit mask
     32  *				 is used to identify the heaps, so only 32
     33  *				 total heap types are supported
     34  */
     35 enum ion_heap_type {
     36 	ION_HEAP_TYPE_SYSTEM,
     37 	ION_HEAP_TYPE_SYSTEM_CONTIG,
     38 	ION_HEAP_TYPE_CARVEOUT,
     39 	ION_HEAP_TYPE_CHUNK,
     40 	ION_HEAP_TYPE_DMA,
     41 	ION_HEAP_TYPE_CUSTOM, /*
     42 			       * must be last so device specific heaps always
     43 			       * are at the end of this enum
     44 			       */
     45 };
     46 
     47 #define ION_NUM_HEAP_IDS		(sizeof(unsigned int) * 8)
     48 
     49 /**
     50  * allocation flags - the lower 16 bits are used by core ion, the upper 16
     51  * bits are reserved for use by the heaps themselves.
     52  */
     53 
     54 /*
     55  * mappings of this buffer should be cached, ion will do cache maintenance
     56  * when the buffer is mapped for dma
     57  */
     58 #define ION_FLAG_CACHED 1
     59 
     60 /**
     61  * DOC: Ion Userspace API
     62  *
     63  * create a client by opening /dev/ion
     64  * most operations handled via following ioctls
     65  *
     66  */
     67 
     68 /**
     69  * struct ion_allocation_data - metadata passed from userspace for allocations
     70  * @len:		size of the allocation
     71  * @heap_id_mask:	mask of heap ids to allocate from
     72  * @flags:		flags passed to heap
     73  * @handle:		pointer that will be populated with a cookie to use to
     74  *			refer to this allocation
     75  *
     76  * Provided by userspace as an argument to the ioctl
     77  */
     78 struct ion_allocation_data {
     79 	__u64 len;
     80 	__u32 heap_id_mask;
     81 	__u32 flags;
     82 	__u32 fd;
     83 	__u32 unused;
     84 };
     85 
     86 #define MAX_HEAP_NAME			32
     87 
     88 /**
     89  * struct ion_heap_data - data about a heap
     90  * @name - first 32 characters of the heap name
     91  * @type - heap type
     92  * @heap_id - heap id for the heap
     93  */
     94 struct ion_heap_data {
     95 	char name[MAX_HEAP_NAME];
     96 	__u32 type;
     97 	__u32 heap_id;
     98 	__u32 reserved0;
     99 	__u32 reserved1;
    100 	__u32 reserved2;
    101 };
    102 
    103 /**
    104  * struct ion_heap_query - collection of data about all heaps
    105  * @cnt - total number of heaps to be copied
    106  * @heaps - buffer to copy heap data
    107  */
    108 struct ion_heap_query {
    109 	__u32 cnt; /* Total number of heaps to be copied */
    110 	__u32 reserved0; /* align to 64bits */
    111 	__u64 heaps; /* buffer to be populated */
    112 	__u32 reserved1;
    113 	__u32 reserved2;
    114 };
    115 
    116 #define ION_IOC_MAGIC		'I'
    117 
    118 /**
    119  * DOC: ION_IOC_ALLOC - allocate memory
    120  *
    121  * Takes an ion_allocation_data struct and returns it with the handle field
    122  * populated with the opaque handle for the allocation.
    123  */
    124 #define ION_IOC_ALLOC		_IOWR(ION_IOC_MAGIC, 0, \
    125 				      struct ion_allocation_data)
    126 
    127 /**
    128  * DOC: ION_IOC_HEAP_QUERY - information about available heaps
    129  *
    130  * Takes an ion_heap_query structure and populates information about
    131  * available Ion heaps.
    132  */
    133 #define ION_IOC_HEAP_QUERY     _IOWR(ION_IOC_MAGIC, 8, \
    134 					struct ion_heap_query)
    135 
    136 #endif /* _UAPI_LINUX_ION_H */
    137