1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright (C) 2013, Intel Corporation
3*4882a593Smuzhiyun * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * SPDX-License-Identifier: Intel
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #ifndef __FSP_HOB_H__
9*4882a593Smuzhiyun #define __FSP_HOB_H__
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun #include <efi.h>
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun /* Type of HOB Header */
14*4882a593Smuzhiyun #define HOB_TYPE_MEM_ALLOC 0x0002
15*4882a593Smuzhiyun #define HOB_TYPE_RES_DESC 0x0003
16*4882a593Smuzhiyun #define HOB_TYPE_GUID_EXT 0x0004
17*4882a593Smuzhiyun #define HOB_TYPE_UNUSED 0xFFFE
18*4882a593Smuzhiyun #define HOB_TYPE_EOH 0xFFFF
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun /*
21*4882a593Smuzhiyun * Describes the format and size of the data inside the HOB.
22*4882a593Smuzhiyun * All HOBs must contain this generic HOB header.
23*4882a593Smuzhiyun */
24*4882a593Smuzhiyun struct hob_header {
25*4882a593Smuzhiyun u16 type; /* HOB type */
26*4882a593Smuzhiyun u16 len; /* HOB length */
27*4882a593Smuzhiyun u32 reserved; /* always zero */
28*4882a593Smuzhiyun };
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun /*
31*4882a593Smuzhiyun * Describes all memory ranges used during the HOB producer phase that
32*4882a593Smuzhiyun * exist outside the HOB list. This HOB type describes how memory is used,
33*4882a593Smuzhiyun * not the physical attributes of memory.
34*4882a593Smuzhiyun */
35*4882a593Smuzhiyun struct hob_mem_alloc {
36*4882a593Smuzhiyun struct hob_header hdr;
37*4882a593Smuzhiyun /*
38*4882a593Smuzhiyun * A GUID that defines the memory allocation region's type and purpose,
39*4882a593Smuzhiyun * as well as other fields within the memory allocation HOB. This GUID
40*4882a593Smuzhiyun * is used to define the additional data within the HOB that may be
41*4882a593Smuzhiyun * present for the memory allocation HOB. Type efi_guid is defined in
42*4882a593Smuzhiyun * InstallProtocolInterface() in the UEFI 2.0 specification.
43*4882a593Smuzhiyun */
44*4882a593Smuzhiyun struct efi_guid name;
45*4882a593Smuzhiyun /*
46*4882a593Smuzhiyun * The base address of memory allocated by this HOB.
47*4882a593Smuzhiyun * Type phys_addr_t is defined in AllocatePages() in the UEFI 2.0
48*4882a593Smuzhiyun * specification.
49*4882a593Smuzhiyun */
50*4882a593Smuzhiyun phys_addr_t mem_base;
51*4882a593Smuzhiyun /* The length in bytes of memory allocated by this HOB */
52*4882a593Smuzhiyun phys_size_t mem_len;
53*4882a593Smuzhiyun /*
54*4882a593Smuzhiyun * Defines the type of memory allocated by this HOB.
55*4882a593Smuzhiyun * The memory type definition follows the EFI_MEMORY_TYPE definition.
56*4882a593Smuzhiyun * Type EFI_MEMORY_TYPE is defined in AllocatePages() in the UEFI 2.0
57*4882a593Smuzhiyun * specification.
58*4882a593Smuzhiyun */
59*4882a593Smuzhiyun enum efi_mem_type mem_type;
60*4882a593Smuzhiyun /* padding */
61*4882a593Smuzhiyun u8 reserved[4];
62*4882a593Smuzhiyun };
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun /* Value of ResourceType in HOB_RES_DESC */
65*4882a593Smuzhiyun #define RES_SYS_MEM 0x00000000
66*4882a593Smuzhiyun #define RES_MMAP_IO 0x00000001
67*4882a593Smuzhiyun #define RES_IO 0x00000002
68*4882a593Smuzhiyun #define RES_FW_DEVICE 0x00000003
69*4882a593Smuzhiyun #define RES_MMAP_IO_PORT 0x00000004
70*4882a593Smuzhiyun #define RES_MEM_RESERVED 0x00000005
71*4882a593Smuzhiyun #define RES_IO_RESERVED 0x00000006
72*4882a593Smuzhiyun #define RES_MAX_MEM_TYPE 0x00000007
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun /*
75*4882a593Smuzhiyun * These types can be ORed together as needed.
76*4882a593Smuzhiyun *
77*4882a593Smuzhiyun * The first three enumerations describe settings
78*4882a593Smuzhiyun * The rest of the settings describe capabilities
79*4882a593Smuzhiyun */
80*4882a593Smuzhiyun #define RES_ATTR_PRESENT 0x00000001
81*4882a593Smuzhiyun #define RES_ATTR_INITIALIZED 0x00000002
82*4882a593Smuzhiyun #define RES_ATTR_TESTED 0x00000004
83*4882a593Smuzhiyun #define RES_ATTR_SINGLE_BIT_ECC 0x00000008
84*4882a593Smuzhiyun #define RES_ATTR_MULTIPLE_BIT_ECC 0x00000010
85*4882a593Smuzhiyun #define RES_ATTR_ECC_RESERVED_1 0x00000020
86*4882a593Smuzhiyun #define RES_ATTR_ECC_RESERVED_2 0x00000040
87*4882a593Smuzhiyun #define RES_ATTR_READ_PROTECTED 0x00000080
88*4882a593Smuzhiyun #define RES_ATTR_WRITE_PROTECTED 0x00000100
89*4882a593Smuzhiyun #define RES_ATTR_EXECUTION_PROTECTED 0x00000200
90*4882a593Smuzhiyun #define RES_ATTR_UNCACHEABLE 0x00000400
91*4882a593Smuzhiyun #define RES_ATTR_WRITE_COMBINEABLE 0x00000800
92*4882a593Smuzhiyun #define RES_ATTR_WRITE_THROUGH_CACHEABLE 0x00001000
93*4882a593Smuzhiyun #define RES_ATTR_WRITE_BACK_CACHEABLE 0x00002000
94*4882a593Smuzhiyun #define RES_ATTR_16_BIT_IO 0x00004000
95*4882a593Smuzhiyun #define RES_ATTR_32_BIT_IO 0x00008000
96*4882a593Smuzhiyun #define RES_ATTR_64_BIT_IO 0x00010000
97*4882a593Smuzhiyun #define RES_ATTR_UNCACHED_EXPORTED 0x00020000
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun /*
100*4882a593Smuzhiyun * Describes the resource properties of all fixed, nonrelocatable resource
101*4882a593Smuzhiyun * ranges found on the processor host bus during the HOB producer phase.
102*4882a593Smuzhiyun */
103*4882a593Smuzhiyun struct hob_res_desc {
104*4882a593Smuzhiyun struct hob_header hdr;
105*4882a593Smuzhiyun /*
106*4882a593Smuzhiyun * A GUID representing the owner of the resource. This GUID is
107*4882a593Smuzhiyun * used by HOB consumer phase components to correlate device
108*4882a593Smuzhiyun * ownership of a resource.
109*4882a593Smuzhiyun */
110*4882a593Smuzhiyun struct efi_guid owner;
111*4882a593Smuzhiyun u32 type;
112*4882a593Smuzhiyun u32 attr;
113*4882a593Smuzhiyun /* The physical start address of the resource region */
114*4882a593Smuzhiyun phys_addr_t phys_start;
115*4882a593Smuzhiyun /* The number of bytes of the resource region */
116*4882a593Smuzhiyun phys_size_t len;
117*4882a593Smuzhiyun };
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun /*
120*4882a593Smuzhiyun * Allows writers of executable content in the HOB producer phase to
121*4882a593Smuzhiyun * maintain and manage HOBs with specific GUID.
122*4882a593Smuzhiyun */
123*4882a593Smuzhiyun struct hob_guid {
124*4882a593Smuzhiyun struct hob_header hdr;
125*4882a593Smuzhiyun /* A GUID that defines the contents of this HOB */
126*4882a593Smuzhiyun struct efi_guid name;
127*4882a593Smuzhiyun /* GUID specific data goes here */
128*4882a593Smuzhiyun };
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun /**
131*4882a593Smuzhiyun * get_next_hob() - return a pointer to the next HOB in the HOB list
132*4882a593Smuzhiyun *
133*4882a593Smuzhiyun * This macro returns a pointer to HOB that follows the HOB specified by hob
134*4882a593Smuzhiyun * in the HOB List.
135*4882a593Smuzhiyun *
136*4882a593Smuzhiyun * @hdr: A pointer to a HOB.
137*4882a593Smuzhiyun *
138*4882a593Smuzhiyun * @return: A pointer to the next HOB in the HOB list.
139*4882a593Smuzhiyun */
get_next_hob(const struct hob_header * hdr)140*4882a593Smuzhiyun static inline const struct hob_header *get_next_hob(const struct hob_header *hdr)
141*4882a593Smuzhiyun {
142*4882a593Smuzhiyun return (const struct hob_header *)((uintptr_t)hdr + hdr->len);
143*4882a593Smuzhiyun }
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun /**
146*4882a593Smuzhiyun * end_of_hob() - determine if a HOB is the last HOB in the HOB list
147*4882a593Smuzhiyun *
148*4882a593Smuzhiyun * This macro determine if the HOB specified by hob is the last HOB in the
149*4882a593Smuzhiyun * HOB list. If hob is last HOB in the HOB list, then true is returned.
150*4882a593Smuzhiyun * Otherwise, false is returned.
151*4882a593Smuzhiyun *
152*4882a593Smuzhiyun * @hdr: A pointer to a HOB.
153*4882a593Smuzhiyun *
154*4882a593Smuzhiyun * @retval true: The HOB specified by hdr is the last HOB in the HOB list.
155*4882a593Smuzhiyun * @retval false: The HOB specified by hdr is not the last HOB in the HOB list.
156*4882a593Smuzhiyun */
end_of_hob(const struct hob_header * hdr)157*4882a593Smuzhiyun static inline bool end_of_hob(const struct hob_header *hdr)
158*4882a593Smuzhiyun {
159*4882a593Smuzhiyun return hdr->type == HOB_TYPE_EOH;
160*4882a593Smuzhiyun }
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun /**
163*4882a593Smuzhiyun * get_guid_hob_data() - return a pointer to data buffer from a HOB of
164*4882a593Smuzhiyun * type HOB_TYPE_GUID_EXT
165*4882a593Smuzhiyun *
166*4882a593Smuzhiyun * This macro returns a pointer to the data buffer in a HOB specified by hob.
167*4882a593Smuzhiyun * hob is assumed to be a HOB of type HOB_TYPE_GUID_EXT.
168*4882a593Smuzhiyun *
169*4882a593Smuzhiyun * @hdr: A pointer to a HOB.
170*4882a593Smuzhiyun *
171*4882a593Smuzhiyun * @return: A pointer to the data buffer in a HOB.
172*4882a593Smuzhiyun */
get_guid_hob_data(const struct hob_header * hdr)173*4882a593Smuzhiyun static inline void *get_guid_hob_data(const struct hob_header *hdr)
174*4882a593Smuzhiyun {
175*4882a593Smuzhiyun return (void *)((uintptr_t)hdr + sizeof(struct hob_guid));
176*4882a593Smuzhiyun }
177*4882a593Smuzhiyun
178*4882a593Smuzhiyun /**
179*4882a593Smuzhiyun * get_guid_hob_data_size() - return the size of the data buffer from a HOB
180*4882a593Smuzhiyun * of type HOB_TYPE_GUID_EXT
181*4882a593Smuzhiyun *
182*4882a593Smuzhiyun * This macro returns the size, in bytes, of the data buffer in a HOB
183*4882a593Smuzhiyun * specified by hob. hob is assumed to be a HOB of type HOB_TYPE_GUID_EXT.
184*4882a593Smuzhiyun *
185*4882a593Smuzhiyun * @hdr: A pointer to a HOB.
186*4882a593Smuzhiyun *
187*4882a593Smuzhiyun * @return: The size of the data buffer.
188*4882a593Smuzhiyun */
get_guid_hob_data_size(const struct hob_header * hdr)189*4882a593Smuzhiyun static inline u16 get_guid_hob_data_size(const struct hob_header *hdr)
190*4882a593Smuzhiyun {
191*4882a593Smuzhiyun return hdr->len - sizeof(struct hob_guid);
192*4882a593Smuzhiyun }
193*4882a593Smuzhiyun
194*4882a593Smuzhiyun /* FSP specific GUID HOB definitions */
195*4882a593Smuzhiyun #define FSP_GUID_DATA1 0x912740be
196*4882a593Smuzhiyun #define FSP_GUID_DATA2 0x2284
197*4882a593Smuzhiyun #define FSP_GUID_DATA3 0x4734
198*4882a593Smuzhiyun #define FSP_GUID_DATA4_0 0xb9
199*4882a593Smuzhiyun #define FSP_GUID_DATA4_1 0x71
200*4882a593Smuzhiyun #define FSP_GUID_DATA4_2 0x84
201*4882a593Smuzhiyun #define FSP_GUID_DATA4_3 0xb0
202*4882a593Smuzhiyun #define FSP_GUID_DATA4_4 0x27
203*4882a593Smuzhiyun #define FSP_GUID_DATA4_5 0x35
204*4882a593Smuzhiyun #define FSP_GUID_DATA4_6 0x3f
205*4882a593Smuzhiyun #define FSP_GUID_DATA4_7 0x0c
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun #define FSP_HEADER_GUID \
208*4882a593Smuzhiyun { \
209*4882a593Smuzhiyun FSP_GUID_DATA1, FSP_GUID_DATA2, FSP_GUID_DATA3, \
210*4882a593Smuzhiyun { FSP_GUID_DATA4_0, FSP_GUID_DATA4_1, FSP_GUID_DATA4_2, \
211*4882a593Smuzhiyun FSP_GUID_DATA4_3, FSP_GUID_DATA4_4, FSP_GUID_DATA4_5, \
212*4882a593Smuzhiyun FSP_GUID_DATA4_6, FSP_GUID_DATA4_7 } \
213*4882a593Smuzhiyun }
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun #define FSP_NON_VOLATILE_STORAGE_HOB_GUID \
216*4882a593Smuzhiyun { \
217*4882a593Smuzhiyun 0x721acf02, 0x4d77, 0x4c2a, \
218*4882a593Smuzhiyun { 0xb3, 0xdc, 0x27, 0xb, 0x7b, 0xa9, 0xe4, 0xb0 } \
219*4882a593Smuzhiyun }
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun #define FSP_BOOTLOADER_TEMP_MEM_HOB_GUID \
222*4882a593Smuzhiyun { \
223*4882a593Smuzhiyun 0xbbcff46c, 0xc8d3, 0x4113, \
224*4882a593Smuzhiyun { 0x89, 0x85, 0xb9, 0xd4, 0xf3, 0xb3, 0xf6, 0x4e } \
225*4882a593Smuzhiyun }
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun #define FSP_HOB_RESOURCE_OWNER_FSP_GUID \
228*4882a593Smuzhiyun { \
229*4882a593Smuzhiyun 0x69a79759, 0x1373, 0x4367, \
230*4882a593Smuzhiyun { 0xa6, 0xc4, 0xc7, 0xf5, 0x9e, 0xfd, 0x98, 0x6e } \
231*4882a593Smuzhiyun }
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun #define FSP_HOB_RESOURCE_OWNER_TSEG_GUID \
234*4882a593Smuzhiyun { \
235*4882a593Smuzhiyun 0xd038747c, 0xd00c, 0x4980, \
236*4882a593Smuzhiyun { 0xb3, 0x19, 0x49, 0x01, 0x99, 0xa4, 0x7d, 0x55 } \
237*4882a593Smuzhiyun }
238*4882a593Smuzhiyun
239*4882a593Smuzhiyun #define FSP_HOB_RESOURCE_OWNER_GRAPHICS_GUID \
240*4882a593Smuzhiyun { \
241*4882a593Smuzhiyun 0x9c7c3aa7, 0x5332, 0x4917, \
242*4882a593Smuzhiyun { 0x82, 0xb9, 0x56, 0xa5, 0xf3, 0xe6, 0x2a, 0x07 } \
243*4882a593Smuzhiyun }
244*4882a593Smuzhiyun
245*4882a593Smuzhiyun #endif
246