hob.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* SPDX-License-Identifier: Intel */
  2. /*
  3. * Copyright (C) 2013, Intel Corporation
  4. * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
  5. */
  6. #ifndef __HOB_H__
  7. #define __HOB_H__
  8. #include <efi.h>
  9. #include <efi_loader.h>
  10. /* Type of HOB Header */
  11. #define HOB_TYPE_MEM_ALLOC 0x0002
  12. #define HOB_TYPE_RES_DESC 0x0003
  13. #define HOB_TYPE_GUID_EXT 0x0004
  14. #define HOB_TYPE_UNUSED 0xFFFE
  15. #define HOB_TYPE_EOH 0xFFFF
  16. /* Value of ResourceType in HOB_RES_DESC */
  17. #define RES_SYS_MEM 0x00000000
  18. #define RES_MMAP_IO 0x00000001
  19. #define RES_IO 0x00000002
  20. #define RES_FW_DEVICE 0x00000003
  21. #define RES_MMAP_IO_PORT 0x00000004
  22. #define RES_MEM_RESERVED 0x00000005
  23. #define RES_IO_RESERVED 0x00000006
  24. #define RES_MAX_MEM_TYPE 0x00000007
  25. /*
  26. * These types can be ORed together as needed.
  27. *
  28. * The first three enumerations describe settings
  29. * The rest of the settings describe capabilities
  30. */
  31. #define RES_ATTR_PRESENT 0x00000001
  32. #define RES_ATTR_INITIALIZED 0x00000002
  33. #define RES_ATTR_TESTED 0x00000004
  34. #define RES_ATTR_SINGLE_BIT_ECC 0x00000008
  35. #define RES_ATTR_MULTIPLE_BIT_ECC 0x00000010
  36. #define RES_ATTR_ECC_RESERVED_1 0x00000020
  37. #define RES_ATTR_ECC_RESERVED_2 0x00000040
  38. #define RES_ATTR_READ_PROTECTED 0x00000080
  39. #define RES_ATTR_WRITE_PROTECTED 0x00000100
  40. #define RES_ATTR_EXECUTION_PROTECTED 0x00000200
  41. #define RES_ATTR_UNCACHEABLE 0x00000400
  42. #define RES_ATTR_WRITE_COMBINEABLE 0x00000800
  43. #define RES_ATTR_WRITE_THROUGH_CACHEABLE 0x00001000
  44. #define RES_ATTR_WRITE_BACK_CACHEABLE 0x00002000
  45. #define RES_ATTR_16_BIT_IO 0x00004000
  46. #define RES_ATTR_32_BIT_IO 0x00008000
  47. #define RES_ATTR_64_BIT_IO 0x00010000
  48. #define RES_ATTR_UNCACHED_EXPORTED 0x00020000
  49. /*
  50. * Describes the format and size of the data inside the HOB.
  51. * All HOBs must contain this generic HOB header.
  52. */
  53. struct hob_header {
  54. u16 type; /* HOB type */
  55. u16 len; /* HOB length */
  56. u32 reserved; /* always zero */
  57. };
  58. /*
  59. * Describes all memory ranges used during the HOB producer phase that
  60. * exist outside the HOB list. This HOB type describes how memory is used,
  61. * not the physical attributes of memory.
  62. */
  63. struct hob_mem_alloc {
  64. struct hob_header hdr;
  65. /*
  66. * A GUID that defines the memory allocation region's type and purpose,
  67. * as well as other fields within the memory allocation HOB. This GUID
  68. * is used to define the additional data within the HOB that may be
  69. * present for the memory allocation HOB. Type efi_guid_t is defined in
  70. * InstallProtocolInterface() in the UEFI 2.0 specification.
  71. */
  72. efi_guid_t name;
  73. /*
  74. * The base address of memory allocated by this HOB.
  75. * Type phys_addr_t is defined in AllocatePages() in the UEFI 2.0
  76. * specification.
  77. */
  78. phys_addr_t mem_base;
  79. /* The length in bytes of memory allocated by this HOB */
  80. phys_size_t mem_len;
  81. /*
  82. * Defines the type of memory allocated by this HOB.
  83. * The memory type definition follows the EFI_MEMORY_TYPE definition.
  84. * Type EFI_MEMORY_TYPE is defined in AllocatePages() in the UEFI 2.0
  85. * specification.
  86. */
  87. enum efi_memory_type mem_type;
  88. /* padding */
  89. u8 reserved[4];
  90. };
  91. /*
  92. * Describes the resource properties of all fixed, nonrelocatable resource
  93. * ranges found on the processor host bus during the HOB producer phase.
  94. */
  95. struct hob_res_desc {
  96. struct hob_header hdr;
  97. /*
  98. * A GUID representing the owner of the resource. This GUID is
  99. * used by HOB consumer phase components to correlate device
  100. * ownership of a resource.
  101. */
  102. efi_guid_t owner;
  103. u32 type;
  104. u32 attr;
  105. /* The physical start address of the resource region */
  106. phys_addr_t phys_start;
  107. /* The number of bytes of the resource region */
  108. phys_size_t len;
  109. };
  110. /*
  111. * Allows writers of executable content in the HOB producer phase to
  112. * maintain and manage HOBs with specific GUID.
  113. */
  114. struct hob_guid {
  115. struct hob_header hdr;
  116. /* A GUID that defines the contents of this HOB */
  117. efi_guid_t name;
  118. /* GUID specific data goes here */
  119. };
  120. /**
  121. * get_next_hob() - return a pointer to the next HOB in the HOB list
  122. *
  123. * This macro returns a pointer to HOB that follows the HOB specified by hob
  124. * in the HOB List.
  125. *
  126. * @hdr: A pointer to a HOB.
  127. *
  128. * @return A pointer to the next HOB in the HOB list.
  129. */
  130. static inline const struct hob_header *get_next_hob(const struct hob_header
  131. *hdr)
  132. {
  133. return (const struct hob_header *)((uintptr_t)hdr + hdr->len);
  134. }
  135. /**
  136. * end_of_hob() - determine if a HOB is the last HOB in the HOB list
  137. *
  138. * This macro determine if the HOB specified by hob is the last HOB in the
  139. * HOB list. If hob is last HOB in the HOB list, then true is returned.
  140. * Otherwise, false is returned.
  141. *
  142. * @hdr: A pointer to a HOB.
  143. *
  144. * @return true: The HOB specified by hdr is the last HOB in the HOB list.
  145. * @return false: The HOB specified by hdr is not the last HOB in the HOB list.
  146. */
  147. static inline bool end_of_hob(const struct hob_header *hdr)
  148. {
  149. return hdr->type == HOB_TYPE_EOH;
  150. }
  151. /**
  152. * get_guid_hob_data() - return a pointer to data buffer from a HOB of
  153. * type HOB_TYPE_GUID_EXT
  154. *
  155. * This macro returns a pointer to the data buffer in a HOB specified by hob.
  156. * hob is assumed to be a HOB of type HOB_TYPE_GUID_EXT.
  157. *
  158. * @hdr: A pointer to a HOB.
  159. *
  160. * @return A pointer to the data buffer in a HOB.
  161. */
  162. static inline void *get_guid_hob_data(const struct hob_header *hdr)
  163. {
  164. return (void *)((uintptr_t)hdr + sizeof(struct hob_guid));
  165. }
  166. /**
  167. * get_guid_hob_data_size() - return the size of the data buffer from a HOB
  168. * of type HOB_TYPE_GUID_EXT
  169. *
  170. * This macro returns the size, in bytes, of the data buffer in a HOB
  171. * specified by hob. hob is assumed to be a HOB of type HOB_TYPE_GUID_EXT.
  172. *
  173. * @hdr: A pointer to a HOB.
  174. *
  175. * @return The size of the data buffer.
  176. */
  177. static inline u16 get_guid_hob_data_size(const struct hob_header *hdr)
  178. {
  179. return hdr->len - sizeof(struct hob_guid);
  180. }
  181. /**
  182. * Returns the next instance of a HOB type from the starting HOB.
  183. *
  184. * @type: HOB type to search
  185. * @hob_list: A pointer to the HOB list
  186. *
  187. * @return A HOB object with matching type; Otherwise NULL.
  188. */
  189. const struct hob_header *hob_get_next_hob(uint type, const void *hob_list);
  190. /**
  191. * Returns the next instance of the matched GUID HOB from the starting HOB.
  192. *
  193. * @guid: GUID to search
  194. * @hob_list: A pointer to the HOB list
  195. *
  196. * @return A HOB object with matching GUID; Otherwise NULL.
  197. */
  198. const struct hob_header *hob_get_next_guid_hob(const efi_guid_t *guid,
  199. const void *hob_list);
  200. /**
  201. * This function retrieves a GUID HOB data buffer and size.
  202. *
  203. * @hob_list: A HOB list pointer.
  204. * @len: A pointer to the GUID HOB data buffer length.
  205. * If the GUID HOB is located, the length will be updated.
  206. * @guid A pointer to HOB GUID.
  207. *
  208. * @return NULL: Failed to find the GUID HOB.
  209. * @return others: GUID HOB data buffer pointer.
  210. */
  211. void *hob_get_guid_hob_data(const void *hob_list, u32 *len,
  212. const efi_guid_t *guid);
  213. #endif /* __HOB_H__ */