]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/SataControllerDxe/SataController.c
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / SataControllerDxe / SataController.c
CommitLineData
12e92a23
RJ
1/** @file\r
2 This driver module produces IDE_CONTROLLER_INIT protocol for Sata Controllers.\r
3\r
4 Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
b26f0cf9 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
12e92a23
RJ
6\r
7**/\r
8\r
9#include "SataController.h"\r
10\r
11///\r
12/// EFI_DRIVER_BINDING_PROTOCOL instance\r
13///\r
ac0a286f 14EFI_DRIVER_BINDING_PROTOCOL gSataControllerDriverBinding = {\r
12e92a23
RJ
15 SataControllerSupported,\r
16 SataControllerStart,\r
17 SataControllerStop,\r
18 0xa,\r
19 NULL,\r
20 NULL\r
21};\r
22\r
23/**\r
24 Read AHCI Operation register.\r
25\r
26 @param PciIo The PCI IO protocol instance.\r
27 @param Offset The operation register offset.\r
28\r
29 @return The register content read.\r
30\r
31**/\r
32UINT32\r
33EFIAPI\r
34AhciReadReg (\r
ac0a286f
MK
35 IN EFI_PCI_IO_PROTOCOL *PciIo,\r
36 IN UINT32 Offset\r
12e92a23
RJ
37 )\r
38{\r
ac0a286f 39 UINT32 Data;\r
12e92a23
RJ
40\r
41 ASSERT (PciIo != NULL);\r
4040754d 42\r
12e92a23
RJ
43 Data = 0;\r
44\r
45 PciIo->Mem.Read (\r
46 PciIo,\r
47 EfiPciIoWidthUint32,\r
48 AHCI_BAR_INDEX,\r
ac0a286f 49 (UINT64)Offset,\r
12e92a23
RJ
50 1,\r
51 &Data\r
52 );\r
53\r
54 return Data;\r
55}\r
56\r
57/**\r
58 Write AHCI Operation register.\r
59\r
60 @param PciIo The PCI IO protocol instance.\r
61 @param Offset The operation register offset.\r
62 @param Data The data used to write down.\r
63\r
64**/\r
65VOID\r
66EFIAPI\r
67AhciWriteReg (\r
ac0a286f
MK
68 IN EFI_PCI_IO_PROTOCOL *PciIo,\r
69 IN UINT32 Offset,\r
70 IN UINT32 Data\r
12e92a23
RJ
71 )\r
72{\r
73 ASSERT (PciIo != NULL);\r
74\r
75 PciIo->Mem.Write (\r
76 PciIo,\r
77 EfiPciIoWidthUint32,\r
78 AHCI_BAR_INDEX,\r
ac0a286f 79 (UINT64)Offset,\r
12e92a23
RJ
80 1,\r
81 &Data\r
82 );\r
83\r
84 return;\r
85}\r
86\r
87/**\r
88 This function is used to calculate the best PIO mode supported by specific IDE device\r
89\r
90 @param IdentifyData The identify data of specific IDE device.\r
91 @param DisPioMode Disqualified PIO modes collection.\r
92 @param SelectedMode Available PIO modes collection.\r
93\r
94 @retval EFI_SUCCESS Best PIO modes are returned.\r
95 @retval EFI_UNSUPPORTED The device doesn't support PIO mode,\r
96 or all supported modes have been disqualified.\r
97**/\r
98EFI_STATUS\r
99CalculateBestPioMode (\r
100 IN EFI_IDENTIFY_DATA *IdentifyData,\r
101 IN UINT16 *DisPioMode OPTIONAL,\r
102 OUT UINT16 *SelectedMode\r
103 )\r
104{\r
ac0a286f
MK
105 UINT16 PioMode;\r
106 UINT16 AdvancedPioMode;\r
107 UINT16 Temp;\r
108 UINT16 Index;\r
109 UINT16 MinimumPioCycleTime;\r
12e92a23
RJ
110\r
111 Temp = 0xff;\r
112\r
ac0a286f 113 PioMode = (UINT8)(((ATA5_IDENTIFY_DATA *)(&(IdentifyData->AtaData)))->pio_cycle_timing >> 8);\r
12e92a23
RJ
114\r
115 //\r
116 // See whether Identify Data word 64 - 70 are valid\r
117 //\r
118 if ((IdentifyData->AtaData.field_validity & 0x02) == 0x02) {\r
12e92a23 119 AdvancedPioMode = IdentifyData->AtaData.advanced_pio_modes;\r
70d5086c 120 DEBUG ((DEBUG_INFO, "CalculateBestPioMode: AdvancedPioMode = %x\n", AdvancedPioMode));\r
12e92a23
RJ
121\r
122 for (Index = 0; Index < 8; Index++) {\r
123 if ((AdvancedPioMode & 0x01) != 0) {\r
124 Temp = Index;\r
125 }\r
126\r
127 AdvancedPioMode >>= 1;\r
128 }\r
129\r
130 //\r
131 // If Temp is modified, mean the advanced_pio_modes is not zero;\r
132 // if Temp is not modified, mean there is no advanced PIO mode supported,\r
133 // the best PIO Mode is the value in pio_cycle_timing.\r
134 //\r
135 if (Temp != 0xff) {\r
ac0a286f 136 AdvancedPioMode = (UINT16)(Temp + 3);\r
12e92a23
RJ
137 } else {\r
138 AdvancedPioMode = PioMode;\r
139 }\r
140\r
141 //\r
142 // Limit the PIO mode to at most PIO4.\r
143 //\r
ac0a286f 144 PioMode = (UINT16)MIN (AdvancedPioMode, 4);\r
12e92a23
RJ
145\r
146 MinimumPioCycleTime = IdentifyData->AtaData.min_pio_cycle_time_with_flow_control;\r
147\r
148 if (MinimumPioCycleTime <= 120) {\r
ac0a286f 149 PioMode = (UINT16)MIN (4, PioMode);\r
12e92a23 150 } else if (MinimumPioCycleTime <= 180) {\r
ac0a286f 151 PioMode = (UINT16)MIN (3, PioMode);\r
12e92a23 152 } else if (MinimumPioCycleTime <= 240) {\r
ac0a286f 153 PioMode = (UINT16)MIN (2, PioMode);\r
12e92a23
RJ
154 } else {\r
155 PioMode = 0;\r
156 }\r
157\r
158 //\r
159 // Degrade the PIO mode if the mode has been disqualified\r
160 //\r
161 if (DisPioMode != NULL) {\r
162 if (*DisPioMode < 2) {\r
163 return EFI_UNSUPPORTED; // no mode below ATA_PIO_MODE_BELOW_2\r
164 }\r
165\r
166 if (PioMode >= *DisPioMode) {\r
ac0a286f 167 PioMode = (UINT16)(*DisPioMode - 1);\r
12e92a23
RJ
168 }\r
169 }\r
170\r
171 if (PioMode < 2) {\r
172 *SelectedMode = 1; // ATA_PIO_MODE_BELOW_2;\r
173 } else {\r
174 *SelectedMode = PioMode; // ATA_PIO_MODE_2 to ATA_PIO_MODE_4;\r
175 }\r
12e92a23
RJ
176 } else {\r
177 //\r
178 // Identify Data word 64 - 70 are not valid\r
179 // Degrade the PIO mode if the mode has been disqualified\r
180 //\r
181 if (DisPioMode != NULL) {\r
182 if (*DisPioMode < 2) {\r
183 return EFI_UNSUPPORTED; // no mode below ATA_PIO_MODE_BELOW_2\r
184 }\r
185\r
186 if (PioMode == *DisPioMode) {\r
187 PioMode--;\r
188 }\r
189 }\r
190\r
191 if (PioMode < 2) {\r
192 *SelectedMode = 1; // ATA_PIO_MODE_BELOW_2;\r
193 } else {\r
194 *SelectedMode = 2; // ATA_PIO_MODE_2;\r
195 }\r
12e92a23
RJ
196 }\r
197\r
198 return EFI_SUCCESS;\r
199}\r
200\r
201/**\r
202 This function is used to calculate the best UDMA mode supported by specific IDE device\r
203\r
204 @param IdentifyData The identify data of specific IDE device.\r
205 @param DisUDmaMode Disqualified UDMA modes collection.\r
206 @param SelectedMode Available UDMA modes collection.\r
207\r
208 @retval EFI_SUCCESS Best UDMA modes are returned.\r
209 @retval EFI_UNSUPPORTED The device doesn't support UDMA mode,\r
210 or all supported modes have been disqualified.\r
211**/\r
212EFI_STATUS\r
213CalculateBestUdmaMode (\r
214 IN EFI_IDENTIFY_DATA *IdentifyData,\r
215 IN UINT16 *DisUDmaMode OPTIONAL,\r
216 OUT UINT16 *SelectedMode\r
217 )\r
218{\r
ac0a286f
MK
219 UINT16 TempMode;\r
220 UINT16 DeviceUDmaMode;\r
12e92a23
RJ
221\r
222 DeviceUDmaMode = 0;\r
223\r
224 //\r
225 // Check whether the WORD 88 (supported UltraDMA by drive) is valid\r
226 //\r
227 if ((IdentifyData->AtaData.field_validity & 0x04) == 0x00) {\r
228 return EFI_UNSUPPORTED;\r
229 }\r
230\r
231 DeviceUDmaMode = IdentifyData->AtaData.ultra_dma_mode;\r
70d5086c 232 DEBUG ((DEBUG_INFO, "CalculateBestUdmaMode: DeviceUDmaMode = %x\n", DeviceUDmaMode));\r
12e92a23 233 DeviceUDmaMode &= 0x3f;\r
ac0a286f 234 TempMode = 0; // initialize it to UDMA-0\r
12e92a23
RJ
235\r
236 while ((DeviceUDmaMode >>= 1) != 0) {\r
237 TempMode++;\r
238 }\r
239\r
240 //\r
241 // Degrade the UDMA mode if the mode has been disqualified\r
242 //\r
243 if (DisUDmaMode != NULL) {\r
244 if (*DisUDmaMode == 0) {\r
245 *SelectedMode = 0;\r
246 return EFI_UNSUPPORTED; // no mode below ATA_UDMA_MODE_0\r
247 }\r
248\r
249 if (TempMode >= *DisUDmaMode) {\r
ac0a286f 250 TempMode = (UINT16)(*DisUDmaMode - 1);\r
12e92a23
RJ
251 }\r
252 }\r
253\r
254 //\r
255 // Possible returned mode is between ATA_UDMA_MODE_0 and ATA_UDMA_MODE_5\r
256 //\r
257 *SelectedMode = TempMode;\r
258\r
259 return EFI_SUCCESS;\r
260}\r
261\r
262/**\r
263 The Entry Point of module. It follows the standard UEFI driver model.\r
264\r
4040754d 265 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
12e92a23 266 @param[in] SystemTable A pointer to the EFI System Table.\r
4040754d 267\r
12e92a23
RJ
268 @retval EFI_SUCCESS The entry point is executed successfully.\r
269 @retval other Some error occurs when executing this entry point.\r
270\r
271**/\r
272EFI_STATUS\r
273EFIAPI\r
274InitializeSataControllerDriver (\r
ac0a286f
MK
275 IN EFI_HANDLE ImageHandle,\r
276 IN EFI_SYSTEM_TABLE *SystemTable\r
12e92a23
RJ
277 )\r
278{\r
ac0a286f 279 EFI_STATUS Status;\r
12e92a23
RJ
280\r
281 //\r
282 // Install driver model protocol(s).\r
283 //\r
284 Status = EfiLibInstallDriverBindingComponentName2 (\r
285 ImageHandle,\r
286 SystemTable,\r
287 &gSataControllerDriverBinding,\r
288 ImageHandle,\r
289 &gSataControllerComponentName,\r
290 &gSataControllerComponentName2\r
291 );\r
292 ASSERT_EFI_ERROR (Status);\r
293\r
294 return Status;\r
295}\r
296\r
297/**\r
298 Supported function of Driver Binding protocol for this driver.\r
299 Test to see if this driver supports ControllerHandle.\r
300\r
301 @param This Protocol instance pointer.\r
302 @param Controller Handle of device to test.\r
303 @param RemainingDevicePath A pointer to the device path.\r
304 it should be ignored by device driver.\r
305\r
306 @retval EFI_SUCCESS This driver supports this device.\r
307 @retval EFI_ALREADY_STARTED This driver is already running on this device.\r
308 @retval other This driver does not support this device.\r
309\r
310**/\r
311EFI_STATUS\r
312EFIAPI\r
313SataControllerSupported (\r
ac0a286f
MK
314 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
315 IN EFI_HANDLE Controller,\r
316 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
12e92a23
RJ
317 )\r
318{\r
ac0a286f
MK
319 EFI_STATUS Status;\r
320 EFI_PCI_IO_PROTOCOL *PciIo;\r
321 PCI_TYPE00 PciData;\r
12e92a23
RJ
322\r
323 //\r
324 // Attempt to open PCI I/O Protocol\r
325 //\r
326 Status = gBS->OpenProtocol (\r
327 Controller,\r
328 &gEfiPciIoProtocolGuid,\r
ac0a286f 329 (VOID **)&PciIo,\r
12e92a23
RJ
330 This->DriverBindingHandle,\r
331 Controller,\r
332 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
333 );\r
334 if (EFI_ERROR (Status)) {\r
335 return Status;\r
336 }\r
337\r
338 //\r
339 // Now further check the PCI header: Base Class (offset 0x0B) and\r
340 // Sub Class (offset 0x0A). This controller should be an SATA controller\r
341 //\r
342 Status = PciIo->Pci.Read (\r
343 PciIo,\r
344 EfiPciIoWidthUint8,\r
345 PCI_CLASSCODE_OFFSET,\r
346 sizeof (PciData.Hdr.ClassCode),\r
347 PciData.Hdr.ClassCode\r
348 );\r
349 if (EFI_ERROR (Status)) {\r
350 return EFI_UNSUPPORTED;\r
351 }\r
352\r
353 if (IS_PCI_IDE (&PciData) || IS_PCI_SATADPA (&PciData)) {\r
354 return EFI_SUCCESS;\r
355 }\r
356\r
357 return EFI_UNSUPPORTED;\r
358}\r
359\r
360/**\r
4040754d 361 This routine is called right after the .Supported() called and\r
12e92a23
RJ
362 Start this driver on ControllerHandle.\r
363\r
364 @param This Protocol instance pointer.\r
365 @param Controller Handle of device to bind driver to.\r
366 @param RemainingDevicePath A pointer to the device path.\r
367 it should be ignored by device driver.\r
368\r
369 @retval EFI_SUCCESS This driver is added to this device.\r
370 @retval EFI_ALREADY_STARTED This driver is already running on this device.\r
371 @retval other Some error occurs when binding this driver to this device.\r
372\r
373**/\r
374EFI_STATUS\r
375EFIAPI\r
376SataControllerStart (\r
ac0a286f
MK
377 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
378 IN EFI_HANDLE Controller,\r
379 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
12e92a23
RJ
380 )\r
381{\r
5dfba97c 382 UINTN BailLogMask;\r
12e92a23
RJ
383 EFI_STATUS Status;\r
384 EFI_PCI_IO_PROTOCOL *PciIo;\r
bcab7141 385 UINT64 OriginalPciAttributes;\r
12e92a23
RJ
386 PCI_TYPE00 PciData;\r
387 EFI_SATA_CONTROLLER_PRIVATE_DATA *SataPrivateData;\r
388 UINT32 Data32;\r
389 UINTN ChannelDeviceCount;\r
390\r
70d5086c 391 DEBUG ((DEBUG_INFO, "SataControllerStart START\n"));\r
12e92a23 392\r
ac0a286f 393 BailLogMask = DEBUG_ERROR;\r
12e92a23
RJ
394 SataPrivateData = NULL;\r
395\r
396 //\r
397 // Now test and open PCI I/O Protocol\r
398 //\r
399 Status = gBS->OpenProtocol (\r
400 Controller,\r
401 &gEfiPciIoProtocolGuid,\r
ac0a286f 402 (VOID **)&PciIo,\r
12e92a23
RJ
403 This->DriverBindingHandle,\r
404 Controller,\r
405 EFI_OPEN_PROTOCOL_BY_DRIVER\r
406 );\r
407 if (EFI_ERROR (Status)) {\r
5dfba97c
LE
408 if (Status == EFI_ALREADY_STARTED) {\r
409 //\r
410 // This is an expected condition for OpenProtocol() / BY_DRIVER, in a\r
411 // DriverBindingStart() member function; degrade the log mask to\r
412 // DEBUG_INFO.\r
413 //\r
414 BailLogMask = DEBUG_INFO;\r
415 }\r
ac0a286f 416\r
379b1796 417 goto Bail;\r
12e92a23
RJ
418 }\r
419\r
bcab7141
LE
420 //\r
421 // Save original PCI attributes, and enable IO space access, memory space\r
422 // access, and Bus Master (DMA).\r
423 //\r
ac0a286f
MK
424 Status = PciIo->Attributes (\r
425 PciIo,\r
426 EfiPciIoAttributeOperationGet,\r
427 0,\r
428 &OriginalPciAttributes\r
429 );\r
bcab7141
LE
430 if (EFI_ERROR (Status)) {\r
431 goto ClosePciIo;\r
432 }\r
ac0a286f
MK
433\r
434 Status = PciIo->Attributes (\r
435 PciIo,\r
436 EfiPciIoAttributeOperationEnable,\r
437 EFI_PCI_DEVICE_ENABLE,\r
438 NULL\r
439 );\r
bcab7141
LE
440 if (EFI_ERROR (Status)) {\r
441 goto ClosePciIo;\r
442 }\r
443\r
12e92a23
RJ
444 //\r
445 // Allocate Sata Private Data structure\r
446 //\r
447 SataPrivateData = AllocateZeroPool (sizeof (EFI_SATA_CONTROLLER_PRIVATE_DATA));\r
448 if (SataPrivateData == NULL) {\r
449 Status = EFI_OUT_OF_RESOURCES;\r
bcab7141 450 goto RestorePciAttributes;\r
12e92a23
RJ
451 }\r
452\r
453 //\r
454 // Initialize Sata Private Data\r
455 //\r
ac0a286f
MK
456 SataPrivateData->Signature = SATA_CONTROLLER_SIGNATURE;\r
457 SataPrivateData->PciIo = PciIo;\r
458 SataPrivateData->OriginalPciAttributes = OriginalPciAttributes;\r
12e92a23 459 SataPrivateData->IdeInit.GetChannelInfo = IdeInitGetChannelInfo;\r
ac0a286f
MK
460 SataPrivateData->IdeInit.NotifyPhase = IdeInitNotifyPhase;\r
461 SataPrivateData->IdeInit.SubmitData = IdeInitSubmitData;\r
12e92a23 462 SataPrivateData->IdeInit.DisqualifyMode = IdeInitDisqualifyMode;\r
ac0a286f
MK
463 SataPrivateData->IdeInit.CalculateMode = IdeInitCalculateMode;\r
464 SataPrivateData->IdeInit.SetTiming = IdeInitSetTiming;\r
465 SataPrivateData->IdeInit.EnumAll = SATA_ENUMER_ALL;\r
12e92a23
RJ
466\r
467 Status = PciIo->Pci.Read (\r
468 PciIo,\r
469 EfiPciIoWidthUint8,\r
470 PCI_CLASSCODE_OFFSET,\r
471 sizeof (PciData.Hdr.ClassCode),\r
472 PciData.Hdr.ClassCode\r
473 );\r
379b1796
LE
474 if (EFI_ERROR (Status)) {\r
475 goto FreeSataPrivateData;\r
476 }\r
12e92a23
RJ
477\r
478 if (IS_PCI_IDE (&PciData)) {\r
479 SataPrivateData->IdeInit.ChannelCount = IDE_MAX_CHANNEL;\r
ac0a286f 480 SataPrivateData->DeviceCount = IDE_MAX_DEVICES;\r
12e92a23
RJ
481 } else if (IS_PCI_SATADPA (&PciData)) {\r
482 //\r
483 // Read Host Capability Register(CAP) to get Number of Ports(NPS) and Supports Port Multiplier(SPM)\r
484 // NPS is 0's based value indicating the maximum number of ports supported by the HBA silicon.\r
485 // A maximum of 32 ports can be supported. A value of '0h', indicating one port, is the minimum requirement.\r
486 //\r
ac0a286f
MK
487 Data32 = AhciReadReg (PciIo, R_AHCI_CAP);\r
488 SataPrivateData->IdeInit.ChannelCount = (UINT8)((Data32 & B_AHCI_CAP_NPS) + 1);\r
489 SataPrivateData->DeviceCount = AHCI_MAX_DEVICES;\r
12e92a23
RJ
490 if ((Data32 & B_AHCI_CAP_SPM) == B_AHCI_CAP_SPM) {\r
491 SataPrivateData->DeviceCount = AHCI_MULTI_MAX_DEVICES;\r
492 }\r
493 }\r
494\r
ac0a286f 495 ChannelDeviceCount = (UINTN)(SataPrivateData->IdeInit.ChannelCount) * (UINTN)(SataPrivateData->DeviceCount);\r
12e92a23
RJ
496 SataPrivateData->DisqualifiedModes = AllocateZeroPool ((sizeof (EFI_ATA_COLLECTIVE_MODE)) * ChannelDeviceCount);\r
497 if (SataPrivateData->DisqualifiedModes == NULL) {\r
498 Status = EFI_OUT_OF_RESOURCES;\r
379b1796 499 goto FreeSataPrivateData;\r
12e92a23
RJ
500 }\r
501\r
502 SataPrivateData->IdentifyData = AllocateZeroPool ((sizeof (EFI_IDENTIFY_DATA)) * ChannelDeviceCount);\r
503 if (SataPrivateData->IdentifyData == NULL) {\r
504 Status = EFI_OUT_OF_RESOURCES;\r
379b1796 505 goto FreeDisqualifiedModes;\r
12e92a23
RJ
506 }\r
507\r
508 SataPrivateData->IdentifyValid = AllocateZeroPool ((sizeof (BOOLEAN)) * ChannelDeviceCount);\r
509 if (SataPrivateData->IdentifyValid == NULL) {\r
510 Status = EFI_OUT_OF_RESOURCES;\r
379b1796 511 goto FreeIdentifyData;\r
12e92a23
RJ
512 }\r
513\r
514 //\r
515 // Install IDE Controller Init Protocol to this instance\r
516 //\r
517 Status = gBS->InstallMultipleProtocolInterfaces (\r
518 &Controller,\r
519 &gEfiIdeControllerInitProtocolGuid,\r
520 &(SataPrivateData->IdeInit),\r
521 NULL\r
522 );\r
523\r
12e92a23 524 if (EFI_ERROR (Status)) {\r
379b1796 525 goto FreeIdentifyValid;\r
12e92a23
RJ
526 }\r
527\r
70d5086c 528 DEBUG ((DEBUG_INFO, "SataControllerStart END status = %r\n", Status));\r
379b1796
LE
529 return Status;\r
530\r
531FreeIdentifyValid:\r
532 FreePool (SataPrivateData->IdentifyValid);\r
533\r
534FreeIdentifyData:\r
535 FreePool (SataPrivateData->IdentifyData);\r
536\r
537FreeDisqualifiedModes:\r
538 FreePool (SataPrivateData->DisqualifiedModes);\r
539\r
540FreeSataPrivateData:\r
541 FreePool (SataPrivateData);\r
542\r
bcab7141 543RestorePciAttributes:\r
ac0a286f
MK
544 PciIo->Attributes (\r
545 PciIo,\r
546 EfiPciIoAttributeOperationSet,\r
547 OriginalPciAttributes,\r
548 NULL\r
549 );\r
bcab7141 550\r
379b1796
LE
551ClosePciIo:\r
552 gBS->CloseProtocol (\r
553 Controller,\r
554 &gEfiPciIoProtocolGuid,\r
555 This->DriverBindingHandle,\r
556 Controller\r
557 );\r
12e92a23 558\r
379b1796 559Bail:\r
ac0a286f
MK
560 DEBUG ((\r
561 BailLogMask,\r
562 "SataControllerStart error return status = %r\n",\r
563 Status\r
564 ));\r
12e92a23
RJ
565 return Status;\r
566}\r
567\r
568/**\r
569 Stop this driver on ControllerHandle.\r
570\r
571 @param This Protocol instance pointer.\r
572 @param Controller Handle of device to stop driver on.\r
573 @param NumberOfChildren Not used.\r
574 @param ChildHandleBuffer Not used.\r
575\r
576 @retval EFI_SUCCESS This driver is removed from this device.\r
577 @retval other Some error occurs when removing this driver from this device.\r
578\r
579**/\r
580EFI_STATUS\r
581EFIAPI\r
582SataControllerStop (\r
ac0a286f
MK
583 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
584 IN EFI_HANDLE Controller,\r
585 IN UINTN NumberOfChildren,\r
586 IN EFI_HANDLE *ChildHandleBuffer\r
12e92a23
RJ
587 )\r
588{\r
589 EFI_STATUS Status;\r
590 EFI_IDE_CONTROLLER_INIT_PROTOCOL *IdeInit;\r
591 EFI_SATA_CONTROLLER_PRIVATE_DATA *SataPrivateData;\r
0b448dd8
LE
592 EFI_PCI_IO_PROTOCOL *PciIo;\r
593 UINT64 OriginalPciAttributes;\r
12e92a23
RJ
594\r
595 //\r
596 // Open the produced protocol\r
597 //\r
598 Status = gBS->OpenProtocol (\r
599 Controller,\r
600 &gEfiIdeControllerInitProtocolGuid,\r
ac0a286f 601 (VOID **)&IdeInit,\r
12e92a23
RJ
602 This->DriverBindingHandle,\r
603 Controller,\r
604 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
605 );\r
606 if (EFI_ERROR (Status)) {\r
607 return EFI_UNSUPPORTED;\r
608 }\r
609\r
610 SataPrivateData = SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (IdeInit);\r
611 ASSERT (SataPrivateData != NULL);\r
612\r
0b448dd8
LE
613 PciIo = SataPrivateData->PciIo;\r
614 OriginalPciAttributes = SataPrivateData->OriginalPciAttributes;\r
615\r
12e92a23
RJ
616 //\r
617 // Uninstall the IDE Controller Init Protocol from this instance\r
618 //\r
619 Status = gBS->UninstallMultipleProtocolInterfaces (\r
620 Controller,\r
621 &gEfiIdeControllerInitProtocolGuid,\r
622 &(SataPrivateData->IdeInit),\r
623 NULL\r
624 );\r
625 if (EFI_ERROR (Status)) {\r
626 return Status;\r
627 }\r
628\r
81310a62
LE
629 if (SataPrivateData->DisqualifiedModes != NULL) {\r
630 FreePool (SataPrivateData->DisqualifiedModes);\r
12e92a23 631 }\r
ac0a286f 632\r
81310a62
LE
633 if (SataPrivateData->IdentifyData != NULL) {\r
634 FreePool (SataPrivateData->IdentifyData);\r
635 }\r
ac0a286f 636\r
81310a62
LE
637 if (SataPrivateData->IdentifyValid != NULL) {\r
638 FreePool (SataPrivateData->IdentifyValid);\r
639 }\r
ac0a286f 640\r
81310a62 641 FreePool (SataPrivateData);\r
12e92a23 642\r
bcab7141
LE
643 //\r
644 // Restore original PCI attributes\r
645 //\r
0b448dd8
LE
646 PciIo->Attributes (\r
647 PciIo,\r
648 EfiPciIoAttributeOperationSet,\r
649 OriginalPciAttributes,\r
650 NULL\r
651 );\r
bcab7141 652\r
12e92a23
RJ
653 //\r
654 // Close protocols opened by Sata Controller driver\r
655 //\r
656 return gBS->CloseProtocol (\r
657 Controller,\r
658 &gEfiPciIoProtocolGuid,\r
659 This->DriverBindingHandle,\r
660 Controller\r
661 );\r
662}\r
663\r
664/**\r
665 Calculate the flat array subscript of a (Channel, Device) pair.\r
666\r
667 @param[in] SataPrivateData The private data structure corresponding to the\r
668 SATA controller that attaches the device for\r
669 which the flat array subscript is being\r
670 calculated.\r
671\r
672 @param[in] Channel The channel (ie. port) number on the SATA\r
673 controller that the device is attached to.\r
674\r
675 @param[in] Device The device number on the channel.\r
676\r
677 @return The flat array subscript suitable for indexing DisqualifiedModes,\r
678 IdentifyData, and IdentifyValid.\r
679**/\r
680STATIC\r
681UINTN\r
682FlatDeviceIndex (\r
683 IN CONST EFI_SATA_CONTROLLER_PRIVATE_DATA *SataPrivateData,\r
684 IN UINTN Channel,\r
685 IN UINTN Device\r
686 )\r
687{\r
688 ASSERT (SataPrivateData != NULL);\r
689 ASSERT (Channel < SataPrivateData->IdeInit.ChannelCount);\r
690 ASSERT (Device < SataPrivateData->DeviceCount);\r
691\r
692 return Channel * SataPrivateData->DeviceCount + Device;\r
693}\r
694\r
695//\r
696// Interface functions of IDE_CONTROLLER_INIT protocol\r
697//\r
ac0a286f 698\r
12e92a23
RJ
699/**\r
700 Returns the information about the specified IDE channel.\r
4040754d 701\r
12e92a23 702 This function can be used to obtain information about a particular IDE channel.\r
4040754d
LL
703 The driver entity uses this information during the enumeration process.\r
704\r
705 If Enabled is set to FALSE, the driver entity will not scan the channel. Note\r
12e92a23 706 that it will not prevent an operating system driver from scanning the channel.\r
4040754d
LL
707\r
708 For most of today's controllers, MaxDevices will either be 1 or 2. For SATA\r
709 controllers, this value will always be 1. SATA configurations can contain SATA\r
12e92a23 710 port multipliers. SATA port multipliers behave like SATA bridges and can support\r
4040754d
LL
711 up to 16 devices on the other side. If a SATA port out of the IDE controller\r
712 is connected to a port multiplier, MaxDevices will be set to the number of SATA\r
713 devices that the port multiplier supports. Because today's port multipliers\r
714 support up to fifteen SATA devices, this number can be as large as fifteen. The IDE\r
715 bus driver is required to scan for the presence of port multipliers behind an SATA\r
716 controller and enumerate up to MaxDevices number of devices behind the port\r
717 multiplier.\r
718\r
719 In this context, the devices behind a port multiplier constitute a channel.\r
720\r
12e92a23
RJ
721 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
722 @param[in] Channel Zero-based channel number.\r
4040754d 723 @param[out] Enabled TRUE if this channel is enabled. Disabled channels\r
12e92a23
RJ
724 are not scanned to see if any devices are present.\r
725 @param[out] MaxDevices The maximum number of IDE devices that the bus driver\r
4040754d
LL
726 can expect on this channel. For the ATA/ATAPI\r
727 specification, version 6, this number will either be\r
728 one or two. For Serial ATA (SATA) configurations with a\r
12e92a23
RJ
729 port multiplier, this number can be as large as fifteen.\r
730\r
731 @retval EFI_SUCCESS Information was returned without any errors.\r
732 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).\r
733\r
734**/\r
735EFI_STATUS\r
736EFIAPI\r
737IdeInitGetChannelInfo (\r
ac0a286f
MK
738 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
739 IN UINT8 Channel,\r
740 OUT BOOLEAN *Enabled,\r
741 OUT UINT8 *MaxDevices\r
12e92a23
RJ
742 )\r
743{\r
744 EFI_SATA_CONTROLLER_PRIVATE_DATA *SataPrivateData;\r
ac0a286f 745\r
12e92a23
RJ
746 SataPrivateData = SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This);\r
747 ASSERT (SataPrivateData != NULL);\r
748\r
749 if (Channel < This->ChannelCount) {\r
ac0a286f 750 *Enabled = TRUE;\r
12e92a23
RJ
751 *MaxDevices = SataPrivateData->DeviceCount;\r
752 return EFI_SUCCESS;\r
753 }\r
754\r
755 *Enabled = FALSE;\r
756 return EFI_INVALID_PARAMETER;\r
757}\r
758\r
759/**\r
760 The notifications from the driver entity that it is about to enter a certain\r
761 phase of the IDE channel enumeration process.\r
4040754d
LL
762\r
763 This function can be used to notify the IDE controller driver to perform\r
764 specific actions, including any chipset-specific initialization, so that the\r
765 chipset is ready to enter the next phase. Seven notification points are defined\r
766 at this time.\r
767\r
768 More synchronization points may be added as required in the future.\r
12e92a23
RJ
769\r
770 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
771 @param[in] Phase The phase during enumeration.\r
772 @param[in] Channel Zero-based channel number.\r
773\r
774 @retval EFI_SUCCESS The notification was accepted without any errors.\r
775 @retval EFI_UNSUPPORTED Phase is not supported.\r
776 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).\r
4040754d
LL
777 @retval EFI_NOT_READY This phase cannot be entered at this time; for\r
778 example, an attempt was made to enter a Phase\r
779 without having entered one or more previous\r
12e92a23
RJ
780 Phase.\r
781\r
782**/\r
783EFI_STATUS\r
784EFIAPI\r
785IdeInitNotifyPhase (\r
ac0a286f
MK
786 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
787 IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase,\r
788 IN UINT8 Channel\r
12e92a23
RJ
789 )\r
790{\r
791 return EFI_SUCCESS;\r
792}\r
793\r
794/**\r
795 Submits the device information to the IDE controller driver.\r
796\r
4040754d
LL
797 This function is used by the driver entity to pass detailed information about\r
798 a particular device to the IDE controller driver. The driver entity obtains\r
12e92a23 799 this information by issuing an ATA or ATAPI IDENTIFY_DEVICE command. IdentifyData\r
4040754d
LL
800 is the pointer to the response data buffer. The IdentifyData buffer is owned\r
801 by the driver entity, and the IDE controller driver must make a local copy\r
802 of the entire buffer or parts of the buffer as needed. The original IdentifyData\r
12e92a23 803 buffer pointer may not be valid when\r
4040754d 804\r
12e92a23
RJ
805 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() or\r
806 - EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() is called at a later point.\r
4040754d
LL
807\r
808 The IDE controller driver may consult various fields of EFI_IDENTIFY_DATA to\r
809 compute the optimum mode for the device. These fields are not limited to the\r
810 timing information. For example, an implementation of the IDE controller driver\r
811 may examine the vendor and type/mode field to match known bad drives.\r
812\r
813 The driver entity may submit drive information in any order, as long as it\r
814 submits information for all the devices belonging to the enumeration group\r
12e92a23
RJ
815 before EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() is called for any device\r
816 in that enumeration group. If a device is absent, EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()\r
4040754d
LL
817 should be called with IdentifyData set to NULL. The IDE controller driver may\r
818 not have any other mechanism to know whether a device is present or not. Therefore,\r
819 setting IdentifyData to NULL does not constitute an error condition.\r
820 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData() can be called only once for a\r
821 given (Channel, Device) pair.\r
822\r
12e92a23
RJ
823 @param[in] This A pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
824 @param[in] Channel Zero-based channel number.\r
825 @param[in] Device Zero-based device number on the Channel.\r
826 @param[in] IdentifyData The device's response to the ATA IDENTIFY_DEVICE command.\r
827\r
828 @retval EFI_SUCCESS The information was accepted without any errors.\r
829 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).\r
830 @retval EFI_INVALID_PARAMETER Device is invalid.\r
831\r
832**/\r
833EFI_STATUS\r
834EFIAPI\r
835IdeInitSubmitData (\r
ac0a286f
MK
836 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
837 IN UINT8 Channel,\r
838 IN UINT8 Device,\r
839 IN EFI_IDENTIFY_DATA *IdentifyData\r
12e92a23
RJ
840 )\r
841{\r
842 EFI_SATA_CONTROLLER_PRIVATE_DATA *SataPrivateData;\r
843 UINTN DeviceIndex;\r
844\r
845 SataPrivateData = SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This);\r
846 ASSERT (SataPrivateData != NULL);\r
847\r
848 if ((Channel >= This->ChannelCount) || (Device >= SataPrivateData->DeviceCount)) {\r
849 return EFI_INVALID_PARAMETER;\r
850 }\r
851\r
852 DeviceIndex = FlatDeviceIndex (SataPrivateData, Channel, Device);\r
853\r
854 //\r
855 // Make a local copy of device's IdentifyData and mark the valid flag\r
856 //\r
857 if (IdentifyData != NULL) {\r
858 CopyMem (\r
859 &(SataPrivateData->IdentifyData[DeviceIndex]),\r
860 IdentifyData,\r
861 sizeof (EFI_IDENTIFY_DATA)\r
862 );\r
863\r
864 SataPrivateData->IdentifyValid[DeviceIndex] = TRUE;\r
865 } else {\r
866 SataPrivateData->IdentifyValid[DeviceIndex] = FALSE;\r
867 }\r
868\r
869 return EFI_SUCCESS;\r
870}\r
871\r
872/**\r
873 Disqualifies specific modes for an IDE device.\r
874\r
4040754d 875 This function allows the driver entity or other drivers (such as platform\r
12e92a23 876 drivers) to reject certain timing modes and request the IDE controller driver\r
4040754d
LL
877 to recalculate modes. This function allows the driver entity and the IDE\r
878 controller driver to negotiate the timings on a per-device basis. This function\r
879 is useful in the case of drives that lie about their capabilities. An example\r
880 is when the IDE device fails to accept the timing modes that are calculated\r
12e92a23
RJ
881 by the IDE controller driver based on the response to the Identify Drive command.\r
882\r
4040754d
LL
883 If the driver entity does not want to limit the ATA timing modes and leave that\r
884 decision to the IDE controller driver, it can either not call this function for\r
885 the given device or call this function and set the Valid flag to FALSE for all\r
12e92a23 886 modes that are listed in EFI_ATA_COLLECTIVE_MODE.\r
4040754d
LL
887\r
888 The driver entity may disqualify modes for a device in any order and any number\r
12e92a23 889 of times.\r
4040754d
LL
890\r
891 This function can be called multiple times to invalidate multiple modes of the\r
892 same type (e.g., Programmed Input/Output [PIO] modes 3 and 4). See the ATA/ATAPI\r
893 specification for more information on PIO modes.\r
894\r
12e92a23
RJ
895 For Serial ATA (SATA) controllers, this member function can be used to disqualify\r
896 a higher transfer rate mode on a given channel. For example, a platform driver\r
4040754d 897 may inform the IDE controller driver to not use second-generation (Gen2) speeds\r
12e92a23 898 for a certain SATA drive.\r
4040754d 899\r
12e92a23
RJ
900 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
901 @param[in] Channel The zero-based channel number.\r
902 @param[in] Device The zero-based device number on the Channel.\r
903 @param[in] BadModes The modes that the device does not support and that\r
904 should be disqualified.\r
905\r
906 @retval EFI_SUCCESS The modes were accepted without any errors.\r
907 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).\r
908 @retval EFI_INVALID_PARAMETER Device is invalid.\r
909 @retval EFI_INVALID_PARAMETER IdentifyData is NULL.\r
4040754d 910\r
12e92a23
RJ
911**/\r
912EFI_STATUS\r
913EFIAPI\r
914IdeInitDisqualifyMode (\r
ac0a286f
MK
915 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
916 IN UINT8 Channel,\r
917 IN UINT8 Device,\r
918 IN EFI_ATA_COLLECTIVE_MODE *BadModes\r
12e92a23
RJ
919 )\r
920{\r
921 EFI_SATA_CONTROLLER_PRIVATE_DATA *SataPrivateData;\r
922 UINTN DeviceIndex;\r
923\r
924 SataPrivateData = SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This);\r
925 ASSERT (SataPrivateData != NULL);\r
926\r
927 if ((Channel >= This->ChannelCount) || (BadModes == NULL) || (Device >= SataPrivateData->DeviceCount)) {\r
928 return EFI_INVALID_PARAMETER;\r
929 }\r
930\r
931 DeviceIndex = FlatDeviceIndex (SataPrivateData, Channel, Device);\r
932\r
933 //\r
934 // Record the disqualified modes per channel per device. From ATA/ATAPI spec,\r
935 // if a mode is not supported, the modes higher than it is also not supported.\r
936 //\r
937 CopyMem (\r
938 &(SataPrivateData->DisqualifiedModes[DeviceIndex]),\r
939 BadModes,\r
940 sizeof (EFI_ATA_COLLECTIVE_MODE)\r
941 );\r
942\r
943 return EFI_SUCCESS;\r
944}\r
945\r
946/**\r
947 Returns the information about the optimum modes for the specified IDE device.\r
948\r
949 This function is used by the driver entity to obtain the optimum ATA modes for\r
4040754d 950 a specific device. The IDE controller driver takes into account the following\r
12e92a23
RJ
951 while calculating the mode:\r
952 - The IdentifyData inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()\r
953 - The BadModes inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode()\r
954\r
4040754d
LL
955 The driver entity is required to call EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()\r
956 for all the devices that belong to an enumeration group before calling\r
957 EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() for any device in the same group.\r
958\r
959 The IDE controller driver will use controller- and possibly platform-specific\r
960 algorithms to arrive at SupportedModes. The IDE controller may base its\r
961 decision on user preferences and other considerations as well. This function\r
962 may be called multiple times because the driver entity may renegotiate the mode\r
12e92a23 963 with the IDE controller driver using EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode().\r
4040754d
LL
964\r
965 The driver entity may collect timing information for various devices in any\r
12e92a23 966 order. The driver entity is responsible for making sure that all the dependencies\r
4040754d
LL
967 are satisfied. For example, the SupportedModes information for device A that\r
968 was previously returned may become stale after a call to\r
12e92a23 969 EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() for device B.\r
4040754d
LL
970\r
971 The buffer SupportedModes is allocated by the callee because the caller does\r
972 not necessarily know the size of the buffer. The type EFI_ATA_COLLECTIVE_MODE\r
973 is defined in a way that allows for future extensibility and can be of variable\r
974 length. This memory pool should be deallocated by the caller when it is no\r
975 longer necessary.\r
976\r
977 The IDE controller driver for a Serial ATA (SATA) controller can use this\r
978 member function to force a lower speed (first-generation [Gen1] speeds on a\r
979 second-generation [Gen2]-capable hardware). The IDE controller driver can\r
980 also allow the driver entity to stay with the speed that has been negotiated\r
12e92a23 981 by the physical layer.\r
4040754d 982\r
12e92a23
RJ
983 @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
984 @param[in] Channel A zero-based channel number.\r
985 @param[in] Device A zero-based device number on the Channel.\r
986 @param[out] SupportedModes The optimum modes for the device.\r
987\r
988 @retval EFI_SUCCESS SupportedModes was returned.\r
989 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).\r
4040754d 990 @retval EFI_INVALID_PARAMETER Device is invalid.\r
12e92a23 991 @retval EFI_INVALID_PARAMETER SupportedModes is NULL.\r
4040754d
LL
992 @retval EFI_NOT_READY Modes cannot be calculated due to a lack of\r
993 data. This error may happen if\r
994 EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()\r
995 and EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyData()\r
996 were not called for at least one drive in the\r
12e92a23
RJ
997 same enumeration group.\r
998\r
999**/\r
1000EFI_STATUS\r
1001EFIAPI\r
1002IdeInitCalculateMode (\r
ac0a286f
MK
1003 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
1004 IN UINT8 Channel,\r
1005 IN UINT8 Device,\r
1006 OUT EFI_ATA_COLLECTIVE_MODE **SupportedModes\r
12e92a23
RJ
1007 )\r
1008{\r
1009 EFI_SATA_CONTROLLER_PRIVATE_DATA *SataPrivateData;\r
1010 EFI_IDENTIFY_DATA *IdentifyData;\r
1011 BOOLEAN IdentifyValid;\r
1012 EFI_ATA_COLLECTIVE_MODE *DisqualifiedModes;\r
1013 UINT16 SelectedMode;\r
1014 EFI_STATUS Status;\r
1015 UINTN DeviceIndex;\r
1016\r
1017 SataPrivateData = SATA_CONTROLLER_PRIVATE_DATA_FROM_THIS (This);\r
1018 ASSERT (SataPrivateData != NULL);\r
1019\r
1020 if ((Channel >= This->ChannelCount) || (SupportedModes == NULL) || (Device >= SataPrivateData->DeviceCount)) {\r
1021 return EFI_INVALID_PARAMETER;\r
1022 }\r
1023\r
1024 *SupportedModes = AllocateZeroPool (sizeof (EFI_ATA_COLLECTIVE_MODE));\r
1025 if (*SupportedModes == NULL) {\r
1026 ASSERT (*SupportedModes != NULL);\r
1027 return EFI_OUT_OF_RESOURCES;\r
1028 }\r
1029\r
1030 DeviceIndex = FlatDeviceIndex (SataPrivateData, Channel, Device);\r
1031\r
ac0a286f
MK
1032 IdentifyData = &(SataPrivateData->IdentifyData[DeviceIndex]);\r
1033 IdentifyValid = SataPrivateData->IdentifyValid[DeviceIndex];\r
12e92a23
RJ
1034 DisqualifiedModes = &(SataPrivateData->DisqualifiedModes[DeviceIndex]);\r
1035\r
1036 //\r
1037 // Make sure we've got the valid identify data of the device from SubmitData()\r
1038 //\r
1039 if (!IdentifyValid) {\r
1040 FreePool (*SupportedModes);\r
1041 return EFI_NOT_READY;\r
1042 }\r
1043\r
1044 Status = CalculateBestPioMode (\r
ac0a286f
MK
1045 IdentifyData,\r
1046 (DisqualifiedModes->PioMode.Valid ? ((UINT16 *)&(DisqualifiedModes->PioMode.Mode)) : NULL),\r
1047 &SelectedMode\r
1048 );\r
12e92a23
RJ
1049 if (!EFI_ERROR (Status)) {\r
1050 (*SupportedModes)->PioMode.Valid = TRUE;\r
ac0a286f 1051 (*SupportedModes)->PioMode.Mode = SelectedMode;\r
12e92a23
RJ
1052 } else {\r
1053 (*SupportedModes)->PioMode.Valid = FALSE;\r
1054 }\r
ac0a286f 1055\r
70d5086c 1056 DEBUG ((DEBUG_INFO, "IdeInitCalculateMode: PioMode = %x\n", (*SupportedModes)->PioMode.Mode));\r
12e92a23
RJ
1057\r
1058 Status = CalculateBestUdmaMode (\r
ac0a286f
MK
1059 IdentifyData,\r
1060 (DisqualifiedModes->UdmaMode.Valid ? ((UINT16 *)&(DisqualifiedModes->UdmaMode.Mode)) : NULL),\r
1061 &SelectedMode\r
1062 );\r
12e92a23
RJ
1063\r
1064 if (!EFI_ERROR (Status)) {\r
1065 (*SupportedModes)->UdmaMode.Valid = TRUE;\r
1066 (*SupportedModes)->UdmaMode.Mode = SelectedMode;\r
12e92a23
RJ
1067 } else {\r
1068 (*SupportedModes)->UdmaMode.Valid = FALSE;\r
1069 }\r
ac0a286f 1070\r
70d5086c 1071 DEBUG ((DEBUG_INFO, "IdeInitCalculateMode: UdmaMode = %x\n", (*SupportedModes)->UdmaMode.Mode));\r
12e92a23
RJ
1072\r
1073 //\r
1074 // The modes other than PIO and UDMA are not supported\r
1075 //\r
1076 return EFI_SUCCESS;\r
1077}\r
1078\r
1079/**\r
1080 Commands the IDE controller driver to program the IDE controller hardware\r
1081 so that the specified device can operate at the specified mode.\r
1082\r
4040754d
LL
1083 This function is used by the driver entity to instruct the IDE controller\r
1084 driver to program the IDE controller hardware to the specified modes. This\r
1085 function can be called only once for a particular device. For a Serial ATA\r
12e92a23
RJ
1086 (SATA) Advanced Host Controller Interface (AHCI) controller, no controller-\r
1087 specific programming may be required.\r
1088\r
1089 @param[in] This Pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
1090 @param[in] Channel Zero-based channel number.\r
1091 @param[in] Device Zero-based device number on the Channel.\r
1092 @param[in] Modes The modes to set.\r
1093\r
1094 @retval EFI_SUCCESS The command was accepted without any errors.\r
1095 @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).\r
1096 @retval EFI_INVALID_PARAMETER Device is invalid.\r
1097 @retval EFI_NOT_READY Modes cannot be set at this time due to lack of data.\r
1098 @retval EFI_DEVICE_ERROR Modes cannot be set due to hardware failure.\r
1099 The driver entity should not use this device.\r
1100\r
1101**/\r
1102EFI_STATUS\r
1103EFIAPI\r
1104IdeInitSetTiming (\r
ac0a286f
MK
1105 IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
1106 IN UINT8 Channel,\r
1107 IN UINT8 Device,\r
1108 IN EFI_ATA_COLLECTIVE_MODE *Modes\r
12e92a23
RJ
1109 )\r
1110{\r
1111 return EFI_SUCCESS;\r
1112}\r