]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDriver.c
MdeModulePkg/UdfDxe: Add type cast to fix build failure in VS tools
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / RamDiskDxe / RamDiskDriver.c
CommitLineData
20752cb8
HW
1/** @file\r
2 The driver entry point for RamDiskDxe driver.\r
3\r
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "RamDiskImpl.h"\r
16\r
17//\r
18// Handle for the EFI_RAM_DISK_PROTOCOL instance\r
19//\r
20EFI_HANDLE mRamDiskHandle = NULL;\r
21\r
22//\r
23// The EFI_RAM_DISK_PROTOCOL instances that is installed onto the driver\r
24// handle\r
25//\r
26EFI_RAM_DISK_PROTOCOL mRamDiskProtocol = {\r
27 RamDiskRegister,\r
28 RamDiskUnregister\r
29};\r
30\r
31//\r
32// RamDiskDxe driver maintains a list of registered RAM disks.\r
33//\r
34LIST_ENTRY RegisteredRamDisks;\r
20752cb8 35\r
07a3fecd
HW
36//\r
37// Pointers to the EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL.\r
38//\r
39EFI_ACPI_TABLE_PROTOCOL *mAcpiTableProtocol = NULL;\r
40EFI_ACPI_SDT_PROTOCOL *mAcpiSdtProtocol = NULL;\r
41\r
42\r
43/**\r
44 Check whether EFI_ACPI_TABLE_PROTOCOL and EFI_ACPI_SDT_PROTOCOL are produced.\r
45 If both protocols are produced, publish all the reserved memory type RAM\r
46 disks to the NVDIMM Firmware Interface Table (NFIT).\r
47\r
48 @param[in] Event Event whose notification function is being invoked.\r
49 @param[in] Context The pointer to the notification function's context,\r
50 which is implementation-dependent.\r
51\r
52**/\r
53VOID\r
54EFIAPI\r
55RamDiskAcpiCheck (\r
56 IN EFI_EVENT Event,\r
57 IN VOID *Context\r
58 )\r
59{\r
60 EFI_STATUS Status;\r
61 LIST_ENTRY *Entry;\r
62 RAM_DISK_PRIVATE_DATA *PrivateData;\r
63\r
64 gBS->CloseEvent (Event);\r
65\r
66 //\r
67 // Locate the EFI_ACPI_TABLE_PROTOCOL.\r
68 //\r
69 Status = gBS->LocateProtocol (\r
70 &gEfiAcpiTableProtocolGuid,\r
71 NULL,\r
72 (VOID **)&mAcpiTableProtocol\r
73 );\r
74 if (EFI_ERROR (Status)) {\r
75 DEBUG ((\r
76 EFI_D_INFO,\r
76874be3 77 "RamDiskAcpiCheck: Cannot locate the EFI ACPI Table Protocol, "\r
07a3fecd
HW
78 "unable to publish RAM disks to NFIT.\n"\r
79 ));\r
80 return;\r
81 }\r
82\r
83 //\r
84 // Locate the EFI_ACPI_SDT_PROTOCOL.\r
85 //\r
86 Status = gBS->LocateProtocol (\r
87 &gEfiAcpiSdtProtocolGuid,\r
88 NULL,\r
89 (VOID **)&mAcpiSdtProtocol\r
90 );\r
91 if (EFI_ERROR (Status)) {\r
92 DEBUG ((\r
93 EFI_D_INFO,\r
76874be3 94 "RamDiskAcpiCheck: Cannot locate the EFI ACPI Sdt Protocol, "\r
07a3fecd
HW
95 "unable to publish RAM disks to NFIT.\n"\r
96 ));\r
97 mAcpiTableProtocol = NULL;\r
98 return;\r
99 }\r
100\r
101 EFI_LIST_FOR_EACH (Entry, &RegisteredRamDisks) {\r
102 PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry);\r
103 RamDiskPublishNfit (PrivateData);\r
104 }\r
105}\r
106\r
20752cb8
HW
107\r
108/**\r
109 The entry point for RamDiskDxe driver.\r
110\r
111 @param[in] ImageHandle The image handle of the driver.\r
112 @param[in] SystemTable The system table.\r
113\r
114 @retval EFI_ALREADY_STARTED The driver already exists in system.\r
115 @retval EFI_OUT_OF_RESOURCES Fail to execute entry point due to lack of\r
116 resources.\r
117 @retval EFI_SUCCES All the related protocols are installed on\r
118 the driver.\r
119\r
120**/\r
121EFI_STATUS\r
122EFIAPI\r
123RamDiskDxeEntryPoint (\r
124 IN EFI_HANDLE ImageHandle,\r
125 IN EFI_SYSTEM_TABLE *SystemTable\r
126 )\r
127{\r
128 EFI_STATUS Status;\r
129 RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivate;\r
130 VOID *DummyInterface;\r
07a3fecd 131 EFI_EVENT Event;\r
20752cb8
HW
132\r
133 //\r
134 // If already started, return.\r
135 //\r
136 Status = gBS->LocateProtocol (\r
137 &gEfiRamDiskProtocolGuid,\r
138 NULL,\r
139 &DummyInterface\r
140 );\r
141 if (!EFI_ERROR (Status)) {\r
142 DEBUG ((EFI_D_INFO, "Driver already started!\n"));\r
143 return EFI_ALREADY_STARTED;\r
144 }\r
145\r
146 //\r
147 // Create a private data structure.\r
148 //\r
149 ConfigPrivate = AllocateCopyPool (sizeof (RAM_DISK_CONFIG_PRIVATE_DATA), &mRamDiskConfigPrivateDataTemplate);\r
150 if (ConfigPrivate == NULL) {\r
151 return EFI_OUT_OF_RESOURCES;\r
152 }\r
153\r
154 //\r
155 // Install RAM disk configuration form\r
156 //\r
157 Status = InstallRamDiskConfigForm (ConfigPrivate);\r
158 if (EFI_ERROR (Status)) {\r
159 goto ErrorExit;\r
160 }\r
161\r
162 //\r
163 // Install the EFI_RAM_DISK_PROTOCOL and RAM disk private data onto a\r
164 // new handle\r
165 //\r
166 Status = gBS->InstallMultipleProtocolInterfaces (\r
167 &mRamDiskHandle,\r
168 &gEfiRamDiskProtocolGuid,\r
169 &mRamDiskProtocol,\r
170 &gEfiCallerIdGuid,\r
171 ConfigPrivate,\r
172 NULL\r
173 );\r
174 if (EFI_ERROR (Status)) {\r
175 goto ErrorExit;\r
176 }\r
177\r
178 //\r
179 // Initialize the list of registered RAM disks maintained by the driver\r
180 //\r
181 InitializeListHead (&RegisteredRamDisks);\r
182\r
07a3fecd
HW
183 Status = EfiCreateEventReadyToBootEx (\r
184 TPL_CALLBACK,\r
185 RamDiskAcpiCheck,\r
186 NULL,\r
187 &Event\r
188 );\r
189 ASSERT_EFI_ERROR (Status);\r
190\r
20752cb8
HW
191 return EFI_SUCCESS;\r
192\r
193ErrorExit:\r
194 if (ConfigPrivate != NULL) {\r
195 UninstallRamDiskConfigForm (ConfigPrivate);\r
196 }\r
197\r
198 return Status;\r
199}\r
200\r
201\r
202/**\r
203 Unload the RamDiskDxe driver and its configuration form.\r
204\r
205 @param[in] ImageHandle The driver's image handle.\r
206\r
207 @retval EFI_SUCCESS The RamDiskDxe driver and its configuration\r
208 form is unloaded.\r
209 @retval Others Failed to unload the form.\r
210\r
211**/\r
212EFI_STATUS\r
213EFIAPI\r
214RamDiskDxeUnload (\r
215 IN EFI_HANDLE ImageHandle\r
216 )\r
217{\r
218 EFI_STATUS Status;\r
219 RAM_DISK_CONFIG_PRIVATE_DATA *ConfigPrivate;\r
220\r
221 Status = gBS->HandleProtocol (\r
222 mRamDiskHandle,\r
223 &gEfiCallerIdGuid,\r
224 (VOID **) &ConfigPrivate\r
225 );\r
226 if (EFI_ERROR (Status)) {\r
227 return Status;\r
228 }\r
229\r
230 ASSERT (ConfigPrivate->Signature == RAM_DISK_CONFIG_PRIVATE_DATA_SIGNATURE);\r
231\r
232 //\r
233 // Unregister all registered RAM disks\r
234 //\r
235 UnregisterAllRamDisks ();\r
236\r
237 gBS->UninstallMultipleProtocolInterfaces (\r
238 mRamDiskHandle,\r
239 &gEfiRamDiskProtocolGuid,\r
240 &mRamDiskProtocol,\r
241 &gEfiCallerIdGuid,\r
242 ConfigPrivate,\r
243 NULL\r
244 );\r
245\r
246 UninstallRamDiskConfigForm (ConfigPrivate);\r
247\r
248 return EFI_SUCCESS;\r
249}\r