]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/PCD/Pei/Pcd.c
MdeModulePkg PCD: Update PCD database structure definition to match BaseTools
[mirror_edk2.git] / MdeModulePkg / Universal / PCD / Pei / Pcd.c
index 557b915a1234e9c881297db174d7bc9570572fda..7a486b7d1d0503be801f5b948b158e210e6f0735 100644 (file)
@@ -1,7 +1,7 @@
 /** @file \r
   All Pcd Ppi services are implemented here.\r
   \r
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -83,6 +83,25 @@ EFI_PEI_PCD_PPI  mEfiPcdPpiInstance = {
   PeiPcdGetNextTokenSpace\r
 };\r
 \r
+///\r
+/// Instance of GET_PCD_INFO_PPI protocol is EDKII native implementation.\r
+/// This protocol instance support dynamic and dynamicEx type PCDs.\r
+///\r
+GET_PCD_INFO_PPI mGetPcdInfoInstance = {\r
+  PeiGetPcdInfoGetInfo,\r
+  PeiGetPcdInfoGetInfoEx,\r
+  PeiGetPcdInfoGetSku\r
+};\r
+\r
+///\r
+/// Instance of EFI_GET_PCD_INFO_PPI which is defined in PI 1.2.1 Vol 3.\r
+/// This PPI instance only support dyanmicEx type PCD.\r
+///\r
+EFI_GET_PCD_INFO_PPI  mEfiGetPcdInfoInstance = {\r
+  PeiGetPcdInfoGetInfoEx,\r
+  PeiGetPcdInfoGetSku\r
+};\r
+\r
 EFI_PEI_PPI_DESCRIPTOR  mPpiList[] = {\r
   {\r
     EFI_PEI_PPI_DESCRIPTOR_PPI,\r
@@ -96,6 +115,19 @@ EFI_PEI_PPI_DESCRIPTOR  mPpiList[] = {
   }\r
 };\r
 \r
+EFI_PEI_PPI_DESCRIPTOR  mPpiList2[] = {\r
+  {\r
+    EFI_PEI_PPI_DESCRIPTOR_PPI,\r
+    &gGetPcdInfoPpiGuid,\r
+    &mGetPcdInfoInstance\r
+  },\r
+  {\r
+    (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+    &gEfiGetPcdInfoPpiGuid,\r
+    &mEfiGetPcdInfoInstance\r
+  }\r
+};\r
+\r
 /**\r
   Main entry for PCD PEIM driver.\r
   \r
@@ -115,7 +147,7 @@ PcdPeimInit (
   )\r
 {\r
   EFI_STATUS Status;\r
-  \r
+\r
   BuildPcdDatabase (FileHandle);\r
 \r
   //\r
@@ -123,10 +155,80 @@ PcdPeimInit (
   //\r
   Status = PeiServicesInstallPpi (&mPpiList[0]);\r
   ASSERT_EFI_ERROR (Status);\r
-  \r
+\r
+  //\r
+  // Install GET_PCD_INFO_PPI and EFI_GET_PCD_INFO_PPI.\r
+  //\r
+  Status = PeiServicesInstallPpi (&mPpiList2[0]);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   return Status;\r
 }\r
 \r
+/**\r
+  Retrieve additional information associated with a PCD token in the default token space.\r
+\r
+  This includes information such as the type of value the TokenNumber is associated with as well as possible\r
+  human readable name that is associated with the token.\r
+\r
+  @param[in]    TokenNumber The PCD token number.\r
+  @param[out]   PcdInfo     The returned information associated with the requested TokenNumber.\r
+                            The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r
+\r
+  @retval  EFI_SUCCESS      The PCD information was returned successfully.\r
+  @retval  EFI_NOT_FOUND    The PCD service could not find the requested token number.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiGetPcdInfoGetInfo (\r
+  IN        UINTN           TokenNumber,\r
+  OUT       EFI_PCD_INFO    *PcdInfo\r
+  )\r
+{\r
+  return PeiGetPcdInfo (NULL, TokenNumber, PcdInfo);\r
+}\r
+\r
+/**\r
+  Retrieve additional information associated with a PCD token.\r
+\r
+  This includes information such as the type of value the TokenNumber is associated with as well as possible\r
+  human readable name that is associated with the token.\r
+\r
+  @param[in]    Guid        The 128-bit unique value that designates the namespace from which to extract the value.\r
+  @param[in]    TokenNumber The PCD token number.\r
+  @param[out]   PcdInfo     The returned information associated with the requested TokenNumber.\r
+                            The caller is responsible for freeing the buffer that is allocated by callee for PcdInfo->PcdName.\r
+\r
+  @retval  EFI_SUCCESS      The PCD information was returned successfully.\r
+  @retval  EFI_NOT_FOUND    The PCD service could not find the requested token number.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiGetPcdInfoGetInfoEx (\r
+  IN CONST  EFI_GUID        *Guid,\r
+  IN        UINTN           TokenNumber,\r
+  OUT       EFI_PCD_INFO    *PcdInfo\r
+  )\r
+{\r
+  return PeiGetPcdInfo (Guid, TokenNumber, PcdInfo);\r
+}\r
+\r
+/**\r
+  Retrieve the currently set SKU Id.\r
+\r
+  @return   The currently set SKU Id. If the platform has not set at a SKU Id, then the\r
+            default SKU Id value of 0 is returned. If the platform has set a SKU Id, then the currently set SKU\r
+            Id is returned.\r
+**/\r
+UINTN\r
+EFIAPI\r
+PeiGetPcdInfoGetSku (\r
+  VOID\r
+  )\r
+{\r
+  return (UINTN) GetPcdDatabase()->SystemSkuId;\r
+}\r
+\r
 /**\r
   Sets the SKU value for subsequent calls to set or get PCD token values.\r
 \r
@@ -137,7 +239,7 @@ PcdPeimInit (
   or multiple values, where each value is associated with a specific SKU Id. Items with multiple, \r
   SKU-specific values are called SKU enabled. \r
   \r
-  The SKU Id of zero is reserved as a default. The valid SkuId range is 1 to 255.  \r
+  The SKU Id of zero is reserved as a default.\r
   For tokens that are not SKU enabled, the system ignores any set SKU Id and works with the \r
   single value for that token. For SKU-enabled tokens, the system will use the SKU Id set by the \r
   last call to SetSku(). If no SKU Id is set or the currently set SKU Id isn't valid for the specified token, \r
@@ -154,9 +256,24 @@ PeiPcdSetSku (
   IN  UINTN                  SkuId\r
   )\r
 {\r
+  PEI_PCD_DATABASE  *PeiPcdDb;\r
+  SKU_ID            *SkuIdTable;\r
+  UINTN             Index;\r
+\r
+  PeiPcdDb = GetPcdDatabase();\r
+  SkuIdTable = (SKU_ID *) ((UINT8 *) PeiPcdDb + PeiPcdDb->SkuIdTableOffset);\r
+  for (Index = 0; Index < SkuIdTable[0]; Index++) {\r
+    if (SkuId == SkuIdTable[Index + 1]) {\r
+      PeiPcdDb->SystemSkuId = (SKU_ID) SkuId;\r
+      return;\r
+    }\r
+  }\r
 \r
-  GetPcdDatabase()->SystemSkuId = (SKU_ID) SkuId;\r
-\r
+  //\r
+  // Invalid input SkuId, the default SKU Id will be used for the system.\r
+  //\r
+  DEBUG ((EFI_D_INFO, "PcdPei - Invalid input SkuId, the default SKU Id will be used.\n"));\r
+  PeiPcdDb->SystemSkuId = (SKU_ID) 0;\r
   return;\r
 }\r
 \r