]>
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 |
7 | Copyright (c) 2009 - 2012, 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 | |
632 | //\r | |
633 | // Test RemainingDevicePath is valid or not.\r | |
634 | //\r | |
635 | if ((RemainingDevicePath != NULL) && !IsDevicePathEnd (RemainingDevicePath)) {\r | |
636 | Status = AtaPassThru->GetDevice (AtaPassThru, RemainingDevicePath, &Port, &PortMultiplierPort);\r | |
637 | if (EFI_ERROR (Status)) {\r | |
638 | return Status;\r | |
639 | }\r | |
640 | }\r | |
641 | \r | |
642 | //\r | |
643 | // Close the I/O Abstraction(s) used to perform the supported test\r | |
644 | //\r | |
645 | gBS->CloseProtocol (\r | |
646 | Controller,\r | |
647 | &gEfiAtaPassThruProtocolGuid,\r | |
648 | This->DriverBindingHandle,\r | |
649 | Controller\r | |
650 | );\r | |
651 | \r | |
652 | //\r | |
653 | // Open the EFI Device Path protocol needed to perform the supported test\r | |
654 | //\r | |
655 | Status = gBS->OpenProtocol (\r | |
656 | Controller,\r | |
657 | &gEfiDevicePathProtocolGuid,\r | |
658 | (VOID **) &ParentDevicePath,\r | |
659 | This->DriverBindingHandle,\r | |
660 | Controller,\r | |
661 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
662 | );\r | |
663 | return Status;\r | |
664 | }\r | |
665 | \r | |
666 | \r | |
667 | /**\r | |
668 | Starts a device controller or a bus controller.\r | |
669 | \r | |
670 | The Start() function is designed to be invoked from the EFI boot service ConnectController().\r | |
58727f29 | 671 | As a result, much of the error checking on the parameters to Start() has been moved into this\r |
672 | common boot service. It is legal to call Start() from other locations,\r | |
ad86a50a | 673 | but the following calling restrictions must be followed or the system behavior will not be deterministic.\r |
674 | 1. ControllerHandle must be a valid EFI_HANDLE.\r | |
675 | 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r | |
676 | EFI_DEVICE_PATH_PROTOCOL.\r | |
677 | 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r | |
58727f29 | 678 | have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r |
ad86a50a | 679 | \r |
680 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r | |
58727f29 | 681 | @param[in] ControllerHandle The handle of the controller to start. This handle\r |
682 | must support a protocol interface that supplies\r | |
ad86a50a | 683 | an I/O abstraction to the driver.\r |
58727f29 | 684 | @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r |
685 | parameter is ignored by device drivers, and is optional for bus\r | |
686 | drivers. For a bus driver, if this parameter is NULL, then handles\r | |
490b5ea1 | 687 | for all the children of Controller are created by this driver.\r |
58727f29 | 688 | If this parameter is not NULL and the first Device Path Node is\r |
689 | not the End of Device Path Node, then only the handle for the\r | |
690 | child device specified by the first Device Path Node of\r | |
ad86a50a | 691 | RemainingDevicePath is created by this driver.\r |
58727f29 | 692 | If the first Device Path Node of RemainingDevicePath is\r |
ad86a50a | 693 | the End of Device Path Node, no child handle is created by this\r |
694 | driver.\r | |
695 | \r | |
696 | @retval EFI_SUCCESS The device was started.\r | |
697 | @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r | |
698 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
699 | @retval Others The driver failded to start the device.\r | |
700 | \r | |
701 | **/\r | |
702 | EFI_STATUS\r | |
703 | EFIAPI\r | |
704 | AtaBusDriverBindingStart (\r | |
705 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
706 | IN EFI_HANDLE Controller,\r | |
707 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
708 | )\r | |
709 | {\r | |
710 | EFI_STATUS Status;\r | |
711 | EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThru;\r | |
712 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
713 | ATA_BUS_DRIVER_DATA *AtaBusDriverData;\r | |
714 | UINT16 Port;\r | |
715 | UINT16 PortMultiplierPort;\r | |
716 | \r | |
717 | AtaBusDriverData = NULL;\r | |
718 | \r | |
719 | Status = gBS->OpenProtocol (\r | |
720 | Controller,\r | |
721 | &gEfiDevicePathProtocolGuid,\r | |
722 | (VOID **) &ParentDevicePath,\r | |
723 | This->DriverBindingHandle,\r | |
724 | Controller,\r | |
725 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
726 | );\r | |
727 | if (EFI_ERROR (Status)) {\r | |
728 | return Status;\r | |
729 | }\r | |
730 | \r | |
37623a5c | 731 | //\r |
732 | // Report Status Code to indicate ATA bus starts\r | |
733 | //\r | |
734 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
735 | EFI_PROGRESS_CODE,\r | |
736 | (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_PC_INIT),\r | |
737 | ParentDevicePath\r | |
738 | );\r | |
739 | \r | |
ad86a50a | 740 | Status = gBS->OpenProtocol (\r |
741 | Controller,\r | |
742 | &gEfiAtaPassThruProtocolGuid,\r | |
743 | (VOID **) &AtaPassThru,\r | |
744 | This->DriverBindingHandle,\r | |
745 | Controller,\r | |
746 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
747 | );\r | |
748 | if ((EFI_ERROR (Status)) && (Status != EFI_ALREADY_STARTED)) {\r | |
749 | goto ErrorExit;\r | |
750 | }\r | |
751 | \r | |
752 | //\r | |
753 | // Check EFI_ALREADY_STARTED to reuse the original ATA_BUS_DRIVER_DATA.\r | |
754 | //\r | |
755 | if (Status != EFI_ALREADY_STARTED) {\r | |
756 | AtaBusDriverData = AllocateZeroPool (sizeof (ATA_BUS_DRIVER_DATA));\r | |
757 | if (AtaBusDriverData == NULL) {\r | |
758 | Status = EFI_OUT_OF_RESOURCES;\r | |
759 | goto ErrorExit;\r | |
760 | }\r | |
761 | \r | |
762 | AtaBusDriverData->AtaPassThru = AtaPassThru;\r | |
490b5ea1 | 763 | AtaBusDriverData->Controller = Controller;\r |
ad86a50a | 764 | AtaBusDriverData->ParentDevicePath = ParentDevicePath;\r |
765 | AtaBusDriverData->DriverBindingHandle = This->DriverBindingHandle;\r | |
766 | \r | |
767 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
768 | &Controller,\r | |
769 | &gEfiCallerIdGuid,\r | |
770 | AtaBusDriverData,\r | |
771 | NULL\r | |
772 | );\r | |
773 | if (EFI_ERROR (Status)) {\r | |
774 | goto ErrorExit;\r | |
775 | }\r | |
776 | \r | |
777 | } else {\r | |
778 | Status = gBS->OpenProtocol (\r | |
779 | Controller,\r | |
780 | &gEfiCallerIdGuid,\r | |
781 | (VOID **) &AtaBusDriverData,\r | |
782 | This->DriverBindingHandle,\r | |
783 | Controller,\r | |
784 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
785 | );\r | |
786 | if (EFI_ERROR (Status)) {\r | |
787 | AtaBusDriverData = NULL;\r | |
788 | goto ErrorExit;\r | |
789 | }\r | |
790 | }\r | |
791 | \r | |
37623a5c | 792 | //\r |
793 | // Report Status Code to indicate detecting devices on bus\r | |
794 | //\r | |
795 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
796 | EFI_PROGRESS_CODE,\r | |
797 | (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_PC_DETECT),\r | |
798 | ParentDevicePath\r | |
799 | );\r | |
800 | \r | |
ad86a50a | 801 | if (RemainingDevicePath == NULL) {\r |
802 | Port = 0xFFFF;\r | |
803 | while (TRUE) {\r | |
804 | Status = AtaPassThru->GetNextPort (AtaPassThru, &Port);\r | |
805 | if (EFI_ERROR (Status)) {\r | |
806 | //\r | |
807 | // We cannot find more legal port then we are done.\r | |
808 | //\r | |
809 | break;\r | |
810 | }\r | |
490b5ea1 | 811 | \r |
ad86a50a | 812 | PortMultiplierPort = 0xFFFF;\r |
813 | while (TRUE) {\r | |
814 | Status = AtaPassThru->GetNextDevice (AtaPassThru, Port, &PortMultiplierPort);\r | |
815 | if (EFI_ERROR (Status)) {\r | |
816 | //\r | |
817 | // We cannot find more legal port multiplier port number for ATA device\r | |
818 | // on the port, then we are done.\r | |
819 | //\r | |
820 | break;\r | |
821 | }\r | |
822 | RegisterAtaDevice (AtaBusDriverData, Port, PortMultiplierPort);\r | |
823 | }\r | |
824 | }\r | |
825 | Status = EFI_SUCCESS;\r | |
826 | } else if (!IsDevicePathEnd (RemainingDevicePath)) {\r | |
827 | Status = AtaPassThru->GetDevice (AtaPassThru, RemainingDevicePath, &Port, &PortMultiplierPort);\r | |
828 | if (!EFI_ERROR (Status)) {\r | |
829 | Status = RegisterAtaDevice (AtaBusDriverData,Port, PortMultiplierPort);\r | |
830 | }\r | |
831 | }\r | |
490b5ea1 | 832 | \r |
ad86a50a | 833 | return Status;\r |
834 | \r | |
835 | ErrorExit:\r | |
836 | \r | |
837 | if (AtaBusDriverData != NULL) {\r | |
838 | gBS->UninstallMultipleProtocolInterfaces (\r | |
839 | Controller,\r | |
840 | &gEfiCallerIdGuid,\r | |
841 | AtaBusDriverData,\r | |
842 | NULL\r | |
843 | );\r | |
844 | FreePool (AtaBusDriverData);\r | |
845 | }\r | |
846 | \r | |
847 | gBS->CloseProtocol (\r | |
848 | Controller,\r | |
849 | &gEfiAtaPassThruProtocolGuid,\r | |
850 | This->DriverBindingHandle,\r | |
851 | Controller\r | |
852 | );\r | |
853 | \r | |
854 | return Status;\r | |
855 | \r | |
856 | }\r | |
857 | \r | |
858 | \r | |
859 | /**\r | |
860 | Stops a device controller or a bus controller.\r | |
58727f29 | 861 | \r |
862 | The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r | |
863 | As a result, much of the error checking on the parameters to Stop() has been moved\r | |
864 | into this common boot service. It is legal to call Stop() from other locations,\r | |
ad86a50a | 865 | but the following calling restrictions must be followed or the system behavior will not be deterministic.\r |
866 | 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r | |
867 | same driver's Start() function.\r | |
868 | 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r | |
869 | EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r | |
870 | Start() function, and the Start() function must have called OpenProtocol() on\r | |
871 | ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r | |
58727f29 | 872 | \r |
ad86a50a | 873 | @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r |
58727f29 | 874 | @param[in] ControllerHandle A handle to the device being stopped. The handle must\r |
875 | support a bus specific I/O protocol for the driver\r | |
ad86a50a | 876 | to use to stop the device.\r |
877 | @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r | |
58727f29 | 878 | @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r |
ad86a50a | 879 | if NumberOfChildren is 0.\r |
880 | \r | |
881 | @retval EFI_SUCCESS The device was stopped.\r | |
882 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
883 | \r | |
884 | **/\r | |
885 | EFI_STATUS\r | |
886 | EFIAPI\r | |
887 | AtaBusDriverBindingStop (\r | |
888 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
889 | IN EFI_HANDLE Controller,\r | |
890 | IN UINTN NumberOfChildren,\r | |
891 | IN EFI_HANDLE *ChildHandleBuffer\r | |
892 | )\r | |
893 | {\r | |
894 | EFI_STATUS Status;\r | |
895 | BOOLEAN AllChildrenStopped;\r | |
896 | UINTN Index;\r | |
897 | ATA_BUS_DRIVER_DATA *AtaBusDriverData;\r | |
898 | \r | |
899 | if (NumberOfChildren == 0) {\r | |
900 | Status = gBS->OpenProtocol (\r | |
901 | Controller,\r | |
902 | &gEfiCallerIdGuid,\r | |
903 | (VOID **) &AtaBusDriverData,\r | |
904 | This->DriverBindingHandle,\r | |
905 | Controller,\r | |
906 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
907 | );\r | |
908 | if (!EFI_ERROR (Status)) {\r | |
909 | gBS->UninstallMultipleProtocolInterfaces (\r | |
910 | Controller,\r | |
911 | &gEfiCallerIdGuid,\r | |
912 | AtaBusDriverData,\r | |
913 | NULL\r | |
914 | );\r | |
915 | FreePool (AtaBusDriverData);\r | |
916 | }\r | |
917 | \r | |
918 | gBS->CloseProtocol (\r | |
919 | Controller,\r | |
920 | &gEfiAtaPassThruProtocolGuid,\r | |
921 | This->DriverBindingHandle,\r | |
922 | Controller\r | |
923 | );\r | |
924 | \r | |
925 | return EFI_SUCCESS;\r | |
926 | }\r | |
927 | \r | |
928 | AllChildrenStopped = TRUE;\r | |
929 | \r | |
930 | for (Index = 0; Index < NumberOfChildren; Index++) {\r | |
931 | \r | |
932 | Status = UnregisterAtaDevice (This, Controller, ChildHandleBuffer[Index]);\r | |
933 | if (EFI_ERROR (Status)) {\r | |
934 | AllChildrenStopped = FALSE;\r | |
935 | }\r | |
936 | }\r | |
937 | \r | |
938 | if (!AllChildrenStopped) {\r | |
939 | return EFI_DEVICE_ERROR;\r | |
940 | }\r | |
941 | \r | |
942 | return EFI_SUCCESS;\r | |
943 | }\r | |
944 | \r | |
945 | \r | |
946 | /**\r | |
947 | Reset the Block Device.\r | |
948 | \r | |
949 | @param This Indicates a pointer to the calling context.\r | |
950 | @param ExtendedVerification Driver may perform diagnostics on reset.\r | |
951 | \r | |
952 | @retval EFI_SUCCESS The device was reset.\r | |
953 | @retval EFI_DEVICE_ERROR The device is not functioning properly and could\r | |
954 | not be reset.\r | |
955 | \r | |
956 | **/\r | |
957 | EFI_STATUS\r | |
958 | EFIAPI\r | |
959 | AtaBlockIoReset (\r | |
960 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
961 | IN BOOLEAN ExtendedVerification\r | |
962 | )\r | |
963 | {\r | |
964 | EFI_STATUS Status;\r | |
965 | ATA_DEVICE *AtaDevice;\r | |
966 | EFI_TPL OldTpl;\r | |
967 | \r | |
968 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
969 | \r | |
970 | AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (This);\r | |
971 | \r | |
490b5ea1 | 972 | Status = ResetAtaDevice (AtaDevice);\r |
ad86a50a | 973 | \r |
c6e797ae | 974 | if (EFI_ERROR (Status)) {\r |
975 | Status = EFI_DEVICE_ERROR;\r | |
976 | }\r | |
977 | \r | |
ad86a50a | 978 | gBS->RestoreTPL (OldTpl);\r |
979 | return Status;\r | |
980 | }\r | |
981 | \r | |
982 | \r | |
983 | /**\r | |
984 | Read/Write BufferSize bytes from Lba from/into Buffer.\r | |
985 | \r | |
490b5ea1 | 986 | @param[in] This Indicates a pointer to the calling context. Either be\r |
58727f29 | 987 | block I/O or block I/O2.\r |
490b5ea1 | 988 | @param[in] MediaId The media ID that the read/write request is for.\r |
989 | @param[in] Lba The starting logical block address to be read/written.\r | |
990 | The caller is responsible for reading/writing to only\r | |
991 | legitimate locations.\r | |
992 | @param[in, out] Token A pointer to the token associated with the transaction.\r | |
993 | @param[in] BufferSize Size of Buffer, must be a multiple of device block size.\r | |
994 | @param[out] Buffer A pointer to the destination/source buffer for the data.\r | |
995 | @param[in] IsBlockIo2 Indicate the calling is from BlockIO or BlockIO2. TURE is\r | |
996 | from BlockIO2, FALSE is for BlockIO.\r | |
997 | @param[in] IsWrite Indicates whether it is a write operation.\r | |
ad86a50a | 998 | \r |
999 | @retval EFI_SUCCESS The data was read/written correctly to the device.\r | |
1000 | @retval EFI_WRITE_PROTECTED The device can not be read/written to.\r | |
1001 | @retval EFI_DEVICE_ERROR The device reported an error while performing the read/write.\r | |
1002 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
1003 | @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r | |
1004 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
58727f29 | 1005 | @retval EFI_INVALID_PARAMETER The read/write request contains LBAs that are not valid,\r |
ad86a50a | 1006 | or the buffer is not on proper alignment.\r |
1007 | \r | |
1008 | **/\r | |
1009 | EFI_STATUS\r | |
1010 | BlockIoReadWrite (\r | |
490b5ea1 | 1011 | IN VOID *This,\r |
1012 | IN UINT32 MediaId,\r | |
1013 | IN EFI_LBA Lba,\r | |
1014 | IN OUT EFI_BLOCK_IO2_TOKEN *Token,\r | |
1015 | IN UINTN BufferSize,\r | |
1016 | OUT VOID *Buffer,\r | |
1017 | IN BOOLEAN IsBlockIo2,\r | |
1018 | IN BOOLEAN IsWrite\r | |
ad86a50a | 1019 | )\r |
1020 | {\r | |
1021 | ATA_DEVICE *AtaDevice;\r | |
1022 | EFI_STATUS Status;\r | |
1023 | EFI_TPL OldTpl;\r | |
1024 | EFI_BLOCK_IO_MEDIA *Media;\r | |
1025 | UINTN BlockSize;\r | |
1026 | UINTN NumberOfBlocks;\r | |
1027 | UINTN IoAlign;\r | |
1028 | \r | |
490b5ea1 | 1029 | if (IsBlockIo2) {\r |
1030 | Media = ((EFI_BLOCK_IO2_PROTOCOL *) This)->Media;\r | |
1031 | AtaDevice = ATA_DEVICE_FROM_BLOCK_IO2 (This);\r | |
1032 | } else {\r | |
1033 | Media = ((EFI_BLOCK_IO_PROTOCOL *) This)->Media;\r | |
1034 | AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (This);\r | |
1035 | }\r | |
1036 | \r | |
fcf5e49d RN |
1037 | if (MediaId != Media->MediaId) {\r |
1038 | return EFI_MEDIA_CHANGED;\r | |
1039 | }\r | |
1040 | \r | |
490b5ea1 | 1041 | //\r |
1042 | // Check parameters.\r | |
1043 | //\r | |
ad86a50a | 1044 | if (Buffer == NULL) {\r |
1045 | return EFI_INVALID_PARAMETER;\r | |
1046 | }\r | |
1047 | \r | |
1048 | if (BufferSize == 0) {\r | |
1049 | return EFI_SUCCESS;\r | |
58727f29 | 1050 | }\r |
ad86a50a | 1051 | \r |
ad86a50a | 1052 | BlockSize = Media->BlockSize;\r |
1053 | if ((BufferSize % BlockSize) != 0) {\r | |
1054 | return EFI_BAD_BUFFER_SIZE;\r | |
1055 | }\r | |
58727f29 | 1056 | \r |
ad86a50a | 1057 | NumberOfBlocks = BufferSize / BlockSize;\r |
1058 | if ((Lba + NumberOfBlocks - 1) > Media->LastBlock) {\r | |
1059 | return EFI_INVALID_PARAMETER;\r | |
1060 | }\r | |
1061 | \r | |
1062 | IoAlign = Media->IoAlign;\r | |
1063 | if (IoAlign > 0 && (((UINTN) Buffer & (IoAlign - 1)) != 0)) {\r | |
1064 | return EFI_INVALID_PARAMETER;\r | |
1065 | }\r | |
1066 | \r | |
1067 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
58727f29 | 1068 | \r |
ad86a50a | 1069 | //\r |
1070 | // Invoke low level AtaDevice Access Routine.\r | |
1071 | //\r | |
490b5ea1 | 1072 | Status = AccessAtaDevice (AtaDevice, Buffer, Lba, NumberOfBlocks, IsWrite, Token);\r |
58727f29 | 1073 | \r |
ad86a50a | 1074 | gBS->RestoreTPL (OldTpl);\r |
1075 | \r | |
1076 | return Status;\r | |
1077 | }\r | |
1078 | \r | |
1079 | \r | |
1080 | /**\r | |
1081 | Read BufferSize bytes from Lba into Buffer.\r | |
1082 | \r | |
1083 | @param This Indicates a pointer to the calling context.\r | |
1084 | @param MediaId Id of the media, changes every time the media is replaced.\r | |
1085 | @param Lba The starting Logical Block Address to read from\r | |
1086 | @param BufferSize Size of Buffer, must be a multiple of device block size.\r | |
1087 | @param Buffer A pointer to the destination buffer for the data. The caller is\r | |
1088 | responsible for either having implicit or explicit ownership of the buffer.\r | |
1089 | \r | |
1090 | @retval EFI_SUCCESS The data was read correctly from the device.\r | |
1091 | @retval EFI_DEVICE_ERROR The device reported an error while performing the read.\r | |
1092 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
1093 | @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.\r | |
1094 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
58727f29 | 1095 | @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r |
ad86a50a | 1096 | or the buffer is not on proper alignment.\r |
1097 | \r | |
1098 | **/\r | |
1099 | EFI_STATUS\r | |
1100 | EFIAPI\r | |
1101 | AtaBlockIoReadBlocks (\r | |
1102 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
1103 | IN UINT32 MediaId,\r | |
1104 | IN EFI_LBA Lba,\r | |
1105 | IN UINTN BufferSize,\r | |
1106 | OUT VOID *Buffer\r | |
1107 | )\r | |
1108 | {\r | |
490b5ea1 | 1109 | return BlockIoReadWrite ((VOID *) This, MediaId, Lba, NULL, BufferSize, Buffer, FALSE, FALSE);\r |
ad86a50a | 1110 | }\r |
1111 | \r | |
1112 | \r | |
1113 | /**\r | |
1114 | Write BufferSize bytes from Lba into Buffer.\r | |
1115 | \r | |
1116 | @param This Indicates a pointer to the calling context.\r | |
1117 | @param MediaId The media ID that the write request is for.\r | |
1118 | @param Lba The starting logical block address to be written. The caller is\r | |
1119 | responsible for writing to only legitimate locations.\r | |
1120 | @param BufferSize Size of Buffer, must be a multiple of device block size.\r | |
1121 | @param Buffer A pointer to the source buffer for the data.\r | |
1122 | \r | |
1123 | @retval EFI_SUCCESS The data was written correctly to the device.\r | |
1124 | @retval EFI_WRITE_PROTECTED The device can not be written to.\r | |
1125 | @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r | |
1126 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
1127 | @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r | |
1128 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
58727f29 | 1129 | @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,\r |
ad86a50a | 1130 | or the buffer is not on proper alignment.\r |
1131 | \r | |
1132 | **/\r | |
1133 | EFI_STATUS\r | |
1134 | EFIAPI\r | |
1135 | AtaBlockIoWriteBlocks (\r | |
1136 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
1137 | IN UINT32 MediaId,\r | |
1138 | IN EFI_LBA Lba,\r | |
1139 | IN UINTN BufferSize,\r | |
1140 | IN VOID *Buffer\r | |
1141 | )\r | |
1142 | {\r | |
490b5ea1 | 1143 | return BlockIoReadWrite ((VOID *) This, MediaId, Lba, NULL, BufferSize, Buffer, FALSE, TRUE);\r |
ad86a50a | 1144 | }\r |
1145 | \r | |
1146 | \r | |
1147 | /**\r | |
1148 | Flush the Block Device.\r | |
1149 | \r | |
1150 | @param This Indicates a pointer to the calling context.\r | |
1151 | \r | |
1152 | @retval EFI_SUCCESS All outstanding data was written to the device\r | |
1153 | @retval EFI_DEVICE_ERROR The device reported an error while writing back the data\r | |
1154 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
1155 | \r | |
1156 | **/\r | |
1157 | EFI_STATUS\r | |
1158 | EFIAPI\r | |
1159 | AtaBlockIoFlushBlocks (\r | |
1160 | IN EFI_BLOCK_IO_PROTOCOL *This\r | |
1161 | )\r | |
1162 | {\r | |
1163 | //\r | |
1164 | // return directly\r | |
1165 | //\r | |
1166 | return EFI_SUCCESS;\r | |
1167 | }\r | |
1168 | \r | |
490b5ea1 | 1169 | /**\r |
1170 | Reset the Block Device.\r | |
1171 | \r | |
1172 | @param[in] This Indicates a pointer to the calling context.\r | |
1173 | @param[in] ExtendedVerification Driver may perform diagnostics on reset.\r | |
1174 | \r | |
1175 | @retval EFI_SUCCESS The device was reset.\r | |
1176 | @retval EFI_DEVICE_ERROR The device is not functioning properly and could\r | |
1177 | not be reset.\r | |
1178 | \r | |
1179 | **/\r | |
1180 | EFI_STATUS\r | |
1181 | EFIAPI\r | |
1182 | AtaBlockIoResetEx (\r | |
1183 | IN EFI_BLOCK_IO2_PROTOCOL *This,\r | |
1184 | IN BOOLEAN ExtendedVerification\r | |
1185 | )\r | |
1186 | {\r | |
1187 | EFI_STATUS Status;\r | |
1188 | ATA_DEVICE *AtaDevice;\r | |
1189 | EFI_TPL OldTpl;\r | |
1190 | \r | |
1191 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r | |
1192 | \r | |
1193 | AtaDevice = ATA_DEVICE_FROM_BLOCK_IO2 (This);\r | |
1194 | \r | |
1195 | Status = ResetAtaDevice (AtaDevice);\r | |
1196 | \r | |
1197 | if (EFI_ERROR (Status)) {\r | |
1198 | Status = EFI_DEVICE_ERROR;\r | |
1199 | }\r | |
1200 | \r | |
1201 | gBS->RestoreTPL (OldTpl);\r | |
1202 | return Status;\r | |
1203 | }\r | |
1204 | \r | |
1205 | /**\r | |
1206 | Read BufferSize bytes from Lba into Buffer.\r | |
1207 | \r | |
1208 | @param[in] This Indicates a pointer to the calling context.\r | |
1209 | @param[in] MediaId Id of the media, changes every time the media is replaced.\r | |
1210 | @param[in] Lba The starting Logical Block Address to read from.\r | |
1211 | @param[in, out] Token A pointer to the token associated with the transaction.\r | |
1212 | @param[in] BufferSize Size of Buffer, must be a multiple of device block size.\r | |
1213 | @param[out] Buffer A pointer to the destination buffer for the data. The caller is\r | |
1214 | responsible for either having implicit or explicit ownership of the buffer.\r | |
1215 | \r | |
1216 | @retval EFI_SUCCESS The read request was queued if Event is not NULL.\r | |
1217 | The data was read correctly from the device if\r | |
1218 | the Event is NULL.\r | |
1219 | @retval EFI_DEVICE_ERROR The device reported an error while performing\r | |
1220 | the read.\r | |
1221 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
1222 | @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.\r | |
1223 | @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the\r | |
1224 | intrinsic block size of the device.\r | |
58727f29 | 1225 | @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r |
490b5ea1 | 1226 | or the buffer is not on proper alignment.\r |
1227 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack\r | |
1228 | of resources.\r | |
1229 | \r | |
1230 | **/\r | |
1231 | EFI_STATUS\r | |
1232 | EFIAPI\r | |
1233 | AtaBlockIoReadBlocksEx (\r | |
1234 | IN EFI_BLOCK_IO2_PROTOCOL *This,\r | |
1235 | IN UINT32 MediaId,\r | |
1236 | IN EFI_LBA Lba,\r | |
1237 | IN OUT EFI_BLOCK_IO2_TOKEN *Token,\r | |
1238 | IN UINTN BufferSize,\r | |
1239 | OUT VOID *Buffer\r | |
1240 | )\r | |
1241 | {\r | |
1242 | return BlockIoReadWrite ((VOID *) This, MediaId, Lba, Token, BufferSize, Buffer, TRUE, FALSE);\r | |
1243 | }\r | |
1244 | \r | |
1245 | \r | |
1246 | /**\r | |
1247 | Write BufferSize bytes from Lba into Buffer.\r | |
1248 | \r | |
1249 | @param[in] This Indicates a pointer to the calling context.\r | |
1250 | @param[in] MediaId The media ID that the write request is for.\r | |
1251 | @param[in] Lba The starting logical block address to be written. The\r | |
1252 | caller is responsible for writing to only legitimate\r | |
1253 | locations.\r | |
1254 | @param[in, out] Token A pointer to the token associated with the transaction.\r | |
1255 | @param[in] BufferSize Size of Buffer, must be a multiple of device block size.\r | |
1256 | @param[in] Buffer A pointer to the source buffer for the data.\r | |
ad86a50a | 1257 | \r |
490b5ea1 | 1258 | @retval EFI_SUCCESS The data was written correctly to the device.\r |
1259 | @retval EFI_WRITE_PROTECTED The device can not be written to.\r | |
1260 | @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r | |
1261 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
1262 | @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r | |
1263 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
58727f29 | 1264 | @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,\r |
490b5ea1 | 1265 | or the buffer is not on proper alignment.\r |
1266 | \r | |
1267 | **/\r | |
1268 | EFI_STATUS\r | |
1269 | EFIAPI\r | |
1270 | AtaBlockIoWriteBlocksEx (\r | |
1271 | IN EFI_BLOCK_IO2_PROTOCOL *This,\r | |
1272 | IN UINT32 MediaId,\r | |
1273 | IN EFI_LBA Lba,\r | |
1274 | IN OUT EFI_BLOCK_IO2_TOKEN *Token,\r | |
1275 | IN UINTN BufferSize,\r | |
1276 | IN VOID *Buffer\r | |
1277 | )\r | |
1278 | {\r | |
1279 | return BlockIoReadWrite ((VOID *) This, MediaId, Lba, Token, BufferSize, Buffer, TRUE, TRUE);\r | |
1280 | }\r | |
1281 | \r | |
1282 | \r | |
1283 | /**\r | |
1284 | Flush the Block Device.\r | |
1285 | \r | |
1286 | @param[in] This Indicates a pointer to the calling context.\r | |
1287 | @param[in, out] Token A pointer to the token associated with the transaction.\r | |
1288 | \r | |
1289 | @retval EFI_SUCCESS All outstanding data was written to the device\r | |
1290 | @retval EFI_DEVICE_ERROR The device reported an error while writing back the data\r | |
1291 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
1292 | \r | |
1293 | **/\r | |
1294 | EFI_STATUS\r | |
1295 | EFIAPI\r | |
1296 | AtaBlockIoFlushBlocksEx (\r | |
1297 | IN EFI_BLOCK_IO2_PROTOCOL *This,\r | |
1298 | IN OUT EFI_BLOCK_IO2_TOKEN *Token\r | |
1299 | )\r | |
1300 | {\r | |
1301 | //\r | |
3c063fed | 1302 | // Signal event and return directly.\r |
490b5ea1 | 1303 | //\r |
1304 | if (Token != NULL && Token->Event != NULL) {\r | |
1305 | Token->TransactionStatus = EFI_SUCCESS;\r | |
1306 | gBS->SignalEvent (Token->Event);\r | |
1307 | }\r | |
1308 | return EFI_SUCCESS;\r | |
1309 | }\r | |
ad86a50a | 1310 | /**\r |
1311 | Provides inquiry information for the controller type.\r | |
58727f29 | 1312 | \r |
ad86a50a | 1313 | This function is used by the IDE bus driver to get inquiry data. Data format\r |
1314 | of Identify data is defined by the Interface GUID.\r | |
1315 | \r | |
05a44e91 | 1316 | @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.\r |
1317 | @param[in, out] InquiryData Pointer to a buffer for the inquiry data.\r | |
1318 | @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.\r | |
ad86a50a | 1319 | \r |
1320 | @retval EFI_SUCCESS The command was accepted without any errors.\r | |
58727f29 | 1321 | @retval EFI_NOT_FOUND Device does not support this data class\r |
1322 | @retval EFI_DEVICE_ERROR Error reading InquiryData from device\r | |
1323 | @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough\r | |
ad86a50a | 1324 | \r |
1325 | **/\r | |
1326 | EFI_STATUS\r | |
1327 | EFIAPI\r | |
1328 | AtaDiskInfoInquiry (\r | |
1329 | IN EFI_DISK_INFO_PROTOCOL *This,\r | |
1330 | IN OUT VOID *InquiryData,\r | |
1331 | IN OUT UINT32 *InquiryDataSize\r | |
1332 | )\r | |
1333 | {\r | |
1334 | return EFI_NOT_FOUND;\r | |
1335 | }\r | |
1336 | \r | |
1337 | \r | |
1338 | /**\r | |
1339 | Provides identify information for the controller type.\r | |
1340 | \r | |
1341 | This function is used by the IDE bus driver to get identify data. Data format\r | |
1342 | of Identify data is defined by the Interface GUID.\r | |
1343 | \r | |
58727f29 | 1344 | @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL\r |
ad86a50a | 1345 | instance.\r |
05a44e91 | 1346 | @param[in, out] IdentifyData Pointer to a buffer for the identify data.\r |
1347 | @param[in, out] IdentifyDataSize Pointer to the value for the identify data\r | |
ad86a50a | 1348 | size.\r |
1349 | \r | |
1350 | @retval EFI_SUCCESS The command was accepted without any errors.\r | |
58727f29 | 1351 | @retval EFI_NOT_FOUND Device does not support this data class\r |
1352 | @retval EFI_DEVICE_ERROR Error reading IdentifyData from device\r | |
1353 | @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough\r | |
ad86a50a | 1354 | \r |
1355 | **/\r | |
1356 | EFI_STATUS\r | |
1357 | EFIAPI\r | |
1358 | AtaDiskInfoIdentify (\r | |
1359 | IN EFI_DISK_INFO_PROTOCOL *This,\r | |
1360 | IN OUT VOID *IdentifyData,\r | |
1361 | IN OUT UINT32 *IdentifyDataSize\r | |
1362 | )\r | |
1363 | {\r | |
1364 | EFI_STATUS Status;\r | |
1365 | ATA_DEVICE *AtaDevice;\r | |
1366 | \r | |
1367 | AtaDevice = ATA_DEVICE_FROM_DISK_INFO (This);\r | |
1368 | \r | |
1369 | Status = EFI_BUFFER_TOO_SMALL;\r | |
3c063fed | 1370 | if (*IdentifyDataSize >= sizeof (ATA_IDENTIFY_DATA)) {\r |
ad86a50a | 1371 | Status = EFI_SUCCESS;\r |
3c063fed | 1372 | CopyMem (IdentifyData, AtaDevice->IdentifyData, sizeof (ATA_IDENTIFY_DATA));\r |
ad86a50a | 1373 | }\r |
3c063fed | 1374 | *IdentifyDataSize = sizeof (ATA_IDENTIFY_DATA);\r |
ad86a50a | 1375 | \r |
1376 | return Status;\r | |
1377 | }\r | |
1378 | \r | |
1379 | \r | |
1380 | /**\r | |
1381 | Provides sense data information for the controller type.\r | |
58727f29 | 1382 | \r |
1383 | This function is used by the IDE bus driver to get sense data.\r | |
ad86a50a | 1384 | Data format of Sense data is defined by the Interface GUID.\r |
1385 | \r | |
05a44e91 | 1386 | @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.\r |
1387 | @param[in, out] SenseData Pointer to the SenseData.\r | |
1388 | @param[in, out] SenseDataSize Size of SenseData in bytes.\r | |
1389 | @param[out] SenseDataNumber Pointer to the value for the sense data size.\r | |
ad86a50a | 1390 | \r |
1391 | @retval EFI_SUCCESS The command was accepted without any errors.\r | |
1392 | @retval EFI_NOT_FOUND Device does not support this data class.\r | |
1393 | @retval EFI_DEVICE_ERROR Error reading SenseData from device.\r | |
1394 | @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.\r | |
1395 | \r | |
1396 | **/\r | |
1397 | EFI_STATUS\r | |
1398 | EFIAPI\r | |
1399 | AtaDiskInfoSenseData (\r | |
1400 | IN EFI_DISK_INFO_PROTOCOL *This,\r | |
1401 | IN OUT VOID *SenseData,\r | |
1402 | IN OUT UINT32 *SenseDataSize,\r | |
1403 | OUT UINT8 *SenseDataNumber\r | |
1404 | )\r | |
1405 | {\r | |
1406 | return EFI_NOT_FOUND;\r | |
1407 | }\r | |
1408 | \r | |
1409 | \r | |
1410 | /**\r | |
1411 | This function is used by the IDE bus driver to get controller information.\r | |
1412 | \r | |
58727f29 | 1413 | @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.\r |
ad86a50a | 1414 | @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.\r |
1415 | @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.\r | |
1416 | \r | |
1417 | @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.\r | |
1418 | @retval EFI_UNSUPPORTED This is not an IDE device.\r | |
1419 | \r | |
1420 | **/\r | |
1421 | EFI_STATUS\r | |
1422 | EFIAPI\r | |
1423 | AtaDiskInfoWhichIde (\r | |
1424 | IN EFI_DISK_INFO_PROTOCOL *This,\r | |
1425 | OUT UINT32 *IdeChannel,\r | |
1426 | OUT UINT32 *IdeDevice\r | |
1427 | )\r | |
1428 | {\r | |
1429 | ATA_DEVICE *AtaDevice;\r | |
1430 | \r | |
1431 | AtaDevice = ATA_DEVICE_FROM_DISK_INFO (This);\r | |
1432 | *IdeChannel = AtaDevice->Port;\r | |
1433 | *IdeDevice = AtaDevice->PortMultiplierPort;\r | |
1434 | \r | |
1435 | return EFI_SUCCESS;\r | |
1436 | }\r | |
1437 | \r | |
c24097a5 | 1438 | /**\r |
1439 | Send a security protocol command to a device that receives data and/or the result\r | |
1440 | of one or more commands sent by SendData.\r | |
1441 | \r | |
1442 | The ReceiveData function sends a security protocol command to the given MediaId.\r | |
1443 | The security protocol command sent is defined by SecurityProtocolId and contains\r | |
1444 | the security protocol specific data SecurityProtocolSpecificData. The function\r | |
1445 | returns the data from the security protocol command in PayloadBuffer.\r | |
1446 | \r | |
1447 | For devices supporting the SCSI command set, the security protocol command is sent\r | |
1448 | using the SECURITY PROTOCOL IN command defined in SPC-4.\r | |
1449 | \r | |
1450 | For devices supporting the ATA command set, the security protocol command is sent\r | |
1451 | using one of the TRUSTED RECEIVE commands defined in ATA8-ACS if PayloadBufferSize\r | |
1452 | is non-zero.\r | |
1453 | \r | |
1454 | If the PayloadBufferSize is zero, the security protocol command is sent using the\r | |
1455 | Trusted Non-Data command defined in ATA8-ACS.\r | |
1456 | \r | |
1457 | If PayloadBufferSize is too small to store the available data from the security\r | |
1458 | protocol command, the function shall copy PayloadBufferSize bytes into the\r | |
1459 | PayloadBuffer and return EFI_WARN_BUFFER_TOO_SMALL.\r | |
1460 | \r | |
1461 | If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,\r | |
1462 | the function shall return EFI_INVALID_PARAMETER.\r | |
1463 | \r | |
1464 | If the given MediaId does not support security protocol commands, the function shall\r | |
1465 | return EFI_UNSUPPORTED. If there is no media in the device, the function returns\r | |
1466 | EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the device,\r | |
1467 | the function returns EFI_MEDIA_CHANGED.\r | |
1468 | \r | |
1469 | If the security protocol fails to complete within the Timeout period, the function\r | |
1470 | shall return EFI_TIMEOUT.\r | |
1471 | \r | |
1472 | If the security protocol command completes without an error, the function shall\r | |
1473 | return EFI_SUCCESS. If the security protocol command completes with an error, the\r | |
1474 | function shall return EFI_DEVICE_ERROR.\r | |
1475 | \r | |
1476 | @param This Indicates a pointer to the calling context.\r | |
1477 | @param MediaId ID of the medium to receive data from.\r | |
1478 | @param Timeout The timeout, in 100ns units, to use for the execution\r | |
1479 | of the security protocol command. A Timeout value of 0\r | |
1480 | means that this function will wait indefinitely for the\r | |
1481 | security protocol command to execute. If Timeout is greater\r | |
1482 | than zero, then this function will return EFI_TIMEOUT\r | |
1483 | if the time required to execute the receive data command\r | |
1484 | is greater than Timeout.\r | |
1485 | @param SecurityProtocolId The value of the "Security Protocol" parameter of\r | |
1486 | the security protocol command to be sent.\r | |
1487 | @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter\r | |
1488 | of the security protocol command to be sent.\r | |
1489 | @param PayloadBufferSize Size in bytes of the payload data buffer.\r | |
1490 | @param PayloadBuffer A pointer to a destination buffer to store the security\r | |
1491 | protocol command specific payload data for the security\r | |
1492 | protocol command. The caller is responsible for having\r | |
1493 | either implicit or explicit ownership of the buffer.\r | |
1494 | @param PayloadTransferSize A pointer to a buffer to store the size in bytes of the\r | |
1495 | data written to the payload data buffer.\r | |
1496 | \r | |
1497 | @retval EFI_SUCCESS The security protocol command completed successfully.\r | |
1498 | @retval EFI_WARN_BUFFER_TOO_SMALL The PayloadBufferSize was too small to store the available\r | |
1499 | data from the device. The PayloadBuffer contains the truncated data.\r | |
1500 | @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.\r | |
1501 | @retval EFI_DEVICE_ERROR The security protocol command completed with an error.\r | |
1502 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
1503 | @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.\r | |
1504 | @retval EFI_INVALID_PARAMETER The PayloadBuffer or PayloadTransferSize is NULL and\r | |
1505 | PayloadBufferSize is non-zero.\r | |
1506 | @retval EFI_TIMEOUT A timeout occurred while waiting for the security\r | |
1507 | protocol command to execute.\r | |
1508 | \r | |
1509 | **/\r | |
1510 | EFI_STATUS\r | |
1511 | EFIAPI\r | |
1512 | AtaStorageSecurityReceiveData (\r | |
1513 | IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,\r | |
1514 | IN UINT32 MediaId,\r | |
1515 | IN UINT64 Timeout,\r | |
1516 | IN UINT8 SecurityProtocolId,\r | |
1517 | IN UINT16 SecurityProtocolSpecificData,\r | |
1518 | IN UINTN PayloadBufferSize,\r | |
1519 | OUT VOID *PayloadBuffer,\r | |
1520 | OUT UINTN *PayloadTransferSize\r | |
1521 | )\r | |
1522 | {\r | |
1523 | EFI_STATUS Status;\r | |
1524 | ATA_DEVICE *Private;\r | |
3c063fed | 1525 | EFI_TPL OldTpl;\r |
c24097a5 | 1526 | \r |
1527 | DEBUG ((EFI_D_INFO, "EFI Storage Security Protocol - Read"));\r | |
1528 | if ((PayloadBuffer == NULL || PayloadTransferSize == NULL) && PayloadBufferSize != 0) {\r | |
1529 | return EFI_INVALID_PARAMETER;\r | |
1530 | }\r | |
1531 | \r | |
1532 | Status = EFI_SUCCESS;\r | |
1533 | Private = ATA_DEVICE_FROM_STORAGE_SECURITY (This);\r | |
1534 | \r | |
1535 | if (MediaId != Private->BlockIo.Media->MediaId) {\r | |
1536 | return EFI_MEDIA_CHANGED;\r | |
1537 | }\r | |
1538 | \r | |
1539 | if (!Private->BlockIo.Media->MediaPresent) {\r | |
1540 | return EFI_NO_MEDIA;\r | |
1541 | }\r | |
1542 | \r | |
3c063fed | 1543 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
1544 | \r | |
c24097a5 | 1545 | Status = TrustTransferAtaDevice (\r |
1546 | Private,\r | |
1547 | PayloadBuffer,\r | |
1548 | SecurityProtocolId,\r | |
1549 | SecurityProtocolSpecificData,\r | |
1550 | PayloadBufferSize,\r | |
1551 | FALSE,\r | |
1552 | Timeout,\r | |
1553 | PayloadTransferSize\r | |
1554 | );\r | |
1555 | \r | |
3c063fed | 1556 | gBS->RestoreTPL (OldTpl);\r |
c24097a5 | 1557 | return Status;\r |
1558 | }\r | |
1559 | \r | |
1560 | /**\r | |
1561 | Send a security protocol command to a device.\r | |
1562 | \r | |
1563 | The SendData function sends a security protocol command containing the payload\r | |
1564 | PayloadBuffer to the given MediaId. The security protocol command sent is\r | |
1565 | defined by SecurityProtocolId and contains the security protocol specific data\r | |
1566 | SecurityProtocolSpecificData. If the underlying protocol command requires a\r | |
1567 | specific padding for the command payload, the SendData function shall add padding\r | |
1568 | bytes to the command payload to satisfy the padding requirements.\r | |
1569 | \r | |
1570 | For devices supporting the SCSI command set, the security protocol command is sent\r | |
1571 | using the SECURITY PROTOCOL OUT command defined in SPC-4.\r | |
1572 | \r | |
1573 | For devices supporting the ATA command set, the security protocol command is sent\r | |
1574 | using one of the TRUSTED SEND commands defined in ATA8-ACS if PayloadBufferSize\r | |
1575 | is non-zero. If the PayloadBufferSize is zero, the security protocol command is\r | |
1576 | sent using the Trusted Non-Data command defined in ATA8-ACS.\r | |
1577 | \r | |
1578 | If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall\r | |
1579 | return EFI_INVALID_PARAMETER.\r | |
1580 | \r | |
1581 | If the given MediaId does not support security protocol commands, the function\r | |
1582 | shall return EFI_UNSUPPORTED. If there is no media in the device, the function\r | |
1583 | returns EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the\r | |
1584 | device, the function returns EFI_MEDIA_CHANGED.\r | |
1585 | \r | |
1586 | If the security protocol fails to complete within the Timeout period, the function\r | |
1587 | shall return EFI_TIMEOUT.\r | |
1588 | \r | |
1589 | If the security protocol command completes without an error, the function shall return\r | |
1590 | EFI_SUCCESS. If the security protocol command completes with an error, the function\r | |
1591 | shall return EFI_DEVICE_ERROR.\r | |
1592 | \r | |
1593 | @param This Indicates a pointer to the calling context.\r | |
1594 | @param MediaId ID of the medium to receive data from.\r | |
1595 | @param Timeout The timeout, in 100ns units, to use for the execution\r | |
1596 | of the security protocol command. A Timeout value of 0\r | |
1597 | means that this function will wait indefinitely for the\r | |
1598 | security protocol command to execute. If Timeout is greater\r | |
1599 | than zero, then this function will return EFI_TIMEOUT\r | |
1600 | if the time required to execute the receive data command\r | |
1601 | is greater than Timeout.\r | |
1602 | @param SecurityProtocolId The value of the "Security Protocol" parameter of\r | |
1603 | the security protocol command to be sent.\r | |
1604 | @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter\r | |
1605 | of the security protocol command to be sent.\r | |
1606 | @param PayloadBufferSize Size in bytes of the payload data buffer.\r | |
1607 | @param PayloadBuffer A pointer to a destination buffer to store the security\r | |
1608 | protocol command specific payload data for the security\r | |
1609 | protocol command.\r | |
1610 | \r | |
1611 | @retval EFI_SUCCESS The security protocol command completed successfully.\r | |
1612 | @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.\r | |
1613 | @retval EFI_DEVICE_ERROR The security protocol command completed with an error.\r | |
1614 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
1615 | @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.\r | |
1616 | @retval EFI_INVALID_PARAMETER The PayloadBuffer is NULL and PayloadBufferSize is non-zero.\r | |
1617 | @retval EFI_TIMEOUT A timeout occurred while waiting for the security\r | |
1618 | protocol command to execute.\r | |
1619 | \r | |
1620 | **/\r | |
1621 | EFI_STATUS\r | |
1622 | EFIAPI\r | |
1623 | AtaStorageSecuritySendData (\r | |
1624 | IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,\r | |
1625 | IN UINT32 MediaId,\r | |
1626 | IN UINT64 Timeout,\r | |
1627 | IN UINT8 SecurityProtocolId,\r | |
1628 | IN UINT16 SecurityProtocolSpecificData,\r | |
1629 | IN UINTN PayloadBufferSize,\r | |
1630 | IN VOID *PayloadBuffer\r | |
1631 | )\r | |
1632 | {\r | |
1633 | EFI_STATUS Status;\r | |
1634 | ATA_DEVICE *Private;\r | |
3c063fed | 1635 | EFI_TPL OldTpl;\r |
c24097a5 | 1636 | \r |
1637 | DEBUG ((EFI_D_INFO, "EFI Storage Security Protocol - Send"));\r | |
1638 | if ((PayloadBuffer == NULL) && (PayloadBufferSize != 0)) {\r | |
1639 | return EFI_INVALID_PARAMETER;\r | |
1640 | }\r | |
1641 | \r | |
1642 | Status = EFI_SUCCESS;\r | |
1643 | Private = ATA_DEVICE_FROM_STORAGE_SECURITY (This);\r | |
1644 | \r | |
1645 | if (MediaId != Private->BlockIo.Media->MediaId) {\r | |
1646 | return EFI_MEDIA_CHANGED;\r | |
1647 | }\r | |
1648 | \r | |
3c063fed | 1649 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
c24097a5 | 1650 | Status = TrustTransferAtaDevice (\r |
1651 | Private,\r | |
1652 | PayloadBuffer,\r | |
1653 | SecurityProtocolId,\r | |
1654 | SecurityProtocolSpecificData,\r | |
1655 | PayloadBufferSize,\r | |
1656 | TRUE,\r | |
1657 | Timeout,\r | |
1658 | NULL\r | |
1659 | );\r | |
1660 | \r | |
3c063fed | 1661 | gBS->RestoreTPL (OldTpl);\r |
c24097a5 | 1662 | return Status;\r |
1663 | }\r | |
ad86a50a | 1664 | \r |
1665 | /**\r | |
1666 | The user Entry Point for module AtaBus. The user code starts with this function.\r | |
1667 | \r | |
1668 | @param[in] ImageHandle The firmware allocated handle for the EFI image.\r | |
1669 | @param[in] SystemTable A pointer to the EFI System Table.\r | |
1670 | \r | |
1671 | @retval EFI_SUCCESS The entry point is executed successfully.\r | |
1672 | @retval other Some error occurs when executing this entry point.\r | |
1673 | \r | |
1674 | **/\r | |
1675 | EFI_STATUS\r | |
1676 | EFIAPI\r | |
1677 | InitializeAtaBus(\r | |
1678 | IN EFI_HANDLE ImageHandle,\r | |
1679 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
1680 | )\r | |
1681 | {\r | |
1682 | EFI_STATUS Status;\r | |
90398d55 | 1683 | UINTN DataSize;\r |
ad86a50a | 1684 | \r |
1685 | //\r | |
1686 | // Install driver model protocol(s).\r | |
1687 | //\r | |
1688 | Status = EfiLibInstallDriverBindingComponentName2 (\r | |
1689 | ImageHandle,\r | |
1690 | SystemTable,\r | |
1691 | &gAtaBusDriverBinding,\r | |
1692 | ImageHandle,\r | |
1693 | &gAtaBusComponentName,\r | |
1694 | &gAtaBusComponentName2\r | |
1695 | );\r | |
1696 | ASSERT_EFI_ERROR (Status);\r | |
1697 | \r | |
90398d55 | 1698 | //\r |
1699 | // Get the MorControl bit.\r | |
1700 | //\r | |
1701 | DataSize = sizeof (mMorControl);\r | |
1702 | Status = gRT->GetVariable (\r | |
1703 | MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,\r | |
1704 | &gEfiMemoryOverwriteControlDataGuid,\r | |
1705 | NULL,\r | |
1706 | &DataSize,\r | |
1707 | &mMorControl\r | |
1708 | );\r | |
1709 | \r | |
1710 | if (EFI_ERROR (Status)) {\r | |
1711 | DEBUG ((EFI_D_INFO, "AtaBus:gEfiMemoryOverwriteControlDataGuid doesn't exist!!***\n"));\r | |
90398d55 | 1712 | mMorControl = 0;\r |
1713 | Status = EFI_SUCCESS;\r | |
1714 | } else {\r | |
1715 | DEBUG ((EFI_D_INFO, "AtaBus:Get the gEfiMemoryOverwriteControlDataGuid = %x!!***\n", mMorControl));\r | |
90398d55 | 1716 | }\r |
1717 | \r | |
ad86a50a | 1718 | return Status;\r |
1719 | }\r | |
90398d55 | 1720 | \r |
1721 | /**\r | |
1722 | Send TPer Reset command to reset eDrive to lock all protected bands.\r | |
1723 | Typically, there are 2 mechanism for resetting eDrive. They are:\r | |
1724 | 1. TPer Reset through IEEE 1667 protocol.\r | |
1725 | 2. TPer Reset through native TCG protocol.\r | |
1726 | This routine will detect what protocol the attached eDrive comform to, TCG or\r | |
1727 | IEEE 1667 protocol. Then send out TPer Reset command separately.\r | |
1728 | \r | |
1729 | @param[in] AtaDevice ATA_DEVICE pointer.\r | |
1730 | \r | |
1731 | **/\r | |
1732 | VOID\r | |
1733 | InitiateTPerReset (\r | |
1734 | IN ATA_DEVICE *AtaDevice\r | |
1735 | )\r | |
1736 | {\r | |
1737 | \r | |
1738 | EFI_STATUS Status;\r | |
1739 | UINT8 *Buffer;\r | |
1740 | UINTN XferSize;\r | |
1741 | UINTN Len;\r | |
1742 | UINTN Index;\r | |
1743 | BOOLEAN TcgFlag;\r | |
1744 | BOOLEAN IeeeFlag;\r | |
1745 | EFI_BLOCK_IO_PROTOCOL *BlockIo;\r | |
1746 | EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *Ssp;\r | |
1747 | SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA *Data;\r | |
1748 | \r | |
1749 | Buffer = NULL;\r | |
1750 | TcgFlag = FALSE;\r | |
1751 | IeeeFlag = FALSE;\r | |
1752 | Ssp = &AtaDevice->StorageSecurity;\r | |
1753 | BlockIo = &AtaDevice->BlockIo;\r | |
1754 | \r | |
1755 | //\r | |
1756 | // ATA8-ACS 7.57.6.1 indicates the Transfer Length field requirements a multiple of 512.\r | |
1757 | // If the length of the TRUSTED RECEIVE parameter data is greater than the Transfer Length,\r | |
1758 | // then the device shall return the TRUSTED RECEIVE parameter data truncated to the requested Transfer Length.\r | |
1759 | //\r | |
1760 | Len = ROUNDUP512(sizeof(SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA));\r | |
1761 | Buffer = AllocateZeroPool(Len);\r | |
1762 | \r | |
1763 | if (Buffer == NULL) {\r | |
1764 | return;\r | |
1765 | }\r | |
1766 | \r | |
1767 | //\r | |
1768 | // When the Security Protocol field is set to 00h, and SP Specific is set to 0000h in a TRUSTED RECEIVE\r | |
1769 | // command, the device basic information data shall be returned.\r | |
1770 | //\r | |
1771 | Status = Ssp->ReceiveData (\r | |
1772 | Ssp,\r | |
1773 | BlockIo->Media->MediaId,\r | |
1774 | 100000000, // Timeout 10-sec\r | |
1775 | 0, // SecurityProtocol\r | |
1776 | 0, // SecurityProtocolSpecifcData\r | |
1777 | Len, // PayloadBufferSize,\r | |
1778 | Buffer, // PayloadBuffer\r | |
1779 | &XferSize\r | |
1780 | );\r | |
1781 | if (EFI_ERROR (Status)) {\r | |
1782 | goto Exit;\r | |
1783 | }\r | |
1784 | \r | |
1785 | //\r | |
1786 | // In returned data, the ListLength field indicates the total length, in bytes,\r | |
1787 | // of the supported security protocol list.\r | |
1788 | //\r | |
1789 | Data = (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA*)Buffer;\r | |
1790 | Len = ROUNDUP512(sizeof (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA) +\r | |
1791 | (Data->SupportedSecurityListLength[0] << 8) +\r | |
1792 | (Data->SupportedSecurityListLength[1])\r | |
1793 | );\r | |
1794 | \r | |
1795 | //\r | |
1796 | // Free original buffer and allocate new buffer.\r | |
1797 | //\r | |
1798 | FreePool(Buffer);\r | |
1799 | Buffer = AllocateZeroPool(Len);\r | |
1800 | if (Buffer == NULL) {\r | |
1801 | return;\r | |
1802 | }\r | |
1803 | \r | |
1804 | //\r | |
1805 | // Read full supported security protocol list from device.\r | |
1806 | //\r | |
1807 | Status = Ssp->ReceiveData (\r | |
1808 | Ssp,\r | |
1809 | BlockIo->Media->MediaId,\r | |
1810 | 100000000, // Timeout 10-sec\r | |
1811 | 0, // SecurityProtocol\r | |
1812 | 0, // SecurityProtocolSpecifcData\r | |
1813 | Len, // PayloadBufferSize,\r | |
1814 | Buffer, // PayloadBuffer\r | |
1815 | &XferSize\r | |
1816 | );\r | |
1817 | \r | |
1818 | if (EFI_ERROR (Status)) {\r | |
1819 | goto Exit;\r | |
1820 | }\r | |
1821 | \r | |
1822 | Data = (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA*)Buffer;\r | |
1823 | Len = (Data->SupportedSecurityListLength[0] << 8) + Data->SupportedSecurityListLength[1];\r | |
1824 | \r | |
1825 | //\r | |
1826 | // Iterate full supported security protocol list to check if TCG or IEEE 1667 protocol\r | |
1827 | // is supported.\r | |
1828 | //\r | |
1829 | for (Index = 0; Index < Len; Index++) {\r | |
1830 | if (Data->SupportedSecurityProtocol[Index] == SECURITY_PROTOCOL_TCG) {\r | |
1831 | //\r | |
1832 | // Found a TCG device.\r | |
1833 | //\r | |
1834 | TcgFlag = TRUE;\r | |
1835 | DEBUG ((EFI_D_INFO, "This device is a TCG protocol device\n"));\r | |
1836 | break;\r | |
1837 | }\r | |
1838 | \r | |
1839 | if (Data->SupportedSecurityProtocol[Index] == SECURITY_PROTOCOL_IEEE1667) {\r | |
1840 | //\r | |
1841 | // Found a IEEE 1667 device.\r | |
1842 | //\r | |
1843 | IeeeFlag = TRUE;\r | |
1844 | DEBUG ((EFI_D_INFO, "This device is a IEEE 1667 protocol device\n"));\r | |
1845 | break;\r | |
1846 | }\r | |
1847 | }\r | |
1848 | \r | |
1849 | if (!TcgFlag && !IeeeFlag) {\r | |
1850 | DEBUG ((EFI_D_INFO, "Neither a TCG nor IEEE 1667 protocol device is found\n"));\r | |
1851 | goto Exit;\r | |
1852 | }\r | |
1853 | \r | |
1854 | if (TcgFlag) {\r | |
1855 | //\r | |
1856 | // As long as TCG protocol is supported, send out a TPer Reset\r | |
1857 | // TCG command to the device via the TrustedSend command with a non-zero Transfer Length.\r | |
1858 | //\r | |
1859 | Status = Ssp->SendData (\r | |
1860 | Ssp,\r | |
1861 | BlockIo->Media->MediaId,\r | |
1862 | 100000000, // Timeout 10-sec\r | |
1863 | SECURITY_PROTOCOL_TCG, // SecurityProtocol\r | |
1864 | 0x0400, // SecurityProtocolSpecifcData\r | |
1865 | 512, // PayloadBufferSize,\r | |
1866 | Buffer // PayloadBuffer\r | |
1867 | );\r | |
1868 | \r | |
1869 | if (!EFI_ERROR (Status)) {\r | |
1870 | DEBUG ((EFI_D_INFO, "Send TPer Reset Command Successfully !\n"));\r | |
1871 | } else {\r | |
1872 | DEBUG ((EFI_D_INFO, "Send TPer Reset Command Fail !\n"));\r | |
1873 | }\r | |
1874 | }\r | |
1875 | \r | |
1876 | if (IeeeFlag) {\r | |
1877 | //\r | |
1878 | // TBD : Perform a TPer Reset via IEEE 1667 Protocol\r | |
1879 | //\r | |
1880 | DEBUG ((EFI_D_INFO, "IEEE 1667 Protocol didn't support yet!\n"));\r | |
1881 | }\r | |
1882 | \r | |
1883 | Exit:\r | |
1884 | \r | |
1885 | if (Buffer != NULL) {\r | |
1886 | FreePool(Buffer);\r | |
1887 | }\r | |
1888 | }\r |