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