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