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