/** ************************************************************************************************ * 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_mac.c * \brief SSDK Firewall MAC Driver * * *
Date Version *
2023/11/29 1.0.0 *
**************************************************************************************************/ #ifdef __cplusplus extern "C" { #endif /*************************************************************************************************** * Private Macro definition **************************************************************************************************/ #include #include "sdrv_firewall_mac.h" /*************************************************************************************************** * Private Macro definition **************************************************************************************************/ /** \brief The offset address of the master domain assignment register. */ #define MAC_MDA_OFFSET_ADDR(n) ((uint32_t)((uint32_t)(n)*0x8U)) /** \brief The bit mask of locking the master domain assignment register. */ #define MAC_MDA_LOCK ((uint32_t)(0x1UL << 31U)) /** \brief The domain id range is 0 ~ 7. */ #define MAC_MDA_DID_VALUE(did) ((uint32_t)(did)&0x7U) /** \brief The offset address of the master transaction attribute register. */ #define MAC_MAA_ADDR(n) ((uint32_t)(0x4U + ((uint32_t)(n)*0x8U))) /** \brief The bit mask of locking the master transaction privileged/user attribute. */ #define MAC_MAA_PRI_LOCK ((uint32_t)(0x1UL << 5U)) /** \brief The bit mask of locking the master transaction secure/non-secure attribute. */ #define MAC_MAA_SEC_LOCK ((uint32_t)(0x1UL << 2U)) /** \brief The offset address of the global manager register. */ #define MAC_ACS_DID ((uint32_t)0x200U) /** \brief The bit mask of locking the global manager configuration. */ #define MAC_ACS_DID_LOCK ((uint32_t)(0x1UL << 31U)) /** \brief The domain id range is 0 ~ 7. */ #define MAC_ACS_DID_VALUE(did) ((uint32_t)((did)&0x7U)) /** \brief The offset address of the response error disable register. */ #define MAC_RESP_ERR_DIS ((uint32_t)0x3FCU) /** \brief The bit mask of locking the response error disable configurations for MAC/MPC/PPC. */ #define MAC_RESP_ERR_DIS_ALL_LOCK ((uint32_t)(0x1UL << 31U)) /** \brief The bit mask of locking the response error disable configurations for MAC. */ #define MAC_RESP_ERR_DIS_MAC_LOCK ((uint32_t)(0x1UL << 30U)) /** \brief The bit mask of disabling the response error feature for MAC/MPC/PPC. */ #define MAC_RESP_ERR_DIS_ALL_DIS ((uint32_t)(0x1UL << 1U)) /** \brief The bit mask of disabling the response error feature for MAC. */ #define MAC_RESP_ERR_DIS_MAC_DIS ((uint32_t)(0x1UL)) /** \brief The offset address of the MAC interrupt status register. */ #define MAC_FUNC_INT_STA ((uint32_t)0x2E0U) /** \brief The offset address of the MAC interrupt controller register. */ #define MAC_FUNC_INT_STA_EN ((uint32_t)0x2E4U) /** \brief The offset address of the MAC interrupt signal register. */ #define MAC_FUNC_INT_SIG_EN ((uint32_t)0x2E8U) /*************************************************************************************************** * Global Function Declarations **************************************************************************************************/ /** * @brief Configure the mapping between masters and domains in MAC module. * * This function configure the mapping between masters and domains in MAC module. * The System should call sdrv_firewall_mac_lock_domain_assignment() to lock the MAC * configurations after calling this function. * * @param[in] base the address of the MAC module. * @param[in] mac_cfg the configuration of the MAC. * * @return The result of the MAC initialization function * @details - return FIREWALL_E_OK : initializa MAC success. * - return FIREWALL_E_NULL_POINTER : The pointer is a NULL_PTR. */ status_t sdrv_firewall_mac_configure(uint32_t base, const sdrv_mac_config_t *mac_cfg) { status_t ret_val = FIREWALL_E_OK; uint8_t master_num; uint8_t domain_num; /* #10 Check the parameters. */ if (NULL == mac_cfg) { ret_val = FIREWALL_E_NULL_POINTER; } else { /* #20 Configure the firewall permission for main core. */ /* Assign the main master to the manager domain, and lock this configuration. */ writel(MAC_MDA_DID_VALUE(FIREWALL_MANAGER_DOMAIN_ID), base + MAC_MDA_OFFSET_ADDR(FIREWALL_MAIN_MASTER_ID)); writel(MAC_MDA_DID_VALUE(FIREWALL_MANAGER_DOMAIN_ID) | MAC_MDA_LOCK, base + MAC_MDA_OFFSET_ADDR(FIREWALL_MAIN_MASTER_ID)); /* Set the global manager. */ writel(MAC_MDA_DID_VALUE(FIREWALL_MANAGER_DOMAIN_ID), base + MAC_ACS_DID); writel(MAC_MDA_DID_VALUE(FIREWALL_MANAGER_DOMAIN_ID) | MAC_MDA_LOCK, base + MAC_ACS_DID); /* #30 Assign all masters to the different domain. */ for (domain_num = 0U; domain_num < FIREWALL_DOMAIN_MAXNUM; domain_num++) { if (NULL != mac_cfg[domain_num]) { for (master_num = 0U; mac_cfg[domain_num][master_num] < FIREWALL_MASTER_MAXNUM; ++master_num) { /* Assign the master to the specified domain. */ writel(MAC_MDA_DID_VALUE(domain_num), base + MAC_MDA_OFFSET_ADDR( mac_cfg[domain_num][master_num])); } } } /* #40 lock the master transaction attribute, not modify transaction * attribute. */ for (uint32_t i = 0U; i < FIREWALL_MASTER_MAXNUM; i++) { writel(MAC_MAA_PRI_LOCK | MAC_MAA_SEC_LOCK, base + MAC_MAA_ADDR(i)); } #if (1U != FIREWALL_RESPONSE_ERROR_EN) /* #50 Disable respone error when illegal access */ writel(MAC_RESP_ERR_DIS_ALL_DIS | MAC_RESP_ERR_DIS_MAC_DIS, base + MAC_RESP_ERR_DIS); writel(MAC_RESP_ERR_DIS_ALL_LOCK | MAC_RESP_ERR_DIS_MAC_LOCK, base + MAC_RESP_ERR_DIS); #endif /* (1U != FIREWALL_RESPONSE_ERROR_EN) */ } return ret_val; } /** * @brief Assigns the specified master to a domain. * * This function is called by sdrv_firewall_assign_domain(). * * @param[in] base the address of the MAC module. * @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 : Change domain success. * - return FIREWALL_E_MAC_MASTER_ID : invalid master id. * - return FIREWALL_E_MAC_DOMAIN_ID : invalid domain id. * - return FIREWALL_E_MAC_LOCKED : domain assign has been locked. */ status_t sdrv_firewall_mac_assign_domain(uint32_t base, uint8_t master_id, uint8_t domain_id) { status_t ret_val = FIREWALL_E_OK; /* #10 Check the parameters. */ if (master_id >= FIREWALL_MASTER_MAXNUM) { ret_val = FIREWALL_E_MAC_MASTER_ID; } else if (domain_id >= FIREWALL_DOMAIN_MAXNUM) { ret_val = FIREWALL_E_MAC_DOMAIN_ID; } else if (0U != (MAC_ACS_DID_LOCK & readl(base + MAC_MDA_OFFSET_ADDR(master_id)))) { ret_val = FIREWALL_E_MAC_LOCKED; } else { /* #20 Assign the master to the specified domain. */ writel(MAC_MDA_DID_VALUE(domain_id), base + MAC_MDA_OFFSET_ADDR(master_id)); } return ret_val; } /** * @brief Lock the configuration of the map between masters and domains * in MAC module. * * This function lock the configuration of map between masters and domains * in MAC module. * This function is called by sdrv_firewall_lock_domain_assignment(). * * @param[in] base the address of the MAC module. */ void sdrv_firewall_mac_lock_domain_assignment(uint32_t base) { uint8_t master_num; for (master_num = 0U; master_num < FIREWALL_MASTER_MAXNUM; ++master_num) { writel(MAC_MDA_LOCK | readl(base + MAC_MDA_OFFSET_ADDR(master_num)), base + MAC_MDA_OFFSET_ADDR(master_num)); } } /** * @brief Clear the interrupt status of the MAC module. * * @param[in] base the address of the MAC module. */ void sdrv_firewall_mac_clear_interrupt(uint32_t base) { /* #10 Clear the interrupt of the MAC module. */ /* Disable the interrupt of the mac. */ writel(FIREWALL_REG_VALUE_MIN, base + MAC_FUNC_INT_STA_EN); /* Disable the interrupt signal of the mac. */ writel(FIREWALL_REG_VALUE_MIN, base + MAC_FUNC_INT_SIG_EN); /* Clear the interrupt status of the mac. */ writel(FIREWALL_REG_VALUE_MAX, base + MAC_FUNC_INT_STA); } #ifdef __cplusplus } #endif /* End of file */