TianoCore EDK2 master
Loading...
Searching...
No Matches
RamDiskDriver.c
Go to the documentation of this file.
1
10#include "RamDiskImpl.h"
11
12//
13// Handle for the EFI_RAM_DISK_PROTOCOL instance
14//
15EFI_HANDLE mRamDiskHandle = NULL;
16
17//
18// The EFI_RAM_DISK_PROTOCOL instances that is installed onto the driver
19// handle
20//
21EFI_RAM_DISK_PROTOCOL mRamDiskProtocol = {
24};
25
26//
27// RamDiskDxe driver maintains a list of registered RAM disks.
28//
29LIST_ENTRY RegisteredRamDisks;
30
31//
32// Pointers to the EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL.
33//
34EFI_ACPI_TABLE_PROTOCOL *mAcpiTableProtocol = NULL;
35EFI_ACPI_SDT_PROTOCOL *mAcpiSdtProtocol = NULL;
36
47VOID
48EFIAPI
50 IN EFI_EVENT Event,
51 IN VOID *Context
52 )
53{
54 EFI_STATUS Status;
55 LIST_ENTRY *Entry;
56 RAM_DISK_PRIVATE_DATA *PrivateData;
57
58 gBS->CloseEvent (Event);
59
60 //
61 // Locate the EFI_ACPI_TABLE_PROTOCOL.
62 //
63 Status = gBS->LocateProtocol (
64 &gEfiAcpiTableProtocolGuid,
65 NULL,
66 (VOID **)&mAcpiTableProtocol
67 );
68 if (EFI_ERROR (Status)) {
69 DEBUG ((
70 DEBUG_INFO,
71 "RamDiskAcpiCheck: Cannot locate the EFI ACPI Table Protocol, "
72 "unable to publish RAM disks to NFIT.\n"
73 ));
74 return;
75 }
76
77 //
78 // Locate the EFI_ACPI_SDT_PROTOCOL.
79 //
80 Status = gBS->LocateProtocol (
81 &gEfiAcpiSdtProtocolGuid,
82 NULL,
83 (VOID **)&mAcpiSdtProtocol
84 );
85 if (EFI_ERROR (Status)) {
86 DEBUG ((
87 DEBUG_INFO,
88 "RamDiskAcpiCheck: Cannot locate the EFI ACPI Sdt Protocol, "
89 "unable to publish RAM disks to NFIT.\n"
90 ));
91 mAcpiTableProtocol = NULL;
92 return;
93 }
94
95 BASE_LIST_FOR_EACH (Entry, &RegisteredRamDisks) {
96 PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);
97 RamDiskPublishNfit (PrivateData);
98 }
99}
100
115EFIAPI
117 IN EFI_HANDLE ImageHandle,
118 IN EFI_SYSTEM_TABLE *SystemTable
119 )
120{
121 EFI_STATUS Status;
122 RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivate;
123 VOID *DummyInterface;
124 EFI_EVENT Event;
125
126 //
127 // If already started, return.
128 //
129 Status = gBS->LocateProtocol (
131 NULL,
132 &DummyInterface
133 );
134 if (!EFI_ERROR (Status)) {
135 DEBUG ((DEBUG_INFO, "Driver already started!\n"));
136 return EFI_ALREADY_STARTED;
137 }
138
139 //
140 // Create a private data structure.
141 //
142 ConfigPrivate = AllocateCopyPool (sizeof (RAM_DISK_CONFIG_PRIVATE_DATA), &mRamDiskConfigPrivateDataTemplate);
143 if (ConfigPrivate == NULL) {
144 return EFI_OUT_OF_RESOURCES;
145 }
146
147 //
148 // Install RAM disk configuration form
149 //
150 Status = InstallRamDiskConfigForm (ConfigPrivate);
151 if (EFI_ERROR (Status)) {
152 goto ErrorExit;
153 }
154
155 //
156 // Initialize the list of registered RAM disks maintained by the driver
157 // before installing the protocol
158 //
159 InitializeListHead (&RegisteredRamDisks);
160
161 //
162 // Install the EFI_RAM_DISK_PROTOCOL and RAM disk private data onto a
163 // new handle
164 //
165 Status = gBS->InstallMultipleProtocolInterfaces (
166 &mRamDiskHandle,
168 &mRamDiskProtocol,
169 &gEfiCallerIdGuid,
170 ConfigPrivate,
171 NULL
172 );
173 if (EFI_ERROR (Status)) {
174 goto ErrorExit;
175 }
176
178 TPL_CALLBACK,
180 NULL,
181 &Event
182 );
183 ASSERT_EFI_ERROR (Status);
184
185 return EFI_SUCCESS;
186
187ErrorExit:
188 if (ConfigPrivate != NULL) {
189 UninstallRamDiskConfigForm (ConfigPrivate);
190 }
191
192 return Status;
193}
194
206EFIAPI
208 IN EFI_HANDLE ImageHandle
209 )
210{
211 EFI_STATUS Status;
212 RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivate;
213
214 Status = gBS->HandleProtocol (
215 mRamDiskHandle,
216 &gEfiCallerIdGuid,
217 (VOID **)&ConfigPrivate
218 );
219 if (EFI_ERROR (Status)) {
220 return Status;
221 }
222
223 ASSERT (ConfigPrivate->Signature == RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE);
224
225 //
226 // Unregister all registered RAM disks
227 //
229
230 gBS->UninstallMultipleProtocolInterfaces (
231 mRamDiskHandle,
233 &mRamDiskProtocol,
234 &gEfiCallerIdGuid,
235 ConfigPrivate,
236 NULL
237 );
238
239 UninstallRamDiskConfigForm (ConfigPrivate);
240
241 return EFI_SUCCESS;
242}
#define BASE_LIST_FOR_EACH(Entry, ListHead)
Definition: BaseLib.h:2913
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
Definition: LinkedList.c:182
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_GUID gEfiRamDiskProtocolGuid
EFI_STATUS EFIAPI RamDiskDxeUnload(IN EFI_HANDLE ImageHandle)
VOID EFIAPI RamDiskAcpiCheck(IN EFI_EVENT Event, IN VOID *Context)
Definition: RamDiskDriver.c:49
EFI_STATUS EFIAPI RamDiskDxeEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
VOID UninstallRamDiskConfigForm(IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivateData)
Definition: RamDiskImpl.c:122
EFI_STATUS InstallRamDiskConfigForm(IN OUT RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivateData)
Definition: RamDiskImpl.c:62
VOID UnregisterAllRamDisks(VOID)
Definition: RamDiskImpl.c:157
EFI_STATUS RamDiskPublishNfit(IN RAM_DISK_PRIVATE_DATA *PrivateData)
EFI_STATUS EFIAPI RamDiskRegister(IN UINT64 RamDiskBase, IN UINT64 RamDiskSize, IN EFI_GUID *RamDiskType, IN EFI_DEVICE_PATH *ParentDevicePath OPTIONAL, OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath)
EFI_STATUS EFIAPI RamDiskUnregister(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI EfiCreateEventReadyToBootEx(IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL, IN VOID *NotifyContext OPTIONAL, OUT EFI_EVENT *ReadyToBootEvent)
Definition: UefiNotTiano.c:164