pcpu.h revision 245202
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 245202 2013-01-09 01:52:28Z cognet $ 28129198Scognet */ 29129198Scognet 30129198Scognet#ifndef _MACHINE_PCPU_H_ 31129198Scognet#define _MACHINE_PCPU_H_ 32129198Scognet 33129198Scognet#ifdef _KERNEL 34129198Scognet 35239268Sgonzo#include <machine/cpuconf.h> 36129198Scognet#include <machine/frame.h> 37129198Scognet 38129198Scognet#define ALT_STACK_SIZE 128 39129198Scognet 40129198Scognetstruct vmspace; 41129198Scognet 42181875Sjhb#endif /* _KERNEL */ 43181875Sjhb 44239268Sgonzo#ifdef ARM_VFP_SUPPORT 45239268Sgonzo#define PCPU_MD_FIELDS \ 46239268Sgonzo unsigned int pc_cpu; \ 47239268Sgonzo unsigned int pc_vfpsid; \ 48239268Sgonzo unsigned int pc_vfpmvfr0; \ 49239268Sgonzo unsigned int pc_vfpmvfr1; \ 50239268Sgonzo struct thread *pc_vfpcthread; \ 51239268Sgonzo struct pmap *pc_curpmap; 52239268Sgonzo#else 53239268Sgonzo#define PCPU_MD_FIELDS 54239268Sgonzo#endif 55129198Scognet 56239268Sgonzo 57181875Sjhb#ifdef _KERNEL 58181875Sjhb 59129198Scognetstruct pcb; 60129198Scognetstruct pcpu; 61129198Scognet 62129198Scognetextern struct pcpu *pcpup; 63239268Sgonzo#if ARM_ARCH_6 || ARM_ARCH_7A 64239268Sgonzo/* or ARM_TP_ADDRESS mark REMOVE ME NOTE */ 65239268Sgonzostatic inline struct pcpu * 66239268Sgonzoget_pcpu(void) 67239268Sgonzo{ 68239268Sgonzo void *pcpu; 69129198Scognet 70239268Sgonzo __asm __volatile("mrc p15, 0, %0, c13, c0, 4" : "=r" (pcpu)); 71239268Sgonzo return (pcpu); 72239268Sgonzo} 73167429Salc 74239268Sgonzostatic inline void 75239268Sgonzoset_pcpu(void *pcpu) 76239268Sgonzo{ 77239268Sgonzo 78239268Sgonzo __asm __volatile("mcr p15, 0, %0, c13, c0, 4" : : "r" (pcpu)); 79239268Sgonzo} 80239268Sgonzo 81239268Sgonzostatic inline void * 82239268Sgonzoget_tls(void) 83239268Sgonzo{ 84239268Sgonzo void *tls; 85239268Sgonzo 86239268Sgonzo __asm __volatile("mrc p15, 0, %0, c13, c0, 3" : "=r" (tls)); 87239268Sgonzo return (tls); 88239268Sgonzo} 89239268Sgonzo 90239268Sgonzostatic inline void 91239268Sgonzoset_tls(void *tls) 92239268Sgonzo{ 93239268Sgonzo 94239268Sgonzo __asm __volatile("mcr p15, 0, %0, c13, c0, 3" : : "r" (tls)); 95239268Sgonzo} 96239268Sgonzo#else 97239268Sgonzo#define get_pcpu() pcpup 98239268Sgonzo#endif 99239268Sgonzo 100239268Sgonzo#define PCPU_GET(member) (get_pcpu()->pc_ ## member) 101239268Sgonzo#define PCPU_ADD(member, value) (get_pcpu()->pc_ ## member += (value)) 102170388Sjeff#define PCPU_INC(member) PCPU_ADD(member, 1) 103245202Scognet#define PCPU_PTR(member) (&get_pcpu()->pc_ ## member) 104245202Scognet#define PCPU_SET(member,value) (get_pcpu()->pc_ ## member = (value)) 105129198Scognet 106239268Sgonzovoid pcpu0_init(void); 107129198Scognet#endif /* _KERNEL */ 108129198Scognet 109129198Scognet#endif /* !_MACHINE_PCPU_H_ */ 110