2 This driver module produces IDE_CONTROLLER_INIT protocol and will be used by
3 IDE Bus driver to support platform dependent timing information. This driver
4 is responsible for early initialization of IDE controller.
6 Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "IdeController.h"
20 /// EFI_DRIVER_BINDING_PROTOCOL instance
22 EFI_DRIVER_BINDING_PROTOCOL gIdeControllerDriverBinding
= {
23 IdeControllerSupported
,
32 /// EFI_IDE_CONTROLLER_PROVATE_DATA Template
34 EFI_IDE_CONTROLLER_INIT_PROTOCOL gEfiIdeControllerInit
= {
35 IdeInitGetChannelInfo
,
38 IdeInitDisqualifyMode
,
46 /// EFI_ATA_COLLECTIVE_MODE Template
48 EFI_ATA_COLLECTIVE_MODE gEfiAtaCollectiveModeTemplate
= {
50 TRUE
, ///< PioMode.Valid
54 TRUE
, ///< SingleWordDmaMode.Valid
58 FALSE
, ///< MultiWordDmaMode.Valid
62 TRUE
, ///< UdmaMode.Valid
68 Chipset Ide Driver EntryPoint function. It follows the standard EFI driver model.
69 It's called by StartImage() of DXE Core.
71 @param ImageHandle While the driver image loaded be the ImageLoader(),
72 an image handle is assigned to this driver binary,
73 all activities of the driver is tied to this ImageHandle
74 @param SystemTable A pointer to the system table, for all BS(Boo Services) and
77 @return EFI_STATUS Status of EfiLibInstallDriverBindingComponentName2().
81 InitializeIdeControllerDriver (
82 IN EFI_HANDLE ImageHandle
,
83 IN EFI_SYSTEM_TABLE
*SystemTable
89 // Install driver model protocol(s).
91 Status
= EfiLibInstallDriverBindingComponentName2 (
94 &gIdeControllerDriverBinding
,
96 &gIdeControllerComponentName
,
97 &gIdeControllerComponentName2
99 ASSERT_EFI_ERROR (Status
);
105 Register Driver Binding protocol for this driver.
107 @param This A pointer points to the Binding Protocol instance
108 @param Controller The handle of controller to be tested.
109 @param RemainingDevicePath A pointer to the device path. Ignored by device
110 driver but used by bus driver
112 @retval EFI_SUCCESS Driver loaded.
113 @retval !EFI_SUCESS Driver not loaded.
117 IdeControllerSupported (
118 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
119 IN EFI_HANDLE Controller
,
120 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
124 EFI_PCI_IO_PROTOCOL
*PciIo
;
129 // Attempt to Open PCI I/O Protocol
131 Status
= gBS
->OpenProtocol (
133 &gEfiPciIoProtocolGuid
,
135 This
->DriverBindingHandle
,
137 EFI_OPEN_PROTOCOL_BY_DRIVER
139 if (EFI_ERROR (Status
)) {
144 // Now further check the PCI header: Base class (offset 0x0B) and
145 // Sub Class (offset 0x0A). This controller should be an Ide controller
147 Status
= PciIo
->Pci
.Read (
150 PCI_CLASSCODE_OFFSET
+ 2,
154 if (EFI_ERROR (Status
)) {
158 Status
= PciIo
->Pci
.Read (
161 PCI_CLASSCODE_OFFSET
+ 1,
165 if (EFI_ERROR (Status
)) {
170 // Examine Ide PCI Configuration table fields
172 if ((PciClass
!= PCI_CLASS_MASS_STORAGE
) || (PciSubClass
!= PCI_CLASS_MASS_STORAGE_IDE
)) {
173 Status
= EFI_UNSUPPORTED
;
179 &gEfiPciIoProtocolGuid
,
180 This
->DriverBindingHandle
,
188 This routine is called right after the .Supported() called and return
189 EFI_SUCCESS. Notes: The supported protocols are checked but the Protocols
192 @param This A pointer points to the Binding Protocol instance
193 @param Controller The handle of controller to be tested. Parameter
195 @param RemainingDevicePath A pointer to the device path. Should be ignored by
198 @return EFI_STATUS Status of InstallMultipleProtocolInterfaces()
203 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
204 IN EFI_HANDLE Controller
,
205 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
209 EFI_PCI_IO_PROTOCOL
*PciIo
;
212 // Now test and open the EfiPciIoProtocol
214 Status
= gBS
->OpenProtocol (
216 &gEfiPciIoProtocolGuid
,
218 This
->DriverBindingHandle
,
220 EFI_OPEN_PROTOCOL_BY_DRIVER
223 // Status == EFI_SUCCESS - A normal execution flow, SUCCESS and the program proceeds.
224 // Status == ALREADY_STARTED - A non-zero Status code returned. It indicates
225 // that the protocol has been opened and should be treated as a
226 // normal condition and the program proceeds. The Protocol will not
227 // opened 'again' by this call.
228 // Status != ALREADY_STARTED - Error status, terminate program execution
230 if (EFI_ERROR (Status
)) {
235 // Install IDE_CONTROLLER_INIT protocol
237 return gBS
->InstallMultipleProtocolInterfaces (
239 &gEfiIdeControllerInitProtocolGuid
, &gEfiIdeControllerInit
,
245 Stop this driver on Controller Handle.
247 @param This Protocol instance pointer.
248 @param Controller Handle of device to stop driver on
249 @param NumberOfChildren Not used
250 @param ChildHandleBuffer Not used
252 @retval EFI_SUCESS This driver is removed DeviceHandle
253 @retval !EFI_SUCCESS This driver was not removed from this device
258 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
259 IN EFI_HANDLE Controller
,
260 IN UINTN NumberOfChildren
,
261 IN EFI_HANDLE
*ChildHandleBuffer
265 EFI_IDE_CONTROLLER_INIT_PROTOCOL
*IdeControllerInit
;
268 // Open the produced protocol
270 Status
= gBS
->OpenProtocol (
272 &gEfiIdeControllerInitProtocolGuid
,
273 (VOID
**) &IdeControllerInit
,
274 This
->DriverBindingHandle
,
276 EFI_OPEN_PROTOCOL_GET_PROTOCOL
278 if (EFI_ERROR (Status
)) {
279 return EFI_UNSUPPORTED
;
283 // Make sure the protocol was produced by this driver
285 if (IdeControllerInit
!= &gEfiIdeControllerInit
) {
286 return EFI_UNSUPPORTED
;
290 // Uninstall the IDE Controller Init Protocol
292 Status
= gBS
->UninstallMultipleProtocolInterfaces (
294 &gEfiIdeControllerInitProtocolGuid
, &gEfiIdeControllerInit
,
297 if (EFI_ERROR (Status
)) {
302 // Close protocols opened by Ide controller driver
304 return gBS
->CloseProtocol (
306 &gEfiPciIoProtocolGuid
,
307 This
->DriverBindingHandle
,
313 // Interface functions of IDE_CONTROLLER_INIT protocol
316 Returns the information about the specified IDE channel.
318 This function can be used to obtain information about a particular IDE channel.
319 The driver entity uses this information during the enumeration process.
321 If Enabled is set to FALSE, the driver entity will not scan the channel. Note
322 that it will not prevent an operating system driver from scanning the channel.
324 For most of today's controllers, MaxDevices will either be 1 or 2. For SATA
325 controllers, this value will always be 1. SATA configurations can contain SATA
326 port multipliers. SATA port multipliers behave like SATA bridges and can support
327 up to 16 devices on the other side. If a SATA port out of the IDE controller
328 is connected to a port multiplier, MaxDevices will be set to the number of SATA
329 devices that the port multiplier supports. Because today's port multipliers
330 support up to fifteen SATA devices, this number can be as large as fifteen. The IDE
331 bus driver is required to scan for the presence of port multipliers behind an SATA
332 controller and enumerate up to MaxDevices number of devices behind the port
335 In this context, the devices behind a port multiplier constitute a channel.
337 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
338 @param[in] Channel Zero-based channel number.
339 @param[out] Enabled TRUE if this channel is enabled. Disabled channels
340 are not scanned to see if any devices are present.
341 @param[out] MaxDevices The maximum number of IDE devices that the bus driver
342 can expect on this channel. For the ATA/ATAPI
343 specification, version 6, this number will either be
344 one or two. For Serial ATA (SATA) configurations with a
345 port multiplier, this number can be as large as fifteen.
347 @retval EFI_SUCCESS Information was returned without any errors.
348 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
353 IdeInitGetChannelInfo (
354 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
356 OUT BOOLEAN
*Enabled
,
357 OUT UINT8
*MaxDevices
361 // Channel number (0 based, either 0 or 1)
363 if (Channel
< ICH_IDE_MAX_CHANNEL
) {
365 *MaxDevices
= ICH_IDE_MAX_DEVICES
;
370 return EFI_INVALID_PARAMETER
;
374 The notifications from the driver entity that it is about to enter a certain
375 phase of the IDE channel enumeration process.
377 This function can be used to notify the IDE controller driver to perform
378 specific actions, including any chipset-specific initialization, so that the
379 chipset is ready to enter the next phase. Seven notification points are defined
382 More synchronization points may be added as required in the future.
384 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
385 @param[in] Phase The phase during enumeration.
386 @param[in] Channel Zero-based channel number.
388 @retval EFI_SUCCESS The notification was accepted without any errors.
389 @retval EFI_UNSUPPORTED Phase is not supported.
390 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
391 @retval EFI_NOT_READY This phase cannot be entered at this time; for
392 example, an attempt was made to enter a Phase
393 without having entered one or more previous
400 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
401 IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase
,
409 Submits the device information to the IDE controller driver.
411 This function is used by the driver entity to pass detailed information about
412 a particular device to the IDE controller driver. The driver entity obtains
413 this information by issuing an ATA or ATAPI IDENTIFY_DEVICE command. IdentifyData
414 is the pointer to the response data buffer. The IdentifyData buffer is owned
415 by the driver entity, and the IDE controller driver must make a local copy
416 of the entire buffer or parts of the buffer as needed. The original IdentifyData
417 buffer pointer may not be valid when
419 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() or
420 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() is called at a later point.
422 The IDE controller driver may consult various fields of EFI_IDENTIFY_DATA to
423 compute the optimum mode for the device. These fields are not limited to the
424 timing information. For example, an implementation of the IDE controller driver
425 may examine the vendor and type/mode field to match known bad drives.
427 The driver entity may submit drive information in any order, as long as it
428 submits information for all the devices belonging to the enumeration group
429 before EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() is called for any device
430 in that enumeration group. If a device is absent, EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
431 should be called with IdentifyData set to NULL. The IDE controller driver may
432 not have any other mechanism to know whether a device is present or not. Therefore,
433 setting IdentifyData to NULL does not constitute an error condition.
434 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData() can be called only once for a
435 given (Channel, Device) pair.
437 @param[in] This A pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
438 @param[in] Channel Zero-based channel number.
439 @param[in] Device Zero-based device number on the Channel.
440 @param[in] IdentifyData The device's response to the ATA IDENTIFY_DEVICE command.
442 @retval EFI_SUCCESS The information was accepted without any errors.
443 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
444 @retval EFI_INVALID_PARAMETER Device is invalid.
450 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
453 IN EFI_IDENTIFY_DATA
*IdentifyData
460 Disqualifies specific modes for an IDE device.
462 This function allows the driver entity or other drivers (such as platform
463 drivers) to reject certain timing modes and request the IDE controller driver
464 to recalculate modes. This function allows the driver entity and the IDE
465 controller driver to negotiate the timings on a per-device basis. This function
466 is useful in the case of drives that lie about their capabilities. An example
467 is when the IDE device fails to accept the timing modes that are calculated
468 by the IDE controller driver based on the response to the Identify Drive command.
470 If the driver entity does not want to limit the ATA timing modes and leave that
471 decision to the IDE controller driver, it can either not call this function for
472 the given device or call this function and set the Valid flag to FALSE for all
473 modes that are listed in EFI_ATA_COLLECTIVE_MODE.
475 The driver entity may disqualify modes for a device in any order and any number
478 This function can be called multiple times to invalidate multiple modes of the
479 same type (e.g., Programmed Input/Output [PIO] modes 3 and 4). See the ATA/ATAPI
480 specification for more information on PIO modes.
482 For Serial ATA (SATA) controllers, this member function can be used to disqualify
483 a higher transfer rate mode on a given channel. For example, a platform driver
484 may inform the IDE controller driver to not use second-generation (Gen2) speeds
485 for a certain SATA drive.
487 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
488 @param[in] Channel The zero-based channel number.
489 @param[in] Device The zero-based device number on the Channel.
490 @param[in] BadModes The modes that the device does not support and that
491 should be disqualified.
493 @retval EFI_SUCCESS The modes were accepted without any errors.
494 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
495 @retval EFI_INVALID_PARAMETER Device is invalid.
496 @retval EFI_INVALID_PARAMETER IdentifyData is NULL.
501 IdeInitDisqualifyMode (
502 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
505 IN EFI_ATA_COLLECTIVE_MODE
*BadModes
512 Returns the information about the optimum modes for the specified IDE device.
514 This function is used by the driver entity to obtain the optimum ATA modes for
515 a specific device. The IDE controller driver takes into account the following
516 while calculating the mode:
517 - The IdentifyData inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
518 - The BadModes inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode()
520 The driver entity is required to call EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
521 for all the devices that belong to an enumeration group before calling
522 EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() for any device in the same group.
524 The IDE controller driver will use controller- and possibly platform-specific
525 algorithms to arrive at SupportedModes. The IDE controller may base its
526 decision on user preferences and other considerations as well. This function
527 may be called multiple times because the driver entity may renegotiate the mode
528 with the IDE controller driver using EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode().
530 The driver entity may collect timing information for various devices in any
531 order. The driver entity is responsible for making sure that all the dependencies
532 are satisfied. For example, the SupportedModes information for device A that
533 was previously returned may become stale after a call to
534 EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() for device B.
536 The buffer SupportedModes is allocated by the callee because the caller does
537 not necessarily know the size of the buffer. The type EFI_ATA_COLLECTIVE_MODE
538 is defined in a way that allows for future extensibility and can be of variable
539 length. This memory pool should be deallocated by the caller when it is no
542 The IDE controller driver for a Serial ATA (SATA) controller can use this
543 member function to force a lower speed (first-generation [Gen1] speeds on a
544 second-generation [Gen2]-capable hardware). The IDE controller driver can
545 also allow the driver entity to stay with the speed that has been negotiated
546 by the physical layer.
548 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
549 @param[in] Channel A zero-based channel number.
550 @param[in] Device A zero-based device number on the Channel.
551 @param[out] SupportedModes The optimum modes for the device.
553 @retval EFI_SUCCESS SupportedModes was returned.
554 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
555 @retval EFI_INVALID_PARAMETER Device is invalid.
556 @retval EFI_INVALID_PARAMETER SupportedModes is NULL.
557 @retval EFI_NOT_READY Modes cannot be calculated due to a lack of
558 data. This error may happen if
559 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
560 and EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyData()
561 were not called for at least one drive in the
562 same enumeration group.
567 IdeInitCalculateMode (
568 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
571 OUT EFI_ATA_COLLECTIVE_MODE
**SupportedModes
574 if (Channel
>= ICH_IDE_MAX_CHANNEL
|| Device
>= ICH_IDE_MAX_DEVICES
) {
575 return EFI_INVALID_PARAMETER
;
578 *SupportedModes
= AllocateCopyPool (sizeof (EFI_ATA_COLLECTIVE_MODE
), &gEfiAtaCollectiveModeTemplate
);
579 if (*SupportedModes
== NULL
) {
580 return EFI_OUT_OF_RESOURCES
;
587 Commands the IDE controller driver to program the IDE controller hardware
588 so that the specified device can operate at the specified mode.
590 This function is used by the driver entity to instruct the IDE controller
591 driver to program the IDE controller hardware to the specified modes. This
592 function can be called only once for a particular device. For a Serial ATA
593 (SATA) Advanced Host Controller Interface (AHCI) controller, no controller-
594 specific programming may be required.
596 @param[in] This Pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
597 @param[in] Channel Zero-based channel number.
598 @param[in] Device Zero-based device number on the Channel.
599 @param[in] Modes The modes to set.
601 @retval EFI_SUCCESS The command was accepted without any errors.
602 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
603 @retval EFI_INVALID_PARAMETER Device is invalid.
604 @retval EFI_NOT_READY Modes cannot be set at this time due to lack of data.
605 @retval EFI_DEVICE_ERROR Modes cannot be set due to hardware failure.
606 The driver entity should not use this device.
612 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
615 IN EFI_ATA_COLLECTIVE_MODE
*Modes