Home | History | Annotate | Download | only in Bug-35139833
      1 /**
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 
     18 #ifndef __KILROY_H__
     19 #define __KILROY_H__
     20 
     21 typedef int ion_user_handle_t;
     22 
     23 enum ion_heap_ids {
     24   INVALID_HEAP_ID = -1,
     25   ION_CP_MM_HEAP_ID = 8,
     26   ION_CP_MFC_HEAP_ID = 12,
     27   ION_CP_WB_HEAP_ID = 16,  /* 8660 only */
     28   ION_CAMERA_HEAP_ID = 20, /* 8660 only */
     29   ION_SYSTEM_CONTIG_HEAP_ID = 21,
     30   ION_ADSP_HEAP_ID = 22,
     31   ION_PIL1_HEAP_ID = 23, /* Currently used for other PIL images */
     32   ION_SF_HEAP_ID = 24,
     33   ION_IOMMU_HEAP_ID = 25,
     34   ION_PIL2_HEAP_ID = 26, /* Currently used for modem firmware images */
     35   ION_QSECOM_HEAP_ID = 27,
     36   ION_AUDIO_HEAP_ID = 28,
     37 
     38   ION_MM_FIRMWARE_HEAP_ID = 29,
     39   ION_SYSTEM_HEAP_ID = 30,
     40 
     41   ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_FLAG_SECURE flag */
     42 };
     43 
     44 /**
     45  * Flag to use when allocating to indicate that a heap is secure.
     46  */
     47 #define ION_FLAG_SECURE (1 << ION_HEAP_ID_RESERVED)
     48 
     49 /**
     50  * Flag for clients to force contiguous memort allocation
     51  *
     52  * Use of this flag is carefully monitored!
     53  */
     54 #define ION_FLAG_FORCE_CONTIGUOUS (1 << 30)
     55 
     56 /**
     57  * Deprecated! Please use the corresponding ION_FLAG_*
     58  */
     59 #define ION_SECURE ION_FLAG_SECURE
     60 #define ION_FORCE_CONTIGUOUS ION_FLAG_FORCE_CONTIGUOUS
     61 
     62 /**
     63  * Macro should be used with ion_heap_ids defined above.
     64  */
     65 #define ION_HEAP(bit) (1 << (bit))
     66 
     67 #define ION_IOC_MAGIC 'I'
     68 
     69 /**
     70  * DOC: ION_IOC_ALLOC - allocate memory
     71  *
     72  * Takes an ion_allocation_data struct and returns it with the handle field
     73  * populated with the opaque handle for the allocation.
     74  */
     75 #define ION_IOC_ALLOC _IOWR(ION_IOC_MAGIC, 0, struct ion_allocation_data)
     76 
     77 /**
     78  * DOC: ION_IOC_FREE - free memory
     79  *
     80  * Takes an ion_handle_data struct and frees the handle.
     81  */
     82 #define ION_IOC_FREE _IOWR(ION_IOC_MAGIC, 1, struct ion_handle_data)
     83 
     84 /**
     85  * DOC: ION_IOC_MAP - get a file descriptor to mmap
     86  *
     87  * Takes an ion_fd_data struct with the handle field populated with a valid
     88  * opaque handle.  Returns the struct with the fd field set to a file
     89  * descriptor open in the current address space.  This file descriptor
     90  * can then be used as an argument to mmap.
     91  */
     92 #define ION_IOC_MAP _IOWR(ION_IOC_MAGIC, 2, struct ion_fd_data)
     93 
     94 /**
     95  * struct ion_allocation_data - metadata passed from userspace for allocations
     96  * @len:		size of the allocation
     97  * @align:		required alignment of the allocation
     98  * @heap_id_mask:	mask of heap ids to allocate from
     99  * @flags:		flags passed to heap
    100  * @handle:		pointer that will be populated with a cookie to use to
    101  *			refer to this allocation
    102  *
    103  * Provided by userspace as an argument to the ioctl
    104  */
    105 struct ion_allocation_data {
    106   size_t len;
    107   size_t align;
    108   unsigned int heap_id_mask;
    109   unsigned int flags;
    110   ion_user_handle_t handle;
    111 };
    112 
    113 /**
    114  * struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair
    115  * @handle:	a handle
    116  * @fd:		a file descriptor representing that handle
    117  *
    118  * For ION_IOC_SHARE or ION_IOC_MAP userspace populates the handle field with
    119  * the handle returned from ion alloc, and the kernel returns the file
    120  * descriptor to share or map in the fd field.  For ION_IOC_IMPORT, userspace
    121  * provides the file descriptor and the kernel returns the handle.
    122  */
    123 struct ion_fd_data {
    124   ion_user_handle_t handle;
    125   int fd;
    126 };
    127 
    128 /**
    129  * struct ion_handle_data - a handle passed to/from the kernel
    130  * @handle:	a handle
    131  */
    132 struct ion_handle_data {
    133   ion_user_handle_t handle;
    134 };
    135 
    136 #endif /* __KILROY_H__ */
    137