cpufunc.h revision 234589
150476Speter/*- 215903Swosch * Copyright (c) 1998 Doug Rabson 315903Swosch * All rights reserved. 415903Swosch * 515903Swosch * Redistribution and use in source and binary forms, with or without 615903Swosch * modification, are permitted provided that the following conditions 715903Swosch * are met: 815903Swosch * 1. Redistributions of source code must retain the above copyright 915903Swosch * notice, this list of conditions and the following disclaimer. 1015903Swosch * 2. Redistributions in binary form must reproduce the above copyright 1115903Swosch * notice, this list of conditions and the following disclaimer in the 1215903Swosch * documentation and/or other materials provided with the distribution. 1315903Swosch * 14139761Skrion * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1534678Sbde * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1623546Swosch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1723546Swosch * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1823546Swosch * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1939161Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2015903Swosch * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2139161Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2215903Swosch * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2315903Swosch * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2415903Swosch * SUCH DAMAGE. 2515903Swosch * 2615903Swosch * $FreeBSD: head/sys/powerpc/include/cpufunc.h 234589 2012-04-22 21:55:19Z nwhitehorn $ 2715903Swosch */ 2815903Swosch 2932216Swosch#ifndef _MACHINE_CPUFUNC_H_ 3032216Swosch#define _MACHINE_CPUFUNC_H_ 3132216Swosch 3232216Swosch#ifdef _KERNEL 3315903Swosch 3415903Swosch#include <sys/types.h> 3515903Swosch 3615903Swosch#include <machine/psl.h> 37119057Sobrien#include <machine/spr.h> 3815903Swosch 3915903Swoschstruct thread; 4015903Swosch 4115903Swosch#ifdef KDB 4215903Swoschvoid breakpoint(void); 4315903Swosch#else 4415903Swoschstatic __inline void 4565501Sobrienbreakpoint(void) 4615903Swosch{ 47186894Sbz 4815903Swosch return; 49186894Sbz} 5015903Swosch#endif 5153033Sphantom 5215903Swosch/* CPU register mangling inlines */ 5315903Swosch 5415903Swoschstatic __inline void 5515903Swoschmtmsr(register_t value) 5615903Swosch{ 5739161Sobrien 5815903Swosch __asm __volatile ("mtmsr %0; isync" :: "r"(value)); 5939161Sobrien} 6015903Swosch 6115903Swosch#ifdef __powerpc64__ 6215903Swoschstatic __inline void 6315903Swoschmtmsrd(register_t value) 6415903Swosch{ 6515903Swosch 6615903Swosch __asm __volatile ("mtmsrd %0; isync" :: "r"(value)); 6715903Swosch} 6815903Swosch#endif 6915903Swosch 7015903Swoschstatic __inline register_t 7115903Swoschmfmsr(void) 7215903Swosch{ 7315903Swosch register_t value; 7415903Swosch 7515903Swosch __asm __volatile ("mfmsr %0" : "=r"(value)); 7615903Swosch 7715903Swosch return (value); 7815903Swosch} 7915903Swosch 8015903Swosch#ifndef __powerpc64__ 8115903Swoschstatic __inline void 8215903Swoschmtsrin(vm_offset_t va, register_t value) 8315903Swosch{ 8415903Swosch 8515903Swosch __asm __volatile ("mtsrin %0,%1" :: "r"(value), "r"(va)); 8615903Swosch} 8715903Swosch 8815903Swoschstatic __inline register_t 8915903Swoschmfsrin(vm_offset_t va) 9015903Swosch{ 9115903Swosch register_t value; 9215903Swosch 9315903Swosch __asm __volatile ("mfsrin %0,%1" : "=r"(value) : "r"(va)); 9490627Sphantom 9515903Swosch return (value); 9690626Sphantom} 9715903Swosch#endif 9890626Sphantom 9915903Swoschstatic __inline register_t 10061462Sghelmermfctrl(void) 10115903Swosch{ 10232216Swosch register_t value; 10315903Swosch 10494982Sru __asm __volatile ("mfspr %0,136" : "=r"(value)); 10594982Sru 10694982Sru return (value); 107164411Sru} 108156813Sru 109156836Sru 110156836Srustatic __inline void 111156836Srumtdec(register_t value) 112164411Sru{ 113156813Sru 11414968Swosch __asm __volatile ("mtdec %0" :: "r"(value)); 11539161Sobrien} 11639161Sobrien 11714573Swoschstatic __inline register_t 11814968Swoschmfdec(void) 11914573Swosch{ 120111853Sru register_t value; 121111853Sru 122111853Sru __asm __volatile ("mfdec %0" : "=r"(value)); 12365501Sobrien 124111853Sru return (value); 12548204Sjmg} 12648204Sjmg 12748204Sjmgstatic __inline register_t 12848204Sjmgmfpvr(void) 12914573Swosch{ 13032226Ssteve register_t value; 13132226Ssteve 13214573Swosch __asm __volatile ("mfpvr %0" : "=r"(value)); 13314573Swosch 13414968Swosch return (value); 13514968Swosch} 13614968Swosch 13714573Swoschstatic __inline u_quad_t 13814968Swoschmftb(void) 13914968Swosch{ 14014968Swosch u_quad_t tb; 14139161Sobrien #ifdef __powerpc64__ 14239161Sobrien __asm __volatile ("mftb %0" : "=r"(tb)); 14314968Swosch #else 14414968Swosch uint32_t *tbup = (uint32_t *)&tb; 14514968Swosch uint32_t *tblp = tbup + 1; 14614968Swosch 14714968Swosch do { 14814968Swosch *tbup = mfspr(TBR_TBU); 14914968Swosch *tblp = mfspr(TBR_TBL); 15014968Swosch } while (*tbup != mfspr(TBR_TBU)); 15114968Swosch #endif 15214968Swosch 15314968Swosch return (tb); 15414968Swosch} 15514968Swosch 15614968Swoschstatic __inline void 15714968Swoschmttb(u_quad_t time) 15814968Swosch{ 15914968Swosch 16014968Swosch mtspr(TBR_TBWL, 0); 16190626Sphantom mtspr(TBR_TBWU, (uint32_t)(time >> 32)); 16290626Sphantom mtspr(TBR_TBWL, (uint32_t)(time & 0xffffffff)); 16361462Sghelmer} 16414968Swosch 16532216Swoschstatic __inline void 16632216Swoscheieio(void) 16714968Swosch{ 168125494Sru 169125494Sru __asm __volatile ("eieio" : : : "memory"); 170125494Sru} 171125494Sru 17234678Sbdestatic __inline void 17323546Swoschisync(void) 17494982Sru{ 175164411Sru 176156813Sru __asm __volatile ("isync" : : : "memory"); 177156813Sru} 178156813Sru 179156813Srustatic __inline void 180156813Srupowerpc_sync(void) 181156813Sru{ 182156813Sru 183156813Sru __asm __volatile ("sync" : : : "memory"); 184156813Sru} 185156813Sru 186156813Srustatic __inline register_t 187156813Sruintr_disable(void) 188156813Sru{ 189172832Sru register_t msr; 190156869Sru 191156869Sru msr = mfmsr(); 192156813Sru mtmsr(msr & ~PSL_EE); 193156813Sru return (msr); 194156813Sru} 195156813Sru 196156813Srustatic __inline void 197156813Sruintr_restore(register_t msr) 198156813Sru{ 199156813Sru 200156813Sru mtmsr(msr); 201156813Sru} 202156813Sru 203156813Srustatic __inline struct pcpu * 204156813Srupowerpc_get_pcpup(void) 205156813Sru{ 206156813Sru struct pcpu *ret; 207156813Sru 208156813Sru __asm __volatile("mfsprg %0, 0" : "=r"(ret)); 209156813Sru 210156813Sru return (ret); 211156813Sru} 212156813Sru 213156813Sru#endif /* _KERNEL */ 214156813Sru 215156813Sru#endif /* !_MACHINE_CPUFUNC_H_ */ 216156813Sru