Sync with trunk r58740.
[reactos.git] / drivers / bus / pcix / pdo.c
index 8ed578c..9d06b6f 100644 (file)
@@ -79,8 +79,7 @@ PciPdoWaitWake(IN PIRP Irp,
                IN PIO_STACK_LOCATION IoStackLocation,
                IN PPCI_PDO_EXTENSION DeviceExtension)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
+    UNIMPLEMENTED_DBGBREAK();
     return STATUS_NOT_SUPPORTED;
 }
 
@@ -91,7 +90,6 @@ PciPdoSetPowerState(IN PIRP Irp,
                     IN PPCI_PDO_EXTENSION DeviceExtension)
 {
     UNIMPLEMENTED;
-    while (TRUE);
     return STATUS_NOT_SUPPORTED;
 }
 
@@ -101,8 +99,7 @@ PciPdoIrpQueryPower(IN PIRP Irp,
                     IN PIO_STACK_LOCATION IoStackLocation,
                     IN PPCI_PDO_EXTENSION DeviceExtension)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
+    UNIMPLEMENTED_DBGBREAK();
     return STATUS_NOT_SUPPORTED;
 }
 
@@ -112,9 +109,95 @@ PciPdoIrpStartDevice(IN PIRP Irp,
                      IN PIO_STACK_LOCATION IoStackLocation,
                      IN PPCI_PDO_EXTENSION DeviceExtension)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
-    return STATUS_NOT_SUPPORTED;
+    NTSTATUS Status;
+    BOOLEAN Changed, DoReset;
+    POWER_STATE PowerState;
+    PAGED_CODE();
+
+    DoReset = FALSE;
+
+    /* Begin entering the start phase */
+    Status = PciBeginStateTransition((PVOID)DeviceExtension, PciStarted);
+    if (!NT_SUCCESS(Status)) return Status;
+
+    /* Check if this is a VGA device */
+    if (((DeviceExtension->BaseClass == PCI_CLASS_PRE_20) &&
+         (DeviceExtension->SubClass == PCI_SUBCLASS_PRE_20_VGA)) ||
+        ((DeviceExtension->BaseClass == PCI_CLASS_DISPLAY_CTLR) &&
+         (DeviceExtension->SubClass == PCI_SUBCLASS_VID_VGA_CTLR)))
+    {
+        /* Always force it on */
+        DeviceExtension->CommandEnables |= (PCI_ENABLE_IO_SPACE |
+                                            PCI_ENABLE_MEMORY_SPACE);
+    }
+
+    /* Check if native IDE is enabled and it owns the I/O ports */
+    if (DeviceExtension->IoSpaceUnderNativeIdeControl)
+    {
+        /* Then don't allow I/O access */
+        DeviceExtension->CommandEnables &= ~PCI_ENABLE_IO_SPACE;
+    }
+
+    /* Always enable bus mastering */
+    DeviceExtension->CommandEnables |= PCI_ENABLE_BUS_MASTER;
+
+    /* Check if the OS assigned resources differ from the PCI configuration */
+    Changed = PciComputeNewCurrentSettings(DeviceExtension,
+                                           IoStackLocation->Parameters.
+                                           StartDevice.AllocatedResources);
+    if (Changed)
+    {
+        /* Remember this for later */
+        DeviceExtension->MovedDevice = TRUE;
+    }
+    else
+    {
+        /* All good */
+        DPRINT1("PCI - START not changing resource settings.\n");
+    }
+
+    /* Check if the device was sleeping */
+    if (DeviceExtension->PowerState.CurrentDeviceState != PowerDeviceD0)
+    {
+        /* Power it up */
+        Status = PciSetPowerManagedDevicePowerState(DeviceExtension,
+                                                    PowerDeviceD0,
+                                                    FALSE);
+        if (!NT_SUCCESS(Status))
+        {
+            /* Powerup fail, fail the request */
+            PciCancelStateTransition((PVOID)DeviceExtension, PciStarted);
+            return STATUS_DEVICE_POWER_FAILURE;
+        }
+
+        /* Tell the power manager that the device is powered up */
+        PowerState.DeviceState = PowerDeviceD0;
+        PoSetPowerState(DeviceExtension->PhysicalDeviceObject,
+                        DevicePowerState,
+                        PowerState);
+
+        /* Update internal state */
+        DeviceExtension->PowerState.CurrentDeviceState = PowerDeviceD0;
+
+        /* This device's resources and decodes will need to be reset */
+        DoReset = TRUE;
+    }
+
+    /* Update resource information now that the device is powered up and active */
+    Status = PciSetResources(DeviceExtension, DoReset, TRUE);
+    if (!NT_SUCCESS(Status))
+    {
+        /* That failed, so cancel the transition */
+        PciCancelStateTransition((PVOID)DeviceExtension, PciStarted);
+    }
+    else
+    {
+        /* Fully commit, as the device is now started up and ready to go */
+        PciCommitStateTransition((PVOID)DeviceExtension, PciStarted);
+    }
+
+    /* Return the result of the start request */
+    return Status;
 }
 
 NTSTATUS
