]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c
OvmfPkg: SmmCpuFeaturesLib: remove unnecessary bits
[mirror_edk2.git] / OvmfPkg / QemuFlashFvbServicesRuntimeDxe / FwBlockServiceDxe.c
CommitLineData
1767877a
LE
1/**@file\r
2 Functions related to the Firmware Volume Block service whose\r
3 implementation is specific to the runtime DXE driver build.\r
4\r
5 Copyright (C) 2015, Red Hat, Inc.\r
6 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
7\r
8 This program and the accompanying materials are licensed and made available\r
9 under the terms and conditions of the BSD License which accompanies this\r
10 distribution. The full text of the license may be found at\r
11 http://opensource.org/licenses/bsd-license.php\r
12\r
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
15**/\r
16\r
17#include <Guid/EventGroup.h>\r
18#include <Library/DebugLib.h>\r
19#include <Library/DevicePathLib.h>\r
20#include <Library/UefiBootServicesTableLib.h>\r
21#include <Library/UefiRuntimeLib.h>\r
22#include <Protocol/DevicePath.h>\r
23#include <Protocol/FirmwareVolumeBlock.h>\r
24\r
25#include "FwBlockService.h"\r
26#include "QemuFlash.h"\r
27\r
28VOID\r
29InstallProtocolInterfaces (\r
30 IN EFI_FW_VOL_BLOCK_DEVICE *FvbDevice\r
31 )\r
32{\r
33 EFI_STATUS Status;\r
34 EFI_HANDLE FwbHandle;\r
35 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *OldFwbInterface;\r
36\r
37 //\r
38 // Find a handle with a matching device path that has supports FW Block\r
39 // protocol\r
40 //\r
41 Status = gBS->LocateDevicePath (&gEfiFirmwareVolumeBlockProtocolGuid,\r
42 &FvbDevice->DevicePath, &FwbHandle);\r
43 if (EFI_ERROR (Status)) {\r
44 //\r
45 // LocateDevicePath fails so install a new interface and device path\r
46 //\r
47 FwbHandle = NULL;\r
48 DEBUG ((EFI_D_INFO, "Installing QEMU flash FVB\n"));\r
49 Status = gBS->InstallMultipleProtocolInterfaces (\r
50 &FwbHandle,\r
51 &gEfiFirmwareVolumeBlockProtocolGuid,\r
52 &FvbDevice->FwVolBlockInstance,\r
53 &gEfiDevicePathProtocolGuid,\r
54 FvbDevice->DevicePath,\r
55 NULL\r
56 );\r
57 ASSERT_EFI_ERROR (Status);\r
58 } else if (IsDevicePathEnd (FvbDevice->DevicePath)) {\r
59 //\r
60 // Device already exists, so reinstall the FVB protocol\r
61 //\r
62 Status = gBS->HandleProtocol (\r
63 FwbHandle,\r
64 &gEfiFirmwareVolumeBlockProtocolGuid,\r
65 (VOID**)&OldFwbInterface\r
66 );\r
67 ASSERT_EFI_ERROR (Status);\r
68\r
69 DEBUG ((EFI_D_INFO, "Reinstalling FVB for QEMU flash region\n"));\r
70 Status = gBS->ReinstallProtocolInterface (\r
71 FwbHandle,\r
72 &gEfiFirmwareVolumeBlockProtocolGuid,\r
73 OldFwbInterface,\r
74 &FvbDevice->FwVolBlockInstance\r
75 );\r
76 ASSERT_EFI_ERROR (Status);\r
77 } else {\r
78 //\r
79 // There was a FVB protocol on an End Device Path node\r
80 //\r
81 ASSERT (FALSE);\r
82 }\r
83}\r
84\r
85\r
86STATIC\r
87VOID\r
88EFIAPI\r
89FvbVirtualAddressChangeEvent (\r
90 IN EFI_EVENT Event,\r
91 IN VOID *Context\r
92 )\r
93/*++\r
94\r
95 Routine Description:\r
96\r
97 Fixup internal data so that EFI and SAL can be call in virtual mode.\r
98 Call the passed in Child Notify event and convert the mFvbModuleGlobal\r
99 date items to there virtual address.\r
100\r
101 Arguments:\r
102\r
103 (Standard EFI notify event - EFI_EVENT_NOTIFY)\r
104\r
105 Returns:\r
106\r
107 None\r
108\r
109--*/\r
110{\r
111 EFI_FW_VOL_INSTANCE *FwhInstance;\r
112 UINTN Index;\r
113\r
114 FwhInstance = mFvbModuleGlobal->FvInstance;\r
115 EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal->FvInstance);\r
116\r
117 //\r
118 // Convert the base address of all the instances\r
119 //\r
120 Index = 0;\r
121 while (Index < mFvbModuleGlobal->NumFv) {\r
122 EfiConvertPointer (0x0, (VOID **) &FwhInstance->FvBase);\r
123 FwhInstance = (EFI_FW_VOL_INSTANCE *)\r
124 (\r
125 (UINTN) ((UINT8 *) FwhInstance) +\r
126 FwhInstance->VolumeHeader.HeaderLength +\r
127 (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))\r
128 );\r
129 Index++;\r
130 }\r
131\r
132 EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal);\r
133 QemuFlashConvertPointers ();\r
134}\r
135\r
136\r
137VOID\r
138InstallVirtualAddressChangeHandler (\r
139 VOID\r
140 )\r
141{\r
142 EFI_STATUS Status;\r
143 EFI_EVENT VirtualAddressChangeEvent;\r
144\r
145 Status = gBS->CreateEventEx (\r
146 EVT_NOTIFY_SIGNAL,\r
147 TPL_NOTIFY,\r
148 FvbVirtualAddressChangeEvent,\r
149 NULL,\r
150 &gEfiEventVirtualAddressChangeGuid,\r
151 &VirtualAddressChangeEvent\r
152 );\r
153 ASSERT_EFI_ERROR (Status);\r
154}\r