2 Header file for IDE Bus Driver.
4 Copyright (c) 2006 - 2007 Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include <FrameworkDxe.h>
22 #include <Protocol/IdeControllerInit.h>
23 #include <Protocol/BlockIo.h>
24 #include <Protocol/PciIo.h>
25 #include <Protocol/DiskInfo.h>
26 #include <Protocol/DevicePath.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/ReportStatusCodeLib.h>
34 #include <Library/MemoryAllocationLib.h>
35 #include <Library/PerformanceLib.h>
36 #include <Library/UefiBootServicesTableLib.h>
37 #include <Library/UefiRuntimeServicesTableLib.h>
38 #include <Library/DevicePathLib.h>
40 #include <Guid/EventGroup.h>
42 #include <IndustryStandard/Pci22.h>
48 extern EFI_DRIVER_BINDING_PROTOCOL gIDEBusDriverBinding
;
49 extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL gIDEBusDriverDiagnostics
;
50 extern EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gIDEBusDriverDiagnostics2
;
53 // Extra Definition to porting
55 #define MAX_IDE_DEVICE 4
56 #define MAX_IDE_CHANNELS 2
57 #define MAX_IDE_DRIVES 2
59 #define INVALID_DEVICE_TYPE 0xff
60 #define ATA_DEVICE_TYPE 0x00
61 #define ATAPI_DEVICE_TYPE 0x01
63 #define EFI_IOB_ATA_BUS_SMART_ENABLE (EFI_SUBCLASS_SPECIFIC | 0x00000000)
64 #define EFI_IOB_ATA_BUS_SMART_DISABLE (EFI_SUBCLASS_SPECIFIC | 0x00000001)
65 #define EFI_IOB_ATA_BUS_SMART_OVERTHRESHOLD (EFI_SUBCLASS_SPECIFIC | 0x00000002)
66 #define EFI_IOB_ATA_BUS_SMART_UNDERTHRESHOLD (EFI_SUBCLASS_SPECIFIC | 0x00000003)
69 BOOLEAN HaveScannedDevice
[MAX_IDE_DEVICE
];
70 BOOLEAN DeviceFound
[MAX_IDE_DEVICE
];
71 BOOLEAN DeviceProcessed
[MAX_IDE_DEVICE
];
72 } IDE_BUS_DRIVER_PRIVATE_DATA
;
74 #define IDE_BLK_IO_DEV_SIGNATURE SIGNATURE_32 ('i', 'b', 'i', 'd')
80 EFI_BLOCK_IO_PROTOCOL BlkIo
;
81 EFI_BLOCK_IO_MEDIA BlkMedia
;
82 EFI_DISK_INFO_PROTOCOL DiskInfo
;
83 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
84 EFI_PCI_IO_PROTOCOL
*PciIo
;
85 IDE_BUS_DRIVER_PRIVATE_DATA
*IdeBusDriverPrivateData
;
88 // Local Data for IDE interface goes here
90 EFI_IDE_CHANNEL Channel
;
91 EFI_IDE_DEVICE Device
;
95 IDE_BASE_REGISTERS
*IoPort
;
98 ATAPI_INQUIRY_DATA
*InquiryData
;
99 EFI_IDENTIFY_DATA
*IdData
;
100 ATA_PIO_MODE PioMode
;
101 EFI_ATA_MODE UdmaMode
;
103 ATAPI_REQUEST_SENSE_DATA
*SenseData
;
104 UINT8 SenseDataNumber
;
108 // ExitBootService Event, it is used to clear pending IDE interrupt
110 EFI_EVENT ExitBootServiceEvent
;
112 EFI_UNICODE_STRING_TABLE
*ControllerNameTable
;
115 #include "ComponentName.h"
117 #define IDE_BLOCK_IO_DEV_FROM_THIS(a) CR (a, IDE_BLK_IO_DEV, BlkIo, IDE_BLK_IO_DEV_SIGNATURE)
118 #define IDE_BLOCK_IO_DEV_FROM_DISK_INFO_THIS(a) CR (a, IDE_BLK_IO_DEV, DiskInfo, IDE_BLK_IO_DEV_SIGNATURE)
124 Supported function of Driver Binding protocol for this driver.
126 @param This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
127 @param ControllerHandle The handle of the controller to test.
128 @param RemainingDevicePath A pointer to the remaining portion of a device path.
130 @retval EFI_SUCCESS Driver loaded.
131 @retval other Driver not loaded.
136 IDEBusDriverBindingSupported (
137 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
138 IN EFI_HANDLE Controller
,
139 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
143 Start function of Driver binding protocol which start this driver on Controller
144 by detecting all disks and installing BlockIo protocol on them.
146 @param This Protocol instance pointer.
147 @param Controller Handle of device to bind driver to.
148 @param RemainingDevicePath produce all possible children.
150 @retval EFI_SUCCESS This driver is added to ControllerHandle.
151 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.
152 @retval other This driver does not support this device.
157 IDEBusDriverBindingStart (
158 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
159 IN EFI_HANDLE Controller
,
160 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
164 Stop function of Driver Binding Protocol which is to stop the driver on Controller Handle and all
165 child handle attached to the controller handle if there are.
167 @param This Protocol instance pointer.
168 @param Controller Handle of device to stop driver on
169 @param NumberOfChildren Not used
170 @param ChildHandleBuffer Not used
172 @retval EFI_SUCCESS This driver is removed DeviceHandle
173 @retval other This driver was not removed from this device
178 IDEBusDriverBindingStop (
179 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
180 IN EFI_HANDLE Controller
,
181 IN UINTN NumberOfChildren
,
182 IN EFI_HANDLE
*ChildHandleBuffer
186 // EFI Driver Configuration Functions
189 Allows the user to set controller specific options for a controller that a
190 driver is currently managing.
192 @param This A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.
193 @param ControllerHandle The handle of the controller to set options on.
194 @param ChildHandle The handle of the child controller to set options on.
195 This is an optional parameter that may be NULL.
196 It will be NULL for device drivers, and for a bus drivers
197 that wish to set options for the bus controller.
198 It will not be NULL for a bus driver that wishes to set
199 options for one of its child controllers.
200 @param Language A pointer to a three character ISO 639-2 language identifier.
201 This is the language of the user interface that should be presented
202 to the user, and it must match one of the languages specified in
203 SupportedLanguages. The number of languages supported by a driver is up to
205 @param ActionRequired A pointer to the action that the calling agent is required
206 to perform when this function returns.
209 @retval EFI_SUCCESS The driver specified by This successfully set the configuration
210 options for the controller specified by ControllerHandle..
211 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
212 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
213 @retval EFI_INVALID_PARAMETER ActionRequired is NULL.
214 @retval EFI_UNSUPPORTED The driver specified by This does not support setting configuration options for
215 the controller specified by ControllerHandle and ChildHandle.
216 @retval EFI_UNSUPPORTED The driver specified by This does not support the language specified by Language.
217 @retval EFI_DEVICE_ERROR A device error occurred while attempt to set the configuration options for the
218 controller specified by ControllerHandle and ChildHandle.
219 @retval EFI_OUT_RESOURCES There are not enough resources available to set the configuration options for the
220 controller specified by ControllerHandle and ChildHandle
224 IDEBusDriverConfigurationSetOptions (
225 IN EFI_DRIVER_CONFIGURATION_PROTOCOL
*This
,
226 IN EFI_HANDLE ControllerHandle
,
227 IN EFI_HANDLE ChildHandle OPTIONAL
,
229 OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED
*ActionRequired
233 Tests to see if a controller's current configuration options are valid.
235 @param This A pointer to the EFI_DRIVER_CONFIGURATION_PROTOCOL instance.
236 @param ControllerHandle The handle of the controller to test if it's current configuration options
238 @param ChildHandle The handle of the child controller to test if it's current configuration
239 options are valid. This is an optional parameter that may be NULL. It will
240 be NULL for device drivers. It will also be NULL for a bus drivers that
241 wish to test the configuration options for the bus controller. It will
242 not be NULL for a bus driver that wishes to test configuration options for
243 one of its child controllers.
244 @retval EFI_SUCCESS The controller specified by ControllerHandle and ChildHandle that is being
245 managed by the driver specified by This has a valid set of configuration
247 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
248 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
249 @retval EFI_UNSUPPORTED The driver specified by This is not currently managing the controller
250 specified by ControllerHandle and ChildHandle.
251 @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and ChildHandle that is being
252 managed by the driver specified by This has an invalid set of configuration
257 IDEBusDriverConfigurationOptionsValid (
258 IN EFI_DRIVER_CONFIGURATION_PROTOCOL
*This
,
259 IN EFI_HANDLE ControllerHandle
,
260 IN EFI_HANDLE ChildHandle OPTIONAL
264 Forces a driver to set the default configuration options for a controller.
266 @param This A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.
267 @param ControllerHandle The handle of the controller to force default configuration options on.
268 @param ChildHandle The handle of the child controller to force default configuration
269 options on This is an optional parameter that may be NULL. It
270 will be NULL for device drivers. It will also be NULL for a bus
271 drivers that wish to force default configuration options for the bus
272 controller. It will not be NULL for a bus driver that wishes to force
273 default configuration options for one of its child controllers.
274 @param DefaultType The type of default configuration options to force on the controller
275 specified by ControllerHandle and ChildHandle.
276 @param ActionRequired A pointer to the action that the calling agent is required to perform
277 when this function returns.
279 @retval EFI_SUCCESS The driver specified by This successfully forced the
280 default configuration options on the controller specified by
281 ControllerHandle and ChildHandle.
282 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
283 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
284 @retval EFI_INVALID_PARAMETER ActionRequired is NULL.
285 @retval EFI_UNSUPPORTED The driver specified by This does not support forcing the default
286 configuration options on the controller specified by ControllerHandle
288 @retval EFI_UNSUPPORTED The driver specified by This does not support the configuration type
289 specified by DefaultType.
290 @retval EFI_DEVICE_ERROR A device error occurred while attempt to force the default configuration
291 options on the controller specified by ControllerHandle and ChildHandle.
292 @retval EFI_OUT_RESOURCES There are not enough resources available to force the default configuration
293 options on the controller specified by ControllerHandle and ChildHandle.
297 IDEBusDriverConfigurationForceDefaults (
298 IN EFI_DRIVER_CONFIGURATION_PROTOCOL
*This
,
299 IN EFI_HANDLE ControllerHandle
,
300 IN EFI_HANDLE ChildHandle OPTIONAL
,
301 IN UINT32 DefaultType
,
302 OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED
*ActionRequired
306 // EFI Driver Diagnostics Functions
309 Runs diagnostics on a controller.
311 @param This A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOLinstance.
312 @param ControllerHandle The handle of the controller to run diagnostics on.
313 @param ChildHandle The handle of the child controller to run diagnostics on
314 This is an optional parameter that may be NULL. It will
315 be NULL for device drivers. It will also be NULL for a
316 bus drivers that wish to run diagnostics on the bus controller.
317 It will not be NULL for a bus driver that wishes to run
318 diagnostics on one of its child controllers.
319 @param DiagnosticType Indicates type of diagnostics to perform on the controller
320 specified by ControllerHandle and ChildHandle.
321 @param Language A pointer to a three character ISO 639-2 language identifier.
322 This is the language in which the optional error message should
323 be returned in Buffer, and it must match one of the languages
324 specified in SupportedLanguages. The number of languages supported by
325 a driver is up to the driver writer.
326 @param ErrorType A GUID that defines the format of the data returned in Buffer.
327 @param BufferSize The size, in bytes, of the data returned in Buffer.
328 @param Buffer A buffer that contains a Null-terminated Unicode string
329 plus some additional data whose format is defined by ErrorType.
330 Buffer is allocated by this function with AllocatePool(), and
331 it is the caller's responsibility to free it with a call to FreePool().
333 @retval EFI_SUCCESS The controller specified by ControllerHandle and ChildHandle passed
335 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
336 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.
337 @retval EFI_INVALID_PARAMETER Language is NULL.
338 @retval EFI_INVALID_PARAMETER ErrorType is NULL.
339 @retval EFI_INVALID_PARAMETER BufferType is NULL.
340 @retval EFI_INVALID_PARAMETER Buffer is NULL.
341 @retval EFI_UNSUPPORTED The driver specified by This does not support running
342 diagnostics for the controller specified by ControllerHandle
344 @retval EFI_UNSUPPORTED The driver specified by This does not support the
345 type of diagnostic specified by DiagnosticType.
346 @retval EFI_UNSUPPORTED The driver specified by This does not support the language
347 specified by Language.
348 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to complete the
350 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to return the
351 status information in ErrorType, BufferSize,and Buffer.
352 @retval EFI_DEVICE_ERROR The controller specified by ControllerHandle and ChildHandle
353 did not pass the diagnostic.
357 IDEBusDriverDiagnosticsRunDiagnostics (
358 IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL
*This
,
359 IN EFI_HANDLE ControllerHandle
,
360 IN EFI_HANDLE ChildHandle OPTIONAL
,
361 IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType
,
363 OUT EFI_GUID
**ErrorType
,
364 OUT UINTN
*BufferSize
,
369 issue ATA or ATAPI command to reset a block IO device.
370 @param This Block IO protocol instance pointer.
371 @param ExtendedVerification If FALSE,for ATAPI device, driver will only invoke ATAPI reset method
372 If TRUE, for ATAPI device, driver need invoke ATA reset method after
373 invoke ATAPI reset method
375 @retval EFI_DEVICE_ERROR When the device is neighther ATA device or ATAPI device.
376 @retval EFI_SUCCESS The device reset successfully
382 IN EFI_BLOCK_IO_PROTOCOL
*This
,
383 IN BOOLEAN ExtendedVerification
387 Read data from a block IO device.
389 @param This Block IO protocol instance pointer.
390 @param MediaId The media ID of the device
391 @param Lba Starting LBA address to read data
392 @param BufferSize The size of data to be read
393 @param Buffer Caller supplied buffer to save data
395 @retval EFI_DEVICE_ERROR unknown device type
396 @retval EFI_SUCCESS read the data successfully.
402 IN EFI_BLOCK_IO_PROTOCOL
*This
,
410 Write data to block io device
412 @param This Protocol instance pointer.
413 @param MediaId The media ID of the device
414 @param Lba Starting LBA address to write data
415 @param BufferSize The size of data to be written
416 @param Buffer Caller supplied buffer to save data
418 @retval EFI_DEVICE_ERROR unknown device type
419 @retval other write data status
424 IDEBlkIoWriteBlocks (
425 IN EFI_BLOCK_IO_PROTOCOL
*This
,
433 Flushes all modified data to a physical block devices
435 @param This Indicates a pointer to the calling context which to sepcify a
436 sepcific block device
438 @retval EFI_SUCCESS Always return success.
442 IDEBlkIoFlushBlocks (
443 IN EFI_BLOCK_IO_PROTOCOL
*This
446 This function is used by the IDE bus driver to get inquiry data.
447 Data format of Identify data is defined by the Interface GUID.
449 @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
450 @param InquiryData Pointer to a buffer for the inquiry data.
451 @param InquiryDataSize Pointer to the value for the inquiry data size.
453 @retval EFI_SUCCESS The command was accepted without any errors.
454 @retval EFI_NOT_FOUND Device does not support this data class
455 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
456 @retval EFI_BUFFER_TOO_SMALL IntquiryDataSize not big enough
462 IN EFI_DISK_INFO_PROTOCOL
*This
,
463 IN OUT VOID
*InquiryData
,
464 IN OUT UINT32
*InquiryDataSize
468 This function is used by the IDE bus driver to get identify data.
469 Data format of Identify data is defined by the Interface GUID.
471 @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
472 @param IdentifyData Pointer to a buffer for the identify data.
473 @param IdentifyDataSize Pointer to the value for the identify data size.
475 @retval EFI_SUCCESS The command was accepted without any errors.
476 @retval EFI_NOT_FOUND Device does not support this data class
477 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
478 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
483 IDEDiskInfoIdentify (
484 IN EFI_DISK_INFO_PROTOCOL
*This
,
485 IN OUT VOID
*IdentifyData
,
486 IN OUT UINT32
*IdentifyDataSize
490 This function is used by the IDE bus driver to get sense data.
491 Data format of Sense data is defined by the Interface GUID.
493 @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
494 @param SenseData Pointer to the SenseData.
495 @param SenseDataSize Size of SenseData in bytes.
496 @param SenseDataNumber Pointer to the value for the identify data size.
498 @retval EFI_SUCCESS The command was accepted without any errors.
499 @retval EFI_NOT_FOUND Device does not support this data class
500 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
501 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough
506 IDEDiskInfoSenseData (
507 IN EFI_DISK_INFO_PROTOCOL
*This
,
508 IN OUT VOID
*SenseData
,
509 IN OUT UINT32
*SenseDataSize
,
510 OUT UINT8
*SenseDataNumber
514 This function is used by the IDE bus driver to get controller information.
516 @param This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
517 @param IdeChannel Pointer to the Ide Channel number. Primary or secondary.
518 @param IdeDevice Pointer to the Ide Device number. Master or slave.
520 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid
521 @retval EFI_UNSUPPORTED This is not an IDE device
526 IDEDiskInfoWhichIde (
527 IN EFI_DISK_INFO_PROTOCOL
*This
,
528 OUT UINT32
*IdeChannel
,
529 OUT UINT32
*IdeDevice
532 The is an event(generally the event is exitBootService event) call back function.
533 Clear pending IDE interrupt before OS loader/kernel take control of the IDE device.
535 @param Event Pointer to this event
536 @param Context Event hanlder private data