2 Master header file for DiskIo driver. It includes the module private defininitions.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include <Protocol/BlockIo.h>
14 #include <Protocol/BlockIo2.h>
15 #include <Protocol/DiskIo2.h>
16 #include <Protocol/ComponentName.h>
17 #include <Protocol/DriverBinding.h>
18 #include <Protocol/DiskIo.h>
19 #include <Library/DebugLib.h>
20 #include <Library/UefiDriverEntryPoint.h>
21 #include <Library/UefiLib.h>
22 #include <Library/BaseLib.h>
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/MemoryAllocationLib.h>
25 #include <Library/UefiBootServicesTableLib.h>
27 #define DISK_IO_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('d', 's', 'k', 'I')
31 EFI_DISK_IO_PROTOCOL DiskIo
;
32 EFI_DISK_IO2_PROTOCOL DiskIo2
;
33 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
34 EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
;
36 UINT8
*SharedWorkingBuffer
;
38 EFI_LOCK TaskQueueLock
;
40 } DISK_IO_PRIVATE_DATA
;
41 #define DISK_IO_PRIVATE_DATA_FROM_DISK_IO(a) CR (a, DISK_IO_PRIVATE_DATA, DiskIo, DISK_IO_PRIVATE_DATA_SIGNATURE)
42 #define DISK_IO_PRIVATE_DATA_FROM_DISK_IO2(a) CR (a, DISK_IO_PRIVATE_DATA, DiskIo2, DISK_IO_PRIVATE_DATA_SIGNATURE)
44 #define DISK_IO2_TASK_SIGNATURE SIGNATURE_32 ('d', 'i', 'a', 't')
47 LIST_ENTRY Link
; /// < link to other task
48 EFI_LOCK SubtasksLock
;
49 LIST_ENTRY Subtasks
; /// < header of subtasks
50 EFI_DISK_IO2_TOKEN
*Token
;
51 DISK_IO_PRIVATE_DATA
*Instance
;
54 #define DISK_IO2_FLUSH_TASK_SIGNATURE SIGNATURE_32 ('d', 'i', 'f', 't')
57 EFI_BLOCK_IO2_TOKEN BlockIo2Token
;
58 EFI_DISK_IO2_TOKEN
*Token
;
59 } DISK_IO2_FLUSH_TASK
;
61 #define DISK_IO_SUBTASK_SIGNATURE SIGNATURE_32 ('d', 'i', 's', 't')
64 // UnderRun: Offset != 0, Length < BlockSize
65 // OverRun: Offset == 0, Length < BlockSize
66 // Middle: Offset is block aligned, Length is multiple of block size
74 UINT8
*WorkingBuffer
; /// < NULL indicates using "Buffer" directly
79 // Following fields are for DiskIo2
82 EFI_BLOCK_IO2_TOKEN BlockIo2Token
;
88 extern EFI_DRIVER_BINDING_PROTOCOL gDiskIoDriverBinding
;
89 extern EFI_COMPONENT_NAME_PROTOCOL gDiskIoComponentName
;
90 extern EFI_COMPONENT_NAME2_PROTOCOL gDiskIoComponentName2
;
94 // Driver model protocol interface
97 Test to see if this driver supports ControllerHandle.
99 @param This Protocol instance pointer.
100 @param ControllerHandle Handle of device to test
101 @param RemainingDevicePath Optional parameter use to pick a specific child
104 @retval EFI_SUCCESS This driver supports this device
105 @retval EFI_ALREADY_STARTED This driver is already running on this device
106 @retval other This driver does not support this device
111 DiskIoDriverBindingSupported (
112 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
113 IN EFI_HANDLE ControllerHandle
,
114 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
118 Start this driver on ControllerHandle by opening a Block IO protocol and
119 installing a Disk IO protocol on ControllerHandle.
121 @param This Protocol instance pointer.
122 @param ControllerHandle Handle of device to bind driver to
123 @param RemainingDevicePath Optional parameter use to pick a specific child
126 @retval EFI_SUCCESS This driver is added to ControllerHandle
127 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
128 @retval other This driver does not support this device
133 DiskIoDriverBindingStart (
134 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
135 IN EFI_HANDLE ControllerHandle
,
136 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
140 Stop this driver on ControllerHandle by removing Disk IO protocol and closing
141 the Block IO protocol on ControllerHandle.
143 @param This Protocol instance pointer.
144 @param ControllerHandle Handle of device to stop driver on
145 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
146 children is zero stop the entire bus driver.
147 @param ChildHandleBuffer List of Child Handles to Stop.
149 @retval EFI_SUCCESS This driver is removed ControllerHandle
150 @retval other This driver was not removed from this device
155 DiskIoDriverBindingStop (
156 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
157 IN EFI_HANDLE ControllerHandle
,
158 IN UINTN NumberOfChildren
,
159 IN EFI_HANDLE
*ChildHandleBuffer
163 // Disk I/O Protocol Interface
166 Read BufferSize bytes from Offset into Buffer.
167 Reads may support reads that are not aligned on
168 sector boundaries. There are three cases:
169 UnderRun - The first byte is not on a sector boundary or the read request is
170 less than a sector in length.
171 Aligned - A read of N contiguous sectors.
172 OverRun - The last byte is not on a sector boundary.
174 @param This Protocol instance pointer.
175 @param MediaId Id of the media, changes every time the media is replaced.
176 @param Offset The starting byte offset to read from
177 @param BufferSize Size of Buffer
178 @param Buffer Buffer containing read data
180 @retval EFI_SUCCESS The data was read correctly from the device.
181 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
182 @retval EFI_NO_MEDIA There is no media in the device.
183 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
184 @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not
185 valid for the device.
191 IN EFI_DISK_IO_PROTOCOL
*This
,
199 Writes BufferSize bytes from Buffer into Offset.
200 Writes may require a read modify write to support writes that are not
201 aligned on sector boundaries. There are three cases:
202 UnderRun - The first byte is not on a sector boundary or the write request
203 is less than a sector in length. Read modify write is required.
204 Aligned - A write of N contiguous sectors.
205 OverRun - The last byte is not on a sector boundary. Read modified write
208 @param This Protocol instance pointer.
209 @param MediaId Id of the media, changes every time the media is replaced.
210 @param Offset The starting byte offset to read from
211 @param BufferSize Size of Buffer
212 @param Buffer Buffer containing read data
214 @retval EFI_SUCCESS The data was written correctly to the device.
215 @retval EFI_WRITE_PROTECTED The device can not be written to.
216 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
217 @retval EFI_NO_MEDIA There is no media in the device.
218 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
219 @retval EFI_INVALID_PARAMETER The write request contains device addresses that are not
220 valid for the device.
226 IN EFI_DISK_IO_PROTOCOL
*This
,
235 Terminate outstanding asynchronous requests to a device.
237 @param This Indicates a pointer to the calling context.
239 @retval EFI_SUCCESS All outstanding requests were successfully terminated.
240 @retval EFI_DEVICE_ERROR The device reported an error while performing the cancel
246 IN EFI_DISK_IO2_PROTOCOL
*This
250 Reads a specified number of bytes from a device.
252 @param This Indicates a pointer to the calling context.
253 @param MediaId ID of the medium to be read.
254 @param Offset The starting byte offset on the logical block I/O device to read from.
255 @param Token A pointer to the token associated with the transaction.
256 If this field is NULL, synchronous/blocking IO is performed.
257 @param BufferSize The size in bytes of Buffer. The number of bytes to read from the device.
258 @param Buffer A pointer to the destination buffer for the data.
259 The caller is responsible either having implicit or explicit ownership of the buffer.
261 @retval EFI_SUCCESS If Event is NULL (blocking I/O): The data was read correctly from the device.
262 If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.
263 Event will be signaled upon completion.
264 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
265 @retval EFI_NO_MEDIA There is no medium in the device.
266 @retval EFI_MEDIA_CHNAGED The MediaId is not for the current medium.
267 @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not valid for the device.
268 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
274 IN EFI_DISK_IO2_PROTOCOL
*This
,
277 IN OUT EFI_DISK_IO2_TOKEN
*Token
,
283 Writes a specified number of bytes to a device.
285 @param This Indicates a pointer to the calling context.
286 @param MediaId ID of the medium to be written.
287 @param Offset The starting byte offset on the logical block I/O device to write to.
288 @param Token A pointer to the token associated with the transaction.
289 If this field is NULL, synchronous/blocking IO is performed.
290 @param BufferSize The size in bytes of Buffer. The number of bytes to write to the device.
291 @param Buffer A pointer to the buffer containing the data to be written.
293 @retval EFI_SUCCESS If Event is NULL (blocking I/O): The data was written correctly to the device.
294 If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.
295 Event will be signaled upon completion.
296 @retval EFI_WRITE_PROTECTED The device cannot be written to.
297 @retval EFI_DEVICE_ERROR The device reported an error while performing the write operation.
298 @retval EFI_NO_MEDIA There is no medium in the device.
299 @retval EFI_MEDIA_CHNAGED The MediaId is not for the current medium.
300 @retval EFI_INVALID_PARAMETER The write request contains device addresses that are not valid for the device.
301 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
307 IN EFI_DISK_IO2_PROTOCOL
*This
,
310 IN EFI_DISK_IO2_TOKEN
*Token
,
316 Flushes all modified data to the physical device.
318 @param This Indicates a pointer to the calling context.
319 @param Token A pointer to the token associated with the transaction.
320 If this field is NULL, synchronous/blocking IO is performed.
322 @retval EFI_SUCCESS If Event is NULL (blocking I/O): The data was flushed successfully to the device.
323 If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.
324 Event will be signaled upon completion.
325 @retval EFI_WRITE_PROTECTED The device cannot be written to.
326 @retval EFI_DEVICE_ERROR The device reported an error while performing the write operation.
327 @retval EFI_NO_MEDIA There is no medium in the device.
328 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
333 IN EFI_DISK_IO2_PROTOCOL
*This
,
334 IN OUT EFI_DISK_IO2_TOKEN
*Token
338 // EFI Component Name Functions
341 Retrieves a Unicode string that is the user readable name of the driver.
343 This function retrieves the user readable name of a driver in the form of a
344 Unicode string. If the driver specified by This has a user readable name in
345 the language specified by Language, then a pointer to the driver name is
346 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
347 by This does not support the language specified by Language,
348 then EFI_UNSUPPORTED is returned.
350 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
351 EFI_COMPONENT_NAME_PROTOCOL instance.
353 @param Language[in] A pointer to a Null-terminated ASCII string
354 array indicating the language. This is the
355 language of the driver name that the caller is
356 requesting, and it must match one of the
357 languages specified in SupportedLanguages. The
358 number of languages supported by a driver is up
359 to the driver writer. Language is specified
360 in RFC 4646 or ISO 639-2 language code format.
362 @param DriverName[out] A pointer to the Unicode string to return.
363 This Unicode string is the name of the
364 driver specified by This in the language
365 specified by Language.
367 @retval EFI_SUCCESS The Unicode string for the Driver specified by
368 This and the language specified by Language was
369 returned in DriverName.
371 @retval EFI_INVALID_PARAMETER Language is NULL.
373 @retval EFI_INVALID_PARAMETER DriverName is NULL.
375 @retval EFI_UNSUPPORTED The driver specified by This does not support
376 the language specified by Language.
381 DiskIoComponentNameGetDriverName (
382 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
384 OUT CHAR16
**DriverName
389 Retrieves a Unicode string that is the user readable name of the controller
390 that is being managed by a driver.
392 This function retrieves the user readable name of the controller specified by
393 ControllerHandle and ChildHandle in the form of a Unicode string. If the
394 driver specified by This has a user readable name in the language specified by
395 Language, then a pointer to the controller name is returned in ControllerName,
396 and EFI_SUCCESS is returned. If the driver specified by This is not currently
397 managing the controller specified by ControllerHandle and ChildHandle,
398 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
399 support the language specified by Language, then EFI_UNSUPPORTED is returned.
401 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
402 EFI_COMPONENT_NAME_PROTOCOL instance.
404 @param ControllerHandle[in] The handle of a controller that the driver
405 specified by This is managing. This handle
406 specifies the controller whose name is to be
409 @param ChildHandle[in] The handle of the child controller to retrieve
410 the name of. This is an optional parameter that
411 may be NULL. It will be NULL for device
412 drivers. It will also be NULL for a bus drivers
413 that wish to retrieve the name of the bus
414 controller. It will not be NULL for a bus
415 driver that wishes to retrieve the name of a
418 @param Language[in] A pointer to a Null-terminated ASCII string
419 array indicating the language. This is the
420 language of the driver name that the caller is
421 requesting, and it must match one of the
422 languages specified in SupportedLanguages. The
423 number of languages supported by a driver is up
424 to the driver writer. Language is specified in
425 RFC 4646 or ISO 639-2 language code format.
427 @param ControllerName[out] A pointer to the Unicode string to return.
428 This Unicode string is the name of the
429 controller specified by ControllerHandle and
430 ChildHandle in the language specified by
431 Language from the point of view of the driver
434 @retval EFI_SUCCESS The Unicode string for the user readable name in
435 the language specified by Language for the
436 driver specified by This was returned in
439 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
441 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
444 @retval EFI_INVALID_PARAMETER Language is NULL.
446 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
448 @retval EFI_UNSUPPORTED The driver specified by This is not currently
449 managing the controller specified by
450 ControllerHandle and ChildHandle.
452 @retval EFI_UNSUPPORTED The driver specified by This does not support
453 the language specified by Language.
458 DiskIoComponentNameGetControllerName (
459 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
460 IN EFI_HANDLE ControllerHandle
,
461 IN EFI_HANDLE ChildHandle OPTIONAL
,
463 OUT CHAR16
**ControllerName