]>
Commit | Line | Data |
---|---|---|
ad86a50a | 1 | /** @file\r |
2 | This file implements protocol interfaces for ATA bus driver.\r | |
58727f29 | 3 | \r |
ad86a50a | 4 | This file implements protocol interfaces: Driver Binding protocol,\r |
5 | Block IO protocol and DiskInfo protocol.\r | |
58727f29 | 6 | \r |
8908e764 | 7 | Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r |
cd5ebaa0 | 8 | This program and the accompanying materials\r |
ad86a50a | 9 | are licensed and made available under the terms and conditions of the BSD License\r |
10 | which accompanies this distribution. The full text of the license may be found at\r | |
11 | http://opensource.org/licenses/bsd-license.php\r | |
12 | \r | |
13 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
14 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
15 | \r | |
16 | \r | |
17 | **/\r | |
18 | \r | |
19 | #include "AtaBus.h"\r | |
20 | \r | |
90398d55 | 21 | UINT8 mMorControl;\r |
90398d55 | 22 | \r |
ad86a50a | 23 | //\r |
24 | // ATA Bus Driver Binding Protocol Instance\r | |
25 | //\r | |
26 | EFI_DRIVER_BINDING_PROTOCOL gAtaBusDriverBinding = {\r | |
27 | AtaBusDriverBindingSupported,\r | |
28 | AtaBusDriverBindingStart,\r | |
29 | AtaBusDriverBindingStop,\r | |
30 | 0x10,\r | |
31 | NULL,\r | |
32 | NULL\r | |
33 | };\r | |
34 | \r | |
35 | //\r | |
36 | // Template for ATA Child Device.\r | |
37 | //\r | |
38 | ATA_DEVICE gAtaDeviceTemplate = {\r | |
05a44e91 | 39 | ATA_DEVICE_SIGNATURE, // Signature\r |
40 | NULL, // Handle\r | |
ad86a50a | 41 | { // BlockIo\r |
42 | EFI_BLOCK_IO_PROTOCOL_REVISION,\r | |
43 | NULL,\r | |
44 | AtaBlockIoReset,\r | |
45 | AtaBlockIoReadBlocks,\r | |
46 | AtaBlockIoWriteBlocks,\r | |
47 | AtaBlockIoFlushBlocks\r | |
48 | },\r | |
490b5ea1 | 49 | { // BlockIo2\r |
50 | NULL,\r | |
51 | AtaBlockIoResetEx,\r | |
52 | AtaBlockIoReadBlocksEx,\r | |
53 | AtaBlockIoWriteBlocksEx,\r | |
54 | AtaBlockIoFlushBlocksEx\r | |
55 | },\r | |
ad86a50a | 56 | { // BlockMedia\r |
57 | 0, // MediaId\r | |
58 | FALSE, // RemovableMedia\r | |
59 | TRUE, // MediaPresent\r | |
60 | FALSE, // LogicPartition\r | |
61 | FALSE, // ReadOnly\r | |
62 | FALSE, // WritingCache\r | |
58727f29 | 63 | 0x200, // BlockSize\r |
907c1a00 | 64 | 0, // IoAlign\r |
3bfa77f0 | 65 | 0, // LastBlock\r |
66 | 0, // LowestAlignedLba\r | |
67 | 1 // LogicalBlocksPerPhysicalBlock\r | |
ad86a50a | 68 | },\r |
69 | { // DiskInfo\r | |
70 | EFI_DISK_INFO_IDE_INTERFACE_GUID,\r | |
71 | AtaDiskInfoInquiry,\r | |
72 | AtaDiskInfoIdentify,\r | |
73 | AtaDiskInfoSenseData,\r | |
74 | AtaDiskInfoWhichIde\r | |
75 | },\r | |
05a44e91 | 76 | NULL, // DevicePath\r |
c24097a5 | 77 | {\r |
78 | AtaStorageSecurityReceiveData,\r | |
79 | AtaStorageSecuritySendData\r | |
80 | },\r | |
05a44e91 | 81 | NULL, // AtaBusDriverData\r |
82 | 0, // Port\r | |
83 | 0, // PortMultiplierPort\r | |
ad86a50a | 84 | { 0, }, // Packet\r |
85 | {{ 0}, }, // Acb\r | |
86 | NULL, // Asb\r | |
87 | FALSE, // UdmaValid\r | |
88 | FALSE, // Lba48Bit\r | |
89 | NULL, // IdentifyData\r | |
90 | NULL, // ControllerNameTable\r | |
490b5ea1 | 91 | {L'\0', }, // ModelName\r |
58727f29 | 92 | {NULL, NULL}, // AtaTaskList\r |
93 | {NULL, NULL} // AtaSubTaskList\r | |
ad86a50a | 94 | };\r |
95 | \r | |
96 | /**\r | |
97 | Allocates an aligned buffer for ATA device.\r | |
98 | \r | |
99 | This function allocates an aligned buffer for the ATA device to perform\r | |
100 | ATA pass through operations. The alignment requirement is from ATA pass\r | |
101 | through interface.\r | |
102 | \r | |
103 | @param AtaDevice The ATA child device involved for the operation.\r | |
104 | @param BufferSize The request buffer size.\r | |
105 | \r | |
106 | @return A pointer to the aligned buffer or NULL if the allocation fails.\r | |
107 | \r | |
108 | **/\r | |
109 | VOID *\r | |
110 | AllocateAlignedBuffer (\r | |
111 | IN ATA_DEVICE *AtaDevice,\r | |
112 | IN UINTN BufferSize\r | |
113 | )\r | |
114 | {\r | |
115 | return AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), AtaDevice->AtaBusDriverData->AtaPassThru->Mode->IoAlign);\r | |
116 | }\r | |
117 | \r | |
118 | /**\r | |
119 | Frees an aligned buffer for ATA device.\r | |
120 | \r | |
121 | This function frees an aligned buffer for the ATA device to perform\r | |
122 | ATA pass through operations.\r | |
123 | \r | |
05a44e91 | 124 | @param Buffer The aligned buffer to be freed.\r |
ad86a50a | 125 | @param BufferSize The request buffer size.\r |
126 | \r | |
127 | **/\r | |
128 | VOID\r | |
129 | FreeAlignedBuffer (\r | |
130 | IN VOID *Buffer,\r | |
131 | IN UINTN BufferSize\r | |
132 | )\r | |
133 | {\r | |
134 | if (Buffer != NULL) {\r | |
957fe093 | 135 | FreeAlignedPages (Buffer, EFI_SIZE_TO_PAGES (BufferSize));\r |
ad86a50a | 136 | }\r |
137 | }\r | |
138 | \r | |
139 | \r | |
140 | /**\r | |
141 | Release all the resources allocated for the ATA device.\r | |
142 | \r | |
143 | This function releases all the resources allocated for the ATA device.\r | |
144 | \r | |
145 | @param AtaDevice The ATA child device involved for the operation.\r | |
146 | \r | |
147 | **/\r | |
148 | VOID\r | |
149 | ReleaseAtaResources (\r | |
150 | IN ATA_DEVICE *AtaDevice\r | |
151 | )\r | |
152 | {\r | |
58727f29 | 153 | ATA_BUS_ASYN_SUB_TASK *SubTask;\r |
154 | ATA_BUS_ASYN_TASK *AtaTask;\r | |
155 | LIST_ENTRY *Entry;\r | |
156 | LIST_ENTRY *DelEntry;\r | |
157 | EFI_TPL OldTpl;\r | |
490b5ea1 | 158 | \r |
ad86a50a | 159 | FreeUnicodeStringTable (AtaDevice->ControllerNameTable);\r |
3c063fed | 160 | FreeAlignedBuffer (AtaDevice->Asb, sizeof (EFI_ATA_STATUS_BLOCK));\r |
161 | FreeAlignedBuffer (AtaDevice->IdentifyData, sizeof (ATA_IDENTIFY_DATA));\r | |
ad86a50a | 162 | if (AtaDevice->DevicePath != NULL) {\r |
163 | FreePool (AtaDevice->DevicePath);\r | |
164 | }\r | |
490b5ea1 | 165 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY);\r |
58727f29 | 166 | if (!IsListEmpty (&AtaDevice->AtaSubTaskList)) {\r |
167 | //\r | |
168 | // Free the Subtask list.\r | |
169 | //\r | |
170 | for(Entry = AtaDevice->AtaSubTaskList.ForwardLink;\r | |
171 | Entry != (&AtaDevice->AtaSubTaskList);\r | |
172 | ) {\r | |
173 | DelEntry = Entry;\r | |
174 | Entry = Entry->ForwardLink;\r | |
175 | SubTask = ATA_AYNS_SUB_TASK_FROM_ENTRY (DelEntry);\r | |
176 | \r | |
177 | RemoveEntryList (DelEntry);\r | |
178 | FreeAtaSubTask (SubTask);\r | |
179 | }\r | |
180 | }\r | |
490b5ea1 | 181 | if (!IsListEmpty (&AtaDevice->AtaTaskList)) {\r |
182 | //\r | |
183 | // Free the Subtask list.\r | |
184 | //\r | |
58727f29 | 185 | for(Entry = AtaDevice->AtaTaskList.ForwardLink;\r |
490b5ea1 | 186 | Entry != (&AtaDevice->AtaTaskList);\r |
187 | ) {\r | |
188 | DelEntry = Entry;\r | |
189 | Entry = Entry->ForwardLink;\r | |
58727f29 | 190 | AtaTask = ATA_AYNS_TASK_FROM_ENTRY (DelEntry);\r |
191 | \r | |
490b5ea1 | 192 | RemoveEntryList (DelEntry);\r |
58727f29 | 193 | FreePool (AtaTask);\r |
490b5ea1 | 194 | }\r |
195 | }\r | |
196 | gBS->RestoreTPL (OldTpl);\r | |
ad86a50a | 197 | FreePool (AtaDevice);\r |
198 | }\r | |
199 | \r | |
200 | \r | |
201 | /**\r | |
202 | Registers an ATA device.\r | |
203 | \r | |
204 | This function allocates an ATA device structure for the ATA device specified by\r | |
58727f29 | 205 | Port and PortMultiplierPort if the ATA device is identified as a valid one.\r |
ad86a50a | 206 | Then it will create child handle and install Block IO and Disk Info protocol on\r |
207 | it.\r | |
208 | \r | |
05a44e91 | 209 | @param AtaBusDriverData The parent ATA bus driver data structure.\r |
ad86a50a | 210 | @param Port The port number of the ATA device.\r |
211 | @param PortMultiplierPort The port multiplier port number of the ATA device.\r | |
212 | \r | |
213 | @retval EFI_SUCCESS The ATA device is successfully registered.\r | |
214 | @retval EFI_OUT_OF_RESOURCES There is not enough memory to allocate the ATA device\r | |
215 | and related data structures.\r | |
216 | @return Others Some error occurs when registering the ATA device.\r | |
217 | **/\r | |
218 | EFI_STATUS\r | |
219 | RegisterAtaDevice (\r | |
220 | IN OUT ATA_BUS_DRIVER_DATA *AtaBusDriverData,\r | |
221 | IN UINT16 Port,\r | |
222 | IN UINT16 PortMultiplierPort\r | |
223 | )\r | |
224 | {\r | |
225 | EFI_STATUS Status;\r | |
226 | ATA_DEVICE *AtaDevice;\r | |
227 | EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThru;\r | |
228 | EFI_DEVICE_PATH_PROTOCOL *NewDevicePathNode;\r | |
e519983a | 229 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r |
230 | EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;\r | |
231 | EFI_HANDLE DeviceHandle;\r | |
ad86a50a | 232 | \r |
e519983a | 233 | AtaDevice = NULL;\r |
ad86a50a | 234 | NewDevicePathNode = NULL;\r |
e519983a | 235 | DevicePath = NULL;\r |
236 | RemainingDevicePath = NULL;\r | |
237 | \r | |
238 | //\r | |
58727f29 | 239 | // Build device path\r |
e519983a | 240 | //\r |
241 | AtaPassThru = AtaBusDriverData->AtaPassThru;\r | |
242 | Status = AtaPassThru->BuildDevicePath (AtaPassThru, Port, PortMultiplierPort, &NewDevicePathNode);\r | |
243 | if (EFI_ERROR (Status)) {\r | |
244 | goto Done;\r | |
245 | }\r | |
246 | \r | |
247 | DevicePath = AppendDevicePathNode (AtaBusDriverData->ParentDevicePath, NewDevicePathNode);\r | |
248 | if (DevicePath == NULL) {\r | |
e70ae46c | 249 | Status = EFI_OUT_OF_RESOURCES;\r |
e519983a | 250 | goto Done;\r |
251 | }\r | |
252 | \r | |
253 | DeviceHandle = NULL;\r | |
e70ae46c | 254 | RemainingDevicePath = DevicePath;\r |
e519983a | 255 | Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &DeviceHandle);\r |
256 | if (!EFI_ERROR (Status) && (DeviceHandle != NULL) && IsDevicePathEnd(RemainingDevicePath)) {\r | |
257 | Status = EFI_ALREADY_STARTED;\r | |
e70ae46c | 258 | FreePool (DevicePath);\r |
e519983a | 259 | goto Done;\r |
260 | }\r | |
ad86a50a | 261 | \r |
262 | //\r | |
263 | // Allocate ATA device from the template.\r | |
264 | //\r | |
3c063fed | 265 | AtaDevice = AllocateCopyPool (sizeof (ATA_DEVICE), &gAtaDeviceTemplate);\r |
ad86a50a | 266 | if (AtaDevice == NULL) {\r |
e519983a | 267 | Status = EFI_OUT_OF_RESOURCES;\r |
268 | goto Done;\r | |
ad86a50a | 269 | }\r |
270 | \r | |
271 | //\r | |
272 | // Initializes ATA device structures and allocates the required buffer.\r | |
273 | //\r | |
490b5ea1 | 274 | AtaDevice->BlockIo.Media = &AtaDevice->BlockMedia;\r |
275 | AtaDevice->BlockIo2.Media = &AtaDevice->BlockMedia;\r | |
276 | AtaDevice->AtaBusDriverData = AtaBusDriverData;\r | |
277 | AtaDevice->DevicePath = DevicePath;\r | |
278 | AtaDevice->Port = Port;\r | |
ad86a50a | 279 | AtaDevice->PortMultiplierPort = PortMultiplierPort;\r |
3c063fed | 280 | AtaDevice->Asb = AllocateAlignedBuffer (AtaDevice, sizeof (EFI_ATA_STATUS_BLOCK));\r |
ad86a50a | 281 | if (AtaDevice->Asb == NULL) {\r |
282 | Status = EFI_OUT_OF_RESOURCES;\r | |
283 | goto Done;\r | |
284 | }\r | |
3c063fed | 285 | AtaDevice->IdentifyData = AllocateAlignedBuffer (AtaDevice, sizeof (ATA_IDENTIFY_DATA));\r |
ad86a50a | 286 | if (AtaDevice->IdentifyData == NULL) {\r |
287 | Status = EFI_OUT_OF_RESOURCES;\r | |
288 | goto Done;\r | |
289 | }\r | |
290 | \r | |
490b5ea1 | 291 | //\r |
292 | // Initial Ata Task List\r | |
293 | //\r | |
294 | InitializeListHead (&AtaDevice->AtaTaskList);\r | |
58727f29 | 295 | InitializeListHead (&AtaDevice->AtaSubTaskList);\r |
490b5ea1 | 296 | \r |
37623a5c | 297 | //\r |
298 | // Report Status Code to indicate the ATA device will be enabled\r | |
299 | //\r | |
300 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
301 | EFI_PROGRESS_CODE,\r | |
302 | (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_PC_ENABLE),\r | |
303 | AtaBusDriverData->ParentDevicePath\r | |
304 | );\r | |
305 | \r | |
ad86a50a | 306 | //\r |
58727f29 | 307 | // Try to identify the ATA device via the ATA pass through command.\r |
ad86a50a | 308 | //\r |
309 | Status = DiscoverAtaDevice (AtaDevice);\r | |
310 | if (EFI_ERROR (Status)) {\r | |
311 | goto Done;\r | |
312 | }\r | |
490b5ea1 | 313 | \r |
ad86a50a | 314 | //\r |
315 | // Build controller name for Component Name (2) protocol.\r | |
316 | //\r | |
317 | Status = AddUnicodeString2 (\r | |
318 | "eng",\r | |
319 | gAtaBusComponentName.SupportedLanguages,\r | |
320 | &AtaDevice->ControllerNameTable,\r | |
321 | AtaDevice->ModelName,\r | |
322 | TRUE\r | |
323 | );\r | |
324 | if (EFI_ERROR (Status)) {\r | |
325 | goto Done;\r | |
326 | }\r | |
327 | \r | |
328 | Status = AddUnicodeString2 (\r | |
329 | "en",\r | |
330 | gAtaBusComponentName2.SupportedLanguages,\r | |
331 | &AtaDevice->ControllerNameTable,\r | |
332 | AtaDevice->ModelName,\r | |
333 | FALSE\r | |
334 | );\r | |
335 | if (EFI_ERROR (Status)) {\r | |
336 | goto Done;\r | |
337 | }\r | |
338 | \r | |
ad86a50a | 339 | //\r |
340 | // Update to AHCI interface GUID based on device path node. The default one\r | |
341 | // is IDE interface GUID copied from template.\r | |
342 | //\r | |
343 | if (NewDevicePathNode->SubType == MSG_SATA_DP) {\r | |
344 | CopyGuid (&AtaDevice->DiskInfo.Interface, &gEfiDiskInfoAhciInterfaceGuid);\r | |
345 | }\r | |
346 | \r | |
ad86a50a | 347 | Status = gBS->InstallMultipleProtocolInterfaces (\r |
348 | &AtaDevice->Handle,\r | |
349 | &gEfiDevicePathProtocolGuid,\r | |
350 | AtaDevice->DevicePath,\r | |
351 | &gEfiBlockIoProtocolGuid,\r | |
352 | &AtaDevice->BlockIo,\r | |
490b5ea1 | 353 | &gEfiBlockIo2ProtocolGuid,\r |
354 | &AtaDevice->BlockIo2,\r | |
ad86a50a | 355 | &gEfiDiskInfoProtocolGuid,\r |
356 | &AtaDevice->DiskInfo,\r | |
357 | NULL\r | |
358 | );\r | |
359 | if (EFI_ERROR (Status)) {\r | |
360 | goto Done;\r | |
361 | }\r | |
362 | \r | |
c24097a5 | 363 | //\r |
364 | // See if the ata device support trust computing feature or not.\r | |
365 | // If yes, then install Storage Security Protocol at the ata device handle.\r | |
366 | //\r | |
367 | if ((AtaDevice->IdentifyData->trusted_computing_support & BIT0) != 0) {\r | |
368 | DEBUG ((EFI_D_INFO, "Found TCG support in Port %x PortMultiplierPort %x\n", Port, PortMultiplierPort));\r | |
369 | Status = gBS->InstallProtocolInterface (\r | |
370 | &AtaDevice->Handle,\r | |
371 | &gEfiStorageSecurityCommandProtocolGuid,\r | |
372 | EFI_NATIVE_INTERFACE,\r | |
373 | &AtaDevice->StorageSecurity\r | |
374 | );\r | |
375 | if (EFI_ERROR (Status)) {\r | |
376 | goto Done;\r | |
377 | }\r | |
90398d55 | 378 | DEBUG ((EFI_D_INFO, "Successfully Install Storage Security Protocol on the ATA device\n"));\r |
379 | }\r | |
380 | \r | |
2ca85489 | 381 | \r |
382 | if (((mMorControl & 0x01) == 0x01) && ((AtaDevice->IdentifyData->trusted_computing_support & BIT0) != 0)) {\r | |
383 | DEBUG ((EFI_D_INFO,\r | |
384 | "mMorControl = %x, AtaDevice->IdentifyData->trusted_computing_support & BIT0 = %x\n",\r | |
385 | mMorControl,\r | |
386 | (AtaDevice->IdentifyData->trusted_computing_support & BIT0)\r | |
387 | ));\r | |
388 | DEBUG ((EFI_D_INFO, "Try to lock device by sending TPer Reset command...\n"));\r | |
389 | InitiateTPerReset(AtaDevice);\r | |
c24097a5 | 390 | }\r |
391 | \r | |
ad86a50a | 392 | gBS->OpenProtocol (\r |
393 | AtaBusDriverData->Controller,\r | |
394 | &gEfiAtaPassThruProtocolGuid,\r | |
395 | (VOID **) &AtaPassThru,\r | |
396 | AtaBusDriverData->DriverBindingHandle,\r | |
397 | AtaDevice->Handle,\r | |
398 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
399 | );\r | |
e519983a | 400 | \r |
ad86a50a | 401 | Done:\r |
402 | if (NewDevicePathNode != NULL) {\r | |
403 | FreePool (NewDevicePathNode);\r | |
404 | }\r | |
405 | \r | |
e519983a | 406 | if (EFI_ERROR (Status) && (AtaDevice != NULL)) {\r |
58727f29 | 407 | ReleaseAtaResources (AtaDevice);\r |
25dd150b | 408 | DEBUG ((EFI_D_ERROR | EFI_D_INIT, "Failed to initialize Port %x PortMultiplierPort %x, status = %r\n", Port, PortMultiplierPort, Status));\r |
ad86a50a | 409 | }\r |
410 | return Status;\r | |
411 | }\r | |
412 | \r | |
413 | \r | |
414 | /**\r | |
415 | Unregisters an ATA device.\r | |
416 | \r | |
58727f29 | 417 | This function removes the protocols installed on the controller handle and\r |
418 | frees the resources allocated for the ATA device.\r | |
ad86a50a | 419 | \r |
05a44e91 | 420 | @param This The pointer to EFI_DRIVER_BINDING_PROTOCOL instance.\r |
ad86a50a | 421 | @param Controller The controller handle of the ATA device.\r |
422 | @param Handle The child handle.\r | |
423 | \r | |
424 | @retval EFI_SUCCESS The ATA device is successfully unregistered.\r | |
425 | @return Others Some error occurs when unregistering the ATA device.\r | |
426 | \r | |
427 | **/\r | |
428 | EFI_STATUS\r | |
429 | UnregisterAtaDevice (\r | |
430 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
431 | IN EFI_HANDLE Controller,\r | |
432 | IN EFI_HANDLE Handle\r | |
433 | )\r | |
434 | {\r | |
c24097a5 | 435 | EFI_STATUS Status;\r |
436 | EFI_BLOCK_IO_PROTOCOL *BlockIo;\r | |
437 | EFI_BLOCK_IO2_PROTOCOL *BlockIo2;\r | |
438 | ATA_DEVICE *AtaDevice;\r | |
439 | EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThru;\r | |
440 | EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *StorageSecurity;\r | |
441 | \r | |
442 | BlockIo2 = NULL;\r | |
443 | BlockIo = NULL;\r | |
ad86a50a | 444 | \r |
445 | Status = gBS->OpenProtocol (\r | |
446 | Handle,\r | |
447 | &gEfiBlockIoProtocolGuid,\r | |
448 | (VOID **) &BlockIo,\r | |
449 | This->DriverBindingHandle,\r | |
450 | Controller,\r | |
451 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
452 | );\r | |
453 | if (EFI_ERROR (Status)) {\r | |
490b5ea1 | 454 | //\r |
455 | // Locate BlockIo2 protocol\r | |
456 | //\r | |
457 | Status = gBS->OpenProtocol (\r | |
458 | Handle,\r | |
459 | &gEfiBlockIo2ProtocolGuid,\r | |
460 | (VOID **) &BlockIo2,\r | |
461 | This->DriverBindingHandle,\r | |
462 | Controller,\r | |
463 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
464 | );\r | |
465 | if (EFI_ERROR (Status)) {\r | |
466 | return Status;\r | |
467 | }\r | |
ad86a50a | 468 | }\r |
469 | \r | |
490b5ea1 | 470 | //\r |
471 | // Get AtaDevice data.\r | |
472 | //\r | |
473 | if (BlockIo != NULL) {\r | |
474 | AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (BlockIo);\r | |
475 | } else {\r | |
3d267c70 | 476 | ASSERT (BlockIo2 != NULL);\r |
490b5ea1 | 477 | AtaDevice = ATA_DEVICE_FROM_BLOCK_IO2 (BlockIo2);\r |
58727f29 | 478 | }\r |
ad86a50a | 479 | \r |
480 | //\r | |
481 | // Close the child handle\r | |
482 | //\r | |
483 | gBS->CloseProtocol (\r | |
484 | Controller,\r | |
485 | &gEfiAtaPassThruProtocolGuid,\r | |
486 | This->DriverBindingHandle,\r | |
487 | Handle\r | |
488 | );\r | |
489 | \r | |
490b5ea1 | 490 | //\r |
491 | // The Ata Bus driver installs the BlockIo and BlockIo2 in the DriverBindingStart().\r | |
492 | // Here should uninstall both of them.\r | |
493 | //\r | |
ad86a50a | 494 | Status = gBS->UninstallMultipleProtocolInterfaces (\r |
495 | Handle,\r | |
496 | &gEfiDevicePathProtocolGuid,\r | |
497 | AtaDevice->DevicePath,\r | |
498 | &gEfiBlockIoProtocolGuid,\r | |
499 | &AtaDevice->BlockIo,\r | |
490b5ea1 | 500 | &gEfiBlockIo2ProtocolGuid,\r |
501 | &AtaDevice->BlockIo2,\r | |
ad86a50a | 502 | &gEfiDiskInfoProtocolGuid,\r |
503 | &AtaDevice->DiskInfo,\r | |
504 | NULL\r | |
505 | );\r | |
506 | \r | |
507 | if (EFI_ERROR (Status)) {\r | |
508 | gBS->OpenProtocol (\r | |
509 | Controller,\r | |
510 | &gEfiAtaPassThruProtocolGuid,\r | |
511 | (VOID **) &AtaPassThru,\r | |
512 | This->DriverBindingHandle,\r | |
513 | Handle,\r | |
514 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
515 | );\r | |
516 | return Status;\r | |
517 | }\r | |
518 | \r | |
c24097a5 | 519 | //\r |
520 | // If Storage Security Command Protocol is installed, then uninstall this protocol.\r | |
521 | //\r | |
522 | Status = gBS->OpenProtocol (\r | |
523 | Handle,\r | |
524 | &gEfiStorageSecurityCommandProtocolGuid,\r | |
525 | (VOID **) &StorageSecurity,\r | |
526 | This->DriverBindingHandle,\r | |
527 | Controller,\r | |
528 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
529 | );\r | |
530 | \r | |
531 | if (!EFI_ERROR (Status)) {\r | |
532 | Status = gBS->UninstallProtocolInterface (\r | |
533 | Handle,\r | |
534 | &gEfiStorageSecurityCommandProtocolGuid,\r | |
535 | &AtaDevice->StorageSecurity\r | |
536 | );\r | |
537 | if (EFI_ERROR (Status)) {\r | |
538 | gBS->OpenProtocol (\r | |
539 | Controller,\r | |
540 | &gEfiAtaPassThruProtocolGuid,\r | |
541 | (VOID **) &AtaPassThru,\r | |
542 | This->DriverBindingHandle,\r | |
543 | Handle,\r | |
544 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
545 | );\r | |
3c063fed | 546 | return Status;\r |
c24097a5 | 547 | }\r |
548 | }\r | |
549 | \r | |
ad86a50a | 550 | ReleaseAtaResources (AtaDevice);\r |
7f070be5 | 551 | return EFI_SUCCESS;\r |
ad86a50a | 552 | }\r |
553 | \r | |
554 | \r | |
555 | \r | |
556 | /**\r | |
58727f29 | 557 | Tests to see if this driver supports a given controller. If a child device is provided,\r |
ad86a50a | 558 | it further tests to see if this driver supports creating a handle for the specified child device.\r |
559 | \r | |
58727f29 | 560 | This function checks to see if the driver specified by This supports the device specified by\r |
561 | ControllerHandle. Drivers will typically use the device path attached to\r | |
562 | ControllerHandle and/or the services from the bus I/O abstraction attached to\r | |
563 | ControllerHandle to determine if the driver supports ControllerHandle. This function\r | |
564 | may be called many times during platform initialization. In order to reduce boot times, the tests\r | |
565 | performed by this function must be very small, and take as little time as possible to execute. This\r | |
566 | function must not change the state of any hardware devices, and this function must be aware that the\r | |
567 | device specified by ControllerHandle may already be managed by the same driver or a\r | |
568 | different driver. This function must match its calls to AllocatePages() with FreePages(),\r | |
569 | AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r | |
570 | Since ControllerHandle may have been previously started by the same driver, if a protocol is\r | |
571 | already in the opened state, then it must not be closed with CloseProtocol(). This is required\r | |
ad86a50a | 572 | to guarantee the state of ControllerHandle is not modified by this function.\r |
573 | \r | |
574 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
58727f29 | 575 | @param[in] ControllerHandle The handle of the controller to test. This handle\r |
576 | must support a protocol interface that supplies\r | |
ad86a50a | 577 | an I/O abstraction to the driver.\r |
58727f29 | 578 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r |
579 | parameter is ignored by device drivers, and is optional for bus\r | |
580 | drivers. For bus drivers, if this parameter is not NULL, then\r | |
581 | the bus driver must determine if the bus controller specified\r | |
582 | by ControllerHandle and the child controller specified\r | |
583 | by RemainingDevicePath are both supported by this\r | |
ad86a50a | 584 | bus driver.\r |
585 | \r | |
586 | @retval EFI_SUCCESS The device specified by ControllerHandle and\r | |
587 | RemainingDevicePath is supported by the driver specified by This.\r | |
588 | @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r | |
589 | RemainingDevicePath is already being managed by the driver\r | |
590 | specified by This.\r | |
591 | @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r | |
592 | RemainingDevicePath is already being managed by a different\r | |
593 | driver or an application that requires exclusive access.\r | |
594 | Currently not implemented.\r | |
595 | @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r | |
596 | RemainingDevicePath is not supported by the driver specified by This.\r | |
597 | **/\r | |
598 | EFI_STATUS\r | |
599 | EFIAPI\r | |
600 | AtaBusDriverBindingSupported (\r | |
601 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
602 | IN EFI_HANDLE Controller,\r | |
603 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
604 | )\r | |
605 | {\r | |
606 | EFI_STATUS Status;\r | |
607 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
608 | EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThru;\r | |
609 | UINT16 Port;\r | |
610 | UINT16 PortMultiplierPort;\r | |
490b5ea1 | 611 | \r |
ad86a50a | 612 | //\r |
613 | // Test EFI_ATA_PASS_THRU_PROTOCOL on controller handle.\r | |
614 | //\r | |
615 | Status = gBS->OpenProtocol (\r | |
616 | Controller,\r | |
617 | &gEfiAtaPassThruProtocolGuid,\r | |
618 | (VOID **) &AtaPassThru,\r | |
619 | This->DriverBindingHandle,\r | |
620 | Controller,\r | |
621 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
622 | );\r | |
623 | \r | |
624 | if (Status == EFI_ALREADY_STARTED) {\r | |
625 | return EFI_SUCCESS;\r | |
626 | }\r | |
627 | \r | |
628 | if (EFI_ERROR (Status)) {\r | |
629 | return Status;\r | |
630 | }\r | |
631 | \r | |
8908e764 | 632 | //\r |
633 | // Test to see if this ATA Pass Thru Protocol is for a LOGICAL channel\r | |
634 | //\r | |
635 | if ((AtaPassThru->Mode->Attributes & EFI_ATA_PASS_THRU_ATTRIBUTES_LOGICAL) == 0) {\r | |
636 | //\r | |
637 | // Close the I/O Abstraction(s) used to perform the supported test\r | |
638 | //\r | |
639 | gBS->CloseProtocol (\r | |
640 | Controller,\r | |
641 | &gEfiAtaPassThruProtocolGuid,\r | |
642 | This->DriverBindingHandle,\r | |
643 | Controller\r | |
644 | );\r | |
645 | return EFI_UNSUPPORTED;\r | |
646 | }\r | |
647 | \r | |
ad86a50a | 648 | //\r |
649 | // Test RemainingDevicePath is valid or not.\r | |
650 | //\r | |
651 | if ((RemainingDevicePath != NULL) && !IsDevicePathEnd (RemainingDevicePath)) {\r | |
652 | Status = AtaPassThru->GetDevice (AtaPassThru, RemainingDevicePath, &Port, &PortMultiplierPort);\r | |
653 | if (EFI_ERROR (Status)) {\r | |
8908e764 | 654 | //\r |
655 | // Close the I/O Abstraction(s) used to perform the supported test\r | |
656 | //\r | |
657 | gBS->CloseProtocol (\r | |
658 | Controller,\r | |
659 | &gEfiAtaPassThruProtocolGuid,\r | |
660 | This->DriverBindingHandle,\r | |
661 | Controller\r | |
662 | );\r | |
ad86a50a | 663 | return Status;\r |
664 | }\r | |
665 | }\r | |
666 | \r | |
667 | //\r | |
668 | // Close the I/O Abstraction(s) used to perform the supported test\r | |
669 | //\r | |
670 | gBS->CloseProtocol (\r | |
671 | Controller,\r | |
672 | &gEfiAtaPassThruProtocolGuid,\r | |
673 | This->DriverBindingHandle,\r | |
674 | Controller\r | |
675 | );\r | |
676 | \r | |
677 | //\r | |
678 | // Open the EFI Device Path protocol needed to perform the supported test\r | |
679 | //\r | |
680 | Status = gBS->OpenProtocol (\r | |
681 | Controller,\r | |
682 | &gEfiDevicePathProtocolGuid,\r | |
683 | (VOID **) &ParentDevicePath,\r | |
684 | This->DriverBindingHandle,\r | |
685 | Controller,\r | |
686 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
687 | );\r | |
688 | return Status;\r | |
689 | }\r | |
690 | \r | |
691 | \r | |
692 | /**\r | |
693 | Starts a device controller or a bus controller.\r | |
694 | \r | |
695 | The Start() function is designed to be invoked from the EFI boot service ConnectController().\r | |
58727f29 | 696 | As a result, much of the error checking on the parameters to Start() has been moved into this\r |
697 | common boot service. It is legal to call Start() from other locations,\r | |
ad86a50a | 698 | but the following calling restrictions must be followed or the system behavior will not be deterministic.\r |
699 | 1. ControllerHandle must be a valid EFI_HANDLE.\r | |
700 | 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r | |
701 | EFI_DEVICE_PATH_PROTOCOL.\r | |
702 | 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r | |
58727f29 | 703 | have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r |
ad86a50a | 704 | \r |
705 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
58727f29 | 706 | @param[in] ControllerHandle The handle of the controller to start. This handle\r |
707 | must support a protocol interface that supplies\r | |
ad86a50a | 708 | an I/O abstraction to the driver.\r |
58727f29 | 709 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r |
710 | parameter is ignored by device drivers, and is optional for bus\r | |
711 | drivers. For a bus driver, if this parameter is NULL, then handles\r | |
490b5ea1 | 712 | for all the children of Controller are created by this driver.\r |
58727f29 | 713 | If this parameter is not NULL and the first Device Path Node is\r |
714 | not the End of Device Path Node, then only the handle for the\r | |
715 | child device specified by the first Device Path Node of\r | |
ad86a50a | 716 | RemainingDevicePath is created by this driver.\r |
58727f29 | 717 | If the first Device Path Node of RemainingDevicePath is\r |
ad86a50a | 718 | the End of Device Path Node, no child handle is created by this\r |
719 | driver.\r | |
720 | \r | |
721 | @retval EFI_SUCCESS The device was started.\r | |
722 | @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r | |
723 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
724 | @retval Others The driver failded to start the device.\r | |
725 | \r | |
726 | **/\r | |
727 | EFI_STATUS\r | |
728 | EFIAPI\r | |
729 | AtaBusDriverBindingStart (\r | |
730 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
731 | IN EFI_HANDLE Controller,\r | |
732 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
733 | )\r | |
734 | {\r | |
735 | EFI_STATUS Status;\r | |
736 | EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThru;\r | |
737 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
738 | ATA_BUS_DRIVER_DATA *AtaBusDriverData;\r | |
739 | UINT16 Port;\r | |
740 | UINT16 PortMultiplierPort;\r | |
741 | \r | |
742 | AtaBusDriverData = NULL;\r | |
743 | \r | |
744 | Status = gBS->OpenProtocol (\r | |
745 | Controller,\r | |
746 | &gEfiDevicePathProtocolGuid,\r | |
747 | (VOID **) &ParentDevicePath,\r | |
748 | This->DriverBindingHandle,\r | |
749 | Controller,\r | |
750 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
751 | );\r | |
752 | if (EFI_ERROR (Status)) {\r | |
753 | return Status;\r | |
754 | }\r | |
755 | \r | |
37623a5c | 756 | //\r |
757 | // Report Status Code to indicate ATA bus starts\r | |
758 | //\r | |
759 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
760 | EFI_PROGRESS_CODE,\r | |
761 | (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_PC_INIT),\r | |
762 | ParentDevicePath\r | |
763 | );\r | |
764 | \r | |
ad86a50a | 765 | Status = gBS->OpenProtocol (\r |
766 | Controller,\r | |
767 | &gEfiAtaPassThruProtocolGuid,\r | |
768 | (VOID **) &AtaPassThru,\r | |
769 | This->DriverBindingHandle,\r | |
770 | Controller,\r | |
771 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
772 | );\r | |
773 | if ((EFI_ERROR (Status)) && (Status != EFI_ALREADY_STARTED)) {\r | |
774 | goto ErrorExit;\r | |
775 | }\r | |
776 | \r | |
777 | //\r | |
778 | // Check EFI_ALREADY_STARTED to reuse the original ATA_BUS_DRIVER_DATA.\r | |
779 | //\r | |
780 | if (Status != EFI_ALREADY_STARTED) {\r | |
781 | AtaBusDriverData = AllocateZeroPool (sizeof (ATA_BUS_DRIVER_DATA));\r | |
782 | if (AtaBusDriverData == NULL) {\r | |
783 | Status = EFI_OUT_OF_RESOURCES;\r | |
784 | goto ErrorExit;\r | |
785 | }\r | |
786 | \r | |
787 | AtaBusDriverData->AtaPassThru = AtaPassThru;\r | |
490b5ea1 | 788 | AtaBusDriverData->Controller = Controller;\r |
ad86a50a | 789 | AtaBusDriverData->ParentDevicePath = ParentDevicePath;\r |
790 | AtaBusDriverData->DriverBindingHandle = This->DriverBindingHandle;\r | |
791 | \r | |
792 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
793 | &Controller,\r | |
794 | &gEfiCallerIdGuid,\r | |
795 | AtaBusDriverData,\r | |
796 | NULL\r | |
797 | );\r | |
798 | if (EFI_ERROR (Status)) {\r | |
799 | goto ErrorExit;\r | |
800 | }\r | |
801 | \r | |
802 | } else {\r | |
803 | Status = gBS->OpenProtocol (\r | |
804 | Controller,\r | |
805 | &gEfiCallerIdGuid,\r | |
806 | (VOID **) &AtaBusDriverData,\r | |
807 | This->DriverBindingHandle,\r | |
808 | Controller,\r | |
809 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
810 | );\r | |
811 | if (EFI_ERROR (Status)) {\r | |
812 | AtaBusDriverData = NULL;\r | |
813 | goto ErrorExit;\r | |
814 | }\r | |
815 | }\r | |
816 | \r | |
37623a5c | 817 | //\r |
818 | // Report Status Code to indicate detecting devices on bus\r | |
819 | //\r | |
820 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
821 | EFI_PROGRESS_CODE,\r | |
822 | (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_PC_DETECT),\r | |
823 | ParentDevicePath\r | |
824 | );\r | |
825 | \r | |
ad86a50a | 826 | if (RemainingDevicePath == NULL) {\r |
827 | Port = 0xFFFF;\r | |
828 | while (TRUE) {\r | |
829 | Status = AtaPassThru->GetNextPort (AtaPassThru, &Port);\r | |
830 | if (EFI_ERROR (Status)) {\r | |
831 | //\r | |
832 | // We cannot find more legal port then we are done.\r | |
833 | //\r | |
834 | break;\r | |
835 | }\r | |
490b5ea1 | 836 | \r |
ad86a50a | 837 | PortMultiplierPort = 0xFFFF;\r |
838 | while (TRUE) {\r | |
839 | Status = AtaPassThru->GetNextDevice (AtaPassThru, Port, &PortMultiplierPort);\r | |
840 | if (EFI_ERROR (Status)) {\r | |
841 | //\r | |
842 | // We cannot find more legal port multiplier port number for ATA device\r | |
843 | // on the port, then we are done.\r | |
844 | //\r | |
845 | break;\r | |
846 | }\r | |
847 | RegisterAtaDevice (AtaBusDriverData, Port, PortMultiplierPort);\r | |
848 | }\r | |
849 | }\r | |
850 | Status = EFI_SUCCESS;\r | |
851 | } else if (!IsDevicePathEnd (RemainingDevicePath)) {\r | |
852 | Status = AtaPassThru->GetDevice (AtaPassThru, RemainingDevicePath, &Port, &PortMultiplierPort);\r | |
853 | if (!EFI_ERROR (Status)) {\r | |
854 | Status = RegisterAtaDevice (AtaBusDriverData,Port, PortMultiplierPort);\r | |
855 | }\r | |
856 | }\r | |
490b5ea1 | 857 | \r |
ad86a50a | 858 | return Status;\r |
859 | \r | |
860 | ErrorExit:\r | |
861 | \r | |
862 | if (AtaBusDriverData != NULL) {\r | |
863 | gBS->UninstallMultipleProtocolInterfaces (\r | |
864 | Controller,\r | |
865 | &gEfiCallerIdGuid,\r | |
866 | AtaBusDriverData,\r | |
867 | NULL\r | |
868 | );\r | |
869 | FreePool (AtaBusDriverData);\r | |
870 | }\r | |
871 | \r | |
872 | gBS->CloseProtocol (\r | |
873 | Controller,\r | |
874 | &gEfiAtaPassThruProtocolGuid,\r | |
875 | This->DriverBindingHandle,\r | |
876 | Controller\r | |
877 | );\r | |
878 | \r | |
879 | return Status;\r | |
880 | \r | |
881 | }\r | |
882 | \r | |
883 | \r | |
884 | /**\r | |
885 | Stops a device controller or a bus controller.\r | |
58727f29 | 886 | \r |
887 | The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r | |
888 | As a result, much of the error checking on the parameters to Stop() has been moved\r | |
889 | into this common boot service. It is legal to call Stop() from other locations,\r | |
ad86a50a | 890 | but the following calling restrictions must be followed or the system behavior will not be deterministic.\r |
891 | 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r | |
892 | same driver's Start() function.\r | |
893 | 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r | |
894 | EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r | |
895 | Start() function, and the Start() function must have called OpenProtocol() on\r | |
896 | ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r | |
58727f29 | 897 | \r |
ad86a50a | 898 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r |
58727f29 | 899 | @param[in] ControllerHandle A handle to the device being stopped. The handle must\r |
900 | support a bus specific I/O protocol for the driver\r | |
ad86a50a | 901 | to use to stop the device.\r |
902 | @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r | |
58727f29 | 903 | @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r |
ad86a50a | 904 | if NumberOfChildren is 0.\r |
905 | \r | |
906 | @retval EFI_SUCCESS The device was stopped.\r | |
907 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
908 | \r | |
909 | **/\r | |
910 | EFI_STATUS\r | |
911 | EFIAPI\r | |
912 | AtaBusDriverBindingStop (\r | |
913 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
914 | IN EFI_HANDLE Controller,\r | |
915 | IN UINTN NumberOfChildren,\r | |
916 | IN EFI_HANDLE *ChildHandleBuffer\r | |
917 | )\r | |
918 | {\r | |
919 | EFI_STATUS Status;\r | |
920 | BOOLEAN AllChildrenStopped;\r | |
921 | UINTN Index;\r | |
922 | ATA_BUS_DRIVER_DATA *AtaBusDriverData;\r | |
923 | \r | |
924 | if (NumberOfChildren == 0) {\r | |
925 | Status = gBS->OpenProtocol (\r | |
926 | Controller,\r | |
927 | &gEfiCallerIdGuid,\r | |
928 | (VOID **) &AtaBusDriverData,\r | |
929 | This->DriverBindingHandle,\r | |
930 | Controller,\r | |
931 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
932 | );\r | |
933 | if (!EFI_ERROR (Status)) {\r | |
934 | gBS->UninstallMultipleProtocolInterfaces (\r | |
935 | Controller,\r | |
936 | &gEfiCallerIdGuid,\r | |
937 | AtaBusDriverData,\r | |
938 | NULL\r | |
939 | );\r | |
940 | FreePool (AtaBusDriverData);\r | |
941 | }\r | |
942 | \r | |
943 | gBS->CloseProtocol (\r | |
944 | Controller,\r | |
945 | &gEfiAtaPassThruProtocolGuid,\r | |
946 | This->DriverBindingHandle,\r | |
947 | Controller\r | |
948 | );\r | |
949 | \r | |
950 | return EFI_SUCCESS;\r | |
951 | }\r | |
952 | \r | |
953 | AllChildrenStopped = TRUE;\r | |
954 | \r | |
955 | for (Index = 0; Index < NumberOfChildren; Index++) {\r | |
956 | \r | |
957 | Status = UnregisterAtaDevice (This, Controller, ChildHandleBuffer[Index]);\r | |
958 | if (EFI_ERROR (Status)) {\r | |
959 | AllChildrenStopped = FALSE;\r | |
960 | }\r | |
961 | }\r | |
962 | \r | |
963 | if (!AllChildrenStopped) {\r | |
964 | return EFI_DEVICE_ERROR;\r | |
965 | }\r | |
966 | \r | |
967 | return EFI_SUCCESS;\r | |
968 | }\r | |
969 | \r | |
970 | \r | |
971 | /**\r | |
972 | Reset the Block Device.\r | |
973 | \r | |
974 | @param This Indicates a pointer to the calling context.\r | |
975 | @param ExtendedVerification Driver may perform diagnostics on reset.\r | |
976 | \r | |
977 | @retval EFI_SUCCESS The device was reset.\r | |
978 | @retval EFI_DEVICE_ERROR The device is not functioning properly and could\r | |
979 | not be reset.\r | |
980 | \r | |
981 | **/\r | |
982 | EFI_STATUS\r | |
983 | EFIAPI\r | |
984 | AtaBlockIoReset (\r | |
985 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
986 | IN BOOLEAN ExtendedVerification\r | |
987 | )\r | |
988 | {\r | |
989 | EFI_STATUS Status;\r | |
990 | ATA_DEVICE *AtaDevice;\r | |
991 | EFI_TPL OldTpl;\r | |
992 | \r | |
993 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
994 | \r | |
995 | AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (This);\r | |
996 | \r | |
490b5ea1 | 997 | Status = ResetAtaDevice (AtaDevice);\r |
ad86a50a | 998 | \r |
c6e797ae | 999 | if (EFI_ERROR (Status)) {\r |
1000 | Status = EFI_DEVICE_ERROR;\r | |
1001 | }\r | |
1002 | \r | |
ad86a50a | 1003 | gBS->RestoreTPL (OldTpl);\r |
1004 | return Status;\r | |
1005 | }\r | |
1006 | \r | |
1007 | \r | |
1008 | /**\r | |
1009 | Read/Write BufferSize bytes from Lba from/into Buffer.\r | |
1010 | \r | |
490b5ea1 | 1011 | @param[in] This Indicates a pointer to the calling context. Either be\r |
58727f29 | 1012 | block I/O or block I/O2.\r |
490b5ea1 | 1013 | @param[in] MediaId The media ID that the read/write request is for.\r |
1014 | @param[in] Lba The starting logical block address to be read/written.\r | |
1015 | The caller is responsible for reading/writing to only\r | |
1016 | legitimate locations.\r | |
1017 | @param[in, out] Token A pointer to the token associated with the transaction.\r | |
1018 | @param[in] BufferSize Size of Buffer, must be a multiple of device block size.\r | |
1019 | @param[out] Buffer A pointer to the destination/source buffer for the data.\r | |
1020 | @param[in] IsBlockIo2 Indicate the calling is from BlockIO or BlockIO2. TURE is\r | |
1021 | from BlockIO2, FALSE is for BlockIO.\r | |
1022 | @param[in] IsWrite Indicates whether it is a write operation.\r | |
ad86a50a | 1023 | \r |
1024 | @retval EFI_SUCCESS The data was read/written correctly to the device.\r | |
1025 | @retval EFI_WRITE_PROTECTED The device can not be read/written to.\r | |
1026 | @retval EFI_DEVICE_ERROR The device reported an error while performing the read/write.\r | |
1027 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
1028 | @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r | |
1029 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
58727f29 | 1030 | @retval EFI_INVALID_PARAMETER The read/write request contains LBAs that are not valid,\r |
ad86a50a | 1031 | or the buffer is not on proper alignment.\r |
1032 | \r | |
1033 | **/\r | |
1034 | EFI_STATUS\r | |
1035 | BlockIoReadWrite (\r | |
490b5ea1 | 1036 | IN VOID *This,\r |
1037 | IN UINT32 MediaId,\r | |
1038 | IN EFI_LBA Lba,\r | |
1039 | IN OUT EFI_BLOCK_IO2_TOKEN *Token,\r | |
1040 | IN UINTN BufferSize,\r | |
1041 | OUT VOID *Buffer,\r | |
1042 | IN BOOLEAN IsBlockIo2,\r | |
1043 | IN BOOLEAN IsWrite\r | |
ad86a50a | 1044 | )\r |
1045 | {\r | |
1046 | ATA_DEVICE *AtaDevice;\r | |
1047 | EFI_STATUS Status;\r | |
1048 | EFI_TPL OldTpl;\r | |
1049 | EFI_BLOCK_IO_MEDIA *Media;\r | |
1050 | UINTN BlockSize;\r | |
1051 | UINTN NumberOfBlocks;\r | |
1052 | UINTN IoAlign;\r | |
1053 | \r | |
490b5ea1 | 1054 | if (IsBlockIo2) {\r |
1055 | Media = ((EFI_BLOCK_IO2_PROTOCOL *) This)->Media;\r | |
1056 | AtaDevice = ATA_DEVICE_FROM_BLOCK_IO2 (This);\r | |
1057 | } else {\r | |
1058 | Media = ((EFI_BLOCK_IO_PROTOCOL *) This)->Media;\r | |
1059 | AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (This);\r | |
1060 | }\r | |
1061 | \r | |
fcf5e49d RN |
1062 | if (MediaId != Media->MediaId) {\r |
1063 | return EFI_MEDIA_CHANGED;\r | |
1064 | }\r | |
1065 | \r | |
490b5ea1 | 1066 | //\r |
1067 | // Check parameters.\r | |
1068 | //\r | |
ad86a50a | 1069 | if (Buffer == NULL) {\r |
1070 | return EFI_INVALID_PARAMETER;\r | |
1071 | }\r | |
1072 | \r | |
1073 | if (BufferSize == 0) {\r | |
1074 | return EFI_SUCCESS;\r | |
58727f29 | 1075 | }\r |
ad86a50a | 1076 | \r |
ad86a50a | 1077 | BlockSize = Media->BlockSize;\r |
1078 | if ((BufferSize % BlockSize) != 0) {\r | |
1079 | return EFI_BAD_BUFFER_SIZE;\r | |
1080 | }\r | |
58727f29 | 1081 | \r |
ad86a50a | 1082 | NumberOfBlocks = BufferSize / BlockSize;\r |
1083 | if ((Lba + NumberOfBlocks - 1) > Media->LastBlock) {\r | |
1084 | return EFI_INVALID_PARAMETER;\r | |
1085 | }\r | |
1086 | \r | |
1087 | IoAlign = Media->IoAlign;\r | |
1088 | if (IoAlign > 0 && (((UINTN) Buffer & (IoAlign - 1)) != 0)) {\r | |
1089 | return EFI_INVALID_PARAMETER;\r | |
1090 | }\r | |
1091 | \r | |
1092 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
58727f29 | 1093 | \r |
ad86a50a | 1094 | //\r |
1095 | // Invoke low level AtaDevice Access Routine.\r | |
1096 | //\r | |
490b5ea1 | 1097 | Status = AccessAtaDevice (AtaDevice, Buffer, Lba, NumberOfBlocks, IsWrite, Token);\r |
58727f29 | 1098 | \r |
ad86a50a | 1099 | gBS->RestoreTPL (OldTpl);\r |
1100 | \r | |
1101 | return Status;\r | |
1102 | }\r | |
1103 | \r | |
1104 | \r | |
1105 | /**\r | |
1106 | Read BufferSize bytes from Lba into Buffer.\r | |
1107 | \r | |
1108 | @param This Indicates a pointer to the calling context.\r | |
1109 | @param MediaId Id of the media, changes every time the media is replaced.\r | |
1110 | @param Lba The starting Logical Block Address to read from\r | |
1111 | @param BufferSize Size of Buffer, must be a multiple of device block size.\r | |
1112 | @param Buffer A pointer to the destination buffer for the data. The caller is\r | |
1113 | responsible for either having implicit or explicit ownership of the buffer.\r | |
1114 | \r | |
1115 | @retval EFI_SUCCESS The data was read correctly from the device.\r | |
1116 | @retval EFI_DEVICE_ERROR The device reported an error while performing the read.\r | |
1117 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
1118 | @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.\r | |
1119 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
58727f29 | 1120 | @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r |
ad86a50a | 1121 | or the buffer is not on proper alignment.\r |
1122 | \r | |
1123 | **/\r | |
1124 | EFI_STATUS\r | |
1125 | EFIAPI\r | |
1126 | AtaBlockIoReadBlocks (\r | |
1127 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
1128 | IN UINT32 MediaId,\r | |
1129 | IN EFI_LBA Lba,\r | |
1130 | IN UINTN BufferSize,\r | |
1131 | OUT VOID *Buffer\r | |
1132 | )\r | |
1133 | {\r | |
490b5ea1 | 1134 | return BlockIoReadWrite ((VOID *) This, MediaId, Lba, NULL, BufferSize, Buffer, FALSE, FALSE);\r |
ad86a50a | 1135 | }\r |
1136 | \r | |
1137 | \r | |
1138 | /**\r | |
1139 | Write BufferSize bytes from Lba into Buffer.\r | |
1140 | \r | |
1141 | @param This Indicates a pointer to the calling context.\r | |
1142 | @param MediaId The media ID that the write request is for.\r | |
1143 | @param Lba The starting logical block address to be written. The caller is\r | |
1144 | responsible for writing to only legitimate locations.\r | |
1145 | @param BufferSize Size of Buffer, must be a multiple of device block size.\r | |
1146 | @param Buffer A pointer to the source buffer for the data.\r | |
1147 | \r | |
1148 | @retval EFI_SUCCESS The data was written correctly to the device.\r | |
1149 | @retval EFI_WRITE_PROTECTED The device can not be written to.\r | |
1150 | @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r | |
1151 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
1152 | @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r | |
1153 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
58727f29 | 1154 | @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,\r |
ad86a50a | 1155 | or the buffer is not on proper alignment.\r |
1156 | \r | |
1157 | **/\r | |
1158 | EFI_STATUS\r | |
1159 | EFIAPI\r | |
1160 | AtaBlockIoWriteBlocks (\r | |
1161 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
1162 | IN UINT32 MediaId,\r | |
1163 | IN EFI_LBA Lba,\r | |
1164 | IN UINTN BufferSize,\r | |
1165 | IN VOID *Buffer\r | |
1166 | )\r | |
1167 | {\r | |
490b5ea1 | 1168 | return BlockIoReadWrite ((VOID *) This, MediaId, Lba, NULL, BufferSize, Buffer, FALSE, TRUE);\r |
ad86a50a | 1169 | }\r |
1170 | \r | |
1171 | \r | |
1172 | /**\r | |
1173 | Flush the Block Device.\r | |
1174 | \r | |
1175 | @param This Indicates a pointer to the calling context.\r | |
1176 | \r | |
1177 | @retval EFI_SUCCESS All outstanding data was written to the device\r | |
1178 | @retval EFI_DEVICE_ERROR The device reported an error while writing back the data\r | |
1179 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
1180 | \r | |
1181 | **/\r | |
1182 | EFI_STATUS\r | |
1183 | EFIAPI\r | |
1184 | AtaBlockIoFlushBlocks (\r | |
1185 | IN EFI_BLOCK_IO_PROTOCOL *This\r | |
1186 | )\r | |
1187 | {\r | |
1188 | //\r | |
1189 | // return directly\r | |
1190 | //\r | |
1191 | return EFI_SUCCESS;\r | |
1192 | }\r | |
1193 | \r | |
490b5ea1 | 1194 | /**\r |
1195 | Reset the Block Device.\r | |
1196 | \r | |
1197 | @param[in] This Indicates a pointer to the calling context.\r | |
1198 | @param[in] ExtendedVerification Driver may perform diagnostics on reset.\r | |
1199 | \r | |
1200 | @retval EFI_SUCCESS The device was reset.\r | |
1201 | @retval EFI_DEVICE_ERROR The device is not functioning properly and could\r | |
1202 | not be reset.\r | |
1203 | \r | |
1204 | **/\r | |
1205 | EFI_STATUS\r | |
1206 | EFIAPI\r | |
1207 | AtaBlockIoResetEx (\r | |
1208 | IN EFI_BLOCK_IO2_PROTOCOL *This,\r | |
1209 | IN BOOLEAN ExtendedVerification\r | |
1210 | )\r | |
1211 | {\r | |
1212 | EFI_STATUS Status;\r | |
1213 | ATA_DEVICE *AtaDevice;\r | |
1214 | EFI_TPL OldTpl;\r | |
1215 | \r | |
1216 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
1217 | \r | |
1218 | AtaDevice = ATA_DEVICE_FROM_BLOCK_IO2 (This);\r | |
1219 | \r | |
1220 | Status = ResetAtaDevice (AtaDevice);\r | |
1221 | \r | |
1222 | if (EFI_ERROR (Status)) {\r | |
1223 | Status = EFI_DEVICE_ERROR;\r | |
1224 | }\r | |
1225 | \r | |
1226 | gBS->RestoreTPL (OldTpl);\r | |
1227 | return Status;\r | |
1228 | }\r | |
1229 | \r | |
1230 | /**\r | |
1231 | Read BufferSize bytes from Lba into Buffer.\r | |
1232 | \r | |
1233 | @param[in] This Indicates a pointer to the calling context.\r | |
1234 | @param[in] MediaId Id of the media, changes every time the media is replaced.\r | |
1235 | @param[in] Lba The starting Logical Block Address to read from.\r | |
1236 | @param[in, out] Token A pointer to the token associated with the transaction.\r | |
1237 | @param[in] BufferSize Size of Buffer, must be a multiple of device block size.\r | |
1238 | @param[out] Buffer A pointer to the destination buffer for the data. The caller is\r | |
1239 | responsible for either having implicit or explicit ownership of the buffer.\r | |
1240 | \r | |
1241 | @retval EFI_SUCCESS The read request was queued if Event is not NULL.\r | |
1242 | The data was read correctly from the device if\r | |
1243 | the Event is NULL.\r | |
1244 | @retval EFI_DEVICE_ERROR The device reported an error while performing\r | |
1245 | the read.\r | |
1246 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
1247 | @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.\r | |
1248 | @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the\r | |
1249 | intrinsic block size of the device.\r | |
58727f29 | 1250 | @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r |
490b5ea1 | 1251 | or the buffer is not on proper alignment.\r |
1252 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack\r | |
1253 | of resources.\r | |
1254 | \r | |
1255 | **/\r | |
1256 | EFI_STATUS\r | |
1257 | EFIAPI\r | |
1258 | AtaBlockIoReadBlocksEx (\r | |
1259 | IN EFI_BLOCK_IO2_PROTOCOL *This,\r | |
1260 | IN UINT32 MediaId,\r | |
1261 | IN EFI_LBA Lba,\r | |
1262 | IN OUT EFI_BLOCK_IO2_TOKEN *Token,\r | |
1263 | IN UINTN BufferSize,\r | |
1264 | OUT VOID *Buffer\r | |
1265 | )\r | |
1266 | {\r | |
1267 | return BlockIoReadWrite ((VOID *) This, MediaId, Lba, Token, BufferSize, Buffer, TRUE, FALSE);\r | |
1268 | }\r | |
1269 | \r | |
1270 | \r | |
1271 | /**\r | |
1272 | Write BufferSize bytes from Lba into Buffer.\r | |
1273 | \r | |
1274 | @param[in] This Indicates a pointer to the calling context.\r | |
1275 | @param[in] MediaId The media ID that the write request is for.\r | |
1276 | @param[in] Lba The starting logical block address to be written. The\r | |
1277 | caller is responsible for writing to only legitimate\r | |
1278 | locations.\r | |
1279 | @param[in, out] Token A pointer to the token associated with the transaction.\r | |
1280 | @param[in] BufferSize Size of Buffer, must be a multiple of device block size.\r | |
1281 | @param[in] Buffer A pointer to the source buffer for the data.\r | |
ad86a50a | 1282 | \r |
490b5ea1 | 1283 | @retval EFI_SUCCESS The data was written correctly to the device.\r |
1284 | @retval EFI_WRITE_PROTECTED The device can not be written to.\r | |
1285 | @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r | |
1286 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
1287 | @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r | |
1288 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
58727f29 | 1289 | @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,\r |
490b5ea1 | 1290 | or the buffer is not on proper alignment.\r |
1291 | \r | |
1292 | **/\r | |
1293 | EFI_STATUS\r | |
1294 | EFIAPI\r | |
1295 | AtaBlockIoWriteBlocksEx (\r | |
1296 | IN EFI_BLOCK_IO2_PROTOCOL *This,\r | |
1297 | IN UINT32 MediaId,\r | |
1298 | IN EFI_LBA Lba,\r | |
1299 | IN OUT EFI_BLOCK_IO2_TOKEN *Token,\r | |
1300 | IN UINTN BufferSize,\r | |
1301 | IN VOID *Buffer\r | |
1302 | )\r | |
1303 | {\r | |
1304 | return BlockIoReadWrite ((VOID *) This, MediaId, Lba, Token, BufferSize, Buffer, TRUE, TRUE);\r | |
1305 | }\r | |
1306 | \r | |
1307 | \r | |
1308 | /**\r | |
1309 | Flush the Block Device.\r | |
1310 | \r | |
1311 | @param[in] This Indicates a pointer to the calling context.\r | |
1312 | @param[in, out] Token A pointer to the token associated with the transaction.\r | |
1313 | \r | |
1314 | @retval EFI_SUCCESS All outstanding data was written to the device\r | |
1315 | @retval EFI_DEVICE_ERROR The device reported an error while writing back the data\r | |
1316 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
1317 | \r | |
1318 | **/\r | |
1319 | EFI_STATUS\r | |
1320 | EFIAPI\r | |
1321 | AtaBlockIoFlushBlocksEx (\r | |
1322 | IN EFI_BLOCK_IO2_PROTOCOL *This,\r | |
1323 | IN OUT EFI_BLOCK_IO2_TOKEN *Token\r | |
1324 | )\r | |
1325 | {\r | |
1326 | //\r | |
3c063fed | 1327 | // Signal event and return directly.\r |
490b5ea1 | 1328 | //\r |
1329 | if (Token != NULL && Token->Event != NULL) {\r | |
1330 | Token->TransactionStatus = EFI_SUCCESS;\r | |
1331 | gBS->SignalEvent (Token->Event);\r | |
1332 | }\r | |
1333 | return EFI_SUCCESS;\r | |
1334 | }\r | |
ad86a50a | 1335 | /**\r |
1336 | Provides inquiry information for the controller type.\r | |
58727f29 | 1337 | \r |
ad86a50a | 1338 | This function is used by the IDE bus driver to get inquiry data. Data format\r |
1339 | of Identify data is defined by the Interface GUID.\r | |
1340 | \r | |
05a44e91 | 1341 | @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.\r |
1342 | @param[in, out] InquiryData Pointer to a buffer for the inquiry data.\r | |
1343 | @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.\r | |
ad86a50a | 1344 | \r |
1345 | @retval EFI_SUCCESS The command was accepted without any errors.\r | |
58727f29 | 1346 | @retval EFI_NOT_FOUND Device does not support this data class\r |
1347 | @retval EFI_DEVICE_ERROR Error reading InquiryData from device\r | |
1348 | @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough\r | |
ad86a50a | 1349 | \r |
1350 | **/\r | |
1351 | EFI_STATUS\r | |
1352 | EFIAPI\r | |
1353 | AtaDiskInfoInquiry (\r | |
1354 | IN EFI_DISK_INFO_PROTOCOL *This,\r | |
1355 | IN OUT VOID *InquiryData,\r | |
1356 | IN OUT UINT32 *InquiryDataSize\r | |
1357 | )\r | |
1358 | {\r | |
1359 | return EFI_NOT_FOUND;\r | |
1360 | }\r | |
1361 | \r | |
1362 | \r | |
1363 | /**\r | |
1364 | Provides identify information for the controller type.\r | |
1365 | \r | |
1366 | This function is used by the IDE bus driver to get identify data. Data format\r | |
1367 | of Identify data is defined by the Interface GUID.\r | |
1368 | \r | |
58727f29 | 1369 | @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL\r |
ad86a50a | 1370 | instance.\r |
05a44e91 | 1371 | @param[in, out] IdentifyData Pointer to a buffer for the identify data.\r |
1372 | @param[in, out] IdentifyDataSize Pointer to the value for the identify data\r | |
ad86a50a | 1373 | size.\r |
1374 | \r | |
1375 | @retval EFI_SUCCESS The command was accepted without any errors.\r | |
58727f29 | 1376 | @retval EFI_NOT_FOUND Device does not support this data class\r |
1377 | @retval EFI_DEVICE_ERROR Error reading IdentifyData from device\r | |
1378 | @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough\r | |
ad86a50a | 1379 | \r |
1380 | **/\r | |
1381 | EFI_STATUS\r | |
1382 | EFIAPI\r | |
1383 | AtaDiskInfoIdentify (\r | |
1384 | IN EFI_DISK_INFO_PROTOCOL *This,\r | |
1385 | IN OUT VOID *IdentifyData,\r | |
1386 | IN OUT UINT32 *IdentifyDataSize\r | |
1387 | )\r | |
1388 | {\r | |
1389 | EFI_STATUS Status;\r | |
1390 | ATA_DEVICE *AtaDevice;\r | |
1391 | \r | |
1392 | AtaDevice = ATA_DEVICE_FROM_DISK_INFO (This);\r | |
1393 | \r | |
1394 | Status = EFI_BUFFER_TOO_SMALL;\r | |
3c063fed | 1395 | if (*IdentifyDataSize >= sizeof (ATA_IDENTIFY_DATA)) {\r |
ad86a50a | 1396 | Status = EFI_SUCCESS;\r |
3c063fed | 1397 | CopyMem (IdentifyData, AtaDevice->IdentifyData, sizeof (ATA_IDENTIFY_DATA));\r |
ad86a50a | 1398 | }\r |
3c063fed | 1399 | *IdentifyDataSize = sizeof (ATA_IDENTIFY_DATA);\r |
ad86a50a | 1400 | \r |
1401 | return Status;\r | |
1402 | }\r | |
1403 | \r | |
1404 | \r | |
1405 | /**\r | |
1406 | Provides sense data information for the controller type.\r | |
58727f29 | 1407 | \r |
1408 | This function is used by the IDE bus driver to get sense data.\r | |
ad86a50a | 1409 | Data format of Sense data is defined by the Interface GUID.\r |
1410 | \r | |
05a44e91 | 1411 | @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.\r |
1412 | @param[in, out] SenseData Pointer to the SenseData.\r | |
1413 | @param[in, out] SenseDataSize Size of SenseData in bytes.\r | |
1414 | @param[out] SenseDataNumber Pointer to the value for the sense data size.\r | |
ad86a50a | 1415 | \r |
1416 | @retval EFI_SUCCESS The command was accepted without any errors.\r | |
1417 | @retval EFI_NOT_FOUND Device does not support this data class.\r | |
1418 | @retval EFI_DEVICE_ERROR Error reading SenseData from device.\r | |
1419 | @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.\r | |
1420 | \r | |
1421 | **/\r | |
1422 | EFI_STATUS\r | |
1423 | EFIAPI\r | |
1424 | AtaDiskInfoSenseData (\r | |
1425 | IN EFI_DISK_INFO_PROTOCOL *This,\r | |
1426 | IN OUT VOID *SenseData,\r | |
1427 | IN OUT UINT32 *SenseDataSize,\r | |
1428 | OUT UINT8 *SenseDataNumber\r | |
1429 | )\r | |
1430 | {\r | |
1431 | return EFI_NOT_FOUND;\r | |
1432 | }\r | |
1433 | \r | |
1434 | \r | |
1435 | /**\r | |
1436 | This function is used by the IDE bus driver to get controller information.\r | |
1437 | \r | |
58727f29 | 1438 | @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.\r |
ad86a50a | 1439 | @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.\r |
1440 | @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.\r | |
1441 | \r | |
1442 | @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.\r | |
1443 | @retval EFI_UNSUPPORTED This is not an IDE device.\r | |
1444 | \r | |
1445 | **/\r | |
1446 | EFI_STATUS\r | |
1447 | EFIAPI\r | |
1448 | AtaDiskInfoWhichIde (\r | |
1449 | IN EFI_DISK_INFO_PROTOCOL *This,\r | |
1450 | OUT UINT32 *IdeChannel,\r | |
1451 | OUT UINT32 *IdeDevice\r | |
1452 | )\r | |
1453 | {\r | |
1454 | ATA_DEVICE *AtaDevice;\r | |
1455 | \r | |
1456 | AtaDevice = ATA_DEVICE_FROM_DISK_INFO (This);\r | |
1457 | *IdeChannel = AtaDevice->Port;\r | |
1458 | *IdeDevice = AtaDevice->PortMultiplierPort;\r | |
1459 | \r | |
1460 | return EFI_SUCCESS;\r | |
1461 | }\r | |
1462 | \r | |
c24097a5 | 1463 | /**\r |
1464 | Send a security protocol command to a device that receives data and/or the result\r | |
1465 | of one or more commands sent by SendData.\r | |
1466 | \r | |
1467 | The ReceiveData function sends a security protocol command to the given MediaId.\r | |
1468 | The security protocol command sent is defined by SecurityProtocolId and contains\r | |
1469 | the security protocol specific data SecurityProtocolSpecificData. The function\r | |
1470 | returns the data from the security protocol command in PayloadBuffer.\r | |
1471 | \r | |
1472 | For devices supporting the SCSI command set, the security protocol command is sent\r | |
1473 | using the SECURITY PROTOCOL IN command defined in SPC-4.\r | |
1474 | \r | |
1475 | For devices supporting the ATA command set, the security protocol command is sent\r | |
1476 | using one of the TRUSTED RECEIVE commands defined in ATA8-ACS if PayloadBufferSize\r | |
1477 | is non-zero.\r | |
1478 | \r | |
1479 | If the PayloadBufferSize is zero, the security protocol command is sent using the\r | |
1480 | Trusted Non-Data command defined in ATA8-ACS.\r | |
1481 | \r | |
1482 | If PayloadBufferSize is too small to store the available data from the security\r | |
1483 | protocol command, the function shall copy PayloadBufferSize bytes into the\r | |
1484 | PayloadBuffer and return EFI_WARN_BUFFER_TOO_SMALL.\r | |
1485 | \r | |
1486 | If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,\r | |
1487 | the function shall return EFI_INVALID_PARAMETER.\r | |
1488 | \r | |
1489 | If the given MediaId does not support security protocol commands, the function shall\r | |
1490 | return EFI_UNSUPPORTED. If there is no media in the device, the function returns\r | |
1491 | EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the device,\r | |
1492 | the function returns EFI_MEDIA_CHANGED.\r | |
1493 | \r | |
1494 | If the security protocol fails to complete within the Timeout period, the function\r | |
1495 | shall return EFI_TIMEOUT.\r | |
1496 | \r | |
1497 | If the security protocol command completes without an error, the function shall\r | |
1498 | return EFI_SUCCESS. If the security protocol command completes with an error, the\r | |
1499 | function shall return EFI_DEVICE_ERROR.\r | |
1500 | \r | |
1501 | @param This Indicates a pointer to the calling context.\r | |
1502 | @param MediaId ID of the medium to receive data from.\r | |
1503 | @param Timeout The timeout, in 100ns units, to use for the execution\r | |
1504 | of the security protocol command. A Timeout value of 0\r | |
1505 | means that this function will wait indefinitely for the\r | |
1506 | security protocol command to execute. If Timeout is greater\r | |
1507 | than zero, then this function will return EFI_TIMEOUT\r | |
1508 | if the time required to execute the receive data command\r | |
1509 | is greater than Timeout.\r | |
1510 | @param SecurityProtocolId The value of the "Security Protocol" parameter of\r | |
1511 | the security protocol command to be sent.\r | |
1512 | @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter\r | |
1513 | of the security protocol command to be sent.\r | |
1514 | @param PayloadBufferSize Size in bytes of the payload data buffer.\r | |
1515 | @param PayloadBuffer A pointer to a destination buffer to store the security\r | |
1516 | protocol command specific payload data for the security\r | |
1517 | protocol command. The caller is responsible for having\r | |
1518 | either implicit or explicit ownership of the buffer.\r | |
1519 | @param PayloadTransferSize A pointer to a buffer to store the size in bytes of the\r | |
1520 | data written to the payload data buffer.\r | |
1521 | \r | |
1522 | @retval EFI_SUCCESS The security protocol command completed successfully.\r | |
1523 | @retval EFI_WARN_BUFFER_TOO_SMALL The PayloadBufferSize was too small to store the available\r | |
1524 | data from the device. The PayloadBuffer contains the truncated data.\r | |
1525 | @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.\r | |
1526 | @retval EFI_DEVICE_ERROR The security protocol command completed with an error.\r | |
1527 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
1528 | @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.\r | |
1529 | @retval EFI_INVALID_PARAMETER The PayloadBuffer or PayloadTransferSize is NULL and\r | |
1530 | PayloadBufferSize is non-zero.\r | |
1531 | @retval EFI_TIMEOUT A timeout occurred while waiting for the security\r | |
1532 | protocol command to execute.\r | |
1533 | \r | |
1534 | **/\r | |
1535 | EFI_STATUS\r | |
1536 | EFIAPI\r | |
1537 | AtaStorageSecurityReceiveData (\r | |
1538 | IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,\r | |
1539 | IN UINT32 MediaId,\r | |
1540 | IN UINT64 Timeout,\r | |
1541 | IN UINT8 SecurityProtocolId,\r | |
1542 | IN UINT16 SecurityProtocolSpecificData,\r | |
1543 | IN UINTN PayloadBufferSize,\r | |
1544 | OUT VOID *PayloadBuffer,\r | |
1545 | OUT UINTN *PayloadTransferSize\r | |
1546 | )\r | |
1547 | {\r | |
1548 | EFI_STATUS Status;\r | |
1549 | ATA_DEVICE *Private;\r | |
3c063fed | 1550 | EFI_TPL OldTpl;\r |
c24097a5 | 1551 | \r |
1552 | DEBUG ((EFI_D_INFO, "EFI Storage Security Protocol - Read"));\r | |
1553 | if ((PayloadBuffer == NULL || PayloadTransferSize == NULL) && PayloadBufferSize != 0) {\r | |
1554 | return EFI_INVALID_PARAMETER;\r | |
1555 | }\r | |
1556 | \r | |
1557 | Status = EFI_SUCCESS;\r | |
1558 | Private = ATA_DEVICE_FROM_STORAGE_SECURITY (This);\r | |
1559 | \r | |
1560 | if (MediaId != Private->BlockIo.Media->MediaId) {\r | |
1561 | return EFI_MEDIA_CHANGED;\r | |
1562 | }\r | |
1563 | \r | |
1564 | if (!Private->BlockIo.Media->MediaPresent) {\r | |
1565 | return EFI_NO_MEDIA;\r | |
1566 | }\r | |
1567 | \r | |
3c063fed | 1568 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
1569 | \r | |
c24097a5 | 1570 | Status = TrustTransferAtaDevice (\r |
1571 | Private,\r | |
1572 | PayloadBuffer,\r | |
1573 | SecurityProtocolId,\r | |
1574 | SecurityProtocolSpecificData,\r | |
1575 | PayloadBufferSize,\r | |
1576 | FALSE,\r | |
1577 | Timeout,\r | |
1578 | PayloadTransferSize\r | |
1579 | );\r | |
1580 | \r | |
3c063fed | 1581 | gBS->RestoreTPL (OldTpl);\r |
c24097a5 | 1582 | return Status;\r |
1583 | }\r | |
1584 | \r | |
1585 | /**\r | |
1586 | Send a security protocol command to a device.\r | |
1587 | \r | |
1588 | The SendData function sends a security protocol command containing the payload\r | |
1589 | PayloadBuffer to the given MediaId. The security protocol command sent is\r | |
1590 | defined by SecurityProtocolId and contains the security protocol specific data\r | |
1591 | SecurityProtocolSpecificData. If the underlying protocol command requires a\r | |
1592 | specific padding for the command payload, the SendData function shall add padding\r | |
1593 | bytes to the command payload to satisfy the padding requirements.\r | |
1594 | \r | |
1595 | For devices supporting the SCSI command set, the security protocol command is sent\r | |
1596 | using the SECURITY PROTOCOL OUT command defined in SPC-4.\r | |
1597 | \r | |
1598 | For devices supporting the ATA command set, the security protocol command is sent\r | |
1599 | using one of the TRUSTED SEND commands defined in ATA8-ACS if PayloadBufferSize\r | |
1600 | is non-zero. If the PayloadBufferSize is zero, the security protocol command is\r | |
1601 | sent using the Trusted Non-Data command defined in ATA8-ACS.\r | |
1602 | \r | |
1603 | If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall\r | |
1604 | return EFI_INVALID_PARAMETER.\r | |
1605 | \r | |
1606 | If the given MediaId does not support security protocol commands, the function\r | |
1607 | shall return EFI_UNSUPPORTED. If there is no media in the device, the function\r | |
1608 | returns EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the\r | |
1609 | device, the function returns EFI_MEDIA_CHANGED.\r | |
1610 | \r | |
1611 | If the security protocol fails to complete within the Timeout period, the function\r | |
1612 | shall return EFI_TIMEOUT.\r | |
1613 | \r | |
1614 | If the security protocol command completes without an error, the function shall return\r | |
1615 | EFI_SUCCESS. If the security protocol command completes with an error, the function\r | |
1616 | shall return EFI_DEVICE_ERROR.\r | |
1617 | \r | |
1618 | @param This Indicates a pointer to the calling context.\r | |
1619 | @param MediaId ID of the medium to receive data from.\r | |
1620 | @param Timeout The timeout, in 100ns units, to use for the execution\r | |
1621 | of the security protocol command. A Timeout value of 0\r | |
1622 | means that this function will wait indefinitely for the\r | |
1623 | security protocol command to execute. If Timeout is greater\r | |
1624 | than zero, then this function will return EFI_TIMEOUT\r | |
1625 | if the time required to execute the receive data command\r | |
1626 | is greater than Timeout.\r | |
1627 | @param SecurityProtocolId The value of the "Security Protocol" parameter of\r | |
1628 | the security protocol command to be sent.\r | |
1629 | @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter\r | |
1630 | of the security protocol command to be sent.\r | |
1631 | @param PayloadBufferSize Size in bytes of the payload data buffer.\r | |
1632 | @param PayloadBuffer A pointer to a destination buffer to store the security\r | |
1633 | protocol command specific payload data for the security\r | |
1634 | protocol command.\r | |
1635 | \r | |
1636 | @retval EFI_SUCCESS The security protocol command completed successfully.\r | |
1637 | @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.\r | |
1638 | @retval EFI_DEVICE_ERROR The security protocol command completed with an error.\r | |
1639 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
1640 | @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.\r | |
1641 | @retval EFI_INVALID_PARAMETER The PayloadBuffer is NULL and PayloadBufferSize is non-zero.\r | |
1642 | @retval EFI_TIMEOUT A timeout occurred while waiting for the security\r | |
1643 | protocol command to execute.\r | |
1644 | \r | |
1645 | **/\r | |
1646 | EFI_STATUS\r | |
1647 | EFIAPI\r | |
1648 | AtaStorageSecuritySendData (\r | |
1649 | IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,\r | |
1650 | IN UINT32 MediaId,\r | |
1651 | IN UINT64 Timeout,\r | |
1652 | IN UINT8 SecurityProtocolId,\r | |
1653 | IN UINT16 SecurityProtocolSpecificData,\r | |
1654 | IN UINTN PayloadBufferSize,\r | |
1655 | IN VOID *PayloadBuffer\r | |
1656 | )\r | |
1657 | {\r | |
1658 | EFI_STATUS Status;\r | |
1659 | ATA_DEVICE *Private;\r | |
3c063fed | 1660 | EFI_TPL OldTpl;\r |
c24097a5 | 1661 | \r |
1662 | DEBUG ((EFI_D_INFO, "EFI Storage Security Protocol - Send"));\r | |
1663 | if ((PayloadBuffer == NULL) && (PayloadBufferSize != 0)) {\r | |
1664 | return EFI_INVALID_PARAMETER;\r | |
1665 | }\r | |
1666 | \r | |
1667 | Status = EFI_SUCCESS;\r | |
1668 | Private = ATA_DEVICE_FROM_STORAGE_SECURITY (This);\r | |
1669 | \r | |
1670 | if (MediaId != Private->BlockIo.Media->MediaId) {\r | |
1671 | return EFI_MEDIA_CHANGED;\r | |
1672 | }\r | |
1673 | \r | |
3c063fed | 1674 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
c24097a5 | 1675 | Status = TrustTransferAtaDevice (\r |
1676 | Private,\r | |
1677 | PayloadBuffer,\r | |
1678 | SecurityProtocolId,\r | |
1679 | SecurityProtocolSpecificData,\r | |
1680 | PayloadBufferSize,\r | |
1681 | TRUE,\r | |
1682 | Timeout,\r | |
1683 | NULL\r | |
1684 | );\r | |
1685 | \r | |
3c063fed | 1686 | gBS->RestoreTPL (OldTpl);\r |
c24097a5 | 1687 | return Status;\r |
1688 | }\r | |
ad86a50a | 1689 | \r |
1690 | /**\r | |
1691 | The user Entry Point for module AtaBus. The user code starts with this function.\r | |
1692 | \r | |
1693 | @param[in] ImageHandle The firmware allocated handle for the EFI image.\r | |
1694 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
1695 | \r | |
1696 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
1697 | @retval other Some error occurs when executing this entry point.\r | |
1698 | \r | |
1699 | **/\r | |
1700 | EFI_STATUS\r | |
1701 | EFIAPI\r | |
1702 | InitializeAtaBus(\r | |
1703 | IN EFI_HANDLE ImageHandle,\r | |
1704 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
1705 | )\r | |
1706 | {\r | |
1707 | EFI_STATUS Status;\r | |
90398d55 | 1708 | UINTN DataSize;\r |
ad86a50a | 1709 | \r |
1710 | //\r | |
1711 | // Install driver model protocol(s).\r | |
1712 | //\r | |
1713 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
1714 | ImageHandle,\r | |
1715 | SystemTable,\r | |
1716 | &gAtaBusDriverBinding,\r | |
1717 | ImageHandle,\r | |
1718 | &gAtaBusComponentName,\r | |
1719 | &gAtaBusComponentName2\r | |
1720 | );\r | |
1721 | ASSERT_EFI_ERROR (Status);\r | |
1722 | \r | |
90398d55 | 1723 | //\r |
1724 | // Get the MorControl bit.\r | |
1725 | //\r | |
1726 | DataSize = sizeof (mMorControl);\r | |
1727 | Status = gRT->GetVariable (\r | |
1728 | MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,\r | |
1729 | &gEfiMemoryOverwriteControlDataGuid,\r | |
1730 | NULL,\r | |
1731 | &DataSize,\r | |
1732 | &mMorControl\r | |
1733 | );\r | |
1734 | \r | |
1735 | if (EFI_ERROR (Status)) {\r | |
1736 | DEBUG ((EFI_D_INFO, "AtaBus:gEfiMemoryOverwriteControlDataGuid doesn't exist!!***\n"));\r | |
90398d55 | 1737 | mMorControl = 0;\r |
1738 | Status = EFI_SUCCESS;\r | |
1739 | } else {\r | |
1740 | DEBUG ((EFI_D_INFO, "AtaBus:Get the gEfiMemoryOverwriteControlDataGuid = %x!!***\n", mMorControl));\r | |
90398d55 | 1741 | }\r |
1742 | \r | |
ad86a50a | 1743 | return Status;\r |
1744 | }\r | |
90398d55 | 1745 | \r |
1746 | /**\r | |
1747 | Send TPer Reset command to reset eDrive to lock all protected bands.\r | |
1748 | Typically, there are 2 mechanism for resetting eDrive. They are:\r | |
1749 | 1. TPer Reset through IEEE 1667 protocol.\r | |
1750 | 2. TPer Reset through native TCG protocol.\r | |
1751 | This routine will detect what protocol the attached eDrive comform to, TCG or\r | |
1752 | IEEE 1667 protocol. Then send out TPer Reset command separately.\r | |
1753 | \r | |
1754 | @param[in] AtaDevice ATA_DEVICE pointer.\r | |
1755 | \r | |
1756 | **/\r | |
1757 | VOID\r | |
1758 | InitiateTPerReset (\r | |
1759 | IN ATA_DEVICE *AtaDevice\r | |
1760 | )\r | |
1761 | {\r | |
1762 | \r | |
1763 | EFI_STATUS Status;\r | |
1764 | UINT8 *Buffer;\r | |
1765 | UINTN XferSize;\r | |
1766 | UINTN Len;\r | |
1767 | UINTN Index;\r | |
1768 | BOOLEAN TcgFlag;\r | |
1769 | BOOLEAN IeeeFlag;\r | |
1770 | EFI_BLOCK_IO_PROTOCOL *BlockIo;\r | |
1771 | EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *Ssp;\r | |
1772 | SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA *Data;\r | |
1773 | \r | |
1774 | Buffer = NULL;\r | |
1775 | TcgFlag = FALSE;\r | |
1776 | IeeeFlag = FALSE;\r | |
1777 | Ssp = &AtaDevice->StorageSecurity;\r | |
1778 | BlockIo = &AtaDevice->BlockIo;\r | |
1779 | \r | |
1780 | //\r | |
1781 | // ATA8-ACS 7.57.6.1 indicates the Transfer Length field requirements a multiple of 512.\r | |
1782 | // If the length of the TRUSTED RECEIVE parameter data is greater than the Transfer Length,\r | |
1783 | // then the device shall return the TRUSTED RECEIVE parameter data truncated to the requested Transfer Length.\r | |
1784 | //\r | |
1785 | Len = ROUNDUP512(sizeof(SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA));\r | |
1786 | Buffer = AllocateZeroPool(Len);\r | |
1787 | \r | |
1788 | if (Buffer == NULL) {\r | |
1789 | return;\r | |
1790 | }\r | |
1791 | \r | |
1792 | //\r | |
1793 | // When the Security Protocol field is set to 00h, and SP Specific is set to 0000h in a TRUSTED RECEIVE\r | |
1794 | // command, the device basic information data shall be returned.\r | |
1795 | //\r | |
1796 | Status = Ssp->ReceiveData (\r | |
1797 | Ssp,\r | |
1798 | BlockIo->Media->MediaId,\r | |
1799 | 100000000, // Timeout 10-sec\r | |
1800 | 0, // SecurityProtocol\r | |
1801 | 0, // SecurityProtocolSpecifcData\r | |
1802 | Len, // PayloadBufferSize,\r | |
1803 | Buffer, // PayloadBuffer\r | |
1804 | &XferSize\r | |
1805 | );\r | |
1806 | if (EFI_ERROR (Status)) {\r | |
1807 | goto Exit;\r | |
1808 | }\r | |
1809 | \r | |
1810 | //\r | |
1811 | // In returned data, the ListLength field indicates the total length, in bytes,\r | |
1812 | // of the supported security protocol list.\r | |
1813 | //\r | |
1814 | Data = (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA*)Buffer;\r | |
1815 | Len = ROUNDUP512(sizeof (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA) +\r | |
1816 | (Data->SupportedSecurityListLength[0] << 8) +\r | |
1817 | (Data->SupportedSecurityListLength[1])\r | |
1818 | );\r | |
1819 | \r | |
1820 | //\r | |
1821 | // Free original buffer and allocate new buffer.\r | |
1822 | //\r | |
1823 | FreePool(Buffer);\r | |
1824 | Buffer = AllocateZeroPool(Len);\r | |
1825 | if (Buffer == NULL) {\r | |
1826 | return;\r | |
1827 | }\r | |
1828 | \r | |
1829 | //\r | |
1830 | // Read full supported security protocol list from device.\r | |
1831 | //\r | |
1832 | Status = Ssp->ReceiveData (\r | |
1833 | Ssp,\r | |
1834 | BlockIo->Media->MediaId,\r | |
1835 | 100000000, // Timeout 10-sec\r | |
1836 | 0, // SecurityProtocol\r | |
1837 | 0, // SecurityProtocolSpecifcData\r | |
1838 | Len, // PayloadBufferSize,\r | |
1839 | Buffer, // PayloadBuffer\r | |
1840 | &XferSize\r | |
1841 | );\r | |
1842 | \r | |
1843 | if (EFI_ERROR (Status)) {\r | |
1844 | goto Exit;\r | |
1845 | }\r | |
1846 | \r | |
1847 | Data = (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA*)Buffer;\r | |
1848 | Len = (Data->SupportedSecurityListLength[0] << 8) + Data->SupportedSecurityListLength[1];\r | |
1849 | \r | |
1850 | //\r | |
1851 | // Iterate full supported security protocol list to check if TCG or IEEE 1667 protocol\r | |
1852 | // is supported.\r | |
1853 | //\r | |
1854 | for (Index = 0; Index < Len; Index++) {\r | |
1855 | if (Data->SupportedSecurityProtocol[Index] == SECURITY_PROTOCOL_TCG) {\r | |
1856 | //\r | |
1857 | // Found a TCG device.\r | |
1858 | //\r | |
1859 | TcgFlag = TRUE;\r | |
1860 | DEBUG ((EFI_D_INFO, "This device is a TCG protocol device\n"));\r | |
1861 | break;\r | |
1862 | }\r | |
1863 | \r | |
1864 | if (Data->SupportedSecurityProtocol[Index] == SECURITY_PROTOCOL_IEEE1667) {\r | |
1865 | //\r | |
1866 | // Found a IEEE 1667 device.\r | |
1867 | //\r | |
1868 | IeeeFlag = TRUE;\r | |
1869 | DEBUG ((EFI_D_INFO, "This device is a IEEE 1667 protocol device\n"));\r | |
1870 | break;\r | |
1871 | }\r | |
1872 | }\r | |
1873 | \r | |
1874 | if (!TcgFlag && !IeeeFlag) {\r | |
1875 | DEBUG ((EFI_D_INFO, "Neither a TCG nor IEEE 1667 protocol device is found\n"));\r | |
1876 | goto Exit;\r | |
1877 | }\r | |
1878 | \r | |
1879 | if (TcgFlag) {\r | |
1880 | //\r | |
1881 | // As long as TCG protocol is supported, send out a TPer Reset\r | |
1882 | // TCG command to the device via the TrustedSend command with a non-zero Transfer Length.\r | |
1883 | //\r | |
1884 | Status = Ssp->SendData (\r | |
1885 | Ssp,\r | |
1886 | BlockIo->Media->MediaId,\r | |
1887 | 100000000, // Timeout 10-sec\r | |
1888 | SECURITY_PROTOCOL_TCG, // SecurityProtocol\r | |
1889 | 0x0400, // SecurityProtocolSpecifcData\r | |
1890 | 512, // PayloadBufferSize,\r | |
1891 | Buffer // PayloadBuffer\r | |
1892 | );\r | |
1893 | \r | |
1894 | if (!EFI_ERROR (Status)) {\r | |
1895 | DEBUG ((EFI_D_INFO, "Send TPer Reset Command Successfully !\n"));\r | |
1896 | } else {\r | |
1897 | DEBUG ((EFI_D_INFO, "Send TPer Reset Command Fail !\n"));\r | |
1898 | }\r | |
1899 | }\r | |
1900 | \r | |
1901 | if (IeeeFlag) {\r | |
1902 | //\r | |
1903 | // TBD : Perform a TPer Reset via IEEE 1667 Protocol\r | |
1904 | //\r | |
1905 | DEBUG ((EFI_D_INFO, "IEEE 1667 Protocol didn't support yet!\n"));\r | |
1906 | }\r | |
1907 | \r | |
1908 | Exit:\r | |
1909 | \r | |
1910 | if (Buffer != NULL) {\r | |
1911 | FreePool(Buffer);\r | |
1912 | }\r | |
1913 | }\r |