2 Partition driver that produces logical BlockIo devices from a physical
3 BlockIo device. The logical BlockIo devices are based on the format
4 of the raw block devices media. Currently "El Torito CD-ROM", Legacy
5 MBR, and GPT partition schemes are supported.
7 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #include <Protocol/BlockIo.h>
24 #include <Protocol/ComponentName.h>
25 #include <Protocol/DevicePath.h>
26 #include <Protocol/DriverBinding.h>
27 #include <Protocol/DiskIo.h>
28 #include <Library/DebugLib.h>
29 #include <Library/UefiDriverEntryPoint.h>
30 #include <Library/BaseLib.h>
31 #include <Library/UefiLib.h>
32 #include <Library/BaseMemoryLib.h>
33 #include <Library/MemoryAllocationLib.h>
34 #include <Library/UefiBootServicesTableLib.h>
35 #include <Library/DevicePathLib.h>
37 #include <IndustryStandard/Mbr.h>
38 #include <IndustryStandard/ElTorito.h>
42 // Partition private data
44 #define PARTITION_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32 ('P', 'a', 'r', 't')
49 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
50 EFI_BLOCK_IO_PROTOCOL BlockIo
;
51 EFI_BLOCK_IO_MEDIA Media
;
53 EFI_DISK_IO_PROTOCOL
*DiskIo
;
54 EFI_BLOCK_IO_PROTOCOL
*ParentBlockIo
;
61 } PARTITION_PRIVATE_DATA
;
63 #define PARTITION_DEVICE_FROM_BLOCK_IO_THIS(a) CR (a, PARTITION_PRIVATE_DATA, BlockIo, PARTITION_PRIVATE_DATA_SIGNATURE)
68 extern EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding
;
69 extern EFI_COMPONENT_NAME_PROTOCOL gPartitionComponentName
;
70 extern EFI_COMPONENT_NAME2_PROTOCOL gPartitionComponentName2
;
73 // Extract INT32 from char array
75 #define UNPACK_INT32(a) (INT32)( (((UINT8 *) a)[0] << 0) | \
76 (((UINT8 *) a)[1] << 8) | \
77 (((UINT8 *) a)[2] << 16) | \
78 (((UINT8 *) a)[3] << 24) )
81 // Extract UINT32 from char array
83 #define UNPACK_UINT32(a) (UINT32)( (((UINT8 *) a)[0] << 0) | \
84 (((UINT8 *) a)[1] << 8) | \
85 (((UINT8 *) a)[2] << 16) | \
86 (((UINT8 *) a)[3] << 24) )
89 // Function Prototypes
92 Test to see if this driver supports ControllerHandle. Any ControllerHandle
93 than contains a BlockIo and DiskIo protocol can be supported.
95 @param This Protocol instance pointer.
96 @param ControllerHandle Handle of device to test
97 @param RemainingDevicePath Optional parameter use to pick a specific child
100 @retval EFI_SUCCESS This driver supports this device
101 @retval EFI_ALREADY_STARTED This driver is already running on this device
102 @retval other This driver does not support this device
107 PartitionDriverBindingSupported (
108 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
109 IN EFI_HANDLE ControllerHandle
,
110 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
114 Start this driver on ControllerHandle by opening a Block IO and Disk IO
115 protocol, reading Device Path, and creating a child handle with a
116 Disk IO and device path protocol.
118 @param This Protocol instance pointer.
119 @param ControllerHandle Handle of device to bind driver to
120 @param RemainingDevicePath Optional parameter use to pick a specific child
123 @retval EFI_SUCCESS This driver is added to ControllerHandle
124 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
125 @retval other This driver does not support this device
130 PartitionDriverBindingStart (
131 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
132 IN EFI_HANDLE ControllerHandle
,
133 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
137 Stop this driver on ControllerHandle. Support stoping any child handles
138 created by this driver.
140 @param This Protocol instance pointer.
141 @param ControllerHandle Handle of device to stop driver on
142 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
143 children is zero stop the entire bus driver.
144 @param ChildHandleBuffer List of Child Handles to Stop.
146 @retval EFI_SUCCESS This driver is removed ControllerHandle
147 @retval other This driver was not removed from this device
152 PartitionDriverBindingStop (
153 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
154 IN EFI_HANDLE ControllerHandle
,
155 IN UINTN NumberOfChildren
,
156 IN EFI_HANDLE
*ChildHandleBuffer
160 // EFI Component Name Functions
163 Retrieves a Unicode string that is the user readable name of the driver.
165 This function retrieves the user readable name of a driver in the form of a
166 Unicode string. If the driver specified by This has a user readable name in
167 the language specified by Language, then a pointer to the driver name is
168 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
169 by This does not support the language specified by Language,
170 then EFI_UNSUPPORTED is returned.
172 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
173 EFI_COMPONENT_NAME_PROTOCOL instance.
175 @param Language[in] A pointer to a Null-terminated ASCII string
176 array indicating the language. This is the
177 language of the driver name that the caller is
178 requesting, and it must match one of the
179 languages specified in SupportedLanguages. The
180 number of languages supported by a driver is up
181 to the driver writer. Language is specified
182 in RFC 3066 or ISO 639-2 language code format.
184 @param DriverName[out] A pointer to the Unicode string to return.
185 This Unicode string is the name of the
186 driver specified by This in the language
187 specified by Language.
189 @retval EFI_SUCCESS The Unicode string for the Driver specified by
190 This and the language specified by Language was
191 returned in DriverName.
193 @retval EFI_INVALID_PARAMETER Language is NULL.
195 @retval EFI_INVALID_PARAMETER DriverName is NULL.
197 @retval EFI_UNSUPPORTED The driver specified by This does not support
198 the language specified by Language.
203 PartitionComponentNameGetDriverName (
204 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
206 OUT CHAR16
**DriverName
211 Retrieves a Unicode string that is the user readable name of the controller
212 that is being managed by a driver.
214 This function retrieves the user readable name of the controller specified by
215 ControllerHandle and ChildHandle in the form of a Unicode string. If the
216 driver specified by This has a user readable name in the language specified by
217 Language, then a pointer to the controller name is returned in ControllerName,
218 and EFI_SUCCESS is returned. If the driver specified by This is not currently
219 managing the controller specified by ControllerHandle and ChildHandle,
220 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
221 support the language specified by Language, then EFI_UNSUPPORTED is returned.
223 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
224 EFI_COMPONENT_NAME_PROTOCOL instance.
226 @param ControllerHandle[in] The handle of a controller that the driver
227 specified by This is managing. This handle
228 specifies the controller whose name is to be
231 @param ChildHandle[in] The handle of the child controller to retrieve
232 the name of. This is an optional parameter that
233 may be NULL. It will be NULL for device
234 drivers. It will also be NULL for a bus drivers
235 that wish to retrieve the name of the bus
236 controller. It will not be NULL for a bus
237 driver that wishes to retrieve the name of a
240 @param Language[in] A pointer to a Null-terminated ASCII string
241 array indicating the language. This is the
242 language of the driver name that the caller is
243 requesting, and it must match one of the
244 languages specified in SupportedLanguages. The
245 number of languages supported by a driver is up
246 to the driver writer. Language is specified in
247 RFC 3066 or ISO 639-2 language code format.
249 @param ControllerName[out] A pointer to the Unicode string to return.
250 This Unicode string is the name of the
251 controller specified by ControllerHandle and
252 ChildHandle in the language specified by
253 Language from the point of view of the driver
256 @retval EFI_SUCCESS The Unicode string for the user readable name in
257 the language specified by Language for the
258 driver specified by This was returned in
261 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
263 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
266 @retval EFI_INVALID_PARAMETER Language is NULL.
268 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
270 @retval EFI_UNSUPPORTED The driver specified by This is not currently
271 managing the controller specified by
272 ControllerHandle and ChildHandle.
274 @retval EFI_UNSUPPORTED The driver specified by This does not support
275 the language specified by Language.
280 PartitionComponentNameGetControllerName (
281 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
282 IN EFI_HANDLE ControllerHandle
,
283 IN EFI_HANDLE ChildHandle OPTIONAL
,
285 OUT CHAR16
**ControllerName
290 Create a child handle for a logical block device that represents the
291 bytes Start to End of the Parent Block IO device.
293 @param[in] This Protocol instance pointer
294 @param[in] ParentHandle Parent Handle for new child
295 @param[in] ParentDiskIo Parent DiskIo interface
296 @param[in] ParentBlockIo Parent BlockIo interface
297 @param[in] ParentDevicePath Parent Device Path
298 @param[in] DevicePathNode Child Device Path node
299 @param[in] Start Start Block
300 @param[in] End End Block
301 @param[in] BlockSize Child block size
302 @param[in] InstallEspGuid Flag to install EFI System Partition GUID on handle
304 @retval EFI_SUCCESS A child handle was added
305 @retval other A child handle was not added
309 PartitionInstallChildHandle (
310 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
311 IN EFI_HANDLE ParentHandle
,
312 IN EFI_DISK_IO_PROTOCOL
*ParentDiskIo
,
313 IN EFI_BLOCK_IO_PROTOCOL
*ParentBlockIo
,
314 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
315 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
319 IN BOOLEAN InstallEspGuid
324 Install child handles if the Handle supports GPT partition structure.
326 @param[in] This - Calling context.
327 @param[in] Handle - Parent Handle
328 @param[in] DiskIo - Parent DiskIo interface
329 @param[in] BlockIo - Parent BlockIo interface
330 @param[in] DevicePath - Parent Device Path
332 @retval EFI_SUCCESS Valid GPT disk
333 @retval EFI_MEDIA_CHANGED Media changed Detected
334 @retval other Not a valid GPT disk
338 PartitionInstallGptChildHandles (
339 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
340 IN EFI_HANDLE Handle
,
341 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
342 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
343 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
348 Install child handles if the Handle supports El Torito format.
350 @param[in] This Calling context.
351 @param[in] Handle Parent Handle
352 @param[in] DiskIo Parent DiskIo interface
353 @param[in] BlockIo Parent BlockIo interface
354 @param[in] DevicePath Parent Device Path
357 @retval EFI_SUCCESS Child handle(s) was added
358 @retval EFI_MEDIA_CHANGED Media changed Detected
359 @retval other no child handle was added
363 PartitionInstallElToritoChildHandles (
364 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
365 IN EFI_HANDLE Handle
,
366 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
367 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
368 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
373 Install child handles if the Handle supports MBR format.
375 @param This Calling context.
376 @param Handle Parent Handle.
377 @param DiskIo Parent DiskIo interface.
378 @param BlockIo Parent BlockIo interface.
379 @param DevicePath Parent Device Path.
381 @retval EFI_SUCCESS A child handle was added.
382 @retval EFI_MEDIA_CHANGED Media change was detected.
383 @retval Others MBR partition was not found.
387 PartitionInstallMbrChildHandles (
388 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
389 IN EFI_HANDLE Handle
,
390 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
391 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
392 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
398 (*PARTITION_DETECT_ROUTINE
) (
399 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
400 IN EFI_HANDLE Handle
,
401 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
402 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
403 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath