SpiFlashCommonSmmLib.c 1.5 KB

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