2 The driver entry point for RamDiskDxe driver.
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "RamDiskImpl.h"
18 // Handle for the EFI_RAM_DISK_PROTOCOL instance
20 EFI_HANDLE mRamDiskHandle
= NULL
;
23 // The EFI_RAM_DISK_PROTOCOL instances that is installed onto the driver
26 EFI_RAM_DISK_PROTOCOL mRamDiskProtocol
= {
32 // RamDiskDxe driver maintains a list of registered RAM disks.
34 LIST_ENTRY RegisteredRamDisks
;
37 // Pointers to the EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL.
39 EFI_ACPI_TABLE_PROTOCOL
*mAcpiTableProtocol
= NULL
;
40 EFI_ACPI_SDT_PROTOCOL
*mAcpiSdtProtocol
= NULL
;
44 Check whether EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL are produced.
45 If both protocols are produced, publish all the reserved memory type RAM
46 disks to the NVDIMM Firmware Interface Table (NFIT).
48 @param[in] Event Event whose notification function is being invoked.
49 @param[in] Context The pointer to the notification function's context,
50 which is implementation-dependent.
62 RAM_DISK_PRIVATE_DATA
*PrivateData
;
64 gBS
->CloseEvent (Event
);
67 // Locate the EFI_ACPI_TABLE_PROTOCOL.
69 Status
= gBS
->LocateProtocol (
70 &gEfiAcpiTableProtocolGuid
,
72 (VOID
**)&mAcpiTableProtocol
74 if (EFI_ERROR (Status
)) {
77 "RamDiskAcpiCheck: Cannot locate the EFI ACPI Table Protocol, "
78 "unable to publish RAM disks to NFIT.\n"
84 // Locate the EFI_ACPI_SDT_PROTOCOL.
86 Status
= gBS
->LocateProtocol (
87 &gEfiAcpiSdtProtocolGuid
,
89 (VOID
**)&mAcpiSdtProtocol
91 if (EFI_ERROR (Status
)) {
94 "RamDiskAcpiCheck: Cannot locate the EFI ACPI Sdt Protocol, "
95 "unable to publish RAM disks to NFIT.\n"
97 mAcpiTableProtocol
= NULL
;
101 EFI_LIST_FOR_EACH (Entry
, &RegisteredRamDisks
) {
102 PrivateData
= RAM_DISK_PRIVATE_FROM_THIS (Entry
);
103 RamDiskPublishNfit (PrivateData
);
109 The entry point for RamDiskDxe driver.
111 @param[in] ImageHandle The image handle of the driver.
112 @param[in] SystemTable The system table.
114 @retval EFI_ALREADY_STARTED The driver already exists in system.
115 @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of
117 @retval EFI_SUCCES All the related protocols are installed on
123 RamDiskDxeEntryPoint (
124 IN EFI_HANDLE ImageHandle
,
125 IN EFI_SYSTEM_TABLE
*SystemTable
129 RAM_DISK_CONFIG_PRIVATE_DATA
*ConfigPrivate
;
130 VOID
*DummyInterface
;
134 // If already started, return.
136 Status
= gBS
->LocateProtocol (
137 &gEfiRamDiskProtocolGuid
,
141 if (!EFI_ERROR (Status
)) {
142 DEBUG ((EFI_D_INFO
, "Driver already started!\n"));
143 return EFI_ALREADY_STARTED
;
147 // Create a private data structure.
149 ConfigPrivate
= AllocateCopyPool (sizeof (RAM_DISK_CONFIG_PRIVATE_DATA
), &mRamDiskConfigPrivateDataTemplate
);
150 if (ConfigPrivate
== NULL
) {
151 return EFI_OUT_OF_RESOURCES
;
155 // Install RAM disk configuration form
157 Status
= InstallRamDiskConfigForm (ConfigPrivate
);
158 if (EFI_ERROR (Status
)) {
163 // Install the EFI_RAM_DISK_PROTOCOL and RAM disk private data onto a
166 Status
= gBS
->InstallMultipleProtocolInterfaces (
168 &gEfiRamDiskProtocolGuid
,
174 if (EFI_ERROR (Status
)) {
179 // Initialize the list of registered RAM disks maintained by the driver
181 InitializeListHead (&RegisteredRamDisks
);
183 Status
= EfiCreateEventReadyToBootEx (
189 ASSERT_EFI_ERROR (Status
);
194 if (ConfigPrivate
!= NULL
) {
195 UninstallRamDiskConfigForm (ConfigPrivate
);
203 Unload the RamDiskDxe driver and its configuration form.
205 @param[in] ImageHandle The driver's image handle.
207 @retval EFI_SUCCESS The RamDiskDxe driver and its configuration
209 @retval Others Failed to unload the form.
215 IN EFI_HANDLE ImageHandle
219 RAM_DISK_CONFIG_PRIVATE_DATA
*ConfigPrivate
;
221 Status
= gBS
->HandleProtocol (
224 (VOID
**) &ConfigPrivate
226 if (EFI_ERROR (Status
)) {
230 ASSERT (ConfigPrivate
->Signature
== RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE
);
233 // Unregister all registered RAM disks
235 UnregisterAllRamDisks ();
237 gBS
->UninstallMultipleProtocolInterfaces (
239 &gEfiRamDiskProtocolGuid
,
246 UninstallRamDiskConfigForm (ConfigPrivate
);