Edison Ai | 75afd37 | 2020-04-21 18:29:57 +0800 | [diff] [blame^] | 1 | ########################## |
| 2 | Hardware Abstraction Layer |
| 3 | ########################## |
| 4 | |
| 5 | :Organization: Arm Limited |
| 6 | :Contact: tf-m@lists.trustedfirmware.org |
| 7 | |
| 8 | :API Version: 0.9 |
| 9 | |
| 10 | ************ |
| 11 | Introduction |
| 12 | ************ |
| 13 | :term:`TF-M` :term:`HAL` abstracts the hardware-oriented and platform specific |
| 14 | operations on the :term:`SPE` side and provides a set of APIs to the upper |
| 15 | layers such as :term:`SPM`, :term:`RoT Service`. |
| 16 | The :term:`HAL` aims to cover the platform different aspects whereas common |
| 17 | architecturally defined aspects are done generically within the common |
| 18 | :term:`SPE`. |
| 19 | In some cases, although the operations are defined architecturally, |
| 20 | it may not be possible to generalize implementations because lots of information |
| 21 | is only known to platforms. |
| 22 | It is more efficient to define a :term:`HAL` API for those architectural |
| 23 | operations as well. |
| 24 | |
| 25 | .. note:: |
| 26 | :term:`TBSA-M` provides the hardware requirements for security purposes. |
| 27 | :term:`TF-M` :term:`HAL` tries to reference :term:`TBSA-M` recommendations in |
| 28 | the interfaces from the software perspective only. Please reference |
| 29 | :term:`TBSA-M` for your security hardware design. |
| 30 | |
| 31 | Design Goals |
| 32 | ============ |
| 33 | :term:`TF-M` :term:`HAL` is designed to simplify the integration efforts on |
| 34 | different platforms. |
| 35 | |
| 36 | :term:`TF-M` :term:`HAL` is designed to make it easy to use the hardware and |
| 37 | develop the :term:`SPM` and :term:`RoT Service` which need to access the |
| 38 | devices. |
| 39 | |
| 40 | :term:`TF-M` :term:`HAL` is designed to make the structure clearer and let the |
| 41 | :term:`TF-M` mainly focus on :term:`PSA` implementation. |
| 42 | |
| 43 | ******** |
| 44 | Overview |
| 45 | ******** |
| 46 | This section provides an overview of the abstraction layer structure. |
| 47 | |
| 48 | .. figure:: media/hal_structure.png |
| 49 | |
| 50 | Here lists a minimal set of necessary functionalities: |
| 51 | |
| 52 | - **Isolation API**: Provides the necessary isolation functionalities required |
| 53 | by the :term:`PSA-FF-M` and :term:`TBSA-M`, and provides APIs to :term:`SPM` |
| 54 | to check the permissions of memory access. |
| 55 | - **Platform API**: Provides the platform initialization, platform-specific |
| 56 | memory information, system reset, etc. |
| 57 | - **Loader API**: Provides the functions to load partitions and services and |
| 58 | provides the necessary data to :term:`SPM`. |
| 59 | - **Log dev API**: Provides the log system functions. |
| 60 | - **Interrupt API**: Provides the interrupt functions. |
| 61 | |
| 62 | .. note:: |
| 63 | - There is a non-secure :term:`HAL` that focuses on the mailbox operation API |
| 64 | for Dual-core topology. For more information about it, please refer to |
| 65 | :doc:`Mailbox Design in TF-M on Dual-core System |
| 66 | </docs/design_documents/dual-cpu/mailbox_design_on_dual_core_system>`. |
| 67 | - The minimal set of :term:`TF-M` :term:`HAL` is sufficient for Secure |
| 68 | Partitions by using customized peripheral interfaces. To provide easier |
| 69 | portability for the Secure Partitions, a Secure Partition :term:`HAL` is |
| 70 | provided in this design too. |
| 71 | - The debug mechanisms give the external entity the corresponding right to |
| 72 | access the system assets. :term:`TF-M` ensures that the external entity is |
| 73 | permitted access to those assets. Currently, :term:`TF-M` only needs the |
| 74 | debug authentication. The whole debug mechanism and related :term:`HAL` will |
| 75 | be enhanced in the future. Please refer to the :doc:`Debug authentication |
| 76 | settings section </platform/readme>` for more detail. |
| 77 | |
| 78 | ***************** |
| 79 | Design Principles |
| 80 | ***************** |
| 81 | As :term:`TF-M` runs on resource-constrained devices, the :term:`HAL` tries to |
| 82 | avoid multiple level abstractions which cost more resources. |
| 83 | |
| 84 | Part of the :term:`HAL` interfaces does not focus on exact hardware operations |
| 85 | such as power on/off or PIN manipulation. |
| 86 | Instead, the :term:`HAL` abstracts higher-level interfaces to reserve the |
| 87 | implementation flexibility for the platform vendors. |
| 88 | |
| 89 | The :term:`TF-M` :term:`HAL` should be easy to deprecate APIs and provide |
| 90 | compatibilities. |
| 91 | Any API incompatibility should be detected during building. |
| 92 | |
| 93 | :term:`TF-M` relies on the :term:`HAL` APIs to be implemented correctly and |
| 94 | trusts the :term:`HAL` APIs. |
| 95 | :term:`TFM` can provide assertions to detect common programming errors but |
| 96 | essentially no further extensive checks will be provided. |
| 97 | |
| 98 | ************ |
| 99 | Source Files |
| 100 | ************ |
| 101 | This section describes the source file of the :term:`TF-M` :term:`HAL`, |
| 102 | including the header and c files. |
| 103 | |
| 104 | tfm_hal_defs.h |
| 105 | ============== |
| 106 | This header file contains the definitions of common macros and types used by all |
| 107 | :term:`HAL` APIs. Please refer to `Status Codes`_ for detailed definitions. |
| 108 | |
| 109 | tfm_hal_[module].[h/c] |
| 110 | ====================== |
| 111 | All other headers and c files are classified by the modules, such as isolation, |
| 112 | platform, interrupt, devices, etc. |
| 113 | |
| 114 | .. note:: |
| 115 | There are common files in the platform folder include the implemented |
| 116 | :term:`HAL` APIs. The platform vendors can use them directly but need to |
| 117 | implement all the sub APIs. |
| 118 | |
| 119 | ************ |
| 120 | Status Codes |
| 121 | ************ |
| 122 | These are common status and error codes for all :term:`HAL` APIs. |
| 123 | |
| 124 | Types |
| 125 | ===== |
| 126 | tfm_hal_status_t |
| 127 | ---------------- |
| 128 | This is a status code to be used as the return type of :term:`HAL` APIs. |
| 129 | |
| 130 | .. code-block:: c |
| 131 | |
| 132 | typedef int32_t tfm_hal_status_t |
| 133 | |
| 134 | Error Codes |
| 135 | =========== |
| 136 | Negative values indicate an error. Zero and positive values indicate success. |
| 137 | |
| 138 | Here is the general list. The detailed usages for each error code are described |
| 139 | in the API introduction sections. |
| 140 | |
| 141 | TFM_HAL_SUCCESS |
| 142 | --------------- |
| 143 | Status code to indicate general success. |
| 144 | |
| 145 | .. code-block:: c |
| 146 | |
| 147 | #define TFM_HAL_SUCCESS ((tfm_hal_status_t)0) |
| 148 | |
| 149 | TFM_HAL_ERROR_GENERIC |
| 150 | --------------------- |
| 151 | Status code to indicate an error that does not correspond to any defined failure |
| 152 | cause. |
| 153 | |
| 154 | .. code-block:: c |
| 155 | |
| 156 | #define TFM_HAL_ERROR_GENERIC ((tfm_hal_status_t)-1) |
| 157 | |
| 158 | TFM_HAL_ERROR_NOT_INIT |
| 159 | ---------------------- |
| 160 | Status code to indicate that the module is not initialed. |
| 161 | |
| 162 | .. code-block:: c |
| 163 | |
| 164 | #define TFM_HAL_ERROR_NOT_INIT ((tfm_hal_status_t)-2) |
| 165 | |
| 166 | TFM_HAL_ERROR_INVALID_INPUT |
| 167 | --------------------------- |
| 168 | Status code to indicate that the input is invalid. |
| 169 | |
| 170 | .. code-block:: c |
| 171 | |
| 172 | #define TFM_HAL_ERROR_INVALID_INPUT ((tfm_hal_status_t)-3) |
| 173 | |
| 174 | TFM_HAL_ERROR_NOT_SUPPORTED |
| 175 | --------------------------- |
| 176 | Status code to indicate that the requested operation or a parameter is not |
| 177 | supported. |
| 178 | |
| 179 | .. code-block:: c |
| 180 | |
| 181 | #define TFM_HAL_ERROR_NOT_SUPPORTED ((tfm_hal_status_t)-4) |
| 182 | |
| 183 | TFM_HAL_ERROR_BAD_STATE |
| 184 | ----------------------- |
| 185 | Status code to indicate that the requested action cannot be performed in the |
| 186 | current state. |
| 187 | |
| 188 | .. code-block:: c |
| 189 | |
| 190 | #define TFM_HAL_ERROR_BAD_STATE ((tfm_hal_status_t)-5) |
| 191 | |
| 192 | TFM_HAL_ERROR_MAX_VALUE |
| 193 | ----------------------- |
| 194 | Status code to indicate that the current number has got the max value. |
| 195 | |
| 196 | .. code-block:: c |
| 197 | |
| 198 | #define TFM_HAL_ERROR_MAX_VALUE ((tfm_hal_status_t)-6) |
| 199 | |
| 200 | TFM_HAL_ERROR_MEM_FAULT |
| 201 | ----------------------- |
| 202 | Status code to indicate that the memory check failed. |
| 203 | |
| 204 | .. code-block:: c |
| 205 | |
| 206 | #define TFM_HAL_ERROR_MEM_FAULT ((tfm_hal_status_t)-7) |
| 207 | |
| 208 | -------------- |
| 209 | |
| 210 | *Copyright (c) 2020, Arm Limited. All rights reserved.* |