[PCI]
authorCameron Gutman <aicommander@gmail.com>
Sat, 11 Feb 2012 05:47:56 +0000 (05:47 +0000)
committerCameron Gutman <aicommander@gmail.com>
Sat, 11 Feb 2012 05:47:56 +0000 (05:47 +0000)
- Set device command flags when starting the PCI device PDO

svn path=/branches/usb-bringup-trunk/; revision=55540

drivers/bus/pci/fdo.c
drivers/bus/pci/pci.h
drivers/bus/pci/pdo.c

index 4b12ded..28153ec 100644 (file)
@@ -341,15 +341,13 @@ FdoQueryBusRelations(
       }
     }
 
       }
     }
 
-    if (!Device->RemovePending) {
-      /* Reference the physical device object. The PnP manager
-         will dereference it again when it is no longer needed */
-      ObReferenceObject(Device->Pdo);
+    /* Reference the physical device object. The PnP manager
+       will dereference it again when it is no longer needed */
+    ObReferenceObject(Device->Pdo);
 
 
-      Relations->Objects[i] = Device->Pdo;
+    Relations->Objects[i] = Device->Pdo;
 
 
-      i++;
-    }
+    i++;
 
     CurrentEntry = CurrentEntry->Flink;
   }
 
     CurrentEntry = CurrentEntry->Flink;
   }
index f400151..605be08 100644 (file)
@@ -17,8 +17,12 @@ typedef struct _PCI_DEVICE
   PCI_SLOT_NUMBER SlotNumber;
   // PCI configuration data
   PCI_COMMON_CONFIG PciConfig;
   PCI_SLOT_NUMBER SlotNumber;
   // PCI configuration data
   PCI_COMMON_CONFIG PciConfig;
-  // Flag used during enumeration to locate removed devices
-  BOOLEAN RemovePending;
+  // Enable memory space
+  BOOLEAN EnableMemorySpace;
+  // Enable I/O space
+  BOOLEAN EnableIoSpace;
+  // Enable bus master
+  BOOLEAN EnableBusMaster;
 } PCI_DEVICE, *PPCI_DEVICE;
 
 
 } PCI_DEVICE, *PPCI_DEVICE;
 
 
index 26569a4..d5fe392 100644 (file)
@@ -766,6 +766,9 @@ PdoQueryResources(
         Descriptor->u.Port.Start.QuadPart =
           (ULONGLONG)Base;
         Descriptor->u.Port.Length = Length;
         Descriptor->u.Port.Start.QuadPart =
           (ULONGLONG)Base;
         Descriptor->u.Port.Length = Length;
+
+        /* Enable IO space access */
+        DeviceExtension->PciDevice->EnableIoSpace = TRUE;
       }
       else
       {
       }
       else
       {
@@ -775,6 +778,9 @@ PdoQueryResources(
         Descriptor->u.Memory.Start.QuadPart =
           (ULONGLONG)Base;
         Descriptor->u.Memory.Length = Length;
         Descriptor->u.Memory.Start.QuadPart =
           (ULONGLONG)Base;
         Descriptor->u.Memory.Length = Length;
+
+        /* Enable memory space access */
+        DeviceExtension->PciDevice->EnableMemorySpace = TRUE;
       }
 
       Descriptor++;
       }
 
       Descriptor++;
@@ -792,6 +798,9 @@ PdoQueryResources(
       Descriptor->u.Interrupt.Vector = PciConfig.u.type0.InterruptLine;
       Descriptor->u.Interrupt.Affinity = 0xFFFFFFFF;
     }
       Descriptor->u.Interrupt.Vector = PciConfig.u.type0.InterruptLine;
       Descriptor->u.Interrupt.Affinity = 0xFFFFFFFF;
     }
