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
)) {
78 // If no Esrt table installed in Configure Table
80 if (Index
< gST
->NumberOfTableEntries
) {
82 // Search Esrt to check given capsule is qualified
84 EsrtTable
= (EFI_SYSTEM_RESOURCE_TABLE
*)ConfigEntry
->VendorTable
;
86 mEsrtTable
= AllocateRuntimeCopyPool (
87 sizeof (EFI_SYSTEM_RESOURCE_TABLE
) +
88 EsrtTable
->FwResourceCount
* sizeof (EFI_SYSTEM_RESOURCE_ENTRY
),
91 ASSERT (mEsrtTable
!= NULL
);
94 // Set FwResourceCountMax to a sane value.
96 mEsrtTable
->FwResourceCountMax
= mEsrtTable
->FwResourceCount
;
101 The constructor function hook VirtualAddressChange event to use ESRT table as capsule routing table.
103 @param ImageHandle The firmware allocated handle for the EFI image.
104 @param SystemTable A pointer to the EFI System Table.
106 @retval EFI_SUCCESS The constructor successfully .
110 DxeRuntimeCapsuleLibConstructor (
111 IN EFI_HANDLE ImageHandle
,
112 IN EFI_SYSTEM_TABLE
*SystemTable
118 // Make sure we can handle virtual address changes.
120 Status
= gBS
->CreateEventEx (
123 DxeCapsuleLibVirtualAddressChangeEvent
,
125 &gEfiEventVirtualAddressChangeGuid
,
126 &mDxeRuntimeCapsuleLibVirtualAddressChangeEvent
128 ASSERT_EFI_ERROR (Status
);
131 // Register notify function to cache the FMP capsule GUIDs at ReadyToBoot.
133 Status
= gBS
->CreateEventEx (
136 DxeCapsuleLibReadyToBootEventNotify
,
138 &gEfiEventReadyToBootGuid
,
139 &mDxeRuntimeCapsuleLibReadyToBootEvent
141 ASSERT_EFI_ERROR (Status
);
147 The destructor function closes the VirtualAddressChange event.
149 @param ImageHandle The firmware allocated handle for the EFI image.
150 @param SystemTable A pointer to the EFI System Table.
152 @retval EFI_SUCCESS The destructor completed successfully.
156 DxeRuntimeCapsuleLibDestructor (
157 IN EFI_HANDLE ImageHandle
,
158 IN EFI_SYSTEM_TABLE
*SystemTable
164 // Close the VirtualAddressChange event.
166 Status
= gBS
->CloseEvent (mDxeRuntimeCapsuleLibVirtualAddressChangeEvent
);
167 ASSERT_EFI_ERROR (Status
);
170 // Close the ReadyToBoot event.
172 Status
= gBS
->CloseEvent (mDxeRuntimeCapsuleLibReadyToBootEvent
);
173 ASSERT_EFI_ERROR (Status
);