2 Header file for IDE controller driver.
4 Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #ifndef _IDE_CONTROLLER_H_
10 #define _IDE_CONTROLLER_H_
13 #include <Protocol/ComponentName.h>
14 #include <Protocol/DriverBinding.h>
15 #include <Protocol/PciIo.h>
16 #include <Protocol/IdeControllerInit.h>
17 #include <Library/UefiDriverEntryPoint.h>
18 #include <Library/DebugLib.h>
19 #include <Library/UefiLib.h>
20 #include <Library/BaseLib.h>
21 #include <Library/BaseMemoryLib.h>
22 #include <Library/MemoryAllocationLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <IndustryStandard/Pci.h>
27 // Global Variables definitions
29 extern EFI_DRIVER_BINDING_PROTOCOL gIdeControllerDriverBinding
;
30 extern EFI_COMPONENT_NAME_PROTOCOL gIdeControllerComponentName
;
31 extern EFI_COMPONENT_NAME2_PROTOCOL gIdeControllerComponentName2
;
34 /// Supports 2 channel max
36 #define ICH_IDE_MAX_CHANNEL 0x02
39 /// Supports 2 devices max
41 #define ICH_IDE_MAX_DEVICES 0x02
42 #define ICH_IDE_ENUMER_ALL FALSE
45 // Driver binding functions declaration
49 Register Driver Binding protocol for this driver.
51 @param This A pointer points to the Binding Protocol instance
52 @param Controller The handle of controller to be tested.
53 @param RemainingDevicePath A pointer to the device path. Ignored by device
54 driver but used by bus driver
56 @retval EFI_SUCCESS Driver loaded.
57 @retval !EFI_SUCCESS Driver not loaded.
61 IdeControllerSupported (
62 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
63 IN EFI_HANDLE Controller
,
64 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
69 This routine is called right after the .Supported() called and return
70 EFI_SUCCESS. Notes: The supported protocols are checked but the Protocols
73 @param This A pointer points to the Binding Protocol instance
74 @param Controller The handle of controller to be tested. Parameter
76 @param RemainingDevicePath A pointer to the device path. Should be ignored by
79 @return EFI_STATUS Status of InstallMultipleProtocolInterfaces()
84 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
85 IN EFI_HANDLE Controller
,
86 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
91 Stop this driver on Controller Handle.
93 @param This Protocol instance pointer.
94 @param Controller Handle of device to stop driver on
95 @param NumberOfChildren Not used
96 @param ChildHandleBuffer Not used
98 @retval EFI_SUCCESS This driver is removed DeviceHandle
99 @retval !EFI_SUCCESS This driver was not removed from this device
104 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
105 IN EFI_HANDLE Controller
,
106 IN UINTN NumberOfChildren
,
107 IN EFI_HANDLE
*ChildHandleBuffer
112 // IDE controller init functions declaration
116 Returns the information about the specified IDE channel.
118 This function can be used to obtain information about a particular IDE channel.
119 The driver entity uses this information during the enumeration process.
121 If Enabled is set to FALSE, the driver entity will not scan the channel. Note
122 that it will not prevent an operating system driver from scanning the channel.
124 For most of today's controllers, MaxDevices will either be 1 or 2. For SATA
125 controllers, this value will always be 1. SATA configurations can contain SATA
126 port multipliers. SATA port multipliers behave like SATA bridges and can support
127 up to 16 devices on the other side. If a SATA port out of the IDE controller
128 is connected to a port multiplier, MaxDevices will be set to the number of SATA
129 devices that the port multiplier supports. Because today's port multipliers
130 support up to fifteen SATA devices, this number can be as large as fifteen. The IDE
131 bus driver is required to scan for the presence of port multipliers behind an SATA
132 controller and enumerate up to MaxDevices number of devices behind the port
135 In this context, the devices behind a port multiplier constitute a channel.
137 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
138 @param[in] Channel Zero-based channel number.
139 @param[out] Enabled TRUE if this channel is enabled. Disabled channels
140 are not scanned to see if any devices are present.
141 @param[out] MaxDevices The maximum number of IDE devices that the bus driver
142 can expect on this channel. For the ATA/ATAPI
143 specification, version 6, this number will either be
144 one or two. For Serial ATA (SATA) configurations with a
145 port multiplier, this number can be as large as fifteen.
147 @retval EFI_SUCCESS Information was returned without any errors.
148 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
153 IdeInitGetChannelInfo (
154 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
156 OUT BOOLEAN
*Enabled
,
157 OUT UINT8
*MaxDevices
162 The notifications from the driver entity that it is about to enter a certain
163 phase of the IDE channel enumeration process.
165 This function can be used to notify the IDE controller driver to perform
166 specific actions, including any chipset-specific initialization, so that the
167 chipset is ready to enter the next phase. Seven notification points are defined
170 More synchronization points may be added as required in the future.
172 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
173 @param[in] Phase The phase during enumeration.
174 @param[in] Channel Zero-based channel number.
176 @retval EFI_SUCCESS The notification was accepted without any errors.
177 @retval EFI_UNSUPPORTED Phase is not supported.
178 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
179 @retval EFI_NOT_READY This phase cannot be entered at this time; for
180 example, an attempt was made to enter a Phase
181 without having entered one or more previous
188 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
189 IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase
,
195 Submits the device information to the IDE controller driver.
197 This function is used by the driver entity to pass detailed information about
198 a particular device to the IDE controller driver. The driver entity obtains
199 this information by issuing an ATA or ATAPI IDENTIFY_DEVICE command. IdentifyData
200 is the pointer to the response data buffer. The IdentifyData buffer is owned
201 by the driver entity, and the IDE controller driver must make a local copy
202 of the entire buffer or parts of the buffer as needed. The original IdentifyData
203 buffer pointer may not be valid when
205 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() or
206 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() is called at a later point.
208 The IDE controller driver may consult various fields of EFI_IDENTIFY_DATA to
209 compute the optimum mode for the device. These fields are not limited to the
210 timing information. For example, an implementation of the IDE controller driver
211 may examine the vendor and type/mode field to match known bad drives.
213 The driver entity may submit drive information in any order, as long as it
214 submits information for all the devices belonging to the enumeration group
215 before EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() is called for any device
216 in that enumeration group. If a device is absent, EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
217 should be called with IdentifyData set to NULL. The IDE controller driver may
218 not have any other mechanism to know whether a device is present or not. Therefore,
219 setting IdentifyData to NULL does not constitute an error condition.
220 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData() can be called only once for a
221 given (Channel, Device) pair.
223 @param[in] This A pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
224 @param[in] Channel Zero-based channel number.
225 @param[in] Device Zero-based device number on the Channel.
226 @param[in] IdentifyData The device's response to the ATA IDENTIFY_DEVICE command.
228 @retval EFI_SUCCESS The information was accepted without any errors.
229 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
230 @retval EFI_INVALID_PARAMETER Device is invalid.
236 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
239 IN EFI_IDENTIFY_DATA
*IdentifyData
244 Disqualifies specific modes for an IDE device.
246 This function allows the driver entity or other drivers (such as platform
247 drivers) to reject certain timing modes and request the IDE controller driver
248 to recalculate modes. This function allows the driver entity and the IDE
249 controller driver to negotiate the timings on a per-device basis. This function
250 is useful in the case of drives that lie about their capabilities. An example
251 is when the IDE device fails to accept the timing modes that are calculated
252 by the IDE controller driver based on the response to the Identify Drive command.
254 If the driver entity does not want to limit the ATA timing modes and leave that
255 decision to the IDE controller driver, it can either not call this function for
256 the given device or call this function and set the Valid flag to FALSE for all
257 modes that are listed in EFI_ATA_COLLECTIVE_MODE.
259 The driver entity may disqualify modes for a device in any order and any number
262 This function can be called multiple times to invalidate multiple modes of the
263 same type (e.g., Programmed Input/Output [PIO] modes 3 and 4). See the ATA/ATAPI
264 specification for more information on PIO modes.
266 For Serial ATA (SATA) controllers, this member function can be used to disqualify
267 a higher transfer rate mode on a given channel. For example, a platform driver
268 may inform the IDE controller driver to not use second-generation (Gen2) speeds
269 for a certain SATA drive.
271 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
272 @param[in] Channel The zero-based channel number.
273 @param[in] Device The zero-based device number on the Channel.
274 @param[in] BadModes The modes that the device does not support and that
275 should be disqualified.
277 @retval EFI_SUCCESS The modes were accepted without any errors.
278 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
279 @retval EFI_INVALID_PARAMETER Device is invalid.
280 @retval EFI_INVALID_PARAMETER IdentifyData is NULL.
285 IdeInitDisqualifyMode (
286 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
289 IN EFI_ATA_COLLECTIVE_MODE
*BadModes
294 Returns the information about the optimum modes for the specified IDE device.
296 This function is used by the driver entity to obtain the optimum ATA modes for
297 a specific device. The IDE controller driver takes into account the following
298 while calculating the mode:
299 - The IdentifyData inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
300 - The BadModes inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode()
302 The driver entity is required to call EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
303 for all the devices that belong to an enumeration group before calling
304 EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() for any device in the same group.
306 The IDE controller driver will use controller- and possibly platform-specific
307 algorithms to arrive at SupportedModes. The IDE controller may base its
308 decision on user preferences and other considerations as well. This function
309 may be called multiple times because the driver entity may renegotiate the mode
310 with the IDE controller driver using EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode().
312 The driver entity may collect timing information for various devices in any
313 order. The driver entity is responsible for making sure that all the dependencies
314 are satisfied. For example, the SupportedModes information for device A that
315 was previously returned may become stale after a call to
316 EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() for device B.
318 The buffer SupportedModes is allocated by the callee because the caller does
319 not necessarily know the size of the buffer. The type EFI_ATA_COLLECTIVE_MODE
320 is defined in a way that allows for future extensibility and can be of variable
321 length. This memory pool should be deallocated by the caller when it is no
324 The IDE controller driver for a Serial ATA (SATA) controller can use this
325 member function to force a lower speed (first-generation [Gen1] speeds on a
326 second-generation [Gen2]-capable hardware). The IDE controller driver can
327 also allow the driver entity to stay with the speed that has been negotiated
328 by the physical layer.
330 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
331 @param[in] Channel A zero-based channel number.
332 @param[in] Device A zero-based device number on the Channel.
333 @param[out] SupportedModes The optimum modes for the device.
335 @retval EFI_SUCCESS SupportedModes was returned.
336 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
337 @retval EFI_INVALID_PARAMETER Device is invalid.
338 @retval EFI_INVALID_PARAMETER SupportedModes is NULL.
339 @retval EFI_NOT_READY Modes cannot be calculated due to a lack of
340 data. This error may happen if
341 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
342 and EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyData()
343 were not called for at least one drive in the
344 same enumeration group.
349 IdeInitCalculateMode (
350 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
353 OUT EFI_ATA_COLLECTIVE_MODE
**SupportedModes
358 Commands the IDE controller driver to program the IDE controller hardware
359 so that the specified device can operate at the specified mode.
361 This function is used by the driver entity to instruct the IDE controller
362 driver to program the IDE controller hardware to the specified modes. This
363 function can be called only once for a particular device. For a Serial ATA
364 (SATA) Advanced Host Controller Interface (AHCI) controller, no controller-
365 specific programming may be required.
367 @param[in] This Pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
368 @param[in] Channel Zero-based channel number.
369 @param[in] Device Zero-based device number on the Channel.
370 @param[in] Modes The modes to set.
372 @retval EFI_SUCCESS The command was accepted without any errors.
373 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
374 @retval EFI_INVALID_PARAMETER Device is invalid.
375 @retval EFI_NOT_READY Modes cannot be set at this time due to lack of data.
376 @retval EFI_DEVICE_ERROR Modes cannot be set due to hardware failure.
377 The driver entity should not use this device.
383 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL
*This
,
386 IN EFI_ATA_COLLECTIVE_MODE
*Modes
391 // Forward reference declaration
395 Retrieves a Unicode string that is the user readable name of the EFI Driver.
397 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
398 @param Language A pointer to a three character ISO 639-2 language identifier.
399 This is the language of the driver name that that the caller
400 is requesting, and it must match one of the languages specified
401 in SupportedLanguages. The number of languages supported by a
402 driver is up to the driver writer.
403 @param DriverName A pointer to the Unicode string to return. This Unicode string
404 is the name of the driver specified by This in the language
405 specified by Language.
407 @retval EFI_SUCCESS The Unicode string for the Driver specified by This
408 and the language specified by Language was returned
410 @retval EFI_INVALID_PARAMETER Language is NULL.
411 @retval EFI_INVALID_PARAMETER DriverName is NULL.
412 @retval EFI_UNSUPPORTED The driver specified by This does not support the
413 language specified by Language.
417 IdeControllerComponentNameGetDriverName (
418 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
420 OUT CHAR16
**DriverName
425 Retrieves a Unicode string that is the user readable name of the controller
426 that is being managed by an EFI Driver.
428 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
429 @param ControllerHandle The handle of a controller that the driver specified by
430 This is managing. This handle specifies the controller
431 whose name is to be returned.
432 @param OPTIONAL ChildHandle The handle of the child controller to retrieve the name
433 of. This is an optional parameter that may be NULL. It
434 will be NULL for device drivers. It will also be NULL
435 for a bus drivers that wish to retrieve the name of the
436 bus controller. It will not be NULL for a bus driver
437 that wishes to retrieve the name of a child controller.
438 @param Language A pointer to a three character ISO 639-2 language
439 identifier. This is the language of the controller name
440 that that the caller is requesting, and it must match one
441 of the languages specified in SupportedLanguages. The
442 number of languages supported by a driver is up to the
444 @param ControllerName A pointer to the Unicode string to return. This Unicode
445 string is the name of the controller specified by
446 ControllerHandle and ChildHandle in the language
447 specified by Language from the point of view of the
448 driver specified by This.
450 @retval EFI_SUCCESS The Unicode string for the user readable name in the
451 language specified by Language for the driver
452 specified by This was returned in DriverName.
453 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
454 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
456 @retval EFI_INVALID_PARAMETER Language is NULL.
457 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
458 @retval EFI_UNSUPPORTED The driver specified by This is not currently
459 managing the controller specified by
460 ControllerHandle and ChildHandle.
461 @retval EFI_UNSUPPORTED The driver specified by This does not support the
462 language specified by Language.
466 IdeControllerComponentNameGetControllerName (
467 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
468 IN EFI_HANDLE ControllerHandle
,
469 IN EFI_HANDLE ChildHandle OPTIONAL
,
471 OUT CHAR16
**ControllerName