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