summaryrefslogtreecommitdiff
path: root/EdkModulePkg/Universal/PCD/Common/PcdCommon.h
blob: f61aa5be6a29f23a591ad8f915fb7e3023fb4dd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/** @file
Common functions used by PCD PEIM and PCD DXE.

Copyright (c) 2006, Intel Corporation                                                         
All rights reserved. This program and the accompanying materials                          
are licensed and made available under the terms and conditions of the BSD License         
which accompanies this distribution.  The full text of the license may be found at        
http://opensource.org/licenses/bsd-license.php                                            
                                                                                          
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             


Module Name: PcdCommon.h

**/

#ifndef __PCD_COMMON_H__
#define __PCD_COMMON_H__

//
// Enumeration for PCD_DATA_TYPE
//
typedef enum {
  PcdByte8,
  PcdByte16,
  PcdByte32,
  PcdByte64,
  PcdPointer,
  PcdBoolean
} PCD_DATA_TYPE;


//
// The definitions for Global PCD Length Fields
//
#define PCD_LENGTH_BIT8   0x01
#define PCD_LENGTH_BIT16  0x02
#define PCD_LENGTH_BIT24  0x03
#define PCD_LENGTH_BIT32  0x04



/*
 * This data structure is used in <PCD_IMAGE> transverse
 */
typedef struct {
  UINTN                EntryCount;
  UINTN                GlobalOffsetLength;
  UINTN                GlobalTokenLength;
  UINTN                GlobalGuidTabIdxLength;
  UINTN                GlobalDatumLength;
  UINTN                GlobalStrTabIdxLength;
  
  CONST UINT8          *DataDefaultStart;
  UINTN                DataDefaultLength;
  UINTN                WholeDataDefaultLength;
  CONST UINT8          *IndexStart;
  UINTN                IndexLength;
  CONST GUID           *GuidTableStart;
  UINTN                GuidTableLength;
  CONST UINT16         *StringTableStart;
  UINTN                StringTableLength;
  /* Length of the <PCD_IMAGE> in byte.
     This info is from Section header
     in FFS */
  UINTN               ImageLength;
  CONST UINT8         *ImageStart;

} PCD_IMAGE_RECORD;



typedef struct {
  BOOLEAN       HiiEnable;
  BOOLEAN       SkuEnable;
  BOOLEAN       VpdEnable;
  BOOLEAN       SkuDataArrayEnable;
  PCD_DATA_TYPE DataType;
  BOOLEAN       ExtendedGuidPresent;
} PCD_STATEBYTE;



typedef struct  {
  //
  // All Pointer's Offset in byte
  //
  UINT32           TokenNumber;
  PCD_STATEBYTE    StateByte;
  UINT32           HiiData;
  UINT32           SkuIdArray;   //Pointer
  UINT32           ExtendedDataOffset;
  UINT32           DatumSize;
  UINT16           DynamicExGuid; //Pointer
  UINT8            SkuCount;
} PCD_INDEX;



/* 
 * PCD Image Definition according PCD Specification 0.51. 
 *
 */
#pragma pack(1)
typedef struct {
  UINT8 ImageLength[3]; 
  //
  // The length of PCD_FFS_ENCODING is included
  // in ImageLength
  //
  UINT8 DataBufferLength[3];
  UINT8 WholeDataBufferLength[3];
  UINT8 PcdIndexLength[3];
  UINT8 GuidTableLength[3];
  //
  // The StringTable can be computed using:
  // ImageLength, DataBufferLength, PcdIndexLength, GuidTableLength,
  // and length of PCD_FFS_ENCODING
  //
  UINT8 EntryCount[3];
  UINT8 GlobalOffsetLength[1];
  UINT8 GlobalTokenLength[1];
  UINT8 GuidLength[1];
  UINT8 GlobalDatumLength[1];
  UINT8 GlobalStrTabIdxLength[1];
} PCD_FFS_ENCODING;
#pragma pack()


  
typedef struct {
  UINTN      DatabaseLen;
  UINTN      EntryCount;
  UINTN      InfoLength;
  UINTN      GuidTableOffset;
  UINTN      PcdIndexOffset;
  UINTN      StringTableOffset;
  UINTN      CallbackTableOffset;
  UINTN      ImageIndexOffset;
  UINTN      DataBufferOffset;
  UINTN      MaxCallbackNum;
  UINTN      HiiVariableOffsetLength;
  UINTN      HiiGuidOffsetLength;
  UINTN      ExtendedOffsetLength;
  UINT8      *VpdStart;
  UINTN      SkuId;
} PCD_DATABASE_HEADER;



typedef struct {
  PCD_DATABASE_HEADER Info;
  EFI_GUID            GuidTable[1];
} PCD_DATABASE;

extern EFI_GUID gPcdDataBaseHobGuid;


/**
  The function returns the actual address of item in the PCD
  database according to its Segment and Offset.

  @param[out] Offset        The offset within the segment.
  @param[in]  SegmentStart  The starting address of the segment.
  @param[in]  DatabaseStart The base address of the PCD DataBase.
  

  @retval EFI_SUCESS If data value is found according to SKU_ID.
  @retval EFI_NOT_FOUND If not such a value is found.

--*/
UINT8 *
GetAbsoluteAddress (
  IN UINTN        Offset, 
  IN UINTN        SegmentStart, 
  IN CONST VOID   *Base
  )
;



/**
  The function return the number of Unicode Character in a NULL terminated string.
  The NULL is  NOT counted.
  
  @param[in] String The unicode string starts from an unaligned address.
  
  @retval UINTN     The number of Unicode characters.
--*/
UINTN
GetUnalignedStrLen (
  UINT16 *String
);


