efilink.h 3.9 KB

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