smp.h revision 61136
1238730Sdelphij/*
2293190Sdelphij * ----------------------------------------------------------------------------
3238730Sdelphij * "THE BEER-WARE LICENSE" (Revision 42):
4238730Sdelphij * <phk@FreeBSD.org> wrote this file.  As long as you retain this notice you
5238730Sdelphij * can do whatever you want with this stuff. If we meet some day, and you think
6238730Sdelphij * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
7238730Sdelphij * ----------------------------------------------------------------------------
8238730Sdelphij *
989019Sps * $FreeBSD: head/sys/amd64/include/smp.h 61136 2000-05-31 21:37:28Z msmith $
1089019Sps *
1189019Sps */
1289019Sps
1389019Sps#ifndef _MACHINE_SMP_H_
1489019Sps#define _MACHINE_SMP_H_
1589019Sps
1689019Sps#ifdef _KERNEL
1789019Sps
1889019Sps#if defined(SMP) && !defined(APIC_IO)
1989019Sps# error APIC_IO required for SMP, add "options APIC_IO" to your config file.
2089019Sps#endif /* SMP && !APIC_IO */
2189019Sps
2289019Sps/* Number of CPUs. */
2389019Sps#if defined(SMP) && !defined(NCPU)
2489019Sps# define NCPU			2
2589019Sps#endif /* SMP && NCPU */
2689019Sps
2789019Sps/* Number of IO APICs. */
2889019Sps#if defined(APIC_IO) && !defined(NAPIC)
2989019Sps# define NAPIC			1
3089019Sps#endif /* SMP && NAPIC */
3189019Sps
3289019Sps
3389019Sps#if defined(SMP) || defined(APIC_IO)
3489019Sps
3589019Sps#ifndef LOCORE
3689019Sps
3789019Sps/*
3889019Sps * For sending values to POST displays.
3989019Sps * XXX FIXME: where does this really belong, isa.h/isa.c perhaps?
4089019Sps */
4189019Spsextern int current_postcode;  /** XXX currently in mp_machdep.c */
4289019Sps#define POSTCODE(X)	current_postcode = (X), \
4389019Sps			outb(0x80, current_postcode)
4489019Sps#define POSTCODE_LO(X)	current_postcode &= 0xf0, \
4589019Sps			current_postcode |= ((X) & 0x0f), \
4689019Sps			outb(0x80, current_postcode)
4789019Sps#define POSTCODE_HI(X)	current_postcode &= 0x0f, \
4889019Sps			current_postcode |= (((X) << 4) & 0xf0), \
4989019Sps			outb(0x80, current_postcode)
5089019Sps
5189019Sps
5289019Sps#include <machine/apic.h>
5389019Sps
5489019Sps/* global data in mpboot.s */
5589019Spsextern int			bootMP_size;
5689019Sps
5789019Sps/* functions in mpboot.s */
5889019Spsvoid	bootMP			__P((void));
5989019Sps
6089019Sps/* global data in mplock.s */
6189019Spsextern u_int			mp_lock;
6289019Spsextern u_int			isr_lock;
6389019Sps#ifdef RECURSIVE_MPINTRLOCK
6489019Spsextern u_int			mpintr_lock;
6589019Sps#endif /*  RECURSIVE_MPINTRLOCK */
6689019Sps
6789019Sps/* functions in mplock.s */
6889019Spsvoid	get_mplock		__P((void));
6989019Spsvoid	rel_mplock		__P((void));
7089019Spsint		try_mplock		__P((void));
7189019Sps#ifdef RECURSIVE_MPINTRLOCK
7289019Spsvoid	get_mpintrlock		__P((void));
7389019Spsvoid	rel_mpintrlock		__P((void));
7489019Spsint		try_mpintrlock		__P((void));
7589019Sps#endif /*  RECURSIVE_MPINTRLOCK */
7689019Sps
7789019Sps/* global data in apic_vector.s */
7889019Spsextern volatile u_int		stopped_cpus;
7989019Spsextern volatile u_int		started_cpus;
8089019Sps
8189019Spsextern volatile u_int		checkstate_probed_cpus;
8289019Spsextern volatile u_int		checkstate_need_ast;
8389019Spsextern volatile u_int		resched_cpus;
8489019Spsextern void (*cpustop_restartfunc) __P((void));
8589019Sps
8689019Sps/* functions in apic_ipl.s */
8789019Spsvoid	apic_eoi		__P((void));
8889019Spsu_int	io_apic_read		__P((int, int));
8989019Spsvoid	io_apic_write		__P((int, int, u_int));
9089019Sps
9189019Sps/* global data in mp_machdep.c */
9289019Spsextern int			bsp_apic_ready;
9389019Spsextern int			mp_ncpus;
9489019Spsextern int			mp_naps;
9589019Spsextern int			mp_nbusses;
9689019Spsextern int			mp_napics;
9789019Spsextern int			mp_picmode;
9889019Spsextern int			boot_cpu_id;
9989019Spsextern vm_offset_t		cpu_apic_address;
10089019Spsextern vm_offset_t		io_apic_address[];
10189019Spsextern u_int32_t		cpu_apic_versions[];
10289019Spsextern u_int32_t		io_apic_versions[];
10389019Spsextern int			cpu_num_to_apic_id[];
104extern int			io_num_to_apic_id[];
105extern int			apic_id_to_logical[];
106#define APIC_INTMAPSIZE 24
107struct apic_intmapinfo {
108  	int ioapic;
109	int int_pin;
110	volatile void *apic_address;
111	int redirindex;
112};
113extern struct apic_intmapinfo	int_to_apicintpin[];
114extern u_int			all_cpus;
115extern struct pcb		stoppcbs[];
116
117/* functions in mp_machdep.c */
118u_int	mp_bootaddress		__P((u_int));
119int	mp_probe		__P((void));
120void	mp_start		__P((void));
121void	mp_announce		__P((void));
122u_int	isa_apic_mask		__P((u_int));
123int	isa_apic_irq		__P((int));
124int	pci_apic_irq		__P((int, int, int));
125int	apic_irq		__P((int, int));
126int	next_apic_irq		__P((int));
127int	undirect_isa_irq	__P((int));
128int	undirect_pci_irq	__P((int));
129int	apic_bus_type		__P((int));
130int	apic_src_bus_id		__P((int, int));
131int	apic_src_bus_irq	__P((int, int));
132int	apic_int_type		__P((int, int));
133int	apic_trigger		__P((int, int));
134int	apic_polarity		__P((int, int));
135void	assign_apic_irq		__P((int apic, int intpin, int irq));
136void	revoke_apic_irq		__P((int irq));
137void	bsp_apic_configure	__P((void));
138void	init_secondary		__P((void));
139void	smp_invltlb		__P((void));
140int	stop_cpus		__P((u_int));
141int	restart_cpus		__P((u_int));
142#ifdef BETTER_CLOCK
143void	forward_statclock	__P((int pscnt));
144void	forward_hardclock	__P((int pscnt));
145#endif /* BETTER_CLOCK */
146void	forward_signal		__P((struct proc *));
147void	forward_roundrobin	__P((void));
148#ifdef	APIC_INTR_REORDER
149void	set_lapic_isrloc	__P((int, int));
150#endif /* APIC_INTR_REORDER */
151void	smp_rendezvous_action	__P((void));
152void	smp_rendezvous		__P((void (*)(void *),
153				     void (*)(void *),
154				     void (*)(void *),
155				     void *arg));
156
157/* global data in mpapic.c */
158extern volatile lapic_t		lapic;
159extern volatile ioapic_t	*ioapic[];
160
161/* functions in mpapic.c */
162void	apic_dump		__P((char*));
163void	apic_initialize		__P((void));
164void	imen_dump		__P((void));
165int	apic_ipi		__P((int, int, int));
166int	selected_apic_ipi	__P((u_int, int, int));
167int	io_apic_setup		__P((int));
168void	io_apic_set_id		__P((int, int));
169int	ext_int_setup		__P((int, int));
170
171#if defined(READY)
172void	clr_io_apic_mask24	__P((int, u_int32_t));
173void	set_io_apic_mask24	__P((int, u_int32_t));
174#endif /* READY */
175
176void	set_apic_timer		__P((int));
177int	read_apic_timer		__P((void));
178void	u_sleep			__P((int));
179
180/* global data in init_smp.c */
181extern int			invltlb_ok;
182extern int			smp_active;
183extern int			smp_started;
184extern volatile int		smp_idle_loops;
185
186#endif /* !LOCORE */
187#else	/* !SMP && !APIC_IO */
188
189/*
190 * Create dummy MP lock empties
191 */
192
193static __inline void
194get_mplock(void)
195{
196}
197
198static __inline void
199rel_mplock(void)
200{
201}
202
203#endif
204
205#endif /* _KERNEL */
206#endif /* _MACHINE_SMP_H_ */
207