1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2 /* 3 * 4 * (C) COPYRIGHT 2019-2021 ARM Limited. All rights reserved. 5 * 6 * This program is free software and is provided to you under the terms of the 7 * GNU General Public License version 2 as published by the Free Software 8 * Foundation, and any use by you of this program is subject to the terms 9 * of such GNU license. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, you can access it online at 18 * http://www.gnu.org/licenses/gpl-2.0.html. 19 * 20 */ 21 22 #ifndef _PROTECTED_MEMORY_ALLOCATOR_H_ 23 #define _PROTECTED_MEMORY_ALLOCATOR_H_ 24 25 #include <linux/mm.h> 26 27 /** 28 * struct protected_memory_allocation - Protected memory allocation 29 * 30 * @pa: Physical address of the protected memory allocation. 31 * @order: Size of memory allocation in pages, as a base-2 logarithm. 32 */ 33 struct protected_memory_allocation { 34 phys_addr_t pa; 35 unsigned int order; 36 }; 37 38 struct protected_memory_allocator_device; 39 40 /** 41 * struct protected_memory_allocator_ops - Callbacks for protected memory 42 * allocator operations 43 * 44 * @pma_alloc_page: Callback to allocate protected memory 45 * @pma_get_phys_addr: Callback to get the physical address of an allocation 46 * @pma_free_page: Callback to free protected memory 47 */ 48 struct protected_memory_allocator_ops { 49 /* 50 * pma_alloc_page - Allocate protected memory pages 51 * 52 * @pma_dev: The protected memory allocator the request is being made 53 * through. 54 * @order: How many pages to allocate, as a base-2 logarithm. 55 * 56 * Return: Pointer to allocated memory, or NULL if allocation failed. 57 */ 58 struct protected_memory_allocation *(*pma_alloc_page)( 59 struct protected_memory_allocator_device *pma_dev, 60 unsigned int order); 61 62 /* 63 * pma_get_phys_addr - Get the physical address of the protected memory 64 * allocation 65 * 66 * @pma_dev: The protected memory allocator the request is being made 67 * through. 68 * @pma: The protected memory allocation whose physical address 69 * shall be retrieved 70 * 71 * Return: The physical address of the given allocation. 72 */ 73 phys_addr_t (*pma_get_phys_addr)( 74 struct protected_memory_allocator_device *pma_dev, 75 struct protected_memory_allocation *pma); 76 77 /* 78 * pma_free_page - Free a page of memory 79 * 80 * @pma_dev: The protected memory allocator the request is being made 81 * through. 82 * @pma: The protected memory allocation to free. 83 */ 84 void (*pma_free_page)( 85 struct protected_memory_allocator_device *pma_dev, 86 struct protected_memory_allocation *pma); 87 }; 88 89 /** 90 * struct protected_memory_allocator_device - Device structure for protected 91 * memory allocator 92 * 93 * @ops: Callbacks associated with this device 94 * @owner: Pointer to the module owner 95 * 96 * In order for a system integrator to provide custom behaviors for protected 97 * memory operations performed by the kbase module (controller driver), 98 * they shall provide a platform-specific driver module which implements 99 * this interface. 100 * 101 * This structure should be registered with the platform device using 102 * platform_set_drvdata(). 103 */ 104 struct protected_memory_allocator_device { 105 struct protected_memory_allocator_ops ops; 106 struct module *owner; 107 }; 108 109 #endif /* _PROTECTED_MEMORY_ALLOCATOR_H_ */ 110