pcpu.h revision 284265
1129198Scognet/*-
2129198Scognet * Copyright (c) 1999 Luoqi Chen <luoqi@freebsd.org>
3129198Scognet * All rights reserved.
4129198Scognet *
5129198Scognet * Redistribution and use in source and binary forms, with or without
6129198Scognet * modification, are permitted provided that the following conditions
7129198Scognet * are met:
8129198Scognet * 1. Redistributions of source code must retain the above copyright
9129198Scognet *    notice, this list of conditions and the following disclaimer.
10129198Scognet * 2. Redistributions in binary form must reproduce the above copyright
11129198Scognet *    notice, this list of conditions and the following disclaimer in the
12129198Scognet *    documentation and/or other materials provided with the distribution.
13129198Scognet *
14129198Scognet * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15129198Scognet * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16129198Scognet * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17129198Scognet * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18129198Scognet * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19129198Scognet * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20129198Scognet * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21129198Scognet * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22129198Scognet * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23129198Scognet * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24129198Scognet * SUCH DAMAGE.
25129198Scognet *
26129198Scognet *	from: FreeBSD: src/sys/i386/include/globaldata.h,v 1.27 2001/04/27
27129198Scognet * $FreeBSD: head/sys/arm/include/pcpu.h 284265 2015-06-11 13:58:40Z andrew $
28129198Scognet */
29129198Scognet
30129198Scognet#ifndef	_MACHINE_PCPU_H_
31129198Scognet#define	_MACHINE_PCPU_H_
32129198Scognet
33129198Scognet#ifdef _KERNEL
34129198Scognet
35284265Sandrew#include <machine/acle-compat.h>
36239268Sgonzo#include <machine/cpuconf.h>
37129198Scognet
38129198Scognet#define	ALT_STACK_SIZE	128
39129198Scognet
40129198Scognetstruct vmspace;
41129198Scognet
42181875Sjhb#endif	/* _KERNEL */
43181875Sjhb
44284265Sandrew#if __ARM_ARCH >= 6
45239268Sgonzo#define PCPU_MD_FIELDS							\
46239268Sgonzo	unsigned int pc_vfpsid;						\
47239268Sgonzo	unsigned int pc_vfpmvfr0;					\
48239268Sgonzo	unsigned int pc_vfpmvfr1;					\
49249265Sglebius	struct pmap *pc_curpmap;					\
50284109Sandrew	char __pad[141]
51239268Sgonzo#else
52249265Sglebius#define PCPU_MD_FIELDS							\
53249265Sglebius	char __pad[157]
54239268Sgonzo#endif
55129198Scognet
56181875Sjhb#ifdef _KERNEL
57181875Sjhb
58129198Scognetstruct pcb;
59129198Scognetstruct pcpu;
60129198Scognet
61129198Scognetextern struct pcpu *pcpup;
62261415Scognet
63284265Sandrew#if __ARM_ARCH >= 6
64261415Scognet#define CPU_MASK (0xf)
65261415Scognet
66261419Scognet#ifndef SMP
67261419Scognet#define get_pcpu() (pcpup)
68261419Scognet#else
69261415Scognet#define get_pcpu() __extension__ ({			  		\
70261415Scognet    	int id;								\
71261415Scognet        __asm __volatile("mrc p15, 0, %0, c0, c0, 5" : "=r" (id));	\
72261415Scognet    	(pcpup + (id & CPU_MASK));					\
73261415Scognet    })
74261419Scognet#endif
75261415Scognet
76261415Scognetstatic inline struct thread *
77261415Scognetget_curthread(void)
78239268Sgonzo{
79261415Scognet	void *ret;
80129198Scognet
81261415Scognet	__asm __volatile("mrc p15, 0, %0, c13, c0, 4" : "=r" (ret));
82261415Scognet	return (ret);
83239268Sgonzo}
84167429Salc
85239268Sgonzostatic inline void
86261415Scognetset_curthread(struct thread *td)
87239268Sgonzo{
88239268Sgonzo
89261415Scognet	__asm __volatile("mcr p15, 0, %0, c13, c0, 4" : : "r" (td));
90239268Sgonzo}
91239268Sgonzo
92261415Scognet
93239268Sgonzostatic inline void *
94239268Sgonzoget_tls(void)
95239268Sgonzo{
96239268Sgonzo	void *tls;
97239268Sgonzo
98239268Sgonzo	__asm __volatile("mrc p15, 0, %0, c13, c0, 3" : "=r" (tls));
99239268Sgonzo	return (tls);
100239268Sgonzo}
101239268Sgonzo
102239268Sgonzostatic inline void
103239268Sgonzoset_tls(void *tls)
104239268Sgonzo{
105239268Sgonzo
106239268Sgonzo	__asm __volatile("mcr p15, 0, %0, c13, c0, 3" : : "r" (tls));
107239268Sgonzo}
108261415Scognet
109261415Scognet#define curthread get_curthread()
110261415Scognet
111239268Sgonzo#else
112239268Sgonzo#define get_pcpu()	pcpup
113239268Sgonzo#endif
114239268Sgonzo
115239268Sgonzo#define	PCPU_GET(member)	(get_pcpu()->pc_ ## member)
116239268Sgonzo#define	PCPU_ADD(member, value)	(get_pcpu()->pc_ ## member += (value))
117170388Sjeff#define	PCPU_INC(member)	PCPU_ADD(member, 1)
118245202Scognet#define	PCPU_PTR(member)	(&get_pcpu()->pc_ ## member)
119245202Scognet#define	PCPU_SET(member,value)	(get_pcpu()->pc_ ## member = (value))
120129198Scognet
121239268Sgonzovoid pcpu0_init(void);
122129198Scognet#endif	/* _KERNEL */
123129198Scognet
124129198Scognet#endif	/* !_MACHINE_PCPU_H_ */
125