Bladeren bron

WhitleyOpenBoardPkg: Add UbaPlatLib Library

UbaPlatLib is required by AcpiTablesLib used by AcpiPlatform driver.

Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Signed-off-by: Isaac Oram <isaac.w.oram@intel.com>
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
Isaac Oram 2 jaren geleden
bovenliggende
commit
2088856726

+ 388 - 0
Platform/Intel/WhitleyOpenBoardPkg/Library/UbaPlatLib/DxeUbaGpioPlatformConfigLib.c

@@ -0,0 +1,388 @@
+/** @file
+
+  @copyright
+  Copyright 2012 - 2017 Intel Corporation. <BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Base.h>
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DebugLib.h>
+#include <Protocol/UbaCfgDb.h>
+#include <Library/SmmServicesTableLib.h>
+#include <Protocol/SmmBase2.h>
+#include <Protocol/DynamicSiLibraryProtocol.h>
+
+//
+// UBA and GPIO headers
+//
+
+#include <Library/UbaGpioPlatformConfig.h>
+#include <Library/GpioLib.h>
+
+STATIC PLATFORM_GPIO_CONFIG_TABLE             mGpioParams;
+DYNAMIC_SI_LIBARY_PROTOCOL                    *mDynamicSiLibraryProtocol = NULL;
+
+/**
+  The library constructor call. Gets required protocols and stores for later usage
+  This also applies for SMM mode usage
+
+  @param[in]  None
+
+  @retval EFI_SUCCESS             The function completed successfully
+
+**/
+EFI_STATUS
+EFIAPI
+InitializeDxeUbaPlatLib (
+  IN  EFI_HANDLE        ImageHandle,
+  IN  EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  EFI_STATUS                            Status;
+  UBA_CONFIG_DATABASE_PROTOCOL          *UbaConfigProtocol = NULL;
+  UINTN                                 TableSize;
+
+  Status = gBS->LocateProtocol (&gDynamicSiLibraryProtocolGuid, NULL, &mDynamicSiLibraryProtocol);
+  if (EFI_ERROR (Status)) {
+    ASSERT_EFI_ERROR (Status);
+    return EFI_NOT_FOUND;
+  }
+
+    Status = gBS->LocateProtocol (
+                    &gUbaConfigDatabaseProtocolGuid,
+                    NULL,
+                    &UbaConfigProtocol
+                    );
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+
+  TableSize = sizeof (PLATFORM_GPIO_CONFIG_TABLE);
+  Status = UbaConfigProtocol->GetData (
+                                UbaConfigProtocol,
+                                &gPlatformGpioPlatformConfigDataGuid,
+                                &mGpioParams,
+                                &TableSize
+                                );
+
+  return Status;
+
+}
+
+/**
+  Reads GPIO pin to get DFX jumper status
+
+  @param[out] DfxJumper - The pointer to the DFX jumper input
+
+  @retval Status - Success if GPIO's are read properly
+
+**/
+EFI_STATUS
+GpioGetDfxPadVal (
+  OUT UINT32 *DfxJumper
+  )
+{
+  EFI_STATUS           Status;
+
+  if (mGpioParams.ReservedM == UNUSED_GPIO) {
+    return EFI_UNSUPPORTED;
+  }
+
+  Status = mDynamicSiLibraryProtocol->GpioGetInputValue (mGpioParams.ReservedM, DfxJumper);
+  return Status;
+}
+
+/**
+  Reads GPIO pin to get recovery jumper status
+
+  @param[out] RcvJumper - The pointer to the Recovery jumper input
+
+  @retval Status - Success if GPIO's are read properly
+
+**/
+EFI_STATUS
+GpioGetRcvPadVal (
+  OUT UINT32 *RcvJumper
+  )
+{
+  EFI_STATUS           Status;
+
+  if (mGpioParams.RcvJumper == UNUSED_GPIO) {
+    return EFI_UNSUPPORTED;
+  }
+
+  Status = mDynamicSiLibraryProtocol->GpioGetInputValue (mGpioParams.RcvJumper, RcvJumper);
+  return Status;
+}
+
+/**
+  Reads GPIO pin to get FM ADR trigger pin
+
+  @param[out] FmAdrTrigger - The pointer to the ADR trigger input
+
+  @retval Status - Success if GPIO's are read properly
+
+**/
+EFI_STATUS
+GpioGetFmAdrTriggerPadVal (
+  OUT UINT32 *FmAdrTrigger
+  )
+{
+  EFI_STATUS           Status;
+
+  if (mGpioParams.FmAdrTrigger == UNUSED_GPIO) {
+    return EFI_UNSUPPORTED;
+  }
+
+  Status = mDynamicSiLibraryProtocol->GpioGetInputValue (mGpioParams.FmAdrTrigger, FmAdrTrigger);
+  return Status;
+}
+
+/**
+  Sets GPIO pin to enable ADR on the board
+
+  @param Set[in] - If TRUE means the pas should go 'high', otherwise 'low'
+
+  @retval Status - Success if GPIO set properly
+
+**/
+EFI_STATUS
+GpioSetAdrEnablePadOutVal (
+  IN BOOLEAN Set
+  )
+{
+  EFI_STATUS           Status;
+
+  if (mGpioParams.AdrEnable == UNUSED_GPIO) {
+    return EFI_UNSUPPORTED;
+  }
+
+  if (Set) {
+    Status = mDynamicSiLibraryProtocol->GpioSetOutputValue (mGpioParams.AdrEnable, GpioOutHigh);
+  } else {
+    Status = mDynamicSiLibraryProtocol->GpioSetOutputValue (mGpioParams.AdrEnable, GpioOutLow);
+  }
+  return Status;
+}
+
+/**
+  Reads GPIO pin to Force to S1 config mode pad
+
+  @param[out] ForceS1ConfigPad - Input value of the Force S1 Config pad
+
+  @retval Status - Success if GPIO's are read properly
+
+**/
+EFI_STATUS
+GpioGetForcetoS1ConfigModePadVal (
+  OUT UINT32 *ForceS1ConfigPad
+  )
+{
+  EFI_STATUS           Status;
+
+  if (mGpioParams.ForceTo1SConfigModePad == UNUSED_GPIO) {
+    return EFI_UNSUPPORTED;
+  }
+
+  Status = mDynamicSiLibraryProtocol->GpioGetInputValue (mGpioParams.ForceTo1SConfigModePad, ForceS1ConfigPad);
+  return Status;
+}
+
+/**
+  Reads GPIO pin related to QAT
+
+  @param[out] QATPad - Input value of the QAT pad
+
+  @retval Status - Success if GPIO's are read properly
+
+**/
+EFI_STATUS
+GpioGetQATPadVal (
+  OUT UINT32 *QATPad
+  )
+{
+  EFI_STATUS           Status;
+
+  if (mGpioParams.QATGpio == UNUSED_GPIO) {
+    return EFI_UNSUPPORTED;
+  }
+
+  Status = mDynamicSiLibraryProtocol->GpioGetInputValue (mGpioParams.QATGpio, QATPad);
+  return Status;
+}
+
+/**
+  Get GPIO pin for SCI detection for WHEA RAS functionality
+
+  @param[out] WheaSciPad - Input value of the Whea SCI pad
+
+  @retval Status - Success if GPIO's pad read properly
+
+**/
+EFI_STATUS
+GpioGetWheaSciPad (
+  OUT UINT32 *WheaSciPad
+  )
+{
+  if (mGpioParams.WheaSciPad == UNUSED_GPIO) {
+    return EFI_UNSUPPORTED;
+  }
+
+  *WheaSciPad = (UINT32) mGpioParams.WheaSciPad;
+  return EFI_SUCCESS;
+}
+
+/**
+  Get GPIO pin for FPGA error detection RAS functionality
+
+  @param[out] FpgaErrorPad -The input value of the FPGA error 1 pad
+
+  @retval Status - Success if GPIO's pad read properly
+
+**/
+EFI_STATUS
+GpioGetFpgaErrorPad1 (
+  OUT UINT32 *FpgaErrorPad
+  )
+{
+  if (mGpioParams.FpgaErrorSingnalPad1 == UNUSED_GPIO) {
+    return EFI_UNSUPPORTED;
+  }
+
+  *FpgaErrorPad = (UINT32) mGpioParams.FpgaErrorSingnalPad1;
+  return EFI_SUCCESS;
+}
+
+/**
+  Get GPIO pin for FPGA error detection RAS functionality
+
+  @param[out] FpgaErrorPad -The input value of the FPGA error 2 pad
+
+  @retval Status - Success if GPIO's pad read properly
+
+**/
+EFI_STATUS
+GpioGetFpgaErrorPad2 (
+  OUT UINT32 *FpgaErrorPad
+  )
+{
+
+  if (mGpioParams.FpgaErrorSingnalPad2 == UNUSED_GPIO) {
+    return EFI_UNSUPPORTED;
+  }
+
+  *FpgaErrorPad = (UINT32) mGpioParams.FpgaErrorSingnalPad2;
+  return EFI_SUCCESS;
+}
+
+/**
+  Get GPIO pin for CPU HP SMI detection for RAS functionality
+
+  @retval Status - Success if GPIO's pad read properly
+
+**/
+EFI_STATUS
+GpioGetCpuHpSmiPad (
+  OUT UINT32 *CpuHpSmiPad
+  )
+{
+
+  if (mGpioParams.CpuHpSmiPad == UNUSED_GPIO) {
+    return EFI_UNSUPPORTED;
+  }
+
+  *CpuHpSmiPad = (UINT32) mGpioParams.CpuHpSmiPad;
+  return EFI_SUCCESS;
+}
+
+/**
+  Reads GPIO pin that is first bit of the Board ID indication word
+
+  @param[out] BoardID0Gpio - Input value of the first Board ID pad
+
+  @retval Status - Success if GPIO's are read properly
+
+**/
+EFI_STATUS
+GpioGetBoardId0PadVal (
+  OUT UINT32 *BoardID0Gpio
+  )
+{
+  EFI_STATUS           Status;
+
+  if (mGpioParams.BoardID0Gpio == UNUSED_GPIO) {
+    return EFI_UNSUPPORTED;
+  }
+
+  Status = mDynamicSiLibraryProtocol->GpioGetInputValue (mGpioParams.BoardID0Gpio, BoardID0Gpio);
+  return Status;
+}
+
+/**
+  Sets GPIO's used for Boot Mode
+
+  @param None
+
+  @retval Status - Success if GPIO's are configured
+
+**/
+EFI_STATUS
+GpioConfigForMFGMode (
+  VOID
+  )
+{
+  EFI_STATUS                  Status;
+
+  if (mGpioParams.GpioMfgPad.GpioPad == UNUSED_GPIO) {
+    return EFI_UNSUPPORTED;
+  }
+
+  DEBUG ((DEBUG_INFO, "Start ConfigureGpio() for BootMode Detection.\n"));
+
+  Status = mDynamicSiLibraryProtocol->GpioSetPadConfig (mGpioParams.GpioMfgPad.GpioPad,
+    &mGpioParams.GpioMfgPad.GpioConfig);
+  ASSERT_EFI_ERROR (Status);
+
+  DEBUG ((DEBUG_INFO, "End ConfigureGpio() for BootMode Detection.\n"));
+  return Status;
+}
+
+/**
+  Checks whether the MDF jumper has been set
+
+  @param None
+
+  @retval ManufacturingMode - TRUE when MFG jumper is on, FALSE otherwise
+
+**/
+BOOLEAN
+IsManufacturingMode (
+  VOID
+  )
+{
+  BOOLEAN ManufacturingMode = TRUE;
+
+  EFI_STATUS Status;
+  UINT32 GpiValue;
+
+  if (mGpioParams.GpioMfgPad.GpioPad == UNUSED_GPIO) {
+    return FALSE;
+  }
+
+  Status = GpioConfigForMFGMode ();
+  ASSERT_EFI_ERROR (Status);
+
+  Status = mDynamicSiLibraryProtocol->GpioGetInputValue (mGpioParams.GpioMfgPad.GpioPad, &GpiValue);
+  ASSERT_EFI_ERROR (Status);
+
+  if (!GpiValue) {
+    ManufacturingMode = FALSE;
+  }
+  return ManufacturingMode;
+}

