xref: /freebsd/sys/arm64/include/pcpu.h (revision 6c03ba71f8eb3b7b9fe56d325a6a66123549aba5)
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  * $FreeBSD$
28412042e2SAndrew Turner  */
29412042e2SAndrew Turner 
30412042e2SAndrew Turner #ifndef	_MACHINE_PCPU_H_
31412042e2SAndrew Turner #define	_MACHINE_PCPU_H_
32412042e2SAndrew Turner 
33412042e2SAndrew Turner #include <machine/cpu.h>
34412042e2SAndrew Turner #include <machine/cpufunc.h>
35412042e2SAndrew Turner 
36412042e2SAndrew Turner #define	ALT_STACK_SIZE	128
37412042e2SAndrew Turner 
38412042e2SAndrew Turner #define	PCPU_MD_FIELDS							\
39617994efSAndrew Turner 	u_int	pc_acpi_id;	/* ACPI CPU id */		\
40*6c03ba71SZbigniew Bodek 	u_int	pc_midr;	/* stored MIDR value */	\
41*6c03ba71SZbigniew Bodek 	char __pad[121]
42412042e2SAndrew Turner 
43412042e2SAndrew Turner #ifdef _KERNEL
44412042e2SAndrew Turner 
45412042e2SAndrew Turner struct pcb;
46412042e2SAndrew Turner struct pcpu;
47412042e2SAndrew Turner 
48412042e2SAndrew Turner static inline struct pcpu *
49412042e2SAndrew Turner get_pcpu(void)
50412042e2SAndrew Turner {
51412042e2SAndrew Turner 	struct pcpu *pcpu;
52412042e2SAndrew Turner 
53412042e2SAndrew Turner 	__asm __volatile("mov	%0, x18" : "=&r"(pcpu));
54412042e2SAndrew Turner 	return (pcpu);
55412042e2SAndrew Turner }
56412042e2SAndrew Turner 
57412042e2SAndrew Turner static inline struct thread *
58412042e2SAndrew Turner get_curthread(void)
59412042e2SAndrew Turner {
60412042e2SAndrew Turner 	struct thread *td;
61412042e2SAndrew Turner 
62412042e2SAndrew Turner 	__asm __volatile("ldr	%0, [x18]" : "=&r"(td));
63412042e2SAndrew Turner 	return (td);
64412042e2SAndrew Turner }
65412042e2SAndrew Turner 
66412042e2SAndrew Turner #define	curthread get_curthread()
67412042e2SAndrew Turner 
68412042e2SAndrew Turner #define	PCPU_GET(member)	(get_pcpu()->pc_ ## member)
69412042e2SAndrew Turner #define	PCPU_ADD(member, value)	(get_pcpu()->pc_ ## member += (value))
70412042e2SAndrew Turner #define	PCPU_INC(member)	PCPU_ADD(member, 1)
71412042e2SAndrew Turner #define	PCPU_PTR(member)	(&get_pcpu()->pc_ ## member)
72412042e2SAndrew Turner #define	PCPU_SET(member,value)	(get_pcpu()->pc_ ## member = (value))
73412042e2SAndrew Turner 
74412042e2SAndrew Turner #endif	/* _KERNEL */
75412042e2SAndrew Turner 
76412042e2SAndrew Turner #endif	/* !_MACHINE_PCPU_H_ */
77