xref: /openbsd-src/sys/arch/amd64/include/i82093reg.h (revision 4ce05526d28688dc55506472d1277c2974eb4047)
1*4ce05526Sguenther /*	$OpenBSD: i82093reg.h,v 1.8 2022/12/01 00:26:15 guenther Exp $	*/
2f5df1827Smickey /* 	$NetBSD: i82093reg.h,v 1.1 2003/02/26 21:26:10 fvdl Exp $ */
3f5df1827Smickey 
4f5df1827Smickey /*-
5f5df1827Smickey  * Copyright (c) 2000 The NetBSD Foundation, Inc.
6f5df1827Smickey  * All rights reserved.
7f5df1827Smickey  *
8f5df1827Smickey  * This code is derived from software contributed to The NetBSD Foundation
9f5df1827Smickey  * by RedBack Networks Inc.
10f5df1827Smickey  *
11f5df1827Smickey  * Author: Bill Sommerfeld
12f5df1827Smickey  *
13f5df1827Smickey  * Redistribution and use in source and binary forms, with or without
14f5df1827Smickey  * modification, are permitted provided that the following conditions
15f5df1827Smickey  * are met:
16f5df1827Smickey  * 1. Redistributions of source code must retain the above copyright
17f5df1827Smickey  *    notice, this list of conditions and the following disclaimer.
18f5df1827Smickey  * 2. Redistributions in binary form must reproduce the above copyright
19f5df1827Smickey  *    notice, this list of conditions and the following disclaimer in the
20f5df1827Smickey  *    documentation and/or other materials provided with the distribution.
21f5df1827Smickey  *
22f5df1827Smickey  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23f5df1827Smickey  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24f5df1827Smickey  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25f5df1827Smickey  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26f5df1827Smickey  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27f5df1827Smickey  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28f5df1827Smickey  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29f5df1827Smickey  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30f5df1827Smickey  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31f5df1827Smickey  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32f5df1827Smickey  * POSSIBILITY OF SUCH DAMAGE.
33f5df1827Smickey  */
34f5df1827Smickey 
35f5df1827Smickey /*
36f5df1827Smickey  * Typically, the first apic lives here.
37f5df1827Smickey  */
38f5df1827Smickey #define IOAPIC_BASE_DEFAULT	0xfec00000
39f5df1827Smickey 
40f5df1827Smickey /*
41f5df1827Smickey  * Memory-space registers.
42f5df1827Smickey  */
43f5df1827Smickey 
44f5df1827Smickey /*
45f5df1827Smickey  * The externally visible registers are all 32 bits wide;
46f5df1827Smickey  * store the register number of interest in IOAPIC_REG, and store/fetch
47f5df1827Smickey  * the real value in IOAPIC_DATA.
48f5df1827Smickey  */
49f5df1827Smickey #define	IOAPIC_REG		0x0000
50f5df1827Smickey #define IOAPIC_DATA		0x0010
51f5df1827Smickey 
52f5df1827Smickey /*
53f5df1827Smickey  * Internal I/O APIC registers.
54f5df1827Smickey  */
55f5df1827Smickey 
56f5df1827Smickey #define IOAPIC_ID		0x00
57f5df1827Smickey 
58f5df1827Smickey #define 	IOAPIC_ID_SHIFT		24
59f5df1827Smickey #define		IOAPIC_ID_MASK		0x0f000000
60f5df1827Smickey 
61f5df1827Smickey /* Version, and maximum interrupt pin number. */
62f5df1827Smickey 
63f5df1827Smickey #define IOAPIC_VER		0x01
64f5df1827Smickey 
65f5df1827Smickey #define		IOAPIC_VER_SHIFT		0
66f5df1827Smickey #define		IOAPIC_VER_MASK			0x000000ff
67f5df1827Smickey 
68f5df1827Smickey #define		IOAPIC_MAX_SHIFT	       	16
69f5df1827Smickey #define		IOAPIC_MAX_MASK	       	0x00ff0000
70f5df1827Smickey 
71f5df1827Smickey /*
72f5df1827Smickey  * Arbitration ID.  Same format as IOAPIC_ID register.
73f5df1827Smickey  */
74f5df1827Smickey #define IOAPIC_ARB		0x02
75f5df1827Smickey 
76f5df1827Smickey /*
77f5df1827Smickey  * Redirection table registers.
78f5df1827Smickey  */
79f5df1827Smickey 
80f5df1827Smickey #define IOAPIC_REDHI(pin)	(0x11 + ((pin)<<1))
81f5df1827Smickey #define IOAPIC_REDLO(pin)	(0x10 + ((pin)<<1))
82f5df1827Smickey 
83f5df1827Smickey #define IOAPIC_REDHI_DEST_SHIFT		24	   /* destination. */
84f5df1827Smickey #define IOAPIC_REDHI_DEST_MASK		0xff000000
85f5df1827Smickey 
86f5df1827Smickey #define IOAPIC_REDLO_MASK		0x00010000 /* 0=enabled; 1=masked */
87f5df1827Smickey 
88f5df1827Smickey #define IOAPIC_REDLO_LEVEL		0x00008000 /* 0=edge, 1=level */
89f5df1827Smickey #define IOAPIC_REDLO_RIRR		0x00004000 /* remote IRR; read only */
90f5df1827Smickey #define IOAPIC_REDLO_ACTLO		0x00002000 /* 0=act. hi; 1=act. lo */
91f5df1827Smickey #define IOAPIC_REDLO_DELSTS		0x00001000 /* 0=idle; 1=send pending */
92f5df1827Smickey #define IOAPIC_REDLO_DSTMOD		0x00000800 /* 0=physical; 1=logical */
93f5df1827Smickey 
94f5df1827Smickey #define IOAPIC_REDLO_DEL_MASK		0x00000700 /* del. mode mask */
95f5df1827Smickey #define IOAPIC_REDLO_DEL_SHIFT		8
96f5df1827Smickey 
97f5df1827Smickey #define IOAPIC_REDLO_DEL_FIXED		0
98f5df1827Smickey #define IOAPIC_REDLO_DEL_LOPRI		1
99f5df1827Smickey #define IOAPIC_REDLO_DEL_SMI		2
100f5df1827Smickey #define IOAPIC_REDLO_DEL_NMI		4
101f5df1827Smickey #define IOAPIC_REDLO_DEL_INIT		5
102f5df1827Smickey #define IOAPIC_REDLO_DEL_EXTINT		7
103f5df1827Smickey 
104f5df1827Smickey #define IOAPIC_REDLO_VECTOR_MASK	0x000000ff /* delivery vector */
105f5df1827Smickey 
106f5df1827Smickey #define IMCR_ADDR		0x22
107f5df1827Smickey #define IMCR_DATA		0x23
108f5df1827Smickey 
109f5df1827Smickey #define IMCR_REGISTER		0x70
110f5df1827Smickey #define		IMCR_PIC	0x00
111f5df1827Smickey #define 	IMCR_APIC	0x01
112b5b9857bSart 
113b5b9857bSart #ifdef _KERNEL
114b5b9857bSart 
115984d4744Ssf #include <machine/codepatch.h>
116984d4744Ssf 
117b5b9857bSart #define ioapic_asm_ack(num) 					 \
118984d4744Ssf 	CODEPATCH_START						;\
119*4ce05526Sguenther 	movl	$0,(local_apic+LAPIC_EOI)(%rip)			;\
120984d4744Ssf 	CODEPATCH_END(CPTAG_EOI)
121984d4744Ssf 
122b5b9857bSart 
123b5b9857bSart #ifdef MULTIPROCESSOR
124b5b9857bSart 
125b5b9857bSart #ifdef notyet
126b5b9857bSart #define ioapic_asm_lock(num) \
127b5b9857bSart 	movl	$1,%esi						;\
128b5b9857bSart 77:								\
129b5b9857bSart 	xchgl	%esi,PIC_LOCK(%rdi)				;\
130b5b9857bSart 	testl	%esi,%esi					;\
131b5b9857bSart 	jne	77b
132b5b9857bSart 
133b5b9857bSart #define ioapic_asm_unlock(num) \
134b5b9857bSart 	movl	$0,PIC_LOCK(%rdi)
135b5b9857bSart #else
136b5b9857bSart #define ioapic_asm_lock(num)
137b5b9857bSart #define ioapic_asm_unlock(num)
138b5b9857bSart #endif
139b5b9857bSart 
140b5b9857bSart #else
141b5b9857bSart 
142b5b9857bSart #define ioapic_asm_lock(num)
143b5b9857bSart #define ioapic_asm_unlock(num)
144b5b9857bSart 
145b5b9857bSart #endif	/* MULTIPROCESSOR */
146b5b9857bSart 
147b5b9857bSart 
148b5b9857bSart #define ioapic_mask(num) \
149b5b9857bSart 	movq	IS_PIC(%r14),%rdi				;\
150b5b9857bSart 	ioapic_asm_lock(num)					;\
151b5b9857bSart 	movl	IS_PIN(%r14),%esi				;\
152b5b9857bSart 	leaq	0x10(%rsi,%rsi,1),%rsi				;\
153b5b9857bSart 	movq	IOAPIC_SC_REG(%rdi),%r15			;\
154b5b9857bSart 	movl	%esi, (%r15)					;\
155b5b9857bSart 	movq	IOAPIC_SC_DATA(%rdi),%r15			;\
156b5b9857bSart 	movl	(%r15),%esi					;\
157b5b9857bSart 	orl	$IOAPIC_REDLO_MASK,%esi				;\
1582af81419Smlarkin 	andl	$~IOAPIC_REDLO_RIRR,%esi			;\
159b5b9857bSart 	movl	%esi,(%r15)					;\
160b5b9857bSart 	ioapic_asm_unlock(num)
161b5b9857bSart 
162b5b9857bSart #define ioapic_unmask(num) \
1637effbc1fSguenther 	cmpq	$IREENT_MAGIC,IF_ERR(%rsp)			;\
164b5b9857bSart 	jne	79f						;\
165b5b9857bSart 	movq	IS_PIC(%r14),%rdi				;\
166b5b9857bSart 	ioapic_asm_lock(num)					;\
167b5b9857bSart 	movl	IS_PIN(%r14),%esi				;\
168b5b9857bSart 	leaq	0x10(%rsi,%rsi,1),%rsi				;\
169b5b9857bSart 	movq	IOAPIC_SC_REG(%rdi),%r15			;\
170b5b9857bSart 	movq	IOAPIC_SC_DATA(%rdi),%r13			;\
171b5b9857bSart 	movl	%esi, (%r15)					;\
172b5b9857bSart 	movl	(%r13),%r12d					;\
173b5b9857bSart 	andl	$~IOAPIC_REDLO_MASK,%r12d			;\
1742af81419Smlarkin 	andl	$~IOAPIC_REDLO_RIRR,%r12d			;\
175b5b9857bSart 	movl	%esi,(%r15)					;\
176b5b9857bSart 	movl	%r12d,(%r13)					;\
177b5b9857bSart 	ioapic_asm_unlock(num)					;\
178b5b9857bSart 79:
179b5b9857bSart 
180b5b9857bSart #endif
181