xref: /illumos-gate/usr/src/uts/i86pc/sys/apic.h (revision 41afdfa77f9af46beb3aaab2eccc0d9afe660d31)
1ae115bc7Smrj /*
2ae115bc7Smrj  * CDDL HEADER START
3ae115bc7Smrj  *
4ae115bc7Smrj  * The contents of this file are subject to the terms of the
5ae115bc7Smrj  * Common Development and Distribution License (the "License").
6ae115bc7Smrj  * You may not use this file except in compliance with the License.
7ae115bc7Smrj  *
8ae115bc7Smrj  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9ae115bc7Smrj  * or http://www.opensolaris.org/os/licensing.
10ae115bc7Smrj  * See the License for the specific language governing permissions
11ae115bc7Smrj  * and limitations under the License.
12ae115bc7Smrj  *
13ae115bc7Smrj  * When distributing Covered Code, include this CDDL HEADER in each
14ae115bc7Smrj  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15ae115bc7Smrj  * If applicable, add the following below this CDDL HEADER, with the
16ae115bc7Smrj  * fields enclosed by brackets "[]" replaced with your own identifying
17ae115bc7Smrj  * information: Portions Copyright [yyyy] [name of copyright owner]
18ae115bc7Smrj  *
19ae115bc7Smrj  * CDDL HEADER END
20ae115bc7Smrj  */
21ae115bc7Smrj /*
22e7c3cdaeSjiang.liu@intel.com  * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
23ae115bc7Smrj  */
24ae115bc7Smrj 
25*41afdfa7SKrishnendu Sadhukhan - Sun Microsystems /*
26*41afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * Copyright (c) 2010, Intel Corporation.
27*41afdfa7SKrishnendu Sadhukhan - Sun Microsystems  * All rights reserved.
28*41afdfa7SKrishnendu Sadhukhan - Sun Microsystems  */
29*41afdfa7SKrishnendu Sadhukhan - Sun Microsystems 
30ae115bc7Smrj #ifndef _SYS_APIC_APIC_H
31ae115bc7Smrj #define	_SYS_APIC_APIC_H
32ae115bc7Smrj 
33ae115bc7Smrj #include <sys/psm_types.h>
34c8589f13Ssethg #include <sys/avintr.h>
35c8589f13Ssethg #include <sys/pci.h>
36ae115bc7Smrj 
37ae115bc7Smrj #ifdef	__cplusplus
38ae115bc7Smrj extern "C" {
39ae115bc7Smrj #endif
40ae115bc7Smrj 
41ae115bc7Smrj #include <sys/psm_common.h>
42ae115bc7Smrj 
432917a9c9Sschwartz #define	APIC_PCPLUSMP_NAME	"pcplusmp"
447ff178cdSJimmy Vetayases #define	APIC_APIX_NAME		"apix"
452917a9c9Sschwartz 
46ae115bc7Smrj #define	APIC_IO_ADDR	0xfec00000
47ae115bc7Smrj #define	APIC_LOCAL_ADDR	0xfee00000
48ae115bc7Smrj #define	APIC_IO_MEMLEN	0xf
49ae115bc7Smrj #define	APIC_LOCAL_MEMLEN	0xfffff
50ae115bc7Smrj 
51ae115bc7Smrj /* Local Unit ID register */
52ae115bc7Smrj #define	APIC_LID_REG		0x8
53ae115bc7Smrj 
54ae115bc7Smrj /* I/o Unit Version Register */
55ae115bc7Smrj #define	APIC_VERS_REG		0xc
56ae115bc7Smrj 
57ae115bc7Smrj /* Task Priority register */
58ae115bc7Smrj #define	APIC_TASK_REG		0x20
59ae115bc7Smrj 
60ae115bc7Smrj /* EOI register */
61ae115bc7Smrj #define	APIC_EOI_REG		0x2c
62ae115bc7Smrj 
63ae115bc7Smrj /* Remote Read register		*/
64ae115bc7Smrj #define	APIC_REMOTE_READ	0x30
65ae115bc7Smrj 
66ae115bc7Smrj /* Logical Destination register */
67ae115bc7Smrj #define	APIC_DEST_REG		0x34
68ae115bc7Smrj 
6987cc6269SSaurabh Misra /* Destination Format register */
70ae115bc7Smrj #define	APIC_FORMAT_REG		0x38
71ae115bc7Smrj 
72ae115bc7Smrj /* Spurious Interrupt Vector register */
73ae115bc7Smrj #define	APIC_SPUR_INT_REG	0x3c
74ae115bc7Smrj 
75ae115bc7Smrj /* Error Status Register */
76ae115bc7Smrj #define	APIC_ERROR_STATUS	0xa0
77ae115bc7Smrj 
78ae115bc7Smrj /* Interrupt Command registers */
79ae115bc7Smrj #define	APIC_INT_CMD1		0xc0
80ae115bc7Smrj #define	APIC_INT_CMD2		0xc4
81ae115bc7Smrj 
82ae115bc7Smrj /* Local Interrupt Vector registers */
83e3d60c9bSAdrian Frost #define	APIC_CMCI_VECT		0xbc
84da2743adSdmick #define	APIC_THERM_VECT		0xcc
85ae115bc7Smrj #define	APIC_PCINT_VECT		0xd0
86ae115bc7Smrj #define	APIC_INT_VECT0		0xd4
87ae115bc7Smrj #define	APIC_INT_VECT1		0xd8
88ae115bc7Smrj #define	APIC_ERR_VECT		0xdc
89ae115bc7Smrj 
90ae115bc7Smrj /* IPL for performance counter interrupts */
91ae115bc7Smrj #define	APIC_PCINT_IPL		0xe
92ae115bc7Smrj #define	APIC_LVT_MASK		0x10000		/* Mask bit (16) in LVT */
93ae115bc7Smrj 
94ae115bc7Smrj /* Initial Count register */
95ae115bc7Smrj #define	APIC_INIT_COUNT		0xe0
96ae115bc7Smrj 
97ae115bc7Smrj /* Current Count Register */
98ae115bc7Smrj #define	APIC_CURR_COUNT		0xe4
99ae115bc7Smrj #define	APIC_CURR_ADD		0x39	/* used for remote read command */
100ae115bc7Smrj #define	CURR_COUNT_OFFSET	(sizeof (int32_t) * APIC_CURR_COUNT)
101ae115bc7Smrj 
102ae115bc7Smrj /* Divider Configuration Register */
103ae115bc7Smrj #define	APIC_DIVIDE_REG		0xf8
104ae115bc7Smrj 
105b6917abeSmishra /* Various mode for local APIC. Modes are mutually exclusive  */
106b6917abeSmishra #define	APIC_IS_DISABLED	0x0
107b6917abeSmishra #define	APIC_MODE_NOTSET	0x1
108b6917abeSmishra #define	LOCAL_APIC		0x2
109b6917abeSmishra #define	LOCAL_X2APIC		0x3
110b6917abeSmishra 
1115d8efbbcSSaurabh Misra /* x2APIC SELF IPI Register */
11287cc6269SSaurabh Misra #define	X2APIC_SELF_IPI		0xFC
113b6917abeSmishra 
114b6917abeSmishra /* General x2APIC constants used at various places */
115e511d54dSSaurabh Misra #define	APIC_SVR_SUPPRESS_BROADCAST_EOI		0x1000
116e511d54dSSaurabh Misra #define	APIC_DIRECTED_EOI_BIT			0x1000000
117b6917abeSmishra 
118ae115bc7Smrj /* IRR register	*/
119ae115bc7Smrj #define	APIC_IRR_REG		0x80
120ae115bc7Smrj 
121ae115bc7Smrj /* ISR register	*/
122ae115bc7Smrj #define	APIC_ISR_REG		0x40
123ae115bc7Smrj 
124ae115bc7Smrj #define	APIC_IO_REG		0x0
125ae115bc7Smrj #define	APIC_IO_DATA		0x4
126b6917abeSmishra #define	APIC_IO_EOI		0x10
127ae115bc7Smrj 
128ae115bc7Smrj /* Bit offset of APIC ID in LID_REG, INT_CMD and in DEST_REG */
129ae115bc7Smrj #define	APIC_ID_BIT_OFFSET	24
130ae115bc7Smrj #define	APIC_ICR_ID_BIT_OFFSET	24
131ae115bc7Smrj #define	APIC_LDR_ID_BIT_OFFSET	24
132ae115bc7Smrj 
133ae115bc7Smrj /*
134ae115bc7Smrj  * Choose between flat and clustered models by writing the following to the
135ae115bc7Smrj  * FORMAT_REG. 82489 DX documentation seemed to suggest that writing 0 will
136ae115bc7Smrj  * disable logical destination mode.
137ae115bc7Smrj  * Does not seem to be in the docs for local APICs on the processors.
138ae115bc7Smrj  */
139ae115bc7Smrj #define	APIC_FLAT_MODEL		0xFFFFFFFFUL
140ae115bc7Smrj #define	APIC_CLUSTER_MODEL	0x0FFFFFFF
141ae115bc7Smrj 
142ae115bc7Smrj /*
143ae115bc7Smrj  * The commands which follow are window selectors written to APIC_IO_REG
144ae115bc7Smrj  * before data can be read/written from/to APIC_IO_DATA
145ae115bc7Smrj  */
146ae115bc7Smrj 
147ae115bc7Smrj #define	APIC_ID_CMD		0x0
148ae115bc7Smrj #define	APIC_VERS_CMD		0x1
149ae115bc7Smrj #define	APIC_RDT_CMD		0x10
150ae115bc7Smrj #define	APIC_RDT_CMD2		0x11
151ae115bc7Smrj 
152ae115bc7Smrj #define	APIC_INTEGRATED_VERS	0x10	/* 0x10 & above indicates integrated */
153ae115bc7Smrj #define	IOAPIC_VER_82489DX	0x01	/* Version ID: 82489DX External APIC */
154ae115bc7Smrj 
155ae115bc7Smrj #define	APIC_INT_SPURIOUS	-1
156ae115bc7Smrj 
157ae115bc7Smrj #define	APIC_IMCR_P1	0x22		/* int mode conf register port 1 */
158ae115bc7Smrj #define	APIC_IMCR_P2	0x23		/* int mode conf register port 2 */
159ae115bc7Smrj #define	APIC_IMCR_SELECT 0x70		/* select imcr by writing into P1 */
160ae115bc7Smrj #define	APIC_IMCR_PIC	0x0		/* selects PIC mode (8259-> BSP) */
161ae115bc7Smrj #define	APIC_IMCR_APIC	0x1		/* selects APIC mode (8259->APIC) */
162ae115bc7Smrj 
163ae115bc7Smrj #define	APIC_CT_VECT	0x4ac		/* conf table vector		*/
164ae115bc7Smrj #define	APIC_CT_SIZE	1024		/* conf table size		*/
165ae115bc7Smrj 
166ae115bc7Smrj #define	APIC_ID		'MPAT'		/* conf table signature 	*/
167ae115bc7Smrj 
168c8589f13Ssethg #define	VENID_AMD		0x1022
169c8589f13Ssethg #define	DEVID_8131_IOAPIC	0x7451
170c8589f13Ssethg #define	DEVID_8132_IOAPIC	0x7459
171c8589f13Ssethg 
172c8589f13Ssethg #define	IOAPICS_NODE_NAME	"ioapics"
173c8589f13Ssethg #define	IOAPICS_CHILD_NAME	"ioapic"
174c8589f13Ssethg #define	IOAPICS_DEV_TYPE	"ioapic"
175c8589f13Ssethg #define	IOAPICS_PROP_VENID	"vendor-id"
176c8589f13Ssethg #define	IOAPICS_PROP_DEVID	"device-id"
177c8589f13Ssethg 
178c8589f13Ssethg #define	IS_CLASS_IOAPIC(b, s, p) \
179c8589f13Ssethg 	((b) == PCI_CLASS_PERIPH && (s) == PCI_PERIPH_PIC &&	\
180c8589f13Ssethg 	((p) == PCI_PERIPH_PIC_IF_IO_APIC ||			\
181c8589f13Ssethg 	(p) == PCI_PERIPH_PIC_IF_IOX_APIC))
182c8589f13Ssethg 
183b6917abeSmishra /*
184b6917abeSmishra  * These macros are used in frequently called routines like
185b6917abeSmishra  * apic_intr_enter().
186b6917abeSmishra  */
187b6917abeSmishra #define	X2APIC_WRITE(reg, v) \
188b6917abeSmishra 	wrmsr((REG_X2APIC_BASE_MSR + (reg >> 2)), v)
189b6917abeSmishra 
190b6917abeSmishra #define	LOCAL_APIC_WRITE_REG(reg, v) \
191b6917abeSmishra 	apicadr[reg] = v
192ae115bc7Smrj 
193ae115bc7Smrj /*
194ae115bc7Smrj  * MP floating pointer structure defined in Intel MP Spec 1.1
195ae115bc7Smrj  */
196ae115bc7Smrj struct apic_mpfps_hdr {
197ae115bc7Smrj 	uint32_t	mpfps_sig;	/* _MP_ (0x5F4D505F)		*/
198ae115bc7Smrj 	uint32_t	mpfps_mpct_paddr; /* paddr of MP configuration tbl */
199ae115bc7Smrj 	uchar_t	mpfps_length;		/* in paragraph (16-bytes units) */
200ae115bc7Smrj 	uchar_t	mpfps_spec_rev;		/* version number of MP spec	 */
201ae115bc7Smrj 	uchar_t	mpfps_checksum;		/* checksum of complete structure */
202ae115bc7Smrj 	uchar_t	mpfps_featinfo1;	/* mp feature info bytes 1	 */
203ae115bc7Smrj 	uchar_t	mpfps_featinfo2;	/* mp feature info bytes 2	 */
204ae115bc7Smrj 	uchar_t	mpfps_featinfo3;	/* mp feature info bytes 3	 */
205ae115bc7Smrj 	uchar_t	mpfps_featinfo4;	/* mp feature info bytes 4	 */
206ae115bc7Smrj 	uchar_t	mpfps_featinfo5;	/* mp feature info bytes 5	 */
207ae115bc7Smrj };
208ae115bc7Smrj 
209ae115bc7Smrj #define	MPFPS_FEATINFO2_IMCRP		0x80	/* IMCRP presence bit	*/
210ae115bc7Smrj 
211ae115bc7Smrj #define	APIC_MPS_OEM_ID_LEN		8
212ae115bc7Smrj #define	APIC_MPS_PROD_ID_LEN		12
213ae115bc7Smrj 
214ae115bc7Smrj struct apic_mp_cnf_hdr {
215ae115bc7Smrj 	uint_t	mpcnf_sig;
216ae115bc7Smrj 
217ae115bc7Smrj 	uint_t	mpcnf_tbl_length:	16,
218ae115bc7Smrj 		mpcnf_spec:		8,
219ae115bc7Smrj 		mpcnf_cksum:		8;
220ae115bc7Smrj 
221ae115bc7Smrj 	char	mpcnf_oem_str[APIC_MPS_OEM_ID_LEN];
222ae115bc7Smrj 
223ae115bc7Smrj 	char	mpcnf_prod_str[APIC_MPS_PROD_ID_LEN];
224ae115bc7Smrj 
225ae115bc7Smrj 	uint_t	mpcnf_oem_ptr;
226ae115bc7Smrj 
227ae115bc7Smrj 	uint_t	mpcnf_oem_tbl_size:	16,
228ae115bc7Smrj 		mpcnf_entry_cnt:	16;
229ae115bc7Smrj 
230ae115bc7Smrj 	uint_t	mpcnf_local_apic;
231ae115bc7Smrj 
232ae115bc7Smrj 	uint_t	mpcnf_resv;
233ae115bc7Smrj };
234ae115bc7Smrj 
235ae115bc7Smrj struct apic_procent {
236ae115bc7Smrj 	uint_t	proc_entry:		8,
237ae115bc7Smrj 		proc_apicid:		8,
238ae115bc7Smrj 		proc_version:		8,
239ae115bc7Smrj 		proc_cpuflags:		8;
240ae115bc7Smrj 
241ae115bc7Smrj 	uint_t	proc_stepping:		4,
242ae115bc7Smrj 		proc_model:		4,
243ae115bc7Smrj 		proc_family:		4,
244ae115bc7Smrj 		proc_type:		2,	/* undocumented feature */
245ae115bc7Smrj 		proc_resv1:		18;
246ae115bc7Smrj 
247ae115bc7Smrj 	uint_t	proc_feature;
248ae115bc7Smrj 
249ae115bc7Smrj 	uint_t	proc_resv2;
250ae115bc7Smrj 
251ae115bc7Smrj 	uint_t	proc_resv3;
252ae115bc7Smrj };
253ae115bc7Smrj 
254ae115bc7Smrj /*
255ae115bc7Smrj  * proc_cpuflags definitions
256ae115bc7Smrj  */
257ae115bc7Smrj #define	CPUFLAGS_EN	1	/* if not set, this processor is unusable */
258ae115bc7Smrj #define	CPUFLAGS_BP	2	/* set if this is the bootstrap processor */
259ae115bc7Smrj 
260ae115bc7Smrj 
261ae115bc7Smrj struct apic_bus {
262ae115bc7Smrj 	uchar_t	bus_entry;
263ae115bc7Smrj 	uchar_t	bus_id;
264ae115bc7Smrj 	ushort_t	bus_str1;
265ae115bc7Smrj 	uint_t	bus_str2;
266ae115bc7Smrj };
267ae115bc7Smrj 
268ae115bc7Smrj struct apic_io_entry {
269ae115bc7Smrj 	uint_t	io_entry:		8,
270ae115bc7Smrj 		io_apicid:		8,
271ae115bc7Smrj 		io_version:		8,
272ae115bc7Smrj 		io_flags:		8;
273ae115bc7Smrj 
274ae115bc7Smrj 	uint_t	io_apic_addr;
275ae115bc7Smrj };
276ae115bc7Smrj 
277ae115bc7Smrj #define	IOAPIC_FLAGS_EN		0x01	/* this I/O apic is enable or not */
278ae115bc7Smrj 
279ae115bc7Smrj #define	MAX_IO_APIC		32	/* maximum # of IOAPICs supported */
280ae115bc7Smrj 
281ae115bc7Smrj struct apic_io_intr {
282ae115bc7Smrj 	uint_t	intr_entry:		8,
283ae115bc7Smrj 		intr_type:		8,
284ae115bc7Smrj 		intr_po:		2,
285ae115bc7Smrj 		intr_el:		2,
286ae115bc7Smrj 		intr_resv:		12;
287ae115bc7Smrj 
288ae115bc7Smrj 	uint_t	intr_busid:		8,
289ae115bc7Smrj 		intr_irq:		8,
290ae115bc7Smrj 		intr_destid:		8,
291ae115bc7Smrj 		intr_destintin:		8;
292ae115bc7Smrj };
293ae115bc7Smrj 
294ae115bc7Smrj /*
295ae115bc7Smrj  * intr_type definitions
296ae115bc7Smrj  */
297ae115bc7Smrj #define	IO_INTR_INT	0x00
298ae115bc7Smrj #define	IO_INTR_NMI	0x01
299ae115bc7Smrj #define	IO_INTR_SMI	0x02
300ae115bc7Smrj #define	IO_INTR_EXTINT	0x03
301ae115bc7Smrj 
302ae115bc7Smrj /*
303ae115bc7Smrj  * destination APIC ID
304ae115bc7Smrj  */
305ae115bc7Smrj #define	INTR_ALL_APIC		0xff
306ae115bc7Smrj 
307ae115bc7Smrj 
308ae115bc7Smrj /* local vector table							*/
309ae115bc7Smrj #define	AV_MASK		0x10000
310ae115bc7Smrj 
311ae115bc7Smrj /* interrupt command register 32-63					*/
312ae115bc7Smrj #define	AV_TOALL	0x7fffffff
313ae115bc7Smrj #define	AV_HIGH_ORDER	0x40000000
314ae115bc7Smrj #define	AV_IM_OFF	0x40000000
315ae115bc7Smrj 
316ae115bc7Smrj /* interrupt command register 0-31					*/
317da2743adSdmick #define	AV_DELIV_MODE	0x700
318da2743adSdmick 
319ae115bc7Smrj #define	AV_FIXED	0x000
320ae115bc7Smrj #define	AV_LOPRI	0x100
321da2743adSdmick #define	AV_SMI		0x200
322ae115bc7Smrj #define	AV_REMOTE	0x300
323ae115bc7Smrj #define	AV_NMI		0x400
324ae115bc7Smrj #define	AV_RESET	0x500
325ae115bc7Smrj #define	AV_STARTUP	0x600
326ae115bc7Smrj #define	AV_EXTINT	0x700
327ae115bc7Smrj 
328ae115bc7Smrj #define	AV_PDEST	0x000
329ae115bc7Smrj #define	AV_LDEST	0x800
330ae115bc7Smrj 
331ae115bc7Smrj /* IO & Local APIC Bit Definitions */
332ae115bc7Smrj #define	RDT_VECTOR(x)	((uchar_t)((x) & 0xFF))
333ae115bc7Smrj #define	AV_PENDING	0x1000
334ae115bc7Smrj #define	AV_ACTIVE_LOW	0x2000		/* only for integrated APIC */
335ae115bc7Smrj #define	AV_REMOTE_IRR   0x4000		/* IOAPIC RDT-specific */
336ae115bc7Smrj #define	AV_LEVEL	0x8000
337ae115bc7Smrj #define	AV_DEASSERT	AV_LEVEL
338ae115bc7Smrj #define	AV_ASSERT	0xc000
339ae115bc7Smrj 
340ae115bc7Smrj #define	AV_READ_PENDING	0x10000
341ae115bc7Smrj #define	AV_REMOTE_STATUS	0x20000	/* 1 = valid, 0 = invalid */
342ae115bc7Smrj 
343ae115bc7Smrj #define	AV_SH_SELF		0x40000	/* Short hand for self */
344ae115bc7Smrj #define	AV_SH_ALL_INCSELF	0x80000 /* All processors */
345ae115bc7Smrj #define	AV_SH_ALL_EXCSELF	0xc0000 /* All excluding self */
346ae115bc7Smrj /* spurious interrupt vector register					*/
347ae115bc7Smrj #define	AV_UNIT_ENABLE	0x100
348ae115bc7Smrj 
349ae115bc7Smrj #define	APIC_MAXVAL	0xffffffffUL
350ae115bc7Smrj #define	APIC_TIME_MIN	0x5000
351ae115bc7Smrj #define	APIC_TIME_COUNT	0x4000
352ae115bc7Smrj 
353ae115bc7Smrj /*
354ae115bc7Smrj  * Range of the low byte value in apic_tick before starting calibration
355ae115bc7Smrj  */
356ae115bc7Smrj #define	APIC_LB_MIN	0x60
357ae115bc7Smrj #define	APIC_LB_MAX	0xe0
358ae115bc7Smrj 
359ae115bc7Smrj #define	APIC_MAX_VECTOR		255
360ae115bc7Smrj #define	APIC_RESV_VECT		0x00
361ae115bc7Smrj #define	APIC_RESV_IRQ		0xfe
362ae115bc7Smrj #define	APIC_BASE_VECT		0x20	/* This will come in as interrupt 0 */
363ae115bc7Smrj #define	APIC_AVAIL_VECTOR	(APIC_MAX_VECTOR+1-APIC_BASE_VECT)
364ae115bc7Smrj #define	APIC_VECTOR_PER_IPL	0x10	/* # of vectors before PRI changes */
365ae115bc7Smrj #define	APIC_VECTOR(ipl)	(apic_ipltopri[ipl] | APIC_RESV_VECT)
366ae115bc7Smrj #define	APIC_VECTOR_MASK	0x0f
367ae115bc7Smrj #define	APIC_HI_PRI_VECTS	2	/* vects reserved for hi pri reqs */
368ae115bc7Smrj #define	APIC_IPL_MASK		0xf0
369ae115bc7Smrj #define	APIC_IPL_SHIFT		4	/* >> to get ipl part of vector */
370ae115bc7Smrj #define	APIC_FIRST_FREE_IRQ	0x10
371ae115bc7Smrj #define	APIC_MAX_ISA_IRQ	15
372ae115bc7Smrj #define	APIC_IPL0		0x0f	/* let IDLE_IPL be the lowest */
373ae115bc7Smrj #define	APIC_IDLE_IPL		0x00
374ae115bc7Smrj 
375ae115bc7Smrj #define	APIC_MASK_ALL		0xf0	/* Mask all interrupts */
376ae115bc7Smrj 
377ae115bc7Smrj /* spurious interrupt vector						*/
378ae115bc7Smrj #define	APIC_SPUR_INTR		0xFF
379ae115bc7Smrj 
380ae115bc7Smrj /* special or reserve vectors */
381ae115bc7Smrj #define	APIC_CHECK_RESERVE_VECTORS(v) \
382a7639048Sjohnny 	(((v) == T_FASTTRAP) || ((v) == APIC_SPUR_INTR) || \
383eb5a5c78SSurya Prakki 	((v) == T_SYSCALLINT) || ((v) == T_DTRACE_RET))
384ae115bc7Smrj 
385ae115bc7Smrj /* cmos shutdown code for BIOS						*/
386ae115bc7Smrj #define	BIOS_SHUTDOWN		0x0a
387ae115bc7Smrj 
388ae115bc7Smrj /* define the entry types for BIOS information tables as defined in PC+MP */
389ae115bc7Smrj #define	APIC_CPU_ENTRY		0
390ae115bc7Smrj #define	APIC_BUS_ENTRY		1
391ae115bc7Smrj #define	APIC_IO_ENTRY		2
392ae115bc7Smrj #define	APIC_IO_INTR_ENTRY	3
393ae115bc7Smrj #define	APIC_LOCAL_INTR_ENTRY	4
394ae115bc7Smrj #define	APIC_MPTBL_ADDR		(639 * 1024)
395ae115bc7Smrj /*
396ae115bc7Smrj  * The MP Floating Point structure could be in 1st 1KB of EBDA or last KB
397ae115bc7Smrj  * of system base memory or in ROM between 0xF0000 and 0xFFFFF
398ae115bc7Smrj  */
399ae115bc7Smrj #define	MPFPS_RAM_WIN_LEN	1024
400ae115bc7Smrj #define	MPFPS_ROM_WIN_START	(uint32_t)0xf0000
401ae115bc7Smrj #define	MPFPS_ROM_WIN_LEN	0x10000
402ae115bc7Smrj 
403ae115bc7Smrj #define	EISA_LEVEL_CNTL		0x4D0
404ae115bc7Smrj 
405ae115bc7Smrj /* definitions for apic_irq_table */
406ae115bc7Smrj #define	FREE_INDEX		(short)-1	/* empty slot */
407ae115bc7Smrj #define	RESERVE_INDEX		(short)-2	/* ipi, softintr, clkintr */
408ae115bc7Smrj #define	ACPI_INDEX		(short)-3	/* ACPI */
409ae115bc7Smrj #define	MSI_INDEX		(short)-4	/* MSI */
410ae115bc7Smrj #define	MSIX_INDEX		(short)-5	/* MSI-X */
411ae115bc7Smrj #define	DEFAULT_INDEX		(short)0x7FFF
412ae115bc7Smrj 	/* biggest positive no. to avoid conflict with actual index */
413ae115bc7Smrj 
414ae115bc7Smrj #define	APIC_IS_MSI_OR_MSIX_INDEX(index) \
415ae115bc7Smrj 	((index) == MSI_INDEX || (index) == MSIX_INDEX)
416ae115bc7Smrj 
417ae115bc7Smrj /*
418ae115bc7Smrj  * definitions for MSI Address
419ae115bc7Smrj  */
420ae115bc7Smrj #define	MSI_ADDR_HDR		APIC_LOCAL_ADDR
421ae115bc7Smrj #define	MSI_ADDR_DEST_SHIFT	12	/* Destination CPU's apic id */
422ae115bc7Smrj #define	MSI_ADDR_RH_FIXED	0x0	/* Redirection Hint Fixed */
423ae115bc7Smrj #define	MSI_ADDR_RH_LOPRI	0x1	/* Redirection Hint Lowest priority */
424ae115bc7Smrj #define	MSI_ADDR_RH_SHIFT	3
425ae115bc7Smrj #define	MSI_ADDR_DM_PHYSICAL	0x0	/* Physical Destination Mode */
426ae115bc7Smrj #define	MSI_ADDR_DM_LOGICAL	0x1	/* Logical Destination Mode */
427ae115bc7Smrj #define	MSI_ADDR_DM_SHIFT	2
428ae115bc7Smrj 
429ae115bc7Smrj /*
430e511d54dSSaurabh Misra  * TM is either edge or level.
431e511d54dSSaurabh Misra  */
432e511d54dSSaurabh Misra #define	TRIGGER_MODE_EDGE		0x0	/* edge sensitive */
433e511d54dSSaurabh Misra #define	TRIGGER_MODE_LEVEL		0x1	/* level sensitive */
434e511d54dSSaurabh Misra 
435e511d54dSSaurabh Misra /*
436ae115bc7Smrj  * definitions for MSI Data
437ae115bc7Smrj  */
438ae115bc7Smrj #define	MSI_DATA_DELIVERY_FIXED		0x0	/* Fixed delivery */
439ae115bc7Smrj #define	MSI_DATA_DELIVERY_LOPRI		0x1	/* Lowest priority delivery */
440ae115bc7Smrj #define	MSI_DATA_DELIVERY_SMI		0x2
441ae115bc7Smrj #define	MSI_DATA_DELIVERY_NMI		0x4
442ae115bc7Smrj #define	MSI_DATA_DELIVERY_INIT		0x5
443ae115bc7Smrj #define	MSI_DATA_DELIVERY_EXTINT	0x7
444ae115bc7Smrj #define	MSI_DATA_DELIVERY_SHIFT		8
445e511d54dSSaurabh Misra #define	MSI_DATA_TM_EDGE		TRIGGER_MODE_EDGE
446e511d54dSSaurabh Misra #define	MSI_DATA_TM_LEVEL		TRIGGER_MODE_LEVEL
447ae115bc7Smrj #define	MSI_DATA_TM_SHIFT		15
448ae115bc7Smrj #define	MSI_DATA_LEVEL_DEASSERT		0x0
449ae115bc7Smrj #define	MSI_DATA_LEVEL_ASSERT		0x1	/* Edge always assert */
450ae115bc7Smrj #define	MSI_DATA_LEVEL_SHIFT		14
451ae115bc7Smrj 
452ae115bc7Smrj /*
453ae115bc7Smrj  * use to define each irq setup by the apic
454ae115bc7Smrj  */
455ae115bc7Smrj typedef struct	apic_irq {
456ae115bc7Smrj 	short	airq_mps_intr_index;	/* index into mps interrupt entries */
457ae115bc7Smrj 					/*  table */
458ae115bc7Smrj 	uchar_t	airq_intin_no;
459ae115bc7Smrj 	uchar_t	airq_ioapicindex;
460ae115bc7Smrj 	dev_info_t	*airq_dip; /* device corresponding to this interrupt */
461ae115bc7Smrj 	/*
462ae115bc7Smrj 	 * IRQ could be shared (in H/W) in which case dip & major will be
463ae115bc7Smrj 	 * for the one that was last added at this level. We cannot keep a
464ae115bc7Smrj 	 * linked list as delspl does not tell us which device has just
465ae115bc7Smrj 	 * been unloaded. For most servers where we are worried about
466ae115bc7Smrj 	 * performance, interrupt should not be shared & should not be
467ae115bc7Smrj 	 * a problem. This does not cause any correctness issue - dip is
468ae115bc7Smrj 	 * used only as an optimisation to avoid going thru all the tables
469ae115bc7Smrj 	 * in translate IRQ (which is always called twice due to brokenness
470ae115bc7Smrj 	 * in the way IPLs are determined for devices). major is used only
471ae115bc7Smrj 	 * to bind interrupts corresponding to the same device on the same
472ae115bc7Smrj 	 * CPU. Not finding major will just cause it to be potentially bound
473ae115bc7Smrj 	 * to another CPU.
474ae115bc7Smrj 	 */
475ae115bc7Smrj 	major_t	airq_major;	/* major number corresponding to the device */
476ae115bc7Smrj 	ushort_t airq_rdt_entry;	/* level, polarity & trig mode */
4774e30c628SEvan Yan 	uint32_t airq_cpu;		/* target CPU, non-reserved IRQ only */
4784e30c628SEvan Yan 	uint32_t airq_temp_cpu;   /* non-reserved IRQ only, for disable_intr */
479ae115bc7Smrj 	uchar_t	airq_vector;		/* Vector chosen for this irq */
480ae115bc7Smrj 	uchar_t	airq_share;		/* number of interrupts at this irq */
481ae115bc7Smrj 	uchar_t	airq_share_id;		/* id to identify source from irqno */
482ae115bc7Smrj 	uchar_t	airq_ipl;		/* The ipl at which this is handled */
483ae115bc7Smrj 	iflag_t airq_iflag;		/* interrupt flag */
484ae115bc7Smrj 	uchar_t	airq_origirq;		/* original irq passed in */
485ae115bc7Smrj 	uint_t	airq_busy;		/* How frequently did clock find */
486ae115bc7Smrj 					/* us in this */
48786a9c507SGuoli Shu 	struct apic_irq *airq_next;	/* chain of intpts sharing a vector */
4883a634bfcSVikram Hegde 	void		*airq_intrmap_private; /* intr remap private data */
489ae115bc7Smrj } apic_irq_t;
490ae115bc7Smrj 
491b6917abeSmishra #define	IRQ_USER_BOUND	0x80000000 /* user requested bind if set in airq_cpu */
492b6917abeSmishra #define	IRQ_UNBOUND	(uint32_t)-1	/* set in airq_cpu and airq_temp_cpu */
493b6917abeSmishra #define	IRQ_UNINIT	(uint32_t)-2 /* in airq_temp_cpu till addspl called */
494ae115bc7Smrj 
495ae115bc7Smrj /* Macros to help deal with shared interrupts */
496ae115bc7Smrj #define	VIRTIRQ(irqno, share_id)	((irqno) | ((share_id) << 8))
497ae115bc7Smrj #define	IRQINDEX(irq)	((irq) & 0xFF)	/* Mask to get irq from virtual irq */
498ae115bc7Smrj 
49978a542e2SSaurabh Misra /*
50078a542e2SSaurabh Misra  * We align apic_cpus_info at 64-byte cache line boundary. Please make sure we
50178a542e2SSaurabh Misra  * adjust APIC_PADSZ as we add/modify any member of apic_cpus_info. We also
50278a542e2SSaurabh Misra  * don't want the compiler to optimize apic_cpus_info.
50378a542e2SSaurabh Misra  */
504a3114836SGerry Liu #define	APIC_PADSZ	15
50578a542e2SSaurabh Misra 
50678a542e2SSaurabh Misra #pragma	pack(1)
507ae115bc7Smrj typedef struct apic_cpus_info {
508b6917abeSmishra 	uint32_t aci_local_id;
509ae115bc7Smrj 	uchar_t	aci_local_ver;
510ae115bc7Smrj 	uchar_t	aci_status;
511ae115bc7Smrj 	uchar_t	aci_redistribute;	/* Selected for redistribution */
512ae115bc7Smrj 	uint_t	aci_busy;		/* Number of ticks we were in ISR */
513ae115bc7Smrj 	uint_t	aci_spur_cnt;		/* # of spurious intpts on this cpu */
514ae115bc7Smrj 	uint_t	aci_ISR_in_progress;	/* big enough to hold 1 << MAXIPL */
515ae115bc7Smrj 	uchar_t	aci_curipl;		/* IPL of current ISR */
516ae115bc7Smrj 	uchar_t	aci_current[MAXIPL];	/* Current IRQ at each IPL */
517ae115bc7Smrj 	uint32_t aci_bound;		/* # of user requested binds ? */
518ae115bc7Smrj 	uint32_t aci_temp_bound;	/* # of non user IRQ binds */
519a3114836SGerry Liu 	uint32_t aci_processor_id;	/* Only used in ACPI mode. */
520ae115bc7Smrj 	uchar_t	aci_idle;		/* The CPU is idle */
521ae115bc7Smrj 	/*
52278a542e2SSaurabh Misra 	 * Fill to make sure each struct is in separate 64-byte cache line.
523ae115bc7Smrj 	 */
52478a542e2SSaurabh Misra 	uchar_t	aci_pad[APIC_PADSZ];	/* padding for 64-byte cache line */
525ae115bc7Smrj } apic_cpus_info_t;
52678a542e2SSaurabh Misra #pragma	pack()
527ae115bc7Smrj 
5287ff178cdSJimmy Vetayases #define	APIC_CPU_ONLINE		0x1
5297ff178cdSJimmy Vetayases #define	APIC_CPU_INTR_ENABLE	0x2
5307ff178cdSJimmy Vetayases #define	APIC_CPU_FREE		0x4	/* APIC CPU slot is free */
5317ff178cdSJimmy Vetayases #define	APIC_CPU_DIRTY		0x8	/* Slot was once used */
5327ff178cdSJimmy Vetayases #define	APIC_CPU_SUSPEND	0x10
533ae115bc7Smrj 
534ae115bc7Smrj /*
535b6917abeSmishra  * APIC ops to support various flavors of APIC like APIC and x2APIC.
536b6917abeSmishra  */
537b6917abeSmishra typedef	struct apic_regs_ops {
538b6917abeSmishra 	uint64_t	(*apic_read)(uint32_t);
539b6917abeSmishra 	void 		(*apic_write)(uint32_t, uint64_t);
540b6917abeSmishra 	int		(*apic_get_pri)(void);
541b6917abeSmishra 	void		(*apic_write_task_reg)(uint64_t);
542b6917abeSmishra 	void		(*apic_write_int_cmd)(uint32_t, uint32_t);
543b6917abeSmishra 	void		(*apic_send_eoi)(uint32_t);
544b6917abeSmishra } apic_reg_ops_t;
545b6917abeSmishra 
546b6917abeSmishra /*
547bb8220baSVikram Hegde  * interrupt structure for ioapic and msi
548bb8220baSVikram Hegde  */
549bb8220baSVikram Hegde typedef struct ioapic_rdt {
550bb8220baSVikram Hegde 	uint32_t	ir_lo;
551bb8220baSVikram Hegde 	uint32_t	ir_hi;
552bb8220baSVikram Hegde } ioapic_rdt_t;
553bb8220baSVikram Hegde 
554bb8220baSVikram Hegde typedef struct msi_regs {
555bb8220baSVikram Hegde 	uint32_t	mr_data;
556bb8220baSVikram Hegde 	uint64_t	mr_addr;
557bb8220baSVikram Hegde }msi_regs_t;
558bb8220baSVikram Hegde 
559bb8220baSVikram Hegde /*
560bb8220baSVikram Hegde  * APIC ops to support intel interrupt remapping
561bb8220baSVikram Hegde  */
5623a634bfcSVikram Hegde typedef struct apic_intrmap_ops {
5633a634bfcSVikram Hegde 	int	(*apic_intrmap_init)(int);
5643a634bfcSVikram Hegde 	void	(*apic_intrmap_enable)(int);
5657ff178cdSJimmy Vetayases 	void	(*apic_intrmap_alloc_entry)(void **, dev_info_t *, uint16_t,
5667ff178cdSJimmy Vetayases 		    int, uchar_t);
5677ff178cdSJimmy Vetayases 	void	(*apic_intrmap_map_entry)(void *, void *, uint16_t, int);
5687ff178cdSJimmy Vetayases 	void	(*apic_intrmap_free_entry)(void **);
5697ff178cdSJimmy Vetayases 	void	(*apic_intrmap_record_rdt)(void *, ioapic_rdt_t *);
5707ff178cdSJimmy Vetayases 	void	(*apic_intrmap_record_msi)(void *, msi_regs_t *);
5713a634bfcSVikram Hegde } apic_intrmap_ops_t;
572bb8220baSVikram Hegde 
573bb8220baSVikram Hegde /*
574ae115bc7Smrj  * Various poweroff methods and ports & bits for them
575ae115bc7Smrj  */
576ae115bc7Smrj #define	APIC_POWEROFF_NONE		0
577ae115bc7Smrj #define	APIC_POWEROFF_VIA_RTC		1
578ae115bc7Smrj #define	APIC_POWEROFF_VIA_ASPEN_BMC	2
579ae115bc7Smrj #define	APIC_POWEROFF_VIA_SITKA_BMC	3
580ae115bc7Smrj 
581ae115bc7Smrj /* For RTC */
582ae115bc7Smrj #define	RTC_REGA		0x0a
583ae115bc7Smrj #define	PFR_REG			0x4a    /* extended control register */
584ae115bc7Smrj #define	PAB_CBIT		0x08
585ae115bc7Smrj #define	WF_FLAG			0x02
586ae115bc7Smrj #define	KS_FLAG			0x01
587ae115bc7Smrj #define	EXT_BANK		0x10
588ae115bc7Smrj 
589ae115bc7Smrj /* For Aspen/Drake BMC */
590ae115bc7Smrj 
591ae115bc7Smrj #define	CC_SMS_GET_STATUS	0x40
592ae115bc7Smrj #define	CC_SMS_WR_START		0x41
593ae115bc7Smrj #define	CC_SMS_WR_NEXT		0x42
594ae115bc7Smrj #define	CC_SMS_WR_END		0x43
595ae115bc7Smrj 
596ae115bc7Smrj #define	MISMIC_DATA_REGISTER	0x0ca9
597ae115bc7Smrj #define	MISMIC_CNTL_REGISTER	0x0caa
598ae115bc7Smrj #define	MISMIC_FLAG_REGISTER	0x0cab
599ae115bc7Smrj 
600ae115bc7Smrj #define	MISMIC_BUSY_MASK	0x01
601ae115bc7Smrj 
602ae115bc7Smrj /* For Sitka/Cabrillo BMC */
603ae115bc7Smrj 
604ae115bc7Smrj #define	SMS_GET_STATUS		0x60
605ae115bc7Smrj #define	SMS_WRITE_START		0x61
606ae115bc7Smrj #define	SMS_WRITE_END		0x62
607ae115bc7Smrj 
608ae115bc7Smrj #define	SMS_DATA_REGISTER	0x0ca2
609ae115bc7Smrj #define	SMS_STATUS_REGISTER	0x0ca3
610ae115bc7Smrj #define	SMS_COMMAND_REGISTER	0x0ca3
611ae115bc7Smrj 
612ae115bc7Smrj #define	SMS_IBF_MASK		0x02
613ae115bc7Smrj #define	SMS_STATE_MASK		0xc0
614ae115bc7Smrj 
615ae115bc7Smrj #define	SMS_IDLE_STATE		0x00
616ae115bc7Smrj #define	SMS_READ_STATE		0x40
617ae115bc7Smrj #define	SMS_WRITE_STATE		0x80
618ae115bc7Smrj #define	SMS_ERROR_STATE		0xc0
619ae115bc7Smrj 
620ae115bc7Smrj extern uint32_t ioapic_read(int ioapic_ix, uint32_t reg);
621ae115bc7Smrj extern void ioapic_write(int ioapic_ix, uint32_t reg, uint32_t value);
622b6917abeSmishra extern void ioapic_write_eoi(int ioapic_ix, uint32_t value);
623ae115bc7Smrj 
624ae115bc7Smrj /* Macros for reading/writing the IOAPIC RDT entries */
625ae115bc7Smrj #define	READ_IOAPIC_RDT_ENTRY_LOW_DWORD(ioapic_ix, ipin) \
626ae115bc7Smrj 	ioapic_read(ioapic_ix, APIC_RDT_CMD + (2 * (ipin)))
627ae115bc7Smrj 
628ae115bc7Smrj #define	READ_IOAPIC_RDT_ENTRY_HIGH_DWORD(ioapic_ix, ipin) \
629ae115bc7Smrj 	ioapic_read(ioapic_ix, APIC_RDT_CMD2 + (2 * (ipin)))
630ae115bc7Smrj 
631ae115bc7Smrj #define	WRITE_IOAPIC_RDT_ENTRY_LOW_DWORD(ioapic_ix, ipin, value) \
632ae115bc7Smrj 	ioapic_write(ioapic_ix, APIC_RDT_CMD + (2 * (ipin)), value)
633ae115bc7Smrj 
634ae115bc7Smrj #define	WRITE_IOAPIC_RDT_ENTRY_HIGH_DWORD(ioapic_ix, ipin, value) \
635ae115bc7Smrj 	ioapic_write(ioapic_ix, APIC_RDT_CMD2 + (2 * (ipin)), value)
636ae115bc7Smrj 
637ae115bc7Smrj /* Used by PSM_INTR_OP_GET_INTR to return device information. */
638ae115bc7Smrj typedef struct {
639ae115bc7Smrj 	uint16_t	avgi_req_flags;	/* request flags - to kernel */
640ae115bc7Smrj 	uint8_t		avgi_num_devs;	/* # devs on this ino - from kernel */
641ae115bc7Smrj 	uint8_t		avgi_vector;	/* vector */
642ae115bc7Smrj 	uint32_t	avgi_cpu_id;	/* cpu of interrupt - from kernel */
643ae115bc7Smrj 	dev_info_t	**avgi_dip_list; /* kmem_alloc'ed list of dev_infos. */
644ae115bc7Smrj 					/* Contains num_devs elements. */
645ae115bc7Smrj } apic_get_intr_t;
646ae115bc7Smrj 
6477ff178cdSJimmy Vetayases /* Used by PSM_INTR_OP_GET_TYPE to return platform information. */
6487ff178cdSJimmy Vetayases typedef struct {
6497ff178cdSJimmy Vetayases 	char		*avgi_type;	/*  platform type - from kernel */
6507ff178cdSJimmy Vetayases 	uint32_t	avgi_num_intr;	/*  max intr number - from kernel */
6517ff178cdSJimmy Vetayases 	uint32_t	avgi_num_cpu;	/*  max cpu number - from kernel */
6527ff178cdSJimmy Vetayases } apic_get_type_t;
6537ff178cdSJimmy Vetayases 
654ae115bc7Smrj /* Masks for avgi_req_flags. */
655ae115bc7Smrj #define	PSMGI_REQ_CPUID		0x1	/* Request CPU ID */
656ae115bc7Smrj #define	PSMGI_REQ_NUM_DEVS	0x2	/* Request num of devices on vector */
657ae115bc7Smrj #define	PSMGI_REQ_VECTOR	0x4
658ae115bc7Smrj #define	PSMGI_REQ_GET_DEVS	0x8	/* Request device list */
659ae115bc7Smrj #define	PSMGI_REQ_ALL		0xf	/* Request everything */
660ae115bc7Smrj 
661ae115bc7Smrj /* Other flags */
662ae115bc7Smrj #define	PSMGI_INTRBY_VEC	0	/* Vec passed.  xlate to IRQ needed */
663ae115bc7Smrj #define	PSMGI_INTRBY_IRQ	0x8000	/* IRQ passed.  no xlate needed */
6647ff178cdSJimmy Vetayases #define	PSMGI_INTRBY_DEFAULT	0x4000	/* PSM specific default value */
6657ff178cdSJimmy Vetayases #define	PSMGI_INTRBY_FLAGS	0xc000	/* Mask for this flag */
666ae115bc7Smrj 
667ae115bc7Smrj extern int	apic_verbose;
668ae115bc7Smrj 
669ae115bc7Smrj /* Flag definitions for apic_verbose */
670ae115bc7Smrj #define	APIC_VERBOSE_IOAPIC_FLAG		0x00000001
671ae115bc7Smrj #define	APIC_VERBOSE_IRQ_FLAG			0x00000002
672ae115bc7Smrj #define	APIC_VERBOSE_POWEROFF_FLAG		0x00000004
673ae115bc7Smrj #define	APIC_VERBOSE_POWEROFF_PAUSE_FLAG	0x00000008
6747ff178cdSJimmy Vetayases #define	APIC_VERBOSE_INIT			0x00000010
6757ff178cdSJimmy Vetayases #define	APIC_VERBOSE_REBIND			0x00000020
6767ff178cdSJimmy Vetayases #define	APIC_VERBOSE_ALLOC			0x00000040
6777ff178cdSJimmy Vetayases #define	APIC_VERBOSE_IPI			0x00000080
6787ff178cdSJimmy Vetayases #define	APIC_VERBOSE_INTR			0x00000100
679ae115bc7Smrj 
6807ff178cdSJimmy Vetayases /* required test to wait until APIC command is sent on the bus */
6815d8efbbcSSaurabh Misra #define	APIC_AV_PENDING_SET() \
6825d8efbbcSSaurabh Misra 	while (apic_reg_ops->apic_read(APIC_INT_CMD1) & AV_PENDING) \
6835d8efbbcSSaurabh Misra 		apic_ret();
6845d8efbbcSSaurabh Misra 
685ae115bc7Smrj #ifdef	DEBUG
6867ff178cdSJimmy Vetayases 
687ae115bc7Smrj #define	DENT		0x0001
688ae115bc7Smrj extern int	apic_debug;
689ae115bc7Smrj /*
690ae115bc7Smrj  * set apic_restrict_vector to the # of vectors we want to allow per range
691ae115bc7Smrj  * useful in testing shared interrupt logic by setting it to 2 or 3
692ae115bc7Smrj  */
693ae115bc7Smrj extern int	apic_restrict_vector;
694ae115bc7Smrj 
695ae115bc7Smrj #define	APIC_DEBUG_MSGBUFSIZE	2048
696ae115bc7Smrj extern int	apic_debug_msgbuf[];
697ae115bc7Smrj extern int	apic_debug_msgbufindex;
698ae115bc7Smrj 
699ae115bc7Smrj /*
700ae115bc7Smrj  * Put "int" info into debug buffer. No MP consistency, but light weight.
701ae115bc7Smrj  * Good enough for most debugging.
702ae115bc7Smrj  */
703ae115bc7Smrj #define	APIC_DEBUG_BUF_PUT(x) \
704ae115bc7Smrj 	apic_debug_msgbuf[apic_debug_msgbufindex++] = x; \
705ae115bc7Smrj 	if (apic_debug_msgbufindex >= (APIC_DEBUG_MSGBUFSIZE - NCPU)) \
706ae115bc7Smrj 		apic_debug_msgbufindex = 0;
707ae115bc7Smrj 
7087ff178cdSJimmy Vetayases #define	APIC_VERBOSE(flag, fmt)			     \
7097ff178cdSJimmy Vetayases 	if (apic_verbose & APIC_VERBOSE_##flag) \
7107ff178cdSJimmy Vetayases 		cmn_err fmt;
7117ff178cdSJimmy Vetayases 
7127ff178cdSJimmy Vetayases #define	APIC_VERBOSE_POWEROFF(fmt) \
7137ff178cdSJimmy Vetayases 	if (apic_verbose & APIC_VERBOSE_POWEROFF_FLAG) \
7147ff178cdSJimmy Vetayases 		prom_printf fmt;
7157ff178cdSJimmy Vetayases 
7167ff178cdSJimmy Vetayases #else	/* DEBUG */
7177ff178cdSJimmy Vetayases 
7187ff178cdSJimmy Vetayases #define	APIC_VERBOSE(flag, fmt)
7197ff178cdSJimmy Vetayases #define	APIC_VERBOSE_POWEROFF(fmt)
7207ff178cdSJimmy Vetayases 
721ae115bc7Smrj #endif	/* DEBUG */
722ae115bc7Smrj 
7237ff178cdSJimmy Vetayases #define	APIC_VERBOSE_IOAPIC(fmt)	APIC_VERBOSE(IOAPIC_FLAG, fmt)
7247ff178cdSJimmy Vetayases #define	APIC_VERBOSE_IRQ(fmt)		APIC_VERBOSE(IRQ_FLAG, fmt)
7257ff178cdSJimmy Vetayases 
726ae115bc7Smrj extern int	apic_error;
727ae115bc7Smrj /* values which apic_error can take. Not catastrophic, but may help debug */
728ae115bc7Smrj #define	APIC_ERR_BOOT_EOI		0x1
729ae115bc7Smrj #define	APIC_ERR_GET_IPIVECT_FAIL	0x2
730ae115bc7Smrj #define	APIC_ERR_INVALID_INDEX		0x4
731ae115bc7Smrj #define	APIC_ERR_MARK_VECTOR_FAIL	0x8
732ae115bc7Smrj #define	APIC_ERR_APIC_ERROR		0x40000000
733ae115bc7Smrj #define	APIC_ERR_NMI			0x80000000
734ae115bc7Smrj 
735ae115bc7Smrj /*
736ae115bc7Smrj  * ACPI definitions
737ae115bc7Smrj  */
738ae115bc7Smrj /* _PIC method arguments */
739ae115bc7Smrj #define	ACPI_PIC_MODE	0
740ae115bc7Smrj #define	ACPI_APIC_MODE	1
741ae115bc7Smrj 
742ae115bc7Smrj /* APIC error flags we care about */
743ae115bc7Smrj #define	APIC_SEND_CS_ERROR	0x01
744ae115bc7Smrj #define	APIC_RECV_CS_ERROR	0x02
745ae115bc7Smrj #define	APIC_CS_ERRORS		(APIC_SEND_CS_ERROR|APIC_RECV_CS_ERROR)
746ae115bc7Smrj 
747ae115bc7Smrj /* Maximum number of times to retry reprogramming at apic_intr_exit time */
748ae115bc7Smrj #define	APIC_REPROGRAM_MAX_TRIES 10000
749ae115bc7Smrj 
750ae115bc7Smrj /* Parameter to ioapic_init_intr(): Should ioapic ints be masked? */
751ae115bc7Smrj #define	IOAPIC_MASK 1
752ae115bc7Smrj #define	IOAPIC_NOMASK 0
753ae115bc7Smrj 
754ae115bc7Smrj #define	INTR_ROUND_ROBIN_WITH_AFFINITY	0
755ae115bc7Smrj #define	INTR_ROUND_ROBIN		1
756ae115bc7Smrj #define	INTR_LOWEST_PRIORITY		2
757ae115bc7Smrj 
758ae115bc7Smrj struct ioapic_reprogram_data {
759ae115bc7Smrj 	boolean_t			done;
760ae115bc7Smrj 	apic_irq_t			*irqp;
761ae115bc7Smrj 	/* The CPU to which the int will be bound */
762ae115bc7Smrj 	int				bindcpu;
763ae115bc7Smrj 	/* # times the reprogram timeout was called */
764ae115bc7Smrj 	unsigned			tries;
765ae115bc7Smrj };
766ae115bc7Smrj 
767ae115bc7Smrj /* The irq # is implicit in the array index: */
768ae115bc7Smrj extern struct ioapic_reprogram_data apic_reprogram_info[];
769ae115bc7Smrj 
770ae115bc7Smrj extern void apic_intr_exit(int ipl, int irq);
771b6917abeSmishra extern void x2apic_intr_exit(int ipl, int irq);
772ae115bc7Smrj extern int apic_probe_common();
773ae115bc7Smrj extern void apic_init_common();
774ae115bc7Smrj extern void ioapic_init_intr();
775ae115bc7Smrj extern void ioapic_disable_redirection();
776ae115bc7Smrj extern int apic_addspl_common(int irqno, int ipl, int min_ipl, int max_ipl);
777ae115bc7Smrj extern int apic_delspl_common(int irqno, int ipl, int min_ipl, int max_ipl);
778ae115bc7Smrj extern void apic_cleanup_busy();
779ae115bc7Smrj extern void apic_intr_redistribute();
780ae115bc7Smrj extern uchar_t apic_xlate_vector(uchar_t vector);
781ae115bc7Smrj extern uchar_t apic_allocate_vector(int ipl, int irq, int pri);
782ae115bc7Smrj extern void apic_free_vector(uchar_t vector);
783ae115bc7Smrj extern int apic_allocate_irq(int irq);
784b6917abeSmishra extern uint32_t apic_bind_intr(dev_info_t *dip, int irq, uchar_t ioapicid,
785ae115bc7Smrj     uchar_t intin);
786ae115bc7Smrj extern int apic_rebind(apic_irq_t *irq_ptr, int bind_cpu,
787ae115bc7Smrj     struct ioapic_reprogram_data *drep);
788ae115bc7Smrj extern int apic_rebind_all(apic_irq_t *irq_ptr, int bind_cpu);
789ae115bc7Smrj extern int apic_introp_xlate(dev_info_t *dip, struct intrspec *ispec, int type);
790ae115bc7Smrj extern int apic_intr_ops(dev_info_t *dip, ddi_intr_handle_impl_t *hdlp,
791ae115bc7Smrj     psm_intr_op_t intr_op, int *result);
7922df1fe9cSrandyf extern int apic_state(psm_state_request_t *);
793ae115bc7Smrj extern boolean_t apic_cpu_in_range(int cpu);
794ae115bc7Smrj extern int apic_check_msi_support();
795ae115bc7Smrj extern apic_irq_t *apic_find_irq(dev_info_t *dip, struct intrspec *ispec,
796ae115bc7Smrj     int type);
797ae115bc7Smrj extern int apic_navail_vector(dev_info_t *dip, int pri);
798a7639048Sjohnny extern int apic_alloc_msi_vectors(dev_info_t *dip, int inum, int count,
799a7639048Sjohnny     int pri, int behavior);
800a7639048Sjohnny extern int apic_alloc_msix_vectors(dev_info_t *dip, int inum, int count,
801a7639048Sjohnny     int pri, int behavior);
802ae115bc7Smrj extern void  apic_free_vectors(dev_info_t *dip, int inum, int count, int pri,
803ae115bc7Smrj     int type);
804843e1988Sjohnlev extern int apic_get_vector_intr_info(int vecirq,
805843e1988Sjohnlev     apic_get_intr_t *intr_params_p);
806ae115bc7Smrj extern uchar_t apic_find_multi_vectors(int pri, int count);
807ae115bc7Smrj extern int apic_setup_io_intr(void *p, int irq, boolean_t deferred);
808ae115bc7Smrj extern uint32_t *mapin_apic(uint32_t addr, size_t len, int flags);
809ae115bc7Smrj extern uint32_t *mapin_ioapic(uint32_t addr, size_t len, int flags);
810ae115bc7Smrj extern void mapout_apic(caddr_t addr, size_t len);
811ae115bc7Smrj extern void mapout_ioapic(caddr_t addr, size_t len);
812ae115bc7Smrj extern uchar_t apic_modify_vector(uchar_t vector, int irq);
813a7639048Sjohnny extern void apic_pci_msi_unconfigure(dev_info_t *rdip, int type, int inum);
814a7639048Sjohnny extern void apic_pci_msi_disable_mode(dev_info_t *rdip, int type);
815a7639048Sjohnny extern void apic_pci_msi_enable_mode(dev_info_t *rdip, int type, int inum);
816bb8220baSVikram Hegde extern void apic_pci_msi_enable_vector(apic_irq_t *, int type, int inum,
817a7639048Sjohnny     int vector, int count, int target_apic_id);
8182917a9c9Sschwartz extern char *apic_get_apic_type();
8192917a9c9Sschwartz extern uint16_t	apic_get_apic_version();
820b6917abeSmishra extern void x2apic_send_ipi();
821b6917abeSmishra extern void apic_ret();
822b6917abeSmishra extern int apic_detect_x2apic();
823b6917abeSmishra extern void apic_enable_x2apic();
824325e77f4SSaurabh Misra extern int apic_local_mode();
825b6917abeSmishra extern void apic_change_eoi();
826b6917abeSmishra extern void apic_send_EOI(uint32_t);
827b6917abeSmishra extern void apic_send_directed_EOI(uint32_t);
828*41afdfa7SKrishnendu Sadhukhan - Sun Microsystems extern uint_t apic_calibrate(volatile uint32_t *, uint16_t *);
829ae115bc7Smrj 
830ae115bc7Smrj extern volatile uint32_t *apicadr;	/* virtual addr of local APIC   */
831ae115bc7Smrj extern int apic_forceload;
832ae115bc7Smrj extern apic_cpus_info_t *apic_cpus;
833c8589f13Ssethg #ifdef _MACHDEP
834ae115bc7Smrj extern cpuset_t apic_cpumask;
835c8589f13Ssethg #endif
836843e1988Sjohnlev extern uint_t apic_picinit_called;
837ae115bc7Smrj extern uchar_t apic_ipltopri[MAXIPL+1];
838ae115bc7Smrj extern uchar_t apic_vector_to_irq[APIC_MAX_VECTOR+1];
839ae115bc7Smrj extern int apic_max_device_irq;
840ae115bc7Smrj extern int apic_min_device_irq;
841ae115bc7Smrj extern apic_irq_t *apic_irq_table[APIC_MAX_VECTOR+1];
842ae115bc7Smrj extern volatile uint32_t *apicioadr[MAX_IO_APIC];
843ae115bc7Smrj extern uchar_t apic_io_id[MAX_IO_APIC];
844ae115bc7Smrj extern lock_t apic_ioapic_lock;
845ae115bc7Smrj extern uint32_t apic_physaddr[MAX_IO_APIC];
846ae115bc7Smrj extern kmutex_t airq_mutex;
847ae115bc7Smrj extern int apic_first_avail_irq;
848ae115bc7Smrj extern uchar_t apic_vectortoipl[APIC_AVAIL_VECTOR / APIC_VECTOR_PER_IPL];
849ae115bc7Smrj extern int apic_imcrp;
850ae115bc7Smrj extern int apic_revector_pending;
851ae115bc7Smrj extern char apic_level_intr[APIC_MAX_VECTOR+1];
852ae115bc7Smrj extern uchar_t apic_resv_vector[MAXIPL+1];
853ae115bc7Smrj extern int apic_sample_factor_redistribution;
854ae115bc7Smrj extern int apic_int_busy_mark;
855ae115bc7Smrj extern int apic_int_free_mark;
856ae115bc7Smrj extern int apic_diff_for_redistribution;
857ae115bc7Smrj extern int apic_poweroff_method;
858ae115bc7Smrj extern int apic_enable_acpi;
859ae115bc7Smrj extern int apic_nproc;
860a3114836SGerry Liu extern int apic_max_nproc;
861ae115bc7Smrj extern int apic_next_bind_cpu;
862ae115bc7Smrj extern int apic_redistribute_sample_interval;
863ae115bc7Smrj extern int apic_multi_msi_enable;
864ae115bc7Smrj extern int apic_sci_vect;
8657ff178cdSJimmy Vetayases extern int apic_hpet_vect;
866c8589f13Ssethg extern uchar_t apic_ipls[];
867b6917abeSmishra extern apic_reg_ops_t *apic_reg_ops;
868b6917abeSmishra extern int apic_mode;
869b6917abeSmishra extern void x2apic_update_psm();
870325e77f4SSaurabh Misra extern void apic_change_ops();
871325e77f4SSaurabh Misra extern void apic_common_send_ipi(int, int);
872e511d54dSSaurabh Misra extern void apic_set_directed_EOI_handler();
873e511d54dSSaurabh Misra extern int apic_directed_EOI_supported();
874ae115bc7Smrj 
8753a634bfcSVikram Hegde extern apic_intrmap_ops_t *apic_vt_ops;
876ae115bc7Smrj 
877ae115bc7Smrj #ifdef	__cplusplus
878ae115bc7Smrj }
879ae115bc7Smrj #endif
880ae115bc7Smrj 
881ae115bc7Smrj #endif	/* _SYS_APIC_APIC_H */
882