878ddf1f |
1 | /** @file\r |
2 | Common functions used by PCD PEIM and PCD DXE.\r |
3 | \r |
4 | Copyright (c) 2006, Intel Corporation \r |
5 | All rights reserved. This program and the accompanying materials \r |
6 | are licensed and made available under the terms and conditions of the BSD License \r |
7 | which accompanies this distribution. The full text of the license may be found at \r |
8 | http://opensource.org/licenses/bsd-license.php \r |
9 | \r |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r |
12 | \r |
13 | \r |
14 | Module Name: PcdCommon.h\r |
15 | \r |
16 | **/\r |
17 | \r |
18 | #ifndef __PCD_COMMON_H__\r |
19 | #define __PCD_COMMON_H__\r |
20 | \r |
21 | //\r |
22 | // Enumeration for PCD_DATA_TYPE\r |
23 | //\r |
24 | typedef enum {\r |
25 | PcdByte8,\r |
26 | PcdByte16,\r |
27 | PcdByte32,\r |
28 | PcdByte64,\r |
29 | PcdPointer,\r |
30 | PcdBoolean\r |
31 | } PCD_DATA_TYPE;\r |
32 | \r |
33 | \r |
34 | //\r |
35 | // The definitions for Global PCD Length Fields\r |
36 | //\r |
37 | #define PCD_LENGTH_BIT8 0x01\r |
38 | #define PCD_LENGTH_BIT16 0x02\r |
39 | #define PCD_LENGTH_BIT24 0x03\r |
40 | #define PCD_LENGTH_BIT32 0x04\r |
41 | \r |
42 | \r |
43 | \r |
44 | /*\r |
45 | * This data structure is used in <PCD_IMAGE> transverse\r |
46 | */\r |
47 | typedef struct {\r |
48 | UINTN EntryCount;\r |
49 | UINTN GlobalOffsetLength;\r |
50 | UINTN GlobalTokenLength;\r |
51 | UINTN GlobalGuidTabIdxLength;\r |
52 | UINTN GlobalDatumLength;\r |
53 | UINTN GlobalStrTabIdxLength;\r |
54 | \r |
55 | CONST UINT8 *DataDefaultStart;\r |
56 | UINTN DataDefaultLength;\r |
57 | UINTN WholeDataDefaultLength;\r |
58 | CONST UINT8 *IndexStart;\r |
59 | UINTN IndexLength;\r |
60 | CONST GUID *GuidTableStart;\r |
61 | UINTN GuidTableLength;\r |
62 | CONST UINT16 *StringTableStart;\r |
63 | UINTN StringTableLength;\r |
64 | /* Length of the <PCD_IMAGE> in byte.\r |
65 | This info is from Section header\r |
66 | in FFS */\r |
67 | UINTN ImageLength;\r |
68 | CONST UINT8 *ImageStart;\r |
69 | \r |
70 | } PCD_IMAGE_RECORD;\r |
71 | \r |
72 | \r |
73 | \r |
74 | typedef struct {\r |
75 | BOOLEAN HiiEnable;\r |
76 | BOOLEAN SkuEnable;\r |
77 | BOOLEAN VpdEnable;\r |
78 | BOOLEAN SkuDataArrayEnable;\r |
79 | PCD_DATA_TYPE DataType;\r |
80 | BOOLEAN ExtendedGuidPresent;\r |
81 | } PCD_STATEBYTE;\r |
82 | \r |
83 | \r |
84 | \r |
85 | typedef struct {\r |
86 | //\r |
87 | // All Pointer's Offset in byte\r |
88 | //\r |
89 | UINT32 TokenNumber;\r |
90 | PCD_STATEBYTE StateByte;\r |
91 | UINT32 HiiData;\r |
92 | UINT32 SkuIdArray; //Pointer\r |
93 | UINT32 ExtendedDataOffset;\r |
94 | UINT32 DatumSize;\r |
95 | UINT16 DynamicExGuid; //Pointer\r |
96 | UINT8 SkuCount;\r |
97 | } PCD_INDEX;\r |
98 | \r |
99 | \r |
100 | \r |
101 | /* \r |
102 | * PCD Image Definition according PCD Specification 0.51. \r |
103 | *\r |
104 | */\r |
105 | #pragma pack(1)\r |
106 | typedef struct {\r |
107 | UINT8 ImageLength[3]; \r |
108 | //\r |
109 | // The length of PCD_FFS_ENCODING is included\r |
110 | // in ImageLength\r |
111 | //\r |
112 | UINT8 DataBufferLength[3];\r |
113 | UINT8 WholeDataBufferLength[3];\r |
114 | UINT8 PcdIndexLength[3];\r |
115 | UINT8 GuidTableLength[3];\r |
116 | //\r |
117 | // The StringTable can be computed using:\r |
118 | // ImageLength, DataBufferLength, PcdIndexLength, GuidTableLength,\r |
119 | // and length of PCD_FFS_ENCODING\r |
120 | //\r |
121 | UINT8 EntryCount[3];\r |
122 | UINT8 GlobalOffsetLength[1];\r |
123 | UINT8 GlobalTokenLength[1];\r |
124 | UINT8 GuidLength[1];\r |
125 | UINT8 GlobalDatumLength[1];\r |
126 | UINT8 GlobalStrTabIdxLength[1];\r |
127 | } PCD_FFS_ENCODING;\r |
128 | #pragma pack()\r |
129 | \r |
130 | \r |
131 | \r |
132 | typedef struct {\r |
133 | UINTN DatabaseLen;\r |
134 | UINTN EntryCount;\r |
135 | UINTN InfoLength;\r |
136 | UINTN GuidTableOffset;\r |
137 | UINTN PcdIndexOffset;\r |
138 | UINTN StringTableOffset;\r |
139 | UINTN CallbackTableOffset;\r |
140 | UINTN ImageIndexOffset;\r |
141 | UINTN DataBufferOffset;\r |
142 | UINTN MaxCallbackNum;\r |
143 | UINTN HiiVariableOffsetLength;\r |
144 | UINTN HiiGuidOffsetLength;\r |
145 | UINTN ExtendedOffsetLength;\r |
146 | UINT8 *VpdStart;\r |
147 | UINTN SkuId;\r |
148 | } PCD_DATABASE_HEADER;\r |
149 | \r |
150 | \r |
151 | \r |
152 | typedef struct {\r |
153 | PCD_DATABASE_HEADER Info;\r |
154 | EFI_GUID GuidTable[1];\r |
155 | } PCD_DATABASE;\r |
156 | \r |
157 | extern EFI_GUID gPcdDataBaseHobGuid;\r |
158 | \r |
159 | \r |
160 | /**\r |
161 | The function returns the actual address of item in the PCD\r |
162 | database according to its Segment and Offset.\r |
163 | \r |
164 | @param[out] Offset The offset within the segment.\r |
165 | @param[in] SegmentStart The starting address of the segment.\r |
166 | @param[in] DatabaseStart The base address of the PCD DataBase.\r |
167 | \r |
168 | \r |
169 | @retval EFI_SUCESS If data value is found according to SKU_ID.\r |
170 | @retval EFI_NOT_FOUND If not such a value is found.\r |
171 | \r |
172 | --*/\r |
173 | UINT8 *\r |
174 | GetAbsoluteAddress (\r |
175 | IN UINTN Offset, \r |
176 | IN UINTN SegmentStart, \r |
177 | IN CONST VOID *Base\r |
178 | )\r |
179 | ;\r |
180 | \r |
181 | \r |
182 | \r |
183 | /**\r |
184 | The function return the number of Unicode Character in a NULL terminated string.\r |
185 | The NULL is NOT counted.\r |
186 | \r |
187 | @param[in] String The unicode string starts from an unaligned address.\r |
188 | \r |
189 | @retval UINTN The number of Unicode characters.\r |
190 | --*/\r |
191 | UINTN\r |
192 | GetUnalignedStrLen (\r |
193 | UINT16 *String\r |
194 | );\r |
195 | \r |
196 | \r |
197 | /**\r |
198 | The function retrieves the PCD data value according to \r |
199 | TokenNumber and Guid space given.\r |
200 | \r |
201 | @param[in] Info The PCD Database Info.\r |
202 | @param[in] TokenNumber The token number.\r |
203 | @param[in] Guid The Guid space.\r |
204 | @param[in] Type The storage type.\r |
205 | @param[out] Data The output data.\r |
206 | \r |
207 | @retval VOID\r |
208 | \r |
209 | --*/\r |
210 | VOID\r |
211 | GetPcdEntryWorker (\r |
212 | IN CONST PCD_DATABASE_HEADER *Info,\r |
213 | IN UINTN TokenNumber,\r |
214 | IN CONST GUID *Guid, OPTIONAL\r |
215 | IN PCD_DATA_TYPE Type,\r |
216 | OUT VOID *Data\r |
217 | )\r |
218 | ;\r |
219 | \r |
220 | \r |
221 | \r |
222 | /**\r |
223 | The function retrieves the PCD data value according to \r |
224 | TokenNumber and Guid space given.\r |
225 | \r |
226 | @param[in] Info The PCD Database info.\r |
227 | @param[in] TokenNumber The token number.\r |
228 | @param[in] Guid The Guid space.\r |
229 | \r |
230 | @retval UINTN The size of the PCD Entry.\r |
231 | \r |
232 | --*/\r |
233 | UINTN\r |
234 | GetPcdEntrySizeWorker (\r |
235 | IN CONST PCD_DATABASE_HEADER *Info,\r |
236 | IN UINTN TokenNumber,\r |
237 | IN CONST GUID *Guid OPTIONAL\r |
238 | )\r |
239 | ;\r |
240 | \r |
241 | \r |
242 | \r |
243 | /**\r |
244 | The function looks for the next PCD ENTRY.\r |
245 | If *TokenNumber is 0, the first TokenNumber in\r |
246 | the GUID token space is return.\r |
247 | If there is no next TokenNumber found,\r |
248 | *TokenNumber will be 0.\r |
249 | \r |
250 | @param[in] Info The PCD Database info.\r |
251 | @param[in,out] TokenNumber The token number.\r |
252 | @param[in] Guid The Guid space.\r |
253 | \r |
254 | @retval EFI_NOT_FOUND Can't find the PCD_ENTRY.\r |
255 | @retval EFI_SUCCESS Operation succesful.\r |
256 | \r |
257 | --*/\r |
258 | EFI_STATUS\r |
259 | GetNextTokenWorker (\r |
260 | IN CONST PCD_DATABASE_HEADER *Info,\r |
261 | IN OUT UINTN *TokenNumber,\r |
262 | IN CONST GUID *Guid OPTIONAL\r |
263 | )\r |
264 | ;\r |
265 | \r |
266 | \r |
267 | \r |
268 | /**\r |
269 | The function is the worker function to set the data of a PCD entry.\r |
270 | \r |
271 | @param[in] PcdIndex The PCD Index.\r |
272 | @param[in] Info The attributes of the PCD database.\r |
273 | @param[in] Data The input data.\r |
274 | \r |
275 | @retval VOID\r |
276 | --*/\r |
277 | EFI_STATUS\r |
278 | SetPcdData (\r |
279 | IN CONST PCD_INDEX *PcdIndex,\r |
280 | IN CONST PCD_DATABASE_HEADER *Info,\r |
281 | IN CONST VOID *Data\r |
282 | )\r |
283 | ;\r |
284 | \r |
285 | \r |
286 | /**\r |
287 | The function is provided by PCD PEIM and PCD DXE driver to\r |
288 | do the work of reading a HII variable from variable service.\r |
289 | \r |
290 | @param[in] VariableGuid The Variable GUID.\r |
291 | @param[in] VariableName The Variable Name.\r |
292 | @param[out] VariableData The output data.\r |
293 | @param[out] VariableSize The size of the variable.\r |
294 | \r |
295 | @retval EFI_SUCCESS Operation successful.\r |
296 | @retval EFI_SUCCESS Variablel not found.\r |
297 | --*/\r |
298 | EFI_STATUS\r |
299 | GetHiiVariable (\r |
300 | IN EFI_GUID *VariableGuid,\r |
301 | IN UINT16 *VariableName,\r |
302 | OUT VOID **VariableData,\r |
303 | OUT UINTN *VariableSize\r |
304 | )\r |
305 | ;\r |
306 | \r |
307 | \r |
308 | \r |
309 | /**\r |
310 | The function is provided by PCD PEIM and PCD DXE driver to\r |
311 | do the work of reading a HII variable from variable service.\r |
312 | \r |
313 | @param[in] VariableGuid The Variable GUID.\r |
314 | @param[in] VariableName The Variable Name.\r |
315 | @param[in] Data The input data.\r |
316 | @param[out] VariableSize The size of the variable.\r |
317 | @param[in] Offset The offset of the variable data that a PCD entry will starts from.\r |
318 | \r |
319 | @retval EFI_SUCCESS Operation successful.\r |
320 | @retval EFI_SUCCESS Variablel not found.\r |
321 | --*/\r |
322 | EFI_STATUS\r |
323 | SetHiiVariable (\r |
324 | IN EFI_GUID *VariableGuid,\r |
325 | IN UINT16 *VariableName,\r |
326 | IN CONST VOID *Data,\r |
327 | IN UINTN VariableSize,\r |
328 | IN UINTN Offset\r |
329 | )\r |
330 | ;\r |
331 | \r |
332 | /**\r |
333 | The function locates the PCD_INDEX according to TokeNumber and GUID space given.\r |
334 | \r |
335 | @param[in] TokenNumber The token number.\r |
336 | @param[in] Guid The GUID token space.\r |
337 | @param[out] Info The attributes of the PCD database.\r |
338 | \r |
339 | @retval PCD_INDEX* The PCD_INDEX found.\r |
340 | --*/\r |
341 | PCD_INDEX *\r |
342 | FindPcdIndex (\r |
343 | IN UINTN TokenNumber,\r |
344 | IN CONST GUID *Guid,\r |
345 | IN CONST PCD_DATABASE_HEADER *Info,\r |
346 | OUT UINTN *Index\r |
347 | )\r |
348 | ;\r |
349 | \r |
350 | /**\r |
351 | (WQBUGBUG: You must handle the new SKU_ID encoding.\r |
352 | The function is the worker function to get the data of a PCD entry.\r |
353 | \r |
354 | @param[in] PcdIndex The PCD Index.\r |
355 | @param[in] Info The attributes of the PCD database.\r |
356 | @param[out] Data The output data.\r |
357 | \r |
358 | @retval VOID\r |
359 | --*/\r |
360 | UINT8*\r |
361 | GetPcdDataPtr (\r |
362 | IN CONST PCD_INDEX *PcdIndex,\r |
363 | IN CONST PCD_DATABASE_HEADER *Info\r |
364 | )\r |
365 | ;\r |
366 | \r |
367 | /**\r |
368 | The function retrieves the PCD data value according to\r |
369 | the PCD_DATA_TYPE specified.\r |
370 | \r |
371 | @param[in] Type The PCD_DATA_TYPE used to interpret the data.\r |
372 | @param[in] InData The input data.\r |
373 | @param[in] OutData The output data.\r |
374 | @param[in] Len The length of the data; it is mainly used for PcdPointer type.\r |
375 | \r |
376 | @retval VOID\r |
377 | --*/\r |
378 | VOID\r |
379 | GetDataBasedOnType (\r |
380 | IN PCD_DATA_TYPE Type,\r |
381 | IN VOID *InData,\r |
382 | OUT VOID *OutData,\r |
383 | IN UINTN Len\r |
384 | )\r |
385 | ;\r |
386 | #endif\r |