X-Git-Url: https://git.reactos.org/?p=reactos.git;a=blobdiff_plain;f=reactos%2Fdrivers%2Fvideo%2Fvideoprt%2Finterrupt.c;h=254eedc035840e251073b15ca80474d9e3e2eea8;hp=248ae5e7fbfbb91dc19cf08e962a4d6734c63030;hb=07bd1f96bd7fcaa812701b8bd481a01b8d06b893;hpb=499908b04f0a4e3ec5ddcf041b35f57feacfeb26 diff --git a/reactos/drivers/video/videoprt/interrupt.c b/reactos/drivers/video/videoprt/interrupt.c index 248ae5e7fbf..254eedc0358 100644 --- a/reactos/drivers/video/videoprt/interrupt.c +++ b/reactos/drivers/video/videoprt/interrupt.c @@ -4,70 +4,170 @@ * 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: interrupt.c,v 1.1 2004/03/04 18:51:58 navaraf Exp $ */ #include "videoprt.h" +/* PRIVATE FUNCTIONS **********************************************************/ + +BOOLEAN NTAPI +IntVideoPortInterruptRoutine( + IN struct _KINTERRUPT *Interrupt, + IN PVOID ServiceContext) +{ + PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension = ServiceContext; + + ASSERT(DeviceExtension->DriverExtension->InitializationData.HwInterrupt != NULL); + + return DeviceExtension->DriverExtension->InitializationData.HwInterrupt( + &DeviceExtension->MiniPortDeviceExtension); +} + +BOOLEAN NTAPI +IntVideoPortSetupInterrupt( + IN PDEVICE_OBJECT DeviceObject, + IN PVIDEO_PORT_DRIVER_EXTENSION DriverExtension, + IN PVIDEO_PORT_CONFIG_INFO ConfigInfo) +{ + NTSTATUS Status; + PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension; + + DeviceExtension = (PVIDEO_PORT_DEVICE_EXTENSION)DeviceObject->DeviceExtension; + + /* + * 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; + KAFFINITY Affinity; + + InterruptVector = HalGetInterruptVector( + ConfigInfo->AdapterInterfaceType, + ConfigInfo->SystemIoBusNumber, + ConfigInfo->BusInterruptLevel, + ConfigInfo->BusInterruptVector, + &Irql, + &Affinity); + + if (InterruptVector == 0) + { + WARN_(VIDEOPRT, "HalGetInterruptVector failed\n"); + return FALSE; + } + + KeInitializeSpinLock(&DeviceExtension->InterruptSpinLock); + Status = IoConnectInterrupt( + &DeviceExtension->InterruptObject, + IntVideoPortInterruptRoutine, + DeviceExtension, + &DeviceExtension->InterruptSpinLock, + InterruptVector, + Irql, + Irql, + ConfigInfo->InterruptMode, + DeviceExtension->InterruptShared, + Affinity, + FALSE); + + if (!NT_SUCCESS(Status)) + { + WARN_(VIDEOPRT, "IoConnectInterrupt failed with status 0x%08x\n", Status); + return FALSE; + } + } + + return TRUE; +} + +/* PUBLIC FUNCTIONS ***********************************************************/ + /* * @implemented */ - -VP_STATUS STDCALL +VP_STATUS +NTAPI VideoPortEnableInterrupt(IN PVOID HwDeviceExtension) { +#ifndef _M_AMD64 PVIDEO_PORT_DEVICE_EXTENSION DeviceExtension; - BOOLEAN Status; + BOOLEAN InterruptValid; - DPRINT("VideoPortEnableInterrupt\n"); + /* Get the device extension */ + DeviceExtension = VIDEO_PORT_GET_DEVICE_EXTENSION(HwDeviceExtension); - DeviceExtension = CONTAINING_RECORD( - HwDeviceExtension, - VIDEO_PORT_DEVICE_EXTENSION, - MiniPortDeviceExtension); + /* Fail if the driver didn't register an ISR */ + if (!DeviceExtension->DriverExtension->InitializationData.HwInterrupt) + { + /* No ISR, no interrupts */ + return ERROR_INVALID_FUNCTION; + } - Status = HalEnableSystemInterrupt( - DeviceExtension->InterruptVector, + /* Re-enable the interrupt and return */ + InterruptValid = HalEnableSystemInterrupt(DeviceExtension->InterruptVector, 0, DeviceExtension->InterruptLevel); - return Status ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL; + /* 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 STDCALL +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); - DeviceExtension = CONTAINING_RECORD( - HwDeviceExtension, - VIDEO_PORT_DEVICE_EXTENSION, - MiniPortDeviceExtension); + /* Fail if the driver didn't register an ISR */ + if (!DeviceExtension->DriverExtension->InitializationData.HwInterrupt) + { + /* No ISR, no interrupts */ + return ERROR_INVALID_FUNCTION; + } - Status = HalDisableSystemInterrupt( - DeviceExtension->InterruptVector, + /* Disable the interrupt and return */ + HalDisableSystemInterrupt(DeviceExtension->InterruptVector, 0); - - return Status ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL; + return NO_ERROR; +#else + /* FIXME: Function still present? If so what to use instead of HalDisableSystemInterrupt? */ + UNIMPLEMENTED; + return ERROR_INVALID_FUNCTION; +#endif }