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