15bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson/* 25bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 35bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Copyright (c) 2012-2013, Code Aurora Forum. All rights reserved. 45bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 55bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * This software is licensed under the terms of the GNU General Public 65bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * License version 2, as published by the Free Software Foundation, and 75bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * may be copied, distributed, and modified under those terms. 85bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 95bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * This program is distributed in the hope that it will be useful, 105bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * but WITHOUT ANY WARRANTY; without even the implied warranty of 115bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 125bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * GNU General Public License for more details. 135bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 145bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson */ 155bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 165bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#ifndef _LINUX_MSM_ION_H 175bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define _LINUX_MSM_ION_H 185bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 195bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#include <linux/ion.h> 205bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 215bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilsonenum msm_ion_heap_types { 225bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson ION_HEAP_TYPE_MSM_START = ION_HEAP_TYPE_CUSTOM + 1, 235bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson ION_HEAP_TYPE_IOMMU = ION_HEAP_TYPE_MSM_START, 245bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson ION_HEAP_TYPE_CP, 255bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson}; 265bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 275bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson/** 285bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * These are the only ids that should be used for Ion heap ids. 295bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * The ids listed are the order in which allocation will be attempted 305bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * if specified. Don't swap the order of heap ids unless you know what 315bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * you are doing! 325bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Id's are spaced by purpose to allow new Id's to be inserted in-between (for 335bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * possible fallbacks) 345bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson */ 355bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 365bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilsonenum ion_heap_ids { 375bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson INVALID_HEAP_ID = -1, 385bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson ION_CP_MM_HEAP_ID = 8, 395bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson ION_CP_MFC_HEAP_ID = 12, 405bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson ION_CP_WB_HEAP_ID = 16, /* 8660 only */ 415bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson ION_CAMERA_HEAP_ID = 20, /* 8660 only */ 425bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson ION_SF_HEAP_ID = 24, 435bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson ION_IOMMU_HEAP_ID = 25, 445bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson ION_QSECOM_HEAP_ID = 27, 455bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson ION_AUDIO_HEAP_ID = 28, 465bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 475bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson ION_MM_FIRMWARE_HEAP_ID = 29, 485bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson ION_SYSTEM_HEAP_ID = 30, 495bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 505bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson ION_HEAP_ID_RESERVED = 31 /** Bit reserved for ION_SECURE flag */ 515bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson}; 525bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 535bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilsonenum ion_fixed_position { 545bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson NOT_FIXED, 555bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson FIXED_LOW, 565bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson FIXED_MIDDLE, 575bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson FIXED_HIGH, 585bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson}; 595bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 605bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilsonenum cp_mem_usage { 615bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson VIDEO_BITSTREAM = 0x1, 625bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson VIDEO_PIXEL = 0x2, 635bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson VIDEO_NONPIXEL = 0x3, 645bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson MAX_USAGE = 0x4, 655bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson UNKNOWN = 0x7FFFFFFF, 665bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson}; 675bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 685bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_HEAP_CP_MASK (1 << ION_HEAP_TYPE_CP) 695bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 705bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson/** 715bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Flag to use when allocating to indicate that a heap is secure. 725bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson */ 735bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_SECURE (1 << ION_HEAP_ID_RESERVED) 745bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 755bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson/** 765bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Flag for clients to force contiguous memort allocation 775bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 785bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Use of this flag is carefully monitored! 795bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson */ 805bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_FORCE_CONTIGUOUS (1 << 30) 815bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 825bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson/** 835bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Macro should be used with ion_heap_ids defined above. 845bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson */ 855bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_HEAP(bit) (1 << (bit)) 865bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 875bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_VMALLOC_HEAP_NAME "vmalloc" 885bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_AUDIO_HEAP_NAME "audio" 895bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_SF_HEAP_NAME "sf" 905bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_MM_HEAP_NAME "mm" 915bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_CAMERA_HEAP_NAME "camera_preview" 925bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_IOMMU_HEAP_NAME "iommu" 935bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_MFC_HEAP_NAME "mfc" 945bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_WB_HEAP_NAME "wb" 955bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_MM_FIRMWARE_HEAP_NAME "mm_fw" 965bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_QSECOM_HEAP_NAME "qsecom" 975bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_FMEM_HEAP_NAME "fmem" 985bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 995bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_SET_CACHED(__cache) (__cache | ION_FLAG_CACHED) 1005bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_SET_UNCACHED(__cache) (__cache & ~ION_FLAG_CACHED) 1015bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 1025bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_IS_CACHED(__flags) ((__flags) & ION_FLAG_CACHED) 1035bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 1045bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#ifdef __KERNEL__ 1055bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 1065bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson/* 1075bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * This flag allows clients when mapping into the IOMMU to specify to 1085bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * defer un-mapping from the IOMMU until the buffer memory is freed. 1095bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson */ 1105bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_IOMMU_UNMAP_DELAYED 1 1115bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 1125bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson/** 1135bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * struct ion_cp_heap_pdata - defines a content protection heap in the given 1145bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * platform 1155bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @permission_type: Memory ID used to identify the memory to TZ 1165bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @align: Alignment requirement for the memory 1175bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @secure_base: Base address for securing the heap. 1185bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Note: This might be different from actual base address 1195bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * of this heap in the case of a shared heap. 1205bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @secure_size: Memory size for securing the heap. 1215bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Note: This might be different from actual size 1225bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * of this heap in the case of a shared heap. 1235bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @reusable Flag indicating whether this heap is reusable of not. 1245bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * (see FMEM) 1255bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @mem_is_fmem Flag indicating whether this memory is coming from fmem 1265bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * or not. 1275bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @fixed_position If nonzero, position in the fixed area. 1285bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @virt_addr: Virtual address used when using fmem. 1295bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @iommu_map_all: Indicates whether we should map whole heap into IOMMU. 1305bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @iommu_2x_map_domain: Indicates the domain to use for overmapping. 1315bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @request_region: function to be called when the number of allocations 1325bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * goes from 0 -> 1 1335bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @release_region: function to be called when the number of allocations 1345bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * goes from 1 -> 0 1355bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @setup_region: function to be called upon ion registration 1365bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @memory_type:Memory type used for the heap 1375bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @no_nonsecure_alloc: don't allow non-secure allocations from this heap 1385bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 1395bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson */ 1405bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilsonstruct ion_cp_heap_pdata { 1415bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson enum ion_permission_type permission_type; 1425bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson unsigned int align; 1435bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson ion_phys_addr_t secure_base; /* Base addr used when heap is shared */ 1445bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson size_t secure_size; /* Size used for securing heap when heap is shared*/ 1455bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson int reusable; 1465bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson int mem_is_fmem; 1475bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson int is_cma; 1485bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson enum ion_fixed_position fixed_position; 1495bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson int iommu_map_all; 1505bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson int iommu_2x_map_domain; 1515bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson ion_virt_addr_t *virt_addr; 1525bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson int (*request_region)(void *); 1535bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson int (*release_region)(void *); 1545bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson void *(*setup_region)(void); 1555bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson enum ion_memory_types memory_type; 1565bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson int no_nonsecure_alloc; 1575bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson}; 1585bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 1595bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson/** 1605bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * struct ion_co_heap_pdata - defines a carveout heap in the given platform 1615bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @adjacent_mem_id: Id of heap that this heap must be adjacent to. 1625bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @align: Alignment requirement for the memory 1635bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @mem_is_fmem Flag indicating whether this memory is coming from fmem 1645bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * or not. 1655bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @fixed_position If nonzero, position in the fixed area. 1665bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @request_region: function to be called when the number of allocations 1675bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * goes from 0 -> 1 1685bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @release_region: function to be called when the number of allocations 1695bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * goes from 1 -> 0 1705bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @setup_region: function to be called upon ion registration 1715bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @memory_type:Memory type used for the heap 1725bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 1735bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson */ 1745bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilsonstruct ion_co_heap_pdata { 1755bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson int adjacent_mem_id; 1765bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson unsigned int align; 1775bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson int mem_is_fmem; 1785bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson enum ion_fixed_position fixed_position; 1795bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson int (*request_region)(void *); 1805bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson int (*release_region)(void *); 1815bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson void *(*setup_region)(void); 1825bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson enum ion_memory_types memory_type; 1835bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson}; 1845bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 1855bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#ifdef CONFIG_ION 1865bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson/** 1875bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * msm_ion_secure_heap - secure a heap. Wrapper around ion_secure_heap. 1885bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 1895bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @heap_id - heap id to secure. 1905bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 1915bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Secure a heap 1925bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Returns 0 on success 1935bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson */ 1945bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilsonint msm_ion_secure_heap(int heap_id); 1955bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 1965bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson/** 1975bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * msm_ion_unsecure_heap - unsecure a heap. Wrapper around ion_unsecure_heap. 1985bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 1995bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @heap_id - heap id to secure. 2005bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 2015bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Un-secure a heap 2025bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Returns 0 on success 2035bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson */ 2045bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilsonint msm_ion_unsecure_heap(int heap_id); 2055bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 2065bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson/** 2075bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * msm_ion_secure_heap_2_0 - secure a heap using 2.0 APIs 2085bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Wrapper around ion_secure_heap. 2095bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 2105bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @heap_id - heap id to secure. 2115bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @usage - usage hint to TZ 2125bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 2135bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Secure a heap 2145bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Returns 0 on success 2155bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson */ 2165bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilsonint msm_ion_secure_heap_2_0(int heap_id, enum cp_mem_usage usage); 2175bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 2185bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson/** 2195bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * msm_ion_unsecure_heap - unsecure a heap secured with 3.0 APIs. 2205bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Wrapper around ion_unsecure_heap. 2215bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 2225bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @heap_id - heap id to secure. 2235bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @usage - usage hint to TZ 2245bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 2255bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Un-secure a heap 2265bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Returns 0 on success 2275bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson */ 2285bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilsonint msm_ion_unsecure_heap_2_0(int heap_id, enum cp_mem_usage usage); 2295bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#else 2305bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilsonstatic inline int msm_ion_secure_heap(int heap_id) 2315bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson{ 2325bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson return -ENODEV; 2335bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 2345bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson} 2355bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 2365bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilsonstatic inline int msm_ion_unsecure_heap(int heap_id) 2375bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson{ 2385bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson return -ENODEV; 2395bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson} 2405bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 2415bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilsonstatic inline int msm_ion_secure_heap_2_0(int heap_id, enum cp_mem_usage usage) 2425bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson{ 2435bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson return -ENODEV; 2445bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson} 2455bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 2465bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilsonstatic inline int msm_ion_unsecure_heap_2_0(int heap_id, 2475bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson enum cp_mem_usage usage) 2485bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson{ 2495bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson return -ENODEV; 2505bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson} 2515bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#endif /* CONFIG_ION */ 2525bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 2535bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#endif /* __KERNEL */ 2545bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 2555bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson/* struct ion_flush_data - data passed to ion for flushing caches 2565bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 2575bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @handle: handle with data to flush 2585bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @fd: fd to flush 2595bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @vaddr: userspace virtual address mapped with mmap 2605bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @offset: offset into the handle to flush 2615bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @length: length of handle to flush 2625bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 2635bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Performs cache operations on the handle. If p is the start address 2645bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * of the handle, p + offset through p + offset + length will have 2655bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * the cache operations performed 2665bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson */ 2675bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilsonstruct ion_flush_data { 2685bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson struct ion_handle *handle; 2695bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson int fd; 2705bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson void *vaddr; 2715bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson unsigned int offset; 2725bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson unsigned int length; 2735bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson}; 2745bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 2755bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson/* struct ion_flag_data - information about flags for this buffer 2765bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 2775bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @handle: handle to get flags from 2785bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * @flags: flags of this handle 2795bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 2805bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Takes handle as an input and outputs the flags from the handle 2815bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * in the flag field. 2825bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson */ 2835bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilsonstruct ion_flag_data { 2845bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson struct ion_handle *handle; 2855bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson unsigned long flags; 2865bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson}; 2875bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 2885bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_IOC_MSM_MAGIC 'M' 2895bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 2905bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson/** 2915bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * DOC: ION_IOC_CLEAN_CACHES - clean the caches 2925bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 2935bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Clean the caches of the handle specified. 2945bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson */ 2955bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_IOC_CLEAN_CACHES _IOWR(ION_IOC_MSM_MAGIC, 0, \ 2965bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson struct ion_flush_data) 2975bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson/** 2985bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * DOC: ION_IOC_INV_CACHES - invalidate the caches 2995bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 3005bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Invalidate the caches of the handle specified. 3015bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson */ 3025bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_IOC_INV_CACHES _IOWR(ION_IOC_MSM_MAGIC, 1, \ 3035bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson struct ion_flush_data) 3045bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson/** 3055bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * DOC: ION_IOC_CLEAN_INV_CACHES - clean and invalidate the caches 3065bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 3075bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Clean and invalidate the caches of the handle specified. 3085bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson */ 3095bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_IOC_CLEAN_INV_CACHES _IOWR(ION_IOC_MSM_MAGIC, 2, \ 3105bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson struct ion_flush_data) 3115bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 3125bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson/** 3135bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * DOC: ION_IOC_GET_FLAGS - get the flags of the handle 3145bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * 3155bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * Gets the flags of the current handle which indicate cachability, 3165bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson * secure state etc. 3175bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson */ 3185bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#define ION_IOC_GET_FLAGS _IOWR(ION_IOC_MSM_MAGIC, 3, \ 3195bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson struct ion_flag_data) 3205bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson 3215bccd2d0d6de8ffd0c244c1b66ef5a9ac9409404Simon Wilson#endif 322