2 The driver entry point for RamDiskDxe driver.
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "RamDiskImpl.h"
12 // Handle for the EFI_RAM_DISK_PROTOCOL instance
14 EFI_HANDLE mRamDiskHandle
= NULL
;
17 // The EFI_RAM_DISK_PROTOCOL instances that is installed onto the driver
20 EFI_RAM_DISK_PROTOCOL mRamDiskProtocol
= {
26 // RamDiskDxe driver maintains a list of registered RAM disks.
28 LIST_ENTRY RegisteredRamDisks
;
31 // Pointers to the EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL.
33 EFI_ACPI_TABLE_PROTOCOL
*mAcpiTableProtocol
= NULL
;
34 EFI_ACPI_SDT_PROTOCOL
*mAcpiSdtProtocol
= NULL
;
38 Check whether EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL are produced.
39 If both protocols are produced, publish all the reserved memory type RAM
40 disks to the NVDIMM Firmware Interface Table (NFIT).
42 @param[in] Event Event whose notification function is being invoked.
43 @param[in] Context The pointer to the notification function's context,
44 which is implementation-dependent.
56 RAM_DISK_PRIVATE_DATA
*PrivateData
;
58 gBS
->CloseEvent (Event
);
61 // Locate the EFI_ACPI_TABLE_PROTOCOL.
63 Status
= gBS
->LocateProtocol (
64 &gEfiAcpiTableProtocolGuid
,
66 (VOID
**)&mAcpiTableProtocol
68 if (EFI_ERROR (Status
)) {
71 "RamDiskAcpiCheck: Cannot locate the EFI ACPI Table Protocol, "
72 "unable to publish RAM disks to NFIT.\n"
78 // Locate the EFI_ACPI_SDT_PROTOCOL.
80 Status
= gBS
->LocateProtocol (
81 &gEfiAcpiSdtProtocolGuid
,
83 (VOID
**)&mAcpiSdtProtocol
85 if (EFI_ERROR (Status
)) {
88 "RamDiskAcpiCheck: Cannot locate the EFI ACPI Sdt Protocol, "
89 "unable to publish RAM disks to NFIT.\n"
91 mAcpiTableProtocol
= NULL
;
95 EFI_LIST_FOR_EACH (Entry
, &RegisteredRamDisks
) {
96 PrivateData
= RAM_DISK_PRIVATE_FROM_THIS (Entry
);
97 RamDiskPublishNfit (PrivateData
);
103 The entry point for RamDiskDxe driver.
105 @param[in] ImageHandle The image handle of the driver.
106 @param[in] SystemTable The system table.
108 @retval EFI_ALREADY_STARTED The driver already exists in system.
109 @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of
111 @retval EFI_SUCCES All the related protocols are installed on
117 RamDiskDxeEntryPoint (
118 IN EFI_HANDLE ImageHandle
,
119 IN EFI_SYSTEM_TABLE
*SystemTable
123 RAM_DISK_CONFIG_PRIVATE_DATA
*ConfigPrivate
;
124 VOID
*DummyInterface
;
128 // If already started, return.
130 Status
= gBS
->LocateProtocol (
131 &gEfiRamDiskProtocolGuid
,
135 if (!EFI_ERROR (Status
)) {
136 DEBUG ((EFI_D_INFO
, "Driver already started!\n"));
137 return EFI_ALREADY_STARTED
;
141 // Create a private data structure.
143 ConfigPrivate
= AllocateCopyPool (sizeof (RAM_DISK_CONFIG_PRIVATE_DATA
), &mRamDiskConfigPrivateDataTemplate
);
144 if (ConfigPrivate
== NULL
) {
145 return EFI_OUT_OF_RESOURCES
;
149 // Install RAM disk configuration form
151 Status
= InstallRamDiskConfigForm (ConfigPrivate
);
152 if (EFI_ERROR (Status
)) {
157 // Install the EFI_RAM_DISK_PROTOCOL and RAM disk private data onto a
160 Status
= gBS
->InstallMultipleProtocolInterfaces (
162 &gEfiRamDiskProtocolGuid
,
168 if (EFI_ERROR (Status
)) {
173 // Initialize the list of registered RAM disks maintained by the driver
175 InitializeListHead (&RegisteredRamDisks
);
177 Status
= EfiCreateEventReadyToBootEx (
183 ASSERT_EFI_ERROR (Status
);
188 if (ConfigPrivate
!= NULL
) {
189 UninstallRamDiskConfigForm (ConfigPrivate
);
197 Unload the RamDiskDxe driver and its configuration form.
199 @param[in] ImageHandle The driver's image handle.
201 @retval EFI_SUCCESS The RamDiskDxe driver and its configuration
203 @retval Others Failed to unload the form.
209 IN EFI_HANDLE ImageHandle
213 RAM_DISK_CONFIG_PRIVATE_DATA
*ConfigPrivate
;
215 Status
= gBS
->HandleProtocol (
218 (VOID
**) &ConfigPrivate
220 if (EFI_ERROR (Status
)) {
224 ASSERT (ConfigPrivate
->Signature
== RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE
);
227 // Unregister all registered RAM disks
229 UnregisterAllRamDisks ();
231 gBS
->UninstallMultipleProtocolInterfaces (
233 &gEfiRamDiskProtocolGuid
,
240 UninstallRamDiskConfigForm (ConfigPrivate
);