efilink.h 3.9 KB

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