diff options
author | Mingyang Sun <mingyang.sun@arm.com> | 2021-05-25 21:04:12 +0800 |
---|---|---|
committer | Ken Liu <ken.liu@arm.com> | 2021-06-30 05:45:14 +0200 |
commit | e5c151d0c8dd37c0b79ff928109a3b8537162d8c (patch) | |
tree | 1da8774d7cf2f27d95d4f167bb6409efa3006baa /secure_fw | |
parent | 41123280c5c4433f5cd1a0683d703da7d5b00dbc (diff) | |
download | trusted-firmware-m-e5c151d0c8dd37c0b79ff928109a3b8537162d8c.tar.gz |
SPM: Add logic for unidirectional linked list
Add operations for unidirectional list: Initialize a head node,
insert a node and iterate the list.
Also change bi-list "next" and "prev" to "bnext" and "bprev" to
avoid misuse between unidirectional list and bi-list operations.
The unidirectional linked list is prepared for linking the
partitions and linking the services.
Change-Id: I7c230f14b8ae78942efd5b1e524f4a05df364f7d
Signed-off-by: Ken Liu <ken.liu@arm.com>
Co-authored-by: Mingyang Sun <mingyang.sun@arm.com>
Diffstat (limited to 'secure_fw')
-rw-r--r-- | secure_fw/spm/include/lists.h | 76 |
1 files changed, 52 insertions, 24 deletions
diff --git a/secure_fw/spm/include/lists.h b/secure_fw/spm/include/lists.h index 41c540a0e1..c630ff7aaf 100644 --- a/secure_fw/spm/include/lists.h +++ b/secure_fw/spm/include/lists.h @@ -7,48 +7,76 @@ #ifndef __LISTS_H__ #define __LISTS_H__ +/********* Bi-directional list operations ********/ /* Bi-directional list structure */ struct bi_list_node_t { - struct bi_list_node_t *prev; - struct bi_list_node_t *next; + struct bi_list_node_t *bprev; + struct bi_list_node_t *bnext; }; /* Init an empty node. */ #define BI_LIST_INIT_NODE(node) do { \ - (node)->next = node; \ - (node)->prev = node; \ -} while(0) + (node)->bnext = node; \ + (node)->bprev = node; \ +} while (0) -/* Insert a new node after (next) current. */ +/* Insert a new node after current node: (bnext) of current. */ #define BI_LIST_INSERT_AFTER(curr, node) do { \ - (node)->next = (curr)->next; \ - (node)->prev = curr; \ - (curr)->next->prev = node; \ - (curr)->next = node; \ -} while(0) + (node)->bnext = (curr)->bnext; \ + (node)->bprev = curr; \ + (curr)->bnext->bprev = node; \ + (curr)->bnext = node; \ +} while (0) -/* Add one node into list as the tail (prev) of head. */ +/* Add one node into list as the tail: (bprev) of head. */ #define BI_LIST_INSERT_BEFORE(curr, node) do { \ - (curr)->prev->next = node; \ - (node)->prev = (curr)->prev; \ - (curr)->prev = node; \ - (node)->next = curr; \ -} while(0) + (curr)->bprev->bnext = node; \ + (node)->bprev = (curr)->bprev; \ + (curr)->bprev = node; \ + (node)->bnext = curr; \ +} while (0) /* Remove one node from the list. */ -#define BI_LIST_REMOVE_NODE(node) do { \ - (node)->prev->next = (node)->next; \ - (node)->next->prev = (node)->prev; \ -} while(0) +#define BI_LIST_REMOVE_NODE(node) do { \ + (node)->bprev->bnext = (node)->bnext; \ + (node)->bnext->bprev = (node)->bprev; \ +} while (0) /* Is the head empty? */ -#define BI_LIST_IS_EMPTY(head) ((head)->next == (head)) +#define BI_LIST_IS_EMPTY(head) ((head)->bnext == (head)) /* The node's next node */ -#define BI_LIST_NEXT_NODE(node) ((node)->next) +#define BI_LIST_NEXT_NODE(node) ((node)->bnext) /* Go through each node of a list */ #define BI_LIST_FOR_EACH(node, head) \ - for (node = (head)->next; node != head; node = (node)->next) + for (node = (head)->bnext; node != head; node = (node)->bnext) + +/********* Uni-directional list operations ********/ +/* + * To use these single linked list operations, a head node must have been + * defined already, and the "next" pointer initialized to "NULL". Like: + * struct head_t { + * uint32_t data; + * User_Type *next; + * } head; + */ + +/* Initialize the head node */ +#define UNI_LISI_INIT_HEAD(head) do { \ + if (head) { \ + (head)->next = NULL; \ + } \ +} while (0) + +/* Insert a node after current node */ +#define UNI_LIST_INSERT_AFTER(curr, node) do { \ + (node)->next = (curr)->next; \ + (curr)->next = node; \ +} while (0) + +/* Go through each node of a list */ +#define UNI_LIST_FOR_EACH(node, head) \ + for (node = (head)->next; node != NULL; node = (node)->next) #endif /* __LISTS_H__ */ |