]> git.proxmox.com Git - mirror_edk2.git/blame - Vlv2TbltDevicePkg/FvbRuntimeDxe/FvbServiceSmm.c
MdeModulePkg: Fix use-after-free error in InstallConfigurationTable()
[mirror_edk2.git] / Vlv2TbltDevicePkg / FvbRuntimeDxe / FvbServiceSmm.c
CommitLineData
3cbfba02
DW
1/** @file\r
2 SMM Firmware Volume Block Driver for Lakeport Platform.\r
3\r
4 Firmware volume block driver for FWH or SPI device.\r
5 It depends on which Flash Device Library to be linked with this driver.\r
6\r
7Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
8 \r\r
9 This program and the accompanying materials are licensed and made available under\r\r
10 the terms and conditions of the BSD License that accompanies this distribution. \r\r
11 The full text of the license may be found at \r\r
12 http://opensource.org/licenses/bsd-license.php. \r\r
13 \r\r
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r\r
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r\r
16 \r\r
17\r
18**/\r
19\r
20#include <PiSmm.h>\r
21#include <Library/SmmServicesTableLib.h>\r
22#include "FvbSmmCommon.h"\r
23#include "FvbService.h"\r
24\r
25/**\r
26 The function installs EFI_SMM_FIRMWARE_VOLUME_BLOCK protocol\r
27 for each FV in the system.\r
28\r
29 @param[in] FwhInstance The pointer to a FW volume instance structure,\r
30 which contains the information about one FV.\r
31 @param[in] InstanceNum The instance number which can be used as a ID\r
32 to locate this FwhInstance in other functions.\r
33\r
34 @retval VOID\r
35\r
36**/\r
37VOID\r
38InstallFvbProtocol (\r
39 IN EFI_FW_VOL_INSTANCE *FwhInstance,\r
40 IN UINTN InstanceNum\r
41 )\r
42{\r
43 EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
44 EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
45 EFI_STATUS Status;\r
46 EFI_HANDLE FvbHandle;\r
47\r
48 FvbDevice = (EFI_FW_VOL_BLOCK_DEVICE *) AllocateRuntimeCopyPool (\r
49 sizeof (EFI_FW_VOL_BLOCK_DEVICE),\r
50 &mFvbDeviceTemplate\r
51 );\r
52 ASSERT (FvbDevice != NULL);\r
53\r
54 FvbDevice->Instance = InstanceNum;\r
55 FwVolHeader = &FwhInstance->VolumeHeader;\r
56\r
57 //\r
58 // Set up the devicepath.\r
59 //\r
60 if (FwVolHeader->ExtHeaderOffset == 0) {\r
61 //\r
62 // FV does not contains extension header, then produce MEMMAP_DEVICE_PATH.\r
63 //\r
64 FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateRuntimeCopyPool (sizeof (FV_MEMMAP_DEVICE_PATH), &mFvMemmapDevicePathTemplate);\r
65 ((FV_MEMMAP_DEVICE_PATH *) FvbDevice->DevicePath)->MemMapDevPath.StartingAddress = FwhInstance->FvBase;\r
66 ((FV_MEMMAP_DEVICE_PATH *) FvbDevice->DevicePath)->MemMapDevPath.EndingAddress = FwhInstance->FvBase + FwVolHeader->FvLength - 1;\r
67 } else {\r
68 FvbDevice->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) AllocateRuntimeCopyPool (sizeof (FV_PIWG_DEVICE_PATH), &mFvPIWGDevicePathTemplate);\r
69 CopyGuid (\r
70 &((FV_PIWG_DEVICE_PATH *)FvbDevice->DevicePath)->FvDevPath.FvName,\r
71 (GUID *)(UINTN)(FwhInstance->FvBase + FwVolHeader->ExtHeaderOffset)\r
72 );\r
73 }\r
74\r
75 //\r
76 // Install the SMM Firmware Volume Block Protocol and Device Path Protocol.\r
77 //\r
78 FvbHandle = NULL;\r
79 Status = gSmst->SmmInstallProtocolInterface (\r
80 &FvbHandle,\r
81 &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r
82 EFI_NATIVE_INTERFACE,\r
83 &FvbDevice->FwVolBlockInstance\r
84 );\r
85 ASSERT_EFI_ERROR (Status);\r
86\r
87 Status = gSmst->SmmInstallProtocolInterface (\r
88 &FvbHandle,\r
89 &gEfiDevicePathProtocolGuid,\r
90 EFI_NATIVE_INTERFACE,\r
91 FvbDevice->DevicePath\r
92 );\r
93 ASSERT_EFI_ERROR (Status);\r
94\r
95 //\r
96 // Notify the Fvb wrapper driver SMM fvb is ready.\r
97 //\r
98 FvbHandle = NULL;\r
99 Status = gBS->InstallProtocolInterface (\r
100 &FvbHandle,\r
101 &gEfiSmmFirmwareVolumeBlockProtocolGuid,\r
102 EFI_NATIVE_INTERFACE,\r
103 &FvbDevice->FwVolBlockInstance\r
104 );\r
105}\r
106\r
107\r
108/**\r
109 The driver entry point for SMM Firmware Volume Block Driver.\r
110\r
111 The function does the necessary initialization work\r
112 Firmware Volume Block Driver.\r
113\r
114 @param[in] ImageHandle The firmware allocated handle for the UEFI image.\r
115 @param[in] SystemTable A pointer to the EFI system table.\r
116\r
117 @retval EFI_SUCCESS This funtion always return EFI_SUCCESS.\r
118 It will ASSERT on errors.\r
119\r
120**/\r
121EFI_STATUS\r
122EFIAPI\r
123FvbSmmInitialize (\r
124 IN EFI_HANDLE ImageHandle,\r
125 IN EFI_SYSTEM_TABLE *SystemTable\r
126 )\r
127{\r
128 FvbInitialize ();\r
129\r
130 return EFI_SUCCESS;\r
131}\r
132\r