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