Commit | Line | Data |
---|---|---|
adbcbf8f | 1 | /** @file\r |
2 | Partition driver that produces logical BlockIo devices from a physical\r | |
3 | BlockIo device. The logical BlockIo devices are based on the format\r | |
4 | of the raw block devices media. Currently "El Torito CD-ROM", Legacy\r | |
5 | MBR, and GPT partition schemes are supported.\r | |
6 | \r | |
67f802ed | 7 | Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r |
e5eed7d3 | 8 | This program and the accompanying materials\r |
f42be642 | 9 | are licensed and made available under the terms and conditions of the BSD License\r |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
adbcbf8f | 12 | \r |
f42be642 | 13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
adbcbf8f | 15 | \r |
16 | **/\r | |
17 | \r | |
18 | \r | |
19 | #include "Partition.h"\r | |
20 | \r | |
21 | //\r | |
ff61847d | 22 | // Partition Driver Global Variables.\r |
adbcbf8f | 23 | //\r |
24 | EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding = {\r | |
25 | PartitionDriverBindingSupported,\r | |
26 | PartitionDriverBindingStart,\r | |
27 | PartitionDriverBindingStop,\r | |
c86b273d RN |
28 | //\r |
29 | // Grub4Dos copies the BPB of the first partition to the MBR. If the \r | |
30 | // DriverBindingStart() of the Fat driver gets run before that of Partition \r | |
31 | // driver only the first partition can be recognized.\r | |
32 | // Let the driver binding version of Partition driver be higher than that of\r | |
33 | // Fat driver to make sure the DriverBindingStart() of the Partition driver\r | |
34 | // gets run before that of Fat driver so that all the partitions can be recognized.\r | |
35 | //\r | |
36 | 0xb,\r | |
adbcbf8f | 37 | NULL,\r |
38 | NULL\r | |
39 | };\r | |
40 | \r | |
ff61847d | 41 | //\r |
48557c65 | 42 | // Prioritized function list to detect partition table. \r |
ff61847d | 43 | //\r |
adbcbf8f | 44 | PARTITION_DETECT_ROUTINE mPartitionDetectRoutineTable[] = {\r |
45 | PartitionInstallGptChildHandles,\r | |
46 | PartitionInstallElToritoChildHandles,\r | |
47 | PartitionInstallMbrChildHandles,\r | |
48 | NULL\r | |
49 | };\r | |
50 | \r | |
adbcbf8f | 51 | /**\r |
52 | Test to see if this driver supports ControllerHandle. Any ControllerHandle\r | |
490b5ea1 | 53 | than contains a BlockIo and DiskIo protocol or a BlockIo2 protocol can be\r |
54 | supported.\r | |
adbcbf8f | 55 | \r |
490b5ea1 | 56 | @param[in] This Protocol instance pointer.\r |
57 | @param[in] ControllerHandle Handle of device to test.\r | |
58 | @param[in] RemainingDevicePath Optional parameter use to pick a specific child\r | |
59 | device to start.\r | |
adbcbf8f | 60 | \r |
61 | @retval EFI_SUCCESS This driver supports this device\r | |
62 | @retval EFI_ALREADY_STARTED This driver is already running on this device\r | |
63 | @retval other This driver does not support this device\r | |
64 | \r | |
65 | **/\r | |
66 | EFI_STATUS\r | |
67 | EFIAPI\r | |
68 | PartitionDriverBindingSupported (\r | |
69 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
70 | IN EFI_HANDLE ControllerHandle,\r | |
71 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
72 | )\r | |
73 | {\r | |
74 | EFI_STATUS Status;\r | |
75 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
76 | EFI_DISK_IO_PROTOCOL *DiskIo;\r | |
77 | EFI_DEV_PATH *Node;\r | |
78 | \r | |
9be29006 | 79 | //\r |
80 | // Check RemainingDevicePath validation\r | |
81 | //\r | |
adbcbf8f | 82 | if (RemainingDevicePath != NULL) {\r |
9be29006 | 83 | //\r |
84 | // Check if RemainingDevicePath is the End of Device Path Node, \r | |
85 | // if yes, go on checking other conditions\r | |
86 | //\r | |
87 | if (!IsDevicePathEnd (RemainingDevicePath)) {\r | |
88 | //\r | |
89 | // If RemainingDevicePath isn't the End of Device Path Node,\r | |
90 | // check its validation\r | |
91 | //\r | |
92 | Node = (EFI_DEV_PATH *) RemainingDevicePath;\r | |
93 | if (Node->DevPath.Type != MEDIA_DEVICE_PATH ||\r | |
adbcbf8f | 94 | Node->DevPath.SubType != MEDIA_HARDDRIVE_DP ||\r |
9be29006 | 95 | DevicePathNodeLength (&Node->DevPath) != sizeof (HARDDRIVE_DEVICE_PATH)) {\r |
490b5ea1 | 96 | return EFI_UNSUPPORTED;\r |
9be29006 | 97 | }\r |
adbcbf8f | 98 | }\r |
99 | }\r | |
9be29006 | 100 | \r |
adbcbf8f | 101 | //\r |
102 | // Open the IO Abstraction(s) needed to perform the supported test\r | |
103 | //\r | |
104 | Status = gBS->OpenProtocol (\r | |
105 | ControllerHandle,\r | |
9be29006 | 106 | &gEfiDiskIoProtocolGuid,\r |
107 | (VOID **) &DiskIo,\r | |
adbcbf8f | 108 | This->DriverBindingHandle,\r |
109 | ControllerHandle,\r | |
110 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
111 | );\r | |
112 | if (Status == EFI_ALREADY_STARTED) {\r | |
113 | return EFI_SUCCESS;\r | |
114 | }\r | |
adbcbf8f | 115 | if (EFI_ERROR (Status)) {\r |
116 | return Status;\r | |
117 | }\r | |
118 | //\r | |
119 | // Close the I/O Abstraction(s) used to perform the supported test\r | |
120 | //\r | |
121 | gBS->CloseProtocol (\r | |
ff61847d | 122 | ControllerHandle,\r |
9be29006 | 123 | &gEfiDiskIoProtocolGuid,\r |
ff61847d | 124 | This->DriverBindingHandle,\r |
125 | ControllerHandle\r | |
126 | );\r | |
adbcbf8f | 127 | \r |
128 | //\r | |
9be29006 | 129 | // Open the EFI Device Path protocol needed to perform the supported test\r |
adbcbf8f | 130 | //\r |
131 | Status = gBS->OpenProtocol (\r | |
132 | ControllerHandle,\r | |
9be29006 | 133 | &gEfiDevicePathProtocolGuid,\r |
134 | (VOID **) &ParentDevicePath,\r | |
adbcbf8f | 135 | This->DriverBindingHandle,\r |
136 | ControllerHandle,\r | |
137 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
138 | );\r | |
139 | if (Status == EFI_ALREADY_STARTED) {\r | |
140 | return EFI_SUCCESS;\r | |
141 | }\r | |
142 | \r | |
143 | if (EFI_ERROR (Status)) {\r | |
144 | return Status;\r | |
145 | }\r | |
9be29006 | 146 | \r |
adbcbf8f | 147 | //\r |
9be29006 | 148 | // Close protocol, don't use device path protocol in the Support() function\r |
adbcbf8f | 149 | //\r |
150 | gBS->CloseProtocol (\r | |
151 | ControllerHandle,\r | |
9be29006 | 152 | &gEfiDevicePathProtocolGuid,\r |
adbcbf8f | 153 | This->DriverBindingHandle,\r |
154 | ControllerHandle\r | |
155 | );\r | |
156 | \r | |
157 | //\r | |
158 | // Open the IO Abstraction(s) needed to perform the supported test\r | |
159 | //\r | |
160 | Status = gBS->OpenProtocol (\r | |
161 | ControllerHandle,\r | |
162 | &gEfiBlockIoProtocolGuid,\r | |
163 | NULL,\r | |
164 | This->DriverBindingHandle,\r | |
165 | ControllerHandle,\r | |
166 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
167 | );\r | |
490b5ea1 | 168 | if (EFI_ERROR (Status)) {\r |
21e1018b | 169 | return Status;\r |
170 | }\r | |
171 | \r | |
490b5ea1 | 172 | return EFI_SUCCESS; \r |
adbcbf8f | 173 | }\r |
174 | \r | |
adbcbf8f | 175 | /**\r |
490b5ea1 | 176 | Start this driver on ControllerHandle by opening a Block IO or a Block IO2\r |
177 | or both, and Disk IO protocol, reading Device Path, and creating a child\r | |
178 | handle with a Disk IO and device path protocol.\r | |
adbcbf8f | 179 | \r |
490b5ea1 | 180 | @param[in] This Protocol instance pointer.\r |
181 | @param[in] ControllerHandle Handle of device to bind driver to\r | |
182 | @param[in] RemainingDevicePath Optional parameter use to pick a specific child\r | |
183 | device to start.\r | |
adbcbf8f | 184 | \r |
185 | @retval EFI_SUCCESS This driver is added to ControllerHandle\r | |
186 | @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r | |
187 | @retval other This driver does not support this device\r | |
188 | \r | |
189 | **/\r | |
190 | EFI_STATUS\r | |
191 | EFIAPI\r | |
192 | PartitionDriverBindingStart (\r | |
193 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
194 | IN EFI_HANDLE ControllerHandle,\r | |
195 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
196 | )\r | |
197 | {\r | |
198 | EFI_STATUS Status;\r | |
199 | EFI_STATUS OpenStatus;\r | |
200 | EFI_BLOCK_IO_PROTOCOL *BlockIo;\r | |
490b5ea1 | 201 | EFI_BLOCK_IO2_PROTOCOL *BlockIo2;\r |
adbcbf8f | 202 | EFI_DISK_IO_PROTOCOL *DiskIo;\r |
203 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
204 | PARTITION_DETECT_ROUTINE *Routine;\r | |
9afd0514 | 205 | BOOLEAN MediaPresent;\r |
15cc67e6 | 206 | EFI_TPL OldTpl;\r |
adbcbf8f | 207 | \r |
21e1018b | 208 | BlockIo2 = NULL;\r |
15cc67e6 | 209 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK); \r |
9be29006 | 210 | //\r |
211 | // Check RemainingDevicePath validation\r | |
212 | //\r | |
213 | if (RemainingDevicePath != NULL) {\r | |
214 | //\r | |
215 | // Check if RemainingDevicePath is the End of Device Path Node, \r | |
216 | // if yes, return EFI_SUCCESS\r | |
217 | //\r | |
218 | if (IsDevicePathEnd (RemainingDevicePath)) {\r | |
15cc67e6 | 219 | Status = EFI_SUCCESS;\r |
220 | goto Exit;\r | |
9be29006 | 221 | }\r |
222 | }\r | |
223 | \r | |
490b5ea1 | 224 | //\r |
225 | // Try to open BlockIO and BlockIO2. If BlockIO would be opened, continue,\r | |
226 | // otherwise, return error.\r | |
227 | //\r | |
adbcbf8f | 228 | Status = gBS->OpenProtocol (\r |
229 | ControllerHandle,\r | |
230 | &gEfiBlockIoProtocolGuid,\r | |
231 | (VOID **) &BlockIo,\r | |
232 | This->DriverBindingHandle,\r | |
233 | ControllerHandle,\r | |
234 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
235 | );\r | |
236 | if (EFI_ERROR (Status)) {\r | |
15cc67e6 | 237 | goto Exit;\r |
adbcbf8f | 238 | }\r |
490b5ea1 | 239 | \r |
240 | Status = gBS->OpenProtocol (\r | |
241 | ControllerHandle,\r | |
242 | &gEfiBlockIo2ProtocolGuid,\r | |
243 | (VOID **) &BlockIo2,\r | |
244 | This->DriverBindingHandle,\r | |
245 | ControllerHandle,\r | |
246 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
247 | );\r | |
490b5ea1 | 248 | \r |
adbcbf8f | 249 | //\r |
490b5ea1 | 250 | // Get the Device Path Protocol on ControllerHandle's handle.\r |
adbcbf8f | 251 | //\r |
252 | Status = gBS->OpenProtocol (\r | |
253 | ControllerHandle,\r | |
254 | &gEfiDevicePathProtocolGuid,\r | |
255 | (VOID **) &ParentDevicePath,\r | |
256 | This->DriverBindingHandle,\r | |
257 | ControllerHandle,\r | |
258 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
259 | );\r | |
260 | if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r | |
15cc67e6 | 261 | goto Exit;\r |
adbcbf8f | 262 | }\r |
263 | \r | |
264 | Status = gBS->OpenProtocol (\r | |
265 | ControllerHandle,\r | |
266 | &gEfiDiskIoProtocolGuid,\r | |
267 | (VOID **) &DiskIo,\r | |
268 | This->DriverBindingHandle,\r | |
269 | ControllerHandle,\r | |
270 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
271 | );\r | |
272 | if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r | |
273 | gBS->CloseProtocol (\r | |
274 | ControllerHandle,\r | |
275 | &gEfiDevicePathProtocolGuid,\r | |
276 | This->DriverBindingHandle,\r | |
277 | ControllerHandle\r | |
278 | );\r | |
15cc67e6 | 279 | goto Exit;\r |
adbcbf8f | 280 | }\r |
281 | \r | |
282 | OpenStatus = Status;\r | |
283 | \r | |
284 | //\r | |
9afd0514 | 285 | // Try to read blocks when there's media or it is removable physical partition.\r |
adbcbf8f | 286 | //\r |
9afd0514 | 287 | Status = EFI_UNSUPPORTED;\r |
288 | MediaPresent = BlockIo->Media->MediaPresent;\r | |
289 | if (BlockIo->Media->MediaPresent ||\r | |
290 | (BlockIo->Media->RemovableMedia && !BlockIo->Media->LogicalPartition)) {\r | |
adbcbf8f | 291 | //\r |
292 | // Try for GPT, then El Torito, and then legacy MBR partition types. If the\r | |
293 | // media supports a given partition type install child handles to represent\r | |
294 | // the partitions described by the media.\r | |
295 | //\r | |
296 | Routine = &mPartitionDetectRoutineTable[0];\r | |
297 | while (*Routine != NULL) {\r | |
298 | Status = (*Routine) (\r | |
299 | This,\r | |
300 | ControllerHandle,\r | |
301 | DiskIo,\r | |
302 | BlockIo,\r | |
490b5ea1 | 303 | BlockIo2,\r |
adbcbf8f | 304 | ParentDevicePath\r |
305 | );\r | |
9afd0514 | 306 | if (!EFI_ERROR (Status) || Status == EFI_MEDIA_CHANGED || Status == EFI_NO_MEDIA) {\r |
adbcbf8f | 307 | break;\r |
308 | }\r | |
309 | Routine++;\r | |
310 | }\r | |
311 | }\r | |
312 | //\r | |
313 | // In the case that the driver is already started (OpenStatus == EFI_ALREADY_STARTED),\r | |
314 | // the DevicePathProtocol and the DiskIoProtocol are not actually opened by the\r | |
315 | // driver. So don't try to close them. Otherwise, we will break the dependency\r | |
316 | // between the controller and the driver set up before.\r | |
317 | //\r | |
9afd0514 | 318 | // In the case that when the media changes on a device it will Reinstall the \r |
319 | // BlockIo interaface. This will cause a call to our Stop(), and a subsequent\r | |
320 | // reentrant call to our Start() successfully. We should leave the device open\r | |
321 | // when this happen. The "media change" case includes either the status is\r | |
322 | // EFI_MEDIA_CHANGED or it is a "media" to "no media" change. \r | |
323 | // \r | |
324 | if (EFI_ERROR (Status) &&\r | |
325 | !EFI_ERROR (OpenStatus) &&\r | |
326 | Status != EFI_MEDIA_CHANGED &&\r | |
327 | !(MediaPresent && Status == EFI_NO_MEDIA)) {\r | |
adbcbf8f | 328 | gBS->CloseProtocol (\r |
329 | ControllerHandle,\r | |
330 | &gEfiDiskIoProtocolGuid,\r | |
331 | This->DriverBindingHandle,\r | |
332 | ControllerHandle\r | |
333 | );\r | |
490b5ea1 | 334 | //\r |
335 | // Close Parent BlockIO2 if has.\r | |
336 | // \r | |
337 | gBS->CloseProtocol (\r | |
338 | ControllerHandle,\r | |
339 | &gEfiBlockIo2ProtocolGuid,\r | |
340 | This->DriverBindingHandle,\r | |
341 | ControllerHandle\r | |
342 | );\r | |
adbcbf8f | 343 | \r |
344 | gBS->CloseProtocol (\r | |
345 | ControllerHandle,\r | |
346 | &gEfiDevicePathProtocolGuid,\r | |
347 | This->DriverBindingHandle,\r | |
348 | ControllerHandle\r | |
349 | );\r | |
350 | }\r | |
351 | \r | |
15cc67e6 | 352 | Exit:\r |
353 | gBS->RestoreTPL (OldTpl);\r | |
adbcbf8f | 354 | return Status;\r |
355 | }\r | |
356 | \r | |
adbcbf8f | 357 | /**\r |
48557c65 | 358 | Stop this driver on ControllerHandle. Support stopping any child handles\r |
adbcbf8f | 359 | created by this driver.\r |
360 | \r | |
361 | @param This Protocol instance pointer.\r | |
362 | @param ControllerHandle Handle of device to stop driver on\r | |
363 | @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r | |
364 | children is zero stop the entire bus driver.\r | |
365 | @param ChildHandleBuffer List of Child Handles to Stop.\r | |
366 | \r | |
367 | @retval EFI_SUCCESS This driver is removed ControllerHandle\r | |
368 | @retval other This driver was not removed from this device\r | |
369 | \r | |
370 | **/\r | |
371 | EFI_STATUS\r | |
372 | EFIAPI\r | |
373 | PartitionDriverBindingStop (\r | |
374 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
375 | IN EFI_HANDLE ControllerHandle,\r | |
376 | IN UINTN NumberOfChildren,\r | |
377 | IN EFI_HANDLE *ChildHandleBuffer\r | |
378 | )\r | |
379 | {\r | |
380 | EFI_STATUS Status;\r | |
381 | UINTN Index;\r | |
382 | EFI_BLOCK_IO_PROTOCOL *BlockIo;\r | |
490b5ea1 | 383 | EFI_BLOCK_IO2_PROTOCOL *BlockIo2;\r |
adbcbf8f | 384 | BOOLEAN AllChildrenStopped;\r |
385 | PARTITION_PRIVATE_DATA *Private;\r | |
386 | EFI_DISK_IO_PROTOCOL *DiskIo;\r | |
387 | \r | |
490b5ea1 | 388 | BlockIo = NULL;\r |
389 | BlockIo2 = NULL;\r | |
390 | Private = NULL;\r | |
391 | \r | |
adbcbf8f | 392 | if (NumberOfChildren == 0) {\r |
393 | //\r | |
394 | // Close the bus driver\r | |
395 | //\r | |
396 | gBS->CloseProtocol (\r | |
397 | ControllerHandle,\r | |
398 | &gEfiDiskIoProtocolGuid,\r | |
399 | This->DriverBindingHandle,\r | |
400 | ControllerHandle\r | |
401 | );\r | |
490b5ea1 | 402 | //\r |
403 | // Close Parent BlockIO2 if has.\r | |
404 | // \r | |
405 | gBS->CloseProtocol (\r | |
406 | ControllerHandle,\r | |
407 | &gEfiBlockIo2ProtocolGuid,\r | |
408 | This->DriverBindingHandle,\r | |
409 | ControllerHandle\r | |
410 | );\r | |
adbcbf8f | 411 | \r |
412 | gBS->CloseProtocol (\r | |
413 | ControllerHandle,\r | |
414 | &gEfiDevicePathProtocolGuid,\r | |
415 | This->DriverBindingHandle,\r | |
416 | ControllerHandle\r | |
417 | );\r | |
adbcbf8f | 418 | return EFI_SUCCESS;\r |
419 | }\r | |
420 | \r | |
421 | AllChildrenStopped = TRUE;\r | |
422 | for (Index = 0; Index < NumberOfChildren; Index++) {\r | |
490b5ea1 | 423 | gBS->OpenProtocol (\r |
424 | ChildHandleBuffer[Index],\r | |
425 | &gEfiBlockIoProtocolGuid,\r | |
426 | (VOID **) &BlockIo,\r | |
427 | This->DriverBindingHandle,\r | |
428 | ControllerHandle,\r | |
429 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
430 | );\r | |
431 | //\r | |
432 | // Try to locate BlockIo2.\r | |
433 | //\r | |
434 | gBS->OpenProtocol (\r | |
435 | ChildHandleBuffer[Index],\r | |
436 | &gEfiBlockIo2ProtocolGuid,\r | |
437 | (VOID **) &BlockIo2,\r | |
438 | This->DriverBindingHandle,\r | |
439 | ControllerHandle,\r | |
440 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
441 | ); \r | |
442 | \r | |
d0844d13 | 443 | \r |
444 | Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (BlockIo);\r | |
adbcbf8f | 445 | \r |
490b5ea1 | 446 | Status = gBS->CloseProtocol (\r |
447 | ControllerHandle,\r | |
448 | &gEfiDiskIoProtocolGuid,\r | |
449 | This->DriverBindingHandle,\r | |
450 | ChildHandleBuffer[Index]\r | |
451 | );\r | |
452 | //\r | |
453 | // All Software protocols have be freed from the handle so remove it.\r | |
454 | // Remove the BlockIo Protocol if has.\r | |
455 | // Remove the BlockIo2 Protocol if has.\r | |
456 | //\r | |
457 | if (BlockIo2 != NULL) {\r | |
adbcbf8f | 458 | BlockIo->FlushBlocks (BlockIo);\r |
490b5ea1 | 459 | BlockIo2->FlushBlocksEx (BlockIo2, NULL);\r |
adbcbf8f | 460 | Status = gBS->UninstallMultipleProtocolInterfaces (\r |
490b5ea1 | 461 | ChildHandleBuffer[Index],\r |
462 | &gEfiDevicePathProtocolGuid,\r | |
463 | Private->DevicePath,\r | |
464 | &gEfiBlockIoProtocolGuid,\r | |
465 | &Private->BlockIo,\r | |
466 | &gEfiBlockIo2ProtocolGuid,\r | |
467 | &Private->BlockIo2,\r | |
468 | Private->EspGuid,\r | |
469 | NULL,\r | |
470 | NULL\r | |
471 | );\r | |
472 | } else {\r | |
473 | BlockIo->FlushBlocks (BlockIo);\r | |
474 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
475 | ChildHandleBuffer[Index],\r | |
476 | &gEfiDevicePathProtocolGuid,\r | |
477 | Private->DevicePath,\r | |
478 | &gEfiBlockIoProtocolGuid,\r | |
479 | &Private->BlockIo,\r | |
480 | Private->EspGuid,\r | |
481 | NULL,\r | |
482 | NULL\r | |
483 | );\r | |
484 | }\r | |
adbcbf8f | 485 | \r |
490b5ea1 | 486 | if (EFI_ERROR (Status)) {\r |
487 | gBS->OpenProtocol (\r | |
488 | ControllerHandle,\r | |
489 | &gEfiDiskIoProtocolGuid,\r | |
490 | (VOID **) &DiskIo,\r | |
491 | This->DriverBindingHandle,\r | |
492 | ChildHandleBuffer[Index],\r | |
493 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
494 | );\r | |
495 | } else {\r | |
496 | FreePool (Private->DevicePath);\r | |
497 | FreePool (Private);\r | |
adbcbf8f | 498 | }\r |
499 | \r | |
500 | if (EFI_ERROR (Status)) {\r | |
501 | AllChildrenStopped = FALSE;\r | |
502 | }\r | |
503 | }\r | |
504 | \r | |
505 | if (!AllChildrenStopped) {\r | |
506 | return EFI_DEVICE_ERROR;\r | |
507 | }\r | |
508 | \r | |
509 | return EFI_SUCCESS;\r | |
510 | }\r | |
511 | \r | |
512 | \r | |
513 | /**\r | |
514 | Reset the Block Device.\r | |
515 | \r | |
516 | @param This Protocol instance pointer.\r | |
517 | @param ExtendedVerification Driver may perform diagnostics on reset.\r | |
518 | \r | |
519 | @retval EFI_SUCCESS The device was reset.\r | |
520 | @retval EFI_DEVICE_ERROR The device is not functioning properly and could\r | |
521 | not be reset.\r | |
522 | \r | |
523 | **/\r | |
adbcbf8f | 524 | EFI_STATUS\r |
525 | EFIAPI\r | |
526 | PartitionReset (\r | |
527 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
528 | IN BOOLEAN ExtendedVerification\r | |
529 | )\r | |
530 | {\r | |
531 | PARTITION_PRIVATE_DATA *Private;\r | |
532 | \r | |
533 | Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);\r | |
534 | \r | |
535 | return Private->ParentBlockIo->Reset (\r | |
536 | Private->ParentBlockIo,\r | |
537 | ExtendedVerification\r | |
538 | );\r | |
539 | }\r | |
540 | \r | |
fcf5e49d RN |
541 | /**\r |
542 | Probe the media status and return EFI_NO_MEDIA or EFI_MEDIA_CHANGED\r | |
543 | for no media or media change case. Otherwise DefaultStatus is returned.\r | |
544 | \r | |
545 | @param DiskIo Pointer to the DiskIo instance.\r | |
546 | @param MediaId Id of the media, changes every time the media is replaced.\r | |
547 | @param DefaultStatus The default status to return when it's not the no media\r | |
548 | or media change case.\r | |
549 | \r | |
550 | @retval EFI_NO_MEDIA There is no media.\r | |
551 | @retval EFI_MEDIA_CHANGED The media was changed.\r | |
552 | @retval others The default status to return.\r | |
553 | **/\r | |
554 | EFI_STATUS\r | |
555 | ProbeMediaStatus (\r | |
556 | IN EFI_DISK_IO_PROTOCOL *DiskIo,\r | |
557 | IN UINT32 MediaId,\r | |
558 | IN EFI_STATUS DefaultStatus\r | |
559 | )\r | |
560 | {\r | |
561 | EFI_STATUS Status;\r | |
562 | \r | |
563 | //\r | |
564 | // Read 1 byte from offset 0 but passing NULL as buffer pointer\r | |
565 | //\r | |
566 | Status = DiskIo->ReadDisk (DiskIo, MediaId, 0, 1, NULL);\r | |
567 | if ((Status == EFI_NO_MEDIA) || (Status == EFI_MEDIA_CHANGED)) {\r | |
568 | return Status;\r | |
569 | }\r | |
570 | return DefaultStatus;\r | |
571 | }\r | |
adbcbf8f | 572 | \r |
573 | /**\r | |
574 | Read by using the Disk IO protocol on the parent device. Lba addresses\r | |
575 | must be converted to byte offsets.\r | |
576 | \r | |
577 | @param This Protocol instance pointer.\r | |
578 | @param MediaId Id of the media, changes every time the media is replaced.\r | |
579 | @param Lba The starting Logical Block Address to read from\r | |
580 | @param BufferSize Size of Buffer, must be a multiple of device block size.\r | |
581 | @param Buffer Buffer containing read data\r | |
582 | \r | |
583 | @retval EFI_SUCCESS The data was read correctly from the device.\r | |
584 | @retval EFI_DEVICE_ERROR The device reported an error while performing the read.\r | |
585 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
586 | @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.\r | |
587 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
588 | @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not\r | |
589 | valid for the device.\r | |
590 | \r | |
591 | **/\r | |
adbcbf8f | 592 | EFI_STATUS\r |
593 | EFIAPI\r | |
594 | PartitionReadBlocks (\r | |
595 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
596 | IN UINT32 MediaId,\r | |
597 | IN EFI_LBA Lba,\r | |
598 | IN UINTN BufferSize,\r | |
599 | OUT VOID *Buffer\r | |
600 | )\r | |
601 | {\r | |
602 | PARTITION_PRIVATE_DATA *Private;\r | |
603 | UINT64 Offset;\r | |
604 | \r | |
605 | Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);\r | |
606 | \r | |
607 | if (BufferSize % Private->BlockSize != 0) {\r | |
fcf5e49d | 608 | return ProbeMediaStatus (Private->DiskIo, MediaId, EFI_BAD_BUFFER_SIZE);\r |
adbcbf8f | 609 | }\r |
610 | \r | |
611 | Offset = MultU64x32 (Lba, Private->BlockSize) + Private->Start;\r | |
612 | if (Offset + BufferSize > Private->End) {\r | |
fcf5e49d | 613 | return ProbeMediaStatus (Private->DiskIo, MediaId, EFI_INVALID_PARAMETER);\r |
adbcbf8f | 614 | }\r |
615 | //\r | |
616 | // Because some kinds of partition have different block size from their parent\r | |
617 | // device, we call the Disk IO protocol on the parent device, not the Block IO\r | |
618 | // protocol\r | |
619 | //\r | |
620 | return Private->DiskIo->ReadDisk (Private->DiskIo, MediaId, Offset, BufferSize, Buffer);\r | |
621 | }\r | |
622 | \r | |
623 | /**\r | |
624 | Write by using the Disk IO protocol on the parent device. Lba addresses\r | |
625 | must be converted to byte offsets.\r | |
626 | \r | |
490b5ea1 | 627 | @param[in] This Protocol instance pointer.\r |
628 | @param[in] MediaId Id of the media, changes every time the media is replaced.\r | |
629 | @param[in] Lba The starting Logical Block Address to read from\r | |
630 | @param[in] BufferSize Size of Buffer, must be a multiple of device block size.\r | |
631 | @param[in] Buffer Buffer containing data to be written to device.\r | |
adbcbf8f | 632 | \r |
633 | @retval EFI_SUCCESS The data was written correctly to the device.\r | |
634 | @retval EFI_WRITE_PROTECTED The device can not be written to.\r | |
635 | @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r | |
636 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
637 | @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r | |
638 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
639 | @retval EFI_INVALID_PARAMETER The write request contains a LBA that is not\r | |
640 | valid for the device.\r | |
641 | \r | |
642 | **/\r | |
adbcbf8f | 643 | EFI_STATUS\r |
644 | EFIAPI\r | |
645 | PartitionWriteBlocks (\r | |
646 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
647 | IN UINT32 MediaId,\r | |
648 | IN EFI_LBA Lba,\r | |
649 | IN UINTN BufferSize,\r | |
490b5ea1 | 650 | IN VOID *Buffer\r |
adbcbf8f | 651 | )\r |
652 | {\r | |
653 | PARTITION_PRIVATE_DATA *Private;\r | |
654 | UINT64 Offset;\r | |
655 | \r | |
656 | Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);\r | |
657 | \r | |
658 | if (BufferSize % Private->BlockSize != 0) {\r | |
fcf5e49d | 659 | return ProbeMediaStatus (Private->DiskIo, MediaId, EFI_BAD_BUFFER_SIZE);\r |
adbcbf8f | 660 | }\r |
661 | \r | |
662 | Offset = MultU64x32 (Lba, Private->BlockSize) + Private->Start;\r | |
663 | if (Offset + BufferSize > Private->End) {\r | |
fcf5e49d | 664 | return ProbeMediaStatus (Private->DiskIo, MediaId, EFI_INVALID_PARAMETER);\r |
adbcbf8f | 665 | }\r |
666 | //\r | |
667 | // Because some kinds of partition have different block size from their parent\r | |
668 | // device, we call the Disk IO protocol on the parent device, not the Block IO\r | |
669 | // protocol\r | |
670 | //\r | |
671 | return Private->DiskIo->WriteDisk (Private->DiskIo, MediaId, Offset, BufferSize, Buffer);\r | |
672 | }\r | |
673 | \r | |
674 | \r | |
675 | /**\r | |
676 | Flush the parent Block Device.\r | |
677 | \r | |
678 | @param This Protocol instance pointer.\r | |
679 | \r | |
680 | @retval EFI_SUCCESS All outstanding data was written to the device\r | |
681 | @retval EFI_DEVICE_ERROR The device reported an error while writting back the data\r | |
682 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
683 | \r | |
684 | **/\r | |
adbcbf8f | 685 | EFI_STATUS\r |
686 | EFIAPI\r | |
687 | PartitionFlushBlocks (\r | |
688 | IN EFI_BLOCK_IO_PROTOCOL *This\r | |
689 | )\r | |
690 | {\r | |
691 | PARTITION_PRIVATE_DATA *Private;\r | |
692 | \r | |
693 | Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);\r | |
694 | \r | |
695 | return Private->ParentBlockIo->FlushBlocks (Private->ParentBlockIo);\r | |
696 | }\r | |
697 | \r | |
65fd3952 RN |
698 | /**\r |
699 | Probe the media status and return EFI_NO_MEDIA or EFI_MEDIA_CHANGED\r | |
700 | for no media or media change case. Otherwise DefaultStatus is returned.\r | |
701 | \r | |
702 | @param BlockIo2 Pointer to the BlockIo2 instance.\r | |
703 | @param MediaId Id of the media, changes every time the media is replaced.\r | |
704 | @param DefaultStatus The default status to return when it's not the no media\r | |
705 | or media change case.\r | |
706 | \r | |
707 | @retval EFI_NO_MEDIA There is no media.\r | |
708 | @retval EFI_MEDIA_CHANGED The media was changed.\r | |
709 | @retval others The default status to return.\r | |
710 | **/\r | |
711 | EFI_STATUS\r | |
712 | ProbeMediaStatusEx (\r | |
713 | IN EFI_BLOCK_IO2_PROTOCOL *BlockIo2,\r | |
714 | IN UINT32 MediaId,\r | |
715 | IN EFI_STATUS DefaultStatus\r | |
716 | )\r | |
717 | {\r | |
718 | EFI_STATUS Status;\r | |
719 | \r | |
720 | //\r | |
721 | // Read from LBA 0 but passing NULL as buffer pointer to detect the media status.\r | |
722 | //\r | |
723 | Status = BlockIo2->ReadBlocksEx (\r | |
724 | BlockIo2,\r | |
725 | MediaId,\r | |
726 | 0,\r | |
727 | NULL,\r | |
728 | 0,\r | |
729 | NULL\r | |
730 | );\r | |
731 | if ((Status == EFI_NO_MEDIA) || (Status == EFI_MEDIA_CHANGED)) {\r | |
732 | return Status;\r | |
733 | }\r | |
734 | return DefaultStatus;\r | |
735 | }\r | |
736 | \r | |
490b5ea1 | 737 | /**\r |
738 | Reset the Block Device throught Block I/O2 protocol.\r | |
739 | \r | |
740 | @param This Protocol instance pointer.\r | |
741 | @param ExtendedVerification Driver may perform diagnostics on reset.\r | |
742 | \r | |
743 | @retval EFI_SUCCESS The device was reset.\r | |
744 | @retval EFI_DEVICE_ERROR The device is not functioning properly and could\r | |
745 | not be reset.\r | |
746 | \r | |
747 | **/\r | |
748 | EFI_STATUS\r | |
749 | EFIAPI\r | |
750 | PartitionResetEx (\r | |
751 | IN EFI_BLOCK_IO2_PROTOCOL *This,\r | |
752 | IN BOOLEAN ExtendedVerification\r | |
753 | )\r | |
754 | {\r | |
755 | PARTITION_PRIVATE_DATA *Private;\r | |
756 | \r | |
757 | Private = PARTITION_DEVICE_FROM_BLOCK_IO2_THIS (This);\r | |
758 | \r | |
759 | return Private->ParentBlockIo2->Reset (\r | |
760 | Private->ParentBlockIo2,\r | |
761 | ExtendedVerification\r | |
762 | );\r | |
763 | }\r | |
764 | \r | |
765 | /**\r | |
766 | Read BufferSize bytes from Lba into Buffer.\r | |
767 | \r | |
768 | This function reads the requested number of blocks from the device. All the\r | |
769 | blocks are read, or an error is returned.\r | |
770 | If EFI_DEVICE_ERROR, EFI_NO_MEDIA,_or EFI_MEDIA_CHANGED is returned and\r | |
771 | non-blocking I/O is being used, the Event associated with this request will\r | |
772 | not be signaled.\r | |
773 | \r | |
774 | @param[in] This Indicates a pointer to the calling context.\r | |
775 | @param[in] MediaId Id of the media, changes every time the media is \r | |
776 | replaced.\r | |
777 | @param[in] Lba The starting Logical Block Address to read from.\r | |
778 | @param[in, out] Token A pointer to the token associated with the transaction.\r | |
779 | @param[in] BufferSize Size of Buffer, must be a multiple of device block size. \r | |
780 | @param[out] Buffer A pointer to the destination buffer for the data. The \r | |
781 | caller is responsible for either having implicit or \r | |
782 | explicit ownership of the buffer.\r | |
783 | \r | |
784 | @retval EFI_SUCCESS The read request was queued if Token->Event is\r | |
785 | not NULL.The data was read correctly from the\r | |
786 | device if the Token->Event is NULL.\r | |
787 | @retval EFI_DEVICE_ERROR The device reported an error while performing\r | |
788 | the read.\r | |
789 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
790 | @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.\r | |
791 | @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the\r | |
792 | intrinsic block size of the device.\r | |
793 | @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid, \r | |
794 | or the buffer is not on proper alignment.\r | |
795 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack\r | |
796 | of resources.\r | |
797 | **/\r | |
798 | EFI_STATUS\r | |
799 | EFIAPI\r | |
800 | PartitionReadBlocksEx (\r | |
801 | IN EFI_BLOCK_IO2_PROTOCOL *This,\r | |
802 | IN UINT32 MediaId,\r | |
803 | IN EFI_LBA Lba,\r | |
804 | IN OUT EFI_BLOCK_IO2_TOKEN *Token,\r | |
805 | IN UINTN BufferSize,\r | |
806 | OUT VOID *Buffer\r | |
807 | )\r | |
808 | {\r | |
809 | PARTITION_PRIVATE_DATA *Private;\r | |
810 | UINT64 Offset;\r | |
811 | UINT32 UnderRun;\r | |
812 | \r | |
65fd3952 RN |
813 | Private = PARTITION_DEVICE_FROM_BLOCK_IO2_THIS (This);\r |
814 | \r | |
490b5ea1 | 815 | if (Token == NULL) {\r |
65fd3952 | 816 | return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_INVALID_PARAMETER);\r |
490b5ea1 | 817 | }\r |
818 | \r | |
490b5ea1 | 819 | if (BufferSize % Private->BlockSize != 0) {\r |
65fd3952 | 820 | return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_BAD_BUFFER_SIZE);\r |
490b5ea1 | 821 | }\r |
822 | \r | |
823 | Offset = MultU64x32 (Lba, Private->BlockSize) + Private->Start;\r | |
824 | if (Offset + BufferSize > Private->End) {\r | |
65fd3952 | 825 | return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_INVALID_PARAMETER);\r |
490b5ea1 | 826 | }\r |
827 | \r | |
828 | //\r | |
829 | // Since the BlockIO2 call Parent BlockIO2 directly, so here the offset must\r | |
830 | // be multiple of BlockSize. If the Spec will be updated the DiskIO to support\r | |
831 | // BlockIO2, this limitation will be removed and call DiskIO here.\r | |
832 | //\r | |
833 | Lba = DivU64x32Remainder (Offset, Private->BlockSize, &UnderRun);\r | |
834 | if (UnderRun != 0) {\r | |
65fd3952 | 835 | return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_UNSUPPORTED);\r |
490b5ea1 | 836 | }\r |
837 | \r | |
838 | //\r | |
839 | // Because some partitions have different block size from their parent\r | |
840 | // device, in that case the Block I/O2 couldn't be called.\r | |
841 | //\r | |
842 | if (Private->BlockSize != Private->ParentBlockIo->Media->BlockSize) {\r | |
65fd3952 | 843 | return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_UNSUPPORTED);\r |
490b5ea1 | 844 | }\r |
845 | \r | |
846 | return Private->ParentBlockIo2->ReadBlocksEx (Private->ParentBlockIo2, MediaId, Lba, Token, BufferSize, Buffer);\r | |
847 | }\r | |
848 | \r | |
849 | /**\r | |
850 | Write BufferSize bytes from Lba into Buffer.\r | |
851 | \r | |
852 | This function writes the requested number of blocks to the device. All blocks\r | |
853 | are written, or an error is returned.If EFI_DEVICE_ERROR, EFI_NO_MEDIA,\r | |
854 | EFI_WRITE_PROTECTED or EFI_MEDIA_CHANGED is returned and non-blocking I/O is\r | |
855 | being used, the Event associated with this request will not be signaled.\r | |
856 | \r | |
857 | @param[in] This Indicates a pointer to the calling context.\r | |
858 | @param[in] MediaId The media ID that the write request is for.\r | |
859 | @param[in] Lba The starting logical block address to be written. The\r | |
860 | caller is responsible for writing to only legitimate\r | |
861 | locations.\r | |
862 | @param[in, out] Token A pointer to the token associated with the transaction.\r | |
863 | @param[in] BufferSize Size of Buffer, must be a multiple of device block size.\r | |
864 | @param[in] Buffer A pointer to the source buffer for the data.\r | |
865 | \r | |
866 | @retval EFI_SUCCESS The write request was queued if Event is not NULL.\r | |
867 | The data was written correctly to the device if\r | |
868 | the Event is NULL.\r | |
869 | @retval EFI_WRITE_PROTECTED The device can not be written to.\r | |
870 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
871 | @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r | |
872 | @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r | |
873 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
874 | @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid, \r | |
875 | or the buffer is not on proper alignment.\r | |
876 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack\r | |
877 | of resources.\r | |
878 | \r | |
879 | **/\r | |
880 | EFI_STATUS\r | |
881 | EFIAPI\r | |
882 | PartitionWriteBlocksEx (\r | |
883 | IN EFI_BLOCK_IO2_PROTOCOL *This,\r | |
884 | IN UINT32 MediaId,\r | |
885 | IN EFI_LBA Lba,\r | |
886 | IN OUT EFI_BLOCK_IO2_TOKEN *Token,\r | |
887 | IN UINTN BufferSize,\r | |
888 | IN VOID *Buffer\r | |
889 | )\r | |
890 | {\r | |
891 | PARTITION_PRIVATE_DATA *Private;\r | |
892 | UINT64 Offset;\r | |
893 | UINT32 UnderRun;\r | |
894 | \r | |
65fd3952 RN |
895 | Private = PARTITION_DEVICE_FROM_BLOCK_IO2_THIS (This);\r |
896 | \r | |
490b5ea1 | 897 | if (Token == NULL) {\r |
65fd3952 | 898 | return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_INVALID_PARAMETER);\r |
490b5ea1 | 899 | }\r |
900 | \r | |
490b5ea1 | 901 | if (BufferSize % Private->BlockSize != 0) {\r |
65fd3952 | 902 | return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_BAD_BUFFER_SIZE);\r |
490b5ea1 | 903 | }\r |
904 | \r | |
905 | Offset = MultU64x32 (Lba, Private->BlockSize) + Private->Start;\r | |
906 | if (Offset + BufferSize > Private->End) {\r | |
65fd3952 | 907 | return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_INVALID_PARAMETER);\r |
490b5ea1 | 908 | }\r |
909 | \r | |
910 | //\r | |
911 | // Since the BlockIO2 call Parent BlockIO2 directly, so here the offset must\r | |
912 | // be multiple of BlockSize. If the Spec will be updated the DiskIO to support\r | |
913 | // BlockIO2, this limitation will be removed and call DiskIO here.\r | |
914 | //\r | |
915 | Lba = DivU64x32Remainder (Offset, Private->BlockSize, &UnderRun);\r | |
916 | if (UnderRun != 0) {\r | |
65fd3952 | 917 | return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_UNSUPPORTED);\r |
490b5ea1 | 918 | }\r |
919 | \r | |
920 | //\r | |
921 | // Because some kinds of partition have different block size from their parent,\r | |
922 | // in that case it couldn't call parent Block I/O2. \r | |
923 | //\r | |
924 | if (Private->BlockSize != Private->ParentBlockIo->Media->BlockSize) {\r | |
65fd3952 | 925 | return ProbeMediaStatusEx (Private->ParentBlockIo2, MediaId, EFI_UNSUPPORTED);\r |
490b5ea1 | 926 | }\r |
927 | \r | |
928 | return Private->ParentBlockIo2->WriteBlocksEx (Private->ParentBlockIo2, MediaId, Lba, Token, BufferSize, Buffer);\r | |
929 | }\r | |
930 | \r | |
931 | /**\r | |
932 | Flush the Block Device.\r | |
933 | \r | |
934 | If EFI_DEVICE_ERROR, EFI_NO_MEDIA,_EFI_WRITE_PROTECTED or EFI_MEDIA_CHANGED\r | |
935 | is returned and non-blocking I/O is being used, the Event associated with\r | |
936 | this request will not be signaled. \r | |
937 | \r | |
938 | @param[in] This Indicates a pointer to the calling context.\r | |
86d8e199 | 939 | @param[in, out] Token A pointer to the token associated with the transaction\r |
490b5ea1 | 940 | \r |
941 | @retval EFI_SUCCESS The flush request was queued if Event is not NULL.\r | |
942 | All outstanding data was written correctly to the\r | |
943 | device if the Event is NULL.\r | |
944 | @retval EFI_DEVICE_ERROR The device reported an error while writting back\r | |
945 | the data.\r | |
946 | @retval EFI_WRITE_PROTECTED The device cannot be written to.\r | |
947 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
948 | @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.\r | |
949 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack\r | |
950 | of resources.\r | |
951 | \r | |
952 | **/\r | |
953 | EFI_STATUS\r | |
954 | EFIAPI\r | |
955 | PartitionFlushBlocksEx (\r | |
956 | IN EFI_BLOCK_IO2_PROTOCOL *This,\r | |
957 | IN OUT EFI_BLOCK_IO2_TOKEN *Token\r | |
958 | )\r | |
959 | {\r | |
960 | PARTITION_PRIVATE_DATA *Private;\r | |
961 | \r | |
962 | Private = PARTITION_DEVICE_FROM_BLOCK_IO2_THIS (This);\r | |
963 | \r | |
964 | //\r | |
965 | // Because some kinds of partition have different block size from their parent,\r | |
966 | // in that case it couldn't call parent Block I/O2. \r | |
967 | //\r | |
968 | if (Private->BlockSize != Private->ParentBlockIo->Media->BlockSize) {\r | |
969 | return EFI_UNSUPPORTED;\r | |
970 | }\r | |
971 | \r | |
972 | return Private->ParentBlockIo2->FlushBlocksEx (Private->ParentBlockIo2, Token);\r | |
973 | }\r | |
adbcbf8f | 974 | \r |
975 | \r | |
976 | /**\r | |
977 | Create a child handle for a logical block device that represents the\r | |
978 | bytes Start to End of the Parent Block IO device.\r | |
979 | \r | |
490b5ea1 | 980 | @param[in] This Protocol instance pointer.\r |
981 | @param[in] ParentHandle Parent Handle for new child.\r | |
982 | @param[in] ParentDiskIo Parent DiskIo interface.\r | |
983 | @param[in] ParentBlockIo Parent BlockIo interface.\r | |
984 | @param[in] ParentBlockIo2 Parent BlockIo2 interface.\r | |
985 | @param[in] ParentDevicePath Parent Device Path.\r | |
986 | @param[in] DevicePathNode Child Device Path node.\r | |
987 | @param[in] Start Start Block.\r | |
988 | @param[in] End End Block.\r | |
989 | @param[in] BlockSize Child block size.\r | |
990 | @param[in] InstallEspGuid Flag to install EFI System Partition GUID on handle.\r | |
991 | \r | |
992 | @retval EFI_SUCCESS A child handle was added.\r | |
993 | @retval other A child handle was not added.\r | |
adbcbf8f | 994 | \r |
995 | **/\r | |
996 | EFI_STATUS\r | |
997 | PartitionInstallChildHandle (\r | |
998 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
999 | IN EFI_HANDLE ParentHandle,\r | |
1000 | IN EFI_DISK_IO_PROTOCOL *ParentDiskIo,\r | |
1001 | IN EFI_BLOCK_IO_PROTOCOL *ParentBlockIo,\r | |
490b5ea1 | 1002 | IN EFI_BLOCK_IO2_PROTOCOL *ParentBlockIo2,\r |
adbcbf8f | 1003 | IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,\r |
1004 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
1005 | IN EFI_LBA Start,\r | |
1006 | IN EFI_LBA End,\r | |
1007 | IN UINT32 BlockSize,\r | |
1008 | IN BOOLEAN InstallEspGuid\r | |
1009 | )\r | |
1010 | {\r | |
1011 | EFI_STATUS Status;\r | |
1012 | PARTITION_PRIVATE_DATA *Private;\r | |
1013 | \r | |
490b5ea1 | 1014 | Status = EFI_SUCCESS;\r |
adbcbf8f | 1015 | Private = AllocateZeroPool (sizeof (PARTITION_PRIVATE_DATA));\r |
1016 | if (Private == NULL) {\r | |
1017 | return EFI_OUT_OF_RESOURCES;\r | |
1018 | }\r | |
1019 | \r | |
1020 | Private->Signature = PARTITION_PRIVATE_DATA_SIGNATURE;\r | |
1021 | \r | |
1022 | Private->Start = MultU64x32 (Start, ParentBlockIo->Media->BlockSize);\r | |
1023 | Private->End = MultU64x32 (End + 1, ParentBlockIo->Media->BlockSize);\r | |
1024 | \r | |
1025 | Private->BlockSize = BlockSize;\r | |
1026 | Private->ParentBlockIo = ParentBlockIo;\r | |
490b5ea1 | 1027 | Private->ParentBlockIo2 = ParentBlockIo2;\r |
adbcbf8f | 1028 | Private->DiskIo = ParentDiskIo;\r |
1029 | \r | |
d0844d13 | 1030 | //\r |
1031 | // Set the BlockIO into Private Data.\r | |
1032 | //\r | |
1033 | Private->BlockIo.Revision = ParentBlockIo->Revision;\r | |
1034 | \r | |
1035 | Private->BlockIo.Media = &Private->Media;\r | |
1036 | CopyMem (Private->BlockIo.Media, ParentBlockIo->Media, sizeof (EFI_BLOCK_IO_MEDIA));\r | |
490b5ea1 | 1037 | \r |
d0844d13 | 1038 | Private->BlockIo.Reset = PartitionReset;\r |
1039 | Private->BlockIo.ReadBlocks = PartitionReadBlocks;\r | |
1040 | Private->BlockIo.WriteBlocks = PartitionWriteBlocks;\r | |
1041 | Private->BlockIo.FlushBlocks = PartitionFlushBlocks;\r | |
490b5ea1 | 1042 | \r |
d0844d13 | 1043 | //\r |
1044 | // Set the BlockIO2 into Private Data.\r | |
1045 | //\r | |
490b5ea1 | 1046 | if (Private->ParentBlockIo2 != NULL) {\r |
1047 | Private->BlockIo2.Media = &Private->Media2;\r | |
1048 | CopyMem (Private->BlockIo2.Media, ParentBlockIo2->Media, sizeof (EFI_BLOCK_IO_MEDIA));\r | |
1049 | \r | |
1050 | Private->BlockIo2.Reset = PartitionResetEx;\r | |
1051 | Private->BlockIo2.ReadBlocksEx = PartitionReadBlocksEx;\r | |
1052 | Private->BlockIo2.WriteBlocksEx = PartitionWriteBlocksEx;\r | |
1053 | Private->BlockIo2.FlushBlocksEx = PartitionFlushBlocksEx; \r | |
1054 | }\r | |
67f802ed | 1055 | \r |
67f802ed | 1056 | Private->Media.IoAlign = 0;\r |
490b5ea1 | 1057 | Private->Media.LogicalPartition = TRUE;\r |
adbcbf8f | 1058 | Private->Media.LastBlock = DivU64x32 (\r |
1059 | MultU64x32 (\r | |
1060 | End - Start + 1,\r | |
d0844d13 | 1061 | ParentBlockIo->Media->BlockSize\r |
adbcbf8f | 1062 | ),\r |
490b5ea1 | 1063 | BlockSize\r |
adbcbf8f | 1064 | ) - 1;\r |
1065 | \r | |
67f802ed | 1066 | Private->Media.BlockSize = (UINT32) BlockSize;\r |
adbcbf8f | 1067 | \r |
490b5ea1 | 1068 | //\r |
1069 | // For BlockIO2, it should keep the same alignment with the parent BlockIO2's.\r | |
1070 | //\r | |
1071 | Private->Media2.LogicalPartition = TRUE;\r | |
1072 | Private->Media2.LastBlock = Private->Media.LastBlock;\r | |
1073 | Private->Media2.BlockSize = (UINT32) BlockSize;\r | |
1074 | \r | |
fe3b68bb | 1075 | //\r |
0e87144e | 1076 | // Per UEFI Spec, LowestAlignedLba, LogicalBlocksPerPhysicalBlock and OptimalTransferLengthGranularity must be 0\r |
fe3b68bb RN |
1077 | // for logical partitions.\r |
1078 | //\r | |
1079 | if (Private->BlockIo.Revision >= EFI_BLOCK_IO_PROTOCOL_REVISION2) {\r | |
c582ad45 EB |
1080 | Private->Media.LowestAlignedLba = 0;\r |
1081 | Private->Media.LogicalBlocksPerPhysicalBlock = 0;\r | |
1082 | Private->Media2.LowestAlignedLba = 0;\r | |
1083 | Private->Media2.LogicalBlocksPerPhysicalBlock = 0;\r | |
0e87144e | 1084 | if (Private->BlockIo.Revision >= EFI_BLOCK_IO_PROTOCOL_REVISION3) {\r |
c582ad45 EB |
1085 | Private->Media.OptimalTransferLengthGranularity = 0;\r |
1086 | Private->Media2.OptimalTransferLengthGranularity = 0;\r | |
0e87144e | 1087 | }\r |
fe3b68bb RN |
1088 | }\r |
1089 | \r | |
490b5ea1 | 1090 | Private->DevicePath = AppendDevicePathNode (ParentDevicePath, DevicePathNode);\r |
adbcbf8f | 1091 | \r |
1092 | if (Private->DevicePath == NULL) {\r | |
1093 | FreePool (Private);\r | |
1094 | return EFI_OUT_OF_RESOURCES;\r | |
1095 | }\r | |
1096 | \r | |
1097 | if (InstallEspGuid) {\r | |
1098 | Private->EspGuid = &gEfiPartTypeSystemPartGuid;\r | |
1099 | } else {\r | |
1100 | //\r | |
1101 | // If NULL InstallMultipleProtocolInterfaces will ignore it.\r | |
1102 | //\r | |
1103 | Private->EspGuid = NULL;\r | |
1104 | }\r | |
490b5ea1 | 1105 | \r |
adbcbf8f | 1106 | //\r |
490b5ea1 | 1107 | // Create the new handle. \r |
1108 | // BlockIO2 will be installed on the condition that the blocksize of parent BlockIO \r | |
1109 | // is same with the child BlockIO's. Instead of calling the DiskIO, the child BlockIO2 \r | |
1110 | // directly call the parent BlockIO and doesn't handle the different block size issue.\r | |
1111 | // If SPEC will update the DiskIO to support the Non-Blocking model, the BlockIO2 will call\r | |
1112 | // DiskIO to handle the blocksize unequal issue and the limitation will be remove from\r | |
1113 | // here.\r | |
adbcbf8f | 1114 | //\r |
1115 | Private->Handle = NULL;\r | |
d0844d13 | 1116 | if ((Private->ParentBlockIo2 != NULL) &&\r |
490b5ea1 | 1117 | (Private->ParentBlockIo2->Media->BlockSize == BlockSize)\r |
1118 | ) {\r | |
1119 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
1120 | &Private->Handle,\r | |
1121 | &gEfiDevicePathProtocolGuid,\r | |
1122 | Private->DevicePath,\r | |
1123 | &gEfiBlockIoProtocolGuid,\r | |
1124 | &Private->BlockIo,\r | |
1125 | &gEfiBlockIo2ProtocolGuid,\r | |
1126 | &Private->BlockIo2,\r | |
1127 | Private->EspGuid,\r | |
1128 | NULL,\r | |
1129 | NULL\r | |
1130 | );\r | |
d0844d13 | 1131 | } else { \r |
1132 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
1133 | &Private->Handle,\r | |
1134 | &gEfiDevicePathProtocolGuid,\r | |
1135 | Private->DevicePath,\r | |
1136 | &gEfiBlockIoProtocolGuid,\r | |
1137 | &Private->BlockIo,\r | |
1138 | Private->EspGuid,\r | |
1139 | NULL,\r | |
1140 | NULL\r | |
1141 | );\r | |
490b5ea1 | 1142 | }\r |
adbcbf8f | 1143 | \r |
1144 | if (!EFI_ERROR (Status)) {\r | |
1145 | //\r | |
1146 | // Open the Parent Handle for the child\r | |
1147 | //\r | |
1148 | Status = gBS->OpenProtocol (\r | |
1149 | ParentHandle,\r | |
1150 | &gEfiDiskIoProtocolGuid,\r | |
1151 | (VOID **) &ParentDiskIo,\r | |
1152 | This->DriverBindingHandle,\r | |
1153 | Private->Handle,\r | |
1154 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
1155 | );\r | |
1156 | } else {\r | |
1157 | FreePool (Private->DevicePath);\r | |
1158 | FreePool (Private);\r | |
1159 | }\r | |
1160 | \r | |
1161 | return Status;\r | |
1162 | }\r | |
1163 | \r | |
1164 | \r | |
1165 | /**\r | |
1166 | The user Entry Point for module Partition. The user code starts with this function.\r | |
1167 | \r | |
1168 | @param[in] ImageHandle The firmware allocated handle for the EFI image. \r | |
1169 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
1170 | \r | |
1171 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
1172 | @retval other Some error occurs when executing this entry point.\r | |
1173 | \r | |
1174 | **/\r | |
1175 | EFI_STATUS\r | |
1176 | EFIAPI\r | |
1177 | InitializePartition (\r | |
1178 | IN EFI_HANDLE ImageHandle,\r | |
1179 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
1180 | )\r | |
1181 | {\r | |
1182 | EFI_STATUS Status;\r | |
1183 | \r | |
1184 | //\r | |
1185 | // Install driver model protocol(s).\r | |
1186 | //\r | |
d38a0f44 | 1187 | Status = EfiLibInstallDriverBindingComponentName2 (\r |
adbcbf8f | 1188 | ImageHandle,\r |
1189 | SystemTable,\r | |
1190 | &gPartitionDriverBinding,\r | |
1191 | ImageHandle,\r | |
1192 | &gPartitionComponentName,\r | |
d38a0f44 | 1193 | &gPartitionComponentName2\r |
adbcbf8f | 1194 | );\r |
1195 | ASSERT_EFI_ERROR (Status);\r | |
1196 | \r | |
1197 | \r | |
1198 | return Status;\r | |
1199 | }\r | |
1200 | \r |