xref: /freebsd/sys/i386/include/smp.h (revision 7660b554bc59a07be0431c17e0e33815818baa69)
1 /*
2  * ----------------------------------------------------------------------------
3  * "THE BEER-WARE LICENSE" (Revision 42):
4  * <phk@FreeBSD.org> wrote this file.  As long as you retain this notice you
5  * can do whatever you want with this stuff. If we meet some day, and you think
6  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
7  * ----------------------------------------------------------------------------
8  *
9  * $FreeBSD$
10  *
11  */
12 
13 #ifndef _MACHINE_SMP_H_
14 #define _MACHINE_SMP_H_
15 
16 #ifdef _KERNEL
17 
18 #if defined(SMP) && defined(I386_CPU) && !defined(COMPILING_LINT)
19 #error SMP not supported with I386_CPU
20 #endif
21 #if defined(SMP) && !defined(APIC_IO)
22 # error APIC_IO required for SMP, add "options APIC_IO" to your config file.
23 #endif /* SMP && !APIC_IO */
24 #if defined(SMP) && defined(CPU_DISABLE_CMPXCHG) && !defined(COMPILING_LINT)
25 #error SMP not supported with CPU_DISABLE_CMPXCHG
26 #endif
27 
28 #if defined(SMP) || defined(APIC_IO)
29 
30 #ifndef LOCORE
31 
32 /*
33  * For sending values to POST displays.
34  * XXX FIXME: where does this really belong, isa.h/isa.c perhaps?
35  */
36 extern int current_postcode;  /** XXX currently in mp_machdep.c */
37 #define POSTCODE(X)	current_postcode = (X), \
38 			outb(0x80, current_postcode)
39 #define POSTCODE_LO(X)	current_postcode &= 0xf0, \
40 			current_postcode |= ((X) & 0x0f), \
41 			outb(0x80, current_postcode)
42 #define POSTCODE_HI(X)	current_postcode &= 0x0f, \
43 			current_postcode |= (((X) << 4) & 0xf0), \
44 			outb(0x80, current_postcode)
45 
46 
47 #include <sys/bus.h>	/* XXX */
48 #include <machine/apic.h>
49 #include <machine/frame.h>
50 #include <i386/isa/icu.h>
51 #include <i386/isa/intr_machdep.h>
52 
53 /*
54  * Interprocessor interrupts for SMP.
55  */
56 #define	IPI_INVLTLB		XINVLTLB_OFFSET
57 #define	IPI_INVLPG		XINVLPG_OFFSET
58 #define	IPI_INVLRNG		XINVLRNG_OFFSET
59 #define	IPI_LAZYPMAP		XLAZYPMAP_OFFSET
60 #define	IPI_RENDEZVOUS		XRENDEZVOUS_OFFSET
61 #define	IPI_AST			XCPUAST_OFFSET
62 #define	IPI_STOP		XCPUSTOP_OFFSET
63 #define	IPI_HARDCLOCK		XHARDCLOCK_OFFSET
64 #define	IPI_STATCLOCK		XSTATCLOCK_OFFSET
65 
66 /* global data in mpboot.s */
67 extern int			bootMP_size;
68 
69 /* functions in mpboot.s */
70 void	bootMP(void);
71 
72 /* global data in mp_machdep.c */
73 extern int			bsp_apic_ready;
74 extern int			mp_naps;
75 extern int			mp_nbusses;
76 extern int			mp_napics;
77 extern int			mp_picmode;
78 extern int			boot_cpu_id;
79 extern vm_offset_t		cpu_apic_address;
80 extern vm_offset_t		io_apic_address[];
81 extern u_int32_t		cpu_apic_versions[];
82 extern u_int32_t		*io_apic_versions;
83 extern int			cpu_num_to_apic_id[];
84 extern int			io_num_to_apic_id[];
85 extern int			apic_id_to_logical[];
86 #define APIC_INTMAPSIZE 32
87 struct apic_intmapinfo {
88   	int ioapic;
89 	int int_pin;
90 	volatile void *apic_address;
91 	int redirindex;
92 };
93 extern struct apic_intmapinfo	int_to_apicintpin[];
94 extern struct pcb		stoppcbs[];
95 
96 /* functions in mp_machdep.c */
97 void	i386_mp_probe(void);
98 u_int	mp_bootaddress(u_int);
99 u_int	isa_apic_mask(u_int);
100 int	isa_apic_irq(int);
101 int	pci_apic_irq(int, int, int);
102 int	apic_irq(int, int);
103 int	next_apic_irq(int);
104 int	undirect_isa_irq(int);
105 int	undirect_pci_irq(int);
106 int	apic_bus_type(int);
107 int	apic_src_bus_id(int, int);
108 int	apic_src_bus_irq(int, int);
109 int	apic_int_type(int, int);
110 int	apic_trigger(int, int);
111 int	apic_polarity(int, int);
112 int	mp_grab_cpu_hlt(void);
113 void	assign_apic_irq(int apic, int intpin, int irq);
114 void	revoke_apic_irq(int irq);
115 void	bsp_apic_configure(void);
116 void	init_secondary(void);
117 void	forward_statclock(void);
118 void	forwarded_statclock(struct clockframe frame);
119 void	forward_hardclock(void);
120 void	forwarded_hardclock(struct clockframe frame);
121 void	ipi_selected(u_int cpus, u_int ipi);
122 void	ipi_all(u_int ipi);
123 void	ipi_all_but_self(u_int ipi);
124 void	ipi_self(u_int ipi);
125 #ifdef	APIC_INTR_REORDER
126 void	set_lapic_isrloc(int, int);
127 #endif /* APIC_INTR_REORDER */
128 void	smp_invlpg(vm_offset_t addr);
129 void	smp_masked_invlpg(u_int mask, vm_offset_t addr);
130 void	smp_invlpg_range(vm_offset_t startva, vm_offset_t endva);
131 void	smp_masked_invlpg_range(u_int mask, vm_offset_t startva,
132 	    vm_offset_t endva);
133 void	smp_invltlb(void);
134 void	smp_masked_invltlb(u_int mask);
135 
136 /* global data in mpapic.c */
137 extern volatile lapic_t		lapic;
138 extern volatile ioapic_t	**ioapic;
139 
140 /* functions in mpapic.c */
141 void	apic_dump(char*);
142 void	apic_initialize(void);
143 void	imen_dump(void);
144 int	apic_ipi(int, int, int);
145 int	selected_apic_ipi(u_int, int, int);
146 int	io_apic_setup(int);
147 void	io_apic_setup_intpin(int, int);
148 void	io_apic_set_id(int, int);
149 int	io_apic_get_id(int);
150 int	ext_int_setup(int, int);
151 
152 void	set_apic_timer(int);
153 int	read_apic_timer(void);
154 void	u_sleep(int);
155 u_int	io_apic_read(int, int);
156 void	io_apic_write(int, int, u_int);
157 
158 #endif /* !LOCORE */
159 #endif /* SMP && !APIC_IO */
160 
161 #endif /* _KERNEL */
162 #endif /* _MACHINE_SMP_H_ */
163