Commit | Line | Data |
---|---|---|
b9575d60 | 1 | /** @file\r |
79840ee1 | 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 | |
b9575d60 A |
7 | Copyright (c) 2006 - 2007, Intel Corporation \r |
8 | All rights reserved. This program and the accompanying materials \r | |
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 | |
12 | \r | |
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 | |
15 | \r | |
16 | **/\r | |
79840ee1 | 17 | \r |
79840ee1 | 18 | \r |
19 | #include "Partition.h"\r | |
20 | \r | |
21 | //\r | |
22 | // Partition Driver Global Variables\r | |
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 | |
33 | STATIC \r | |
34 | PARTITION_DETECT_ROUTINE mPartitionDetectRoutineTable[] = {\r | |
35 | PartitionInstallGptChildHandles,\r | |
36 | PartitionInstallElToritoChildHandles,\r | |
37 | PartitionInstallMbrChildHandles,\r | |
38 | NULL\r | |
39 | };\r | |
40 | \r | |
41 | \r | |
b9575d60 A |
42 | \r |
43 | /**\r | |
44 | Test to see if this driver supports ControllerHandle. Any ControllerHandle\r | |
45 | than contains a BlockIo and DiskIo protocol can be supported.\r | |
46 | \r | |
47 | @param This Protocol instance pointer.\r | |
48 | @param ControllerHandle Handle of device to test\r | |
49 | @param RemainingDevicePath Optional parameter use to pick a specific child\r | |
50 | device to start.\r | |
51 | \r | |
52 | @retval EFI_SUCCESS This driver supports this device\r | |
53 | @retval EFI_ALREADY_STARTED This driver is already running on this device\r | |
54 | @retval other This driver does not support this device\r | |
55 | \r | |
56 | **/\r | |
79840ee1 | 57 | EFI_STATUS\r |
58 | EFIAPI\r | |
59 | PartitionDriverBindingSupported (\r | |
60 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
61 | IN EFI_HANDLE ControllerHandle,\r | |
62 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
63 | )\r | |
79840ee1 | 64 | {\r |
65 | EFI_STATUS Status;\r | |
66 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
67 | EFI_DISK_IO_PROTOCOL *DiskIo;\r | |
68 | EFI_DEV_PATH *Node;\r | |
69 | \r | |
70 | if (RemainingDevicePath != NULL) {\r | |
71 | Node = (EFI_DEV_PATH *) RemainingDevicePath;\r | |
72 | if (Node->DevPath.Type != MEDIA_DEVICE_PATH ||\r | |
73 | Node->DevPath.SubType != MEDIA_HARDDRIVE_DP ||\r | |
74 | DevicePathNodeLength (&Node->DevPath) != sizeof (HARDDRIVE_DEVICE_PATH)\r | |
75 | ) {\r | |
76 | return EFI_UNSUPPORTED;\r | |
77 | }\r | |
78 | }\r | |
79 | //\r | |
80 | // Open the IO Abstraction(s) needed to perform the supported test\r | |
81 | //\r | |
82 | Status = gBS->OpenProtocol (\r | |
83 | ControllerHandle,\r | |
84 | &gEfiDevicePathProtocolGuid,\r | |
85 | (VOID **) &ParentDevicePath,\r | |
86 | This->DriverBindingHandle,\r | |
87 | ControllerHandle,\r | |
88 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
89 | );\r | |
90 | if (Status == EFI_ALREADY_STARTED) {\r | |
91 | return EFI_SUCCESS;\r | |
92 | }\r | |
93 | \r | |
94 | if (EFI_ERROR (Status)) {\r | |
95 | return Status;\r | |
96 | }\r | |
97 | //\r | |
98 | // Close the I/O Abstraction(s) used to perform the supported test\r | |
99 | //\r | |
100 | gBS->CloseProtocol (\r | |
101 | ControllerHandle,\r | |
102 | &gEfiDevicePathProtocolGuid,\r | |
103 | This->DriverBindingHandle,\r | |
104 | ControllerHandle\r | |
105 | );\r | |
106 | \r | |
107 | //\r | |
108 | // Open the IO Abstraction(s) needed to perform the supported test\r | |
109 | //\r | |
110 | Status = gBS->OpenProtocol (\r | |
111 | ControllerHandle,\r | |
112 | &gEfiDiskIoProtocolGuid,\r | |
113 | (VOID **) &DiskIo,\r | |
114 | This->DriverBindingHandle,\r | |
115 | ControllerHandle,\r | |
116 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
117 | );\r | |
118 | if (Status == EFI_ALREADY_STARTED) {\r | |
119 | return EFI_SUCCESS;\r | |
120 | }\r | |
121 | \r | |
122 | if (EFI_ERROR (Status)) {\r | |
123 | return Status;\r | |
124 | }\r | |
125 | //\r | |
126 | // Close the I/O Abstraction(s) used to perform the supported test\r | |
127 | //\r | |
128 | gBS->CloseProtocol (\r | |
129 | ControllerHandle,\r | |
130 | &gEfiDiskIoProtocolGuid,\r | |
131 | This->DriverBindingHandle,\r | |
132 | ControllerHandle\r | |
133 | );\r | |
134 | \r | |
135 | //\r | |
136 | // Open the IO Abstraction(s) needed to perform the supported test\r | |
137 | //\r | |
138 | Status = gBS->OpenProtocol (\r | |
139 | ControllerHandle,\r | |
140 | &gEfiBlockIoProtocolGuid,\r | |
141 | NULL,\r | |
142 | This->DriverBindingHandle,\r | |
143 | ControllerHandle,\r | |
144 | EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r | |
145 | );\r | |
146 | \r | |
147 | return Status;\r | |
148 | }\r | |
149 | \r | |
b9575d60 A |
150 | \r |
151 | /**\r | |
152 | Start this driver on ControllerHandle by opening a Block IO and Disk IO\r | |
153 | protocol, reading Device Path, and creating a child handle with a\r | |
154 | Disk IO and device path protocol.\r | |
155 | \r | |
156 | @param This Protocol instance pointer.\r | |
157 | @param ControllerHandle Handle of device to bind driver to\r | |
158 | @param RemainingDevicePath Optional parameter use to pick a specific child\r | |
159 | device to start.\r | |
160 | \r | |
161 | @retval EFI_SUCCESS This driver is added to ControllerHandle\r | |
162 | @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r | |
163 | @retval other This driver does not support this device\r | |
164 | \r | |
165 | **/\r | |
79840ee1 | 166 | EFI_STATUS\r |
167 | EFIAPI\r | |
168 | PartitionDriverBindingStart (\r | |
169 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
170 | IN EFI_HANDLE ControllerHandle,\r | |
171 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
172 | )\r | |
79840ee1 | 173 | {\r |
174 | EFI_STATUS Status;\r | |
175 | EFI_STATUS OpenStatus;\r | |
176 | EFI_BLOCK_IO_PROTOCOL *BlockIo;\r | |
177 | EFI_DISK_IO_PROTOCOL *DiskIo;\r | |
178 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
179 | PARTITION_DETECT_ROUTINE *Routine;\r | |
180 | \r | |
181 | Status = gBS->OpenProtocol (\r | |
182 | ControllerHandle,\r | |
183 | &gEfiBlockIoProtocolGuid,\r | |
184 | (VOID **) &BlockIo,\r | |
185 | This->DriverBindingHandle,\r | |
186 | ControllerHandle,\r | |
187 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
188 | );\r | |
189 | if (EFI_ERROR (Status)) {\r | |
190 | return Status;\r | |
191 | }\r | |
192 | //\r | |
193 | // Get the Device Path Protocol on ControllerHandle's handle\r | |
194 | //\r | |
195 | Status = gBS->OpenProtocol (\r | |
196 | ControllerHandle,\r | |
197 | &gEfiDevicePathProtocolGuid,\r | |
198 | (VOID **) &ParentDevicePath,\r | |
199 | This->DriverBindingHandle,\r | |
200 | ControllerHandle,\r | |
201 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
202 | );\r | |
203 | if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r | |
204 | return Status;\r | |
205 | }\r | |
206 | \r | |
207 | Status = gBS->OpenProtocol (\r | |
208 | ControllerHandle,\r | |
209 | &gEfiDiskIoProtocolGuid,\r | |
210 | (VOID **) &DiskIo,\r | |
211 | This->DriverBindingHandle,\r | |
212 | ControllerHandle,\r | |
213 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
214 | );\r | |
215 | if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r | |
216 | gBS->CloseProtocol (\r | |
217 | ControllerHandle,\r | |
218 | &gEfiDevicePathProtocolGuid,\r | |
219 | This->DriverBindingHandle,\r | |
220 | ControllerHandle\r | |
221 | );\r | |
222 | return Status;\r | |
223 | }\r | |
224 | \r | |
225 | OpenStatus = Status;\r | |
226 | \r | |
227 | //\r | |
228 | // If no media is present, do nothing here.\r | |
229 | //\r | |
230 | Status = EFI_UNSUPPORTED;\r | |
231 | if (BlockIo->Media->MediaPresent) {\r | |
232 | //\r | |
233 | // Try for GPT, then El Torito, and then legacy MBR partition types. If the\r | |
234 | // media supports a given partition type install child handles to represent\r | |
235 | // the partitions described by the media.\r | |
236 | //\r | |
237 | Routine = &mPartitionDetectRoutineTable[0];\r | |
238 | while (*Routine != NULL) {\r | |
239 | Status = (*Routine) (\r | |
240 | This,\r | |
241 | ControllerHandle,\r | |
242 | DiskIo,\r | |
243 | BlockIo,\r | |
244 | ParentDevicePath\r | |
245 | );\r | |
246 | if (!EFI_ERROR (Status) || Status == EFI_MEDIA_CHANGED) {\r | |
247 | break;\r | |
248 | }\r | |
249 | Routine++;\r | |
250 | }\r | |
251 | }\r | |
252 | //\r | |
253 | // In the case that the driver is already started (OpenStatus == EFI_ALREADY_STARTED),\r | |
254 | // the DevicePathProtocol and the DiskIoProtocol are not actually opened by the\r | |
255 | // driver. So don't try to close them. Otherwise, we will break the dependency\r | |
256 | // between the controller and the driver set up before.\r | |
257 | //\r | |
258 | if (EFI_ERROR (Status) && !EFI_ERROR (OpenStatus) && Status != EFI_MEDIA_CHANGED) {\r | |
259 | gBS->CloseProtocol (\r | |
260 | ControllerHandle,\r | |
261 | &gEfiDiskIoProtocolGuid,\r | |
262 | This->DriverBindingHandle,\r | |
263 | ControllerHandle\r | |
264 | );\r | |
265 | \r | |
266 | gBS->CloseProtocol (\r | |
267 | ControllerHandle,\r | |
268 | &gEfiDevicePathProtocolGuid,\r | |
269 | This->DriverBindingHandle,\r | |
270 | ControllerHandle\r | |
271 | );\r | |
272 | }\r | |
273 | \r | |
274 | return Status;\r | |
275 | }\r | |
276 | \r | |
b9575d60 A |
277 | \r |
278 | /**\r | |
279 | Stop this driver on ControllerHandle. Support stoping any child handles\r | |
280 | created by this driver.\r | |
281 | \r | |
282 | @param This Protocol instance pointer.\r | |
283 | @param ControllerHandle Handle of device to stop driver on\r | |
284 | @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r | |
285 | children is zero stop the entire bus driver.\r | |
286 | @param ChildHandleBuffer List of Child Handles to Stop.\r | |
287 | \r | |
288 | @retval EFI_SUCCESS This driver is removed ControllerHandle\r | |
289 | @retval other This driver was not removed from this device\r | |
290 | \r | |
291 | **/\r | |
79840ee1 | 292 | EFI_STATUS\r |
293 | EFIAPI\r | |
294 | PartitionDriverBindingStop (\r | |
295 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
296 | IN EFI_HANDLE ControllerHandle,\r | |
297 | IN UINTN NumberOfChildren,\r | |
298 | IN EFI_HANDLE *ChildHandleBuffer\r | |
299 | )\r | |
79840ee1 | 300 | {\r |
301 | EFI_STATUS Status;\r | |
302 | UINTN Index;\r | |
303 | EFI_BLOCK_IO_PROTOCOL *BlockIo;\r | |
304 | BOOLEAN AllChildrenStopped;\r | |
305 | PARTITION_PRIVATE_DATA *Private;\r | |
306 | EFI_DISK_IO_PROTOCOL *DiskIo;\r | |
307 | \r | |
308 | if (NumberOfChildren == 0) {\r | |
309 | //\r | |
310 | // Close the bus driver\r | |
311 | //\r | |
312 | gBS->CloseProtocol (\r | |
313 | ControllerHandle,\r | |
314 | &gEfiDiskIoProtocolGuid,\r | |
315 | This->DriverBindingHandle,\r | |
316 | ControllerHandle\r | |
317 | );\r | |
318 | \r | |
319 | gBS->CloseProtocol (\r | |
320 | ControllerHandle,\r | |
321 | &gEfiDevicePathProtocolGuid,\r | |
322 | This->DriverBindingHandle,\r | |
323 | ControllerHandle\r | |
324 | );\r | |
325 | \r | |
326 | return EFI_SUCCESS;\r | |
327 | }\r | |
328 | \r | |
329 | AllChildrenStopped = TRUE;\r | |
330 | for (Index = 0; Index < NumberOfChildren; Index++) {\r | |
331 | Status = gBS->OpenProtocol (\r | |
332 | ChildHandleBuffer[Index],\r | |
333 | &gEfiBlockIoProtocolGuid,\r | |
334 | (VOID **) &BlockIo,\r | |
335 | This->DriverBindingHandle,\r | |
336 | ControllerHandle,\r | |
337 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
338 | );\r | |
339 | if (!EFI_ERROR (Status)) {\r | |
340 | \r | |
341 | Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (BlockIo);\r | |
342 | \r | |
343 | //\r | |
344 | // All Software protocols have be freed from the handle so remove it.\r | |
345 | //\r | |
346 | BlockIo->FlushBlocks (BlockIo);\r | |
347 | \r | |
348 | Status = gBS->CloseProtocol (\r | |
349 | ControllerHandle,\r | |
350 | &gEfiDiskIoProtocolGuid,\r | |
351 | This->DriverBindingHandle,\r | |
352 | ChildHandleBuffer[Index]\r | |
353 | );\r | |
354 | \r | |
355 | Status = gBS->UninstallMultipleProtocolInterfaces (\r | |
356 | ChildHandleBuffer[Index],\r | |
357 | &gEfiDevicePathProtocolGuid,\r | |
358 | Private->DevicePath,\r | |
359 | &gEfiBlockIoProtocolGuid,\r | |
360 | &Private->BlockIo,\r | |
361 | Private->EspGuid,\r | |
362 | NULL,\r | |
363 | NULL\r | |
364 | );\r | |
365 | if (EFI_ERROR (Status)) {\r | |
366 | gBS->OpenProtocol (\r | |
367 | ControllerHandle,\r | |
368 | &gEfiDiskIoProtocolGuid,\r | |
369 | (VOID **) &DiskIo,\r | |
370 | This->DriverBindingHandle,\r | |
371 | ChildHandleBuffer[Index],\r | |
372 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
373 | );\r | |
374 | } else {\r | |
375 | FreePool (Private->DevicePath);\r | |
376 | FreePool (Private);\r | |
377 | }\r | |
378 | \r | |
379 | }\r | |
380 | \r | |
381 | if (EFI_ERROR (Status)) {\r | |
382 | AllChildrenStopped = FALSE;\r | |
383 | }\r | |
384 | }\r | |
385 | \r | |
386 | if (!AllChildrenStopped) {\r | |
387 | return EFI_DEVICE_ERROR;\r | |
388 | }\r | |
389 | \r | |
390 | return EFI_SUCCESS;\r | |
391 | }\r | |
392 | \r | |
b9575d60 A |
393 | \r |
394 | /**\r | |
395 | Reset the Block Device.\r | |
396 | \r | |
397 | @param This Protocol instance pointer.\r | |
398 | @param ExtendedVerification Driver may perform diagnostics on reset.\r | |
399 | \r | |
400 | @retval EFI_SUCCESS The device was reset.\r | |
401 | @retval EFI_DEVICE_ERROR The device is not functioning properly and could\r | |
402 | not be reset.\r | |
403 | \r | |
404 | **/\r | |
79840ee1 | 405 | STATIC\r |
406 | EFI_STATUS\r | |
407 | EFIAPI\r | |
408 | PartitionReset (\r | |
409 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
410 | IN BOOLEAN ExtendedVerification\r | |
411 | )\r | |
79840ee1 | 412 | {\r |
413 | PARTITION_PRIVATE_DATA *Private;\r | |
414 | \r | |
415 | Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);\r | |
416 | \r | |
417 | return Private->ParentBlockIo->Reset (\r | |
418 | Private->ParentBlockIo,\r | |
419 | ExtendedVerification\r | |
420 | );\r | |
421 | }\r | |
422 | \r | |
b9575d60 A |
423 | \r |
424 | /**\r | |
425 | Read by using the Disk IO protocol on the parent device. Lba addresses\r | |
426 | must be converted to byte offsets.\r | |
427 | \r | |
428 | @param This Protocol instance pointer.\r | |
429 | @param MediaId Id of the media, changes every time the media is replaced.\r | |
430 | @param Lba The starting Logical Block Address to read from\r | |
431 | @param BufferSize Size of Buffer, must be a multiple of device block size.\r | |
432 | @param Buffer Buffer containing read data\r | |
433 | \r | |
434 | @retval EFI_SUCCESS The data was read correctly from the device.\r | |
435 | @retval EFI_DEVICE_ERROR The device reported an error while performing the read.\r | |
436 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
437 | @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.\r | |
438 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
439 | @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not\r | |
440 | valid for the device.\r | |
441 | \r | |
442 | **/\r | |
79840ee1 | 443 | STATIC\r |
444 | EFI_STATUS\r | |
445 | EFIAPI\r | |
446 | PartitionReadBlocks (\r | |
447 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
448 | IN UINT32 MediaId,\r | |
449 | IN EFI_LBA Lba,\r | |
450 | IN UINTN BufferSize,\r | |
451 | OUT VOID *Buffer\r | |
452 | )\r | |
79840ee1 | 453 | {\r |
454 | PARTITION_PRIVATE_DATA *Private;\r | |
455 | UINT64 Offset;\r | |
456 | \r | |
457 | Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);\r | |
458 | \r | |
459 | if (BufferSize % Private->BlockSize != 0) {\r | |
460 | return EFI_BAD_BUFFER_SIZE;\r | |
461 | }\r | |
462 | \r | |
463 | Offset = MultU64x32 (Lba, Private->BlockSize) + Private->Start;\r | |
464 | if (Offset + BufferSize > Private->End) {\r | |
465 | return EFI_INVALID_PARAMETER;\r | |
466 | }\r | |
467 | //\r | |
468 | // Because some kinds of partition have different block size from their parent\r | |
469 | // device, we call the Disk IO protocol on the parent device, not the Block IO\r | |
470 | // protocol\r | |
471 | //\r | |
472 | return Private->DiskIo->ReadDisk (Private->DiskIo, MediaId, Offset, BufferSize, Buffer);\r | |
473 | }\r | |
474 | \r | |
b9575d60 A |
475 | /**\r |
476 | Write by using the Disk IO protocol on the parent device. Lba addresses\r | |
477 | must be converted to byte offsets.\r | |
478 | \r | |
479 | @param This Protocol instance pointer.\r | |
480 | @param MediaId Id of the media, changes every time the media is replaced.\r | |
481 | @param Lba The starting Logical Block Address to read from\r | |
482 | @param BufferSize Size of Buffer, must be a multiple of device block size.\r | |
483 | @param Buffer Buffer containing read data\r | |
484 | \r | |
485 | @retval EFI_SUCCESS The data was written correctly to the device.\r | |
486 | @retval EFI_WRITE_PROTECTED The device can not be written to.\r | |
487 | @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r | |
488 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
489 | @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r | |
490 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
491 | @retval EFI_INVALID_PARAMETER The write request contains a LBA that is not\r | |
492 | valid for the device.\r | |
493 | \r | |
494 | **/\r | |
79840ee1 | 495 | STATIC\r |
496 | EFI_STATUS\r | |
497 | EFIAPI\r | |
498 | PartitionWriteBlocks (\r | |
499 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
500 | IN UINT32 MediaId,\r | |
501 | IN EFI_LBA Lba,\r | |
502 | IN UINTN BufferSize,\r | |
503 | OUT VOID *Buffer\r | |
504 | )\r | |
79840ee1 | 505 | {\r |
506 | PARTITION_PRIVATE_DATA *Private;\r | |
507 | UINT64 Offset;\r | |
508 | \r | |
509 | Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);\r | |
510 | \r | |
511 | if (BufferSize % Private->BlockSize != 0) {\r | |
512 | return EFI_BAD_BUFFER_SIZE;\r | |
513 | }\r | |
514 | \r | |
515 | Offset = MultU64x32 (Lba, Private->BlockSize) + Private->Start;\r | |
516 | if (Offset + BufferSize > Private->End) {\r | |
517 | return EFI_INVALID_PARAMETER;\r | |
518 | }\r | |
519 | //\r | |
520 | // Because some kinds of partition have different block size from their parent\r | |
521 | // device, we call the Disk IO protocol on the parent device, not the Block IO\r | |
522 | // protocol\r | |
523 | //\r | |
524 | return Private->DiskIo->WriteDisk (Private->DiskIo, MediaId, Offset, BufferSize, Buffer);\r | |
525 | }\r | |
526 | \r | |
b9575d60 A |
527 | \r |
528 | /**\r | |
529 | Flush the parent Block Device.\r | |
530 | \r | |
531 | @param This Protocol instance pointer.\r | |
532 | \r | |
533 | @retval EFI_SUCCESS All outstanding data was written to the device\r | |
534 | @retval EFI_DEVICE_ERROR The device reported an error while writting back the data\r | |
535 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
536 | \r | |
537 | **/\r | |
79840ee1 | 538 | STATIC\r |
539 | EFI_STATUS\r | |
540 | EFIAPI\r | |
541 | PartitionFlushBlocks (\r | |
542 | IN EFI_BLOCK_IO_PROTOCOL *This\r | |
543 | )\r | |
79840ee1 | 544 | {\r |
545 | PARTITION_PRIVATE_DATA *Private;\r | |
546 | \r | |
547 | Private = PARTITION_DEVICE_FROM_BLOCK_IO_THIS (This);\r | |
548 | \r | |
549 | return Private->ParentBlockIo->FlushBlocks (Private->ParentBlockIo);\r | |
550 | }\r | |
551 | \r | |
b9575d60 A |
552 | \r |
553 | \r | |
554 | /**\r | |
555 | Create a child handle for a logical block device that represents the\r | |
556 | bytes Start to End of the Parent Block IO device.\r | |
557 | \r | |
558 | @param[in] This Protocol instance pointer.\r | |
559 | @param[in] This Calling context.\r | |
560 | @param[in] ParentHandle Parent Handle for new child\r | |
561 | @param[in] ParentDiskIo Parent DiskIo interface\r | |
562 | @param[in] ParentBlockIo Parent BlockIo interface\r | |
563 | @param[in] ParentDevicePath Parent Device Path\r | |
564 | @param[in] DevicePathNode Child Device Path node\r | |
565 | @param[in] Start Start Block\r | |
566 | @param[in] End End Block\r | |
567 | @param[in] BlockSize Child block size\r | |
568 | @param[in] InstallEspGuid Flag to install EFI System Partition GUID on handle\r | |
569 | \r | |
570 | @retval EFI_SUCCESS A child handle was added\r | |
571 | @retval other A child handle was not added\r | |
572 | \r | |
573 | **/\r | |
79840ee1 | 574 | EFI_STATUS\r |
575 | PartitionInstallChildHandle (\r | |
576 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
577 | IN EFI_HANDLE ParentHandle,\r | |
578 | IN EFI_DISK_IO_PROTOCOL *ParentDiskIo,\r | |
579 | IN EFI_BLOCK_IO_PROTOCOL *ParentBlockIo,\r | |
580 | IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,\r | |
581 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,\r | |
582 | IN EFI_LBA Start,\r | |
583 | IN EFI_LBA End,\r | |
584 | IN UINT32 BlockSize,\r | |
585 | IN BOOLEAN InstallEspGuid\r | |
586 | )\r | |
79840ee1 | 587 | {\r |
588 | EFI_STATUS Status;\r | |
589 | PARTITION_PRIVATE_DATA *Private;\r | |
590 | \r | |
591 | Private = AllocateZeroPool (sizeof (PARTITION_PRIVATE_DATA));\r | |
592 | if (Private == NULL) {\r | |
593 | return EFI_OUT_OF_RESOURCES;\r | |
594 | }\r | |
595 | \r | |
596 | Private->Signature = PARTITION_PRIVATE_DATA_SIGNATURE;\r | |
597 | \r | |
598 | Private->Start = MultU64x32 (Start, ParentBlockIo->Media->BlockSize);\r | |
599 | Private->End = MultU64x32 (End + 1, ParentBlockIo->Media->BlockSize);\r | |
600 | \r | |
601 | Private->BlockSize = BlockSize;\r | |
602 | Private->ParentBlockIo = ParentBlockIo;\r | |
603 | Private->DiskIo = ParentDiskIo;\r | |
604 | \r | |
605 | Private->BlockIo.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION;\r | |
606 | \r | |
607 | Private->BlockIo.Media = &Private->Media;\r | |
608 | CopyMem (Private->BlockIo.Media, ParentBlockIo->Media, sizeof (EFI_BLOCK_IO_MEDIA));\r | |
609 | Private->Media.LogicalPartition = TRUE;\r | |
610 | Private->Media.LastBlock = DivU64x32 (\r | |
611 | MultU64x32 (\r | |
612 | End - Start + 1,\r | |
613 | ParentBlockIo->Media->BlockSize\r | |
614 | ),\r | |
615 | BlockSize\r | |
616 | ) - 1;\r | |
617 | \r | |
618 | Private->Media.BlockSize = (UINT32) BlockSize;\r | |
619 | \r | |
620 | Private->BlockIo.Reset = PartitionReset;\r | |
621 | Private->BlockIo.ReadBlocks = PartitionReadBlocks;\r | |
622 | Private->BlockIo.WriteBlocks = PartitionWriteBlocks;\r | |
623 | Private->BlockIo.FlushBlocks = PartitionFlushBlocks;\r | |
624 | \r | |
625 | Private->DevicePath = AppendDevicePathNode (ParentDevicePath, DevicePathNode);\r | |
626 | \r | |
627 | if (Private->DevicePath == NULL) {\r | |
628 | FreePool (Private);\r | |
629 | return EFI_OUT_OF_RESOURCES;\r | |
630 | }\r | |
631 | \r | |
632 | if (InstallEspGuid) {\r | |
633 | Private->EspGuid = &gEfiPartTypeSystemPartGuid;\r | |
634 | } else {\r | |
635 | //\r | |
636 | // If NULL InstallMultipleProtocolInterfaces will ignore it.\r | |
637 | //\r | |
638 | Private->EspGuid = NULL;\r | |
639 | }\r | |
640 | //\r | |
641 | // Create the new handle\r | |
642 | //\r | |
643 | Private->Handle = NULL;\r | |
644 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
645 | &Private->Handle,\r | |
646 | &gEfiDevicePathProtocolGuid,\r | |
647 | Private->DevicePath,\r | |
648 | &gEfiBlockIoProtocolGuid,\r | |
649 | &Private->BlockIo,\r | |
650 | Private->EspGuid,\r | |
651 | NULL,\r | |
652 | NULL\r | |
653 | );\r | |
654 | \r | |
655 | if (!EFI_ERROR (Status)) {\r | |
656 | //\r | |
657 | // Open the Parent Handle for the child\r | |
658 | //\r | |
659 | Status = gBS->OpenProtocol (\r | |
660 | ParentHandle,\r | |
661 | &gEfiDiskIoProtocolGuid,\r | |
662 | (VOID **) &ParentDiskIo,\r | |
663 | This->DriverBindingHandle,\r | |
664 | Private->Handle,\r | |
665 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
666 | );\r | |
667 | } else {\r | |
668 | FreePool (Private->DevicePath);\r | |
669 | FreePool (Private);\r | |
670 | }\r | |
671 | \r | |
672 | return Status;\r | |
673 | }\r | |
b9575d60 A |
674 | \r |
675 | \r | |
676 | /**\r | |
677 | The user Entry Point for module Partition. The user code starts with this function.\r | |
678 | \r | |
679 | @param[in] ImageHandle The firmware allocated handle for the EFI image. \r | |
680 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
681 | \r | |
682 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
683 | @retval other Some error occurs when executing this entry point.\r | |
684 | \r | |
685 | **/\r | |
686 | EFI_STATUS\r | |
687 | EFIAPI\r | |
688 | InitializePartition (\r | |
689 | IN EFI_HANDLE ImageHandle,\r | |
690 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
691 | )\r | |
692 | {\r | |
693 | EFI_STATUS Status;\r | |
694 | \r | |
695 | //\r | |
696 | // Install driver model protocol(s).\r | |
697 | //\r | |
698 | Status = EfiLibInstallAllDriverProtocols (\r | |
699 | ImageHandle,\r | |
700 | SystemTable,\r | |
701 | &gPartitionDriverBinding,\r | |
702 | ImageHandle,\r | |
703 | &gPartitionComponentName,\r | |
704 | NULL,\r | |
705 | NULL\r | |
706 | );\r | |
707 | ASSERT_EFI_ERROR (Status);\r | |
708 | \r | |
709 | \r | |
710 | return Status;\r | |
711 | }\r | |
712 | \r |