Sync to trunk (r44371)
[reactos.git] / reactos / drivers / video / videoprt / interrupt.c
index b53838d..254eedc 100644 (file)
@@ -4,21 +4,19 @@
  * Copyright (C) 2002, 2003, 2004 ReactOS Team
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; see the file COPYING.LIB.
- * If not, write to the Free Software Foundation,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * $Id$
  */
 
 #include "videoprt.h"
@@ -49,13 +47,17 @@ IntVideoPortSetupInterrupt(
 
    DeviceExtension = (PVIDEO_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
 
-   if (ConfigInfo->BusInterruptVector == 0)
-      ConfigInfo->BusInterruptVector = DeviceExtension->InterruptVector;
-
-   if (ConfigInfo->BusInterruptLevel == 0)
-      ConfigInfo->BusInterruptLevel = DeviceExtension->InterruptLevel;
-
-   if (DriverExtension->InitializationData.HwInterrupt != NULL)
+   /*
+    * MSDN documentation for VIDEO_PORT_CONFIG_INFO states: "If a miniport driver's
+    * HwVidFindAdapter function finds that the video adapter does not generate
+    * interrupts or that it cannot determine a valid interrupt vector/level for
+    * the adapter, HwVidFindAdapter should set both BusInterruptVector and
+    * BusInterruptLevel to zero.
+    */
+
+   if (DriverExtension->InitializationData.HwInterrupt != NULL &&
+       (ConfigInfo->BusInterruptLevel != 0 ||
+       ConfigInfo->BusInterruptVector != 0))
    {
       ULONG InterruptVector;
       KIRQL Irql;
@@ -71,7 +73,7 @@ IntVideoPortSetupInterrupt(
 
       if (InterruptVector == 0)
       {
-         DPRINT("HalGetInterruptVector failed\n");
+         WARN_(VIDEOPRT, "HalGetInterruptVector failed\n");
          return FALSE;
       }
 
@@ -91,7 +93,7 @@ IntVideoPortSetupInterrupt(
 
       if (!NT_SUCCESS(Status))
       {
-         DPRINT("IoConnectInterrupt failed with status 0x%08x\n", Status);
+         WARN_(VIDEOPRT, "IoConnectInterrupt failed with status 0x%08x\n", Status);
          return FALSE;
       }
    }
@@ -104,42 +106,68 @@ IntVideoPortSetupInterrupt(
 /*
  * @implemented
  */
-
-VP_STATUS NTAPI
+VP_STATUS
+NTAPI
 VideoPortEnableInterrupt(IN PVOID HwDeviceExtension)
 {
+#ifndef _M_AMD64
    PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
-   BOOLEAN Status;
-
-   DPRINT("VideoPortEnableInterrupt\n");
+    BOOLEAN InterruptValid;
 
+    /* Get the device extension */
    DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
 
-   Status = HalEnableSystemInterrupt(
-      DeviceExtension->InterruptVector,
+    /* Fail if the driver didn't register an ISR */
+    if (!DeviceExtension->DriverExtension->InitializationData.HwInterrupt)
+    {
+        /* No ISR, no interrupts */
+        return ERROR_INVALID_FUNCTION;
+    }
+
+    /* Re-enable the interrupt and return */
+    InterruptValid = HalEnableSystemInterrupt(DeviceExtension->InterruptVector,
       0,
       DeviceExtension->InterruptLevel);
 
-   return Status ? NO_ERROR : ERROR_INVALID_ACCESS;
+    /* Make sure the interrupt was valid */
+    ASSERT(InterruptValid == TRUE);
+
+    /* Return to caller */
+    return NO_ERROR;
+#else
+    /* FIXME: Function still present? If so what to use instead of HalEnableSystemInterrupt? */
+    UNIMPLEMENTED;
+    return ERROR_INVALID_FUNCTION;
+#endif
 }
 
 /*
  * @implemented
  */
-
-VP_STATUS NTAPI
+VP_STATUS
+NTAPI
 VideoPortDisableInterrupt(IN PVOID HwDeviceExtension)
 {
+#ifndef _M_AMD64
    PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
-   BOOLEAN Status;
-
-   DPRINT("VideoPortDisableInterrupt\n");
 
+    /* Get the device extension */
    DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
 
-   Status = HalDisableSystemInterrupt(
-      DeviceExtension->InterruptVector,
-      0);
+    /* Fail if the driver didn't register an ISR */
+    if (!DeviceExtension->DriverExtension->InitializationData.HwInterrupt)
+    {
+        /* No ISR, no interrupts */
+        return ERROR_INVALID_FUNCTION;
+    }
 
-   return Status ? NO_ERROR : ERROR_INVALID_ACCESS;
+    /* Disable the interrupt and return */
+    HalDisableSystemInterrupt(DeviceExtension->InterruptVector,
+      0);
+    return NO_ERROR;
+#else
+    /* FIXME: Function still present? If so what to use instead of HalDisableSystemInterrupt? */
+    UNIMPLEMENTED;
+    return ERROR_INVALID_FUNCTION;
+#endif
 }