migrate substitution keywords to SVN
[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 * $Id$
22 */
23
24 #include "videoprt.h"
25
26 /* PRIVATE FUNCTIONS **********************************************************/
27
28 BOOLEAN STDCALL
29 IntVideoPortInterruptRoutine(
30 IN struct _KINTERRUPT *Interrupt,
31 IN PVOID ServiceContext)
32 {
33 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = ServiceContext;
34
35 ASSERT(DeviceExtension->DriverExtension->InitializationData.HwInterrupt != NULL);
36
37 return DeviceExtension->DriverExtension->InitializationData.HwInterrupt(
38 &DeviceExtension->MiniPortDeviceExtension);
39 }
40
41 BOOLEAN STDCALL
42 IntVideoPortSetupInterrupt(
43 IN PDEVICE_OBJECT DeviceObject,
44 IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension,
45 IN PVIDEO_PORT_CONFIG_INFO ConfigInfo)
46 {
47 NTSTATUS Status;
48 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
49
50 DeviceExtension = (PVIDEO_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
51
52 if (ConfigInfo->BusInterruptVector == 0)
53 ConfigInfo->BusInterruptVector = DeviceExtension->InterruptVector;
54
55 if (ConfigInfo->BusInterruptLevel == 0)
56 ConfigInfo->BusInterruptLevel = DeviceExtension->InterruptLevel;
57
58 if (DriverExtension->InitializationData.HwInterrupt != NULL)
59 {
60 ULONG InterruptVector;
61 KIRQL Irql;
62 KAFFINITY Affinity;
63
64 InterruptVector = HalGetInterruptVector(
65 ConfigInfo->AdapterInterfaceType,
66 ConfigInfo->SystemIoBusNumber,
67 ConfigInfo->BusInterruptLevel,
68 ConfigInfo->BusInterruptVector,
69 &Irql,
70 &Affinity);
71
72 if (InterruptVector == 0)
73 {
74 DPRINT("HalGetInterruptVector failed\n");
75 return FALSE;
76 }
77
78 KeInitializeSpinLock(&DeviceExtension->InterruptSpinLock);
79 Status = IoConnectInterrupt(
80 &DeviceExtension->InterruptObject,
81 IntVideoPortInterruptRoutine,
82 DeviceExtension,
83 &DeviceExtension->InterruptSpinLock,
84 InterruptVector,
85 Irql,
86 Irql,
87 ConfigInfo->InterruptMode,
88 FALSE,
89 Affinity,
90 FALSE);
91
92 if (!NT_SUCCESS(Status))
93 {
94 DPRINT("IoConnectInterrupt failed with status 0x%08x\n", Status);
95 return FALSE;
96 }
97 }
98
99 return TRUE;
100 }
101
102 /* PUBLIC FUNCTIONS ***********************************************************/
103
104 /*
105 * @implemented
106 */
107
108 VP_STATUS STDCALL
109 VideoPortEnableInterrupt(IN PVOID HwDeviceExtension)
110 {
111 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
112 BOOLEAN Status;
113
114 DPRINT("VideoPortEnableInterrupt\n");
115
116 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
117
118 Status = HalEnableSystemInterrupt(
119 DeviceExtension->InterruptVector,
120 0,
121 DeviceExtension->InterruptLevel);
122
123 return Status ? NO_ERROR : ERROR_INVALID_ACCESS;
124 }
125
126 /*
127 * @implemented
128 */
129
130 VP_STATUS STDCALL
131 VideoPortDisableInterrupt(IN PVOID HwDeviceExtension)
132 {
133 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
134 BOOLEAN Status;
135
136 DPRINT("VideoPortDisableInterrupt\n");
137
138 DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
139
140 Status = HalDisableSystemInterrupt(
141 DeviceExtension->InterruptVector,
142 0);
143
144 return Status ? NO_ERROR : ERROR_INVALID_ACCESS;
145 }