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