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