]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIo.h
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / DiskIoDxe / DiskIo.h
CommitLineData
adbcbf8f 1/** @file\r
ff61847d 2 Master header file for DiskIo driver. It includes the module private defininitions.\r
adbcbf8f 3\r
d1102dba 4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
adbcbf8f 6\r
7**/\r
8\r
ea7cb08c 9#ifndef _DISK_IO_H_\r
10#define _DISK_IO_H_\r
adbcbf8f 11\r
12#include <Uefi.h>\r
13#include <Protocol/BlockIo.h>\r
493d8e3a
RN
14#include <Protocol/BlockIo2.h>\r
15#include <Protocol/DiskIo2.h>\r
adbcbf8f 16#include <Protocol/ComponentName.h>\r
17#include <Protocol/DriverBinding.h>\r
18#include <Protocol/DiskIo.h>\r
19#include <Library/DebugLib.h>\r
20#include <Library/UefiDriverEntryPoint.h>\r
21#include <Library/UefiLib.h>\r
22#include <Library/BaseLib.h>\r
23#include <Library/BaseMemoryLib.h>\r
24#include <Library/MemoryAllocationLib.h>\r
25#include <Library/UefiBootServicesTableLib.h>\r
26\r
48557c65 27#define DISK_IO_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('d', 's', 'k', 'I')\r
adbcbf8f 28typedef struct {\r
1436aea4 29 UINT32 Signature;\r
493d8e3a 30\r
1436aea4
MK
31 EFI_DISK_IO_PROTOCOL DiskIo;\r
32 EFI_DISK_IO2_PROTOCOL DiskIo2;\r
33 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
34 EFI_BLOCK_IO2_PROTOCOL *BlockIo2;\r
493d8e3a 35\r
1436aea4 36 UINT8 *SharedWorkingBuffer;\r
493d8e3a 37\r
1436aea4
MK
38 EFI_LOCK TaskQueueLock;\r
39 LIST_ENTRY TaskQueue;\r
adbcbf8f 40} DISK_IO_PRIVATE_DATA;\r
1436aea4
MK
41#define DISK_IO_PRIVATE_DATA_FROM_DISK_IO(a) CR (a, DISK_IO_PRIVATE_DATA, DiskIo, DISK_IO_PRIVATE_DATA_SIGNATURE)\r
42#define DISK_IO_PRIVATE_DATA_FROM_DISK_IO2(a) CR (a, DISK_IO_PRIVATE_DATA, DiskIo2, DISK_IO_PRIVATE_DATA_SIGNATURE)\r
adbcbf8f 43\r
1436aea4 44#define DISK_IO2_TASK_SIGNATURE SIGNATURE_32 ('d', 'i', 'a', 't')\r
493d8e3a 45typedef struct {\r
1436aea4
MK
46 UINT32 Signature;\r
47 LIST_ENTRY Link; /// < link to other task\r
48 EFI_LOCK SubtasksLock;\r
49 LIST_ENTRY Subtasks; /// < header of subtasks\r
50 EFI_DISK_IO2_TOKEN *Token;\r
51 DISK_IO_PRIVATE_DATA *Instance;\r
493d8e3a
RN
52} DISK_IO2_TASK;\r
53\r
1436aea4 54#define DISK_IO2_FLUSH_TASK_SIGNATURE SIGNATURE_32 ('d', 'i', 'f', 't')\r
493d8e3a 55typedef struct {\r
1436aea4
MK
56 UINT32 Signature;\r
57 EFI_BLOCK_IO2_TOKEN BlockIo2Token;\r
58 EFI_DISK_IO2_TOKEN *Token;\r
493d8e3a
RN
59} DISK_IO2_FLUSH_TASK;\r
60\r
1436aea4 61#define DISK_IO_SUBTASK_SIGNATURE SIGNATURE_32 ('d', 'i', 's', 't')\r
493d8e3a
RN
62typedef struct {\r
63 //\r
64 // UnderRun: Offset != 0, Length < BlockSize\r
65 // OverRun: Offset == 0, Length < BlockSize\r
66 // Middle: Offset is block aligned, Length is multiple of block size\r
67 //\r
1436aea4
MK
68 UINT32 Signature;\r
69 LIST_ENTRY Link;\r
70 BOOLEAN Write;\r
71 UINT64 Lba;\r
72 UINT32 Offset;\r
73 UINTN Length;\r
74 UINT8 *WorkingBuffer; /// < NULL indicates using "Buffer" directly\r
75 UINT8 *Buffer;\r
76 BOOLEAN Blocking;\r
493d8e3a
RN
77\r
78 //\r
79 // Following fields are for DiskIo2\r
80 //\r
1436aea4
MK
81 DISK_IO2_TASK *Task;\r
82 EFI_BLOCK_IO2_TOKEN BlockIo2Token;\r
493d8e3a 83} DISK_IO_SUBTASK;\r
adbcbf8f 84\r
85//\r
86// Global Variables\r
87//\r
d38a0f44 88extern EFI_DRIVER_BINDING_PROTOCOL gDiskIoDriverBinding;\r
89extern EFI_COMPONENT_NAME_PROTOCOL gDiskIoComponentName;\r
90extern EFI_COMPONENT_NAME2_PROTOCOL gDiskIoComponentName2;\r
adbcbf8f 91\r
92//\r
93// Prototypes\r
94// Driver model protocol interface\r
95//\r
1436aea4 96\r
a8d0c20e 97/**\r
d1102dba 98 Test to see if this driver supports ControllerHandle.\r
a8d0c20e 99\r
100 @param This Protocol instance pointer.\r
101 @param ControllerHandle Handle of device to test\r
102 @param RemainingDevicePath Optional parameter use to pick a specific child\r
103 device to start.\r
104\r
105 @retval EFI_SUCCESS This driver supports this device\r
106 @retval EFI_ALREADY_STARTED This driver is already running on this device\r
107 @retval other This driver does not support this device\r
108\r
109**/\r
adbcbf8f 110EFI_STATUS\r
111EFIAPI\r
112DiskIoDriverBindingSupported (\r
ea7cb08c 113 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
114 IN EFI_HANDLE ControllerHandle,\r
115 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
adbcbf8f 116 );\r
117\r
a8d0c20e 118/**\r
119 Start this driver on ControllerHandle by opening a Block IO protocol and\r
120 installing a Disk IO protocol on ControllerHandle.\r
121\r
122 @param This Protocol instance pointer.\r
123 @param ControllerHandle Handle of device to bind driver to\r
124 @param RemainingDevicePath Optional parameter use to pick a specific child\r
125 device to start.\r
126\r
127 @retval EFI_SUCCESS This driver is added to ControllerHandle\r
128 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r
129 @retval other This driver does not support this device\r
130\r
131**/\r
adbcbf8f 132EFI_STATUS\r
133EFIAPI\r
134DiskIoDriverBindingStart (\r
ea7cb08c 135 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
136 IN EFI_HANDLE ControllerHandle,\r
137 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
adbcbf8f 138 );\r
139\r
a8d0c20e 140/**\r
141 Stop this driver on ControllerHandle by removing Disk IO protocol and closing\r
142 the Block IO protocol on ControllerHandle.\r
143\r
144 @param This Protocol instance pointer.\r
145 @param ControllerHandle Handle of device to stop driver on\r
146 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
147 children is zero stop the entire bus driver.\r
148 @param ChildHandleBuffer List of Child Handles to Stop.\r
149\r
150 @retval EFI_SUCCESS This driver is removed ControllerHandle\r
151 @retval other This driver was not removed from this device\r
152\r
153**/\r
adbcbf8f 154EFI_STATUS\r
155EFIAPI\r
156DiskIoDriverBindingStop (\r
1436aea4
MK
157 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
158 IN EFI_HANDLE ControllerHandle,\r
159 IN UINTN NumberOfChildren,\r
160 IN EFI_HANDLE *ChildHandleBuffer\r
adbcbf8f 161 );\r
162\r
163//\r
164// Disk I/O Protocol Interface\r
165//\r
1436aea4 166\r
a8d0c20e 167/**\r
168 Read BufferSize bytes from Offset into Buffer.\r
169 Reads may support reads that are not aligned on\r
170 sector boundaries. There are three cases:\r
171 UnderRun - The first byte is not on a sector boundary or the read request is\r
172 less than a sector in length.\r
173 Aligned - A read of N contiguous sectors.\r
174 OverRun - The last byte is not on a sector boundary.\r
175\r
176 @param This Protocol instance pointer.\r
177 @param MediaId Id of the media, changes every time the media is replaced.\r
178 @param Offset The starting byte offset to read from\r
179 @param BufferSize Size of Buffer\r
180 @param Buffer Buffer containing read data\r
181\r
182 @retval EFI_SUCCESS The data was read correctly from the device.\r
183 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.\r
184 @retval EFI_NO_MEDIA There is no media in the device.\r
185 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r
186 @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not\r
187 valid for the device.\r
188\r
189**/\r
adbcbf8f 190EFI_STATUS\r
191EFIAPI\r
192DiskIoReadDisk (\r
193 IN EFI_DISK_IO_PROTOCOL *This,\r
194 IN UINT32 MediaId,\r
195 IN UINT64 Offset,\r
196 IN UINTN BufferSize,\r
197 OUT VOID *Buffer\r
198 );\r
199\r
a8d0c20e 200/**\r
ff61847d 201 Writes BufferSize bytes from Buffer into Offset.\r
a8d0c20e 202 Writes may require a read modify write to support writes that are not\r
203 aligned on sector boundaries. There are three cases:\r
204 UnderRun - The first byte is not on a sector boundary or the write request\r
205 is less than a sector in length. Read modify write is required.\r
206 Aligned - A write of N contiguous sectors.\r
207 OverRun - The last byte is not on a sector boundary. Read modified write\r
208 required.\r
209\r
210 @param This Protocol instance pointer.\r
211 @param MediaId Id of the media, changes every time the media is replaced.\r
212 @param Offset The starting byte offset to read from\r
213 @param BufferSize Size of Buffer\r
214 @param Buffer Buffer containing read data\r
215\r
216 @retval EFI_SUCCESS The data was written correctly to the device.\r
217 @retval EFI_WRITE_PROTECTED The device can not be written to.\r
218 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r
219 @retval EFI_NO_MEDIA There is no media in the device.\r
220 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r
221 @retval EFI_INVALID_PARAMETER The write request contains device addresses that are not\r
222 valid for the device.\r
223\r
224**/\r
adbcbf8f 225EFI_STATUS\r
226EFIAPI\r
227DiskIoWriteDisk (\r
228 IN EFI_DISK_IO_PROTOCOL *This,\r
229 IN UINT32 MediaId,\r
230 IN UINT64 Offset,\r
231 IN UINTN BufferSize,\r
232 IN VOID *Buffer\r
233 );\r
234\r
493d8e3a
RN
235/**\r
236 Terminate outstanding asynchronous requests to a device.\r
237\r
238 @param This Indicates a pointer to the calling context.\r
239\r
240 @retval EFI_SUCCESS All outstanding requests were successfully terminated.\r
241 @retval EFI_DEVICE_ERROR The device reported an error while performing the cancel\r
242 operation.\r
243**/\r
244EFI_STATUS\r
245EFIAPI\r
246DiskIo2Cancel (\r
1436aea4 247 IN EFI_DISK_IO2_PROTOCOL *This\r
493d8e3a
RN
248 );\r
249\r
250/**\r
251 Reads a specified number of bytes from a device.\r
252\r
253 @param This Indicates a pointer to the calling context.\r
254 @param MediaId ID of the medium to be read.\r
255 @param Offset The starting byte offset on the logical block I/O device to read from.\r
256 @param Token A pointer to the token associated with the transaction.\r
257 If this field is NULL, synchronous/blocking IO is performed.\r
258 @param BufferSize The size in bytes of Buffer. The number of bytes to read from the device.\r
259 @param Buffer A pointer to the destination buffer for the data.\r
260 The caller is responsible either having implicit or explicit ownership of the buffer.\r
261\r
262 @retval EFI_SUCCESS If Event is NULL (blocking I/O): The data was read correctly from the device.\r
263 If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.\r
264 Event will be signaled upon completion.\r
265 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r
266 @retval EFI_NO_MEDIA There is no medium in the device.\r
267 @retval EFI_MEDIA_CHNAGED The MediaId is not for the current medium.\r
268 @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not valid for the device.\r
269 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
270\r
271**/\r
272EFI_STATUS\r
273EFIAPI\r
274DiskIo2ReadDiskEx (\r
1436aea4
MK
275 IN EFI_DISK_IO2_PROTOCOL *This,\r
276 IN UINT32 MediaId,\r
277 IN UINT64 Offset,\r
278 IN OUT EFI_DISK_IO2_TOKEN *Token,\r
279 IN UINTN BufferSize,\r
280 OUT VOID *Buffer\r
493d8e3a
RN
281 );\r
282\r
283/**\r
284 Writes a specified number of bytes to a device.\r
285\r
286 @param This Indicates a pointer to the calling context.\r
287 @param MediaId ID of the medium to be written.\r
288 @param Offset The starting byte offset on the logical block I/O device to write to.\r
289 @param Token A pointer to the token associated with the transaction.\r
290 If this field is NULL, synchronous/blocking IO is performed.\r
291 @param BufferSize The size in bytes of Buffer. The number of bytes to write to the device.\r
292 @param Buffer A pointer to the buffer containing the data to be written.\r
293\r
294 @retval EFI_SUCCESS If Event is NULL (blocking I/O): The data was written correctly to the device.\r
295 If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.\r
296 Event will be signaled upon completion.\r
297 @retval EFI_WRITE_PROTECTED The device cannot be written to.\r
298 @retval EFI_DEVICE_ERROR The device reported an error while performing the write operation.\r
299 @retval EFI_NO_MEDIA There is no medium in the device.\r
300 @retval EFI_MEDIA_CHNAGED The MediaId is not for the current medium.\r
301 @retval EFI_INVALID_PARAMETER The write request contains device addresses that are not valid for the device.\r
302 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
303\r
304**/\r
305EFI_STATUS\r
306EFIAPI\r
307DiskIo2WriteDiskEx (\r
1436aea4
MK
308 IN EFI_DISK_IO2_PROTOCOL *This,\r
309 IN UINT32 MediaId,\r
310 IN UINT64 Offset,\r
311 IN EFI_DISK_IO2_TOKEN *Token,\r
312 IN UINTN BufferSize,\r
313 IN VOID *Buffer\r
493d8e3a
RN
314 );\r
315\r
316/**\r
317 Flushes all modified data to the physical device.\r
318\r
319 @param This Indicates a pointer to the calling context.\r
320 @param Token A pointer to the token associated with the transaction.\r
321 If this field is NULL, synchronous/blocking IO is performed.\r
322\r
323 @retval EFI_SUCCESS If Event is NULL (blocking I/O): The data was flushed successfully to the device.\r
324 If Event is not NULL (asynchronous I/O): The request was successfully queued for processing.\r
325 Event will be signaled upon completion.\r
326 @retval EFI_WRITE_PROTECTED The device cannot be written to.\r
327 @retval EFI_DEVICE_ERROR The device reported an error while performing the write operation.\r
328 @retval EFI_NO_MEDIA There is no medium in the device.\r
329 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
330**/\r
331EFI_STATUS\r
332EFIAPI\r
333DiskIo2FlushDiskEx (\r
1436aea4
MK
334 IN EFI_DISK_IO2_PROTOCOL *This,\r
335 IN OUT EFI_DISK_IO2_TOKEN *Token\r
493d8e3a
RN
336 );\r
337\r
adbcbf8f 338//\r
339// EFI Component Name Functions\r
340//\r
1436aea4 341\r
d38a0f44 342/**\r
343 Retrieves a Unicode string that is the user readable name of the driver.\r
344\r
345 This function retrieves the user readable name of a driver in the form of a\r
346 Unicode string. If the driver specified by This has a user readable name in\r
347 the language specified by Language, then a pointer to the driver name is\r
348 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
349 by This does not support the language specified by Language,\r
350 then EFI_UNSUPPORTED is returned.\r
351\r
352 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
353 EFI_COMPONENT_NAME_PROTOCOL instance.\r
354\r
355 @param Language[in] A pointer to a Null-terminated ASCII string\r
356 array indicating the language. This is the\r
357 language of the driver name that the caller is\r
358 requesting, and it must match one of the\r
359 languages specified in SupportedLanguages. The\r
360 number of languages supported by a driver is up\r
361 to the driver writer. Language is specified\r
0254efc0 362 in RFC 4646 or ISO 639-2 language code format.\r
d38a0f44 363\r
364 @param DriverName[out] A pointer to the Unicode string to return.\r
365 This Unicode string is the name of the\r
366 driver specified by This in the language\r
367 specified by Language.\r
368\r
369 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
370 This and the language specified by Language was\r
371 returned in DriverName.\r
372\r
373 @retval EFI_INVALID_PARAMETER Language is NULL.\r
374\r
375 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
376\r
377 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
378 the language specified by Language.\r
379\r
380**/\r
adbcbf8f 381EFI_STATUS\r
382EFIAPI\r
383DiskIoComponentNameGetDriverName (\r
384 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
385 IN CHAR8 *Language,\r
386 OUT CHAR16 **DriverName\r
387 );\r
388\r
d38a0f44 389/**\r
390 Retrieves a Unicode string that is the user readable name of the controller\r
391 that is being managed by a driver.\r
392\r
393 This function retrieves the user readable name of the controller specified by\r
394 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
395 driver specified by This has a user readable name in the language specified by\r
396 Language, then a pointer to the controller name is returned in ControllerName,\r
397 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
398 managing the controller specified by ControllerHandle and ChildHandle,\r
399 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
400 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
401\r
402 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
403 EFI_COMPONENT_NAME_PROTOCOL instance.\r
404\r
405 @param ControllerHandle[in] The handle of a controller that the driver\r
406 specified by This is managing. This handle\r
407 specifies the controller whose name is to be\r
408 returned.\r
409\r
410 @param ChildHandle[in] The handle of the child controller to retrieve\r
411 the name of. This is an optional parameter that\r
412 may be NULL. It will be NULL for device\r
413 drivers. It will also be NULL for a bus drivers\r
414 that wish to retrieve the name of the bus\r
415 controller. It will not be NULL for a bus\r
416 driver that wishes to retrieve the name of a\r
417 child controller.\r
418\r
419 @param Language[in] A pointer to a Null-terminated ASCII string\r
420 array indicating the language. This is the\r
421 language of the driver name that the caller is\r
422 requesting, and it must match one of the\r
423 languages specified in SupportedLanguages. The\r
424 number of languages supported by a driver is up\r
425 to the driver writer. Language is specified in\r
0254efc0 426 RFC 4646 or ISO 639-2 language code format.\r
d38a0f44 427\r
428 @param ControllerName[out] A pointer to the Unicode string to return.\r
429 This Unicode string is the name of the\r
430 controller specified by ControllerHandle and\r
431 ChildHandle in the language specified by\r
432 Language from the point of view of the driver\r
433 specified by This.\r
434\r
435 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
436 the language specified by Language for the\r
437 driver specified by This was returned in\r
438 DriverName.\r
439\r
284ee2e8 440 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
d38a0f44 441\r
442 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
443 EFI_HANDLE.\r
444\r
445 @retval EFI_INVALID_PARAMETER Language is NULL.\r
446\r
447 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
448\r
449 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
450 managing the controller specified by\r
451 ControllerHandle and ChildHandle.\r
452\r
453 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
454 the language specified by Language.\r
455\r
456**/\r
adbcbf8f 457EFI_STATUS\r
458EFIAPI\r
459DiskIoComponentNameGetControllerName (\r
1436aea4
MK
460 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
461 IN EFI_HANDLE ControllerHandle,\r
462 IN EFI_HANDLE ChildHandle OPTIONAL,\r
463 IN CHAR8 *Language,\r
464 OUT CHAR16 **ControllerName\r
adbcbf8f 465 );\r
466\r
467#endif\r