1 // Copyright (C) 2022 Beken Corporation 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include <driver/mpc_types.h> 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 /** 24 * @brief Init the MPC driver 25 * 26 * This API init the resoure common: 27 * - Init MPC driver control memory 28 * 29 * @attention 1. This API should be called before any other MPC APIs. 30 * 31 * @return 32 * - BK_OK: succeed 33 * - others: other errors. 34 */ 35 bk_err_t bk_mpc_driver_init(void); 36 37 /** 38 * @brief Deinit the MPC driver 39 * 40 * This API free all resource related to MPC. 41 * 42 * @return 43 * - BK_OK: succeed 44 * - others: other errors. 45 */ 46 bk_err_t bk_mpc_driver_deinit(void); 47 48 /** 49 * @brief Get the block size, unit is byte 50 * 51 * @param dev the MPC device 52 * 53 * @return the block size 54 */ 55 uint32_t bk_mpc_get_block_size(mpc_dev_t dev); 56 57 /** 58 * @brief Get the block index max value 59 * 60 * @param dev the MPC device 61 * 62 * @return the max block index 63 */ 64 uint32_t bk_mpc_get_max_block_index(mpc_dev_t dev); 65 66 /** 67 * @brief Set a MPC secure attribute configuration on the memory passed as parameter for a number of blocks 68 * 69 * @param dev the MPC device 70 * @param mem_addr_offset start memory address offset to configure 71 * (must be block size aligned) 72 * @param block_num number of blocks to configure 73 * (block size is bk_mpc_get_block_size(dev)) 74 * @param secure_type the MPC secure type, with each element must be MPC_BLOCK_SECURE or MPC_BLOCK_NON_SECURE 75 * 76 * @return 77 * - BK_OK: succeed 78 * - BK_ERR_MPC_DRIVER_NOT_INIT: MPC driver is not init 79 * - BK_ERR_MPC_BLOCK_INDEX_OUT_OF_RANGE: MPC block index is out of range 80 * - BK_ERR_MPC_INVALID_LUT_PARAM: MPC invalid lut parameter 81 */ 82 bk_err_t bk_mpc_set_secure_attribute(mpc_dev_t dev, uint32_t mem_addr_offset, uint32_t block_num, mpc_block_secure_type_t secure_type); 83 84 /** 85 * @brief Lockdown MPC. After locking, only read operations are allowed 86 * 87 * @attention Once we call this API, MPC will be unlocked until the next reset 88 * 89 * @param dev the MPC device 90 * 91 * @return 92 * - BK_OK: succeed 93 * - BK_ERR_MPC_DRIVER_NOT_INIT: MPC driver is not init 94 */ 95 bk_err_t bk_mpc_lockdown(mpc_dev_t dev); 96 97 #ifdef __cplusplus 98 } 99 #endif 100 101