/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 1999 Luoqi Chen <[email protected]>4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*27* from: FreeBSD: src/sys/i386/include/globaldata.h,v 1.27 2001/04/2728*/2930#ifndef _MACHINE_PCPU_H_31#define _MACHINE_PCPU_H_3233#ifdef _KERNEL3435#include <sys/_lock.h>36#include <sys/_mutex.h>3738struct vmspace;3940#endif /* _KERNEL */4142/* Branch predictor hardening method */43#define PCPU_BP_HARDEN_KIND_NONE 044#define PCPU_BP_HARDEN_KIND_BPIALL 145#define PCPU_BP_HARDEN_KIND_ICIALLU 24647#define PCPU_MD_FIELDS \48unsigned int pc_vfpsid; \49unsigned int pc_vfpmvfr0; \50unsigned int pc_vfpmvfr1; \51struct pmap *pc_curpmap; \52struct mtx pc_cmap_lock; \53void *pc_cmap1_pte2p; \54void *pc_cmap2_pte2p; \55caddr_t pc_cmap1_addr; \56caddr_t pc_cmap2_addr; \57vm_offset_t pc_qmap_addr; \58void *pc_qmap_pte2p; \59unsigned int pc_dbreg[32]; \60int pc_dbreg_cmd; \61int pc_bp_harden_kind; \62uint32_t pc_original_actlr; \63uint64_t pc_clock; \64uint32_t pc_mpidr; \65char __pad[135]6667#ifdef _KERNEL6869#define PC_DBREG_CMD_NONE 070#define PC_DBREG_CMD_LOAD 17172struct pcb;73struct pcpu;7475extern struct pcpu *pcpup;7677#define CPU_MASK (0xf)7879#ifndef SMP80#define get_pcpu() (pcpup)81#else82#define get_pcpu() __extension__ ({ \83int id; \84__asm __volatile("mrc p15, 0, %0, c0, c0, 5" : "=r" (id)); \85(pcpup + (id & CPU_MASK)); \86})87#endif8889static inline struct thread *90get_curthread(void)91{92void *ret;9394__asm __volatile("mrc p15, 0, %0, c13, c0, 4" : "=r" (ret));95return (ret);96}9798static inline void99set_curthread(struct thread *td)100{101102__asm __volatile("mcr p15, 0, %0, c13, c0, 4" : : "r" (td));103}104105static inline void *106get_tls(void)107{108void *tls;109110/* TPIDRURW contains the authoritative value. */111__asm __volatile("mrc p15, 0, %0, c13, c0, 2" : "=r" (tls));112return (tls);113}114115static inline void116set_tls(void *tls)117{118119/*120* Update both TPIDRURW and TPIDRURO. TPIDRURW needs to be written121* first to ensure that a context switch between the two writes will122* still give the desired result of updating both.123*/124__asm __volatile(125"mcr p15, 0, %0, c13, c0, 2\n"126"mcr p15, 0, %0, c13, c0, 3\n"127: : "r" (tls));128}129130#define curthread get_curthread()131132133#define PCPU_GET(member) (get_pcpu()->pc_ ## member)134#define PCPU_ADD(member, value) (get_pcpu()->pc_ ## member += (value))135#define PCPU_PTR(member) (&get_pcpu()->pc_ ## member)136#define PCPU_SET(member,value) (get_pcpu()->pc_ ## member = (value))137138#define PCPU_GET_MPIDR(pc) ((pc)->pc_mpidr)139140void pcpu0_init(void);141#endif /* _KERNEL */142143#endif /* !_MACHINE_PCPU_H_ */144145146