/** Variable Driver main entry point. The Variable driver places the 4 EFI runtime services in the EFI System Table and installs arch protocols for variable read and write services being available. It also registers a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event. @param[in] ImageHandle The firmware allocated handle for the EFI image. @param[in] SystemTable A pointer to the EFI System Table. @retval EFI_SUCCESS Variable service successfully initialized. **/ EFI_STATUS EFIAPI VariableServiceInitialize ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; EFI_HANDLE VariableHandle; VOID *SmmFtwRegistration; VOID *SmmEndOfDxeRegistration; // // Variable initialize. // Status = VariableCommonInitialize (); ASSERT_EFI_ERROR (Status); // // Install the Smm Variable Protocol on a new handle. // VariableHandle = NULL; Status = gSmst->SmmInstallProtocolInterface ( &VariableHandle, &gEfiSmmVariableProtocolGuid, EFI_NATIVE_INTERFACE, &gSmmVariable ); ASSERT_EFI_ERROR (Status); Status = gSmst->SmmInstallProtocolInterface ( &VariableHandle, &gEdkiiSmmVarCheckProtocolGuid, EFI_NATIVE_INTERFACE, &mSmmVarCheck ); ASSERT_EFI_ERROR (Status); mVariableBufferPayloadSize = GetNonVolatileMaxVariableSize () + OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY, Name) - GetVariableHeaderSize (); Status = gSmst->SmmAllocatePool ( EfiRuntimeServicesData, mVariableBufferPayloadSize, (VOID **)&mVariableBufferPayload ); ASSERT_EFI_ERROR (Status); /// /// Register SMM variable SMI handler /// VariableHandle = NULL; Status = gSmst->SmiHandlerRegister (SmmVariableHandler, &gEfiSmmVariableProtocolGuid, &VariableHandle); ASSERT_EFI_ERROR (Status); // // Notify the variable wrapper driver the variable service is ready // Status = SystemTable->BootServices->InstallProtocolInterface ( &mVariableHandle, &gEfiSmmVariableProtocolGuid, EFI_NATIVE_INTERFACE, &gSmmVariable ); ASSERT_EFI_ERROR (Status); // // Register EFI_SMM_END_OF_DXE_PROTOCOL_GUID notify function. // Status = gSmst->SmmRegisterProtocolNotify ( &gEfiSmmEndOfDxeProtocolGuid, SmmEndOfDxeCallback, &SmmEndOfDxeRegistration ); ASSERT_EFI_ERROR (Status); // // Register FtwNotificationEvent () notify function. // Status = gSmst->SmmRegisterProtocolNotify ( &gEfiSmmFaultTolerantWriteProtocolGuid, SmmFtwNotificationEvent, &SmmFtwRegistration ); ASSERT_EFI_ERROR (Status); SmmFtwNotificationEvent (NULL, NULL, NULL); return EFI_SUCCESS; }
/** Variable Driver main entry point. The Variable driver places the 4 EFI runtime services in the EFI System Table and installs arch protocols for variable read and write services being available. It also registers a notification function for an EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE event. @param[in] ImageHandle The firmware allocated handle for the EFI image. @param[in] SystemTable A pointer to the EFI System Table. @retval EFI_SUCCESS Variable service successfully initialized. **/ EFI_STATUS EFIAPI VariableServiceInitialize ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; EFI_HANDLE VariableHandle; VOID *SmmFtwRegistration; EFI_SMM_ACCESS2_PROTOCOL *SmmAccess; UINTN Size; // // Variable initialize. // Status = VariableCommonInitialize (); ASSERT_EFI_ERROR (Status); // // Install the Smm Variable Protocol on a new handle. // VariableHandle = NULL; Status = gSmst->SmmInstallProtocolInterface ( &VariableHandle, &gEfiSmmVariableProtocolGuid, EFI_NATIVE_INTERFACE, &gSmmVariable ); ASSERT_EFI_ERROR (Status); // // Get SMRAM information // Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&SmmAccess); ASSERT_EFI_ERROR (Status); Size = 0; Status = SmmAccess->GetCapabilities (SmmAccess, &Size, NULL); ASSERT (Status == EFI_BUFFER_TOO_SMALL); Status = gSmst->SmmAllocatePool ( EfiRuntimeServicesData, Size, (VOID **)&mSmramRanges ); ASSERT_EFI_ERROR (Status); Status = SmmAccess->GetCapabilities (SmmAccess, &Size, mSmramRanges); ASSERT_EFI_ERROR (Status); mSmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR); /// /// Register SMM variable SMI handler /// VariableHandle = NULL; Status = gSmst->SmiHandlerRegister (SmmVariableHandler, &gEfiSmmVariableProtocolGuid, &VariableHandle); ASSERT_EFI_ERROR (Status); // // Notify the variable wrapper driver the variable service is ready // Status = SystemTable->BootServices->InstallProtocolInterface ( &mVariableHandle, &gEfiSmmVariableProtocolGuid, EFI_NATIVE_INTERFACE, &gSmmVariable ); ASSERT_EFI_ERROR (Status); // // Register FtwNotificationEvent () notify function. // Status = gSmst->SmmRegisterProtocolNotify ( &gEfiSmmFaultTolerantWriteProtocolGuid, SmmFtwNotificationEvent, &SmmFtwRegistration ); ASSERT_EFI_ERROR (Status); SmmFtwNotificationEvent (NULL, NULL, NULL); return EFI_SUCCESS; }