1 /*
2  * Copyright (c) 2021, Arm Limited. All rights reserved.
3  * Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon
4  * company) or an affiliate of Cypress Semiconductor Corporation. All rights
5  * reserved.
6  *
7  * SPDX-License-Identifier: BSD-3-Clause
8  *
9  */
10 
11 /* !! For SPM load usage, no including by components out of SPM !! */
12 #ifndef __SPM_LOAD_API_H__
13 #define __SPM_LOAD_API_H__
14 
15 #include "asset_defs.h"
16 #include "interrupt_defs.h"
17 #include "partition_defs.h"
18 #include "service_defs.h"
19 #include "spm.h"
20 
21 /* No more partition to be loaded */
22 #define NO_MORE_PARTITION        NULL
23 
24 /* Length of extendable variables in partition load type */
25 #define LOAD_INFO_EXT_LENGTH                        (2)
26 /* Argument "pldinf" must be a "struct partition_load_info_t *". */
27 #define LOAD_INFSZ_BYTES(pldinf)                                       \
28     (sizeof(*(pldinf)) + LOAD_INFO_EXT_LENGTH * sizeof(uintptr_t) +    \
29      (pldinf)->ndeps * sizeof(uint32_t) +                              \
30      (pldinf)->nservices * sizeof(struct service_load_info_t) +        \
31      (pldinf)->nassets * sizeof(struct asset_desc_t) +                 \
32      (pldinf)->nirqs * sizeof(struct irq_load_info_t))
33 
34 /* 'Allocate' stack based on load info */
35 #define LOAD_ALLOCED_STACK_ADDR(pldinf)    (*((uintptr_t *)(pldinf + 1)))
36 
37 #define LOAD_INFO_DEPS(pldinf)                                         \
38     ((const uint32_t *)((uintptr_t)(pldinf + 1) + LOAD_INFO_EXT_LENGTH * sizeof(uintptr_t)))
39 #define LOAD_INFO_SERVICE(pldinf)                                      \
40     ((const struct service_load_info_t *)((uintptr_t)LOAD_INFO_DEPS(pldinf) + \
41      (pldinf)->ndeps * sizeof(uint32_t)))
42 #define LOAD_INFO_ASSET(pldinf)                                        \
43     ((const struct asset_desc_t *)((uintptr_t)LOAD_INFO_SERVICE(pldinf) + \
44      (pldinf)->nservices * sizeof(struct service_load_info_t)))
45 #define LOAD_INFO_IRQ(pldinf)                                          \
46     ((const struct irq_load_info_t *)((uintptr_t)LOAD_INFO_ASSET(pldinf) + \
47      (pldinf)->nassets * sizeof(struct asset_desc_t)))
48 
49 /* Runtime partition struct list head node type */
50 struct partition_head_t {
51     uint32_t reserved;                  /* Reserved             */
52     struct partition_t *next;           /* Next partition node  */
53 };
54 
55 /* Runtime service struct list head node type */
56 struct service_head_t {
57     uint32_t reserved;                  /* Reserved             */
58     struct service_t *next;             /* Next partition node  */
59 };
60 
61 /*
62  * Load a partition object to linked list and return if a load is successful.
63  * An 'assuredly' function, return NO_MORE_PARTITION for no more partitions and
64  * return a valid pointer if succeed. Other errors simply panic the system and
65  * never return.
66  */
67 struct partition_t *load_a_partition_assuredly(struct partition_head_t *head);
68 
69 /*
70  * Load numbers of service objects to linked list based on given partition.
71  * It loads connection based services and stateless services that partition
72  * contains.
73  * As an 'assuredly' function, errors simply panic the system and never
74  * return.
75  * This function returns the service signal set in a 32 bit number. Return
76  * ZERO if services are not represented by signals.
77  */
78 uint32_t load_services_assuredly(struct partition_t *p_partition,
79                                  struct service_head_t *services_listhead,
80                                  struct service_t **stateless_services_ref_tbl,
81                                  size_t ref_tbl_size);
82 
83 /*
84  * Append IRQ signals to Partition signals.
85  * Set initial IRQ enabled status according to framework version.
86  * And initialize the IRQ.
87  * Any error within this API causes system to panic.
88  */
89 void load_irqs_assuredly(struct partition_t *p_partition);
90 
91 #endif /* __SPM_LOAD_API_H__ */
92