/**
  The function retrieves the PCD data value according to 
  TokenNumber and Guid space given.

  @param[in]  Info        The PCD Database Info.
  @param[in]  TokenNumber The token number.
  @param[in]  Guid        The Guid space.
  @param[in]  Type        The storage type.
  @param[out] Data        The output data.

  @retval VOID

--*/
VOID
GetPcdEntryWorker (
  IN     CONST PCD_DATABASE_HEADER  *Info,
  IN     UINTN                      TokenNumber,
  IN     CONST GUID                 *Guid,  OPTIONAL
  IN     PCD_DATA_TYPE              Type,
  OUT    VOID                       *Data
  )
;



/**
  The function retrieves the PCD data value according to 
  TokenNumber and Guid space given.

  @param[in]  Info        The PCD Database info.
  @param[in]  TokenNumber The token number.
  @param[in]  Guid        The Guid space.

  @retval     UINTN       The size of the PCD Entry.

--*/
UINTN
GetPcdEntrySizeWorker (
  IN CONST PCD_DATABASE_HEADER  *Info,
  IN UINTN                      TokenNumber,
  IN CONST GUID                 *Guid  OPTIONAL
  )
;



/**
  The function looks for the next PCD ENTRY.
  If *TokenNumber is 0, the first TokenNumber in
  the GUID token space is return.
  If there is no next TokenNumber found,
  *TokenNumber will be 0.

  @param[in]      Info              The PCD Database info.
  @param[in,out]  TokenNumber       The token number.
  @param[in]      Guid              The Guid space.
  
  @retval     EFI_NOT_FOUND     Can't find the PCD_ENTRY.
  @retval     EFI_SUCCESS       Operation succesful.

--*/
EFI_STATUS
GetNextTokenWorker (
  IN CONST PCD_DATABASE_HEADER    *Info,
  IN OUT UINTN                    *TokenNumber,
  IN CONST GUID                   *Guid     OPTIONAL
  )
;



/**
  The function is the worker function to set the data of a PCD entry.
  
  @param[in] PcdIndex The PCD Index.
  @param[in] Info     The attributes of the PCD database.
  @param[in] Data     The input data.
  
  @retval VOID
--*/
EFI_STATUS
SetPcdData (
  IN CONST PCD_INDEX           *PcdIndex,
  IN CONST PCD_DATABASE_HEADER *Info,
  IN CONST VOID                *Data
  )
;


/**
  The function is provided by PCD PEIM and PCD DXE driver to
  do the work of reading a HII variable from variable service.
  
  @param[in] VariableGuid     The Variable GUID.
  @param[in] VariableName     The Variable Name.
  @param[out] VariableData    The output data.
  @param[out] VariableSize    The size of the variable.
  
  @retval EFI_SUCCESS         Operation successful.
  @retval EFI_SUCCESS         Variablel not found.
--*/
EFI_STATUS
GetHiiVariable (
  IN  EFI_GUID     *VariableGuid,
  IN  UINT16       *VariableName,
  OUT VOID         **VariableData,
  OUT UINTN        *VariableSize
  )
;



/**
  The function is provided by PCD PEIM and PCD DXE driver to
  do the work of reading a HII variable from variable service.
  
  @param[in] VariableGuid     The Variable GUID.
  @param[in] VariableName     The Variable Name.
  @param[in] Data             The input data.
  @param[out] VariableSize    The size of the variable.
  @param[in] Offset           The offset of the variable data that a PCD entry will starts from.
  
  @retval EFI_SUCCESS         Operation successful.
  @retval EFI_SUCCESS         Variablel not found.
--*/
EFI_STATUS
SetHiiVariable (
  IN  EFI_GUID     *VariableGuid,
  IN  UINT16       *VariableName,
  IN  CONST VOID   *Data,
  IN  UINTN        VariableSize,
  IN  UINTN        Offset
  )
;

/**
  The function locates the PCD_INDEX according to TokeNumber and GUID space given.

  @param[in] TokenNumber The token number.
  @param[in] Guid        The GUID token space.
  @param[out] Info       The attributes of the PCD database.

  @retval PCD_INDEX*     The PCD_INDEX found.
--*/
PCD_INDEX *
FindPcdIndex (
  IN   UINTN                     TokenNumber,
  IN   CONST GUID                *Guid,
  IN   CONST PCD_DATABASE_HEADER *Info,
  OUT  UINTN                     *Index
  )
;

/**
  (WQBUGBUG: You must handle the new SKU_ID encoding.
  The function is the worker function to get the data of a PCD entry.

  @param[in] PcdIndex The PCD Index.
  @param[in] Info     The attributes of the PCD database.
  @param[out] Data    The output data.

  @retval VOID
--*/
UINT8*
GetPcdDataPtr (
  IN CONST PCD_INDEX           *PcdIndex,
  IN CONST PCD_DATABASE_HEADER *Info
  )
;

/**
  The function retrieves the PCD data value according to
  the PCD_DATA_TYPE specified.

  @param[in] Type The PCD_DATA_TYPE used to interpret the data.
  @param[in] InData The input data.
  @param[in] OutData The output data.
  @param[in] Len The length of the data; it is mainly used for PcdPointer type.

  @retval VOID
--*/
VOID
GetDataBasedOnType (
  IN PCD_DATA_TYPE Type,
  IN VOID          *InData,
  OUT VOID         *OutData,
  IN UINTN         Len
  )
;
#endif