xref: /openbsd-src/sys/arch/i386/include/intrdefs.h (revision b53e5cb6267fa6f38fd6043836bb47fc47539036)
1*b53e5cb6Sjsg /*	$OpenBSD: intrdefs.h,v 1.19 2024/11/08 00:13:39 jsg Exp $	*/
2012ea299Sniklas /*	$NetBSD: intrdefs.h,v 1.2 2003/05/04 22:01:56 fvdl Exp $	*/
3012ea299Sniklas 
4584b2611Sderaadt #ifndef _I386_INTRDEFS_H
5584b2611Sderaadt #define _I386_INTRDEFS_H
6012ea299Sniklas 
7012ea299Sniklas /*
8012ea299Sniklas  * Intel APICs (advanced programmable interrupt controllers) have
9012ea299Sniklas  * bytesized priority registers where the upper nibble is the actual
10012ea299Sniklas  * interrupt priority level (a.k.a. IPL).  Interrupt vectors are
11012ea299Sniklas  * closely tied to these levels as interrupts whose vectors' upper
12012ea299Sniklas  * nibble is lower than or equal to the current level are blocked.
13012ea299Sniklas  * Not all 256 possible vectors are available for interrupts in
14012ea299Sniklas  * APIC systems, only
15012ea299Sniklas  *
16012ea299Sniklas  * For systems where instead the older ICU (interrupt controlling
17012ea299Sniklas  * unit, a.k.a. PIC or 82C59) is used, the IPL is not directly useful,
18012ea299Sniklas  * since the interrupt blocking is handled via interrupt masks instead
19012ea299Sniklas  * of levels.  However the IPL is easily used as an offset into arrays
20012ea299Sniklas  * of masks.
21012ea299Sniklas  */
22012ea299Sniklas #define IPLSHIFT 4	/* The upper nibble of vectors is the IPL.	*/
23012ea299Sniklas #define NIPL 16		/* Four bits of information gives as much.	*/
24012ea299Sniklas #define IPL(level) ((level) >> IPLSHIFT)	/* Extract the IPL.	*/
25012ea299Sniklas /* XXX Maybe this IDTVECOFF definition should be elsewhere? */
26012ea299Sniklas #define IDTVECOFF 0x20	/* The lower 32 IDT vectors are reserved.	*/
27012ea299Sniklas 
28012ea299Sniklas /*
29012ea299Sniklas  * This macro is only defined for 0 <= x < 14, i.e. there are fourteen
30012ea299Sniklas  * distinct priority levels available for interrupts.
31012ea299Sniklas  */
32012ea299Sniklas #define MAKEIPL(priority) (IDTVECOFF + ((priority) << IPLSHIFT))
33012ea299Sniklas 
34012ea299Sniklas /*
35012ea299Sniklas  * Interrupt priority levels.
36012ea299Sniklas  *
37012ea299Sniklas  * XXX We are somewhat sloppy about what we mean by IPLs, sometimes
38012ea299Sniklas  * XXX we refer to the eight-bit value suitable for storing into APICs'
39012ea299Sniklas  * XXX priority registers, other times about the four-bit entity found
40012ea299Sniklas  * XXX in the former values' upper nibble, which can be used as offsets
41012ea299Sniklas  * XXX in various arrays of our implementation.  We are hoping that
42012ea299Sniklas  * XXX the context will provide enough information to not make this
43012ea299Sniklas  * XXX sloppy naming a real problem.
44012ea299Sniklas  *
45012ea299Sniklas  * There are tty, network and disk drivers that use free() at interrupt
46012ea299Sniklas  * time, so imp > (tty | net | bio).
47012ea299Sniklas  *
48012ea299Sniklas  * Since run queues may be manipulated by both the statclock and tty,
49012ea299Sniklas  * network, and disk drivers, clock > imp.
50012ea299Sniklas  *
51012ea299Sniklas  * IPL_HIGH must block everything that can manipulate a run queue.
52012ea299Sniklas  *
53012ea299Sniklas  * XXX Ultimately we may need serial drivers to run at the absolute highest
54012ea299Sniklas  * XXX priority to avoid overruns, then we must make serial > high.
55012ea299Sniklas  *
56012ea299Sniklas  * The level numbers are picked to fit into APIC vector priorities.
57012ea299Sniklas  */
58012ea299Sniklas #define	IPL_NONE	0		/* nothing */
597a83af50Sart #define	IPL_SOFTCLOCK	MAKEIPL(1)	/* timeouts */
607a83af50Sart #define	IPL_SOFTNET	MAKEIPL(2)	/* protocol stacks */
617a83af50Sart #define	IPL_BIO		MAKEIPL(3)	/* block I/O */
627a83af50Sart #define	IPL_NET		MAKEIPL(4)	/* network */
637a83af50Sart #define	IPL_SOFTTTY	MAKEIPL(5)	/* delayed terminal handling */
647a83af50Sart #define	IPL_TTY		MAKEIPL(6)	/* terminal */
657a83af50Sart #define	IPL_VM		MAKEIPL(7)	/* memory allocation */
667a83af50Sart #define	IPL_AUDIO	MAKEIPL(8)	/* audio */
677a83af50Sart #define	IPL_CLOCK	MAKEIPL(9)	/* clock */
68950cab9cSoga #define	IPL_STATCLOCK	IPL_CLOCK	/* statclock */
69950cab9cSoga #define	IPL_SCHED	IPL_CLOCK
70950cab9cSoga #define	IPL_HIGH	MAKEIPL(10)	/* everything */
71950cab9cSoga #define	IPL_IPI		MAKEIPL(11)	/* interprocessor interrupt */
72012ea299Sniklas 
734965d1a4Smpi #define	IPL_MPFLOOR	IPL_TTY
74747479c5Skettenis #define	IPL_MPSAFE	0x100
75747479c5Skettenis 
76012ea299Sniklas /* Interrupt sharing types. */
77012ea299Sniklas #define	IST_NONE	0	/* none */
78012ea299Sniklas #define	IST_PULSE	1	/* pulsed */
79012ea299Sniklas #define	IST_EDGE	2	/* edge-triggered */
80012ea299Sniklas #define	IST_LEVEL	3	/* level-triggered */
81012ea299Sniklas 
82012ea299Sniklas /*
83012ea299Sniklas  * Local APIC masks. Must not conflict with SIR_* below, and must
84012ea299Sniklas  * be >= NUM_LEGACY_IRQs. Note that LIR_IPI must be first.
85012ea299Sniklas  */
86012ea299Sniklas #define LIR_IPI		31
87012ea299Sniklas #define LIR_TIMER	30
88012ea299Sniklas 
89012ea299Sniklas /* Soft interrupt masks. */
90012ea299Sniklas #define	SIR_CLOCK	29
91012ea299Sniklas #define	SIR_NET		28
92012ea299Sniklas #define	SIR_TTY		27
93012ea299Sniklas 
94012ea299Sniklas 
95012ea299Sniklas /*
96012ea299Sniklas  * Maximum # of interrupt sources per CPU. 32 to fit in one word.
97012ea299Sniklas  * ioapics can theoretically produce more, but it's not likely to
98012ea299Sniklas  * happen. For multiple ioapics, things can be routed to different
99012ea299Sniklas  * CPUs.
100012ea299Sniklas  */
101012ea299Sniklas #define MAX_INTR_SOURCES	32
102012ea299Sniklas #define NUM_LEGACY_IRQS		16
103012ea299Sniklas 
104012ea299Sniklas /*
105012ea299Sniklas  * Low and high boundaries between which interrupt gates will
106012ea299Sniklas  * be allocated in the IDT.
107012ea299Sniklas  */
108012ea299Sniklas #define IDT_INTR_LOW	(0x20 + NUM_LEGACY_IRQS)
109012ea299Sniklas #define IDT_INTR_HIGH	0xef
110012ea299Sniklas 
111012ea299Sniklas #define I386_IPI_HALT		0x00000001
1120330a9d2Skettenis #define I386_IPI_NOP		0x00000002
1130330a9d2Skettenis #define I386_IPI_FLUSH_FPU	0x00000004
1140330a9d2Skettenis #define I386_IPI_SYNCH_FPU	0x00000008
1150330a9d2Skettenis #define I386_IPI_MTRR		0x00000010
1160330a9d2Skettenis #define I386_IPI_GDT		0x00000020
1170330a9d2Skettenis #define I386_IPI_DDB		0x00000040	/* synchronize while in ddb */
1180330a9d2Skettenis #define I386_IPI_SETPERF	0x00000080
1193fb0e55cSjsg #define I386_IPI_WBINVD		0x00000100
120012ea299Sniklas 
1213fb0e55cSjsg #define I386_NIPI	9
122012ea299Sniklas 
123012ea299Sniklas #define IREENT_MAGIC	0x18041969
124012ea299Sniklas 
125012ea299Sniklas #endif /* _I386_INTRDEFS_H */
126