SpiFlashCommonSmmLib.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /** @file
  2. SMM Library instance of SPI Flash Common Library Class
  3. @copyright
  4. Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include <Library/SpiFlashCommonLib.h>
  8. #include <Library/SmmServicesTableLib.h>
  9. #include <Protocol/Spi.h>
  10. extern PCH_SPI_PROTOCOL *mSpiProtocol;
  11. extern UINTN mFlashAreaBaseAddress;
  12. extern UINTN mFlashAreaSize;
  13. /**
  14. The library constructuor.
  15. The function does the necessary initialization work for this library
  16. instance.
  17. @param[in] ImageHandle The firmware allocated handle for the UEFI image.
  18. @param[in] SystemTable A pointer to the EFI system table.
  19. @retval EFI_SUCCESS The function always return EFI_SUCCESS for now.
  20. It will ASSERT on error for debug version.
  21. @retval EFI_ERROR Please reference LocateProtocol for error code details.
  22. **/
  23. EFI_STATUS
  24. EFIAPI
  25. SmmSpiFlashCommonLibConstructor (
  26. IN EFI_HANDLE ImageHandle,
  27. IN EFI_SYSTEM_TABLE *SystemTable
  28. )
  29. {
  30. EFI_STATUS Status;
  31. mFlashAreaBaseAddress = (UINTN)PcdGet32 (PcdFlashAreaBaseAddress);
  32. mFlashAreaSize = (UINTN)PcdGet32 (PcdFlashAreaSize);
  33. //
  34. // Locate the SMM SPI protocol.
  35. //
  36. Status = gSmst->SmmLocateProtocol (
  37. &gPchSmmSpiProtocolGuid,
  38. NULL,
  39. (VOID **) &mSpiProtocol
  40. );
  41. ASSERT_EFI_ERROR (Status);
  42. return Status;
  43. }