c5da1a50f0ed683d6073e6def3dedea667ec8c8d
[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 Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 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 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22 #include "videoprt.h"
23
24 /* PRIVATE FUNCTIONS **********************************************************/
25
26 BOOLEAN NTAPI
27 IntVideoPortInterruptRoutine(
28 IN struct _KINTERRUPT *Interrupt,
29 IN PVOID ServiceContext)
30 {
31 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = ServiceContext;
32
33 ASSERT(DeviceExtension->DriverExtension->InitializationData.HwInterrupt != NULL);
34
35 return DeviceExtension->DriverExtension->InitializationData.HwInterrupt(
36 &DeviceExtension->MiniPortDeviceExtension);
37 }
38
39 BOOLEAN NTAPI
40 IntVideoPortSetupInterrupt(
41 IN PDEVICE_OBJECT DeviceObject,
42 IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension,
43 IN PVIDEO_PORT_CONFIG_INFO ConfigInfo)
44 {
45 NTSTATUS Status;
46 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
47
48 DeviceExtension = (PVIDEO_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
49
50 /*
51 * MSDN documentation for VIDEO_PORT_CONFIG_INFO states: "If a miniport driver's
52 * HwVidFindAdapter function finds that the video adapter does not generate
53 * interrupts or that it cannot determine a valid interrupt vector/level for
54 * the adapter, HwVidFindAdapter should set both BusInterruptVector and
55 * BusInterruptLevel to zero.
56 */
57
58 if (DriverExtension->InitializationData.HwInterrupt != NULL &&
59 (ConfigInfo->BusInterruptLevel != 0 ||
60 ConfigInfo->BusInterruptVector != 0))
61 {
62 ULONG InterruptVector;
63 KIRQL Irql;
64 KAFFINITY Affinity;
65
66 InterruptVector = HalGetInterruptVector(
67 ConfigInfo->AdapterInterfaceType,
68 ConfigInfo->SystemIoBusNumber,
69 ConfigInfo->BusInterruptLevel,
70 ConfigInfo->BusInterruptVector,
71 &Irql,
72 &Affinity);
73
74 if (InterruptVector == 0)
75 {
76 WARN_(VIDEOPRT, "HalGetInterruptVector failed\n");
77 return FALSE;
78 }
79
80 KeInitializeSpinLock(&DeviceExtension->InterruptSpinLock);
81 Status = IoConnectInterrupt(
82 &DeviceExtension->InterruptObject,
83 IntVideoPortInterruptRoutine,
84 DeviceExtension,
85 &DeviceExtension->InterruptSpinLock,
86 InterruptVector,
87 Irql,
88 Irql,
89 ConfigInfo->InterruptMode,
90 DeviceExtension->InterruptShared,
91 Affinity,
92 FALSE);
93
94 if (!NT_SUCCESS(Status))
95 {
96 WARN_(VIDEOPRT, "IoConnectInterrupt failed with status 0x%08x\n", Status);
97 return FALSE;
98 }
99 }
100
101 return TRUE;
102 }
103
104 /* PUBLIC FUNCTIONS ***********************************************************/
105
106 /*
107 * @implemented
108 */
109
110 VP_STATUS NTAPI
111 VideoPortEnableInterrupt(IN PVOID HwDeviceExtension)
112 {
113 #ifndef _M_AMD64
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_PARAMETER;
127 #else
128 /* FIXME: Function still present? If so what to use instead of HalEnableSystemInterrupt? */
129 UNIMPLEMENTED;
130 return ERROR_INVALID_FUNCTION;
131 #endif
132 }
133
134 /*
135 * @implemented
136 */
137
138 VP_STATUS NTAPI
139 VideoPortDisableInterrupt(IN PVOID HwDeviceExtension)
140 {
141 #ifndef _M_AMD64
142 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
143 BOOLEAN Status;
144
145 TRACE_(VIDEOPRT, "VideoPortDisableInterrupt\n");
146
147 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
148
149 Status = HalDisableSystemInterrupt(
150 DeviceExtension->InterruptVector,
151 0);
152
153 return Status ? NO_ERROR : ERROR_INVALID_PARAMETER;
154 #else
155 /* FIXME: Function still present? If so what to use instead of HalDisableSystemInterrupt? */
156 UNIMPLEMENTED;
157 return ERROR_INVALID_FUNCTION;
158 #endif
159 }