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