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