Fix incorrect logic in IntVideoPortSetupInterrupt and add comment.
[reactos.git] / reactos / drivers / video / videoprt / interrupt.c
1 /*
2 * VideoPort driver
3 *
4 * Copyright (C) 2002, 2003, 2004 ReactOS Team
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; see the file COPYING.LIB.
18 * If not, write to the Free Software Foundation,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 *
21 */
22
23 #include "videoprt.h"
24
25 /* PRIVATE FUNCTIONS **********************************************************/
26
27 BOOLEAN NTAPI
28 IntVideoPortInterruptRoutine(
29 IN struct _KINTERRUPT *Interrupt,
30 IN PVOID ServiceContext)
31 {
32 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = ServiceContext;
33
34 ASSERT(DeviceExtension->DriverExtension->InitializationData.HwInterrupt != NULL);
35
36 return DeviceExtension->DriverExtension->InitializationData.HwInterrupt(
37 &DeviceExtension->MiniPortDeviceExtension);
38 }
39
40 BOOLEAN NTAPI
41 IntVideoPortSetupInterrupt(
42 IN PDEVICE_OBJECT DeviceObject,
43 IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension,
44 IN PVIDEO_PORT_CONFIG_INFO ConfigInfo)
45 {
46 NTSTATUS Status;
47 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
48
49 DeviceExtension = (PVIDEO_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
50
51 /*
52 * MSDN documentation for VIDEO_PORT_CONFIG_INFO states: "If a miniport driver's
53 * HwVidFindAdapter function finds that the video adapter does not generate
54 * interrupts or that it cannot determine a valid interrupt vector/level for
55 * the adapter, HwVidFindAdapter should set both BusInterruptVector and
56 * BusInterruptLevel to zero.
57 */
58
59 if (DriverExtension->InitializationData.HwInterrupt != NULL &&
60 ConfigInfo->BusInterruptLevel != 0 &&
61 ConfigInfo->BusInterruptVector != 0)
62 {
63 ULONG InterruptVector;
64 KIRQL Irql;
65 KAFFINITY Affinity;
66
67 InterruptVector = HalGetInterruptVector(
68 ConfigInfo->AdapterInterfaceType,
69 ConfigInfo->SystemIoBusNumber,
70 ConfigInfo->BusInterruptLevel,
71 ConfigInfo->BusInterruptVector,
72 &Irql,
73 &Affinity);
74
75 if (InterruptVector == 0)
76 {
77 WARN_(VIDEOPRT, "HalGetInterruptVector failed\n");
78 return FALSE;
79 }
80
81 KeInitializeSpinLock(&DeviceExtension->InterruptSpinLock);
82 Status = IoConnectInterrupt(
83 &DeviceExtension->InterruptObject,
84 IntVideoPortInterruptRoutine,
85 DeviceExtension,
86 &DeviceExtension->InterruptSpinLock,
87 InterruptVector,
88 Irql,
89 Irql,
90 ConfigInfo->InterruptMode,
91 DeviceExtension->InterruptShared,
92 Affinity,
93 FALSE);
94
95 if (!NT_SUCCESS(Status))
96 {
97 WARN_(VIDEOPRT, "IoConnectInterrupt failed with status 0x%08x\n", Status);
98 return FALSE;
99 }
100 }
101
102 return TRUE;
103 }
104
105 /* PUBLIC FUNCTIONS ***********************************************************/
106
107 /*
108 * @implemented
109 */
110
111 VP_STATUS NTAPI
112 VideoPortEnableInterrupt(IN PVOID HwDeviceExtension)
113 {
114 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
115 BOOLEAN Status;
116
117 TRACE_(VIDEOPRT, "VideoPortEnableInterrupt\n");
118
119 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
120
121 Status = HalEnableSystemInterrupt(
122 DeviceExtension->InterruptVector,
123 0,
124 DeviceExtension->InterruptLevel);
125
126 return Status ? NO_ERROR : ERROR_INVALID_ACCESS;
127 }
128
129 /*
130 * @implemented
131 */
132
133 VP_STATUS NTAPI
134 VideoPortDisableInterrupt(IN PVOID HwDeviceExtension)
135 {
136 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
137 BOOLEAN Status;
138
139 TRACE_(VIDEOPRT, "VideoPortDisableInterrupt\n");
140
141 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
142
143 Status = HalDisableSystemInterrupt(
144 DeviceExtension->InterruptVector,
145 0);
146
147 return Status ? NO_ERROR : ERROR_INVALID_ACCESS;
148 }