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