xref: /freebsd/sys/amd64/include/smp.h (revision 78292efeef6fe20911f07b09e626a12e9c12b234)
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  * $Id: smp.h,v 1.30 1997/08/26 18:10:37 peter Exp $
10  *
11  */
12 
13 #ifndef _MACHINE_SMP_H_
14 #define _MACHINE_SMP_H_
15 
16 #ifdef KERNEL
17 
18 #if defined(SMP) && !defined(APIC_IO)
19 # error APIC_IO required for SMP, add "options APIC_IO" to your config file.
20 #endif /* SMP && !APIC_IO */
21 
22 /* Number of CPUs. */
23 #if defined(SMP) && !defined(NCPU)
24 # define NCPU			2
25 #endif /* SMP && NCPU */
26 
27 /* Number of IO APICs. */
28 #if defined(APIC_IO) && !defined(NAPIC)
29 # define NAPIC			1
30 #endif /* SMP && NAPIC */
31 
32 
33 #if defined(SMP) || defined(APIC_IO)
34 
35 #ifndef LOCORE
36 
37 /*
38  * For sending values to POST displays.
39  * XXX FIXME: where does this really belong, isa.h/isa.c perhaps?
40  */
41 extern int current_postcode;  /** XXX currently in mp_machdep.c */
42 #define POSTCODE(X)	current_postcode = (X), \
43 			outb(0x80, current_postcode)
44 #define POSTCODE_LO(X)	current_postcode &= 0xf0, \
45 			current_postcode |= ((X) & 0x0f), \
46 			outb(0x80, current_postcode)
47 #define POSTCODE_HI(X)	current_postcode &= 0x0f, \
48 			current_postcode |= (((X) << 4) & 0xf0), \
49 			outb(0x80, current_postcode)
50 
51 
52 #include <machine/apic.h>
53 
54 /* global data in mpboot.s */
55 extern int			bootMP_size;
56 
57 /* functions in mpboot.s */
58 void	bootMP			__P((void));
59 
60 /* global data in mplock.s */
61 extern u_int			mp_lock;
62 extern u_int			isr_lock;
63 #ifdef RECURSIVE_MPINTRLOCK
64 extern u_int			mpintr_lock;
65 #endif /*  RECURSIVE_MPINTRLOCK */
66 
67 /* functions in mplock.s */
68 void	get_mplock		__P((void));
69 void	rel_mplock		__P((void));
70 void	try_mplock		__P((void));
71 #ifdef RECURSIVE_MPINTRLOCK
72 void	get_mpintrlock		__P((void));
73 void	rel_mpintrlock		__P((void));
74 void	try_mpintrlock		__P((void));
75 #endif /*  RECURSIVE_MPINTRLOCK */
76 
77 /* global data in apic_vector.s */
78 extern u_int			ivectors[];
79 extern volatile u_int		stopped_cpus;
80 extern volatile u_int		started_cpus;
81 
82 /* global data in apic_ipl.s */
83 extern u_int			vec[];
84 extern u_int			Xintr8254;
85 extern u_int			mask8254;
86 
87 /* functions in apic_ipl.s */
88 void	vec8254			__P((void));
89 void	INTREN			__P((u_int));
90 void	INTRDIS			__P((u_int));
91 void	apic_eoi		__P((void));
92 u_int	io_apic_read		__P((int, int));
93 void	io_apic_write		__P((int, int, u_int));
94 
95 /* global data in mp_machdep.c */
96 extern int			bsp_apic_ready;
97 extern int			mp_ncpus;
98 extern int			mp_naps;
99 extern int			mp_nbusses;
100 extern int			mp_napics;
101 extern int			mp_picmode;
102 extern int			boot_cpu_id;
103 extern vm_offset_t		cpu_apic_address;
104 extern vm_offset_t		io_apic_address[];
105 extern u_int32_t		cpu_apic_versions[];
106 extern u_int32_t		io_apic_versions[];
107 extern int			cpu_num_to_apic_id[];
108 extern int			io_num_to_apic_id[];
109 extern int			apic_id_to_logical[];
110 extern u_int			all_cpus;
111 extern u_char			SMP_ioapic[];
112 
113 /* functions in mp_machdep.c */
114 u_int	mp_bootaddress		__P((u_int));
115 int	mp_probe		__P((void));
116 void	mp_start		__P((void));
117 void	mp_announce		__P((void));
118 u_int	isa_apic_mask		__P((u_int));
119 int	isa_apic_pin		__P((int));
120 int	pci_apic_pin		__P((int, int, int));
121 int	undirect_isa_irq	__P((int));
122 int	undirect_pci_irq	__P((int));
123 int	apic_bus_type		__P((int));
124 int	apic_src_bus_id		__P((int, int));
125 int	apic_src_bus_irq	__P((int, int));
126 int	apic_int_type		__P((int, int));
127 int	apic_trigger		__P((int, int));
128 int	apic_polarity		__P((int, int));
129 void	bsp_apic_configure	__P((void));
130 void	init_secondary		__P((void));
131 void	smp_invltlb		__P((void));
132 int	stop_cpus		__P((u_int));
133 int	restart_cpus		__P((u_int));
134 
135 /* global data in mpapic.c */
136 extern volatile lapic_t		lapic;
137 
138 #if defined(MULTIPLE_IOAPICS)
139 #error MULTIPLE_IOAPICSXXX
140 #else
141 extern volatile ioapic_t	*ioapic[];
142 #endif /* MULTIPLE_IOAPICS */
143 
144 /* functions in mpapic.c */
145 void	apic_dump		__P((char*));
146 void	apic_initialize		__P((void));
147 void	imen_dump		__P((void));
148 int	apic_ipi		__P((int, int, int));
149 int	selected_apic_ipi	__P((u_int, int, int));
150 int	io_apic_setup		__P((int));
151 int	ext_int_setup		__P((int, int));
152 
153 #if defined(READY)
154 void	clr_io_apic_mask24	__P((int, u_int32_t));
155 void	set_io_apic_mask24	__P((int, u_int32_t));
156 #endif /* READY */
157 
158 void	set_apic_timer		__P((int));
159 int	read_apic_timer		__P((void));
160 void	u_sleep			__P((int));
161 
162 /* global data in init_smp.c */
163 extern int			invltlb_ok;
164 extern int			smp_active;
165 extern volatile int		smp_idle_loops;
166 
167 /* 'private' global data in locore.s */
168 extern volatile u_int		cpuid;
169 extern volatile u_int		cpu_lockid;
170 extern volatile u_int		other_cpus;
171 
172 #endif /* !LOCORE */
173 #endif /* SMP || APIC_IO */
174 #endif /* KERNEL */
175 #endif /* _MACHINE_SMP_H_ */
176