stm32_firewall.h 2.9 KB

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