1*48a1cce4SGatien Chevallier /* SPDX-License-Identifier: BSD-2-Clause */ 2*48a1cce4SGatien Chevallier /* 3*48a1cce4SGatien Chevallier * Copyright (C) 2024, STMicroelectronics 4*48a1cce4SGatien Chevallier */ 5*48a1cce4SGatien Chevallier 6*48a1cce4SGatien Chevallier #ifndef __DRIVERS_FIREWALL_H 7*48a1cce4SGatien Chevallier #define __DRIVERS_FIREWALL_H 8*48a1cce4SGatien Chevallier 9*48a1cce4SGatien Chevallier #include <compiler.h> 10*48a1cce4SGatien Chevallier #include <drivers/firewall_device.h> 11*48a1cce4SGatien Chevallier #include <mm/core_memprot.h> 12*48a1cce4SGatien Chevallier #include <stdbool.h> 13*48a1cce4SGatien Chevallier #include <stddef.h> 14*48a1cce4SGatien Chevallier #include <tee_api_defines.h> 15*48a1cce4SGatien Chevallier #include <types_ext.h> 16*48a1cce4SGatien Chevallier 17*48a1cce4SGatien Chevallier struct firewall_controller_ops; 18*48a1cce4SGatien Chevallier 19*48a1cce4SGatien Chevallier /** 20*48a1cce4SGatien Chevallier * struct firewall_controller - Firewall controller supplying services 21*48a1cce4SGatien Chevallier * 22*48a1cce4SGatien Chevallier * @ops: Operation handlers 23*48a1cce4SGatien Chevallier * @name: Name of the firewall controller 24*48a1cce4SGatien Chevallier * @base: Base address of the firewall controller 25*48a1cce4SGatien Chevallier * @priv: Private data of the firewall controller 26*48a1cce4SGatien Chevallier */ 27*48a1cce4SGatien Chevallier struct firewall_controller { 28*48a1cce4SGatien Chevallier const struct firewall_controller_ops *ops; 29*48a1cce4SGatien Chevallier const char *name; 30*48a1cce4SGatien Chevallier struct io_pa_va *base; 31*48a1cce4SGatien Chevallier void *priv; 32*48a1cce4SGatien Chevallier }; 33*48a1cce4SGatien Chevallier 34*48a1cce4SGatien Chevallier /** 35*48a1cce4SGatien Chevallier * struct firewall_controller_ops - Firewall controller operation handlers 36*48a1cce4SGatien Chevallier * 37*48a1cce4SGatien Chevallier * @set_conf: Callback used to set given firewall configuration 38*48a1cce4SGatien Chevallier * @check_access: Callback used to check access for a consumer on a resource 39*48a1cce4SGatien Chevallier * against a firewall controller 40*48a1cce4SGatien Chevallier * @acquire_access: Callback used to acquire access for OP-TEE on a resource 41*48a1cce4SGatien Chevallier * against a firewall controller 42*48a1cce4SGatien Chevallier * @release_access: Callback used to release resources taken by a consumer when 43*48a1cce4SGatien Chevallier * the access was acquired with @acquire_access 44*48a1cce4SGatien Chevallier * @check_memory_access: Callback used to check access for a consumer to a 45*48a1cce4SGatien Chevallier * memory range covered by a firewall controller, for read and/or write accesses 46*48a1cce4SGatien Chevallier * @acquire_memory_access: Callback used to acquire access for OP-TEE to a 47*48a1cce4SGatien Chevallier * memory range covered by a firewall controller, for read and/or write accesses 48*48a1cce4SGatien Chevallier * @release_memory_access: Callback used to release resources taken by a 49*48a1cce4SGatien Chevallier * consumer when the memory access was acquired with @acquire_memory_access 50*48a1cce4SGatien Chevallier */ 51*48a1cce4SGatien Chevallier struct firewall_controller_ops { 52*48a1cce4SGatien Chevallier TEE_Result (*set_conf)(struct firewall_query *conf); 53*48a1cce4SGatien Chevallier TEE_Result (*check_access)(struct firewall_query *conf); 54*48a1cce4SGatien Chevallier TEE_Result (*acquire_access)(struct firewall_query *conf); 55*48a1cce4SGatien Chevallier void (*release_access)(struct firewall_query *conf); 56*48a1cce4SGatien Chevallier TEE_Result (*check_memory_access)(struct firewall_query *fw, 57*48a1cce4SGatien Chevallier paddr_t paddr, size_t size, 58*48a1cce4SGatien Chevallier bool read, bool write); 59*48a1cce4SGatien Chevallier TEE_Result (*acquire_memory_access)(struct firewall_query *fw, 60*48a1cce4SGatien Chevallier paddr_t paddr, size_t size, 61*48a1cce4SGatien Chevallier bool read, bool write); 62*48a1cce4SGatien Chevallier void (*release_memory_access)(struct firewall_query *fw, 63*48a1cce4SGatien Chevallier paddr_t paddr, size_t size, bool read, 64*48a1cce4SGatien Chevallier bool write); 65*48a1cce4SGatien Chevallier }; 66*48a1cce4SGatien Chevallier 67*48a1cce4SGatien Chevallier #ifdef CFG_DRIVERS_FIREWALL 68*48a1cce4SGatien Chevallier /** 69*48a1cce4SGatien Chevallier * firewall_dt_controller_register() - Register a firewall controller to the 70*48a1cce4SGatien Chevallier * firewall framework 71*48a1cce4SGatien Chevallier * @fdt: FDT to work on 72*48a1cce4SGatien Chevallier * @node: DT node of the controller 73*48a1cce4SGatien Chevallier * @ctrl: Firewall controller to register 74*48a1cce4SGatien Chevallier */ 75*48a1cce4SGatien Chevallier TEE_Result firewall_dt_controller_register(const void *fdt, int node, 76*48a1cce4SGatien Chevallier struct firewall_controller *ctrl); 77*48a1cce4SGatien Chevallier 78*48a1cce4SGatien Chevallier /** 79*48a1cce4SGatien Chevallier * firewall_dt_probe_bus() - Add bus device tree subnodes that are accessible by 80*48a1cce4SGatien Chevallier * OP-TEE to the driver probe list. This is used at boot time only, as a sanity 81*48a1cce4SGatien Chevallier * check between device tree and firewalls hardware configurations to prevent 82*48a1cce4SGatien Chevallier * undesired accesses when access to a device is not authorized. This function 83*48a1cce4SGatien Chevallier * tries to acquire access to every resource entries listed in the 84*48a1cce4SGatien Chevallier * access-controllers property of each of the subnodes. It panics if it fails 85*48a1cce4SGatien Chevallier * to do so. 86*48a1cce4SGatien Chevallier * 87*48a1cce4SGatien Chevallier * @fdt: FDT to work on 88*48a1cce4SGatien Chevallier * @node: Firewall controller node 89*48a1cce4SGatien Chevallier * @ctrl:Firewall controller which subnodes will be populated or not 90*48a1cce4SGatien Chevallier */ 91*48a1cce4SGatien Chevallier TEE_Result firewall_dt_probe_bus(const void *fdt, int node, 92*48a1cce4SGatien Chevallier struct firewall_controller *ctrl); 93*48a1cce4SGatien Chevallier 94*48a1cce4SGatien Chevallier #else /* CFG_DRIVERS_FIREWALL */ 95*48a1cce4SGatien Chevallier 96*48a1cce4SGatien Chevallier static inline TEE_Result 97*48a1cce4SGatien Chevallier firewall_dt_controller_register(const void *fdt __unused, int node __unused, 98*48a1cce4SGatien Chevallier struct firewall_controller *ctrl __unused) 99*48a1cce4SGatien Chevallier { 100*48a1cce4SGatien Chevallier return TEE_ERROR_NOT_IMPLEMENTED; 101*48a1cce4SGatien Chevallier } 102*48a1cce4SGatien Chevallier 103*48a1cce4SGatien Chevallier static inline TEE_Result 104*48a1cce4SGatien Chevallier firewall_dt_probe_bus(const void *fdt __unused, int node __unused, 105*48a1cce4SGatien Chevallier struct firewall_controller *ctrl __unused) 106*48a1cce4SGatien Chevallier { 107*48a1cce4SGatien Chevallier return TEE_ERROR_NOT_IMPLEMENTED; 108*48a1cce4SGatien Chevallier } 109*48a1cce4SGatien Chevallier #endif /* CFG_DRIVERS_FIREWALL */ 110*48a1cce4SGatien Chevallier #endif /* __DRIVERS_FIREWALL_H */ 111