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
93 PartitionDriverBindingSupported (
94 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
95 IN EFI_HANDLE ControllerHandle
,
96 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
101 PartitionDriverBindingStart (
102 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
103 IN EFI_HANDLE ControllerHandle
,
104 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
109 PartitionDriverBindingStop (
110 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
111 IN EFI_HANDLE ControllerHandle
,
112 IN UINTN NumberOfChildren
,
113 IN EFI_HANDLE
*ChildHandleBuffer
117 // EFI Component Name Functions
120 Retrieves a Unicode string that is the user readable name of the driver.
122 This function retrieves the user readable name of a driver in the form of a
123 Unicode string. If the driver specified by This has a user readable name in
124 the language specified by Language, then a pointer to the driver name is
125 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
126 by This does not support the language specified by Language,
127 then EFI_UNSUPPORTED is returned.
129 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
130 EFI_COMPONENT_NAME_PROTOCOL instance.
132 @param Language[in] A pointer to a Null-terminated ASCII string
133 array indicating the language. This is the
134 language of the driver name that the caller is
135 requesting, and it must match one of the
136 languages specified in SupportedLanguages. The
137 number of languages supported by a driver is up
138 to the driver writer. Language is specified
139 in RFC 3066 or ISO 639-2 language code format.
141 @param DriverName[out] A pointer to the Unicode string to return.
142 This Unicode string is the name of the
143 driver specified by This in the language
144 specified by Language.
146 @retval EFI_SUCCESS The Unicode string for the Driver specified by
147 This and the language specified by Language was
148 returned in DriverName.
150 @retval EFI_INVALID_PARAMETER Language is NULL.
152 @retval EFI_INVALID_PARAMETER DriverName is NULL.
154 @retval EFI_UNSUPPORTED The driver specified by This does not support
155 the language specified by Language.
160 PartitionComponentNameGetDriverName (
161 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
163 OUT CHAR16
**DriverName
168 Retrieves a Unicode string that is the user readable name of the controller
169 that is being managed by a driver.
171 This function retrieves the user readable name of the controller specified by
172 ControllerHandle and ChildHandle in the form of a Unicode string. If the
173 driver specified by This has a user readable name in the language specified by
174 Language, then a pointer to the controller name is returned in ControllerName,
175 and EFI_SUCCESS is returned. If the driver specified by This is not currently
176 managing the controller specified by ControllerHandle and ChildHandle,
177 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
178 support the language specified by Language, then EFI_UNSUPPORTED is returned.
180 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
181 EFI_COMPONENT_NAME_PROTOCOL instance.
183 @param ControllerHandle[in] The handle of a controller that the driver
184 specified by This is managing. This handle
185 specifies the controller whose name is to be
188 @param ChildHandle[in] The handle of the child controller to retrieve
189 the name of. This is an optional parameter that
190 may be NULL. It will be NULL for device
191 drivers. It will also be NULL for a bus drivers
192 that wish to retrieve the name of the bus
193 controller. It will not be NULL for a bus
194 driver that wishes to retrieve the name of a
197 @param Language[in] A pointer to a Null-terminated ASCII string
198 array indicating the language. This is the
199 language of the driver name that the caller is
200 requesting, and it must match one of the
201 languages specified in SupportedLanguages. The
202 number of languages supported by a driver is up
203 to the driver writer. Language is specified in
204 RFC 3066 or ISO 639-2 language code format.
206 @param ControllerName[out] A pointer to the Unicode string to return.
207 This Unicode string is the name of the
208 controller specified by ControllerHandle and
209 ChildHandle in the language specified by
210 Language from the point of view of the driver
213 @retval EFI_SUCCESS The Unicode string for the user readable name in
214 the language specified by Language for the
215 driver specified by This was returned in
218 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
220 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
223 @retval EFI_INVALID_PARAMETER Language is NULL.
225 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
227 @retval EFI_UNSUPPORTED The driver specified by This is not currently
228 managing the controller specified by
229 ControllerHandle and ChildHandle.
231 @retval EFI_UNSUPPORTED The driver specified by This does not support
232 the language specified by Language.
237 PartitionComponentNameGetControllerName (
238 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
239 IN EFI_HANDLE ControllerHandle
,
240 IN EFI_HANDLE ChildHandle OPTIONAL
,
242 OUT CHAR16
**ControllerName
247 PartitionInstallChildHandle (
248 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
249 IN EFI_HANDLE ParentHandle
,
250 IN EFI_DISK_IO_PROTOCOL
*ParentDiskIo
,
251 IN EFI_BLOCK_IO_PROTOCOL
*ParentBlockIo
,
252 IN EFI_DEVICE_PATH_PROTOCOL
*ParentDevicePath
,
253 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
257 IN BOOLEAN InstallEspGuid
262 PartitionInstallGptChildHandles (
263 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
264 IN EFI_HANDLE Handle
,
265 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
266 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
267 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
272 PartitionInstallElToritoChildHandles (
273 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
274 IN EFI_HANDLE Handle
,
275 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
276 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
277 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
282 PartitionInstallMbrChildHandles (
283 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
284 IN EFI_HANDLE Handle
,
285 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
286 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
287 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
293 (*PARTITION_DETECT_ROUTINE
) (
294 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
295 IN EFI_HANDLE Handle
,
296 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
297 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
298 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath