- Share the irq/irql/vector definitions between ntoskrnl and hal.

- Changed the handling of interrupts for uniprocessor machines from irqs to interrupt vectors.

svn path=/trunk/; revision=11520
This commit is contained in:
Hartmut Birr 2004-11-01 14:37:19 +00:00
parent c8583d9809
commit 3edce321a2
8 changed files with 106 additions and 196 deletions

View file

@ -0,0 +1,35 @@
/*
* $Id: halirq.h,v 1.1 2004/11/01 14:37:18 hbirr Exp $
*/
#ifndef __INCLUDE_HAL_HALIRQ
#define __INCLUDE_HAL_HALIRQ
#ifdef MP
#define FIRST_DEVICE_VECTOR (0x30)
#define FIRST_SYSTEM_VECTOR (0xef)
#define IRQ_BASE FIRST_DEVICE_VECTOR
#define NR_IRQS (FIRST_SYSTEM_VECTOR - FIRST_DEVICE_VECTOR)
/*
* FIXME:
* This does not work if we have more than 24 IRQs (ie. more than one I/O APIC)
*/
#define VECTOR2IRQ(vector) (23 - (vector - IRQ_BASE) / 8)
#define VECTOR2IRQL(vector) (PROFILE_LEVEL - VECTOR2IRQ(vector))
#define IRQ2VECTOR(irq) (((23 - (irq)) * 8) + FIRST_DEVICE_VECTOR)
#else
#define IRQ_BASE (0x40)
#define NR_IRQS (16)
#define VECTOR2IRQ(vector) ((vector) - IRQ_BASE)
#define VECTOR2IRQL(vector) (PROFILE_LEVEL - VECTOR2IRQ(vector))
#define IRQ2VECTOR(irq) ((irq) + IRQ_BASE)
#endif
#endif /* __INCLUDE_HAL_HALIRQ */

View file

@ -1,4 +1,4 @@
/* $Id: irql.c,v 1.18 2004/10/31 21:22:06 navaraf Exp $
/* $Id: irql.c,v 1.19 2004/11/01 14:37:19 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -9,19 +9,18 @@
/* INCLUDES *****************************************************************/
#include <roscfg.h>
#include <ddk/ntddk.h>
#include <internal/ps.h>
#include <ntos/minmax.h>
#include <hal.h>
#include <halirq.h>
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS ******************************************************************/
#define NR_IRQS (16)
#define IRQ_BASE (0x40)
/*
* PURPOSE: Current irq level
*/
@ -86,8 +85,8 @@ VOID HalpInitPICs(VOID)
WRITE_PORT_UCHAR((PUCHAR)0x20, 0x11);
WRITE_PORT_UCHAR((PUCHAR)0xa0, 0x11);
/* Start of hardware irqs (0x24) */
WRITE_PORT_UCHAR((PUCHAR)0x21, 0x40);
WRITE_PORT_UCHAR((PUCHAR)0xa1, 0x48);
WRITE_PORT_UCHAR((PUCHAR)0x21, IRQ_BASE);
WRITE_PORT_UCHAR((PUCHAR)0xa1, IRQ_BASE + 8);
/* 8259-1 is master */
WRITE_PORT_UCHAR((PUCHAR)0x21, 0x4);
/* 8259-2 is slave */
@ -152,7 +151,7 @@ HalpExecuteIrqs(KIRQL NewIrql)
* For each deferred interrupt execute all the handlers at DIRQL.
*/
HalpPendingInterruptCount[i]--;
KiInterruptDispatch2(i, NewIrql);
KiInterruptDispatch2(i + IRQ_BASE, NewIrql);
}
KeGetCurrentKPCR()->Irql--;
HalpEndSystemInterrupt(KeGetCurrentKPCR()->Irql);

View file

