18d7e7a98SRuslan Bukin /*- 28d7e7a98SRuslan Bukin * Copyright (c) 1999 Luoqi Chen <luoqi@freebsd.org> 317696c12SRuslan Bukin * Copyright (c) 2015-2016 Ruslan Bukin <br@bsdpad.com> 48d7e7a98SRuslan Bukin * All rights reserved. 58d7e7a98SRuslan Bukin * 617696c12SRuslan Bukin * Portions of this software were developed by SRI International and the 717696c12SRuslan Bukin * University of Cambridge Computer Laboratory under DARPA/AFRL contract 817696c12SRuslan Bukin * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. 917696c12SRuslan Bukin * 1017696c12SRuslan Bukin * Portions of this software were developed by the University of Cambridge 1117696c12SRuslan Bukin * Computer Laboratory as part of the CTSRD Project, with support from the 1217696c12SRuslan Bukin * UK Higher Education Innovation Fund (HEIF). 1317696c12SRuslan Bukin * 148d7e7a98SRuslan Bukin * Redistribution and use in source and binary forms, with or without 158d7e7a98SRuslan Bukin * modification, are permitted provided that the following conditions 168d7e7a98SRuslan Bukin * are met: 178d7e7a98SRuslan Bukin * 1. Redistributions of source code must retain the above copyright 188d7e7a98SRuslan Bukin * notice, this list of conditions and the following disclaimer. 198d7e7a98SRuslan Bukin * 2. Redistributions in binary form must reproduce the above copyright 208d7e7a98SRuslan Bukin * notice, this list of conditions and the following disclaimer in the 218d7e7a98SRuslan Bukin * documentation and/or other materials provided with the distribution. 228d7e7a98SRuslan Bukin * 238d7e7a98SRuslan Bukin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 248d7e7a98SRuslan Bukin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 258d7e7a98SRuslan Bukin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 268d7e7a98SRuslan Bukin * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 278d7e7a98SRuslan Bukin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 288d7e7a98SRuslan Bukin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 298d7e7a98SRuslan Bukin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 308d7e7a98SRuslan Bukin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 318d7e7a98SRuslan Bukin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 328d7e7a98SRuslan Bukin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 338d7e7a98SRuslan Bukin * SUCH DAMAGE. 348d7e7a98SRuslan Bukin * 358d7e7a98SRuslan Bukin * from: FreeBSD: src/sys/i386/include/globaldata.h,v 1.27 2001/04/27 368d7e7a98SRuslan Bukin * $FreeBSD$ 378d7e7a98SRuslan Bukin */ 388d7e7a98SRuslan Bukin 398d7e7a98SRuslan Bukin #ifndef _MACHINE_PCPU_H_ 408d7e7a98SRuslan Bukin #define _MACHINE_PCPU_H_ 418d7e7a98SRuslan Bukin 428d7e7a98SRuslan Bukin #include <machine/cpu.h> 438d7e7a98SRuslan Bukin #include <machine/cpufunc.h> 448d7e7a98SRuslan Bukin 458d7e7a98SRuslan Bukin #define ALT_STACK_SIZE 128 468d7e7a98SRuslan Bukin 478d7e7a98SRuslan Bukin #define PCPU_MD_FIELDS \ 4835c91b0cSMark Johnston struct pmap *pc_curpmap; /* Currently active pmap */ \ 4917696c12SRuslan Bukin uint32_t pc_pending_ipis; /* IPIs pending to this CPU */ \ 50b803d0b7SRuslan Bukin uint32_t pc_hart; /* Hart ID */ \ 51*90699f2aSJohn Baldwin char __pad[56] /* Pad to factor of PAGE_SIZE */ 528d7e7a98SRuslan Bukin 538d7e7a98SRuslan Bukin #ifdef _KERNEL 548d7e7a98SRuslan Bukin 558d7e7a98SRuslan Bukin struct pcb; 568d7e7a98SRuslan Bukin struct pcpu; 578d7e7a98SRuslan Bukin 588d7e7a98SRuslan Bukin static inline struct pcpu * 598d7e7a98SRuslan Bukin get_pcpu(void) 608d7e7a98SRuslan Bukin { 614d50647dSRuslan Bukin struct pcpu *pcpu; 628d7e7a98SRuslan Bukin 636ae48dd8SMitchell Horne __asm __volatile("mv %0, tp" : "=&r"(pcpu)); 644d50647dSRuslan Bukin 654d50647dSRuslan Bukin return (pcpu); 668d7e7a98SRuslan Bukin } 678d7e7a98SRuslan Bukin 688d7e7a98SRuslan Bukin static inline struct thread * 698d7e7a98SRuslan Bukin get_curthread(void) 708d7e7a98SRuslan Bukin { 718d7e7a98SRuslan Bukin struct thread *td; 728d7e7a98SRuslan Bukin 736ae48dd8SMitchell Horne __asm __volatile("ld %0, 0(tp)" : "=&r"(td)); 748d7e7a98SRuslan Bukin 758d7e7a98SRuslan Bukin return (td); 768d7e7a98SRuslan Bukin } 778d7e7a98SRuslan Bukin 788d7e7a98SRuslan Bukin #define curthread get_curthread() 798d7e7a98SRuslan Bukin 808d7e7a98SRuslan Bukin #define PCPU_GET(member) (get_pcpu()->pc_ ## member) 818d7e7a98SRuslan Bukin #define PCPU_ADD(member, value) (get_pcpu()->pc_ ## member += (value)) 828d7e7a98SRuslan Bukin #define PCPU_INC(member) PCPU_ADD(member, 1) 838d7e7a98SRuslan Bukin #define PCPU_PTR(member) (&get_pcpu()->pc_ ## member) 848d7e7a98SRuslan Bukin #define PCPU_SET(member,value) (get_pcpu()->pc_ ## member = (value)) 858d7e7a98SRuslan Bukin 868d7e7a98SRuslan Bukin #endif /* _KERNEL */ 878d7e7a98SRuslan Bukin 888d7e7a98SRuslan Bukin #endif /* !_MACHINE_PCPU_H_ */ 89