blob: 982a93ae4cd111472976d8430e40611a39340f26 [file] [log] [blame]
Edison Ai75afd372020-04-21 18:29:57 +08001##########################
2Hardware Abstraction Layer
3##########################
4
5:Organization: Arm Limited
6:Contact: tf-m@lists.trustedfirmware.org
7
8:API Version: 0.9
9
10************
11Introduction
12************
13:term:`TF-M` :term:`HAL` abstracts the hardware-oriented and platform specific
14operations on the :term:`SPE` side and provides a set of APIs to the upper
15layers such as :term:`SPM`, :term:`RoT Service`.
16The :term:`HAL` aims to cover the platform different aspects whereas common
17architecturally defined aspects are done generically within the common
18:term:`SPE`.
19In some cases, although the operations are defined architecturally,
20it may not be possible to generalize implementations because lots of information
21is only known to platforms.
22It is more efficient to define a :term:`HAL` API for those architectural
23operations 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
31Design Goals
32============
33:term:`TF-M` :term:`HAL` is designed to simplify the integration efforts on
34different platforms.
35
36:term:`TF-M` :term:`HAL` is designed to make it easy to use the hardware and
37develop the :term:`SPM` and :term:`RoT Service` which need to access the
38devices.
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********
44Overview
45********
46This section provides an overview of the abstraction layer structure.
47
Anton Komlevb3f64662023-01-28 11:53:05 +000048.. figure:: /design_docs/media/hal_structure.png
Edison Ai75afd372020-04-21 18:29:57 +080049
50Here 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.
Edison Ai75afd372020-04-21 18:29:57 +080057 - **Log dev API**: Provides the log system functions.
58 - **Interrupt API**: Provides the interrupt functions.
59
60.. note::
61 - There is a non-secure :term:`HAL` that focuses on the mailbox operation API
62 for Dual-core topology. For more information about it, please refer to
63 :doc:`Mailbox Design in TF-M on Dual-core System
Anton Komlevff7cbae2023-01-12 16:28:26 +000064 </design_docs/dual-cpu/mailbox_design_on_dual_core_system>`.
Edison Ai75afd372020-04-21 18:29:57 +080065 - The minimal set of :term:`TF-M` :term:`HAL` is sufficient for Secure
66 Partitions by using customized peripheral interfaces. To provide easier
67 portability for the Secure Partitions, a Secure Partition :term:`HAL` is
68 provided in this design too.
69 - The debug mechanisms give the external entity the corresponding right to
70 access the system assets. :term:`TF-M` ensures that the external entity is
71 permitted access to those assets. Currently, :term:`TF-M` only needs the
72 debug authentication. The whole debug mechanism and related :term:`HAL` will
73 be enhanced in the future. Please refer to the :doc:`Debug authentication
Anton Komleve69cf682023-01-31 11:59:25 +000074 settings section </integration_guide/source_structure/platform_folder>`
75 for more details.
Edison Ai75afd372020-04-21 18:29:57 +080076
77*****************
78Design Principles
79*****************
80As :term:`TF-M` runs on resource-constrained devices, the :term:`HAL` tries to
81avoid multiple level abstractions which cost more resources.
82
83Part of the :term:`HAL` interfaces does not focus on exact hardware operations
84such as power on/off or PIN manipulation.
85Instead, the :term:`HAL` abstracts higher-level interfaces to reserve the
86implementation flexibility for the platform vendors.
87
88The :term:`TF-M` :term:`HAL` should be easy to deprecate APIs and provide
89compatibilities.
90Any API incompatibility should be detected during building.
91
92:term:`TF-M` relies on the :term:`HAL` APIs to be implemented correctly and
93trusts the :term:`HAL` APIs.
94:term:`TFM` can provide assertions to detect common programming errors but
95essentially no further extensive checks will be provided.
96
97************
98Source Files
99************
100This section describes the source file of the :term:`TF-M` :term:`HAL`,
101including the header and c files.
102
103tfm_hal_defs.h
104==============
105This header file contains the definitions of common macros and types used by all
106:term:`HAL` APIs. Please refer to `Status Codes`_ for detailed definitions.
107
108tfm_hal_[module].[h/c]
109======================
110All other headers and c files are classified by the modules, such as isolation,
111platform, interrupt, devices, etc.
112
113.. note::
114 There are common files in the platform folder include the implemented
115 :term:`HAL` APIs. The platform vendors can use them directly but need to
116 implement all the sub APIs.
117
118************
119Status Codes
120************
121These are common status and error codes for all :term:`HAL` APIs.
122
123Types
124=====
125tfm_hal_status_t
126----------------
127This is a status code to be used as the return type of :term:`HAL` APIs.
128
129.. code-block:: c
130
Summer Qin2ecfc9f2020-08-20 14:20:27 +0800131 enum tfm_hal_status_t {
Mingyang Sun45c6c202020-09-23 16:17:50 +0800132 TFM_HAL_ERROR_MEM_FAULT = SCHAR_MIN,
Summer Qin2ecfc9f2020-08-20 14:20:27 +0800133 TFM_HAL_ERROR_MAX_VALUE,
134 TFM_HAL_ERROR_BAD_STATE,
135 TFM_HAL_ERROR_NOT_SUPPORTED,
136 TFM_HAL_ERROR_INVALID_INPUT,
137 TFM_HAL_ERROR_NOT_INIT,
138 TFM_HAL_ERROR_GENERIC,
139 TFM_HAL_SUCCESS = 0
140 };
Edison Ai75afd372020-04-21 18:29:57 +0800141
142Error Codes
143===========
144Negative values indicate an error. Zero and positive values indicate success.
145
146Here is the general list. The detailed usages for each error code are described
147in the API introduction sections.
148
149TFM_HAL_SUCCESS
150---------------
151Status code to indicate general success.
152
Edison Ai75afd372020-04-21 18:29:57 +0800153TFM_HAL_ERROR_GENERIC
154---------------------
155Status code to indicate an error that does not correspond to any defined failure
156cause.
157
Edison Ai75afd372020-04-21 18:29:57 +0800158TFM_HAL_ERROR_NOT_INIT
159----------------------
160Status code to indicate that the module is not initialed.
161
Edison Ai75afd372020-04-21 18:29:57 +0800162TFM_HAL_ERROR_INVALID_INPUT
163---------------------------
164Status code to indicate that the input is invalid.
165
Edison Ai75afd372020-04-21 18:29:57 +0800166TFM_HAL_ERROR_NOT_SUPPORTED
167---------------------------
168Status code to indicate that the requested operation or a parameter is not
169supported.
170
Edison Ai75afd372020-04-21 18:29:57 +0800171TFM_HAL_ERROR_BAD_STATE
172-----------------------
173Status code to indicate that the requested action cannot be performed in the
174current state.
175
Edison Ai75afd372020-04-21 18:29:57 +0800176TFM_HAL_ERROR_MAX_VALUE
177-----------------------
178Status code to indicate that the current number has got the max value.
179
Edison Ai75afd372020-04-21 18:29:57 +0800180TFM_HAL_ERROR_MEM_FAULT
181-----------------------
182Status code to indicate that the memory check failed.
183
Edison Aif4b61132020-07-01 18:35:17 +0800184***************************
185API Definition for TF-M SPM
186***************************
187This section describes the APIs defined for :term:`TF-M` :term:`SPM`.
188
Edison Aif542e6b2020-07-01 17:55:42 +0800189Platform API
190============
191The platform API is a higher-level abstraction layer of the platform, other than
192a dedicated API set for the special hardware devices.
193
194APIs
195----
196tfm_hal_platform_init()
197^^^^^^^^^^^^^^^^^^^^^^^
198**Prototype**
199
200.. code-block:: c
201
202 enum tfm_hal_status_t tfm_hal_platform_init(void)
203
204**Description**
205
Kevin Pengb8bc0d22021-09-08 14:37:50 +0800206This API performs the platform initializations **before** the :term:`SPM`
207initialization.
Edison Aif542e6b2020-07-01 17:55:42 +0800208
Kevin Pengb8bc0d22021-09-08 14:37:50 +0800209The initializations could include but not limited to:
210- Fault handlers
211- Reset configurations
212- Debug init
213- NVIC init
Edison Aif542e6b2020-07-01 17:55:42 +0800214
215**Parameter**
216
217- ``void`` - None.
218
219**Return Values**
220
221- ``TFM_HAL_SUCCESS`` - Init success.
222- ``TFM_HAL_ERROR_GENERIC`` - Generic errors.
223
224tfm_hal_system_reset()
225^^^^^^^^^^^^^^^^^^^^^^
226**Prototype**
227
228.. code-block:: c
229
230 void tfm_hal_system_reset(void)
231
232**Description**
233
234This API performs a system reset.
235
236The platform can uninitialize some resources before reset.
237
Joakim Anderssone0a1dc32022-09-27 10:39:18 +0200238When ``CONFIG_TFM_HALT_ON_CORE_PANIC`` is disabled this function is called to reset
Sebastian Bøe055d83a2022-02-21 12:01:41 +0100239the system when a fatal error occurs.
240
241**Parameter**
242
243- ``void`` - None
244
245**Return Values**
246
247- ``void`` - None
248
249**Note**
250
251This API should not return.
252
253tfm_hal_system_halt()
254^^^^^^^^^^^^^^^^^^^^^
255**Prototype**
256
257.. code-block:: c
258
259 void tfm_hal_system_halt(void)
260
261**Description**
262
263This API enters the CPU into an infinite loop.
264
265The platform can uninitialize some resources before looping forever.
266
Joakim Anderssone0a1dc32022-09-27 10:39:18 +0200267When ``CONFIG_TFM_HALT_ON_CORE_PANIC`` is enabled this function is called to halt the
Sebastian Bøe055d83a2022-02-21 12:01:41 +0100268system when a fatal error occurs.
269
Edison Aif542e6b2020-07-01 17:55:42 +0800270**Parameter**
271
272- ``void`` - None
273
274**Return Values**
275
276- ``void`` - None
277
278**Note**
279
280This API should not return.
281
edison.ai37e0f602020-07-13 18:30:58 +0800282Isolation API
283=============
284The :term:`PSA-FF-M` defines three isolation levels and a memory access rule to
Nicola Mazzucatoafd24bb2024-02-14 17:27:27 +0000285provide diverse levels of security. The isolation API provides the functions to
edison.ai37e0f602020-07-13 18:30:58 +0800286implement these requirements.
287
Ken Liu967ffa92022-05-25 15:13:34 +0800288The Isolation API operates on boundaries. A boundary represents a set of
289protection settings that isolates components and domains. Below are the
290boundary examples in the current implementation:
291
292 - Boundaries between SPM and Secure Partitions.
293 - Boundaries between ARoT domain and PRoT domain.
294
295There are two types of boundaries:
296
297 - Static boundaries: Set up when the system is initializing and
298 persistent after the initialization. This type of boundary needs the
299 set-up operations only.
300 - Partition boundaries: Keeps switching from one to another when the system
301 is running. This type of boundary needs both set-up and switching
302 operations.
303
304The boundary operations are abstracted as HAL interfaces because isolation
305hardwares can be different for platforms:
306
307 - The set-up HAL interface creates a partition boundary based on given
308 partition information. This created boundary is bound with the partition
309 for subsequent usage. The binding is done by storing the boundary into
310 partition runtime data.
311 - The activation HAL interface activates the partition boundary to secure
312 the execution for the partition to be switched. The target partition's
313 information and boundary are given to the activation HAL to accomplish
314 the operation.
315
316The data representing the partition boundary in runtime is defined with the
317opaque type ``uintptr_t``:
318
319 - It is required that one value represents one boundary. The different values
320 represent different boundaries.
321 - The value is created by HAL implementation with its own-defined encoding
322 scheme.
323
324The HAL implementation defined encoding scheme can be designed for
325implementation convenience. For example:
326
327 - The implementation scheme can encode attribute flags into integer bits.
328 This could help the activation HAL to extract the protection settings
329 quickly from this encoded value, or even write to hardware registers
330 directly in the most ideal case. The initial TF-M Isolation HAL reference
331 implementation applies this scheme.
332 - The implementation scheme can reference the addresses of isolation
333 hardware description data. This could help the activation HAL to reference
334 the protection settings directly by pointers.
335
336Multiple Secure Partitions can bind with the same boundary value. This
337flexibility is useful for specific configurations. Take Isolation Level 2 as
338an example, assigning PRoT and ARoT domain boundaries to respective partitions
339can make execution more efficient, because switching two partitions in the
340same domain does not need to change the activated boundary.
341
Summer Qin56725eb2022-05-06 15:23:40 +0800342The boundary contains the partition's memory accessibility information, hence
343memory access check shall be performed based on boundary.
344
edison.ai37e0f602020-07-13 18:30:58 +0800345Memory Access Attributes
346------------------------
347The memory access attributes are encoded as bit fields, you can logic OR them to
Antonio de Angelis9d496a52025-01-07 21:18:00 +0000348have a combination of the attributes, for example
Ken Liuce58bfc2021-05-12 17:54:48 +0800349``TFM_HAL_ACCESS_UNPRIVILEGED | TFM_HAL_ACCESS_READABLE`` is unprivileged
edison.ai37e0f602020-07-13 18:30:58 +0800350readable. The data type is `uint32_t`.
351
Ken Liuce58bfc2021-05-12 17:54:48 +0800352TFM_HAL_ACCESS_EXECUTABLE
353^^^^^^^^^^^^^^^^^^^^^^^^^
edison.ai37e0f602020-07-13 18:30:58 +0800354The memory is executable.
355
356.. code-block:: c
357
Ken Liuce58bfc2021-05-12 17:54:48 +0800358 #define TFM_HAL_ACCESS_EXECUTABLE (1UL << 0)
edison.ai37e0f602020-07-13 18:30:58 +0800359
Ken Liuce58bfc2021-05-12 17:54:48 +0800360TFM_HAL_ACCESS_READABLE
361^^^^^^^^^^^^^^^^^^^^^^^
edison.ai37e0f602020-07-13 18:30:58 +0800362The memory is readable.
363
364.. code-block:: c
365
Ken Liuce58bfc2021-05-12 17:54:48 +0800366 #define TFM_HAL_ACCESS_READABLE (1UL << 1)
edison.ai37e0f602020-07-13 18:30:58 +0800367
Ken Liuce58bfc2021-05-12 17:54:48 +0800368TFM_HAL_ACCESS_WRITABLE
369^^^^^^^^^^^^^^^^^^^^^^^
edison.ai37e0f602020-07-13 18:30:58 +0800370The memory is writable.
371
372.. code-block:: c
373
Ken Liuce58bfc2021-05-12 17:54:48 +0800374 #define TFM_HAL_ACCESS_WRITABLE (1UL << 2)
edison.ai37e0f602020-07-13 18:30:58 +0800375
Ken Liuce58bfc2021-05-12 17:54:48 +0800376TFM_HAL_ACCESS_UNPRIVILEGED
377^^^^^^^^^^^^^^^^^^^^^^^^^^^
edison.ai37e0f602020-07-13 18:30:58 +0800378The memory is unprivileged mode accessible.
379
380.. code-block:: c
381
Ken Liuce58bfc2021-05-12 17:54:48 +0800382 #define TFM_HAL_ACCESS_UNPRIVILEGED (1UL << 3)
edison.ai37e0f602020-07-13 18:30:58 +0800383
Ken Liuce58bfc2021-05-12 17:54:48 +0800384TFM_HAL_ACCESS_DEVICE
385^^^^^^^^^^^^^^^^^^^^^
edison.ai37e0f602020-07-13 18:30:58 +0800386The memory is a MMIO device.
387
388.. code-block:: c
389
Ken Liuce58bfc2021-05-12 17:54:48 +0800390 #define TFM_HAL_ACCESS_DEVICE (1UL << 4)
edison.ai37e0f602020-07-13 18:30:58 +0800391
Ken Liuce58bfc2021-05-12 17:54:48 +0800392TFM_HAL_ACCESS_NS
393^^^^^^^^^^^^^^^^^
edison.ai37e0f602020-07-13 18:30:58 +0800394The memory is accessible from :term:`NSPE`
395
396.. code-block:: c
397
Ken Liuce58bfc2021-05-12 17:54:48 +0800398 #define TFM_HAL_ACCESS_NS (1UL << 5)
edison.ai37e0f602020-07-13 18:30:58 +0800399
400APIs
401----
Ken Liu967ffa92022-05-25 15:13:34 +0800402
Nicola Mazzucatoadd545e2024-02-19 09:57:56 +0000403tfm_hal_verify_static_boundaries()
404^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
405**Prototype**
406
407.. code-block:: c
408
409 fih_int tfm_hal_verify_static_boundaries(void)
410
411**Description**
412
413This API verifies the static isolation boundaries.
414
415Refer to the :term:`PSA-FF-M` for the definitions of the isolation boundaries.
416
417**Parameter**
418
419- ``void`` - None
420
421**Return Values**
422
423- ``TFM_HAL_SUCCESS`` - Verification has been successful.
424- ``TFM_HAL_ERROR_GENERIC`` - Verification failed.
425
edison.ai37e0f602020-07-13 18:30:58 +0800426tfm_hal_set_up_static_boundaries()
427^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
428**Prototype**
429
430.. code-block:: c
431
Ken Liuce58bfc2021-05-12 17:54:48 +0800432 enum tfm_hal_status_t tfm_hal_set_up_static_boundaries(void)
edison.ai37e0f602020-07-13 18:30:58 +0800433
434**Description**
435
436This API sets up the static isolation boundaries which are constant throughout
Ken Liu967ffa92022-05-25 15:13:34 +0800437the system runtime.
edison.ai37e0f602020-07-13 18:30:58 +0800438
Ken Liu967ffa92022-05-25 15:13:34 +0800439These boundaries include:
edison.ai37e0f602020-07-13 18:30:58 +0800440
Ken Liu967ffa92022-05-25 15:13:34 +0800441- The boundary between the :term:`SPE` and the :term:`NSPE`
442- The boundary to protect the SPM execution. For example, the PSA RoT
443 isolation boundary between the PSA Root of Trust and the Application Root of
444 Trust which is for isolation level 2 and 3 only.
edison.ai37e0f602020-07-13 18:30:58 +0800445
Ken Liu967ffa92022-05-25 15:13:34 +0800446Refer to the :term:`PSA-FF-M` for the definitions of the isolation boundaries.
edison.ai37e0f602020-07-13 18:30:58 +0800447
Nicola Mazzucatoadd545e2024-02-19 09:57:56 +0000448**Parameter**
449
450- ``void`` - None
451
edison.ai37e0f602020-07-13 18:30:58 +0800452**Return Values**
453
Ken Liu967ffa92022-05-25 15:13:34 +0800454- ``TFM_HAL_SUCCESS`` - Isolation boundaries have been set up.
455- ``TFM_HAL_ERROR_GENERIC`` - Failed to set up the static boundaries.
edison.ai37e0f602020-07-13 18:30:58 +0800456
Ken Liu967ffa92022-05-25 15:13:34 +0800457tfm_hal_bind_boundary()
458^^^^^^^^^^^^^^^^^^^^^^^^^
459**Prototype**
460
461.. code-block:: c
462
463 enum tfm_hal_status_t tfm_hal_bind_boundary(
464 const struct partition_load_info_t *p_ldinf,
465 uintptr_t *p_boundary);
466
467**Description**
468
469This API binds partition with a platform-generated boundary. The boundary is
470bound by writing the generated value into ``p_boundary``. And this bound
471boundary is used in subsequent calls to `tfm_hal_activate_boundary()`_ when
472boundary's owner partition get scheduled for running.
473
474**Parameter**
475
476- ``p_ldinf`` - Load information of the partition that is under loading.
477- ``p_boundary`` - Pointer for holding a partition's boundary.
478
479**Return Values**
480
481- ``TFM_HAL_SUCCESS`` - The boundary has been bound successfully.
482- ``TFM_HAL_ERROR_GENERIC`` - Failed to bind the handle.
483
484tfm_hal_activate_boundary()
Ken Liuce58bfc2021-05-12 17:54:48 +0800485^^^^^^^^^^^^^^^^^^^^^^^^^^^
edison.ai37e0f602020-07-13 18:30:58 +0800486**Prototype**
487
488.. code-block:: c
489
Ken Liu967ffa92022-05-25 15:13:34 +0800490 enum tfm_hal_status_t tfm_hal_activate_boundary(
Ken Liuce58bfc2021-05-12 17:54:48 +0800491 const struct partition_load_info_t *p_ldinf,
Ken Liu967ffa92022-05-25 15:13:34 +0800492 uintptr_t boundary);
edison.ai37e0f602020-07-13 18:30:58 +0800493
494**Description**
495
Ken Liu967ffa92022-05-25 15:13:34 +0800496This API requires the platform to activate the boundary to ensure the given
497Secure Partition can run successfully.
edison.ai37e0f602020-07-13 18:30:58 +0800498
Ken Liuce58bfc2021-05-12 17:54:48 +0800499The access permissions outside the boundary is platform-dependent.
edison.ai37e0f602020-07-13 18:30:58 +0800500
501**Parameter**
502
Ken Liu967ffa92022-05-25 15:13:34 +0800503- ``p_ldinf`` - The load information of the partition that is going to be run.
504- ``boundary`` - The boundary for the owner partition of ``p_ldinf``. This
Nicola Mazzucatoadd545e2024-02-19 09:57:56 +0000505 value is bound in function ``tfm_hal_bind_boundary``.
edison.ai37e0f602020-07-13 18:30:58 +0800506
507**Return Values**
508
509- ``TFM_HAL_SUCCESS`` - the isolation boundary has been set up.
Nicola Mazzucatoafd24bb2024-02-14 17:27:27 +0000510- ``TFM_HAL_ERROR_GENERIC`` - failed to set up the isolation boundary.
edison.ai37e0f602020-07-13 18:30:58 +0800511
Summer Qin56725eb2022-05-06 15:23:40 +0800512tfm_hal_memory_check()
513^^^^^^^^^^^^^^^^^^^^^^
edison.ai37e0f602020-07-13 18:30:58 +0800514**Prototype**
515
516.. code-block:: c
517
Summer Qin56725eb2022-05-06 15:23:40 +0800518 tfm_hal_status_t tfm_hal_memory_check(uintptr_t boundary,
519 uintptr_t base,
520 size_t size,
521 uint32_t access_type)
edison.ai37e0f602020-07-13 18:30:58 +0800522
523**Description**
524
Summer Qin56725eb2022-05-06 15:23:40 +0800525This API checks if a given range of memory can be accessed with specified
526access types in boundary. The boundary belongs to a partition which
527contains asset info.
edison.ai37e0f602020-07-13 18:30:58 +0800528
529**Parameter**
530
Summer Qin56725eb2022-05-06 15:23:40 +0800531- ``boundary`` - Boundary of a Secure Partition.
532 Check `tfm_hal_bind_boundary` for details.
edison.ai37e0f602020-07-13 18:30:58 +0800533- ``base`` - The base address of the region.
534- ``size`` - The size of the region.
Summer Qin56725eb2022-05-06 15:23:40 +0800535- ``access_type`` - The memory access types to be checked between given memory
536 and boundaries. The `Memory Access Attributes`_.
edison.ai37e0f602020-07-13 18:30:58 +0800537
538**Return Values**
539
540- ``TFM_HAL_SUCCESS`` - The memory region has the access permissions.
541- ``TFM_HAL_ERROR_MEM_FAULT`` - The memory region does not have the access
542 permissions.
543- ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid inputs.
544- ``TFM_HAL_ERROR_GENERIC`` - An error occurred.
545
Summer Qin56725eb2022-05-06 15:23:40 +0800546**Note**
547
548If the implementation chooses to encode a pointer as the boundary,
549a platform-specific pointer validation needs to be considered before
550referencing the content in this pointer.
551
Nicola Mazzucatoadd545e2024-02-19 09:57:56 +0000552tfm_hal_boundary_need_switch()
553^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
554**Prototype**
555
556.. code-block:: c
557
558 bool tfm_hal_boundary_need_switch(uintptr_t boundary_from,
559 uintptr_t boundary_to)
560
561**Description**
562
563This API let the platform decide if a boundary switch is needed.
564
565**Parameter**
566
567- ``boundary_from`` - Boundary to switch from.
568- ``boundary_to`` - Boundary to switch to.
569
570**Return Values**
571
572- ``true`` - A switching is needed
573- ``false`` - No need for a boundary switch
574
Roman Mazurak96585b82024-04-03 14:35:00 +0300575tfm_hal_post_partition_init_hook()
576^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
577**Prototype**
578
579.. code-block:: c
580
581 enum tfm_hal_status_t tfm_hal_post_partition_init_hook(void)
582
583**Description**
584
585This API let the platform to finish static isolation after all partitions have been bound.
586It's called by SPM right before starting scheduler. Use CONFIG_TFM_POST_PARTITION_INIT_HOOK
587to enable it.
588
589**Parameter**
590
591- ``void`` - None
592
593**Return Values**
594
595- ``TFM_HAL_SUCCESS`` - Booting has been successful.
596- ``TFM_HAL_ERROR_GENERIC`` - Error occurred.
597
Edison Aif4b61132020-07-01 18:35:17 +0800598Log API
599=======
Anton Komlevb3f64662023-01-28 11:53:05 +0000600The log API is used by the :term:`TF-M` :doc:`log system </design_docs/tfm_log_system_design_document>`.
Edison Aif4b61132020-07-01 18:35:17 +0800601The log device could be uart, memory, usb, etc.
602
603APIs
604----
605tfm_hal_output_partition_log()
606^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
607**Prototype**
608
609.. code-block:: c
610
611 int32_t tfm_hal_output_partition_log(const unsigned char *str, uint32_t len)
612
613**Description**
614
615This API is called by Secure Partition to output logs.
616
617**Parameter**
618
619- ``str`` - The string to output.
620- ``len`` - Length of the string in bytes.
621
622**Return Values**
623
624- Positive values - Number of bytes output.
625- ``TFM_HAL_ERROR_NOT_INIT`` - The log device has not been initialized.
626- ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid inputs when ``str`` is ``NULL`` or
627 ``len`` is zero.
628
629**Note**
630
631None.
632
633tfm_hal_output_spm_log()
634^^^^^^^^^^^^^^^^^^^^^^^^
635**Prototype**
636
637.. code-block:: c
638
639 int32_t tfm_hal_output_spm_log(const unsigned char *str, uint32_t len)
640
641**Description**
642
643This API is called by :term:`SPM` to output logs.
644
645**Parameter**
646
647- ``str`` - The string to output.
648- ``len`` - Length of the string in bytes.
649
650**Return Values**
651
652- Positive numbers - Number of bytes output.
653- ``TFM_HAL_ERROR_NOT_INIT`` - The log device has not been initialized.
654- ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid inputs when ``str`` is ``NULL``
655 or ``len`` is zero.
656
657**Note**
658
Anton Komlevb3f64662023-01-28 11:53:05 +0000659Please check :doc:`TF-M log system </design_docs/tfm_log_system_design_document>`
660for more information.
Edison Aif4b61132020-07-01 18:35:17 +0800661
Kevin Pengd399a1f2021-09-08 15:33:14 +0800662Interrupt APIs
663==============
664
665The SPM HAL interrupt APIs are intended for operations on Interrupt Controllers
666of platforms.
667
668APIs for control registers of interrupt sources are not in the scope of this set
669of APIs.
670Secure Partitions should define the APIs for managing interrupts with those MMIO
671registers.
672
673APIs
674----
675
676tfm_hal_irq_enable()
677^^^^^^^^^^^^^^^^^^^^
678
679**Prototype**
680
681.. code-block:: c
682
683 enum tfm_hal_status_t tfm_hal_irq_enable(uint32_t irq_num)
684
685**Description**
686
687This API enables an interrupt from the Interrupt Controller of the platform.
688
689**Parameter**
690
691- ``irq_num`` - the interrupt to be enabled with a number
692
693**Return Values**
694
695- ``TFM_HAL_ERROR_INVALID_INPUT`` - the ``irq_num`` exceeds The maximum
Nicola Mazzucatoadd545e2024-02-19 09:57:56 +0000696 supported number of external interrupts.
Kevin Pengd399a1f2021-09-08 15:33:14 +0800697- ``TFM_HAL_ERROR_GENERIC`` - failed to enable the interrupt.
698- ``TFM_HAL_SUCCESS`` - the interrupt is successfully enabled.
699
700tfm_hal_irq_disable()
701^^^^^^^^^^^^^^^^^^^^^
702
703**Prototype**
704
705.. code-block:: c
706
707 enum tfm_hal_status_t tfm_hal_irq_disable(uint32_t irq_num)
708
709**Description**
710
711This API disables an interrupt from the Interrupt Controller of the platform.
712
713**Parameter**
714
715- ``irq_num`` - the interrupt to be disabled with a number
716
717**Return Values**
718
719- ``TFM_HAL_ERROR_INVALID_INPUT`` - the ``irq_num`` exceeds The maximum
Nicola Mazzucatoadd545e2024-02-19 09:57:56 +0000720 supported number of external interrupts.
Kevin Pengd399a1f2021-09-08 15:33:14 +0800721- ``TFM_HAL_ERROR_GENERIC`` - failed to disable the interrupt.
722- ``TFM_HAL_SUCCESS`` - the interrupt is successfully disabled.
723
724tfm_hal_irq_clear_pending()
725^^^^^^^^^^^^^^^^^^^^^^^^^^^
726
727**Prototype**
728
729.. code-block:: c
730
731 enum tfm_hal_status_t tfm_hal_irq_clear_pending(uint32_t irq_num)
732
733**Description**
734
735This API clears an active and pending interrupt.
736
737**Parameter**
738
739- ``irq_num`` - the interrupt to be disabled with a number
740
741**Return Values**
742
743- ``TFM_HAL_ERROR_INVALID_INPUT`` - the ``irq_num`` exceeds The maximum
Nicola Mazzucatoadd545e2024-02-19 09:57:56 +0000744 supported number of external interrupts.
Kevin Pengd399a1f2021-09-08 15:33:14 +0800745- ``TFM_HAL_ERROR_GENERIC`` - failed to clear the pending interrupt.
746- ``TFM_HAL_SUCCESS`` - the pending interrupt has been cleared.
747
Kevin Pengec239bb2021-09-03 15:40:27 +0800748Initializations
749^^^^^^^^^^^^^^^
750
751**Prototype**
752
753.. code-block:: c
754
755 enum tfm_hal_status_t {source_symbol}_init(void *p_pt,
Chris Brand11ff8a52022-10-18 17:46:50 -0700756 const struct irq_load_info_t *p_ildi)
Kevin Pengec239bb2021-09-03 15:40:27 +0800757
758The ``{source_symbol}`` is:
759
760- ``irq_{source}``, if the ``source`` attribute of the IRQ in Partition manifest
761 is a number
762- Lowercase of ``source`` attribute, if ``source`` is a symbolic name
763
764**Description**
765
766Each interrupt has an initialization function individually.
767The :term:`SPM` calls the functions while loading the Partitions.
768
769The following initializations are required for each interrupt:
770
771- Setting the priority. The value must between 0 to 0x80 exclusively.
772- Ensuring that the interrupt targets the Secure State.
773- Saving the input parameters for future use.
774
775Platforms can have extra initializations as well.
776
777**Parameter**
778
779- ``p_pt`` - pointer to Partition runtime struct of the owner Partition
780- ``p_ildi`` - pointer to ``irq_load_info_t`` struct of the interrupt
781
782**Note**
783
784Please refer to the
Antonio de Angelis9d496a52025-01-07 21:18:00 +0000785:doc: `IRQ integration guide<tfm_secure_irq_integration_guide>`
Kevin Pengec239bb2021-09-03 15:40:27 +0800786for more information.
787
Edison Aib28b9712020-06-04 14:41:23 +0800788************************************
789API Definition for Secure Partitions
790************************************
791The Secure Partition (SP) :term:`HAL` mainly focuses on two parts:
792
793 - Peripheral devices. The peripherals accessed by the :term:`TF-M` default
794 Secure Partitions.
795 - Secure Partition abstraction support. The Secure Partition data that must be
796 provided by the platform.
797
798The Secure Partition abstraction support will be introduced in the peripheral
799API definition.
800
801ITS and PS flash API
802====================
803There are two kinds of flash:
804
805 - Internal flash. Accessed by the PSA Internal Trusted Storage (ITS) service.
806 - External flash. Accessed by the PSA Protected Storage (PS) service.
807
808The ITS HAL for the internal flash device is defined in the ``tfm_hal_its.h``
809header and the PS HAL in the ``tfm_hal_ps.h`` header.
810
811Macros
812------
813Internal Trusted Storage
814^^^^^^^^^^^^^^^^^^^^^^^^
815TFM_HAL_ITS_FLASH_DRIVER
816~~~~~~~~~~~~~~~~~~~~~~~~
817Defines the identifier of the CMSIS Flash ARM_DRIVER_FLASH object to use for
818ITS. It must have been allocated by the platform and will be declared extern in
819the HAL header.
820
821TFM_HAL_ITS_PROGRAM_UNIT
822~~~~~~~~~~~~~~~~~~~~~~~~
823Defines the size of the ITS flash device's physical program unit (the smallest
824unit of data that can be individually programmed to flash). It must be equal to
825TFM_HAL_ITS_FLASH_DRIVER.GetInfo()->program_unit, but made available at compile
826time so that filesystem structures can be statically sized.
827
828TFM_HAL_ITS_FLASH_AREA_ADDR
829~~~~~~~~~~~~~~~~~~~~~~~~~~~
830Defines the base address of the dedicated flash area for ITS.
831
832TFM_HAL_ITS_FLASH_AREA_SIZE
833~~~~~~~~~~~~~~~~~~~~~~~~~~~
834Defines the size of the dedicated flash area for ITS in bytes.
835
836TFM_HAL_ITS_SECTORS_PER_BLOCK
837~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
838Defines the number of contiguous physical flash erase sectors that form a
839logical filesystem erase block.
840
841Protected Storage
842^^^^^^^^^^^^^^^^^
843TFM_HAL_PS_FLASH_DRIVER
844~~~~~~~~~~~~~~~~~~~~~~~
845Defines the identifier of the CMSIS Flash ARM_DRIVER_FLASH object to use for
846PS. It must have been allocated by the platform and will be declared extern in
847the HAL header.
848
849TFM_HAL_PS_PROGRAM_UNIT
850~~~~~~~~~~~~~~~~~~~~~~~~
851Defines the size of the PS flash device's physical program unit (the smallest
852unit of data that can be individually programmed to flash). It must be equal to
853TFM_HAL_PS_FLASH_DRIVER.GetInfo()->program_unit, but made available at compile
854time so that filesystem structures can be statically sized.
855
856TFM_HAL_PS_FLASH_AREA_ADDR
857~~~~~~~~~~~~~~~~~~~~~~~~~~~
858Defines the base address of the dedicated flash area for PS.
859
860TFM_HAL_PS_FLASH_AREA_SIZE
861~~~~~~~~~~~~~~~~~~~~~~~~~~~
862Defines the size of the dedicated flash area for PS in bytes.
863
864TFM_HAL_PS_SECTORS_PER_BLOCK
865~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
866Defines the number of contiguous physical flash erase sectors that form a
867logical filesystem erase block.
868
869Optional definitions
870--------------------
871The ``TFM_HAL_ITS_FLASH_AREA_ADDR``, ``TFM_HAL_ITS_FLASH_AREA_SIZE`` and
872``TFM_HAL_ITS_SECTORS_PER_BLOCK`` definitions are optional. If not defined, the
873platform must implement ``tfm_hal_its_fs_info()`` instead.
874
875Equivalently, ``tfm_hal_its_ps_info()`` must be implemented by the platform if
876``TFM_HAL_ITS_FLASH_AREA_ADDR``, ``TFM_HAL_ITS_FLASH_AREA_SIZE`` or
877``TFM_HAL_ITS_SECTORS_PER_BLOCK`` is not defined.
878
879Objects
880-------
881ARM_DRIVER_FLASH
882^^^^^^^^^^^^^^^^
883The ITS and PS HAL headers each expose a CMSIS Flash Driver instance.
884
885.. code-block:: c
886
887 extern ARM_DRIVER_FLASH TFM_HAL_ITS_FLASH_DRIVER
888
889 extern ARM_DRIVER_FLASH TFM_HAL_PS_FLASH_DRIVER
890
891The CMSIS Flash Driver provides the flash primitives ReadData(), ProgramData()
892and EraseSector() as well as GetInfo() to access flash device properties such
893as the sector size.
894
895Types
896-----
897tfm_hal_its_fs_info_t
898^^^^^^^^^^^^^^^^^^^^^
899Struct containing information required from the platform at runtime to configure
900the ITS filesystem.
901
902.. code-block:: c
903
904 struct tfm_hal_its_fs_info_t {
905 uint32_t flash_area_addr;
906 size_t flash_area_size;
907 uint8_t sectors_per_block;
908 };
909
910Each attribute is described below:
911
912 - ``flash_area_addr`` - Location of the block of flash to use for ITS
913 - ``flash_area_size`` - Number of bytes of flash to use for ITS
914 - ``sectors_per_block`` - Number of erase sectors per logical FS block
915
916tfm_hal_ps_fs_info_t
917^^^^^^^^^^^^^^^^^^^^^
918Struct containing information required from the platform at runtime to configure
919the PS filesystem.
920
921.. code-block:: c
922
923 struct tfm_hal_ps_fs_info_t {
924 uint32_t flash_area_addr;
925 size_t flash_area_size;
926 uint8_t sectors_per_block;
927 };
928
929Each attribute is described below:
930
931 - ``flash_area_addr`` - Location of the block of flash to use for PS
932 - ``flash_area_size`` - Number of bytes of flash to use for PS
933 - ``sectors_per_block`` - Number of erase sectors per logical FS block
934
935Functions
936---------
937tfm_hal_its_fs_info()
938^^^^^^^^^^^^^^^^^^^^^
939**Prototype**
940
941.. code-block:: c
942
943 enum tfm_hal_status_t tfm_hal_its_fs_info(struct tfm_hal_its_fs_info_t *fs_info);
944
945**Description**
946
947Retrieves the filesystem configuration parameters for ITS.
948
949**Parameter**
950
951- ``fs_info`` - Filesystem config information
952
953**Return values**
954
955- ``TFM_HAL_SUCCESS`` - The operation completed successfully
956- ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid parameter
957
958**Note**
959
960This function should ensure that the values returned do not result in a security
961compromise. The block of flash supplied must meet the security requirements of
962Internal Trusted Storage.
963
964tfm_hal_ps_fs_info()
965^^^^^^^^^^^^^^^^^^^^
966**Prototype**
967
968.. code-block:: c
969
970 enum tfm_hal_status_t tfm_hal_ps_fs_info(struct tfm_hal_ps_fs_info_t *fs_info);
971
972**Description**
973
974Retrieves the filesystem configuration parameters for PS.
975
976**Parameter**
977
978- ``fs_info`` - Filesystem config information
979
980**Return values**
981
982- ``TFM_HAL_SUCCESS`` - The operation completed successfully
983- ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid parameter
984
985**Note**
986
987This function should ensure that the values returned do not result in a security
988compromise.
989
Edison Ai75afd372020-04-21 18:29:57 +0800990--------------
991
Nicola Mazzucatoafd24bb2024-02-14 17:27:27 +0000992*Copyright (c) 2020-2024, Arm Limited. All rights reserved.*
Chris Brand11ff8a52022-10-18 17:46:50 -0700993*Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon company)
994or an affiliate of Cypress Semiconductor Corporation. All rights reserved.*