]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Ata/AtaBusDxe/AtaBus.c
AtaBusDxe: Fix ReadBlockEx andWriteBlockEx to still signal event when the BufferSize...
[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 - 2014, 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 if ((Token != NULL) && (Token->Event != NULL)) {
1076 Token->TransactionStatus = EFI_SUCCESS;
1077 gBS->SignalEvent (Token->Event);
1078 }
1079 return EFI_SUCCESS;
1080 }
1081
1082 BlockSize = Media->BlockSize;
1083 if ((BufferSize % BlockSize) != 0) {
1084 return EFI_BAD_BUFFER_SIZE;
1085 }
1086
1087 NumberOfBlocks = BufferSize / BlockSize;
1088 if ((Lba + NumberOfBlocks - 1) > Media->LastBlock) {
1089 return EFI_INVALID_PARAMETER;
1090 }
1091
1092 IoAlign = Media->IoAlign;
1093 if (IoAlign > 0 && (((UINTN) Buffer & (IoAlign - 1)) != 0)) {
1094 return EFI_INVALID_PARAMETER;
1095 }
1096
1097 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1098
1099 //
1100 // Invoke low level AtaDevice Access Routine.
1101 //
1102 Status = AccessAtaDevice (AtaDevice, Buffer, Lba, NumberOfBlocks, IsWrite, Token);
1103
1104 gBS->RestoreTPL (OldTpl);
1105
1106 return Status;
1107 }
1108
1109
1110 /**
1111 Read BufferSize bytes from Lba into Buffer.
1112
1113 @param This Indicates a pointer to the calling context.
1114 @param MediaId Id of the media, changes every time the media is replaced.
1115 @param Lba The starting Logical Block Address to read from
1116 @param BufferSize Size of Buffer, must be a multiple of device block size.
1117 @param Buffer A pointer to the destination buffer for the data. The caller is
1118 responsible for either having implicit or explicit ownership of the buffer.
1119
1120 @retval EFI_SUCCESS The data was read correctly from the device.
1121 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.
1122 @retval EFI_NO_MEDIA There is no media in the device.
1123 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.
1124 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1125 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
1126 or the buffer is not on proper alignment.
1127
1128 **/
1129 EFI_STATUS
1130 EFIAPI
1131 AtaBlockIoReadBlocks (
1132 IN EFI_BLOCK_IO_PROTOCOL *This,
1133 IN UINT32 MediaId,
1134 IN EFI_LBA Lba,
1135 IN UINTN BufferSize,
1136 OUT VOID *Buffer
1137 )
1138 {
1139 return BlockIoReadWrite ((VOID *) This, MediaId, Lba, NULL, BufferSize, Buffer, FALSE, FALSE);
1140 }
1141
1142
1143 /**
1144 Write BufferSize bytes from Lba into Buffer.
1145
1146 @param This Indicates a pointer to the calling context.
1147 @param MediaId The media ID that the write request is for.
1148 @param Lba The starting logical block address to be written. The caller is
1149 responsible for writing to only legitimate locations.
1150 @param BufferSize Size of Buffer, must be a multiple of device block size.
1151 @param Buffer A pointer to the source buffer for the data.
1152
1153 @retval EFI_SUCCESS The data was written correctly to the device.
1154 @retval EFI_WRITE_PROTECTED The device can not be written to.
1155 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
1156 @retval EFI_NO_MEDIA There is no media in the device.
1157 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1158 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1159 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
1160 or the buffer is not on proper alignment.
1161
1162 **/
1163 EFI_STATUS
1164 EFIAPI
1165 AtaBlockIoWriteBlocks (
1166 IN EFI_BLOCK_IO_PROTOCOL *This,
1167 IN UINT32 MediaId,
1168 IN EFI_LBA Lba,
1169 IN UINTN BufferSize,
1170 IN VOID *Buffer
1171 )
1172 {
1173 return BlockIoReadWrite ((VOID *) This, MediaId, Lba, NULL, BufferSize, Buffer, FALSE, TRUE);
1174 }
1175
1176
1177 /**
1178 Flush the Block Device.
1179
1180 @param This Indicates a pointer to the calling context.
1181
1182 @retval EFI_SUCCESS All outstanding data was written to the device
1183 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
1184 @retval EFI_NO_MEDIA There is no media in the device.
1185
1186 **/
1187 EFI_STATUS
1188 EFIAPI
1189 AtaBlockIoFlushBlocks (
1190 IN EFI_BLOCK_IO_PROTOCOL *This
1191 )
1192 {
1193 //
1194 // return directly
1195 //
1196 return EFI_SUCCESS;
1197 }
1198
1199 /**
1200 Reset the Block Device.
1201
1202 @param[in] This Indicates a pointer to the calling context.
1203 @param[in] ExtendedVerification Driver may perform diagnostics on reset.
1204
1205 @retval EFI_SUCCESS The device was reset.
1206 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
1207 not be reset.
1208
1209 **/
1210 EFI_STATUS
1211 EFIAPI
1212 AtaBlockIoResetEx (
1213 IN EFI_BLOCK_IO2_PROTOCOL *This,
1214 IN BOOLEAN ExtendedVerification
1215 )
1216 {
1217 EFI_STATUS Status;
1218 ATA_DEVICE *AtaDevice;
1219 EFI_TPL OldTpl;
1220
1221 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1222
1223 AtaDevice = ATA_DEVICE_FROM_BLOCK_IO2 (This);
1224
1225 AtaTerminateNonBlockingTask (AtaDevice);
1226
1227 Status = ResetAtaDevice (AtaDevice);
1228
1229 if (EFI_ERROR (Status)) {
1230 Status = EFI_DEVICE_ERROR;
1231 }
1232
1233 gBS->RestoreTPL (OldTpl);
1234 return Status;
1235 }
1236
1237 /**
1238 Read BufferSize bytes from Lba into Buffer.
1239
1240 @param[in] This Indicates a pointer to the calling context.
1241 @param[in] MediaId Id of the media, changes every time the media is replaced.
1242 @param[in] Lba The starting Logical Block Address to read from.
1243 @param[in, out] Token A pointer to the token associated with the transaction.
1244 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1245 @param[out] Buffer A pointer to the destination buffer for the data. The caller is
1246 responsible for either having implicit or explicit ownership of the buffer.
1247
1248 @retval EFI_SUCCESS The read request was queued if Event is not NULL.
1249 The data was read correctly from the device if
1250 the Event is NULL.
1251 @retval EFI_DEVICE_ERROR The device reported an error while performing
1252 the read.
1253 @retval EFI_NO_MEDIA There is no media in the device.
1254 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1255 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the
1256 intrinsic block size of the device.
1257 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,
1258 or the buffer is not on proper alignment.
1259 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
1260 of resources.
1261
1262 **/
1263 EFI_STATUS
1264 EFIAPI
1265 AtaBlockIoReadBlocksEx (
1266 IN EFI_BLOCK_IO2_PROTOCOL *This,
1267 IN UINT32 MediaId,
1268 IN EFI_LBA Lba,
1269 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
1270 IN UINTN BufferSize,
1271 OUT VOID *Buffer
1272 )
1273 {
1274 return BlockIoReadWrite ((VOID *) This, MediaId, Lba, Token, BufferSize, Buffer, TRUE, FALSE);
1275 }
1276
1277
1278 /**
1279 Write BufferSize bytes from Lba into Buffer.
1280
1281 @param[in] This Indicates a pointer to the calling context.
1282 @param[in] MediaId The media ID that the write request is for.
1283 @param[in] Lba The starting logical block address to be written. The
1284 caller is responsible for writing to only legitimate
1285 locations.
1286 @param[in, out] Token A pointer to the token associated with the transaction.
1287 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.
1288 @param[in] Buffer A pointer to the source buffer for the data.
1289
1290 @retval EFI_SUCCESS The data was written correctly to the device.
1291 @retval EFI_WRITE_PROTECTED The device can not be written to.
1292 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.
1293 @retval EFI_NO_MEDIA There is no media in the device.
1294 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.
1295 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
1296 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,
1297 or the buffer is not on proper alignment.
1298
1299 **/
1300 EFI_STATUS
1301 EFIAPI
1302 AtaBlockIoWriteBlocksEx (
1303 IN EFI_BLOCK_IO2_PROTOCOL *This,
1304 IN UINT32 MediaId,
1305 IN EFI_LBA Lba,
1306 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
1307 IN UINTN BufferSize,
1308 IN VOID *Buffer
1309 )
1310 {
1311 return BlockIoReadWrite ((VOID *) This, MediaId, Lba, Token, BufferSize, Buffer, TRUE, TRUE);
1312 }
1313
1314
1315 /**
1316 Flush the Block Device.
1317
1318 @param[in] This Indicates a pointer to the calling context.
1319 @param[in, out] Token A pointer to the token associated with the transaction.
1320
1321 @retval EFI_SUCCESS All outstanding data was written to the device
1322 @retval EFI_DEVICE_ERROR The device reported an error while writing back the data
1323 @retval EFI_NO_MEDIA There is no media in the device.
1324
1325 **/
1326 EFI_STATUS
1327 EFIAPI
1328 AtaBlockIoFlushBlocksEx (
1329 IN EFI_BLOCK_IO2_PROTOCOL *This,
1330 IN OUT EFI_BLOCK_IO2_TOKEN *Token
1331 )
1332 {
1333 //
1334 // Signal event and return directly.
1335 //
1336 if (Token != NULL && Token->Event != NULL) {
1337 Token->TransactionStatus = EFI_SUCCESS;
1338 gBS->SignalEvent (Token->Event);
1339 }
1340 return EFI_SUCCESS;
1341 }
1342 /**
1343 Provides inquiry information for the controller type.
1344
1345 This function is used by the IDE bus driver to get inquiry data. Data format
1346 of Identify data is defined by the Interface GUID.
1347
1348 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1349 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
1350 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
1351
1352 @retval EFI_SUCCESS The command was accepted without any errors.
1353 @retval EFI_NOT_FOUND Device does not support this data class
1354 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
1355 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
1356
1357 **/
1358 EFI_STATUS
1359 EFIAPI
1360 AtaDiskInfoInquiry (
1361 IN EFI_DISK_INFO_PROTOCOL *This,
1362 IN OUT VOID *InquiryData,
1363 IN OUT UINT32 *InquiryDataSize
1364 )
1365 {
1366 return EFI_NOT_FOUND;
1367 }
1368
1369
1370 /**
1371 Provides identify information for the controller type.
1372
1373 This function is used by the IDE bus driver to get identify data. Data format
1374 of Identify data is defined by the Interface GUID.
1375
1376 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
1377 instance.
1378 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
1379 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
1380 size.
1381
1382 @retval EFI_SUCCESS The command was accepted without any errors.
1383 @retval EFI_NOT_FOUND Device does not support this data class
1384 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
1385 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
1386
1387 **/
1388 EFI_STATUS
1389 EFIAPI
1390 AtaDiskInfoIdentify (
1391 IN EFI_DISK_INFO_PROTOCOL *This,
1392 IN OUT VOID *IdentifyData,
1393 IN OUT UINT32 *IdentifyDataSize
1394 )
1395 {
1396 EFI_STATUS Status;
1397 ATA_DEVICE *AtaDevice;
1398
1399 AtaDevice = ATA_DEVICE_FROM_DISK_INFO (This);
1400
1401 Status = EFI_BUFFER_TOO_SMALL;
1402 if (*IdentifyDataSize >= sizeof (ATA_IDENTIFY_DATA)) {
1403 Status = EFI_SUCCESS;
1404 CopyMem (IdentifyData, AtaDevice->IdentifyData, sizeof (ATA_IDENTIFY_DATA));
1405 }
1406 *IdentifyDataSize = sizeof (ATA_IDENTIFY_DATA);
1407
1408 return Status;
1409 }
1410
1411
1412 /**
1413 Provides sense data information for the controller type.
1414
1415 This function is used by the IDE bus driver to get sense data.
1416 Data format of Sense data is defined by the Interface GUID.
1417
1418 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1419 @param[in, out] SenseData Pointer to the SenseData.
1420 @param[in, out] SenseDataSize Size of SenseData in bytes.
1421 @param[out] SenseDataNumber Pointer to the value for the sense data size.
1422
1423 @retval EFI_SUCCESS The command was accepted without any errors.
1424 @retval EFI_NOT_FOUND Device does not support this data class.
1425 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
1426 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
1427
1428 **/
1429 EFI_STATUS
1430 EFIAPI
1431 AtaDiskInfoSenseData (
1432 IN EFI_DISK_INFO_PROTOCOL *This,
1433 IN OUT VOID *SenseData,
1434 IN OUT UINT32 *SenseDataSize,
1435 OUT UINT8 *SenseDataNumber
1436 )
1437 {
1438 return EFI_NOT_FOUND;
1439 }
1440
1441
1442 /**
1443 This function is used by the IDE bus driver to get controller information.
1444
1445 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
1446 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
1447 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
1448
1449 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
1450 @retval EFI_UNSUPPORTED This is not an IDE device.
1451
1452 **/
1453 EFI_STATUS
1454 EFIAPI
1455 AtaDiskInfoWhichIde (
1456 IN EFI_DISK_INFO_PROTOCOL *This,
1457 OUT UINT32 *IdeChannel,
1458 OUT UINT32 *IdeDevice
1459 )
1460 {
1461 ATA_DEVICE *AtaDevice;
1462
1463 AtaDevice = ATA_DEVICE_FROM_DISK_INFO (This);
1464 *IdeChannel = AtaDevice->Port;
1465 *IdeDevice = AtaDevice->PortMultiplierPort;
1466
1467 return EFI_SUCCESS;
1468 }
1469
1470 /**
1471 Send a security protocol command to a device that receives data and/or the result
1472 of one or more commands sent by SendData.
1473
1474 The ReceiveData function sends a security protocol command to the given MediaId.
1475 The security protocol command sent is defined by SecurityProtocolId and contains
1476 the security protocol specific data SecurityProtocolSpecificData. The function
1477 returns the data from the security protocol command in PayloadBuffer.
1478
1479 For devices supporting the SCSI command set, the security protocol command is sent
1480 using the SECURITY PROTOCOL IN command defined in SPC-4.
1481
1482 For devices supporting the ATA command set, the security protocol command is sent
1483 using one of the TRUSTED RECEIVE commands defined in ATA8-ACS if PayloadBufferSize
1484 is non-zero.
1485
1486 If the PayloadBufferSize is zero, the security protocol command is sent using the
1487 Trusted Non-Data command defined in ATA8-ACS.
1488
1489 If PayloadBufferSize is too small to store the available data from the security
1490 protocol command, the function shall copy PayloadBufferSize bytes into the
1491 PayloadBuffer and return EFI_WARN_BUFFER_TOO_SMALL.
1492
1493 If PayloadBuffer or PayloadTransferSize is NULL and PayloadBufferSize is non-zero,
1494 the function shall return EFI_INVALID_PARAMETER.
1495
1496 If the given MediaId does not support security protocol commands, the function shall
1497 return EFI_UNSUPPORTED. If there is no media in the device, the function returns
1498 EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the device,
1499 the function returns EFI_MEDIA_CHANGED.
1500
1501 If the security protocol fails to complete within the Timeout period, the function
1502 shall return EFI_TIMEOUT.
1503
1504 If the security protocol command completes without an error, the function shall
1505 return EFI_SUCCESS. If the security protocol command completes with an error, the
1506 function shall return EFI_DEVICE_ERROR.
1507
1508 @param This Indicates a pointer to the calling context.
1509 @param MediaId ID of the medium to receive data from.
1510 @param Timeout The timeout, in 100ns units, to use for the execution
1511 of the security protocol command. A Timeout value of 0
1512 means that this function will wait indefinitely for the
1513 security protocol command to execute. If Timeout is greater
1514 than zero, then this function will return EFI_TIMEOUT
1515 if the time required to execute the receive data command
1516 is greater than Timeout.
1517 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1518 the security protocol command to be sent.
1519 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1520 of the security protocol command to be sent.
1521 @param PayloadBufferSize Size in bytes of the payload data buffer.
1522 @param PayloadBuffer A pointer to a destination buffer to store the security
1523 protocol command specific payload data for the security
1524 protocol command. The caller is responsible for having
1525 either implicit or explicit ownership of the buffer.
1526 @param PayloadTransferSize A pointer to a buffer to store the size in bytes of the
1527 data written to the payload data buffer.
1528
1529 @retval EFI_SUCCESS The security protocol command completed successfully.
1530 @retval EFI_WARN_BUFFER_TOO_SMALL The PayloadBufferSize was too small to store the available
1531 data from the device. The PayloadBuffer contains the truncated data.
1532 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1533 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1534 @retval EFI_NO_MEDIA There is no media in the device.
1535 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1536 @retval EFI_INVALID_PARAMETER The PayloadBuffer or PayloadTransferSize is NULL and
1537 PayloadBufferSize is non-zero.
1538 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1539 protocol command to execute.
1540
1541 **/
1542 EFI_STATUS
1543 EFIAPI
1544 AtaStorageSecurityReceiveData (
1545 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,
1546 IN UINT32 MediaId,
1547 IN UINT64 Timeout,
1548 IN UINT8 SecurityProtocolId,
1549 IN UINT16 SecurityProtocolSpecificData,
1550 IN UINTN PayloadBufferSize,
1551 OUT VOID *PayloadBuffer,
1552 OUT UINTN *PayloadTransferSize
1553 )
1554 {
1555 EFI_STATUS Status;
1556 ATA_DEVICE *Private;
1557 EFI_TPL OldTpl;
1558
1559 DEBUG ((EFI_D_INFO, "EFI Storage Security Protocol - Read"));
1560 if ((PayloadBuffer == NULL || PayloadTransferSize == NULL) && PayloadBufferSize != 0) {
1561 return EFI_INVALID_PARAMETER;
1562 }
1563
1564 Status = EFI_SUCCESS;
1565 Private = ATA_DEVICE_FROM_STORAGE_SECURITY (This);
1566
1567 if (MediaId != Private->BlockIo.Media->MediaId) {
1568 return EFI_MEDIA_CHANGED;
1569 }
1570
1571 if (!Private->BlockIo.Media->MediaPresent) {
1572 return EFI_NO_MEDIA;
1573 }
1574
1575 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1576
1577 Status = TrustTransferAtaDevice (
1578 Private,
1579 PayloadBuffer,
1580 SecurityProtocolId,
1581 SecurityProtocolSpecificData,
1582 PayloadBufferSize,
1583 FALSE,
1584 Timeout,
1585 PayloadTransferSize
1586 );
1587
1588 gBS->RestoreTPL (OldTpl);
1589 return Status;
1590 }
1591
1592 /**
1593 Send a security protocol command to a device.
1594
1595 The SendData function sends a security protocol command containing the payload
1596 PayloadBuffer to the given MediaId. The security protocol command sent is
1597 defined by SecurityProtocolId and contains the security protocol specific data
1598 SecurityProtocolSpecificData. If the underlying protocol command requires a
1599 specific padding for the command payload, the SendData function shall add padding
1600 bytes to the command payload to satisfy the padding requirements.
1601
1602 For devices supporting the SCSI command set, the security protocol command is sent
1603 using the SECURITY PROTOCOL OUT command defined in SPC-4.
1604
1605 For devices supporting the ATA command set, the security protocol command is sent
1606 using one of the TRUSTED SEND commands defined in ATA8-ACS if PayloadBufferSize
1607 is non-zero. If the PayloadBufferSize is zero, the security protocol command is
1608 sent using the Trusted Non-Data command defined in ATA8-ACS.
1609
1610 If PayloadBuffer is NULL and PayloadBufferSize is non-zero, the function shall
1611 return EFI_INVALID_PARAMETER.
1612
1613 If the given MediaId does not support security protocol commands, the function
1614 shall return EFI_UNSUPPORTED. If there is no media in the device, the function
1615 returns EFI_NO_MEDIA. If the MediaId is not the ID for the current media in the
1616 device, the function returns EFI_MEDIA_CHANGED.
1617
1618 If the security protocol fails to complete within the Timeout period, the function
1619 shall return EFI_TIMEOUT.
1620
1621 If the security protocol command completes without an error, the function shall return
1622 EFI_SUCCESS. If the security protocol command completes with an error, the function
1623 shall return EFI_DEVICE_ERROR.
1624
1625 @param This Indicates a pointer to the calling context.
1626 @param MediaId ID of the medium to receive data from.
1627 @param Timeout The timeout, in 100ns units, to use for the execution
1628 of the security protocol command. A Timeout value of 0
1629 means that this function will wait indefinitely for the
1630 security protocol command to execute. If Timeout is greater
1631 than zero, then this function will return EFI_TIMEOUT
1632 if the time required to execute the receive data command
1633 is greater than Timeout.
1634 @param SecurityProtocolId The value of the "Security Protocol" parameter of
1635 the security protocol command to be sent.
1636 @param SecurityProtocolSpecificData The value of the "Security Protocol Specific" parameter
1637 of the security protocol command to be sent.
1638 @param PayloadBufferSize Size in bytes of the payload data buffer.
1639 @param PayloadBuffer A pointer to a destination buffer to store the security
1640 protocol command specific payload data for the security
1641 protocol command.
1642
1643 @retval EFI_SUCCESS The security protocol command completed successfully.
1644 @retval EFI_UNSUPPORTED The given MediaId does not support security protocol commands.
1645 @retval EFI_DEVICE_ERROR The security protocol command completed with an error.
1646 @retval EFI_NO_MEDIA There is no media in the device.
1647 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.
1648 @retval EFI_INVALID_PARAMETER The PayloadBuffer is NULL and PayloadBufferSize is non-zero.
1649 @retval EFI_TIMEOUT A timeout occurred while waiting for the security
1650 protocol command to execute.
1651
1652 **/
1653 EFI_STATUS
1654 EFIAPI
1655 AtaStorageSecuritySendData (
1656 IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This,
1657 IN UINT32 MediaId,
1658 IN UINT64 Timeout,
1659 IN UINT8 SecurityProtocolId,
1660 IN UINT16 SecurityProtocolSpecificData,
1661 IN UINTN PayloadBufferSize,
1662 IN VOID *PayloadBuffer
1663 )
1664 {
1665 EFI_STATUS Status;
1666 ATA_DEVICE *Private;
1667 EFI_TPL OldTpl;
1668
1669 DEBUG ((EFI_D_INFO, "EFI Storage Security Protocol - Send"));
1670 if ((PayloadBuffer == NULL) && (PayloadBufferSize != 0)) {
1671 return EFI_INVALID_PARAMETER;
1672 }
1673
1674 Status = EFI_SUCCESS;
1675 Private = ATA_DEVICE_FROM_STORAGE_SECURITY (This);
1676
1677 if (MediaId != Private->BlockIo.Media->MediaId) {
1678 return EFI_MEDIA_CHANGED;
1679 }
1680
1681 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1682 Status = TrustTransferAtaDevice (
1683 Private,
1684 PayloadBuffer,
1685 SecurityProtocolId,
1686 SecurityProtocolSpecificData,
1687 PayloadBufferSize,
1688 TRUE,
1689 Timeout,
1690 NULL
1691 );
1692
1693 gBS->RestoreTPL (OldTpl);
1694 return Status;
1695 }
1696
1697 /**
1698 The user Entry Point for module AtaBus. The user code starts with this function.
1699
1700 @param[in] ImageHandle The firmware allocated handle for the EFI image.
1701 @param[in] SystemTable A pointer to the EFI System Table.
1702
1703 @retval EFI_SUCCESS The entry point is executed successfully.
1704 @retval other Some error occurs when executing this entry point.
1705
1706 **/
1707 EFI_STATUS
1708 EFIAPI
1709 InitializeAtaBus(
1710 IN EFI_HANDLE ImageHandle,
1711 IN EFI_SYSTEM_TABLE *SystemTable
1712 )
1713 {
1714 EFI_STATUS Status;
1715 UINTN DataSize;
1716
1717 //
1718 // Install driver model protocol(s).
1719 //
1720 Status = EfiLibInstallDriverBindingComponentName2 (
1721 ImageHandle,
1722 SystemTable,
1723 &gAtaBusDriverBinding,
1724 ImageHandle,
1725 &gAtaBusComponentName,
1726 &gAtaBusComponentName2
1727 );
1728 ASSERT_EFI_ERROR (Status);
1729
1730 //
1731 // Get the MorControl bit.
1732 //
1733 DataSize = sizeof (mMorControl);
1734 Status = gRT->GetVariable (
1735 MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,
1736 &gEfiMemoryOverwriteControlDataGuid,
1737 NULL,
1738 &DataSize,
1739 &mMorControl
1740 );
1741
1742 if (EFI_ERROR (Status)) {
1743 DEBUG ((EFI_D_INFO, "AtaBus:gEfiMemoryOverwriteControlDataGuid doesn't exist!!***\n"));
1744 mMorControl = 0;
1745 Status = EFI_SUCCESS;
1746 } else {
1747 DEBUG ((EFI_D_INFO, "AtaBus:Get the gEfiMemoryOverwriteControlDataGuid = %x!!***\n", mMorControl));
1748 }
1749
1750 return Status;
1751 }
1752
1753 /**
1754 Send TPer Reset command to reset eDrive to lock all protected bands.
1755 Typically, there are 2 mechanism for resetting eDrive. They are:
1756 1. TPer Reset through IEEE 1667 protocol.
1757 2. TPer Reset through native TCG protocol.
1758 This routine will detect what protocol the attached eDrive comform to, TCG or
1759 IEEE 1667 protocol. Then send out TPer Reset command separately.
1760
1761 @param[in] AtaDevice ATA_DEVICE pointer.
1762
1763 **/
1764 VOID
1765 InitiateTPerReset (
1766 IN ATA_DEVICE *AtaDevice
1767 )
1768 {
1769
1770 EFI_STATUS Status;
1771 UINT8 *Buffer;
1772 UINTN XferSize;
1773 UINTN Len;
1774 UINTN Index;
1775 BOOLEAN TcgFlag;
1776 BOOLEAN IeeeFlag;
1777 EFI_BLOCK_IO_PROTOCOL *BlockIo;
1778 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *Ssp;
1779 SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA *Data;
1780
1781 Buffer = NULL;
1782 TcgFlag = FALSE;
1783 IeeeFlag = FALSE;
1784 Ssp = &AtaDevice->StorageSecurity;
1785 BlockIo = &AtaDevice->BlockIo;
1786
1787 //
1788 // ATA8-ACS 7.57.6.1 indicates the Transfer Length field requirements a multiple of 512.
1789 // If the length of the TRUSTED RECEIVE parameter data is greater than the Transfer Length,
1790 // then the device shall return the TRUSTED RECEIVE parameter data truncated to the requested Transfer Length.
1791 //
1792 Len = ROUNDUP512(sizeof(SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA));
1793 Buffer = AllocateZeroPool(Len);
1794
1795 if (Buffer == NULL) {
1796 return;
1797 }
1798
1799 //
1800 // When the Security Protocol field is set to 00h, and SP Specific is set to 0000h in a TRUSTED RECEIVE
1801 // command, the device basic information data shall be returned.
1802 //
1803 Status = Ssp->ReceiveData (
1804 Ssp,
1805 BlockIo->Media->MediaId,
1806 100000000, // Timeout 10-sec
1807 0, // SecurityProtocol
1808 0, // SecurityProtocolSpecifcData
1809 Len, // PayloadBufferSize,
1810 Buffer, // PayloadBuffer
1811 &XferSize
1812 );
1813 if (EFI_ERROR (Status)) {
1814 goto Exit;
1815 }
1816
1817 //
1818 // In returned data, the ListLength field indicates the total length, in bytes,
1819 // of the supported security protocol list.
1820 //
1821 Data = (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA*)Buffer;
1822 Len = ROUNDUP512(sizeof (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA) +
1823 (Data->SupportedSecurityListLength[0] << 8) +
1824 (Data->SupportedSecurityListLength[1])
1825 );
1826
1827 //
1828 // Free original buffer and allocate new buffer.
1829 //
1830 FreePool(Buffer);
1831 Buffer = AllocateZeroPool(Len);
1832 if (Buffer == NULL) {
1833 return;
1834 }
1835
1836 //
1837 // Read full supported security protocol list from device.
1838 //
1839 Status = Ssp->ReceiveData (
1840 Ssp,
1841 BlockIo->Media->MediaId,
1842 100000000, // Timeout 10-sec
1843 0, // SecurityProtocol
1844 0, // SecurityProtocolSpecifcData
1845 Len, // PayloadBufferSize,
1846 Buffer, // PayloadBuffer
1847 &XferSize
1848 );
1849
1850 if (EFI_ERROR (Status)) {
1851 goto Exit;
1852 }
1853
1854 Data = (SUPPORTED_SECURITY_PROTOCOLS_PARAMETER_DATA*)Buffer;
1855 Len = (Data->SupportedSecurityListLength[0] << 8) + Data->SupportedSecurityListLength[1];
1856
1857 //
1858 // Iterate full supported security protocol list to check if TCG or IEEE 1667 protocol
1859 // is supported.
1860 //
1861 for (Index = 0; Index < Len; Index++) {
1862 if (Data->SupportedSecurityProtocol[Index] == SECURITY_PROTOCOL_TCG) {
1863 //
1864 // Found a TCG device.
1865 //
1866 TcgFlag = TRUE;
1867 DEBUG ((EFI_D_INFO, "This device is a TCG protocol device\n"));
1868 break;
1869 }
1870
1871 if (Data->SupportedSecurityProtocol[Index] == SECURITY_PROTOCOL_IEEE1667) {
1872 //
1873 // Found a IEEE 1667 device.
1874 //
1875 IeeeFlag = TRUE;
1876 DEBUG ((EFI_D_INFO, "This device is a IEEE 1667 protocol device\n"));
1877 break;
1878 }
1879 }
1880
1881 if (!TcgFlag && !IeeeFlag) {
1882 DEBUG ((EFI_D_INFO, "Neither a TCG nor IEEE 1667 protocol device is found\n"));
1883 goto Exit;
1884 }
1885
1886 if (TcgFlag) {
1887 //
1888 // As long as TCG protocol is supported, send out a TPer Reset
1889 // TCG command to the device via the TrustedSend command with a non-zero Transfer Length.
1890 //
1891 Status = Ssp->SendData (
1892 Ssp,
1893 BlockIo->Media->MediaId,
1894 100000000, // Timeout 10-sec
1895 SECURITY_PROTOCOL_TCG, // SecurityProtocol
1896 0x0400, // SecurityProtocolSpecifcData
1897 512, // PayloadBufferSize,
1898 Buffer // PayloadBuffer
1899 );
1900
1901 if (!EFI_ERROR (Status)) {
1902 DEBUG ((EFI_D_INFO, "Send TPer Reset Command Successfully !\n"));
1903 } else {
1904 DEBUG ((EFI_D_INFO, "Send TPer Reset Command Fail !\n"));
1905 }
1906 }
1907
1908 if (IeeeFlag) {
1909 //
1910 // TBD : Perform a TPer Reset via IEEE 1667 Protocol
1911 //
1912 DEBUG ((EFI_D_INFO, "IEEE 1667 Protocol didn't support yet!\n"));
1913 }
1914
1915 Exit:
1916
1917 if (Buffer != NULL) {
1918 FreePool(Buffer);
1919 }
1920 }