@ -1,4 +1,4 @@
/* $Id: isa.c,v 1.6 2003/12/28 22:38:09 fireball Exp $
/* $Id: isa.c,v 1.7 2004/11/01 14:37:19 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -14,10 +14,10 @@
#include <roscfg.h>
#include <ddk/ntddk.h>
#include <bus.h>
#ifdef MP
#include <mps.h>
#endif
#include <halirq.h>
#define NDEBUG
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
@ -71,14 +71,9 @@ HalpGetIsaInterruptVector(PVOID BusHandler,
PKIRQL Irql,
PKAFFINITY Affinity)
{
#ifdef MP
*Irql = (KIRQL)(PROFILE_LEVEL - BusInterruptVector);
ULONG Vector = IRQ2VECTOR(BusInterruptVector);
*Irql = VECTOR2IRQL(Vector);
*Affinity = 0xFFFFFFFF;
return IRQ2VECTOR(BusInterruptVector);
#else
*Irql = (KIRQL)(PROFILE_LEVEL - BusInterruptVector);
*Affinity = 0xFFFFFFFF;
return BusInterruptVector;
#endif
return Vector;
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: mps.S,v 1.1 2001/08/21 20:18:27 chorns Exp $
/* $Id: mps.S,v 1.2 2004/11/01 14:37:19 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -16,6 +16,7 @@
/* FUNCTIONS *****************************************************************/
#define BEFORE \
cld; \
pusha; \
pushl %ds; \
pushl %es; \

View file

