VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c@ 105668

Last change on this file since 105668 was 99404, checked in by vboxsync, 2 years ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 4.6 KB
Line 
1/** @file
2 Capsule library runtime support.
3
4 Copyright (c) 2016 - 2017, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7**/
8
9#include <PiDxe.h>
10
11#include <Guid/FmpCapsule.h>
12#include <Guid/SystemResourceTable.h>
13#include <Guid/EventGroup.h>
14
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>
22
23extern EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable;
24extern BOOLEAN mIsVirtualAddrConverted;
25EFI_EVENT mDxeRuntimeCapsuleLibVirtualAddressChangeEvent = NULL;
26EFI_EVENT mDxeRuntimeCapsuleLibReadyToBootEvent = NULL;
27
28/**
29 Convert EsrtTable physical address to virtual address.
30
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.
34**/
35VOID
36EFIAPI
37DxeCapsuleLibVirtualAddressChangeEvent (
38 IN EFI_EVENT Event,
39 IN VOID *Context
40 )
41{
42 gRT->ConvertPointer (EFI_OPTIONAL_PTR, (VOID **)&mEsrtTable);
43 mIsVirtualAddrConverted = TRUE;
44}
45
46/**
47 Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT.
48
49 @param[in] Event The Event that is being processed.
50 @param[in] Context The Event Context.
51
52**/
53STATIC
54VOID
55EFIAPI
56DxeCapsuleLibReadyToBootEventNotify (
57 IN EFI_EVENT Event,
58 IN VOID *Context
59 )
60{
61 UINTN Index;
62 EFI_CONFIGURATION_TABLE *ConfigEntry;
63 EFI_SYSTEM_RESOURCE_TABLE *EsrtTable;
64
65 //
66 // Get Esrt table first
67 //
68 ConfigEntry = gST->ConfigurationTable;
69 for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {
70 if (CompareGuid (&gEfiSystemResourceTableGuid, &ConfigEntry->VendorGuid)) {
71 break;
72 }
73
74 ConfigEntry++;
75 }
76
77 //
78 // If no Esrt table installed in Configure Table
79 //
80 if (Index < gST->NumberOfTableEntries) {
81 //
82 // Search Esrt to check given capsule is qualified
83 //
84 EsrtTable = (EFI_SYSTEM_RESOURCE_TABLE *)ConfigEntry->VendorTable;
85
86 mEsrtTable = AllocateRuntimeCopyPool (
87 sizeof (EFI_SYSTEM_RESOURCE_TABLE) +
88 EsrtTable->FwResourceCount * sizeof (EFI_SYSTEM_RESOURCE_ENTRY),
89 EsrtTable
90 );
91 ASSERT (mEsrtTable != NULL);
92
93 //
94 // Set FwResourceCountMax to a sane value.
95 //
96 mEsrtTable->FwResourceCountMax = mEsrtTable->FwResourceCount;
97 }
98}
99
100/**
101 The constructor function hook VirtualAddressChange event to use ESRT table as capsule routing table.
102
103 @param ImageHandle The firmware allocated handle for the EFI image.
104 @param SystemTable A pointer to the EFI System Table.
105
106 @retval EFI_SUCCESS The constructor successfully .
107**/
108EFI_STATUS
109EFIAPI
110DxeRuntimeCapsuleLibConstructor (
111 IN EFI_HANDLE ImageHandle,
112 IN EFI_SYSTEM_TABLE *SystemTable
113 )
114{
115 EFI_STATUS Status;
116
117 //
118 // Make sure we can handle virtual address changes.
119 //
120 Status = gBS->CreateEventEx (
121 EVT_NOTIFY_SIGNAL,
122 TPL_NOTIFY,
123 DxeCapsuleLibVirtualAddressChangeEvent,
124 NULL,
125 &gEfiEventVirtualAddressChangeGuid,
126 &mDxeRuntimeCapsuleLibVirtualAddressChangeEvent
127 );
128 ASSERT_EFI_ERROR (Status);
129
130 //
131 // Register notify function to cache the FMP capsule GUIDs at ReadyToBoot.
132 //
133 Status = gBS->CreateEventEx (
134 EVT_NOTIFY_SIGNAL,
135 TPL_CALLBACK,
136 DxeCapsuleLibReadyToBootEventNotify,
137 NULL,
138 &gEfiEventReadyToBootGuid,
139 &mDxeRuntimeCapsuleLibReadyToBootEvent
140 );
141 ASSERT_EFI_ERROR (Status);
142
143 return EFI_SUCCESS;
144}
145
146/**
147 The destructor function closes the VirtualAddressChange event.
148
149 @param ImageHandle The firmware allocated handle for the EFI image.
150 @param SystemTable A pointer to the EFI System Table.
151
152 @retval EFI_SUCCESS The destructor completed successfully.
153**/
154EFI_STATUS
155EFIAPI
156DxeRuntimeCapsuleLibDestructor (
157 IN EFI_HANDLE ImageHandle,
158 IN EFI_SYSTEM_TABLE *SystemTable
159 )
160{
161 EFI_STATUS Status;
162
163 //
164 // Close the VirtualAddressChange event.
165 //
166 Status = gBS->CloseEvent (mDxeRuntimeCapsuleLibVirtualAddressChangeEvent);
167 ASSERT_EFI_ERROR (Status);
168
169 //
170 // Close the ReadyToBoot event.
171 //
172 Status = gBS->CloseEvent (mDxeRuntimeCapsuleLibReadyToBootEvent);
173 ASSERT_EFI_ERROR (Status);
174
175 return EFI_SUCCESS;
176}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette