| 1 | /** @file\r |
| 2 | All Pcd Ppi services are implemented here.\r |
| 3 | \r |
| 4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
| 5 | (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r |
| 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
| 7 | \r |
| 8 | **/\r |
| 9 | \r |
| 10 | #include "Service.h"\r |
| 11 | \r |
| 12 | ///\r |
| 13 | /// Instance of PCD_PPI protocol is EDKII native implementation.\r |
| 14 | /// This protocol instance support dynamic and dynamicEx type PCDs.\r |
| 15 | ///\r |
| 16 | PCD_PPI mPcdPpiInstance = {\r |
| 17 | PeiPcdSetSku,\r |
| 18 | \r |
| 19 | PeiPcdGet8,\r |
| 20 | PeiPcdGet16,\r |
| 21 | PeiPcdGet32,\r |
| 22 | PeiPcdGet64,\r |
| 23 | PeiPcdGetPtr,\r |
| 24 | PeiPcdGetBool,\r |
| 25 | PeiPcdGetSize,\r |
| 26 | \r |
| 27 | PeiPcdGet8Ex,\r |
| 28 | PeiPcdGet16Ex,\r |
| 29 | PeiPcdGet32Ex,\r |
| 30 | PeiPcdGet64Ex,\r |
| 31 | PeiPcdGetPtrEx,\r |
| 32 | PeiPcdGetBoolEx,\r |
| 33 | PeiPcdGetSizeEx,\r |
| 34 | \r |
| 35 | PeiPcdSet8,\r |
| 36 | PeiPcdSet16,\r |
| 37 | PeiPcdSet32,\r |
| 38 | PeiPcdSet64,\r |
| 39 | PeiPcdSetPtr,\r |
| 40 | PeiPcdSetBool,\r |
| 41 | \r |
| 42 | PeiPcdSet8Ex,\r |
| 43 | PeiPcdSet16Ex,\r |
| 44 | PeiPcdSet32Ex,\r |
| 45 | PeiPcdSet64Ex,\r |
| 46 | PeiPcdSetPtrEx,\r |
| 47 | PeiPcdSetBoolEx,\r |
| 48 | \r |
| 49 | PeiRegisterCallBackOnSet,\r |
| 50 | PcdUnRegisterCallBackOnSet,\r |
| 51 | PeiPcdGetNextToken,\r |
| 52 | PeiPcdGetNextTokenSpace\r |
| 53 | };\r |
| 54 | \r |
| 55 | ///\r |
| 56 | /// Instance of EFI_PEI_PCD_PPI which is defined in PI 1.2 Vol 3.\r |
| 57 | /// This PPI instance only support dyanmicEx type PCD.\r |
| 58 | ///\r |
| 59 | EFI_PEI_PCD_PPI mEfiPcdPpiInstance = {\r |
| 60 | PeiPcdSetSku,\r |
| 61 | \r |
| 62 | PeiPcdGet8Ex,\r |
| 63 | PeiPcdGet16Ex,\r |
| 64 | PeiPcdGet32Ex,\r |
| 65 | PeiPcdGet64Ex,\r |
| 66 | PeiPcdGetPtrEx,\r |
| 67 | PeiPcdGetBoolEx,\r |
| 68 | PeiPcdGetSizeEx,\r |
| 69 | PeiPcdSet8Ex,\r |
| 70 | PeiPcdSet16Ex,\r |
| 71 | PeiPcdSet32Ex,\r |
| 72 | PeiPcdSet64Ex,\r |
| 73 | PeiPcdSetPtrEx,\r |
| 74 | PeiPcdSetBoolEx,\r |
| 75 | (EFI_PEI_PCD_PPI_CALLBACK_ON_SET) PeiRegisterCallBackOnSet,\r |
| 76 | (EFI_PEI_PCD_PPI_CANCEL_CALLBACK) PcdUnRegisterCallBackOnSet,\r |
| 77 | PeiPcdGetNextToken,\r |
| 78 | PeiPcdGetNextTokenSpace\r |
| 79 | };\r |
| 80 | \r |
| 81 | ///\r |
| 82 | /// Instance of GET_PCD_INFO_PPI protocol is EDKII native implementation.\r |
| 83 | /// This protocol instance support dynamic and dynamicEx type PCDs.\r |
| 84 | ///\r |
| 85 | GET_PCD_INFO_PPI mGetPcdInfoInstance = {\r |
| 86 | PeiGetPcdInfoGetInfo,\r |
| 87 | PeiGetPcdInfoGetInfoEx,\r |
| 88 | PeiGetPcdInfoGetSku\r |
| 89 | };\r |
| 90 | \r |
| 91 | ///\r |
| 92 | /// Instance of EFI_GET_PCD_INFO_PPI which is defined in PI 1.2.1 Vol 3.\r |
| 93 | /// This PPI instance only support dyanmicEx type PCD.\r |
| 94 | ///\r |
| 95 | EFI_GET_PCD_INFO_PPI mEfiGetPcdInfoInstance = {\r |
| 96 | PeiGetPcdInfoGetInfoEx,\r |
| 97 | PeiGetPcdInfoGetSku\r |
| 98 | };\r |
| 99 | \r |
| 100 | EFI_PEI_PPI_DESCRIPTOR mPpiList[] = {\r |
| 101 | {\r |
| 102 | EFI_PEI_PPI_DESCRIPTOR_PPI,\r |
| 103 | &gPcdPpiGuid,\r |
| 104 | &mPcdPpiInstance\r |
| 105 | },\r |
| 106 | {\r |
| 107 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r |
| 108 | &gEfiPeiPcdPpiGuid,\r |
| 109 | &mEfiPcdPpiInstance\r |
| 110 | }\r |
| 111 | };\r |
| 112 | \r |
| 113 | EFI_PEI_PPI_DESCRIPTOR mPpiList2[] = {\r |
| 114 | {\r |
| 115 | EFI_PEI_PPI_DESCRIPTOR_PPI,\r |
| 116 | &gGetPcdInfoPpiGuid,\r |
| 117 | &mGetPcdInfoInstance\r |
| 118 | },\r |
| 119 | {\r |
| 120 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r |
| 121 | &gEfiGetPcdInfoPpiGuid,\r |
| 122 | &mEfiGetPcdInfoInstance\r |
| 123 | }\r |
| 124 | };\r |
| 125 | \r |
| 126 | /**\r |
| 127 | Callback on SET PcdSetNvStoreDefaultId\r |
| 128 | \r |
| 129 | Once PcdSetNvStoreDefaultId is set, the default NV storage will be found from\r |
| 130 | PcdNvStoreDefaultValueBuffer, and built into VariableHob.\r |
| 131 | \r |
| 132 | @param[in] CallBackGuid The PCD token GUID being set.\r |
| 133 | @param[in] CallBackToken The PCD token number being set.\r |
| 134 | @param[in, out] TokenData A pointer to the token data being set.\r |
| 135 | @param[in] TokenDataSize The size, in bytes, of the data being set.\r |
| 136 | \r |
| 137 | **/\r |
| 138 | VOID\r |
| 139 | EFIAPI\r |
| 140 | PcdSetNvStoreDefaultIdCallBack (\r |
| 141 | IN CONST EFI_GUID *CallBackGuid, OPTIONAL\r |
| 142 | IN UINTN CallBackToken,\r |
| 143 | IN OUT VOID *TokenData,\r |
| 144 | IN UINTN TokenDataSize\r |
| 145 | )\r |
| 146 | {\r |
| 147 | EFI_STATUS Status;\r |
| 148 | UINT16 DefaultId;\r |
| 149 | SKU_ID SkuId;\r |
| 150 | UINTN FullSize;\r |
| 151 | UINTN Index;\r |
| 152 | UINT8 *DataBuffer;\r |
| 153 | UINT8 *VarStoreHobData;\r |
| 154 | UINT8 *BufferEnd;\r |
| 155 | BOOLEAN IsFound;\r |
| 156 | VARIABLE_STORE_HEADER *NvStoreBuffer;\r |
| 157 | PCD_DEFAULT_DATA *DataHeader;\r |
| 158 | PCD_DEFAULT_INFO *DefaultInfo;\r |
| 159 | PCD_DATA_DELTA *DeltaData;\r |
| 160 | \r |
| 161 | DefaultId = *(UINT16 *) TokenData;\r |
| 162 | SkuId = GetPcdDatabase()->SystemSkuId;\r |
| 163 | IsFound = FALSE;\r |
| 164 | \r |
| 165 | if (PeiPcdGetSizeEx (&gEfiMdeModulePkgTokenSpaceGuid, PcdToken (PcdNvStoreDefaultValueBuffer)) > sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER)) {\r |
| 166 | DataBuffer = (UINT8 *) PeiPcdGetPtrEx (&gEfiMdeModulePkgTokenSpaceGuid, PcdToken (PcdNvStoreDefaultValueBuffer));\r |
| 167 | FullSize = ((PCD_NV_STORE_DEFAULT_BUFFER_HEADER *) DataBuffer)->Length;\r |
| 168 | DataHeader = (PCD_DEFAULT_DATA *) (DataBuffer + sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER));\r |
| 169 | //\r |
| 170 | // The first section data includes NV storage default setting.\r |
| 171 | //\r |
| 172 | NvStoreBuffer = (VARIABLE_STORE_HEADER *) ((UINT8 *) DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize);\r |
| 173 | VarStoreHobData = (UINT8 *) BuildGuidHob (&NvStoreBuffer->Signature, NvStoreBuffer->Size);\r |
| 174 | ASSERT (VarStoreHobData != NULL);\r |
| 175 | CopyMem (VarStoreHobData, NvStoreBuffer, NvStoreBuffer->Size);\r |
| 176 | //\r |
| 177 | // Find the matched SkuId and DefaultId in the first section\r |
| 178 | //\r |
| 179 | DefaultInfo = &(DataHeader->DefaultInfo[0]);\r |
| 180 | BufferEnd = (UINT8 *) DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize;\r |
| 181 | while ((UINT8 *) DefaultInfo < BufferEnd) {\r |
| 182 | if (DefaultInfo->DefaultId == DefaultId && DefaultInfo->SkuId == SkuId) {\r |
| 183 | IsFound = TRUE;\r |
| 184 | break;\r |
| 185 | }\r |
| 186 | DefaultInfo ++;\r |
| 187 | }\r |
| 188 | //\r |
| 189 | // Find the matched SkuId and DefaultId in the remaining section\r |
| 190 | //\r |
| 191 | Index = sizeof (PCD_NV_STORE_DEFAULT_BUFFER_HEADER) + ((DataHeader->DataSize + 7) & (~7));\r |
| 192 | DataHeader = (PCD_DEFAULT_DATA *) (DataBuffer + Index);\r |
| 193 | while (!IsFound && Index < FullSize && DataHeader->DataSize != 0xFFFFFFFF) {\r |
| 194 | DefaultInfo = &(DataHeader->DefaultInfo[0]);\r |
| 195 | BufferEnd = (UINT8 *) DataHeader + sizeof (DataHeader->DataSize) + DataHeader->HeaderSize;\r |
| 196 | while ((UINT8 *) DefaultInfo < BufferEnd) {\r |
| 197 | if (DefaultInfo->DefaultId == DefaultId && DefaultInfo->SkuId == SkuId) {\r |
| 198 | IsFound = TRUE;\r |
| 199 | break;\r |
| 200 | }\r |
| 201 | DefaultInfo ++;\r |
| 202 | }\r |
| 203 | if (IsFound) {\r |
| 204 | DeltaData = (PCD_DATA_DELTA *) BufferEnd;\r |
| 205 | BufferEnd = (UINT8 *) DataHeader + DataHeader->DataSize;\r |
| 206 | while ((UINT8 *) DeltaData < BufferEnd) {\r |
| 207 | *(VarStoreHobData + DeltaData->Offset) = (UINT8) DeltaData->Value;\r |
| 208 | DeltaData ++;\r |
| 209 | }\r |
| 210 | break;\r |
| 211 | }\r |
| 212 | Index = (Index + DataHeader->DataSize + 7) & (~7) ;\r |
| 213 | DataHeader = (PCD_DEFAULT_DATA *) (DataBuffer + Index);\r |
| 214 | }\r |
| 215 | }\r |
| 216 | \r |
| 217 | Status = PcdUnRegisterCallBackOnSet (\r |
| 218 | &gEfiMdeModulePkgTokenSpaceGuid,\r |
| 219 | PcdToken(PcdSetNvStoreDefaultId),\r |
| 220 | PcdSetNvStoreDefaultIdCallBack\r |
| 221 | );\r |
| 222 | ASSERT_EFI_ERROR (Status);\r |
| 223 | }\r |
| 224 | \r |
| 225 | /**\r |
| 226 | Report Pei PCD database of all SKUs as Guid HOB so that DxePcd can access it.\r |
| 227 | \r |
| 228 | @param PeiServices An indirect pointer to the EFI_PEI_SERVICES table published by the PEI Foundation\r |
| 229 | @param NotifyDescriptor Address of the notification descriptor data structure.\r |
| 230 | @param Ppi Address of the PPI that was installed.\r |
| 231 | \r |
| 232 | @retval EFI_SUCCESS Successfully update the Boot records.\r |
| 233 | **/\r |
| 234 | EFI_STATUS\r |
| 235 | EFIAPI\r |
| 236 | EndOfPeiSignalPpiNotifyCallback (\r |
| 237 | IN EFI_PEI_SERVICES **PeiServices,\r |
| 238 | IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDescriptor,\r |
| 239 | IN VOID *Ppi\r |
| 240 | )\r |
| 241 | {\r |
| 242 | PEI_PCD_DATABASE *Database;\r |
| 243 | EFI_BOOT_MODE BootMode;\r |
| 244 | EFI_STATUS Status;\r |
| 245 | UINTN Instance;\r |
| 246 | EFI_PEI_FV_HANDLE VolumeHandle;\r |
| 247 | EFI_PEI_FILE_HANDLE FileHandle;\r |
| 248 | VOID *PcdDb;\r |
| 249 | UINT32 Length;\r |
| 250 | PEI_PCD_DATABASE *PeiPcdDb;\r |
| 251 | \r |
| 252 | Status = PeiServicesGetBootMode(&BootMode);\r |
| 253 | ASSERT_EFI_ERROR (Status);\r |
| 254 | \r |
| 255 | //\r |
| 256 | // Don't need to report it on S3 boot.\r |
| 257 | //\r |
| 258 | if (BootMode == BOOT_ON_S3_RESUME) {\r |
| 259 | return EFI_SUCCESS;\r |
| 260 | }\r |
| 261 | \r |
| 262 | PeiPcdDb = GetPcdDatabase();\r |
| 263 | if (PeiPcdDb->SystemSkuId != (SKU_ID) 0) {\r |
| 264 | //\r |
| 265 | // SkuId has been set. Don't need to report it to DXE phase.\r |
| 266 | //\r |
| 267 | return EFI_SUCCESS;\r |
| 268 | }\r |
| 269 | \r |
| 270 | //\r |
| 271 | // Get full PCD database from PcdPeim FileHandle\r |
| 272 | //\r |
| 273 | Instance = 0;\r |
| 274 | FileHandle = NULL;\r |
| 275 | while (TRUE) {\r |
| 276 | //\r |
| 277 | // Traverse all firmware volume instances\r |
| 278 | //\r |
| 279 | Status = PeiServicesFfsFindNextVolume (Instance, &VolumeHandle);\r |
| 280 | //\r |
| 281 | // Error should not happen\r |
| 282 | //\r |
| 283 | ASSERT_EFI_ERROR (Status);\r |
| 284 | \r |
| 285 | //\r |
| 286 | // Find PcdDb file from the beginning in this firmware volume.\r |
| 287 | //\r |
| 288 | FileHandle = NULL;\r |
| 289 | Status = PeiServicesFfsFindFileByName (&gEfiCallerIdGuid, VolumeHandle, &FileHandle);\r |
| 290 | if (!EFI_ERROR (Status)) {\r |
| 291 | //\r |
| 292 | // Find PcdPeim FileHandle in this volume\r |
| 293 | //\r |
| 294 | break;\r |
| 295 | }\r |
| 296 | //\r |
| 297 | // We cannot find PcdPeim in this firmware volume, then search the next volume.\r |
| 298 | //\r |
| 299 | Instance++;\r |
| 300 | }\r |
| 301 | \r |
| 302 | //\r |
| 303 | // Find PEI PcdDb and Build second PcdDB GuidHob\r |
| 304 | //\r |
| 305 | Status = PeiServicesFfsFindSectionData (EFI_SECTION_RAW, FileHandle, &PcdDb);\r |
| 306 | ASSERT_EFI_ERROR (Status);\r |
| 307 | Length = PeiPcdDb->LengthForAllSkus;\r |
| 308 | Database = BuildGuidHob (&gPcdDataBaseHobGuid, Length);\r |
| 309 | CopyMem (Database, PcdDb, Length);\r |
| 310 | \r |
| 311 | return EFI_SUCCESS;\r |
| 312 | }\r |
| 313 | \r |
| 314 | EFI_PEI_NOTIFY_DESCRIPTOR mEndOfPeiSignalPpiNotifyList[] = {\r |
| 315 | {\r |
| 316 | (EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r |
| 317 | &gEfiEndOfPeiSignalPpiGuid,\r |
| 318 | EndOfPeiSignalPpiNotifyCallback\r |
| 319 | }\r |
| 320 | };\r |
| 321 | \r |
| 322 | /**\r |
| 323 | Main entry for PCD PEIM driver.\r |
| 324 | \r |
| 325 | This routine initialize the PCD database for PEI phase and install PCD_PPI/EFI_PEI_PCD_PPI.\r |
| 326 | \r |
| 327 | @param FileHandle Handle of the file being invoked.\r |
| 328 | @param PeiServices Describes the list of possible PEI Services.\r |
| 329 | \r |
| 330 | @return Status of install PCD_PPI\r |
| 331 | \r |
| 332 | **/\r |
| 333 | EFI_STATUS\r |
| 334 | EFIAPI\r |
| 335 | PcdPeimInit (\r |
| 336 | IN EFI_PEI_FILE_HANDLE FileHandle,\r |
| 337 | IN CONST EFI_PEI_SERVICES **PeiServices\r |
| 338 | )\r |
| 339 | {\r |
| 340 | EFI_STATUS Status;\r |
| 341 | \r |
| 342 | BuildPcdDatabase (FileHandle);\r |
| 343 | \r |
| 344 | //\r |
| 345 | // Install PCD_PPI and EFI_PEI_PCD_PPI.\r |
| 346 | //\r |
| 347 | Status = PeiServicesInstallPpi (&mPpiList[0]);\r |
| 348 | ASSERT_EFI_ERROR (Status);\r |
| 349 | \r |
| 350 | //\r |
| 351 | // Install GET_PCD_INFO_PPI and EFI_GET_PCD_INFO_PPI.\r |
| 352 | //\r |
| 353 | Status = PeiServicesInstallPpi (&mPpiList2[0]);\r |
| 354 | ASSERT_EFI_ERROR (Status);\r |
| 355 | \r |
| 356 | Status = PeiServicesNotifyPpi (&mEndOfPeiSignalPpiNotifyList[0]);\r |
| 357 | ASSERT_EFI_ERROR (Status);\r |
| 358 | \r |
| 359 | Status = PeiRegisterCallBackOnSet (\r |
| 360 | &gEfiMdeModulePkgTokenSpaceGuid,\r |
| 361 | PcdToken(PcdSetNvStoreDefaultId),\r |
| 362 | PcdSetNvStoreDefaultIdCallBack\r |
| 363 | );\r |
| 364 | ASSERT_EFI_ERROR (Status);\r |
| 365 | \r |
| 366 | return Status;\r |
| 367 | }\r |
| 368 | \r |
| 369 | /**\r |
| 370 | Retrieve additional information associated with a PCD token in the default token space.\r |
| 371 | \r |
| 372 | This includes information such as the type of value the TokenNumber is associated with as well as possible\r |
| 373 | human readable name that is associated with the token.\r |
| 374 | \r |
| 375 | @param[in] TokenNumber The PCD token number.\r |
| 376 | @param[out] PcdInfo The returned information associated with the requested TokenNumber.\r |
| 377 | The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r |
| 378 | \r |
| 379 | @retval EFI_SUCCESS The PCD information was returned successfully.\r |
| 380 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r |
| 381 | **/\r |
| 382 | EFI_STATUS\r |
| 383 | EFIAPI\r |
| 384 | PeiGetPcdInfoGetInfo (\r |
| 385 | IN UINTN TokenNumber,\r |
| 386 | OUT EFI_PCD_INFO *PcdInfo\r |
| 387 | )\r |
| 388 | {\r |
| 389 | return PeiGetPcdInfo (NULL, TokenNumber, PcdInfo);\r |
| 390 | }\r |
| 391 | \r |
| 392 | /**\r |
| 393 | Retrieve additional information associated with a PCD token.\r |
| 394 | \r |
| 395 | This includes information such as the type of value the TokenNumber is associated with as well as possible\r |
| 396 | human readable name that is associated with the token.\r |
| 397 | \r |
| 398 | @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r |
| 399 | @param[in] TokenNumber The PCD token number.\r |
| 400 | @param[out] PcdInfo The returned information associated with the requested TokenNumber.\r |
| 401 | The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r |
| 402 | \r |
| 403 | @retval EFI_SUCCESS The PCD information was returned successfully.\r |
| 404 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r |
| 405 | **/\r |
| 406 | EFI_STATUS\r |
| 407 | EFIAPI\r |
| 408 | PeiGetPcdInfoGetInfoEx (\r |
| 409 | IN CONST EFI_GUID *Guid,\r |
| 410 | IN UINTN TokenNumber,\r |
| 411 | OUT EFI_PCD_INFO *PcdInfo\r |
| 412 | )\r |
| 413 | {\r |
| 414 | return PeiGetPcdInfo (Guid, TokenNumber, PcdInfo);\r |
| 415 | }\r |
| 416 | \r |
| 417 | /**\r |
| 418 | Retrieve the currently set SKU Id.\r |
| 419 | \r |
| 420 | @return The currently set SKU Id. If the platform has not set at a SKU Id, then the\r |
| 421 | default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU\r |
| 422 | Id is returned.\r |
| 423 | **/\r |
| 424 | UINTN\r |
| 425 | EFIAPI\r |
| 426 | PeiGetPcdInfoGetSku (\r |
| 427 | VOID\r |
| 428 | )\r |
| 429 | {\r |
| 430 | return (UINTN) GetPcdDatabase()->SystemSkuId;\r |
| 431 | }\r |
| 432 | \r |
| 433 | /**\r |
| 434 | Sets the SKU value for subsequent calls to set or get PCD token values.\r |
| 435 | \r |
| 436 | SetSku() sets the SKU Id to be used for subsequent calls to set or get PCD values.\r |
| 437 | SetSku() is normally called only once by the system.\r |
| 438 | \r |
| 439 | For each item (token), the database can hold a single value that applies to all SKUs,\r |
| 440 | or multiple values, where each value is associated with a specific SKU Id. Items with multiple,\r |
| 441 | SKU-specific values are called SKU enabled.\r |
| 442 | \r |
| 443 | The SKU Id of zero is reserved as a default.\r |
| 444 | For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the\r |
| 445 | single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the\r |
| 446 | last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token,\r |
| 447 | the system uses the default SKU Id. If the system attempts to use the default SKU Id and no value has been\r |
| 448 | set for that Id, the results are unpredictable.\r |
| 449 | \r |
| 450 | @param[in] SkuId The SKU value that will be used when the PCD service will retrieve and\r |
| 451 | set values associated with a PCD token.\r |
| 452 | \r |
| 453 | **/\r |
| 454 | VOID\r |
| 455 | EFIAPI\r |
| 456 | PeiPcdSetSku (\r |
| 457 | IN UINTN SkuId\r |
| 458 | )\r |
| 459 | {\r |
| 460 | PEI_PCD_DATABASE *PeiPcdDb;\r |
| 461 | SKU_ID *SkuIdTable;\r |
| 462 | UINTN Index;\r |
| 463 | EFI_STATUS Status;\r |
| 464 | UINTN Instance;\r |
| 465 | EFI_PEI_FV_HANDLE VolumeHandle;\r |
| 466 | EFI_PEI_FILE_HANDLE FileHandle;\r |
| 467 | VOID *PcdDb;\r |
| 468 | UINT32 Length;\r |
| 469 | PCD_DATABASE_SKU_DELTA *SkuDelta;\r |
| 470 | PCD_DATA_DELTA *SkuDeltaData;\r |
| 471 | \r |
| 472 | DEBUG ((DEBUG_INFO, "PcdPei - SkuId 0x%lx is to be set.\n", (SKU_ID) SkuId));\r |
| 473 | \r |
| 474 | PeiPcdDb = GetPcdDatabase();\r |
| 475 | \r |
| 476 | if (SkuId == PeiPcdDb->SystemSkuId) {\r |
| 477 | //\r |
| 478 | // The input SKU Id is equal to current SKU Id, return directly.\r |
| 479 | //\r |
| 480 | DEBUG ((DEBUG_INFO, "PcdPei - SkuId is same to current system Sku.\n"));\r |
| 481 | return;\r |
| 482 | }\r |
| 483 | \r |
| 484 | if (PeiPcdDb->SystemSkuId != (SKU_ID) 0) {\r |
| 485 | DEBUG ((DEBUG_ERROR, "PcdPei - The SKU Id could be changed only once."));\r |
| 486 | DEBUG ((\r |
| 487 | DEBUG_ERROR,\r |
| 488 | "PcdPei - The SKU Id was set to 0x%lx already, it could not be set to 0x%lx any more.",\r |
| 489 | PeiPcdDb->SystemSkuId,\r |
| 490 | (SKU_ID) SkuId\r |
| 491 | ));\r |
| 492 | ASSERT (FALSE);\r |
| 493 | return;\r |
| 494 | }\r |
| 495 | \r |
| 496 | SkuIdTable = (SKU_ID *) ((UINT8 *) PeiPcdDb + PeiPcdDb->SkuIdTableOffset);\r |
| 497 | for (Index = 0; Index < SkuIdTable[0]; Index++) {\r |
| 498 | if (SkuId == SkuIdTable[Index + 1]) {\r |
| 499 | DEBUG ((DEBUG_INFO, "PcdPei - SkuId is found in SkuId table.\n"));\r |
| 500 | break;\r |
| 501 | }\r |
| 502 | }\r |
| 503 | \r |
| 504 | if (Index < SkuIdTable[0]) {\r |
| 505 | //\r |
| 506 | // Get full PCD database from PcdPeim FileHandle\r |
| 507 | //\r |
| 508 | Instance = 0;\r |
| 509 | FileHandle = NULL;\r |
| 510 | while (TRUE) {\r |
| 511 | //\r |
| 512 | // Traverse all firmware volume instances\r |
| 513 | //\r |
| 514 | Status = PeiServicesFfsFindNextVolume (Instance, &VolumeHandle);\r |
| 515 | //\r |
| 516 | // Error should not happen\r |
| 517 | //\r |
| 518 | ASSERT_EFI_ERROR (Status);\r |
| 519 | \r |
| 520 | //\r |
| 521 | // Find PcdDb file from the beginning in this firmware volume.\r |
| 522 | //\r |
| 523 | FileHandle = NULL;\r |
| 524 | Status = PeiServicesFfsFindFileByName (&gEfiCallerIdGuid, VolumeHandle, &FileHandle);\r |
| 525 | if (!EFI_ERROR (Status)) {\r |
| 526 | //\r |
| 527 | // Find PcdPeim FileHandle in this volume\r |
| 528 | //\r |
| 529 | break;\r |
| 530 | }\r |
| 531 | //\r |
| 532 | // We cannot find PcdPeim in this firmware volume, then search the next volume.\r |
| 533 | //\r |
| 534 | Instance++;\r |
| 535 | }\r |
| 536 | \r |
| 537 | //\r |
| 538 | // Find the delta data between the different Skus\r |
| 539 | //\r |
| 540 | Status = PeiServicesFfsFindSectionData (EFI_SECTION_RAW, FileHandle, &PcdDb);\r |
| 541 | ASSERT_EFI_ERROR (Status);\r |
| 542 | Length = PeiPcdDb->LengthForAllSkus;\r |
| 543 | Index = (PeiPcdDb->Length + 7) & (~7);\r |
| 544 | SkuDelta = NULL;\r |
| 545 | while (Index < Length) {\r |
| 546 | SkuDelta = (PCD_DATABASE_SKU_DELTA *) ((UINT8 *) PcdDb + Index);\r |
| 547 | if (SkuDelta->SkuId == SkuId && SkuDelta->SkuIdCompared == 0) {\r |
| 548 | break;\r |
| 549 | }\r |
| 550 | Index = (Index + SkuDelta->Length + 7) & (~7);\r |
| 551 | }\r |
| 552 | \r |
| 553 | //\r |
| 554 | // Patch the delta data into current PCD database\r |
| 555 | //\r |
| 556 | if (Index < Length && SkuDelta != NULL) {\r |
| 557 | SkuDeltaData = (PCD_DATA_DELTA *) (SkuDelta + 1);\r |
| 558 | while ((UINT8 *) SkuDeltaData < (UINT8 *) SkuDelta + SkuDelta->Length) {\r |
| 559 | *((UINT8 *) PeiPcdDb + SkuDeltaData->Offset) = (UINT8) SkuDeltaData->Value;\r |
| 560 | SkuDeltaData ++;\r |
| 561 | }\r |
| 562 | PeiPcdDb->SystemSkuId = (SKU_ID) SkuId;\r |
| 563 | DEBUG ((DEBUG_INFO, "PcdPei - Set current SKU Id to 0x%lx.\n", (SKU_ID) SkuId));\r |
| 564 | return;\r |
| 565 | }\r |
| 566 | }\r |
| 567 | \r |
| 568 | //\r |
| 569 | // Invalid input SkuId, the default SKU Id will be still used for the system.\r |
| 570 | //\r |
| 571 | DEBUG ((DEBUG_ERROR, "PcdPei - Invalid input SkuId, the default SKU Id will be still used.\n"));\r |
| 572 | \r |
| 573 | return;\r |
| 574 | }\r |
| 575 | \r |
| 576 | /**\r |
| 577 | Retrieves an 8-bit value for a given PCD token.\r |
| 578 | \r |
| 579 | Retrieves the current byte-sized value for a PCD token number.\r |
| 580 | If the TokenNumber is invalid, the results are unpredictable.\r |
| 581 | \r |
| 582 | @param[in] TokenNumber The PCD token number.\r |
| 583 | \r |
| 584 | @return The UINT8 value.\r |
| 585 | \r |
| 586 | **/\r |
| 587 | UINT8\r |
| 588 | EFIAPI\r |
| 589 | PeiPcdGet8 (\r |
| 590 | IN UINTN TokenNumber\r |
| 591 | )\r |
| 592 | {\r |
| 593 | return *((UINT8 *) GetWorker (TokenNumber, sizeof (UINT8)));\r |
| 594 | }\r |
| 595 | \r |
| 596 | /**\r |
| 597 | Retrieves an 16-bit value for a given PCD token.\r |
| 598 | \r |
| 599 | Retrieves the current 16-bits value for a PCD token number.\r |
| 600 | If the TokenNumber is invalid, the results are unpredictable.\r |
| 601 | \r |
| 602 | @param[in] TokenNumber The PCD token number.\r |
| 603 | \r |
| 604 | @return The UINT16 value.\r |
| 605 | \r |
| 606 | **/\r |
| 607 | UINT16\r |
| 608 | EFIAPI\r |
| 609 | PeiPcdGet16 (\r |
| 610 | IN UINTN TokenNumber\r |
| 611 | )\r |
| 612 | {\r |
| 613 | return ReadUnaligned16 (GetWorker (TokenNumber, sizeof (UINT16)));\r |
| 614 | }\r |
| 615 | \r |
| 616 | /**\r |
| 617 | Retrieves an 32-bit value for a given PCD token.\r |
| 618 | \r |
| 619 | Retrieves the current 32-bits value for a PCD token number.\r |
| 620 | If the TokenNumber is invalid, the results are unpredictable.\r |
| 621 | \r |
| 622 | @param[in] TokenNumber The PCD token number.\r |
| 623 | \r |
| 624 | @return The UINT32 value.\r |
| 625 | \r |
| 626 | **/\r |
| 627 | UINT32\r |
| 628 | EFIAPI\r |
| 629 | PeiPcdGet32 (\r |
| 630 | IN UINTN TokenNumber\r |
| 631 | )\r |
| 632 | {\r |
| 633 | return ReadUnaligned32 (GetWorker (TokenNumber, sizeof (UINT32)));\r |
| 634 | }\r |
| 635 | \r |
| 636 | /**\r |
| 637 | Retrieves an 64-bit value for a given PCD token.\r |
| 638 | \r |
| 639 | Retrieves the current 64-bits value for a PCD token number.\r |
| 640 | If the TokenNumber is invalid, the results are unpredictable.\r |
| 641 | \r |
| 642 | @param[in] TokenNumber The PCD token number.\r |
| 643 | \r |
| 644 | @return The UINT64 value.\r |
| 645 | \r |
| 646 | **/\r |
| 647 | UINT64\r |
| 648 | EFIAPI\r |
| 649 | PeiPcdGet64 (\r |
| 650 | IN UINTN TokenNumber\r |
| 651 | )\r |
| 652 | {\r |
| 653 | return ReadUnaligned64 (GetWorker (TokenNumber, sizeof (UINT64)));\r |
| 654 | }\r |
| 655 | \r |
| 656 | /**\r |
| 657 | Retrieves a pointer to a value for a given PCD token.\r |
| 658 | \r |
| 659 | Retrieves the current pointer to the buffer for a PCD token number.\r |
| 660 | Do not make any assumptions about the alignment of the pointer that\r |
| 661 | is returned by this function call. If the TokenNumber is invalid,\r |
| 662 | the results are unpredictable.\r |
| 663 | \r |
| 664 | @param[in] TokenNumber The PCD token number.\r |
| 665 | \r |
| 666 | @return The pointer to the buffer to be retrieved.\r |
| 667 | \r |
| 668 | **/\r |
| 669 | VOID *\r |
| 670 | EFIAPI\r |
| 671 | PeiPcdGetPtr (\r |
| 672 | IN UINTN TokenNumber\r |
| 673 | )\r |
| 674 | {\r |
| 675 | return GetWorker (TokenNumber, 0);\r |
| 676 | }\r |
| 677 | \r |
| 678 | /**\r |
| 679 | Retrieves a Boolean value for a given PCD token.\r |
| 680 | \r |
| 681 | Retrieves the current boolean value for a PCD token number.\r |
| 682 | Do not make any assumptions about the alignment of the pointer that\r |
| 683 | is returned by this function call. If the TokenNumber is invalid,\r |
| 684 | the results are unpredictable.\r |
| 685 | \r |
| 686 | @param[in] TokenNumber The PCD token number.\r |
| 687 | \r |
| 688 | @return The Boolean value.\r |
| 689 | \r |
| 690 | **/\r |
| 691 | BOOLEAN\r |
| 692 | EFIAPI\r |
| 693 | PeiPcdGetBool (\r |
| 694 | IN UINTN TokenNumber\r |
| 695 | )\r |
| 696 | {\r |
| 697 | return *((BOOLEAN *) GetWorker (TokenNumber, sizeof (BOOLEAN)));\r |
| 698 | }\r |
| 699 | \r |
| 700 | /**\r |
| 701 | Retrieves the size of the value for a given PCD token.\r |
| 702 | \r |
| 703 | Retrieves the current size of a particular PCD token.\r |
| 704 | If the TokenNumber is invalid, the results are unpredictable.\r |
| 705 | \r |
| 706 | @param[in] TokenNumber The PCD token number.\r |
| 707 | \r |
| 708 | @return The size of the value for the PCD token.\r |
| 709 | \r |
| 710 | **/\r |
| 711 | UINTN\r |
| 712 | EFIAPI\r |
| 713 | PeiPcdGetSize (\r |
| 714 | IN UINTN TokenNumber\r |
| 715 | )\r |
| 716 | {\r |
| 717 | PEI_PCD_DATABASE *PeiPcdDb;\r |
| 718 | UINTN Size;\r |
| 719 | UINTN MaxSize;\r |
| 720 | UINT32 LocalTokenCount;\r |
| 721 | \r |
| 722 | PeiPcdDb = GetPcdDatabase ();\r |
| 723 | LocalTokenCount = PeiPcdDb->LocalTokenCount;\r |
| 724 | //\r |
| 725 | // TokenNumber Zero is reserved as PCD_INVALID_TOKEN_NUMBER.\r |
| 726 | // We have to decrement TokenNumber by 1 to make it usable\r |
| 727 | // as the array index.\r |
| 728 | //\r |
| 729 | TokenNumber--;\r |
| 730 | \r |
| 731 | // EBC compiler is very choosy. It may report warning about comparison\r |
| 732 | // between UINTN and 0 . So we add 1 in each size of the\r |
| 733 | // comparison.\r |
| 734 | ASSERT (TokenNumber + 1 < (LocalTokenCount + 1));\r |
| 735 | \r |
| 736 | Size = (*((UINT32 *)((UINT8 *)PeiPcdDb + PeiPcdDb->LocalTokenNumberTableOffset) + TokenNumber) & PCD_DATUM_TYPE_ALL_SET) >> PCD_DATUM_TYPE_SHIFT;\r |
| 737 | \r |
| 738 | if (Size == 0) {\r |
| 739 | //\r |
| 740 | // For pointer type, we need to scan the SIZE_TABLE to get the current size.\r |
| 741 | //\r |
| 742 | return GetPtrTypeSize (TokenNumber, &MaxSize, PeiPcdDb);\r |
| 743 | } else {\r |
| 744 | return Size;\r |
| 745 | }\r |
| 746 | \r |
| 747 | }\r |
| 748 | \r |
| 749 | /**\r |
| 750 | Retrieves an 8-bit value for a given PCD token.\r |
| 751 | \r |
| 752 | Retrieves the 8-bit value of a particular PCD token.\r |
| 753 | If the TokenNumber is invalid or the token space\r |
| 754 | specified by Guid does not exist, the results are\r |
| 755 | unpredictable.\r |
| 756 | \r |
| 757 | @param[in] Guid The token space for the token number.\r |
| 758 | @param[in] ExTokenNumber The PCD token number.\r |
| 759 | \r |
| 760 | @return The size 8-bit value for the PCD token.\r |
| 761 | \r |
| 762 | **/\r |
| 763 | UINT8\r |
| 764 | EFIAPI\r |
| 765 | PeiPcdGet8Ex (\r |
| 766 | IN CONST EFI_GUID *Guid,\r |
| 767 | IN UINTN ExTokenNumber\r |
| 768 | )\r |
| 769 | {\r |
| 770 | return *((UINT8 *) ExGetWorker (Guid, ExTokenNumber, sizeof (UINT8)));\r |
| 771 | }\r |
| 772 | \r |
| 773 | /**\r |
| 774 | Retrieves an 16-bit value for a given PCD token.\r |
| 775 | \r |
| 776 | Retrieves the 16-bit value of a particular PCD token.\r |
| 777 | If the TokenNumber is invalid or the token space\r |
| 778 | specified by Guid does not exist, the results are\r |
| 779 | unpredictable.\r |
| 780 | \r |
| 781 | @param[in] Guid The token space for the token number.\r |
| 782 | @param[in] ExTokenNumber The PCD token number.\r |
| 783 | \r |
| 784 | @return The size 16-bit value for the PCD token.\r |
| 785 | \r |
| 786 | **/\r |
| 787 | UINT16\r |
| 788 | EFIAPI\r |
| 789 | PeiPcdGet16Ex (\r |
| 790 | IN CONST EFI_GUID *Guid,\r |
| 791 | IN UINTN ExTokenNumber\r |
| 792 | )\r |
| 793 | {\r |
| 794 | return ReadUnaligned16 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT16)));\r |
| 795 | }\r |
| 796 | \r |
| 797 | /**\r |
| 798 | Retrieves an 32-bit value for a given PCD token.\r |
| 799 | \r |
| 800 | Retrieves the 32-bit value of a particular PCD token.\r |
| 801 | If the TokenNumber is invalid or the token space\r |
| 802 | specified by Guid does not exist, the results are\r |
| 803 | unpredictable.\r |
| 804 | \r |
| 805 | @param[in] Guid The token space for the token number.\r |
| 806 | @param[in] ExTokenNumber The PCD token number.\r |
| 807 | \r |
| 808 | @return The size 32-bit value for the PCD token.\r |
| 809 | \r |
| 810 | **/\r |
| 811 | UINT32\r |
| 812 | EFIAPI\r |
| 813 | PeiPcdGet32Ex (\r |
| 814 | IN CONST EFI_GUID *Guid,\r |
| 815 | IN UINTN ExTokenNumber\r |
| 816 | )\r |
| 817 | {\r |
| 818 | return ReadUnaligned32 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT32)));\r |
| 819 | }\r |
| 820 | \r |
| 821 | /**\r |
| 822 | Retrieves an 64-bit value for a given PCD token.\r |
| 823 | \r |
| 824 | Retrieves the 64-bit value of a particular PCD token.\r |
| 825 | If the TokenNumber is invalid or the token space\r |
| 826 | specified by Guid does not exist, the results are\r |
| 827 | unpredictable.\r |
| 828 | \r |
| 829 | @param[in] Guid The token space for the token number.\r |
| 830 | @param[in] ExTokenNumber The PCD token number.\r |
| 831 | \r |
| 832 | @return The size 64-bit value for the PCD token.\r |
| 833 | \r |
| 834 | **/\r |
| 835 | UINT64\r |
| 836 | EFIAPI\r |
| 837 | PeiPcdGet64Ex (\r |
| 838 | IN CONST EFI_GUID *Guid,\r |
| 839 | IN UINTN ExTokenNumber\r |
| 840 | )\r |
| 841 | {\r |
| 842 | return ReadUnaligned64 (ExGetWorker (Guid, ExTokenNumber, sizeof (UINT64)));\r |
| 843 | }\r |
| 844 | \r |
| 845 | /**\r |
| 846 | Retrieves a pointer to a value for a given PCD token.\r |
| 847 | \r |
| 848 | Retrieves the current pointer to the buffer for a PCD token number.\r |
| 849 | Do not make any assumptions about the alignment of the pointer that\r |
| 850 | is returned by this function call. If the TokenNumber is invalid,\r |
| 851 | the results are unpredictable.\r |
| 852 | \r |
| 853 | @param[in] Guid The token space for the token number.\r |
| 854 | @param[in] ExTokenNumber The PCD token number.\r |
| 855 | \r |
| 856 | @return The pointer to the buffer to be retrieved.\r |
| 857 | \r |
| 858 | **/\r |
| 859 | VOID *\r |
| 860 | EFIAPI\r |
| 861 | PeiPcdGetPtrEx (\r |
| 862 | IN CONST EFI_GUID *Guid,\r |
| 863 | IN UINTN ExTokenNumber\r |
| 864 | )\r |
| 865 | {\r |
| 866 | return ExGetWorker (Guid, ExTokenNumber, 0);\r |
| 867 | }\r |
| 868 | \r |
| 869 | /**\r |
| 870 | Retrieves an Boolean value for a given PCD token.\r |
| 871 | \r |
| 872 | Retrieves the Boolean value of a particular PCD token.\r |
| 873 | If the TokenNumber is invalid or the token space\r |
| 874 | specified by Guid does not exist, the results are\r |
| 875 | unpredictable.\r |
| 876 | \r |
| 877 | @param[in] Guid The token space for the token number.\r |
| 878 | @param[in] ExTokenNumber The PCD token number.\r |
| 879 | \r |
| 880 | @return The size Boolean value for the PCD token.\r |
| 881 | \r |
| 882 | **/\r |
| 883 | BOOLEAN\r |
| 884 | EFIAPI\r |
| 885 | PeiPcdGetBoolEx (\r |
| 886 | IN CONST EFI_GUID *Guid,\r |
| 887 | IN UINTN ExTokenNumber\r |
| 888 | )\r |
| 889 | {\r |
| 890 | return *((BOOLEAN *) ExGetWorker (Guid, ExTokenNumber, sizeof (BOOLEAN)));\r |
| 891 | }\r |
| 892 | \r |
| 893 | /**\r |
| 894 | Retrieves the size of the value for a given PCD token.\r |
| 895 | \r |
| 896 | Retrieves the current size of a particular PCD token.\r |
| 897 | If the TokenNumber is invalid, the results are unpredictable.\r |
| 898 | \r |
| 899 | @param[in] Guid The token space for the token number.\r |
| 900 | @param[in] ExTokenNumber The PCD token number.\r |
| 901 | \r |
| 902 | @return The size of the value for the PCD token.\r |
| 903 | \r |
| 904 | **/\r |
| 905 | UINTN\r |
| 906 | EFIAPI\r |
| 907 | PeiPcdGetSizeEx (\r |
| 908 | IN CONST EFI_GUID *Guid,\r |
| 909 | IN UINTN ExTokenNumber\r |
| 910 | )\r |
| 911 | {\r |
| 912 | return PeiPcdGetSize (GetExPcdTokenNumber (Guid, ExTokenNumber));\r |
| 913 | }\r |
| 914 | \r |
| 915 | /**\r |
| 916 | Sets an 8-bit value for a given PCD token.\r |
| 917 | \r |
| 918 | When the PCD service sets a value, it will check to ensure that the\r |
| 919 | size of the value being set is compatible with the Token's existing definition.\r |
| 920 | If it is not, an error will be returned.\r |
| 921 | \r |
| 922 | @param[in] TokenNumber The PCD token number.\r |
| 923 | @param[in] Value The value to set for the PCD token.\r |
| 924 | \r |
| 925 | @retval EFI_SUCCESS Procedure returned successfully.\r |
| 926 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r |
| 927 | being set was incompatible with a call to this function.\r |
| 928 | Use GetSize() to retrieve the size of the target data.\r |
| 929 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r |
| 930 | \r |
| 931 | **/\r |
| 932 | EFI_STATUS\r |
| 933 | EFIAPI\r |
| 934 | PeiPcdSet8 (\r |
| 935 | IN UINTN TokenNumber,\r |
| 936 | IN UINT8 Value\r |
| 937 | )\r |
| 938 | {\r |
| 939 | return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r |
| 940 | }\r |
| 941 | \r |
| 942 | /**\r |
| 943 | Sets an 16-bit value for a given PCD token.\r |
| 944 | \r |
| 945 | When the PCD service sets a value, it will check to ensure that the\r |
| 946 | size of the value being set is compatible with the Token's existing definition.\r |
| 947 | If it is not, an error will be returned.\r |
| 948 | \r |
| 949 | @param[in] TokenNumber The PCD token number.\r |
| 950 | @param[in] Value The value to set for the PCD token.\r |
| 951 | \r |
| 952 | @retval EFI_SUCCESS Procedure returned successfully.\r |
| 953 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r |
| 954 | being set was incompatible with a call to this function.\r |
| 955 | Use GetSize() to retrieve the size of the target data.\r |
| 956 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r |
| 957 | \r |
| 958 | **/\r |
| 959 | EFI_STATUS\r |
| 960 | EFIAPI\r |
| 961 | PeiPcdSet16 (\r |
| 962 | IN UINTN TokenNumber,\r |
| 963 | IN UINT16 Value\r |
| 964 | )\r |
| 965 | {\r |
| 966 | return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r |
| 967 | }\r |
| 968 | \r |
| 969 | /**\r |
| 970 | Sets an 32-bit value for a given PCD token.\r |
| 971 | \r |
| 972 | When the PCD service sets a value, it will check to ensure that the\r |
| 973 | size of the value being set is compatible with the Token's existing definition.\r |
| 974 | If it is not, an error will be returned.\r |
| 975 | \r |
| 976 | @param[in] TokenNumber The PCD token number.\r |
| 977 | @param[in] Value The value to set for the PCD token.\r |
| 978 | \r |
| 979 | @retval EFI_SUCCESS Procedure returned successfully.\r |
| 980 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r |
| 981 | being set was incompatible with a call to this function.\r |
| 982 | Use GetSize() to retrieve the size of the target data.\r |
| 983 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r |
| 984 | \r |
| 985 | **/\r |
| 986 | EFI_STATUS\r |
| 987 | EFIAPI\r |
| 988 | PeiPcdSet32 (\r |
| 989 | IN UINTN TokenNumber,\r |
| 990 | IN UINT32 Value\r |
| 991 | )\r |
| 992 | {\r |
| 993 | return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r |
| 994 | }\r |
| 995 | \r |
| 996 | /**\r |
| 997 | Sets an 64-bit value for a given PCD token.\r |
| 998 | \r |
| 999 | When the PCD service sets a value, it will check to ensure that the\r |
| 1000 | size of the value being set is compatible with the Token's existing definition.\r |
| 1001 | If it is not, an error will be returned.\r |
| 1002 | \r |
| 1003 | @param[in] TokenNumber The PCD token number.\r |
| 1004 | @param[in] Value The value to set for the PCD token.\r |
| 1005 | \r |
| 1006 | @retval EFI_SUCCESS Procedure returned successfully.\r |
| 1007 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r |
| 1008 | being set was incompatible with a call to this function.\r |
| 1009 | Use GetSize() to retrieve the size of the target data.\r |
| 1010 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r |
| 1011 | \r |
| 1012 | **/\r |
| 1013 | EFI_STATUS\r |
| 1014 | EFIAPI\r |
| 1015 | PeiPcdSet64 (\r |
| 1016 | IN UINTN TokenNumber,\r |
| 1017 | IN UINT64 Value\r |
| 1018 | )\r |
| 1019 | {\r |
| 1020 | return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r |
| 1021 | }\r |
| 1022 | \r |
| 1023 | /**\r |
| 1024 | Sets a value of a specified size for a given PCD token.\r |
| 1025 | \r |
| 1026 | When the PCD service sets a value, it will check to ensure that the\r |
| 1027 | size of the value being set is compatible with the Token's existing definition.\r |
| 1028 | If it is not, an error will be returned.\r |
| 1029 | \r |
| 1030 | @param[in] TokenNumber The PCD token number.\r |
| 1031 | @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.\r |
| 1032 | On input, if the SizeOfValue is greater than the maximum size supported\r |
| 1033 | for this TokenNumber then the output value of SizeOfValue will reflect\r |
| 1034 | the maximum size supported for this TokenNumber.\r |
| 1035 | @param[in] Buffer The buffer to set for the PCD token.\r |
| 1036 | \r |
| 1037 | @retval EFI_SUCCESS Procedure returned successfully.\r |
| 1038 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r |
| 1039 | being set was incompatible with a call to this function.\r |
| 1040 | Use GetSize() to retrieve the size of the target data.\r |
| 1041 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r |
| 1042 | \r |
| 1043 | **/\r |
| 1044 | EFI_STATUS\r |
| 1045 | EFIAPI\r |
| 1046 | PeiPcdSetPtr (\r |
| 1047 | IN UINTN TokenNumber,\r |
| 1048 | IN OUT UINTN *SizeOfBuffer,\r |
| 1049 | IN VOID *Buffer\r |
| 1050 | )\r |
| 1051 | {\r |
| 1052 | return SetWorker (TokenNumber, Buffer, SizeOfBuffer, TRUE);\r |
| 1053 | }\r |
| 1054 | \r |
| 1055 | /**\r |
| 1056 | Sets an Boolean value for a given PCD token.\r |
| 1057 | \r |
| 1058 | When the PCD service sets a value, it will check to ensure that the\r |
| 1059 | size of the value being set is compatible with the Token's existing definition.\r |
| 1060 | If it is not, an error will be returned.\r |
| 1061 | \r |
| 1062 | @param[in] TokenNumber The PCD token number.\r |
| 1063 | @param[in] Value The value to set for the PCD token.\r |
| 1064 | \r |
| 1065 | @retval EFI_SUCCESS Procedure returned successfully.\r |
| 1066 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r |
| 1067 | being set was incompatible with a call to this function.\r |
| 1068 | Use GetSize() to retrieve the size of the target data.\r |
| 1069 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r |
| 1070 | \r |
| 1071 | **/\r |
| 1072 | EFI_STATUS\r |
| 1073 | EFIAPI\r |
| 1074 | PeiPcdSetBool (\r |
| 1075 | IN UINTN TokenNumber,\r |
| 1076 | IN BOOLEAN Value\r |
| 1077 | )\r |
| 1078 | {\r |
| 1079 | return SetValueWorker (TokenNumber, &Value, sizeof (Value));\r |
| 1080 | }\r |
| 1081 | \r |
| 1082 | /**\r |
| 1083 | Sets an 8-bit value for a given PCD token.\r |
| 1084 | \r |
| 1085 | When the PCD service sets a value, it will check to ensure that the\r |
| 1086 | size of the value being set is compatible with the Token's existing definition.\r |
| 1087 | If it is not, an error will be returned.\r |
| 1088 | \r |
| 1089 | @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r |
| 1090 | @param[in] ExTokenNumber The PCD token number.\r |
| 1091 | @param[in] Value The value to set for the PCD token.\r |
| 1092 | \r |
| 1093 | @retval EFI_SUCCESS Procedure returned successfully.\r |
| 1094 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r |
| 1095 | being set was incompatible with a call to this function.\r |
| 1096 | Use GetSize() to retrieve the size of the target data.\r |
| 1097 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r |
| 1098 | \r |
| 1099 | **/\r |
| 1100 | EFI_STATUS\r |
| 1101 | EFIAPI\r |
| 1102 | PeiPcdSet8Ex (\r |
| 1103 | IN CONST EFI_GUID *Guid,\r |
| 1104 | IN UINTN ExTokenNumber,\r |
| 1105 | IN UINT8 Value\r |
| 1106 | )\r |
| 1107 | {\r |
| 1108 | return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r |
| 1109 | }\r |
| 1110 | \r |
| 1111 | /**\r |
| 1112 | Sets an 16-bit value for a given PCD token.\r |
| 1113 | \r |
| 1114 | When the PCD service sets a value, it will check to ensure that the\r |
| 1115 | size of the value being set is compatible with the Token's existing definition.\r |
| 1116 | If it is not, an error will be returned.\r |
| 1117 | \r |
| 1118 | @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r |
| 1119 | @param[in] ExTokenNumber The PCD token number.\r |
| 1120 | @param[in] Value The value to set for the PCD token.\r |
| 1121 | \r |
| 1122 | @retval EFI_SUCCESS Procedure returned successfully.\r |
| 1123 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r |
| 1124 | being set was incompatible with a call to this function.\r |
| 1125 | Use GetSize() to retrieve the size of the target data.\r |
| 1126 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r |
| 1127 | \r |
| 1128 | **/\r |
| 1129 | EFI_STATUS\r |
| 1130 | EFIAPI\r |
| 1131 | PeiPcdSet16Ex (\r |
| 1132 | IN CONST EFI_GUID *Guid,\r |
| 1133 | IN UINTN ExTokenNumber,\r |
| 1134 | IN UINT16 Value\r |
| 1135 | )\r |
| 1136 | {\r |
| 1137 | return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r |
| 1138 | }\r |
| 1139 | \r |
| 1140 | /**\r |
| 1141 | Sets an 32-bit value for a given PCD token.\r |
| 1142 | \r |
| 1143 | When the PCD service sets a value, it will check to ensure that the\r |
| 1144 | size of the value being set is compatible with the Token's existing definition.\r |
| 1145 | If it is not, an error will be returned.\r |
| 1146 | \r |
| 1147 | @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r |
| 1148 | @param[in] ExTokenNumber The PCD token number.\r |
| 1149 | @param[in] Value The value to set for the PCD token.\r |
| 1150 | \r |
| 1151 | @retval EFI_SUCCESS Procedure returned successfully.\r |
| 1152 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r |
| 1153 | being set was incompatible with a call to this function.\r |
| 1154 | Use GetSize() to retrieve the size of the target data.\r |
| 1155 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r |
| 1156 | \r |
| 1157 | **/\r |
| 1158 | EFI_STATUS\r |
| 1159 | EFIAPI\r |
| 1160 | PeiPcdSet32Ex (\r |
| 1161 | IN CONST EFI_GUID *Guid,\r |
| 1162 | IN UINTN ExTokenNumber,\r |
| 1163 | IN UINT32 Value\r |
| 1164 | )\r |
| 1165 | {\r |
| 1166 | return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r |
| 1167 | }\r |
| 1168 | \r |
| 1169 | /**\r |
| 1170 | Sets an 64-bit value for a given PCD token.\r |
| 1171 | \r |
| 1172 | When the PCD service sets a value, it will check to ensure that the\r |
| 1173 | size of the value being set is compatible with the Token's existing definition.\r |
| 1174 | If it is not, an error will be returned.\r |
| 1175 | \r |
| 1176 | @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r |
| 1177 | @param[in] ExTokenNumber The PCD token number.\r |
| 1178 | @param[in] Value The value to set for the PCD token.\r |
| 1179 | \r |
| 1180 | @retval EFI_SUCCESS Procedure returned successfully.\r |
| 1181 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r |
| 1182 | being set was incompatible with a call to this function.\r |
| 1183 | Use GetSize() to retrieve the size of the target data.\r |
| 1184 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r |
| 1185 | \r |
| 1186 | **/\r |
| 1187 | EFI_STATUS\r |
| 1188 | EFIAPI\r |
| 1189 | PeiPcdSet64Ex (\r |
| 1190 | IN CONST EFI_GUID *Guid,\r |
| 1191 | IN UINTN ExTokenNumber,\r |
| 1192 | IN UINT64 Value\r |
| 1193 | )\r |
| 1194 | {\r |
| 1195 | return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r |
| 1196 | }\r |
| 1197 | \r |
| 1198 | /**\r |
| 1199 | Sets a value of a specified size for a given PCD token.\r |
| 1200 | \r |
| 1201 | When the PCD service sets a value, it will check to ensure that the\r |
| 1202 | size of the value being set is compatible with the Token's existing definition.\r |
| 1203 | If it is not, an error will be returned.\r |
| 1204 | \r |
| 1205 | @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r |
| 1206 | @param[in] ExTokenNumber The PCD token number.\r |
| 1207 | @param[in, out] SizeOfBuffer A pointer to the length of the value being set for the PCD token.\r |
| 1208 | On input, if the SizeOfValue is greater than the maximum size supported\r |
| 1209 | for this TokenNumber then the output value of SizeOfValue will reflect\r |
| 1210 | the maximum size supported for this TokenNumber.\r |
| 1211 | @param[in] Value The buffer to set for the PCD token.\r |
| 1212 | \r |
| 1213 | @retval EFI_SUCCESS Procedure returned successfully.\r |
| 1214 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r |
| 1215 | being set was incompatible with a call to this function.\r |
| 1216 | Use GetSize() to retrieve the size of the target data.\r |
| 1217 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r |
| 1218 | \r |
| 1219 | **/\r |
| 1220 | EFI_STATUS\r |
| 1221 | EFIAPI\r |
| 1222 | PeiPcdSetPtrEx (\r |
| 1223 | IN CONST EFI_GUID *Guid,\r |
| 1224 | IN UINTN ExTokenNumber,\r |
| 1225 | IN OUT UINTN *SizeOfBuffer,\r |
| 1226 | IN VOID *Value\r |
| 1227 | )\r |
| 1228 | {\r |
| 1229 | return ExSetWorker (ExTokenNumber, Guid, Value, SizeOfBuffer, TRUE);\r |
| 1230 | }\r |
| 1231 | \r |
| 1232 | /**\r |
| 1233 | Sets an Boolean value for a given PCD token.\r |
| 1234 | \r |
| 1235 | When the PCD service sets a value, it will check to ensure that the\r |
| 1236 | size of the value being set is compatible with the Token's existing definition.\r |
| 1237 | If it is not, an error will be returned.\r |
| 1238 | \r |
| 1239 | @param [in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r |
| 1240 | @param [in] ExTokenNumber The PCD token number.\r |
| 1241 | @param [in] Value The value to set for the PCD token.\r |
| 1242 | \r |
| 1243 | @retval EFI_SUCCESS Procedure returned successfully.\r |
| 1244 | @retval EFI_INVALID_PARAMETER The PCD service determined that the size of the data\r |
| 1245 | being set was incompatible with a call to this function.\r |
| 1246 | Use GetSize() to retrieve the size of the target data.\r |
| 1247 | @retval EFI_NOT_FOUND The PCD service could not find the requested token number.\r |
| 1248 | \r |
| 1249 | **/\r |
| 1250 | EFI_STATUS\r |
| 1251 | EFIAPI\r |
| 1252 | PeiPcdSetBoolEx (\r |
| 1253 | IN CONST EFI_GUID *Guid,\r |
| 1254 | IN UINTN ExTokenNumber,\r |
| 1255 | IN BOOLEAN Value\r |
| 1256 | )\r |
| 1257 | {\r |
| 1258 | return ExSetValueWorker (ExTokenNumber, Guid, &Value, sizeof (Value));\r |
| 1259 | }\r |
| 1260 | \r |
| 1261 | /**\r |
| 1262 | Specifies a function to be called anytime the value of a designated token is changed.\r |
| 1263 | \r |
| 1264 | @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r |
| 1265 | @param[in] ExTokenNumber The PCD token number.\r |
| 1266 | @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.\r |
| 1267 | \r |
| 1268 | @retval EFI_SUCCESS The PCD service has successfully established a call event\r |
| 1269 | for the CallBackToken requested.\r |
| 1270 | @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.\r |
| 1271 | \r |
| 1272 | **/\r |
| 1273 | EFI_STATUS\r |
| 1274 | EFIAPI\r |
| 1275 | PeiRegisterCallBackOnSet (\r |
| 1276 | IN CONST EFI_GUID *Guid, OPTIONAL\r |
| 1277 | IN UINTN ExTokenNumber,\r |
| 1278 | IN PCD_PPI_CALLBACK CallBackFunction\r |
| 1279 | )\r |
| 1280 | {\r |
| 1281 | if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable)) {\r |
| 1282 | return EFI_UNSUPPORTED;\r |
| 1283 | }\r |
| 1284 | \r |
| 1285 | if (CallBackFunction == NULL) {\r |
| 1286 | return EFI_INVALID_PARAMETER;\r |
| 1287 | }\r |
| 1288 | \r |
| 1289 | return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, TRUE);\r |
| 1290 | }\r |
| 1291 | \r |
| 1292 | /**\r |
| 1293 | Cancels a previously set callback function for a particular PCD token number.\r |
| 1294 | \r |
| 1295 | @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r |
| 1296 | @param[in] ExTokenNumber The PCD token number.\r |
| 1297 | @param[in] CallBackFunction The function prototype called when the value associated with the CallBackToken is set.\r |
| 1298 | \r |
| 1299 | @retval EFI_SUCCESS The PCD service has successfully established a call event\r |
| 1300 | for the CallBackToken requested.\r |
| 1301 | @retval EFI_NOT_FOUND The PCD service could not find the referenced token number.\r |
| 1302 | \r |
| 1303 | **/\r |
| 1304 | EFI_STATUS\r |
| 1305 | EFIAPI\r |
| 1306 | PcdUnRegisterCallBackOnSet (\r |
| 1307 | IN CONST EFI_GUID *Guid, OPTIONAL\r |
| 1308 | IN UINTN ExTokenNumber,\r |
| 1309 | IN PCD_PPI_CALLBACK CallBackFunction\r |
| 1310 | )\r |
| 1311 | {\r |
| 1312 | if (!FeaturePcdGet(PcdPeiFullPcdDatabaseEnable)) {\r |
| 1313 | return EFI_UNSUPPORTED;\r |
| 1314 | }\r |
| 1315 | \r |
| 1316 | if (CallBackFunction == NULL) {\r |
| 1317 | return EFI_INVALID_PARAMETER;\r |
| 1318 | }\r |
| 1319 | \r |
| 1320 | return PeiRegisterCallBackWorker (ExTokenNumber, Guid, CallBackFunction, FALSE);\r |
| 1321 | }\r |
| 1322 | \r |
| 1323 | /**\r |
| 1324 | Retrieves the next valid token number in a given namespace.\r |
| 1325 | \r |
| 1326 | This is useful since the PCD infrastructure contains a sparse list of token numbers,\r |
| 1327 | and one cannot a priori know what token numbers are valid in the database.\r |
| 1328 | \r |
| 1329 | If TokenNumber is 0 and Guid is not NULL, then the first token from the token space specified by Guid is returned.\r |
| 1330 | If TokenNumber is not 0 and Guid is not NULL, then the next token in the token space specified by Guid is returned.\r |
| 1331 | If TokenNumber is 0 and Guid is NULL, then the first token in the default token space is returned.\r |
| 1332 | If TokenNumber is not 0 and Guid is NULL, then the next token in the default token space is returned.\r |
| 1333 | The token numbers in the default token space may not be related to token numbers in token spaces that are named by Guid.\r |
| 1334 | If the next token number can be retrieved, then it is returned in TokenNumber, and EFI_SUCCESS is returned.\r |
| 1335 | If TokenNumber represents the last token number in the token space specified by Guid, then EFI_NOT_FOUND is returned.\r |
| 1336 | If TokenNumber is not present in the token space specified by Guid, then EFI_NOT_FOUND is returned.\r |
| 1337 | \r |
| 1338 | \r |
| 1339 | @param[in] Guid The 128-bit unique value that designates the namespace from which to extract the value.\r |
| 1340 | This is an optional parameter that may be NULL. If this parameter is NULL, then a request\r |
| 1341 | is being made to retrieve tokens from the default token space.\r |
| 1342 | @param[in, out] TokenNumber A pointer to the PCD token number to use to find the subsequent token number.\r |
| 1343 | \r |
| 1344 | @retval EFI_SUCCESS The PCD service has retrieved the next valid token number.\r |
| 1345 | @retval EFI_NOT_FOUND The PCD service could not find data from the requested token number.\r |
| 1346 | \r |
| 1347 | **/\r |
| 1348 | EFI_STATUS\r |
| 1349 | EFIAPI\r |
| 1350 | PeiPcdGetNextToken (\r |
| 1351 | IN CONST EFI_GUID *Guid, OPTIONAL\r |
| 1352 | IN OUT UINTN *TokenNumber\r |
| 1353 | )\r |
| 1354 | {\r |
| 1355 | UINTN GuidTableIdx;\r |
| 1356 | PEI_PCD_DATABASE *PeiPcdDb;\r |
| 1357 | EFI_GUID *MatchGuid;\r |
| 1358 | EFI_GUID *GuidTable;\r |
| 1359 | DYNAMICEX_MAPPING *ExMapTable;\r |
| 1360 | UINTN Index;\r |
| 1361 | BOOLEAN Found;\r |
| 1362 | BOOLEAN PeiExMapTableEmpty;\r |
| 1363 | UINTN PeiNexTokenNumber;\r |
| 1364 | \r |
| 1365 | if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) {\r |
| 1366 | return EFI_UNSUPPORTED;\r |
| 1367 | }\r |
| 1368 | \r |
| 1369 | PeiPcdDb = GetPcdDatabase ();\r |
| 1370 | PeiNexTokenNumber = PeiPcdDb->LocalTokenCount - PeiPcdDb->ExTokenCount;\r |
| 1371 | GuidTable = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset);\r |
| 1372 | \r |
| 1373 | if (PeiPcdDb->ExTokenCount == 0) {\r |
| 1374 | PeiExMapTableEmpty = TRUE;\r |
| 1375 | } else {\r |
| 1376 | PeiExMapTableEmpty = FALSE;\r |
| 1377 | }\r |
| 1378 | if (Guid == NULL) {\r |
| 1379 | if (*TokenNumber > PeiNexTokenNumber) {\r |
| 1380 | return EFI_NOT_FOUND;\r |
| 1381 | }\r |
| 1382 | (*TokenNumber)++;\r |
| 1383 | if (*TokenNumber > PeiNexTokenNumber) {\r |
| 1384 | *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r |
| 1385 | return EFI_NOT_FOUND;\r |
| 1386 | }\r |
| 1387 | return EFI_SUCCESS;\r |
| 1388 | } else {\r |
| 1389 | if (PeiExMapTableEmpty) {\r |
| 1390 | return EFI_NOT_FOUND;\r |
| 1391 | }\r |
| 1392 | \r |
| 1393 | MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(EFI_GUID), Guid);\r |
| 1394 | \r |
| 1395 | if (MatchGuid == NULL) {\r |
| 1396 | return EFI_NOT_FOUND;\r |
| 1397 | }\r |
| 1398 | \r |
| 1399 | GuidTableIdx = MatchGuid - GuidTable;\r |
| 1400 | \r |
| 1401 | ExMapTable = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset);\r |
| 1402 | \r |
| 1403 | Found = FALSE;\r |
| 1404 | //\r |
| 1405 | // Locate the GUID in ExMapTable first.\r |
| 1406 | //\r |
| 1407 | for (Index = 0; Index < PeiPcdDb->ExTokenCount; Index++) {\r |
| 1408 | if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {\r |
| 1409 | Found = TRUE;\r |
| 1410 | break;\r |
| 1411 | }\r |
| 1412 | }\r |
| 1413 | \r |
| 1414 | if (Found) {\r |
| 1415 | //\r |
| 1416 | // If given token number is PCD_INVALID_TOKEN_NUMBER, then return the first\r |
| 1417 | // token number in found token space.\r |
| 1418 | //\r |
| 1419 | if (*TokenNumber == PCD_INVALID_TOKEN_NUMBER) {\r |
| 1420 | *TokenNumber = ExMapTable[Index].ExTokenNumber;\r |
| 1421 | return EFI_SUCCESS;\r |
| 1422 | }\r |
| 1423 | \r |
| 1424 | for ( ; Index < PeiPcdDb->ExTokenCount; Index++) {\r |
| 1425 | if ((ExMapTable[Index].ExTokenNumber == *TokenNumber) && (ExMapTable[Index].ExGuidIndex == GuidTableIdx)) {\r |
| 1426 | break;\r |
| 1427 | }\r |
| 1428 | }\r |
| 1429 | \r |
| 1430 | while (Index < PeiPcdDb->ExTokenCount) {\r |
| 1431 | Index++;\r |
| 1432 | if (Index == PeiPcdDb->ExTokenCount) {\r |
| 1433 | //\r |
| 1434 | // Exceed the length of ExMap Table\r |
| 1435 | //\r |
| 1436 | *TokenNumber = PCD_INVALID_TOKEN_NUMBER;\r |
| 1437 | return EFI_NOT_FOUND;\r |
| 1438 | } else if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {\r |
| 1439 | //\r |
| 1440 | // Found the next match\r |
| 1441 | //\r |
| 1442 | *TokenNumber = ExMapTable[Index].ExTokenNumber;\r |
| 1443 | return EFI_SUCCESS;\r |
| 1444 | }\r |
| 1445 | }\r |
| 1446 | }\r |
| 1447 | }\r |
| 1448 | \r |
| 1449 | return EFI_NOT_FOUND;\r |
| 1450 | }\r |
| 1451 | \r |
| 1452 | /**\r |
| 1453 | Retrieves the next valid PCD token namespace for a given namespace.\r |
| 1454 | \r |
| 1455 | Gets the next valid token namespace for a given namespace. This is useful to traverse the valid\r |
| 1456 | token namespaces on a platform.\r |
| 1457 | \r |
| 1458 | @param[in, out] Guid An indirect pointer to EFI_GUID. On input it designates a known token\r |
| 1459 | namespace from which the search will start. On output, it designates the next valid\r |
| 1460 | token namespace on the platform. If *Guid is NULL, then the GUID of the first token\r |
| 1461 | space of the current platform is returned. If the search cannot locate the next valid\r |
| 1462 | token namespace, an error is returned and the value of *Guid is undefined.\r |
| 1463 | \r |
| 1464 | @retval EFI_SUCCESS The PCD service retrieved the value requested.\r |
| 1465 | @retval EFI_NOT_FOUND The PCD service could not find the next valid token namespace.\r |
| 1466 | \r |
| 1467 | **/\r |
| 1468 | EFI_STATUS\r |
| 1469 | EFIAPI\r |
| 1470 | PeiPcdGetNextTokenSpace (\r |
| 1471 | IN OUT CONST EFI_GUID **Guid\r |
| 1472 | )\r |
| 1473 | {\r |
| 1474 | UINTN GuidTableIdx;\r |
| 1475 | EFI_GUID *MatchGuid;\r |
| 1476 | PEI_PCD_DATABASE *PeiPcdDb;\r |
| 1477 | DYNAMICEX_MAPPING *ExMapTable;\r |
| 1478 | UINTN Index;\r |
| 1479 | UINTN Index2;\r |
| 1480 | BOOLEAN Found;\r |
| 1481 | BOOLEAN PeiExMapTableEmpty;\r |
| 1482 | EFI_GUID *GuidTable;\r |
| 1483 | \r |
| 1484 | if (!FeaturePcdGet (PcdPeiFullPcdDatabaseEnable)) {\r |
| 1485 | return EFI_UNSUPPORTED;\r |
| 1486 | }\r |
| 1487 | \r |
| 1488 | ASSERT (Guid != NULL);\r |
| 1489 | \r |
| 1490 | PeiPcdDb = GetPcdDatabase ();\r |
| 1491 | \r |
| 1492 | if (PeiPcdDb->ExTokenCount == 0) {\r |
| 1493 | PeiExMapTableEmpty = TRUE;\r |
| 1494 | } else {\r |
| 1495 | PeiExMapTableEmpty = FALSE;\r |
| 1496 | }\r |
| 1497 | \r |
| 1498 | if (PeiExMapTableEmpty) {\r |
| 1499 | return EFI_NOT_FOUND;\r |
| 1500 | }\r |
| 1501 | \r |
| 1502 | ExMapTable = (DYNAMICEX_MAPPING *)((UINT8 *)PeiPcdDb + PeiPcdDb->ExMapTableOffset);\r |
| 1503 | GuidTable = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset);\r |
| 1504 | \r |
| 1505 | if (*Guid == NULL) {\r |
| 1506 | //\r |
| 1507 | // return the first Token Space Guid.\r |
| 1508 | //\r |
| 1509 | *Guid = GuidTable + ExMapTable[0].ExGuidIndex;\r |
| 1510 | return EFI_SUCCESS;\r |
| 1511 | }\r |
| 1512 | \r |
| 1513 | MatchGuid = ScanGuid (GuidTable, PeiPcdDb->GuidTableCount * sizeof(GuidTable[0]), *Guid);\r |
| 1514 | \r |
| 1515 | if (MatchGuid == NULL) {\r |
| 1516 | return EFI_NOT_FOUND;\r |
| 1517 | }\r |
| 1518 | \r |
| 1519 | GuidTableIdx = MatchGuid - GuidTable;\r |
| 1520 | \r |
| 1521 | Found = FALSE;\r |
| 1522 | for (Index = 0; Index < PeiPcdDb->ExTokenCount; Index++) {\r |
| 1523 | if (ExMapTable[Index].ExGuidIndex == GuidTableIdx) {\r |
| 1524 | Found = TRUE;\r |
| 1525 | break;\r |
| 1526 | }\r |
| 1527 | }\r |
| 1528 | \r |
| 1529 | if (Found) {\r |
| 1530 | Index++;\r |
| 1531 | for ( ; Index < PeiPcdDb->ExTokenCount; Index++ ) {\r |
| 1532 | if (ExMapTable[Index].ExGuidIndex != GuidTableIdx) {\r |
| 1533 | Found = FALSE;\r |
| 1534 | for (Index2 = 0 ; Index2 < Index; Index2++) {\r |
| 1535 | if (ExMapTable[Index2].ExGuidIndex == ExMapTable[Index].ExGuidIndex) {\r |
| 1536 | //\r |
| 1537 | // This token namespace should have been found and output at preceding getting.\r |
| 1538 | //\r |
| 1539 | Found = TRUE;\r |
| 1540 | break;\r |
| 1541 | }\r |
| 1542 | }\r |
| 1543 | if (!Found) {\r |
| 1544 | *Guid = (EFI_GUID *)((UINT8 *)PeiPcdDb + PeiPcdDb->GuidTableOffset) + ExMapTable[Index].ExGuidIndex;\r |
| 1545 | return EFI_SUCCESS;\r |
| 1546 | }\r |
| 1547 | }\r |
| 1548 | }\r |
| 1549 | *Guid = NULL;\r |
| 1550 | }\r |
| 1551 | \r |
| 1552 | return EFI_NOT_FOUND;\r |
| 1553 | \r |
| 1554 | }\r |
| 1555 | \r |
| 1556 | /**\r |
| 1557 | Get PCD value's size for POINTER type PCD.\r |
| 1558 | \r |
| 1559 | The POINTER type PCD's value will be stored into a buffer in specified size.\r |
| 1560 | The max size of this PCD's value is described in PCD's definition in DEC file.\r |
| 1561 | \r |
| 1562 | @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table\r |
| 1563 | @param MaxSize Maximum size of PCD's value\r |
| 1564 | @param Database Pcd database in PEI phase.\r |
| 1565 | \r |
| 1566 | @return PCD value's size for POINTER type PCD.\r |
| 1567 | \r |
| 1568 | **/\r |
| 1569 | UINTN\r |
| 1570 | GetPtrTypeSize (\r |
| 1571 | IN UINTN LocalTokenNumberTableIdx,\r |
| 1572 | OUT UINTN *MaxSize,\r |
| 1573 | IN PEI_PCD_DATABASE *Database\r |
| 1574 | )\r |
| 1575 | {\r |
| 1576 | INTN SizeTableIdx;\r |
| 1577 | UINTN LocalTokenNumber;\r |
| 1578 | SIZE_INFO *SizeTable;\r |
| 1579 | \r |
| 1580 | SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);\r |
| 1581 | \r |
| 1582 | LocalTokenNumber = *((UINT32 *)((UINT8 *)Database + Database->LocalTokenNumberTableOffset) + LocalTokenNumberTableIdx);\r |
| 1583 | \r |
| 1584 | ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);\r |
| 1585 | \r |
| 1586 | SizeTable = (SIZE_INFO *)((UINT8 *)Database + Database->SizeTableOffset);\r |
| 1587 | \r |
| 1588 | *MaxSize = SizeTable[SizeTableIdx];\r |
| 1589 | //\r |
| 1590 | // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type\r |
| 1591 | // PCD entry.\r |
| 1592 | //\r |
| 1593 | if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {\r |
| 1594 | //\r |
| 1595 | // We have only two entry for VPD enabled PCD entry:\r |
| 1596 | // 1) MAX Size.\r |
| 1597 | // 2) Current Size\r |
| 1598 | // We consider current size is equal to MAX size.\r |
| 1599 | //\r |
| 1600 | return *MaxSize;\r |
| 1601 | } else {\r |
| 1602 | //\r |
| 1603 | // We have only two entry for Non-Sku enabled PCD entry:\r |
| 1604 | // 1) MAX SIZE\r |
| 1605 | // 2) Current Size\r |
| 1606 | //\r |
| 1607 | return SizeTable[SizeTableIdx + 1];\r |
| 1608 | }\r |
| 1609 | }\r |
| 1610 | \r |
| 1611 | /**\r |
| 1612 | Set PCD value's size for POINTER type PCD.\r |
| 1613 | \r |
| 1614 | The POINTER type PCD's value will be stored into a buffer in specified size.\r |
| 1615 | The max size of this PCD's value is described in PCD's definition in DEC file.\r |
| 1616 | \r |
| 1617 | @param LocalTokenNumberTableIdx Index of PCD token number in PCD token table\r |
| 1618 | @param CurrentSize Maximum size of PCD's value\r |
| 1619 | @param Database Pcd database in PEI phase.\r |
| 1620 | \r |
| 1621 | @retval TRUE Success to set PCD's value size, which is not exceed maximum size\r |
| 1622 | @retval FALSE Fail to set PCD's value size, which maybe exceed maximum size\r |
| 1623 | \r |
| 1624 | **/\r |
| 1625 | BOOLEAN\r |
| 1626 | SetPtrTypeSize (\r |
| 1627 | IN UINTN LocalTokenNumberTableIdx,\r |
| 1628 | IN OUT UINTN *CurrentSize,\r |
| 1629 | IN PEI_PCD_DATABASE *Database\r |
| 1630 | )\r |
| 1631 | {\r |
| 1632 | INTN SizeTableIdx;\r |
| 1633 | UINTN LocalTokenNumber;\r |
| 1634 | SIZE_INFO *SizeTable;\r |
| 1635 | UINTN MaxSize;\r |
| 1636 | \r |
| 1637 | SizeTableIdx = GetSizeTableIndex (LocalTokenNumberTableIdx, Database);\r |
| 1638 | \r |
| 1639 | LocalTokenNumber = *((UINT32 *)((UINT8 *)Database + Database->LocalTokenNumberTableOffset) + LocalTokenNumberTableIdx);\r |
| 1640 | \r |
| 1641 | ASSERT ((LocalTokenNumber & PCD_DATUM_TYPE_ALL_SET) == PCD_DATUM_TYPE_POINTER);\r |
| 1642 | \r |
| 1643 | SizeTable = (SIZE_INFO *)((UINT8 *)Database + Database->SizeTableOffset);\r |
| 1644 | \r |
| 1645 | MaxSize = SizeTable[SizeTableIdx];\r |
| 1646 | //\r |
| 1647 | // SizeTable only contain record for PCD_DATUM_TYPE_POINTER type\r |
| 1648 | // PCD entry.\r |
| 1649 | //\r |
| 1650 | if ((LocalTokenNumber & PCD_TYPE_VPD) != 0) {\r |
| 1651 | //\r |
| 1652 | // We shouldn't come here as we don't support SET for VPD\r |
| 1653 | //\r |
| 1654 | ASSERT (FALSE);\r |
| 1655 | return FALSE;\r |
| 1656 | } else {\r |
| 1657 | if ((*CurrentSize > MaxSize) ||\r |
| 1658 | (*CurrentSize == MAX_ADDRESS)) {\r |
| 1659 | *CurrentSize = MaxSize;\r |
| 1660 | return FALSE;\r |
| 1661 | }\r |
| 1662 | \r |
| 1663 | //\r |
| 1664 | // We have only two entry for Non-Sku enabled PCD entry:\r |
| 1665 | // 1) MAX SIZE\r |
| 1666 | // 2) Current Size\r |
| 1667 | //\r |
| 1668 | SizeTable[SizeTableIdx + 1] = (SIZE_INFO) *CurrentSize;\r |
| 1669 | return TRUE;\r |
| 1670 | }\r |
| 1671 | \r |
| 1672 | }\r |