]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add IDE support for edk2 Duet platform.
authorklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 24 Jul 2009 07:36:29 +0000 (07:36 +0000)
committerklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 24 Jul 2009 07:36:29 +0000 (07:36 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9000 6f19259b-4bc3-4df7-8a09-765794883524

DuetPkg/DuetPkg.dsc
DuetPkg/DuetPkg.fdf
DuetPkg/IdeControllerDxe/ComponentName.h [new file with mode: 0644]
DuetPkg/IdeControllerDxe/IdeController.c [new file with mode: 0644]
DuetPkg/IdeControllerDxe/IdeController.h [new file with mode: 0644]
DuetPkg/IdeControllerDxe/IdeController.inf [new file with mode: 0644]
DuetPkg/IdeControllerDxe/IdeControllerName.c [new file with mode: 0644]
DuetPkg/IdeControllerDxe/IdeData.h [new file with mode: 0644]

index fa45258732d71ef2d533b369e8211cac2b94d054..525aa793445b7ac2aa052e9bad73380b7a016073 100644 (file)
   IntelFrameworkModulePkg/Universal/Console/VgaClassDxe/VgaClassDxe.inf
 
   # IDE Support
   IntelFrameworkModulePkg/Universal/Console/VgaClassDxe/VgaClassDxe.inf
 
   # IDE Support
-  #IntelFrameworkModulePkg/Bus/Pci/IdeBusDxe/IdeBusDxe.inf
-
+  IntelFrameworkModulePkg/Bus/Pci/IdeBusDxe/IdeBusDxe.inf
+  DuetPkg/IdeControllerDxe/IdeController.inf\r
+  
   # Usb Support
   MdeModulePkg/Bus/Pci/UhciDxe/UhciDxe.inf
   MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf
   # Usb Support
   MdeModulePkg/Bus/Pci/UhciDxe/UhciDxe.inf
   MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBusDxe.inf
index 928b0f991f70d01913e261f49cc3b0d0890512dc..aa1b6f7689975c9763504c8ad682ca2db7074179 100644 (file)
@@ -94,7 +94,8 @@ INF  IntelFrameworkModulePkg/Bus/Pci/VgaMiniPortDxe/VgaMiniPortDxe.inf
 INF  IntelFrameworkModulePkg/Universal/Console/VgaClassDxe/VgaClassDxe.inf\r
 \r
   # IDE Support\r
 INF  IntelFrameworkModulePkg/Universal/Console/VgaClassDxe/VgaClassDxe.inf\r
 \r
   # IDE Support\r
-#IntelFrameworkModulePkg/Bus/Pci/IdeBusDxe/IdeBusDxe.inf\r
+INF  IntelFrameworkModulePkg/Bus/Pci/IdeBusDxe/IdeBusDxe.inf\r
+INF  DuetPkg/IdeControllerDxe/IdeController.inf\r
 \r
   # Usb Support\r
 INF  MdeModulePkg/Bus/Pci/UhciDxe/UhciDxe.inf\r
 \r
   # Usb Support\r
 INF  MdeModulePkg/Bus/Pci/UhciDxe/UhciDxe.inf\r
diff --git a/DuetPkg/IdeControllerDxe/ComponentName.h b/DuetPkg/IdeControllerDxe/ComponentName.h
new file mode 100644 (file)
index 0000000..9797650
--- /dev/null
@@ -0,0 +1,145 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007 Intel Corporation. All rights reserved\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
+Module Name:\r
+\r
+  ComponentName.h\r
+\r
+Abstract:\r
+\r
+\r
+Revision History\r
+--*/\r
+\r
+#ifndef _IDE_CONTROLLER_COMPONENT_NAME_H\r
+#define _IDE_CONTROLLER_COMPONENT_NAME_H\r
+\r
+#ifndef EFI_SIZE_REDUCTION_APPLIED\r
+\r
+#include "Tiano.h"\r
+#include EFI_PROTOCOL_DEFINITION (ComponentName)\r
+#include EFI_PROTOCOL_DEFINITION (ComponentName2)\r
+\r
+//\r
+// Global Variables definitions\r
+//\r
+#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
+extern EFI_COMPONENT_NAME2_PROTOCOL gIdeControllerName;\r
+#else\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gIdeControllerName;\r
+#endif\r
+\r
+//\r
+// Forward reference declaration\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+IdeControllerGetDriverName (\r
+#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
+  IN  EFI_COMPONENT_NAME2_PROTOCOL *This,\r
+#else\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+#endif\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
+\r
+  Arguments:\r
+    This       - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    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
+    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
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the Driver specified by This\r
+                            and the language specified by Language was returned \r
+                            in DriverName.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - DriverName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeControllerGetControllerName (\r
+#if (EFI_SPECIFICATION_VERSION >= 0x00020000)\r
+  IN  EFI_COMPONENT_NAME2_PROTOCOL                    *This,\r
+#else\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+#endif\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\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
+  Arguments:\r
+    This             - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    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
+    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
+    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
+    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
+  Returns:\r
+    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
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid \r
+                            EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ControllerName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently \r
+                            managing the controller specified by \r
+                            ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+;\r
+\r
+#endif\r
+\r
+#endif\r
diff --git a/DuetPkg/IdeControllerDxe/IdeController.c b/DuetPkg/IdeControllerDxe/IdeController.c
new file mode 100644 (file)
index 0000000..d1334c0
--- /dev/null
@@ -0,0 +1,631 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007 Intel Corporation. All rights reserved\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
+Module Name:\r
+\r
+  IdeController.c\r
+\r
+Abstract:\r
+    \r
+  This driver module produces IDE_CONTROLLER_INIT protocol and will be used by \r
+  IDE Bus driver to support platform dependent timing information. This driver\r
+  is responsible for early initialization of IDE controller.\r
+\r
+Revision History\r
+--*/\r
+\r
+#include "IdeController.h"\r
+#include "IdeData.h"\r
+\r
+//\r
+// IDE Controller Init Guid\r
+//\r
+EFI_GUID\r
+  gIdeControllerDriverGuid = { 0x91e365e9, 0xe0c0, 0x4647, 0xb0, 0xeb, 0xf6, 0x78, 0xf6, 0x21, 0xf8, 0x8d };\r
+\r
+//\r
+//  EFI_DRIVER_BINDING_PROTOCOL instance\r
+//\r
+EFI_DRIVER_BINDING_PROTOCOL gIdeControllerDriverBinding = {\r
+  IdeControllerSupported,\r
+  IdeControllerStart,\r
+  IdeControllerStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+//\r
+// Internal function definitions\r
+//\r
+EFI_STATUS\r
+EnableNativeIdeDecode (\r
+  IN  EFI_PCI_IO_PROTOCOL        *PciIo\r
+  );\r
+\r
+EFI_STATUS\r
+EnableLegacyIdeDecode (\r
+  EFI_EVENT  Event,\r
+  VOID       *Context\r
+  );\r
+\r
+EFI_STATUS\r
+IdeDetectCableType (\r
+  IN  UINT8                      Channel,\r
+  IN  UINT8                      Device,\r
+  IN  EFI_PCI_IO_PROTOCOL        *PciIo,\r
+  IN  EFI_IDENTIFY_DATA          *IdentifyData\r
+  );\r
+\r
+EFI_STATUS\r
+AdjustUdmaModeByCableType (\r
+  IN     UINT8                   Channel,\r
+  IN     UINT8                   Device,\r
+  IN     EFI_PCI_IO_PROTOCOL     *PciIo,\r
+  IN OUT EFI_ATA_COLLECTIVE_MODE *Modes\r
+  );\r
+\r
+EFI_STATUS\r
+CalculateBestPioMode (\r
+  IN  EFI_IDENTIFY_DATA          * IdentifyData,\r
+  IN  UINT16                     *DisPioMode OPTIONAL,\r
+  OUT UINT16                     *SelectedMode\r
+  );\r
+\r
+EFI_STATUS\r
+CalculateBestUdmaMode (\r
+  IN  EFI_IDENTIFY_DATA          * IdentifyData,\r
+  IN  UINT16                     *DisUDmaMode OPTIONAL,\r
+  OUT UINT16                     *SelectedMode\r
+  );\r
+\r
+EFI_STATUS\r
+IdeInitSetUdmaTiming (\r
+  IN  UINT8                       Channel,\r
+  IN  UINT8                       Device,\r
+  IN  EFI_PCI_IO_PROTOCOL         *PciIo,\r
+  IN  EFI_ATA_COLLECTIVE_MODE     *Modes\r
+  );\r
+\r
+EFI_STATUS\r
+IdeInitSetPioTiming (\r
+  IN  UINT8                       Channel,\r
+  IN  UINT8                       Device,\r
+  IN  EFI_PCI_IO_PROTOCOL         *PciIo,\r
+  IN  EFI_IDENTIFY_DATA           *IdentifyData,\r
+  IN  EFI_ATA_COLLECTIVE_MODE     *Modes\r
+  );\r
+\r
+//\r
+// *************************************\r
+//  IdeController Driver Entry Point\r
+// *************************************\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeIdeControllerDriver (\r
+  IN EFI_HANDLE       ImageHandle,\r
+  IN EFI_SYSTEM_TABLE *SystemTable\r
+  )\r
+/*++\r
+  Routine Description:\r
+  \r
+    Chipset Ide Driver EntryPoint function. It follows the standard EFI driver \r
+    model. It's called by StartImage() of DXE Core\r
+    \r
+  Argments:\r
+  \r
+    ImageHnadle  -- While the driver image loaded be the ImageLoader(), \r
+                    an image handle is assigned to this driver binary, \r
+                    all activities of the driver is tied to this ImageHandle\r
+    *SystemTable -- A pointer to the system table, for all BS(Boo Services) and\r
+                    RT(Runtime Services)\r
+\r
+  Retruns:\r
+  \r
+    Always call EfiLibInstallDriverBindingProtocol( ) and retrun the result\r
+\r
+--*/\r
+{\r
+\r
+  return  EfiLibInstallDriverBindingComponentName2 (\r
+            ImageHandle,\r
+            SystemTable,\r
+            &gIdeControllerDriverBinding,\r
+            ImageHandle,\r
+            &gIdeControllerName,\r
+            &gIdeControllerName2\r
+            );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeControllerSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
+  IN EFI_HANDLE                  Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL    *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+  \r
+  Register Driver Binding protocol for this driver.\r
+  \r
+  Arguments:\r
+  \r
+    This                 -- a pointer points to the Binding Protocol instance\r
+    Controller           -- The handle of controller to be tested. \r
+    *RemainingDevicePath -- A pointer to the device path. Ignored by device\r
+                            driver but used by bus driver\r
+\r
+  Returns:\r
+\r
+    EFI_SUCCESS          -- Driver loaded.\r
+    other                -- Driver not loaded.\r
+--*/\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
+  EFI_PCI_IO_PROTOCOL       *PciIo;\r
+  PCI_TYPE00                PciData;\r
+\r
+  //\r
+  // Ide Controller is a device driver, and should ingore the\r
+  // "RemainingDevicePath" according to EFI spec\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID *) &ParentDevicePath,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // EFI_ALREADY_STARTED is also an error\r
+    //\r
+    return Status;\r
+  }\r
+  //\r
+  // Close the protocol because we don't use it here\r
+  //\r
+  gBS->CloseProtocol (\r
+        Controller,\r
+        &gEfiDevicePathProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Controller\r
+        );\r
+\r
+  //\r
+  // Now test the EfiPciIoProtocol\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
+  // Now further check the PCI header: Base class (offset 0x0B) and\r
+  // Sub Class (offset 0x0A). This controller should be an Ide controller\r
+  //\r
+  Status = PciIo->Pci.Read (\r
+                        PciIo,\r
+                        EfiPciIoWidthUint8,\r
+                        0,\r
+                        sizeof (PciData),\r
+                        &PciData\r
+                        );\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
+  // Examine Ide PCI Configuration table fields\r
+  //\r
+  if ((PciData.Hdr.ClassCode[2] != PCI_CLASS_MASS_STORAGE) ||\r
+      (PciData.Hdr.ClassCode[1] != PCI_SUB_CLASS_IDE)\r
+      ) {\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
+EFI_STATUS\r
+EFIAPI\r
+IdeControllerStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+  \r
+    This routine is called right after the .Supported() called and return \r
+    EFI_SUCCESS. Notes: The supported protocols are checked but the Protocols\r
+    are closed.\r
+\r
+  Arguments:\r
+      \r
+    This                 -- a pointer points to the Binding Protocol instance\r
+    Controller           -- The handle of controller to be tested. Parameter\r
+                            passed by the caller\r
+    *RemainingDevicePath -- A pointer to the device path. Should be ignored by\r
+                            device driver\r
+--*/\r
+{\r
+  EFI_STATUS                      Status;\r
+  EFI_PCI_IO_PROTOCOL             *PciIo;\r
+  EFI_IDE_CONTROLLER_PRIVATE_DATA *IdePrivateData;\r
+\r
+  //\r
+  // Now test and open the EfiPciIoProtocol\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
+\r
+  //\r
+  // Status == 0 - A normal execution flow, SUCCESS and the program proceeds.\r
+  // Status == ALREADY_STARTED - A non-zero Status code returned. It indicates\r
+  //           that the protocol has been opened and should be treated as a\r
+  //           normal condition and the program proceeds. The Protocol will not\r
+  //           opened 'again' by this call.\r
+  // Status != ALREADY_STARTED - Error status, terminate program execution\r
+  //\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // EFI_ALREADY_STARTED is also an error\r
+    //\r
+    return Status;\r
+  }\r
+  //\r
+  // Allocate Ide private data structure\r
+  //\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  sizeof (EFI_IDE_CONTROLLER_PRIVATE_DATA),\r
+                  (VOID **) &IdePrivateData\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  //\r
+  // Initialize Ide controller private data\r
+  //\r
+  ZeroMem (IdePrivateData, sizeof (EFI_IDE_CONTROLLER_PRIVATE_DATA));\r
+  IdePrivateData->Signature               = IDE_CONTROLLER_SIGNATURE;\r
+  IdePrivateData->PciIo                   = PciIo;\r
+  IdePrivateData->IdeInit.GetChannelInfo  = IdeInitGetChannelInfo;\r
+  IdePrivateData->IdeInit.NotifyPhase     = IdeInitNotifyPhase;\r
+  IdePrivateData->IdeInit.SubmitData      = IdeInitSubmitData;\r
+  IdePrivateData->IdeInit.DisqualifyMode  = IdeInitDisqualifyMode;\r
+  IdePrivateData->IdeInit.CalculateMode   = IdeInitCalculateMode;\r
+  IdePrivateData->IdeInit.SetTiming       = IdeInitSetTiming;\r
+  IdePrivateData->IdeInit.EnumAll         = ICH_IDE_ENUMER_ALL;\r
+  IdePrivateData->IdeInit.ChannelCount    = ICH_IDE_MAX_CHANNEL;\r
+\r
+  //\r
+  // Install IDE_CONTROLLER_INIT protocol & private data to this instance\r
+  //\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Controller,\r
+                  &gIdeControllerDriverGuid,\r
+                  IdePrivateData,\r
+                  &gEfiIdeControllerInitProtocolGuid,\r
+                  &(IdePrivateData->IdeInit),\r
+                  NULL\r
+                  );\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeControllerStop (\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
+  Routine Description:\r
+    Stop this driver on Controller Handle. \r
+\r
+  Arguments:\r
+    This              - Protocol instance pointer.\r
+    Controller        - Handle of device to stop driver on \r
+    NumberOfChildren  - Not used\r
+    ChildHandleBuffer - Not used\r
+\r
+  Returns:\r
+    EFI_SUCCESS       - This driver is removed DeviceHandle\r
+    other             - This driver was not removed from this device\r
+  \r
+--*/\r
+{\r
+  EFI_STATUS                      Status;\r
+  EFI_IDE_CONTROLLER_PRIVATE_DATA *IdePrivateData;\r
+\r
+  //\r
+  // Get private data\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gIdeControllerDriverGuid,\r
+                  (VOID **) &IdePrivateData,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Close protocols opened by Ide controller driver\r
+  //\r
+  Status = gBS->CloseProtocol (\r
+                  Controller,\r
+                  &gEfiPciIoProtocolGuid,\r
+                  This->DriverBindingHandle,\r
+                  Controller\r
+                  );\r
+\r
+  gBS->UninstallMultipleProtocolInterfaces (\r
+        Controller,\r
+        &gIdeControllerDriverGuid,\r
+        IdePrivateData,\r
+        &gEfiIdeControllerInitProtocolGuid,\r
+        &(IdePrivateData->IdeInit),\r
+        NULL\r
+        );\r
+\r
+  gBS->FreePool (IdePrivateData);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+//\r
+// Interface functions of IDE_CONTROLLER_INIT protocol\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+IdeInitGetChannelInfo (\r
+  IN   EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
+  IN   UINT8                            Channel,\r
+  OUT  BOOLEAN                          *Enabled,\r
+  OUT  UINT8                            *MaxDevices\r
+  )\r
+/*++\r
+Routine Description:\r
+\r
+  This function can be used to obtain information about a specified channel. \r
+  It's usually used by IDE Bus driver during enumeration process.\r
+\r
+Arguments:\r
+\r
+  This       -- the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
+  Channel    -- Channel number (0 based, either 0 or 1)\r
+  Enabled    -- TRUE if the channel is enabled. If the channel is disabled, \r
+                then it will no be enumerated.\r
+  MaxDevices -- The Max number of IDE devices that the bus driver can expect\r
+                on this channel. For ATA/ATAPI, this number is either 1 or 2.\r
+\r
+Returns:\r
+  EFI_STATUS \r
+\r
+--*/\r
+{\r
+  //\r
+  // Channel number (0 based, either 0 or 1)\r
+  //\r
+  if (Channel < ICH_IDE_MAX_CHANNEL) {\r
+    *Enabled    = TRUE;\r
+    *MaxDevices = ICH_IDE_MAX_DEVICES;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  *Enabled = FALSE;\r
+  return EFI_INVALID_PARAMETER;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeInitNotifyPhase (\r
+  IN  EFI_IDE_CONTROLLER_INIT_PROTOCOL   *This,\r
+  IN  EFI_IDE_CONTROLLER_ENUM_PHASE      Phase,\r
+  IN  UINT8                              Channel\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function is called by IdeBus driver before executing certain actions. \r
+  This allows IDE Controller Init to prepare for each action.\r
+\r
+Arguments:\r
+\r
+  This     -- the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
+  Phase    -- phase indicator defined by IDE_CONTROLLER_INIT protocol\r
+  Channel  -- Channel number (0 based, either 0 or 1)\r
+\r
+Returns:\r
+    \r
+--*/\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeInitSubmitData (\r
+  IN  EFI_IDE_CONTROLLER_INIT_PROTOCOL    *This,\r
+  IN  UINT8                               Channel,\r
+  IN  UINT8                               Device,\r
+  IN  EFI_IDENTIFY_DATA                   *IdentifyData\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function is called by IdeBus driver to submit EFI_IDENTIFY_DATA data structure\r
+  obtained from IDE deivce. This structure is used to set IDE timing\r
+\r
+Arguments:\r
+\r
+  This         -- the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
+  Channel      -- IDE channel number (0 based, either 0 or 1)\r
+  Device       -- IDE device number\r
+  IdentifyData -- A pointer to EFI_IDENTIFY_DATA data structure\r
+\r
+Returns:\r
+    \r
+--*/\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeInitDisqualifyMode (\r
+  IN  EFI_IDE_CONTROLLER_INIT_PROTOCOL    *This,\r
+  IN  UINT8                               Channel,\r
+  IN  UINT8                               Device,\r
+  IN  EFI_ATA_COLLECTIVE_MODE             *BadModes\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function is called by IdeBus driver to disqualify unsupported operation\r
+  mode on specfic IDE device\r
+\r
+Arguments:\r
+\r
+  This     -- the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
+  Channel  -- IDE channel number (0 based, either 0 or 1)\r
+  Device   -- IDE device number\r
+  BadModes -- Operation mode indicator\r
+\r
+Returns:\r
+    \r
+--*/\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeInitCalculateMode (\r
+  IN  EFI_IDE_CONTROLLER_INIT_PROTOCOL       *This,\r
+  IN  UINT8                                  Channel,\r
+  IN  UINT8                                  Device,\r
+  OUT EFI_ATA_COLLECTIVE_MODE                **SupportedModes\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function is called by IdeBus driver to calculate the best operation mode\r
+  supported by specific IDE device\r
+\r
+Arguments:\r
+\r
+  This           -- the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
+  Channel        -- IDE channel number (0 based, either 0 or 1)\r
+  Device         -- IDE device number\r
+  SupportedModes -- Modes collection supported by IDE device\r
+\r
+Returns:\r
+    \r
+--*/\r
+{\r
+  if (Channel >= ICH_IDE_MAX_CHANNEL || Device >= ICH_IDE_MAX_DEVICES) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *SupportedModes = AllocateZeroPool (sizeof (EFI_ATA_COLLECTIVE_MODE));\r
+  if (*SupportedModes == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // In EoE enviroment, when nothing is known about the platform hardware,\r
+  // just set the mode to lowest PIO mode for compatibility.\r
+  //\r
+  (*SupportedModes)->PioMode.Valid  = TRUE;\r
+  (*SupportedModes)->PioMode.Mode   = AtaPioModeBelow2;\r
+  (*SupportedModes)->UdmaMode.Valid = FALSE;\r
+  (*SupportedModes)->SingleWordDmaMode.Valid = FALSE;\r
+  (*SupportedModes)->MultiWordDmaMode.Valid = FALSE;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeInitSetTiming (\r
+  IN  EFI_IDE_CONTROLLER_INIT_PROTOCOL    *This,\r
+  IN  UINT8                               Channel,\r
+  IN  UINT8                               Device,\r
+  IN  EFI_ATA_COLLECTIVE_MODE             *Modes\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function is called by IdeBus driver to set appropriate timing on IDE\r
+  controller according supported operation mode\r
+\r
+Arguments:\r
+\r
+  This           -- the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.\r
+  Channel        -- IDE channel number (0 based, either 0 or 1)\r
+  Device         -- IDE device number\r
+\r
+Returns:\r
+    \r
+--*/\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
diff --git a/DuetPkg/IdeControllerDxe/IdeController.h b/DuetPkg/IdeControllerDxe/IdeController.h
new file mode 100644 (file)
index 0000000..15f7ba4
--- /dev/null
@@ -0,0 +1,382 @@
+/*++\r
+\r
+Copyright (c) 2006 Intel Corporation. All rights reserved\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
+Module Name:\r
+\r
+  IdeController.h\r
+\r
+Abstract:\r
+\r
+  Header file for chipset ATA controller driver.\r
+\r
+Revision History\r
+--*/\r
+\r
+#ifndef _IDE_CONTROLLER_H\r
+#define _IDE_CONTROLLER_H\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Protocol/PciIo.h>\r
+#include <Protocol/IdeControllerInit.h>\r
+\r
+//\r
+// Driver Binding Externs\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL  gIdeControllerDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gIdeControllerName;\r
+extern EFI_COMPONENT_NAME2_PROTOCOL gIdeControllerName2;\r
+\r
+#include <IndustryStandard/Pci22.h>\r
+\r
+//\r
+// Symbol definition, for PCI IDE configuration field\r
+//\r
+#define PCI_CLASS_MASS_STORAGE  0x01\r
+#define PCI_SUB_CLASS_IDE       0x01\r
+\r
+//\r
+// Supports 2 channel max\r
+//\r
+#define ICH_IDE_MAX_CHANNEL 0x02\r
+//\r
+// Supports 2 devices max\r
+//\r
+#define ICH_IDE_MAX_DEVICES 0x02\r
+#define ICH_IDE_ENUMER_ALL  FALSE\r
+\r
+#define IDE_CONTROLLER_SIGNATURE  SIGNATURE_32 ('i', 'i', 'd', 'e')\r
+\r
+//\r
+// Ide controller driver private data structure\r
+//\r
+typedef struct {\r
+  //\r
+  // Standard signature used to identify Ide controller private data\r
+  //\r
+  UINT32                            Signature;\r
+\r
+  //\r
+  // Protocol instance of IDE_CONTROLLER_INIT produced by this driver\r
+  //\r
+  EFI_IDE_CONTROLLER_INIT_PROTOCOL  IdeInit;\r
+\r
+  //\r
+  // copy of protocol pointers used by this driver\r
+  //\r
+  EFI_PCI_IO_PROTOCOL               *PciIo;\r
+\r
+  //\r
+  // The highest disqulified mode for each attached Ide device.\r
+  // Per ATA/ATAPI spec, if a mode is not supported, the modes higher than\r
+  // it should not be supported\r
+  //\r
+  EFI_ATA_COLLECTIVE_MODE           DisqulifiedModes[ICH_IDE_MAX_CHANNEL][ICH_IDE_MAX_DEVICES];\r
+\r
+  //\r
+  // A copy of EFI_IDENTIFY_DATA data for each attached Ide device and its flag\r
+  //\r
+  EFI_IDENTIFY_DATA                 IdentifyData[ICH_IDE_MAX_CHANNEL][ICH_IDE_MAX_DEVICES];\r
+  BOOLEAN                           IdentifyValid[ICH_IDE_MAX_CHANNEL][ICH_IDE_MAX_DEVICES];\r
+\r
+} EFI_IDE_CONTROLLER_PRIVATE_DATA;\r
+\r
+#define IDE_CONTROLLER_PRIVATE_DATA_FROM_THIS(a) \\r
+  CR (a, \\r
+      EFI_IDE_CONTROLLER_PRIVATE_DATA, \\r
+      IdeInit, \\r
+      IDE_CONTROLLER_SIGNATURE \\r
+      )\r
+\r
+//\r
+// Driver binding functions declaration\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+IdeControllerSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL       *This,\r
+  IN EFI_HANDLE                        Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL          *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+  \r
+  Register Driver Binding protocol for this driver.\r
+  \r
+  Arguments:\r
+  \r
+    This                 -- a pointer points to the Binding Protocol instance\r
+    Controller           -- The handle of controller to be tested. \r
+    *RemainingDevicePath -- A pointer to the device path. Ignored by device\r
+                            driver but used by bus driver\r
+\r
+  Returns:\r
+\r
+    EFI_SUCCESS          -- Driver loaded.\r
+    other                -- Driver not loaded.\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeControllerStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL        *This,\r
+  IN EFI_HANDLE                         Controller,\r
+  IN EFI_DEVICE_PATH_PROTOCOL           *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+  \r
+    This routine is called right after the .Supported() called and return \r
+    EFI_SUCCESS. Notes: The supported protocols are checked but the Protocols\r
+    are closed.\r
+\r
+  Arguments:\r
+      \r
+    This                 -- a pointer points to the Binding Protocol instance\r
+    Controller           -- The handle of controller to be tested. Parameter\r
+                            passed by the caller\r
+    *RemainingDevicePath -- A pointer to the device path. Should be ignored by\r
+                            device driver\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeControllerStop (\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
+  Routine Description:\r
+    Stop this driver on Controller Handle. \r
+\r
+  Arguments:\r
+    This              - Protocol instance pointer.\r
+    Controller        - Handle of device to stop driver on \r
+    NumberOfChildren  - Not used\r
+    ChildHandleBuffer - Not used\r
+\r
+  Returns:\r
+    EFI_SUCCESS       - This driver is removed DeviceHandle\r
+    other             - This driver was not removed from this device\r
+  \r
+--*/\r
+;\r
+\r
+//\r
+// IDE controller init functions declaration\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+IdeInitGetChannelInfo (\r
+  IN   EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,\r
+  IN   UINT8                            Channel,\r
+  OUT  BOOLEAN                          *Enabled,\r
+  OUT  UINT8                            *MaxDevices\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  Channel     - TODO: add argument description\r
+  Enabled     - TODO: add argument description\r
+  MaxDevices  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeInitNotifyPhase (\r
+  IN  EFI_IDE_CONTROLLER_INIT_PROTOCOL  *This,\r
+  IN  EFI_IDE_CONTROLLER_ENUM_PHASE     Phase,\r
+  OUT UINT8                             Channel\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  Phase   - TODO: add argument description\r
+  Channel - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeInitSubmitData (\r
+  IN  EFI_IDE_CONTROLLER_INIT_PROTOCOL  *This,\r
+  IN  UINT8                             Channel,\r
+  IN  UINT8                             Device,\r
+  IN  EFI_IDENTIFY_DATA                 *IdentifyData\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This          - TODO: add argument description\r
+  Channel       - TODO: add argument description\r
+  Device        - TODO: add argument description\r
+  IdentifyData  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeInitSubmitFailingModes (\r
+  IN  EFI_IDE_CONTROLLER_INIT_PROTOCOL  *This,\r
+  IN  UINT8                             Channel,\r
+  IN  UINT8                             Device\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  Channel - TODO: add argument description\r
+  Device  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeInitDisqualifyMode (\r
+  IN  EFI_IDE_CONTROLLER_INIT_PROTOCOL  *This,\r
+  IN  UINT8                             Channel,\r
+  IN  UINT8                             Device,\r
+  IN  EFI_ATA_COLLECTIVE_MODE           *BadModes\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This      - TODO: add argument description\r
+  Channel   - TODO: add argument description\r
+  Device    - TODO: add argument description\r
+  BadModes  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeInitCalculateMode (\r
+  IN  EFI_IDE_CONTROLLER_INIT_PROTOCOL  *This,\r
+  IN  UINT8                             Channel,\r
+  IN  UINT8                             Device,\r
+  IN  EFI_ATA_COLLECTIVE_MODE           **SupportedModes\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This            - TODO: add argument description\r
+  Channel         - TODO: add argument description\r
+  Device          - TODO: add argument description\r
+  SupportedModes  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeInitSetTiming (\r
+  IN  EFI_IDE_CONTROLLER_INIT_PROTOCOL  *This,\r
+  IN  UINT8                             Channel,\r
+  IN  UINT8                             Device,\r
+  IN  EFI_ATA_COLLECTIVE_MODE           *Modes\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  Channel - TODO: add argument description\r
+  Device  - TODO: add argument description\r
+  Modes   - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+#endif\r
diff --git a/DuetPkg/IdeControllerDxe/IdeController.inf b/DuetPkg/IdeControllerDxe/IdeController.inf
new file mode 100644 (file)
index 0000000..076dd10
--- /dev/null
@@ -0,0 +1,55 @@
+#/*++\r
+#\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:\r
+#\r
+#   IdeController.inf\r
+#\r
+# Abstract:\r
+#\r
+#   Component description file for IDE Controller Driver module.\r
+#\r
+#--*/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = IdeController\r
+  FILE_GUID                      = F3790689-FB90-4479-A2EF-B82A43AFE74D\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+  ENTRY_POINT                    = InitializeIdeControllerDriver\r
+  \r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  DuetPkg/DuetPkg.dec\r
+  \r
+[Sources]\r
+  IdeController.h\r
+  IdeController.c\r
+  IdeControllerName.c\r
+  \r
+\r
+[LibraryClasses]\r
+  UefiLib\r
+  MemoryAllocationLib\r
+  DebugLib\r
+  BaseMemoryLib\r
+  UefiDriverEntryPoint\r
+  UefiBootServicesTableLib\r
+\r
+[Protocols]\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL TO_START\r
+  gEfiIdeControllerInitProtocolGuid             # PROTOCOL BY_START\r
+  gEfiPciIoProtocolGuid                         # PROTOCOL TO_START\r
+\r
diff --git a/DuetPkg/IdeControllerDxe/IdeControllerName.c b/DuetPkg/IdeControllerDxe/IdeControllerName.c
new file mode 100644 (file)
index 0000000..69ef253
--- /dev/null
@@ -0,0 +1,215 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007 Intel Corporation. All rights reserved\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
+Module Name:\r
+  \r
+  IdeControllerName.c\r
+\r
+Abstract: \r
+\r
+  This portion is to register the IDE Controller Driver name:\r
+  "IDE Controller Init Driver"\r
+\r
+Revision History\r
+--*/\r
+\r
+#include "IdeController.h"\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeControllerGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+  \r
+EFI_STATUS\r
+EFIAPI\r
+IdeControllerGetControllerName (\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
+// EFI Component Name Protocol\r
+// This portion declares a gloabl variable of EFI_COMPONENT_NAME_PROTOCOL type.\r
+// It initializes the followings:\r
+//      .GetDriverName()     to PlatformIdeGetDriverName() and\r
+//      SupportedLanguages   to LANGUAGE_CODE_ENGLISH (3 char ISO639-2 language indetifier)\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gIdeControllerName = {\r
+  IdeControllerGetDriverName,\r
+  IdeControllerGetControllerName,\r
+  "eng" // Egnlish\r
+};\r
+\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gIdeControllerName2 = {\r
+  (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) IdeControllerGetDriverName,\r
+  (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) IdeControllerGetControllerName,\r
+  "en" // Egnlish\r
+};\r
+\r
+//\r
+//  Define the Driver's unicode name string\r
+//  IDE controller Driver name string and IDE Controller Name string\r
+//\r
+static EFI_UNICODE_STRING_TABLE mIdeControllerDriverNameTable[] = {\r
+  {\r
+    "eng;en",\r
+    L"IDE Controller Init Driver"\r
+  },\r
+  {\r
+    NULL,\r
+    NULL\r
+  }\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mIdeControllerControllerNameTable[] = {\r
+  {\r
+    "eng;en",\r
+    L"ICH IDE Controller"\r
+  },\r
+  {\r
+    NULL,\r
+    NULL\r
+  }\r
+};\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeControllerGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
+\r
+  Arguments:\r
+    This       - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    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
+    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
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the Driver specified by This\r
+                            and the language specified by Language was returned \r
+                            in DriverName.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - DriverName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+\r
+  return LookupUnicodeString2 (\r
+          Language,\r
+          This->SupportedLanguages,\r
+          mIdeControllerDriverNameTable,\r
+          DriverName,\r
+          (BOOLEAN)(This == &gIdeControllerName)\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+IdeControllerGetControllerName (\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
+  Routine Description:\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
+  Arguments:\r
+    This             - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    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
+    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
+    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
+    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
+  Returns:\r
+    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
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid \r
+                            EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ControllerName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently \r
+                            managing the controller specified by \r
+                            ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Make sure this driver is currently managing ControllHandle\r
+  //\r
+  Status = EfiTestManagedDevice (\r
+             ControllerHandle,\r
+             gIdeControllerDriverBinding.DriverBindingHandle,\r
+             &gEfiPciIoProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           mIdeControllerControllerNameTable,\r
+           ControllerName,\r
+           (BOOLEAN)(This == &gIdeControllerName)\r
+           );\r
+}\r
diff --git a/DuetPkg/IdeControllerDxe/IdeData.h b/DuetPkg/IdeControllerDxe/IdeData.h
new file mode 100644 (file)
index 0000000..1baf46b
--- /dev/null
@@ -0,0 +1,311 @@
+/** @file\r
+  Header file for IDE Bus Driver's Data Structures\r
+\r
+  Copyright (c) 2006 - 2007 Intel Corporation. <BR>\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
+#ifndef _IDE_DATA_H_\r
+#define _IDE_DATA_H_\r
+\r
+#include <IndustryStandard/Atapi.h>\r
+\r
+//\r
+// common constants\r
+//\r
+#define STALL_1_MILLI_SECOND  1000    // stall 1 ms\r
+#define STALL_1_SECOND        1000000 // stall 1 second\r
+typedef enum {\r
+  IdePrimary    = 0,\r
+  IdeSecondary  = 1,\r
+  IdeMaxChannel = 2\r
+} EFI_IDE_CHANNEL;\r
+\r
+typedef enum {\r
+  IdeMaster     = 0,\r
+  IdeSlave      = 1,\r
+  IdeMaxDevice  = 2\r
+} EFI_IDE_DEVICE;\r
+\r
+typedef enum {\r
+  IdeMagnetic,                        /* ZIP Drive or LS120 Floppy Drive */\r
+  IdeCdRom,                           /* ATAPI CDROM */\r
+  IdeHardDisk,                        /* Hard Disk */\r
+  Ide48bitAddressingHardDisk,         /* Hard Disk larger than 120GB */\r
+  IdeUnknown\r
+} IDE_DEVICE_TYPE;\r
+\r
+typedef enum {\r
+  SenseNoSenseKey,\r
+  SenseDeviceNotReadyNoRetry,\r
+  SenseDeviceNotReadyNeedRetry,\r
+  SenseNoMedia,\r
+  SenseMediaChange,\r
+  SenseMediaError,\r
+  SenseOtherSense\r
+} SENSE_RESULT;\r
+\r
+typedef enum {\r
+  AtaUdmaReadOp,\r
+  AtaUdmaReadExtOp,\r
+  AtaUdmaWriteOp,\r
+  AtaUdmaWriteExtOp\r
+} ATA_UDMA_OPERATION;\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
+  UINT16                          BusMasterBaseAddr;\r
+} IDE_BASE_REGISTERS;\r
+\r
+//\r
+// IDE registers' base addresses\r
+//\r
+typedef struct {\r
+  UINT16  CommandBlockBaseAddr;\r
+  UINT16  ControlBlockBaseAddr;\r
+  UINT16  BusMasterBaseAddr;\r
+} IDE_REGISTERS_BASE_ADDR;\r
+\r
+//\r
+// Bit definitions in Programming Interface byte of the Class Code field\r
+// in PCI IDE controller's Configuration Space\r
+//\r
+#define IDE_PRIMARY_OPERATING_MODE            BIT0\r
+#define IDE_PRIMARY_PROGRAMMABLE_INDICATOR    BIT1\r
+#define IDE_SECONDARY_OPERATING_MODE          BIT2\r
+#define IDE_SECONDARY_PROGRAMMABLE_INDICATOR  BIT3\r
+\r
+\r
+//\r
+// Bus Master Reg\r
+//\r
+#define BMIC_NREAD      BIT3\r
+#define BMIC_START      BIT0\r
+#define BMIS_INTERRUPT  BIT2\r
+#define BMIS_ERROR      BIT1\r
+\r
+#define BMICP_OFFSET    0x00\r
+#define BMISP_OFFSET    0x02\r
+#define BMIDP_OFFSET    0x04\r
+#define BMICS_OFFSET    0x08\r
+#define BMISS_OFFSET    0x0A\r
+#define BMIDS_OFFSET    0x0C\r
+\r
+//\r
+// Time Out Value For IDE Device Polling\r
+//\r
+\r
+//\r
+// ATATIMEOUT is used for waiting time out for ATA device\r
+//\r
+\r
+//\r
+// 1 second\r
+//\r
+#define ATATIMEOUT  1000  \r
+\r
+//\r
+// ATAPITIMEOUT is used for waiting operation\r
+// except read and write time out for ATAPI device\r
+//\r
+\r
+//\r
+// 1 second\r
+//\r
+#define ATAPITIMEOUT  1000 \r
+\r
+//\r
+// ATAPILONGTIMEOUT is used for waiting read and\r
+// write operation timeout for ATAPI device\r
+//\r
+\r
+//\r
+// 2 seconds\r
+//\r
+#define CDROMLONGTIMEOUT  2000  \r
+\r
+//\r
+// 5 seconds\r
+//\r
+#define ATAPILONGTIMEOUT  5000  \r
+\r
+//\r
+// 10 seconds\r
+//\r
+#define ATASMARTTIMEOUT   10000\r
+\r
+\r
+//\r
+// ATAPI6 related data structure definition\r
+//\r
+\r
+//\r
+// The maximum sectors count in 28 bit addressing mode\r
+//\r
+#define MAX_28BIT_ADDRESSING_CAPACITY 0xfffffff\r
+\r
+#pragma pack(1)\r
+\r
+typedef struct {\r
+  UINT32  RegionBaseAddr;\r
+  UINT16  ByteCount;\r
+  UINT16  EndOfTable;\r
+} IDE_DMA_PRD;\r
+\r
+#pragma pack()\r
+\r
+#define SETFEATURE        TRUE\r
+#define CLEARFEATURE      FALSE\r
+\r
+///\r
+/// PIO mode definition\r
+///\r
+typedef enum _ATA_PIO_MODE_ {\r
+  AtaPioModeBelow2,\r
+  AtaPioMode2,\r
+  AtaPioMode3,\r
+  AtaPioMode4\r
+} ATA_PIO_MODE;\r
+\r
+//\r
+// Multi word DMA definition\r
+//\r
+typedef enum _ATA_MDMA_MODE_ {\r
+  AtaMdmaMode0,\r
+  AtaMdmaMode1,\r
+  AtaMdmaMode2\r
+} ATA_MDMA_MODE;\r
+\r
+//\r
+// UDMA mode definition\r
+//\r
+typedef enum _ATA_UDMA_MODE_ {\r
+  AtaUdmaMode0,\r
+  AtaUdmaMode1,\r
+  AtaUdmaMode2,\r
+  AtaUdmaMode3,\r
+  AtaUdmaMode4,\r
+  AtaUdmaMode5\r
+} ATA_UDMA_MODE;\r
+\r
+#define ATA_MODE_CATEGORY_DEFAULT_PIO 0x00\r
+#define ATA_MODE_CATEGORY_FLOW_PIO    0x01\r
+#define ATA_MODE_CATEGORY_MDMA        0x04\r
+#define ATA_MODE_CATEGORY_UDMA        0x08\r
+\r
+#pragma pack(1)\r
+\r
+typedef struct {\r
+  UINT8 ModeNumber : 3;\r
+  UINT8 ModeCategory : 5;\r
+} ATA_TRANSFER_MODE;\r
+\r
+typedef struct {\r
+  UINT8 Sector;\r
+  UINT8 Heads;\r
+  UINT8 MultipleSector;\r
+} ATA_DRIVE_PARMS;\r
+\r
+#pragma pack()\r
+//\r
+// IORDY Sample Point field value\r
+//\r
+#define ISP_5_CLK 0\r
+#define ISP_4_CLK 1\r
+#define ISP_3_CLK 2\r
+#define ISP_2_CLK 3\r
+\r
+//\r
+// Recovery Time field value\r
+//\r
+#define RECVY_4_CLK 0\r
+#define RECVY_3_CLK 1\r
+#define RECVY_2_CLK 2\r
+#define RECVY_1_CLK 3\r
+\r
+//\r
+// Slave IDE Timing Register Enable\r
+//\r
+#define SITRE BIT14\r
+\r
+//\r
+// DMA Timing Enable Only Select 1\r
+//\r
+#define DTE1  BIT7\r
+\r
+//\r
+// Pre-fetch and Posting Enable Select 1\r
+//\r
+#define PPE1  BIT6\r
+\r
+//\r
+// IORDY Sample Point Enable Select 1\r
+//\r
+#define IE1 BIT5\r
+\r
+//\r
+// Fast Timing Bank Drive Select 1\r
+//\r
+#define TIME1 BIT4\r
+\r
+//\r
+// DMA Timing Enable Only Select 0\r
+//\r
+#define DTE0  BIT3\r
+\r
+//\r
+// Pre-fetch and Posting Enable Select 0\r
+//\r
+#define PPE0  BIT2\r
+\r
+//\r
+// IOREY Sample Point Enable Select 0\r
+//\r
+#define IE0 BIT1\r
+\r
+//\r
+// Fast Timing Bank Drive Select 0\r
+//\r
+#define TIME0 BIT0\r
+\r
+#endif\r