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/10.3/sys/sparc64/include/pcpu.h 249265 2013-04-08 19:19:10Z glebius $ 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; \ 54145150Smarius u_long pc_tickref; \ 55145150Smarius u_long pc_tickadj; \ 56210601Smav u_long pc_tickincrement; \ 57182730Smarius u_int pc_clock; \ 58204152Smarius u_int pc_impl; \ 59181701Smarius u_int pc_mid; \ 60101898Sjake u_int pc_node; \ 6191613Sjake u_int pc_tlb_ctx; \ 6291613Sjake u_int pc_tlb_ctx_max; \ 63249265Sglebius u_int pc_tlb_ctx_min; \ 64249265Sglebius char __pad[405] 6585232Sjake 66181875Sjhb#ifdef _KERNEL 67181875Sjhb 68194784Sjeffextern void *dpcpu0; 69194784Sjeff 7089035Sjakestruct pcb; 7187702Sjhbstruct pcpu; 7285232Sjake 7389035Sjakeregister struct pcb *curpcb __asm__(__XSTRING(PCB_REG)); 7489035Sjakeregister struct pcpu *pcpup __asm__(__XSTRING(PCPU_REG)); 7580708Sjake 7687702Sjhb#define PCPU_GET(member) (pcpup->pc_ ## member) 77167429Salc 78227539Smariusstatic __inline __pure2 struct thread * 79227539Smarius__curthread(void) 80227539Smarius{ 81227539Smarius struct thread *td; 82227539Smarius 83227539Smarius __asm("ldx [%" __XSTRING(PCPU_REG) "], %0" : "=r" (td)); 84227539Smarius return (td); 85227539Smarius} 86227539Smarius#define curthread (__curthread()) 87227539Smarius 88167429Salc/* 89167429Salc * XXX The implementation of this operation should be made atomic 90167429Salc * with respect to preemption. 91167429Salc */ 92170291Sattilio#define PCPU_ADD(member, value) (pcpup->pc_ ## member += (value)) 93170291Sattilio#define PCPU_INC(member) PCPU_ADD(member, 1) 9487702Sjhb#define PCPU_PTR(member) (&pcpup->pc_ ## member) 9587702Sjhb#define PCPU_SET(member,value) (pcpup->pc_ ## member = (value)) 9687702Sjhb 9781763Sobrien#endif /* _KERNEL */ 9881763Sobrien 9987702Sjhb#endif /* !_MACHINE_PCPU_H_ */ 100