47 ASSERT (Instance !=
NULL);
48 if (Instance ==
NULL) {
49 return EFI_OUT_OF_RESOURCES;
53 Status =
gSmst->SmmHandleProtocol (
55 &gEdk2JedecSfdpSpiSmmDriverGuid,
56 (VOID **)&Instance->SpiIo
59 if (EFI_ERROR (Status)) {
60 DEBUG ((DEBUG_ERROR,
"%a: Fail to locate SPI I/O protocol.\n", __func__));
65 if (EFI_ERROR (Status)) {
66 DEBUG ((DEBUG_ERROR,
"%a: Fail to initial SPI_NOR_FLASH_INSTANCE.\n", __func__));
72 &gEfiSpiSmmNorFlashProtocolGuid,
76 if (EFI_ERROR (Status)) {
77 DEBUG ((DEBUG_ERROR,
"%a: Fail to Install gEfiSpiSmmNorFlashProtocolGuid protocol.\n", __func__));
107 DEBUG ((DEBUG_INFO,
"%a: Entry.\n", __func__));
128 Status =
gSmst->SmmRegisterProtocolNotify (
129 &gEdk2JedecSfdpSpiSmmDriverGuid,
133 if (EFI_ERROR (Status)) {
134 DEBUG ((DEBUG_ERROR,
"%a: Fail to register event for the SPI I/O Protocol installation.", __func__));
136 DEBUG ((DEBUG_INFO,
"%a: Notification for SPI I/O Protocol installation was registered.", __func__));
165 UINTN InstanceBufferSize;
167 DEBUG ((DEBUG_INFO,
"%a - ENTRY.\n", __func__));
173 DEBUG ((DEBUG_INFO,
"Check if there were already some gEdk2JedecSfdpSpiSmmDriverGuid handles installed.\n"));
181 InstanceBufferSize = 0;
182 InstanceBuffer =
NULL;
183 Status =
gSmst->SmmLocateHandle (
185 &gEdk2JedecSfdpSpiSmmDriverGuid,
190 if (Status == EFI_NOT_FOUND) {
193 "No gEdk2JedecSfdpSpiSmmDriverGuid handles found at the moment, wait for the notification of SPI I/O protocol installation.\n"
195 DEBUG ((DEBUG_INFO,
"%a: EXIT - Status=%r\n", __func__, Status));
197 }
else if (Status == EFI_BUFFER_TOO_SMALL) {
199 ASSERT (InstanceBuffer !=
NULL);
200 if (InstanceBuffer ==
NULL) {
201 DEBUG ((DEBUG_ERROR,
"Not enough resource for gEdk2JedecSfdpSpiSmmDriverGuid handles.\n"));
202 DEBUG ((DEBUG_INFO,
"%a: EXIT - Status=%r\n", __func__, Status));
203 return EFI_OUT_OF_RESOURCES;
205 }
else if (EFI_ERROR (Status)) {
206 DEBUG ((DEBUG_ERROR,
"Error to locate gEdk2JedecSfdpSpiSmmDriverGuid - Status = %r.\n", Status));
207 DEBUG ((DEBUG_INFO,
"%a: EXIT - Status=%r\n", __func__, Status));
211 Status =
gSmst->SmmLocateHandle (
213 &gEdk2JedecSfdpSpiSmmDriverGuid,
218 if (EFI_ERROR (Status)) {
219 DEBUG ((DEBUG_ERROR,
"Fail to locate all gEdk2JedecSfdpSpiSmmDriverGuid handles.\n"));
220 DEBUG ((DEBUG_INFO,
"%a: EXIT - Status=%r\n", __func__, Status));
224 DEBUG ((DEBUG_INFO,
"%d of gEdk2JedecSfdpSpiSmmDriverGuid handles are found.\n", InstanceBufferSize /
sizeof (
EFI_HANDLE)));
225 for (InstanceIndex = 0; InstanceIndex < InstanceBufferSize /
sizeof (
EFI_HANDLE); InstanceIndex++) {
227 if (EFI_ERROR (Status)) {
228 DEBUG ((DEBUG_ERROR,
"Fail to create SPI NOR Flash SFDP instance #%d.\n", InstanceIndex));
232 DEBUG ((DEBUG_INFO,
"%a: EXIT - Status=%r\n", __func__, Status));
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
EFI_SMM_SYSTEM_TABLE2 * gSmst
EFI_STATUS InitialSpiNorFlashSfdpInstance(IN SPI_NOR_FLASH_INSTANCE *Instance)
EFI_STATUS RegisterSpioProtocolNotification(VOID)
EFI_STATUS EFIAPI SpiIoProtocolInstalledCallback(IN CONST EFI_GUID *Protocol, IN VOID *Interface, IN EFI_HANDLE Handle)
EFI_STATUS EFIAPI SpiNorFlashJedecSfdpSmmEntry(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS CreateSpiNorFlashSfdpInstance(IN EFI_HANDLE SpiIoHandle)
EFI_INSTALL_PROTOCOL_INTERFACE SmmInstallProtocolInterface