blob: 2a0629774af6b226ef73fc465a2d53135eed15cb [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
48.. figure:: media/hal_structure.png
49
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
285provide diverse levels of securitiy. The isolation API provides the functions to
286implement 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
348have a combination of the atrributes, 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
edison.ai37e0f602020-07-13 18:30:58 +0800403tfm_hal_set_up_static_boundaries()
404^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
405**Prototype**
406
407.. code-block:: c
408
Ken Liuce58bfc2021-05-12 17:54:48 +0800409 enum tfm_hal_status_t tfm_hal_set_up_static_boundaries(void)
edison.ai37e0f602020-07-13 18:30:58 +0800410
411**Description**
412
413This API sets up the static isolation boundaries which are constant throughout
Ken Liu967ffa92022-05-25 15:13:34 +0800414the system runtime.
edison.ai37e0f602020-07-13 18:30:58 +0800415
Ken Liu967ffa92022-05-25 15:13:34 +0800416These boundaries include:
edison.ai37e0f602020-07-13 18:30:58 +0800417
Ken Liu967ffa92022-05-25 15:13:34 +0800418- The boundary between the :term:`SPE` and the :term:`NSPE`
419- The boundary to protect the SPM execution. For example, the PSA RoT
420 isolation boundary between the PSA Root of Trust and the Application Root of
421 Trust which is for isolation level 2 and 3 only.
edison.ai37e0f602020-07-13 18:30:58 +0800422
Ken Liu967ffa92022-05-25 15:13:34 +0800423Refer to the :term:`PSA-FF-M` for the definitions of the isolation boundaries.
edison.ai37e0f602020-07-13 18:30:58 +0800424
425**Return Values**
426
Ken Liu967ffa92022-05-25 15:13:34 +0800427- ``TFM_HAL_SUCCESS`` - Isolation boundaries have been set up.
428- ``TFM_HAL_ERROR_GENERIC`` - Failed to set up the static boundaries.
edison.ai37e0f602020-07-13 18:30:58 +0800429
Ken Liu967ffa92022-05-25 15:13:34 +0800430tfm_hal_bind_boundary()
431^^^^^^^^^^^^^^^^^^^^^^^^^
432**Prototype**
433
434.. code-block:: c
435
436 enum tfm_hal_status_t tfm_hal_bind_boundary(
437 const struct partition_load_info_t *p_ldinf,
438 uintptr_t *p_boundary);
439
440**Description**
441
442This API binds partition with a platform-generated boundary. The boundary is
443bound by writing the generated value into ``p_boundary``. And this bound
444boundary is used in subsequent calls to `tfm_hal_activate_boundary()`_ when
445boundary's owner partition get scheduled for running.
446
447**Parameter**
448
449- ``p_ldinf`` - Load information of the partition that is under loading.
450- ``p_boundary`` - Pointer for holding a partition's boundary.
451
452**Return Values**
453
454- ``TFM_HAL_SUCCESS`` - The boundary has been bound successfully.
455- ``TFM_HAL_ERROR_GENERIC`` - Failed to bind the handle.
456
457tfm_hal_activate_boundary()
Ken Liuce58bfc2021-05-12 17:54:48 +0800458^^^^^^^^^^^^^^^^^^^^^^^^^^^
edison.ai37e0f602020-07-13 18:30:58 +0800459**Prototype**
460
461.. code-block:: c
462
Ken Liu967ffa92022-05-25 15:13:34 +0800463 enum tfm_hal_status_t tfm_hal_activate_boundary(
Ken Liuce58bfc2021-05-12 17:54:48 +0800464 const struct partition_load_info_t *p_ldinf,
Ken Liu967ffa92022-05-25 15:13:34 +0800465 uintptr_t boundary);
edison.ai37e0f602020-07-13 18:30:58 +0800466
467**Description**
468
Ken Liu967ffa92022-05-25 15:13:34 +0800469This API requires the platform to activate the boundary to ensure the given
470Secure Partition can run successfully.
edison.ai37e0f602020-07-13 18:30:58 +0800471
Ken Liuce58bfc2021-05-12 17:54:48 +0800472The access permissions outside the boundary is platform-dependent.
edison.ai37e0f602020-07-13 18:30:58 +0800473
474**Parameter**
475
Ken Liu967ffa92022-05-25 15:13:34 +0800476- ``p_ldinf`` - The load information of the partition that is going to be run.
477- ``boundary`` - The boundary for the owner partition of ``p_ldinf``. This
478 value is bound in function ``tfm_hal_bind_boundary``.
edison.ai37e0f602020-07-13 18:30:58 +0800479
480**Return Values**
481
482- ``TFM_HAL_SUCCESS`` - the isolation boundary has been set up.
483- ``TFM_HAL_ERROR_GENERIC`` - failed to set upthe isolation boundary.
484
Summer Qin56725eb2022-05-06 15:23:40 +0800485tfm_hal_memory_check()
486^^^^^^^^^^^^^^^^^^^^^^
edison.ai37e0f602020-07-13 18:30:58 +0800487**Prototype**
488
489.. code-block:: c
490
Summer Qin56725eb2022-05-06 15:23:40 +0800491 tfm_hal_status_t tfm_hal_memory_check(uintptr_t boundary,
492 uintptr_t base,
493 size_t size,
494 uint32_t access_type)
edison.ai37e0f602020-07-13 18:30:58 +0800495
496**Description**
497
Summer Qin56725eb2022-05-06 15:23:40 +0800498This API checks if a given range of memory can be accessed with specified
499access types in boundary. The boundary belongs to a partition which
500contains asset info.
edison.ai37e0f602020-07-13 18:30:58 +0800501
502**Parameter**
503
Summer Qin56725eb2022-05-06 15:23:40 +0800504- ``boundary`` - Boundary of a Secure Partition.
505 Check `tfm_hal_bind_boundary` for details.
edison.ai37e0f602020-07-13 18:30:58 +0800506- ``base`` - The base address of the region.
507- ``size`` - The size of the region.
Summer Qin56725eb2022-05-06 15:23:40 +0800508- ``access_type`` - The memory access types to be checked between given memory
509 and boundaries. The `Memory Access Attributes`_.
edison.ai37e0f602020-07-13 18:30:58 +0800510
511**Return Values**
512
513- ``TFM_HAL_SUCCESS`` - The memory region has the access permissions.
514- ``TFM_HAL_ERROR_MEM_FAULT`` - The memory region does not have the access
515 permissions.
516- ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid inputs.
517- ``TFM_HAL_ERROR_GENERIC`` - An error occurred.
518
Summer Qin56725eb2022-05-06 15:23:40 +0800519**Note**
520
521If the implementation chooses to encode a pointer as the boundary,
522a platform-specific pointer validation needs to be considered before
523referencing the content in this pointer.
524
Edison Aif4b61132020-07-01 18:35:17 +0800525Log API
526=======
527The log API is used by the :term:`TF-M` :doc:`log system <tfm_log_system_design_document>`.
528The log device could be uart, memory, usb, etc.
529
530APIs
531----
532tfm_hal_output_partition_log()
533^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
534**Prototype**
535
536.. code-block:: c
537
538 int32_t tfm_hal_output_partition_log(const unsigned char *str, uint32_t len)
539
540**Description**
541
542This API is called by Secure Partition to output logs.
543
544**Parameter**
545
546- ``str`` - The string to output.
547- ``len`` - Length of the string in bytes.
548
549**Return Values**
550
551- Positive values - Number of bytes output.
552- ``TFM_HAL_ERROR_NOT_INIT`` - The log device has not been initialized.
553- ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid inputs when ``str`` is ``NULL`` or
554 ``len`` is zero.
555
556**Note**
557
558None.
559
560tfm_hal_output_spm_log()
561^^^^^^^^^^^^^^^^^^^^^^^^
562**Prototype**
563
564.. code-block:: c
565
566 int32_t tfm_hal_output_spm_log(const unsigned char *str, uint32_t len)
567
568**Description**
569
570This API is called by :term:`SPM` to output logs.
571
572**Parameter**
573
574- ``str`` - The string to output.
575- ``len`` - Length of the string in bytes.
576
577**Return Values**
578
579- Positive numbers - Number of bytes output.
580- ``TFM_HAL_ERROR_NOT_INIT`` - The log device has not been initialized.
581- ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid inputs when ``str`` is ``NULL``
582 or ``len`` is zero.
583
584**Note**
585
586Please check :doc:`TF-M log system <tfm_log_system_design_document>` for more
587information.
588
Kevin Pengd399a1f2021-09-08 15:33:14 +0800589Interrupt APIs
590==============
591
592The SPM HAL interrupt APIs are intended for operations on Interrupt Controllers
593of platforms.
594
595APIs for control registers of interrupt sources are not in the scope of this set
596of APIs.
597Secure Partitions should define the APIs for managing interrupts with those MMIO
598registers.
599
600APIs
601----
602
603tfm_hal_irq_enable()
604^^^^^^^^^^^^^^^^^^^^
605
606**Prototype**
607
608.. code-block:: c
609
610 enum tfm_hal_status_t tfm_hal_irq_enable(uint32_t irq_num)
611
612**Description**
613
614This API enables an interrupt from the Interrupt Controller of the platform.
615
616**Parameter**
617
618- ``irq_num`` - the interrupt to be enabled with a number
619
620**Return Values**
621
622- ``TFM_HAL_ERROR_INVALID_INPUT`` - the ``irq_num`` exceeds The maximum
623 supported number of external interrupts.
624- ``TFM_HAL_ERROR_GENERIC`` - failed to enable the interrupt.
625- ``TFM_HAL_SUCCESS`` - the interrupt is successfully enabled.
626
627tfm_hal_irq_disable()
628^^^^^^^^^^^^^^^^^^^^^
629
630**Prototype**
631
632.. code-block:: c
633
634 enum tfm_hal_status_t tfm_hal_irq_disable(uint32_t irq_num)
635
636**Description**
637
638This API disables an interrupt from the Interrupt Controller of the platform.
639
640**Parameter**
641
642- ``irq_num`` - the interrupt to be disabled with a number
643
644**Return Values**
645
646- ``TFM_HAL_ERROR_INVALID_INPUT`` - the ``irq_num`` exceeds The maximum
647 supported number of external interrupts.
648- ``TFM_HAL_ERROR_GENERIC`` - failed to disable the interrupt.
649- ``TFM_HAL_SUCCESS`` - the interrupt is successfully disabled.
650
651tfm_hal_irq_clear_pending()
652^^^^^^^^^^^^^^^^^^^^^^^^^^^
653
654**Prototype**
655
656.. code-block:: c
657
658 enum tfm_hal_status_t tfm_hal_irq_clear_pending(uint32_t irq_num)
659
660**Description**
661
662This API clears an active and pending interrupt.
663
664**Parameter**
665
666- ``irq_num`` - the interrupt to be disabled with a number
667
668**Return Values**
669
670- ``TFM_HAL_ERROR_INVALID_INPUT`` - the ``irq_num`` exceeds The maximum
671 supported number of external interrupts.
672- ``TFM_HAL_ERROR_GENERIC`` - failed to clear the pending interrupt.
673- ``TFM_HAL_SUCCESS`` - the pending interrupt has been cleared.
674
Kevin Pengec239bb2021-09-03 15:40:27 +0800675Initializations
676^^^^^^^^^^^^^^^
677
678**Prototype**
679
680.. code-block:: c
681
682 enum tfm_hal_status_t {source_symbol}_init(void *p_pt,
Chris Brand11ff8a52022-10-18 17:46:50 -0700683 const struct irq_load_info_t *p_ildi)
Kevin Pengec239bb2021-09-03 15:40:27 +0800684
685The ``{source_symbol}`` is:
686
687- ``irq_{source}``, if the ``source`` attribute of the IRQ in Partition manifest
688 is a number
689- Lowercase of ``source`` attribute, if ``source`` is a symbolic name
690
691**Description**
692
693Each interrupt has an initialization function individually.
694The :term:`SPM` calls the functions while loading the Partitions.
695
696The following initializations are required for each interrupt:
697
698- Setting the priority. The value must between 0 to 0x80 exclusively.
699- Ensuring that the interrupt targets the Secure State.
700- Saving the input parameters for future use.
701
702Platforms can have extra initializations as well.
703
704**Parameter**
705
706- ``p_pt`` - pointer to Partition runtime struct of the owner Partition
707- ``p_ildi`` - pointer to ``irq_load_info_t`` struct of the interrupt
708
709**Note**
710
711Please refer to the
712:doc: `IRQ intergration guide<tfm_secure_irq_integration_guide>`
713for more information.
714
Edison Aib28b9712020-06-04 14:41:23 +0800715************************************
716API Definition for Secure Partitions
717************************************
718The Secure Partition (SP) :term:`HAL` mainly focuses on two parts:
719
720 - Peripheral devices. The peripherals accessed by the :term:`TF-M` default
721 Secure Partitions.
722 - Secure Partition abstraction support. The Secure Partition data that must be
723 provided by the platform.
724
725The Secure Partition abstraction support will be introduced in the peripheral
726API definition.
727
728ITS and PS flash API
729====================
730There are two kinds of flash:
731
732 - Internal flash. Accessed by the PSA Internal Trusted Storage (ITS) service.
733 - External flash. Accessed by the PSA Protected Storage (PS) service.
734
735The ITS HAL for the internal flash device is defined in the ``tfm_hal_its.h``
736header and the PS HAL in the ``tfm_hal_ps.h`` header.
737
738Macros
739------
740Internal Trusted Storage
741^^^^^^^^^^^^^^^^^^^^^^^^
742TFM_HAL_ITS_FLASH_DRIVER
743~~~~~~~~~~~~~~~~~~~~~~~~
744Defines the identifier of the CMSIS Flash ARM_DRIVER_FLASH object to use for
745ITS. It must have been allocated by the platform and will be declared extern in
746the HAL header.
747
748TFM_HAL_ITS_PROGRAM_UNIT
749~~~~~~~~~~~~~~~~~~~~~~~~
750Defines the size of the ITS flash device's physical program unit (the smallest
751unit of data that can be individually programmed to flash). It must be equal to
752TFM_HAL_ITS_FLASH_DRIVER.GetInfo()->program_unit, but made available at compile
753time so that filesystem structures can be statically sized.
754
755TFM_HAL_ITS_FLASH_AREA_ADDR
756~~~~~~~~~~~~~~~~~~~~~~~~~~~
757Defines the base address of the dedicated flash area for ITS.
758
759TFM_HAL_ITS_FLASH_AREA_SIZE
760~~~~~~~~~~~~~~~~~~~~~~~~~~~
761Defines the size of the dedicated flash area for ITS in bytes.
762
763TFM_HAL_ITS_SECTORS_PER_BLOCK
764~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
765Defines the number of contiguous physical flash erase sectors that form a
766logical filesystem erase block.
767
768Protected Storage
769^^^^^^^^^^^^^^^^^
770TFM_HAL_PS_FLASH_DRIVER
771~~~~~~~~~~~~~~~~~~~~~~~
772Defines the identifier of the CMSIS Flash ARM_DRIVER_FLASH object to use for
773PS. It must have been allocated by the platform and will be declared extern in
774the HAL header.
775
776TFM_HAL_PS_PROGRAM_UNIT
777~~~~~~~~~~~~~~~~~~~~~~~~
778Defines the size of the PS flash device's physical program unit (the smallest
779unit of data that can be individually programmed to flash). It must be equal to
780TFM_HAL_PS_FLASH_DRIVER.GetInfo()->program_unit, but made available at compile
781time so that filesystem structures can be statically sized.
782
783TFM_HAL_PS_FLASH_AREA_ADDR
784~~~~~~~~~~~~~~~~~~~~~~~~~~~
785Defines the base address of the dedicated flash area for PS.
786
787TFM_HAL_PS_FLASH_AREA_SIZE
788~~~~~~~~~~~~~~~~~~~~~~~~~~~
789Defines the size of the dedicated flash area for PS in bytes.
790
791TFM_HAL_PS_SECTORS_PER_BLOCK
792~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
793Defines the number of contiguous physical flash erase sectors that form a
794logical filesystem erase block.
795
796Optional definitions
797--------------------
798The ``TFM_HAL_ITS_FLASH_AREA_ADDR``, ``TFM_HAL_ITS_FLASH_AREA_SIZE`` and
799``TFM_HAL_ITS_SECTORS_PER_BLOCK`` definitions are optional. If not defined, the
800platform must implement ``tfm_hal_its_fs_info()`` instead.
801
802Equivalently, ``tfm_hal_its_ps_info()`` must be implemented by the platform if
803``TFM_HAL_ITS_FLASH_AREA_ADDR``, ``TFM_HAL_ITS_FLASH_AREA_SIZE`` or
804``TFM_HAL_ITS_SECTORS_PER_BLOCK`` is not defined.
805
806Objects
807-------
808ARM_DRIVER_FLASH
809^^^^^^^^^^^^^^^^
810The ITS and PS HAL headers each expose a CMSIS Flash Driver instance.
811
812.. code-block:: c
813
814 extern ARM_DRIVER_FLASH TFM_HAL_ITS_FLASH_DRIVER
815
816 extern ARM_DRIVER_FLASH TFM_HAL_PS_FLASH_DRIVER
817
818The CMSIS Flash Driver provides the flash primitives ReadData(), ProgramData()
819and EraseSector() as well as GetInfo() to access flash device properties such
820as the sector size.
821
822Types
823-----
824tfm_hal_its_fs_info_t
825^^^^^^^^^^^^^^^^^^^^^
826Struct containing information required from the platform at runtime to configure
827the ITS filesystem.
828
829.. code-block:: c
830
831 struct tfm_hal_its_fs_info_t {
832 uint32_t flash_area_addr;
833 size_t flash_area_size;
834 uint8_t sectors_per_block;
835 };
836
837Each attribute is described below:
838
839 - ``flash_area_addr`` - Location of the block of flash to use for ITS
840 - ``flash_area_size`` - Number of bytes of flash to use for ITS
841 - ``sectors_per_block`` - Number of erase sectors per logical FS block
842
843tfm_hal_ps_fs_info_t
844^^^^^^^^^^^^^^^^^^^^^
845Struct containing information required from the platform at runtime to configure
846the PS filesystem.
847
848.. code-block:: c
849
850 struct tfm_hal_ps_fs_info_t {
851 uint32_t flash_area_addr;
852 size_t flash_area_size;
853 uint8_t sectors_per_block;
854 };
855
856Each attribute is described below:
857
858 - ``flash_area_addr`` - Location of the block of flash to use for PS
859 - ``flash_area_size`` - Number of bytes of flash to use for PS
860 - ``sectors_per_block`` - Number of erase sectors per logical FS block
861
862Functions
863---------
864tfm_hal_its_fs_info()
865^^^^^^^^^^^^^^^^^^^^^
866**Prototype**
867
868.. code-block:: c
869
870 enum tfm_hal_status_t tfm_hal_its_fs_info(struct tfm_hal_its_fs_info_t *fs_info);
871
872**Description**
873
874Retrieves the filesystem configuration parameters for ITS.
875
876**Parameter**
877
878- ``fs_info`` - Filesystem config information
879
880**Return values**
881
882- ``TFM_HAL_SUCCESS`` - The operation completed successfully
883- ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid parameter
884
885**Note**
886
887This function should ensure that the values returned do not result in a security
888compromise. The block of flash supplied must meet the security requirements of
889Internal Trusted Storage.
890
891tfm_hal_ps_fs_info()
892^^^^^^^^^^^^^^^^^^^^
893**Prototype**
894
895.. code-block:: c
896
897 enum tfm_hal_status_t tfm_hal_ps_fs_info(struct tfm_hal_ps_fs_info_t *fs_info);
898
899**Description**
900
901Retrieves the filesystem configuration parameters for PS.
902
903**Parameter**
904
905- ``fs_info`` - Filesystem config information
906
907**Return values**
908
909- ``TFM_HAL_SUCCESS`` - The operation completed successfully
910- ``TFM_HAL_ERROR_INVALID_INPUT`` - Invalid parameter
911
912**Note**
913
914This function should ensure that the values returned do not result in a security
915compromise.
916
Edison Ai75afd372020-04-21 18:29:57 +0800917--------------
918
Sebastian Bøe055d83a2022-02-21 12:01:41 +0100919*Copyright (c) 2020-2022, Arm Limited. All rights reserved.*
Chris Brand11ff8a52022-10-18 17:46:50 -0700920*Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon company)
921or an affiliate of Cypress Semiconductor Corporation. All rights reserved.*