fix a typo in a comment
[mirror_edk2.git] / EdkModulePkg / Bus / Pci / IdeBus / Dxe / idebus.c
CommitLineData
ed72955c 1/** @file\r
2 Copyright (c) 2006, Intel Corporation \r
3 All rights reserved. This program and the accompanying materials \r
4 are licensed and made available under the terms and conditions of the BSD License \r
5 which accompanies this distribution. The full text of the license may be found at \r
6 http://opensource.org/licenses/bsd-license.php \r
878ddf1f 7\r
ed72955c 8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
878ddf1f 10\r
ed72955c 11 @par Revision Reference:\r
878ddf1f 12 This module is modified from DXE\IDE module for Ide Contriller Init support\r
13\r
ed72955c 14**/\r
878ddf1f 15\r
16#include "idebus.h"\r
17\r
18#define PCI_CLASS_MASS_STORAGE 0x01\r
19#define PCI_SUB_CLASS_IDE 0x01\r
20\r
21\r
22//\r
23// IDE Bus Driver Binding Protocol Instance\r
24//\r
25EFI_DRIVER_BINDING_PROTOCOL gIDEBusDriverBinding = {\r
26 IDEBusDriverBindingSupported,\r
27 IDEBusDriverBindingStart,\r
28 IDEBusDriverBindingStop,\r
61fb1657 29 0xa,\r
878ddf1f 30 NULL,\r
31 NULL\r
32};\r
33\r
34//\r
35// ***********************************************************************************\r
36// IDEBusDriverBindingSupported\r
37// ***********************************************************************************\r
38//\r
ed72955c 39/**\r
40 Register Driver Binding protocol for this driver.\r
41\r
42 @param[in] This -- A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
43 @param[in] ControllerHandle -- The handle of the controller to test.\r
44 @param[in] RemainingDevicePath -- A pointer to the remaining portion of a device path.\r
45\r
46 @retval EFI_SUCCESS Driver loaded.\r
47 @retval other Driver not loaded.\r
48\r
49**/\r
878ddf1f 50EFI_STATUS\r
51EFIAPI\r
52IDEBusDriverBindingSupported (\r
53 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
54 IN EFI_HANDLE Controller,\r
55 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
56 )\r
878ddf1f 57// TODO: Controller - add argument and description to function comment\r
58// TODO: EFI_UNSUPPORTED - add return value to function comment\r
59{\r
60 EFI_STATUS Status;\r
61 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
62 EFI_DEV_PATH *Node;\r
63 EFI_IDE_CONTROLLER_INIT_PROTOCOL *IdeInit;\r
64\r
65 if (RemainingDevicePath != NULL) {\r
66 Node = (EFI_DEV_PATH *) RemainingDevicePath;\r
67 if (Node->DevPath.Type != MESSAGING_DEVICE_PATH ||\r
68 Node->DevPath.SubType != MSG_ATAPI_DP ||\r
69 DevicePathNodeLength(&Node->DevPath) != sizeof(ATAPI_DEVICE_PATH)) {\r
70 return EFI_UNSUPPORTED;\r
71 }\r
72 }\r
73\r
74 //\r
75 // Open the IO Abstraction(s) needed to perform the supported test\r
76 //\r
77 Status = gBS->OpenProtocol (\r
78 Controller,\r
79 &gEfiDevicePathProtocolGuid,\r
80 (VOID **) &ParentDevicePath,\r
81 This->DriverBindingHandle,\r
82 Controller,\r
83 EFI_OPEN_PROTOCOL_BY_DRIVER\r
84 );\r
85 if (Status == EFI_ALREADY_STARTED) {\r
86 return EFI_SUCCESS;\r
87 }\r
88\r
89 if (EFI_ERROR (Status)) {\r
90 return Status;\r
91 }\r
92 \r
93 //\r
0b293ccb 94 // Close protocol, don't use device path protocol in the .Support() function\r
878ddf1f 95 //\r
96 gBS->CloseProtocol (\r
97 Controller,\r
98 &gEfiDevicePathProtocolGuid,\r
99 This->DriverBindingHandle,\r
100 Controller\r
101 );\r
102\r
103 //\r
104 // Verify the Ide Controller Init Protocol, which installed by the\r
105 // IdeController module.\r
106 // Note 1: PciIo protocol has been opened BY_DRIVER by ide_init, so We can't\r
107 // open BY_DRIVER here) That's why we don't check pciio protocol\r
108 // Note 2: ide_init driver check ide controller's pci config space, so we dont\r
109 // check here any more to save code size\r
110 //\r
111 Status = gBS->OpenProtocol (\r
112 Controller,\r
113 &gEfiIdeControllerInitProtocolGuid,\r
114 (VOID **) &IdeInit,\r
115 This->DriverBindingHandle,\r
116 Controller,\r
117 EFI_OPEN_PROTOCOL_BY_DRIVER\r
118 );\r
119\r
120 if (Status == EFI_ALREADY_STARTED) {\r
121 return EFI_SUCCESS;\r
122 }\r
123\r
124 //\r
125 // If protocols were opened normally, closed it\r
126 //\r
127 gBS->CloseProtocol (\r
128 Controller,\r
129 &gEfiIdeControllerInitProtocolGuid,\r
130 This->DriverBindingHandle,\r
131 Controller\r
132 );\r
133\r
134 return Status;\r
135}\r
136\r
137//\r
138// ***********************************************************************************\r
139// IDEBusDriverBindingStart\r
140// ***********************************************************************************\r
141//\r
ed72955c 142/**\r
143 Start this driver on Controller by detecting all disks and installing \r
144 BlockIo protocol on them.\r
145\r
146 @param This Protocol instance pointer.\r
147 @param Controller Handle of device to bind driver to.\r
148 @param RemainingDevicePath Not used, always produce all possible children.\r
149\r
150 @retval EFI_SUCCESS This driver is added to ControllerHandle.\r
151 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle.\r
152 @retval other This driver does not support this device.\r
153\r
154**/\r
878ddf1f 155EFI_STATUS\r
156EFIAPI\r
157IDEBusDriverBindingStart (\r
158 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
159 IN EFI_HANDLE Controller,\r
160 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
161 )\r
878ddf1f 162{\r
163 EFI_STATUS Status;\r
164 EFI_STATUS SavedStatus;\r
165 EFI_PCI_IO_PROTOCOL *PciIo;\r
166 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
167 EFI_DEV_PATH *Node;\r
168 UINT8 IdeChannel;\r
169 UINT8 BeginningIdeChannel;\r
170 UINT8 EndIdeChannel;\r
171 UINT8 IdeDevice;\r
172 UINT8 BeginningIdeDevice;\r
173 UINT8 EndIdeDevice;\r
174 IDE_BLK_IO_DEV *IdeBlkIoDevice[IdeMaxChannel][IdeMaxDevice];\r
175 IDE_BLK_IO_DEV *IdeBlkIoDevicePtr;\r
176 IDE_REGISTERS_BASE_ADDR IdeRegsBaseAddr[IdeMaxChannel];\r
177 ATA_TRANSFER_MODE TransferMode;\r
178 ATA_DRIVE_PARMS DriveParameters;\r
179 EFI_DEV_PATH NewNode;\r
180 UINT8 ConfigurationOptions;\r
181 UINT16 CommandBlockBaseAddr;\r
182 UINT16 ControlBlockBaseAddr;\r
183 UINTN DataSize;\r
878ddf1f 184 IDE_BUS_DRIVER_PRIVATE_DATA *IdeBusDriverPrivateData;\r
185\r
186 //\r
187 // Local variables declaration for IdeControllerInit support\r
188 //\r
189 EFI_IDE_CONTROLLER_INIT_PROTOCOL *IdeInit;\r
190 BOOLEAN EnumAll;\r
191 BOOLEAN ChannelEnabled;\r
878ddf1f 192 UINT8 MaxDevices;\r
193 EFI_IDENTIFY_DATA IdentifyData;\r
194 EFI_ATA_COLLECTIVE_MODE *SupportedModes;\r
195\r
196 IdeBusDriverPrivateData = NULL;\r
197 SupportedModes = NULL;\r
198\r
199 //\r
200 // Perform IdeBus initialization\r
201 //\r
202 Status = gBS->OpenProtocol (\r
203 Controller,\r
204 &gEfiDevicePathProtocolGuid,\r
205 (VOID **) &ParentDevicePath,\r
206 This->DriverBindingHandle,\r
207 Controller,\r
208 EFI_OPEN_PROTOCOL_BY_DRIVER\r
209 );\r
210 if ((EFI_ERROR (Status)) && (Status != EFI_ALREADY_STARTED)) {\r
211 return Status;\r
212 }\r
213 \r
214 //\r
215 // Now open the IDE_CONTROLLER_INIT protocol. Step7.1\r
216 //\r
217 Status = gBS->OpenProtocol (\r
218 Controller,\r
219 &gEfiIdeControllerInitProtocolGuid,\r
220 (VOID **) &IdeInit,\r
221 This->DriverBindingHandle,\r
222 Controller,\r
223 EFI_OPEN_PROTOCOL_BY_DRIVER\r
224 );\r
225\r
226 //\r
227 // The following OpenProtocol function with _GET_PROTOCOL attribute and\r
228 // will not return EFI_ALREADY_STARTED, so save it for now\r
229 //\r
230 SavedStatus = Status;\r
231\r
232 if ((EFI_ERROR (Status)) && (Status != EFI_ALREADY_STARTED)) {\r
233 DEBUG ((EFI_D_ERROR, "Open Init, Status=%x", Status));\r
234 //\r
235 // open protocol is not SUCCESS or not ALREADY_STARTED, error exit\r
236 //\r
237 goto ErrorExit;\r
238 }\r
239\r
240 //\r
1cc8ee78 241 // Save Enumall. Step7.2\r
878ddf1f 242 //\r
243 EnumAll = IdeInit->EnumAll;\r
878ddf1f 244\r
245 //\r
246 // Consume PCI I/O protocol. Note that the OpenProtocol with _GET_PROTOCOL\r
247 // attribute will not return EFI_ALREADY_STARTED\r
248 //\r
249 Status = gBS->OpenProtocol (\r
250 Controller,\r
251 &gEfiPciIoProtocolGuid,\r
252 (VOID **) &PciIo,\r
253 This->DriverBindingHandle,\r
254 Controller,\r
255 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
256 );\r
257 if (EFI_ERROR (Status)) {\r
258 DEBUG ((EFI_D_ERROR, "Open PciIo, Status=%x", Status));\r
259 goto ErrorExit;\r
260 }\r
261\r
262 //\r
263 // We must check EFI_ALREADY_STARTED because many ATAPI devices are removable\r
264 //\r
265 if (SavedStatus != EFI_ALREADY_STARTED) {\r
266 IdeBusDriverPrivateData = AllocatePool (sizeof (IDE_BUS_DRIVER_PRIVATE_DATA));\r
267 if (IdeBusDriverPrivateData == NULL) {\r
268 Status = EFI_OUT_OF_RESOURCES;\r
269 goto ErrorExit;\r
270 }\r
271\r
272 ZeroMem (IdeBusDriverPrivateData, sizeof (IDE_BUS_DRIVER_PRIVATE_DATA));\r
273 Status = gBS->InstallMultipleProtocolInterfaces (\r
274 &Controller,\r
275 &gEfiCallerIdGuid,\r
276 IdeBusDriverPrivateData,\r
277 NULL\r
278 );\r
279 if (EFI_ERROR (Status)) {\r
280 goto ErrorExit;\r
281 }\r
282\r
283 } else {\r
284 Status = gBS->OpenProtocol (\r
285 Controller,\r
286 &gEfiCallerIdGuid,\r
287 (VOID **) &IdeBusDriverPrivateData,\r
288 This->DriverBindingHandle,\r
289 Controller,\r
290 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
291 );\r
292 if (EFI_ERROR (Status)) {\r
293 IdeBusDriverPrivateData = NULL;\r
294 goto ErrorExit;\r
295 }\r
296 }\r
297\r
298 Status = PciIo->Attributes (\r
299 PciIo,\r
300 EfiPciIoAttributeOperationEnable,\r
301 EFI_PCI_DEVICE_ENABLE,\r
302 NULL\r
303 );\r
304 if (EFI_ERROR (Status)) {\r
305 goto ErrorExit;\r
306 }\r
307\r
308 //\r
309 // Read the environment variable that contains the IDEBus Driver's\r
310 // Config options that were set by the Driver Configuration Protocol\r
311 //\r
312 DataSize = sizeof (ConfigurationOptions);\r
313 Status = gRT->GetVariable (\r
314 (CHAR16 *) L"Configuration",\r
315 &gEfiCallerIdGuid,\r
6874dbd0 316 NULL,\r
878ddf1f 317 &DataSize,\r
318 &ConfigurationOptions\r
319 );\r
320 if (EFI_ERROR (Status)) {\r
321 ConfigurationOptions = 0x0f;\r
322 }\r
323\r
324 if (EnumAll) {\r
325 //\r
326 // If IdeInit->EnumAll is TRUE, must enumerate all IDE device anyway\r
327 //\r
328 BeginningIdeChannel = IdePrimary;\r
329 EndIdeChannel = IdeSecondary;\r
330 BeginningIdeDevice = IdeMaster;\r
331 EndIdeDevice = IdeSlave;\r
332 } else if (RemainingDevicePath == NULL) {\r
333 //\r
334 // RemainingDevicePath is NULL, scan IDE bus for each device;\r
335 //\r
336 BeginningIdeChannel = IdePrimary;\r
337 EndIdeChannel = IdeSecondary;\r
338 BeginningIdeDevice = IdeMaster;\r
339 //\r
340 // default, may be redefined by IdeInit\r
341 //\r
342 EndIdeDevice = IdeSlave;\r
343 } else {\r
344 //\r
345 // RemainingDevicePath is not NULL, only scan the specified device.\r
346 //\r
347 Node = (EFI_DEV_PATH *) RemainingDevicePath;\r
348 BeginningIdeChannel = Node->Atapi.PrimarySecondary;\r
349 EndIdeChannel = BeginningIdeChannel;\r
350 BeginningIdeDevice = Node->Atapi.SlaveMaster;\r
351 EndIdeDevice = BeginningIdeDevice;\r
352 }\r
353\r
354 //\r
355 // Obtain IDE IO port registers' base addresses\r
356 //\r
357 Status = GetIdeRegistersBaseAddr (PciIo, IdeRegsBaseAddr);\r
358 if (EFI_ERROR (Status)) {\r
359 goto ErrorExit;\r
360 }\r
361\r
362 //\r
363 // Report status code: begin IdeBus initialization\r
364 //\r
365 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
366 EFI_PROGRESS_CODE,\r
367 (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_PC_RESET),\r
368 ParentDevicePath\r
369 );\r
370\r
371 //\r
372 // Strictly follow the enumeration based on IDE_CONTROLLER_INIT protocol\r
373 //\r
374 for (IdeChannel = BeginningIdeChannel; IdeChannel <= EndIdeChannel; IdeChannel++) {\r
375\r
376 IdeInit->NotifyPhase (IdeInit, EfiIdeBeforeChannelEnumeration, IdeChannel);\r
377\r
378 //\r
379 // now obtain channel information fron IdeControllerInit protocol. Step9\r
380 //\r
381 Status = IdeInit->GetChannelInfo (\r
382 IdeInit,\r
383 IdeChannel,\r
384 &ChannelEnabled,\r
385 &MaxDevices\r
386 );\r
387 if (EFI_ERROR (Status)) {\r
388 DEBUG ((EFI_D_ERROR, "[GetChannel, Status=%x]", Status));\r
389 continue;\r
390 }\r
391\r
392 if (!ChannelEnabled) {\r
393 continue;\r
394 }\r
395\r
396 EndIdeDevice = (UINT8) EFI_MIN ((MaxDevices - 1), EndIdeDevice);\r
397\r
398 //\r
399 // Now inform the IDE Controller Init Module. Sept10\r
400 //\r
401 IdeInit->NotifyPhase (IdeInit, EfiIdeBeforeChannelReset, IdeChannel);\r
402\r
403 //\r
404 // No reset channel function implemented. Sept11\r
405 //\r
406 IdeInit->NotifyPhase (IdeInit, EfiIdeAfterChannelReset, IdeChannel);\r
407\r
408 //\r
409 // Step13\r
410 //\r
411 IdeInit->NotifyPhase (\r
412 IdeInit,\r
413 EfiIdeBusBeforeDevicePresenceDetection,\r
414 IdeChannel\r
415 );\r
a98f11c5 416\r
417 //\r
418 // Prepare to detect IDE device of this channel\r
419 //\r
420 InitializeIDEChannelData ();\r
421\r
878ddf1f 422 //\r
423 // -- 1st inner loop --- Master/Slave ------------ Step14\r
424 //\r
425 for (IdeDevice = BeginningIdeDevice; IdeDevice <= EndIdeDevice; IdeDevice++) {\r
426 //\r
427 // Check whether the configuration options allow this device\r
428 //\r
429 if (!(ConfigurationOptions & (1 << (IdeChannel * 2 + IdeDevice)))) {\r
430 continue;\r
431 }\r
432 \r
433 //\r
434 // The device has been scanned in another Start(), No need to scan it again\r
435 // for perf optimization.\r
436 //\r
437 if (IdeBusDriverPrivateData->HaveScannedDevice[IdeChannel * 2 + IdeDevice]) {\r
438 continue;\r
439 }\r
440 \r
441 //\r
442 // create child handle for the detected device.\r
443 //\r
444 IdeBlkIoDevice[IdeChannel][IdeDevice] = AllocatePool (sizeof (IDE_BLK_IO_DEV));\r
445 if (IdeBlkIoDevice[IdeChannel][IdeDevice] == NULL) {\r
446 continue;\r
447 }\r
448\r
449 IdeBlkIoDevicePtr = IdeBlkIoDevice[IdeChannel][IdeDevice];\r
450\r
451 ZeroMem (IdeBlkIoDevicePtr, sizeof (IDE_BLK_IO_DEV));\r
452\r
453 IdeBlkIoDevicePtr->Signature = IDE_BLK_IO_DEV_SIGNATURE;\r
1cc8ee78 454 IdeBlkIoDevicePtr->Channel = (EFI_IDE_CHANNEL) IdeChannel;\r
455 IdeBlkIoDevicePtr->Device = (EFI_IDE_DEVICE) IdeDevice;\r
878ddf1f 456\r
457 //\r
458 // initialize Block IO interface's Media pointer\r
459 //\r
460 IdeBlkIoDevicePtr->BlkIo.Media = &IdeBlkIoDevicePtr->BlkMedia;\r
461\r
462 //\r
463 // Initialize IDE IO port addresses, including Command Block registers\r
464 // and Control Block registers\r
465 //\r
466 IdeBlkIoDevicePtr->IoPort = AllocatePool (sizeof (IDE_BASE_REGISTERS));\r
467 if (IdeBlkIoDevicePtr->IoPort == NULL) {\r
468 continue;\r
469 }\r
470\r
471 ZeroMem (IdeBlkIoDevicePtr->IoPort, sizeof (IDE_BASE_REGISTERS));\r
472 CommandBlockBaseAddr = IdeRegsBaseAddr[IdeChannel].CommandBlockBaseAddr;\r
473 ControlBlockBaseAddr = IdeRegsBaseAddr[IdeChannel].ControlBlockBaseAddr;\r
474\r
475 IdeBlkIoDevicePtr->IoPort->Data = CommandBlockBaseAddr;\r
476 (*(UINT16 *) &IdeBlkIoDevicePtr->IoPort->Reg1) = (UINT16) (CommandBlockBaseAddr + 0x01);\r
477 IdeBlkIoDevicePtr->IoPort->SectorCount = (UINT16) (CommandBlockBaseAddr + 0x02);\r
478 IdeBlkIoDevicePtr->IoPort->SectorNumber = (UINT16) (CommandBlockBaseAddr + 0x03);\r
479 IdeBlkIoDevicePtr->IoPort->CylinderLsb = (UINT16) (CommandBlockBaseAddr + 0x04);\r
480 IdeBlkIoDevicePtr->IoPort->CylinderMsb = (UINT16) (CommandBlockBaseAddr + 0x05);\r
481 IdeBlkIoDevicePtr->IoPort->Head = (UINT16) (CommandBlockBaseAddr + 0x06);\r
482 (*(UINT16 *) &IdeBlkIoDevicePtr->IoPort->Reg) = (UINT16) (CommandBlockBaseAddr + 0x07);\r
483\r
484 (*(UINT16 *) &IdeBlkIoDevicePtr->IoPort->Alt) = ControlBlockBaseAddr;\r
485 IdeBlkIoDevicePtr->IoPort->DriveAddress = (UINT16) (ControlBlockBaseAddr + 0x01);\r
486\r
487 IdeBlkIoDevicePtr->IoPort->MasterSlave = (UINT16) ((IdeDevice == IdeMaster) ? 1 : 0);\r
488\r
489 IdeBlkIoDevicePtr->PciIo = PciIo;\r
490 IdeBlkIoDevicePtr->IdeBusDriverPrivateData = IdeBusDriverPrivateData;\r
491 IdeBlkIoDevicePtr->IoPort->BusMasterBaseAddr = IdeRegsBaseAddr[IdeChannel].BusMasterBaseAddr;\r
492\r
a98f11c5 493 //\r
494 // Report Status code: is about to detect IDE drive\r
495 //\r
715a44f1 496 REPORT_STATUS_CODE_EX (\r
a98f11c5 497 EFI_PROGRESS_CODE,\r
498 (EFI_IO_BUS_ATA_ATAPI | EFI_P_PC_PRESENCE_DETECT),\r
715a44f1 499 0,\r
500 &gEfiCallerIdGuid,\r
501 NULL,\r
502 NULL,\r
503 0\r
504 );\r
a98f11c5 505\r
878ddf1f 506 //\r
507 // Discover device, now!\r
508 //\r
509 PERF_START (0, "DiscoverIdeDevice", "IDE", 0);\r
510 Status = DiscoverIdeDevice (IdeBlkIoDevicePtr);\r
511 PERF_END (0, "DiscoverIdeDevice", "IDE", 0);\r
512\r
513 IdeBusDriverPrivateData->HaveScannedDevice[IdeChannel * 2 + IdeDevice] = TRUE;\r
514 IdeBusDriverPrivateData->DeviceProcessed[IdeChannel * 2 + IdeDevice] = FALSE;\r
515\r
516 if (!EFI_ERROR (Status)) {\r
517 //\r
518 // Set Device Path\r
519 //\r
520 ZeroMem (&NewNode, sizeof (NewNode));\r
521 NewNode.DevPath.Type = MESSAGING_DEVICE_PATH;\r
522 NewNode.DevPath.SubType = MSG_ATAPI_DP;\r
523 SetDevicePathNodeLength (&NewNode.DevPath, sizeof (ATAPI_DEVICE_PATH));\r
524\r
525 NewNode.Atapi.PrimarySecondary = (UINT8) IdeBlkIoDevicePtr->Channel;\r
526 NewNode.Atapi.SlaveMaster = (UINT8) IdeBlkIoDevicePtr->Device;\r
527 NewNode.Atapi.Lun = IdeBlkIoDevicePtr->Lun;\r
528 IdeBlkIoDevicePtr->DevicePath = AppendDevicePathNode (\r
529 ParentDevicePath,\r
530 &NewNode.DevPath\r
531 );\r
532 if (IdeBlkIoDevicePtr->DevicePath == NULL) {\r
533 ReleaseIdeResources (IdeBlkIoDevicePtr);\r
534 continue;\r
535 }\r
536\r
537 //\r
538 // Submit identify data to IDE controller init driver\r
539 //\r
540 CopyMem (&IdentifyData, IdeBlkIoDevicePtr->pIdData, sizeof (IdentifyData));\r
878ddf1f 541 IdeBusDriverPrivateData->DeviceFound[IdeChannel * 2 + IdeDevice] = TRUE;\r
542 IdeInit->SubmitData (IdeInit, IdeChannel, IdeDevice, &IdentifyData);\r
543 } else {\r
544 //\r
545 // Device detection failed\r
546 //\r
547 IdeBusDriverPrivateData->DeviceFound[IdeChannel * 2 + IdeDevice] = FALSE;\r
548 IdeInit->SubmitData (IdeInit, IdeChannel, IdeDevice, NULL);\r
549 ReleaseIdeResources (IdeBlkIoDevicePtr);\r
550 IdeBlkIoDevicePtr = NULL;\r
551 }\r
552 //\r
553 // end of 1st inner loop ---\r
554 //\r
555 }\r
556 //\r
557 // end of 1st outer loop =========\r
558 //\r
559 }\r
560\r
561 //\r
562 // = 2nd outer loop == Primary/Secondary =================\r
563 //\r
564 for (IdeChannel = BeginningIdeChannel; IdeChannel <= EndIdeChannel; IdeChannel++) {\r
565\r
566 //\r
567 // -- 2nd inner loop --- Master/Slave --------\r
568 //\r
569 for (IdeDevice = BeginningIdeDevice; IdeDevice <= EndIdeDevice; IdeDevice++) {\r
570\r
571 if (IdeBusDriverPrivateData->DeviceProcessed[IdeChannel * 2 + IdeDevice]) {\r
572 continue;\r
573 }\r
574\r
575 if (!IdeBusDriverPrivateData->DeviceFound[IdeChannel * 2 + IdeDevice]) {\r
576 continue;\r
577 }\r
578\r
579 Status = IdeInit->CalculateMode (\r
580 IdeInit,\r
581 IdeChannel,\r
582 IdeDevice,\r
583 &SupportedModes\r
584 );\r
585 if (EFI_ERROR (Status)) {\r
586 DEBUG ((EFI_D_ERROR, "[bStStp20S=%x]", Status));\r
587 continue;\r
588 }\r
589\r
590 IdeBlkIoDevicePtr = IdeBlkIoDevice[IdeChannel][IdeDevice];\r
591\r
592 //\r
593 // Set best supported PIO mode on this IDE device\r
594 //\r
595 if (SupportedModes->PioMode.Mode <= ATA_PIO_MODE_2) {\r
596 TransferMode.ModeCategory = ATA_MODE_CATEGORY_DEFAULT_PIO;\r
597 } else {\r
598 TransferMode.ModeCategory = ATA_MODE_CATEGORY_FLOW_PIO;\r
599 }\r
600\r
601 TransferMode.ModeNumber = (UINT8) (SupportedModes->PioMode.Mode);\r
602\r
603 if (SupportedModes->ExtModeCount == 0){\r
604 Status = SetDeviceTransferMode (IdeBlkIoDevicePtr, &TransferMode);\r
605\r
606 if (EFI_ERROR (Status)) {\r
607 IdeBusDriverPrivateData->DeviceFound[IdeChannel * 2 + IdeDevice] = FALSE;\r
608 ReleaseIdeResources (IdeBlkIoDevicePtr);\r
609 IdeBlkIoDevicePtr = NULL;\r
610 continue;\r
611 }\r
612 }\r
613\r
614 //\r
615 // Set supported DMA mode on this IDE device. Note that UDMA & MDMA cann't\r
616 // be set together. Only one DMA mode can be set to a device. If setting\r
617 // DMA mode operation fails, we can continue moving on because we only use\r
618 // PIO mode at boot time. DMA modes are used by certain kind of OS booting\r
619 //\r
620 if (SupportedModes->UdmaMode.Valid) {\r
621\r
622 TransferMode.ModeCategory = ATA_MODE_CATEGORY_UDMA;\r
623 TransferMode.ModeNumber = (UINT8) (SupportedModes->UdmaMode.Mode);\r
624 Status = SetDeviceTransferMode (IdeBlkIoDevicePtr, &TransferMode);\r
625\r
626 if (EFI_ERROR (Status)) {\r
627 IdeBusDriverPrivateData->DeviceFound[IdeChannel * 2 + IdeDevice] = FALSE;\r
628 ReleaseIdeResources (IdeBlkIoDevicePtr);\r
629 IdeBlkIoDevicePtr = NULL;\r
630 continue;\r
631 }\r
632\r
633 EnableInterrupt (IdeBlkIoDevicePtr);\r
634 } else if (SupportedModes->MultiWordDmaMode.Valid) {\r
635\r
636 TransferMode.ModeCategory = ATA_MODE_CATEGORY_MDMA;\r
637 TransferMode.ModeNumber = (UINT8) SupportedModes->MultiWordDmaMode.Mode;\r
638 Status = SetDeviceTransferMode (IdeBlkIoDevicePtr, &TransferMode);\r
639\r
640 if (EFI_ERROR (Status)) {\r
641 IdeBusDriverPrivateData->DeviceFound[IdeChannel * 2 + IdeDevice] = FALSE;\r
642 ReleaseIdeResources (IdeBlkIoDevicePtr);\r
643 IdeBlkIoDevicePtr = NULL;\r
644 continue;\r
645 }\r
646\r
647 EnableInterrupt (IdeBlkIoDevicePtr);\r
648 }\r
649 //\r
650 // Init driver parameters\r
651 //\r
652 DriveParameters.Sector = (UINT8) IdeBlkIoDevicePtr->pIdData->AtaData.sectors_per_track;\r
653 DriveParameters.Heads = (UINT8) (IdeBlkIoDevicePtr->pIdData->AtaData.heads - 1);\r
654 DriveParameters.MultipleSector = (UINT8) IdeBlkIoDevicePtr->pIdData->AtaData.multi_sector_cmd_max_sct_cnt;\r
655 //\r
656 // Set Parameters for the device:\r
657 // 1) Init\r
658 // 2) Establish the block count for READ/WRITE MULTIPLE (EXT) command\r
659 //\r
660 if ((IdeBlkIoDevicePtr->Type == IdeHardDisk) || (IdeBlkIoDevicePtr->Type == Ide48bitAddressingHardDisk)) {\r
661 Status = SetDriveParameters (IdeBlkIoDevicePtr, &DriveParameters);\r
662 }\r
663 \r
664 //\r
665 // Record PIO mode used in private data\r
666 //\r
1cc8ee78 667 IdeBlkIoDevicePtr->PioMode = (ATA_PIO_MODE) SupportedModes->PioMode.Mode;\r
878ddf1f 668\r
669 //\r
670 // Set IDE controller Timing Blocks in the PCI Configuration Space\r
671 //\r
672 IdeInit->SetTiming (IdeInit, IdeChannel, IdeDevice, SupportedModes);\r
673\r
674 //\r
675 // Add Component Name for the IDE/ATAPI device that was discovered.\r
676 //\r
677 IdeBlkIoDevicePtr->ControllerNameTable = NULL;\r
678 ADD_NAME (IdeBlkIoDevicePtr);\r
679\r
680 Status = gBS->InstallMultipleProtocolInterfaces (\r
681 &IdeBlkIoDevicePtr->Handle,\r
682 &gEfiDevicePathProtocolGuid,\r
683 IdeBlkIoDevicePtr->DevicePath,\r
684 &gEfiBlockIoProtocolGuid,\r
685 &IdeBlkIoDevicePtr->BlkIo,\r
686 &gEfiDiskInfoProtocolGuid,\r
687 &IdeBlkIoDevicePtr->DiskInfo,\r
688 NULL\r
689 );\r
690\r
691 if (EFI_ERROR (Status)) {\r
692 ReleaseIdeResources (IdeBlkIoDevicePtr);\r
693 }\r
694\r
695 gBS->OpenProtocol (\r
696 Controller,\r
697 &gEfiPciIoProtocolGuid,\r
698 (VOID **) &PciIo,\r
699 This->DriverBindingHandle,\r
700 IdeBlkIoDevicePtr->Handle,\r
701 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
702 );\r
703\r
704 IdeBusDriverPrivateData->DeviceProcessed[IdeChannel * 2 + IdeDevice] = TRUE;\r
705\r
706 //\r
707 // Report status code: device eanbled!\r
708 //\r
709 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
710 EFI_PROGRESS_CODE,\r
711 (EFI_IO_BUS_ATA_ATAPI | EFI_P_PC_ENABLE),\r
712 IdeBlkIoDevicePtr->DevicePath\r
713 );\r
905dd497 714 \r
715 //\r
716 // Create event to clear pending IDE interrupt\r
717 //\r
718 Status = gBS->CreateEvent (\r
719 EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES,\r
720 EFI_TPL_NOTIFY,\r
721 ClearInterrupt,\r
722 IdeBlkIoDevicePtr,\r
a98f11c5 723 &IdeBlkIoDevicePtr->ExitBootServiceEvent\r
905dd497 724 );\r
725\r
878ddf1f 726 //\r
727 // end of 2nd inner loop ----\r
728 //\r
729 }\r
730 //\r
731 // end of 2nd outer loop ==========\r
732 //\r
733 }\r
734 \r
735 //\r
736 // All configurations done! Notify IdeController to do post initialization\r
737 // work such as saving IDE controller PCI settings for S3 resume\r
738 //\r
739 IdeInit->NotifyPhase (IdeInit, EfiIdeBusPhaseMaximum, 0);\r
740\r
741 if (SupportedModes != NULL) {\r
742 gBS->FreePool (SupportedModes);\r
743 }\r
744\r
745 PERF_START (0, "Finish IDE detection", "IDE", 1);\r
746 PERF_END (0, "Finish IDE detection", "IDE", 0);\r
747\r
748 return EFI_SUCCESS;\r
749\r
750ErrorExit:\r
751\r
752 //\r
753 // Report error code: controller error\r
754 //\r
755 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
756 EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
757 (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_EC_CONTROLLER_ERROR),\r
758 ParentDevicePath\r
759 );\r
760\r
761 gBS->CloseProtocol (\r
762 Controller,\r
763 &gEfiIdeControllerInitProtocolGuid,\r
764 This->DriverBindingHandle,\r
765 Controller\r
766 );\r
767\r
768 gBS->UninstallMultipleProtocolInterfaces (\r
769 Controller,\r
770 &gEfiCallerIdGuid,\r
771 IdeBusDriverPrivateData,\r
772 NULL\r
773 );\r
774\r
775 if (IdeBusDriverPrivateData != NULL) {\r
776 gBS->FreePool (IdeBusDriverPrivateData);\r
777 }\r
778\r
779 if (SupportedModes != NULL) {\r
780 gBS->FreePool (SupportedModes);\r
781 }\r
782\r
783 gBS->CloseProtocol (\r
784 Controller,\r
785 &gEfiPciIoProtocolGuid,\r
786 This->DriverBindingHandle,\r
787 Controller\r
788 );\r
789\r
790 gBS->CloseProtocol (\r
791 Controller,\r
792 &gEfiDevicePathProtocolGuid,\r
793 This->DriverBindingHandle,\r
794 Controller\r
795 );\r
796\r
797 return Status;\r
798\r
799}\r
800\r
801//\r
802// ***********************************************************************************\r
803// IDEBusDriverBindingStop\r
804// ***********************************************************************************\r
805//\r
ed72955c 806/**\r
807 Stop this driver on Controller Handle. \r
808\r
809 @param This Protocol instance pointer.\r
810 @param DeviceHandle Handle of device to stop driver on\r
811 @param NumberOfChildren Not used\r
812 @param ChildHandleBuffer Not used\r
813\r
814 @retval EFI_SUCCESS This driver is removed DeviceHandle\r
815 @retval other This driver was not removed from this device\r
816\r
817**/\r
878ddf1f 818EFI_STATUS\r
819EFIAPI\r
820IDEBusDriverBindingStop (\r
821 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
822 IN EFI_HANDLE Controller,\r
823 IN UINTN NumberOfChildren,\r
824 IN EFI_HANDLE *ChildHandleBuffer\r
825 )\r
878ddf1f 826// TODO: Controller - add argument and description to function comment\r
827// TODO: EFI_DEVICE_ERROR - add return value to function comment\r
828{\r
829 EFI_STATUS Status;\r
830 EFI_PCI_IO_PROTOCOL *PciIo;\r
831 BOOLEAN AllChildrenStopped;\r
832 UINTN Index;\r
833 IDE_BUS_DRIVER_PRIVATE_DATA *IdeBusDriverPrivateData;\r
834\r
835 IdeBusDriverPrivateData = NULL;\r
836\r
837 if (NumberOfChildren == 0) {\r
838\r
839 Status = gBS->OpenProtocol (\r
840 Controller,\r
841 &gEfiPciIoProtocolGuid,\r
842 (VOID **) &PciIo,\r
843 This->DriverBindingHandle,\r
844 Controller,\r
845 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
846 );\r
847 if (!EFI_ERROR (Status)) {\r
848 PciIo->Attributes (\r
849 PciIo,\r
850 EfiPciIoAttributeOperationDisable,\r
851 EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO | EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO | EFI_PCI_DEVICE_ENABLE,\r
852 NULL\r
853 );\r
854 }\r
855\r
856 gBS->OpenProtocol (\r
857 Controller,\r
858 &gEfiCallerIdGuid,\r
859 (VOID **) &IdeBusDriverPrivateData,\r
860 This->DriverBindingHandle,\r
861 Controller,\r
862 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
863 );\r
864\r
865 gBS->UninstallMultipleProtocolInterfaces (\r
866 Controller,\r
867 &gEfiCallerIdGuid,\r
868 IdeBusDriverPrivateData,\r
869 NULL\r
870 );\r
871\r
872 if (IdeBusDriverPrivateData != NULL) {\r
873 gBS->FreePool (IdeBusDriverPrivateData);\r
874 }\r
875 //\r
876 // Close the bus driver\r
877 //\r
878 gBS->CloseProtocol (\r
879 Controller,\r
880 &gEfiIdeControllerInitProtocolGuid,\r
881 This->DriverBindingHandle,\r
882 Controller\r
883 );\r
884 gBS->CloseProtocol (\r
885 Controller,\r
886 &gEfiPciIoProtocolGuid,\r
887 This->DriverBindingHandle,\r
888 Controller\r
889 );\r
890 gBS->CloseProtocol (\r
891 Controller,\r
892 &gEfiDevicePathProtocolGuid,\r
893 This->DriverBindingHandle,\r
894 Controller\r
895 );\r
896\r
897 return EFI_SUCCESS;\r
898 }\r
899\r
900 AllChildrenStopped = TRUE;\r
901\r
902 for (Index = 0; Index < NumberOfChildren; Index++) {\r
903\r
904 Status = DeRegisterIdeDevice (This, Controller, ChildHandleBuffer[Index]);\r
905\r
906 if (EFI_ERROR (Status)) {\r
907 AllChildrenStopped = FALSE;\r
908 }\r
909 }\r
910\r
911 if (!AllChildrenStopped) {\r
912 return EFI_DEVICE_ERROR;\r
913 }\r
914\r
915 return EFI_SUCCESS;\r
916}\r
917\r
918//\r
919// ***********************************************************************************\r
920// DeRegisterIdeDevice\r
921// ***********************************************************************************\r
922//\r
ed72955c 923/**\r
924 Deregister an IDE device and free resources\r
925\r
926 @param This Protocol instance pointer.\r
927 @param Controller Ide device handle\r
928 @param Handle Handle of device to deregister driver on\r
929\r
930 @return EFI_STATUS\r
931\r
932**/\r
878ddf1f 933EFI_STATUS\r
934DeRegisterIdeDevice (\r
935 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
936 IN EFI_HANDLE Controller,\r
937 IN EFI_HANDLE Handle\r
938 )\r
878ddf1f 939// TODO: EFI_SUCCESS - add return value to function comment\r
940{\r
941 EFI_STATUS Status;\r
942 EFI_BLOCK_IO_PROTOCOL *BlkIo;\r
943 IDE_BLK_IO_DEV *IdeBlkIoDevice;\r
944 EFI_PCI_IO_PROTOCOL *PciIo;\r
945 UINTN Index;\r
946\r
947 Status = gBS->OpenProtocol (\r
948 Handle,\r
949 &gEfiBlockIoProtocolGuid,\r
950 (VOID **) &BlkIo,\r
951 This->DriverBindingHandle,\r
952 Controller,\r
953 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
954 );\r
955 if (EFI_ERROR (Status)) {\r
956 return Status;\r
957 }\r
958\r
959 IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (BlkIo);\r
960\r
961 //\r
962 // Report Status code: Device disabled\r
963 //\r
964 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
965 EFI_PROGRESS_CODE,\r
966 (EFI_IO_BUS_ATA_ATAPI | EFI_P_PC_DISABLE),\r
967 IdeBlkIoDevice->DevicePath\r
968 );\r
969\r
970 //\r
971 // Close the child handle\r
972 //\r
973 Status = gBS->CloseProtocol (\r
974 Controller,\r
975 &gEfiPciIoProtocolGuid,\r
976 This->DriverBindingHandle,\r
977 Handle\r
978 );\r
979\r
980 Status = gBS->UninstallMultipleProtocolInterfaces (\r
981 Handle,\r
982 &gEfiDevicePathProtocolGuid,\r
983 IdeBlkIoDevice->DevicePath,\r
984 &gEfiBlockIoProtocolGuid,\r
985 &IdeBlkIoDevice->BlkIo,\r
986 &gEfiDiskInfoProtocolGuid,\r
987 &IdeBlkIoDevice->DiskInfo,\r
988 NULL\r
989 );\r
990\r
991 if (EFI_ERROR (Status)) {\r
992 gBS->OpenProtocol (\r
993 Controller,\r
994 &gEfiPciIoProtocolGuid,\r
995 (VOID **) &PciIo,\r
996 This->DriverBindingHandle,\r
997 Handle,\r
998 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
999 );\r
1000 return Status;\r
1001 }\r
1002 \r
1003 //\r
1004 // Release allocated resources\r
1005 //\r
1006 Index = IdeBlkIoDevice->Channel * 2 + IdeBlkIoDevice->Device;\r
1007 IdeBlkIoDevice->IdeBusDriverPrivateData->HaveScannedDevice[Index] = FALSE;\r
1008\r
1009 ReleaseIdeResources (IdeBlkIoDevice);\r
1010\r
1011 return EFI_SUCCESS;\r
1012}\r
1013\r
1014//\r
1015// ***********************************************************************************\r
1016// IDEBlkIoReset\r
1017// ***********************************************************************************\r
1018//\r
ed72955c 1019/**\r
1020 TODO: This - add argument and description to function comment\r
1021 TODO: ExtendedVerification - add argument and description to function comment\r
1022 TODO: EFI_DEVICE_ERROR - add return value to function comment\r
1023\r
1024**/\r
878ddf1f 1025EFI_STATUS\r
1026EFIAPI\r
1027IDEBlkIoReset (\r
1028 IN EFI_BLOCK_IO_PROTOCOL *This,\r
1029 IN BOOLEAN ExtendedVerification\r
1030 )\r
878ddf1f 1031{\r
1032 IDE_BLK_IO_DEV *IdeBlkIoDevice;\r
1033 EFI_STATUS Status;\r
1034\r
1035 IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (This);\r
1036 //\r
1037 // Requery IDE IO resources in case of the switch of native and legacy modes\r
1038 //\r
1039 ReassignIdeResources (IdeBlkIoDevice);\r
1040\r
1041 //\r
1042 // for ATA device, using ATA reset method\r
1043 //\r
a98f11c5 1044 if (IdeBlkIoDevice->Type == IdeHardDisk ||\r
1045 IdeBlkIoDevice->Type == Ide48bitAddressingHardDisk) {\r
878ddf1f 1046 return AtaSoftReset (IdeBlkIoDevice);\r
1047 }\r
1048\r
1049 if (IdeBlkIoDevice->Type == IdeUnknown) {\r
1050 return EFI_DEVICE_ERROR;\r
1051 }\r
1052 \r
1053 //\r
1054 // for ATAPI device, using ATAPI reset method\r
1055 //\r
1056 Status = AtapiSoftReset (IdeBlkIoDevice);\r
1057 if (ExtendedVerification) {\r
1058 Status = AtaSoftReset (IdeBlkIoDevice);\r
1059 }\r
1060\r
1061 return Status;\r
1062}\r
1063\r
ed72955c 1064/**\r
1065 Read data from block io device\r
1066\r
1067 @param This Protocol instance pointer.\r
1068 @param MediaId The media ID of the device\r
1069 @param LBA Starting LBA address to read data\r
1070 @param BufferSize The size of data to be read\r
1071 @param Buffer Caller supplied buffer to save data\r
1072\r
1073 @return read data status\r
1074\r
1075**/\r
878ddf1f 1076EFI_STATUS\r
1077EFIAPI\r
1078IDEBlkIoReadBlocks (\r
1079 IN EFI_BLOCK_IO_PROTOCOL *This,\r
1080 IN UINT32 MediaId,\r
1081 IN EFI_LBA LBA,\r
1082 IN UINTN BufferSize,\r
1083 OUT VOID *Buffer\r
1084 )\r
878ddf1f 1085// TODO: EFI_DEVICE_ERROR - add return value to function comment\r
1086{\r
1087 IDE_BLK_IO_DEV *IdeBlkIoDevice;\r
1088\r
1089 IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (This);\r
1090\r
1091 //\r
1092 // Requery IDE IO resources in case of the switch of native and legacy modes\r
1093 //\r
1094 ReassignIdeResources (IdeBlkIoDevice);\r
1095\r
1096 //\r
1097 // For ATA compatible device, use ATA read block's mechanism\r
1098 //\r
1099 if (IdeBlkIoDevice->Type == IdeHardDisk ||\r
1100 IdeBlkIoDevice->Type == Ide48bitAddressingHardDisk) {\r
1101 return AtaBlkIoReadBlocks (\r
1102 IdeBlkIoDevice,\r
1103 MediaId,\r
1104 LBA,\r
1105 BufferSize,\r
1106 Buffer\r
1107 );\r
1108 }\r
1109\r
1110 if (IdeBlkIoDevice->Type == IdeUnknown) {\r
1111 return EFI_DEVICE_ERROR;\r
1112 }\r
1113 \r
1114 //\r
1115 // for ATAPI device, using ATAPI read block's mechanism\r
1116 //\r
1117 return AtapiBlkIoReadBlocks (\r
1118 IdeBlkIoDevice,\r
1119 MediaId,\r
1120 LBA,\r
1121 BufferSize,\r
1122 Buffer\r
1123 );\r
1124\r
1125}\r
1126\r
ed72955c 1127/**\r
1128 Write data to block io device\r
1129\r
1130 @param This Protocol instance pointer.\r
1131 @param MediaId The media ID of the device\r
1132 @param LBA Starting LBA address to write data\r
1133 @param BufferSize The size of data to be written\r
1134 @param Buffer Caller supplied buffer to save data\r
1135\r
1136 @return write data status\r
1137\r
1138**/\r
878ddf1f 1139EFI_STATUS\r
1140EFIAPI\r
1141IDEBlkIoWriteBlocks (\r
1142 IN EFI_BLOCK_IO_PROTOCOL *This,\r
1143 IN UINT32 MediaId,\r
1144 IN EFI_LBA LBA,\r
1145 IN UINTN BufferSize,\r
1146 IN VOID *Buffer\r
1147 )\r
878ddf1f 1148// TODO: EFI_DEVICE_ERROR - add return value to function comment\r
1149{\r
1150 IDE_BLK_IO_DEV *IdeBlkIoDevice;\r
1151\r
1152 IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (This);\r
1153 //\r
1154 // Requery IDE IO resources in case of the switch of native and legacy modes\r
1155 //\r
1156 ReassignIdeResources (IdeBlkIoDevice);\r
1157\r
1158 //\r
1159 // for ATA device, using ATA write block's mechanism\r
1160 //\r
1161 if (IdeBlkIoDevice->Type == IdeHardDisk ||\r
1162 IdeBlkIoDevice->Type == Ide48bitAddressingHardDisk) { \r
1163\r
1164 return AtaBlkIoWriteBlocks (\r
1165 IdeBlkIoDevice,\r
1166 MediaId,\r
1167 LBA,\r
1168 BufferSize,\r
1169 Buffer\r
1170 );\r
1171 }\r
1172\r
1173 if (IdeBlkIoDevice->Type == IdeUnknown) {\r
1174 return EFI_DEVICE_ERROR;\r
1175 }\r
1176 \r
1177 //\r
1178 // for ATAPI device, using ATAPI write block's mechanism\r
1179 //\r
1180 return AtapiBlkIoWriteBlocks (\r
1181 IdeBlkIoDevice,\r
1182 MediaId,\r
1183 LBA,\r
1184 BufferSize,\r
1185 Buffer\r
1186 );\r
1187}\r
1188\r
1189//\r
1190// ***********************************************************************************\r
1191// IDEBlkIoFlushBlocks\r
1192// ***********************************************************************************\r
1193//\r
ed72955c 1194/**\r
1195 TODO: This - add argument and description to function comment\r
1196 TODO: EFI_SUCCESS - add return value to function comment\r
1197**/\r
878ddf1f 1198EFI_STATUS\r
1199EFIAPI\r
1200IDEBlkIoFlushBlocks (\r
1201 IN EFI_BLOCK_IO_PROTOCOL *This\r
1202 )\r
878ddf1f 1203{\r
1204 //\r
1205 // return directly\r
1206 //\r
1207 return EFI_SUCCESS;\r
1208}\r
1209\r
ed72955c 1210/**\r
1211 Return the results of the Inquiry command to a drive in InquiryData.\r
1212 Data format of Inquiry data is defined by the Interface GUID.\r
1213\r
1214 @param This Protocol instance pointer.\r
1215 @param InquiryData Results of Inquiry command to device\r
1216 @param InquiryDataSize Size of InquiryData in bytes.\r
1217\r
1218 @retval EFI_SUCCESS InquiryData valid\r
1219 @retval EFI_NOT_FOUND Device does not support this data class\r
1220 @retval EFI_DEVICE_ERROR Error reading InquiryData from device\r
1221 @retval EFI_BUFFER_TOO_SMALL IntquiryDataSize not big enough\r
1222\r
1223**/\r
878ddf1f 1224EFI_STATUS\r
1225EFIAPI\r
1226IDEDiskInfoInquiry (\r
1227 IN EFI_DISK_INFO_PROTOCOL *This,\r
1228 IN OUT VOID *InquiryData,\r
1229 IN OUT UINT32 *InquiryDataSize\r
1230 )\r
878ddf1f 1231{\r
1232 IDE_BLK_IO_DEV *IdeBlkIoDevice;\r
1233\r
1234 IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_DISK_INFO_THIS (This);\r
1235\r
1236 if (*InquiryDataSize < sizeof (INQUIRY_DATA)) {\r
1237 *InquiryDataSize = sizeof (INQUIRY_DATA);\r
1238 return EFI_BUFFER_TOO_SMALL;\r
1239 }\r
1240\r
1241 if (IdeBlkIoDevice->pInquiryData == NULL) {\r
1242 return EFI_NOT_FOUND;\r
1243 }\r
1244\r
1245 gBS->CopyMem (InquiryData, IdeBlkIoDevice->pInquiryData, sizeof (INQUIRY_DATA));\r
1246 *InquiryDataSize = sizeof (INQUIRY_DATA);\r
1247\r
1248 return EFI_SUCCESS;\r
1249}\r
1250\r
ed72955c 1251/**\r
1252 Return the results of the Identify command to a drive in IdentifyData.\r
1253 Data format of Identify data is defined by the Interface GUID.\r
1254\r
1255 @param This Protocol instance pointer.\r
1256 @param IdentifyData Results of Identify command to device\r
1257 @param IdentifyDataSize Size of IdentifyData in bytes.\r
1258\r
1259 @retval EFI_SUCCESS IdentifyData valid\r
1260 @retval EFI_NOT_FOUND Device does not support this data class\r
1261 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device\r
1262 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough\r
1263\r
1264**/\r
878ddf1f 1265EFI_STATUS\r
1266EFIAPI\r
1267IDEDiskInfoIdentify (\r
1268 IN EFI_DISK_INFO_PROTOCOL *This,\r
1269 IN OUT VOID *IdentifyData,\r
1270 IN OUT UINT32 *IdentifyDataSize\r
1271 )\r
878ddf1f 1272{\r
1273 IDE_BLK_IO_DEV *IdeBlkIoDevice;\r
1274\r
1275 IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_DISK_INFO_THIS (This);\r
1276\r
1277 if (*IdentifyDataSize < sizeof (EFI_IDENTIFY_DATA)) {\r
1278 *IdentifyDataSize = sizeof (EFI_IDENTIFY_DATA);\r
1279 return EFI_BUFFER_TOO_SMALL;\r
1280 }\r
1281\r
1282 if (IdeBlkIoDevice->pIdData == NULL) {\r
1283 return EFI_NOT_FOUND;\r
1284 }\r
1285\r
1286 gBS->CopyMem (IdentifyData, IdeBlkIoDevice->pIdData, sizeof (EFI_IDENTIFY_DATA));\r
1287 *IdentifyDataSize = sizeof (EFI_IDENTIFY_DATA);\r
1288\r
1289 return EFI_SUCCESS;\r
1290}\r
1291\r
ed72955c 1292/**\r
1293 Return the results of the Request Sense command to a drive in SenseData.\r
1294 Data format of Sense data is defined by the Interface GUID.\r
1295\r
1296 @param This Protocol instance pointer.\r
1297 @param SenseData Results of Request Sense command to device\r
1298 @param SenseDataSize Size of SenseData in bytes.\r
1299 @param SenseDataNumber Type of SenseData\r
1300\r
1301 @retval EFI_SUCCESS InquiryData valid\r
1302 @retval EFI_NOT_FOUND Device does not support this data class\r
1303 @retval EFI_DEVICE_ERROR Error reading InquiryData from device\r
1304 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough\r
1305\r
1306**/\r
878ddf1f 1307EFI_STATUS\r
1308EFIAPI\r
1309IDEDiskInfoSenseData (\r
1310 IN EFI_DISK_INFO_PROTOCOL *This,\r
1311 IN OUT VOID *SenseData,\r
1312 IN OUT UINT32 *SenseDataSize,\r
1313 OUT UINT8 *SenseDataNumber\r
1314 )\r
878ddf1f 1315{\r
1316 return EFI_NOT_FOUND;\r
1317}\r
1318\r
ed72955c 1319/**\r
1320 Return the results of the Request Sense command to a drive in SenseData.\r
1321 Data format of Sense data is defined by the Interface GUID.\r
1322\r
1323 @param This Protocol instance pointer.\r
1324 @param IdeChannel Primary or Secondary\r
1325 @param IdeDevice Master or Slave\r
1326\r
1327 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid\r
1328 @retval EFI_UNSUPPORTED This is not an IDE device\r
1329\r
1330**/\r
878ddf1f 1331EFI_STATUS\r
1332EFIAPI\r
1333IDEDiskInfoWhichIde (\r
1334 IN EFI_DISK_INFO_PROTOCOL *This,\r
1335 OUT UINT32 *IdeChannel,\r
1336 OUT UINT32 *IdeDevice\r
1337 )\r
878ddf1f 1338{\r
1339 IDE_BLK_IO_DEV *IdeBlkIoDevice;\r
1340\r
1341 IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_DISK_INFO_THIS (This);\r
1342 *IdeChannel = IdeBlkIoDevice->Channel;\r
1343 *IdeDevice = IdeBlkIoDevice->Device;\r
1344\r
1345 return EFI_SUCCESS;\r
1346}\r