xref: /minix3/sys/arch/x86/include/i82093var.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /* $NetBSD: i82093var.h,v 1.14 2015/04/27 07:03:58 knakahara Exp $ */
21cd76c75SBen Gras 
31cd76c75SBen Gras /*-
41cd76c75SBen Gras  * Copyright (c) 2000 The NetBSD Foundation, Inc.
51cd76c75SBen Gras  * All rights reserved.
61cd76c75SBen Gras  *
71cd76c75SBen Gras  * This code is derived from software contributed to The NetBSD Foundation
81cd76c75SBen Gras  * by RedBack Networks Inc.
91cd76c75SBen Gras  *
101cd76c75SBen Gras  * Author: Bill Sommerfeld
111cd76c75SBen Gras  *
121cd76c75SBen Gras  * Redistribution and use in source and binary forms, with or without
131cd76c75SBen Gras  * modification, are permitted provided that the following conditions
141cd76c75SBen Gras  * are met:
151cd76c75SBen Gras  * 1. Redistributions of source code must retain the above copyright
161cd76c75SBen Gras  *    notice, this list of conditions and the following disclaimer.
171cd76c75SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
181cd76c75SBen Gras  *    notice, this list of conditions and the following disclaimer in the
191cd76c75SBen Gras  *    documentation and/or other materials provided with the distribution.
201cd76c75SBen Gras  *
211cd76c75SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
221cd76c75SBen Gras  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
231cd76c75SBen Gras  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
241cd76c75SBen Gras  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
251cd76c75SBen Gras  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
261cd76c75SBen Gras  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
271cd76c75SBen Gras  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
281cd76c75SBen Gras  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
291cd76c75SBen Gras  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
301cd76c75SBen Gras  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
311cd76c75SBen Gras  * POSSIBILITY OF SUCH DAMAGE.
321cd76c75SBen Gras  */
331cd76c75SBen Gras 
341cd76c75SBen Gras #ifndef _X86_I82093VAR_H_
351cd76c75SBen Gras #define _X86_I82093VAR_H_
361cd76c75SBen Gras 
371cd76c75SBen Gras #include <sys/device.h>
381cd76c75SBen Gras #include <machine/apicvar.h>
391cd76c75SBen Gras 
401cd76c75SBen Gras struct ioapic_pin
411cd76c75SBen Gras {
421cd76c75SBen Gras 	struct ioapic_pin	*ip_next;	/* next pin on this vector */
431cd76c75SBen Gras 	struct mp_intr_map 	*ip_map;
441cd76c75SBen Gras 	int			ip_vector;	/* IDT vector */
451cd76c75SBen Gras 	int			ip_type;
461cd76c75SBen Gras 	struct cpu_info		*ip_cpu;	/* target CPU */
471cd76c75SBen Gras };
481cd76c75SBen Gras 
491cd76c75SBen Gras struct ioapic_softc {
501cd76c75SBen Gras 	device_t		sc_dev;
511cd76c75SBen Gras 	struct pic		sc_pic;
521cd76c75SBen Gras 	struct ioapic_softc	*sc_next;
531cd76c75SBen Gras 	int			sc_apicid;
541cd76c75SBen Gras 	int			sc_apic_vers;
551cd76c75SBen Gras 	int			sc_apic_vecbase; /* global int base if ACPI */
561cd76c75SBen Gras 	int			sc_apic_sz;	/* apic size*/
571cd76c75SBen Gras 	int			sc_flags;
581cd76c75SBen Gras 	paddr_t			sc_pa;		/* PA of ioapic */
591cd76c75SBen Gras 	volatile uint32_t	*sc_reg;	/* KVA of ioapic addr */
601cd76c75SBen Gras 	volatile uint32_t	*sc_data;	/* KVA of ioapic data */
611cd76c75SBen Gras 	struct ioapic_pin	*sc_pins;	/* sc_apic_sz entries */
621cd76c75SBen Gras };
631cd76c75SBen Gras 
641cd76c75SBen Gras /*
651cd76c75SBen Gras  * MP: intr_handle_t is bitfielded.
661cd76c75SBen Gras  * ih&0xff -> legacy irq number.
671cd76c75SBen Gras  * ih&0x10000000 -> if 0, old-style isa irq; if 1, routed via ioapic.
681cd76c75SBen Gras  * (ih&0xff0000)>>16 -> ioapic id.
691cd76c75SBen Gras  * (ih&0x00ff00)>>8 -> ioapic pin.
701cd76c75SBen Gras  *
71*0a6a1f1dSLionel Sambuc  * MSI/MSI-X:
72*0a6a1f1dSLionel Sambuc  * (ih&0x000ff80000000000)>>43 -> MSI/MSI-X device id.
73*0a6a1f1dSLionel Sambuc  * (ih&0x000007ff00000000)>>32 -> MSI/MSI-X vector id in a device.
741cd76c75SBen Gras  */
75*0a6a1f1dSLionel Sambuc #define	MPSAFE_MASK		0x80000000ULL
76*0a6a1f1dSLionel Sambuc #define APIC_INT_VIA_APIC	0x10000000ULL
77*0a6a1f1dSLionel Sambuc #define APIC_INT_VIA_MSI	0x20000000ULL
78*0a6a1f1dSLionel Sambuc #define APIC_INT_APIC_MASK	0x00ff0000ULL
791cd76c75SBen Gras #define APIC_INT_APIC_SHIFT	16
80*0a6a1f1dSLionel Sambuc #define APIC_INT_PIN_MASK	0x0000ff00ULL
811cd76c75SBen Gras #define APIC_INT_PIN_SHIFT	8
821cd76c75SBen Gras 
83*0a6a1f1dSLionel Sambuc #define APIC_IRQ_APIC(x) (int)(((x) & APIC_INT_APIC_MASK) >> APIC_INT_APIC_SHIFT)
84*0a6a1f1dSLionel Sambuc #define APIC_IRQ_PIN(x) (int)(((x) & APIC_INT_PIN_MASK) >> APIC_INT_PIN_SHIFT)
85*0a6a1f1dSLionel Sambuc #define APIC_IRQ_ISLEGACY(x) (bool)(!((x) & APIC_INT_VIA_APIC))
86*0a6a1f1dSLionel Sambuc #define APIC_IRQ_LEGACY_IRQ(x) (int)((x) & 0xff)
87*0a6a1f1dSLionel Sambuc 
88*0a6a1f1dSLionel Sambuc #define INT_VIA_MSI(x) (bool)(((x) & APIC_INT_VIA_MSI) != 0)
89*0a6a1f1dSLionel Sambuc 
90*0a6a1f1dSLionel Sambuc #define MSI_INT_MSIX		0x1000000000000000ULL
91*0a6a1f1dSLionel Sambuc #define MSI_INT_DEV_MASK	0x000ff80000000000ULL
92*0a6a1f1dSLionel Sambuc #define MSI_INT_VEC_MASK	0x000007ff00000000ULL
93*0a6a1f1dSLionel Sambuc 
94*0a6a1f1dSLionel Sambuc #define MSI_INT_IS_MSIX(x) (bool)((((x) & MSI_INT_MSIX) != 0))
95*0a6a1f1dSLionel Sambuc #define MSI_INT_MAKE_MSI(x) ((x) &= ~MSI_INT_MSIX)
96*0a6a1f1dSLionel Sambuc #define MSI_INT_MAKE_MSIX(x) ((x) |= MSI_INT_MSIX)
97*0a6a1f1dSLionel Sambuc #define MSI_INT_DEV(x) __SHIFTOUT((x), MSI_INT_DEV_MASK)
98*0a6a1f1dSLionel Sambuc #define MSI_INT_VEC(x) __SHIFTOUT((x), MSI_INT_VEC_MASK)
991cd76c75SBen Gras 
1001cd76c75SBen Gras void ioapic_print_redir(struct ioapic_softc *, const char *, int);
1011cd76c75SBen Gras void ioapic_format_redir(char *, const char *, int, uint32_t, uint32_t);
1021cd76c75SBen Gras struct ioapic_softc *ioapic_find(int);
1031cd76c75SBen Gras struct ioapic_softc *ioapic_find_bybase(int);
1041cd76c75SBen Gras 
1051cd76c75SBen Gras void ioapic_enable(void);
1061cd76c75SBen Gras void ioapic_reenable(void);
1071cd76c75SBen Gras 
1081cd76c75SBen Gras extern int nioapics;
1091cd76c75SBen Gras extern struct ioapic_softc *ioapics;
1101cd76c75SBen Gras 
1111cd76c75SBen Gras #endif /* !_X86_I82093VAR_H_ */
112