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