2 DiskIo driver that layers it's self on every Block IO protocol in the system.
3 DiskIo converts a block oriented device to a byte oriented device.
5 Copyright (c) 2006 - 2009, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include <Protocol/BlockIo.h>
21 #include <Protocol/ComponentName.h>
22 #include <Protocol/DriverBinding.h>
23 #include <Protocol/DriverConfiguration.h>
24 #include <Protocol/DriverConfiguration2.h>
25 #include <Protocol/DriverHealth.h>
26 #include <Protocol/DiskIo.h>
27 #include <Protocol/HiiDatabase.h>
28 #include <Protocol/HiiConfigAccess.h>
29 #include <Protocol/HiiConfigRouting.h>
30 #include <Protocol/DevicePath.h>
31 #include <Protocol/HiiString.h>
33 #include <Library/DebugLib.h>
34 #include <Library/UefiDriverEntryPoint.h>
35 #include <Library/UefiLib.h>
36 #include <Library/BaseLib.h>
37 #include <Library/BaseMemoryLib.h>
38 #include <Library/MemoryAllocationLib.h>
39 #include <Library/UefiBootServicesTableLib.h>
40 #include <Library/UefiRuntimeServicesTableLib.h>
41 #include <Library/DevicePathLib.h>
42 #include <Library/HiiLib.h>
43 #include <Library/PrintLib.h>
44 #include "NVDataStruc.h"
46 #define DISK_IO_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('d', 's', 'k', 'I')
48 #define DISK_IO_CONTROLLER_STATE_SIGNATURE SIGNATURE_32 ('c', 't', 's', 'S')
50 #define DATA_BUFFER_BLOCK_NUM (64)
53 VENDOR_DEVICE_PATH VendorDevicePath
;
54 EFI_DEVICE_PATH_PROTOCOL End
;
55 } HII_VENDOR_DEVICE_PATH
;
59 EFI_DISK_IO_PROTOCOL DiskIo
;
60 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
65 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
66 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
71 EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess
;
73 DISK_IO_NV_DATA NVdata
;
74 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
75 UINT8 ControllerIndex
;
76 } DISK_IO_PRIVATE_DATA
;
82 EFI_STRING_ID StringId
;
84 EFI_DRIVER_HEALTH_STATUS HealthStatus
;
91 EFI_HANDLE ControllerHandle
;
92 UINTN ControllerIndex
;
93 EFI_HANDLE ChildHandle
;
97 #define DISK_IO_PRIVATE_DATA_FROM_THIS(a) CR (a, DISK_IO_PRIVATE_DATA, DiskIo, DISK_IO_PRIVATE_DATA_SIGNATURE)
98 #define DISK_IO_PRIVATE_DATA_FROM_CONFIG_ACCESS(a) CR (a, DISK_IO_PRIVATE_DATA, ConfigAccess, DISK_IO_PRIVATE_DATA_SIGNATURE)
100 #define DISK_IO_CONTROLLER_STATE_FROM_HANDLE(a) CR (a, CONTROLLER_STATE, ControllerHandle, DISK_IO_CONTROLLER_STATE_SIGNATURE)
101 #define DISK_IO_CONTROLLER_STATE_FROM_LINK(a) CR (a, CONTROLLER_STATE, Link, DISK_IO_CONTROLLER_STATE_SIGNATURE)
105 extern EFI_DRIVER_BINDING_PROTOCOL gDiskIoDriverBinding
;
106 extern EFI_COMPONENT_NAME_PROTOCOL gDiskIoComponentName
;
107 extern EFI_COMPONENT_NAME2_PROTOCOL gDiskIoComponentName2
;
108 extern EFI_DRIVER_HEALTH_PROTOCOL gDiskIoDriverHealth
;
111 // This is the generated String package data for all .UNI files.
112 // This data array is ready to be used as input of HiiAddPackages() to
113 // create a packagelist (which contains Form packages, String packages, etc).
115 extern UINT8 DriverHealthDxeStrings
[];
116 extern UINT8 DriverHealthVfrBin
[];
121 // Driver model protocol interface
124 Test to see if this driver supports ControllerHandle.
126 @param This Protocol instance pointer.
127 @param ControllerHandle Handle of device to test
128 @param RemainingDevicePath Optional parameter use to pick a specific child
131 @retval EFI_SUCCESS This driver supports this device
132 @retval EFI_ALREADY_STARTED This driver is already running on this device
133 @retval other This driver does not support this device
138 DiskIoDriverBindingSupported (
139 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
140 IN EFI_HANDLE ControllerHandle
,
141 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
145 Start this driver on ControllerHandle by opening a Block IO protocol and
146 installing a Disk IO protocol on ControllerHandle.
148 @param This Protocol instance pointer.
149 @param ControllerHandle Handle of device to bind driver to
150 @param RemainingDevicePath Optional parameter use to pick a specific child
153 @retval EFI_SUCCESS This driver is added to ControllerHandle
154 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
155 @retval other This driver does not support this device
160 DiskIoDriverBindingStart (
161 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
162 IN EFI_HANDLE ControllerHandle
,
163 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
167 Stop this driver on ControllerHandle by removing Disk IO protocol and closing
168 the Block IO protocol on ControllerHandle.
170 @param This Protocol instance pointer.
171 @param ControllerHandle Handle of device to stop driver on
172 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
173 children is zero stop the entire bus driver.
174 @param ChildHandleBuffer List of Child Handles to Stop.
176 @retval EFI_SUCCESS This driver is removed ControllerHandle
177 @retval other This driver was not removed from this device
182 DiskIoDriverBindingStop (
183 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
184 IN EFI_HANDLE ControllerHandle
,
185 IN UINTN NumberOfChildren
,
186 IN EFI_HANDLE
*ChildHandleBuffer
190 // Disk I/O Protocol Interface
193 Read BufferSize bytes from Offset into Buffer.
194 Reads may support reads that are not aligned on
195 sector boundaries. There are three cases:
196 UnderRun - The first byte is not on a sector boundary or the read request is
197 less than a sector in length.
198 Aligned - A read of N contiguous sectors.
199 OverRun - The last byte is not on a sector boundary.
201 @param This Protocol instance pointer.
202 @param MediaId Id of the media, changes every time the media is replaced.
203 @param Offset The starting byte offset to read from
204 @param BufferSize Size of Buffer
205 @param Buffer Buffer containing read data
207 @retval EFI_SUCCESS The data was read correctly from the device.
208 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
209 @retval EFI_NO_MEDIA There is no media in the device.
210 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
211 @retval EFI_INVALID_PARAMETER The read request contains device addresses that are not
212 valid for the device.
218 IN EFI_DISK_IO_PROTOCOL
*This
,
226 Writes BufferSize bytes from Buffer into Offset.
227 Writes may require a read modify write to support writes that are not
228 aligned on sector boundaries. There are three cases:
229 UnderRun - The first byte is not on a sector boundary or the write request
230 is less than a sector in length. Read modify write is required.
231 Aligned - A write of N contiguous sectors.
232 OverRun - The last byte is not on a sector boundary. Read modified write
235 @param This Protocol instance pointer.
236 @param MediaId Id of the media, changes every time the media is replaced.
237 @param Offset The starting byte offset to read from
238 @param BufferSize Size of Buffer
239 @param Buffer Buffer containing read data
241 @retval EFI_SUCCESS The data was written correctly to the device.
242 @retval EFI_WRITE_PROTECTED The device can not be written to.
243 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
244 @retval EFI_NO_MEDIA There is no media in the device.
245 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
246 @retval EFI_INVALID_PARAMETER The write request contains device addresses that are not
247 valid for the device.
253 IN EFI_DISK_IO_PROTOCOL
*This
,
261 // EFI Component Name Functions
264 Retrieves a Unicode string that is the user readable name of the driver.
266 This function retrieves the user readable name of a driver in the form of a
267 Unicode string. If the driver specified by This has a user readable name in
268 the language specified by Language, then a pointer to the driver name is
269 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
270 by This does not support the language specified by Language,
271 then EFI_UNSUPPORTED is returned.
273 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
274 EFI_COMPONENT_NAME_PROTOCOL instance.
276 @param Language[in] A pointer to a Null-terminated ASCII string
277 array indicating the language. This is the
278 language of the driver name that the caller is
279 requesting, and it must match one of the
280 languages specified in SupportedLanguages. The
281 number of languages supported by a driver is up
282 to the driver writer. Language is specified
283 in RFC 4646 or ISO 639-2 language code format.
285 @param DriverName[out] A pointer to the Unicode string to return.
286 This Unicode string is the name of the
287 driver specified by This in the language
288 specified by Language.
290 @retval EFI_SUCCESS The Unicode string for the Driver specified by
291 This and the language specified by Language was
292 returned in DriverName.
294 @retval EFI_INVALID_PARAMETER Language is NULL.
296 @retval EFI_INVALID_PARAMETER DriverName is NULL.
298 @retval EFI_UNSUPPORTED The driver specified by This does not support
299 the language specified by Language.
304 DiskIoComponentNameGetDriverName (
305 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
307 OUT CHAR16
**DriverName
311 Retrieves a Unicode string that is the user readable name of the controller
312 that is being managed by a driver.
314 This function retrieves the user readable name of the controller specified by
315 ControllerHandle and ChildHandle in the form of a Unicode string. If the
316 driver specified by This has a user readable name in the language specified by
317 Language, then a pointer to the controller name is returned in ControllerName,
318 and EFI_SUCCESS is returned. If the driver specified by This is not currently
319 managing the controller specified by ControllerHandle and ChildHandle,
320 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
321 support the language specified by Language, then EFI_UNSUPPORTED is returned.
323 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
324 EFI_COMPONENT_NAME_PROTOCOL instance.
326 @param ControllerHandle[in] The handle of a controller that the driver
327 specified by This is managing. This handle
328 specifies the controller whose name is to be
331 @param ChildHandle[in] The handle of the child controller to retrieve
332 the name of. This is an optional parameter that
333 may be NULL. It will be NULL for device
334 drivers. It will also be NULL for a bus drivers
335 that wish to retrieve the name of the bus
336 controller. It will not be NULL for a bus
337 driver that wishes to retrieve the name of a
340 @param Language[in] A pointer to a Null-terminated ASCII string
341 array indicating the language. This is the
342 language of the driver name that the caller is
343 requesting, and it must match one of the
344 languages specified in SupportedLanguages. The
345 number of languages supported by a driver is up
346 to the driver writer. Language is specified in
347 RFC 4646 or ISO 639-2 language code format.
349 @param ControllerName[out] A pointer to the Unicode string to return.
350 This Unicode string is the name of the
351 controller specified by ControllerHandle and
352 ChildHandle in the language specified by
353 Language from the point of view of the driver
356 @retval EFI_SUCCESS The Unicode string for the user readable name in
357 the language specified by Language for the
358 driver specified by This was returned in
361 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
363 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
366 @retval EFI_INVALID_PARAMETER Language is NULL.
368 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
370 @retval EFI_UNSUPPORTED The driver specified by This is not currently
371 managing the controller specified by
372 ControllerHandle and ChildHandle.
374 @retval EFI_UNSUPPORTED The driver specified by This does not support
375 the language specified by Language.
380 DiskIoComponentNameGetControllerName (
381 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
382 IN EFI_HANDLE ControllerHandle
,
383 IN EFI_HANDLE ChildHandle OPTIONAL
,
385 OUT CHAR16
**ControllerName
389 // EFI Driver Health Functions
392 Retrieves the health status of a controller in the platform. This function can also
393 optionally return warning messages, error messages, and a set of HII Forms that may
394 be repair a controller that is not proper configured.
396 @param This A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.
398 @param ControllerHandle The handle of the controller to retrieve the health status
399 on. This is an optional parameter that may be NULL. If
400 this parameter is NULL, then the value of ChildHandle is
401 ignored, and the combined health status of all the devices
402 that the driver is managing is returned.
404 @param ChildHandle The handle of the child controller to retrieve the health
405 status on. This is an optional parameter that may be NULL.
406 This parameter is ignored of ControllerHandle is NULL. It
407 will be NULL for device drivers. It will also be NULL for
408 bus drivers when an attempt is made to collect the health
409 status of the bus controller. If will not be NULL when an
410 attempt is made to collect the health status for a child
411 controller produced by the driver.
413 @param HealthStatus A pointer to the health status that is returned by this
414 function. This is an optional parameter that may be NULL.
415 This parameter is ignored of ControllerHandle is NULL.
416 The health status for the controller specified by
417 ControllerHandle and ChildHandle is returned.
419 @param MessageList A pointer to an array of warning or error messages associated
420 with the controller specified by ControllerHandle and
421 ChildHandle. This is an optional parameter that may be NULL.
422 MessageList is allocated by this function with the EFI Boot
423 Service AllocatePool(), and it is the caller's responsibility
424 to free MessageList with the EFI Boot Service FreePool().
425 Each message is specified by tuple of an EFI_HII_HANDLE and
426 an EFI_STRING_ID. The array of messages is terminated by tuple
427 containing a EFI_HII_HANDLE with a value of NULL. The
428 EFI_HII_STRING_PROTOCOL.GetString() function can be used to
429 retrieve the warning or error message as a Null-terminated
430 Unicode string in a specific language. Messages may be
431 returned for any of the HealthStatus values except
432 EfiDriverHealthStatusReconnectRequired and
433 EfiDriverHealthStatusRebootRequired.
435 @param FormHiiHandle A pointer to the HII handle for an HII form associated with the
436 controller specified by ControllerHandle and ChildHandle.
437 This is an optional parameter that may be NULL. An HII form
438 is specified by a combination of an EFI_HII_HANDLE and an
439 EFI_GUID that identifies the Form Set GUID. The
440 EFI_FORM_BROWSER2_PROTOCOL.SendForm() function can be used
441 to display and allow the user to make configuration changes
442 to the HII Form. An HII form may only be returned with a
443 HealthStatus value of EfiDriverHealthStatusConfigurationRequired.
445 @retval EFI_SUCCESS ControllerHandle is NULL, and all the controllers
446 managed by this driver specified by This have a health
447 status of EfiDriverHealthStatusHealthy with no warning
448 messages to be returned. The ChildHandle, HealthStatus,
449 MessageList, and FormList parameters are ignored.
451 @retval EFI_DEVICE_ERROR ControllerHandle is NULL, and one or more of the
452 controllers managed by this driver specified by This
453 do not have a health status of EfiDriverHealthStatusHealthy.
454 The ChildHandle, HealthStatus, MessageList, and
455 FormList parameters are ignored.
457 @retval EFI_DEVICE_ERROR ControllerHandle is NULL, and one or more of the
458 controllers managed by this driver specified by This
459 have one or more warning and/or error messages.
460 The ChildHandle, HealthStatus, MessageList, and
461 FormList parameters are ignored.
463 @retval EFI_SUCCESS ControllerHandle is not NULL and the health status
464 of the controller specified by ControllerHandle and
465 ChildHandle was returned in HealthStatus. A list
466 of warning and error messages may be optionally
467 returned in MessageList, and a list of HII Forms
468 may be optionally returned in FormList.
470 @retval EFI_UNSUPPORTED ControllerHandle is not NULL, and the controller
471 specified by ControllerHandle and ChildHandle is not
472 currently being managed by the driver specified by This.
474 @retval EFI_INVALID_PARAMETER HealthStatus is NULL.
476 @retval EFI_OUT_OF_RESOURCES MessageList is not NULL, and there are not enough
477 resource available to allocate memory for MessageList.
481 DiskIoDriverHealthGetHealthStatus (
482 IN EFI_DRIVER_HEALTH_PROTOCOL
*This
,
483 IN EFI_HANDLE ControllerHandle OPTIONAL
,
484 IN EFI_HANDLE ChildHandle OPTIONAL
,
485 OUT EFI_DRIVER_HEALTH_STATUS
*HealthStatus
,
486 OUT EFI_DRIVER_HEALTH_HII_MESSAGE
**MessageList OPTIONAL
,
487 OUT EFI_HII_HANDLE
*FormHiiHandle OPTIONAL
491 Performs a repair operation on a controller in the platform. This function can
492 optionally report repair progress information back to the platform.
494 @param This A pointer to the EFI_DRIVER_HEALTH_PROTOCOL instance.
495 @param ControllerHandle The handle of the controller to repair.
496 @param ChildHandle The handle of the child controller to repair. This is
497 an optional parameter that may be NULL. It will be NULL
498 for device drivers. It will also be NULL for bus
499 drivers when an attempt is made to repair a bus controller.
500 If will not be NULL when an attempt is made to repair a
501 child controller produced by the driver.
502 @param RepairNotify A notification function that may be used by a driver to
503 report the progress of the repair operation. This is
504 an optional parameter that may be NULL.
507 @retval EFI_SUCCESS An attempt to repair the controller specified by
508 ControllerHandle and ChildHandle was performed.
509 The result of the repair operation can be
510 determined by calling GetHealthStatus().
511 @retval EFI_UNSUPPORTED The driver specified by This is not currently
512 managing the controller specified by ControllerHandle
514 @retval EFI_OUT_OF_RESOURCES There are not enough resources to perform the
519 DiskIoDriverHealthRepair (
520 IN EFI_DRIVER_HEALTH_PROTOCOL
*This
,
521 IN EFI_HANDLE ControllerHandle
,
522 IN EFI_HANDLE ChildHandle OPTIONAL
,
523 IN EFI_DRIVER_HEALTH_REPAIR_PROGRESS_NOTIFY RepairNotify OPTIONAL
527 Initialize the serial configuration form.
529 @retval EFI_SUCCESS The serial configuration form is initialized.
530 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.
531 @retval Others Other errors as indicated.
534 DiskIoConfigFormInit (
539 This function allows a caller to extract the current configuration for one
540 or more named elements from the target driver.
542 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
543 @param Request A null-terminated Unicode string in
544 <ConfigRequest> format.
545 @param Progress On return, points to a character in the Request
546 string. Points to the string's null terminator if
547 request was successful. Points to the most recent
548 '&' before the first failing name/value pair (or
549 the beginning of the string if the failure is in
550 the first name/value pair) if the request was not
552 @param Results A null-terminated Unicode string in
553 <ConfigAltResp> format which has all values filled
554 in for the names in the Request string. String to
555 be allocated by the called function.
557 @retval EFI_SUCCESS The Results is filled with the requested values.
558 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
559 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
560 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
567 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
568 IN CONST EFI_STRING Request
,
569 OUT EFI_STRING
*Progress
,
570 OUT EFI_STRING
*Results
574 This function processes the results of changes in configuration.
576 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
577 @param Configuration A null-terminated Unicode string in <ConfigResp>
579 @param Progress A pointer to a string filled in with the offset of
580 the most recent '&' before the first failing
581 name/value pair (or the beginning of the string if
582 the failure is in the first name/value pair) or
583 the terminating NULL if all was successful.
585 @retval EFI_SUCCESS The Results is processed successfully.
586 @retval EFI_INVALID_PARAMETER Configuration is NULL.
587 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
594 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
595 IN CONST EFI_STRING Configuration
,
596 OUT EFI_STRING
*Progress
600 This function processes the results of changes in configuration.
602 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
603 @param Action Specifies the type of action taken by the browser.
604 @param QuestionId A unique value which is sent to the original
605 exporting driver so that it can identify the type
607 @param Type The type of value for the question.
608 @param Value A pointer to the data being sent to the original
610 @param ActionRequest On return, points to the action requested by the
613 @retval EFI_SUCCESS The callback successfully handled the action.
614 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
615 variable and its data.
616 @retval EFI_DEVICE_ERROR The variable could not be saved.
617 @retval EFI_UNSUPPORTED The specified Action is not supported by the
623 DummyDriverCallback (
624 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
625 IN EFI_BROWSER_ACTION Action
,
626 IN EFI_QUESTION_ID QuestionId
,
628 IN EFI_IFR_TYPE_VALUE
*Value
,
629 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
633 Add the ISO639-2 and RFC4646 component name both for the Disk IO device
635 @param DiskIoDevice A pointer to the DISK_IO_PRIVATE_DATA instance.
640 IN DISK_IO_PRIVATE_DATA
*DiskIoDevice