]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Ata/AtaAtapiPassThru/AtaAtapiPassThru.c
Introduce tow non-blocking task lists to AtaBus. One maintains the sub-task which...
[mirror_edk2.git] / MdeModulePkg / Bus / Ata / AtaAtapiPassThru / AtaAtapiPassThru.c
1 /** @file
2 This file implements ATA_PASSTHRU_PROCTOCOL and EXT_SCSI_PASSTHRU_PROTOCOL interfaces
3 for managed ATA controllers.
4
5 Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "AtaAtapiPassThru.h"
17
18 //
19 // EFI_DRIVER_BINDING_PROTOCOL instance
20 //
21 EFI_DRIVER_BINDING_PROTOCOL gAtaAtapiPassThruDriverBinding = {
22 AtaAtapiPassThruSupported,
23 AtaAtapiPassThruStart,
24 AtaAtapiPassThruStop,
25 0x10,
26 NULL,
27 NULL
28 };
29
30 ATA_ATAPI_PASS_THRU_INSTANCE gAtaAtapiPassThruInstanceTemplate = {
31 ATA_ATAPI_PASS_THRU_SIGNATURE,
32 0, // Controller Handle
33 NULL, // PciIo Protocol
34 NULL, // IdeControllerInit Protocol
35 { // AtaPassThruMode
36 //
37 // According to UEFI2.3 spec Section 12.10, Drivers for non-RAID ATA controllers should set
38 // both EFI_ATA_PASS_THRU_ATTRIBUTES_PHYSICAL and EFI_ATA_PASS_THRU_ATTRIBUTES_LOGICAL
39 // bits.
40 // Note that the driver doesn't support AtaPassThru non blocking I/O.
41 //
42 EFI_ATA_PASS_THRU_ATTRIBUTES_PHYSICAL | EFI_ATA_PASS_THRU_ATTRIBUTES_LOGICAL | EFI_ATA_PASS_THRU_ATTRIBUTES_NONBLOCKIO,
43 //
44 // IoAlign
45 //
46 sizeof (UINTN)
47 },
48 { // AtaPassThru
49 NULL,
50 AtaPassThruPassThru,
51 AtaPassThruGetNextPort,
52 AtaPassThruGetNextDevice,
53 AtaPassThruBuildDevicePath,
54 AtaPassThruGetDevice,
55 AtaPassThruResetPort,
56 AtaPassThruResetDevice
57 },
58 { // ExtScsiPassThruMode
59 //
60 // AdapterId
61 //
62 0,
63 //
64 // According to UEFI2.3 spec Section 14.7, Drivers for non-RAID SCSI controllers should set
65 // both EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL and EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL
66 // bits.
67 // Note that the driver doesn't support ExtScsiPassThru non blocking I/O.
68 //
69 EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL | EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL,
70 //
71 // IoAlign
72 //
73 sizeof (UINTN)
74 },
75 { // ExtScsiPassThru
76 NULL,
77 ExtScsiPassThruPassThru,
78 ExtScsiPassThruGetNextTargetLun,
79 ExtScsiPassThruBuildDevicePath,
80 ExtScsiPassThruGetTargetLun,
81 ExtScsiPassThruResetChannel,
82 ExtScsiPassThruResetTargetLun,
83 ExtScsiPassThruGetNextTarget
84 },
85 EfiAtaUnknownMode, // Work Mode
86 { // IdeRegisters
87 {0},
88 {0}
89 },
90 { // AhciRegisters
91 0
92 },
93 { // DeviceList
94 NULL,
95 NULL
96 },
97 0, // OriginalAttributes
98 0, // PreviousPort
99 0, // PreviousPortMultiplier
100 0, // PreviousTargetId
101 0, // PreviousLun
102 NULL, // Timer event
103 { // NonBlocking TaskList
104 NULL,
105 NULL
106 }
107 };
108
109 ATAPI_DEVICE_PATH mAtapiDevicePathTemplate = {
110 {
111 MESSAGING_DEVICE_PATH,
112 MSG_ATAPI_DP,
113 (UINT8) (sizeof (ATAPI_DEVICE_PATH)),
114 (UINT8) ((sizeof (ATAPI_DEVICE_PATH)) >> 8),
115 },
116 0,
117 0,
118 0
119 };
120
121 SATA_DEVICE_PATH mSataDevicePathTemplate = {
122 {
123 MESSAGING_DEVICE_PATH,
124 MSG_SATA_DP,
125 (UINT8) (sizeof (SATA_DEVICE_PATH)),
126 (UINT8) ((sizeof (SATA_DEVICE_PATH)) >> 8),
127 },
128 0,
129 0,
130 0
131 };
132
133 UINT8 mScsiId[TARGET_MAX_BYTES] = {
134 0xFF, 0xFF, 0xFF, 0xFF,
135 0xFF, 0xFF, 0xFF, 0xFF,
136 0xFF, 0xFF, 0xFF, 0xFF,
137 0xFF, 0xFF, 0xFF, 0xFF
138 };
139
140 /**
141 Sends an ATA command to an ATA device that is attached to the ATA controller. This function
142 supports both blocking I/O and non-blocking I/O. The blocking I/O functionality is required,
143 and the non-blocking I/O functionality is optional.
144
145 @param[in] Port The port number of the ATA device to send the command.
146 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command.
147 If there is no port multiplier, then specify 0.
148 @param[in, out] Packet A pointer to the ATA command to send to the ATA device specified by Port
149 and PortMultiplierPort.
150 @param[in] Instance Pointer to the ATA_ATAPI_PASS_THRU_INSTANCE.
151 @param[in] Task Optional. Pointer to the ATA_NONBLOCK_TASK
152 used by non-blocking mode.
153
154 @retval EFI_SUCCESS The ATA command was sent by the host. For
155 bi-directional commands, InTransferLength bytes
156 were transferred from InDataBuffer. For
157 write and bi-directional commands, OutTransferLength
158 bytes were transferred by OutDataBuffer.
159 @retval EFI_BAD_BUFFER_SIZE The ATA command was not executed. The number
160 of bytes that could be transferred is returned
161 in InTransferLength. For write and bi-directional
162 commands, OutTransferLength bytes were transferred
163 by OutDataBuffer.
164 @retval EFI_NOT_READY The ATA command could not be sent because
165 there are too many ATA commands already
166 queued. The caller may retry again later.
167 @retval EFI_DEVICE_ERROR A device error occurred while attempting
168 to send the ATA command.
169 @retval EFI_INVALID_PARAMETER Port, PortMultiplierPort, or the contents
170 of Acb are invalid. The ATA command was
171 not sent, so no additional status information
172 is available.
173
174 **/
175 EFI_STATUS
176 EFIAPI
177 AtaPassThruPassThruExecute (
178 IN UINT16 Port,
179 IN UINT16 PortMultiplierPort,
180 IN OUT EFI_ATA_PASS_THRU_COMMAND_PACKET *Packet,
181 IN ATA_ATAPI_PASS_THRU_INSTANCE *Instance,
182 IN ATA_NONBLOCK_TASK *Task OPTIONAL
183 )
184 {
185 EFI_ATA_PASS_THRU_CMD_PROTOCOL Protocol;
186 EFI_ATA_HC_WORK_MODE Mode;
187 EFI_STATUS Status;
188
189 Protocol = Packet->Protocol;
190
191 Mode = Instance->Mode;
192 switch (Mode) {
193 case EfiAtaIdeMode:
194 //
195 // Reassign IDE mode io port registers' base addresses
196 //
197 Status = GetIdeRegisterIoAddr (Instance->PciIo, Instance->IdeRegisters);
198
199 if (EFI_ERROR (Status)) {
200 return Status;
201 }
202
203 switch (Protocol) {
204 case EFI_ATA_PASS_THRU_PROTOCOL_ATA_NON_DATA:
205 Status = AtaNonDataCommandIn (
206 Instance->PciIo,
207 &Instance->IdeRegisters[Port],
208 Packet->Acb,
209 Packet->Asb,
210 Packet->Timeout,
211 Task
212 );
213 break;
214 case EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_IN:
215 Status = AtaPioDataInOut (
216 Instance->PciIo,
217 &Instance->IdeRegisters[Port],
218 Packet->InDataBuffer,
219 Packet->InTransferLength,
220 TRUE,
221 Packet->Acb,
222 Packet->Asb,
223 Packet->Timeout,
224 Task
225 );
226 break;
227 case EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_OUT:
228 Status = AtaPioDataInOut (
229 Instance->PciIo,
230 &Instance->IdeRegisters[Port],
231 Packet->OutDataBuffer,
232 Packet->OutTransferLength,
233 FALSE,
234 Packet->Acb,
235 Packet->Asb,
236 Packet->Timeout,
237 Task
238 );
239 break;
240 case EFI_ATA_PASS_THRU_PROTOCOL_UDMA_DATA_IN:
241 Status = AtaUdmaInOut (
242 Instance,
243 &Instance->IdeRegisters[Port],
244 TRUE,
245 Packet->InDataBuffer,
246 Packet->InTransferLength,
247 Packet->Acb,
248 Packet->Asb,
249 Packet->Timeout,
250 Task
251 );
252 break;
253 case EFI_ATA_PASS_THRU_PROTOCOL_UDMA_DATA_OUT:
254 Status = AtaUdmaInOut (
255 Instance,
256 &Instance->IdeRegisters[Port],
257 FALSE,
258 Packet->OutDataBuffer,
259 Packet->OutTransferLength,
260 Packet->Acb,
261 Packet->Asb,
262 Packet->Timeout,
263 Task
264 );
265 break;
266 default :
267 return EFI_UNSUPPORTED;
268 }
269 break;
270 case EfiAtaAhciMode :
271 switch (Protocol) {
272 case EFI_ATA_PASS_THRU_PROTOCOL_ATA_NON_DATA:
273 Status = AhciNonDataTransfer (
274 Instance->PciIo,
275 &Instance->AhciRegisters,
276 (UINT8)Port,
277 (UINT8)PortMultiplierPort,
278 NULL,
279 0,
280 Packet->Acb,
281 Packet->Asb,
282 Packet->Timeout,
283 Task
284 );
285 break;
286 case EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_IN:
287 Status = AhciPioTransfer (
288 Instance->PciIo,
289 &Instance->AhciRegisters,
290 (UINT8)Port,
291 (UINT8)PortMultiplierPort,
292 NULL,
293 0,
294 TRUE,
295 Packet->Acb,
296 Packet->Asb,
297 Packet->InDataBuffer,
298 Packet->InTransferLength,
299 Packet->Timeout,
300 Task
301 );
302 break;
303 case EFI_ATA_PASS_THRU_PROTOCOL_PIO_DATA_OUT:
304 Status = AhciPioTransfer (
305 Instance->PciIo,
306 &Instance->AhciRegisters,
307 (UINT8)Port,
308 (UINT8)PortMultiplierPort,
309 NULL,
310 0,
311 FALSE,
312 Packet->Acb,
313 Packet->Asb,
314 Packet->OutDataBuffer,
315 Packet->OutTransferLength,
316 Packet->Timeout,
317 Task
318 );
319 break;
320 case EFI_ATA_PASS_THRU_PROTOCOL_UDMA_DATA_IN:
321 Status = AhciDmaTransfer (
322 Instance,
323 &Instance->AhciRegisters,
324 (UINT8)Port,
325 (UINT8)PortMultiplierPort,
326 NULL,
327 0,
328 TRUE,
329 Packet->Acb,
330 Packet->Asb,
331 Packet->InDataBuffer,
332 Packet->InTransferLength,
333 Packet->Timeout,
334 Task
335 );
336 break;
337 case EFI_ATA_PASS_THRU_PROTOCOL_UDMA_DATA_OUT:
338 Status = AhciDmaTransfer (
339 Instance,
340 &Instance->AhciRegisters,
341 (UINT8)Port,
342 (UINT8)PortMultiplierPort,
343 NULL,
344 0,
345 FALSE,
346 Packet->Acb,
347 Packet->Asb,
348 Packet->OutDataBuffer,
349 Packet->OutTransferLength,
350 Packet->Timeout,
351 Task
352 );
353 break;
354 default :
355 return EFI_UNSUPPORTED;
356 }
357 break;
358
359 default:
360 Status = EFI_DEVICE_ERROR;
361 break;
362 }
363
364 return Status;
365 }
366
367 /**
368 Call back function when the timer event is signaled.
369
370 @param[in] Event The Event this notify function registered to.
371 @param[in] Context Pointer to the context data registered to the
372 Event.
373
374 **/
375 VOID
376 EFIAPI
377 AsyncNonBlockingTransferRoutine (
378 EFI_EVENT Event,
379 VOID* Context
380 )
381 {
382 LIST_ENTRY *Entry;
383 LIST_ENTRY *EntryHeader;
384 ATA_NONBLOCK_TASK *Task;
385 EFI_STATUS Status;
386 ATA_ATAPI_PASS_THRU_INSTANCE *Instance;
387
388 Instance = (ATA_ATAPI_PASS_THRU_INSTANCE *) Context;
389 EntryHeader = &Instance->NonBlockingTaskList;
390 //
391 // Get the Taks from the Taks List and execute it, until there is
392 // no task in the list or the device is busy with task (EFI_NOT_READY).
393 //
394 while (TRUE) {
395 if (!IsListEmpty (EntryHeader)) {
396 Entry = GetFirstNode (EntryHeader);
397 Task = ATA_NON_BLOCK_TASK_FROM_ENTRY (Entry);
398 } else {
399 return;
400 }
401
402 Status = AtaPassThruPassThruExecute (
403 Task->Port,
404 Task->PortMultiplier,
405 Task->Packet,
406 Instance,
407 Task
408 );
409
410 //
411 // If the data transfer meet a error, remove all tasks in the list since these tasks are
412 // associated with one task from Ata Bus and signal the event with error status.
413 //
414 if ((Status != EFI_NOT_READY) && (Status != EFI_SUCCESS)) {
415 DestroyAsynTaskList (Instance, TRUE);
416 break;
417 }
418
419 //
420 // For Non blocking mode, the Status of EFI_NOT_READY means the operation
421 // is not finished yet. Otherwise the operation is successful.
422 //
423 if (Status == EFI_NOT_READY) {
424 break;
425 } else {
426 RemoveEntryList (&Task->Link);
427 gBS->SignalEvent (Task->Event);
428 FreePool (Task);
429 }
430 }
431 }
432
433 /**
434 The Entry Point of module.
435
436 @param[in] ImageHandle The firmware allocated handle for the EFI image.
437 @param[in] SystemTable A pointer to the EFI System Table.
438
439 @retval EFI_SUCCESS The entry point is executed successfully.
440 @retval other Some error occurs when executing this entry point.
441
442 **/
443 EFI_STATUS
444 EFIAPI
445 InitializeAtaAtapiPassThru (
446 IN EFI_HANDLE ImageHandle,
447 IN EFI_SYSTEM_TABLE *SystemTable
448 )
449 {
450 EFI_STATUS Status;
451
452 //
453 // Install driver model protocol(s).
454 //
455 Status = EfiLibInstallDriverBindingComponentName2 (
456 ImageHandle,
457 SystemTable,
458 &gAtaAtapiPassThruDriverBinding,
459 ImageHandle,
460 &gAtaAtapiPassThruComponentName,
461 &gAtaAtapiPassThruComponentName2
462 );
463 ASSERT_EFI_ERROR (Status);
464
465 return Status;
466 }
467
468 /**
469 Tests to see if this driver supports a given controller. If a child device is provided,
470 it further tests to see if this driver supports creating a handle for the specified child device.
471
472 This function checks to see if the driver specified by This supports the device specified by
473 ControllerHandle. Drivers will typically use the device path attached to
474 ControllerHandle and/or the services from the bus I/O abstraction attached to
475 ControllerHandle to determine if the driver supports ControllerHandle. This function
476 may be called many times during platform initialization. In order to reduce boot times, the tests
477 performed by this function must be very small, and take as little time as possible to execute. This
478 function must not change the state of any hardware devices, and this function must be aware that the
479 device specified by ControllerHandle may already be managed by the same driver or a
480 different driver. This function must match its calls to AllocatePages() with FreePages(),
481 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
482 Because ControllerHandle may have been previously started by the same driver, if a protocol is
483 already in the opened state, then it must not be closed with CloseProtocol(). This is required
484 to guarantee the state of ControllerHandle is not modified by this function.
485
486 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
487 @param[in] ControllerHandle The handle of the controller to test. This handle
488 must support a protocol interface that supplies
489 an I/O abstraction to the driver.
490 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
491 parameter is ignored by device drivers, and is optional for bus
492 drivers. For bus drivers, if this parameter is not NULL, then
493 the bus driver must determine if the bus controller specified
494 by ControllerHandle and the child controller specified
495 by RemainingDevicePath are both supported by this
496 bus driver.
497
498 @retval EFI_SUCCESS The device specified by ControllerHandle and
499 RemainingDevicePath is supported by the driver specified by This.
500 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
501 RemainingDevicePath is already being managed by the driver
502 specified by This.
503 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
504 RemainingDevicePath is already being managed by a different
505 driver or an application that requires exclusive access.
506 Currently not implemented.
507 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
508 RemainingDevicePath is not supported by the driver specified by This.
509 **/
510 EFI_STATUS
511 EFIAPI
512 AtaAtapiPassThruSupported (
513 IN EFI_DRIVER_BINDING_PROTOCOL *This,
514 IN EFI_HANDLE Controller,
515 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
516 )
517 {
518 EFI_STATUS Status;
519 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
520 EFI_PCI_IO_PROTOCOL *PciIo;
521 PCI_TYPE00 PciData;
522 EFI_IDE_CONTROLLER_INIT_PROTOCOL *IdeControllerInit;
523
524 //
525 // SATA Controller is a device driver, and should ingore the
526 // "RemainingDevicePath" according to UEFI spec
527 //
528 Status = gBS->OpenProtocol (
529 Controller,
530 &gEfiDevicePathProtocolGuid,
531 (VOID *) &ParentDevicePath,
532 This->DriverBindingHandle,
533 Controller,
534 EFI_OPEN_PROTOCOL_BY_DRIVER
535 );
536 if (EFI_ERROR (Status)) {
537 //
538 // EFI_ALREADY_STARTED is also an error
539 //
540 return Status;
541 }
542 //
543 // Close the protocol because we don't use it here
544 //
545 gBS->CloseProtocol (
546 Controller,
547 &gEfiDevicePathProtocolGuid,
548 This->DriverBindingHandle,
549 Controller
550 );
551
552 Status = gBS->OpenProtocol (
553 Controller,
554 &gEfiIdeControllerInitProtocolGuid,
555 (VOID **) &IdeControllerInit,
556 This->DriverBindingHandle,
557 Controller,
558 EFI_OPEN_PROTOCOL_BY_DRIVER
559 );
560
561 if (EFI_ERROR (Status)) {
562 //
563 // EFI_ALREADY_STARTED is also an error
564 //
565 return Status;
566 }
567
568 //
569 // Close the I/O Abstraction(s) used to perform the supported test
570 //
571 gBS->CloseProtocol (
572 Controller,
573 &gEfiIdeControllerInitProtocolGuid,
574 This->DriverBindingHandle,
575 Controller
576 );
577
578 //
579 // Now test the EfiPciIoProtocol
580 //
581 Status = gBS->OpenProtocol (
582 Controller,
583 &gEfiPciIoProtocolGuid,
584 (VOID **) &PciIo,
585 This->DriverBindingHandle,
586 Controller,
587 EFI_OPEN_PROTOCOL_GET_PROTOCOL
588 );
589 if (EFI_ERROR (Status)) {
590 return Status;
591 }
592 //
593 // Now further check the PCI header: Base class (offset 0x0B) and
594 // Sub Class (offset 0x0A). This controller should be an ATA controller
595 //
596 Status = PciIo->Pci.Read (
597 PciIo,
598 EfiPciIoWidthUint8,
599 PCI_CLASSCODE_OFFSET,
600 sizeof (PciData.Hdr.ClassCode),
601 PciData.Hdr.ClassCode
602 );
603 if (EFI_ERROR (Status)) {
604 return EFI_UNSUPPORTED;
605 }
606
607 if (IS_PCI_IDE (&PciData) || IS_PCI_SATADPA (&PciData)) {
608 return EFI_SUCCESS;
609 }
610
611 return EFI_UNSUPPORTED;
612 }
613
614 /**
615 Starts a device controller or a bus controller.
616
617 The Start() function is designed to be invoked from the EFI boot service ConnectController().
618 As a result, much of the error checking on the parameters to Start() has been moved into this
619 common boot service. It is legal to call Start() from other locations,
620 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
621 1. ControllerHandle must be a valid EFI_HANDLE.
622 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
623 EFI_DEVICE_PATH_PROTOCOL.
624 3. Prior to calling Start(), the Supported() function for the driver specified by This must
625 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
626
627 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
628 @param[in] ControllerHandle The handle of the controller to start. This handle
629 must support a protocol interface that supplies
630 an I/O abstraction to the driver.
631 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
632 parameter is ignored by device drivers, and is optional for bus
633 drivers. For a bus driver, if this parameter is NULL, then handles
634 for all the children of Controller are created by this driver.
635 If this parameter is not NULL and the first Device Path Node is
636 not the End of Device Path Node, then only the handle for the
637 child device specified by the first Device Path Node of
638 RemainingDevicePath is created by this driver.
639 If the first Device Path Node of RemainingDevicePath is
640 the End of Device Path Node, no child handle is created by this
641 driver.
642
643 @retval EFI_SUCCESS The device was started.
644 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
645 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
646 @retval Others The driver failded to start the device.
647
648 **/
649 EFI_STATUS
650 EFIAPI
651 AtaAtapiPassThruStart (
652 IN EFI_DRIVER_BINDING_PROTOCOL *This,
653 IN EFI_HANDLE Controller,
654 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
655 )
656 {
657 EFI_STATUS Status;
658 EFI_IDE_CONTROLLER_INIT_PROTOCOL *IdeControllerInit;
659 ATA_ATAPI_PASS_THRU_INSTANCE *Instance;
660 EFI_PCI_IO_PROTOCOL *PciIo;
661 UINT64 Supports;
662 UINT64 OriginalPciAttributes;
663
664 Status = EFI_SUCCESS;
665 IdeControllerInit = NULL;
666 Instance = NULL;
667 OriginalPciAttributes = 0;
668
669 DEBUG ((EFI_D_INFO, "==AtaAtapiPassThru Start== Controller = %x\n", Controller));
670
671 Status = gBS->OpenProtocol (
672 Controller,
673 &gEfiIdeControllerInitProtocolGuid,
674 (VOID **) &IdeControllerInit,
675 This->DriverBindingHandle,
676 Controller,
677 EFI_OPEN_PROTOCOL_BY_DRIVER
678 );
679
680 if (EFI_ERROR (Status)) {
681 DEBUG ((EFI_D_ERROR, "Open Ide_Controller_Init Error, Status=%r", Status));
682 goto ErrorExit;
683 }
684
685 Status = gBS->OpenProtocol (
686 Controller,
687 &gEfiPciIoProtocolGuid,
688 (VOID **) &PciIo,
689 This->DriverBindingHandle,
690 Controller,
691 EFI_OPEN_PROTOCOL_GET_PROTOCOL
692 );
693 if (EFI_ERROR (Status)) {
694 DEBUG ((EFI_D_ERROR, "Get Pci_Io Protocol Error, Status=%r", Status));
695 goto ErrorExit;
696 }
697
698 Status = PciIo->Attributes (
699 PciIo,
700 EfiPciIoAttributeOperationGet,
701 0,
702 &OriginalPciAttributes
703 );
704
705 if (EFI_ERROR (Status)) {
706 goto ErrorExit;
707 }
708
709 Status = PciIo->Attributes (
710 PciIo,
711 EfiPciIoAttributeOperationSupported,
712 0,
713 &Supports
714 );
715 if (!EFI_ERROR (Status)) {
716 Supports &= EFI_PCI_DEVICE_ENABLE;
717 Status = PciIo->Attributes (
718 PciIo,
719 EfiPciIoAttributeOperationEnable,
720 Supports,
721 NULL
722 );
723 }
724
725 if (EFI_ERROR (Status)) {
726 goto ErrorExit;
727 }
728
729 //
730 // Allocate a buffer to store the ATA_ATAPI_PASS_THRU_INSTANCE data structure
731 //
732 Instance = AllocateCopyPool (sizeof (ATA_ATAPI_PASS_THRU_INSTANCE), &gAtaAtapiPassThruInstanceTemplate);
733 if (Instance == NULL) {
734 goto ErrorExit;
735 }
736
737 Instance->ControllerHandle = Controller;
738 Instance->IdeControllerInit = IdeControllerInit;
739 Instance->PciIo = PciIo;
740 Instance->OriginalPciAttributes = OriginalPciAttributes;
741 Instance->AtaPassThru.Mode = &Instance->AtaPassThruMode;
742 Instance->ExtScsiPassThru.Mode = &Instance->ExtScsiPassThruMode;
743 InitializeListHead(&Instance->DeviceList);
744 InitializeListHead(&Instance->NonBlockingTaskList);
745
746 Instance->TimerEvent = NULL;
747
748 Status = gBS->CreateEvent (
749 EVT_TIMER | EVT_NOTIFY_SIGNAL,
750 TPL_NOTIFY,
751 AsyncNonBlockingTransferRoutine,
752 Instance,
753 &Instance->TimerEvent
754 );
755 if (EFI_ERROR (Status)) {
756 goto ErrorExit;
757 }
758
759 //
760 // Set 1ms timer.
761 //
762 Status = gBS->SetTimer (Instance->TimerEvent, TimerPeriodic, 10000);
763 if (EFI_ERROR (Status)) {
764 goto ErrorExit;
765 }
766
767 //
768 // Enumerate all inserted ATA devices.
769 //
770 Status = EnumerateAttachedDevice (Instance);
771 if (EFI_ERROR (Status)) {
772 goto ErrorExit;
773 }
774
775 Status = gBS->InstallMultipleProtocolInterfaces (
776 &Controller,
777 &gEfiAtaPassThruProtocolGuid, &(Instance->AtaPassThru),
778 &gEfiExtScsiPassThruProtocolGuid, &(Instance->ExtScsiPassThru),
779 NULL
780 );
781 ASSERT_EFI_ERROR (Status);
782
783 return Status;
784
785 ErrorExit:
786 if (IdeControllerInit != NULL) {
787 gBS->CloseProtocol (
788 Controller,
789 &gEfiIdeControllerInitProtocolGuid,
790 This->DriverBindingHandle,
791 Controller
792 );
793 }
794
795 if ((Instance != NULL) && (Instance->TimerEvent != NULL)) {
796 gBS->CloseEvent (Instance->TimerEvent);
797 }
798
799 //
800 // Remove all inserted ATA devices.
801 //
802 DestroyDeviceInfoList(Instance);
803
804 if (Instance != NULL) {
805 FreePool (Instance);
806 }
807 return EFI_UNSUPPORTED;
808 }
809
810 /**
811 Stops a device controller or a bus controller.
812
813 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
814 As a result, much of the error checking on the parameters to Stop() has been moved
815 into this common boot service. It is legal to call Stop() from other locations,
816 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
817 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
818 same driver's Start() function.
819 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
820 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
821 Start() function, and the Start() function must have called OpenProtocol() on
822 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
823
824 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
825 @param[in] ControllerHandle A handle to the device being stopped. The handle must
826 support a bus specific I/O protocol for the driver
827 to use to stop the device.
828 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
829 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
830 if NumberOfChildren is 0.
831
832 @retval EFI_SUCCESS The device was stopped.
833 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
834
835 **/
836 EFI_STATUS
837 EFIAPI
838 AtaAtapiPassThruStop (
839 IN EFI_DRIVER_BINDING_PROTOCOL *This,
840 IN EFI_HANDLE Controller,
841 IN UINTN NumberOfChildren,
842 IN EFI_HANDLE *ChildHandleBuffer
843 )
844 {
845 EFI_STATUS Status;
846 ATA_ATAPI_PASS_THRU_INSTANCE *Instance;
847 EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThru;
848 EFI_PCI_IO_PROTOCOL *PciIo;
849 EFI_AHCI_REGISTERS *AhciRegisters;
850 UINT64 Supports;
851
852 DEBUG ((EFI_D_INFO, "==AtaAtapiPassThru Stop== Controller = %x\n", Controller));
853
854 Status = gBS->OpenProtocol (
855 Controller,
856 &gEfiAtaPassThruProtocolGuid,
857 (VOID **) &AtaPassThru,
858 This->DriverBindingHandle,
859 Controller,
860 EFI_OPEN_PROTOCOL_GET_PROTOCOL
861 );
862
863 if (EFI_ERROR (Status)) {
864 return EFI_DEVICE_ERROR;
865 }
866
867 Instance = ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS (AtaPassThru);
868
869 //
870 // Close Non-Blocking timer and free Task list.
871 //
872 if (Instance->TimerEvent != NULL) {
873 gBS->CloseEvent (Instance->TimerEvent);
874 Instance->TimerEvent = NULL;
875 }
876 DestroyAsynTaskList (Instance, FALSE);
877
878 //
879 // Disable this ATA host controller.
880 //
881 PciIo = Instance->PciIo;
882 Status = PciIo->Attributes (
883 PciIo,
884 EfiPciIoAttributeOperationSupported,
885 0,
886 &Supports
887 );
888 if (!EFI_ERROR (Status)) {
889 Supports &= EFI_PCI_DEVICE_ENABLE;
890 PciIo->Attributes (
891 PciIo,
892 EfiPciIoAttributeOperationDisable,
893 Supports,
894 NULL
895 );
896 }
897
898 //
899 // Restore original PCI attributes
900 //
901 Status = PciIo->Attributes (
902 PciIo,
903 EfiPciIoAttributeOperationSet,
904 Instance->OriginalPciAttributes,
905 NULL
906 );
907 ASSERT_EFI_ERROR (Status);
908
909 gBS->UninstallMultipleProtocolInterfaces (
910 Controller,
911 &gEfiAtaPassThruProtocolGuid, &(Instance->AtaPassThru),
912 &gEfiExtScsiPassThruProtocolGuid, &(Instance->ExtScsiPassThru),
913 NULL
914 );
915
916 //
917 // Close protocols opened by AtaAtapiPassThru controller driver
918 //
919 gBS->CloseProtocol (
920 Controller,
921 &gEfiIdeControllerInitProtocolGuid,
922 This->DriverBindingHandle,
923 Controller
924 );
925
926 //
927 // Free allocated resource
928 //
929 DestroyDeviceInfoList(Instance);
930
931 //
932 // If the current working mode is AHCI mode, then pre-allocated resource
933 // for AHCI initialization should be released.
934 //
935 if (Instance->Mode == EfiAtaAhciMode) {
936 AhciRegisters = &Instance->AhciRegisters;
937 PciIo->Unmap (
938 PciIo,
939 AhciRegisters->MapCommandTable
940 );
941 PciIo->FreeBuffer (
942 PciIo,
943 EFI_SIZE_TO_PAGES ((UINTN) AhciRegisters->MaxCommandTableSize),
944 AhciRegisters->AhciCommandTable
945 );
946 PciIo->Unmap (
947 PciIo,
948 AhciRegisters->MapCmdList
949 );
950 PciIo->FreeBuffer (
951 PciIo,
952 EFI_SIZE_TO_PAGES ((UINTN) AhciRegisters->MaxCommandListSize),
953 AhciRegisters->AhciCmdList
954 );
955 PciIo->Unmap (
956 PciIo,
957 AhciRegisters->MapRFis
958 );
959 PciIo->FreeBuffer (
960 PciIo,
961 EFI_SIZE_TO_PAGES ((UINTN) AhciRegisters->MaxReceiveFisSize),
962 AhciRegisters->AhciRFis
963 );
964 }
965 FreePool (Instance);
966
967 return Status;
968 }
969
970 /**
971 Traverse the attached ATA devices list to find out the device to access.
972
973 @param[in] Instance A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
974 @param[in] Port The port number of the ATA device to send the command.
975 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command.
976 If there is no port multiplier, then specify 0.
977 @param[in] DeviceType The device type of the ATA device.
978
979 @retval The pointer to the data structure of the device info to access.
980
981 **/
982 LIST_ENTRY *
983 EFIAPI
984 SearchDeviceInfoList (
985 IN ATA_ATAPI_PASS_THRU_INSTANCE *Instance,
986 IN UINT16 Port,
987 IN UINT16 PortMultiplier,
988 IN EFI_ATA_DEVICE_TYPE DeviceType
989 )
990 {
991 EFI_ATA_DEVICE_INFO *DeviceInfo;
992 LIST_ENTRY *Node;
993
994 Node = GetFirstNode (&Instance->DeviceList);
995 while (!IsNull (&Instance->DeviceList, Node)) {
996 DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);
997
998 if ((DeviceInfo->Type == DeviceType) &&
999 (Port == DeviceInfo->Port) &&
1000 (PortMultiplier == DeviceInfo->PortMultiplier)) {
1001 return Node;
1002 }
1003
1004 Node = GetNextNode (&Instance->DeviceList, Node);
1005 }
1006
1007 return NULL;
1008 }
1009
1010 /**
1011 Allocate device info data structure to contain device info.
1012 And insert the data structure to the tail of device list for tracing.
1013
1014 @param[in] Instance A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
1015 @param[in] Port The port number of the ATA device to send the command.
1016 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command.
1017 If there is no port multiplier, then specify 0.
1018 @param[in] DeviceType The device type of the ATA device.
1019 @param[in] IdentifyData The data buffer to store the output of the IDENTIFY cmd.
1020
1021 @retval EFI_SUCCESS Successfully insert the ata device to the tail of device list.
1022 @retval EFI_OUT_OF_RESOURCES Can not allocate enough resource for use.
1023
1024 **/
1025 EFI_STATUS
1026 EFIAPI
1027 CreateNewDeviceInfo (
1028 IN ATA_ATAPI_PASS_THRU_INSTANCE *Instance,
1029 IN UINT16 Port,
1030 IN UINT16 PortMultiplier,
1031 IN EFI_ATA_DEVICE_TYPE DeviceType,
1032 IN EFI_IDENTIFY_DATA *IdentifyData
1033 )
1034 {
1035 EFI_ATA_DEVICE_INFO *DeviceInfo;
1036
1037 DeviceInfo = AllocateZeroPool (sizeof (EFI_ATA_DEVICE_INFO));
1038
1039 if (DeviceInfo == NULL) {
1040 return EFI_OUT_OF_RESOURCES;
1041 }
1042
1043 DeviceInfo->Signature = ATA_ATAPI_DEVICE_SIGNATURE;
1044 DeviceInfo->Port = Port;
1045 DeviceInfo->PortMultiplier = PortMultiplier;
1046 DeviceInfo->Type = DeviceType;
1047
1048 if (IdentifyData != NULL) {
1049 DeviceInfo->IdentifyData = AllocateCopyPool (sizeof (EFI_IDENTIFY_DATA), IdentifyData);
1050 if (DeviceInfo->IdentifyData == NULL) {
1051 FreePool (DeviceInfo);
1052 return EFI_OUT_OF_RESOURCES;
1053 }
1054 }
1055
1056 InsertTailList (&Instance->DeviceList, &DeviceInfo->Link);
1057
1058 return EFI_SUCCESS;
1059 }
1060
1061 /**
1062 Destroy all attached ATA devices info.
1063
1064 @param[in] Instance A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
1065
1066 **/
1067 VOID
1068 EFIAPI
1069 DestroyDeviceInfoList (
1070 IN ATA_ATAPI_PASS_THRU_INSTANCE *Instance
1071 )
1072 {
1073 EFI_ATA_DEVICE_INFO *DeviceInfo;
1074 LIST_ENTRY *Node;
1075
1076 Node = GetFirstNode (&Instance->DeviceList);
1077 while (!IsNull (&Instance->DeviceList, Node)) {
1078 DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);
1079
1080 Node = GetNextNode (&Instance->DeviceList, Node);
1081
1082 RemoveEntryList (&DeviceInfo->Link);
1083 if (DeviceInfo->IdentifyData != NULL) {
1084 FreePool (DeviceInfo->IdentifyData);
1085 }
1086 FreePool (DeviceInfo);
1087 }
1088 }
1089
1090 /**
1091 Destroy all pending non blocking tasks.
1092
1093 @param[in] Instance A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
1094 @param[in] IsSigEvent Indicate whether signal the task event when remove the
1095 task.
1096
1097 **/
1098 VOID
1099 EFIAPI
1100 DestroyAsynTaskList (
1101 IN ATA_ATAPI_PASS_THRU_INSTANCE *Instance,
1102 IN BOOLEAN IsSigEvent
1103 )
1104 {
1105 LIST_ENTRY *Entry;
1106 LIST_ENTRY *DelEntry;
1107 ATA_NONBLOCK_TASK *Task;
1108 EFI_TPL OldTpl;
1109
1110 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
1111 if (!IsListEmpty (&Instance->NonBlockingTaskList)) {
1112 //
1113 // Free the Subtask list.
1114 //
1115 for (Entry = (&Instance->NonBlockingTaskList)->ForwardLink;
1116 Entry != (&Instance->NonBlockingTaskList);
1117 ) {
1118 DelEntry = Entry;
1119 Entry = Entry->ForwardLink;
1120 Task = ATA_NON_BLOCK_TASK_FROM_ENTRY (DelEntry);
1121
1122 RemoveEntryList (DelEntry);
1123 if (IsSigEvent) {
1124 Task->Packet->Asb->AtaStatus = 0x01;
1125 gBS->SignalEvent (Task->Event);
1126 }
1127 FreePool (Task);
1128 }
1129 }
1130 gBS->RestoreTPL (OldTpl);
1131 }
1132
1133 /**
1134 Enumerate all attached ATA devices at IDE mode or AHCI mode separately.
1135
1136 The function is designed to enumerate all attached ATA devices.
1137
1138 @param[in] Instance A pointer to the ATA_ATAPI_PASS_THRU_INSTANCE instance.
1139
1140 @retval EFI_SUCCESS Successfully enumerate attached ATA devices.
1141 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
1142
1143 **/
1144 EFI_STATUS
1145 EFIAPI
1146 EnumerateAttachedDevice (
1147 IN ATA_ATAPI_PASS_THRU_INSTANCE *Instance
1148 )
1149 {
1150 EFI_STATUS Status;
1151 PCI_TYPE00 PciData;
1152 UINT8 ClassCode;
1153
1154 Status = EFI_SUCCESS;
1155
1156 Status = Instance->PciIo->Pci.Read (
1157 Instance->PciIo,
1158 EfiPciIoWidthUint8,
1159 PCI_CLASSCODE_OFFSET,
1160 sizeof (PciData.Hdr.ClassCode),
1161 PciData.Hdr.ClassCode
1162 );
1163 ASSERT_EFI_ERROR (Status);
1164
1165 ClassCode = PciData.Hdr.ClassCode[1];
1166
1167 switch (ClassCode) {
1168 case PCI_CLASS_MASS_STORAGE_IDE :
1169 //
1170 // The ATA controller is working at IDE mode
1171 //
1172 Instance->Mode = EfiAtaIdeMode;
1173
1174 Status = IdeModeInitialization (Instance);
1175 if (EFI_ERROR (Status)) {
1176 Status = EFI_DEVICE_ERROR;
1177 goto Done;
1178 }
1179 break;
1180 case PCI_CLASS_MASS_STORAGE_SATADPA :
1181 //
1182 // The ATA controller is working at AHCI mode
1183 //
1184 Instance->Mode = EfiAtaAhciMode;
1185
1186 Status = AhciModeInitialization (Instance);
1187
1188 if (EFI_ERROR (Status)) {
1189 Status = EFI_DEVICE_ERROR;
1190 goto Done;
1191 }
1192
1193 break;
1194 default :
1195 Status = EFI_UNSUPPORTED;
1196 }
1197
1198 Done:
1199 return Status;
1200 }
1201
1202 /**
1203 Sends an ATA command to an ATA device that is attached to the ATA controller. This function
1204 supports both blocking I/O and non-blocking I/O. The blocking I/O functionality is required,
1205 and the non-blocking I/O functionality is optional.
1206
1207 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1208 @param[in] Port The port number of the ATA device to send the command.
1209 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to send the command.
1210 If there is no port multiplier, then specify 0.
1211 @param[in, out] Packet A pointer to the ATA command to send to the ATA device specified by Port
1212 and PortMultiplierPort.
1213 @param[in] Event If non-blocking I/O is not supported then Event is ignored, and blocking
1214 I/O is performed. If Event is NULL, then blocking I/O is performed. If
1215 Event is not NULL and non blocking I/O is supported, then non-blocking
1216 I/O is performed, and Event will be signaled when the ATA command completes.
1217
1218 @retval EFI_SUCCESS The ATA command was sent by the host. For bi-directional commands,
1219 InTransferLength bytes were transferred from InDataBuffer. For write and
1220 bi-directional commands, OutTransferLength bytes were transferred by OutDataBuffer.
1221 @retval EFI_BAD_BUFFER_SIZE The ATA command was not executed. The number of bytes that could be transferred
1222 is returned in InTransferLength. For write and bi-directional commands,
1223 OutTransferLength bytes were transferred by OutDataBuffer.
1224 @retval EFI_NOT_READY The ATA command could not be sent because there are too many ATA commands
1225 already queued. The caller may retry again later.
1226 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the ATA command.
1227 @retval EFI_INVALID_PARAMETER Port, PortMultiplierPort, or the contents of Acb are invalid. The ATA
1228 command was not sent, so no additional status information is available.
1229
1230 **/
1231 EFI_STATUS
1232 EFIAPI
1233 AtaPassThruPassThru (
1234 IN EFI_ATA_PASS_THRU_PROTOCOL *This,
1235 IN UINT16 Port,
1236 IN UINT16 PortMultiplierPort,
1237 IN OUT EFI_ATA_PASS_THRU_COMMAND_PACKET *Packet,
1238 IN EFI_EVENT Event OPTIONAL
1239 )
1240 {
1241 ATA_ATAPI_PASS_THRU_INSTANCE *Instance;
1242 LIST_ENTRY *Node;
1243 EFI_ATA_DEVICE_INFO *DeviceInfo;
1244 EFI_IDENTIFY_DATA *IdentifyData;
1245 UINT64 Capacity;
1246 UINT32 MaxSectorCount;
1247 ATA_NONBLOCK_TASK *Task;
1248 EFI_TPL OldTpl;
1249
1250 Instance = ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS (This);
1251
1252 if ((This->Mode->IoAlign > 1) && !IS_ALIGNED(Packet->InDataBuffer, This->Mode->IoAlign)) {
1253 return EFI_INVALID_PARAMETER;
1254 }
1255
1256 if ((This->Mode->IoAlign > 1) && !IS_ALIGNED(Packet->OutDataBuffer, This->Mode->IoAlign)) {
1257 return EFI_INVALID_PARAMETER;
1258 }
1259
1260 if ((This->Mode->IoAlign > 1) && !IS_ALIGNED(Packet->Asb, This->Mode->IoAlign)) {
1261 return EFI_INVALID_PARAMETER;
1262 }
1263
1264 //
1265 // convert the transfer length from sector count to byte.
1266 //
1267 if (((Packet->Length & EFI_ATA_PASS_THRU_LENGTH_BYTES) == 0) &&
1268 (Packet->InTransferLength != 0)) {
1269 Packet->InTransferLength = Packet->InTransferLength * 0x200;
1270 }
1271
1272 //
1273 // convert the transfer length from sector count to byte.
1274 //
1275 if (((Packet->Length & EFI_ATA_PASS_THRU_LENGTH_BYTES) == 0) &&
1276 (Packet->OutTransferLength != 0)) {
1277 Packet->OutTransferLength = Packet->OutTransferLength * 0x200;
1278 }
1279
1280 Node = SearchDeviceInfoList (Instance, Port, PortMultiplierPort, EfiIdeHarddisk);
1281
1282 if (Node == NULL) {
1283 return EFI_INVALID_PARAMETER;
1284 }
1285
1286 //
1287 // Check whether this device needs 48-bit addressing (ATAPI-6 ata device).
1288 // Per ATA-6 spec, word83: bit15 is zero and bit14 is one.
1289 // If bit10 is one, it means the ata device support 48-bit addressing.
1290 //
1291 DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);
1292 IdentifyData = DeviceInfo->IdentifyData;
1293 MaxSectorCount = 0x100;
1294 if ((IdentifyData->AtaData.command_set_supported_83 & (BIT10 | BIT15 | BIT14)) == 0x4400) {
1295 Capacity = *((UINT64 *)IdentifyData->AtaData.maximum_lba_for_48bit_addressing);
1296 if (Capacity > 0xFFFFFFF) {
1297 //
1298 // Capacity exceeds 120GB. 48-bit addressing is really needed
1299 // In this case, the max sector count is 0x10000
1300 //
1301 MaxSectorCount = 0x10000;
1302 }
1303 }
1304
1305 //
1306 // If the data buffer described by InDataBuffer/OutDataBuffer and InTransferLength/OutTransferLength
1307 // is too big to be transferred in a single command, then no data is transferred and EFI_BAD_BUFFER_SIZE
1308 // is returned.
1309 //
1310 if (((Packet->InTransferLength != 0) && (Packet->InTransferLength > MaxSectorCount * 0x200)) ||
1311 ((Packet->OutTransferLength != 0) && (Packet->OutTransferLength > MaxSectorCount * 0x200))) {
1312 return EFI_BAD_BUFFER_SIZE;
1313 }
1314
1315 //
1316 // For non-blocking mode, queue the Task into the list.
1317 //
1318 if (Event != NULL) {
1319 Task = AllocateZeroPool (sizeof (ATA_NONBLOCK_TASK));
1320 if (Task == NULL) {
1321 return EFI_OUT_OF_RESOURCES;
1322 }
1323
1324 Task->Signature = ATA_NONBLOCKING_TASK_SIGNATURE;
1325 Task->Port = Port;
1326 Task->PortMultiplier = PortMultiplierPort;
1327 Task->Packet = Packet;
1328 Task->Event = Event;
1329 Task->IsStart = FALSE;
1330 Task->RetryTimes = 0;
1331
1332 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
1333 InsertTailList (&Instance->NonBlockingTaskList, &Task->Link);
1334 gBS->RestoreTPL (OldTpl);
1335
1336 return EFI_SUCCESS;
1337 } else {
1338 return AtaPassThruPassThruExecute (
1339 Port,
1340 PortMultiplierPort,
1341 Packet,
1342 Instance,
1343 NULL
1344 );
1345 }
1346 }
1347
1348 /**
1349 Used to retrieve the list of legal port numbers for ATA devices on an ATA controller.
1350 These can either be the list of ports where ATA devices are actually present or the
1351 list of legal port numbers for the ATA controller. Regardless, the caller of this
1352 function must probe the port number returned to see if an ATA device is actually
1353 present at that location on the ATA controller.
1354
1355 The GetNextPort() function retrieves the port number on an ATA controller. If on input
1356 Port is 0xFFFF, then the port number of the first port on the ATA controller is returned
1357 in Port and EFI_SUCCESS is returned.
1358
1359 If Port is a port number that was returned on a previous call to GetNextPort(), then the
1360 port number of the next port on the ATA controller is returned in Port, and EFI_SUCCESS
1361 is returned. If Port is not 0xFFFF and Port was not returned on a previous call to
1362 GetNextPort(), then EFI_INVALID_PARAMETER is returned.
1363
1364 If Port is the port number of the last port on the ATA controller, then EFI_NOT_FOUND is
1365 returned.
1366
1367 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1368 @param[in, out] Port On input, a pointer to the port number on the ATA controller.
1369 On output, a pointer to the next port number on the ATA
1370 controller. An input value of 0xFFFF retrieves the first port
1371 number on the ATA controller.
1372
1373 @retval EFI_SUCCESS The next port number on the ATA controller was returned in Port.
1374 @retval EFI_NOT_FOUND There are no more ports on this ATA controller.
1375 @retval EFI_INVALID_PARAMETER Port is not 0xFFFF and Port was not returned on a previous call
1376 to GetNextPort().
1377
1378 **/
1379 EFI_STATUS
1380 EFIAPI
1381 AtaPassThruGetNextPort (
1382 IN EFI_ATA_PASS_THRU_PROTOCOL *This,
1383 IN OUT UINT16 *Port
1384 )
1385 {
1386 ATA_ATAPI_PASS_THRU_INSTANCE *Instance;
1387 LIST_ENTRY *Node;
1388 EFI_ATA_DEVICE_INFO *DeviceInfo;
1389
1390 Instance = ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS (This);
1391
1392 if (Port == NULL) {
1393 return EFI_INVALID_PARAMETER;
1394 }
1395
1396 if (*Port == 0xFFFF) {
1397 //
1398 // If the Port is all 0xFF's, start to traverse the device list from the beginning
1399 //
1400 Node = GetFirstNode (&Instance->DeviceList);
1401
1402 while (!IsNull (&Instance->DeviceList, Node)) {
1403 DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);
1404
1405 if (DeviceInfo->Type == EfiIdeHarddisk) {
1406 *Port = DeviceInfo->Port;
1407 goto Exit;
1408 }
1409
1410 Node = GetNextNode (&Instance->DeviceList, Node);
1411 }
1412
1413 return EFI_NOT_FOUND;
1414 } else if (*Port == Instance->PreviousPort) {
1415 Node = GetFirstNode (&Instance->DeviceList);
1416
1417 while (!IsNull (&Instance->DeviceList, Node)) {
1418 DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);
1419
1420 if ((DeviceInfo->Type == EfiIdeHarddisk) &&
1421 (DeviceInfo->Port > *Port)){
1422 *Port = DeviceInfo->Port;
1423 goto Exit;
1424 }
1425
1426 Node = GetNextNode (&Instance->DeviceList, Node);
1427 }
1428
1429 return EFI_NOT_FOUND;
1430 } else {
1431 //
1432 // Port is not equal to 0xFFFF and also not equal to previous return value
1433 //
1434 return EFI_INVALID_PARAMETER;
1435 }
1436
1437 Exit:
1438 //
1439 // Update the PreviousPort and PreviousPortMultiplier.
1440 //
1441 Instance->PreviousPort = *Port;
1442
1443 return EFI_SUCCESS;
1444 }
1445
1446 /**
1447 Used to retrieve the list of legal port multiplier port numbers for ATA devices on a port of an ATA
1448 controller. These can either be the list of port multiplier ports where ATA devices are actually
1449 present on port or the list of legal port multiplier ports on that port. Regardless, the caller of this
1450 function must probe the port number and port multiplier port number returned to see if an ATA
1451 device is actually present.
1452
1453 The GetNextDevice() function retrieves the port multiplier port number of an ATA device
1454 present on a port of an ATA controller.
1455
1456 If PortMultiplierPort points to a port multiplier port number value that was returned on a
1457 previous call to GetNextDevice(), then the port multiplier port number of the next ATA device
1458 on the port of the ATA controller is returned in PortMultiplierPort, and EFI_SUCCESS is
1459 returned.
1460
1461 If PortMultiplierPort points to 0xFFFF, then the port multiplier port number of the first
1462 ATA device on port of the ATA controller is returned in PortMultiplierPort and
1463 EFI_SUCCESS is returned.
1464
1465 If PortMultiplierPort is not 0xFFFF and the value pointed to by PortMultiplierPort
1466 was not returned on a previous call to GetNextDevice(), then EFI_INVALID_PARAMETER
1467 is returned.
1468
1469 If PortMultiplierPort is the port multiplier port number of the last ATA device on the port of
1470 the ATA controller, then EFI_NOT_FOUND is returned.
1471
1472 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1473 @param[in] Port The port number present on the ATA controller.
1474 @param[in, out] PortMultiplierPort On input, a pointer to the port multiplier port number of an
1475 ATA device present on the ATA controller.
1476 If on input a PortMultiplierPort of 0xFFFF is specified,
1477 then the port multiplier port number of the first ATA device
1478 is returned. On output, a pointer to the port multiplier port
1479 number of the next ATA device present on an ATA controller.
1480
1481 @retval EFI_SUCCESS The port multiplier port number of the next ATA device on the port
1482 of the ATA controller was returned in PortMultiplierPort.
1483 @retval EFI_NOT_FOUND There are no more ATA devices on this port of the ATA controller.
1484 @retval EFI_INVALID_PARAMETER PortMultiplierPort is not 0xFFFF, and PortMultiplierPort was not
1485 returned on a previous call to GetNextDevice().
1486
1487 **/
1488 EFI_STATUS
1489 EFIAPI
1490 AtaPassThruGetNextDevice (
1491 IN EFI_ATA_PASS_THRU_PROTOCOL *This,
1492 IN UINT16 Port,
1493 IN OUT UINT16 *PortMultiplierPort
1494 )
1495 {
1496 ATA_ATAPI_PASS_THRU_INSTANCE *Instance;
1497 LIST_ENTRY *Node;
1498 EFI_ATA_DEVICE_INFO *DeviceInfo;
1499
1500 Instance = ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS (This);
1501
1502 if (PortMultiplierPort == NULL) {
1503 return EFI_INVALID_PARAMETER;
1504 }
1505
1506 if (*PortMultiplierPort == 0xFFFF) {
1507 //
1508 // If the PortMultiplierPort is all 0xFF's, start to traverse the device list from the beginning
1509 //
1510 Node = GetFirstNode (&Instance->DeviceList);
1511
1512 while (!IsNull (&Instance->DeviceList, Node)) {
1513 DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);
1514
1515 if ((DeviceInfo->Type == EfiIdeHarddisk) &&
1516 (DeviceInfo->Port == Port)){
1517 *PortMultiplierPort = DeviceInfo->PortMultiplier;
1518 goto Exit;
1519 }
1520
1521 Node = GetNextNode (&Instance->DeviceList, Node);
1522 }
1523
1524 return EFI_NOT_FOUND;
1525 } else if (*PortMultiplierPort == Instance->PreviousPortMultiplier) {
1526 Node = GetFirstNode (&Instance->DeviceList);
1527
1528 while (!IsNull (&Instance->DeviceList, Node)) {
1529 DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);
1530
1531 if ((DeviceInfo->Type == EfiIdeHarddisk) &&
1532 (DeviceInfo->Port == Port) &&
1533 (DeviceInfo->PortMultiplier > *PortMultiplierPort)){
1534 *PortMultiplierPort = DeviceInfo->PortMultiplier;
1535 goto Exit;
1536 }
1537
1538 Node = GetNextNode (&Instance->DeviceList, Node);
1539 }
1540
1541 return EFI_NOT_FOUND;
1542 } else {
1543 //
1544 // PortMultiplierPort is not equal to 0xFFFF and also not equal to previous return value
1545 //
1546 return EFI_INVALID_PARAMETER;
1547 }
1548
1549 Exit:
1550 //
1551 // Update the PreviousPort and PreviousPortMultiplier.
1552 //
1553 Instance->PreviousPortMultiplier = *PortMultiplierPort;
1554
1555 return EFI_SUCCESS;
1556 }
1557
1558 /**
1559 Used to allocate and build a device path node for an ATA device on an ATA controller.
1560
1561 The BuildDevicePath() function allocates and builds a single device node for the ATA
1562 device specified by Port and PortMultiplierPort. If the ATA device specified by Port and
1563 PortMultiplierPort is not present on the ATA controller, then EFI_NOT_FOUND is returned.
1564 If DevicePath is NULL, then EFI_INVALID_PARAMETER is returned. If there are not enough
1565 resources to allocate the device path node, then EFI_OUT_OF_RESOURCES is returned.
1566
1567 Otherwise, DevicePath is allocated with the boot service AllocatePool(), the contents of
1568 DevicePath are initialized to describe the ATA device specified by Port and PortMultiplierPort,
1569 and EFI_SUCCESS is returned.
1570
1571 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1572 @param[in] Port Port specifies the port number of the ATA device for which a
1573 device path node is to be allocated and built.
1574 @param[in] PortMultiplierPort The port multiplier port number of the ATA device for which a
1575 device path node is to be allocated and built. If there is no
1576 port multiplier, then specify 0.
1577 @param[in, out] DevicePath A pointer to a single device path node that describes the ATA
1578 device specified by Port and PortMultiplierPort. This function
1579 is responsible for allocating the buffer DevicePath with the
1580 boot service AllocatePool(). It is the caller's responsibility
1581 to free DevicePath when the caller is finished with DevicePath.
1582 @retval EFI_SUCCESS The device path node that describes the ATA device specified by
1583 Port and PortMultiplierPort was allocated and returned in DevicePath.
1584 @retval EFI_NOT_FOUND The ATA device specified by Port and PortMultiplierPort does not
1585 exist on the ATA controller.
1586 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
1587 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.
1588
1589 **/
1590 EFI_STATUS
1591 EFIAPI
1592 AtaPassThruBuildDevicePath (
1593 IN EFI_ATA_PASS_THRU_PROTOCOL *This,
1594 IN UINT16 Port,
1595 IN UINT16 PortMultiplierPort,
1596 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
1597 )
1598 {
1599 EFI_DEV_PATH *DevicePathNode;
1600 ATA_ATAPI_PASS_THRU_INSTANCE *Instance;
1601 LIST_ENTRY *Node;
1602
1603 Instance = ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS (This);
1604
1605 //
1606 // Validate parameters passed in.
1607 //
1608 if (DevicePath == NULL) {
1609 return EFI_INVALID_PARAMETER;
1610 }
1611
1612 Node = SearchDeviceInfoList(Instance, Port, PortMultiplierPort, EfiIdeHarddisk);
1613 if (Node == NULL) {
1614 return EFI_NOT_FOUND;
1615 }
1616
1617 if (Instance->Mode == EfiAtaIdeMode) {
1618 DevicePathNode = AllocateCopyPool (sizeof (ATAPI_DEVICE_PATH), &mAtapiDevicePathTemplate);
1619 if (DevicePathNode == NULL) {
1620 return EFI_OUT_OF_RESOURCES;
1621 }
1622 DevicePathNode->Atapi.PrimarySecondary = (UINT8) Port;
1623 DevicePathNode->Atapi.SlaveMaster = (UINT8) PortMultiplierPort;
1624 DevicePathNode->Atapi.Lun = 0;
1625 } else {
1626 DevicePathNode = AllocateCopyPool (sizeof (SATA_DEVICE_PATH), &mSataDevicePathTemplate);
1627 if (DevicePathNode == NULL) {
1628 return EFI_OUT_OF_RESOURCES;
1629 }
1630
1631 DevicePathNode->Sata.HBAPortNumber = Port;
1632 DevicePathNode->Sata.PortMultiplierPortNumber = PortMultiplierPort;
1633 DevicePathNode->Sata.Lun = 0;
1634 }
1635
1636 *DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) DevicePathNode;
1637
1638 return EFI_SUCCESS;
1639 }
1640
1641 /**
1642 Used to translate a device path node to a port number and port multiplier port number.
1643
1644 The GetDevice() function determines the port and port multiplier port number associated with
1645 the ATA device described by DevicePath. If DevicePath is a device path node type that the
1646 ATA Pass Thru driver supports, then the ATA Pass Thru driver will attempt to translate the contents
1647 DevicePath into a port number and port multiplier port number.
1648
1649 If this translation is successful, then that port number and port multiplier port number are returned
1650 in Port and PortMultiplierPort, and EFI_SUCCESS is returned.
1651
1652 If DevicePath, Port, or PortMultiplierPort are NULL, then EFI_INVALID_PARAMETER is returned.
1653
1654 If DevicePath is not a device path node type that the ATA Pass Thru driver supports, then
1655 EFI_UNSUPPORTED is returned.
1656
1657 If DevicePath is a device path node type that the ATA Pass Thru driver supports, but there is not
1658 a valid translation from DevicePath to a port number and port multiplier port number, then
1659 EFI_NOT_FOUND is returned.
1660
1661 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1662 @param[in] DevicePath A pointer to the device path node that describes an ATA device on the
1663 ATA controller.
1664 @param[out] Port On return, points to the port number of an ATA device on the ATA controller.
1665 @param[out] PortMultiplierPort On return, points to the port multiplier port number of an ATA device
1666 on the ATA controller.
1667
1668 @retval EFI_SUCCESS DevicePath was successfully translated to a port number and port multiplier
1669 port number, and they were returned in Port and PortMultiplierPort.
1670 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
1671 @retval EFI_INVALID_PARAMETER Port is NULL.
1672 @retval EFI_INVALID_PARAMETER PortMultiplierPort is NULL.
1673 @retval EFI_UNSUPPORTED This driver does not support the device path node type in DevicePath.
1674 @retval EFI_NOT_FOUND A valid translation from DevicePath to a port number and port multiplier
1675 port number does not exist.
1676 **/
1677 EFI_STATUS
1678 EFIAPI
1679 AtaPassThruGetDevice (
1680 IN EFI_ATA_PASS_THRU_PROTOCOL *This,
1681 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
1682 OUT UINT16 *Port,
1683 OUT UINT16 *PortMultiplierPort
1684 )
1685 {
1686 EFI_DEV_PATH *DevicePathNode;
1687 ATA_ATAPI_PASS_THRU_INSTANCE *Instance;
1688 LIST_ENTRY *Node;
1689
1690 Instance = ATA_PASS_THRU_PRIVATE_DATA_FROM_THIS (This);
1691
1692 //
1693 // Validate parameters passed in.
1694 //
1695 if (DevicePath == NULL || Port == NULL || PortMultiplierPort == NULL) {
1696 return EFI_INVALID_PARAMETER;
1697 }
1698
1699 //
1700 // Check whether the DevicePath belongs to SCSI_DEVICE_PATH or ATAPI_DEVICE_PATH
1701 //
1702 if ((DevicePath->Type != MESSAGING_DEVICE_PATH) ||
1703 ((DevicePath->SubType != MSG_SATA_DP) &&
1704 (DevicePath->SubType != MSG_ATAPI_DP)) ||
1705 ((DevicePathNodeLength(DevicePath) != sizeof(ATAPI_DEVICE_PATH)) &&
1706 (DevicePathNodeLength(DevicePath) != sizeof(SATA_DEVICE_PATH)))) {
1707 return EFI_UNSUPPORTED;
1708 }
1709
1710 DevicePathNode = (EFI_DEV_PATH *) DevicePath;
1711
1712 if (Instance->Mode == EfiAtaIdeMode) {
1713 *Port = DevicePathNode->Atapi.PrimarySecondary;
1714 *PortMultiplierPort = DevicePathNode->Atapi.SlaveMaster;
1715 } else {
1716 *Port = DevicePathNode->Sata.HBAPortNumber;
1717 *PortMultiplierPort = DevicePathNode->Sata.PortMultiplierPortNumber;
1718 }
1719
1720 Node = SearchDeviceInfoList(Instance, *Port, *PortMultiplierPort, EfiIdeHarddisk);
1721
1722 if (Node == NULL) {
1723 return EFI_NOT_FOUND;
1724 }
1725
1726 return EFI_SUCCESS;
1727 }
1728
1729 /**
1730 Resets a specific port on the ATA controller. This operation also resets all the ATA devices
1731 connected to the port.
1732
1733 The ResetChannel() function resets an a specific port on an ATA controller. This operation
1734 resets all the ATA devices connected to that port. If this ATA controller does not support
1735 a reset port operation, then EFI_UNSUPPORTED is returned.
1736
1737 If a device error occurs while executing that port reset operation, then EFI_DEVICE_ERROR is
1738 returned.
1739
1740 If a timeout occurs during the execution of the port reset operation, then EFI_TIMEOUT is returned.
1741
1742 If the port reset operation is completed, then EFI_SUCCESS is returned.
1743
1744 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1745 @param[in] Port The port number on the ATA controller.
1746
1747 @retval EFI_SUCCESS The ATA controller port was reset.
1748 @retval EFI_UNSUPPORTED The ATA controller does not support a port reset operation.
1749 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the ATA port.
1750 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the ATA port.
1751
1752 **/
1753 EFI_STATUS
1754 EFIAPI
1755 AtaPassThruResetPort (
1756 IN EFI_ATA_PASS_THRU_PROTOCOL *This,
1757 IN UINT16 Port
1758 )
1759 {
1760 return EFI_UNSUPPORTED;
1761 }
1762
1763 /**
1764 Resets an ATA device that is connected to an ATA controller.
1765
1766 The ResetDevice() function resets the ATA device specified by Port and PortMultiplierPort.
1767 If this ATA controller does not support a device reset operation, then EFI_UNSUPPORTED is
1768 returned.
1769
1770 If Port or PortMultiplierPort are not in a valid range for this ATA controller, then
1771 EFI_INVALID_PARAMETER is returned.
1772
1773 If a device error occurs while executing that device reset operation, then EFI_DEVICE_ERROR
1774 is returned.
1775
1776 If a timeout occurs during the execution of the device reset operation, then EFI_TIMEOUT is
1777 returned.
1778
1779 If the device reset operation is completed, then EFI_SUCCESS is returned.
1780
1781 @param[in] This A pointer to the EFI_ATA_PASS_THRU_PROTOCOL instance.
1782 @param[in] Port Port represents the port number of the ATA device to be reset.
1783 @param[in] PortMultiplierPort The port multiplier port number of the ATA device to reset.
1784 If there is no port multiplier, then specify 0.
1785 @retval EFI_SUCCESS The ATA device specified by Port and PortMultiplierPort was reset.
1786 @retval EFI_UNSUPPORTED The ATA controller does not support a device reset operation.
1787 @retval EFI_INVALID_PARAMETER Port or PortMultiplierPort are invalid.
1788 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the ATA device
1789 specified by Port and PortMultiplierPort.
1790 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the ATA device
1791 specified by Port and PortMultiplierPort.
1792
1793 **/
1794 EFI_STATUS
1795 EFIAPI
1796 AtaPassThruResetDevice (
1797 IN EFI_ATA_PASS_THRU_PROTOCOL *This,
1798 IN UINT16 Port,
1799 IN UINT16 PortMultiplierPort
1800 )
1801 {
1802 return EFI_UNSUPPORTED;
1803 }
1804
1805 /**
1806 Sends a SCSI Request Packet to a SCSI device that is attached to the SCSI channel. This function
1807 supports both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the
1808 nonblocking I/O functionality is optional.
1809
1810 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
1811 @param Target The Target is an array of size TARGET_MAX_BYTES and it represents
1812 the id of the SCSI device to send the SCSI Request Packet. Each
1813 transport driver may choose to utilize a subset of this size to suit the needs
1814 of transport target representation. For example, a Fibre Channel driver
1815 may use only 8 bytes (WWN) to represent an FC target.
1816 @param Lun The LUN of the SCSI device to send the SCSI Request Packet.
1817 @param Packet A pointer to the SCSI Request Packet to send to the SCSI device
1818 specified by Target and Lun.
1819 @param Event If nonblocking I/O is not supported then Event is ignored, and blocking
1820 I/O is performed. If Event is NULL, then blocking I/O is performed. If
1821 Event is not NULL and non blocking I/O is supported, then
1822 nonblocking I/O is performed, and Event will be signaled when the
1823 SCSI Request Packet completes.
1824
1825 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host. For bi-directional
1826 commands, InTransferLength bytes were transferred from
1827 InDataBuffer. For write and bi-directional commands,
1828 OutTransferLength bytes were transferred by
1829 OutDataBuffer.
1830 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was not executed. The number of bytes that
1831 could be transferred is returned in InTransferLength. For write
1832 and bi-directional commands, OutTransferLength bytes were
1833 transferred by OutDataBuffer.
1834 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
1835 SCSI Request Packets already queued. The caller may retry again later.
1836 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request
1837 Packet.
1838 @retval EFI_INVALID_PARAMETER Target, Lun, or the contents of ScsiRequestPacket are invalid.
1839 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported
1840 by the host adapter. This includes the case of Bi-directional SCSI
1841 commands not supported by the implementation. The SCSI Request
1842 Packet was not sent, so no additional status information is available.
1843 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
1844
1845 **/
1846 EFI_STATUS
1847 EFIAPI
1848 ExtScsiPassThruPassThru (
1849 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
1850 IN UINT8 *Target,
1851 IN UINT64 Lun,
1852 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,
1853 IN EFI_EVENT Event OPTIONAL
1854 )
1855 {
1856 EFI_STATUS Status;
1857 ATA_ATAPI_PASS_THRU_INSTANCE *Instance;
1858 UINT8 Port;
1859 UINT8 PortMultiplier;
1860 EFI_ATA_HC_WORK_MODE Mode;
1861 LIST_ENTRY *Node;
1862 EFI_ATA_DEVICE_INFO *DeviceInfo;
1863
1864 Instance = EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This);
1865
1866 if ((Packet == NULL) || (Packet->Cdb == NULL)) {
1867 return EFI_INVALID_PARAMETER;
1868 }
1869
1870 //
1871 // Don't support variable length CDB
1872 //
1873 if ((Packet->CdbLength != 6) && (Packet->CdbLength != 10) &&
1874 (Packet->CdbLength != 12) && (Packet->CdbLength != 16)) {
1875 return EFI_INVALID_PARAMETER;
1876 }
1877
1878 if ((This->Mode->IoAlign > 1) && !IS_ALIGNED(Packet->InDataBuffer, This->Mode->IoAlign)) {
1879 return EFI_INVALID_PARAMETER;
1880 }
1881
1882 if ((This->Mode->IoAlign > 1) && !IS_ALIGNED(Packet->OutDataBuffer, This->Mode->IoAlign)) {
1883 return EFI_INVALID_PARAMETER;
1884 }
1885
1886 if ((This->Mode->IoAlign > 1) && !IS_ALIGNED(Packet->SenseData, This->Mode->IoAlign)) {
1887 return EFI_INVALID_PARAMETER;
1888 }
1889
1890 //
1891 // For ATAPI device, doesn't support multiple LUN device.
1892 //
1893 if (Lun != 0) {
1894 return EFI_INVALID_PARAMETER;
1895 }
1896
1897 //
1898 // The layout of Target array:
1899 // ________________________________________________________________________
1900 // | Byte 0 | Byte 1 | ... | TARGET_MAX_BYTES - 1 |
1901 // |_____________________|_____________________|_____|______________________|
1902 // | | The port multiplier | | |
1903 // | The port number | port number | N/A | N/A |
1904 // |_____________________|_____________________|_____|______________________|
1905 //
1906 // For ATAPI device, 2 bytes is enough to represent the location of SCSI device.
1907 //
1908 Port = Target[0];
1909 PortMultiplier = Target[1];
1910
1911 Node = SearchDeviceInfoList(Instance, Port, PortMultiplier, EfiIdeCdrom);
1912 if (Node == NULL) {
1913 return EFI_INVALID_PARAMETER;
1914 }
1915
1916 DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);
1917
1918 //
1919 // ATA_CMD_IDENTIFY_DEVICE cmd is a ATA cmd but not a SCSI cmd.
1920 // Normally it should NOT be passed down through ExtScsiPassThru protocol interface.
1921 // But to response EFI_DISK_INFO.Identify() request from ScsiDisk, we should handle this command.
1922 //
1923 if (*((UINT8*)Packet->Cdb) == ATA_CMD_IDENTIFY_DEVICE) {
1924 CopyMem (Packet->InDataBuffer, DeviceInfo->IdentifyData, sizeof (EFI_IDENTIFY_DATA));
1925 return EFI_SUCCESS;
1926 }
1927
1928 Mode = Instance->Mode;
1929 switch (Mode) {
1930 case EfiAtaIdeMode:
1931 //
1932 // Reassign IDE mode io port registers' base addresses
1933 //
1934 Status = GetIdeRegisterIoAddr (Instance->PciIo, Instance->IdeRegisters);
1935
1936 if (EFI_ERROR (Status)) {
1937 return Status;
1938 }
1939
1940 Status = AtaPacketCommandExecute (Instance->PciIo, &Instance->IdeRegisters[Port], Port, PortMultiplier, Packet);
1941 break;
1942 case EfiAtaAhciMode:
1943 Status = AhciPacketCommandExecute (Instance->PciIo, &Instance->AhciRegisters, Port, PortMultiplier, Packet);
1944 break;
1945 default :
1946 Status = EFI_DEVICE_ERROR;
1947 break;
1948 }
1949
1950 return Status;
1951 }
1952
1953 /**
1954 Used to retrieve the list of legal Target IDs and LUNs for SCSI devices on a SCSI channel. These
1955 can either be the list SCSI devices that are actually present on the SCSI channel, or the list of legal
1956 Target Ids and LUNs for the SCSI channel. Regardless, the caller of this function must probe the
1957 Target ID and LUN returned to see if a SCSI device is actually present at that location on the SCSI
1958 channel.
1959
1960 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
1961 @param Target On input, a pointer to the Target ID (an array of size
1962 TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.
1963 On output, a pointer to the Target ID (an array of
1964 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI
1965 channel. An input value of 0xF(all bytes in the array are 0xF) in the
1966 Target array retrieves the Target ID of the first SCSI device present on a
1967 SCSI channel.
1968 @param Lun On input, a pointer to the LUN of a SCSI device present on the SCSI
1969 channel. On output, a pointer to the LUN of the next SCSI device present
1970 on a SCSI channel.
1971
1972 @retval EFI_SUCCESS The Target ID and LUN of the next SCSI device on the SCSI
1973 channel was returned in Target and Lun.
1974 @retval EFI_INVALID_PARAMETER Target array is not all 0xF, and Target and Lun were
1975 not returned on a previous call to GetNextTargetLun().
1976 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.
1977
1978 **/
1979 EFI_STATUS
1980 EFIAPI
1981 ExtScsiPassThruGetNextTargetLun (
1982 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
1983 IN OUT UINT8 **Target,
1984 IN OUT UINT64 *Lun
1985 )
1986 {
1987 ATA_ATAPI_PASS_THRU_INSTANCE *Instance;
1988 LIST_ENTRY *Node;
1989 EFI_ATA_DEVICE_INFO *DeviceInfo;
1990 UINT8 *Target8;
1991 UINT16 *Target16;
1992
1993 Instance = EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This);
1994
1995 if (Target == NULL || Lun == NULL) {
1996 return EFI_INVALID_PARAMETER;
1997 }
1998
1999 if (*Target == NULL) {
2000 return EFI_INVALID_PARAMETER;
2001 }
2002
2003 Target8 = *Target;
2004 Target16 = (UINT16 *)*Target;
2005
2006 if (CompareMem(Target8, mScsiId, TARGET_MAX_BYTES) != 0) {
2007 //
2008 // For ATAPI device, we use 2 least significant bytes to represent the location of SCSI device.
2009 // So the higher bytes in Target array should be 0xFF.
2010 //
2011 if (CompareMem (&Target8[2], &mScsiId[2], TARGET_MAX_BYTES - 2) != 0) {
2012 return EFI_INVALID_PARAMETER;
2013 }
2014
2015 //
2016 // When Target is not all 0xFF's, compare 2 least significant bytes with
2017 // previous target id to see if it is returned by previous call.
2018 //
2019 if ((*Target16 != Instance->PreviousTargetId) ||
2020 (*Lun != Instance->PreviousLun)) {
2021 return EFI_INVALID_PARAMETER;
2022 }
2023
2024 //
2025 // Traverse the whole device list to find the next cdrom closed to
2026 // the device signified by Target[0] and Target[1].
2027 //
2028 // Note that we here use a tricky way to find the next cdrom :
2029 // All ata devices are detected and inserted into the device list
2030 // sequentially.
2031 //
2032 Node = GetFirstNode (&Instance->DeviceList);
2033
2034 while (!IsNull (&Instance->DeviceList, Node)) {
2035 DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);
2036
2037 if ((DeviceInfo->Type == EfiIdeCdrom) &&
2038 ((Target8[0] < DeviceInfo->Port) ||
2039 ((Target8[0] == DeviceInfo->Port) &&
2040 (Target8[1] < DeviceInfo->PortMultiplier)))) {
2041 Target8[0] = (UINT8)DeviceInfo->Port;
2042 Target8[1] = (UINT8)DeviceInfo->PortMultiplier;
2043 goto Exit;
2044 }
2045
2046 Node = GetNextNode (&Instance->DeviceList, Node);
2047 }
2048
2049 return EFI_NOT_FOUND;
2050 } else {
2051 //
2052 // If the array is all 0xFF's, start to traverse the device list from the beginning
2053 //
2054 Node = GetFirstNode (&Instance->DeviceList);
2055 while (!IsNull (&Instance->DeviceList, Node)) {
2056 DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);
2057
2058 if (DeviceInfo->Type == EfiIdeCdrom) {
2059 Target8[0] = (UINT8)DeviceInfo->Port;
2060 Target8[1] = (UINT8)DeviceInfo->PortMultiplier;
2061 goto Exit;
2062 }
2063
2064 Node = GetNextNode (&Instance->DeviceList, Node);
2065 }
2066
2067 return EFI_NOT_FOUND;
2068 }
2069
2070 Exit:
2071 *Lun = 0;
2072
2073 //
2074 // Update the PreviousTargetId.
2075 //
2076 Instance->PreviousTargetId = *Target16;
2077 Instance->PreviousLun = *Lun;
2078
2079 return EFI_SUCCESS;
2080 }
2081
2082 /**
2083 Used to allocate and build a device path node for a SCSI device on a SCSI channel.
2084
2085 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
2086 @param Target The Target is an array of size TARGET_MAX_BYTES and it specifies the
2087 Target ID of the SCSI device for which a device path node is to be
2088 allocated and built. Transport drivers may chose to utilize a subset of
2089 this size to suit the representation of targets. For example, a Fibre
2090 Channel driver may use only 8 bytes (WWN) in the array to represent a
2091 FC target.
2092 @param Lun The LUN of the SCSI device for which a device path node is to be
2093 allocated and built.
2094 @param DevicePath A pointer to a single device path node that describes the SCSI device
2095 specified by Target and Lun. This function is responsible for
2096 allocating the buffer DevicePath with the boot service
2097 AllocatePool(). It is the caller's responsibility to free
2098 DevicePath when the caller is finished with DevicePath.
2099
2100 @retval EFI_SUCCESS The device path node that describes the SCSI device specified by
2101 Target and Lun was allocated and returned in
2102 DevicePath.
2103 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
2104 @retval EFI_NOT_FOUND The SCSI devices specified by Target and Lun does not exist
2105 on the SCSI channel.
2106 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.
2107
2108 **/
2109 EFI_STATUS
2110 EFIAPI
2111 ExtScsiPassThruBuildDevicePath (
2112 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
2113 IN UINT8 *Target,
2114 IN UINT64 Lun,
2115 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
2116 )
2117 {
2118 EFI_DEV_PATH *DevicePathNode;
2119 ATA_ATAPI_PASS_THRU_INSTANCE *Instance;
2120 UINT8 Port;
2121 UINT8 PortMultiplier;
2122
2123 Instance = EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This);
2124
2125 Port = Target[0];
2126 PortMultiplier = Target[1];
2127
2128 //
2129 // Validate parameters passed in.
2130 //
2131 if (DevicePath == NULL) {
2132 return EFI_INVALID_PARAMETER;
2133 }
2134
2135 //
2136 // can not build device path for the SCSI Host Controller.
2137 //
2138 if (Lun != 0) {
2139 return EFI_NOT_FOUND;
2140 }
2141
2142 if (SearchDeviceInfoList(Instance, Port, PortMultiplier, EfiIdeCdrom) == NULL) {
2143 return EFI_NOT_FOUND;
2144 }
2145
2146 if (Instance->Mode == EfiAtaIdeMode) {
2147 DevicePathNode = AllocateCopyPool (sizeof (ATAPI_DEVICE_PATH), &mAtapiDevicePathTemplate);
2148 if (DevicePathNode == NULL) {
2149 return EFI_OUT_OF_RESOURCES;
2150 }
2151
2152 DevicePathNode->Atapi.PrimarySecondary = Port;
2153 DevicePathNode->Atapi.SlaveMaster = PortMultiplier;
2154 DevicePathNode->Atapi.Lun = (UINT16) Lun;
2155 } else {
2156 DevicePathNode = AllocateCopyPool (sizeof (SATA_DEVICE_PATH), &mSataDevicePathTemplate);
2157 if (DevicePathNode == NULL) {
2158 return EFI_OUT_OF_RESOURCES;
2159 }
2160
2161 DevicePathNode->Sata.HBAPortNumber = Port;
2162 DevicePathNode->Sata.PortMultiplierPortNumber = PortMultiplier;
2163 DevicePathNode->Sata.Lun = (UINT16) Lun;
2164 }
2165
2166 *DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) DevicePathNode;
2167
2168 return EFI_SUCCESS;
2169 }
2170
2171 /**
2172 Used to translate a device path node to a Target ID and LUN.
2173
2174 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
2175 @param DevicePath A pointer to a single device path node that describes the SCSI device
2176 on the SCSI channel.
2177 @param Target A pointer to the Target Array which represents the ID of a SCSI device
2178 on the SCSI channel.
2179 @param Lun A pointer to the LUN of a SCSI device on the SCSI channel.
2180
2181 @retval EFI_SUCCESS DevicePath was successfully translated to a Target ID and
2182 LUN, and they were returned in Target and Lun.
2183 @retval EFI_INVALID_PARAMETER DevicePath or Target or Lun is NULL.
2184 @retval EFI_NOT_FOUND A valid translation from DevicePath to a Target ID and LUN
2185 does not exist.
2186 @retval EFI_UNSUPPORTED This driver does not support the device path node type in
2187 DevicePath.
2188
2189 **/
2190 EFI_STATUS
2191 EFIAPI
2192 ExtScsiPassThruGetTargetLun (
2193 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
2194 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
2195 OUT UINT8 **Target,
2196 OUT UINT64 *Lun
2197 )
2198 {
2199 EFI_DEV_PATH *DevicePathNode;
2200 ATA_ATAPI_PASS_THRU_INSTANCE *Instance;
2201 LIST_ENTRY *Node;
2202
2203 Instance = EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This);
2204
2205 //
2206 // Validate parameters passed in.
2207 //
2208 if (DevicePath == NULL || Target == NULL || Lun == NULL) {
2209 return EFI_INVALID_PARAMETER;
2210 }
2211
2212 if (*Target == NULL) {
2213 return EFI_INVALID_PARAMETER;
2214 }
2215 //
2216 // Check whether the DevicePath belongs to SCSI_DEVICE_PATH
2217 //
2218 if ((DevicePath->Type != MESSAGING_DEVICE_PATH) ||
2219 ((DevicePath->SubType != MSG_ATAPI_DP) &&
2220 (DevicePath->SubType != MSG_SATA_DP)) ||
2221 ((DevicePathNodeLength(DevicePath) != sizeof(ATAPI_DEVICE_PATH)) &&
2222 (DevicePathNodeLength(DevicePath) != sizeof(SATA_DEVICE_PATH)))) {
2223 return EFI_UNSUPPORTED;
2224 }
2225
2226 SetMem (*Target, TARGET_MAX_BYTES, 0xFF);
2227
2228 DevicePathNode = (EFI_DEV_PATH *) DevicePath;
2229
2230 if (Instance->Mode == EfiAtaIdeMode) {
2231 (*Target)[0] = (UINT8) DevicePathNode->Atapi.PrimarySecondary;
2232 (*Target)[1] = (UINT8) DevicePathNode->Atapi.SlaveMaster;
2233 *Lun = (UINT8) DevicePathNode->Atapi.Lun;
2234 } else {
2235 (*Target)[0] = (UINT8) DevicePathNode->Sata.HBAPortNumber;
2236 (*Target)[1] = (UINT8) DevicePathNode->Sata.PortMultiplierPortNumber;
2237 *Lun = (UINT8) DevicePathNode->Sata.Lun;
2238 }
2239
2240 Node = SearchDeviceInfoList(Instance, (*Target)[0], (*Target)[1], EfiIdeCdrom);
2241
2242 if (Node == NULL) {
2243 return EFI_NOT_FOUND;
2244 }
2245
2246 if (*Lun != 0) {
2247 return EFI_NOT_FOUND;
2248 }
2249
2250 return EFI_SUCCESS;
2251 }
2252
2253 /**
2254 Resets a SCSI channel. This operation resets all the SCSI devices connected to the SCSI channel.
2255
2256 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
2257
2258 @retval EFI_SUCCESS The SCSI channel was reset.
2259 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI channel.
2260 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI channel.
2261 @retval EFI_UNSUPPORTED The SCSI channel does not support a channel reset operation.
2262
2263 **/
2264 EFI_STATUS
2265 EFIAPI
2266 ExtScsiPassThruResetChannel (
2267 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This
2268 )
2269 {
2270 return EFI_UNSUPPORTED;
2271 }
2272
2273 /**
2274 Resets a SCSI logical unit that is connected to a SCSI channel.
2275
2276 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
2277 @param Target The Target is an array of size TARGET_MAX_BYTE and it represents the
2278 target port ID of the SCSI device containing the SCSI logical unit to
2279 reset. Transport drivers may chose to utilize a subset of this array to suit
2280 the representation of their targets.
2281 @param Lun The LUN of the SCSI device to reset.
2282
2283 @retval EFI_SUCCESS The SCSI device specified by Target and Lun was reset.
2284 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.
2285 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI device
2286 specified by Target and Lun.
2287 @retval EFI_UNSUPPORTED The SCSI channel does not support a target reset operation.
2288 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI device
2289 specified by Target and Lun.
2290
2291 **/
2292 EFI_STATUS
2293 EFIAPI
2294 ExtScsiPassThruResetTargetLun (
2295 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
2296 IN UINT8 *Target,
2297 IN UINT64 Lun
2298 )
2299 {
2300 return EFI_UNSUPPORTED;
2301 }
2302
2303 /**
2304 Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI channel. These can either
2305 be the list SCSI devices that are actually present on the SCSI channel, or the list of legal Target IDs
2306 for the SCSI channel. Regardless, the caller of this function must probe the Target ID returned to
2307 see if a SCSI device is actually present at that location on the SCSI channel.
2308
2309 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
2310 @param Target (TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.
2311 On output, a pointer to the Target ID (an array of
2312 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI
2313 channel. An input value of 0xF(all bytes in the array are 0xF) in the
2314 Target array retrieves the Target ID of the first SCSI device present on a
2315 SCSI channel.
2316
2317 @retval EFI_SUCCESS The Target ID of the next SCSI device on the SCSI
2318 channel was returned in Target.
2319 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.
2320 @retval EFI_TIMEOUT Target array is not all 0xF, and Target was not
2321 returned on a previous call to GetNextTarget().
2322 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.
2323
2324 **/
2325 EFI_STATUS
2326 EFIAPI
2327 ExtScsiPassThruGetNextTarget (
2328 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
2329 IN OUT UINT8 **Target
2330 )
2331 {
2332 ATA_ATAPI_PASS_THRU_INSTANCE *Instance;
2333 LIST_ENTRY *Node;
2334 EFI_ATA_DEVICE_INFO *DeviceInfo;
2335 UINT8 *Target8;
2336 UINT16 *Target16;
2337
2338 Instance = EXT_SCSI_PASS_THRU_PRIVATE_DATA_FROM_THIS (This);
2339
2340 if (Target == NULL || *Target == NULL) {
2341 return EFI_INVALID_PARAMETER;
2342 }
2343
2344 Target8 = *Target;
2345 Target16 = (UINT16 *)*Target;
2346
2347 if (CompareMem(Target8, mScsiId, TARGET_MAX_BYTES) != 0) {
2348 //
2349 // For ATAPI device, we use 2 least significant bytes to represent the location of SCSI device.
2350 // So the higher bytes in Target array should be 0xFF.
2351 //
2352 if (CompareMem (&Target8[2], &mScsiId[2], TARGET_MAX_BYTES - 2) != 0) {
2353 return EFI_INVALID_PARAMETER;
2354 }
2355
2356 //
2357 // When Target is not all 0xFF's, compare 2 least significant bytes with
2358 // previous target id to see if it is returned by previous call.
2359 //
2360 if (*Target16 != Instance->PreviousTargetId) {
2361 return EFI_INVALID_PARAMETER;
2362 }
2363
2364 //
2365 // Traverse the whole device list to find the next cdrom closed to
2366 // the device signified by Target[0] and Target[1].
2367 //
2368 // Note that we here use a tricky way to find the next cdrom :
2369 // All ata devices are detected and inserted into the device list
2370 // sequentially.
2371 //
2372 Node = GetFirstNode (&Instance->DeviceList);
2373 while (!IsNull (&Instance->DeviceList, Node)) {
2374 DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);
2375
2376 if ((DeviceInfo->Type == EfiIdeCdrom) &&
2377 ((Target8[0] < DeviceInfo->Port) ||
2378 ((Target8[0] == DeviceInfo->Port) &&
2379 (Target8[1] < DeviceInfo->PortMultiplier)))) {
2380 Target8[0] = (UINT8)DeviceInfo->Port;
2381 Target8[1] = (UINT8)DeviceInfo->PortMultiplier;
2382 goto Exit;
2383 }
2384
2385 Node = GetNextNode (&Instance->DeviceList, Node);
2386 }
2387
2388 return EFI_NOT_FOUND;
2389 } else {
2390 //
2391 // If the array is all 0xFF's, start to traverse the device list from the beginning
2392 //
2393 Node = GetFirstNode (&Instance->DeviceList);
2394
2395 while (!IsNull (&Instance->DeviceList, Node)) {
2396 DeviceInfo = ATA_ATAPI_DEVICE_INFO_FROM_THIS (Node);
2397
2398 if (DeviceInfo->Type == EfiIdeCdrom) {
2399 Target8[0] = (UINT8)DeviceInfo->Port;
2400 Target8[1] = (UINT8)DeviceInfo->PortMultiplier;
2401 goto Exit;
2402 }
2403
2404 Node = GetNextNode (&Instance->DeviceList, Node);
2405 }
2406
2407 return EFI_NOT_FOUND;
2408 }
2409
2410 Exit:
2411 //
2412 // Update the PreviousTargetId.
2413 //
2414 Instance->PreviousTargetId = *Target16;
2415
2416 return EFI_SUCCESS;
2417 }
2418