2 Capsule library runtime support.
4 Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Guid/FmpCapsule.h>
12 #include <Guid/SystemResourceTable.h>
13 #include <Guid/EventGroup.h>
15 #include <Library/BaseLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/BaseMemoryLib.h>
18 #include <Library/DxeServicesTableLib.h>
19 #include <Library/UefiBootServicesTableLib.h>
20 #include <Library/UefiRuntimeServicesTableLib.h>
21 #include <Library/MemoryAllocationLib.h>
23 extern EFI_SYSTEM_RESOURCE_TABLE
*mEsrtTable
;
24 extern BOOLEAN mIsVirtualAddrConverted
;
25 EFI_EVENT mDxeRuntimeCapsuleLibVirtualAddressChangeEvent
= NULL
;
26 EFI_EVENT mDxeRuntimeCapsuleLibReadyToBootEvent
= NULL
;
29 Convert EsrtTable physical address to virtual address.
31 @param[in] Event Event whose notification function is being invoked.
32 @param[in] Context The pointer to the notification function's context, which
33 is implementation-dependent.
37 DxeCapsuleLibVirtualAddressChangeEvent (
42 gRT
->ConvertPointer (EFI_OPTIONAL_PTR
, (VOID
**)&mEsrtTable
);
43 mIsVirtualAddrConverted
= TRUE
;
47 Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT.
49 @param[in] Event The Event that is being processed.
50 @param[in] Context The Event Context.
56 DxeCapsuleLibReadyToBootEventNotify (
62 EFI_CONFIGURATION_TABLE
*ConfigEntry
;
63 EFI_SYSTEM_RESOURCE_TABLE
*EsrtTable
;
66 // Get Esrt table first
68 ConfigEntry
= gST
->ConfigurationTable
;
69 for (Index
= 0; Index
< gST
->NumberOfTableEntries
; Index
++) {
70 if (CompareGuid(&gEfiSystemResourceTableGuid
, &ConfigEntry
->VendorGuid
)) {
77 // If no Esrt table installed in Configure Table
79 if (Index
< gST
->NumberOfTableEntries
) {
81 // Search Esrt to check given capsule is qualified
83 EsrtTable
= (EFI_SYSTEM_RESOURCE_TABLE
*) ConfigEntry
->VendorTable
;
85 mEsrtTable
= AllocateRuntimeCopyPool (
86 sizeof (EFI_SYSTEM_RESOURCE_TABLE
) +
87 EsrtTable
->FwResourceCount
* sizeof (EFI_SYSTEM_RESOURCE_ENTRY
),
89 ASSERT (mEsrtTable
!= NULL
);
92 // Set FwResourceCountMax to a sane value.
94 mEsrtTable
->FwResourceCountMax
= mEsrtTable
->FwResourceCount
;
99 The constructor function hook VirtualAddressChange event to use ESRT table as capsule routing table.
101 @param ImageHandle The firmware allocated handle for the EFI image.
102 @param SystemTable A pointer to the EFI System Table.
104 @retval EFI_SUCCESS The constructor successfully .
108 DxeRuntimeCapsuleLibConstructor (
109 IN EFI_HANDLE ImageHandle
,
110 IN EFI_SYSTEM_TABLE
*SystemTable
116 // Make sure we can handle virtual address changes.
118 Status
= gBS
->CreateEventEx (
121 DxeCapsuleLibVirtualAddressChangeEvent
,
123 &gEfiEventVirtualAddressChangeGuid
,
124 &mDxeRuntimeCapsuleLibVirtualAddressChangeEvent
126 ASSERT_EFI_ERROR (Status
);
129 // Register notify function to cache the FMP capsule GUIDs at ReadyToBoot.
131 Status
= gBS
->CreateEventEx (
134 DxeCapsuleLibReadyToBootEventNotify
,
136 &gEfiEventReadyToBootGuid
,
137 &mDxeRuntimeCapsuleLibReadyToBootEvent
139 ASSERT_EFI_ERROR (Status
);
145 The destructor function closes the VirtualAddressChange event.
147 @param ImageHandle The firmware allocated handle for the EFI image.
148 @param SystemTable A pointer to the EFI System Table.
150 @retval EFI_SUCCESS The destructor completed successfully.
154 DxeRuntimeCapsuleLibDestructor (
155 IN EFI_HANDLE ImageHandle
,
156 IN EFI_SYSTEM_TABLE
*SystemTable
162 // Close the VirtualAddressChange event.
164 Status
= gBS
->CloseEvent (mDxeRuntimeCapsuleLibVirtualAddressChangeEvent
);
165 ASSERT_EFI_ERROR (Status
);
168 // Close the ReadyToBoot event.
170 Status
= gBS
->CloseEvent (mDxeRuntimeCapsuleLibReadyToBootEvent
);
171 ASSERT_EFI_ERROR (Status
);