]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Library / DxeCapsuleLibFmp / DxeCapsuleRuntime.c
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
23 extern EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable;
24 extern BOOLEAN mIsVirtualAddrConverted;
25 EFI_EVENT mDxeRuntimeCapsuleLibVirtualAddressChangeEvent = 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 **/
34 VOID
35 EFIAPI
36 DxeCapsuleLibVirtualAddressChangeEvent (
37 IN EFI_EVENT Event,
38 IN VOID *Context
39 )
40 {
41 UINTN Index;
42 EFI_CONFIGURATION_TABLE *ConfigEntry;
43
44 //
45 // Get Esrt table first
46 //
47 ConfigEntry = gST->ConfigurationTable;
48 for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {
49 if (CompareGuid(&gEfiSystemResourceTableGuid, &ConfigEntry->VendorGuid)) {
50 break;
51 }
52 ConfigEntry++;
53 }
54
55 //
56 // If no Esrt table installed in Configure Table
57 //
58 if (Index < gST->NumberOfTableEntries) {
59 //
60 // Search Esrt to check given capsule is qualified
61 //
62 mEsrtTable = (EFI_SYSTEM_RESOURCE_TABLE *) ConfigEntry->VendorTable;
63
64 //
65 // Update protocol pointer to Esrt Table.
66 //
67 gRT->ConvertPointer (0x00, (VOID**) &(mEsrtTable));
68 }
69
70 mIsVirtualAddrConverted = TRUE;
71
72 }
73
74 /**
75 The constructor function hook VirtualAddressChange event to use ESRT table as capsule routing table.
76
77 @param ImageHandle The firmware allocated handle for the EFI image.
78 @param SystemTable A pointer to the EFI System Table.
79
80 @retval EFI_SUCCESS The constructor successfully .
81 **/
82 EFI_STATUS
83 EFIAPI
84 DxeRuntimeCapsuleLibConstructor (
85 IN EFI_HANDLE ImageHandle,
86 IN EFI_SYSTEM_TABLE *SystemTable
87 )
88 {
89 EFI_STATUS Status;
90
91 //
92 // Make sure we can handle virtual address changes.
93 //
94 Status = gBS->CreateEventEx (
95 EVT_NOTIFY_SIGNAL,
96 TPL_NOTIFY,
97 DxeCapsuleLibVirtualAddressChangeEvent,
98 NULL,
99 &gEfiEventVirtualAddressChangeGuid,
100 &mDxeRuntimeCapsuleLibVirtualAddressChangeEvent
101 );
102 ASSERT_EFI_ERROR (Status);
103
104 return EFI_SUCCESS;
105 }
106
107 /**
108 The destructor function closes the VirtualAddressChange event.
109
110 @param ImageHandle The firmware allocated handle for the EFI image.
111 @param SystemTable A pointer to the EFI System Table.
112
113 @retval EFI_SUCCESS The destructor completed successfully.
114 **/
115 EFI_STATUS
116 EFIAPI
117 DxeRuntimeCapsuleLibDestructor (
118 IN EFI_HANDLE ImageHandle,
119 IN EFI_SYSTEM_TABLE *SystemTable
120 )
121 {
122 EFI_STATUS Status;
123
124 //
125 // Close the VirtualAddressChange event.
126 //
127 Status = gBS->CloseEvent (mDxeRuntimeCapsuleLibVirtualAddressChangeEvent);
128 ASSERT_EFI_ERROR (Status);
129
130 return EFI_SUCCESS;
131 }