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