1 /** @file 2 Header file for IDE controller driver. 3 4 Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR> 5 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 9 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. 12 13 **/ 14 15 #ifndef _IDE_CONTROLLER_H_ 16 #define _IDE_CONTROLLER_H_ 17 18 #include <Uefi.h> 19 #include <Protocol/ComponentName.h> 20 #include <Protocol/DriverBinding.h> 21 #include <Protocol/PciIo.h> 22 #include <Protocol/IdeControllerInit.h> 23 #include <Library/UefiDriverEntryPoint.h> 24 #include <Library/DebugLib.h> 25 #include <Library/UefiLib.h> 26 #include <Library/BaseLib.h> 27 #include <Library/BaseMemoryLib.h> 28 #include <Library/MemoryAllocationLib.h> 29 #include <Library/UefiBootServicesTableLib.h> 30 #include <IndustryStandard/Pci.h> 31 32 // 33 // Global Variables definitions 34 // 35 extern EFI_DRIVER_BINDING_PROTOCOL gIdeControllerDriverBinding; 36 extern EFI_COMPONENT_NAME_PROTOCOL gIdeControllerComponentName; 37 extern EFI_COMPONENT_NAME2_PROTOCOL gIdeControllerComponentName2; 38 39 /// 40 /// Supports 2 channel max 41 /// 42 #define ICH_IDE_MAX_CHANNEL 0x02 43 44 /// 45 /// Supports 2 devices max 46 /// 47 #define ICH_IDE_MAX_DEVICES 0x02 48 #define ICH_IDE_ENUMER_ALL FALSE 49 50 // 51 // Driver binding functions declaration 52 // 53 /** 54 Register Driver Binding protocol for this driver. 55 56 @param This A pointer points to the Binding Protocol instance 57 @param Controller The handle of controller to be tested. 58 @param RemainingDevicePath A pointer to the device path. Ignored by device 59 driver but used by bus driver 60 61 @retval EFI_SUCCESS Driver loaded. 62 @retval !EFI_SUCESS Driver not loaded. 63 **/ 64 EFI_STATUS 65 EFIAPI 66 IdeControllerSupported ( 67 IN EFI_DRIVER_BINDING_PROTOCOL *This, 68 IN EFI_HANDLE Controller, 69 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath 70 ) 71 ; 72 73 /** 74 This routine is called right after the .Supported() called and return 75 EFI_SUCCESS. Notes: The supported protocols are checked but the Protocols 76 are closed. 77 78 @param This A pointer points to the Binding Protocol instance 79 @param Controller The handle of controller to be tested. Parameter 80 passed by the caller 81 @param RemainingDevicePath A pointer to the device path. Should be ignored by 82 device driver 83 84 @return EFI_STATUS Status of InstallMultipleProtocolInterfaces() 85 **/ 86 EFI_STATUS 87 EFIAPI 88 IdeControllerStart ( 89 IN EFI_DRIVER_BINDING_PROTOCOL *This, 90 IN EFI_HANDLE Controller, 91 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath 92 ) 93 ; 94 95 /** 96 Stop this driver on Controller Handle. 97 98 @param This Protocol instance pointer. 99 @param Controller Handle of device to stop driver on 100 @param NumberOfChildren Not used 101 @param ChildHandleBuffer Not used 102 103 @retval EFI_SUCESS This driver is removed DeviceHandle 104 @retval !EFI_SUCCESS This driver was not removed from this device 105 **/ 106 EFI_STATUS 107 EFIAPI 108 IdeControllerStop ( 109 IN EFI_DRIVER_BINDING_PROTOCOL *This, 110 IN EFI_HANDLE Controller, 111 IN UINTN NumberOfChildren, 112 IN EFI_HANDLE *ChildHandleBuffer 113 ) 114 ; 115 116 // 117 // IDE controller init functions declaration 118 // 119 /** 120 Returns the information about the specified IDE channel. 121 122 This function can be used to obtain information about a particular IDE channel. 123 The driver entity uses this information during the enumeration process. 124 125 If Enabled is set to FALSE, the driver entity will not scan the channel. Note 126 that it will not prevent an operating system driver from scanning the channel. 127 128 For most of today's controllers, MaxDevices will either be 1 or 2. For SATA 129 controllers, this value will always be 1. SATA configurations can contain SATA 130 port multipliers. SATA port multipliers behave like SATA bridges and can support 131 up to 16 devices on the other side. If a SATA port out of the IDE controller 132 is connected to a port multiplier, MaxDevices will be set to the number of SATA 133 devices that the port multiplier supports. Because today's port multipliers 134 support up to fifteen SATA devices, this number can be as large as fifteen. The IDE 135 bus driver is required to scan for the presence of port multipliers behind an SATA 136 controller and enumerate up to MaxDevices number of devices behind the port 137 multiplier. 138 139 In this context, the devices behind a port multiplier constitute a channel. 140 141 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance. 142 @param[in] Channel Zero-based channel number. 143 @param[out] Enabled TRUE if this channel is enabled. Disabled channels 144 are not scanned to see if any devices are present. 145 @param[out] MaxDevices The maximum number of IDE devices that the bus driver 146 can expect on this channel. For the ATA/ATAPI 147 specification, version 6, this number will either be 148 one or two. For Serial ATA (SATA) configurations with a 149 port multiplier, this number can be as large as fifteen. 150 151 @retval EFI_SUCCESS Information was returned without any errors. 152 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount). 153 154 **/ 155 EFI_STATUS 156 EFIAPI 157 IdeInitGetChannelInfo ( 158 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This, 159 IN UINT8 Channel, 160 OUT BOOLEAN *Enabled, 161 OUT UINT8 *MaxDevices 162 ) 163 ; 164 165 /** 166 The notifications from the driver entity that it is about to enter a certain 167 phase of the IDE channel enumeration process. 168 169 This function can be used to notify the IDE controller driver to perform 170 specific actions, including any chipset-specific initialization, so that the 171 chipset is ready to enter the next phase. Seven notification points are defined 172 at this time. 173 174 More synchronization points may be added as required in the future. 175 176 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance. 177 @param[in] Phase The phase during enumeration. 178 @param[in] Channel Zero-based channel number. 179 180 @retval EFI_SUCCESS The notification was accepted without any errors. 181 @retval EFI_UNSUPPORTED Phase is not supported. 182 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount). 183 @retval EFI_NOT_READY This phase cannot be entered at this time; for 184 example, an attempt was made to enter a Phase 185 without having entered one or more previous 186 Phase. 187 188 **/ 189 EFI_STATUS 190 EFIAPI 191 IdeInitNotifyPhase ( 192 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This, 193 IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase, 194 IN UINT8 Channel 195 ) 196 ; 197 198 /** 199 Submits the device information to the IDE controller driver. 200 201 This function is used by the driver entity to pass detailed information about 202 a particular device to the IDE controller driver. The driver entity obtains 203 this information by issuing an ATA or ATAPI IDENTIFY_DEVICE command. IdentifyData 204 is the pointer to the response data buffer. The IdentifyData buffer is owned 205 by the driver entity, and the IDE controller driver must make a local copy 206 of the entire buffer or parts of the buffer as needed. The original IdentifyData 207 buffer pointer may not be valid when 208 209 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() or 210 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() is called at a later point. 211 212 The IDE controller driver may consult various fields of EFI_IDENTIFY_DATA to 213 compute the optimum mode for the device. These fields are not limited to the 214 timing information. For example, an implementation of the IDE controller driver 215 may examine the vendor and type/mode field to match known bad drives. 216 217 The driver entity may submit drive information in any order, as long as it 218 submits information for all the devices belonging to the enumeration group 219 before EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() is called for any device 220 in that enumeration group. If a device is absent, EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData() 221 should be called with IdentifyData set to NULL. The IDE controller driver may 222 not have any other mechanism to know whether a device is present or not. Therefore, 223 setting IdentifyData to NULL does not constitute an error condition. 224 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData() can be called only once for a 225 given (Channel, Device) pair. 226 227 @param[in] This A pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance. 228 @param[in] Channel Zero-based channel number. 229 @param[in] Device Zero-based device number on the Channel. 230 @param[in] IdentifyData The device's response to the ATA IDENTIFY_DEVICE command. 231 232 @retval EFI_SUCCESS The information was accepted without any errors. 233 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount). 234 @retval EFI_INVALID_PARAMETER Device is invalid. 235 236 **/ 237 EFI_STATUS 238 EFIAPI 239 IdeInitSubmitData ( 240 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This, 241 IN UINT8 Channel, 242 IN UINT8 Device, 243 IN EFI_IDENTIFY_DATA *IdentifyData 244 ) 245 ; 246 247 /** 248 Disqualifies specific modes for an IDE device. 249 250 This function allows the driver entity or other drivers (such as platform 251 drivers) to reject certain timing modes and request the IDE controller driver 252 to recalculate modes. This function allows the driver entity and the IDE 253 controller driver to negotiate the timings on a per-device basis. This function 254 is useful in the case of drives that lie about their capabilities. An example 255 is when the IDE device fails to accept the timing modes that are calculated 256 by the IDE controller driver based on the response to the Identify Drive command. 257 258 If the driver entity does not want to limit the ATA timing modes and leave that 259 decision to the IDE controller driver, it can either not call this function for 260 the given device or call this function and set the Valid flag to FALSE for all 261 modes that are listed in EFI_ATA_COLLECTIVE_MODE. 262 263 The driver entity may disqualify modes for a device in any order and any number 264 of times. 265 266 This function can be called multiple times to invalidate multiple modes of the 267 same type (e.g., Programmed Input/Output [PIO] modes 3 and 4). See the ATA/ATAPI 268 specification for more information on PIO modes. 269 270 For Serial ATA (SATA) controllers, this member function can be used to disqualify 271 a higher transfer rate mode on a given channel. For example, a platform driver 272 may inform the IDE controller driver to not use second-generation (Gen2) speeds 273 for a certain SATA drive. 274 275 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance. 276 @param[in] Channel The zero-based channel number. 277 @param[in] Device The zero-based device number on the Channel. 278 @param[in] BadModes The modes that the device does not support and that 279 should be disqualified. 280 281 @retval EFI_SUCCESS The modes were accepted without any errors. 282 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount). 283 @retval EFI_INVALID_PARAMETER Device is invalid. 284 @retval EFI_INVALID_PARAMETER IdentifyData is NULL. 285 286 **/ 287 EFI_STATUS 288 EFIAPI 289 IdeInitDisqualifyMode ( 290 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This, 291 IN UINT8 Channel, 292 IN UINT8 Device, 293 IN EFI_ATA_COLLECTIVE_MODE *BadModes 294 ) 295 ; 296 297 /** 298 Returns the information about the optimum modes for the specified IDE device. 299 300 This function is used by the driver entity to obtain the optimum ATA modes for 301 a specific device. The IDE controller driver takes into account the following 302 while calculating the mode: 303 - The IdentifyData inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData() 304 - The BadModes inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() 305 306 The driver entity is required to call EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData() 307 for all the devices that belong to an enumeration group before calling 308 EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() for any device in the same group. 309 310 The IDE controller driver will use controller- and possibly platform-specific 311 algorithms to arrive at SupportedModes. The IDE controller may base its 312 decision on user preferences and other considerations as well. This function 313 may be called multiple times because the driver entity may renegotiate the mode 314 with the IDE controller driver using EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode(). 315 316 The driver entity may collect timing information for various devices in any 317 order. The driver entity is responsible for making sure that all the dependencies 318 are satisfied. For example, the SupportedModes information for device A that 319 was previously returned may become stale after a call to 320 EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() for device B. 321 322 The buffer SupportedModes is allocated by the callee because the caller does 323 not necessarily know the size of the buffer. The type EFI_ATA_COLLECTIVE_MODE 324 is defined in a way that allows for future extensibility and can be of variable 325 length. This memory pool should be deallocated by the caller when it is no 326 longer necessary. 327 328 The IDE controller driver for a Serial ATA (SATA) controller can use this 329 member function to force a lower speed (first-generation [Gen1] speeds on a 330 second-generation [Gen2]-capable hardware). The IDE controller driver can 331 also allow the driver entity to stay with the speed that has been negotiated 332 by the physical layer. 333 334 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance. 335 @param[in] Channel A zero-based channel number. 336 @param[in] Device A zero-based device number on the Channel. 337 @param[out] SupportedModes The optimum modes for the device. 338 339 @retval EFI_SUCCESS SupportedModes was returned. 340 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount). 341 @retval EFI_INVALID_PARAMETER Device is invalid. 342 @retval EFI_INVALID_PARAMETER SupportedModes is NULL. 343 @retval EFI_NOT_READY Modes cannot be calculated due to a lack of 344 data. This error may happen if 345 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData() 346 and EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyData() 347 were not called for at least one drive in the 348 same enumeration group. 349 350 **/ 351 EFI_STATUS 352 EFIAPI 353 IdeInitCalculateMode ( 354 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This, 355 IN UINT8 Channel, 356 IN UINT8 Device, 357 OUT EFI_ATA_COLLECTIVE_MODE **SupportedModes 358 ) 359 ; 360 361 /** 362 Commands the IDE controller driver to program the IDE controller hardware 363 so that the specified device can operate at the specified mode. 364 365 This function is used by the driver entity to instruct the IDE controller 366 driver to program the IDE controller hardware to the specified modes. This 367 function can be called only once for a particular device. For a Serial ATA 368 (SATA) Advanced Host Controller Interface (AHCI) controller, no controller- 369 specific programming may be required. 370 371 @param[in] This Pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance. 372 @param[in] Channel Zero-based channel number. 373 @param[in] Device Zero-based device number on the Channel. 374 @param[in] Modes The modes to set. 375 376 @retval EFI_SUCCESS The command was accepted without any errors. 377 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount). 378 @retval EFI_INVALID_PARAMETER Device is invalid. 379 @retval EFI_NOT_READY Modes cannot be set at this time due to lack of data. 380 @retval EFI_DEVICE_ERROR Modes cannot be set due to hardware failure. 381 The driver entity should not use this device. 382 383 **/ 384 EFI_STATUS 385 EFIAPI 386 IdeInitSetTiming ( 387 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This, 388 IN UINT8 Channel, 389 IN UINT8 Device, 390 IN EFI_ATA_COLLECTIVE_MODE *Modes 391 ) 392 ; 393 394 // 395 // Forward reference declaration 396 // 397 /** 398 Retrieves a Unicode string that is the user readable name of the EFI Driver. 399 400 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance. 401 @param Language A pointer to a three character ISO 639-2 language identifier. 402 This is the language of the driver name that that the caller 403 is requesting, and it must match one of the languages specified 404 in SupportedLanguages. The number of languages supported by a 405 driver is up to the driver writer. 406 @param DriverName A pointer to the Unicode string to return. This Unicode string 407 is the name of the driver specified by This in the language 408 specified by Language. 409 410 @retval EFI_SUCCESS The Unicode string for the Driver specified by This 411 and the language specified by Language was returned 412 in DriverName. 413 @retval EFI_INVALID_PARAMETER Language is NULL. 414 @retval EFI_INVALID_PARAMETER DriverName is NULL. 415 @retval EFI_UNSUPPORTED The driver specified by This does not support the 416 language specified by Language. 417 **/ 418 EFI_STATUS 419 EFIAPI 420 IdeControllerComponentNameGetDriverName ( 421 IN EFI_COMPONENT_NAME_PROTOCOL *This, 422 IN CHAR8 *Language, 423 OUT CHAR16 **DriverName 424 ) 425 ; 426 427 /** 428 Retrieves a Unicode string that is the user readable name of the controller 429 that is being managed by an EFI Driver. 430 431 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance. 432 @param ControllerHandle The handle of a controller that the driver specified by 433 This is managing. This handle specifies the controller 434 whose name is to be returned. 435 @param OPTIONAL ChildHandle The handle of the child controller to retrieve the name 436 of. This is an optional parameter that may be NULL. It 437 will be NULL for device drivers. It will also be NULL 438 for a bus drivers that wish to retrieve the name of the 439 bus controller. It will not be NULL for a bus driver 440 that wishes to retrieve the name of a child controller. 441 @param Language A pointer to a three character ISO 639-2 language 442 identifier. This is the language of the controller name 443 that that the caller is requesting, and it must match one 444 of the languages specified in SupportedLanguages. The 445 number of languages supported by a driver is up to the 446 driver writer. 447 @param ControllerName A pointer to the Unicode string to return. This Unicode 448 string is the name of the controller specified by 449 ControllerHandle and ChildHandle in the language 450 specified by Language from the point of view of the 451 driver specified by This. 452 453 @retval EFI_SUCCESS The Unicode string for the user readable name in the 454 language specified by Language for the driver 455 specified by This was returned in DriverName. 456 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL. 457 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid 458 EFI_HANDLE. 459 @retval EFI_INVALID_PARAMETER Language is NULL. 460 @retval EFI_INVALID_PARAMETER ControllerName is NULL. 461 @retval EFI_UNSUPPORTED The driver specified by This is not currently 462 managing the controller specified by 463 ControllerHandle and ChildHandle. 464 @retval EFI_UNSUPPORTED The driver specified by This does not support the 465 language specified by Language. 466 **/ 467 EFI_STATUS 468 EFIAPI 469 IdeControllerComponentNameGetControllerName ( 470 IN EFI_COMPONENT_NAME_PROTOCOL *This, 471 IN EFI_HANDLE ControllerHandle, 472 IN EFI_HANDLE ChildHandle OPTIONAL, 473 IN CHAR8 *Language, 474 OUT CHAR16 **ControllerName 475 ) 476 ; 477 478 #endif 479