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: releng/10.3/sys/arm/include/pcpu.h 266277 2014-05-17 00:53:12Z ian $ 28129198Scognet */ 29129198Scognet 30129198Scognet#ifndef _MACHINE_PCPU_H_ 31129198Scognet#define _MACHINE_PCPU_H_ 32129198Scognet 33129198Scognet#ifdef _KERNEL 34129198Scognet 35239268Sgonzo#include <machine/cpuconf.h> 36129198Scognet 37129198Scognet#define ALT_STACK_SIZE 128 38129198Scognet 39129198Scognetstruct vmspace; 40129198Scognet 41181875Sjhb#endif /* _KERNEL */ 42181875Sjhb 43254461Sandrew#ifdef VFP 44239268Sgonzo#define PCPU_MD_FIELDS \ 45239268Sgonzo unsigned int pc_cpu; \ 46239268Sgonzo unsigned int pc_vfpsid; \ 47239268Sgonzo unsigned int pc_vfpmvfr0; \ 48239268Sgonzo unsigned int pc_vfpmvfr1; \ 49249265Sglebius struct pmap *pc_curpmap; \ 50266277Sian char __pad[137] 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; 62239268Sgonzo#if ARM_ARCH_6 || ARM_ARCH_7A 63239268Sgonzo/* or ARM_TP_ADDRESS mark REMOVE ME NOTE */ 64266159Sian 65266159Sian#define CPU_MASK (0xf) 66266159Sian 67266159Sian#ifndef SMP 68266159Sian#define get_pcpu() (pcpup) 69266159Sian#else 70266159Sian#define get_pcpu() __extension__ ({ \ 71266159Sian int id; \ 72266159Sian __asm __volatile("mrc p15, 0, %0, c0, c0, 5" : "=r" (id)); \ 73266159Sian (pcpup + (id & CPU_MASK)); \ 74266159Sian }) 75266159Sian#endif 76266159Sian 77266159Sianstatic inline struct thread * 78266159Sianget_curthread(void) 79239268Sgonzo{ 80266159Sian void *ret; 81129198Scognet 82266159Sian __asm __volatile("mrc p15, 0, %0, c13, c0, 4" : "=r" (ret)); 83266159Sian return (ret); 84239268Sgonzo} 85167429Salc 86239268Sgonzostatic inline void 87266159Sianset_curthread(struct thread *td) 88239268Sgonzo{ 89239268Sgonzo 90266159Sian __asm __volatile("mcr p15, 0, %0, c13, c0, 4" : : "r" (td)); 91239268Sgonzo} 92239268Sgonzo 93266159Sian 94239268Sgonzostatic inline void * 95239268Sgonzoget_tls(void) 96239268Sgonzo{ 97239268Sgonzo void *tls; 98239268Sgonzo 99239268Sgonzo __asm __volatile("mrc p15, 0, %0, c13, c0, 3" : "=r" (tls)); 100239268Sgonzo return (tls); 101239268Sgonzo} 102239268Sgonzo 103239268Sgonzostatic inline void 104239268Sgonzoset_tls(void *tls) 105239268Sgonzo{ 106239268Sgonzo 107239268Sgonzo __asm __volatile("mcr p15, 0, %0, c13, c0, 3" : : "r" (tls)); 108239268Sgonzo} 109266159Sian 110266159Sian#define curthread get_curthread() 111266159Sian 112239268Sgonzo#else 113239268Sgonzo#define get_pcpu() pcpup 114239268Sgonzo#endif 115239268Sgonzo 116239268Sgonzo#define PCPU_GET(member) (get_pcpu()->pc_ ## member) 117239268Sgonzo#define PCPU_ADD(member, value) (get_pcpu()->pc_ ## member += (value)) 118170388Sjeff#define PCPU_INC(member) PCPU_ADD(member, 1) 119245202Scognet#define PCPU_PTR(member) (&get_pcpu()->pc_ ## member) 120245202Scognet#define PCPU_SET(member,value) (get_pcpu()->pc_ ## member = (value)) 121129198Scognet 122239268Sgonzovoid pcpu0_init(void); 123129198Scognet#endif /* _KERNEL */ 124129198Scognet 125129198Scognet#endif /* !_MACHINE_PCPU_H_ */ 126