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