pcpu.h revision 249265
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 249265 2013-04-08 19:19:10Z glebius $ 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; \ 51249265Sglebius struct pmap *pc_curpmap; \ 52249265Sglebius char __pad[133] 53239268Sgonzo#else 54249265Sglebius#define PCPU_MD_FIELDS \ 55249265Sglebius char __pad[157] 56239268Sgonzo#endif 57129198Scognet 58181875Sjhb#ifdef _KERNEL 59181875Sjhb 60129198Scognetstruct pcb; 61129198Scognetstruct pcpu; 62129198Scognet 63129198Scognetextern struct pcpu *pcpup; 64239268Sgonzo#if ARM_ARCH_6 || ARM_ARCH_7A 65239268Sgonzo/* or ARM_TP_ADDRESS mark REMOVE ME NOTE */ 66239268Sgonzostatic inline struct pcpu * 67239268Sgonzoget_pcpu(void) 68239268Sgonzo{ 69239268Sgonzo void *pcpu; 70129198Scognet 71239268Sgonzo __asm __volatile("mrc p15, 0, %0, c13, c0, 4" : "=r" (pcpu)); 72239268Sgonzo return (pcpu); 73239268Sgonzo} 74167429Salc 75239268Sgonzostatic inline void 76239268Sgonzoset_pcpu(void *pcpu) 77239268Sgonzo{ 78239268Sgonzo 79239268Sgonzo __asm __volatile("mcr p15, 0, %0, c13, c0, 4" : : "r" (pcpu)); 80239268Sgonzo} 81239268Sgonzo 82239268Sgonzostatic inline void * 83239268Sgonzoget_tls(void) 84239268Sgonzo{ 85239268Sgonzo void *tls; 86239268Sgonzo 87239268Sgonzo __asm __volatile("mrc p15, 0, %0, c13, c0, 3" : "=r" (tls)); 88239268Sgonzo return (tls); 89239268Sgonzo} 90239268Sgonzo 91239268Sgonzostatic inline void 92239268Sgonzoset_tls(void *tls) 93239268Sgonzo{ 94239268Sgonzo 95239268Sgonzo __asm __volatile("mcr p15, 0, %0, c13, c0, 3" : : "r" (tls)); 96239268Sgonzo} 97239268Sgonzo#else 98239268Sgonzo#define get_pcpu() pcpup 99239268Sgonzo#endif 100239268Sgonzo 101239268Sgonzo#define PCPU_GET(member) (get_pcpu()->pc_ ## member) 102239268Sgonzo#define PCPU_ADD(member, value) (get_pcpu()->pc_ ## member += (value)) 103170388Sjeff#define PCPU_INC(member) PCPU_ADD(member, 1) 104245202Scognet#define PCPU_PTR(member) (&get_pcpu()->pc_ ## member) 105245202Scognet#define PCPU_SET(member,value) (get_pcpu()->pc_ ## member = (value)) 106129198Scognet 107239268Sgonzovoid pcpu0_init(void); 108129198Scognet#endif /* _KERNEL */ 109129198Scognet 110129198Scognet#endif /* !_MACHINE_PCPU_H_ */ 111