blob: c4fe825643d0c74d5f0df83187f00437938b582c [file] [log] [blame]
Marc Moreno Berengue20dab392017-11-29 13:18:58 +00001/*
2 * Copyright (c) 2016 ARM Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef __DRIVER_MPC_H
17#define __DRIVER_MPC_H
18
19#include "Driver_Common.h"
20
21/* API version */
22#define ARM_MPC_API_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(1,0)
23
24/* Error code returned by the driver functions */
25#define ARM_MPC_ERR_NOT_INIT (ARM_DRIVER_ERROR_SPECIFIC - 1) ///< MPC not initialized */
26#define ARM_MPC_ERR_NOT_IN_RANGE (ARM_DRIVER_ERROR_SPECIFIC - 2) ///< Address does not belong to a range controlled by the MPC */
27#define ARM_MPC_ERR_NOT_ALIGNED (ARM_DRIVER_ERROR_SPECIFIC - 3) ///< Address is not aligned on the block size of this MPC */
28#define ARM_MPC_ERR_INVALID_RANGE (ARM_DRIVER_ERROR_SPECIFIC - 4) ///< The given address range to configure is invalid
29#define ARM_MPC_ERR_RANGE_SEC_ATTR_NON_COMPATIBLE (ARM_DRIVER_ERROR_SPECIFIC - 4) ///< The given range cannot be accessed with the wanted security attributes */
30
31/* Security attribute used in various place of the API */
32typedef enum _ARM_MPC_SEC_ATTR {
33 ARM_MPC_ATTR_SECURE, ///< Secure attribute
34 ARM_MPC_ATTR_NONSECURE, ///< Non-secure attribute
35 /* Used when getting the configuration of a memory range and some blocks are
36 * secure whereas some other are non secure */
37 ARM_MPC_ATTR_MIXED, ///< Mixed attribute
38} ARM_MPC_SEC_ATTR;
39
40/* Function documentation */
41/**
42 \fn ARM_DRIVER_VERSION ARM_MPC_GetVersion (void)
43 \brief Get driver version.
44 \return \ref ARM_DRIVER_VERSION
45
46 \fn int32_t ARM_MPC_Initialize (void)
47 \brief Initialize MPC Interface.
48 \return Returns error code.
49
50 \fn int32_t ARM_MPC_Uninitialize (void)
51 \brief De-initialize MPC Interface. The controlled memory region
52 should not be accessed after a call to this function, as
53 it is allowed to configure everything to be secure (to
54 prevent information leak for example).
55 \return Returns error code.
56
57 \fn int32_t ARM_MPC_GetBlockSize (uint32_t* blk_size)
58 \brief Get the block size of the MPC. All regions must be aligned
59 on this block size (base address and limit+1 address).
60 \param[out] blk_size: The block size in bytes.
61 \return Returns error code.
62
63 \fn int32_t ARM_MPC_GetCtrlConfig (uint32_t* ctrl_val)
64 \brief Get some information on how the MPC IP is configured.
65 \param[out] ctrl_val: MPC control configuration
66 \return Returns error code.
67
68 \fn int32_t ARM_MPC_SetCtrlConfig (uint32_t ctrl)
69 \brief Set new control configuration for the MPC IP.
70 \param[in] ctrl: New control configuration.
71 \return Returns error code.
72
73 \fn int32_t ARM_MPC_ConfigRegion (uintptr_t base,
74 uintptr_t limit,
75 ARM_MPC_SEC_ATTR attr)
76 \brief Configure a memory region (base and limit included).
77 Both base and limit addresses must belong to the same
78 memory range, and this range must be managed by this MPC.
79 Also, some ranges are only allowed to be configured as
80 secure/non-secure, because of hardware requirements
81 (security aliases), and only a relevant security attribute
82 is therefore allowed for such ranges.
83 \param[in] base: Base address of the region to configure. This
84 bound is included in the configured region.
85 This must be aligned on the block size of this MPC.
86 \param[in] limit: Limit address of the region to configure. This
87 bound is included in the configured region.
88 Limit+1 must be aligned on the block size of this MPC.
89 \param[in] attr: Wanted security attribute of the region.
90 \return Returns error code.
91
92 \fn int32_t ARM_MPC_GetRegionConfig (uintptr_t base,
93 uintptr_t limit,
94 ARM_MPC_SEC_ATTR *attr)
95 \brief Gets a memory region (base and limit included).
96 \param[in] base: Base address of the region to poll. This
97 bound is included. It does not need to be aligned
98 in any way.
99 \param[in] limit: Limit address of the region to poll. This
100 bound is included. (limit+1) does not need to be aligned
101 in any way.
102 \param[out] attr: Security attribute of the region.
103 If the region has mixed secure/non-secure,
104 a special value is returned (\ref ARM_MPC_SEC_ATTR).
105
106 In case base and limit+1 addresses are not aligned on
107 the block size, the enclosing region with base and
108 limit+1 aligned on block size will be queried.
109 In case of early termination of the function (error), the
110 security attribute will be set to ARM_MPC_ATTR_MIXED.
111 \return Returns error code.
112
113 \fn int32_t ARM_MPC_EnableInterrupt (void)
114 \brief Enable MPC interrupt.
115 \return Returns error code.
116
117 \fn void ARM_MPC_DisableInterrupt (void)
118 \brief Disable MPC interrupt.
119
120 \fn void ARM_MPC_ClearInterrupt (void)
121 \brief Clear MPC interrupt.
122
123 \fn uint32_t ARM_MPC_InterruptState (void)
124 \brief MPC interrupt state.
125 \return Returns 1 if the interrupt is active, 0 otherwise.
126
127 \fn int32_t ARM_MPC_LockDown (void)
128 \brief Lock down the MPC configuration.
129 \return Returns error code.
130*/
131
132/**
133 * \brief Access structure of the MPC Driver.
134 */
135typedef struct _ARM_DRIVER_MPC {
136 ARM_DRIVER_VERSION (*GetVersion) (void); ///< Pointer to \ref ARM_MPC_GetVersion : Get driver version.
137 int32_t (*Initialize) (void); ///< Pointer to \ref ARM_MPC_Initialize : Initialize the MPC Interface.
138 int32_t (*Uninitialize) (void); ///< Pointer to \ref ARM_MPC_Uninitialize : De-initialize the MPC Interface.
139 int32_t (*GetBlockSize) (uint32_t* blk_size); ///< Pointer to \ref ARM_MPC_GetBlockSize : Get MPC block size
140 int32_t (*GetCtrlConfig) (uint32_t* ctrl_val); ///< Pointer to \ref ARM_MPC_GetCtrlConfig : Get the MPC control configuration flags.
141 int32_t (*SetCtrlConfig) (uint32_t ctrl); ///< Pointer to \ref ARM_MPC_SetCtrlConfig : Set the MPC control configuration flags.
142 int32_t (*ConfigRegion) (uintptr_t base, uintptr_t limit, ARM_MPC_SEC_ATTR attr); ///< Pointer to \ref ARM_MPC_ConfigRegion : Configure a region using the driver for the specific MPC.
143 int32_t (*GetRegionConfig) (uintptr_t base, uintptr_t limit, ARM_MPC_SEC_ATTR *attr); ///< Pointer to \ref ARM_MPC_GetRegionConfig : Get the configuration of a specific region on this MPC.
144 int32_t (*EnableInterrupt) (void); ///< Pointer to \ref ARM_MPC_EnableInterrupt : Enable MPC interrupt.
145 void (*DisableInterrupt) (void); ///< Pointer to \ref ARM_MPC_DisableInterrupt : Disable MPC interrupt.
146 void (*ClearInterrupt) (void); ///< Pointer to \ref ARM_MPC_ClearInterrupt : Clear MPC interrupt.
147 uint32_t (*InterruptState) (void); ///< Pointer to \ref ARM_MPC_InterruptState : MPC interrupt State.
148 int32_t (*LockDown) (void); ///< Pointer to \ref ARM_MPC_LockDown : Lock down the MPC configuration.
149} const ARM_DRIVER_MPC;
150
151#endif /* __DRIVER_MPC_H */
152