TianoCore EDK2 master
Loading...
Searching...
No Matches
AtaBus.c
Go to the documentation of this file.
1
13#include "AtaBus.h"
14
15//
16// ATA Bus Driver Binding Protocol Instance
17//
18EFI_DRIVER_BINDING_PROTOCOL gAtaBusDriverBinding = {
22 0x10,
23 NULL,
24 NULL
25};
26
27//
28// Template for ATA Child Device.
29//
30ATA_DEVICE gAtaDeviceTemplate = {
31 ATA_DEVICE_SIGNATURE, // Signature
32 NULL, // Handle
33 { // BlockIo
34 EFI_BLOCK_IO_PROTOCOL_REVISION,
35 NULL,
40 },
41 { // BlockIo2
42 NULL,
47 },
48 { // BlockMedia
49 0, // MediaId
50 FALSE, // RemovableMedia
51 TRUE, // MediaPresent
52 FALSE, // LogicPartition
53 FALSE, // ReadOnly
54 FALSE, // WritingCache
55 0x200, // BlockSize
56 0, // IoAlign
57 0, // LastBlock
58 0, // LowestAlignedLba
59 1 // LogicalBlocksPerPhysicalBlock
60 },
61 { // DiskInfo
67 },
68 NULL, // DevicePath
69 {
72 },
73 NULL, // AtaBusDriverData
74 0, // Port
75 0, // PortMultiplierPort
76 { 0, }, // Packet
77 {
78 { 0 },
79 }, // Acb
80 NULL, // Asb
81 FALSE, // UdmaValid
82 FALSE, // Lba48Bit
83 NULL, // IdentifyData
84 NULL, // ControllerNameTable
85 { L'\0', }, // ModelName
86 { NULL, NULL }, // AtaTaskList
87 { NULL, NULL }, // AtaSubTaskList
88 FALSE // Abort
89};
90
104VOID *
106 IN ATA_DEVICE *AtaDevice,
107 IN UINTN BufferSize
108 )
109{
110 return AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), AtaDevice->AtaBusDriverData->AtaPassThru->Mode->IoAlign);
111}
112
123VOID
125 IN VOID *Buffer,
126 IN UINTN BufferSize
127 )
128{
129 if (Buffer != NULL) {
130 FreeAlignedPages (Buffer, EFI_SIZE_TO_PAGES (BufferSize));
131 }
132}
133
142VOID
144 IN ATA_DEVICE *AtaDevice
145 )
146{
147 ATA_BUS_ASYN_SUB_TASK *SubTask;
148 ATA_BUS_ASYN_TASK *AtaTask;
149 LIST_ENTRY *Entry;
150 LIST_ENTRY *DelEntry;
151 EFI_TPL OldTpl;
152
153 FreeUnicodeStringTable (AtaDevice->ControllerNameTable);
154 FreeAlignedBuffer (AtaDevice->Asb, sizeof (EFI_ATA_STATUS_BLOCK));
155 FreeAlignedBuffer (AtaDevice->IdentifyData, sizeof (ATA_IDENTIFY_DATA));
156 if (AtaDevice->DevicePath != NULL) {
157 FreePool (AtaDevice->DevicePath);
158 }
159
160 OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
161 if (!IsListEmpty (&AtaDevice->AtaSubTaskList)) {
162 //
163 // Free the Subtask list.
164 //
165 for (Entry = AtaDevice->AtaSubTaskList.ForwardLink;
166 Entry != (&AtaDevice->AtaSubTaskList);
167 )
168 {
169 DelEntry = Entry;
170 Entry = Entry->ForwardLink;
171 SubTask = ATA_ASYN_SUB_TASK_FROM_ENTRY (DelEntry);
172
173 RemoveEntryList (DelEntry);
174 FreeAtaSubTask (SubTask);
175 }
176 }
177
178 if (!IsListEmpty (&AtaDevice->AtaTaskList)) {
179 //
180 // Free the Subtask list.
181 //
182 for (Entry = AtaDevice->AtaTaskList.ForwardLink;
183 Entry != (&AtaDevice->AtaTaskList);
184 )
185 {
186 DelEntry = Entry;
187 Entry = Entry->ForwardLink;
188 AtaTask = ATA_ASYN_TASK_FROM_ENTRY (DelEntry);
189
190 RemoveEntryList (DelEntry);
191 FreePool (AtaTask);
192 }
193 }
194
195 gBS->RestoreTPL (OldTpl);
196 FreePool (AtaDevice);
197}
198
218 IN OUT ATA_BUS_DRIVER_DATA *AtaBusDriverData,
219 IN UINT16 Port,
220 IN UINT16 PortMultiplierPort
221 )
222{
223 EFI_STATUS Status;
224 ATA_DEVICE *AtaDevice;
225 EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThru;
226 EFI_DEVICE_PATH_PROTOCOL *NewDevicePathNode;
227 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
228 EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath;
229 EFI_HANDLE DeviceHandle;
230
231 AtaDevice = NULL;
232 NewDevicePathNode = NULL;
233 DevicePath = NULL;
234 RemainingDevicePath = NULL;
235
236 //
237 // Build device path
238 //
239 AtaPassThru = AtaBusDriverData->AtaPassThru;
240 Status = AtaPassThru->BuildDevicePath (AtaPassThru, Port, PortMultiplierPort, &NewDevicePathNode);
241 if (EFI_ERROR (Status)) {
242 goto Done;
243 }
244
245 DevicePath = AppendDevicePathNode (AtaBusDriverData->ParentDevicePath, NewDevicePathNode);
246 if (DevicePath == NULL) {
247 Status = EFI_OUT_OF_RESOURCES;
248 goto Done;
249 }
250
251 DeviceHandle = NULL;
252 RemainingDevicePath = DevicePath;
253 Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &DeviceHandle);
254 if (!EFI_ERROR (Status) && (DeviceHandle != NULL) && IsDevicePathEnd (RemainingDevicePath)) {
255 Status = EFI_ALREADY_STARTED;
256 FreePool (DevicePath);
257 goto Done;
258 }
259
260 //
261 // Allocate ATA device from the template.
262 //
263 AtaDevice = AllocateCopyPool (sizeof (ATA_DEVICE), &gAtaDeviceTemplate);
264 if (AtaDevice == NULL) {
265 Status = EFI_OUT_OF_RESOURCES;
266 goto Done;
267 }
268
269 //
270 // Initializes ATA device structures and allocates the required buffer.
271 //
272 AtaDevice->BlockIo.Media = &AtaDevice->BlockMedia;
273 AtaDevice->BlockIo2.Media = &AtaDevice->BlockMedia;
274 AtaDevice->AtaBusDriverData = AtaBusDriverData;
275 AtaDevice->DevicePath = DevicePath;
276 AtaDevice->Port = Port;
277 AtaDevice->PortMultiplierPort = PortMultiplierPort;
278 AtaDevice->Asb = AllocateAlignedBuffer (AtaDevice, sizeof (EFI_ATA_STATUS_BLOCK));
279 if (AtaDevice->Asb == NULL) {
280 Status = EFI_OUT_OF_RESOURCES;
281 goto Done;
282 }
283
284 AtaDevice->IdentifyData = AllocateAlignedBuffer (AtaDevice, sizeof (ATA_IDENTIFY_DATA));
285 if (AtaDevice->IdentifyData == NULL) {
286 Status = EFI_OUT_OF_RESOURCES;
287 goto Done;
288 }
289
290 //
291 // Initial Ata Task List
292 //
293 InitializeListHead (&AtaDevice->AtaTaskList);
294 InitializeListHead (&AtaDevice->AtaSubTaskList);
295
296 //
297 // Report Status Code to indicate the ATA device will be enabled
298 //
301 (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_PC_ENABLE),
302 AtaBusDriverData->ParentDevicePath
303 );
304
305 //
306 // Try to identify the ATA device via the ATA pass through command.
307 //
308 Status = DiscoverAtaDevice (AtaDevice);
309 if (EFI_ERROR (Status)) {
310 goto Done;
311 }
312
313 //
314 // Build controller name for Component Name (2) protocol.
315 //
316 Status = AddUnicodeString2 (
317 "eng",
318 gAtaBusComponentName.SupportedLanguages,
319 &AtaDevice->ControllerNameTable,
320 AtaDevice->ModelName,
321 TRUE
322 );
323 if (EFI_ERROR (Status)) {
324 goto Done;
325 }
326
327 Status = AddUnicodeString2 (
328 "en",
329 gAtaBusComponentName2.SupportedLanguages,
330 &AtaDevice->ControllerNameTable,
331 AtaDevice->ModelName,
332 FALSE
333 );
334 if (EFI_ERROR (Status)) {
335 goto Done;
336 }
337
338 //
339 // Update to AHCI interface GUID based on device path node. The default one
340 // is IDE interface GUID copied from template.
341 //
342 if (NewDevicePathNode->SubType == MSG_SATA_DP) {
343 CopyGuid (&AtaDevice->DiskInfo.Interface, &gEfiDiskInfoAhciInterfaceGuid);
344 }
345
346 Status = gBS->InstallMultipleProtocolInterfaces (
347 &AtaDevice->Handle,
348 &gEfiDevicePathProtocolGuid,
349 AtaDevice->DevicePath,
350 &gEfiBlockIoProtocolGuid,
351 &AtaDevice->BlockIo,
352 &gEfiBlockIo2ProtocolGuid,
353 &AtaDevice->BlockIo2,
354 &gEfiDiskInfoProtocolGuid,
355 &AtaDevice->DiskInfo,
356 NULL
357 );
358 if (EFI_ERROR (Status)) {
359 goto Done;
360 }
361
362 //
363 // See if the ata device support trust computing feature or not.
364 // If yes, then install Storage Security Protocol at the ata device handle.
365 //
366 if ((AtaDevice->IdentifyData->trusted_computing_support & BIT0) != 0) {
367 DEBUG ((DEBUG_INFO, "Found TCG support in Port %x PortMultiplierPort %x\n", Port, PortMultiplierPort));
368 Status = gBS->InstallProtocolInterface (
369 &AtaDevice->Handle,
370 &gEfiStorageSecurityCommandProtocolGuid,
372 &AtaDevice->StorageSecurity
373 );
374 if (EFI_ERROR (Status)) {
375 goto Done;
376 }
377
378 DEBUG ((DEBUG_INFO, "Successfully Install Storage Security Protocol on the ATA device\n"));
379 }
380
381 gBS->OpenProtocol (
382 AtaBusDriverData->Controller,
383 &gEfiAtaPassThruProtocolGuid,
384 (VOID **)&AtaPassThru,
385 AtaBusDriverData->DriverBindingHandle,
386 AtaDevice->Handle,
387 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
388 );
389
390Done:
391 if (NewDevicePathNode != NULL) {
392 FreePool (NewDevicePathNode);
393 }
394
395 if (EFI_ERROR (Status) && (AtaDevice != NULL)) {
396 ReleaseAtaResources (AtaDevice);
397 DEBUG ((DEBUG_ERROR | DEBUG_INIT, "Failed to initialize Port %x PortMultiplierPort %x, status = %r\n", Port, PortMultiplierPort, Status));
398 }
399
400 return Status;
401}
402
420 IN EFI_HANDLE Controller,
421 IN EFI_HANDLE Handle
422 )
423{
424 EFI_STATUS Status;
425 EFI_BLOCK_IO_PROTOCOL *BlockIo;
426 EFI_BLOCK_IO2_PROTOCOL *BlockIo2;
427 ATA_DEVICE *AtaDevice;
428 EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThru;
430
431 BlockIo2 = NULL;
432 BlockIo = NULL;
433
434 Status = gBS->OpenProtocol (
435 Handle,
436 &gEfiBlockIoProtocolGuid,
437 (VOID **)&BlockIo,
438 This->DriverBindingHandle,
439 Controller,
440 EFI_OPEN_PROTOCOL_GET_PROTOCOL
441 );
442 if (EFI_ERROR (Status)) {
443 //
444 // Locate BlockIo2 protocol
445 //
446 Status = gBS->OpenProtocol (
447 Handle,
448 &gEfiBlockIo2ProtocolGuid,
449 (VOID **)&BlockIo2,
450 This->DriverBindingHandle,
451 Controller,
452 EFI_OPEN_PROTOCOL_GET_PROTOCOL
453 );
454 if (EFI_ERROR (Status)) {
455 return Status;
456 }
457 }
458
459 //
460 // Get AtaDevice data.
461 //
462 if (BlockIo != NULL) {
463 AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (BlockIo);
464 } else {
465 ASSERT (BlockIo2 != NULL);
466 AtaDevice = ATA_DEVICE_FROM_BLOCK_IO2 (BlockIo2);
467 }
468
469 //
470 // Close the child handle
471 //
472 gBS->CloseProtocol (
473 Controller,
474 &gEfiAtaPassThruProtocolGuid,
475 This->DriverBindingHandle,
476 Handle
477 );
478
479 //
480 // The Ata Bus driver installs the BlockIo and BlockIo2 in the DriverBindingStart().
481 // Here should uninstall both of them.
482 //
483 Status = gBS->UninstallMultipleProtocolInterfaces (
484 Handle,
485 &gEfiDevicePathProtocolGuid,
486 AtaDevice->DevicePath,
487 &gEfiBlockIoProtocolGuid,
488 &AtaDevice->BlockIo,
489 &gEfiBlockIo2ProtocolGuid,
490 &AtaDevice->BlockIo2,
491 &gEfiDiskInfoProtocolGuid,
492 &AtaDevice->DiskInfo,
493 NULL
494 );
495
496 if (EFI_ERROR (Status)) {
497 gBS->OpenProtocol (
498 Controller,
499 &gEfiAtaPassThruProtocolGuid,
500 (VOID **)&AtaPassThru,
501 This->DriverBindingHandle,
502 Handle,
503 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
504 );
505 return Status;
506 }
507
508 //
509 // If Storage Security Command Protocol is installed, then uninstall this protocol.
510 //
511 Status = gBS->OpenProtocol (
512 Handle,
513 &gEfiStorageSecurityCommandProtocolGuid,
514 (VOID **)&StorageSecurity,
515 This->DriverBindingHandle,
516 Controller,
517 EFI_OPEN_PROTOCOL_GET_PROTOCOL
518 );
519
520 if (!EFI_ERROR (Status)) {
521 Status = gBS->UninstallProtocolInterface (
522 Handle,
523 &gEfiStorageSecurityCommandProtocolGuid,
524 &AtaDevice->StorageSecurity
525 );
526 if (EFI_ERROR (Status)) {
527 gBS->OpenProtocol (
528 Controller,
529 &gEfiAtaPassThruProtocolGuid,
530 (VOID **)&AtaPassThru,
531 This->DriverBindingHandle,
532 Handle,
533 EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
534 );
535 return Status;
536 }
537 }
538
539 ReleaseAtaResources (AtaDevice);
540 return EFI_SUCCESS;
541}
542
586EFIAPI
589 IN EFI_HANDLE Controller,
590 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
591 )
592{
593 EFI_STATUS Status;
594 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
595 EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThru;
596 UINT16 Port;
597 UINT16 PortMultiplierPort;
598
599 //
600 // Test EFI_ATA_PASS_THRU_PROTOCOL on controller handle.
601 //
602 Status = gBS->OpenProtocol (
603 Controller,
604 &gEfiAtaPassThruProtocolGuid,
605 (VOID **)&AtaPassThru,
606 This->DriverBindingHandle,
607 Controller,
608 EFI_OPEN_PROTOCOL_BY_DRIVER
609 );
610
611 if (Status == EFI_ALREADY_STARTED) {
612 return EFI_SUCCESS;
613 }
614
615 if (EFI_ERROR (Status)) {
616 return Status;
617 }
618
619 //
620 // Test to see if this ATA Pass Thru Protocol is for a LOGICAL channel
621 //
622 if ((AtaPassThru->Mode->Attributes & EFI_ATA_PASS_THRU_ATTRIBUTES_LOGICAL) == 0) {
623 //
624 // Close the I/O Abstraction(s) used to perform the supported test
625 //
626 gBS->CloseProtocol (
627 Controller,
628 &gEfiAtaPassThruProtocolGuid,
629 This->DriverBindingHandle,
630 Controller
631 );
632 return EFI_UNSUPPORTED;
633 }
634
635 //
636 // Test RemainingDevicePath is valid or not.
637 //
638 if ((RemainingDevicePath != NULL) && !IsDevicePathEnd (RemainingDevicePath)) {
639 Status = AtaPassThru->GetDevice (AtaPassThru, RemainingDevicePath, &Port, &PortMultiplierPort);
640 if (EFI_ERROR (Status)) {
641 //
642 // Close the I/O Abstraction(s) used to perform the supported test
643 //
644 gBS->CloseProtocol (
645 Controller,
646 &gEfiAtaPassThruProtocolGuid,
647 This->DriverBindingHandle,
648 Controller
649 );
650 return Status;
651 }
652 }
653
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
664 //
665 // Open the EFI Device Path protocol needed to perform the supported test
666 //
667 Status = gBS->OpenProtocol (
668 Controller,
669 &gEfiDevicePathProtocolGuid,
670 (VOID **)&ParentDevicePath,
671 This->DriverBindingHandle,
672 Controller,
673 EFI_OPEN_PROTOCOL_GET_PROTOCOL
674 );
675 return Status;
676}
677
714EFIAPI
717 IN EFI_HANDLE Controller,
718 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
719 )
720{
721 EFI_STATUS Status;
722 EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThru;
723 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
724 ATA_BUS_DRIVER_DATA *AtaBusDriverData;
725 UINT16 Port;
726 UINT16 PortMultiplierPort;
727
728 AtaBusDriverData = NULL;
729
730 Status = gBS->OpenProtocol (
731 Controller,
732 &gEfiDevicePathProtocolGuid,
733 (VOID **)&ParentDevicePath,
734 This->DriverBindingHandle,
735 Controller,
736 EFI_OPEN_PROTOCOL_GET_PROTOCOL
737 );
738 if (EFI_ERROR (Status)) {
739 return Status;
740 }
741
742 //
743 // Report Status Code to indicate ATA bus starts
744 //
747 (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_PC_INIT),
748 ParentDevicePath
749 );
750
751 Status = gBS->OpenProtocol (
752 Controller,
753 &gEfiAtaPassThruProtocolGuid,
754 (VOID **)&AtaPassThru,
755 This->DriverBindingHandle,
756 Controller,
757 EFI_OPEN_PROTOCOL_BY_DRIVER
758 );
759 if ((EFI_ERROR (Status)) && (Status != EFI_ALREADY_STARTED)) {
760 goto ErrorExit;
761 }
762
763 //
764 // Check EFI_ALREADY_STARTED to reuse the original ATA_BUS_DRIVER_DATA.
765 //
766 if (Status != EFI_ALREADY_STARTED) {
767 AtaBusDriverData = AllocateZeroPool (sizeof (ATA_BUS_DRIVER_DATA));
768 if (AtaBusDriverData == NULL) {
769 Status = EFI_OUT_OF_RESOURCES;
770 goto ErrorExit;
771 }
772
773 AtaBusDriverData->AtaPassThru = AtaPassThru;
774 AtaBusDriverData->Controller = Controller;
775 AtaBusDriverData->ParentDevicePath = ParentDevicePath;
776 AtaBusDriverData->DriverBindingHandle = This->DriverBindingHandle;
777
778 Status = gBS->InstallMultipleProtocolInterfaces (
779 &Controller,
780 &gEfiCallerIdGuid,
781 AtaBusDriverData,
782 NULL
783 );
784 if (EFI_ERROR (Status)) {
785 goto ErrorExit;
786 }
787 } else {
788 Status = gBS->OpenProtocol (
789 Controller,
790 &gEfiCallerIdGuid,
791 (VOID **)&AtaBusDriverData,
792 This->DriverBindingHandle,
793 Controller,
794 EFI_OPEN_PROTOCOL_GET_PROTOCOL
795 );
796 if (EFI_ERROR (Status)) {
797 AtaBusDriverData = NULL;
798 goto ErrorExit;
799 }
800 }
801
802 //
803 // Report Status Code to indicate detecting devices on bus
804 //
807 (EFI_IO_BUS_ATA_ATAPI | EFI_IOB_PC_DETECT),
808 ParentDevicePath
809 );
810
811 if (RemainingDevicePath == NULL) {
812 Port = 0xFFFF;
813 while (TRUE) {
814 Status = AtaPassThru->GetNextPort (AtaPassThru, &Port);
815 if (EFI_ERROR (Status)) {
816 //
817 // We cannot find more legal port then we are done.
818 //
819 break;
820 }
821
822 PortMultiplierPort = 0xFFFF;
823 while (TRUE) {
824 Status = AtaPassThru->GetNextDevice (AtaPassThru, Port, &PortMultiplierPort);
825 if (EFI_ERROR (Status)) {
826 //
827 // We cannot find more legal port multiplier port number for ATA device
828 // on the port, then we are done.
829 //
830 break;
831 }
832
833 RegisterAtaDevice (AtaBusDriverData, Port, PortMultiplierPort);
834 }
835 }
836
837 Status = EFI_SUCCESS;
838 } else if (!IsDevicePathEnd (RemainingDevicePath)) {
839 Status = AtaPassThru->GetDevice (AtaPassThru, RemainingDevicePath, &Port, &PortMultiplierPort);
840 if (!EFI_ERROR (Status)) {
841 Status = RegisterAtaDevice (AtaBusDriverData, Port, PortMultiplierPort);
842 }
843 }
844
845 return Status;
846
847ErrorExit:
848
849 if (AtaBusDriverData != NULL) {
850 gBS->UninstallMultipleProtocolInterfaces (
851 Controller,
852 &gEfiCallerIdGuid,
853 AtaBusDriverData,
854 NULL
855 );
856 FreePool (AtaBusDriverData);
857 }
858
859 gBS->CloseProtocol (
860 Controller,
861 &gEfiAtaPassThruProtocolGuid,
862 This->DriverBindingHandle,
863 Controller
864 );
865
866 return Status;
867}
868
896EFIAPI
899 IN EFI_HANDLE Controller,
900 IN UINTN NumberOfChildren,
901 IN EFI_HANDLE *ChildHandleBuffer
902 )
903{
904 EFI_STATUS Status;
905 BOOLEAN AllChildrenStopped;
906 UINTN Index;
907 ATA_BUS_DRIVER_DATA *AtaBusDriverData;
908
909 if (NumberOfChildren == 0) {
910 Status = gBS->OpenProtocol (
911 Controller,
912 &gEfiCallerIdGuid,
913 (VOID **)&AtaBusDriverData,
914 This->DriverBindingHandle,
915 Controller,
916 EFI_OPEN_PROTOCOL_GET_PROTOCOL
917 );
918 if (!EFI_ERROR (Status)) {
919 gBS->UninstallMultipleProtocolInterfaces (
920 Controller,
921 &gEfiCallerIdGuid,
922 AtaBusDriverData,
923 NULL
924 );
925 FreePool (AtaBusDriverData);
926 }
927
928 gBS->CloseProtocol (
929 Controller,
930 &gEfiAtaPassThruProtocolGuid,
931 This->DriverBindingHandle,
932 Controller
933 );
934
935 return EFI_SUCCESS;
936 }
937
938 AllChildrenStopped = TRUE;
939
940 for (Index = 0; Index < NumberOfChildren; Index++) {
941 Status = UnregisterAtaDevice (This, Controller, ChildHandleBuffer[Index]);
942 if (EFI_ERROR (Status)) {
943 AllChildrenStopped = FALSE;
944 }
945 }
946
947 if (!AllChildrenStopped) {
948 return EFI_DEVICE_ERROR;
949 }
950
951 return EFI_SUCCESS;
952}
953
966EFIAPI
969 IN BOOLEAN ExtendedVerification
970 )
971{
972 EFI_STATUS Status;
973 ATA_DEVICE *AtaDevice;
974 EFI_TPL OldTpl;
975
976 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
977
978 AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (This);
979
980 Status = ResetAtaDevice (AtaDevice);
981
982 if (EFI_ERROR (Status)) {
983 Status = EFI_DEVICE_ERROR;
984 }
985
986 gBS->RestoreTPL (OldTpl);
987 return Status;
988}
989
1018 IN VOID *This,
1019 IN UINT32 MediaId,
1020 IN EFI_LBA Lba,
1021 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
1022 IN UINTN BufferSize,
1023 OUT VOID *Buffer,
1024 IN BOOLEAN IsBlockIo2,
1025 IN BOOLEAN IsWrite
1026 )
1027{
1028 ATA_DEVICE *AtaDevice;
1029 EFI_STATUS Status;
1030 EFI_TPL OldTpl;
1031 EFI_BLOCK_IO_MEDIA *Media;
1032 UINTN BlockSize;
1033 UINTN NumberOfBlocks;
1034 UINTN IoAlign;
1035
1036 if (IsBlockIo2) {
1037 Media = ((EFI_BLOCK_IO2_PROTOCOL *)This)->Media;
1038 AtaDevice = ATA_DEVICE_FROM_BLOCK_IO2 (This);
1039 } else {
1040 Media = ((EFI_BLOCK_IO_PROTOCOL *)This)->Media;
1041 AtaDevice = ATA_DEVICE_FROM_BLOCK_IO (This);
1042 }
1043
1044 if (MediaId != Media->MediaId) {
1045 return EFI_MEDIA_CHANGED;
1046 }
1047
1048 //
1049 // Check parameters.
1050 //
1051 if (Buffer == NULL) {
1052 return EFI_INVALID_PARAMETER;
1053 }
1054
1055 if (BufferSize == 0) {
1056 if ((Token != NULL) && (Token->Event != NULL)) {
1057 Token->TransactionStatus = EFI_SUCCESS;
1058 gBS->SignalEvent (Token->Event);
1059 }
1060
1061 return EFI_SUCCESS;
1062 }
1063
1064 BlockSize = Media->BlockSize;
1065 if ((BufferSize % BlockSize) != 0) {
1066 return EFI_BAD_BUFFER_SIZE;
1067 }
1068
1069 NumberOfBlocks = BufferSize / BlockSize;
1070 if ((Lba + NumberOfBlocks - 1) > Media->LastBlock) {
1071 return EFI_INVALID_PARAMETER;
1072 }
1073
1074 IoAlign = Media->IoAlign;
1075 if ((IoAlign > 0) && (((UINTN)Buffer & (IoAlign - 1)) != 0)) {
1076 return EFI_INVALID_PARAMETER;
1077 }
1078
1079 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1080
1081 //
1082 // Invoke low level AtaDevice Access Routine.
1083 //
1084 Status = AccessAtaDevice (AtaDevice, Buffer, Lba, NumberOfBlocks, IsWrite, Token);
1085
1086 gBS->RestoreTPL (OldTpl);
1087
1088 return Status;
1089}
1090
1111EFIAPI
1114 IN UINT32 MediaId,
1115 IN EFI_LBA Lba,
1116 IN UINTN BufferSize,
1117 OUT VOID *Buffer
1118 )
1119{
1120 return BlockIoReadWrite ((VOID *)This, MediaId, Lba, NULL, BufferSize, Buffer, FALSE, FALSE);
1121}
1122
1144EFIAPI
1147 IN UINT32 MediaId,
1148 IN EFI_LBA Lba,
1149 IN UINTN BufferSize,
1150 IN VOID *Buffer
1151 )
1152{
1153 return BlockIoReadWrite ((VOID *)This, MediaId, Lba, NULL, BufferSize, Buffer, FALSE, TRUE);
1154}
1155
1167EFIAPI
1170 )
1171{
1172 //
1173 // return directly
1174 //
1175 return EFI_SUCCESS;
1176}
1177
1190EFIAPI
1193 IN BOOLEAN ExtendedVerification
1194 )
1195{
1196 EFI_STATUS Status;
1197 ATA_DEVICE *AtaDevice;
1198 EFI_TPL OldTpl;
1199
1200 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1201
1202 AtaDevice = ATA_DEVICE_FROM_BLOCK_IO2 (This);
1203
1204 AtaTerminateNonBlockingTask (AtaDevice);
1205
1206 Status = ResetAtaDevice (AtaDevice);
1207
1208 if (EFI_ERROR (Status)) {
1209 Status = EFI_DEVICE_ERROR;
1210 }
1211
1212 gBS->RestoreTPL (OldTpl);
1213 return Status;
1214}
1215
1243EFIAPI
1246 IN UINT32 MediaId,
1247 IN EFI_LBA Lba,
1248 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
1249 IN UINTN BufferSize,
1250 OUT VOID *Buffer
1251 )
1252{
1253 return BlockIoReadWrite ((VOID *)This, MediaId, Lba, Token, BufferSize, Buffer, TRUE, FALSE);
1254}
1255
1279EFIAPI
1282 IN UINT32 MediaId,
1283 IN EFI_LBA Lba,
1284 IN OUT EFI_BLOCK_IO2_TOKEN *Token,
1285 IN UINTN BufferSize,
1286 IN VOID *Buffer
1287 )
1288{
1289 return BlockIoReadWrite ((VOID *)This, MediaId, Lba, Token, BufferSize, Buffer, TRUE, TRUE);
1290}
1291
1304EFIAPI
1308 )
1309{
1310 //
1311 // Signal event and return directly.
1312 //
1313 if ((Token != NULL) && (Token->Event != NULL)) {
1314 Token->TransactionStatus = EFI_SUCCESS;
1315 gBS->SignalEvent (Token->Event);
1316 }
1317
1318 return EFI_SUCCESS;
1319}
1320
1338EFIAPI
1341 IN OUT VOID *InquiryData,
1342 IN OUT UINT32 *InquiryDataSize
1343 )
1344{
1345 return EFI_NOT_FOUND;
1346}
1347
1367EFIAPI
1370 IN OUT VOID *IdentifyData,
1371 IN OUT UINT32 *IdentifyDataSize
1372 )
1373{
1374 EFI_STATUS Status;
1375 ATA_DEVICE *AtaDevice;
1376
1377 AtaDevice = ATA_DEVICE_FROM_DISK_INFO (This);
1378
1379 Status = EFI_BUFFER_TOO_SMALL;
1380 if (*IdentifyDataSize >= sizeof (ATA_IDENTIFY_DATA)) {
1381 Status = EFI_SUCCESS;
1382 CopyMem (IdentifyData, AtaDevice->IdentifyData, sizeof (ATA_IDENTIFY_DATA));
1383 }
1384
1385 *IdentifyDataSize = sizeof (ATA_IDENTIFY_DATA);
1386
1387 return Status;
1388}
1389
1408EFIAPI
1411 IN OUT VOID *SenseData,
1412 IN OUT UINT32 *SenseDataSize,
1413 OUT UINT8 *SenseDataNumber
1414 )
1415{
1416 return EFI_NOT_FOUND;
1417}
1418
1431EFIAPI
1434 OUT UINT32 *IdeChannel,
1435 OUT UINT32 *IdeDevice
1436 )
1437{
1438 ATA_DEVICE *AtaDevice;
1439
1440 AtaDevice = ATA_DEVICE_FROM_DISK_INFO (This);
1441 *IdeChannel = AtaDevice->Port;
1442 *IdeDevice = AtaDevice->PortMultiplierPort;
1443
1444 return EFI_SUCCESS;
1445}
1446
1522EFIAPI
1525 IN UINT32 MediaId,
1526 IN UINT64 Timeout,
1527 IN UINT8 SecurityProtocolId,
1528 IN UINT16 SecurityProtocolSpecificData,
1529 IN UINTN PayloadBufferSize,
1530 OUT VOID *PayloadBuffer,
1531 OUT UINTN *PayloadTransferSize
1532 )
1533{
1534 EFI_STATUS Status;
1535 ATA_DEVICE *Private;
1536 EFI_TPL OldTpl;
1537
1538 DEBUG ((DEBUG_INFO, "EFI Storage Security Protocol - Read\n"));
1539 if (((PayloadBuffer == NULL) || (PayloadTransferSize == NULL)) && (PayloadBufferSize != 0)) {
1540 return EFI_INVALID_PARAMETER;
1541 }
1542
1543 Status = EFI_SUCCESS;
1544 Private = ATA_DEVICE_FROM_STORAGE_SECURITY (This);
1545
1546 if (MediaId != Private->BlockIo.Media->MediaId) {
1547 return EFI_MEDIA_CHANGED;
1548 }
1549
1550 if (!Private->BlockIo.Media->MediaPresent) {
1551 return EFI_NO_MEDIA;
1552 }
1553
1554 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1555
1556 Status = TrustTransferAtaDevice (
1557 Private,
1558 PayloadBuffer,
1559 SecurityProtocolId,
1560 SecurityProtocolSpecificData,
1561 PayloadBufferSize,
1562 FALSE,
1563 Timeout,
1564 PayloadTransferSize
1565 );
1566
1567 gBS->RestoreTPL (OldTpl);
1568 return Status;
1569}
1570
1635EFIAPI
1638 IN UINT32 MediaId,
1639 IN UINT64 Timeout,
1640 IN UINT8 SecurityProtocolId,
1641 IN UINT16 SecurityProtocolSpecificData,
1642 IN UINTN PayloadBufferSize,
1643 IN VOID *PayloadBuffer
1644 )
1645{
1646 EFI_STATUS Status;
1647 ATA_DEVICE *Private;
1648 EFI_TPL OldTpl;
1649
1650 DEBUG ((DEBUG_INFO, "EFI Storage Security Protocol - Send\n"));
1651 if ((PayloadBuffer == NULL) && (PayloadBufferSize != 0)) {
1652 return EFI_INVALID_PARAMETER;
1653 }
1654
1655 Status = EFI_SUCCESS;
1656 Private = ATA_DEVICE_FROM_STORAGE_SECURITY (This);
1657
1658 if (MediaId != Private->BlockIo.Media->MediaId) {
1659 return EFI_MEDIA_CHANGED;
1660 }
1661
1662 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
1663 Status = TrustTransferAtaDevice (
1664 Private,
1665 PayloadBuffer,
1666 SecurityProtocolId,
1667 SecurityProtocolSpecificData,
1668 PayloadBufferSize,
1669 TRUE,
1670 Timeout,
1671 NULL
1672 );
1673
1674 gBS->RestoreTPL (OldTpl);
1675 return Status;
1676}
1677
1689EFIAPI
1691 IN EFI_HANDLE ImageHandle,
1692 IN EFI_SYSTEM_TABLE *SystemTable
1693 )
1694{
1695 EFI_STATUS Status;
1696
1697 //
1698 // Install driver model protocol(s).
1699 //
1701 ImageHandle,
1702 SystemTable,
1703 &gAtaBusDriverBinding,
1704 ImageHandle,
1705 &gAtaBusComponentName,
1706 &gAtaBusComponentName2
1707 );
1708 ASSERT_EFI_ERROR (Status);
1709
1710 return Status;
1711}
UINT64 UINTN
EFI_STATUS TrustTransferAtaDevice(IN PEI_AHCI_ATA_DEVICE_DATA *DeviceData, IN OUT VOID *Buffer, IN UINT8 SecurityProtocolId, IN UINT16 SecurityProtocolSpecificData, IN UINTN TransferLength, IN BOOLEAN IsTrustSend, IN UINT64 Timeout, OUT UINTN *TransferLengthOut)
Definition: AhciMode.c:2063
EFI_STATUS AccessAtaDevice(IN PEI_AHCI_ATA_DEVICE_DATA *DeviceData, IN OUT UINT8 *Buffer, IN EFI_LBA StartLba, IN UINTN NumberOfBlocks)
EFI_STATUS RegisterAtaDevice(IN OUT ATA_BUS_DRIVER_DATA *AtaBusDriverData, IN UINT16 Port, IN UINT16 PortMultiplierPort)
Definition: AtaBus.c:217
EFI_STATUS UnregisterAtaDevice(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_HANDLE Handle)
Definition: AtaBus.c:418
EFI_STATUS EFIAPI AtaBlockIoResetEx(IN EFI_BLOCK_IO2_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
Definition: AtaBus.c:1191
EFI_STATUS EFIAPI AtaDiskInfoSenseData(IN EFI_DISK_INFO_PROTOCOL *This, IN OUT VOID *SenseData, IN OUT UINT32 *SenseDataSize, OUT UINT8 *SenseDataNumber)
Definition: AtaBus.c:1409
EFI_STATUS EFIAPI AtaStorageSecurityReceiveData(IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This, IN UINT32 MediaId, IN UINT64 Timeout, IN UINT8 SecurityProtocolId, IN UINT16 SecurityProtocolSpecificData, IN UINTN PayloadBufferSize, OUT VOID *PayloadBuffer, OUT UINTN *PayloadTransferSize)
Definition: AtaBus.c:1523
EFI_STATUS BlockIoReadWrite(IN VOID *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN OUT EFI_BLOCK_IO2_TOKEN *Token, IN UINTN BufferSize, OUT VOID *Buffer, IN BOOLEAN IsBlockIo2, IN BOOLEAN IsWrite)
Definition: AtaBus.c:1017
VOID FreeAlignedBuffer(IN VOID *Buffer, IN UINTN BufferSize)
Definition: AtaBus.c:124
EFI_STATUS EFIAPI AtaBusDriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: AtaBus.c:715
EFI_STATUS EFIAPI AtaBlockIoWriteBlocksEx(IN EFI_BLOCK_IO2_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN OUT EFI_BLOCK_IO2_TOKEN *Token, IN UINTN BufferSize, IN VOID *Buffer)
Definition: AtaBus.c:1280
EFI_STATUS EFIAPI AtaBlockIoFlushBlocksEx(IN EFI_BLOCK_IO2_PROTOCOL *This, IN OUT EFI_BLOCK_IO2_TOKEN *Token)
Definition: AtaBus.c:1305
EFI_STATUS EFIAPI InitializeAtaBus(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: AtaBus.c:1690
EFI_STATUS EFIAPI AtaBlockIoWriteBlocks(IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, IN VOID *Buffer)
Definition: AtaBus.c:1145
EFI_STATUS EFIAPI AtaBlockIoReset(IN EFI_BLOCK_IO_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
Definition: AtaBus.c:967
EFI_STATUS EFIAPI AtaDiskInfoInquiry(IN EFI_DISK_INFO_PROTOCOL *This, IN OUT VOID *InquiryData, IN OUT UINT32 *InquiryDataSize)
Definition: AtaBus.c:1339
EFI_STATUS EFIAPI AtaBusDriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer)
Definition: AtaBus.c:897
EFI_STATUS EFIAPI AtaBusDriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: AtaBus.c:587
EFI_STATUS EFIAPI AtaBlockIoReadBlocksEx(IN EFI_BLOCK_IO2_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN OUT EFI_BLOCK_IO2_TOKEN *Token, IN UINTN BufferSize, OUT VOID *Buffer)
Definition: AtaBus.c:1244
EFI_STATUS EFIAPI AtaDiskInfoWhichIde(IN EFI_DISK_INFO_PROTOCOL *This, OUT UINT32 *IdeChannel, OUT UINT32 *IdeDevice)
Definition: AtaBus.c:1432
VOID * AllocateAlignedBuffer(IN ATA_DEVICE *AtaDevice, IN UINTN BufferSize)
Definition: AtaBus.c:105
EFI_STATUS EFIAPI AtaStorageSecuritySendData(IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This, IN UINT32 MediaId, IN UINT64 Timeout, IN UINT8 SecurityProtocolId, IN UINT16 SecurityProtocolSpecificData, IN UINTN PayloadBufferSize, IN VOID *PayloadBuffer)
Definition: AtaBus.c:1636
EFI_STATUS EFIAPI AtaBlockIoReadBlocks(IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, OUT VOID *Buffer)
Definition: AtaBus.c:1112
EFI_STATUS EFIAPI AtaDiskInfoIdentify(IN EFI_DISK_INFO_PROTOCOL *This, IN OUT VOID *IdentifyData, IN OUT UINT32 *IdentifyDataSize)
Definition: AtaBus.c:1368
VOID ReleaseAtaResources(IN ATA_DEVICE *AtaDevice)
Definition: AtaBus.c:143
EFI_STATUS EFIAPI AtaBlockIoFlushBlocks(IN EFI_BLOCK_IO_PROTOCOL *This)
Definition: AtaBus.c:1168
EFI_STATUS ResetAtaDevice(IN ATA_DEVICE *AtaDevice)
EFI_STATUS DiscoverAtaDevice(IN OUT ATA_DEVICE *AtaDevice)
VOID EFIAPI FreeAtaSubTask(IN OUT ATA_BUS_ASYN_SUB_TASK *Task)
VOID EFIAPI AtaTerminateNonBlockingTask(IN ATA_DEVICE *AtaDevice)
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
Definition: LinkedList.c:403
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
Definition: LinkedList.c:590
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
Definition: LinkedList.c:182
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
Definition: MemLibGuid.c:39
#define MSG_SATA_DP
Definition: DevicePath.h:510
EFI_DEVICE_PATH_PROTOCOL *EFIAPI AppendDevicePathNode(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL)
BOOLEAN EFIAPI IsDevicePathEnd(IN CONST VOID *Node)
#define EFI_DISK_INFO_IDE_INTERFACE_GUID
Definition: DiskInfo.h:33
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID EFIAPI FreeAlignedPages(IN VOID *Buffer, IN UINTN Pages)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define REPORT_STATUS_CODE_WITH_DEVICE_PATH(Type, Value, DevicePathParameter)
#define EFI_ATA_PASS_THRU_ATTRIBUTES_LOGICAL
Definition: AtaPassThru.h:38
#define EFI_IOB_PC_INIT
Definition: PiStatusCode.h:549
#define EFI_PROGRESS_CODE
Definition: PiStatusCode.h:43
VOID *EFIAPI AllocateAlignedPages(IN UINTN Pages, IN UINTN Alignment)
UINT64 EFI_LBA
Definition: UefiBaseType.h:45
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
UINTN EFI_TPL
Definition: UefiBaseType.h:41
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI AddUnicodeString2(IN CONST CHAR8 *Language, IN CONST CHAR8 *SupportedLanguages, IN OUT EFI_UNICODE_STRING_TABLE **UnicodeStringTable, IN CONST CHAR16 *UnicodeString, IN BOOLEAN Iso639Language)
Definition: UefiLib.c:1087
EFI_STATUS EFIAPI EfiLibInstallDriverBindingComponentName2(IN CONST EFI_HANDLE ImageHandle, IN CONST EFI_SYSTEM_TABLE *SystemTable, IN EFI_DRIVER_BINDING_PROTOCOL *DriverBinding, IN EFI_HANDLE DriverBindingHandle, IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName OPTIONAL, IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2 OPTIONAL)
EFI_STATUS EFIAPI FreeUnicodeStringTable(IN EFI_UNICODE_STRING_TABLE *UnicodeStringTable)
Definition: UefiLib.c:1257
@ EFI_NATIVE_INTERFACE
Definition: UefiSpec.h:1193
EFI_BLOCK_IO_MEDIA * Media
Definition: BlockIo2.h:187
EFI_BLOCK_IO_MEDIA * Media
Definition: BlockIo.h:224
UINT32 BlockSize
Definition: BlockIo.h:167
EFI_LBA LastBlock
Definition: BlockIo.h:178
BOOLEAN MediaPresent
Definition: BlockIo.h:144