]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockServiceDxe.c
OvmfPkg/QemuVideoDxe/VbeShim: handle PAM1 register on Q35 correctly
[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
b963ec49 20#include <Library/PcdLib.h>\r
1767877a
LE
21#include <Library/UefiBootServicesTableLib.h>\r
22#include <Library/UefiRuntimeLib.h>\r
23#include <Protocol/DevicePath.h>\r
24#include <Protocol/FirmwareVolumeBlock.h>\r
25\r
26#include "FwBlockService.h"\r
27#include "QemuFlash.h"\r
28\r
29VOID\r
30InstallProtocolInterfaces (\r
31 IN EFI_FW_VOL_BLOCK_DEVICE *FvbDevice\r
32 )\r
33{\r
34 EFI_STATUS Status;\r
35 EFI_HANDLE FwbHandle;\r
36 EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *OldFwbInterface;\r
37\r
b963ec49
LE
38 ASSERT (!FeaturePcdGet (PcdSmmSmramRequire));\r
39\r
1767877a
LE
40 //\r
41 // Find a handle with a matching device path that has supports FW Block\r
42 // protocol\r
43 //\r
44 Status = gBS->LocateDevicePath (&gEfiFirmwareVolumeBlockProtocolGuid,\r
45 &FvbDevice->DevicePath, &FwbHandle);\r
46 if (EFI_ERROR (Status)) {\r
47 //\r
48 // LocateDevicePath fails so install a new interface and device path\r
49 //\r
50 FwbHandle = NULL;\r
51 DEBUG ((EFI_D_INFO, "Installing QEMU flash FVB\n"));\r
52 Status = gBS->InstallMultipleProtocolInterfaces (\r
53 &FwbHandle,\r
54 &gEfiFirmwareVolumeBlockProtocolGuid,\r
55 &FvbDevice->FwVolBlockInstance,\r
56 &gEfiDevicePathProtocolGuid,\r
57 FvbDevice->DevicePath,\r
58 NULL\r
59 );\r
60 ASSERT_EFI_ERROR (Status);\r
61 } else if (IsDevicePathEnd (FvbDevice->DevicePath)) {\r
62 //\r
63 // Device already exists, so reinstall the FVB protocol\r
64 //\r
65 Status = gBS->HandleProtocol (\r
66 FwbHandle,\r
67 &gEfiFirmwareVolumeBlockProtocolGuid,\r
68 (VOID**)&OldFwbInterface\r
69 );\r
70 ASSERT_EFI_ERROR (Status);\r
71\r
72 DEBUG ((EFI_D_INFO, "Reinstalling FVB for QEMU flash region\n"));\r
73 Status = gBS->ReinstallProtocolInterface (\r
74 FwbHandle,\r
75 &gEfiFirmwareVolumeBlockProtocolGuid,\r
76 OldFwbInterface,\r
77 &FvbDevice->FwVolBlockInstance\r
78 );\r
79 ASSERT_EFI_ERROR (Status);\r
80 } else {\r
81 //\r
82 // There was a FVB protocol on an End Device Path node\r
83 //\r
84 ASSERT (FALSE);\r
85 }\r
86}\r
87\r
88\r
89STATIC\r
90VOID\r
91EFIAPI\r
92FvbVirtualAddressChangeEvent (\r
93 IN EFI_EVENT Event,\r
94 IN VOID *Context\r
95 )\r
96/*++\r
97\r
98 Routine Description:\r
99\r
100 Fixup internal data so that EFI and SAL can be call in virtual mode.\r
101 Call the passed in Child Notify event and convert the mFvbModuleGlobal\r
102 date items to there virtual address.\r
103\r
104 Arguments:\r
105\r
106 (Standard EFI notify event - EFI_EVENT_NOTIFY)\r
107\r
108 Returns:\r
109\r
110 None\r
111\r
112--*/\r
113{\r
114 EFI_FW_VOL_INSTANCE *FwhInstance;\r
115 UINTN Index;\r
116\r
117 FwhInstance = mFvbModuleGlobal->FvInstance;\r
118 EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal->FvInstance);\r
119\r
120 //\r
121 // Convert the base address of all the instances\r
122 //\r
123 Index = 0;\r
124 while (Index < mFvbModuleGlobal->NumFv) {\r
125 EfiConvertPointer (0x0, (VOID **) &FwhInstance->FvBase);\r
126 FwhInstance = (EFI_FW_VOL_INSTANCE *)\r
127 (\r
128 (UINTN) ((UINT8 *) FwhInstance) +\r
129 FwhInstance->VolumeHeader.HeaderLength +\r
130 (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))\r
131 );\r
132 Index++;\r
133 }\r
134\r
135 EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal);\r
136 QemuFlashConvertPointers ();\r
137}\r
138\r
139\r
140VOID\r
141InstallVirtualAddressChangeHandler (\r
142 VOID\r
143 )\r
144{\r
145 EFI_STATUS Status;\r
146 EFI_EVENT VirtualAddressChangeEvent;\r
147\r
148 Status = gBS->CreateEventEx (\r
149 EVT_NOTIFY_SIGNAL,\r
150 TPL_NOTIFY,\r
151 FvbVirtualAddressChangeEvent,\r
152 NULL,\r
153 &gEfiEventVirtualAddressChangeGuid,\r
154 &VirtualAddressChangeEvent\r
155 );\r
156 ASSERT_EFI_ERROR (Status);\r
157}\r