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