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