123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388 |
- /** @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;
- }
|