1 | /** @file
|
---|
2 | SMM Firmware Volume Block Driver.
|
---|
3 |
|
---|
4 | Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>
|
---|
5 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 |
|
---|
7 | **/
|
---|
8 |
|
---|
9 | #include <PiSmm.h>
|
---|
10 | #include <Library/SmmServicesTableLib.h>
|
---|
11 | #include "FvbSmmCommon.h"
|
---|
12 | #include "FvbService.h"
|
---|
13 |
|
---|
14 | /**
|
---|
15 | The function installs EFI_SMM_FIRMWARE_VOLUME_BLOCK protocol
|
---|
16 | for each FV in the system.
|
---|
17 |
|
---|
18 | @param[in] FwhInstance The pointer to a FW volume instance structure,
|
---|
19 | which contains the information about one FV.
|
---|
20 | @param[in] InstanceNum The instance number which can be used as a ID
|
---|
21 | to locate this FwhInstance in other functions.
|
---|
22 |
|
---|
23 | @retval EFI_SUCESS Installed successfully.
|
---|
24 | @retval Else Did not install successfully.
|
---|
25 |
|
---|
26 | **/
|
---|
27 | EFI_STATUS
|
---|
28 | InstallFvbProtocol (
|
---|
29 | IN EFI_FW_VOL_INSTANCE *FwhInstance,
|
---|
30 | IN UINTN InstanceNum
|
---|
31 | )
|
---|
32 | {
|
---|
33 | EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
|
---|
34 | EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
|
---|
35 | EFI_STATUS Status;
|
---|
36 | EFI_HANDLE FvbHandle;
|
---|
37 | FV_MEMMAP_DEVICE_PATH *FvDevicePath;
|
---|
38 | VOID *TempPtr;
|
---|
39 |
|
---|
40 | FvbDevice = (EFI_FW_VOL_BLOCK_DEVICE *)AllocateRuntimeCopyPool (
|
---|
41 | sizeof (EFI_FW_VOL_BLOCK_DEVICE),
|
---|
42 | &mFvbDeviceTemplate
|
---|
43 | );
|
---|
44 | if (FvbDevice == NULL) {
|
---|
45 | return EFI_OUT_OF_RESOURCES;
|
---|
46 | }
|
---|
47 |
|
---|
48 | FvbDevice->Instance = InstanceNum;
|
---|
49 | FwVolHeader = &FwhInstance->VolumeHeader;
|
---|
50 |
|
---|
51 | //
|
---|
52 | // Set up the devicepath
|
---|
53 | //
|
---|
54 | if (FwVolHeader->ExtHeaderOffset == 0) {
|
---|
55 | //
|
---|
56 | // FV does not contains extension header, then produce MEMMAP_DEVICE_PATH
|
---|
57 | //
|
---|
58 | TempPtr = AllocateRuntimeCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH), &mFvMemmapDevicePathTemplate);
|
---|
59 | FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)TempPtr;
|
---|
60 | if (FvbDevice->DevicePath == NULL) {
|
---|
61 | ASSERT (FALSE);
|
---|
62 | return EFI_OUT_OF_RESOURCES;
|
---|
63 | }
|
---|
64 |
|
---|
65 | FvDevicePath = (FV_MEMMAP_DEVICE_PATH *)FvbDevice->DevicePath;
|
---|
66 | FvDevicePath->MemMapDevPath.StartingAddress = FwhInstance->FvBase;
|
---|
67 | FvDevicePath->MemMapDevPath.EndingAddress = FwhInstance->FvBase + FwVolHeader->FvLength - 1;
|
---|
68 | } else {
|
---|
69 | TempPtr = AllocateRuntimeCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePathTemplate);
|
---|
70 | FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)TempPtr;
|
---|
71 | if (FvbDevice->DevicePath == NULL) {
|
---|
72 | ASSERT (FALSE);
|
---|
73 | return EFI_OUT_OF_RESOURCES;
|
---|
74 | }
|
---|
75 |
|
---|
76 | CopyGuid (
|
---|
77 | &((FV_PIWG_DEVICE_PATH *)FvbDevice->DevicePath)->FvDevPath.FvName,
|
---|
78 | (GUID *)(UINTN)(FwhInstance->FvBase + FwVolHeader->ExtHeaderOffset)
|
---|
79 | );
|
---|
80 | }
|
---|
81 |
|
---|
82 | //
|
---|
83 | // Install the SMM Firmware Volume Block Protocol and Device Path Protocol
|
---|
84 | //
|
---|
85 | FvbHandle = NULL;
|
---|
86 | Status = gSmst->SmmInstallProtocolInterface (
|
---|
87 | &FvbHandle,
|
---|
88 | &gEfiSmmFirmwareVolumeBlockProtocolGuid,
|
---|
89 | EFI_NATIVE_INTERFACE,
|
---|
90 | &FvbDevice->FwVolBlockInstance
|
---|
91 | );
|
---|
92 | ASSERT_EFI_ERROR (Status);
|
---|
93 |
|
---|
94 | Status = gSmst->SmmInstallProtocolInterface (
|
---|
95 | &FvbHandle,
|
---|
96 | &gEfiDevicePathProtocolGuid,
|
---|
97 | EFI_NATIVE_INTERFACE,
|
---|
98 | FvbDevice->DevicePath
|
---|
99 | );
|
---|
100 | ASSERT_EFI_ERROR (Status);
|
---|
101 |
|
---|
102 | //
|
---|
103 | // Notify the Fvb wrapper driver SMM fvb is ready
|
---|
104 | //
|
---|
105 | FvbHandle = NULL;
|
---|
106 | Status = gBS->InstallProtocolInterface (
|
---|
107 | &FvbHandle,
|
---|
108 | &gEfiSmmFirmwareVolumeBlockProtocolGuid,
|
---|
109 | EFI_NATIVE_INTERFACE,
|
---|
110 | &FvbDevice->FwVolBlockInstance
|
---|
111 | );
|
---|
112 |
|
---|
113 | return Status;
|
---|
114 | }
|
---|
115 |
|
---|
116 | /**
|
---|
117 | The driver entry point for SMM Firmware Volume Block Driver.
|
---|
118 |
|
---|
119 | The function does the necessary initialization work
|
---|
120 | Firmware Volume Block Driver.
|
---|
121 |
|
---|
122 | @param[in] ImageHandle The firmware allocated handle for the UEFI image.
|
---|
123 | @param[in] SystemTable A pointer to the EFI system table.
|
---|
124 |
|
---|
125 | @retval EFI_SUCCESS This funtion always return EFI_SUCCESS.
|
---|
126 | It will ASSERT on errors.
|
---|
127 |
|
---|
128 | **/
|
---|
129 | EFI_STATUS
|
---|
130 | EFIAPI
|
---|
131 | FvbSmmInitialize (
|
---|
132 | IN EFI_HANDLE ImageHandle,
|
---|
133 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
134 | )
|
---|
135 | {
|
---|
136 | FvbInitialize ();
|
---|
137 |
|
---|
138 | return EFI_SUCCESS;
|
---|
139 | }
|
---|