]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/PCD/Dxe/Pcd.c
MdeModulePkg PCD: Update PCD database structure definition to match BaseTools
[mirror_edk2.git] / MdeModulePkg / Universal / PCD / Dxe / Pcd.c
index 04fcd64306c32c6e8818821b36c15606e5d5efbc..1bb9098c04cf2fe118e4006a39ddc1889ded10ea 100644 (file)
@@ -1,9 +1,9 @@
 /** @file\r
   PCD DXE driver manage all PCD entry initialized in PEI phase and DXE phase, and\r
   produce the implementation of native PCD protocol and EFI_PCD_PROTOCOL defined in\r
-  PI 1.2 Vol3.\r
+  PI 1.4a Vol3.\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
@@ -89,6 +89,25 @@ EFI_PCD_PROTOCOL mEfiPcdInstance = {
   DxePcdGetNextTokenSpace\r
 };\r
 \r
+///\r
+/// Instance of GET_PCD_INFO_PROTOCOL protocol is EDKII native implementation.\r
+/// This protocol instance support dynamic and dynamicEx type PCDs.\r
+///\r
+GET_PCD_INFO_PROTOCOL mGetPcdInfoInstance = {\r
+  DxeGetPcdInfoGetInfo,\r
+  DxeGetPcdInfoGetInfoEx,\r
+  DxeGetPcdInfoGetSku\r
+};\r
+\r
+///\r
+/// Instance of EFI_GET_PCD_INFO_PROTOCOL 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_PROTOCOL  mEfiGetPcdInfoInstance = {\r
+  DxeGetPcdInfoGetInfoEx,\r
+  DxeGetPcdInfoGetSku\r
+};\r
+\r
 EFI_HANDLE mPcdHandle = NULL;\r
 \r
 /**\r
@@ -110,7 +129,8 @@ PcdDxeInit (
   )\r
 {\r
   EFI_STATUS Status;\r
-  \r
+  VOID       *Registration;\r
+\r
   //\r
   // Make sure the Pcd Protocol is not already installed in the system\r
   //\r
@@ -129,11 +149,97 @@ PcdDxeInit (
                   &gEfiPcdProtocolGuid,  &mEfiPcdInstance,\r
                   NULL\r
                   );\r
-                 \r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // Install GET_PCD_INFO_PROTOCOL to handle dynamic type PCD\r
+  // Install EFI_GET_PCD_INFO_PROTOCOL to handle dynamicEx type PCD\r
+  //\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &mPcdHandle,\r
+                  &gGetPcdInfoProtocolGuid,     &mGetPcdInfoInstance,\r
+                  &gEfiGetPcdInfoProtocolGuid,  &mEfiGetPcdInfoInstance,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Register callback function upon VariableLockProtocol\r
+  // to lock the variables referenced by DynamicHii PCDs with RO property set in *.dsc.\r
+  //\r
+  EfiCreateProtocolNotifyEvent (\r
+    &gEdkiiVariableLockProtocolGuid,\r
+    TPL_CALLBACK,\r
+    VariableLockCallBack,\r
+    NULL,\r
+    &Registration\r
+    );\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
+DxeGetPcdInfoGetInfo (\r
+  IN        UINTN           TokenNumber,\r
+  OUT       EFI_PCD_INFO    *PcdInfo\r
+  )\r
+{\r
+  return DxeGetPcdInfo (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
+DxeGetPcdInfoGetInfoEx (\r
+  IN CONST  EFI_GUID        *Guid,\r
+  IN        UINTN           TokenNumber,\r
+  OUT       EFI_PCD_INFO    *PcdInfo\r
+  )\r
+{\r
+  return DxeGetPcdInfo (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
+DxeGetPcdInfoGetSku (\r
+  VOID\r
+  )\r
+{\r
+  return (UINTN) mPcdDatabase.DxeDb->SystemSkuId;\r
 }\r
 \r
 /**\r
@@ -146,7 +252,7 @@ PcdDxeInit (
   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
@@ -163,8 +269,22 @@ DxePcdSetSku (
   IN  UINTN         SkuId\r
   )\r
 {\r
-  mPcdDatabase.PeiDb->SystemSkuId = (SKU_ID) SkuId;\r
-  \r
+  SKU_ID    *SkuIdTable;\r
+  UINTN     Index;\r
+\r
+  SkuIdTable = (SKU_ID *) ((UINT8 *) mPcdDatabase.DxeDb + mPcdDatabase.DxeDb->SkuIdTableOffset);\r
+  for (Index = 0; Index < SkuIdTable[0]; Index++) {\r
+    if (SkuId == SkuIdTable[Index + 1]) {\r
+      mPcdDatabase.DxeDb->SystemSkuId = (SKU_ID) SkuId;\r
+      return;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Invalid input SkuId, the default SKU Id will be used for the system.\r
+  //\r
+  DEBUG ((EFI_D_INFO, "PcdDxe - Invalid input SkuId, the default SKU Id will be used.\n"));\r
+  mPcdDatabase.DxeDb->SystemSkuId = (SKU_ID) 0;\r
   return;\r
 }\r
 \r