VirtualBox

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

Last change on this file since 105681 was 105670, checked in by vboxsync, 9 months ago

Devices/EFI/FirmwareNew: Merge edk2-stable-202405 and make it build on aarch64, bugref:4643

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