xref: /freebsd/sys/arm64/include/pcpu.h (revision d5aead83dfa8859ad8e12b8b782545c75fecb9b1)
1412042e2SAndrew Turner /*-
2412042e2SAndrew Turner  * Copyright (c) 1999 Luoqi Chen <luoqi@freebsd.org>
3412042e2SAndrew Turner  * All rights reserved.
4412042e2SAndrew Turner  *
5412042e2SAndrew Turner  * Redistribution and use in source and binary forms, with or without
6412042e2SAndrew Turner  * modification, are permitted provided that the following conditions
7412042e2SAndrew Turner  * are met:
8412042e2SAndrew Turner  * 1. Redistributions of source code must retain the above copyright
9412042e2SAndrew Turner  *    notice, this list of conditions and the following disclaimer.
10412042e2SAndrew Turner  * 2. Redistributions in binary form must reproduce the above copyright
11412042e2SAndrew Turner  *    notice, this list of conditions and the following disclaimer in the
12412042e2SAndrew Turner  *    documentation and/or other materials provided with the distribution.
13412042e2SAndrew Turner  *
14412042e2SAndrew Turner  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15412042e2SAndrew Turner  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16412042e2SAndrew Turner  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17412042e2SAndrew Turner  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18412042e2SAndrew Turner  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19412042e2SAndrew Turner  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20412042e2SAndrew Turner  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21412042e2SAndrew Turner  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22412042e2SAndrew Turner  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23412042e2SAndrew Turner  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24412042e2SAndrew Turner  * SUCH DAMAGE.
25412042e2SAndrew Turner  *
26412042e2SAndrew Turner  *	from: FreeBSD: src/sys/i386/include/globaldata.h,v 1.27 2001/04/27
27412042e2SAndrew Turner  */
28412042e2SAndrew Turner 
29*d5d97bedSMike Karels #ifdef __arm__
30*d5d97bedSMike Karels #include <arm/pcpu.h>
31*d5d97bedSMike Karels #else /* !__arm__ */
32*d5d97bedSMike Karels 
33412042e2SAndrew Turner #ifndef	_MACHINE_PCPU_H_
34412042e2SAndrew Turner #define	_MACHINE_PCPU_H_
35412042e2SAndrew Turner 
36412042e2SAndrew Turner #include <machine/cpu.h>
37412042e2SAndrew Turner #include <machine/cpufunc.h>
38412042e2SAndrew Turner 
397023544aSAndrew Turner typedef int (*pcpu_bp_harden)(void);
40100a6d19SAndrew Turner typedef int (*pcpu_ssbd)(int);
41a5d295e2SAndrew Turner struct debug_monitor_state;
427023544aSAndrew Turner 
43412042e2SAndrew Turner #define	PCPU_MD_FIELDS							\
44617994efSAndrew Turner 	u_int	pc_acpi_id;	/* ACPI CPU id */			\
456c03ba71SZbigniew Bodek 	u_int	pc_midr;	/* stored MIDR value */			\
46af693689SAndrew Turner 	uint64_t pc_clock;						\
477023544aSAndrew Turner 	pcpu_bp_harden pc_bp_harden;					\
480594061eSAndrew Turner 	pcpu_ssbd pc_ssbd;						\
4950e3ab6bSAlan Cox 	struct pmap *pc_curpmap;					\
502cb0e95fSAndrew Turner 	struct pmap *pc_curvmpmap;					\
51078a69abSAndrew Turner 	uint64_t pc_mpidr;						\
52078a69abSAndrew Turner 	u_int	pc_bcast_tlbi_workaround;				\
53544f047fSAndrew Turner 	char __pad[197]
54412042e2SAndrew Turner 
55412042e2SAndrew Turner #ifdef _KERNEL
56412042e2SAndrew Turner 
57412042e2SAndrew Turner struct pcb;
58412042e2SAndrew Turner struct pcpu;
59412042e2SAndrew Turner 
6063c858a0SAndrew Turner register struct pcpu *pcpup __asm ("x18");
61412042e2SAndrew Turner 
62ed306634SAndrew Turner static inline struct pcpu *
get_pcpu(void)63ed306634SAndrew Turner get_pcpu(void)
64ed306634SAndrew Turner {
65ed306634SAndrew Turner 	struct pcpu *pcpu;
66ed306634SAndrew Turner 
67ed306634SAndrew Turner 	__asm __volatile("mov   %0, x18" : "=&r"(pcpu));
68ed306634SAndrew Turner 	return (pcpu);
69ed306634SAndrew Turner }
70412042e2SAndrew Turner 
71412042e2SAndrew Turner static inline struct thread *
get_curthread(void)72412042e2SAndrew Turner get_curthread(void)
73412042e2SAndrew Turner {
74412042e2SAndrew Turner 	struct thread *td;
75412042e2SAndrew Turner 
76412042e2SAndrew Turner 	__asm __volatile("ldr	%0, [x18]" : "=&r"(td));
77412042e2SAndrew Turner 	return (td);
78412042e2SAndrew Turner }
79412042e2SAndrew Turner 
80412042e2SAndrew Turner #define	curthread get_curthread()
81412042e2SAndrew Turner 
8263c858a0SAndrew Turner #define	PCPU_GET(member)	(pcpup->pc_ ## member)
8363c858a0SAndrew Turner #define	PCPU_ADD(member, value)	(pcpup->pc_ ## member += (value))
8463c858a0SAndrew Turner #define	PCPU_PTR(member)	(&pcpup->pc_ ## member)
8563c858a0SAndrew Turner #define	PCPU_SET(member,value)	(pcpup->pc_ ## member = (value))
86412042e2SAndrew Turner 
87078a69abSAndrew Turner #define	PCPU_GET_MPIDR(pc)	((pc)->pc_mpidr)
88544f047fSAndrew Turner 
89412042e2SAndrew Turner #endif	/* _KERNEL */
90412042e2SAndrew Turner 
91412042e2SAndrew Turner #endif	/* !_MACHINE_PCPU_H_ */
92*d5d97bedSMike Karels 
93*d5d97bedSMike Karels #endif /* !__arm__ */
94