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 - 2009 Intel Corporation. <BR>
7 All rights reserved. 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
69 InitializeIdeControllerDriver (
70 IN EFI_HANDLE ImageHandle
,
71 IN EFI_SYSTEM_TABLE
*SystemTable
76 Chipset Ide Driver EntryPoint function. It follows the standard EFI driver
77 model. It's called by StartImage() of DXE Core
81 ImageHnadle -- While the driver image loaded be the ImageLoader(),
82 an image handle is assigned to this driver binary,
83 all activities of the driver is tied to this ImageHandle
84 *SystemTable -- A pointer to the system table, for all BS(Boo Services) and
89 Always call EfiLibInstallDriverBindingProtocol( ) and retrun the result
96 // Install driver model protocol(s).
98 Status
= EfiLibInstallDriverBindingComponentName2 (
101 &gIdeControllerDriverBinding
,
103 &gIdeControllerComponentName
,
104 &gIdeControllerComponentName2
106 ASSERT_EFI_ERROR (Status
);
113 IdeControllerSupported (
114 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
115 IN EFI_HANDLE Controller
,
116 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
122 Register Driver Binding protocol for this driver.
126 This -- a pointer points to the Binding Protocol instance
127 Controller -- The handle of controller to be tested.
128 *RemainingDevicePath -- A pointer to the device path. Ignored by device
129 driver but used by bus driver
133 EFI_SUCCESS -- Driver loaded.
134 other -- Driver not loaded.
138 EFI_PCI_IO_PROTOCOL
*PciIo
;
143 // Attempt to Open PCI I/O Protocol
145 Status
= gBS
->OpenProtocol (
147 &gEfiPciIoProtocolGuid
,
149 This
->DriverBindingHandle
,
151 EFI_OPEN_PROTOCOL_BY_DRIVER
153 if (EFI_ERROR (Status
)) {
158 // Now further check the PCI header: Base class (offset 0x0B) and
159 // Sub Class (offset 0x0A). This controller should be an Ide controller
161 Status
= PciIo
->Pci
.Read (
164 PCI_CLASSCODE_OFFSET
+ 2,
168 if (EFI_ERROR (Status
)) {
172 Status
= PciIo
->Pci
.Read (
175 PCI_CLASSCODE_OFFSET
+ 1,
179 if (EFI_ERROR (Status
)) {
184 // Examine Ide PCI Configuration table fields
186 if ((PciClass
!= PCI_CLASS_MASS_STORAGE
) || (PciSubClass
!= PCI_CLASS_MASS_STORAGE_IDE
)) {
187 Status
= EFI_UNSUPPORTED
;
193 &gEfiPciIoProtocolGuid
,
194 This
->DriverBindingHandle
,
204 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
205 IN EFI_HANDLE Controller
,
206 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
212 This routine is called right after the .Supported() called and return
213 EFI_SUCCESS. Notes: The supported protocols are checked but the Protocols
218 This -- a pointer points to the Binding Protocol instance
219 Controller -- The handle of controller to be tested. Parameter
221 *RemainingDevicePath -- A pointer to the device path. Should be ignored by
226 EFI_PCI_IO_PROTOCOL
*PciIo
;
229 // Now test and open the EfiPciIoProtocol
231 Status
= gBS
->OpenProtocol (
233 &gEfiPciIoProtocolGuid
,
235 This
->DriverBindingHandle
,
237 EFI_OPEN_PROTOCOL_BY_DRIVER
240 // Status == EFI_SUCCESS - A normal execution flow, SUCCESS and the program proceeds.
241 // Status == ALREADY_STARTED - A non-zero Status code returned. It indicates
242 // that the protocol has been opened and should be treated as a
243 // normal condition and the program proceeds. The Protocol will not
244 // opened 'again' by this call.
245 // Status != ALREADY_STARTED - Error status, terminate program execution
247 if (EFI_ERROR (Status
)) {
252 // Install IDE_CONTROLLER_INIT protocol
254 return gBS
->InstallMultipleProtocolInterfaces (
256 &gEfiIdeControllerInitProtocolGuid
, &gEfiIdeControllerInit
,
264 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
265 IN EFI_HANDLE Controller
,
266 IN UINTN NumberOfChildren
,
267 IN EFI_HANDLE
*ChildHandleBuffer
272 Stop this driver on Controller Handle.
275 This - Protocol instance pointer.
276 Controller - Handle of device to stop driver on
277 NumberOfChildren - Not used
278 ChildHandleBuffer - Not used
281 EFI_SUCCESS - This driver is removed DeviceHandle
282 other - This driver was not removed from this device
287 EFI_IDE_CONTROLLER_INIT_PROTOCOL
*IdeControllerInit
;
290 // Open the produced protocol
292 Status
= gBS
->OpenProtocol (
294 &gEfiIdeControllerInitProtocolGuid
,
295 (VOID
**) &IdeControllerInit
,
296 This
->DriverBindingHandle
,
298 EFI_OPEN_PROTOCOL_GET_PROTOCOL
300 if (EFI_ERROR (Status
)) {
301 return EFI_UNSUPPORTED
;
305 // Make sure the protocol was produced by this driver
307 if (IdeControllerInit
!= &gEfiIdeControllerInit
) {
308 return EFI_UNSUPPORTED
;
312 // Uninstall the IDE Controller Init Protocol
314 Status
= gBS
->UninstallMultipleProtocolInterfaces (
316 &gEfiIdeControllerInitProtocolGuid
, &gEfiIdeControllerInit
,
319 if (EFI_ERROR (Status
)) {
324 // Close protocols opened by Ide controller driver
326 return gBS
->CloseProtocol (
328 &gEfiPciIoProtocolGuid
,
329 This
->DriverBindingHandle
,
335 // Interface functions of IDE_CONTROLLER_INIT protocol
339 IdeInitGetChannelInfo (
340 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
342 OUT BOOLEAN
*Enabled
,
343 OUT UINT8
*MaxDevices
348 This function can be used to obtain information about a specified channel.
349 It's usually used by IDE Bus driver during enumeration process.
353 This -- the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
354 Channel -- Channel number (0 based, either 0 or 1)
355 Enabled -- TRUE if the channel is enabled. If the channel is disabled,
356 then it will no be enumerated.
357 MaxDevices -- The Max number of IDE devices that the bus driver can expect
358 on this channel. For ATA/ATAPI, this number is either 1 or 2.
366 // Channel number (0 based, either 0 or 1)
368 if (Channel
< ICH_IDE_MAX_CHANNEL
) {
370 *MaxDevices
= ICH_IDE_MAX_DEVICES
;
375 return EFI_INVALID_PARAMETER
;
382 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
383 IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase
,
390 This function is called by IdeBus driver before executing certain actions.
391 This allows IDE Controller Init to prepare for each action.
395 This -- the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
396 Phase -- phase indicator defined by IDE_CONTROLLER_INIT protocol
397 Channel -- Channel number (0 based, either 0 or 1)
409 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
412 IN EFI_IDENTIFY_DATA
*IdentifyData
418 This function is called by IdeBus driver to submit EFI_IDENTIFY_DATA data structure
419 obtained from IDE deivce. This structure is used to set IDE timing
423 This -- the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
424 Channel -- IDE channel number (0 based, either 0 or 1)
425 Device -- IDE device number
426 IdentifyData -- A pointer to EFI_IDENTIFY_DATA data structure
437 IdeInitDisqualifyMode (
438 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
441 IN EFI_ATA_COLLECTIVE_MODE
*BadModes
447 This function is called by IdeBus driver to disqualify unsupported operation
448 mode on specfic IDE device
452 This -- the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
453 Channel -- IDE channel number (0 based, either 0 or 1)
454 Device -- IDE device number
455 BadModes -- Operation mode indicator
466 IdeInitCalculateMode (
467 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
470 OUT EFI_ATA_COLLECTIVE_MODE
**SupportedModes
476 This function is called by IdeBus driver to calculate the best operation mode
477 supported by specific IDE device
481 This -- the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
482 Channel -- IDE channel number (0 based, either 0 or 1)
483 Device -- IDE device number
484 SupportedModes -- Modes collection supported by IDE device
490 if (Channel
>= ICH_IDE_MAX_CHANNEL
|| Device
>= ICH_IDE_MAX_DEVICES
) {
491 return EFI_INVALID_PARAMETER
;
494 *SupportedModes
= AllocateCopyPool (sizeof (EFI_ATA_COLLECTIVE_MODE
), &gEfiAtaCollectiveModeTemplate
);
495 if (*SupportedModes
== NULL
) {
496 return EFI_OUT_OF_RESOURCES
;
506 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
509 IN EFI_ATA_COLLECTIVE_MODE
*Modes
515 This function is called by IdeBus driver to set appropriate timing on IDE
516 controller according supported operation mode
520 This -- the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
521 Channel -- IDE channel number (0 based, either 0 or 1)
522 Device -- IDE device number