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 | EFI_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 | **/
|
---|
35 | VOID
|
---|
36 | EFIAPI
|
---|
37 | DxeCapsuleLibVirtualAddressChangeEvent (
|
---|
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 | **/
|
---|
53 | STATIC
|
---|
54 | VOID
|
---|
55 | EFIAPI
|
---|
56 | DxeCapsuleLibReadyToBootEventNotify (
|
---|
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 | **/
|
---|
108 | EFI_STATUS
|
---|
109 | EFIAPI
|
---|
110 | DxeRuntimeCapsuleLibConstructor (
|
---|
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 | **/
|
---|
154 | EFI_STATUS
|
---|
155 | EFIAPI
|
---|
156 | DxeRuntimeCapsuleLibDestructor (
|
---|
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 | }
|
---|