xref: /netbsd-src/sys/external/bsd/gnu-efi/dist/inc/efilink.h (revision 1eb4b21779cd330f45cea12cb60eb09e852039cb)
1 /*	$NetBSD: efilink.h,v 1.1.1.3 2021/09/30 18:50:09 jmcneill Exp $	*/
2 
3 #ifndef _EFI_LINK_H
4 #define _EFI_LINK_H
5 
6 /*++
7 
8 Copyright (c) 1998  Intel Corporation
9 
10 Module Name:
11 
12     link.h (renamed efilink.h to avoid conflicts)
13 
14 Abstract:
15 
16     EFI link list macro's
17 
18 
19 
20 Revision History
21 
22 --*/
23 
24 #ifndef EFI_NT_EMUL
25 
26 //
27 // List entry - doubly linked list
28 //
29 
30 typedef struct _LIST_ENTRY {
31     struct _LIST_ENTRY  *Flink;
32     struct _LIST_ENTRY  *Blink;
33 } LIST_ENTRY, EFI_LIST_ENTRY;
34 
35 #endif
36 
37 
38 //
39 //  VOID
40 //  InitializeListHead(
41 //      LIST_ENTRY *ListHead
42 //      );
43 //
44 
45 #define InitializeListHead(ListHead) \
46     (ListHead)->Flink = ListHead;    \
47     (ListHead)->Blink = ListHead;
48 
49 //
50 //  BOOLEAN
51 //  IsListEmpty(
52 //      PLIST_ENTRY ListHead
53 //      );
54 //
55 
56 #define IsListEmpty(ListHead) \
57     ((ListHead)->Flink == (ListHead))
58 
59 //
60 //  VOID
61 //  RemoveEntryList(
62 //      PLIST_ENTRY Entry
63 //      );
64 //
65 
66 #define _RemoveEntryList(Entry) {       \
67         LIST_ENTRY *_Blink, *_Flink;    \
68         _Flink = (Entry)->Flink;        \
69         _Blink = (Entry)->Blink;        \
70         _Blink->Flink = _Flink;         \
71         _Flink->Blink = _Blink;         \
72         }
73 
74 #if EFI_DEBUG
75     #define RemoveEntryList(Entry)                      \
76         _RemoveEntryList(Entry);                        \
77         (Entry)->Flink = (LIST_ENTRY *) BAD_POINTER;    \
78         (Entry)->Blink = (LIST_ENTRY *) BAD_POINTER;
79 #else
80     #define RemoveEntryList(Entry)      \
81         _RemoveEntryList(Entry);
82 #endif
83 
84 //
85 //  VOID
86 //  InsertTailList(
87 //      PLIST_ENTRY ListHead,
88 //      PLIST_ENTRY Entry
89 //      );
90 //
91 
92 #define InsertTailList(ListHead,Entry) {\
93     LIST_ENTRY *_ListHead, *_Blink;     \
94     _ListHead = (ListHead);             \
95     _Blink = _ListHead->Blink;          \
96     (Entry)->Flink = _ListHead;         \
97     (Entry)->Blink = _Blink;            \
98     _Blink->Flink = (Entry);            \
99     _ListHead->Blink = (Entry);         \
100     }
101 
102 //
103 //  VOID
104 //  InsertHeadList(
105 //      PLIST_ENTRY ListHead,
106 //      PLIST_ENTRY Entry
107 //      );
108 //
109 
110 #define InsertHeadList(ListHead,Entry) {\
111     LIST_ENTRY *_ListHead, *_Flink;     \
112     _ListHead = (ListHead);             \
113     _Flink = _ListHead->Flink;          \
114     (Entry)->Flink = _Flink;            \
115     (Entry)->Blink = _ListHead;         \
116     _Flink->Blink = (Entry);            \
117     _ListHead->Flink = (Entry);         \
118     }
119 
120 //  VOID
121 //  SwapListEntries(
122 //      PLIST_ENTRY Entry1,
123 //      PLIST_ENTRY Entry2
124 //      );
125 //
126 // Put Entry2 before Entry1
127 //
128 #define SwapListEntries(Entry1,Entry2) {\
129     LIST_ENTRY *Entry1Flink, *Entry1Blink;     \
130     LIST_ENTRY *Entry2Flink, *Entry2Blink;     \
131     Entry2Flink = (Entry2)->Flink;             \
132     Entry2Blink = (Entry2)->Blink;             \
133     Entry1Flink = (Entry1)->Flink;             \
134     Entry1Blink = (Entry1)->Blink;             \
135     Entry2Blink->Flink = Entry2Flink;       \
136     Entry2Flink->Blink = Entry2Blink;        \
137     (Entry2)->Flink = Entry1;               \
138     (Entry2)->Blink = Entry1Blink;          \
139     Entry1Blink->Flink = (Entry2);            \
140     (Entry1)->Blink = (Entry2);             \
141     }
142 
143 //
144 //  EFI_FIELD_OFFSET - returns the byte offset to a field within a structure
145 //
146 
147 #define EFI_FIELD_OFFSET(TYPE,Field) ((UINTN)(intptr_t)(&(((TYPE *) 0)->Field)))
148 
149 //
150 //  CONTAINING_RECORD - returns a pointer to the structure
151 //      from one of it's elements.
152 //
153 
154 #define _CR(Record, TYPE, Field)  \
155     ((TYPE *) ( (CHAR8 *)(Record) - (CHAR8 *) &(((TYPE *) 0)->Field)))
156 
157 //
158 // EDK2 uses BASE_CR for the above
159 //
160 #define BASE_CR _CR
161 
162 #if EFI_DEBUG
163     #define CR(Record, TYPE, Field, Sig)     \
164         _CR(Record, TYPE, Field)->Signature != Sig ?        \
165             (TYPE *) ASSERT_STRUCT(_CR(Record, TYPE, Field), Record) : \
166             _CR(Record, TYPE, Field)
167 #else
168     #define CR(Record, TYPE, Field, Signature)   \
169         _CR(Record, TYPE, Field)
170 #endif
171 
172 
173 //
174 // A lock structure
175 //
176 
177 typedef struct _FLOCK {
178     EFI_TPL     Tpl;
179     EFI_TPL     OwnerTpl;
180     UINTN       Lock;
181 } FLOCK;
182 
183 #endif
184 
185