+ 62 - 0
Platform/Intel/WhitleyOpenBoardPkg/Library/UbaPlatLib/DxeUbaSystemBoardInfoLib.c

@@ -0,0 +1,62 @@
+/** @file
+
+  @copyright
+  Copyright 2017 Intel Corporation. <BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Base.h>
+#include <Uefi.h>
+
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DebugLib.h>
+
+#include <Library/UbaSystemBoardInfoLib.h>
+#include <Protocol/UbaCfgDb.h>
+
+
+EFI_STATUS
+GetSystemBoardInfo (
+  IN OUT   DXE_SYSTEM_BOARD_INFO       **SystemboardInfoTableBuffer
+  )
+{
+  EFI_STATUS                        Status;
+  UBA_CONFIG_DATABASE_PROTOCOL      *UbaConfigProtocol = NULL;
+  UINTN                             DataLength = 0;
+  SYSTEM_BOARD_INFO_DATA            SystemBoardInfoData;
+
+  Status = gBS->LocateProtocol (
+                  &gUbaConfigDatabaseProtocolGuid,
+                  NULL,
+                  &UbaConfigProtocol
+                  );
+
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR," [GetSystemBoardInfo] Locate UbaConfigProtocol fail!\n"));
+    return Status;
+  }
+
+  DataLength = sizeof(SystemBoardInfoData);
+  Status = UbaConfigProtocol->GetData (
+                                   UbaConfigProtocol,
+                                   &gSystemBoardInfoConfigDataGuid,
+                                   &SystemBoardInfoData,
+                                   &DataLength
+                                   );
+
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR," [GetSystemBoardInfo] Get Data fail!\n"));
+    return Status;
+  }
+
+  ASSERT (SystemBoardInfoData.Signature == SYSTEM_SYSTEM_BOARD_INFO_SIGNATURE);
+  ASSERT (SystemBoardInfoData.Version   == SYSTEM_SYSTEM_BOARD_INFO_VERSION);
+
+  *SystemboardInfoTableBuffer = SystemBoardInfoData.CallUpdate ();
+
+  return Status;
+}

+ 60 - 0
Platform/Intel/WhitleyOpenBoardPkg/Library/UbaPlatLib/DxeUbaSystemConfigUpdateLib.c

@@ -0,0 +1,60 @@
+/** @file
+
+  @copyright
+  Copyright 2017 - 2018 Intel Corporation. <BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Base.h>
+#include <Uefi.h>
+
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DebugLib.h>
+
+#include <Library/UbaSystemConfigUpdateLib.h>
+#include <Protocol/UbaCfgDb.h>
+
+EFI_STATUS
+UpdateIioDefaultConfig (
+  IN  SYSTEM_CONFIGURATION       *Default
+  )
+{
+  EFI_STATUS                        Status;
+  UBA_CONFIG_DATABASE_PROTOCOL      *UbaConfigProtocol = NULL;
+  UINTN                             DataLength = 0;
+  SYSTEM_CONFIG_UPDATE_DATA         SystemConfigUpdateTable;
+
+  Status = gBS->LocateProtocol (
+                  &gUbaConfigDatabaseProtocolGuid,
+                  NULL,
+                  &UbaConfigProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR," [UpdateIioDefaultConfig] Locate UbaConfigProtocol fail!\n"));
+    return Status;
+  }
+
+  DataLength = sizeof(SystemConfigUpdateTable);
+  Status = UbaConfigProtocol->GetData (
+                                   UbaConfigProtocol,
+                                   &gSystemConfigUpdateDataGuid,
+                                   &SystemConfigUpdateTable,
+                                   &DataLength
+                                   );
+
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR," [UpdateIioDefaultConfig] Get Data fail!\n"));
+    return Status;
+  }
+
+  ASSERT (SystemConfigUpdateTable.Signature == SYSTEM_CONFIG_UPDATE_SIGNATURE);
+  ASSERT (SystemConfigUpdateTable.Version   == SYSTEM_CONFIG_UPDATE_VERSION);
+
+  SystemConfigUpdateTable.CallUpdateIioConfig (Default);
+
+  return Status;
+}

+ 61 - 0
Platform/Intel/WhitleyOpenBoardPkg/Library/UbaPlatLib/DxeUbaUsbOcUpdateLib.c

@@ -0,0 +1,61 @@
+/** @file
+
+  @copyright
+  Copyright 2012 - 2019 Intel Corporation. <BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Base.h>
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DebugLib.h>
+#include <Protocol/UbaCfgDb.h>
+#include <Library/UbaUsbOcUpdateLib.h>
+
+EFI_STATUS
+PlatformGetUsbOcMappings (
+  IN OUT   USB_OVERCURRENT_PIN   **Usb20OverCurrentMappings,
+  IN OUT   USB_OVERCURRENT_PIN   **Usb30OverCurrentMappings,
+  IN OUT   USB2_PHY_PARAMETERS   **Usb20AfeParams
+  )
+{
+  EFI_STATUS                            Status;
+  UBA_CONFIG_DATABASE_PROTOCOL          *UbaConfigProtocol = NULL;
+  PLATFORM_USBOC_UPDATE_TABLE           UsbOcUpdateTable;
+  UINTN                                 TableSize;
+
+  Status = gBS->LocateProtocol (
+                  &gUbaConfigDatabaseProtocolGuid,
+                  NULL,
+                  &UbaConfigProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  TableSize = sizeof(UsbOcUpdateTable);
+  Status = UbaConfigProtocol->GetData (
+                                UbaConfigProtocol,
+                                &gDxePlatformUbaOcConfigDataGuid,
+                                &UsbOcUpdateTable,
+                                &TableSize
+                                );
+
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  ASSERT (UsbOcUpdateTable.Signature == PLATFORM_USBOC_UPDATE_SIGNATURE);
+  ASSERT (UsbOcUpdateTable.Version == PLATFORM_USBOC_UPDATE_VERSION);
+
+  UsbOcUpdateTable.CallUsbOcUpdate ( Usb20OverCurrentMappings,
+                                     Usb30OverCurrentMappings,
+                                     Usb20AfeParams
+                                   );
+
+  return Status;
+}

+ 59 - 0
Platform/Intel/WhitleyOpenBoardPkg/Library/UbaPlatLib/UbaAcpiUpdateLib.c

@@ -0,0 +1,59 @@
+/** @file
+
+  @copyright
+  Copyright 2013 Intel Corporation. <BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Base.h>
+#include <Uefi.h>
+
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DebugLib.h>
+
+#include <Library/UbaAcpiUpdateLib.h>
+
+#include <Protocol/UbaCfgDb.h>
+
+EFI_STATUS
+PlatformGetAcpiFixTableDataPointer (
+  IN  VOID                               **TablePtr
+  )
+{
+  EFI_STATUS                              Status;
+
+  UBA_CONFIG_DATABASE_PROTOCOL            *UbaConfigProtocol = NULL;
+  UINTN                                   DataLength = 0;
+  ACPI_FIX_UPDATE_TABLE                   AcpiFixUpdateTable;
+
+  Status = gBS->LocateProtocol (
+                  &gUbaConfigDatabaseProtocolGuid,
+                  NULL,
+                  &UbaConfigProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  DataLength  = sizeof (AcpiFixUpdateTable);
+  Status = UbaConfigProtocol->GetData (
+                                    UbaConfigProtocol,
+                                    &gPlatformAcpiFixTableGuid,
+                                    &AcpiFixUpdateTable,
+                                    &DataLength
+                                    );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  ASSERT (AcpiFixUpdateTable.Signature == PLATFORM_ACPI_FIX_UPDATE_SIGNATURE);
+  ASSERT (AcpiFixUpdateTable.Version == PLATFORM_ACPI_FIX_UPDATE_VERSION);
+
+  *TablePtr = AcpiFixUpdateTable.TablePtr;
+
+  return EFI_SUCCESS;
+}

+ 57 - 0
Platform/Intel/WhitleyOpenBoardPkg/Library/UbaPlatLib/UbaFpkConfigLib.c

@@ -0,0 +1,57 @@
+/** @file
+  UBA FPK configuration library
+
+  @copyright
+  Copyright 2016 Intel Corporation. <BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Base.h>
+#include <Uefi.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DebugLib.h>
+#include <Protocol/UbaCfgDb.h>
+#include <Library/UbaFpkConfigLib.h>
+
+/**
+  Retrieves FPK config struct from UBA database
+
+  @retval EFI_SUCCESS           Config struct is retrieved.
+  @retval EFI_NOT_FOUND         UBA protocol, platform or data not found.
+  @retval EFI_INVALID_PARAMETER If PlatformFpkConfigStruct is NULL.
+**/
+EFI_STATUS
+FpkConfigGetConfigStruct (
+  OUT PLATFORM_FPK_CONFIG_STRUCT *PlatformFpkConfigStruct
+  )
+{
+  EFI_STATUS                        Status;
+  UBA_CONFIG_DATABASE_PROTOCOL      *UbaConfigProtocol = NULL;
+  UINTN                             DataLength = 0;
+
+  Status = gBS->LocateProtocol (
+                  &gUbaConfigDatabaseProtocolGuid,
+                  NULL,
+                  &UbaConfigProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  DataLength = sizeof (*PlatformFpkConfigStruct);
+  Status = UbaConfigProtocol->GetData (
+                                    UbaConfigProtocol,
+                                    &gPlatformFpkConfigDataGuid,
+                                    PlatformFpkConfigStruct,
+                                    &DataLength
+                                    );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  ASSERT (PlatformFpkConfigStruct->Signature == PLATFORM_FPK_CONFIG_SIGNATURE);
+  ASSERT (PlatformFpkConfigStruct->Version   == PLATFORM_FPK_CONFIG_VERSION);
+
+  return EFI_SUCCESS;
+}

+ 132 - 0
Platform/Intel/WhitleyOpenBoardPkg/Library/UbaPlatLib/UbaIioConfigLib.c

@@ -0,0 +1,132 @@
+/** @file
+  DxeUbaIioConfigLib implementation.
+
+  @copyright
+  Copyright 2012 - 2018 Intel Corporation. <BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Base.h>
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DebugLib.h>
+#include <Protocol/UbaCfgDb.h>
+#include <Library/UbaIioConfigLib.h>
+
+EFI_STATUS
+PlatformIioConfigInit (
+  IN OUT IIO_BIFURCATION_DATA_ENTRY       **BifurcationTable,
+  IN OUT UINT8                            *BifurcationEntries,
+  IN OUT IIO_SLOT_CONFIG_DATA_ENTRY       **SlotTable,
+  IN OUT UINT8                            *SlotEntries
+  )
+{
+  EFI_STATUS                        Status;
+  UBA_CONFIG_DATABASE_PROTOCOL      *UbaConfigProtocol = NULL;
+  UINTN                             DataLength = 0;
+  PLATFORM_IIO_CONFIG_UPDATE_TABLE  IioUpdateTable;
+
+  Status = gBS->LocateProtocol (
+                  &gUbaConfigDatabaseProtocolGuid,
+                  NULL,
+                  &UbaConfigProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  DataLength  = sizeof (IioUpdateTable);
+  Status = UbaConfigProtocol->GetData (
+                                    UbaConfigProtocol,
+                                    &gPlatformIioConfigDataDxeGuid,
+                                    &IioUpdateTable,
+                                    &DataLength
+                                    );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  ASSERT (IioUpdateTable.Signature == PLATFORM_IIO_CONFIG_UPDATE_SIGNATURE);
+  ASSERT (IioUpdateTable.Version == PLATFORM_IIO_CONFIG_UPDATE_VERSION);
+
+  *BifurcationTable = IioUpdateTable.IioBifurcationTablePtr;
+  *BifurcationEntries = (UINT8) (IioUpdateTable.IioBifurcationTableSize / sizeof(IIO_BIFURCATION_DATA_ENTRY));
+
+  *SlotTable = IioUpdateTable.IioSlotTablePtr;
+  *SlotEntries = (UINT8)(IioUpdateTable.IioSlotTableSize / sizeof(IIO_SLOT_CONFIG_DATA_ENTRY));
+
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS
+PlatformIioConfigInit2 (
+  IN     UINT8                            SkuPersonalityType,
+  IN OUT IIO_BIFURCATION_DATA_ENTRY       **BifurcationTable,
+  IN OUT UINT8                            *BifurcationEntries,
+  IN OUT IIO_SLOT_CONFIG_DATA_ENTRY       **SlotTable,
+  IN OUT UINT8                            *SlotEntries
+  )
+{
+  EFI_STATUS                        Status;
+  UBA_CONFIG_DATABASE_PROTOCOL      *UbaConfigProtocol = NULL;
+  UINTN                             DataLength = 0;
+  PLATFORM_IIO_CONFIG_UPDATE_TABLE  IioUpdateTable;
+
+  Status = gBS->LocateProtocol (
+                  &gUbaConfigDatabaseProtocolGuid,
+                  NULL,
+                  &UbaConfigProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  DataLength  = sizeof (IioUpdateTable);
+  if (SkuPersonalityType == 1) {
+    Status = UbaConfigProtocol->GetData (
+                                      UbaConfigProtocol,
+                                      &gPlatformIioConfigDataDxeGuid_1,
+                                      &IioUpdateTable,
+                                      &DataLength
+                                      );
+  } else if (SkuPersonalityType == 2) {
+    Status = UbaConfigProtocol->GetData (
+                                      UbaConfigProtocol,
+                                      &gPlatformIioConfigDataDxeGuid_2,
+                                      &IioUpdateTable,
+                                      &DataLength
+                                      );
+  } else if (SkuPersonalityType == 3) {
+    Status = UbaConfigProtocol->GetData (
+                                      UbaConfigProtocol,
+                                      &gPlatformIioConfigDataDxeGuid_3,
+                                      &IioUpdateTable,
+                                      &DataLength
+                                      );
+  } else {
+    Status = UbaConfigProtocol->GetData (
+                                      UbaConfigProtocol,
+                                      &gPlatformIioConfigDataDxeGuid,
+                                      &IioUpdateTable,
+                                      &DataLength
+                                      );
+  }
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  ASSERT (IioUpdateTable.Signature == PLATFORM_IIO_CONFIG_UPDATE_SIGNATURE);
+  ASSERT (IioUpdateTable.Version == PLATFORM_IIO_CONFIG_UPDATE_VERSION);
+
+  *BifurcationTable = IioUpdateTable.IioBifurcationTablePtr;
+  *BifurcationEntries = (UINT8) (IioUpdateTable.IioBifurcationTableSize / sizeof(IIO_BIFURCATION_DATA_ENTRY));
+
+  *SlotTable = IioUpdateTable.IioSlotTablePtr;
+  *SlotEntries = (UINT8)(IioUpdateTable.IioSlotTableSize / sizeof(IIO_SLOT_CONFIG_DATA_ENTRY));
+
+  return EFI_SUCCESS;
+}

+ 221 - 0
Platform/Intel/WhitleyOpenBoardPkg/Library/UbaPlatLib/UbaOpromUpdateLib.c

@@ -0,0 +1,221 @@
+/** @file
+
+  @copyright
+  Copyright 2013 Intel Corporation. <BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Base.h>
+#include <Uefi.h>
+
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DebugLib.h>
+
+#include <Library/UbaOpromUpdateLib.h>
+
+#include <Protocol/UbaCfgDb.h>
+
+
+BOOLEAN
+PlatformCheckPcieRootPort (
+  IN  UINTN                 Bus,
+  IN  UINT32                PcieSlotOpromBitMap
+  )
+{
+  EFI_STATUS                              Status;
+
+  UBA_CONFIG_DATABASE_PROTOCOL            *UbaConfigProtocol = NULL;
+  UINTN                                   DataLength = 0;
+  PLATFORM_OPTION_ROM_UPDATE_DATA         OptionRomUpdateTable;
+
+  Status = gBS->LocateProtocol (
+                  &gUbaConfigDatabaseProtocolGuid,
+                  NULL,
+                  &UbaConfigProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    return TRUE;
+  }
+
+  DataLength  = sizeof (OptionRomUpdateTable);
+  Status = UbaConfigProtocol->GetData (
+                                    UbaConfigProtocol,
+                                    &gPlatformOptionRomUpdateConfigDataGuid,
+                                    &OptionRomUpdateTable,
+                                    &DataLength
+                                    );
+  if (EFI_ERROR (Status)) {
+    return TRUE;
+  }
+
+  ASSERT (OptionRomUpdateTable.Signature == PLATFORM_OPTION_ROM_UPDATE_SIGNATURE);
+  ASSERT (OptionRomUpdateTable.Version == PLATFORM_OPTION_ROM_UPDATE_VERSION);
+
+  return OptionRomUpdateTable.CallCheckRootPort (Bus, PcieSlotOpromBitMap);
+}
+
+EFI_STATUS
+PlatformGetOptionRomTable (
+  IN  PC_PCI_OPTION_ROM_TABLE         **OptionRomTable
+  )
+{
+  EFI_STATUS                              Status;
+
+  UBA_CONFIG_DATABASE_PROTOCOL            *UbaConfigProtocol = NULL;
+  UINTN                                   DataLength = 0;
+  PLATFORM_OPTION_ROM_UPDATE_DATA         OptionRomUpdateTable;
+
+  Status = gBS->LocateProtocol (
+                  &gUbaConfigDatabaseProtocolGuid,
+                  NULL,
+                  &UbaConfigProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  DataLength  = sizeof (OptionRomUpdateTable);
+  Status = UbaConfigProtocol->GetData (
+                                    UbaConfigProtocol,
+                                    &gPlatformOptionRomUpdateConfigDataGuid,
+                                    &OptionRomUpdateTable,
+                                    &DataLength
+                                    );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  ASSERT (OptionRomUpdateTable.Signature == PLATFORM_OPTION_ROM_UPDATE_SIGNATURE);
+  ASSERT (OptionRomUpdateTable.Version == PLATFORM_OPTION_ROM_UPDATE_VERSION);
+
+  if (OptionRomUpdateTable.GetOptionRomTable == NULL) {
+    return EFI_NOT_FOUND;
+  }
+
+  return OptionRomUpdateTable.GetOptionRomTable (OptionRomTable);
+}
+
+EFI_STATUS
+PlatformGetNicSetupConfigTable (
+  IN  NIC_SETUP_CONFIGURATION_STUCT     **NicSetupConfigTable,
+  IN  UINTN                             *NumOfConfig
+  )
+{
+  EFI_STATUS                              Status;
+
+  UBA_CONFIG_DATABASE_PROTOCOL            *UbaConfigProtocol = NULL;
+  UINTN                                   DataLength = 0;
+  PLATFORM_OPTION_ROM_UPDATE_DATA         OptionRomUpdateTable;
+
+  Status = gBS->LocateProtocol (
+                  &gUbaConfigDatabaseProtocolGuid,
+                  NULL,
+                  &UbaConfigProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  DataLength  = sizeof (OptionRomUpdateTable);
+  Status = UbaConfigProtocol->GetData (
+                                    UbaConfigProtocol,
+                                    &gPlatformOptionRomUpdateConfigDataGuid,
+                                    &OptionRomUpdateTable,
+                                    &DataLength
+                                    );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  ASSERT (OptionRomUpdateTable.Signature == PLATFORM_OPTION_ROM_UPDATE_SIGNATURE);
+  ASSERT (OptionRomUpdateTable.Version == PLATFORM_OPTION_ROM_UPDATE_VERSION);
+
+  if (OptionRomUpdateTable.GetNicSetupConfigTable == NULL) {
+    return EFI_NOT_FOUND;
+  }
+
+  return OptionRomUpdateTable.GetNicSetupConfigTable (NicSetupConfigTable, NumOfConfig);
+}
+
+EFI_STATUS
+PlatformGetNicCapabilityTable (
+  IN  NIC_OPTIONROM_CAPBILITY_STRUCT    **NicCapabilityTable,
+  IN  UINTN                             *NumOfNicCapTable
+  )
+{
+  EFI_STATUS                              Status;
+
+  UBA_CONFIG_DATABASE_PROTOCOL            *UbaConfigProtocol = NULL;
+  UINTN                                   DataLength = 0;
+  PLATFORM_OPTION_ROM_UPDATE_DATA         OptionRomUpdateTable;
+
+  Status = gBS->LocateProtocol (
+                  &gUbaConfigDatabaseProtocolGuid,
+                  NULL,
+                  &UbaConfigProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  DataLength  = sizeof (OptionRomUpdateTable);
+  Status = UbaConfigProtocol->GetData (
+                                    UbaConfigProtocol,
+                                    &gPlatformOptionRomUpdateConfigDataGuid,
+                                    &OptionRomUpdateTable,
+                                    &DataLength
+                                    );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  ASSERT (OptionRomUpdateTable.Signature == PLATFORM_OPTION_ROM_UPDATE_SIGNATURE);
+  ASSERT (OptionRomUpdateTable.Version == PLATFORM_OPTION_ROM_UPDATE_VERSION);
+
+  if (OptionRomUpdateTable.GetNicCapabilityTable == NULL) {
+    return EFI_NOT_FOUND;
+  }
+
+  return OptionRomUpdateTable.GetNicCapabilityTable (NicCapabilityTable, NumOfNicCapTable);
+}
+
+EFI_STATUS
+PlatformSetupPcieSlotNumber (
+  OUT  UINT8                   *PcieSlotItemCtrl
+  )
+{
+  EFI_STATUS                              Status;
+
+  UBA_CONFIG_DATABASE_PROTOCOL            *UbaConfigProtocol = NULL;
+  UINTN                                   DataLength = 0;
+  PLATFORM_OPTION_ROM_UPDATE_DATA         OptionRomUpdateTable;
+
+  Status = gBS->LocateProtocol (
+                  &gUbaConfigDatabaseProtocolGuid,
+                  NULL,
+                  &UbaConfigProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  DataLength  = sizeof (OptionRomUpdateTable);
+  Status = UbaConfigProtocol->GetData (
+                                    UbaConfigProtocol,
+                                    &gPlatformOptionRomUpdateConfigDataGuid,
+                                    &OptionRomUpdateTable,
+                                    &DataLength
+                                    );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  ASSERT (OptionRomUpdateTable.Signature == PLATFORM_OPTION_ROM_UPDATE_SIGNATURE);
+  ASSERT (OptionRomUpdateTable.Version == PLATFORM_OPTION_ROM_UPDATE_VERSION);
+
+  return OptionRomUpdateTable.SetupSlotNumber (PcieSlotItemCtrl);
+}

+ 62 - 0
Platform/Intel/WhitleyOpenBoardPkg/Library/UbaPlatLib/UbaPlatLib.inf

@@ -0,0 +1,62 @@
+## @file
+#
+# @copyright
+# Copyright 2014 - 2017 Intel Corporation. <BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = UbaPlatLib
+  FILE_GUID                      = 771FA963-A317-47aa-9D0B-186917B7D829
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = UbaPlatLib | DXE_DRIVER DXE_SMM_DRIVER DXE_RUNTIME_DRIVER
+  CONSTRUCTOR                    = InitializeDxeUbaPlatLib
+
+[sources]
+  UbaAcpiUpdateLib.c
+  UbaOpromUpdateLib.c
+  UbaSmbiosUpdateLib.c
+  UbaIioConfigLib.c
+  UbaSlotUpdateLib.c
+  DxeUbaUsbOcUpdateLib.c
+  DxeUbaGpioPlatformConfigLib.c
+  DxeUbaSystemBoardInfoLib.c
+  DxeUbaSystemConfigUpdateLib.c
+  UbaFpkConfigLib.c
+
+[LibraryClasses]
+  BaseLib
+  DebugLib
+  BaseMemoryLib
+  MemoryAllocationLib
+  UefiLib
+  UefiBootServicesTableLib
+  UefiRuntimeServicesTableLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  WhitleySiliconPkg/CpRcPkg.dec
+  WhitleySiliconPkg/SiliconPkg.dec
+  WhitleySiliconPkg/WhitleySiliconPkg.dec
+  WhitleyOpenBoardPkg/PlatformPkg.dec
+  UefiCpuPkg/UefiCpuPkg.dec
+
+[Protocols]
+  gUbaConfigDatabaseProtocolGuid
+  gEfiSmbiosProtocolGuid
+  gEfiPciIoProtocolGuid
+  gDynamicSiLibraryProtocolGuid                  ## CONSUMES
+
+[Guids]
+  gEfiEndOfDxeEventGroupGuid
+  gSystemBoardInfoConfigDataGuid
+
+[FixedPcd]
+  gEfiCpRcPkgTokenSpaceGuid.PcdMaxCpuSocketCount
+  gEfiCpRcPkgTokenSpaceGuid.PcdMaxCpuCoreCount
+
+[Depex]
+  gDynamicSiLibraryProtocolGuid

+ 114 - 0
Platform/Intel/WhitleyOpenBoardPkg/Library/UbaPlatLib/UbaSlotUpdateLib.c

@@ -0,0 +1,114 @@
+/** @file
+  UbaSlotUpdateLib implementation.
+
+  @copyright
+  Copyright 2012 - 2016 Intel Corporation. <BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Base.h>
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DebugLib.h>
+#include <Library/UbaSlotUpdateLib.h>
+#include <Protocol/UbaCfgDb.h>
+
+EFI_STATUS
+PlatformGetSlotTableData (
+  IN OUT IIO_BROADWAY_ADDRESS_DATA_ENTRY  **BroadwayTable,
+  IN OUT UINT8                            *IOU2Setting,
+  IN OUT UINT8                            *FlagValue
+  )
+{
+  EFI_STATUS                        Status;
+  UBA_CONFIG_DATABASE_PROTOCOL      *UbaConfigProtocol = NULL;
+  UINTN                             DataLength = 0;
+  PLATFORM_SLOT_UPDATE_TABLE        IioSlotUpdateTable;
+
+  Status = gBS->LocateProtocol (
+                  &gUbaConfigDatabaseProtocolGuid,
+                  NULL,
+                  &UbaConfigProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  DataLength = sizeof(IioSlotUpdateTable);
+  Status = UbaConfigProtocol->GetData (
+                                   UbaConfigProtocol,
+                                   &gPlatformSlotDataDxeGuid,
+                                   &IioSlotUpdateTable,
+                                   &DataLength
+                                   );
+
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  ASSERT (IioSlotUpdateTable.Signature == PLATFORM_SLOT_UPDATE_SIGNATURE);
+  ASSERT (IioSlotUpdateTable.Version   == PLATFORM_SLOT_UPDATE_VERSION);
+
+  *BroadwayTable  = IioSlotUpdateTable.BroadwayTablePtr;
+  *IOU2Setting    = IioSlotUpdateTable.GetIOU2Setting (*IOU2Setting);
+  *FlagValue      = IioSlotUpdateTable.FlagValue;
+  return Status;
+}
+
+EFI_STATUS
+PlatformGetSlotTableData2 (
+  IN OUT IIO_BROADWAY_ADDRESS_DATA_ENTRY  **BroadwayTable,
+  IN OUT UINT8                            *IOU0Setting,
+  IN OUT UINT8                            *FlagValue,
+  IN OUT UINT8                            *IOU2Setting,
+  IN     UINT8                            SkuPersonalityType
+  )
+{
+  EFI_STATUS                        Status;
+  UBA_CONFIG_DATABASE_PROTOCOL      *UbaConfigProtocol = NULL;
+  UINTN                             DataLength = 0;
+  PLATFORM_SLOT_UPDATE_TABLE2       IioSlotUpdateTable;
+
+  Status = gBS->LocateProtocol (
+                  &gUbaConfigDatabaseProtocolGuid,
+                  NULL,
+                  &UbaConfigProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  DataLength = sizeof(IioSlotUpdateTable);
+  if ((SkuPersonalityType == 1) || (SkuPersonalityType == 3)) {
+    Status = UbaConfigProtocol->GetData (
+                                     UbaConfigProtocol,
+                                     &gPlatformSlotDataDxeGuid2_1,
+                                     &IioSlotUpdateTable,
+                                     &DataLength
+                                     );
+  } else {
+    Status = UbaConfigProtocol->GetData (
+                                     UbaConfigProtocol,
+                                     &gPlatformSlotDataDxeGuid2,
+                                     &IioSlotUpdateTable,
+                                     &DataLength
+                                     );
+  }
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  ASSERT (IioSlotUpdateTable.Signature == PLATFORM_SLOT_UPDATE_SIGNATURE);
+  ASSERT (IioSlotUpdateTable.Version   == PLATFORM_SLOT_UPDATE_VERSION);
+
+  *BroadwayTable = IioSlotUpdateTable.BroadwayTablePtr;
+  *IOU0Setting   = IioSlotUpdateTable.GetIOU0Setting (*IOU0Setting);
+  *FlagValue     = IioSlotUpdateTable.FlagValue;
+  *IOU2Setting   = IioSlotUpdateTable.GetIOU2Setting (SkuPersonalityType, *IOU2Setting);
+
+  return Status;
+}

+ 663 - 0
Platform/Intel/WhitleyOpenBoardPkg/Library/UbaPlatLib/UbaSmbiosUpdateLib.c

@@ -0,0 +1,663 @@
+/** @file
+  UbaSmbiosUpdateLib implementation.
+
+  @copyright
+  Copyright 2012 - 2017 Intel Corporation. <BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Base.h>
+#include <Uefi.h>
+#include <IndustryStandard/SmBios.h>
+
+#include <Protocol/Smbios.h>
+
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DebugLib.h>
+#include <Library/UbaSmbiosUpdateLib.h>
+
+#include <Protocol/UbaCfgDb.h>
+#include <Guid/EventGroup.h>
+
+#define SMBIOS_TYPE_MAX_LENGTH    0x300
+
+/**
+  Provide the RegData and register a callback for dynamic update SMBIOS data.
+
+  @param RegData                  Callback register data.
+
+  @retval EFI_NOT_FOUND           Data log protocol not found.
+  @retval EFI_OUT_OF_RESOURCES    Data was not logged due to lack of system resources.
+  @retval EFI_SUCCESS             Data have been updated successfully.
+
+**/
+EFI_STATUS
+PlatformRegisterSmbiosUpdate (
+  IN  SMBIOS_UPDATE_DATA              *RegData
+  )
+{
+  EFI_STATUS                              Status;
+  STATIC  UBA_CONFIG_DATABASE_PROTOCOL    *UbaConfigProtocol = NULL;
+
+  if (UbaConfigProtocol == NULL) {
+
+    Status = gBS->LocateProtocol (
+                    &gUbaConfigDatabaseProtocolGuid,
+                    NULL,
+                    &UbaConfigProtocol
+                    );
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+  }
+
+  RegData->Signature  = PLATFORM_SMBIOS_UPDATE_SIGNATURE;
+  RegData->Version    = PLATFORM_SMBIOS_UPDATE_VERSION;
+
+  Status = UbaConfigProtocol->AddData (
+                                     UbaConfigProtocol,
+                                     &gPlatformSmbiosConfigDataGuid,
+                                     RegData,
+                                     sizeof(SMBIOS_UPDATE_DATA)
+                                     );
+  return Status;
+}
+
+/**
+  Update a String for a filled SMBIOS data structure, the structure must be filled
+  before update string.
+  This function update a string indicated by StringNumber to the tail of SMBIOS
+  structure.
+
+  @param Smbios                   SMBIOS structure data buffer pointer.
+  @param BufferSize               SMBIOS structure data buffer size.
+  @param StringNumber             The string index number of SMBIOS structure.
+  @param String                   String want to update.
+
+  @retval EFI_OUT_OF_RESOURCES    No enough memory for this action.
+  @retval EFI_SUCCESS             String updated successfully.
+
+**/
+EFI_STATUS
+PlatformSmbiosUpdateString (
+  IN  OUT SMBIOS_STRUCTURE_POINTER    Smbios,
+  IN      UINTN                       BufferSize,
+  IN      UINTN                       StringNumber,
+  IN      CHAR16                      *String
+  )
+{
+  EFI_STATUS                          Status;
+  CHAR8                               *AsciiString = NULL;
+
+  UINTN                               InputStrLen;
+  UINTN                               TargetStrLen;
+  UINTN                               StrIndex;
+  UINTN                               TargetStrOffset;
+  CHAR8                               *StrStart;
+
+  SMBIOS_STRUCTURE_POINTER            NewSmbiosPtr;
+
+  UINTN                               OrigSize = 0;
+  UINTN                               NewSize = 0;
+  UINTN                               StringSize = 0;
+
+  StringSize = StrSize (String);
+  AsciiString = AllocateZeroPool (StringSize);
+  ASSERT (AsciiString != NULL);
+  if (AsciiString == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+  UnicodeStrToAsciiStrS (String, AsciiString, StringSize);
+  InputStrLen = AsciiStrLen (AsciiString);
+
+  Status = PlatformSmbiosGetTypeLength (Smbios, &OrigSize);
+
+  //
+  // Point to unformed string section
+  //
+  StrStart = (CHAR8 *) Smbios.Hdr + Smbios.Hdr->Length;
+  for (StrIndex = 1, TargetStrOffset = 0; StrIndex < StringNumber; StrStart++, TargetStrOffset++) {
+    //
+    // A string ends in 00h
+    //
+    if (*StrStart == 0) {
+      StrIndex++;
+    }
+  }
+
+  //
+  // Now we get the string target
+  //
+  TargetStrLen = AsciiStrLen(StrStart);
+  if (InputStrLen == TargetStrLen) {
+    Status = AsciiStrCpyS(StrStart, TargetStrLen + 1, AsciiString);
+    ASSERT_EFI_ERROR (Status);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+    return EFI_SUCCESS;
+  }
+
+  //
+  // Original string buffer size is not exactly match input string length.
+  // Re-allocate buffer is needed.
+  //
+  NewSmbiosPtr.Hdr = AllocateZeroPool (SMBIOS_TYPE_MAX_LENGTH);
+  if (NewSmbiosPtr.Hdr == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  //
+  // Copy SMBIOS structure and optional strings.
+  //
+  CopyMem (NewSmbiosPtr.Hdr, Smbios.Hdr, Smbios.Hdr->Length + TargetStrOffset);
+  CopyMem ((CHAR8*)NewSmbiosPtr.Hdr + Smbios.Hdr->Length + TargetStrOffset, AsciiString, InputStrLen + 1);
+  CopyMem ((CHAR8*)NewSmbiosPtr.Hdr + Smbios.Hdr->Length + TargetStrOffset + InputStrLen + 1,
+           (CHAR8*)Smbios.Hdr + Smbios.Hdr->Length + TargetStrOffset + TargetStrLen + 1,
+           OrigSize - Smbios.Hdr->Length - TargetStrOffset - TargetStrLen - 1);
+
+  Status = PlatformSmbiosGetTypeLength (NewSmbiosPtr, &NewSize);
+  CopyMem (Smbios.Hdr, NewSmbiosPtr.Hdr, NewSize);
+
+  FreePool (NewSmbiosPtr.Hdr);
+  FreePool (AsciiString);
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Get SMBIOS data structure length, include the string in tail.
+
+  @param Smbios                   SMBIOS structure data buffer pointer.
+  @param TypeSize                 SMBIOS structure size.
+
+  @retval EFI_INVALID_PARAMETER   Input paramter invalid.
+  @retval EFI_SUCCESS             Caculate data structure size successfully.
+
+**/
+EFI_STATUS
+PlatformSmbiosGetTypeLength (
+  IN  OUT SMBIOS_STRUCTURE_POINTER    Smbios,
+  IN  OUT UINTN                       *TypeSize
+  )
+{
+  UINTN                               FullSize;
+  UINTN                               StrLen;
+  UINTN                               MaxLen;
+  INT8*                               CharInStr;
+
+  if (TypeSize == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  FullSize  = Smbios.Hdr->Length;
+  CharInStr = (INT8*)Smbios.Hdr + Smbios.Hdr->Length;
+  *TypeSize = FullSize;
+  StrLen    = 0;
+
+  //
+  // look for the two consecutive zeros, check the string limit by the way.
+  //
+  while (*CharInStr != 0 || *(CharInStr+1) != 0) {
+    if (*CharInStr == 0) {
+      *TypeSize += 1;
+      CharInStr++;
+    }
+
+    MaxLen = SMBIOS_STRING_MAX_LENGTH;
+    for (StrLen = 0 ; StrLen < MaxLen; StrLen++) {
+      if (*(CharInStr+StrLen) == 0) {
+        break;
+      }
+    }
+
+    if (StrLen == MaxLen) {
+      return EFI_INVALID_PARAMETER;
+    }
+
+    //
+    // forward the pointer
+    //
+    CharInStr += StrLen;
+    *TypeSize += StrLen;
+  }
+
+  //
+  // count ending two zeros.
+  //
+  *TypeSize += 2;
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Add a new SMBIOS structure into SMBIOS database.
+
+  @param Smbios                   SMBIOS structure data buffer pointer.
+
+  @retval EFI_NOT_FOUND           SMBIOS protocol not installed.
+  @retval EFI_SUCCESS             Add data structure successfully.
+
+**/
+EFI_STATUS
+PlatformSmbiosAddNew (
+  IN      SMBIOS_STRUCTURE_POINTER    SmbiosPtr
+  )
+{
+  EFI_STATUS                          Status;
+
+  STATIC  EFI_SMBIOS_PROTOCOL         *Smbios = NULL;
+  EFI_SMBIOS_HANDLE                   SmbiosHandle;
+
+  if (Smbios == NULL) {
+    Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, &Smbios);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+  }
+
+  SmbiosHandle  = SMBIOS_HANDLE_PI_RESERVED;
+  Status = Smbios->Add (Smbios, NULL, &SmbiosHandle, (EFI_SMBIOS_TABLE_HEADER*)SmbiosPtr.Hdr);
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Get the number of instance of SMBIOS type structure in SMBIOS database.
+  return 0 means no instance for this type now.
+
+  @param Type                     SMBIOS type.
+
+  @retval Count                   Number of instance.
+
+**/
+UINTN
+PlatformSmbiosGetInstanceCount (
+  IN      UINT8                       Type
+  )
+{
+  EFI_STATUS                          Status;
+
+  STATIC  EFI_SMBIOS_PROTOCOL         *Smbios = NULL;
+  EFI_SMBIOS_TABLE_HEADER             *SmbiosRecord;
+  EFI_SMBIOS_HANDLE                   SmbiosHandle;
+  EFI_SMBIOS_TYPE                     SmbiosType;
+
+  UINTN                               Count = 0;
+
+  if (Smbios == NULL) {
+    Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, &Smbios);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+  }
+
+  SmbiosHandle  = SMBIOS_HANDLE_PI_RESERVED;
+  SmbiosType    = Type;
+
+  do {
+    Status = Smbios->GetNext (Smbios, &SmbiosHandle, &SmbiosType, &SmbiosRecord, NULL);
+    if (!EFI_ERROR (Status) && (SmbiosHandle != SMBIOS_HANDLE_PI_RESERVED)) {
+      Count ++;
+    }
+  } while (!EFI_ERROR (Status) && (SmbiosHandle != SMBIOS_HANDLE_PI_RESERVED));
+
+  return Count;
+}
+
+/**
+  Get SMBIOS type data structure in SMBIOS database.
+
+  This function give you a pointer of SMBIOS structure directly in the database, you can update
+  the value in formated structure area and it's take affect immediately, but never directly or
+  call PlatformSmbiosUpdateString to edit the string in this buffer,
+  use PlatformSmbiosGetEditCopy->PlatformSmbiosUpdateType instead.
+
+  One of the SmbiosPtr or Handle must be valid value.
+
+  @param Type                     SMBIOS type.
+  @param Instance                 The instance of this type.
+  @param SmbiosPtr                Optional parameter, on input, pass a pointer of SMBIOS_STRUCTURE_POINTER
+                                  to this function.
+                                  On output, return the SMBIOS data pointer in SmbiosPtr.
+  @param Handle                   Optional parameter, on input, pass a pointer of Handle.
+                                  On output, return the SMBIOS data handle value
+
+  @retval EFI_INVALID_PARAMETER   Both the SmbiosPtr and Handle is NULL.
+  @retval EFI_NOT_FOUND           SMBIOS protocol not installed.
+  @retval EFI_SUCCESS             Get structure data successfully.
+
+**/
+EFI_STATUS
+PlatformSmbiosGetInstance (
+  IN      UINT8                       Type,
+  IN      UINTN                       Instance,
+  IN  OUT SMBIOS_STRUCTURE_POINTER    *SmbiosPtr,
+  IN  OUT UINT16                      *Handle
+  )
+{
+  EFI_STATUS                          Status;
+
+  STATIC  EFI_SMBIOS_PROTOCOL         *Smbios = NULL;
+  EFI_SMBIOS_TABLE_HEADER             *SmbiosRecord;
+  EFI_SMBIOS_HANDLE                   SmbiosHandle;
+  EFI_SMBIOS_TYPE                     SmbiosType;
+
+  UINTN                               Count = 0;
+
+  if ((SmbiosPtr == NULL) && (Handle == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (Smbios == NULL) {
+    Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, &Smbios);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+  }
+
+  SmbiosHandle  = SMBIOS_HANDLE_PI_RESERVED;
+  SmbiosType    = Type;
+
+  do {
+    Status = Smbios->GetNext (Smbios, &SmbiosHandle, &SmbiosType, &SmbiosRecord, NULL);
+    if (!EFI_ERROR (Status) && (SmbiosHandle != SMBIOS_HANDLE_PI_RESERVED)) {
+
+      if (++Count == Instance) {
+
+        if (SmbiosPtr != NULL) {
+          (*SmbiosPtr).Hdr = (SMBIOS_STRUCTURE*)SmbiosRecord;
+        }
+
+        if (Handle != NULL) {
+          *Handle = SmbiosHandle;
+        }
+
+        return EFI_SUCCESS;
+      }
+    }
+  } while (!EFI_ERROR (Status) && (SmbiosHandle != SMBIOS_HANDLE_PI_RESERVED));
+
+  return EFI_NOT_FOUND;
+}
+
+/**
+  Get a copy of SMBIOS type structure data in SMBIOS database.
+  Must allocate memory large enough first, then call this function to get the copy.
+
+  @param Type                     SMBIOS type.
+  @param Instance                 The instance of this type.
+  @param SmbiosPtr                A valid buffer pointer which SMBIOS data will copy to this buffer.
+
+  @retval EFI_NOT_FOUND           SMBIOS protocol not installed.
+  @retval EFI_SUCCESS             Get structure data successfully.
+
+**/
+EFI_STATUS
+PlatformSmbiosGetEditCopy (
+  IN      UINT8                       Type,
+  IN      UINTN                       Instance,
+  IN  OUT SMBIOS_STRUCTURE_POINTER    SmbiosPtr
+  )
+{
+  EFI_STATUS                          Status;
+  SMBIOS_STRUCTURE_POINTER            NewSmbiosPtr;
+  UINTN                               Size;
+
+  Status = PlatformSmbiosGetInstance (Type, Instance, &NewSmbiosPtr, NULL);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Status = PlatformSmbiosGetTypeLength (NewSmbiosPtr, &Size);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  CopyMem (SmbiosPtr.Hdr, NewSmbiosPtr.Hdr, Size);
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Update a string which in SMBIOS database.
+  The data structure which string belong to must installed before.
+
+  @param Type                     SMBIOS type.
+  @param Instance                 The instance of this type.
+  @param StringNumber             The string number.
+  @param String                   The string want to update.
+
+  @retval EFI_NOT_FOUND           SMBIOS protocol not installed.
+  @retval EFI_SUCCESS             Update data successfully.
+
+**/
+EFI_STATUS
+PlatformSmbiosUpdateInstalledString (
+  IN      UINT8                       Type,
+  IN      UINTN                       Instance,
+  IN      UINTN                       StringNumber,
+  IN      CHAR16                      *String
+  )
+{
+  EFI_STATUS                          Status;
+  STATIC  EFI_SMBIOS_PROTOCOL         *Smbios = NULL;
+  EFI_SMBIOS_HANDLE                   SmbiosHandle;
+
+  CHAR8                               *AsciiStr = NULL;
+  UINTN                               StringSize = 0;
+
+  if (Smbios == NULL) {
+    Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, &Smbios);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+  }
+
+  StringSize = StrSize (String);
+  AsciiStr = AllocateZeroPool (StringSize);
+  UnicodeStrToAsciiStrS (String, AsciiStr, StringSize);
+
+  Status = PlatformSmbiosGetInstance (Type, Instance, NULL, &SmbiosHandle);
+  if (!EFI_ERROR (Status)) {
+    Status = Smbios->UpdateString (Smbios, &SmbiosHandle, &StringNumber, AsciiStr);
+  }
+
+  FreePool (AsciiStr);
+
+  return Status;
+}
+
+/**
+  Remove a SMBIOS instance in SMBIOS database.
+
+  @param Type                     SMBIOS type.
+  @param Instance                 The instance of this type.
+
+  @retval EFI_NOT_FOUND           SMBIOS protocol not installed.
+  @retval EFI_SUCCESS             Remove data successfully.
+
+**/
+EFI_STATUS
+PlatformSmbiosRemoveType (
+  IN      UINT8                       Type,
+  IN      UINTN                       Instance
+  )
+{
+  EFI_STATUS                          Status;
+
+  STATIC  EFI_SMBIOS_PROTOCOL         *Smbios = NULL;
+  EFI_SMBIOS_HANDLE                   SmbiosHandle;
+
+  if (Smbios == NULL) {
+    Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, &Smbios);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+  }
+
+  Status = PlatformSmbiosGetInstance (Type, Instance, NULL, &SmbiosHandle);
+  if (!EFI_ERROR (Status)) {
+    Status = Smbios->Remove (Smbios, SmbiosHandle);
+  }
+
+  return Status;
+}
+
+/**
+  Remove all the instance of specific SMBIOS type in SMBIOS database.
+
+  @param Type                     SMBIOS type.
+
+  @retval EFI_NOT_FOUND           SMBIOS protocol not installed.
+  @retval EFI_SUCCESS             Remove data successfully.
+
+**/
+EFI_STATUS
+PlatformSmbiosRemoveAll (
+  IN      UINT8                       Type
+  )
+{
+  EFI_STATUS                          Status;
+  UINTN                               Count;
+  UINTN                               Index;
+
+  Count = PlatformSmbiosGetInstanceCount (Type);
+
+  for (Index = 0; Index < Count; Index++) {
+    Status = PlatformSmbiosRemoveType (Type, 1);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Update SMBIOS data structure in database with new structure data.
+
+  @param Type                     SMBIOS type.
+  @param Instance                 The instance of this type.
+  @param SmbiosPtr                A valid buffer pointer which new SMBIOS data stored.
+
+  @retval EFI_NOT_FOUND           SMBIOS protocol not installed.
+  @retval EFI_SUCCESS             Update data successfully.
+
+**/
+EFI_STATUS
+PlatformSmbiosUpdateType (
+  IN      UINT8                       Type,
+  IN      UINTN                       Instance,
+  IN      SMBIOS_STRUCTURE_POINTER    SmbiosPtr
+  )
+{
+  EFI_STATUS                          Status;
+  STATIC  EFI_SMBIOS_PROTOCOL         *Smbios = NULL;
+  EFI_SMBIOS_HANDLE                   SmbiosHandle;
+
+  if (Smbios == NULL) {
+    Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, &Smbios);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+  }
+
+  Status = PlatformSmbiosGetInstance (Type, Instance, NULL, &SmbiosHandle);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Status = PlatformSmbiosRemoveType (Type, Instance);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Status = PlatformSmbiosAddNew (SmbiosPtr);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  return Status;
+}
+
+/**
+  Implement the dynamic SMBIOS data update.
+
+  @param UpdateType               Immediately update or delay update at BDS.
+
+  @retval EFI_SUCCESS             Update successfully.
+
+**/
+EFI_STATUS
+DispatchSmbiosDynamicUpdate (
+  IN      SmbiosUpdateType            UpdateType
+  )
+{
+  EFI_STATUS                              Status;
+
+  UBA_CONFIG_DATABASE_PROTOCOL            *UbaConfigProtocol = NULL;
+  UINTN                                   DataLength = 0;
+  SMBIOS_UPDATE_DATA                      RegData;
+
+  Status = gBS->LocateProtocol (
+                  &gUbaConfigDatabaseProtocolGuid,
+                  NULL,
+                  &UbaConfigProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  DataLength  = sizeof (SMBIOS_UPDATE_DATA);
+  Status = UbaConfigProtocol->GetData (
+                                    UbaConfigProtocol,
+                                    &gPlatformSmbiosConfigDataGuid,
+                                    &RegData,
+                                    &DataLength
+                                    );
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  ASSERT (RegData.Signature == PLATFORM_SMBIOS_UPDATE_SIGNATURE);
+  ASSERT (RegData.Version == PLATFORM_SMBIOS_UPDATE_VERSION);
+
+  //
+  // Check for updatetype match.
+  //
+  if ((RegData.UpdateType == UpdateType) && (RegData.CallUpdate != NULL)) {
+    //
+    // Invoke the callback and update every instance of this type
+    //
+    Status = RegData.CallUpdate ();
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Function provide to DXE driver, which initial the dynamic update.
+
+  @param NULL
+
+  @retval EFI_NOT_FOUND           Required protocol not found.
+  @retval EFI_SUCCESS             Init successfully.
+
+**/
+EFI_STATUS
+PlatformInitSmbiosUpdate (
+  VOID
+  )
+{
+  EFI_STATUS                        Status;
+
+  DEBUG ((DEBUG_INFO, "UBA SMBIOS Update Library: PlatformInitSmbiosUpdate!\n"));
+  Status = DispatchSmbiosDynamicUpdate (SmbiosDelayUpdate);
+
+  return Status;
+}

+ 3 - 0
Platform/Intel/WhitleyOpenBoardPkg/Uba/UbaCommon.dsc

@@ -11,6 +11,9 @@
   UbaPlatLib|$(RP_PKG)/Library/PeiUbaPlatLib/PeiUbaPlatLib.inf
   UbaGpioInitLib|$(RP_PKG)/Library/UbaGpioInitLib/UbaGpioInitLib.inf
 
+[LibraryClasses.X64]
+  UbaPlatLib|$(RP_PKG)/Library/UbaPlatLib/UbaPlatLib.inf
+
 [Components.IA32]
   $(RP_PKG)/Uba/CfgDb/Pei/CfgDbPei.inf
   $(RP_PKG)/Uba/UbaUpdatePcds/Pei/UpdatePcdsPei.inf