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