]> git.proxmox.com Git - mirror_edk2.git/blame - PcAtChipsetPkg/Bus/Pci/IdeControllerDxe/IdeController.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / PcAtChipsetPkg / Bus / Pci / IdeControllerDxe / IdeController.c
CommitLineData
a1f11f75 1/** @file\r
3ea80ba2 2 This driver module produces IDE_CONTROLLER_INIT protocol and will be used by\r
a1f11f75 3 IDE Bus driver to support platform dependent timing information. This driver\r
4 is responsible for early initialization of IDE controller.\r
5\r
5a702acd 6 Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r
e1d302e5 7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
a1f11f75 8\r
9**/\r
10\r
11#include "IdeController.h"\r
12\r
3ea80ba2 13///\r
14/// EFI_DRIVER_BINDING_PROTOCOL instance\r
15///\r
5220bd21 16EFI_DRIVER_BINDING_PROTOCOL gIdeControllerDriverBinding = {\r
a1f11f75 17 IdeControllerSupported,\r
18 IdeControllerStart,\r
19 IdeControllerStop,\r
20 0xa,\r
21 NULL,\r
22 NULL\r
23};\r
24\r
20c1e33f 25///\r
26/// EFI_IDE_CONTROLLER_PROVATE_DATA Template\r
27///\r
a1f11f75 28EFI_IDE_CONTROLLER_INIT_PROTOCOL gEfiIdeControllerInit = {\r
29 IdeInitGetChannelInfo,\r
30 IdeInitNotifyPhase,\r
31 IdeInitSubmitData,\r
32 IdeInitDisqualifyMode,\r
33 IdeInitCalculateMode,\r
34 IdeInitSetTiming,\r
35 ICH_IDE_ENUMER_ALL,\r
36 ICH_IDE_MAX_CHANNEL\r
37};\r
38\r
20c1e33f 39///\r
40/// EFI_ATA_COLLECTIVE_MODE Template\r
41///\r
a1f11f75 42EFI_ATA_COLLECTIVE_MODE gEfiAtaCollectiveModeTemplate = {\r
3ea80ba2 43 {\r
44 TRUE, ///< PioMode.Valid\r
45 0 ///< PioMode.Mode\r
a1f11f75 46 },\r
47 {\r
3ea80ba2 48 TRUE, ///< SingleWordDmaMode.Valid\r
a1f11f75 49 0\r
50 },\r
51 {\r
3ea80ba2 52 FALSE, ///< MultiWordDmaMode.Valid\r
a1f11f75 53 0\r
54 },\r
55 {\r
3ea80ba2 56 TRUE, ///< UdmaMode.Valid\r
57 0 ///< UdmaMode.Mode\r
a1f11f75 58 }\r
59};\r
60\r
20c1e33f 61/**\r
3ea80ba2 62 Chipset Ide Driver EntryPoint function. It follows the standard EFI driver model.\r
20c1e33f 63 It's called by StartImage() of DXE Core.\r
64\r
3ea80ba2 65 @param ImageHandle While the driver image loaded be the ImageLoader(),\r
66 an image handle is assigned to this driver binary,\r
20c1e33f 67 all activities of the driver is tied to this ImageHandle\r
68 @param SystemTable A pointer to the system table, for all BS(Boo Services) and\r
69 RT(Runtime Services)\r
3ea80ba2 70\r
20c1e33f 71 @return EFI_STATUS Status of EfiLibInstallDriverBindingComponentName2().\r
72**/\r
a1f11f75 73EFI_STATUS\r
74EFIAPI\r
75InitializeIdeControllerDriver (\r
5220bd21
MK
76 IN EFI_HANDLE ImageHandle,\r
77 IN EFI_SYSTEM_TABLE *SystemTable\r
a1f11f75 78 )\r
a1f11f75 79{\r
80 EFI_STATUS Status;\r
81\r
82 //\r
83 // Install driver model protocol(s).\r
84 //\r
85 Status = EfiLibInstallDriverBindingComponentName2 (\r
86 ImageHandle,\r
87 SystemTable,\r
88 &gIdeControllerDriverBinding,\r
89 ImageHandle,\r
90 &gIdeControllerComponentName,\r
91 &gIdeControllerComponentName2\r
92 );\r
93 ASSERT_EFI_ERROR (Status);\r
94\r
95 return Status;\r
96}\r
97\r
20c1e33f 98/**\r
99 Register Driver Binding protocol for this driver.\r
100\r
101 @param This A pointer points to the Binding Protocol instance\r
3ea80ba2 102 @param Controller The handle of controller to be tested.\r
20c1e33f 103 @param RemainingDevicePath A pointer to the device path. Ignored by device\r
104 driver but used by bus driver\r
3ea80ba2 105\r
106 @retval EFI_SUCCESS Driver loaded.\r
619ad10f 107 @retval !EFI_SUCCESS Driver not loaded.\r
20c1e33f 108**/\r
a1f11f75 109EFI_STATUS\r
110EFIAPI\r
111IdeControllerSupported (\r
5220bd21
MK
112 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
113 IN EFI_HANDLE Controller,\r
114 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
a1f11f75 115 )\r
a1f11f75 116{\r
5220bd21
MK
117 EFI_STATUS Status;\r
118 EFI_PCI_IO_PROTOCOL *PciIo;\r
119 UINT8 PciClass;\r
120 UINT8 PciSubClass;\r
a1f11f75 121\r
122 //\r
123 // Attempt to Open PCI I/O Protocol\r
124 //\r
125 Status = gBS->OpenProtocol (\r
126 Controller,\r
127 &gEfiPciIoProtocolGuid,\r
5220bd21 128 (VOID **)&PciIo,\r
a1f11f75 129 This->DriverBindingHandle,\r
130 Controller,\r
131 EFI_OPEN_PROTOCOL_BY_DRIVER\r
132 );\r
133 if (EFI_ERROR (Status)) {\r
134 return Status;\r
135 }\r
136\r
137 //\r
138 // Now further check the PCI header: Base class (offset 0x0B) and\r
139 // Sub Class (offset 0x0A). This controller should be an Ide controller\r
140 //\r
141 Status = PciIo->Pci.Read (\r
142 PciIo,\r
143 EfiPciIoWidthUint8,\r
144 PCI_CLASSCODE_OFFSET + 2,\r
145 1,\r
146 &PciClass\r
147 );\r
148 if (EFI_ERROR (Status)) {\r
149 goto Done;\r
150 }\r
151\r
152 Status = PciIo->Pci.Read (\r
153 PciIo,\r
154 EfiPciIoWidthUint8,\r
155 PCI_CLASSCODE_OFFSET + 1,\r
156 1,\r
157 &PciSubClass\r
158 );\r
159 if (EFI_ERROR (Status)) {\r
160 goto Done;\r
161 }\r
162\r
163 //\r
164 // Examine Ide PCI Configuration table fields\r
165 //\r
166 if ((PciClass != PCI_CLASS_MASS_STORAGE) || (PciSubClass != PCI_CLASS_MASS_STORAGE_IDE)) {\r
167 Status = EFI_UNSUPPORTED;\r
168 }\r
169\r
170Done:\r
171 gBS->CloseProtocol (\r
5220bd21
MK
172 Controller,\r
173 &gEfiPciIoProtocolGuid,\r
174 This->DriverBindingHandle,\r
175 Controller\r
176 );\r
a1f11f75 177\r
178 return Status;\r
179}\r
180\r
20c1e33f 181/**\r
3ea80ba2 182 This routine is called right after the .Supported() called and return\r
20c1e33f 183 EFI_SUCCESS. Notes: The supported protocols are checked but the Protocols\r
3ea80ba2 184 are closed.\r
20c1e33f 185\r
186 @param This A pointer points to the Binding Protocol instance\r
187 @param Controller The handle of controller to be tested. Parameter\r
188 passed by the caller\r
189 @param RemainingDevicePath A pointer to the device path. Should be ignored by\r
190 device driver\r
3ea80ba2 191\r
20c1e33f 192 @return EFI_STATUS Status of InstallMultipleProtocolInterfaces()\r
193**/\r
a1f11f75 194EFI_STATUS\r
195EFIAPI\r
196IdeControllerStart (\r
5220bd21
MK
197 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
198 IN EFI_HANDLE Controller,\r
199 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
a1f11f75 200 )\r
a1f11f75 201{\r
202 EFI_STATUS Status;\r
203 EFI_PCI_IO_PROTOCOL *PciIo;\r
204\r
205 //\r
206 // Now test and open the EfiPciIoProtocol\r
207 //\r
208 Status = gBS->OpenProtocol (\r
209 Controller,\r
210 &gEfiPciIoProtocolGuid,\r
5220bd21 211 (VOID **)&PciIo,\r
a1f11f75 212 This->DriverBindingHandle,\r
213 Controller,\r
214 EFI_OPEN_PROTOCOL_BY_DRIVER\r
215 );\r
216 //\r
217 // Status == EFI_SUCCESS - A normal execution flow, SUCCESS and the program proceeds.\r
218 // Status == ALREADY_STARTED - A non-zero Status code returned. It indicates\r
219 // that the protocol has been opened and should be treated as a\r
220 // normal condition and the program proceeds. The Protocol will not\r
221 // opened 'again' by this call.\r
222 // Status != ALREADY_STARTED - Error status, terminate program execution\r
223 //\r
224 if (EFI_ERROR (Status)) {\r
225 return Status;\r
226 }\r
227\r
228 //\r
3ea80ba2 229 // Install IDE_CONTROLLER_INIT protocol\r
a1f11f75 230 //\r
231 return gBS->InstallMultipleProtocolInterfaces (\r
232 &Controller,\r
5220bd21
MK
233 &gEfiIdeControllerInitProtocolGuid,\r
234 &gEfiIdeControllerInit,\r
a1f11f75 235 NULL\r
236 );\r
237}\r
238\r
20c1e33f 239/**\r
3ea80ba2 240 Stop this driver on Controller Handle.\r
20c1e33f 241\r
242 @param This Protocol instance pointer.\r
3ea80ba2 243 @param Controller Handle of device to stop driver on\r
20c1e33f 244 @param NumberOfChildren Not used\r
245 @param ChildHandleBuffer Not used\r
3ea80ba2 246\r
619ad10f 247 @retval EFI_SUCCESS This driver is removed DeviceHandle\r
3ea80ba2 248 @retval !EFI_SUCCESS This driver was not removed from this device\r
20c1e33f 249**/\r
a1f11f75 250EFI_STATUS\r
251EFIAPI\r
252IdeControllerStop (\r
5220bd21
MK
253 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
254 IN EFI_HANDLE Controller,\r
255 IN UINTN NumberOfChildren,\r
256 IN EFI_HANDLE *ChildHandleBuffer\r
a1f11f75 257 )\r
a1f11f75 258{\r
259 EFI_STATUS Status;\r
260 EFI_IDE_CONTROLLER_INIT_PROTOCOL *IdeControllerInit;\r
261\r
262 //\r
263 // Open the produced protocol\r
264 //\r
265 Status = gBS->OpenProtocol (\r
266 Controller,\r
267 &gEfiIdeControllerInitProtocolGuid,\r
5220bd21 268 (VOID **)&IdeControllerInit,\r
a1f11f75 269 This->DriverBindingHandle,\r
270 Controller,\r
271 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
272 );\r
273 if (EFI_ERROR (Status)) {\r
5220bd21 274 return EFI_UNSUPPORTED;\r
a1f11f75 275 }\r
276\r
277 //\r
278 // Make sure the protocol was produced by this driver\r
279 //\r
280 if (IdeControllerInit != &gEfiIdeControllerInit) {\r
281 return EFI_UNSUPPORTED;\r
282 }\r
283\r
284 //\r
285 // Uninstall the IDE Controller Init Protocol\r
286 //\r
287 Status = gBS->UninstallMultipleProtocolInterfaces (\r
288 Controller,\r
5220bd21
MK
289 &gEfiIdeControllerInitProtocolGuid,\r
290 &gEfiIdeControllerInit,\r
a1f11f75 291 NULL\r
292 );\r
293 if (EFI_ERROR (Status)) {\r
294 return Status;\r
295 }\r
296\r
297 //\r
298 // Close protocols opened by Ide controller driver\r
299 //\r
300 return gBS->CloseProtocol (\r
301 Controller,\r
302 &gEfiPciIoProtocolGuid,\r
303 This->DriverBindingHandle,\r
304 Controller\r
305 );\r
306}\r
307\r
308//\r
309// Interface functions of IDE_CONTROLLER_INIT protocol\r
310//\r
5220bd21 311\r
20c1e33f 312/**\r
95717b94 313 Returns the information about the specified IDE channel.\r
5a702acd 314\r
95717b94 315 This function can be used to obtain information about a particular IDE channel.\r
5a702acd
LG
316 The driver entity uses this information during the enumeration process.\r
317\r
318 If Enabled is set to FALSE, the driver entity will not scan the channel. Note\r
95717b94 319 that it will not prevent an operating system driver from scanning the channel.\r
5a702acd
LG
320\r
321 For most of today's controllers, MaxDevices will either be 1 or 2. For SATA\r
322 controllers, this value will always be 1. SATA configurations can contain SATA\r
95717b94 323 port multipliers. SATA port multipliers behave like SATA bridges and can support\r
5a702acd
LG
324 up to 16 devices on the other side. If a SATA port out of the IDE controller\r
325 is connected to a port multiplier, MaxDevices will be set to the number of SATA\r
326 devices that the port multiplier supports. Because today's port multipliers\r
327 support up to fifteen SATA devices, this number can be as large as fifteen. The IDE\r
328 bus driver is required to scan for the presence of port multipliers behind an SATA\r
329 controller and enumerate up to MaxDevices number of devices behind the port\r
330 multiplier.\r
331\r
332 In this context, the devices behind a port multiplier constitute a channel.\r
333\r
95717b94 334 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
335 @param[in] Channel Zero-based channel number.\r
5a702acd 336 @param[out] Enabled TRUE if this channel is enabled. Disabled channels\r
95717b94 337 are not scanned to see if any devices are present.\r
338 @param[out] MaxDevices The maximum number of IDE devices that the bus driver\r
5a702acd
LG
339 can expect on this channel. For the ATA/ATAPI\r
340 specification, version 6, this number will either be\r
341 one or two. For Serial ATA (SATA) configurations with a\r
95717b94 342 port multiplier, this number can be as large as fifteen.\r
343\r
344 @retval EFI_SUCCESS Information was returned without any errors.\r
345 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).\r
346\r
20c1e33f 347**/\r
a1f11f75 348EFI_STATUS\r
349EFIAPI\r
350IdeInitGetChannelInfo (\r
5220bd21
MK
351 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
352 IN UINT8 Channel,\r
353 OUT BOOLEAN *Enabled,\r
354 OUT UINT8 *MaxDevices\r
a1f11f75 355 )\r
a1f11f75 356{\r
357 //\r
358 // Channel number (0 based, either 0 or 1)\r
359 //\r
360 if (Channel < ICH_IDE_MAX_CHANNEL) {\r
361 *Enabled = TRUE;\r
362 *MaxDevices = ICH_IDE_MAX_DEVICES;\r
363 return EFI_SUCCESS;\r
364 }\r
365\r
366 *Enabled = FALSE;\r
367 return EFI_INVALID_PARAMETER;\r
368}\r
369\r
20c1e33f 370/**\r
95717b94 371 The notifications from the driver entity that it is about to enter a certain\r
372 phase of the IDE channel enumeration process.\r
5a702acd
LG
373\r
374 This function can be used to notify the IDE controller driver to perform\r
375 specific actions, including any chipset-specific initialization, so that the\r
376 chipset is ready to enter the next phase. Seven notification points are defined\r
377 at this time.\r
378\r
379 More synchronization points may be added as required in the future.\r
95717b94 380\r
381 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
382 @param[in] Phase The phase during enumeration.\r
383 @param[in] Channel Zero-based channel number.\r
384\r
385 @retval EFI_SUCCESS The notification was accepted without any errors.\r
386 @retval EFI_UNSUPPORTED Phase is not supported.\r
387 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).\r
5a702acd
LG
388 @retval EFI_NOT_READY This phase cannot be entered at this time; for\r
389 example, an attempt was made to enter a Phase\r
390 without having entered one or more previous\r
95717b94 391 Phase.\r
3ea80ba2 392\r
20c1e33f 393**/\r
a1f11f75 394EFI_STATUS\r
395EFIAPI\r
396IdeInitNotifyPhase (\r
5220bd21
MK
397 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
398 IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase,\r
399 IN UINT8 Channel\r
a1f11f75 400 )\r
a1f11f75 401{\r
402 return EFI_SUCCESS;\r
403}\r
404\r
20c1e33f 405/**\r
95717b94 406 Submits the device information to the IDE controller driver.\r
407\r
5a702acd
LG
408 This function is used by the driver entity to pass detailed information about\r
409 a particular device to the IDE controller driver. The driver entity obtains\r
95717b94 410 this information by issuing an ATA or ATAPI IDENTIFY_DEVICE command. IdentifyData\r
5a702acd
LG
411 is the pointer to the response data buffer. The IdentifyData buffer is owned\r
412 by the driver entity, and the IDE controller driver must make a local copy\r
413 of the entire buffer or parts of the buffer as needed. The original IdentifyData\r
95717b94 414 buffer pointer may not be valid when\r
5a702acd 415\r
95717b94 416 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() or\r
417 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() is called at a later point.\r
5a702acd
LG
418\r
419 The IDE controller driver may consult various fields of EFI_IDENTIFY_DATA to\r
420 compute the optimum mode for the device. These fields are not limited to the\r
421 timing information. For example, an implementation of the IDE controller driver\r
422 may examine the vendor and type/mode field to match known bad drives.\r
423\r
424 The driver entity may submit drive information in any order, as long as it\r
425 submits information for all the devices belonging to the enumeration group\r
95717b94 426 before EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() is called for any device\r
427 in that enumeration group. If a device is absent, EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()\r
5a702acd
LG
428 should be called with IdentifyData set to NULL. The IDE controller driver may\r
429 not have any other mechanism to know whether a device is present or not. Therefore,\r
430 setting IdentifyData to NULL does not constitute an error condition.\r
431 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData() can be called only once for a\r
432 given (Channel, Device) pair.\r
433\r
95717b94 434 @param[in] This A pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
435 @param[in] Channel Zero-based channel number.\r
436 @param[in] Device Zero-based device number on the Channel.\r
437 @param[in] IdentifyData The device's response to the ATA IDENTIFY_DEVICE command.\r
438\r
439 @retval EFI_SUCCESS The information was accepted without any errors.\r
440 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).\r
441 @retval EFI_INVALID_PARAMETER Device is invalid.\r
20c1e33f 442\r
20c1e33f 443**/\r
a1f11f75 444EFI_STATUS\r
445EFIAPI\r
446IdeInitSubmitData (\r
5220bd21
MK
447 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
448 IN UINT8 Channel,\r
449 IN UINT8 Device,\r
450 IN EFI_IDENTIFY_DATA *IdentifyData\r
a1f11f75 451 )\r
a1f11f75 452{\r
453 return EFI_SUCCESS;\r
454}\r
455\r
20c1e33f 456/**\r
95717b94 457 Disqualifies specific modes for an IDE device.\r
458\r
5a702acd 459 This function allows the driver entity or other drivers (such as platform\r
95717b94 460 drivers) to reject certain timing modes and request the IDE controller driver\r
5a702acd
LG
461 to recalculate modes. This function allows the driver entity and the IDE\r
462 controller driver to negotiate the timings on a per-device basis. This function\r
463 is useful in the case of drives that lie about their capabilities. An example\r
464 is when the IDE device fails to accept the timing modes that are calculated\r
95717b94 465 by the IDE controller driver based on the response to the Identify Drive command.\r
466\r
5a702acd
LG
467 If the driver entity does not want to limit the ATA timing modes and leave that\r
468 decision to the IDE controller driver, it can either not call this function for\r
469 the given device or call this function and set the Valid flag to FALSE for all\r
95717b94 470 modes that are listed in EFI_ATA_COLLECTIVE_MODE.\r
5a702acd
LG
471\r
472 The driver entity may disqualify modes for a device in any order and any number\r
95717b94 473 of times.\r
5a702acd
LG
474\r
475 This function can be called multiple times to invalidate multiple modes of the\r
476 same type (e.g., Programmed Input/Output [PIO] modes 3 and 4). See the ATA/ATAPI\r
477 specification for more information on PIO modes.\r
478\r
95717b94 479 For Serial ATA (SATA) controllers, this member function can be used to disqualify\r
480 a higher transfer rate mode on a given channel. For example, a platform driver\r
5a702acd 481 may inform the IDE controller driver to not use second-generation (Gen2) speeds\r
95717b94 482 for a certain SATA drive.\r
5a702acd 483\r
95717b94 484 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
485 @param[in] Channel The zero-based channel number.\r
486 @param[in] Device The zero-based device number on the Channel.\r
487 @param[in] BadModes The modes that the device does not support and that\r
488 should be disqualified.\r
489\r
490 @retval EFI_SUCCESS The modes were accepted without any errors.\r
491 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).\r
492 @retval EFI_INVALID_PARAMETER Device is invalid.\r
493 @retval EFI_INVALID_PARAMETER IdentifyData is NULL.\r
5a702acd 494\r
20c1e33f 495**/\r
a1f11f75 496EFI_STATUS\r
497EFIAPI\r
498IdeInitDisqualifyMode (\r
5220bd21
MK
499 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
500 IN UINT8 Channel,\r
501 IN UINT8 Device,\r
502 IN EFI_ATA_COLLECTIVE_MODE *BadModes\r
a1f11f75 503 )\r
a1f11f75 504{\r
505 return EFI_SUCCESS;\r
506}\r
507\r
20c1e33f 508/**\r
95717b94 509 Returns the information about the optimum modes for the specified IDE device.\r
510\r
511 This function is used by the driver entity to obtain the optimum ATA modes for\r
5a702acd 512 a specific device. The IDE controller driver takes into account the following\r
95717b94 513 while calculating the mode:\r
514 - The IdentifyData inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()\r
515 - The BadModes inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode()\r
516\r
5a702acd
LG
517 The driver entity is required to call EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()\r
518 for all the devices that belong to an enumeration group before calling\r
519 EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() for any device in the same group.\r
520\r
521 The IDE controller driver will use controller- and possibly platform-specific\r
522 algorithms to arrive at SupportedModes. The IDE controller may base its\r
523 decision on user preferences and other considerations as well. This function\r
524 may be called multiple times because the driver entity may renegotiate the mode\r
95717b94 525 with the IDE controller driver using EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode().\r
5a702acd
LG
526\r
527 The driver entity may collect timing information for various devices in any\r
95717b94 528 order. The driver entity is responsible for making sure that all the dependencies\r
5a702acd
LG
529 are satisfied. For example, the SupportedModes information for device A that\r
530 was previously returned may become stale after a call to\r
95717b94 531 EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() for device B.\r
5a702acd
LG
532\r
533 The buffer SupportedModes is allocated by the callee because the caller does\r
534 not necessarily know the size of the buffer. The type EFI_ATA_COLLECTIVE_MODE\r
535 is defined in a way that allows for future extensibility and can be of variable\r
536 length. This memory pool should be deallocated by the caller when it is no\r
537 longer necessary.\r
538\r
539 The IDE controller driver for a Serial ATA (SATA) controller can use this\r
540 member function to force a lower speed (first-generation [Gen1] speeds on a\r
541 second-generation [Gen2]-capable hardware). The IDE controller driver can\r
542 also allow the driver entity to stay with the speed that has been negotiated\r
95717b94 543 by the physical layer.\r
5a702acd 544\r
95717b94 545 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
546 @param[in] Channel A zero-based channel number.\r
547 @param[in] Device A zero-based device number on the Channel.\r
548 @param[out] SupportedModes The optimum modes for the device.\r
549\r
550 @retval EFI_SUCCESS SupportedModes was returned.\r
551 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).\r
5a702acd 552 @retval EFI_INVALID_PARAMETER Device is invalid.\r
95717b94 553 @retval EFI_INVALID_PARAMETER SupportedModes is NULL.\r
5a702acd
LG
554 @retval EFI_NOT_READY Modes cannot be calculated due to a lack of\r
555 data. This error may happen if\r
556 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()\r
557 and EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyData()\r
558 were not called for at least one drive in the\r
95717b94 559 same enumeration group.\r
3ea80ba2 560\r
20c1e33f 561**/\r
a1f11f75 562EFI_STATUS\r
563EFIAPI\r
564IdeInitCalculateMode (\r
5220bd21
MK
565 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
566 IN UINT8 Channel,\r
567 IN UINT8 Device,\r
568 OUT EFI_ATA_COLLECTIVE_MODE **SupportedModes\r
a1f11f75 569 )\r
a1f11f75 570{\r
5220bd21 571 if ((Channel >= ICH_IDE_MAX_CHANNEL) || (Device >= ICH_IDE_MAX_DEVICES)) {\r
a1f11f75 572 return EFI_INVALID_PARAMETER;\r
573 }\r
574\r
575 *SupportedModes = AllocateCopyPool (sizeof (EFI_ATA_COLLECTIVE_MODE), &gEfiAtaCollectiveModeTemplate);\r
576 if (*SupportedModes == NULL) {\r
577 return EFI_OUT_OF_RESOURCES;\r
578 }\r
579\r
580 return EFI_SUCCESS;\r
581}\r
582\r
20c1e33f 583/**\r
95717b94 584 Commands the IDE controller driver to program the IDE controller hardware\r
585 so that the specified device can operate at the specified mode.\r
586\r
5a702acd
LG
587 This function is used by the driver entity to instruct the IDE controller\r
588 driver to program the IDE controller hardware to the specified modes. This\r
589 function can be called only once for a particular device. For a Serial ATA\r
95717b94 590 (SATA) Advanced Host Controller Interface (AHCI) controller, no controller-\r
591 specific programming may be required.\r
592\r
593 @param[in] This Pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
594 @param[in] Channel Zero-based channel number.\r
595 @param[in] Device Zero-based device number on the Channel.\r
596 @param[in] Modes The modes to set.\r
597\r
598 @retval EFI_SUCCESS The command was accepted without any errors.\r
599 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).\r
600 @retval EFI_INVALID_PARAMETER Device is invalid.\r
601 @retval EFI_NOT_READY Modes cannot be set at this time due to lack of data.\r
602 @retval EFI_DEVICE_ERROR Modes cannot be set due to hardware failure.\r
603 The driver entity should not use this device.\r
3ea80ba2 604\r
20c1e33f 605**/\r
a1f11f75 606EFI_STATUS\r
607EFIAPI\r
608IdeInitSetTiming (\r
5220bd21
MK
609 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
610 IN UINT8 Channel,\r
611 IN UINT8 Device,\r
612 IN EFI_ATA_COLLECTIVE_MODE *Modes\r
a1f11f75 613 )\r
a1f11f75 614{\r
615 return EFI_SUCCESS;\r
616}\r