@ -1,4 +1,4 @@
/* $Id: pci.c,v 1.12 2004/10/22 20:08:22 ekohl Exp $
/* $Id: pci.c,v 1.13 2004/11/01 14:37:19 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -21,10 +21,7 @@
#include <roscfg.h>
#include <ddk/ntddk.h>
#include <bus.h>
#ifdef MP
#include <mps.h>
#endif
#include <halirq.h>
#define NDEBUG
#include <internal/debug.h>
@ -551,15 +548,10 @@ HalpGetPciInterruptVector(PVOID BusHandler,
PKIRQL Irql,
PKAFFINITY Affinity)
{
#ifdef MP
*Irql = (KIRQL)(PROFILE_LEVEL - BusInterruptVector);
ULONG Vector = IRQ2VECTOR(BusInterruptVector);
*Irql = VECTOR2IRQL(Vector);
*Affinity = 0xFFFFFFFF;
return IRQ2VECTOR(BusInterruptVector);
#else
*Irql = (KIRQL)(PROFILE_LEVEL - BusInterruptVector);
*Affinity = 0xFFFFFFFF;
return BusInterruptVector;
#endif
return Vector;
}
static BOOLEAN STDCALL

View file

@ -1,4 +1,4 @@
/* $Id: sysbus.c,v 1.6 2003/12/28 22:38:09 fireball Exp $
/* $Id: sysbus.c,v 1.7 2004/11/01 14:37:19 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -14,9 +14,10 @@
#include <roscfg.h>
#include <ddk/ntddk.h>
#include <bus.h>
#ifdef MP
#include <mps.h>
#endif
#include <halirq.h>
#define NDEBUG
#include <internal/debug.h>
/* FUNCTIONS ****************************************************************/
@ -29,15 +30,10 @@ HalpGetSystemInterruptVector(PVOID BusHandler,
PKIRQL Irql,
PKAFFINITY Affinity)
{
#ifdef MP
*Irql = (KIRQL)(PROFILE_LEVEL - BusInterruptVector);
ULONG Vector = IRQ2VECTOR(BusInterruptVector);
*Irql = VECTOR2IRQL(Vector);
*Affinity = 0xFFFFFFFF;
return IRQ2VECTOR(BusInterruptVector);
#else
*Irql = (KIRQL)(PROFILE_LEVEL - BusInterruptVector);
*Affinity = 0xFFFFFFFF;
return BusInterruptVector;
#endif
return Vector;
}

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: irq.c,v 1.51 2004/10/31 23:57:15 navaraf Exp $
/* $Id: irq.c,v 1.52 2004/11/01 14:37:19 hbirr Exp $
*
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/i386/irq.c
@ -40,9 +40,7 @@
#include <../dbg/kdb.h>
#endif /* KDBG */
#ifdef MP
#include <internal/hal/mps.h>
#endif /* MP */
#include <../hal/halx86/include/halirq.h>
#define NDEBUG
#include <internal/debug.h>
@ -51,18 +49,6 @@
#ifdef MP
/*
* FIXME: This does not work if we have more than 24 IRQs (ie. more than one
* I/O APIC)
*/
#define VECTOR2IRQ(vector) (((vector) - FIRST_DEVICE_VECTOR) / 8)
#define IRQ2VECTOR(vector) ((vector * 8) + FIRST_DEVICE_VECTOR)
#define VECTOR2IRQL(vector) (DISPATCH_LEVEL /* 2 */ + 1 + VECTOR2IRQ(vector))
#define IRQ_BASE 0x30
#define NR_IRQS 0x100 - IRQ_BASE
#define __STR(x) #x
#define STR(x) __STR(x)
@ -152,9 +138,6 @@ static ULONG irq_handler[NR_IRQS] = {
#else /* MP */
#define NR_IRQS (16)
#define IRQ_BASE (0x40)
void irq_handler_0(void);
void irq_handler_1(void);
void irq_handler_2(void);
@ -217,8 +200,6 @@ KeInitInterrupts (VOID)
{
int i;
#ifdef MP
/*
* Setup the IDT entries to point to the interrupt handlers
*/
@ -229,27 +210,11 @@ KeInitInterrupts (VOID)
I486_INTERRUPT_GATE;
InitializeListHead(&isr_table[i]);
}
#else
/*
* Setup the IDT entries to point to the interrupt handlers
*/
for (i=0;i<NR_IRQS;i++)
{
KiIdt[IRQ_BASE+i].a=(irq_handler[i]&0xffff)+(KERNEL_CS<<16);
KiIdt[IRQ_BASE+i].b=(irq_handler[i]&0xffff0000)+PRESENT+
I486_INTERRUPT_GATE;
InitializeListHead(&isr_table[i]);
}
#endif
}
VOID
STATIC VOID
KeIRQTrapFrameToTrapFrame(PKIRQ_TRAPFRAME IrqTrapFrame,
PKTRAP_FRAME TrapFrame)
PKTRAP_FRAME TrapFrame)
{
TrapFrame->Gs = (USHORT)IrqTrapFrame->Gs;
TrapFrame->Fs = (USHORT)IrqTrapFrame->Fs;
@ -268,9 +233,9 @@ KeIRQTrapFrameToTrapFrame(PKIRQ_TRAPFRAME IrqTrapFrame,
TrapFrame->Eflags = IrqTrapFrame->Eflags;
}
VOID
STATIC VOID
KeTrapFrameToIRQTrapFrame(PKTRAP_FRAME TrapFrame,
PKIRQ_TRAPFRAME IrqTrapFrame)
PKIRQ_TRAPFRAME IrqTrapFrame)
{
IrqTrapFrame->Gs = TrapFrame->Gs;
IrqTrapFrame->Fs = TrapFrame->Fs;
@ -307,10 +272,10 @@ KiInterruptDispatch2 (ULONG vector, KIRQL old_level)
/*
* Iterate the list until one of the isr tells us its device interrupted
*/
current = isr_table[vector].Flink;
current = isr_table[vector - IRQ_BASE].Flink;
isr = CONTAINING_RECORD(current,KINTERRUPT,Entry);
while (current != &isr_table[vector] &&
while (current != &isr_table[vector - IRQ_BASE] &&
!isr->ServiceRoutine(isr, isr->ServiceContext))
{
current = current->Flink;
@ -318,79 +283,8 @@ KiInterruptDispatch2 (ULONG vector, KIRQL old_level)
}
}
#ifdef MP
VOID
KiInterruptDispatch (ULONG Vector, PKIRQ_TRAPFRAME Trapframe)
/*
* FUNCTION: Calls the irq specific handler for an irq
* ARGUMENTS:
* Vector = Interrupt vector
* Trapframe = CPU context
* NOTES: Interrupts are disabled at this point.
*/
{
KIRQL old_level;
KTRAP_FRAME KernelTrapFrame;
DbgPrint("V(0x%.02x)", Vector);
/*
* Notify the rest of the kernel of the raised irq level
*/
if (!HalBeginSystemInterrupt (Vector,
VECTOR2IRQL(Vector),
&old_level))
{
return;
}
/*
* Mask the related irq
*/
//HalDisableSystemInterrupt (Vector, 0);
/*
* Enable interrupts
* NOTE: Only higher priority interrupts will get through
*/
Ke386EnableInterrupts();
if (Vector == 0)
{
KeIRQTrapFrameToTrapFrame(Trapframe, &KernelTrapFrame);
KeUpdateSystemTime(&KernelTrapFrame, PROFILE_LEVEL);
}
else
{
/*
* Actually call the ISR.
*/
KiInterruptDispatch2(Vector, old_level);
}
/*
* Disable interrupts
*/
Ke386DisableInterrupts();
/*
* Unmask the related irq
*/
//HalEnableSystemInterrupt (Vector, 0, 0);
//DbgPrint("E(0x%.02x)\n", Vector);
/*
* End the system interrupt.
*/
HalEndSystemInterrupt (old_level, 0);
}
#else /* MP */
VOID
KiInterruptDispatch (ULONG irq, PKIRQ_TRAPFRAME Trapframe)
KiInterruptDispatch (ULONG vector, PKIRQ_TRAPFRAME Trapframe)
/*
* FUNCTION: Calls the irq specific handler for an irq
* ARGUMENTS:
@ -413,8 +307,8 @@ KiInterruptDispatch (ULONG irq, PKIRQ_TRAPFRAME Trapframe)
* Notify the rest of the kernel of the raised irq level. For the
* default HAL this will send an EOI to the PIC and alter the IRQL.
*/
if (!HalBeginSystemInterrupt (irq + IRQ_BASE,
(KIRQL)(PROFILE_LEVEL - irq),
if (!HalBeginSystemInterrupt (vector,
VECTOR2IRQL(vector),
&old_level))
{
return;
@ -427,21 +321,22 @@ KiInterruptDispatch (ULONG irq, PKIRQ_TRAPFRAME Trapframe)
*/
Ke386EnableInterrupts();
if (irq == 0)
#ifndef MP
if (VECTOR2IRQ(vector) == 0)
{
KeIRQTrapFrameToTrapFrame(Trapframe, &KernelTrapFrame);
KeUpdateSystemTime(&KernelTrapFrame, PROFILE_LEVEL);
KeUpdateSystemTime(&KernelTrapFrame, old_level);
#ifdef KDBG
KdbProfileInterrupt(Trapframe->Eip);
#endif /* KDBG */
}
else
#endif
{
/*
* Actually call the ISR.
*/
KiInterruptDispatch2(irq, old_level);
KiInterruptDispatch2(vector, old_level);
}
/*
@ -480,8 +375,6 @@ KiInterruptDispatch (ULONG irq, PKIRQ_TRAPFRAME Trapframe)
}
}
#endif /* MP */
static VOID
KeDumpIrqList(VOID)
{
@ -519,6 +412,12 @@ KeConnectInterrupt(PKINTERRUPT InterruptObject)
Vector = InterruptObject->Vector;
if (Vector < IRQ_BASE && Vector >= IRQ_BASE + NR_IRQS)
{
return STATUS_INVALID_PARAMETER;
}
Vector -= IRQ_BASE;
/*
* Acquire the table spinlock
*/
@ -549,11 +448,7 @@ KeConnectInterrupt(PKINTERRUPT InterruptObject)
DPRINT("%x %x\n",isr_table[Vector].Flink,isr_table[Vector].Blink);
if (IsListEmpty(&isr_table[Vector]))
{
#ifdef MP
HalEnableSystemInterrupt(Vector, 0, 0);
#else
HalEnableSystemInterrupt(Vector + IRQ_BASE, 0, 0);
#endif
HalEnableSystemInterrupt(Vector + IRQ_BASE, 0, 0);
}
InsertTailList(&isr_table[Vector],&InterruptObject->Entry);
DPRINT("%x %x\n",InterruptObject->Entry.Flink,
@ -588,13 +483,9 @@ KeDisconnectInterrupt(PKINTERRUPT InterruptObject)
KeRaiseIrql(InterruptObject->SynchLevel,&oldlvl);
KiAcquireSpinLock(InterruptObject->IrqLock);
RemoveEntryList(&InterruptObject->Entry);
if (IsListEmpty(&isr_table[InterruptObject->Vector]))
if (IsListEmpty(&isr_table[InterruptObject->Vector - IRQ_BASE]))
{
#ifdef MP
HalDisableSystemInterrupt(InterruptObject->Vector, 0);
#else
HalDisableSystemInterrupt(InterruptObject->Vector + IRQ_BASE, 0);
#endif
HalDisableSystemInterrupt(InterruptObject->Vector, 0);
}
KiReleaseSpinLock(InterruptObject->IrqLock);
KeLowerIrql(oldlvl);
@ -683,7 +574,7 @@ IoConnectInterrupt(PKINTERRUPT* InterruptObject,
/*
* Check the parameters
*/
if (Vector >= NR_IRQS)
if (Vector < IRQ_BASE || Vector >= NR_IRQS + IRQ_BASE)
{
return(STATUS_INVALID_PARAMETER);
}

View file

@ -1,5 +1,6 @@
#include <internal/i386/segment.h>
#include <../hal/halx86/include/halirq.h>
.global _irq_handler_0
_irq_handler_0:
@ -18,7 +19,7 @@ _irq_handler_0:
movl $PCR_SELECTOR, %eax
movl %eax, %fs
pushl %esp
pushl $0
pushl $(IRQ_BASE + 0)
call _KiInterruptDispatch
popl %eax
popl %eax
@ -47,7 +48,7 @@ _irq_handler_1:
movl $PCR_SELECTOR, %eax
movl %eax, %fs
pushl %esp
pushl $1
pushl $(IRQ_BASE + 1)
call _KiInterruptDispatch
popl %eax
popl %eax
@ -76,7 +77,7 @@ _irq_handler_2:
movl $PCR_SELECTOR, %eax
movl %eax, %fs
pushl %esp
pushl $2
pushl $(IRQ_BASE + 2)
call _KiInterruptDispatch
popl %eax
popl %eax
@ -105,7 +106,7 @@ _irq_handler_3:
movl $PCR_SELECTOR, %eax
movl %eax, %fs
pushl %esp
pushl $3
pushl $(IRQ_BASE + 3)
call _KiInterruptDispatch
popl %eax
popl %eax
@ -134,7 +135,7 @@ _irq_handler_4:
movl $PCR_SELECTOR, %eax
movl %eax, %fs
pushl %esp
pushl $4
pushl $(IRQ_BASE + 4)
call _KiInterruptDispatch
popl %eax
popl %eax
@ -163,7 +164,7 @@ _irq_handler_5:
movl $PCR_SELECTOR, %eax
movl %eax, %fs
pushl %esp
pushl $5
pushl $(IRQ_BASE + 5)
call _KiInterruptDispatch
popl %eax
popl %eax
@ -192,7 +193,7 @@ _irq_handler_6:
movl $PCR_SELECTOR, %eax
movl %eax, %fs
pushl %esp
pushl $6
pushl $(IRQ_BASE + 6)
call _KiInterruptDispatch
popl %eax
popl %eax
@ -221,7 +222,7 @@ _irq_handler_7:
movl $PCR_SELECTOR, %eax
movl %eax, %fs
pushl %esp
pushl $7
pushl $(IRQ_BASE + 7)
call _KiInterruptDispatch
popl %eax
popl %eax
@ -250,7 +251,7 @@ _irq_handler_8:
movl $PCR_SELECTOR, %eax
movl %eax, %fs
pushl %esp
pushl $8
pushl $(IRQ_BASE + 8)
call _KiInterruptDispatch
popl %eax
popl %eax
@ -279,7 +280,7 @@ _irq_handler_9:
movl $PCR_SELECTOR, %eax
movl %eax, %fs
pushl %esp
pushl $9
pushl $(IRQ_BASE + 9)
call _KiInterruptDispatch
popl %eax
popl %eax
@ -308,7 +309,7 @@ _irq_handler_10:
movl $PCR_SELECTOR, %eax
movl %eax, %fs
pushl %esp
pushl $10
pushl $(IRQ_BASE + 10)
call _KiInterruptDispatch
popl %eax
popl %eax
@ -337,7 +338,7 @@ _irq_handler_11:
movl $PCR_SELECTOR, %eax
movl %eax, %fs
pushl %esp
pushl $11
pushl $(IRQ_BASE + 11)
call _KiInterruptDispatch
popl %eax
popl %eax
@ -366,7 +367,7 @@ _irq_handler_12:
movl $PCR_SELECTOR, %eax
movl %eax, %fs
pushl %esp
pushl $12
pushl $(IRQ_BASE + 12)
call _KiInterruptDispatch
popl %eax
popl %eax
@ -395,7 +396,7 @@ _irq_handler_13:
movl $PCR_SELECTOR, %eax
movl %eax, %fs
pushl %esp
pushl $13
pushl $(IRQ_BASE + 13)
call _KiInterruptDispatch
popl %eax
popl %eax
@ -424,7 +425,7 @@ _irq_handler_14:
movl $PCR_SELECTOR, %eax
movl %eax, %fs
pushl %esp
pushl $14
pushl $(IRQ_BASE + 14)
call _KiInterruptDispatch
popl %eax
popl %eax
@ -453,7 +454,7 @@ _irq_handler_15:
movl $PCR_SELECTOR, %eax
movl %eax, %fs
pushl %esp
pushl $15
pushl $(IRQ_BASE + 15)
call _KiInterruptDispatch
popl %eax
popl %eax