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
;
28 Convert EsrtTable physical address to virtual address.
30 @param[in] Event Event whose notification function is being invoked.
31 @param[in] Context The pointer to the notification function's context, which
32 is implementation-dependent.
36 DxeCapsuleLibVirtualAddressChangeEvent (
42 EFI_CONFIGURATION_TABLE
*ConfigEntry
;
45 // Get Esrt table first
47 ConfigEntry
= gST
->ConfigurationTable
;
48 for (Index
= 0; Index
< gST
->NumberOfTableEntries
; Index
++) {
49 if (CompareGuid(&gEfiSystemResourceTableGuid
, &ConfigEntry
->VendorGuid
)) {
56 // If no Esrt table installed in Configure Table
58 if (Index
< gST
->NumberOfTableEntries
) {
60 // Search Esrt to check given capsule is qualified
62 mEsrtTable
= (EFI_SYSTEM_RESOURCE_TABLE
*) ConfigEntry
->VendorTable
;
65 // Update protocol pointer to Esrt Table.
67 gRT
->ConvertPointer (0x00, (VOID
**) &(mEsrtTable
));
70 mIsVirtualAddrConverted
= TRUE
;
75 The constructor function hook VirtualAddressChange event to use ESRT table as capsule routing table.
77 @param ImageHandle The firmware allocated handle for the EFI image.
78 @param SystemTable A pointer to the EFI System Table.
80 @retval EFI_SUCCESS The constructor successfully .
84 DxeRuntimeCapsuleLibConstructor (
85 IN EFI_HANDLE ImageHandle
,
86 IN EFI_SYSTEM_TABLE
*SystemTable
92 // Make sure we can handle virtual address changes.
94 Status
= gBS
->CreateEventEx (
97 DxeCapsuleLibVirtualAddressChangeEvent
,
99 &gEfiEventVirtualAddressChangeGuid
,
100 &mDxeRuntimeCapsuleLibVirtualAddressChangeEvent
102 ASSERT_EFI_ERROR (Status
);
108 The destructor function closes the VirtualAddressChange event.
110 @param ImageHandle The firmware allocated handle for the EFI image.
111 @param SystemTable A pointer to the EFI System Table.
113 @retval EFI_SUCCESS The destructor completed successfully.
117 DxeRuntimeCapsuleLibDestructor (
118 IN EFI_HANDLE ImageHandle
,
119 IN EFI_SYSTEM_TABLE
*SystemTable
125 // Close the VirtualAddressChange event.
127 Status
= gBS
->CloseEvent (mDxeRuntimeCapsuleLibVirtualAddressChangeEvent
);
128 ASSERT_EFI_ERROR (Status
);