+
+    /* Allow bus master mode */
+    DeviceExtension->PciDevice->EnableBusMaster = TRUE;
   }
   else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_BRIDGE_TYPE)
   {
   }
   else if (PCI_CONFIGURATION_TYPE(&PciConfig) == PCI_BRIDGE_TYPE)
   {
@@ -821,6 +830,9 @@ PdoQueryResources(
         Descriptor->u.Port.Start.QuadPart =
           (ULONGLONG)Base;
         Descriptor->u.Port.Length = Length;
         Descriptor->u.Port.Start.QuadPart =
           (ULONGLONG)Base;
         Descriptor->u.Port.Length = Length;
+
+        /* Enable IO space access */
+        DeviceExtension->PciDevice->EnableIoSpace = TRUE;
       }
       else
       {
       }
       else
       {
@@ -830,6 +842,9 @@ PdoQueryResources(
         Descriptor->u.Memory.Start.QuadPart =
           (ULONGLONG)Base;
         Descriptor->u.Memory.Length = Length;
         Descriptor->u.Memory.Start.QuadPart =
           (ULONGLONG)Base;
         Descriptor->u.Memory.Length = Length;
+
+        /* Enable memory space access */
+        DeviceExtension->PciDevice->EnableMemorySpace = TRUE;
       }
 
       Descriptor++;
       }
 
       Descriptor++;
@@ -1206,45 +1221,86 @@ PdoStartDevice(
   IN PIRP Irp,
   PIO_STACK_LOCATION IrpSp)
 {
   IN PIRP Irp,
   PIO_STACK_LOCATION IrpSp)
 {
-  PCM_RESOURCE_LIST RawResList = IrpSp->Parameters.StartDevice.AllocatedResources;
-  PCM_FULL_RESOURCE_DESCRIPTOR RawFullDesc;
-  PCM_PARTIAL_RESOURCE_DESCRIPTOR RawPartialDesc;
-  ULONG i, ii;
-  PPDO_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
-  UCHAR Irq;
+    PCM_RESOURCE_LIST RawResList = IrpSp->Parameters.StartDevice.AllocatedResources;
+    PCM_FULL_RESOURCE_DESCRIPTOR RawFullDesc;
+    PCM_PARTIAL_RESOURCE_DESCRIPTOR RawPartialDesc;
+    ULONG i, ii;
+    PPDO_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
+    UCHAR Irq;
+    USHORT Command;
 
 
-  if (!RawResList)
-      return STATUS_SUCCESS;
+    if (!RawResList)
+        return STATUS_SUCCESS;
 
 
-  /* TODO: Assign the other resources we get to the card */
+    /* TODO: Assign the other resources we get to the card */
 
 
-  for (i = 0; i < RawResList->Count; i++)
-  {
-      RawFullDesc = &RawResList->List[i];
+    for (i = 0; i < RawResList->Count; i++)
+    {
+        RawFullDesc = &RawResList->List[i];
 
 
-      for (ii = 0; ii < RawFullDesc->PartialResourceList.Count; ii++)
-      {
-          RawPartialDesc = &RawFullDesc->PartialResourceList.PartialDescriptors[ii];
+        for (ii = 0; ii < RawFullDesc->PartialResourceList.Count; ii++)
+        {
+            RawPartialDesc = &RawFullDesc->PartialResourceList.PartialDescriptors[ii];
+
+            if (RawPartialDesc->Type == CmResourceTypeInterrupt)
+            {
+                DPRINT1("Assigning IRQ %d to PCI device 0x%x on bus 0x%x\n",
+                        RawPartialDesc->u.Interrupt.Vector,
+                        DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
+                        DeviceExtension->PciDevice->BusNumber);
+
+                Irq = (UCHAR)RawPartialDesc->u.Interrupt.Vector;
+                HalSetBusDataByOffset(PCIConfiguration,
+                                      DeviceExtension->PciDevice->BusNumber,
+                                      DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
+                                      &Irq,
+                                      0x3c /* PCI_INTERRUPT_LINE */,
+                                      sizeof(UCHAR));
+            }
+        }
+    }
 
 
-          if (RawPartialDesc->Type == CmResourceTypeInterrupt)
-          {
-              DPRINT1("Assigning IRQ %x to PCI device (%x, %x)\n",
-                      RawPartialDesc->u.Interrupt.Vector,
-                      DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
-                      DeviceExtension->PciDevice->BusNumber);
-
-              Irq = (UCHAR)RawPartialDesc->u.Interrupt.Vector;
-              HalSetBusDataByOffset(PCIConfiguration,
-                                    DeviceExtension->PciDevice->BusNumber,
-                                    DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
-                                    &Irq,
-                                    0x3c /* PCI_INTERRUPT_LINE */,
-                                    sizeof(UCHAR));
-          }
-      }
-   }
+    DPRINT1("Enabling command flags for PCI device 0x%x on bus 0x%x: ",
+            DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
+            DeviceExtension->PciDevice->BusNumber);
+    if (DeviceExtension->PciDevice->EnableBusMaster)
+    {
+        Command |= PCI_ENABLE_BUS_MASTER;
+        DbgPrint("[Bus master] ");
+    }
 
 
-   return STATUS_SUCCESS;
+    if (DeviceExtension->PciDevice->EnableMemorySpace)
+    {
+        Command |= PCI_ENABLE_MEMORY_SPACE;
+        DbgPrint("[Memory space enable] ");
+    }
+
+    if (DeviceExtension->PciDevice->EnableIoSpace)
+    {
+        Command |= PCI_ENABLE_IO_SPACE;
+        DbgPrint("[I/O space enable] ");
+    }
+
+    if (Command != 0)
+    {
+        DbgPrint("\n");
+
+        /* OR with the previous value */
+        Command |= DeviceExtension->PciDevice->PciConfig.Command;
+
+        HalSetBusDataByOffset(PCIConfiguration,
+                              DeviceExtension->PciDevice->BusNumber,
+                              DeviceExtension->PciDevice->SlotNumber.u.AsULONG,
+                              &Command,
+                              FIELD_OFFSET(PCI_COMMON_CONFIG, Command),
+                              sizeof(USHORT));
+    }
+    else
+    {
+        DbgPrint("None\n");
+    }
+
+    return STATUS_SUCCESS;
 }
 
 static NTSTATUS
 }
 
 static NTSTATUS