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