180708Sjake/*-
281763Sobrien * Copyright (c) 1999 Luoqi Chen <luoqi@freebsd.org>
380708Sjake * All rights reserved.
480708Sjake *
580708Sjake * Redistribution and use in source and binary forms, with or without
680708Sjake * modification, are permitted provided that the following conditions
780708Sjake * are met:
880708Sjake * 1. Redistributions of source code must retain the above copyright
980708Sjake *    notice, this list of conditions and the following disclaimer.
1080708Sjake * 2. Redistributions in binary form must reproduce the above copyright
1180708Sjake *    notice, this list of conditions and the following disclaimer in the
1280708Sjake *    documentation and/or other materials provided with the distribution.
1380708Sjake *
1481334Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1580708Sjake * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1680708Sjake * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1781334Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1880708Sjake * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1980708Sjake * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2080708Sjake * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2180708Sjake * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2280708Sjake * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2380708Sjake * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2480708Sjake * SUCH DAMAGE.
2580708Sjake *
2682905Sjake *	from: FreeBSD: src/sys/i386/include/globaldata.h,v 1.27 2001/04/27
2780708Sjake * $FreeBSD: releng/11.0/sys/sparc64/include/pcpu.h 286296 2015-08-04 19:46:13Z jah $
2880708Sjake */
2980708Sjake
3087702Sjhb#ifndef	_MACHINE_PCPU_H_
3187702Sjhb#define	_MACHINE_PCPU_H_
3280708Sjake
3389035Sjake#include <machine/asmacros.h>
34182689Smarius#include <machine/cache.h>
3585232Sjake#include <machine/frame.h>
3685232Sjake#include <machine/intr_machdep.h>
3785232Sjake
3882905Sjake#define	ALT_STACK_SIZE	128
3982905Sjake
40129749Stmmstruct pmap;
4191617Sjake
4281763Sobrien/*
4381763Sobrien * Inside the kernel, the globally reserved register g7 is used to
4481763Sobrien * point at the globaldata structure.
4581763Sobrien */
4687702Sjhb#define	PCPU_MD_FIELDS							\
47182689Smarius	struct	cacheinfo pc_cache;					\
4897265Sjake	struct	intr_request pc_irpool[IR_FREE];			\
4997265Sjake	struct	intr_request *pc_irhead;				\
5097265Sjake	struct	intr_request **pc_irtail;				\
5197265Sjake	struct	intr_request *pc_irfree;				\
52181701Smarius	struct	pmap *pc_pmap;						\
5391617Sjake	vm_offset_t pc_addr;						\
54286296Sjah	vm_offset_t pc_qmap_addr;					\
55145150Smarius	u_long	pc_tickref;						\
56145150Smarius	u_long	pc_tickadj;						\
57210601Smav	u_long	pc_tickincrement;					\
58182730Smarius	u_int	pc_clock;						\
59204152Smarius	u_int	pc_impl;						\
60181701Smarius	u_int	pc_mid;							\
61101898Sjake	u_int	pc_node;						\
6291613Sjake	u_int	pc_tlb_ctx;						\
6391613Sjake	u_int	pc_tlb_ctx_max;						\
64249265Sglebius	u_int	pc_tlb_ctx_min;						\
65286296Sjah	char	__pad[397]
6685232Sjake
67181875Sjhb#ifdef _KERNEL
68181875Sjhb
69194784Sjeffextern void *dpcpu0;
70194784Sjeff
7189035Sjakestruct pcb;
7287702Sjhbstruct pcpu;
7385232Sjake
7489035Sjakeregister struct pcb *curpcb __asm__(__XSTRING(PCB_REG));
7589035Sjakeregister struct pcpu *pcpup __asm__(__XSTRING(PCPU_REG));
7680708Sjake
7787702Sjhb#define	PCPU_GET(member)	(pcpup->pc_ ## member)
78167429Salc
79227539Smariusstatic __inline __pure2 struct thread *
80227539Smarius__curthread(void)
81227539Smarius{
82227539Smarius	struct thread *td;
83227539Smarius
84227539Smarius	__asm("ldx [%" __XSTRING(PCPU_REG) "], %0" : "=r" (td));
85227539Smarius	return (td);
86227539Smarius}
87227539Smarius#define	curthread	(__curthread())
88227539Smarius
89167429Salc/*
90167429Salc * XXX The implementation of this operation should be made atomic
91167429Salc * with respect to preemption.
92167429Salc */
93170291Sattilio#define	PCPU_ADD(member, value)	(pcpup->pc_ ## member += (value))
94170291Sattilio#define	PCPU_INC(member)	PCPU_ADD(member, 1)
9587702Sjhb#define	PCPU_PTR(member)	(&pcpup->pc_ ## member)
9687702Sjhb#define	PCPU_SET(member,value)	(pcpup->pc_ ## member = (value))
9787702Sjhb
9881763Sobrien#endif	/* _KERNEL */
9981763Sobrien
10087702Sjhb#endif	/* !_MACHINE_PCPU_H_ */
101