xref: /linux/drivers/bus/stm32_firewall.h (revision 621cde16e49b3ecf7d59a8106a20aaebfb4a59a9)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2023, STMicroelectronics - All Rights Reserved
4  */
5 
6 #ifndef _STM32_FIREWALL_H
7 #define _STM32_FIREWALL_H
8 
9 #include <linux/kernel.h>
10 #include <linux/list.h>
11 #include <linux/of.h>
12 #include <linux/platform_device.h>
13 #include <linux/types.h>
14 
15 /**
16  * STM32_PERIPHERAL_FIREWALL:		This type of firewall protects peripherals
17  * STM32_MEMORY_FIREWALL:		This type of firewall protects memories/subsets of memory
18  *					zones
19  * STM32_NOTYPE_FIREWALL:		Undefined firewall type
20  */
21 
22 #define STM32_PERIPHERAL_FIREWALL	BIT(1)
23 #define STM32_MEMORY_FIREWALL		BIT(2)
24 #define STM32_NOTYPE_FIREWALL		BIT(3)
25 
26 /**
27  * struct stm32_firewall_controller - Information on firewall controller supplying services
28  *
29  * @name:			Name of the firewall controller
30  * @dev:			Device reference of the firewall controller
31  * @mmio:			Base address of the firewall controller
32  * @entry:			List entry of the firewall controller list
33  * @type:			Type of firewall
34  * @max_entries:		Number of entries covered by the firewall
35  * @grant_access:		Callback used to grant access for a device access against a
36  *				firewall controller
37  * @release_access:		Callback used to release resources taken by a device when access was
38  *				granted
39  * @grant_memory_range_access:	Callback used to grant access for a device to a given memory region
40  */
41 struct stm32_firewall_controller {
42 	const char *name;
43 	struct device *dev;
44 	void __iomem *mmio;
45 	struct list_head entry;
46 	unsigned int type;
47 	unsigned int max_entries;
48 
49 	int (*grant_access)(struct stm32_firewall_controller *ctrl, u32 id);
50 	void (*release_access)(struct stm32_firewall_controller *ctrl, u32 id);
51 	int (*grant_memory_range_access)(struct stm32_firewall_controller *ctrl, phys_addr_t paddr,
52 					 size_t size);
53 };
54 
55 /**
56  * stm32_firewall_controller_register - Register a firewall controller to the STM32 firewall
57  *					framework
58  * @firewall_controller:	Firewall controller to register
59  *
60  * Returns 0 in case of success or -ENODEV if no controller was given.
61  */
62 int stm32_firewall_controller_register(struct stm32_firewall_controller *firewall_controller);
63 
64 /**
65  * stm32_firewall_controller_unregister - Unregister a firewall controller from the STM32
66  *					  firewall framework
67  * @firewall_controller:	Firewall controller to unregister
68  */
69 void stm32_firewall_controller_unregister(struct stm32_firewall_controller *firewall_controller);
70 
71 /**
72  * stm32_firewall_populate_bus - Populate device tree nodes that have a correct firewall
73  *				 configuration. This is used at boot-time only, as a sanity check
74  *				 between device tree and firewalls hardware configurations to
75  *				 prevent a kernel crash when a device driver is not granted access
76  *
77  * @firewall_controller:	Firewall controller which nodes will be populated or not
78  *
79  * Returns 0 in case of success or appropriate errno code if error occurred.
80  */
81 int stm32_firewall_populate_bus(struct stm32_firewall_controller *firewall_controller);
82 
83 #endif /* _STM32_FIREWALL_H */
84