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