@@ -124,7 +207,6 @@ PciPdoIrpQueryRemoveDevice(IN PIRP Irp,
                            IN PPCI_PDO_EXTENSION DeviceExtension)
 {
     UNIMPLEMENTED;
-    while (TRUE);
     return STATUS_NOT_SUPPORTED;
 }
 
@@ -134,8 +216,7 @@ PciPdoIrpRemoveDevice(IN PIRP Irp,
                       IN PIO_STACK_LOCATION IoStackLocation,
                       IN PPCI_PDO_EXTENSION DeviceExtension)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
+    UNIMPLEMENTED_DBGBREAK();
     return STATUS_NOT_SUPPORTED;
 }
 
@@ -145,8 +226,7 @@ PciPdoIrpCancelRemoveDevice(IN PIRP Irp,
                             IN PIO_STACK_LOCATION IoStackLocation,
                             IN PPCI_PDO_EXTENSION DeviceExtension)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
+    UNIMPLEMENTED_DBGBREAK();
     return STATUS_NOT_SUPPORTED;
 }
 
@@ -156,8 +236,7 @@ PciPdoIrpStopDevice(IN PIRP Irp,
                     IN PIO_STACK_LOCATION IoStackLocation,
                     IN PPCI_PDO_EXTENSION DeviceExtension)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
+    UNIMPLEMENTED_DBGBREAK();
     return STATUS_NOT_SUPPORTED;
 }
 
@@ -167,8 +246,7 @@ PciPdoIrpQueryStopDevice(IN PIRP Irp,
                          IN PIO_STACK_LOCATION IoStackLocation,
                          IN PPCI_PDO_EXTENSION DeviceExtension)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
+    UNIMPLEMENTED_DBGBREAK();
     return STATUS_NOT_SUPPORTED;
 }
 
@@ -178,8 +256,7 @@ PciPdoIrpCancelStopDevice(IN PIRP Irp,
                           IN PIO_STACK_LOCATION IoStackLocation,
                           IN PPCI_PDO_EXTENSION DeviceExtension)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
+    UNIMPLEMENTED_DBGBREAK();
     return STATUS_NOT_SUPPORTED;
 }
 
@@ -189,8 +266,7 @@ PciPdoIrpQueryInterface(IN PIRP Irp,
                         IN PIO_STACK_LOCATION IoStackLocation,
                         IN PPCI_PDO_EXTENSION DeviceExtension)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
+    UNIMPLEMENTED_DBGBREAK();
     return STATUS_NOT_SUPPORTED;
 }
 
@@ -320,8 +396,7 @@ PciPdoIrpReadConfig(IN PIRP Irp,
                     IN PIO_STACK_LOCATION IoStackLocation,
                     IN PPCI_PDO_EXTENSION DeviceExtension)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
+    UNIMPLEMENTED_DBGBREAK();
     return STATUS_NOT_SUPPORTED;
 }
 
@@ -331,8 +406,7 @@ PciPdoIrpWriteConfig(IN PIRP Irp,
                      IN PIO_STACK_LOCATION IoStackLocation,
                      IN PPCI_PDO_EXTENSION DeviceExtension)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
+    UNIMPLEMENTED_DBGBREAK();
     return STATUS_NOT_SUPPORTED;
 }
 
@@ -343,7 +417,6 @@ PciPdoIrpQueryDeviceState(IN PIRP Irp,
                           IN PPCI_PDO_EXTENSION DeviceExtension)
 {
     UNIMPLEMENTED;
-    while (TRUE);
     return STATUS_NOT_SUPPORTED;
 }
 
@@ -353,8 +426,7 @@ PciPdoIrpDeviceUsageNotification(IN PIRP Irp,
                                  IN PIO_STACK_LOCATION IoStackLocation,
                                  IN PPCI_PDO_EXTENSION DeviceExtension)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
+    UNIMPLEMENTED_DBGBREAK();
     return STATUS_NOT_SUPPORTED;
 }
 
@@ -364,8 +436,7 @@ PciPdoIrpSurpriseRemoval(IN PIRP Irp,
                          IN PIO_STACK_LOCATION IoStackLocation,
                          IN PPCI_PDO_EXTENSION DeviceExtension)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
+    UNIMPLEMENTED_DBGBREAK();
     return STATUS_NOT_SUPPORTED;
 }
 
@@ -375,8 +446,7 @@ PciPdoIrpQueryLegacyBusInformation(IN PIRP Irp,
                                    IN PIO_STACK_LOCATION IoStackLocation,
                                    IN PPCI_PDO_EXTENSION DeviceExtension)
 {
-    UNIMPLEMENTED;
-    while (TRUE);
+    UNIMPLEMENTED_DBGBREAK();
     return STATUS_NOT_SUPPORTED;
 }