xref: /freebsd/sys/x86/include/x86_smp.h (revision 7ef62cebc2f965b0f640263e179276928885e33d)
1 /*-
2  * SPDX-License-Identifier: Beerware
3  *
4  * ----------------------------------------------------------------------------
5  * "THE BEER-WARE LICENSE" (Revision 42):
6  * <phk@FreeBSD.org> wrote this file.  As long as you retain this notice you
7  * can do whatever you want with this stuff. If we meet some day, and you think
8  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
9  * ----------------------------------------------------------------------------
10  *
11  * $FreeBSD$
12  *
13  */
14 
15 #ifndef _X86_X86_SMP_H_
16 #define	_X86_X86_SMP_H_
17 
18 #include <sys/bus.h>
19 #include <machine/frame.h>
20 #include <machine/intr_machdep.h>
21 #include <x86/apicvar.h>
22 #include <machine/pcb.h>
23 
24 struct pmap;
25 
26 #ifdef __i386__
27 extern unsigned int boot_address;
28 #endif
29 
30 /* global data in mp_x86.c */
31 extern int mp_naps;
32 extern int boot_cpu_id;
33 extern int cpu_apic_ids[];
34 extern int bootAP;
35 extern void *dpcpu;
36 extern char *bootSTK;
37 extern void *bootstacks[];
38 extern unsigned int bootMP_size;
39 extern volatile int aps_ready;
40 extern struct mtx ap_boot_mtx;
41 extern int cpu_logical;
42 extern int cpu_cores;
43 extern volatile uint32_t smp_tlb_generation;
44 extern struct pmap *smp_tlb_pmap;
45 extern vm_offset_t smp_tlb_addr1, smp_tlb_addr2;
46 extern u_int xhits_gbl[];
47 extern u_int xhits_pg[];
48 extern u_int xhits_rng[];
49 extern u_int ipi_global;
50 extern u_int ipi_page;
51 extern u_int ipi_range;
52 extern u_int ipi_range_size;
53 
54 extern int nmi_kdb_lock;
55 extern int nmi_is_broadcast;
56 
57 struct cpu_info {
58 	bool	cpu_present:1;
59 	bool	cpu_bsp:1;
60 	bool	cpu_disabled:1;
61 	bool	cpu_hyperthread:1;
62 };
63 extern struct cpu_info *cpu_info;
64 
65 /*
66  * Set if MWAIT does not reliably wake when the MONITORed address is written.
67  */
68 extern bool mwait_cpustop_broken;
69 
70 #ifdef COUNT_IPIS
71 extern u_long *ipi_invltlb_counts[MAXCPU];
72 extern u_long *ipi_invlrng_counts[MAXCPU];
73 extern u_long *ipi_invlpg_counts[MAXCPU];
74 extern u_long *ipi_invlcache_counts[MAXCPU];
75 extern u_long *ipi_rendezvous_counts[MAXCPU];
76 #endif
77 
78 /* IPI handlers */
79 inthand_t
80 	IDTVEC(ipi_intr_bitmap_handler), /* Bitmap based IPIs */
81 	IDTVEC(ipi_swi),	/* Runs delayed SWI */
82 	IDTVEC(cpustop),	/* CPU stops & waits to be restarted */
83 	IDTVEC(cpususpend),	/* CPU suspends & waits to be resumed */
84 	IDTVEC(rendezvous);	/* handle CPU rendezvous */
85 
86 typedef void (*smp_invl_cb_t)(struct pmap *, vm_offset_t addr1,
87     vm_offset_t addr2);
88 
89 #ifdef __i386__
90 void	alloc_ap_trampoline(vm_paddr_t *physmap, unsigned int *physmap_idx);
91 #endif
92 
93 /* functions in x86_mp.c */
94 void	assign_cpu_ids(void);
95 void	cpu_add(u_int apic_id, char boot_cpu);
96 void	cpustop_handler(void);
97 void	cpususpend_handler(void);
98 void	init_secondary_tail(void);
99 void	init_secondary(void);
100 void	ipi_startup(int apic_id, int vector);
101 void	ipi_all_but_self(u_int ipi);
102 void 	ipi_bitmap_handler(struct trapframe frame);
103 void	ipi_cpu(int cpu, u_int ipi);
104 int	ipi_nmi_handler(void);
105 void	ipi_swi_handler(struct trapframe frame);
106 void	ipi_selected(cpuset_t cpus, u_int ipi);
107 void	ipi_self_from_nmi(u_int vector);
108 void	set_interrupt_apic_ids(void);
109 void	mem_range_AP_init(void);
110 void	topo_probe(void);
111 
112 /* functions in mp_machdep.c */
113 void	smp_cache_flush(smp_invl_cb_t curcpu_cb);
114 #ifdef __i386__
115 void	smp_masked_invlpg(cpuset_t mask, vm_offset_t addr, struct pmap *pmap,
116 	    smp_invl_cb_t curcpu_cb);
117 void	smp_masked_invlpg_range(cpuset_t mask, vm_offset_t startva,
118 	    vm_offset_t endva, struct pmap *pmap, smp_invl_cb_t curcpu_cb);
119 void	smp_masked_invltlb(cpuset_t mask, struct pmap *pmap,
120 	    smp_invl_cb_t curcpu_cb);
121 #else
122 void	smp_masked_invlpg(vm_offset_t addr, struct pmap *pmap,
123 	    smp_invl_cb_t curcpu_cb);
124 void	smp_masked_invlpg_range(vm_offset_t startva, vm_offset_t endva,
125 	    struct pmap *pmap, smp_invl_cb_t curcpu_cb);
126 void	smp_masked_invltlb(struct pmap *pmap, smp_invl_cb_t curcpu_cb);
127 #endif
128 #endif
129