xref: /freebsd/sys/x86/include/x86_smp.h (revision 3b2324c3a800d7599f348c408f01908d0cef05a0)
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 /* global data in mp_x86.c */
27 extern int mp_naps;
28 extern int boot_cpu_id;
29 extern struct pcb stoppcbs[];
30 extern int cpu_apic_ids[];
31 extern int bootAP;
32 extern void *dpcpu;
33 extern char *bootSTK;
34 extern void *bootstacks[];
35 extern unsigned int boot_address;
36 extern unsigned int bootMP_size;
37 extern volatile u_int cpu_ipi_pending[];
38 extern volatile int aps_ready;
39 extern struct mtx ap_boot_mtx;
40 extern int cpu_logical;
41 extern int cpu_cores;
42 extern volatile uint32_t smp_tlb_generation;
43 extern struct pmap *smp_tlb_pmap;
44 extern vm_offset_t smp_tlb_addr1, smp_tlb_addr2;
45 extern u_int xhits_gbl[];
46 extern u_int xhits_pg[];
47 extern u_int xhits_rng[];
48 extern u_int ipi_global;
49 extern u_int ipi_page;
50 extern u_int ipi_range;
51 extern u_int ipi_range_size;
52 
53 extern int nmi_kdb_lock;
54 extern int nmi_is_broadcast;
55 
56 struct cpu_info {
57 	int	cpu_present:1;
58 	int	cpu_bsp:1;
59 	int	cpu_disabled:1;
60 	int	cpu_hyperthread:1;
61 };
62 extern struct cpu_info *cpu_info;
63 
64 /*
65  * Set if MWAIT does not reliably wake when the MONITORed address is written.
66  */
67 extern bool mwait_cpustop_broken;
68 
69 #ifdef COUNT_IPIS
70 extern u_long *ipi_invltlb_counts[MAXCPU];
71 extern u_long *ipi_invlrng_counts[MAXCPU];
72 extern u_long *ipi_invlpg_counts[MAXCPU];
73 extern u_long *ipi_invlcache_counts[MAXCPU];
74 extern u_long *ipi_rendezvous_counts[MAXCPU];
75 #endif
76 
77 /* IPI handlers */
78 inthand_t
79 	IDTVEC(invltlb),	/* TLB shootdowns - global */
80 	IDTVEC(invlpg),		/* TLB shootdowns - 1 page */
81 	IDTVEC(invlrng),	/* TLB shootdowns - page range */
82 	IDTVEC(invlcache),	/* Write back and invalidate cache */
83 	IDTVEC(ipi_intr_bitmap_handler), /* Bitmap based IPIs */
84 	IDTVEC(cpustop),	/* CPU stops & waits to be restarted */
85 	IDTVEC(cpususpend),	/* CPU suspends & waits to be resumed */
86 	IDTVEC(rendezvous);	/* handle CPU rendezvous */
87 
88 /* functions in x86_mp.c */
89 void	assign_cpu_ids(void);
90 void	cpu_add(u_int apic_id, char boot_cpu);
91 void	cpustop_handler(void);
92 void	cpususpend_handler(void);
93 void	alloc_ap_trampoline(vm_paddr_t *physmap, unsigned int *physmap_idx);
94 void	init_secondary_tail(void);
95 void	invltlb_handler(void);
96 void	invlpg_handler(void);
97 void	invlrng_handler(void);
98 void	invlcache_handler(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_selected(cpuset_t cpus, u_int ipi);
106 void	set_interrupt_apic_ids(void);
107 void	smp_cache_flush(void);
108 void	smp_masked_invlpg(cpuset_t mask, vm_offset_t addr, struct pmap *pmap);
109 void	smp_masked_invlpg_range(cpuset_t mask, vm_offset_t startva,
110 	    vm_offset_t endva, struct pmap *pmap);
111 void	smp_masked_invltlb(cpuset_t mask, struct pmap *pmap);
112 void	mem_range_AP_init(void);
113 void	topo_probe(void);
114 void	ipi_send_cpu(int cpu, u_int ipi);
115 
116 #endif
117