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 - 2018, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include "IdeController.h"
14 /// EFI_DRIVER_BINDING_PROTOCOL instance
16 EFI_DRIVER_BINDING_PROTOCOL gIdeControllerDriverBinding
= {
17 IdeControllerSupported
,
26 /// EFI_IDE_CONTROLLER_PROVATE_DATA Template
28 EFI_IDE_CONTROLLER_INIT_PROTOCOL gEfiIdeControllerInit
= {
29 IdeInitGetChannelInfo
,
32 IdeInitDisqualifyMode
,
40 /// EFI_ATA_COLLECTIVE_MODE Template
42 EFI_ATA_COLLECTIVE_MODE gEfiAtaCollectiveModeTemplate
= {
44 TRUE
, ///< PioMode.Valid
48 TRUE
, ///< SingleWordDmaMode.Valid
52 FALSE
, ///< MultiWordDmaMode.Valid
56 TRUE
, ///< UdmaMode.Valid
62 Chipset Ide Driver EntryPoint function. It follows the standard EFI driver model.
63 It's called by StartImage() of DXE Core.
65 @param ImageHandle While the driver image loaded be the ImageLoader(),
66 an image handle is assigned to this driver binary,
67 all activities of the driver is tied to this ImageHandle
68 @param SystemTable A pointer to the system table, for all BS(Boo Services) and
71 @return EFI_STATUS Status of EfiLibInstallDriverBindingComponentName2().
75 InitializeIdeControllerDriver (
76 IN EFI_HANDLE ImageHandle
,
77 IN EFI_SYSTEM_TABLE
*SystemTable
83 // Install driver model protocol(s).
85 Status
= EfiLibInstallDriverBindingComponentName2 (
88 &gIdeControllerDriverBinding
,
90 &gIdeControllerComponentName
,
91 &gIdeControllerComponentName2
93 ASSERT_EFI_ERROR (Status
);
99 Register Driver Binding protocol for this driver.
101 @param This A pointer points to the Binding Protocol instance
102 @param Controller The handle of controller to be tested.
103 @param RemainingDevicePath A pointer to the device path. Ignored by device
104 driver but used by bus driver
106 @retval EFI_SUCCESS Driver loaded.
107 @retval !EFI_SUCCESS Driver not loaded.
111 IdeControllerSupported (
112 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
113 IN EFI_HANDLE Controller
,
114 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
118 EFI_PCI_IO_PROTOCOL
*PciIo
;
123 // Attempt to Open PCI I/O Protocol
125 Status
= gBS
->OpenProtocol (
127 &gEfiPciIoProtocolGuid
,
129 This
->DriverBindingHandle
,
131 EFI_OPEN_PROTOCOL_BY_DRIVER
133 if (EFI_ERROR (Status
)) {
138 // Now further check the PCI header: Base class (offset 0x0B) and
139 // Sub Class (offset 0x0A). This controller should be an Ide controller
141 Status
= PciIo
->Pci
.Read (
144 PCI_CLASSCODE_OFFSET
+ 2,
148 if (EFI_ERROR (Status
)) {
152 Status
= PciIo
->Pci
.Read (
155 PCI_CLASSCODE_OFFSET
+ 1,
159 if (EFI_ERROR (Status
)) {
164 // Examine Ide PCI Configuration table fields
166 if ((PciClass
!= PCI_CLASS_MASS_STORAGE
) || (PciSubClass
!= PCI_CLASS_MASS_STORAGE_IDE
)) {
167 Status
= EFI_UNSUPPORTED
;
173 &gEfiPciIoProtocolGuid
,
174 This
->DriverBindingHandle
,
182 This routine is called right after the .Supported() called and return
183 EFI_SUCCESS. Notes: The supported protocols are checked but the Protocols
186 @param This A pointer points to the Binding Protocol instance
187 @param Controller The handle of controller to be tested. Parameter
189 @param RemainingDevicePath A pointer to the device path. Should be ignored by
192 @return EFI_STATUS Status of InstallMultipleProtocolInterfaces()
197 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
198 IN EFI_HANDLE Controller
,
199 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
203 EFI_PCI_IO_PROTOCOL
*PciIo
;
206 // Now test and open the EfiPciIoProtocol
208 Status
= gBS
->OpenProtocol (
210 &gEfiPciIoProtocolGuid
,
212 This
->DriverBindingHandle
,
214 EFI_OPEN_PROTOCOL_BY_DRIVER
217 // Status == EFI_SUCCESS - A normal execution flow, SUCCESS and the program proceeds.
218 // Status == ALREADY_STARTED - A non-zero Status code returned. It indicates
219 // that the protocol has been opened and should be treated as a
220 // normal condition and the program proceeds. The Protocol will not
221 // opened 'again' by this call.
222 // Status != ALREADY_STARTED - Error status, terminate program execution
224 if (EFI_ERROR (Status
)) {
229 // Install IDE_CONTROLLER_INIT protocol
231 return gBS
->InstallMultipleProtocolInterfaces (
233 &gEfiIdeControllerInitProtocolGuid
, &gEfiIdeControllerInit
,
239 Stop this driver on Controller Handle.
241 @param This Protocol instance pointer.
242 @param Controller Handle of device to stop driver on
243 @param NumberOfChildren Not used
244 @param ChildHandleBuffer Not used
246 @retval EFI_SUCCESS This driver is removed DeviceHandle
247 @retval !EFI_SUCCESS This driver was not removed from this device
252 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
253 IN EFI_HANDLE Controller
,
254 IN UINTN NumberOfChildren
,
255 IN EFI_HANDLE
*ChildHandleBuffer
259 EFI_IDE_CONTROLLER_INIT_PROTOCOL
*IdeControllerInit
;
262 // Open the produced protocol
264 Status
= gBS
->OpenProtocol (
266 &gEfiIdeControllerInitProtocolGuid
,
267 (VOID
**) &IdeControllerInit
,
268 This
->DriverBindingHandle
,
270 EFI_OPEN_PROTOCOL_GET_PROTOCOL
272 if (EFI_ERROR (Status
)) {
273 return EFI_UNSUPPORTED
;
277 // Make sure the protocol was produced by this driver
279 if (IdeControllerInit
!= &gEfiIdeControllerInit
) {
280 return EFI_UNSUPPORTED
;
284 // Uninstall the IDE Controller Init Protocol
286 Status
= gBS
->UninstallMultipleProtocolInterfaces (
288 &gEfiIdeControllerInitProtocolGuid
, &gEfiIdeControllerInit
,
291 if (EFI_ERROR (Status
)) {
296 // Close protocols opened by Ide controller driver
298 return gBS
->CloseProtocol (
300 &gEfiPciIoProtocolGuid
,
301 This
->DriverBindingHandle
,
307 // Interface functions of IDE_CONTROLLER_INIT protocol
310 Returns the information about the specified IDE channel.
312 This function can be used to obtain information about a particular IDE channel.
313 The driver entity uses this information during the enumeration process.
315 If Enabled is set to FALSE, the driver entity will not scan the channel. Note
316 that it will not prevent an operating system driver from scanning the channel.
318 For most of today's controllers, MaxDevices will either be 1 or 2. For SATA
319 controllers, this value will always be 1. SATA configurations can contain SATA
320 port multipliers. SATA port multipliers behave like SATA bridges and can support
321 up to 16 devices on the other side. If a SATA port out of the IDE controller
322 is connected to a port multiplier, MaxDevices will be set to the number of SATA
323 devices that the port multiplier supports. Because today's port multipliers
324 support up to fifteen SATA devices, this number can be as large as fifteen. The IDE
325 bus driver is required to scan for the presence of port multipliers behind an SATA
326 controller and enumerate up to MaxDevices number of devices behind the port
329 In this context, the devices behind a port multiplier constitute a channel.
331 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
332 @param[in] Channel Zero-based channel number.
333 @param[out] Enabled TRUE if this channel is enabled. Disabled channels
334 are not scanned to see if any devices are present.
335 @param[out] MaxDevices The maximum number of IDE devices that the bus driver
336 can expect on this channel. For the ATA/ATAPI
337 specification, version 6, this number will either be
338 one or two. For Serial ATA (SATA) configurations with a
339 port multiplier, this number can be as large as fifteen.
341 @retval EFI_SUCCESS Information was returned without any errors.
342 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
347 IdeInitGetChannelInfo (
348 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
350 OUT BOOLEAN
*Enabled
,
351 OUT UINT8
*MaxDevices
355 // Channel number (0 based, either 0 or 1)
357 if (Channel
< ICH_IDE_MAX_CHANNEL
) {
359 *MaxDevices
= ICH_IDE_MAX_DEVICES
;
364 return EFI_INVALID_PARAMETER
;
368 The notifications from the driver entity that it is about to enter a certain
369 phase of the IDE channel enumeration process.
371 This function can be used to notify the IDE controller driver to perform
372 specific actions, including any chipset-specific initialization, so that the
373 chipset is ready to enter the next phase. Seven notification points are defined
376 More synchronization points may be added as required in the future.
378 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
379 @param[in] Phase The phase during enumeration.
380 @param[in] Channel Zero-based channel number.
382 @retval EFI_SUCCESS The notification was accepted without any errors.
383 @retval EFI_UNSUPPORTED Phase is not supported.
384 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
385 @retval EFI_NOT_READY This phase cannot be entered at this time; for
386 example, an attempt was made to enter a Phase
387 without having entered one or more previous
394 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
395 IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase
,
403 Submits the device information to the IDE controller driver.
405 This function is used by the driver entity to pass detailed information about
406 a particular device to the IDE controller driver. The driver entity obtains
407 this information by issuing an ATA or ATAPI IDENTIFY_DEVICE command. IdentifyData
408 is the pointer to the response data buffer. The IdentifyData buffer is owned
409 by the driver entity, and the IDE controller driver must make a local copy
410 of the entire buffer or parts of the buffer as needed. The original IdentifyData
411 buffer pointer may not be valid when
413 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() or
414 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() is called at a later point.
416 The IDE controller driver may consult various fields of EFI_IDENTIFY_DATA to
417 compute the optimum mode for the device. These fields are not limited to the
418 timing information. For example, an implementation of the IDE controller driver
419 may examine the vendor and type/mode field to match known bad drives.
421 The driver entity may submit drive information in any order, as long as it
422 submits information for all the devices belonging to the enumeration group
423 before EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() is called for any device
424 in that enumeration group. If a device is absent, EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
425 should be called with IdentifyData set to NULL. The IDE controller driver may
426 not have any other mechanism to know whether a device is present or not. Therefore,
427 setting IdentifyData to NULL does not constitute an error condition.
428 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData() can be called only once for a
429 given (Channel, Device) pair.
431 @param[in] This A pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
432 @param[in] Channel Zero-based channel number.
433 @param[in] Device Zero-based device number on the Channel.
434 @param[in] IdentifyData The device's response to the ATA IDENTIFY_DEVICE command.
436 @retval EFI_SUCCESS The information was accepted without any errors.
437 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
438 @retval EFI_INVALID_PARAMETER Device is invalid.
444 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
447 IN EFI_IDENTIFY_DATA
*IdentifyData
454 Disqualifies specific modes for an IDE device.
456 This function allows the driver entity or other drivers (such as platform
457 drivers) to reject certain timing modes and request the IDE controller driver
458 to recalculate modes. This function allows the driver entity and the IDE
459 controller driver to negotiate the timings on a per-device basis. This function
460 is useful in the case of drives that lie about their capabilities. An example
461 is when the IDE device fails to accept the timing modes that are calculated
462 by the IDE controller driver based on the response to the Identify Drive command.
464 If the driver entity does not want to limit the ATA timing modes and leave that
465 decision to the IDE controller driver, it can either not call this function for
466 the given device or call this function and set the Valid flag to FALSE for all
467 modes that are listed in EFI_ATA_COLLECTIVE_MODE.
469 The driver entity may disqualify modes for a device in any order and any number
472 This function can be called multiple times to invalidate multiple modes of the
473 same type (e.g., Programmed Input/Output [PIO] modes 3 and 4). See the ATA/ATAPI
474 specification for more information on PIO modes.
476 For Serial ATA (SATA) controllers, this member function can be used to disqualify
477 a higher transfer rate mode on a given channel. For example, a platform driver
478 may inform the IDE controller driver to not use second-generation (Gen2) speeds
479 for a certain SATA drive.
481 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
482 @param[in] Channel The zero-based channel number.
483 @param[in] Device The zero-based device number on the Channel.
484 @param[in] BadModes The modes that the device does not support and that
485 should be disqualified.
487 @retval EFI_SUCCESS The modes were accepted without any errors.
488 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
489 @retval EFI_INVALID_PARAMETER Device is invalid.
490 @retval EFI_INVALID_PARAMETER IdentifyData is NULL.
495 IdeInitDisqualifyMode (
496 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
499 IN EFI_ATA_COLLECTIVE_MODE
*BadModes
506 Returns the information about the optimum modes for the specified IDE device.
508 This function is used by the driver entity to obtain the optimum ATA modes for
509 a specific device. The IDE controller driver takes into account the following
510 while calculating the mode:
511 - The IdentifyData inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
512 - The BadModes inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode()
514 The driver entity is required to call EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
515 for all the devices that belong to an enumeration group before calling
516 EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() for any device in the same group.
518 The IDE controller driver will use controller- and possibly platform-specific
519 algorithms to arrive at SupportedModes. The IDE controller may base its
520 decision on user preferences and other considerations as well. This function
521 may be called multiple times because the driver entity may renegotiate the mode
522 with the IDE controller driver using EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode().
524 The driver entity may collect timing information for various devices in any
525 order. The driver entity is responsible for making sure that all the dependencies
526 are satisfied. For example, the SupportedModes information for device A that
527 was previously returned may become stale after a call to
528 EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() for device B.
530 The buffer SupportedModes is allocated by the callee because the caller does
531 not necessarily know the size of the buffer. The type EFI_ATA_COLLECTIVE_MODE
532 is defined in a way that allows for future extensibility and can be of variable
533 length. This memory pool should be deallocated by the caller when it is no
536 The IDE controller driver for a Serial ATA (SATA) controller can use this
537 member function to force a lower speed (first-generation [Gen1] speeds on a
538 second-generation [Gen2]-capable hardware). The IDE controller driver can
539 also allow the driver entity to stay with the speed that has been negotiated
540 by the physical layer.
542 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
543 @param[in] Channel A zero-based channel number.
544 @param[in] Device A zero-based device number on the Channel.
545 @param[out] SupportedModes The optimum modes for the device.
547 @retval EFI_SUCCESS SupportedModes was returned.
548 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
549 @retval EFI_INVALID_PARAMETER Device is invalid.
550 @retval EFI_INVALID_PARAMETER SupportedModes is NULL.
551 @retval EFI_NOT_READY Modes cannot be calculated due to a lack of
552 data. This error may happen if
553 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
554 and EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyData()
555 were not called for at least one drive in the
556 same enumeration group.
561 IdeInitCalculateMode (
562 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
565 OUT EFI_ATA_COLLECTIVE_MODE
**SupportedModes
568 if (Channel
>= ICH_IDE_MAX_CHANNEL
|| Device
>= ICH_IDE_MAX_DEVICES
) {
569 return EFI_INVALID_PARAMETER
;
572 *SupportedModes
= AllocateCopyPool (sizeof (EFI_ATA_COLLECTIVE_MODE
), &gEfiAtaCollectiveModeTemplate
);
573 if (*SupportedModes
== NULL
) {
574 return EFI_OUT_OF_RESOURCES
;
581 Commands the IDE controller driver to program the IDE controller hardware
582 so that the specified device can operate at the specified mode.
584 This function is used by the driver entity to instruct the IDE controller
585 driver to program the IDE controller hardware to the specified modes. This
586 function can be called only once for a particular device. For a Serial ATA
587 (SATA) Advanced Host Controller Interface (AHCI) controller, no controller-
588 specific programming may be required.
590 @param[in] This Pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
591 @param[in] Channel Zero-based channel number.
592 @param[in] Device Zero-based device number on the Channel.
593 @param[in] Modes The modes to set.
595 @retval EFI_SUCCESS The command was accepted without any errors.
596 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
597 @retval EFI_INVALID_PARAMETER Device is invalid.
598 @retval EFI_NOT_READY Modes cannot be set at this time due to lack of data.
599 @retval EFI_DEVICE_ERROR Modes cannot be set due to hardware failure.
600 The driver entity should not use this device.
606 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
609 IN EFI_ATA_COLLECTIVE_MODE
*Modes