]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Disk/PartitionDxe/Partition.h
Code scrub DxeIpl, Runtime, DevicePath, FvbServicesLib, DiskIo, Partition, English...
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / PartitionDxe / Partition.h
1 /** @file
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.
6
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
12
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.
15
16 **/
17
18 #ifndef _PARTITION_H_
19 #define _PARTITION_H_
20
21 #include <Uefi.h>
22 #include <Protocol/BlockIo.h>
23 #include <Guid/Gpt.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>
36
37 #include <IndustryStandard/Mbr.h>
38 #include <IndustryStandard/ElTorito.h>
39
40
41 //
42 // Partition private data
43 //
44 #define PARTITION_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('P', 'a', 'r', 't')
45 typedef struct {
46 UINT64 Signature;
47
48 EFI_HANDLE Handle;
49 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
50 EFI_BLOCK_IO_PROTOCOL BlockIo;
51 EFI_BLOCK_IO_MEDIA Media;
52
53 EFI_DISK_IO_PROTOCOL *DiskIo;
54 EFI_BLOCK_IO_PROTOCOL *ParentBlockIo;
55 UINT64 Start;
56 UINT64 End;
57 UINT32 BlockSize;
58
59 EFI_GUID *EspGuid;
60
61 } PARTITION_PRIVATE_DATA;
62
63 #define PARTITION_DEVICE_FROM_BLOCK_IO_THIS(a) CR (a, PARTITION_PRIVATE_DATA, BlockIo, PARTITION_PRIVATE_DATA_SIGNATURE)
64
65 //
66 // Global Variables
67 //
68 extern EFI_DRIVER_BINDING_PROTOCOL gPartitionDriverBinding;
69 extern EFI_COMPONENT_NAME_PROTOCOL gPartitionComponentName;
70 extern EFI_COMPONENT_NAME2_PROTOCOL gPartitionComponentName2;
71
72 //
73 // Extract INT32 from char array
74 //
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) )
79
80 //
81 // Extract UINT32 from char array
82 //
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) )
87
88
89 //
90 // GPT Partition Entry Status
91 //
92 typedef struct {
93 BOOLEAN OutOfRange;
94 BOOLEAN Overlap;
95 } EFI_PARTITION_ENTRY_STATUS;
96
97 //
98 // Function Prototypes
99 //
100 /**
101 Test to see if this driver supports ControllerHandle. Any ControllerHandle
102 than contains a BlockIo and DiskIo protocol can be supported.
103
104 @param This Protocol instance pointer.
105 @param ControllerHandle Handle of device to test
106 @param RemainingDevicePath Optional parameter use to pick a specific child
107 device to start.
108
109 @retval EFI_SUCCESS This driver supports this device
110 @retval EFI_ALREADY_STARTED This driver is already running on this device
111 @retval other This driver does not support this device
112
113 **/
114 EFI_STATUS
115 EFIAPI
116 PartitionDriverBindingSupported (
117 IN EFI_DRIVER_BINDING_PROTOCOL *This,
118 IN EFI_HANDLE ControllerHandle,
119 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
120 );
121
122 /**
123 Start this driver on ControllerHandle by opening a Block IO and Disk IO
124 protocol, reading Device Path, and creating a child handle with a
125 Disk IO and device path protocol.
126
127 @param This Protocol instance pointer.
128 @param ControllerHandle Handle of device to bind driver to
129 @param RemainingDevicePath Optional parameter use to pick a specific child
130 device to start.
131
132 @retval EFI_SUCCESS This driver is added to ControllerHandle
133 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
134 @retval other This driver does not support this device
135
136 **/
137 EFI_STATUS
138 EFIAPI
139 PartitionDriverBindingStart (
140 IN EFI_DRIVER_BINDING_PROTOCOL *This,
141 IN EFI_HANDLE ControllerHandle,
142 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
143 );
144
145 /**
146 Stop this driver on ControllerHandle. Support stopping any child handles
147 created by this driver.
148
149 @param This Protocol instance pointer.
150 @param ControllerHandle Handle of device to stop driver on
151 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
152 children is zero stop the entire bus driver.
153 @param ChildHandleBuffer List of Child Handles to Stop.
154
155 @retval EFI_SUCCESS This driver is removed ControllerHandle
156 @retval other This driver was not removed from this device
157
158 **/
159 EFI_STATUS
160 EFIAPI
161 PartitionDriverBindingStop (
162 IN EFI_DRIVER_BINDING_PROTOCOL *This,
163 IN EFI_HANDLE ControllerHandle,
164 IN UINTN NumberOfChildren,
165 IN EFI_HANDLE *ChildHandleBuffer
166 );
167
168 //
169 // EFI Component Name Functions
170 //
171 /**
172 Retrieves a Unicode string that is the user readable name of the driver.
173
174 This function retrieves the user readable name of a driver in the form of a
175 Unicode string. If the driver specified by This has a user readable name in
176 the language specified by Language, then a pointer to the driver name is
177 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
178 by This does not support the language specified by Language,
179 then EFI_UNSUPPORTED is returned.
180
181 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
182 EFI_COMPONENT_NAME_PROTOCOL instance.
183
184 @param Language[in] A pointer to a Null-terminated ASCII string
185 array indicating the language. This is the
186 language of the driver name that the caller is
187 requesting, and it must match one of the
188 languages specified in SupportedLanguages. The
189 number of languages supported by a driver is up
190 to the driver writer. Language is specified
191 in RFC 3066 or ISO 639-2 language code format.
192
193 @param DriverName[out] A pointer to the Unicode string to return.
194 This Unicode string is the name of the
195 driver specified by This in the language
196 specified by Language.
197
198 @retval EFI_SUCCESS The Unicode string for the Driver specified by
199 This and the language specified by Language was
200 returned in DriverName.
201
202 @retval EFI_INVALID_PARAMETER Language is NULL.
203
204 @retval EFI_INVALID_PARAMETER DriverName is NULL.
205
206 @retval EFI_UNSUPPORTED The driver specified by This does not support
207 the language specified by Language.
208
209 **/
210 EFI_STATUS
211 EFIAPI
212 PartitionComponentNameGetDriverName (
213 IN EFI_COMPONENT_NAME_PROTOCOL *This,
214 IN CHAR8 *Language,
215 OUT CHAR16 **DriverName
216 );
217
218
219 /**
220 Retrieves a Unicode string that is the user readable name of the controller
221 that is being managed by a driver.
222
223 This function retrieves the user readable name of the controller specified by
224 ControllerHandle and ChildHandle in the form of a Unicode string. If the
225 driver specified by This has a user readable name in the language specified by
226 Language, then a pointer to the controller name is returned in ControllerName,
227 and EFI_SUCCESS is returned. If the driver specified by This is not currently
228 managing the controller specified by ControllerHandle and ChildHandle,
229 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
230 support the language specified by Language, then EFI_UNSUPPORTED is returned.
231
232 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
233 EFI_COMPONENT_NAME_PROTOCOL instance.
234
235 @param ControllerHandle[in] The handle of a controller that the driver
236 specified by This is managing. This handle
237 specifies the controller whose name is to be
238 returned.
239
240 @param ChildHandle[in] The handle of the child controller to retrieve
241 the name of. This is an optional parameter that
242 may be NULL. It will be NULL for device
243 drivers. It will also be NULL for a bus drivers
244 that wish to retrieve the name of the bus
245 controller. It will not be NULL for a bus
246 driver that wishes to retrieve the name of a
247 child controller.
248
249 @param Language[in] A pointer to a Null-terminated ASCII string
250 array indicating the language. This is the
251 language of the driver name that the caller is
252 requesting, and it must match one of the
253 languages specified in SupportedLanguages. The
254 number of languages supported by a driver is up
255 to the driver writer. Language is specified in
256 RFC 3066 or ISO 639-2 language code format.
257
258 @param ControllerName[out] A pointer to the Unicode string to return.
259 This Unicode string is the name of the
260 controller specified by ControllerHandle and
261 ChildHandle in the language specified by
262 Language from the point of view of the driver
263 specified by This.
264
265 @retval EFI_SUCCESS The Unicode string for the user readable name in
266 the language specified by Language for the
267 driver specified by This was returned in
268 DriverName.
269
270 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
271
272 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
273 EFI_HANDLE.
274
275 @retval EFI_INVALID_PARAMETER Language is NULL.
276
277 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
278
279 @retval EFI_UNSUPPORTED The driver specified by This is not currently
280 managing the controller specified by
281 ControllerHandle and ChildHandle.
282
283 @retval EFI_UNSUPPORTED The driver specified by This does not support
284 the language specified by Language.
285
286 **/
287 EFI_STATUS
288 EFIAPI
289 PartitionComponentNameGetControllerName (
290 IN EFI_COMPONENT_NAME_PROTOCOL *This,
291 IN EFI_HANDLE ControllerHandle,
292 IN EFI_HANDLE ChildHandle OPTIONAL,
293 IN CHAR8 *Language,
294 OUT CHAR16 **ControllerName
295 );
296
297
298 /**
299 Create a child handle for a logical block device that represents the
300 bytes Start to End of the Parent Block IO device.
301
302 @param[in] This Protocol instance pointer
303 @param[in] ParentHandle Parent Handle for new child
304 @param[in] ParentDiskIo Parent DiskIo interface
305 @param[in] ParentBlockIo Parent BlockIo interface
306 @param[in] ParentDevicePath Parent Device Path
307 @param[in] DevicePathNode Child Device Path node
308 @param[in] Start Start Block
309 @param[in] End End Block
310 @param[in] BlockSize Child block size
311 @param[in] InstallEspGuid Flag to install EFI System Partition GUID on handle
312
313 @retval EFI_SUCCESS A child handle was added
314 @retval other A child handle was not added
315
316 **/
317 EFI_STATUS
318 PartitionInstallChildHandle (
319 IN EFI_DRIVER_BINDING_PROTOCOL *This,
320 IN EFI_HANDLE ParentHandle,
321 IN EFI_DISK_IO_PROTOCOL *ParentDiskIo,
322 IN EFI_BLOCK_IO_PROTOCOL *ParentBlockIo,
323 IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,
324 IN EFI_DEVICE_PATH_PROTOCOL *DevicePathNode,
325 IN EFI_LBA Start,
326 IN EFI_LBA End,
327 IN UINT32 BlockSize,
328 IN BOOLEAN InstallEspGuid
329 );
330
331 /**
332 Install child handles if the Handle supports GPT partition structure.
333
334 @param[in] This - Calling context.
335 @param[in] Handle - Parent Handle
336 @param[in] DiskIo - Parent DiskIo interface
337 @param[in] BlockIo - Parent BlockIo interface
338 @param[in] DevicePath - Parent Device Path
339
340 @retval EFI_SUCCESS Valid GPT disk
341 @retval EFI_MEDIA_CHANGED Media changed Detected
342 @retval other Not a valid GPT disk
343
344 **/
345 EFI_STATUS
346 PartitionInstallGptChildHandles (
347 IN EFI_DRIVER_BINDING_PROTOCOL *This,
348 IN EFI_HANDLE Handle,
349 IN EFI_DISK_IO_PROTOCOL *DiskIo,
350 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
351 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
352 );
353
354 /**
355 Install child handles if the Handle supports El Torito format.
356
357 @param[in] This Calling context.
358 @param[in] Handle Parent Handle
359 @param[in] DiskIo Parent DiskIo interface
360 @param[in] BlockIo Parent BlockIo interface
361 @param[in] DevicePath Parent Device Path
362
363
364 @retval EFI_SUCCESS Child handle(s) was added
365 @retval EFI_MEDIA_CHANGED Media changed Detected
366 @retval other no child handle was added
367
368 **/
369 EFI_STATUS
370 PartitionInstallElToritoChildHandles (
371 IN EFI_DRIVER_BINDING_PROTOCOL *This,
372 IN EFI_HANDLE Handle,
373 IN EFI_DISK_IO_PROTOCOL *DiskIo,
374 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
375 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
376 );
377
378 /**
379 Install child handles if the Handle supports MBR format.
380
381 @param This Calling context.
382 @param Handle Parent Handle.
383 @param DiskIo Parent DiskIo interface.
384 @param BlockIo Parent BlockIo interface.
385 @param DevicePath Parent Device Path.
386
387 @retval EFI_SUCCESS A child handle was added.
388 @retval EFI_MEDIA_CHANGED Media change was detected.
389 @retval Others MBR partition was not found.
390
391 **/
392 EFI_STATUS
393 PartitionInstallMbrChildHandles (
394 IN EFI_DRIVER_BINDING_PROTOCOL *This,
395 IN EFI_HANDLE Handle,
396 IN EFI_DISK_IO_PROTOCOL *DiskIo,
397 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
398 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
399 );
400
401 typedef
402 EFI_STATUS
403 (*PARTITION_DETECT_ROUTINE) (
404 IN EFI_DRIVER_BINDING_PROTOCOL *This,
405 IN EFI_HANDLE Handle,
406 IN EFI_DISK_IO_PROTOCOL *DiskIo,
407 IN EFI_BLOCK_IO_PROTOCOL *BlockIo,
408 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
409 );
410
411 #endif