]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Move Pci/AtapiPassThru/Dxe to Pci/AtapiPassThruDxe.
authoryshang1 <yshang1@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 3 Jul 2007 01:47:19 +0000 (01:47 +0000)
committeryshang1 <yshang1@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 3 Jul 2007 01:47:19 +0000 (01:47 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2970 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Bus/Pci/AtapiPassThru/Dxe/AtapiPassThru.c [deleted file]
MdeModulePkg/Bus/Pci/AtapiPassThru/Dxe/AtapiPassThru.h [deleted file]
MdeModulePkg/Bus/Pci/AtapiPassThru/Dxe/AtapiPassThru.inf [deleted file]
MdeModulePkg/Bus/Pci/AtapiPassThru/Dxe/AtapiPassThru.msa [deleted file]
MdeModulePkg/Bus/Pci/AtapiPassThru/Dxe/ComponentName.c [deleted file]
MdeModulePkg/Bus/Pci/AtapiPassThruDxe/AtapiPassThru.c [new file with mode: 0644]
MdeModulePkg/Bus/Pci/AtapiPassThruDxe/AtapiPassThru.h [new file with mode: 0644]
MdeModulePkg/Bus/Pci/AtapiPassThruDxe/AtapiPassThru.inf [new file with mode: 0644]
MdeModulePkg/Bus/Pci/AtapiPassThruDxe/AtapiPassThru.msa [new file with mode: 0644]
MdeModulePkg/Bus/Pci/AtapiPassThruDxe/ComponentName.c [new file with mode: 0644]

diff --git a/MdeModulePkg/Bus/Pci/AtapiPassThru/Dxe/AtapiPassThru.c b/MdeModulePkg/Bus/Pci/AtapiPassThru/Dxe/AtapiPassThru.c
deleted file mode 100644 (file)
index f14d9e3..0000000
+++ /dev/null
@@ -1,2177 +0,0 @@
-/** @file\r
-  Copyright (c) 2006, Intel Corporation                                                         \r
-  All rights reserved. This program and the accompanying materials                          \r
-  are licensed and made available under the terms and conditions of the BSD License         \r
-  which accompanies this distribution.  The full text of the license may be found at        \r
-  http://opensource.org/licenses/bsd-license.php                                            \r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
-\r
-**/\r
-\r
-#include "AtapiPassThru.h"\r
-\r
-///\r
-/// IDE registers' fixed address\r
-///\r
-static IDE_BASE_REGISTERS   gAtapiIoPortRegisters[2] = {\r
-  { 0x1f0, { 0x1f1 }, 0x1f2, 0x1f3, 0x1f4, 0x1f5, 0x1f6, { 0x1f7 }, { 0x3f6 }, 0x3f7, 0 },\r
-  { 0x170, { 0x171 }, 0x172, 0x173, 0x174, 0x175, 0x176, { 0x177 }, { 0x376 }, 0x377, 0 } \r
-};\r
-\r
-static SCSI_COMMAND_SET     gEndTable = { 0xff, (DATA_DIRECTION) 0xff };\r
-\r
-///\r
-/// This table contains all the supported ATAPI commands.\r
-///\r
-static SCSI_COMMAND_SET     gSupportedATAPICommands[] = {\r
-  { OP_INQUIRY,                     DataIn  },\r
-  { OP_LOAD_UNLOAD_CD,              NoData  },\r
-  { OP_MECHANISM_STATUS,            DataIn  },\r
-  { OP_MODE_SELECT_10,              DataOut },\r
-  { OP_MODE_SENSE_10,               DataIn  },\r
-  { OP_PAUSE_RESUME,                NoData  },\r
-  { OP_PLAY_AUDIO_10,               DataIn  },\r
-  { OP_PLAY_AUDIO_MSF,              DataIn  },\r
-  { OP_PLAY_CD,                     DataIn  },\r
-  { OP_PLAY_CD_MSF,                 DataIn  },\r
-  { OP_PREVENT_ALLOW_MEDIUM_REMOVAL,NoData  },\r
-  { OP_READ_10,                     DataIn  },\r
-  { OP_READ_12,                     DataIn  },\r
-  { OP_READ_CAPACITY,               DataIn  },\r
-  { OP_READ_CD,                     DataIn  },\r
-  { OP_READ_CD_MSF,                 DataIn  },\r
-  { OP_READ_HEADER,                 DataIn  },\r
-  { OP_READ_SUB_CHANNEL,            DataIn  },\r
-  { OP_READ_TOC,                    DataIn  },\r
-  { OP_REQUEST_SENSE,               DataIn  },\r
-  { OP_SCAN,                        NoData  },\r
-  { OP_SEEK_10,                     NoData  },\r
-  { OP_SET_CD_SPEED,                DataOut },\r
-  { OP_STOPPLAY_SCAN,               NoData  },\r
-  { OP_START_STOP_UNIT,             NoData  },\r
-  { OP_TEST_UNIT_READY,             NoData  },\r
-  { OP_FORMAT_UNIT,                 DataOut },\r
-  { OP_READ_FORMAT_CAPACITIES,      DataIn  },\r
-  { OP_VERIFY,                      DataOut },\r
-  { OP_WRITE_10,                    DataOut },\r
-  { OP_WRITE_12,                    DataOut },\r
-  { OP_WRITE_AND_VERIFY,            DataOut },\r
-  { 0xff,                           (DATA_DIRECTION) 0xff    } \r
-};\r
-\r
-static CHAR16               *gControllerNameString  = (CHAR16 *) L"ATAPI Controller";\r
-static CHAR16               *gAtapiChannelString    = (CHAR16 *) L"ATAPI Channel";\r
-\r
-EFI_DRIVER_BINDING_PROTOCOL gAtapiScsiPassThruDriverBinding = {\r
-  AtapiScsiPassThruDriverBindingSupported,\r
-  AtapiScsiPassThruDriverBindingStart,\r
-  AtapiScsiPassThruDriverBindingStop,\r
-  0xa,\r
-  NULL,\r
-  NULL\r
-};\r
-\r
-/**\r
-  Supported.\r
-\r
-  (Standard DriverBinding Protocol Supported() function)\r
-\r
-  @return EFI_STATUS\r
-\r
-  @todo    This - add argument and description to function comment\r
-  @todo    Controller - add argument and description to function comment\r
-  @todo    RemainingDevicePath - add argument and description to function comment\r
-  @todo    EFI_UNSUPPORTED - add return value to function comment\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruDriverBindingSupported (\r
-  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
-  IN EFI_HANDLE                   Controller,\r
-  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
-  )\r
-{\r
-  EFI_STATUS          Status;\r
-  EFI_PCI_IO_PROTOCOL *PciIo;\r
-  PCI_TYPE00          Pci;\r
-\r
-  //\r
-  // Open the IO Abstraction(s) needed to perform the supported test\r
-  //\r
-  Status = gBS->OpenProtocol (\r
-                  Controller,\r
-                  &gEfiPciIoProtocolGuid,\r
-                  (VOID **) &PciIo,\r
-                  This->DriverBindingHandle,\r
-                  Controller,\r
-                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-  //\r
-  // Use the PCI I/O Protocol to see if Controller is a IDE Controller that\r
-  // can be managed by this driver.  Read the PCI Configuration Header\r
-  // for this device.\r
-  //\r
-  Status = PciIo->Pci.Read (\r
-                        PciIo,\r
-                        EfiPciIoWidthUint32,\r
-                        0,\r
-                        sizeof (Pci) / sizeof (UINT32),\r
-                        &Pci\r
-                        );\r
-  if (EFI_ERROR (Status)) {\r
-    gBS->CloseProtocol (\r
-          Controller,\r
-          &gEfiPciIoProtocolGuid,\r
-          This->DriverBindingHandle,\r
-          Controller\r
-          );\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  if (Pci.Hdr.ClassCode[2] != PCI_CLASS_MASS_STORAGE || Pci.Hdr.ClassCode[1] != PCI_CLASS_IDE) {\r
-\r
-    Status = EFI_UNSUPPORTED;\r
-  }\r
-\r
-  gBS->CloseProtocol (\r
-        Controller,\r
-        &gEfiPciIoProtocolGuid,\r
-        This->DriverBindingHandle,\r
-        Controller\r
-        );\r
-\r
-  return Status;\r
-}\r
-\r
-/**\r
-  Create handles for IDE channels specified by RemainingDevicePath.\r
-  Install SCSI Pass Thru Protocol onto each created handle.\r
-\r
-  (Standard DriverBinding Protocol Start() function)\r
-\r
-  @return EFI_STATUS\r
-\r
-  @todo    This - add argument and description to function comment\r
-  @todo    Controller - add argument and description to function comment\r
-  @todo    RemainingDevicePath - add argument and description to function comment\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruDriverBindingStart (\r
-  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
-  IN EFI_HANDLE                   Controller,\r
-  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
-  )\r
-{\r
-  EFI_STATUS          Status;\r
-  EFI_PCI_IO_PROTOCOL *PciIo;\r
-\r
-  PciIo = NULL;\r
-  Status = gBS->OpenProtocol (\r
-                  Controller,\r
-                  &gEfiPciIoProtocolGuid,\r
-                  (VOID **) &PciIo,\r
-                  This->DriverBindingHandle,\r
-                  Controller,\r
-                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  Status = PciIo->Attributes (\r
-                    PciIo,\r
-                    EfiPciIoAttributeOperationEnable,\r
-                    EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO | EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO | EFI_PCI_DEVICE_ENABLE,\r
-                    NULL\r
-                    );\r
-  if (EFI_ERROR (Status)) {\r
-    goto Done;\r
-  }\r
-\r
-  //\r
-  // Create SCSI Pass Thru instance for the IDE channel.\r
-  //\r
-  Status = RegisterAtapiScsiPassThru (This, Controller, PciIo);\r
-\r
-Done:\r
-  if (EFI_ERROR (Status)) {\r
-    if (PciIo) {\r
-      PciIo->Attributes (\r
-              PciIo,\r
-              EfiPciIoAttributeOperationDisable,\r
-              EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO | EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO | EFI_PCI_DEVICE_ENABLE,\r
-              NULL\r
-              );\r
-    }\r
-\r
-    gBS->CloseProtocol (\r
-          Controller,\r
-          &gEfiPciIoProtocolGuid,\r
-          This->DriverBindingHandle,\r
-          Controller\r
-          );\r
-  }\r
-\r
-  return Status;\r
-}\r
-\r
-/**\r
-  Stop.\r
-\r
-  (Standard DriverBinding Protocol Stop() function)\r
-\r
-  @return EFI_STATUS\r
-\r
-  @todo    This - add argument and description to function comment\r
-  @todo    Controller - add argument and description to function comment\r
-  @todo    NumberOfChildren - add argument and description to function comment\r
-  @todo    ChildHandleBuffer - add argument and description to function comment\r
-  @todo    EFI_SUCCESS - add return value to function comment\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruDriverBindingStop (\r
-  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
-  IN  EFI_HANDLE                      Controller,\r
-  IN  UINTN                           NumberOfChildren,\r
-  IN  EFI_HANDLE                      *ChildHandleBuffer\r
-  )\r
-{\r
-  EFI_STATUS                  Status;\r
-  EFI_SCSI_PASS_THRU_PROTOCOL *ScsiPassThru;\r
-  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate;\r
-\r
-  Status = gBS->OpenProtocol (\r
-                  Controller,\r
-                  &gEfiScsiPassThruProtocolGuid,\r
-                  (VOID **) &ScsiPassThru,\r
-                  This->DriverBindingHandle,\r
-                  Controller,\r
-                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  AtapiScsiPrivate = ATAPI_SCSI_PASS_THRU_DEV_FROM_THIS (ScsiPassThru);\r
-\r
-  Status = gBS->UninstallProtocolInterface (\r
-                  Controller,\r
-                  &gEfiScsiPassThruProtocolGuid,\r
-                  &AtapiScsiPrivate->ScsiPassThru\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-  //\r
-  // Release Pci Io protocol on the controller handle.\r
-  //\r
-  AtapiScsiPrivate->PciIo->Attributes (\r
-                            AtapiScsiPrivate->PciIo,\r
-                            EfiPciIoAttributeOperationDisable,\r
-                            EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO | EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO | EFI_PCI_DEVICE_ENABLE,\r
-                            NULL\r
-                            );\r
-\r
-  gBS->CloseProtocol (\r
-        Controller,\r
-        &gEfiPciIoProtocolGuid,\r
-        This->DriverBindingHandle,\r
-        Controller\r
-        );\r
-\r
-  gBS->FreePool (AtapiScsiPrivate);\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Attaches SCSI Pass Thru Protocol for specified IDE channel.\r
-\r
-  @param Controller:       Parent device handle to the IDE channel.\r
-  @param PciIo:            PCI I/O protocol attached on the "Controller".\r
-\r
-  @return EFI_SUCCESS Always returned unless installing SCSI Pass Thru Protocol failed.\r
-\r
-  @todo    This - add argument and description to function comment\r
-  @todo    Controller - add argument and description to function comment\r
-  @todo    PciIo - add argument and description to function comment\r
-  @todo    EFI_OUT_OF_RESOURCES - add return value to function comment\r
-**/\r
-EFI_STATUS\r
-RegisterAtapiScsiPassThru (\r
-  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
-  IN  EFI_HANDLE                  Controller,\r
-  IN  EFI_PCI_IO_PROTOCOL         *PciIo\r
-  )\r
-{\r
-  EFI_STATUS                Status;\r
-  ATAPI_SCSI_PASS_THRU_DEV  *AtapiScsiPrivate;\r
-  UINT64                    Attributes;\r
-\r
-  AtapiScsiPrivate = AllocateZeroPool (sizeof (ATAPI_SCSI_PASS_THRU_DEV));\r
-  if (AtapiScsiPrivate == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  Attributes = EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO | EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO | EFI_PCI_DEVICE_ENABLE;\r
-  CopyMem (AtapiScsiPrivate->ChannelName, gAtapiChannelString, sizeof (gAtapiChannelString));\r
-\r
-  //\r
-  // Enable channel\r
-  //\r
-  PciIo->Attributes (PciIo, EfiPciIoAttributeOperationSet, Attributes, NULL);\r
-\r
-  AtapiScsiPrivate->Signature = ATAPI_SCSI_PASS_THRU_DEV_SIGNATURE;\r
-  AtapiScsiPrivate->Handle    = Controller;\r
-\r
-  //\r
-  // will reset the IoPort inside each API function.\r
-  //\r
-  AtapiScsiPrivate->IoPort  = gAtapiIoPortRegisters;\r
-  AtapiScsiPrivate->PciIo   = PciIo;\r
-\r
-  //\r
-  // initialize SCSI Pass Thru Protocol interface\r
-  //\r
-  AtapiScsiPrivate->ScsiPassThru.Mode             = &AtapiScsiPrivate->ScsiPassThruMode;\r
-  AtapiScsiPrivate->ScsiPassThru.PassThru         = AtapiScsiPassThruFunction;\r
-  AtapiScsiPrivate->ScsiPassThru.GetNextDevice    = AtapiScsiPassThruGetNextDevice;\r
-  AtapiScsiPrivate->ScsiPassThru.BuildDevicePath  = AtapiScsiPassThruBuildDevicePath;\r
-  AtapiScsiPrivate->ScsiPassThru.GetTargetLun     = AtapiScsiPassThruGetTargetLun;\r
-  AtapiScsiPrivate->ScsiPassThru.ResetChannel     = AtapiScsiPassThruResetChannel;\r
-  AtapiScsiPrivate->ScsiPassThru.ResetTarget      = AtapiScsiPassThruResetTarget;\r
-\r
-  //\r
-  // Set Mode\r
-  //\r
-  CopyMem (AtapiScsiPrivate->ControllerName, gControllerNameString, sizeof (gControllerNameString));\r
-\r
-  AtapiScsiPrivate->ScsiPassThruMode.ControllerName = AtapiScsiPrivate->ControllerName;\r
-  AtapiScsiPrivate->ScsiPassThruMode.ChannelName    = AtapiScsiPrivate->ChannelName;\r
-  AtapiScsiPrivate->ScsiPassThruMode.AdapterId      = 4;\r
-  //\r
-  // non-RAID SCSI controllers should set both physical and logical attributes\r
-  //\r
-  AtapiScsiPrivate->ScsiPassThruMode.Attributes = EFI_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL | \r
-                                                  EFI_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL;\r
-  AtapiScsiPrivate->ScsiPassThruMode.IoAlign = 0;\r
-\r
-  //\r
-  // Initialize the LatestTargetId to 0xFFFFFFFF (for the GetNextDevice() call).\r
-  //\r
-  AtapiScsiPrivate->LatestTargetId  = 0xFFFFFFFF;\r
-  AtapiScsiPrivate->LatestLun       = 0;\r
-\r
-  Status = gBS->InstallProtocolInterface (\r
-                  &Controller,\r
-                  &gEfiScsiPassThruProtocolGuid,\r
-                  EFI_NATIVE_INTERFACE,\r
-                  &AtapiScsiPrivate->ScsiPassThru\r
-                  );\r
-  return Status;\r
-}\r
-\r
-/**\r
-  Implements EFI_SCSI_PASS_THRU_PROTOCOL.PassThru() function.\r
-\r
-  @param This     The EFI_SCSI_PASS_THRU_PROTOCOL instance.\r
-  @param Target   The Target ID of the ATAPI device to send the SCSI\r
-  Request Packet. To ATAPI devices attached on an IDE\r
-  Channel, Target ID 0 indicates Master device;Target\r
-  ID 1 indicates Slave device.\r
-  @param Lun      The LUN of the ATAPI device to send the SCSI Request\r
-  Packet. To the ATAPI device, Lun is always 0.\r
-  @param Packet   The SCSI Request Packet to send to the ATAPI device\r
-  specified by Target and Lun.\r
-  @param Event    If non-blocking I/O is not supported then Event is ignored,\r
-  and blocking I/O is performed.<br>\r
-  If Event is NULL, then blocking I/O is performed.<br>\r
-  If Event is not NULL and non blocking I/O is supported,\r
-  then non-blocking I/O is performed, and Event will be signaled\r
-  when the SCSI Request Packet completes.\r
-\r
-  @todo    This - add argument and description to function comment\r
-  @todo    EFI_INVALID_PARAMETER - add return value to function comment\r
-  @todo    EFI_SUCCESS - add return value to function comment\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruFunction (\r
-  IN EFI_SCSI_PASS_THRU_PROTOCOL                        *This,\r
-  IN UINT32                                             Target,\r
-  IN UINT64                                             Lun,\r
-  IN OUT EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET         *Packet,\r
-  IN EFI_EVENT                                          Event OPTIONAL\r
-  )\r
-{\r
-  ATAPI_SCSI_PASS_THRU_DEV  *AtapiScsiPrivate;\r
-  EFI_STATUS                Status;\r
-\r
-  AtapiScsiPrivate = ATAPI_SCSI_PASS_THRU_DEV_FROM_THIS (This);\r
-\r
-  //\r
-  // Target is not allowed beyond MAX_TARGET_ID\r
-  //\r
-  if (Target > MAX_TARGET_ID) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  \r
-  //\r
-  // check the data fields in Packet parameter.\r
-  //\r
-  Status = CheckSCSIRequestPacket (Packet);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  // If Request Packet targets at the IDE channel itself,\r
-  // do nothing.\r
-  //\r
-  if (Target == This->Mode->AdapterId) {\r
-    Packet->TransferLength = 0;\r
-    return EFI_SUCCESS;\r
-  }\r
-  \r
-  //\r
-  // According to Target ID, reset the Atapi I/O Register mapping\r
-  // (Target Id in [0,1] area, using gAtapiIoPortRegisters[0],\r
-  //  Target Id in [2,3] area, using gAtapiIoPortRegisters[1]\r
-  //\r
-  if ((Target / 2) == 0) {\r
-    AtapiScsiPrivate->IoPort = &gAtapiIoPortRegisters[0];\r
-  } else {\r
-    AtapiScsiPrivate->IoPort = &gAtapiIoPortRegisters[1];\r
-  }\r
-  \r
-  //\r
-  // the ATAPI SCSI interface does not support non-blocking I/O\r
-  // ignore the Event parameter\r
-  //\r
-  // Performs blocking I/O.\r
-  //\r
-  Status = SubmitBlockingIoCommand (AtapiScsiPrivate, Target, Packet);\r
-  return Status;\r
-}\r
-\r
-/**\r
-  Used to retrieve the list of legal Target IDs for SCSI devices \r
-  on a SCSI channel.\r
-\r
-  @param  This Protocol instance pointer.\r
-  @param  Target On input, a pointer to the Target ID of a SCSI\r
-  device present on the SCSI channel.  On output,\r
-  a pointer to the Target ID of the next SCSI device\r
-  present on a SCSI channel.  An input value of\r
-  0xFFFFFFFF retrieves the Target ID of the first\r
-  SCSI device present on a SCSI channel.\r
-  @param  Lun On input, a pointer to the LUN of a SCSI device\r
-  present on the SCSI channel. On output, a pointer\r
-  to the LUN of the next SCSI device present on\r
-  a SCSI channel.\r
-\r
-  @retval  EFI_SUCCESS The Target ID and Lun of the next SCSI device\r
-  on the SCSI channel was returned in Target and Lun.\r
-  @retval  EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.\r
-  @retval  EFI_INVALID_PARAMETER Target is not 0xFFFFFFFF,and Target and Lun were not\r
-  returned on a previous call to GetNextDevice().\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruGetNextDevice (\r
-  IN  EFI_SCSI_PASS_THRU_PROTOCOL    *This,\r
-  IN OUT UINT32                      *Target,\r
-  IN OUT UINT64                      *Lun\r
-  )\r
-{\r
-  ATAPI_SCSI_PASS_THRU_DEV  *AtapiScsiPrivate;\r
-\r
-  //\r
-  // Retrieve Device Private Data Structure.\r
-  //\r
-  AtapiScsiPrivate = ATAPI_SCSI_PASS_THRU_DEV_FROM_THIS (This);\r
-\r
-  //\r
-  // Check whether Target is valid.\r
-  //\r
-  if (Target == NULL || Lun == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  if ((*Target != 0xFFFFFFFF) &&\r
-      ((*Target != AtapiScsiPrivate->LatestTargetId) ||\r
-      (*Lun != AtapiScsiPrivate->LatestLun))) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  if (*Target == MAX_TARGET_ID) {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-\r
-  if (*Target == 0xFFFFFFFF) {\r
-    *Target = 0;\r
-  } else {\r
-    *Target = AtapiScsiPrivate->LatestTargetId + 1;\r
-  }\r
-\r
-  *Lun = 0;\r
-\r
-  //\r
-  // Update the LatestTargetId.\r
-  //\r
-  AtapiScsiPrivate->LatestTargetId  = *Target;\r
-  AtapiScsiPrivate->LatestLun       = *Lun;\r
-\r
-  return EFI_SUCCESS;\r
-\r
-}\r
-\r
-/**\r
-  Used to allocate and build a device path node for a SCSI device \r
-  on a SCSI channel. Would not build device path for a SCSI Host Controller.\r
-\r
-  @param  This Protocol instance pointer.\r
-  @param  Target The Target ID of the SCSI device for which\r
-  a device path node is to be allocated and built.\r
-  @param  Lun The LUN of the SCSI device for which a device\r
-  path node is to be allocated and built.\r
-  @param  DevicePath A pointer to a single device path node that\r
-  describes the SCSI device specified by\r
-  Target and Lun. This function is responsible\r
-  for allocating the buffer DevicePath with the boot\r
-  service AllocatePool().  It is the caller's\r
-  responsibility to free DevicePath when the caller\r
-  is finished with DevicePath.\r
-\r
-  @retval  EFI_SUCCESS The device path node that describes the SCSI device\r
-  specified by Target and Lun was allocated and\r
-  returned in DevicePath.\r
-  @retval  EFI_NOT_FOUND The SCSI devices specified by Target and Lun does\r
-  not exist on the SCSI channel.\r
-  @retval  EFI_INVALID_PARAMETER DevicePath is NULL.\r
-  @retval  EFI_OUT_OF_RESOURCES There are not enough resources to allocate\r
-  DevicePath.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruBuildDevicePath (\r
-  IN     EFI_SCSI_PASS_THRU_PROTOCOL    *This,\r
-  IN     UINT32                         Target,\r
-  IN     UINT64                         Lun,\r
-  IN OUT EFI_DEVICE_PATH_PROTOCOL       **DevicePath\r
-  )\r
-{\r
-  EFI_DEV_PATH              *Node;\r
-\r
-  //\r
-  // Validate parameters passed in.\r
-  //\r
-  \r
-  if (DevicePath == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  \r
-  //\r
-  // can not build device path for the SCSI Host Controller.\r
-  //\r
-  if ((Target > (MAX_TARGET_ID - 1)) || (Lun != 0)) {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-\r
-  Node = AllocateZeroPool (sizeof (EFI_DEV_PATH));\r
-  if (Node == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  Node->DevPath.Type    = MESSAGING_DEVICE_PATH;\r
-  Node->DevPath.SubType = MSG_ATAPI_DP;\r
-  SetDevicePathNodeLength (&Node->DevPath, sizeof (ATAPI_DEVICE_PATH));\r
-\r
-  Node->Atapi.PrimarySecondary  = (UINT8) (Target / 2);\r
-  Node->Atapi.SlaveMaster       = (UINT8) (Target % 2);\r
-  Node->Atapi.Lun               = (UINT16) Lun;\r
-\r
-  *DevicePath                   = (EFI_DEVICE_PATH_PROTOCOL *) Node;\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Used to translate a device path node to a Target ID and LUN.\r
-\r
-  @param  This Protocol instance pointer.\r
-  @param  DevicePath A pointer to the device path node that\r
-  describes a SCSI device on the SCSI channel.\r
-  @param  Target A pointer to the Target ID of a SCSI device\r
-  on the SCSI channel.\r
-  @param  Lun A pointer to the LUN of a SCSI device on\r
-  the SCSI channel.\r
-\r
-  @retval  EFI_SUCCESS DevicePath was successfully translated to a\r
-  Target ID and LUN, and they were returned\r
-  in Target and Lun.\r
-  @retval  EFI_INVALID_PARAMETER DevicePath is NULL.\r
-  @retval  EFI_INVALID_PARAMETER Target is NULL.\r
-  @retval  EFI_INVALID_PARAMETER Lun is NULL.\r
-  @retval  EFI_UNSUPPORTED This driver does not support the device path\r
-  node type in DevicePath.\r
-  @retval  EFI_NOT_FOUND A valid translation from DevicePath to a\r
-  Target ID and LUN does not exist.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruGetTargetLun (\r
-  IN  EFI_SCSI_PASS_THRU_PROTOCOL    *This,\r
-  IN  EFI_DEVICE_PATH_PROTOCOL       *DevicePath,\r
-  OUT UINT32                         *Target,\r
-  OUT UINT64                         *Lun\r
-  )\r
-{\r
-  EFI_DEV_PATH  *Node;\r
-\r
-  //\r
-  // Validate parameters passed in.\r
-  //\r
-  if (DevicePath == NULL || Target == NULL || Lun == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  \r
-  //\r
-  // Check whether the DevicePath belongs to SCSI_DEVICE_PATH\r
-  //\r
-  if ((DevicePath->Type != MESSAGING_DEVICE_PATH) ||\r
-      (DevicePath->SubType != MSG_ATAPI_DP) ||\r
-      (DevicePathNodeLength(DevicePath) != sizeof(ATAPI_DEVICE_PATH))) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  Node    = (EFI_DEV_PATH *) DevicePath;\r
-\r
-  *Target = Node->Atapi.PrimarySecondary * 2 + Node->Atapi.SlaveMaster;\r
-  *Lun    = Node->Atapi.Lun;\r
-\r
-  if (*Target > (MAX_TARGET_ID - 1) || *Lun != 0) {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Resets a SCSI channel.This operation resets all the \r
-  SCSI devices connected to the SCSI channel.\r
-\r
-  @param  This Protocol instance pointer.\r
-\r
-  @retval  EFI_SUCCESS The SCSI channel was reset.\r
-  @retval  EFI_UNSUPPORTED The SCSI channel does not support\r
-  a channel reset operation.\r
-  @retval  EFI_DEVICE_ERROR A device error occurred while\r
-  attempting to reset the SCSI channel.\r
-  @retval  EFI_TIMEOUT A timeout occurred while attempting\r
-  to reset the SCSI channel.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruResetChannel (\r
-  IN  EFI_SCSI_PASS_THRU_PROTOCOL   *This\r
-  )\r
-{\r
-  UINT8                     DeviceControlValue;\r
-  ATAPI_SCSI_PASS_THRU_DEV  *AtapiScsiPrivate;\r
-  UINT8                     Index;\r
-\r
-  AtapiScsiPrivate = ATAPI_SCSI_PASS_THRU_DEV_FROM_THIS (This);\r
-\r
-  //\r
-  // Reset both Primary channel and Secondary channel.\r
-  // so, the IoPort pointer must point to the right I/O Register group\r
-  //\r
-  for (Index = 0; Index < 2; Index++) {\r
-    //\r
-    // Reset\r
-    //\r
-    AtapiScsiPrivate->IoPort  = &gAtapiIoPortRegisters[Index];\r
-\r
-    DeviceControlValue        = 0;\r
-    //\r
-    // set SRST bit to initiate soft reset\r
-    //\r
-    DeviceControlValue |= SRST;\r
-    //\r
-    // disable Interrupt\r
-    //\r
-    DeviceControlValue |= bit (1);\r
-    WritePortB (\r
-      AtapiScsiPrivate->PciIo,\r
-      AtapiScsiPrivate->IoPort->Alt.DeviceControl,\r
-      DeviceControlValue\r
-      );\r
-\r
-    //\r
-    // Wait 10us\r
-    //\r
-    gBS->Stall (10);\r
-\r
-    //\r
-    // Clear SRST bit\r
-    // 0xfb:1111,1011\r
-    //\r
-    DeviceControlValue &= 0xfb;\r
-    \r
-    WritePortB (AtapiScsiPrivate->PciIo, AtapiScsiPrivate->IoPort->Alt.DeviceControl, DeviceControlValue);\r
-\r
-    //\r
-    // slave device needs at most 31s to clear BSY\r
-    //\r
-    if (StatusWaitForBSYClear (AtapiScsiPrivate, 31000) == EFI_TIMEOUT) {\r
-      return EFI_DEVICE_ERROR;\r
-    }\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Resets a SCSI device that is connected to a SCSI channel.\r
-\r
-  @param  This Protocol instance pointer.\r
-  @param  Target The Target ID of the SCSI device to reset.\r
-  @param  Lun The LUN of the SCSI device to reset.\r
-\r
-  @retval  EFI_SUCCESS The SCSI device specified by Target and\r
-  Lun was reset.\r
-  @retval  EFI_UNSUPPORTED The SCSI channel does not support a target\r
-  reset operation.\r
-  @retval  EFI_INVALID_PARAMETER Target or Lun are invalid.\r
-  @retval  EFI_DEVICE_ERROR A device error occurred while attempting\r
-  to reset the SCSI device specified by Target\r
-  and Lun.\r
-  @retval  EFI_TIMEOUT A timeout occurred while attempting to reset\r
-  the SCSI device specified by Target and Lun.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruResetTarget (\r
-  IN EFI_SCSI_PASS_THRU_PROTOCOL    *This,\r
-  IN UINT32                         Target,\r
-  IN UINT64                         Lun\r
-  )\r
-{\r
-  ATAPI_SCSI_PASS_THRU_DEV  *AtapiScsiPrivate;\r
-  UINT8                     Command;\r
-  UINT8                     DeviceSelect;\r
-\r
-  AtapiScsiPrivate = ATAPI_SCSI_PASS_THRU_DEV_FROM_THIS (This);\r
-\r
-  if (Target > MAX_TARGET_ID) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  //\r
-  // Directly return EFI_SUCCESS if want to reset the host controller\r
-  //\r
-  if (Target == This->Mode->AdapterId) {\r
-    return EFI_SUCCESS;\r
-  }\r
-  \r
-  //\r
-  // According to Target ID, reset the Atapi I/O Register mapping\r
-  // (Target Id in [0,1] area, using gAtapiIoPortRegisters[0],\r
-  //  Target Id in [2,3] area, using gAtapiIoPortRegisters[1]\r
-  //\r
-  if ((Target / 2) == 0) {\r
-    AtapiScsiPrivate->IoPort = &gAtapiIoPortRegisters[0];\r
-  } else {\r
-    AtapiScsiPrivate->IoPort = &gAtapiIoPortRegisters[1];\r
-  }\r
-  \r
-  //\r
-  // for ATAPI device, no need to wait DRDY ready after device selecting.\r
-  //\r
-  // bit7 and bit5 are both set to 1 for backward compatibility\r
-  //\r
-  DeviceSelect = (UINT8) (((bit (7) | bit (5)) | (Target << 4)));\r
-  WritePortB (AtapiScsiPrivate->PciIo, AtapiScsiPrivate->IoPort->Head, DeviceSelect);\r
-\r
-  Command = ATAPI_SOFT_RESET_CMD;\r
-  WritePortB (AtapiScsiPrivate->PciIo, AtapiScsiPrivate->IoPort->Reg.Command, Command);\r
-\r
-  //\r
-  // BSY clear is the only status return to the host by the device\r
-  // when reset is complete.\r
-  // slave device needs at most 31s to clear BSY\r
-  //\r
-  if (EFI_ERROR (StatusWaitForBSYClear (AtapiScsiPrivate, 31000))) {\r
-    return EFI_DEVICE_ERROR;\r
-  }\r
-  \r
-  //\r
-  // stall 5 seconds to make the device status stable\r
-  //\r
-  gBS->Stall (5000000);\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-    \r
-/**\r
-  Checks the parameters in the SCSI Request Packet to make sure\r
-  they are valid for a SCSI Pass Thru request.\r
-\r
-  @todo function comment is missing 'Routine Description:'\r
-  @todo function comment is missing 'Arguments:'\r
-  @todo function comment is missing 'Returns:'\r
-  @todo    Packet - add argument and description to function comment\r
-  @todo    EFI_INVALID_PARAMETER - add return value to function comment\r
-  @todo    EFI_INVALID_PARAMETER - add return value to function comment\r
-  @todo    EFI_INVALID_PARAMETER - add return value to function comment\r
-  @todo    EFI_UNSUPPORTED - add return value to function comment\r
-  @todo    EFI_SUCCESS - add return value to function comment\r
-**/\r
-EFI_STATUS\r
-CheckSCSIRequestPacket (\r
-  EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET      *Packet\r
-  )\r
-{\r
-  if (Packet == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  if (!ValidCdbLength (Packet->CdbLength)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  if (Packet->Cdb == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  \r
-  //\r
-  // Checks whether the request command is supported.\r
-  //\r
-  if (!IsCommandValid (Packet)) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Checks the requested SCSI command: \r
-  Is it supported by this driver?\r
-  Is the Data transfer direction reasonable?\r
-\r
-  @todo function comment is missing 'Routine Description:'\r
-  @todo function comment is missing 'Arguments:'\r
-  @todo function comment is missing 'Returns:'\r
-  @todo    Packet - add argument and description to function comment\r
-**/\r
-BOOLEAN\r
-IsCommandValid (\r
-  EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET   *Packet\r
-  )\r
-{\r
-  UINT8 Index;\r
-  UINT8 *OpCode;\r
-\r
-  OpCode = (UINT8 *) (Packet->Cdb);\r
-\r
-  for (Index = 0; CompareMem (&gSupportedATAPICommands[Index], &gEndTable, sizeof (SCSI_COMMAND_SET)); Index++) {\r
-\r
-    if (*OpCode == gSupportedATAPICommands[Index].OpCode) {\r
-      //\r
-      // Check whether the requested Command is supported by this driver\r
-      //\r
-      if (Packet->DataDirection == DataIn) {\r
-        //\r
-        // Check whether the requested data direction conforms to\r
-        // what it should be.\r
-        //\r
-        if (gSupportedATAPICommands[Index].Direction == DataOut) {\r
-          return FALSE;\r
-        }\r
-      }\r
-\r
-      if (Packet->DataDirection == DataOut) {\r
-        //\r
-        // Check whether the requested data direction conforms to\r
-        // what it should be.\r
-        //\r
-        if (gSupportedATAPICommands[Index].Direction == DataIn) {\r
-          return FALSE;\r
-        }\r
-      }\r
-\r
-      return TRUE;\r
-    }\r
-  }\r
-\r
-  return FALSE;\r
-}\r
-\r
-/**\r
-  Performs blocking I/O request.\r
-\r
-  @param AtapiScsiPrivate   Private data structure for the specified channel.\r
-  @param Target             The Target ID of the ATAPI device to send the SCSI\r
-  Request Packet. To ATAPI devices attached on an IDE\r
-  Channel, Target ID 0 indicates Master device;Target\r
-  ID 1 indicates Slave device.\r
-  @param Packet             The SCSI Request Packet to send to the ATAPI device\r
-  specified by Target.\r
-\r
-  @todo    AtapiScsiPrivate - add argument and description to function comment\r
-**/\r
-EFI_STATUS\r
-SubmitBlockingIoCommand (\r
-  ATAPI_SCSI_PASS_THRU_DEV                  *AtapiScsiPrivate,\r
-  UINT32                                    Target,\r
-  EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET    *Packet\r
-  )\r
-{\r
-  UINT8       PacketCommand[12];\r
-  UINT64      TimeoutInMicroSeconds;\r
-  EFI_STATUS  PacketCommandStatus;\r
-\r
-  //\r
-  // Fill ATAPI Command Packet according to CDB\r
-  //\r
-  ZeroMem (&PacketCommand, 12);\r
-  CopyMem (&PacketCommand, Packet->Cdb, Packet->CdbLength);\r
-\r
-  //\r
-  // Timeout is 100ns unit, convert it to 1000ns (1us) unit.\r
-  //\r
-  TimeoutInMicroSeconds = DivU64x32 (Packet->Timeout, (UINT32) 10);\r
-\r
-  //\r
-  // Submit ATAPI Command Packet\r
-  //\r
-  PacketCommandStatus = AtapiPacketCommand (\r
-                          AtapiScsiPrivate,\r
-                          Target,\r
-                          PacketCommand,\r
-                          Packet->DataBuffer,\r
-                          &(Packet->TransferLength),\r
-                          (DATA_DIRECTION) Packet->DataDirection,\r
-                          TimeoutInMicroSeconds\r
-                          );\r
-  if (!EFI_ERROR (PacketCommandStatus) || (Packet->SenseData == NULL)) {\r
-    Packet->SenseDataLength = 0;\r
-    return PacketCommandStatus;\r
-  }\r
-  //\r
-  // Return SenseData if PacketCommandStatus matches\r
-  // the following return codes.\r
-  //\r
-  if ((PacketCommandStatus == EFI_WARN_BUFFER_TOO_SMALL) ||\r
-      (PacketCommandStatus == EFI_DEVICE_ERROR) ||\r
-      (PacketCommandStatus == EFI_TIMEOUT)) {\r
-    \r
-    //\r
-    // avoid submit request sense command continuously.\r
-    //\r
-    if (PacketCommand[0] == OP_REQUEST_SENSE) {\r
-      Packet->SenseDataLength = 0;\r
-      return PacketCommandStatus;\r
-    }\r
-\r
-    RequestSenseCommand (\r
-      AtapiScsiPrivate,\r
-      Target,\r
-      Packet->Timeout,\r
-      Packet->SenseData,\r
-      &Packet->SenseDataLength\r
-      );\r
-  }\r
-\r
-  return PacketCommandStatus;\r
-}\r
-\r
-/**\r
-  RequestSenseCommand\r
-\r
-  @param  AtapiScsiPrivate\r
-  @param  Target\r
-  @param  Timeout\r
-  @param  SenseData\r
-  @param  SenseDataLength\r
-\r
-  @todo Add function description\r
-  @todo  AtapiScsiPrivate TODO: add argument description\r
-  @todo  Target TODO: add argument description\r
-  @todo  Timeout TODO: add argument description\r
-  @todo  SenseData TODO: add argument description\r
-  @todo  SenseDataLength TODO: add argument description\r
-  @todo add return values\r
-**/\r
-EFI_STATUS\r
-RequestSenseCommand (\r
-  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate,\r
-  UINT32                      Target,\r
-  UINT64                      Timeout,\r
-  VOID                        *SenseData,\r
-  UINT8                       *SenseDataLength\r
-  )\r
-{\r
-  EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET  Packet;\r
-  UINT8                                   Cdb[12];\r
-  EFI_STATUS                              Status;\r
-\r
-  ZeroMem (&Packet, sizeof (EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET));\r
-  ZeroMem (Cdb, 12);\r
-\r
-  Cdb[0]                = OP_REQUEST_SENSE;\r
-  Cdb[4]                = (UINT8) (*SenseDataLength);\r
-\r
-  Packet.Timeout        = Timeout;\r
-  Packet.DataBuffer     = SenseData;\r
-  Packet.SenseData      = NULL;\r
-  Packet.Cdb            = Cdb;\r
-  Packet.TransferLength = *SenseDataLength;\r
-  Packet.CdbLength      = 12;\r
-  Packet.DataDirection  = DataIn;\r
-\r
-  Status                = SubmitBlockingIoCommand (AtapiScsiPrivate, Target, &Packet);\r
-  *SenseDataLength      = (UINT8) (Packet.TransferLength);\r
-  return Status;\r
-}\r
-\r
-/**\r
-  Submits ATAPI command packet to the specified ATAPI device.\r
-\r
-  @param AtapiScsiPrivate:   Private data structure for the specified channel.\r
-  @param Target:             The Target ID of the ATAPI device to send the SCSI\r
-  Request Packet. To ATAPI devices attached on an IDE\r
-  Channel, Target ID 0 indicates Master device;Target\r
-  ID 1 indicates Slave device.\r
-  @param PacketCommand:      Points to the ATAPI command packet.\r
-  @param Buffer:             Points to the transferred data.\r
-  @param ByteCount:          When input,indicates the buffer size; when output,\r
-  indicates the actually transferred data size.\r
-  @param Direction:          Indicates the data transfer direction.\r
-  @param TimeoutInMicroSeconds: The timeout, in micro second units,\r
-  to use for the execution of this ATAPI command.\r
-  A TimeoutInMicroSeconds value of 0 means that\r
-  this function will wait indefinitely for the ATAPI\r
-  command to execute.\r
-  <P>\r
-  If TimeoutInMicroSeconds is greater than zero, then\r
-  this function will return EFI_TIMEOUT if the time\r
-  required to execute the ATAPI command is greater\r
-  than TimeoutInMicroSeconds.\r
-  </P>\r
-\r
-  @todo    AtapiScsiPrivate - add argument and description to function comment\r
-  @todo    PacketCommand - add argument and description to function comment\r
-  @todo    Buffer - add argument and description to function comment\r
-  @todo    ByteCount - add argument and description to function comment\r
-  @todo    Direction - add argument and description to function comment\r
-**/\r
-EFI_STATUS\r
-AtapiPacketCommand (\r
-  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate,\r
-  UINT32                      Target,\r
-  UINT8                       *PacketCommand,\r
-  VOID                        *Buffer,\r
-  UINT32                      *ByteCount,\r
-  DATA_DIRECTION              Direction,\r
-  UINT64                      TimeoutInMicroSeconds\r
-  )\r
-{\r
-\r
-  UINT16      *CommandIndex;\r
-  UINT8       Count;\r
-  EFI_STATUS  Status;\r
-\r
-  //\r
-  // Set all the command parameters by fill related registers.\r
-  // Before write to all the following registers, BSY and DRQ must be 0.\r
-  //\r
-  Status = StatusDRQClear (AtapiScsiPrivate, TimeoutInMicroSeconds);\r
-  if (EFI_ERROR (Status)) {\r
-    if (Status == EFI_ABORTED) {\r
-      Status = EFI_DEVICE_ERROR;\r
-    }\r
-\r
-    *ByteCount = 0;\r
-    return Status;\r
-  }\r
-  //\r
-  // Select device via Device/Head Register.\r
-  // "Target = 0" indicates device 0; "Target = 1" indicates device 1\r
-  //\r
-  WritePortB (\r
-    AtapiScsiPrivate->PciIo,\r
-    AtapiScsiPrivate->IoPort->Head,\r
-    (UINT8) ((Target << 4) | DEFAULT_CMD) // DEFAULT_CMD: 0xa0 (1010,0000)\r
-    );\r
-\r
-  //\r
-  // No OVL; No DMA (by setting feature register)\r
-  //\r
-  WritePortB (\r
-    AtapiScsiPrivate->PciIo,\r
-    AtapiScsiPrivate->IoPort->Reg1.Feature,\r
-    0x00\r
-    );\r
-\r
-  //\r
-  // set the transfersize to MAX_ATAPI_BYTE_COUNT to let the device\r
-  // determine how much data should be transfered.\r
-  //\r
-  WritePortB (\r
-    AtapiScsiPrivate->PciIo,\r
-    AtapiScsiPrivate->IoPort->CylinderLsb,\r
-    (UINT8) (MAX_ATAPI_BYTE_COUNT & 0x00ff)\r
-    );\r
-  WritePortB (\r
-    AtapiScsiPrivate->PciIo,\r
-    AtapiScsiPrivate->IoPort->CylinderMsb,\r
-    (UINT8) (MAX_ATAPI_BYTE_COUNT >> 8)\r
-    );\r
-\r
-  //\r
-  //  DEFAULT_CTL:0x0a (0000,1010)\r
-  //  Disable interrupt\r
-  //\r
-  WritePortB (\r
-    AtapiScsiPrivate->PciIo,\r
-    AtapiScsiPrivate->IoPort->Alt.DeviceControl,\r
-    DEFAULT_CTL\r
-    );\r
-\r
-  //\r
-  // Send Packet command to inform device\r
-  // that the following data bytes are command packet.\r
-  //\r
-  WritePortB (\r
-    AtapiScsiPrivate->PciIo,\r
-    AtapiScsiPrivate->IoPort->Reg.Command,\r
-    PACKET_CMD\r
-    );\r
-\r
-  //\r
-  // Before data transfer, BSY should be 0 and DRQ should be 1.\r
-  // if they are not in specified time frame,\r
-  // retrieve Sense Key from Error Register before return.\r
-  //\r
-  Status = StatusDRQReady (AtapiScsiPrivate, TimeoutInMicroSeconds);\r
-  if (EFI_ERROR (Status)) {\r
-    if (Status == EFI_ABORTED) {\r
-      Status = EFI_DEVICE_ERROR;\r
-    }\r
-\r
-    *ByteCount = 0;\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  // Send out command packet\r
-  //\r
-  CommandIndex = (UINT16 *) PacketCommand;\r
-  for (Count = 0; Count < 6; Count++, CommandIndex++) {\r
-    WritePortW (AtapiScsiPrivate->PciIo, AtapiScsiPrivate->IoPort->Data, *CommandIndex);\r
-  }\r
-\r
-  //\r
-  // call AtapiPassThruPioReadWriteData() function to get\r
-  // requested transfer data form device.\r
-  //\r
-  return AtapiPassThruPioReadWriteData (\r
-          AtapiScsiPrivate,\r
-          Buffer,\r
-          ByteCount,\r
-          Direction,\r
-          TimeoutInMicroSeconds\r
-          );\r
-}\r
-\r
-/**\r
-  Performs data transfer between ATAPI device and host after the\r
-  ATAPI command packet is sent.\r
-\r
-  @param AtapiScsiPrivate:   Private data structure for the specified channel.\r
-  @param Buffer:             Points to the transferred data.\r
-  @param ByteCount:          When input,indicates the buffer size; when output,\r
-  indicates the actually transferred data size.\r
-  @param Direction:          Indicates the data transfer direction.\r
-  @param TimeoutInMicroSeconds: The timeout, in micro second units,\r
-  to use for the execution of this ATAPI command.\r
-  A TimeoutInMicroSeconds value of 0 means that\r
-  this function will wait indefinitely for the ATAPI\r
-  command to execute.\r
-  <P>\r
-  If TimeoutInMicroSeconds is greater than zero, then\r
-  this function will return EFI_TIMEOUT if the time\r
-  required to execute the ATAPI command is greater\r
-  than TimeoutInMicroSeconds.\r
-  </P>\r
-\r
-  @todo    AtapiScsiPrivate - add argument and description to function comment\r
-  @todo    Buffer - add argument and description to function comment\r
-  @todo    ByteCount - add argument and description to function comment\r
-  @todo    Direction - add argument and description to function comment\r
-  @todo    EFI_DEVICE_ERROR - add return value to function comment\r
-  @todo    EFI_DEVICE_ERROR - add return value to function comment\r
-  @todo    EFI_WARN_BUFFER_TOO_SMALL - add return value to function comment\r
-**/\r
-EFI_STATUS\r
-AtapiPassThruPioReadWriteData (\r
-  ATAPI_SCSI_PASS_THRU_DEV  *AtapiScsiPrivate,\r
-  UINT16                    *Buffer,\r
-  UINT32                    *ByteCount,\r
-  DATA_DIRECTION            Direction,\r
-  UINT64                    TimeoutInMicroSeconds\r
-  )\r
-{\r
-  UINT32      Index;\r
-  UINT32      RequiredWordCount;\r
-  UINT32      ActualWordCount;\r
-\r
-  UINT32      WordCount;\r
-  EFI_STATUS  Status;\r
-  UINT16      *ptrBuffer;\r
-\r
-  Status = EFI_SUCCESS;\r
-\r
-  //\r
-  // Non Data transfer request is also supported.\r
-  //\r
-  if (*ByteCount == 0 || Buffer == NULL) {\r
-    *ByteCount = 0;\r
-    if (EFI_ERROR (StatusWaitForBSYClear (AtapiScsiPrivate, TimeoutInMicroSeconds))) {\r
-      return EFI_DEVICE_ERROR;\r
-    }\r
-  }\r
-\r
-  ptrBuffer         = Buffer;\r
-  RequiredWordCount = *ByteCount / 2;\r
-\r
-  //\r
-  // ActuralWordCount means the word count of data really transfered.\r
-  //\r
-  ActualWordCount = 0;\r
-\r
-  while (ActualWordCount < RequiredWordCount) {\r
-    //\r
-    // before each data transfer stream, the host should poll DRQ bit ready,\r
-    // which indicates device's ready for data transfer .\r
-    //\r
-    Status = StatusDRQReady (AtapiScsiPrivate, TimeoutInMicroSeconds);\r
-    if (EFI_ERROR (Status)) {\r
-      *ByteCount = ActualWordCount * 2;\r
-\r
-      AtapiPassThruCheckErrorStatus (AtapiScsiPrivate);\r
-\r
-      if (ActualWordCount == 0) {\r
-        return EFI_DEVICE_ERROR;\r
-      }\r
-      //\r
-      // ActualWordCount > 0\r
-      //\r
-      if (ActualWordCount < RequiredWordCount) {\r
-        return EFI_WARN_BUFFER_TOO_SMALL;\r
-      }\r
-    }\r
-    //\r
-    // get current data transfer size from Cylinder Registers.\r
-    //\r
-    WordCount = ReadPortB (AtapiScsiPrivate->PciIo, AtapiScsiPrivate->IoPort->CylinderMsb) << 8;\r
-    WordCount = WordCount | ReadPortB (AtapiScsiPrivate->PciIo, AtapiScsiPrivate->IoPort->CylinderLsb);\r
-    WordCount = WordCount & 0xffff;\r
-    WordCount /= 2;\r
-\r
-    //\r
-    // perform a series data In/Out.\r
-    //\r
-    for (Index = 0; (Index < WordCount) && (ActualWordCount < RequiredWordCount); Index++, ActualWordCount++) {\r
-\r
-      if (Direction == DataIn) {\r
-\r
-        *ptrBuffer = ReadPortW (AtapiScsiPrivate->PciIo, AtapiScsiPrivate->IoPort->Data);\r
-      } else {\r
-\r
-        WritePortW (AtapiScsiPrivate->PciIo, AtapiScsiPrivate->IoPort->Data, *ptrBuffer);\r
-      }\r
-\r
-      ptrBuffer++;\r
-\r
-    }\r
-  }\r
-  //\r
-  // After data transfer is completed, normally, DRQ bit should clear.\r
-  //\r
-  StatusDRQClear (AtapiScsiPrivate, TimeoutInMicroSeconds);\r
-\r
-  //\r
-  // read status register to check whether error happens.\r
-  //\r
-  Status      = AtapiPassThruCheckErrorStatus (AtapiScsiPrivate);\r
-\r
-  *ByteCount  = ActualWordCount * 2;\r
-\r
-  return Status;\r
-}\r
-\r
-\r
-/**\r
-  Read one byte from a specified I/O port.\r
-\r
-  @todo function comment is missing 'Routine Description:'\r
-  @todo function comment is missing 'Arguments:'\r
-  @todo function comment is missing 'Returns:'\r
-  @todo    PciIo - add argument and description to function comment\r
-  @todo    Port - add argument and description to function comment\r
-**/\r
-UINT8\r
-ReadPortB (\r
-  IN  EFI_PCI_IO_PROTOCOL   *PciIo,\r
-  IN  UINT16                Port\r
-  )\r
-{\r
-  UINT8 Data;\r
-\r
-  Data = 0;\r
-  PciIo->Io.Read (\r
-              PciIo,\r
-              EfiPciIoWidthUint8,\r
-              EFI_PCI_IO_PASS_THROUGH_BAR,\r
-              (UINT64) Port,\r
-              1,\r
-              &Data\r
-              );\r
-  return Data;\r
-}\r
-\r
-\r
-/**\r
-  Read one word from a specified I/O port.\r
-\r
-  @todo function comment is missing 'Routine Description:'\r
-  @todo function comment is missing 'Arguments:'\r
-  @todo function comment is missing 'Returns:'\r
-  @todo    PciIo - add argument and description to function comment\r
-  @todo    Port - add argument and description to function comment\r
-**/\r
-UINT16\r
-ReadPortW (\r
-  IN  EFI_PCI_IO_PROTOCOL   *PciIo,\r
-  IN  UINT16                Port\r
-  )\r
-{\r
-  UINT16  Data;\r
-\r
-  Data = 0;\r
-  PciIo->Io.Read (\r
-              PciIo,\r
-              EfiPciIoWidthUint16,\r
-              EFI_PCI_IO_PASS_THROUGH_BAR,\r
-              (UINT64) Port,\r
-              1,\r
-              &Data\r
-              );\r
-  return Data;\r
-}\r
-\r
-\r
-/**\r
-  Write one byte to a specified I/O port.\r
-\r
-  @todo function comment is missing 'Routine Description:'\r
-  @todo function comment is missing 'Arguments:'\r
-  @todo function comment is missing 'Returns:'\r
-  @todo    PciIo - add argument and description to function comment\r
-  @todo    Port - add argument and description to function comment\r
-  @todo    Data - add argument and description to function comment\r
-**/\r
-VOID\r
-WritePortB (\r
-  IN  EFI_PCI_IO_PROTOCOL   *PciIo,\r
-  IN  UINT16                Port,\r
-  IN  UINT8                 Data\r
-  )\r
-{\r
-\r
-  PciIo->Io.Write (\r
-              PciIo,\r
-              EfiPciIoWidthUint8,\r
-              EFI_PCI_IO_PASS_THROUGH_BAR,\r
-              (UINT64) Port,\r
-              1,\r
-              &Data\r
-              );\r
-\r
-}\r
-\r
-\r
-/**\r
-  Write one word to a specified I/O port.\r
-\r
-  @todo function comment is missing 'Routine Description:'\r
-  @todo function comment is missing 'Arguments:'\r
-  @todo function comment is missing 'Returns:'\r
-  @todo    PciIo - add argument and description to function comment\r
-  @todo    Port - add argument and description to function comment\r
-  @todo    Data - add argument and description to function comment\r
-**/\r
-VOID\r
-WritePortW (\r
-  IN  EFI_PCI_IO_PROTOCOL   *PciIo,\r
-  IN  UINT16                Port,\r
-  IN  UINT16                Data\r
-  )\r
-{\r
-\r
-  PciIo->Io.Write (\r
-              PciIo,\r
-              EfiPciIoWidthUint16,\r
-              EFI_PCI_IO_PASS_THROUGH_BAR,\r
-              (UINT64) Port,\r
-              1,\r
-              &Data\r
-              );\r
-}\r
-\r
-/**\r
-  Check whether DRQ is clear in the Status Register. (BSY must also be cleared)\r
-  If TimeoutInMicroSeconds is zero, this routine should wait infinitely for\r
-  DRQ clear. Otherwise, it will return EFI_TIMEOUT when specified time is \r
-  elapsed.\r
-\r
-  @todo function comment is missing 'Routine Description:'\r
-  @todo function comment is missing 'Arguments:'\r
-  @todo function comment is missing 'Returns:'\r
-  @todo    AtapiScsiPrivate - add argument and description to function comment\r
-  @todo    TimeoutInMicroSeconds - add argument and description to function comment\r
-  @todo    EFI_ABORTED - add return value to function comment\r
-  @todo    EFI_TIMEOUT - add return value to function comment\r
-  @todo    EFI_SUCCESS - add return value to function comment\r
-**/\r
-EFI_STATUS\r
-StatusDRQClear (\r
-  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate,\r
-  UINT64                          TimeoutInMicroSeconds\r
-  )\r
-{\r
-  UINT64  Delay;\r
-  UINT8   StatusRegister;\r
-  UINT8   ErrRegister;\r
-\r
-  if (TimeoutInMicroSeconds == 0) {\r
-    Delay = 2;\r
-  } else {\r
-    Delay = DivU64x32 (TimeoutInMicroSeconds, (UINT32) 30) + 1;\r
-  }\r
-\r
-  do {\r
-\r
-    StatusRegister = ReadPortB (\r
-                      AtapiScsiPrivate->PciIo,\r
-                      AtapiScsiPrivate->IoPort->Reg.Status\r
-                      );\r
-\r
-    //\r
-    // wait for BSY == 0 and DRQ == 0\r
-    //\r
-    if ((StatusRegister & (DRQ | BSY)) == 0) {\r
-      break;\r
-    }\r
-    //\r
-    // check whether the command is aborted by the device\r
-    //\r
-    if ((StatusRegister & (BSY | ERR)) == ERR) {\r
-\r
-      ErrRegister = ReadPortB (\r
-                      AtapiScsiPrivate->PciIo,\r
-                      AtapiScsiPrivate->IoPort->Reg1.Error\r
-                      );\r
-      if ((ErrRegister & ABRT_ERR) == ABRT_ERR) {\r
-\r
-        return EFI_ABORTED;\r
-      }\r
-    }\r
-    //\r
-    //  Stall for 30 us\r
-    //\r
-    gBS->Stall (30);\r
-\r
-    //\r
-    // Loop infinitely if not meeting expected condition\r
-    //\r
-    if (TimeoutInMicroSeconds == 0) {\r
-      Delay = 2;\r
-    }\r
-\r
-    Delay--;\r
-  } while (Delay);\r
-\r
-  if (Delay == 0) {\r
-    return EFI_TIMEOUT;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Check whether DRQ is clear in the Alternate Status Register. \r
-  (BSY must also be cleared).\r
-  If TimeoutInMicroSeconds is zero, this routine should wait infinitely for\r
-  DRQ clear. Otherwise, it will return EFI_TIMEOUT when specified time is \r
-  elapsed.\r
-\r
-  @todo function comment is missing 'Routine Description:'\r
-  @todo function comment is missing 'Arguments:'\r
-  @todo function comment is missing 'Returns:'\r
-  @todo    AtapiScsiPrivate - add argument and description to function comment\r
-  @todo    TimeoutInMicroSeconds - add argument and description to function comment\r
-  @todo    EFI_ABORTED - add return value to function comment\r
-  @todo    EFI_TIMEOUT - add return value to function comment\r
-  @todo    EFI_SUCCESS - add return value to function comment\r
-**/\r
-EFI_STATUS\r
-AltStatusDRQClear (\r
-  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate,\r
-  UINT64                          TimeoutInMicroSeconds\r
-  )\r
-{\r
-  UINT64  Delay;\r
-  UINT8   AltStatusRegister;\r
-  UINT8   ErrRegister;\r
-\r
-  if (TimeoutInMicroSeconds == 0) {\r
-    Delay = 2;\r
-  } else {\r
-    Delay = DivU64x32 (TimeoutInMicroSeconds, (UINT32) 30) + 1;\r
-  }\r
-\r
-  do {\r
-\r
-    AltStatusRegister = ReadPortB (\r
-                          AtapiScsiPrivate->PciIo,\r
-                          AtapiScsiPrivate->IoPort->Alt.AltStatus\r
-                          );\r
-\r
-    //\r
-    // wait for BSY == 0 and DRQ == 0\r
-    //\r
-    if ((AltStatusRegister & (DRQ | BSY)) == 0) {\r
-      break;\r
-    }\r
-\r
-    if ((AltStatusRegister & (BSY | ERR)) == ERR) {\r
-\r
-      ErrRegister = ReadPortB (\r
-                      AtapiScsiPrivate->PciIo,\r
-                      AtapiScsiPrivate->IoPort->Reg1.Error\r
-                      );\r
-      if ((ErrRegister & ABRT_ERR) == ABRT_ERR) {\r
-\r
-        return EFI_ABORTED;\r
-      }\r
-    }\r
-    //\r
-    //  Stall for 30 us\r
-    //\r
-    gBS->Stall (30);\r
-\r
-    //\r
-    // Loop infinitely if not meeting expected condition\r
-    //\r
-    if (TimeoutInMicroSeconds == 0) {\r
-      Delay = 2;\r
-    }\r
-\r
-    Delay--;\r
-  } while (Delay);\r
-\r
-  if (Delay == 0) {\r
-    return EFI_TIMEOUT;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Check whether DRQ is ready in the Status Register. (BSY must also be cleared)\r
-  If TimeoutInMicroSeconds is zero, this routine should wait infinitely for\r
-  DRQ ready. Otherwise, it will return EFI_TIMEOUT when specified time is \r
-  elapsed.\r
-\r
-  @todo function comment is missing 'Routine Description:'\r
-  @todo function comment is missing 'Arguments:'\r
-  @todo function comment is missing 'Returns:'\r
-  @todo    AtapiScsiPrivate - add argument and description to function comment\r
-  @todo    TimeoutInMicroSeconds - add argument and description to function comment\r
-  @todo    EFI_ABORTED - add return value to function comment\r
-  @todo    EFI_TIMEOUT - add return value to function comment\r
-  @todo    EFI_SUCCESS - add return value to function comment\r
-**/\r
-EFI_STATUS\r
-StatusDRQReady (\r
-  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate,\r
-  UINT64                          TimeoutInMicroSeconds\r
-  )\r
-{\r
-  UINT64  Delay;\r
-  UINT8   StatusRegister;\r
-  UINT8   ErrRegister;\r
-\r
-  if (TimeoutInMicroSeconds == 0) {\r
-    Delay = 2;\r
-  } else {\r
-    Delay = DivU64x32 (TimeoutInMicroSeconds, (UINT32) 30) + 1;\r
-  }\r
-\r
-  do {\r
-    //\r
-    //  read Status Register will clear interrupt\r
-    //\r
-    StatusRegister = ReadPortB (\r
-                      AtapiScsiPrivate->PciIo,\r
-                      AtapiScsiPrivate->IoPort->Reg.Status\r
-                      );\r
-\r
-    //\r
-    //  BSY==0,DRQ==1\r
-    //\r
-    if ((StatusRegister & (BSY | DRQ)) == DRQ) {\r
-      break;\r
-    }\r
-\r
-    if ((StatusRegister & (BSY | ERR)) == ERR) {\r
-\r
-      ErrRegister = ReadPortB (\r
-                      AtapiScsiPrivate->PciIo,\r
-                      AtapiScsiPrivate->IoPort->Reg1.Error\r
-                      );\r
-      if ((ErrRegister & ABRT_ERR) == ABRT_ERR) {\r
-        return EFI_ABORTED;\r
-      }\r
-    }\r
-\r
-    //\r
-    // Stall for 30 us\r
-    //\r
-    gBS->Stall (30);\r
-\r
-    //\r
-    // Loop infinitely if not meeting expected condition\r
-    //\r
-    if (TimeoutInMicroSeconds == 0) {\r
-      Delay = 2;\r
-    }\r
-\r
-    Delay--;\r
-  } while (Delay);\r
-\r
-  if (Delay == 0) {\r
-    return EFI_TIMEOUT;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Check whether DRQ is ready in the Alternate Status Register. \r
-  (BSY must also be cleared)\r
-  If TimeoutInMicroSeconds is zero, this routine should wait infinitely for\r
-  DRQ ready. Otherwise, it will return EFI_TIMEOUT when specified time is \r
-  elapsed.\r
-\r
-  @todo function comment is missing 'Routine Description:'\r
-  @todo function comment is missing 'Arguments:'\r
-  @todo function comment is missing 'Returns:'\r
-  @todo    AtapiScsiPrivate - add argument and description to function comment\r
-  @todo    TimeoutInMicroSeconds - add argument and description to function comment\r
-  @todo    EFI_ABORTED - add return value to function comment\r
-  @todo    EFI_TIMEOUT - add return value to function comment\r
-  @todo    EFI_SUCCESS - add return value to function comment\r
-**/\r
-EFI_STATUS\r
-AltStatusDRQReady (\r
-  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate,\r
-  UINT64                          TimeoutInMicroSeconds\r
-  )\r
-{\r
-  UINT64  Delay;\r
-  UINT8   AltStatusRegister;\r
-  UINT8   ErrRegister;\r
-\r
-  if (TimeoutInMicroSeconds == 0) {\r
-    Delay = 2;\r
-  } else {\r
-    Delay = DivU64x32 (TimeoutInMicroSeconds, (UINT32) 30) + 1;\r
-  }\r
-\r
-  do {\r
-    //\r
-    //  read Status Register will clear interrupt\r
-    //\r
-    AltStatusRegister = ReadPortB (\r
-                          AtapiScsiPrivate->PciIo,\r
-                          AtapiScsiPrivate->IoPort->Alt.AltStatus\r
-                          );\r
-    //\r
-    //  BSY==0,DRQ==1\r
-    //\r
-    if ((AltStatusRegister & (BSY | DRQ)) == DRQ) {\r
-      break;\r
-    }\r
-\r
-    if ((AltStatusRegister & (BSY | ERR)) == ERR) {\r
-\r
-      ErrRegister = ReadPortB (\r
-                      AtapiScsiPrivate->PciIo,\r
-                      AtapiScsiPrivate->IoPort->Reg1.Error\r
-                      );\r
-      if ((ErrRegister & ABRT_ERR) == ABRT_ERR) {\r
-        return EFI_ABORTED;\r
-      }\r
-    }\r
-\r
-    //\r
-    // Stall for 30 us\r
-    //\r
-    gBS->Stall (30);\r
-\r
-    //\r
-    // Loop infinitely if not meeting expected condition\r
-    //\r
-    if (TimeoutInMicroSeconds == 0) {\r
-      Delay = 2;\r
-    }\r
-\r
-    Delay--;\r
-  } while (Delay);\r
-\r
-  if (Delay == 0) {\r
-    return EFI_TIMEOUT;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Check whether BSY is clear in the Status Register.\r
-  If TimeoutInMicroSeconds is zero, this routine should wait infinitely for\r
-  BSY clear. Otherwise, it will return EFI_TIMEOUT when specified time is \r
-  elapsed.\r
-\r
-  @todo function comment is missing 'Routine Description:'\r
-  @todo function comment is missing 'Arguments:'\r
-  @todo function comment is missing 'Returns:'\r
-  @todo    AtapiScsiPrivate - add argument and description to function comment\r
-  @todo    TimeoutInMicroSeconds - add argument and description to function comment\r
-  @todo    EFI_TIMEOUT - add return value to function comment\r
-  @todo    EFI_SUCCESS - add return value to function comment\r
-**/\r
-EFI_STATUS\r
-StatusWaitForBSYClear (\r
-  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate,\r
-  UINT64                      TimeoutInMicroSeconds\r
-  )\r
-{\r
-  UINT64  Delay;\r
-  UINT8   StatusRegister;\r
-\r
-  if (TimeoutInMicroSeconds == 0) {\r
-    Delay = 2;\r
-  } else {\r
-    Delay = DivU64x32 (TimeoutInMicroSeconds, (UINT32) 30) + 1;\r
-  }\r
-\r
-  do {\r
-\r
-    StatusRegister = ReadPortB (\r
-                      AtapiScsiPrivate->PciIo,\r
-                      AtapiScsiPrivate->IoPort->Reg.Status\r
-                      );\r
-    if ((StatusRegister & BSY) == 0x00) {\r
-      break;\r
-    }\r
-\r
-    //\r
-    // Stall for 30 us\r
-    //\r
-    gBS->Stall (30);\r
-\r
-    //\r
-    // Loop infinitely if not meeting expected condition\r
-    //\r
-    if (TimeoutInMicroSeconds == 0) {\r
-      Delay = 2;\r
-    }\r
-\r
-    Delay--;\r
-  } while (Delay);\r
-\r
-  if (Delay == 0) {\r
-    return EFI_TIMEOUT;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Check whether BSY is clear in the Alternate Status Register.\r
-  If TimeoutInMicroSeconds is zero, this routine should wait infinitely for\r
-  BSY clear. Otherwise, it will return EFI_TIMEOUT when specified time is \r
-  elapsed.\r
-\r
-  @todo function comment is missing 'Routine Description:'\r
-  @todo function comment is missing 'Arguments:'\r
-  @todo function comment is missing 'Returns:'\r
-  @todo    AtapiScsiPrivate - add argument and description to function comment\r
-  @todo    TimeoutInMicroSeconds - add argument and description to function comment\r
-  @todo    EFI_TIMEOUT - add return value to function comment\r
-  @todo    EFI_SUCCESS - add return value to function comment\r
-**/\r
-EFI_STATUS\r
-AltStatusWaitForBSYClear (\r
-  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate,\r
-  UINT64                      TimeoutInMicroSeconds\r
-  )\r
-{\r
-  UINT64  Delay;\r
-  UINT8   AltStatusRegister;\r
-\r
-  if (TimeoutInMicroSeconds == 0) {\r
-    Delay = 2;\r
-  } else {\r
-    Delay = DivU64x32 (TimeoutInMicroSeconds, (UINT32) 30) + 1;\r
-  }\r
-\r
-  do {\r
-\r
-    AltStatusRegister = ReadPortB (\r
-                          AtapiScsiPrivate->PciIo,\r
-                          AtapiScsiPrivate->IoPort->Alt.AltStatus\r
-                          );\r
-    if ((AltStatusRegister & BSY) == 0x00) {\r
-      break;\r
-    }\r
-\r
-    //\r
-    // Stall for 30 us\r
-    //\r
-    gBS->Stall (30);\r
-    //\r
-    // Loop infinitely if not meeting expected condition\r
-    //\r
-    if (TimeoutInMicroSeconds == 0) {\r
-      Delay = 2;\r
-    }\r
-\r
-    Delay--;\r
-  } while (Delay);\r
-\r
-  if (Delay == 0) {\r
-    return EFI_TIMEOUT;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Check whether DRDY is ready in the Status Register. \r
-  (BSY must also be cleared)\r
-  If TimeoutInMicroSeconds is zero, this routine should wait infinitely for\r
-  DRDY ready. Otherwise, it will return EFI_TIMEOUT when specified time is \r
-  elapsed.\r
-\r
-  @todo function comment is missing 'Routine Description:'\r
-  @todo function comment is missing 'Arguments:'\r
-  @todo function comment is missing 'Returns:'\r
-  @todo    AtapiScsiPrivate - add argument and description to function comment\r
-  @todo    TimeoutInMicroSeconds - add argument and description to function comment\r
-  @todo    EFI_ABORTED - add return value to function comment\r
-  @todo    EFI_TIMEOUT - add return value to function comment\r
-  @todo    EFI_SUCCESS - add return value to function comment\r
-**/\r
-EFI_STATUS\r
-StatusDRDYReady (\r
-  ATAPI_SCSI_PASS_THRU_DEV     *AtapiScsiPrivate,\r
-  UINT64                       TimeoutInMicroSeconds\r
-  )\r
-{\r
-  UINT64  Delay;\r
-  UINT8   StatusRegister;\r
-  UINT8   ErrRegister;\r
-\r
-  if (TimeoutInMicroSeconds == 0) {\r
-    Delay = 2;\r
-  } else {\r
-    Delay = DivU64x32 (TimeoutInMicroSeconds, (UINT32) 30) + 1;\r
-  }\r
-\r
-  do {\r
-    StatusRegister = ReadPortB (\r
-                      AtapiScsiPrivate->PciIo,\r
-                      AtapiScsiPrivate->IoPort->Reg.Status\r
-                      );\r
-    //\r
-    //  BSY == 0 , DRDY == 1\r
-    //\r
-    if ((StatusRegister & (DRDY | BSY)) == DRDY) {\r
-      break;\r
-    }\r
-\r
-    if ((StatusRegister & (BSY | ERR)) == ERR) {\r
-\r
-      ErrRegister = ReadPortB (\r
-                      AtapiScsiPrivate->PciIo,\r
-                      AtapiScsiPrivate->IoPort->Reg1.Error\r
-                      );\r
-      if ((ErrRegister & ABRT_ERR) == ABRT_ERR) {\r
-        return EFI_ABORTED;\r
-      }\r
-    }\r
-    \r
-    //\r
-    // Stall for 30 us\r
-    //\r
-    gBS->Stall (30);\r
-    //\r
-    // Loop infinitely if not meeting expected condition\r
-    //\r
-    if (TimeoutInMicroSeconds == 0) {\r
-      Delay = 2;\r
-    }\r
-\r
-    Delay--;\r
-  } while (Delay);\r
-\r
-  if (Delay == 0) {\r
-    return EFI_TIMEOUT;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Check whether DRDY is ready in the Alternate Status Register. \r
-  (BSY must also be cleared)\r
-  If TimeoutInMicroSeconds is zero, this routine should wait infinitely for\r
-  DRDY ready. Otherwise, it will return EFI_TIMEOUT when specified time is \r
-  elapsed.\r
-\r
-  @todo function comment is missing 'Routine Description:'\r
-  @todo function comment is missing 'Arguments:'\r
-  @todo function comment is missing 'Returns:'\r
-  @todo    AtapiScsiPrivate - add argument and description to function comment\r
-  @todo    TimeoutInMicroSeconds - add argument and description to function comment\r
-  @todo    EFI_ABORTED - add return value to function comment\r
-  @todo    EFI_TIMEOUT - add return value to function comment\r
-  @todo    EFI_SUCCESS - add return value to function comment\r
-**/\r
-EFI_STATUS\r
-AltStatusDRDYReady (\r
-  ATAPI_SCSI_PASS_THRU_DEV     *AtapiScsiPrivate,\r
-  UINT64                       TimeoutInMicroSeconds\r
-  )\r
-{\r
-  UINT64  Delay;\r
-  UINT8   AltStatusRegister;\r
-  UINT8   ErrRegister;\r
-\r
-  if (TimeoutInMicroSeconds == 0) {\r
-    Delay = 2;\r
-  } else {\r
-    Delay = DivU64x32 (TimeoutInMicroSeconds, (UINT32) 30) + 1;\r
-  }\r
-\r
-  do {\r
-    AltStatusRegister = ReadPortB (\r
-                          AtapiScsiPrivate->PciIo,\r
-                          AtapiScsiPrivate->IoPort->Alt.AltStatus\r
-                          );\r
-    //\r
-    //  BSY == 0 , DRDY == 1\r
-    //\r
-    if ((AltStatusRegister & (DRDY | BSY)) == DRDY) {\r
-      break;\r
-    }\r
-\r
-    if ((AltStatusRegister & (BSY | ERR)) == ERR) {\r
-\r
-      ErrRegister = ReadPortB (\r
-                      AtapiScsiPrivate->PciIo,\r
-                      AtapiScsiPrivate->IoPort->Reg1.Error\r
-                      );\r
-      if ((ErrRegister & ABRT_ERR) == ABRT_ERR) {\r
-        return EFI_ABORTED;\r
-      }\r
-    }\r
-\r
-    //\r
-    // Stall for 30 us\r
-    //\r
-    gBS->Stall (30);\r
-    //\r
-    // Loop infinitely if not meeting expected condition\r
-    //\r
-    if (TimeoutInMicroSeconds == 0) {\r
-      Delay = 2;\r
-    }\r
-\r
-    Delay--;\r
-  } while (Delay);\r
-\r
-  if (Delay == 0) {\r
-    return EFI_TIMEOUT;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Check Error Register for Error Information. \r
-\r
-  @todo function comment is missing 'Routine Description:'\r
-  @todo function comment is missing 'Arguments:'\r
-  @todo function comment is missing 'Returns:'\r
-  @todo    AtapiScsiPrivate - add argument and description to function comment\r
-  @todo    EFI_SUCCESS - add return value to function comment\r
-  @todo    EFI_DEVICE_ERROR - add return value to function comment\r
-**/\r
-EFI_STATUS\r
-AtapiPassThruCheckErrorStatus (\r
-  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate\r
-  )\r
-{\r
-  UINT8 StatusRegister;\r
-  UINT8 ErrorRegister;\r
-\r
-  StatusRegister = ReadPortB (\r
-                    AtapiScsiPrivate->PciIo,\r
-                    AtapiScsiPrivate->IoPort->Reg.Status\r
-                    );\r
-  \r
-  DEBUG_CODE_BEGIN ();\r
-\r
-    if (StatusRegister & DWF) {\r
-      DEBUG (\r
-        (EFI_D_BLKIO,\r
-        "AtapiPassThruCheckErrorStatus()-- %02x : Error : Write Fault\n",\r
-        StatusRegister)\r
-        );\r
-    }\r
-\r
-    if (StatusRegister & CORR) {\r
-      DEBUG (\r
-        (EFI_D_BLKIO,\r
-        "AtapiPassThruCheckErrorStatus()-- %02x : Error : Corrected Data\n",\r
-        StatusRegister)\r
-        );\r
-    }\r
-\r
-    if (StatusRegister & ERR) {\r
-      ErrorRegister = ReadPortB (AtapiScsiPrivate->PciIo, AtapiScsiPrivate->IoPort->Reg1.Error);\r
-      \r
-\r
-      if (ErrorRegister & BBK_ERR) {\r
-        DEBUG (\r
-          (EFI_D_BLKIO,\r
-          "AtapiPassThruCheckErrorStatus()-- %02x : Error : Bad Block Detected\n",\r
-          ErrorRegister)\r
-          );\r
-      }\r
-\r
-      if (ErrorRegister & UNC_ERR) {\r
-        DEBUG (\r
-          (EFI_D_BLKIO,\r
-          "AtapiPassThruCheckErrorStatus()-- %02x : Error : Uncorrectable Data\n",\r
-          ErrorRegister)\r
-          );\r
-      }\r
-\r
-      if (ErrorRegister & MC_ERR) {\r
-        DEBUG (\r
-          (EFI_D_BLKIO,\r
-          "AtapiPassThruCheckErrorStatus()-- %02x : Error : Media Change\n",\r
-          ErrorRegister)\r
-          );\r
-      }\r
-\r
-      if (ErrorRegister & ABRT_ERR) {\r
-        DEBUG (\r
-          (EFI_D_BLKIO,\r
-          "AtapiPassThruCheckErrorStatus()-- %02x : Error : Abort\n",\r
-          ErrorRegister)\r
-          );\r
-      }\r
-\r
-      if (ErrorRegister & TK0NF_ERR) {\r
-        DEBUG (\r
-          (EFI_D_BLKIO,\r
-          "AtapiPassThruCheckErrorStatus()-- %02x : Error : Track 0 Not Found\n",\r
-          ErrorRegister)\r
-          );\r
-      }\r
-\r
-      if (ErrorRegister & AMNF_ERR) {\r
-        DEBUG (\r
-          (EFI_D_BLKIO,\r
-          "AtapiPassThruCheckErrorStatus()-- %02x : Error : Address Mark Not Found\n",\r
-          ErrorRegister)\r
-          );\r
-       }\r
-    }\r
-\r
-  DEBUG_CODE_END ();\r
-\r
-  if ((StatusRegister & (ERR | DWF | CORR)) == 0) {\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
\r
-  return EFI_DEVICE_ERROR;\r
-}\r
-\r
-/**\r
-  The user Entry Point for module AtapiPassThru. The user code starts with this function.\r
-\r
-  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
-  @param[in] SystemTable    A pointer to the EFI System Table.\r
-  \r
-  @retval EFI_SUCCESS       The entry point is executed successfully.\r
-  @retval other             Some error occurs when executing this entry point.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-InitializeAtapiPassThru(\r
-  IN EFI_HANDLE           ImageHandle,\r
-  IN EFI_SYSTEM_TABLE     *SystemTable\r
-  )\r
-{\r
-  EFI_STATUS              Status;\r
-\r
-  //\r
-  // Install driver model protocol(s).\r
-  //\r
-  Status = EfiLibInstallAllDriverProtocols (\r
-             ImageHandle,\r
-             SystemTable,\r
-             &gAtapiScsiPassThruDriverBinding,\r
-             ImageHandle,\r
-             &gAtapiScsiPassThruComponentName,\r
-             NULL,\r
-             NULL\r
-             );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  return Status;\r
-}\r
diff --git a/MdeModulePkg/Bus/Pci/AtapiPassThru/Dxe/AtapiPassThru.h b/MdeModulePkg/Bus/Pci/AtapiPassThru/Dxe/AtapiPassThru.h
deleted file mode 100644 (file)
index 49b97a8..0000000
+++ /dev/null
@@ -1,833 +0,0 @@
-/** @file\r
-  Copyright (c) 2006, Intel Corporation                                                         \r
-  All rights reserved. This program and the accompanying materials                          \r
-  are licensed and made available under the terms and conditions of the BSD License         \r
-  which accompanies this distribution.  The full text of the license may be found at        \r
-  http://opensource.org/licenses/bsd-license.php                                            \r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
-\r
-  Module Name:  AtapiPassThru.h\r
-\r
-**/\r
-\r
-#ifndef _APT_H\r
-#define _APT_H\r
-\r
-\r
-//\r
-// The package level header files this module uses\r
-//\r
-#include <Uefi.h>\r
-//\r
-// The protocols, PPI and GUID defintions for this module\r
-//\r
-#include <Protocol/ScsiPassThru.h>\r
-#include <Protocol/PciIo.h>\r
-//\r
-// The Library classes this module consumes\r
-//\r
-#include <Library/DebugLib.h>\r
-#include <Library/UefiDriverEntryPoint.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/UefiLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <IndustryStandard/pci22.h>\r
-\r
-///\r
-/// bit definition\r
-///\r
-#define bit(a)        (1 << (a))\r
-\r
-#define MAX_TARGET_ID 4\r
-\r
-//\r
-// IDE Registers\r
-//\r
-typedef union {\r
-  UINT16  Command;        /* when write */\r
-  UINT16  Status;         /* when read */\r
-} IDE_CMD_OR_STATUS;\r
-\r
-typedef union {\r
-  UINT16  Error;          /* when read */\r
-  UINT16  Feature;        /* when write */\r
-} IDE_ERROR_OR_FEATURE;\r
-\r
-typedef union {\r
-  UINT16  AltStatus;      /* when read */\r
-  UINT16  DeviceControl;  /* when write */\r
-} IDE_AltStatus_OR_DeviceControl;\r
-\r
-///\r
-/// IDE registers set\r
-///\r
-typedef struct {\r
-  UINT16                          Data;\r
-  IDE_ERROR_OR_FEATURE            Reg1;\r
-  UINT16                          SectorCount;\r
-  UINT16                          SectorNumber;\r
-  UINT16                          CylinderLsb;\r
-  UINT16                          CylinderMsb;\r
-  UINT16                          Head;\r
-  IDE_CMD_OR_STATUS               Reg;\r
-\r
-  IDE_AltStatus_OR_DeviceControl  Alt;\r
-  UINT16                          DriveAddress;\r
-\r
-  UINT16                          MasterSlave;\r
-} IDE_BASE_REGISTERS;\r
-\r
-#define ATAPI_SCSI_PASS_THRU_DEV_SIGNATURE  EFI_SIGNATURE_32 ('a', 's', 'p', 't')\r
-\r
-typedef struct {\r
-  UINTN                       Signature;\r
-\r
-  EFI_HANDLE                  Handle;\r
-  EFI_SCSI_PASS_THRU_PROTOCOL ScsiPassThru;\r
-  EFI_SCSI_PASS_THRU_MODE     ScsiPassThruMode;\r
-  EFI_PCI_IO_PROTOCOL         *PciIo;\r
-\r
-  //\r
-  // Local Data goes here\r
-  //\r
-  IDE_BASE_REGISTERS          *IoPort;\r
-\r
-  CHAR16                      ControllerName[100];\r
-  CHAR16                      ChannelName[100];\r
-\r
-  UINT32                      LatestTargetId;\r
-  UINT64                      LatestLun;\r
-\r
-} ATAPI_SCSI_PASS_THRU_DEV;\r
-\r
-#define ATAPI_SCSI_PASS_THRU_DEV_FROM_THIS(a) \\r
-  CR (a, \\r
-      ATAPI_SCSI_PASS_THRU_DEV, \\r
-      ScsiPassThru, \\r
-      ATAPI_SCSI_PASS_THRU_DEV_SIGNATURE \\r
-      )\r
-\r
-//\r
-// Global Variables\r
-//\r
-extern EFI_DRIVER_BINDING_PROTOCOL  gAtapiScsiPassThruDriverBinding;\r
-extern EFI_COMPONENT_NAME_PROTOCOL  gAtapiScsiPassThruComponentName;\r
-\r
-//\r
-// ATAPI Command op code\r
-//\r
-#define OP_INQUIRY                      0x12\r
-#define OP_LOAD_UNLOAD_CD               0xa6\r
-#define OP_MECHANISM_STATUS             0xbd\r
-#define OP_MODE_SELECT_10               0x55\r
-#define OP_MODE_SENSE_10                0x5a\r
-#define OP_PAUSE_RESUME                 0x4b\r
-#define OP_PLAY_AUDIO_10                0x45\r
-#define OP_PLAY_AUDIO_MSF               0x47\r
-#define OP_PLAY_CD                      0xbc\r
-#define OP_PLAY_CD_MSF                  0xb4\r
-#define OP_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e\r
-#define OP_READ_10                      0x28\r
-#define OP_READ_12                      0xa8\r
-#define OP_READ_CAPACITY                0x25\r
-#define OP_READ_CD                      0xbe\r
-#define OP_READ_CD_MSF                  0xb9\r
-#define OP_READ_HEADER                  0x44\r
-#define OP_READ_SUB_CHANNEL             0x42\r
-#define OP_READ_TOC                     0x43\r
-#define OP_REQUEST_SENSE                0x03\r
-#define OP_SCAN                         0xba\r
-#define OP_SEEK_10                      0x2b\r
-#define OP_SET_CD_SPEED                 0xbb\r
-#define OP_STOPPLAY_SCAN                0x4e\r
-#define OP_START_STOP_UNIT              0x1b\r
-#define OP_TEST_UNIT_READY              0x00\r
-\r
-#define OP_FORMAT_UNIT                  0x04\r
-#define OP_READ_FORMAT_CAPACITIES       0x23\r
-#define OP_VERIFY                       0x2f\r
-#define OP_WRITE_10                     0x2a\r
-#define OP_WRITE_12                     0xaa\r
-#define OP_WRITE_AND_VERIFY             0x2e\r
-\r
-//\r
-// ATA Command\r
-//\r
-#define ATAPI_SOFT_RESET_CMD  0x08\r
-\r
-typedef enum {\r
-  DataIn  = 0,\r
-  DataOut = 1,\r
-  NoData  = 2,\r
-  End     = 0xff\r
-} DATA_DIRECTION;\r
-\r
-typedef struct {\r
-  UINT8           OpCode;\r
-  DATA_DIRECTION  Direction;\r
-} SCSI_COMMAND_SET;\r
-\r
-#define MAX_CHANNEL         2\r
-\r
-#define ValidCdbLength(Len) ((Len) == 6 || (Len) == 10 || (Len) == 12) ? 1 : 0\r
-\r
-//\r
-// IDE registers bit definitions\r
-//\r
-// ATA Err Reg bitmap\r
-//\r
-#define BBK_ERR   bit (7) ///< Bad block detected\r
-#define UNC_ERR   bit (6) ///< Uncorrectable Data\r
-#define MC_ERR    bit (5) ///< Media Change\r
-#define IDNF_ERR  bit (4) ///< ID Not Found\r
-#define MCR_ERR   bit (3) ///< Media Change Requested\r
-#define ABRT_ERR  bit (2) ///< Aborted Command\r
-#define TK0NF_ERR bit (1) ///< Track 0 Not Found\r
-#define AMNF_ERR  bit (0) ///< Address Mark Not Found\r
-\r
-//\r
-// ATAPI Err Reg bitmap\r
-//\r
-#define SENSE_KEY_ERR (bit (7) | bit (6) | bit (5) | bit (4))\r
-#define EOM_ERR bit (1) ///< End of Media Detected\r
-#define ILI_ERR bit (0) ///< Illegal Length Indication\r
-\r
-//\r
-// Device/Head Reg\r
-//\r
-#define LBA_MODE  bit (6)\r
-#define DEV       bit (4)\r
-#define HS3       bit (3)\r
-#define HS2       bit (2)\r
-#define HS1       bit (1)\r
-#define HS0       bit (0)\r
-#define CHS_MODE  (0)\r
-#define DRV0      (0)\r
-#define DRV1      (1)\r
-#define MST_DRV   DRV0\r
-#define SLV_DRV   DRV1\r
-\r
-//\r
-// Status Reg\r
-//\r
-#define BSY   bit (7) ///< Controller Busy\r
-#define DRDY  bit (6) ///< Drive Ready\r
-#define DWF   bit (5) ///< Drive Write Fault\r
-#define DSC   bit (4) ///< Disk Seek Complete\r
-#define DRQ   bit (3) ///< Data Request\r
-#define CORR  bit (2) ///< Corrected Data\r
-#define IDX   bit (1) ///< Index\r
-#define ERR   bit (0) ///< Error\r
-#define CHECK bit (0) ///< Check bit for ATAPI Status Reg\r
-\r
-//\r
-// Device Control Reg\r
-//\r
-#define SRST  bit (2) ///< Software Reset\r
-#define IEN_L bit (1) ///< Interrupt Enable\r
-\r
-//\r
-// ATAPI Feature Register\r
-//\r
-#define OVERLAP bit (1)\r
-#define DMA     bit (0)\r
-\r
-//\r
-// ATAPI Interrupt Reason Reson Reg (ATA Sector Count Register)\r
-//\r
-#define RELEASE     bit (2)\r
-#define IO          bit (1)\r
-#define CoD         bit (0)\r
-\r
-#define PACKET_CMD  0xA0\r
-\r
-#define DEFAULT_CMD (0xa0)\r
-//\r
-// default content of device control register, disable INT\r
-//\r
-#define DEFAULT_CTL           (0x0a)\r
-#define MAX_ATAPI_BYTE_COUNT  (0xfffe)\r
-\r
-//\r
-// function prototype\r
-//\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruDriverBindingSupported (\r
-  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
-  IN EFI_HANDLE                   Controller,\r
-  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
-  );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruDriverBindingStart (\r
-  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
-  IN EFI_HANDLE                   Controller,\r
-  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
-  );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruDriverBindingStop (\r
-  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
-  IN  EFI_HANDLE                      Controller,\r
-  IN  UINTN                           NumberOfChildren,\r
-  IN  EFI_HANDLE                      *ChildHandleBuffer\r
-  );\r
-\r
-//\r
-// EFI Component Name Functions\r
-//\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruComponentNameGetDriverName (\r
-  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
-  IN  CHAR8                        *Language,\r
-  OUT CHAR16                       **DriverName\r
-  );\r
-\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruComponentNameGetControllerName (\r
-  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
-  IN  EFI_HANDLE                                      ControllerHandle,\r
-  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
-  IN  CHAR8                                           *Language,\r
-  OUT CHAR16                                          **ControllerName\r
-  );\r
-\r
-/**\r
-  AtapiScsiPassThruDriverEntryPoint\r
-\r
-  @param ImageHandle\r
-  @param SystemTable\r
-\r
-  @todo Add function description\r
-  @todo ImageHandle - add argument description\r
-  @todo SystemTable - add argument description\r
-  @todo add return values\r
---*/\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruDriverEntryPoint (\r
-  IN EFI_HANDLE         ImageHandle,\r
-  IN EFI_SYSTEM_TABLE   *SystemTable\r
-  )\r
-;\r
-\r
-/**\r
-  RegisterAtapiScsiPassThru\r
-\r
-  @param  This\r
-  @param  Controller\r
-  @param  PciIo\r
-\r
-  @todo Add function description\r
-  @todo This add argument description\r
-  @todo Controller add argument description\r
-  @todo PciIo add argument description\r
-  @todo add return values\r
-**/\r
-EFI_STATUS\r
-RegisterAtapiScsiPassThru (\r
-  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
-  IN  EFI_HANDLE                  Controller,\r
-  IN  EFI_PCI_IO_PROTOCOL         *PciIo\r
-  )\r
-;\r
-\r
-/**\r
-  AtapiScsiPassThruFunction\r
-\r
-  @param  This\r
-  @param  Target\r
-  @param  Lun\r
-  @param  Packet\r
-  @param  Event\r
-\r
-  @todo Add function description\r
-  @todo  This - add argument description\r
-  @todo  Target - add argument description\r
-  @todo  Lun - add argument description\r
-  @todo  Packet - add argument description\r
-  @todo  Event - add argument description\r
-  @todo add return values\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruFunction (\r
-  IN EFI_SCSI_PASS_THRU_PROTOCOL                        *This,\r
-  IN UINT32                                             Target,\r
-  IN UINT64                                             Lun,\r
-  IN OUT EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET         *Packet,\r
-  IN EFI_EVENT                                          Event OPTIONAL\r
-  )\r
-;\r
-\r
-/**\r
-  AtapiScsiPassThruGetNextDevice\r
-\r
-  TODO: Add function description\r
-\r
-  @param  This TODO: add argument description\r
-  @param  Target TODO: add argument description\r
-  @param  Lun TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruGetNextDevice (\r
-  IN  EFI_SCSI_PASS_THRU_PROTOCOL    *This,\r
-  IN OUT UINT32                      *Target,\r
-  IN OUT UINT64                      *Lun\r
-  )\r
-;\r
-\r
-/**\r
-  AtapiScsiPassThruBuildDevicePath\r
-\r
-  TODO: Add function description\r
-\r
-  @param  This TODO: add argument description\r
-  @param  Target TODO: add argument description\r
-  @param  Lun TODO: add argument description\r
-  @param  DevicePath TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruBuildDevicePath (\r
-  IN     EFI_SCSI_PASS_THRU_PROTOCOL    *This,\r
-  IN     UINT32                         Target,\r
-  IN     UINT64                         Lun,\r
-  IN OUT EFI_DEVICE_PATH_PROTOCOL       **DevicePath\r
-  )\r
-;\r
-\r
-/**\r
-  AtapiScsiPassThruGetTargetLun\r
-\r
-  TODO: Add function description\r
-\r
-  @param  This TODO: add argument description\r
-  @param  DevicePath TODO: add argument description\r
-  @param  Target TODO: add argument description\r
-  @param  Lun TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruGetTargetLun (\r
-  IN  EFI_SCSI_PASS_THRU_PROTOCOL    *This,\r
-  IN  EFI_DEVICE_PATH_PROTOCOL       *DevicePath,\r
-  OUT UINT32                         *Target,\r
-  OUT UINT64                         *Lun\r
-  )\r
-;\r
-\r
-/**\r
-  AtapiScsiPassThruResetChannel\r
-\r
-  TODO: Add function description\r
-\r
-  @param  This TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruResetChannel (\r
-  IN  EFI_SCSI_PASS_THRU_PROTOCOL   *This\r
-  )\r
-;\r
-\r
-/**\r
-  AtapiScsiPassThruResetTarget\r
-\r
-  TODO: Add function description\r
-\r
-  @param  This TODO: add argument description\r
-  @param  Target TODO: add argument description\r
-  @param  Lun TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruResetTarget (\r
-  IN EFI_SCSI_PASS_THRU_PROTOCOL    *This,\r
-  IN UINT32                         Target,\r
-  IN UINT64                         Lun\r
-  )\r
-;\r
-\r
-/**\r
-  CheckSCSIRequestPacket\r
-\r
-  TODO: Add function description\r
-\r
-  @param  Packet TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-CheckSCSIRequestPacket (\r
-  EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET      *Packet\r
-  )\r
-;\r
-\r
-/**\r
-  SubmitBlockingIoCommand\r
-\r
-  TODO: Add function description\r
-\r
-  @param  AtapiScsiPrivate TODO: add argument description\r
-  @param  Target TODO: add argument description\r
-  @param  Packet TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-SubmitBlockingIoCommand (\r
-  ATAPI_SCSI_PASS_THRU_DEV                  *AtapiScsiPrivate,\r
-  UINT32                                    Target,\r
-  EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET    *Packet\r
-  )\r
-;\r
-\r
-/**\r
-  IsCommandValid\r
-\r
-  TODO: Add function description\r
-\r
-  @param Packet  - TODO: add argument description\r
-\r
-  @return TODO: add return values\r
-\r
---*/\r
-BOOLEAN\r
-IsCommandValid (\r
-  EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET   *Packet\r
-  )\r
-;\r
-\r
-/**\r
-  RequestSenseCommand\r
-\r
-  TODO: Add function description\r
-\r
-  @param  AtapiScsiPrivate TODO: add argument description\r
-  @param  Target TODO: add argument description\r
-  @param  Timeout TODO: add argument description\r
-  @param  SenseData TODO: add argument description\r
-  @param  SenseDataLength TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-RequestSenseCommand (\r
-  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate,\r
-  UINT32                      Target,\r
-  UINT64                      Timeout,\r
-  VOID                        *SenseData,\r
-  UINT8                       *SenseDataLength\r
-  )\r
-;\r
-\r
-/**\r
-  AtapiPacketCommand\r
-\r
-  TODO: Add function description\r
-\r
-  @param  AtapiScsiPrivate TODO: add argument description\r
-  @param  Target TODO: add argument description\r
-  @param  PacketCommand TODO: add argument description\r
-  @param  Buffer TODO: add argument description\r
-  @param  ByteCount TODO: add argument description\r
-  @param  Direction TODO: add argument description\r
-  @param  TimeOutInMicroSeconds TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-AtapiPacketCommand (\r
-  ATAPI_SCSI_PASS_THRU_DEV                  *AtapiScsiPrivate,\r
-  UINT32                                    Target,\r
-  UINT8                                     *PacketCommand,\r
-  VOID                                      *Buffer,\r
-  UINT32                                    *ByteCount,\r
-  DATA_DIRECTION                            Direction,\r
-  UINT64                                    TimeOutInMicroSeconds\r
-  )\r
-;\r
-\r
-\r
-/**\r
-  ReadPortB\r
-\r
-  TODO: Add function description\r
-\r
-  @param  PciIo TODO: add argument description\r
-  @param  Port TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-UINT8\r
-ReadPortB (\r
-  IN  EFI_PCI_IO_PROTOCOL   *PciIo,\r
-  IN  UINT16                Port\r
-  )\r
-;\r
-\r
-\r
-/**\r
-  ReadPortW\r
-\r
-  TODO: Add function description\r
-\r
-  @param  PciIo TODO: add argument description\r
-  @param  Port TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-UINT16\r
-ReadPortW (\r
-  IN  EFI_PCI_IO_PROTOCOL   *PciIo,\r
-  IN  UINT16                Port\r
-  )\r
-;\r
-\r
-\r
-/**\r
-  WritePortB\r
-\r
-  TODO: Add function description\r
-\r
-  @param  PciIo TODO: add argument description\r
-  @param  Port TODO: add argument description\r
-  @param  Data TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-VOID\r
-WritePortB (\r
-  IN  EFI_PCI_IO_PROTOCOL   *PciIo,\r
-  IN  UINT16                Port,\r
-  IN  UINT8                 Data\r
-  )\r
-;\r
-\r
-\r
-/**\r
-  WritePortW\r
-\r
-  TODO: Add function description\r
-\r
-  @param  PciIo TODO: add argument description\r
-  @param  Port TODO: add argument description\r
-  @param  Data TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-VOID\r
-WritePortW (\r
-  IN  EFI_PCI_IO_PROTOCOL   *PciIo,\r
-  IN  UINT16                Port,\r
-  IN  UINT16                Data\r
-  )\r
-;\r
-\r
-/**\r
-  StatusDRQClear\r
-\r
-  TODO: Add function description\r
-\r
-  @param  AtapiScsiPrivate TODO: add argument description\r
-  @param  TimeOutInMicroSeconds TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-StatusDRQClear (\r
-  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate,\r
-  UINT64                          TimeOutInMicroSeconds\r
-  )\r
-;\r
-\r
-/**\r
-  AltStatusDRQClear\r
-\r
-  TODO: Add function description\r
-\r
-  @param  AtapiScsiPrivate TODO: add argument description\r
-  @param  TimeOutInMicroSeconds TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-AltStatusDRQClear (\r
-  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate,\r
-  UINT64                          TimeOutInMicroSeconds\r
-  )\r
-;\r
-\r
-/**\r
-  StatusDRQReady\r
-\r
-  TODO: Add function description\r
-\r
-  @param  AtapiScsiPrivate TODO: add argument description\r
-  @param  TimeOutInMicroSeconds TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-StatusDRQReady (\r
-  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate,\r
-  UINT64                          TimeOutInMicroSeconds\r
-  )\r
-;\r
-\r
-/**\r
-  AltStatusDRQReady\r
-\r
-  TODO: Add function description\r
-\r
-  @param  AtapiScsiPrivate TODO: add argument description\r
-  @param  TimeOutInMicroSeconds TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-AltStatusDRQReady (\r
-  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate,\r
-  UINT64                          TimeOutInMicroSeconds\r
-  )\r
-;\r
-\r
-/**\r
-  TODO: Add function description\r
-\r
-  @param  AtapiScsiPrivate TODO: add argument description\r
-  @param  TimeoutInMicroSeconds TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-StatusWaitForBSYClear (\r
-  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate,\r
-  UINT64                      TimeoutInMicroSeconds\r
-  )\r
-;\r
-\r
-/**\r
-  TODO: Add function description\r
-\r
-  @param  AtapiScsiPrivate TODO: add argument description\r
-  @param  TimeoutInMicroSeconds TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-AltStatusWaitForBSYClear (\r
-  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate,\r
-  UINT64                      TimeoutInMicroSeconds\r
-  )\r
-;\r
-\r
-/**\r
-  TODO: Add function description\r
-\r
-  @param  AtapiScsiPrivate TODO: add argument description\r
-  @param  TimeoutInMicroSeconds TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-StatusDRDYReady (\r
-  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate,\r
-  UINT64                      TimeoutInMicroSeconds\r
-  )\r
-;\r
-\r
-/**\r
-  TODO: Add function description\r
-\r
-  @param  AtapiScsiPrivate TODO: add argument description\r
-  @param  TimeoutInMicroSeconds TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-AltStatusDRDYReady (\r
-  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate,\r
-  UINT64                      TimeoutInMicroSeconds\r
-  )\r
-;\r
-\r
-/**\r
-  TODO: Add function description\r
-\r
-  @param  AtapiScsiPrivate TODO: add argument description\r
-  @param  Buffer TODO: add argument description\r
-  @param  ByteCount TODO: add argument description\r
-  @param  Direction TODO: add argument description\r
-  @param  TimeOutInMicroSeconds TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-AtapiPassThruPioReadWriteData (\r
-  ATAPI_SCSI_PASS_THRU_DEV  *AtapiScsiPrivate,\r
-  UINT16                    *Buffer,\r
-  UINT32                    *ByteCount,\r
-  DATA_DIRECTION            Direction,\r
-  UINT64                    TimeOutInMicroSeconds\r
-  )\r
-;\r
-\r
-/**\r
-  TODO: Add function description\r
-\r
-  @param  AtapiScsiPrivate TODO: add argument description\r
-\r
-  TODO: add return values\r
-\r
-**/\r
-EFI_STATUS\r
-AtapiPassThruCheckErrorStatus (\r
-  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate\r
-  )\r
-;\r
-#endif\r
diff --git a/MdeModulePkg/Bus/Pci/AtapiPassThru/Dxe/AtapiPassThru.inf b/MdeModulePkg/Bus/Pci/AtapiPassThru/Dxe/AtapiPassThru.inf
deleted file mode 100644 (file)
index d449723..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-#/** @file\r
-# Description file for the Atapi Passthru component.\r
-#\r
-# This driver simulates SCSI devices with Atapi devices to test the SCSI io\r
-#  protocol.\r
-# Copyright (c) 2006 - 2007, Intel Corporation\r
-#\r
-#  All rights reserved. This program and the accompanying materials\r
-#  are licensed and made available under the terms and conditions of the BSD License\r
-#  which accompanies this distribution. The full text of the license may be found at\r
-#  http://opensource.org/licenses/bsd-license.php\r
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-#\r
-#\r
-#**/\r
-\r
-################################################################################\r
-#\r
-# Defines Section - statements that will be processed to create a Makefile.\r
-#\r
-################################################################################\r
-[Defines]\r
-  INF_VERSION                    = 0x00010005\r
-  BASE_NAME                      = AtapiPassThru\r
-  FILE_GUID                      = E49061CE-99A7-41d3-AB3A-36E5CFBAD63E\r
-  MODULE_TYPE                    = UEFI_DRIVER\r
-  VERSION_STRING                 = 1.0\r
-  EDK_RELEASE_VERSION            = 0x00020000\r
-  EFI_SPECIFICATION_VERSION      = 0x00020000\r
-\r
-  ENTRY_POINT                    = InitializeAtapiPassThru\r
-\r
-#\r
-# The following information is for reference only and not required by the build tools.\r
-#\r
-#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
-#\r
-#  DRIVER_BINDING                =  gAtapiScsiPassThruDriverBinding              \r
-#  COMPONENT_NAME                =  gAtapiScsiPassThruComponentName              \r
-#\r
-\r
-################################################################################\r
-#\r
-# Sources Section - list of files that are required for the build to succeed.\r
-#\r
-################################################################################\r
-\r
-[Sources.common]\r
-  ComponentName.c\r
-  AtapiPassThru.c\r
-  AtapiPassThru.h\r
-\r
-\r
-################################################################################\r
-#\r
-# Package Dependency Section - list of Package files that are required for\r
-#                              this module.\r
-#\r
-################################################################################\r
-\r
-[Packages]\r
-  MdePkg/MdePkg.dec\r
-\r
-\r
-################################################################################\r
-#\r
-# Library Class Section - list of Library Classes that are required for\r
-#                         this module.\r
-#\r
-################################################################################\r
-\r
-[LibraryClasses]\r
-  UefiBootServicesTableLib\r
-  MemoryAllocationLib\r
-  BaseMemoryLib\r
-  UefiLib\r
-  BaseLib\r
-  UefiDriverEntryPoint\r
-  DebugLib\r
-\r
-\r
-################################################################################\r
-#\r
-# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
-#                           that this module uses or produces.\r
-#\r
-################################################################################\r
-\r
-[Protocols]\r
-  gEfiScsiPassThruProtocolGuid                  # PROTOCOL BY_START\r
-  gEfiPciIoProtocolGuid                         # PROTOCOL TO_START\r
-\r
diff --git a/MdeModulePkg/Bus/Pci/AtapiPassThru/Dxe/AtapiPassThru.msa b/MdeModulePkg/Bus/Pci/AtapiPassThru/Dxe/AtapiPassThru.msa
deleted file mode 100644 (file)
index b33cb93..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>\r
-<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
-  <MsaHeader>\r
-    <ModuleName>AtapiPassThru</ModuleName>\r
-    <ModuleType>UEFI_DRIVER</ModuleType>\r
-    <GuidValue>E49061CE-99A7-41d3-AB3A-36E5CFBAD63E</GuidValue>\r
-    <Version>1.0</Version>\r
-    <Abstract>Description file for the Atapi Passthru component.</Abstract>\r
-    <Description>This driver simulates SCSI devices with Atapi devices to test the SCSI io\r
-      protocol.</Description>\r
-    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
-    <License>All rights reserved. This program and the accompanying materials\r
-      are licensed and made available under the terms and conditions of the BSD License\r
-      which accompanies this distribution.  The full text of the license may be found at\r
-      http://opensource.org/licenses/bsd-license.php\r
-      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-      WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
-    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
-  </MsaHeader>\r
-  <ModuleDefinitions>\r
-    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
-    <BinaryModule>false</BinaryModule>\r
-    <OutputFileBasename>AtapiPassThru</OutputFileBasename>\r
-  </ModuleDefinitions>\r
-  <LibraryClassDefinitions>\r
-    <LibraryClass Usage="ALWAYS_CONSUMED">\r
-      <Keyword>DebugLib</Keyword>\r
-    </LibraryClass>\r
-    <LibraryClass Usage="ALWAYS_CONSUMED">\r
-      <Keyword>UefiDriverEntryPoint</Keyword>\r
-    </LibraryClass>\r
-    <LibraryClass Usage="ALWAYS_CONSUMED">\r
-      <Keyword>BaseLib</Keyword>\r
-    </LibraryClass>\r
-    <LibraryClass Usage="ALWAYS_CONSUMED">\r
-      <Keyword>UefiLib</Keyword>\r
-    </LibraryClass>\r
-    <LibraryClass Usage="ALWAYS_CONSUMED">\r
-      <Keyword>BaseMemoryLib</Keyword>\r
-    </LibraryClass>\r
-    <LibraryClass Usage="ALWAYS_CONSUMED">\r
-      <Keyword>MemoryAllocationLib</Keyword>\r
-    </LibraryClass>\r
-    <LibraryClass Usage="ALWAYS_CONSUMED">\r
-      <Keyword>UefiBootServicesTableLib</Keyword>\r
-    </LibraryClass>\r
-  </LibraryClassDefinitions>\r
-  <SourceFiles>\r
-    <Filename>AtapiPassThru.h</Filename>\r
-    <Filename>AtapiPassThru.c</Filename>\r
-    <Filename>ComponentName.c</Filename>\r
-  </SourceFiles>\r
-  <PackageDependencies>\r
-    <Package PackageGuid="1E73767F-8F52-4603-AEB4-F29B510B6766"/>\r
-  </PackageDependencies>\r
-  <Protocols>\r
-    <Protocol Usage="TO_START">\r
-      <ProtocolCName>gEfiPciIoProtocolGuid</ProtocolCName>\r
-    </Protocol>\r
-    <Protocol Usage="BY_START">\r
-      <ProtocolCName>gEfiScsiPassThruProtocolGuid</ProtocolCName>\r
-    </Protocol>\r
-  </Protocols>\r
-  <Externs>\r
-    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
-    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
-    <Extern>\r
-      <DriverBinding>gAtapiScsiPassThruDriverBinding</DriverBinding>\r
-      <ComponentName>gAtapiScsiPassThruComponentName</ComponentName>\r
-    </Extern>\r
-  </Externs>\r
-</ModuleSurfaceArea>\r
diff --git a/MdeModulePkg/Bus/Pci/AtapiPassThru/Dxe/ComponentName.c b/MdeModulePkg/Bus/Pci/AtapiPassThru/Dxe/ComponentName.c
deleted file mode 100644 (file)
index 1731571..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-/** @file\r
-  Copyright (c) 2006, Intel Corporation                                                         \r
-  All rights reserved. This program and the accompanying materials                          \r
-  are licensed and made available under the terms and conditions of the BSD License         \r
-  which accompanies this distribution.  The full text of the license may be found at        \r
-  http://opensource.org/licenses/bsd-license.php                                            \r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
-\r
-  Module Name:  ComponentName.c\r
-\r
-**/\r
-#include "AtapiPassThru.h"\r
-\r
-///\r
-/// EFI Component Name Protocol\r
-///\r
-EFI_COMPONENT_NAME_PROTOCOL     gAtapiScsiPassThruComponentName = {\r
-  AtapiScsiPassThruComponentNameGetDriverName,\r
-  AtapiScsiPassThruComponentNameGetControllerName,\r
-  "eng"\r
-};\r
-\r
-static EFI_UNICODE_STRING_TABLE mAtapiScsiPassThruDriverNameTable[] = {\r
-  { "eng", (CHAR16 *) L"ATAPI SCSI Pass Thru Driver" },\r
-  { NULL , NULL }\r
-};\r
-\r
-/**\r
-  Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
-\r
-  @param  This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
-  @param  Language A pointer to a three character ISO 639-2 language identifier.\r
-  This is the language of the driver name that that the caller\r
-  is requesting, and it must match one of the languages specified\r
-  in SupportedLanguages.  The number of languages supported by a\r
-  driver is up to the driver writer.\r
-  @param  DriverName A pointer to the Unicode string to return.  This Unicode string\r
-  is the name of the driver specified by This in the language\r
-  specified by Language.\r
-\r
-  @retval  EFI_SUCCESS The Unicode string for the Driver specified by This\r
-  and the language specified by Language was returned\r
-  in DriverName.\r
-  @retval  EFI_INVALID_PARAMETER Language is NULL.\r
-  @retval  EFI_INVALID_PARAMETER DriverName is NULL.\r
-  @retval  EFI_UNSUPPORTED The driver specified by This does not support the\r
-  language specified by Language.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruComponentNameGetDriverName (\r
-  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
-  IN  CHAR8                        *Language,\r
-  OUT CHAR16                       **DriverName\r
-  )\r
-{\r
-  return LookupUnicodeString (\r
-          Language,\r
-          gAtapiScsiPassThruComponentName.SupportedLanguages,\r
-          mAtapiScsiPassThruDriverNameTable,\r
-          DriverName\r
-          );\r
-}\r
-\r
-/**\r
-  Retrieves a Unicode string that is the user readable name of the controller\r
-  that is being managed by an EFI Driver.\r
-\r
-  @param  This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
-  @param  ControllerHandle The handle of a controller that the driver specified by\r
-  This is managing.  This handle specifies the controller\r
-  whose name is to be returned.\r
-  @param  ChildHandle The handle of the child controller to retrieve the name\r
-  of.  This is an optional parameter that may be NULL.  It\r
-  will be NULL for device drivers.  It will also be NULL\r
-  for a bus drivers that wish to retrieve the name of the\r
-  bus controller.  It will not be NULL for a bus driver\r
-  that wishes to retrieve the name of a child controller.\r
-  @param  Language A pointer to a three character ISO 639-2 language\r
-  identifier.  This is the language of the controller name\r
-  that that the caller is requesting, and it must match one\r
-  of the languages specified in SupportedLanguages.  The\r
-  number of languages supported by a driver is up to the\r
-  driver writer.\r
-  @param  ControllerName A pointer to the Unicode string to return.  This Unicode\r
-  string is the name of the controller specified by\r
-  ControllerHandle and ChildHandle in the language\r
-  specified by Language from the point of view of the\r
-  driver specified by This.\r
-\r
-  @retval  EFI_SUCCESS The Unicode string for the user readable name in the\r
-  language specified by Language for the driver\r
-  specified by This was returned in DriverName.\r
-  @retval  EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
-  @retval  EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
-  EFI_HANDLE.\r
-  @retval  EFI_INVALID_PARAMETER Language is NULL.\r
-  @retval  EFI_INVALID_PARAMETER ControllerName is NULL.\r
-  @retval  EFI_UNSUPPORTED The driver specified by This is not currently\r
-  managing the controller specified by\r
-  ControllerHandle and ChildHandle.\r
-  @retval  EFI_UNSUPPORTED The driver specified by This does not support the\r
-  language specified by Language.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-AtapiScsiPassThruComponentNameGetControllerName (\r
-  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
-  IN  EFI_HANDLE                                      ControllerHandle,\r
-  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
-  IN  CHAR8                                           *Language,\r
-  OUT CHAR16                                          **ControllerName\r
-  )\r
-{\r
-  return EFI_UNSUPPORTED;\r
-}\r
diff --git a/MdeModulePkg/Bus/Pci/AtapiPassThruDxe/AtapiPassThru.c b/MdeModulePkg/Bus/Pci/AtapiPassThruDxe/AtapiPassThru.c
new file mode 100644 (file)
index 0000000..f14d9e3
--- /dev/null
@@ -0,0 +1,2177 @@
+/** @file\r
+  Copyright (c) 2006, Intel Corporation                                                         \r
+  All rights reserved. This program and the accompanying materials                          \r
+  are licensed and made available under the terms and conditions of the BSD License         \r
+  which accompanies this distribution.  The full text of the license may be found at        \r
+  http://opensource.org/licenses/bsd-license.php                                            \r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+**/\r
+\r
+#include "AtapiPassThru.h"\r
+\r
+///\r
+/// IDE registers' fixed address\r
+///\r
+static IDE_BASE_REGISTERS   gAtapiIoPortRegisters[2] = {\r
+  { 0x1f0, { 0x1f1 }, 0x1f2, 0x1f3, 0x1f4, 0x1f5, 0x1f6, { 0x1f7 }, { 0x3f6 }, 0x3f7, 0 },\r
+  { 0x170, { 0x171 }, 0x172, 0x173, 0x174, 0x175, 0x176, { 0x177 }, { 0x376 }, 0x377, 0 } \r
+};\r
+\r
+static SCSI_COMMAND_SET     gEndTable = { 0xff, (DATA_DIRECTION) 0xff };\r
+\r
+///\r
+/// This table contains all the supported ATAPI commands.\r
+///\r
+static SCSI_COMMAND_SET     gSupportedATAPICommands[] = {\r
+  { OP_INQUIRY,                     DataIn  },\r
+  { OP_LOAD_UNLOAD_CD,              NoData  },\r
+  { OP_MECHANISM_STATUS,            DataIn  },\r
+  { OP_MODE_SELECT_10,              DataOut },\r
+  { OP_MODE_SENSE_10,               DataIn  },\r
+  { OP_PAUSE_RESUME,                NoData  },\r
+  { OP_PLAY_AUDIO_10,               DataIn  },\r
+  { OP_PLAY_AUDIO_MSF,              DataIn  },\r
+  { OP_PLAY_CD,                     DataIn  },\r
+  { OP_PLAY_CD_MSF,                 DataIn  },\r
+  { OP_PREVENT_ALLOW_MEDIUM_REMOVAL,NoData  },\r
+  { OP_READ_10,                     DataIn  },\r
+  { OP_READ_12,                     DataIn  },\r
+  { OP_READ_CAPACITY,               DataIn  },\r
+  { OP_READ_CD,                     DataIn  },\r
+  { OP_READ_CD_MSF,                 DataIn  },\r
+  { OP_READ_HEADER,                 DataIn  },\r
+  { OP_READ_SUB_CHANNEL,            DataIn  },\r
+  { OP_READ_TOC,                    DataIn  },\r
+  { OP_REQUEST_SENSE,               DataIn  },\r
+  { OP_SCAN,                        NoData  },\r
+  { OP_SEEK_10,                     NoData  },\r
+  { OP_SET_CD_SPEED,                DataOut },\r
+  { OP_STOPPLAY_SCAN,               NoData  },\r
+  { OP_START_STOP_UNIT,             NoData  },\r
+  { OP_TEST_UNIT_READY,             NoData  },\r
+  { OP_FORMAT_UNIT,                 DataOut },\r
+  { OP_READ_FORMAT_CAPACITIES,      DataIn  },\r
+  { OP_VERIFY,                      DataOut },\r
+  { OP_WRITE_10,                    DataOut },\r
+  { OP_WRITE_12,                    DataOut },\r
+  { OP_WRITE_AND_VERIFY,            DataOut },\r
+  { 0xff,                           (DATA_DIRECTION) 0xff    } \r
+};\r
+\r
+static CHAR16               *gControllerNameString  = (CHAR16 *) L"ATAPI Controller";\r
+static CHAR16               *gAtapiChannelString    = (CHAR16 *) L"ATAPI Channel";\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gAtapiScsiPassThruDriverBinding = {\r
+  AtapiScsiPassThruDriverBindingSupported,\r
+  AtapiScsiPassThruDriverBindingStart,\r
+  AtapiScsiPassThruDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+/**\r
+  Supported.\r
+\r
+  (Standard DriverBinding Protocol Supported() function)\r
+\r
+  @return EFI_STATUS\r
+\r
+  @todo    This - add argument and description to function comment\r
+  @todo    Controller - add argument and description to function comment\r
+  @todo    RemainingDevicePath - add argument and description to function comment\r
+  @todo    EFI_UNSUPPORTED - add return value to function comment\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  EFI_PCI_IO_PROTOCOL *PciIo;\r
+  PCI_TYPE00          Pci;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiPciIoProtocolGuid,\r
+                  (VOID **) &PciIo,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Use the PCI I/O Protocol to see if Controller is a IDE Controller that\r
+  // can be managed by this driver.  Read the PCI Configuration Header\r
+  // for this device.\r
+  //\r
+  Status = PciIo->Pci.Read (\r
+                        PciIo,\r
+                        EfiPciIoWidthUint32,\r
+                        0,\r
+                        sizeof (Pci) / sizeof (UINT32),\r
+                        &Pci\r
+                        );\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          Controller,\r
+          &gEfiPciIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Controller\r
+          );\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Pci.Hdr.ClassCode[2] != PCI_CLASS_MASS_STORAGE || Pci.Hdr.ClassCode[1] != PCI_CLASS_IDE) {\r
+\r
+    Status = EFI_UNSUPPORTED;\r
+  }\r
+\r
+  gBS->CloseProtocol (\r
+        Controller,\r
+        &gEfiPciIoProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Controller\r
+        );\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Create handles for IDE channels specified by RemainingDevicePath.\r
+  Install SCSI Pass Thru Protocol onto each created handle.\r
+\r
+  (Standard DriverBinding Protocol Start() function)\r
+\r
+  @return EFI_STATUS\r
+\r
+  @todo    This - add argument and description to function comment\r
+  @todo    Controller - add argument and description to function comment\r
+  @todo    RemainingDevicePath - add argument and description to function comment\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  EFI_PCI_IO_PROTOCOL *PciIo;\r
+\r
+  PciIo = NULL;\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiPciIoProtocolGuid,\r
+                  (VOID **) &PciIo,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = PciIo->Attributes (\r
+                    PciIo,\r
+                    EfiPciIoAttributeOperationEnable,\r
+                    EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO | EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO | EFI_PCI_DEVICE_ENABLE,\r
+                    NULL\r
+                    );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // Create SCSI Pass Thru instance for the IDE channel.\r
+  //\r
+  Status = RegisterAtapiScsiPassThru (This, Controller, PciIo);\r
+\r
+Done:\r
+  if (EFI_ERROR (Status)) {\r
+    if (PciIo) {\r
+      PciIo->Attributes (\r
+              PciIo,\r
+              EfiPciIoAttributeOperationDisable,\r
+              EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO | EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO | EFI_PCI_DEVICE_ENABLE,\r
+              NULL\r
+              );\r
+    }\r
+\r
+    gBS->CloseProtocol (\r
+          Controller,\r
+          &gEfiPciIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Controller\r
+          );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Stop.\r
+\r
+  (Standard DriverBinding Protocol Stop() function)\r
+\r
+  @return EFI_STATUS\r
+\r
+  @todo    This - add argument and description to function comment\r
+  @todo    Controller - add argument and description to function comment\r
+  @todo    NumberOfChildren - add argument and description to function comment\r
+  @todo    ChildHandleBuffer - add argument and description to function comment\r
+  @todo    EFI_SUCCESS - add return value to function comment\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      Controller,\r
+  IN  UINTN                           NumberOfChildren,\r
+  IN  EFI_HANDLE                      *ChildHandleBuffer\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_SCSI_PASS_THRU_PROTOCOL *ScsiPassThru;\r
+  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate;\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiScsiPassThruProtocolGuid,\r
+                  (VOID **) &ScsiPassThru,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  AtapiScsiPrivate = ATAPI_SCSI_PASS_THRU_DEV_FROM_THIS (ScsiPassThru);\r
+\r
+  Status = gBS->UninstallProtocolInterface (\r
+                  Controller,\r
+                  &gEfiScsiPassThruProtocolGuid,\r
+                  &AtapiScsiPrivate->ScsiPassThru\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Release Pci Io protocol on the controller handle.\r
+  //\r
+  AtapiScsiPrivate->PciIo->Attributes (\r
+                            AtapiScsiPrivate->PciIo,\r
+                            EfiPciIoAttributeOperationDisable,\r
+                            EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO | EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO | EFI_PCI_DEVICE_ENABLE,\r
+                            NULL\r
+                            );\r
+\r
+  gBS->CloseProtocol (\r
+        Controller,\r
+        &gEfiPciIoProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Controller\r
+        );\r
+\r
+  gBS->FreePool (AtapiScsiPrivate);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Attaches SCSI Pass Thru Protocol for specified IDE channel.\r
+\r
+  @param Controller:       Parent device handle to the IDE channel.\r
+  @param PciIo:            PCI I/O protocol attached on the "Controller".\r
+\r
+  @return EFI_SUCCESS Always returned unless installing SCSI Pass Thru Protocol failed.\r
+\r
+  @todo    This - add argument and description to function comment\r
+  @todo    Controller - add argument and description to function comment\r
+  @todo    PciIo - add argument and description to function comment\r
+  @todo    EFI_OUT_OF_RESOURCES - add return value to function comment\r
+**/\r
+EFI_STATUS\r
+RegisterAtapiScsiPassThru (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                  Controller,\r
+  IN  EFI_PCI_IO_PROTOCOL         *PciIo\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  ATAPI_SCSI_PASS_THRU_DEV  *AtapiScsiPrivate;\r
+  UINT64                    Attributes;\r
+\r
+  AtapiScsiPrivate = AllocateZeroPool (sizeof (ATAPI_SCSI_PASS_THRU_DEV));\r
+  if (AtapiScsiPrivate == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Attributes = EFI_PCI_IO_ATTRIBUTE_IDE_PRIMARY_IO | EFI_PCI_IO_ATTRIBUTE_IDE_SECONDARY_IO | EFI_PCI_DEVICE_ENABLE;\r
+  CopyMem (AtapiScsiPrivate->ChannelName, gAtapiChannelString, sizeof (gAtapiChannelString));\r
+\r
+  //\r
+  // Enable channel\r
+  //\r
+  PciIo->Attributes (PciIo, EfiPciIoAttributeOperationSet, Attributes, NULL);\r
+\r
+  AtapiScsiPrivate->Signature = ATAPI_SCSI_PASS_THRU_DEV_SIGNATURE;\r
+  AtapiScsiPrivate->Handle    = Controller;\r
+\r
+  //\r
+  // will reset the IoPort inside each API function.\r
+  //\r
+  AtapiScsiPrivate->IoPort  = gAtapiIoPortRegisters;\r
+  AtapiScsiPrivate->PciIo   = PciIo;\r
+\r
+  //\r
+  // initialize SCSI Pass Thru Protocol interface\r
+  //\r
+  AtapiScsiPrivate->ScsiPassThru.Mode             = &AtapiScsiPrivate->ScsiPassThruMode;\r
+  AtapiScsiPrivate->ScsiPassThru.PassThru         = AtapiScsiPassThruFunction;\r
+  AtapiScsiPrivate->ScsiPassThru.GetNextDevice    = AtapiScsiPassThruGetNextDevice;\r
+  AtapiScsiPrivate->ScsiPassThru.BuildDevicePath  = AtapiScsiPassThruBuildDevicePath;\r
+  AtapiScsiPrivate->ScsiPassThru.GetTargetLun     = AtapiScsiPassThruGetTargetLun;\r
+  AtapiScsiPrivate->ScsiPassThru.ResetChannel     = AtapiScsiPassThruResetChannel;\r
+  AtapiScsiPrivate->ScsiPassThru.ResetTarget      = AtapiScsiPassThruResetTarget;\r
+\r
+  //\r
+  // Set Mode\r
+  //\r
+  CopyMem (AtapiScsiPrivate->ControllerName, gControllerNameString, sizeof (gControllerNameString));\r
+\r
+  AtapiScsiPrivate->ScsiPassThruMode.ControllerName = AtapiScsiPrivate->ControllerName;\r
+  AtapiScsiPrivate->ScsiPassThruMode.ChannelName    = AtapiScsiPrivate->ChannelName;\r
+  AtapiScsiPrivate->ScsiPassThruMode.AdapterId      = 4;\r
+  //\r
+  // non-RAID SCSI controllers should set both physical and logical attributes\r
+  //\r
+  AtapiScsiPrivate->ScsiPassThruMode.Attributes = EFI_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL | \r
+                                                  EFI_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL;\r
+  AtapiScsiPrivate->ScsiPassThruMode.IoAlign = 0;\r
+\r
+  //\r
+  // Initialize the LatestTargetId to 0xFFFFFFFF (for the GetNextDevice() call).\r
+  //\r
+  AtapiScsiPrivate->LatestTargetId  = 0xFFFFFFFF;\r
+  AtapiScsiPrivate->LatestLun       = 0;\r
+\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &Controller,\r
+                  &gEfiScsiPassThruProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &AtapiScsiPrivate->ScsiPassThru\r
+                  );\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Implements EFI_SCSI_PASS_THRU_PROTOCOL.PassThru() function.\r
+\r
+  @param This     The EFI_SCSI_PASS_THRU_PROTOCOL instance.\r
+  @param Target   The Target ID of the ATAPI device to send the SCSI\r
+  Request Packet. To ATAPI devices attached on an IDE\r
+  Channel, Target ID 0 indicates Master device;Target\r
+  ID 1 indicates Slave device.\r
+  @param Lun      The LUN of the ATAPI device to send the SCSI Request\r
+  Packet. To the ATAPI device, Lun is always 0.\r
+  @param Packet   The SCSI Request Packet to send to the ATAPI device\r
+  specified by Target and Lun.\r
+  @param Event    If non-blocking I/O is not supported then Event is ignored,\r
+  and blocking I/O is performed.<br>\r
+  If Event is NULL, then blocking I/O is performed.<br>\r
+  If Event is not NULL and non blocking I/O is supported,\r
+  then non-blocking I/O is performed, and Event will be signaled\r
+  when the SCSI Request Packet completes.\r
+\r
+  @todo    This - add argument and description to function comment\r
+  @todo    EFI_INVALID_PARAMETER - add return value to function comment\r
+  @todo    EFI_SUCCESS - add return value to function comment\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruFunction (\r
+  IN EFI_SCSI_PASS_THRU_PROTOCOL                        *This,\r
+  IN UINT32                                             Target,\r
+  IN UINT64                                             Lun,\r
+  IN OUT EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET         *Packet,\r
+  IN EFI_EVENT                                          Event OPTIONAL\r
+  )\r
+{\r
+  ATAPI_SCSI_PASS_THRU_DEV  *AtapiScsiPrivate;\r
+  EFI_STATUS                Status;\r
+\r
+  AtapiScsiPrivate = ATAPI_SCSI_PASS_THRU_DEV_FROM_THIS (This);\r
+\r
+  //\r
+  // Target is not allowed beyond MAX_TARGET_ID\r
+  //\r
+  if (Target > MAX_TARGET_ID) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  //\r
+  // check the data fields in Packet parameter.\r
+  //\r
+  Status = CheckSCSIRequestPacket (Packet);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // If Request Packet targets at the IDE channel itself,\r
+  // do nothing.\r
+  //\r
+  if (Target == This->Mode->AdapterId) {\r
+    Packet->TransferLength = 0;\r
+    return EFI_SUCCESS;\r
+  }\r
+  \r
+  //\r
+  // According to Target ID, reset the Atapi I/O Register mapping\r
+  // (Target Id in [0,1] area, using gAtapiIoPortRegisters[0],\r
+  //  Target Id in [2,3] area, using gAtapiIoPortRegisters[1]\r
+  //\r
+  if ((Target / 2) == 0) {\r
+    AtapiScsiPrivate->IoPort = &gAtapiIoPortRegisters[0];\r
+  } else {\r
+    AtapiScsiPrivate->IoPort = &gAtapiIoPortRegisters[1];\r
+  }\r
+  \r
+  //\r
+  // the ATAPI SCSI interface does not support non-blocking I/O\r
+  // ignore the Event parameter\r
+  //\r
+  // Performs blocking I/O.\r
+  //\r
+  Status = SubmitBlockingIoCommand (AtapiScsiPrivate, Target, Packet);\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Used to retrieve the list of legal Target IDs for SCSI devices \r
+  on a SCSI channel.\r
+\r
+  @param  This Protocol instance pointer.\r
+  @param  Target On input, a pointer to the Target ID of a SCSI\r
+  device present on the SCSI channel.  On output,\r
+  a pointer to the Target ID of the next SCSI device\r
+  present on a SCSI channel.  An input value of\r
+  0xFFFFFFFF retrieves the Target ID of the first\r
+  SCSI device present on a SCSI channel.\r
+  @param  Lun On input, a pointer to the LUN of a SCSI device\r
+  present on the SCSI channel. On output, a pointer\r
+  to the LUN of the next SCSI device present on\r
+  a SCSI channel.\r
+\r
+  @retval  EFI_SUCCESS The Target ID and Lun of the next SCSI device\r
+  on the SCSI channel was returned in Target and Lun.\r
+  @retval  EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.\r
+  @retval  EFI_INVALID_PARAMETER Target is not 0xFFFFFFFF,and Target and Lun were not\r
+  returned on a previous call to GetNextDevice().\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruGetNextDevice (\r
+  IN  EFI_SCSI_PASS_THRU_PROTOCOL    *This,\r
+  IN OUT UINT32                      *Target,\r
+  IN OUT UINT64                      *Lun\r
+  )\r
+{\r
+  ATAPI_SCSI_PASS_THRU_DEV  *AtapiScsiPrivate;\r
+\r
+  //\r
+  // Retrieve Device Private Data Structure.\r
+  //\r
+  AtapiScsiPrivate = ATAPI_SCSI_PASS_THRU_DEV_FROM_THIS (This);\r
+\r
+  //\r
+  // Check whether Target is valid.\r
+  //\r
+  if (Target == NULL || Lun == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if ((*Target != 0xFFFFFFFF) &&\r
+      ((*Target != AtapiScsiPrivate->LatestTargetId) ||\r
+      (*Lun != AtapiScsiPrivate->LatestLun))) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (*Target == MAX_TARGET_ID) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  if (*Target == 0xFFFFFFFF) {\r
+    *Target = 0;\r
+  } else {\r
+    *Target = AtapiScsiPrivate->LatestTargetId + 1;\r
+  }\r
+\r
+  *Lun = 0;\r
+\r
+  //\r
+  // Update the LatestTargetId.\r
+  //\r
+  AtapiScsiPrivate->LatestTargetId  = *Target;\r
+  AtapiScsiPrivate->LatestLun       = *Lun;\r
+\r
+  return EFI_SUCCESS;\r
+\r
+}\r
+\r
+/**\r
+  Used to allocate and build a device path node for a SCSI device \r
+  on a SCSI channel. Would not build device path for a SCSI Host Controller.\r
+\r
+  @param  This Protocol instance pointer.\r
+  @param  Target The Target ID of the SCSI device for which\r
+  a device path node is to be allocated and built.\r
+  @param  Lun The LUN of the SCSI device for which a device\r
+  path node is to be allocated and built.\r
+  @param  DevicePath A pointer to a single device path node that\r
+  describes the SCSI device specified by\r
+  Target and Lun. This function is responsible\r
+  for allocating the buffer DevicePath with the boot\r
+  service AllocatePool().  It is the caller's\r
+  responsibility to free DevicePath when the caller\r
+  is finished with DevicePath.\r
+\r
+  @retval  EFI_SUCCESS The device path node that describes the SCSI device\r
+  specified by Target and Lun was allocated and\r
+  returned in DevicePath.\r
+  @retval  EFI_NOT_FOUND The SCSI devices specified by Target and Lun does\r
+  not exist on the SCSI channel.\r
+  @retval  EFI_INVALID_PARAMETER DevicePath is NULL.\r
+  @retval  EFI_OUT_OF_RESOURCES There are not enough resources to allocate\r
+  DevicePath.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruBuildDevicePath (\r
+  IN     EFI_SCSI_PASS_THRU_PROTOCOL    *This,\r
+  IN     UINT32                         Target,\r
+  IN     UINT64                         Lun,\r
+  IN OUT EFI_DEVICE_PATH_PROTOCOL       **DevicePath\r
+  )\r
+{\r
+  EFI_DEV_PATH              *Node;\r
+\r
+  //\r
+  // Validate parameters passed in.\r
+  //\r
+  \r
+  if (DevicePath == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  //\r
+  // can not build device path for the SCSI Host Controller.\r
+  //\r
+  if ((Target > (MAX_TARGET_ID - 1)) || (Lun != 0)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  Node = AllocateZeroPool (sizeof (EFI_DEV_PATH));\r
+  if (Node == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Node->DevPath.Type    = MESSAGING_DEVICE_PATH;\r
+  Node->DevPath.SubType = MSG_ATAPI_DP;\r
+  SetDevicePathNodeLength (&Node->DevPath, sizeof (ATAPI_DEVICE_PATH));\r
+\r
+  Node->Atapi.PrimarySecondary  = (UINT8) (Target / 2);\r
+  Node->Atapi.SlaveMaster       = (UINT8) (Target % 2);\r
+  Node->Atapi.Lun               = (UINT16) Lun;\r
+\r
+  *DevicePath                   = (EFI_DEVICE_PATH_PROTOCOL *) Node;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Used to translate a device path node to a Target ID and LUN.\r
+\r
+  @param  This Protocol instance pointer.\r
+  @param  DevicePath A pointer to the device path node that\r
+  describes a SCSI device on the SCSI channel.\r
+  @param  Target A pointer to the Target ID of a SCSI device\r
+  on the SCSI channel.\r
+  @param  Lun A pointer to the LUN of a SCSI device on\r
+  the SCSI channel.\r
+\r
+  @retval  EFI_SUCCESS DevicePath was successfully translated to a\r
+  Target ID and LUN, and they were returned\r
+  in Target and Lun.\r
+  @retval  EFI_INVALID_PARAMETER DevicePath is NULL.\r
+  @retval  EFI_INVALID_PARAMETER Target is NULL.\r
+  @retval  EFI_INVALID_PARAMETER Lun is NULL.\r
+  @retval  EFI_UNSUPPORTED This driver does not support the device path\r
+  node type in DevicePath.\r
+  @retval  EFI_NOT_FOUND A valid translation from DevicePath to a\r
+  Target ID and LUN does not exist.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruGetTargetLun (\r
+  IN  EFI_SCSI_PASS_THRU_PROTOCOL    *This,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL       *DevicePath,\r
+  OUT UINT32                         *Target,\r
+  OUT UINT64                         *Lun\r
+  )\r
+{\r
+  EFI_DEV_PATH  *Node;\r
+\r
+  //\r
+  // Validate parameters passed in.\r
+  //\r
+  if (DevicePath == NULL || Target == NULL || Lun == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  //\r
+  // Check whether the DevicePath belongs to SCSI_DEVICE_PATH\r
+  //\r
+  if ((DevicePath->Type != MESSAGING_DEVICE_PATH) ||\r
+      (DevicePath->SubType != MSG_ATAPI_DP) ||\r
+      (DevicePathNodeLength(DevicePath) != sizeof(ATAPI_DEVICE_PATH))) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Node    = (EFI_DEV_PATH *) DevicePath;\r
+\r
+  *Target = Node->Atapi.PrimarySecondary * 2 + Node->Atapi.SlaveMaster;\r
+  *Lun    = Node->Atapi.Lun;\r
+\r
+  if (*Target > (MAX_TARGET_ID - 1) || *Lun != 0) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Resets a SCSI channel.This operation resets all the \r
+  SCSI devices connected to the SCSI channel.\r
+\r
+  @param  This Protocol instance pointer.\r
+\r
+  @retval  EFI_SUCCESS The SCSI channel was reset.\r
+  @retval  EFI_UNSUPPORTED The SCSI channel does not support\r
+  a channel reset operation.\r
+  @retval  EFI_DEVICE_ERROR A device error occurred while\r
+  attempting to reset the SCSI channel.\r
+  @retval  EFI_TIMEOUT A timeout occurred while attempting\r
+  to reset the SCSI channel.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruResetChannel (\r
+  IN  EFI_SCSI_PASS_THRU_PROTOCOL   *This\r
+  )\r
+{\r
+  UINT8                     DeviceControlValue;\r
+  ATAPI_SCSI_PASS_THRU_DEV  *AtapiScsiPrivate;\r
+  UINT8                     Index;\r
+\r
+  AtapiScsiPrivate = ATAPI_SCSI_PASS_THRU_DEV_FROM_THIS (This);\r
+\r
+  //\r
+  // Reset both Primary channel and Secondary channel.\r
+  // so, the IoPort pointer must point to the right I/O Register group\r
+  //\r
+  for (Index = 0; Index < 2; Index++) {\r
+    //\r
+    // Reset\r
+    //\r
+    AtapiScsiPrivate->IoPort  = &gAtapiIoPortRegisters[Index];\r
+\r
+    DeviceControlValue        = 0;\r
+    //\r
+    // set SRST bit to initiate soft reset\r
+    //\r
+    DeviceControlValue |= SRST;\r
+    //\r
+    // disable Interrupt\r
+    //\r
+    DeviceControlValue |= bit (1);\r
+    WritePortB (\r
+      AtapiScsiPrivate->PciIo,\r
+      AtapiScsiPrivate->IoPort->Alt.DeviceControl,\r
+      DeviceControlValue\r
+      );\r
+\r
+    //\r
+    // Wait 10us\r
+    //\r
+    gBS->Stall (10);\r
+\r
+    //\r
+    // Clear SRST bit\r
+    // 0xfb:1111,1011\r
+    //\r
+    DeviceControlValue &= 0xfb;\r
+    \r
+    WritePortB (AtapiScsiPrivate->PciIo, AtapiScsiPrivate->IoPort->Alt.DeviceControl, DeviceControlValue);\r
+\r
+    //\r
+    // slave device needs at most 31s to clear BSY\r
+    //\r
+    if (StatusWaitForBSYClear (AtapiScsiPrivate, 31000) == EFI_TIMEOUT) {\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Resets a SCSI device that is connected to a SCSI channel.\r
+\r
+  @param  This Protocol instance pointer.\r
+  @param  Target The Target ID of the SCSI device to reset.\r
+  @param  Lun The LUN of the SCSI device to reset.\r
+\r
+  @retval  EFI_SUCCESS The SCSI device specified by Target and\r
+  Lun was reset.\r
+  @retval  EFI_UNSUPPORTED The SCSI channel does not support a target\r
+  reset operation.\r
+  @retval  EFI_INVALID_PARAMETER Target or Lun are invalid.\r
+  @retval  EFI_DEVICE_ERROR A device error occurred while attempting\r
+  to reset the SCSI device specified by Target\r
+  and Lun.\r
+  @retval  EFI_TIMEOUT A timeout occurred while attempting to reset\r
+  the SCSI device specified by Target and Lun.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruResetTarget (\r
+  IN EFI_SCSI_PASS_THRU_PROTOCOL    *This,\r
+  IN UINT32                         Target,\r
+  IN UINT64                         Lun\r
+  )\r
+{\r
+  ATAPI_SCSI_PASS_THRU_DEV  *AtapiScsiPrivate;\r
+  UINT8                     Command;\r
+  UINT8                     DeviceSelect;\r
+\r
+  AtapiScsiPrivate = ATAPI_SCSI_PASS_THRU_DEV_FROM_THIS (This);\r
+\r
+  if (Target > MAX_TARGET_ID) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Directly return EFI_SUCCESS if want to reset the host controller\r
+  //\r
+  if (Target == This->Mode->AdapterId) {\r
+    return EFI_SUCCESS;\r
+  }\r
+  \r
+  //\r
+  // According to Target ID, reset the Atapi I/O Register mapping\r
+  // (Target Id in [0,1] area, using gAtapiIoPortRegisters[0],\r
+  //  Target Id in [2,3] area, using gAtapiIoPortRegisters[1]\r
+  //\r
+  if ((Target / 2) == 0) {\r
+    AtapiScsiPrivate->IoPort = &gAtapiIoPortRegisters[0];\r
+  } else {\r
+    AtapiScsiPrivate->IoPort = &gAtapiIoPortRegisters[1];\r
+  }\r
+  \r
+  //\r
+  // for ATAPI device, no need to wait DRDY ready after device selecting.\r
+  //\r
+  // bit7 and bit5 are both set to 1 for backward compatibility\r
+  //\r
+  DeviceSelect = (UINT8) (((bit (7) | bit (5)) | (Target << 4)));\r
+  WritePortB (AtapiScsiPrivate->PciIo, AtapiScsiPrivate->IoPort->Head, DeviceSelect);\r
+\r
+  Command = ATAPI_SOFT_RESET_CMD;\r
+  WritePortB (AtapiScsiPrivate->PciIo, AtapiScsiPrivate->IoPort->Reg.Command, Command);\r
+\r
+  //\r
+  // BSY clear is the only status return to the host by the device\r
+  // when reset is complete.\r
+  // slave device needs at most 31s to clear BSY\r
+  //\r
+  if (EFI_ERROR (StatusWaitForBSYClear (AtapiScsiPrivate, 31000))) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+  \r
+  //\r
+  // stall 5 seconds to make the device status stable\r
+  //\r
+  gBS->Stall (5000000);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+    \r
+/**\r
+  Checks the parameters in the SCSI Request Packet to make sure\r
+  they are valid for a SCSI Pass Thru request.\r
+\r
+  @todo function comment is missing 'Routine Description:'\r
+  @todo function comment is missing 'Arguments:'\r
+  @todo function comment is missing 'Returns:'\r
+  @todo    Packet - add argument and description to function comment\r
+  @todo    EFI_INVALID_PARAMETER - add return value to function comment\r
+  @todo    EFI_INVALID_PARAMETER - add return value to function comment\r
+  @todo    EFI_INVALID_PARAMETER - add return value to function comment\r
+  @todo    EFI_UNSUPPORTED - add return value to function comment\r
+  @todo    EFI_SUCCESS - add return value to function comment\r
+**/\r
+EFI_STATUS\r
+CheckSCSIRequestPacket (\r
+  EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET      *Packet\r
+  )\r
+{\r
+  if (Packet == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (!ValidCdbLength (Packet->CdbLength)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (Packet->Cdb == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  //\r
+  // Checks whether the request command is supported.\r
+  //\r
+  if (!IsCommandValid (Packet)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Checks the requested SCSI command: \r
+  Is it supported by this driver?\r
+  Is the Data transfer direction reasonable?\r
+\r
+  @todo function comment is missing 'Routine Description:'\r
+  @todo function comment is missing 'Arguments:'\r
+  @todo function comment is missing 'Returns:'\r
+  @todo    Packet - add argument and description to function comment\r
+**/\r
+BOOLEAN\r
+IsCommandValid (\r
+  EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET   *Packet\r
+  )\r
+{\r
+  UINT8 Index;\r
+  UINT8 *OpCode;\r
+\r
+  OpCode = (UINT8 *) (Packet->Cdb);\r
+\r
+  for (Index = 0; CompareMem (&gSupportedATAPICommands[Index], &gEndTable, sizeof (SCSI_COMMAND_SET)); Index++) {\r
+\r
+    if (*OpCode == gSupportedATAPICommands[Index].OpCode) {\r
+      //\r
+      // Check whether the requested Command is supported by this driver\r
+      //\r
+      if (Packet->DataDirection == DataIn) {\r
+        //\r
+        // Check whether the requested data direction conforms to\r
+        // what it should be.\r
+        //\r
+        if (gSupportedATAPICommands[Index].Direction == DataOut) {\r
+          return FALSE;\r
+        }\r
+      }\r
+\r
+      if (Packet->DataDirection == DataOut) {\r
+        //\r
+        // Check whether the requested data direction conforms to\r
+        // what it should be.\r
+        //\r
+        if (gSupportedATAPICommands[Index].Direction == DataIn) {\r
+          return FALSE;\r
+        }\r
+      }\r
+\r
+      return TRUE;\r
+    }\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  Performs blocking I/O request.\r
+\r
+  @param AtapiScsiPrivate   Private data structure for the specified channel.\r
+  @param Target             The Target ID of the ATAPI device to send the SCSI\r
+  Request Packet. To ATAPI devices attached on an IDE\r
+  Channel, Target ID 0 indicates Master device;Target\r
+  ID 1 indicates Slave device.\r
+  @param Packet             The SCSI Request Packet to send to the ATAPI device\r
+  specified by Target.\r
+\r
+  @todo    AtapiScsiPrivate - add argument and description to function comment\r
+**/\r
+EFI_STATUS\r
+SubmitBlockingIoCommand (\r
+  ATAPI_SCSI_PASS_THRU_DEV                  *AtapiScsiPrivate,\r
+  UINT32                                    Target,\r
+  EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET    *Packet\r
+  )\r
+{\r
+  UINT8       PacketCommand[12];\r
+  UINT64      TimeoutInMicroSeconds;\r
+  EFI_STATUS  PacketCommandStatus;\r
+\r
+  //\r
+  // Fill ATAPI Command Packet according to CDB\r
+  //\r
+  ZeroMem (&PacketCommand, 12);\r
+  CopyMem (&PacketCommand, Packet->Cdb, Packet->CdbLength);\r
+\r
+  //\r
+  // Timeout is 100ns unit, convert it to 1000ns (1us) unit.\r
+  //\r
+  TimeoutInMicroSeconds = DivU64x32 (Packet->Timeout, (UINT32) 10);\r
+\r
+  //\r
+  // Submit ATAPI Command Packet\r
+  //\r
+  PacketCommandStatus = AtapiPacketCommand (\r
+                          AtapiScsiPrivate,\r
+                          Target,\r
+                          PacketCommand,\r
+                          Packet->DataBuffer,\r
+                          &(Packet->TransferLength),\r
+                          (DATA_DIRECTION) Packet->DataDirection,\r
+                          TimeoutInMicroSeconds\r
+                          );\r
+  if (!EFI_ERROR (PacketCommandStatus) || (Packet->SenseData == NULL)) {\r
+    Packet->SenseDataLength = 0;\r
+    return PacketCommandStatus;\r
+  }\r
+  //\r
+  // Return SenseData if PacketCommandStatus matches\r
+  // the following return codes.\r
+  //\r
+  if ((PacketCommandStatus == EFI_WARN_BUFFER_TOO_SMALL) ||\r
+      (PacketCommandStatus == EFI_DEVICE_ERROR) ||\r
+      (PacketCommandStatus == EFI_TIMEOUT)) {\r
+    \r
+    //\r
+    // avoid submit request sense command continuously.\r
+    //\r
+    if (PacketCommand[0] == OP_REQUEST_SENSE) {\r
+      Packet->SenseDataLength = 0;\r
+      return PacketCommandStatus;\r
+    }\r
+\r
+    RequestSenseCommand (\r
+      AtapiScsiPrivate,\r
+      Target,\r
+      Packet->Timeout,\r
+      Packet->SenseData,\r
+      &Packet->SenseDataLength\r
+      );\r
+  }\r
+\r
+  return PacketCommandStatus;\r
+}\r
+\r
+/**\r
+  RequestSenseCommand\r
+\r
+  @param  AtapiScsiPrivate\r
+  @param  Target\r
+  @param  Timeout\r
+  @param  SenseData\r
+  @param  SenseDataLength\r
+\r
+  @todo Add function description\r
+  @todo  AtapiScsiPrivate TODO: add argument description\r
+  @todo  Target TODO: add argument description\r
+  @todo  Timeout TODO: add argument description\r
+  @todo  SenseData TODO: add argument description\r
+  @todo  SenseDataLength TODO: add argument description\r
+  @todo add return values\r
+**/\r
+EFI_STATUS\r
+RequestSenseCommand (\r
+  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate,\r
+  UINT32                      Target,\r
+  UINT64                      Timeout,\r
+  VOID                        *SenseData,\r
+  UINT8                       *SenseDataLength\r
+  )\r
+{\r
+  EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET  Packet;\r
+  UINT8                                   Cdb[12];\r
+  EFI_STATUS                              Status;\r
+\r
+  ZeroMem (&Packet, sizeof (EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET));\r
+  ZeroMem (Cdb, 12);\r
+\r
+  Cdb[0]                = OP_REQUEST_SENSE;\r
+  Cdb[4]                = (UINT8) (*SenseDataLength);\r
+\r
+  Packet.Timeout        = Timeout;\r
+  Packet.DataBuffer     = SenseData;\r
+  Packet.SenseData      = NULL;\r
+  Packet.Cdb            = Cdb;\r
+  Packet.TransferLength = *SenseDataLength;\r
+  Packet.CdbLength      = 12;\r
+  Packet.DataDirection  = DataIn;\r
+\r
+  Status                = SubmitBlockingIoCommand (AtapiScsiPrivate, Target, &Packet);\r
+  *SenseDataLength      = (UINT8) (Packet.TransferLength);\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Submits ATAPI command packet to the specified ATAPI device.\r
+\r
+  @param AtapiScsiPrivate:   Private data structure for the specified channel.\r
+  @param Target:             The Target ID of the ATAPI device to send the SCSI\r
+  Request Packet. To ATAPI devices attached on an IDE\r
+  Channel, Target ID 0 indicates Master device;Target\r
+  ID 1 indicates Slave device.\r
+  @param PacketCommand:      Points to the ATAPI command packet.\r
+  @param Buffer:             Points to the transferred data.\r
+  @param ByteCount:          When input,indicates the buffer size; when output,\r
+  indicates the actually transferred data size.\r
+  @param Direction:          Indicates the data transfer direction.\r
+  @param TimeoutInMicroSeconds: The timeout, in micro second units,\r
+  to use for the execution of this ATAPI command.\r
+  A TimeoutInMicroSeconds value of 0 means that\r
+  this function will wait indefinitely for the ATAPI\r
+  command to execute.\r
+  <P>\r
+  If TimeoutInMicroSeconds is greater than zero, then\r
+  this function will return EFI_TIMEOUT if the time\r
+  required to execute the ATAPI command is greater\r
+  than TimeoutInMicroSeconds.\r
+  </P>\r
+\r
+  @todo    AtapiScsiPrivate - add argument and description to function comment\r
+  @todo    PacketCommand - add argument and description to function comment\r
+  @todo    Buffer - add argument and description to function comment\r
+  @todo    ByteCount - add argument and description to function comment\r
+  @todo    Direction - add argument and description to function comment\r
+**/\r
+EFI_STATUS\r
+AtapiPacketCommand (\r
+  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate,\r
+  UINT32                      Target,\r
+  UINT8                       *PacketCommand,\r
+  VOID                        *Buffer,\r
+  UINT32                      *ByteCount,\r
+  DATA_DIRECTION              Direction,\r
+  UINT64                      TimeoutInMicroSeconds\r
+  )\r
+{\r
+\r
+  UINT16      *CommandIndex;\r
+  UINT8       Count;\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Set all the command parameters by fill related registers.\r
+  // Before write to all the following registers, BSY and DRQ must be 0.\r
+  //\r
+  Status = StatusDRQClear (AtapiScsiPrivate, TimeoutInMicroSeconds);\r
+  if (EFI_ERROR (Status)) {\r
+    if (Status == EFI_ABORTED) {\r
+      Status = EFI_DEVICE_ERROR;\r
+    }\r
+\r
+    *ByteCount = 0;\r
+    return Status;\r
+  }\r
+  //\r
+  // Select device via Device/Head Register.\r
+  // "Target = 0" indicates device 0; "Target = 1" indicates device 1\r
+  //\r
+  WritePortB (\r
+    AtapiScsiPrivate->PciIo,\r
+    AtapiScsiPrivate->IoPort->Head,\r
+    (UINT8) ((Target << 4) | DEFAULT_CMD) // DEFAULT_CMD: 0xa0 (1010,0000)\r
+    );\r
+\r
+  //\r
+  // No OVL; No DMA (by setting feature register)\r
+  //\r
+  WritePortB (\r
+    AtapiScsiPrivate->PciIo,\r
+    AtapiScsiPrivate->IoPort->Reg1.Feature,\r
+    0x00\r
+    );\r
+\r
+  //\r
+  // set the transfersize to MAX_ATAPI_BYTE_COUNT to let the device\r
+  // determine how much data should be transfered.\r
+  //\r
+  WritePortB (\r
+    AtapiScsiPrivate->PciIo,\r
+    AtapiScsiPrivate->IoPort->CylinderLsb,\r
+    (UINT8) (MAX_ATAPI_BYTE_COUNT & 0x00ff)\r
+    );\r
+  WritePortB (\r
+    AtapiScsiPrivate->PciIo,\r
+    AtapiScsiPrivate->IoPort->CylinderMsb,\r
+    (UINT8) (MAX_ATAPI_BYTE_COUNT >> 8)\r
+    );\r
+\r
+  //\r
+  //  DEFAULT_CTL:0x0a (0000,1010)\r
+  //  Disable interrupt\r
+  //\r
+  WritePortB (\r
+    AtapiScsiPrivate->PciIo,\r
+    AtapiScsiPrivate->IoPort->Alt.DeviceControl,\r
+    DEFAULT_CTL\r
+    );\r
+\r
+  //\r
+  // Send Packet command to inform device\r
+  // that the following data bytes are command packet.\r
+  //\r
+  WritePortB (\r
+    AtapiScsiPrivate->PciIo,\r
+    AtapiScsiPrivate->IoPort->Reg.Command,\r
+    PACKET_CMD\r
+    );\r
+\r
+  //\r
+  // Before data transfer, BSY should be 0 and DRQ should be 1.\r
+  // if they are not in specified time frame,\r
+  // retrieve Sense Key from Error Register before return.\r
+  //\r
+  Status = StatusDRQReady (AtapiScsiPrivate, TimeoutInMicroSeconds);\r
+  if (EFI_ERROR (Status)) {\r
+    if (Status == EFI_ABORTED) {\r
+      Status = EFI_DEVICE_ERROR;\r
+    }\r
+\r
+    *ByteCount = 0;\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Send out command packet\r
+  //\r
+  CommandIndex = (UINT16 *) PacketCommand;\r
+  for (Count = 0; Count < 6; Count++, CommandIndex++) {\r
+    WritePortW (AtapiScsiPrivate->PciIo, AtapiScsiPrivate->IoPort->Data, *CommandIndex);\r
+  }\r
+\r
+  //\r
+  // call AtapiPassThruPioReadWriteData() function to get\r
+  // requested transfer data form device.\r
+  //\r
+  return AtapiPassThruPioReadWriteData (\r
+          AtapiScsiPrivate,\r
+          Buffer,\r
+          ByteCount,\r
+          Direction,\r
+          TimeoutInMicroSeconds\r
+          );\r
+}\r
+\r
+/**\r
+  Performs data transfer between ATAPI device and host after the\r
+  ATAPI command packet is sent.\r
+\r
+  @param AtapiScsiPrivate:   Private data structure for the specified channel.\r
+  @param Buffer:             Points to the transferred data.\r
+  @param ByteCount:          When input,indicates the buffer size; when output,\r
+  indicates the actually transferred data size.\r
+  @param Direction:          Indicates the data transfer direction.\r
+  @param TimeoutInMicroSeconds: The timeout, in micro second units,\r
+  to use for the execution of this ATAPI command.\r
+  A TimeoutInMicroSeconds value of 0 means that\r
+  this function will wait indefinitely for the ATAPI\r
+  command to execute.\r
+  <P>\r
+  If TimeoutInMicroSeconds is greater than zero, then\r
+  this function will return EFI_TIMEOUT if the time\r
+  required to execute the ATAPI command is greater\r
+  than TimeoutInMicroSeconds.\r
+  </P>\r
+\r
+  @todo    AtapiScsiPrivate - add argument and description to function comment\r
+  @todo    Buffer - add argument and description to function comment\r
+  @todo    ByteCount - add argument and description to function comment\r
+  @todo    Direction - add argument and description to function comment\r
+  @todo    EFI_DEVICE_ERROR - add return value to function comment\r
+  @todo    EFI_DEVICE_ERROR - add return value to function comment\r
+  @todo    EFI_WARN_BUFFER_TOO_SMALL - add return value to function comment\r
+**/\r
+EFI_STATUS\r
+AtapiPassThruPioReadWriteData (\r
+  ATAPI_SCSI_PASS_THRU_DEV  *AtapiScsiPrivate,\r
+  UINT16                    *Buffer,\r
+  UINT32                    *ByteCount,\r
+  DATA_DIRECTION            Direction,\r
+  UINT64                    TimeoutInMicroSeconds\r
+  )\r
+{\r
+  UINT32      Index;\r
+  UINT32      RequiredWordCount;\r
+  UINT32      ActualWordCount;\r
+\r
+  UINT32      WordCount;\r
+  EFI_STATUS  Status;\r
+  UINT16      *ptrBuffer;\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
+  //\r
+  // Non Data transfer request is also supported.\r
+  //\r
+  if (*ByteCount == 0 || Buffer == NULL) {\r
+    *ByteCount = 0;\r
+    if (EFI_ERROR (StatusWaitForBSYClear (AtapiScsiPrivate, TimeoutInMicroSeconds))) {\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+  }\r
+\r
+  ptrBuffer         = Buffer;\r
+  RequiredWordCount = *ByteCount / 2;\r
+\r
+  //\r
+  // ActuralWordCount means the word count of data really transfered.\r
+  //\r
+  ActualWordCount = 0;\r
+\r
+  while (ActualWordCount < RequiredWordCount) {\r
+    //\r
+    // before each data transfer stream, the host should poll DRQ bit ready,\r
+    // which indicates device's ready for data transfer .\r
+    //\r
+    Status = StatusDRQReady (AtapiScsiPrivate, TimeoutInMicroSeconds);\r
+    if (EFI_ERROR (Status)) {\r
+      *ByteCount = ActualWordCount * 2;\r
+\r
+      AtapiPassThruCheckErrorStatus (AtapiScsiPrivate);\r
+\r
+      if (ActualWordCount == 0) {\r
+        return EFI_DEVICE_ERROR;\r
+      }\r
+      //\r
+      // ActualWordCount > 0\r
+      //\r
+      if (ActualWordCount < RequiredWordCount) {\r
+        return EFI_WARN_BUFFER_TOO_SMALL;\r
+      }\r
+    }\r
+    //\r
+    // get current data transfer size from Cylinder Registers.\r
+    //\r
+    WordCount = ReadPortB (AtapiScsiPrivate->PciIo, AtapiScsiPrivate->IoPort->CylinderMsb) << 8;\r
+    WordCount = WordCount | ReadPortB (AtapiScsiPrivate->PciIo, AtapiScsiPrivate->IoPort->CylinderLsb);\r
+    WordCount = WordCount & 0xffff;\r
+    WordCount /= 2;\r
+\r
+    //\r
+    // perform a series data In/Out.\r
+    //\r
+    for (Index = 0; (Index < WordCount) && (ActualWordCount < RequiredWordCount); Index++, ActualWordCount++) {\r
+\r
+      if (Direction == DataIn) {\r
+\r
+        *ptrBuffer = ReadPortW (AtapiScsiPrivate->PciIo, AtapiScsiPrivate->IoPort->Data);\r
+      } else {\r
+\r
+        WritePortW (AtapiScsiPrivate->PciIo, AtapiScsiPrivate->IoPort->Data, *ptrBuffer);\r
+      }\r
+\r
+      ptrBuffer++;\r
+\r
+    }\r
+  }\r
+  //\r
+  // After data transfer is completed, normally, DRQ bit should clear.\r
+  //\r
+  StatusDRQClear (AtapiScsiPrivate, TimeoutInMicroSeconds);\r
+\r
+  //\r
+  // read status register to check whether error happens.\r
+  //\r
+  Status      = AtapiPassThruCheckErrorStatus (AtapiScsiPrivate);\r
+\r
+  *ByteCount  = ActualWordCount * 2;\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Read one byte from a specified I/O port.\r
+\r
+  @todo function comment is missing 'Routine Description:'\r
+  @todo function comment is missing 'Arguments:'\r
+  @todo function comment is missing 'Returns:'\r
+  @todo    PciIo - add argument and description to function comment\r
+  @todo    Port - add argument and description to function comment\r
+**/\r
+UINT8\r
+ReadPortB (\r
+  IN  EFI_PCI_IO_PROTOCOL   *PciIo,\r
+  IN  UINT16                Port\r
+  )\r
+{\r
+  UINT8 Data;\r
+\r
+  Data = 0;\r
+  PciIo->Io.Read (\r
+              PciIo,\r
+              EfiPciIoWidthUint8,\r
+              EFI_PCI_IO_PASS_THROUGH_BAR,\r
+              (UINT64) Port,\r
+              1,\r
+              &Data\r
+              );\r
+  return Data;\r
+}\r
+\r
+\r
+/**\r
+  Read one word from a specified I/O port.\r
+\r
+  @todo function comment is missing 'Routine Description:'\r
+  @todo function comment is missing 'Arguments:'\r
+  @todo function comment is missing 'Returns:'\r
+  @todo    PciIo - add argument and description to function comment\r
+  @todo    Port - add argument and description to function comment\r
+**/\r
+UINT16\r
+ReadPortW (\r
+  IN  EFI_PCI_IO_PROTOCOL   *PciIo,\r
+  IN  UINT16                Port\r
+  )\r
+{\r
+  UINT16  Data;\r
+\r
+  Data = 0;\r
+  PciIo->Io.Read (\r
+              PciIo,\r
+              EfiPciIoWidthUint16,\r
+              EFI_PCI_IO_PASS_THROUGH_BAR,\r
+              (UINT64) Port,\r
+              1,\r
+              &Data\r
+              );\r
+  return Data;\r
+}\r
+\r
+\r
+/**\r
+  Write one byte to a specified I/O port.\r
+\r
+  @todo function comment is missing 'Routine Description:'\r
+  @todo function comment is missing 'Arguments:'\r
+  @todo function comment is missing 'Returns:'\r
+  @todo    PciIo - add argument and description to function comment\r
+  @todo    Port - add argument and description to function comment\r
+  @todo    Data - add argument and description to function comment\r
+**/\r
+VOID\r
+WritePortB (\r
+  IN  EFI_PCI_IO_PROTOCOL   *PciIo,\r
+  IN  UINT16                Port,\r
+  IN  UINT8                 Data\r
+  )\r
+{\r
+\r
+  PciIo->Io.Write (\r
+              PciIo,\r
+              EfiPciIoWidthUint8,\r
+              EFI_PCI_IO_PASS_THROUGH_BAR,\r
+              (UINT64) Port,\r
+              1,\r
+              &Data\r
+              );\r
+\r
+}\r
+\r
+\r
+/**\r
+  Write one word to a specified I/O port.\r
+\r
+  @todo function comment is missing 'Routine Description:'\r
+  @todo function comment is missing 'Arguments:'\r
+  @todo function comment is missing 'Returns:'\r
+  @todo    PciIo - add argument and description to function comment\r
+  @todo    Port - add argument and description to function comment\r
+  @todo    Data - add argument and description to function comment\r
+**/\r
+VOID\r
+WritePortW (\r
+  IN  EFI_PCI_IO_PROTOCOL   *PciIo,\r
+  IN  UINT16                Port,\r
+  IN  UINT16                Data\r
+  )\r
+{\r
+\r
+  PciIo->Io.Write (\r
+              PciIo,\r
+              EfiPciIoWidthUint16,\r
+              EFI_PCI_IO_PASS_THROUGH_BAR,\r
+              (UINT64) Port,\r
+              1,\r
+              &Data\r
+              );\r
+}\r
+\r
+/**\r
+  Check whether DRQ is clear in the Status Register. (BSY must also be cleared)\r
+  If TimeoutInMicroSeconds is zero, this routine should wait infinitely for\r
+  DRQ clear. Otherwise, it will return EFI_TIMEOUT when specified time is \r
+  elapsed.\r
+\r
+  @todo function comment is missing 'Routine Description:'\r
+  @todo function comment is missing 'Arguments:'\r
+  @todo function comment is missing 'Returns:'\r
+  @todo    AtapiScsiPrivate - add argument and description to function comment\r
+  @todo    TimeoutInMicroSeconds - add argument and description to function comment\r
+  @todo    EFI_ABORTED - add return value to function comment\r
+  @todo    EFI_TIMEOUT - add return value to function comment\r
+  @todo    EFI_SUCCESS - add return value to function comment\r
+**/\r
+EFI_STATUS\r
+StatusDRQClear (\r
+  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate,\r
+  UINT64                          TimeoutInMicroSeconds\r
+  )\r
+{\r
+  UINT64  Delay;\r
+  UINT8   StatusRegister;\r
+  UINT8   ErrRegister;\r
+\r
+  if (TimeoutInMicroSeconds == 0) {\r
+    Delay = 2;\r
+  } else {\r
+    Delay = DivU64x32 (TimeoutInMicroSeconds, (UINT32) 30) + 1;\r
+  }\r
+\r
+  do {\r
+\r
+    StatusRegister = ReadPortB (\r
+                      AtapiScsiPrivate->PciIo,\r
+                      AtapiScsiPrivate->IoPort->Reg.Status\r
+                      );\r
+\r
+    //\r
+    // wait for BSY == 0 and DRQ == 0\r
+    //\r
+    if ((StatusRegister & (DRQ | BSY)) == 0) {\r
+      break;\r
+    }\r
+    //\r
+    // check whether the command is aborted by the device\r
+    //\r
+    if ((StatusRegister & (BSY | ERR)) == ERR) {\r
+\r
+      ErrRegister = ReadPortB (\r
+                      AtapiScsiPrivate->PciIo,\r
+                      AtapiScsiPrivate->IoPort->Reg1.Error\r
+                      );\r
+      if ((ErrRegister & ABRT_ERR) == ABRT_ERR) {\r
+\r
+        return EFI_ABORTED;\r
+      }\r
+    }\r
+    //\r
+    //  Stall for 30 us\r
+    //\r
+    gBS->Stall (30);\r
+\r
+    //\r
+    // Loop infinitely if not meeting expected condition\r
+    //\r
+    if (TimeoutInMicroSeconds == 0) {\r
+      Delay = 2;\r
+    }\r
+\r
+    Delay--;\r
+  } while (Delay);\r
+\r
+  if (Delay == 0) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Check whether DRQ is clear in the Alternate Status Register. \r
+  (BSY must also be cleared).\r
+  If TimeoutInMicroSeconds is zero, this routine should wait infinitely for\r
+  DRQ clear. Otherwise, it will return EFI_TIMEOUT when specified time is \r
+  elapsed.\r
+\r
+  @todo function comment is missing 'Routine Description:'\r
+  @todo function comment is missing 'Arguments:'\r
+  @todo function comment is missing 'Returns:'\r
+  @todo    AtapiScsiPrivate - add argument and description to function comment\r
+  @todo    TimeoutInMicroSeconds - add argument and description to function comment\r
+  @todo    EFI_ABORTED - add return value to function comment\r
+  @todo    EFI_TIMEOUT - add return value to function comment\r
+  @todo    EFI_SUCCESS - add return value to function comment\r
+**/\r
+EFI_STATUS\r
+AltStatusDRQClear (\r
+  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate,\r
+  UINT64                          TimeoutInMicroSeconds\r
+  )\r
+{\r
+  UINT64  Delay;\r
+  UINT8   AltStatusRegister;\r
+  UINT8   ErrRegister;\r
+\r
+  if (TimeoutInMicroSeconds == 0) {\r
+    Delay = 2;\r
+  } else {\r
+    Delay = DivU64x32 (TimeoutInMicroSeconds, (UINT32) 30) + 1;\r
+  }\r
+\r
+  do {\r
+\r
+    AltStatusRegister = ReadPortB (\r
+                          AtapiScsiPrivate->PciIo,\r
+                          AtapiScsiPrivate->IoPort->Alt.AltStatus\r
+                          );\r
+\r
+    //\r
+    // wait for BSY == 0 and DRQ == 0\r
+    //\r
+    if ((AltStatusRegister & (DRQ | BSY)) == 0) {\r
+      break;\r
+    }\r
+\r
+    if ((AltStatusRegister & (BSY | ERR)) == ERR) {\r
+\r
+      ErrRegister = ReadPortB (\r
+                      AtapiScsiPrivate->PciIo,\r
+                      AtapiScsiPrivate->IoPort->Reg1.Error\r
+                      );\r
+      if ((ErrRegister & ABRT_ERR) == ABRT_ERR) {\r
+\r
+        return EFI_ABORTED;\r
+      }\r
+    }\r
+    //\r
+    //  Stall for 30 us\r
+    //\r
+    gBS->Stall (30);\r
+\r
+    //\r
+    // Loop infinitely if not meeting expected condition\r
+    //\r
+    if (TimeoutInMicroSeconds == 0) {\r
+      Delay = 2;\r
+    }\r
+\r
+    Delay--;\r
+  } while (Delay);\r
+\r
+  if (Delay == 0) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Check whether DRQ is ready in the Status Register. (BSY must also be cleared)\r
+  If TimeoutInMicroSeconds is zero, this routine should wait infinitely for\r
+  DRQ ready. Otherwise, it will return EFI_TIMEOUT when specified time is \r
+  elapsed.\r
+\r
+  @todo function comment is missing 'Routine Description:'\r
+  @todo function comment is missing 'Arguments:'\r
+  @todo function comment is missing 'Returns:'\r
+  @todo    AtapiScsiPrivate - add argument and description to function comment\r
+  @todo    TimeoutInMicroSeconds - add argument and description to function comment\r
+  @todo    EFI_ABORTED - add return value to function comment\r
+  @todo    EFI_TIMEOUT - add return value to function comment\r
+  @todo    EFI_SUCCESS - add return value to function comment\r
+**/\r
+EFI_STATUS\r
+StatusDRQReady (\r
+  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate,\r
+  UINT64                          TimeoutInMicroSeconds\r
+  )\r
+{\r
+  UINT64  Delay;\r
+  UINT8   StatusRegister;\r
+  UINT8   ErrRegister;\r
+\r
+  if (TimeoutInMicroSeconds == 0) {\r
+    Delay = 2;\r
+  } else {\r
+    Delay = DivU64x32 (TimeoutInMicroSeconds, (UINT32) 30) + 1;\r
+  }\r
+\r
+  do {\r
+    //\r
+    //  read Status Register will clear interrupt\r
+    //\r
+    StatusRegister = ReadPortB (\r
+                      AtapiScsiPrivate->PciIo,\r
+                      AtapiScsiPrivate->IoPort->Reg.Status\r
+                      );\r
+\r
+    //\r
+    //  BSY==0,DRQ==1\r
+    //\r
+    if ((StatusRegister & (BSY | DRQ)) == DRQ) {\r
+      break;\r
+    }\r
+\r
+    if ((StatusRegister & (BSY | ERR)) == ERR) {\r
+\r
+      ErrRegister = ReadPortB (\r
+                      AtapiScsiPrivate->PciIo,\r
+                      AtapiScsiPrivate->IoPort->Reg1.Error\r
+                      );\r
+      if ((ErrRegister & ABRT_ERR) == ABRT_ERR) {\r
+        return EFI_ABORTED;\r
+      }\r
+    }\r
+\r
+    //\r
+    // Stall for 30 us\r
+    //\r
+    gBS->Stall (30);\r
+\r
+    //\r
+    // Loop infinitely if not meeting expected condition\r
+    //\r
+    if (TimeoutInMicroSeconds == 0) {\r
+      Delay = 2;\r
+    }\r
+\r
+    Delay--;\r
+  } while (Delay);\r
+\r
+  if (Delay == 0) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Check whether DRQ is ready in the Alternate Status Register. \r
+  (BSY must also be cleared)\r
+  If TimeoutInMicroSeconds is zero, this routine should wait infinitely for\r
+  DRQ ready. Otherwise, it will return EFI_TIMEOUT when specified time is \r
+  elapsed.\r
+\r
+  @todo function comment is missing 'Routine Description:'\r
+  @todo function comment is missing 'Arguments:'\r
+  @todo function comment is missing 'Returns:'\r
+  @todo    AtapiScsiPrivate - add argument and description to function comment\r
+  @todo    TimeoutInMicroSeconds - add argument and description to function comment\r
+  @todo    EFI_ABORTED - add return value to function comment\r
+  @todo    EFI_TIMEOUT - add return value to function comment\r
+  @todo    EFI_SUCCESS - add return value to function comment\r
+**/\r
+EFI_STATUS\r
+AltStatusDRQReady (\r
+  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate,\r
+  UINT64                          TimeoutInMicroSeconds\r
+  )\r
+{\r
+  UINT64  Delay;\r
+  UINT8   AltStatusRegister;\r
+  UINT8   ErrRegister;\r
+\r
+  if (TimeoutInMicroSeconds == 0) {\r
+    Delay = 2;\r
+  } else {\r
+    Delay = DivU64x32 (TimeoutInMicroSeconds, (UINT32) 30) + 1;\r
+  }\r
+\r
+  do {\r
+    //\r
+    //  read Status Register will clear interrupt\r
+    //\r
+    AltStatusRegister = ReadPortB (\r
+                          AtapiScsiPrivate->PciIo,\r
+                          AtapiScsiPrivate->IoPort->Alt.AltStatus\r
+                          );\r
+    //\r
+    //  BSY==0,DRQ==1\r
+    //\r
+    if ((AltStatusRegister & (BSY | DRQ)) == DRQ) {\r
+      break;\r
+    }\r
+\r
+    if ((AltStatusRegister & (BSY | ERR)) == ERR) {\r
+\r
+      ErrRegister = ReadPortB (\r
+                      AtapiScsiPrivate->PciIo,\r
+                      AtapiScsiPrivate->IoPort->Reg1.Error\r
+                      );\r
+      if ((ErrRegister & ABRT_ERR) == ABRT_ERR) {\r
+        return EFI_ABORTED;\r
+      }\r
+    }\r
+\r
+    //\r
+    // Stall for 30 us\r
+    //\r
+    gBS->Stall (30);\r
+\r
+    //\r
+    // Loop infinitely if not meeting expected condition\r
+    //\r
+    if (TimeoutInMicroSeconds == 0) {\r
+      Delay = 2;\r
+    }\r
+\r
+    Delay--;\r
+  } while (Delay);\r
+\r
+  if (Delay == 0) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Check whether BSY is clear in the Status Register.\r
+  If TimeoutInMicroSeconds is zero, this routine should wait infinitely for\r
+  BSY clear. Otherwise, it will return EFI_TIMEOUT when specified time is \r
+  elapsed.\r
+\r
+  @todo function comment is missing 'Routine Description:'\r
+  @todo function comment is missing 'Arguments:'\r
+  @todo function comment is missing 'Returns:'\r
+  @todo    AtapiScsiPrivate - add argument and description to function comment\r
+  @todo    TimeoutInMicroSeconds - add argument and description to function comment\r
+  @todo    EFI_TIMEOUT - add return value to function comment\r
+  @todo    EFI_SUCCESS - add return value to function comment\r
+**/\r
+EFI_STATUS\r
+StatusWaitForBSYClear (\r
+  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate,\r
+  UINT64                      TimeoutInMicroSeconds\r
+  )\r
+{\r
+  UINT64  Delay;\r
+  UINT8   StatusRegister;\r
+\r
+  if (TimeoutInMicroSeconds == 0) {\r
+    Delay = 2;\r
+  } else {\r
+    Delay = DivU64x32 (TimeoutInMicroSeconds, (UINT32) 30) + 1;\r
+  }\r
+\r
+  do {\r
+\r
+    StatusRegister = ReadPortB (\r
+                      AtapiScsiPrivate->PciIo,\r
+                      AtapiScsiPrivate->IoPort->Reg.Status\r
+                      );\r
+    if ((StatusRegister & BSY) == 0x00) {\r
+      break;\r
+    }\r
+\r
+    //\r
+    // Stall for 30 us\r
+    //\r
+    gBS->Stall (30);\r
+\r
+    //\r
+    // Loop infinitely if not meeting expected condition\r
+    //\r
+    if (TimeoutInMicroSeconds == 0) {\r
+      Delay = 2;\r
+    }\r
+\r
+    Delay--;\r
+  } while (Delay);\r
+\r
+  if (Delay == 0) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Check whether BSY is clear in the Alternate Status Register.\r
+  If TimeoutInMicroSeconds is zero, this routine should wait infinitely for\r
+  BSY clear. Otherwise, it will return EFI_TIMEOUT when specified time is \r
+  elapsed.\r
+\r
+  @todo function comment is missing 'Routine Description:'\r
+  @todo function comment is missing 'Arguments:'\r
+  @todo function comment is missing 'Returns:'\r
+  @todo    AtapiScsiPrivate - add argument and description to function comment\r
+  @todo    TimeoutInMicroSeconds - add argument and description to function comment\r
+  @todo    EFI_TIMEOUT - add return value to function comment\r
+  @todo    EFI_SUCCESS - add return value to function comment\r
+**/\r
+EFI_STATUS\r
+AltStatusWaitForBSYClear (\r
+  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate,\r
+  UINT64                      TimeoutInMicroSeconds\r
+  )\r
+{\r
+  UINT64  Delay;\r
+  UINT8   AltStatusRegister;\r
+\r
+  if (TimeoutInMicroSeconds == 0) {\r
+    Delay = 2;\r
+  } else {\r
+    Delay = DivU64x32 (TimeoutInMicroSeconds, (UINT32) 30) + 1;\r
+  }\r
+\r
+  do {\r
+\r
+    AltStatusRegister = ReadPortB (\r
+                          AtapiScsiPrivate->PciIo,\r
+                          AtapiScsiPrivate->IoPort->Alt.AltStatus\r
+                          );\r
+    if ((AltStatusRegister & BSY) == 0x00) {\r
+      break;\r
+    }\r
+\r
+    //\r
+    // Stall for 30 us\r
+    //\r
+    gBS->Stall (30);\r
+    //\r
+    // Loop infinitely if not meeting expected condition\r
+    //\r
+    if (TimeoutInMicroSeconds == 0) {\r
+      Delay = 2;\r
+    }\r
+\r
+    Delay--;\r
+  } while (Delay);\r
+\r
+  if (Delay == 0) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Check whether DRDY is ready in the Status Register. \r
+  (BSY must also be cleared)\r
+  If TimeoutInMicroSeconds is zero, this routine should wait infinitely for\r
+  DRDY ready. Otherwise, it will return EFI_TIMEOUT when specified time is \r
+  elapsed.\r
+\r
+  @todo function comment is missing 'Routine Description:'\r
+  @todo function comment is missing 'Arguments:'\r
+  @todo function comment is missing 'Returns:'\r
+  @todo    AtapiScsiPrivate - add argument and description to function comment\r
+  @todo    TimeoutInMicroSeconds - add argument and description to function comment\r
+  @todo    EFI_ABORTED - add return value to function comment\r
+  @todo    EFI_TIMEOUT - add return value to function comment\r
+  @todo    EFI_SUCCESS - add return value to function comment\r
+**/\r
+EFI_STATUS\r
+StatusDRDYReady (\r
+  ATAPI_SCSI_PASS_THRU_DEV     *AtapiScsiPrivate,\r
+  UINT64                       TimeoutInMicroSeconds\r
+  )\r
+{\r
+  UINT64  Delay;\r
+  UINT8   StatusRegister;\r
+  UINT8   ErrRegister;\r
+\r
+  if (TimeoutInMicroSeconds == 0) {\r
+    Delay = 2;\r
+  } else {\r
+    Delay = DivU64x32 (TimeoutInMicroSeconds, (UINT32) 30) + 1;\r
+  }\r
+\r
+  do {\r
+    StatusRegister = ReadPortB (\r
+                      AtapiScsiPrivate->PciIo,\r
+                      AtapiScsiPrivate->IoPort->Reg.Status\r
+                      );\r
+    //\r
+    //  BSY == 0 , DRDY == 1\r
+    //\r
+    if ((StatusRegister & (DRDY | BSY)) == DRDY) {\r
+      break;\r
+    }\r
+\r
+    if ((StatusRegister & (BSY | ERR)) == ERR) {\r
+\r
+      ErrRegister = ReadPortB (\r
+                      AtapiScsiPrivate->PciIo,\r
+                      AtapiScsiPrivate->IoPort->Reg1.Error\r
+                      );\r
+      if ((ErrRegister & ABRT_ERR) == ABRT_ERR) {\r
+        return EFI_ABORTED;\r
+      }\r
+    }\r
+    \r
+    //\r
+    // Stall for 30 us\r
+    //\r
+    gBS->Stall (30);\r
+    //\r
+    // Loop infinitely if not meeting expected condition\r
+    //\r
+    if (TimeoutInMicroSeconds == 0) {\r
+      Delay = 2;\r
+    }\r
+\r
+    Delay--;\r
+  } while (Delay);\r
+\r
+  if (Delay == 0) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Check whether DRDY is ready in the Alternate Status Register. \r
+  (BSY must also be cleared)\r
+  If TimeoutInMicroSeconds is zero, this routine should wait infinitely for\r
+  DRDY ready. Otherwise, it will return EFI_TIMEOUT when specified time is \r
+  elapsed.\r
+\r
+  @todo function comment is missing 'Routine Description:'\r
+  @todo function comment is missing 'Arguments:'\r
+  @todo function comment is missing 'Returns:'\r
+  @todo    AtapiScsiPrivate - add argument and description to function comment\r
+  @todo    TimeoutInMicroSeconds - add argument and description to function comment\r
+  @todo    EFI_ABORTED - add return value to function comment\r
+  @todo    EFI_TIMEOUT - add return value to function comment\r
+  @todo    EFI_SUCCESS - add return value to function comment\r
+**/\r
+EFI_STATUS\r
+AltStatusDRDYReady (\r
+  ATAPI_SCSI_PASS_THRU_DEV     *AtapiScsiPrivate,\r
+  UINT64                       TimeoutInMicroSeconds\r
+  )\r
+{\r
+  UINT64  Delay;\r
+  UINT8   AltStatusRegister;\r
+  UINT8   ErrRegister;\r
+\r
+  if (TimeoutInMicroSeconds == 0) {\r
+    Delay = 2;\r
+  } else {\r
+    Delay = DivU64x32 (TimeoutInMicroSeconds, (UINT32) 30) + 1;\r
+  }\r
+\r
+  do {\r
+    AltStatusRegister = ReadPortB (\r
+                          AtapiScsiPrivate->PciIo,\r
+                          AtapiScsiPrivate->IoPort->Alt.AltStatus\r
+                          );\r
+    //\r
+    //  BSY == 0 , DRDY == 1\r
+    //\r
+    if ((AltStatusRegister & (DRDY | BSY)) == DRDY) {\r
+      break;\r
+    }\r
+\r
+    if ((AltStatusRegister & (BSY | ERR)) == ERR) {\r
+\r
+      ErrRegister = ReadPortB (\r
+                      AtapiScsiPrivate->PciIo,\r
+                      AtapiScsiPrivate->IoPort->Reg1.Error\r
+                      );\r
+      if ((ErrRegister & ABRT_ERR) == ABRT_ERR) {\r
+        return EFI_ABORTED;\r
+      }\r
+    }\r
+\r
+    //\r
+    // Stall for 30 us\r
+    //\r
+    gBS->Stall (30);\r
+    //\r
+    // Loop infinitely if not meeting expected condition\r
+    //\r
+    if (TimeoutInMicroSeconds == 0) {\r
+      Delay = 2;\r
+    }\r
+\r
+    Delay--;\r
+  } while (Delay);\r
+\r
+  if (Delay == 0) {\r
+    return EFI_TIMEOUT;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Check Error Register for Error Information. \r
+\r
+  @todo function comment is missing 'Routine Description:'\r
+  @todo function comment is missing 'Arguments:'\r
+  @todo function comment is missing 'Returns:'\r
+  @todo    AtapiScsiPrivate - add argument and description to function comment\r
+  @todo    EFI_SUCCESS - add return value to function comment\r
+  @todo    EFI_DEVICE_ERROR - add return value to function comment\r
+**/\r
+EFI_STATUS\r
+AtapiPassThruCheckErrorStatus (\r
+  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate\r
+  )\r
+{\r
+  UINT8 StatusRegister;\r
+  UINT8 ErrorRegister;\r
+\r
+  StatusRegister = ReadPortB (\r
+                    AtapiScsiPrivate->PciIo,\r
+                    AtapiScsiPrivate->IoPort->Reg.Status\r
+                    );\r
+  \r
+  DEBUG_CODE_BEGIN ();\r
+\r
+    if (StatusRegister & DWF) {\r
+      DEBUG (\r
+        (EFI_D_BLKIO,\r
+        "AtapiPassThruCheckErrorStatus()-- %02x : Error : Write Fault\n",\r
+        StatusRegister)\r
+        );\r
+    }\r
+\r
+    if (StatusRegister & CORR) {\r
+      DEBUG (\r
+        (EFI_D_BLKIO,\r
+        "AtapiPassThruCheckErrorStatus()-- %02x : Error : Corrected Data\n",\r
+        StatusRegister)\r
+        );\r
+    }\r
+\r
+    if (StatusRegister & ERR) {\r
+      ErrorRegister = ReadPortB (AtapiScsiPrivate->PciIo, AtapiScsiPrivate->IoPort->Reg1.Error);\r
+      \r
+\r
+      if (ErrorRegister & BBK_ERR) {\r
+        DEBUG (\r
+          (EFI_D_BLKIO,\r
+          "AtapiPassThruCheckErrorStatus()-- %02x : Error : Bad Block Detected\n",\r
+          ErrorRegister)\r
+          );\r
+      }\r
+\r
+      if (ErrorRegister & UNC_ERR) {\r
+        DEBUG (\r
+          (EFI_D_BLKIO,\r
+          "AtapiPassThruCheckErrorStatus()-- %02x : Error : Uncorrectable Data\n",\r
+          ErrorRegister)\r
+          );\r
+      }\r
+\r
+      if (ErrorRegister & MC_ERR) {\r
+        DEBUG (\r
+          (EFI_D_BLKIO,\r
+          "AtapiPassThruCheckErrorStatus()-- %02x : Error : Media Change\n",\r
+          ErrorRegister)\r
+          );\r
+      }\r
+\r
+      if (ErrorRegister & ABRT_ERR) {\r
+        DEBUG (\r
+          (EFI_D_BLKIO,\r
+          "AtapiPassThruCheckErrorStatus()-- %02x : Error : Abort\n",\r
+          ErrorRegister)\r
+          );\r
+      }\r
+\r
+      if (ErrorRegister & TK0NF_ERR) {\r
+        DEBUG (\r
+          (EFI_D_BLKIO,\r
+          "AtapiPassThruCheckErrorStatus()-- %02x : Error : Track 0 Not Found\n",\r
+          ErrorRegister)\r
+          );\r
+      }\r
+\r
+      if (ErrorRegister & AMNF_ERR) {\r
+        DEBUG (\r
+          (EFI_D_BLKIO,\r
+          "AtapiPassThruCheckErrorStatus()-- %02x : Error : Address Mark Not Found\n",\r
+          ErrorRegister)\r
+          );\r
+       }\r
+    }\r
+\r
+  DEBUG_CODE_END ();\r
+\r
+  if ((StatusRegister & (ERR | DWF | CORR)) == 0) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
\r
+  return EFI_DEVICE_ERROR;\r
+}\r
+\r
+/**\r
+  The user Entry Point for module AtapiPassThru. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeAtapiPassThru(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  //\r
+  // Install driver model protocol(s).\r
+  //\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gAtapiScsiPassThruDriverBinding,\r
+             ImageHandle,\r
+             &gAtapiScsiPassThruComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
diff --git a/MdeModulePkg/Bus/Pci/AtapiPassThruDxe/AtapiPassThru.h b/MdeModulePkg/Bus/Pci/AtapiPassThruDxe/AtapiPassThru.h
new file mode 100644 (file)
index 0000000..49b97a8
--- /dev/null
@@ -0,0 +1,833 @@
+/** @file\r
+  Copyright (c) 2006, Intel Corporation                                                         \r
+  All rights reserved. This program and the accompanying materials                          \r
+  are licensed and made available under the terms and conditions of the BSD License         \r
+  which accompanies this distribution.  The full text of the license may be found at        \r
+  http://opensource.org/licenses/bsd-license.php                                            \r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+  Module Name:  AtapiPassThru.h\r
+\r
+**/\r
+\r
+#ifndef _APT_H\r
+#define _APT_H\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <Uefi.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Protocol/ScsiPassThru.h>\r
+#include <Protocol/PciIo.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <IndustryStandard/pci22.h>\r
+\r
+///\r
+/// bit definition\r
+///\r
+#define bit(a)        (1 << (a))\r
+\r
+#define MAX_TARGET_ID 4\r
+\r
+//\r
+// IDE Registers\r
+//\r
+typedef union {\r
+  UINT16  Command;        /* when write */\r
+  UINT16  Status;         /* when read */\r
+} IDE_CMD_OR_STATUS;\r
+\r
+typedef union {\r
+  UINT16  Error;          /* when read */\r
+  UINT16  Feature;        /* when write */\r
+} IDE_ERROR_OR_FEATURE;\r
+\r
+typedef union {\r
+  UINT16  AltStatus;      /* when read */\r
+  UINT16  DeviceControl;  /* when write */\r
+} IDE_AltStatus_OR_DeviceControl;\r
+\r
+///\r
+/// IDE registers set\r
+///\r
+typedef struct {\r
+  UINT16                          Data;\r
+  IDE_ERROR_OR_FEATURE            Reg1;\r
+  UINT16                          SectorCount;\r
+  UINT16                          SectorNumber;\r
+  UINT16                          CylinderLsb;\r
+  UINT16                          CylinderMsb;\r
+  UINT16                          Head;\r
+  IDE_CMD_OR_STATUS               Reg;\r
+\r
+  IDE_AltStatus_OR_DeviceControl  Alt;\r
+  UINT16                          DriveAddress;\r
+\r
+  UINT16                          MasterSlave;\r
+} IDE_BASE_REGISTERS;\r
+\r
+#define ATAPI_SCSI_PASS_THRU_DEV_SIGNATURE  EFI_SIGNATURE_32 ('a', 's', 'p', 't')\r
+\r
+typedef struct {\r
+  UINTN                       Signature;\r
+\r
+  EFI_HANDLE                  Handle;\r
+  EFI_SCSI_PASS_THRU_PROTOCOL ScsiPassThru;\r
+  EFI_SCSI_PASS_THRU_MODE     ScsiPassThruMode;\r
+  EFI_PCI_IO_PROTOCOL         *PciIo;\r
+\r
+  //\r
+  // Local Data goes here\r
+  //\r
+  IDE_BASE_REGISTERS          *IoPort;\r
+\r
+  CHAR16                      ControllerName[100];\r
+  CHAR16                      ChannelName[100];\r
+\r
+  UINT32                      LatestTargetId;\r
+  UINT64                      LatestLun;\r
+\r
+} ATAPI_SCSI_PASS_THRU_DEV;\r
+\r
+#define ATAPI_SCSI_PASS_THRU_DEV_FROM_THIS(a) \\r
+  CR (a, \\r
+      ATAPI_SCSI_PASS_THRU_DEV, \\r
+      ScsiPassThru, \\r
+      ATAPI_SCSI_PASS_THRU_DEV_SIGNATURE \\r
+      )\r
+\r
+//\r
+// Global Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL  gAtapiScsiPassThruDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gAtapiScsiPassThruComponentName;\r
+\r
+//\r
+// ATAPI Command op code\r
+//\r
+#define OP_INQUIRY                      0x12\r
+#define OP_LOAD_UNLOAD_CD               0xa6\r
+#define OP_MECHANISM_STATUS             0xbd\r
+#define OP_MODE_SELECT_10               0x55\r
+#define OP_MODE_SENSE_10                0x5a\r
+#define OP_PAUSE_RESUME                 0x4b\r
+#define OP_PLAY_AUDIO_10                0x45\r
+#define OP_PLAY_AUDIO_MSF               0x47\r
+#define OP_PLAY_CD                      0xbc\r
+#define OP_PLAY_CD_MSF                  0xb4\r
+#define OP_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e\r
+#define OP_READ_10                      0x28\r
+#define OP_READ_12                      0xa8\r
+#define OP_READ_CAPACITY                0x25\r
+#define OP_READ_CD                      0xbe\r
+#define OP_READ_CD_MSF                  0xb9\r
+#define OP_READ_HEADER                  0x44\r
+#define OP_READ_SUB_CHANNEL             0x42\r
+#define OP_READ_TOC                     0x43\r
+#define OP_REQUEST_SENSE                0x03\r
+#define OP_SCAN                         0xba\r
+#define OP_SEEK_10                      0x2b\r
+#define OP_SET_CD_SPEED                 0xbb\r
+#define OP_STOPPLAY_SCAN                0x4e\r
+#define OP_START_STOP_UNIT              0x1b\r
+#define OP_TEST_UNIT_READY              0x00\r
+\r
+#define OP_FORMAT_UNIT                  0x04\r
+#define OP_READ_FORMAT_CAPACITIES       0x23\r
+#define OP_VERIFY                       0x2f\r
+#define OP_WRITE_10                     0x2a\r
+#define OP_WRITE_12                     0xaa\r
+#define OP_WRITE_AND_VERIFY             0x2e\r
+\r
+//\r
+// ATA Command\r
+//\r
+#define ATAPI_SOFT_RESET_CMD  0x08\r
+\r
+typedef enum {\r
+  DataIn  = 0,\r
+  DataOut = 1,\r
+  NoData  = 2,\r
+  End     = 0xff\r
+} DATA_DIRECTION;\r
+\r
+typedef struct {\r
+  UINT8           OpCode;\r
+  DATA_DIRECTION  Direction;\r
+} SCSI_COMMAND_SET;\r
+\r
+#define MAX_CHANNEL         2\r
+\r
+#define ValidCdbLength(Len) ((Len) == 6 || (Len) == 10 || (Len) == 12) ? 1 : 0\r
+\r
+//\r
+// IDE registers bit definitions\r
+//\r
+// ATA Err Reg bitmap\r
+//\r
+#define BBK_ERR   bit (7) ///< Bad block detected\r
+#define UNC_ERR   bit (6) ///< Uncorrectable Data\r
+#define MC_ERR    bit (5) ///< Media Change\r
+#define IDNF_ERR  bit (4) ///< ID Not Found\r
+#define MCR_ERR   bit (3) ///< Media Change Requested\r
+#define ABRT_ERR  bit (2) ///< Aborted Command\r
+#define TK0NF_ERR bit (1) ///< Track 0 Not Found\r
+#define AMNF_ERR  bit (0) ///< Address Mark Not Found\r
+\r
+//\r
+// ATAPI Err Reg bitmap\r
+//\r
+#define SENSE_KEY_ERR (bit (7) | bit (6) | bit (5) | bit (4))\r
+#define EOM_ERR bit (1) ///< End of Media Detected\r
+#define ILI_ERR bit (0) ///< Illegal Length Indication\r
+\r
+//\r
+// Device/Head Reg\r
+//\r
+#define LBA_MODE  bit (6)\r
+#define DEV       bit (4)\r
+#define HS3       bit (3)\r
+#define HS2       bit (2)\r
+#define HS1       bit (1)\r
+#define HS0       bit (0)\r
+#define CHS_MODE  (0)\r
+#define DRV0      (0)\r
+#define DRV1      (1)\r
+#define MST_DRV   DRV0\r
+#define SLV_DRV   DRV1\r
+\r
+//\r
+// Status Reg\r
+//\r
+#define BSY   bit (7) ///< Controller Busy\r
+#define DRDY  bit (6) ///< Drive Ready\r
+#define DWF   bit (5) ///< Drive Write Fault\r
+#define DSC   bit (4) ///< Disk Seek Complete\r
+#define DRQ   bit (3) ///< Data Request\r
+#define CORR  bit (2) ///< Corrected Data\r
+#define IDX   bit (1) ///< Index\r
+#define ERR   bit (0) ///< Error\r
+#define CHECK bit (0) ///< Check bit for ATAPI Status Reg\r
+\r
+//\r
+// Device Control Reg\r
+//\r
+#define SRST  bit (2) ///< Software Reset\r
+#define IEN_L bit (1) ///< Interrupt Enable\r
+\r
+//\r
+// ATAPI Feature Register\r
+//\r
+#define OVERLAP bit (1)\r
+#define DMA     bit (0)\r
+\r
+//\r
+// ATAPI Interrupt Reason Reson Reg (ATA Sector Count Register)\r
+//\r
+#define RELEASE     bit (2)\r
+#define IO          bit (1)\r
+#define CoD         bit (0)\r
+\r
+#define PACKET_CMD  0xA0\r
+\r
+#define DEFAULT_CMD (0xa0)\r
+//\r
+// default content of device control register, disable INT\r
+//\r
+#define DEFAULT_CTL           (0x0a)\r
+#define MAX_ATAPI_BYTE_COUNT  (0xfffe)\r
+\r
+//\r
+// function prototype\r
+//\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN EFI_HANDLE                   Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      Controller,\r
+  IN  UINTN                           NumberOfChildren,\r
+  IN  EFI_HANDLE                      *ChildHandleBuffer\r
+  );\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  );\r
+\r
+/**\r
+  AtapiScsiPassThruDriverEntryPoint\r
+\r
+  @param ImageHandle\r
+  @param SystemTable\r
+\r
+  @todo Add function description\r
+  @todo ImageHandle - add argument description\r
+  @todo SystemTable - add argument description\r
+  @todo add return values\r
+--*/\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruDriverEntryPoint (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+;\r
+\r
+/**\r
+  RegisterAtapiScsiPassThru\r
+\r
+  @param  This\r
+  @param  Controller\r
+  @param  PciIo\r
+\r
+  @todo Add function description\r
+  @todo This add argument description\r
+  @todo Controller add argument description\r
+  @todo PciIo add argument description\r
+  @todo add return values\r
+**/\r
+EFI_STATUS\r
+RegisterAtapiScsiPassThru (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                  Controller,\r
+  IN  EFI_PCI_IO_PROTOCOL         *PciIo\r
+  )\r
+;\r
+\r
+/**\r
+  AtapiScsiPassThruFunction\r
+\r
+  @param  This\r
+  @param  Target\r
+  @param  Lun\r
+  @param  Packet\r
+  @param  Event\r
+\r
+  @todo Add function description\r
+  @todo  This - add argument description\r
+  @todo  Target - add argument description\r
+  @todo  Lun - add argument description\r
+  @todo  Packet - add argument description\r
+  @todo  Event - add argument description\r
+  @todo add return values\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruFunction (\r
+  IN EFI_SCSI_PASS_THRU_PROTOCOL                        *This,\r
+  IN UINT32                                             Target,\r
+  IN UINT64                                             Lun,\r
+  IN OUT EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET         *Packet,\r
+  IN EFI_EVENT                                          Event OPTIONAL\r
+  )\r
+;\r
+\r
+/**\r
+  AtapiScsiPassThruGetNextDevice\r
+\r
+  TODO: Add function description\r
+\r
+  @param  This TODO: add argument description\r
+  @param  Target TODO: add argument description\r
+  @param  Lun TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruGetNextDevice (\r
+  IN  EFI_SCSI_PASS_THRU_PROTOCOL    *This,\r
+  IN OUT UINT32                      *Target,\r
+  IN OUT UINT64                      *Lun\r
+  )\r
+;\r
+\r
+/**\r
+  AtapiScsiPassThruBuildDevicePath\r
+\r
+  TODO: Add function description\r
+\r
+  @param  This TODO: add argument description\r
+  @param  Target TODO: add argument description\r
+  @param  Lun TODO: add argument description\r
+  @param  DevicePath TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruBuildDevicePath (\r
+  IN     EFI_SCSI_PASS_THRU_PROTOCOL    *This,\r
+  IN     UINT32                         Target,\r
+  IN     UINT64                         Lun,\r
+  IN OUT EFI_DEVICE_PATH_PROTOCOL       **DevicePath\r
+  )\r
+;\r
+\r
+/**\r
+  AtapiScsiPassThruGetTargetLun\r
+\r
+  TODO: Add function description\r
+\r
+  @param  This TODO: add argument description\r
+  @param  DevicePath TODO: add argument description\r
+  @param  Target TODO: add argument description\r
+  @param  Lun TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruGetTargetLun (\r
+  IN  EFI_SCSI_PASS_THRU_PROTOCOL    *This,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL       *DevicePath,\r
+  OUT UINT32                         *Target,\r
+  OUT UINT64                         *Lun\r
+  )\r
+;\r
+\r
+/**\r
+  AtapiScsiPassThruResetChannel\r
+\r
+  TODO: Add function description\r
+\r
+  @param  This TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruResetChannel (\r
+  IN  EFI_SCSI_PASS_THRU_PROTOCOL   *This\r
+  )\r
+;\r
+\r
+/**\r
+  AtapiScsiPassThruResetTarget\r
+\r
+  TODO: Add function description\r
+\r
+  @param  This TODO: add argument description\r
+  @param  Target TODO: add argument description\r
+  @param  Lun TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruResetTarget (\r
+  IN EFI_SCSI_PASS_THRU_PROTOCOL    *This,\r
+  IN UINT32                         Target,\r
+  IN UINT64                         Lun\r
+  )\r
+;\r
+\r
+/**\r
+  CheckSCSIRequestPacket\r
+\r
+  TODO: Add function description\r
+\r
+  @param  Packet TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+CheckSCSIRequestPacket (\r
+  EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET      *Packet\r
+  )\r
+;\r
+\r
+/**\r
+  SubmitBlockingIoCommand\r
+\r
+  TODO: Add function description\r
+\r
+  @param  AtapiScsiPrivate TODO: add argument description\r
+  @param  Target TODO: add argument description\r
+  @param  Packet TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+SubmitBlockingIoCommand (\r
+  ATAPI_SCSI_PASS_THRU_DEV                  *AtapiScsiPrivate,\r
+  UINT32                                    Target,\r
+  EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET    *Packet\r
+  )\r
+;\r
+\r
+/**\r
+  IsCommandValid\r
+\r
+  TODO: Add function description\r
+\r
+  @param Packet  - TODO: add argument description\r
+\r
+  @return TODO: add return values\r
+\r
+--*/\r
+BOOLEAN\r
+IsCommandValid (\r
+  EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET   *Packet\r
+  )\r
+;\r
+\r
+/**\r
+  RequestSenseCommand\r
+\r
+  TODO: Add function description\r
+\r
+  @param  AtapiScsiPrivate TODO: add argument description\r
+  @param  Target TODO: add argument description\r
+  @param  Timeout TODO: add argument description\r
+  @param  SenseData TODO: add argument description\r
+  @param  SenseDataLength TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+RequestSenseCommand (\r
+  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate,\r
+  UINT32                      Target,\r
+  UINT64                      Timeout,\r
+  VOID                        *SenseData,\r
+  UINT8                       *SenseDataLength\r
+  )\r
+;\r
+\r
+/**\r
+  AtapiPacketCommand\r
+\r
+  TODO: Add function description\r
+\r
+  @param  AtapiScsiPrivate TODO: add argument description\r
+  @param  Target TODO: add argument description\r
+  @param  PacketCommand TODO: add argument description\r
+  @param  Buffer TODO: add argument description\r
+  @param  ByteCount TODO: add argument description\r
+  @param  Direction TODO: add argument description\r
+  @param  TimeOutInMicroSeconds TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+AtapiPacketCommand (\r
+  ATAPI_SCSI_PASS_THRU_DEV                  *AtapiScsiPrivate,\r
+  UINT32                                    Target,\r
+  UINT8                                     *PacketCommand,\r
+  VOID                                      *Buffer,\r
+  UINT32                                    *ByteCount,\r
+  DATA_DIRECTION                            Direction,\r
+  UINT64                                    TimeOutInMicroSeconds\r
+  )\r
+;\r
+\r
+\r
+/**\r
+  ReadPortB\r
+\r
+  TODO: Add function description\r
+\r
+  @param  PciIo TODO: add argument description\r
+  @param  Port TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+UINT8\r
+ReadPortB (\r
+  IN  EFI_PCI_IO_PROTOCOL   *PciIo,\r
+  IN  UINT16                Port\r
+  )\r
+;\r
+\r
+\r
+/**\r
+  ReadPortW\r
+\r
+  TODO: Add function description\r
+\r
+  @param  PciIo TODO: add argument description\r
+  @param  Port TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+UINT16\r
+ReadPortW (\r
+  IN  EFI_PCI_IO_PROTOCOL   *PciIo,\r
+  IN  UINT16                Port\r
+  )\r
+;\r
+\r
+\r
+/**\r
+  WritePortB\r
+\r
+  TODO: Add function description\r
+\r
+  @param  PciIo TODO: add argument description\r
+  @param  Port TODO: add argument description\r
+  @param  Data TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+VOID\r
+WritePortB (\r
+  IN  EFI_PCI_IO_PROTOCOL   *PciIo,\r
+  IN  UINT16                Port,\r
+  IN  UINT8                 Data\r
+  )\r
+;\r
+\r
+\r
+/**\r
+  WritePortW\r
+\r
+  TODO: Add function description\r
+\r
+  @param  PciIo TODO: add argument description\r
+  @param  Port TODO: add argument description\r
+  @param  Data TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+VOID\r
+WritePortW (\r
+  IN  EFI_PCI_IO_PROTOCOL   *PciIo,\r
+  IN  UINT16                Port,\r
+  IN  UINT16                Data\r
+  )\r
+;\r
+\r
+/**\r
+  StatusDRQClear\r
+\r
+  TODO: Add function description\r
+\r
+  @param  AtapiScsiPrivate TODO: add argument description\r
+  @param  TimeOutInMicroSeconds TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+StatusDRQClear (\r
+  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate,\r
+  UINT64                          TimeOutInMicroSeconds\r
+  )\r
+;\r
+\r
+/**\r
+  AltStatusDRQClear\r
+\r
+  TODO: Add function description\r
+\r
+  @param  AtapiScsiPrivate TODO: add argument description\r
+  @param  TimeOutInMicroSeconds TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+AltStatusDRQClear (\r
+  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate,\r
+  UINT64                          TimeOutInMicroSeconds\r
+  )\r
+;\r
+\r
+/**\r
+  StatusDRQReady\r
+\r
+  TODO: Add function description\r
+\r
+  @param  AtapiScsiPrivate TODO: add argument description\r
+  @param  TimeOutInMicroSeconds TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+StatusDRQReady (\r
+  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate,\r
+  UINT64                          TimeOutInMicroSeconds\r
+  )\r
+;\r
+\r
+/**\r
+  AltStatusDRQReady\r
+\r
+  TODO: Add function description\r
+\r
+  @param  AtapiScsiPrivate TODO: add argument description\r
+  @param  TimeOutInMicroSeconds TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+AltStatusDRQReady (\r
+  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate,\r
+  UINT64                          TimeOutInMicroSeconds\r
+  )\r
+;\r
+\r
+/**\r
+  TODO: Add function description\r
+\r
+  @param  AtapiScsiPrivate TODO: add argument description\r
+  @param  TimeoutInMicroSeconds TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+StatusWaitForBSYClear (\r
+  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate,\r
+  UINT64                      TimeoutInMicroSeconds\r
+  )\r
+;\r
+\r
+/**\r
+  TODO: Add function description\r
+\r
+  @param  AtapiScsiPrivate TODO: add argument description\r
+  @param  TimeoutInMicroSeconds TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+AltStatusWaitForBSYClear (\r
+  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate,\r
+  UINT64                      TimeoutInMicroSeconds\r
+  )\r
+;\r
+\r
+/**\r
+  TODO: Add function description\r
+\r
+  @param  AtapiScsiPrivate TODO: add argument description\r
+  @param  TimeoutInMicroSeconds TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+StatusDRDYReady (\r
+  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate,\r
+  UINT64                      TimeoutInMicroSeconds\r
+  )\r
+;\r
+\r
+/**\r
+  TODO: Add function description\r
+\r
+  @param  AtapiScsiPrivate TODO: add argument description\r
+  @param  TimeoutInMicroSeconds TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+AltStatusDRDYReady (\r
+  ATAPI_SCSI_PASS_THRU_DEV    *AtapiScsiPrivate,\r
+  UINT64                      TimeoutInMicroSeconds\r
+  )\r
+;\r
+\r
+/**\r
+  TODO: Add function description\r
+\r
+  @param  AtapiScsiPrivate TODO: add argument description\r
+  @param  Buffer TODO: add argument description\r
+  @param  ByteCount TODO: add argument description\r
+  @param  Direction TODO: add argument description\r
+  @param  TimeOutInMicroSeconds TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+AtapiPassThruPioReadWriteData (\r
+  ATAPI_SCSI_PASS_THRU_DEV  *AtapiScsiPrivate,\r
+  UINT16                    *Buffer,\r
+  UINT32                    *ByteCount,\r
+  DATA_DIRECTION            Direction,\r
+  UINT64                    TimeOutInMicroSeconds\r
+  )\r
+;\r
+\r
+/**\r
+  TODO: Add function description\r
+\r
+  @param  AtapiScsiPrivate TODO: add argument description\r
+\r
+  TODO: add return values\r
+\r
+**/\r
+EFI_STATUS\r
+AtapiPassThruCheckErrorStatus (\r
+  ATAPI_SCSI_PASS_THRU_DEV        *AtapiScsiPrivate\r
+  )\r
+;\r
+#endif\r
diff --git a/MdeModulePkg/Bus/Pci/AtapiPassThruDxe/AtapiPassThru.inf b/MdeModulePkg/Bus/Pci/AtapiPassThruDxe/AtapiPassThru.inf
new file mode 100644 (file)
index 0000000..d449723
--- /dev/null
@@ -0,0 +1,93 @@
+#/** @file\r
+# Description file for the Atapi Passthru component.\r
+#\r
+# This driver simulates SCSI devices with Atapi devices to test the SCSI io\r
+#  protocol.\r
+# Copyright (c) 2006 - 2007, Intel Corporation\r
+#\r
+#  All rights reserved. This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = AtapiPassThru\r
+  FILE_GUID                      = E49061CE-99A7-41d3-AB3A-36E5CFBAD63E\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeAtapiPassThru\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+#  DRIVER_BINDING                =  gAtapiScsiPassThruDriverBinding              \r
+#  COMPONENT_NAME                =  gAtapiScsiPassThruComponentName              \r
+#\r
+\r
+################################################################################\r
+#\r
+# Sources Section - list of files that are required for the build to succeed.\r
+#\r
+################################################################################\r
+\r
+[Sources.common]\r
+  ComponentName.c\r
+  AtapiPassThru.c\r
+  AtapiPassThru.h\r
+\r
+\r
+################################################################################\r
+#\r
+# Package Dependency Section - list of Package files that are required for\r
+#                              this module.\r
+#\r
+################################################################################\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+################################################################################\r
+#\r
+# Library Class Section - list of Library Classes that are required for\r
+#                         this module.\r
+#\r
+################################################################################\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  UefiLib\r
+  BaseLib\r
+  UefiDriverEntryPoint\r
+  DebugLib\r
+\r
+\r
+################################################################################\r
+#\r
+# Protocol C Name Section - list of Protocol and Protocol Notify C Names\r
+#                           that this module uses or produces.\r
+#\r
+################################################################################\r
+\r
+[Protocols]\r
+  gEfiScsiPassThruProtocolGuid                  # PROTOCOL BY_START\r
+  gEfiPciIoProtocolGuid                         # PROTOCOL TO_START\r
+\r
diff --git a/MdeModulePkg/Bus/Pci/AtapiPassThruDxe/AtapiPassThru.msa b/MdeModulePkg/Bus/Pci/AtapiPassThruDxe/AtapiPassThru.msa
new file mode 100644 (file)
index 0000000..b33cb93
--- /dev/null
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>AtapiPassThru</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>E49061CE-99A7-41d3-AB3A-36E5CFBAD63E</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Description file for the Atapi Passthru component.</Abstract>\r
+    <Description>This driver simulates SCSI devices with Atapi devices to test the SCSI io\r
+      protocol.</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
+    <License>All rights reserved. This program and the accompanying materials\r
+      are licensed and made available under the terms and conditions of the BSD License\r
+      which accompanies this distribution.  The full text of the license may be found at\r
+      http://opensource.org/licenses/bsd-license.php\r
+      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+      WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>AtapiPassThru</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>AtapiPassThru.h</Filename>\r
+    <Filename>AtapiPassThru.c</Filename>\r
+    <Filename>ComponentName.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="1E73767F-8F52-4603-AEB4-F29B510B6766"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiPciIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiScsiPassThruProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <DriverBinding>gAtapiScsiPassThruDriverBinding</DriverBinding>\r
+      <ComponentName>gAtapiScsiPassThruComponentName</ComponentName>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>\r
diff --git a/MdeModulePkg/Bus/Pci/AtapiPassThruDxe/ComponentName.c b/MdeModulePkg/Bus/Pci/AtapiPassThruDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..1731571
--- /dev/null
@@ -0,0 +1,120 @@
+/** @file\r
+  Copyright (c) 2006, Intel Corporation                                                         \r
+  All rights reserved. This program and the accompanying materials                          \r
+  are licensed and made available under the terms and conditions of the BSD License         \r
+  which accompanies this distribution.  The full text of the license may be found at        \r
+  http://opensource.org/licenses/bsd-license.php                                            \r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+  Module Name:  ComponentName.c\r
+\r
+**/\r
+#include "AtapiPassThru.h"\r
+\r
+///\r
+/// EFI Component Name Protocol\r
+///\r
+EFI_COMPONENT_NAME_PROTOCOL     gAtapiScsiPassThruComponentName = {\r
+  AtapiScsiPassThruComponentNameGetDriverName,\r
+  AtapiScsiPassThruComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mAtapiScsiPassThruDriverNameTable[] = {\r
+  { "eng", (CHAR16 *) L"ATAPI SCSI Pass Thru Driver" },\r
+  { NULL , NULL }\r
+};\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
+\r
+  @param  This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+  @param  Language A pointer to a three character ISO 639-2 language identifier.\r
+  This is the language of the driver name that that the caller\r
+  is requesting, and it must match one of the languages specified\r
+  in SupportedLanguages.  The number of languages supported by a\r
+  driver is up to the driver writer.\r
+  @param  DriverName A pointer to the Unicode string to return.  This Unicode string\r
+  is the name of the driver specified by This in the language\r
+  specified by Language.\r
+\r
+  @retval  EFI_SUCCESS The Unicode string for the Driver specified by This\r
+  and the language specified by Language was returned\r
+  in DriverName.\r
+  @retval  EFI_INVALID_PARAMETER Language is NULL.\r
+  @retval  EFI_INVALID_PARAMETER DriverName is NULL.\r
+  @retval  EFI_UNSUPPORTED The driver specified by This does not support the\r
+  language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+{\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gAtapiScsiPassThruComponentName.SupportedLanguages,\r
+          mAtapiScsiPassThruDriverNameTable,\r
+          DriverName\r
+          );\r
+}\r
+\r
+/**\r
+  Retrieves a Unicode string that is the user readable name of the controller\r
+  that is being managed by an EFI Driver.\r
+\r
+  @param  This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+  @param  ControllerHandle The handle of a controller that the driver specified by\r
+  This is managing.  This handle specifies the controller\r
+  whose name is to be returned.\r
+  @param  ChildHandle The handle of the child controller to retrieve the name\r
+  of.  This is an optional parameter that may be NULL.  It\r
+  will be NULL for device drivers.  It will also be NULL\r
+  for a bus drivers that wish to retrieve the name of the\r
+  bus controller.  It will not be NULL for a bus driver\r
+  that wishes to retrieve the name of a child controller.\r
+  @param  Language A pointer to a three character ISO 639-2 language\r
+  identifier.  This is the language of the controller name\r
+  that that the caller is requesting, and it must match one\r
+  of the languages specified in SupportedLanguages.  The\r
+  number of languages supported by a driver is up to the\r
+  driver writer.\r
+  @param  ControllerName A pointer to the Unicode string to return.  This Unicode\r
+  string is the name of the controller specified by\r
+  ControllerHandle and ChildHandle in the language\r
+  specified by Language from the point of view of the\r
+  driver specified by This.\r
+\r
+  @retval  EFI_SUCCESS The Unicode string for the user readable name in the\r
+  language specified by Language for the driver\r
+  specified by This was returned in DriverName.\r
+  @retval  EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
+  @retval  EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
+  EFI_HANDLE.\r
+  @retval  EFI_INVALID_PARAMETER Language is NULL.\r
+  @retval  EFI_INVALID_PARAMETER ControllerName is NULL.\r
+  @retval  EFI_UNSUPPORTED The driver specified by This is not currently\r
+  managing the controller specified by\r
+  ControllerHandle and ChildHandle.\r
+  @retval  EFI_UNSUPPORTED The driver specified by This does not support the\r
+  language specified by Language.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AtapiScsiPassThruComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r