1 /*- 2 * Copyright (c) 1999 Luoqi Chen <luoqi@freebsd.org> 3 * Copyright (c) Peter Wemm <peter@netplex.com.au> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * $FreeBSD$ 28 */ 29 30 #ifndef _MACHINE_PCPU_H_ 31 #define _MACHINE_PCPU_H_ 32 33 #include <machine/cpufunc.h> 34 #include <machine/slb.h> 35 #include <machine/tlb.h> 36 37 struct pmap; 38 struct pvo_entry; 39 #define CPUSAVE_LEN 9 40 41 #define PCPU_MD_COMMON_FIELDS \ 42 int pc_inside_intr; \ 43 struct pmap *pc_curpmap; /* current pmap */ \ 44 struct thread *pc_fputhread; /* current fpu user */ \ 45 struct thread *pc_vecthread; /* current vec user */ \ 46 uintptr_t pc_hwref; \ 47 uint32_t pc_pir; \ 48 int pc_bsp; \ 49 volatile int pc_awake; \ 50 uint32_t pc_ipimask; \ 51 register_t pc_tempsave[CPUSAVE_LEN]; \ 52 register_t pc_disisave[CPUSAVE_LEN]; \ 53 register_t pc_dbsave[CPUSAVE_LEN]; \ 54 void *pc_restore; 55 56 #define PCPU_MD_AIM32_FIELDS \ 57 vm_offset_t pc_qmap_addr; \ 58 struct pvo_entry *pc_qmap_pvo; \ 59 struct mtx pc_qmap_lock; \ 60 char __pad[128] 61 62 #define PCPU_MD_AIM64_FIELDS \ 63 struct slb pc_slb[64]; \ 64 struct slb **pc_userslb; \ 65 register_t pc_slbsave[18]; \ 66 uint8_t pc_slbstack[1024]; \ 67 vm_offset_t pc_qmap_addr; \ 68 struct pvo_entry *pc_qmap_pvo; \ 69 struct mtx pc_qmap_lock; \ 70 char __pad[1345] 71 72 #ifdef __powerpc64__ 73 #define PCPU_MD_AIM_FIELDS PCPU_MD_AIM64_FIELDS 74 #else 75 #define PCPU_MD_AIM_FIELDS PCPU_MD_AIM32_FIELDS 76 #endif 77 78 #define BOOKE_CRITSAVE_LEN (CPUSAVE_LEN + 2) 79 #define BOOKE_TLB_MAXNEST 3 80 #define BOOKE_TLB_SAVELEN 16 81 #define BOOKE_TLBSAVE_LEN (BOOKE_TLB_SAVELEN * BOOKE_TLB_MAXNEST) 82 83 #ifdef __powerpc64__ 84 #define BOOKE_PCPU_PAD 901 85 #else 86 #define BOOKE_PCPU_PAD 429 87 #endif 88 #define PCPU_MD_BOOKE_FIELDS \ 89 register_t pc_booke_critsave[BOOKE_CRITSAVE_LEN]; \ 90 register_t pc_booke_mchksave[CPUSAVE_LEN]; \ 91 register_t pc_booke_tlbsave[BOOKE_TLBSAVE_LEN]; \ 92 register_t pc_booke_tlb_level; \ 93 vm_offset_t pc_qmap_addr; \ 94 uintptr_t *pc_booke_tlb_lock; \ 95 int pc_tid_next; \ 96 char __pad[BOOKE_PCPU_PAD] 97 98 /* Definitions for register offsets within the exception tmp save areas */ 99 #define CPUSAVE_R27 0 /* where r27 gets saved */ 100 #define CPUSAVE_R28 1 /* where r28 gets saved */ 101 #define CPUSAVE_R29 2 /* where r29 gets saved */ 102 #define CPUSAVE_R30 3 /* where r30 gets saved */ 103 #define CPUSAVE_R31 4 /* where r31 gets saved */ 104 #define CPUSAVE_AIM_DAR 5 /* where SPR_DAR gets saved */ 105 #define CPUSAVE_AIM_DSISR 6 /* where SPR_DSISR gets saved */ 106 #define CPUSAVE_BOOKE_DEAR 5 /* where SPR_DEAR gets saved */ 107 #define CPUSAVE_BOOKE_ESR 6 /* where SPR_ESR gets saved */ 108 #define CPUSAVE_SRR0 7 /* where SRR0 gets saved */ 109 #define CPUSAVE_SRR1 8 /* where SRR1 gets saved */ 110 #define BOOKE_CRITSAVE_SRR0 9 /* where real SRR0 gets saved (critical) */ 111 #define BOOKE_CRITSAVE_SRR1 10 /* where real SRR0 gets saved (critical) */ 112 113 /* Book-E TLBSAVE is more elaborate */ 114 #define TLBSAVE_BOOKE_LR 0 115 #define TLBSAVE_BOOKE_CR 1 116 #define TLBSAVE_BOOKE_SRR0 2 117 #define TLBSAVE_BOOKE_SRR1 3 118 #define TLBSAVE_BOOKE_R20 4 119 #define TLBSAVE_BOOKE_R21 5 120 #define TLBSAVE_BOOKE_R22 6 121 #define TLBSAVE_BOOKE_R23 7 122 #define TLBSAVE_BOOKE_R24 8 123 #define TLBSAVE_BOOKE_R25 9 124 #define TLBSAVE_BOOKE_R26 10 125 #define TLBSAVE_BOOKE_R27 11 126 #define TLBSAVE_BOOKE_R28 12 127 #define TLBSAVE_BOOKE_R29 13 128 #define TLBSAVE_BOOKE_R30 14 129 #define TLBSAVE_BOOKE_R31 15 130 131 #ifdef AIM 132 #define PCPU_MD_FIELDS \ 133 PCPU_MD_COMMON_FIELDS \ 134 PCPU_MD_AIM_FIELDS 135 #endif 136 #if defined(BOOKE) 137 #define PCPU_MD_FIELDS \ 138 PCPU_MD_COMMON_FIELDS \ 139 PCPU_MD_BOOKE_FIELDS 140 #endif 141 142 /* 143 * Catch-all for ports (e.g. lsof, used by gtop) 144 */ 145 #ifndef PCPU_MD_FIELDS 146 #define PCPU_MD_FIELDS \ 147 int pc_md_placeholder[32] 148 #endif 149 150 #ifdef _KERNEL 151 152 #define pcpup (get_pcpu()) 153 154 static __inline __pure2 struct thread * 155 __curthread(void) 156 { 157 struct thread *td; 158 #ifdef __powerpc64__ 159 __asm __volatile("mr %0,13" : "=r"(td)); 160 #else 161 __asm __volatile("mr %0,2" : "=r"(td)); 162 #endif 163 return (td); 164 } 165 #define curthread (__curthread()) 166 167 #define PCPU_GET(member) (pcpup->pc_ ## member) 168 169 /* 170 * XXX The implementation of this operation should be made atomic 171 * with respect to preemption. 172 */ 173 #define PCPU_ADD(member, value) (pcpup->pc_ ## member += (value)) 174 #define PCPU_INC(member) PCPU_ADD(member, 1) 175 #define PCPU_PTR(member) (&pcpup->pc_ ## member) 176 #define PCPU_SET(member,value) (pcpup->pc_ ## member = (value)) 177 178 #endif /* _KERNEL */ 179 180 #endif /* !_MACHINE_PCPU_H_ */ 181