]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c
MdeModulePkg/DxeCapsuleLibFmp: Fix build failure
[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 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <PiDxe.h>
16
17 #include <Guid/FmpCapsule.h>
18 #include <Guid/SystemResourceTable.h>
19 #include <Guid/EventGroup.h>
20
21 #include <Library/BaseLib.h>
22 #include <Library/DebugLib.h>
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/DxeServicesTableLib.h>
25 #include <Library/UefiBootServicesTableLib.h>
26 #include <Library/UefiRuntimeServicesTableLib.h>
27 #include <Library/MemoryAllocationLib.h>
28
29 extern EFI_SYSTEM_RESOURCE_TABLE *mEsrtTable;
30 extern BOOLEAN mIsVirtualAddrConverted;
31 EFI_EVENT mDxeRuntimeCapsuleLibVirtualAddressChangeEvent = NULL;
32
33 /**
34 Convert EsrtTable physical address to virtual address.
35
36 @param[in] Event Event whose notification function is being invoked.
37 @param[in] Context The pointer to the notification function's context, which
38 is implementation-dependent.
39 **/
40 VOID
41 EFIAPI
42 DxeCapsuleLibVirtualAddressChangeEvent (
43 IN EFI_EVENT Event,
44 IN VOID *Context
45 )
46 {
47 UINTN Index;
48 EFI_CONFIGURATION_TABLE *ConfigEntry;
49
50 //
51 // Get Esrt table first
52 //
53 ConfigEntry = gST->ConfigurationTable;
54 for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {
55 if (CompareGuid(&gEfiSystemResourceTableGuid, &ConfigEntry->VendorGuid)) {
56 break;
57 }
58 ConfigEntry++;
59 }
60
61 //
62 // If no Esrt table installed in Configure Table
63 //
64 if (Index < gST->NumberOfTableEntries) {
65 //
66 // Search Esrt to check given capsule is qualified
67 //
68 mEsrtTable = (EFI_SYSTEM_RESOURCE_TABLE *) ConfigEntry->VendorTable;
69
70 //
71 // Update protocol pointer to Esrt Table.
72 //
73 gRT->ConvertPointer (0x00, (VOID**) &(mEsrtTable));
74 }
75
76 mIsVirtualAddrConverted = TRUE;
77
78 }
79
80 /**
81 The constructor function hook VirtualAddressChange event to use ESRT table as capsule routing table.
82
83 @param ImageHandle The firmware allocated handle for the EFI image.
84 @param SystemTable A pointer to the EFI System Table.
85
86 @retval EFI_SUCCESS The constructor successfully .
87 **/
88 EFI_STATUS
89 EFIAPI
90 DxeRuntimeCapsuleLibConstructor (
91 IN EFI_HANDLE ImageHandle,
92 IN EFI_SYSTEM_TABLE *SystemTable
93 )
94 {
95 EFI_STATUS Status;
96
97 //
98 // Make sure we can handle virtual address changes.
99 //
100 Status = gBS->CreateEventEx (
101 EVT_NOTIFY_SIGNAL,
102 TPL_NOTIFY,
103 DxeCapsuleLibVirtualAddressChangeEvent,
104 NULL,
105 &gEfiEventVirtualAddressChangeGuid,
106 &mDxeRuntimeCapsuleLibVirtualAddressChangeEvent
107 );
108 ASSERT_EFI_ERROR (Status);
109
110 return EFI_SUCCESS;
111 }
112
113 /**
114 The destructor function closes the VirtualAddressChange event.
115
116 @param ImageHandle The firmware allocated handle for the EFI image.
117 @param SystemTable A pointer to the EFI System Table.
118
119 @retval EFI_SUCCESS The destructor completed successfully.
120 **/
121 EFI_STATUS
122 EFIAPI
123 DxeRuntimeCapsuleLibDestructor (
124 IN EFI_HANDLE ImageHandle,
125 IN EFI_SYSTEM_TABLE *SystemTable
126 )
127 {
128 EFI_STATUS Status;
129
130 //
131 // Close the VirtualAddressChange event.
132 //
133 Status = gBS->CloseEvent (mDxeRuntimeCapsuleLibVirtualAddressChangeEvent);
134 ASSERT_EFI_ERROR (Status);
135
136 return EFI_SUCCESS;
137 }