ReactOS  0.4.14-dev-854-gb9426a3
interrupt.c
Go to the documentation of this file.
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 #include <ndk/halfuncs.h>
25 
26 #define NDEBUG
27 #include <debug.h>
28 
29 /* PRIVATE FUNCTIONS **********************************************************/
30 
33  IN struct _KINTERRUPT *Interrupt,
35 {
37 
39 
40  return DeviceExtension->DriverExtension->InitializationData.HwInterrupt(
41  &DeviceExtension->MiniPortDeviceExtension);
42 }
43 
48  IN PVIDEO_PORT_CONFIG_INFO ConfigInfo)
49 {
51  PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
52 
54 
55  /*
56  * MSDN documentation for VIDEO_PORT_CONFIG_INFO states: "If a miniport driver's
57  * HwVidFindAdapter function finds that the video adapter does not generate
58  * interrupts or that it cannot determine a valid interrupt vector/level for
59  * the adapter, HwVidFindAdapter should set both BusInterruptVector and
60  * BusInterruptLevel to zero.
61  */
62 
63  if (DriverExtension->InitializationData.HwInterrupt != NULL &&
64  (ConfigInfo->BusInterruptLevel != 0 ||
65  ConfigInfo->BusInterruptVector != 0))
66  {
67  ULONG InterruptVector;
68  KIRQL Irql;
70 
71  InterruptVector = HalGetInterruptVector(
72  ConfigInfo->AdapterInterfaceType,
73  ConfigInfo->SystemIoBusNumber,
74  ConfigInfo->BusInterruptLevel,
75  ConfigInfo->BusInterruptVector,
76  &Irql,
77  &Affinity);
78 
79  if (InterruptVector == 0)
80  {
81  WARN_(VIDEOPRT, "HalGetInterruptVector failed\n");
82  return FALSE;
83  }
84 
85  KeInitializeSpinLock(&DeviceExtension->InterruptSpinLock);
87  &DeviceExtension->InterruptObject,
89  DeviceExtension,
90  &DeviceExtension->InterruptSpinLock,
91  InterruptVector,
92  Irql,
93  Irql,
94  ConfigInfo->InterruptMode,
95  DeviceExtension->InterruptShared,
96  Affinity,
97  FALSE);
98 
99  if (!NT_SUCCESS(Status))
100  {
101  WARN_(VIDEOPRT, "IoConnectInterrupt failed with status 0x%08x\n", Status);
102  return FALSE;
103  }
104  }
105 
106  return TRUE;
107 }
108 
109 /* PUBLIC FUNCTIONS ***********************************************************/
110 
111 /*
112  * @implemented
113  */
114 VP_STATUS
115 NTAPI
117 {
118 #ifndef _M_AMD64
119  PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
120  BOOLEAN InterruptValid;
121 
122  /* Get the device extension */
123  DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
124 
125  /* Fail if the driver didn't register an ISR */
126  if (!DeviceExtension->DriverExtension->InitializationData.HwInterrupt)
127  {
128  /* No ISR, no interrupts */
129  return ERROR_INVALID_FUNCTION;
130  }
131 
132  /* Re-enable the interrupt and return */
133  InterruptValid = HalEnableSystemInterrupt(DeviceExtension->InterruptVector,
134  0,
135  DeviceExtension->InterruptLevel);
136 
137  /* Make sure the interrupt was valid */
138  ASSERT(InterruptValid == TRUE);
139 
140  /* Return to caller */
141  return NO_ERROR;
142 #else
143  /* FIXME: Function still present? If so what to use instead of HalEnableSystemInterrupt? */
145  return ERROR_INVALID_FUNCTION;
146 #endif
147 }
148 
149 /*
150  * @implemented
151  */
152 VP_STATUS
153 NTAPI
155 {
156 #ifndef _M_AMD64
157  PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension;
158 
159  /* Get the device extension */
160  DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension);
161 
162  /* Fail if the driver didn't register an ISR */
163  if (!DeviceExtension->DriverExtension->InitializationData.HwInterrupt)
164  {
165  /* No ISR, no interrupts */
166  return ERROR_INVALID_FUNCTION;
167  }
168 
169  /* Disable the interrupt and return */
170  HalDisableSystemInterrupt(DeviceExtension->InterruptVector, 0);
171  return NO_ERROR;
172 #else
173  /* FIXME: Function still present? If so what to use instead of HalDisableSystemInterrupt? */
175  return ERROR_INVALID_FUNCTION;
176 #endif
177 }
#define IN
Definition: typedefs.h:38
BOOLEAN NTAPI HalEnableSystemInterrupt(IN ULONG Vector, IN KIRQL Irql, IN KINTERRUPT_MODE InterruptMode)
Definition: pic.c:295
#define TRUE
Definition: types.h:120
VIDEO_PORT_DRIVER_EXTENSION * DriverExtension
Definition: videoprt.h:103
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
VIDEO_HW_INITIALIZATION_DATA InitializationData
Definition: videoprt.h:72
LONG NTSTATUS
Definition: precomp.h:26
struct _VIDEO_PORT_DEVICE_EXTENSTION * PVIDEO_PORT_DEVICE_EXTENSION
#define VIDEO_PORT_GET_DEVICE_EXTENSION(MiniportExtension)
Definition: videoprt.h:137
#define NO_ERROR
Definition: dderror.h:5
_Out_ PKIRQL Irql
Definition: csq.h:179
VOID NTAPI HalDisableSystemInterrupt(IN ULONG Vector, IN KIRQL Irql)
Definition: pic.c:309
UCHAR KIRQL
Definition: env_spec_w32.h:591
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
NTSTATUS NTAPI IoConnectInterrupt(OUT PKINTERRUPT *InterruptObject, IN PKSERVICE_ROUTINE ServiceRoutine, IN PVOID ServiceContext, IN PKSPIN_LOCK SpinLock, IN ULONG Vector, IN KIRQL Irql, IN KIRQL SynchronizeIrql, IN KINTERRUPT_MODE InterruptMode, IN BOOLEAN ShareVector, IN KAFFINITY ProcessorEnableMask, IN BOOLEAN FloatingSave)
Definition: irq.c:22
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
BOOLEAN NTAPI IntVideoPortInterruptRoutine(IN struct _KINTERRUPT *Interrupt, IN PVOID ServiceContext)
Definition: interrupt.c:32
NTHALAPI ULONG NTAPI HalGetInterruptVector(INTERFACE_TYPE, ULONG, ULONG, ULONG, PKIRQL, PKAFFINITY)
if(!(yy_init))
Definition: macro.lex.yy.c:714
VP_STATUS NTAPI VideoPortEnableInterrupt(IN PVOID HwDeviceExtension)
Definition: interrupt.c:116
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG _In_ ULONG _Out_ PKIRQL _Out_ PKAFFINITY Affinity
Definition: halfuncs.h:170
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID ServiceContext
Definition: iofuncs.h:798
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
PVIDEO_HW_INTERRUPT HwInterrupt
Definition: video.h:668
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:41
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
ULONG_PTR KAFFINITY
Definition: compat.h:75
BOOLEAN NTAPI IntVideoPortSetupInterrupt(IN PDEVICE_OBJECT DeviceObject, IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension, IN PVIDEO_PORT_CONFIG_INFO ConfigInfo)
Definition: interrupt.c:45
unsigned int ULONG
Definition: retypes.h:1
#define UNIMPLEMENTED
Definition: debug.h:114
LONG VP_STATUS
Definition: video.h:153
VP_STATUS NTAPI VideoPortDisableInterrupt(IN PVOID HwDeviceExtension)
Definition: interrupt.c:154
#define WARN_(ch,...)
Definition: debug.h:157