/** ************************************************************************************************ * SEMIDRIVE Copyright Statement * Copyright (c) SEMIDRIVE. All rights reserved * * This software and all rights therein are owned by SEMIDRIVE, and are * protected by copyright law and other relevant laws, regulations and * protection. Without SEMIDRIVE's prior written consent and/or related rights, * please do not use this software or any potion thereof in any form or by any * means. You may not reproduce, modify or distribute this software except in * compliance with the License. Unless required by applicable law or agreed to * in writing, software distributed under the License is distributed on * an 'AS IS' basis, WITHOUT WARRANTIES OF ANY KIND, either express or implied. * **************************************************************************************************/ /** ************************************************************************************************ * \file sdrv_firewall.h * \brief SemiDrive Firewall driver header file. * * *
Date Version *
2023/11/29 1.0.0 *
**************************************************************************************************/ #ifndef SDRV_FIREWALL_H #define SDRV_FIREWALL_H /*************************************************************************************************** * Include header files **************************************************************************************************/ #include #include #include /*************************************************************************************************** * Global Macro definition **************************************************************************************************/ /** \brief Enable read and write permissions. */ #define FIREWALL_PERMISSION_RW (0x00U) /** \brief Enable read permission. */ #define FIREWALL_PERMISSION_RO (0x01U) /** \brief Enable write permission. */ #define FIREWALL_PERMISSION_WO (0x02U) /** \brief No permission. */ #define FIREWALL_PERMISSION_NONE (0x03U) /** \brief Firewall module uninitialized state. */ #define FIREWALL_UNINIT (0x00U) /** \brief Firewall module initialized state. */ #define FIREWALL_INIT (0x01U) /** \brief The minimum value of register. */ #define FIREWALL_REG_VALUE_MIN (0x00U) /** \brief The maximum value of register. */ #define FIREWALL_REG_VALUE_MAX (0xFFFFFFFFU) /** \brief Firewall module base address. */ #define FIREWALL_APB_MAC_BASE APB_MAC_BASE /*************************************************************************************************** * Global Types definition **************************************************************************************************/ /** * @brief Firewall status return code */ typedef enum sdrv_firewall_err_status { FIREWALL_E_OK = SDRV_STATUS_OK, /**< status for success. */ FIREWALL_E_INIT = SDRV_ERROR_STATUS( SDRV_STATUS_GROUP_FIREWALL, 0U), /**< Error due to API duplicated invoked FIREWALL_Init(). */ FIREWALL_E_UNINIT = SDRV_ERROR_STATUS( SDRV_STATUS_GROUP_FIREWALL, 1U), /**< Error due to API invoked without performing FIREWALL_Init(). */ FIREWALL_E_NULL_POINTER = SDRV_ERROR_STATUS( SDRV_STATUS_GROUP_FIREWALL, 3U), /**< Error due to NULL_PTR passed as parameter. */ FIREWALL_E_MAC_MASTER_ID = SDRV_ERROR_STATUS( SDRV_STATUS_GROUP_FIREWALL, 4U), /**< Error due to invalid master id. */ FIREWALL_E_MAC_DOMAIN_ID = SDRV_ERROR_STATUS( SDRV_STATUS_GROUP_FIREWALL, 5U), /**< Error due to invalid domain id. */ FIREWALL_E_MAC_LOCKED = SDRV_ERROR_STATUS( SDRV_STATUS_GROUP_FIREWALL, 6U), /**< Error due to the MAC module has been locked. */ FIREWALL_E_MPC_PORT_NUM = SDRV_ERROR_STATUS( SDRV_STATUS_GROUP_FIREWALL, 7U), /**< Error due to the unvalid number of memory ports. */ FIREWALL_E_MPC_REGION_NUM = SDRV_ERROR_STATUS( SDRV_STATUS_GROUP_FIREWALL, 8U), /**< Error due to the unvalid number of memory regions. */ FIREWALL_E_PPC_IP_NUM = SDRV_ERROR_STATUS( SDRV_STATUS_GROUP_FIREWALL, 9U), /**< Error due to the unvalid number of peripherals. */ FIREWALL_E_PPC_REGION_NUM = SDRV_ERROR_STATUS( SDRV_STATUS_GROUP_FIREWALL, 10U), /**< Error due to the unvalid number of apb regions. */ FIREWALL_E_GPIO_CORE_ID = SDRV_ERROR_STATUS( SDRV_STATUS_GROUP_FIREWALL, 11U), /**< Error due to invalid core id. */ FIREWALL_E_GPIO_CHANNEL_ID = SDRV_ERROR_STATUS( SDRV_STATUS_GROUP_FIREWALL, 12U), /**< Error due to invalid gpio pin channel id. */ FIREWALL_E_GPIO_CORE_NUM = SDRV_ERROR_STATUS(SDRV_STATUS_GROUP_FIREWALL, 13U), /**< Error due to invalid number of cores. */ FIREWALL_E_GPIO_CHANNEL_NUM = SDRV_ERROR_STATUS( SDRV_STATUS_GROUP_FIREWALL, 14U), /**< Error due to invalid number of gpio pin channels. */ } sdrv_firewall_err_status_e; /** \brief The type of configuarion for the MAC module */ typedef const uint8_t *sdrv_mac_config_t; /** * @brief MPC region configure. */ typedef struct mpc_region_cfg { uint32_t start_addr; /**< start address */ uint32_t end_addr; /**< end address */ uint32_t domain0_perms : 4; /**< user permission << 2 | privilege permission */ uint32_t domain1_perms : 4; /**< user permission << 2 | privilege permission */ uint32_t domain2_perms : 4; /**< user permission << 2 | privilege permission */ uint32_t domain3_perms : 4; /**< user permission << 2 | privilege permission */ uint32_t domain4_perms : 4; /**< user permission << 2 | privilege permission */ uint32_t domain5_perms : 4; /**< user permission << 2 | privilege permission */ uint32_t domain6_perms : 4; /**< user permission << 2 | privilege permission */ uint32_t domain7_perms : 4; /**< user permission << 2 | privilege permission */ } sdrv_mpc_region_cfg_t; /** * @brief MPC memory port configure. */ typedef struct mpc_memport_cfg { uint16_t region_nr; /**< the regions of number in memory */ uint16_t base_offset; /**< memory port base offset */ const sdrv_mpc_region_cfg_t *const region_config; /**< the configuration of the regions */ } sdrv_mpc_memport_cfg_t; /** * @brief PPC address configure. */ typedef struct ppc_addrconfig { uint8_t domain7_user_permission : 2; /**< SF User permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain7_privileged_permission : 2; /**< SF Privileged permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain2_user_permission : 2; /**< SP0 User permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain2_privileged_permission : 2; /**< SP0 Privileged permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain3_user_permission : 2; /**< SP1 User permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain3_privileged_permission : 2; /**< SP1 Privileged permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain4_user_permission : 2; /**< SX0 User permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain4_privileged_permission : 2; /**< SX0 Privileged permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain5_user_permission : 2; /**< SX1 User permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain5_privileged_permission : 2; /**< SX1 Privileged permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain6_permission : 2; /**< Dma Permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t ppc_apbmux_id : 4; /**< PPC protected APBMUX num */ uint8_t ppc_region_index; /**< PPC protected Region N */ uint32_t ppc_start_addr; /**< start address */ uint32_t ppc_end_addr; /**< end address */ } sdrv_ppc_region_config_t; /** * @brief PPC ip configure. */ typedef struct ppc_ipconfig { uint8_t domain7_user_permission : 2; /**< SF User permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain7_privileged_permission : 2; /**< SF Privileged permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain2_user_permission : 2; /**< SP0 User permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain2_privileged_permission : 2; /**< SP0 Privileged permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain3_user_permission : 2; /**< SP1 User permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain3_privileged_permission : 2; /**< SP1 Privileged permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain4_user_permission : 2; /**< SX0 User permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain4_privileged_permission : 2; /**< SX0 Privileged permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain5_user_permission : 2; /**< SX1 User permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain5_privileged_permission : 2; /**< SX1 Privileged permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t domain6_permission : 2; /**< Dma Permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t ppc_apbmux_id : 4; /**< PPC protected APBMUX num */ uint8_t ppc_apbmux_ip_id; /**< ID number of IP */ } sdrv_ppc_ip_config_t; /** * @brief Pin configuration. */ typedef struct gpio_channel_cfg { const uint16_t *gpio_channel_id; /**< gpio channel id */ uint16_t gpio_channel_num; /**< gpio channel number */ } sdrv_gpio_channel_cfg_t; /** * @brief Pin permission for the core. */ typedef struct gpio_core_cfg { uint8_t gpio_user_permission : 2; /**< SF User Permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t gpio_privileged_permission : 2; /**< SF User Permission 0:RW 1:RO 2:WO 3:NONE */ uint8_t gpio_core_id : 4; /**< GPIO core ID 0:sf 1:sx0 2:sx1 3:sp0 4:sp1 */ const sdrv_gpio_channel_cfg_t gpio_channel_cfg; /**< gpio channel id list */ } sdrv_gpio_core_cfg_t; /** * @brief MPC interrupt status. */ typedef struct { uint32_t mpc_memport_id : 16; /**< memport ID:0~22 */ uint32_t mpc_intr_sta : 16; /**< interrupt status 1:memory access error 2:register access error */ } sdrv_mpc_irqsta_t; /** * @brief PPC interrupt status. */ typedef struct { uint32_t ppc_apbmux_ip_id : 16; /**< APBMUX ID:0~6 */ uint32_t ppc_intr_sta : 16; /**< interrupt status 1:peripheral access error 2:register access error */ } sdrv_ppc_irqsta_t; /** * @brief Firewall interrupt status. */ typedef struct { sdrv_ppc_irqsta_t ppc_errinfo[FIREWALL_PPC_APBMUX_MAXNUM]; /**< PPC illegal access information */ sdrv_mpc_irqsta_t mpc_errinfo[FIREWALL_MPC_MEMPORT_MAXNUM]; /**< MPC illegal access information */ } sdrv_firewall_err_t; typedef struct sdrv_firewall sdrv_firewall_t; /** * @brief Firewall callback function type. */ typedef void (*sdrv_firewall_callback_t)(sdrv_firewall_t *ctrl, void *userdata); /** * @brief Firewall controller configuration. */ typedef struct { const sdrv_mac_config_t *mac_cfg; /**< the configuration of the MAC module. */ const sdrv_mpc_memport_cfg_t *mpc_cfg; /**< MPC configuration. */ uint32_t memport_num; /**< the number of memory ports. */ const sdrv_ppc_ip_config_t *ppc_ip_cfg; /**< PPC ip configuration. */ uint16_t ip_num; /**< the number of ip. */ const sdrv_ppc_region_config_t *ppc_region_cfg; /**< PPC address configuration. */ uint16_t region_num; /**< the number of memory regions. */ const sdrv_gpio_core_cfg_t *io_cfg; /**< the configuration of pin permission. */ uint16_t core_num; /**< the number of cores. */ } sdrv_firewall_cfg_t; /** * @brief Firewall controller. */ struct sdrv_firewall { uint32_t base; /**< MAC module address base. */ int irq; /**< firewall module irq number. */ spin_lock_t spinlock; /* firewall spin lock. */ uint8_t init_status; /**< firewall module initialize status. */ sdrv_firewall_callback_t callback; /**< the callback function. */ void *userdata; /**< the param of the callback function. */ sdrv_firewall_err_t error_info; /**< the illegal access error info of the firewall module. */ const sdrv_firewall_cfg_t *config; /**< the configuration of the firewall. */ }; /*************************************************************************************************** * Global Function Declarations **************************************************************************************************/ /** * @brief Configure firewall. * * @param[in] ctrl the firewall instance. * @param[in] cfg the configuration of the MAC/MPC/PPC/GPIO module. * * @return The result of the firewall initialization function * @details - return SDRV_STATUS_OK, initializa firewall success. * - return SDRV_STATUS_INVALID_PARAM, invalid configuration parameter. */ status_t sdrv_firewall_init(sdrv_firewall_t *ctrl, const sdrv_firewall_cfg_t *cfg); /** * @brief Assigns the master to the specified domain. * * Assigns the specified master to a domain. * This function should be executed after the initialization function * sdrv_firewall_init(). * * @param[in] ctrl the firewall instance. * @param[in] master_id the id of the master. * @param[in] domain_id the id of the domain. * * @return The result of this function. * @details - return FIREWALL_E_OK, Assigned the master to the domain success. * - return FIREWALL_E_UNINIT: The firewall is uninitialized. * - return FIREWALL_E_MAC_MASTER_ID: The master id is unvalid. * - return FIREWALL_E_MAC_DOMAIN_ID: The domain id is unvalid. * - return FIREWALL_E_MAC_LOCKED: The domain assignment of the master * is locked. */ status_t sdrv_firewall_assign_domain(sdrv_firewall_t *ctrl, uint8_t master_id, uint8_t domain_id); /** * @brief Lock the domain assignment of the master. * * This function lock the domain assignment of the master, should be called * after the initialization function sdrv_firewall_init() or domain assignment * function sdrv_firewall_assign_domain(). * * @param[in] ctrl the firewall instance. * * @return The result of this function. * @details - return FIREWALL_E_OK : Lock domain assignment success. * - return FIREWALL_E_INIT : The firewall is uninitialized. * - return FIREWALL_E_NULL_POINTER : The pointer to the MAC * configuration is NULL. */ status_t sdrv_firewall_lock_domain_assignment(sdrv_firewall_t *ctrl); /** * @brief Set callback function for firewall. * * @param[in] ctrl the firewall instance. * @param[in] callback the callback function. * @param[in] userdata the param of callback function. * * @return The result of this function. * @details - return FIREWALL_E_OK : Set callback function success. * - return FIREWALL_E_NULL_POINTER : The pointer to the MAC * configuration is NULL. * - return FIREWALL_E_UNINIT : The firewall is uninitialized. */ status_t sdrv_firewall_set_callback(sdrv_firewall_t *ctrl, sdrv_firewall_callback_t callback, void *userdata); /** * @brief Handle firewall interrupt. * * This function clear MAC/PPC/MPC Interruption, return interrupt state. * * @param [in] irq the irq number of the firewall. * @param [in] ctrl sdrv firewall controller. * * @return The result of this function. * @details - return 0 : Handle firewall interrupt success. * - return 1 : The pointer to the MAC configuration is NULL. * - return 2 : The firewall is uninitialized. */ int sdrv_firewall_irq_handler(uint32_t irq, void *ctrl); /** * @brief Get firewall illegal access infomation. * * Should enable the macro FIREWALL_INTERRUPT_EN. * * @param[in] ctrl the firewall instance. * @param[in] firewall_err_info Pointer to the buffer used by system to get the * information. * * @return The result of this function. * @details - return FIREWALL_E_OK : Set callback function success. * - return FIREWALL_E_NULL_POINTER : The pointer to the MAC * configuration is NULL. * - return FIREWALL_E_UNINIT : The firewall is uninitialized. */ status_t sdrv_firewall_get_error_info(sdrv_firewall_t *ctrl, sdrv_firewall_err_t *firewall_err_info); #endif /* SDRV_FIREWALL_H */ /* End of file */