cpufunc.h revision 115295
150477Speter/*- 238465Smsmith * Copyright (c) 1998 Doug Rabson 3156813Sru * All rights reserved. 4188895Sru * 5156813Sru * Redistribution and use in source and binary forms, with or without 6199714Srnoland * modification, are permitted provided that the following conditions 7199714Srnoland * are met: 8125621Sru * 1. Redistributions of source code must retain the above copyright 9212066Sdelphij * notice, this list of conditions and the following disclaimer. 1038465Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1139441Smsmith * notice, this list of conditions and the following disclaimer in the 12125537Sru * documentation and/or other materials provided with the distribution. 1339441Smsmith * 14170101Ssimokawa * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15170101Ssimokawa * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16170101Ssimokawa * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17170101Ssimokawa * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18170101Ssimokawa * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19170101Ssimokawa * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20199714Srnoland * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21185029Spjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22185029Spjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23235156Savg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24185029Spjd * SUCH DAMAGE. 25185029Spjd * 2659087Sps * $FreeBSD: head/sys/ia64/include/cpufunc.h 115295 2003-05-24 21:44:24Z marcel $ 2768310Sps */ 2868310Sps 2968310Sps#ifndef _MACHINE_CPUFUNC_H_ 3059087Sps#define _MACHINE_CPUFUNC_H_ 3168310Sps 3259087Sps#ifdef _KERNEL 33163893Smarcel 34163893Smarcel#include <sys/types.h> 35163893Smarcel#include <machine/ia64_cpu.h> 3639178Smsmith#include <machine/vmparam.h> 3740555Smsmith 3840555Smsmithstruct thread; 3939178Smsmith 40156813Sru#ifdef __GNUC__ 4140877Smsmith 4256903Sjhbstatic __inline void 4356903Sjhbbreakpoint(void) 44271135Semaste{ 45271135Semaste __asm __volatile("break 0x80100"); /* XXX use linux value */ 46271135Semaste} 4741107Sjkh 4841107Sjkh#endif 49271135Semaste 5040877Smsmithextern uint64_t ia64_port_base; 51146874Sobrien#define __MEMIO_ADDR(x) (__volatile void*)(IA64_PHYS_TO_RR6(x)) 5283616Ssobomax#define __PIO_ADDR(x) (__volatile void*)(ia64_port_base | \ 5383616Ssobomax (((x) & 0xFFFC) << 10) | ((x) & 0xFFF)) 5483616Ssobomax 5583616Ssobomax/* 5683616Ssobomax * I/O port reads with ia32 semantics. 57235537Sgber */ 58235537Sgberstatic __inline uint8_t 59235537Sgberinb(unsigned int port) 6083616Ssobomax{ 61227726Smiwi __volatile uint8_t *p; 6238465Smsmith uint8_t v; 63125516Sru p = __PIO_ADDR(port); 6440338Speter ia64_mf(); 65125537Sru v = *p; 6638465Smsmith ia64_mf_a(); 67199714Srnoland ia64_mf(); 6838465Smsmith return (v); 6938465Smsmith} 70125621Sru 7138465Smsmithstatic __inline uint16_t 7238465Smsmithinw(unsigned int port) 7338465Smsmith{ 7438465Smsmith __volatile uint16_t *p; 7538465Smsmith uint16_t v; 76271130Semaste p = __PIO_ADDR(port); 77271130Semaste ia64_mf(); 7839441Smsmith v = *p; 7939646Speter ia64_mf_a(); 8039441Smsmith ia64_mf(); 8139664Smsmith return (v); 8240884Smsmith} 8340884Smsmith 8439664Smsmithstatic __inline uint32_t 85125537Sruinl(unsigned int port) 86125537Sru{ 87125537Sru volatile uint32_t *p; 88199714Srnoland uint32_t v; 89199714Srnoland p = __PIO_ADDR(port); 90199714Srnoland ia64_mf(); 9138465Smsmith v = *p; 92199714Srnoland ia64_mf_a(); 93102623Sjhb ia64_mf(); 94199714Srnoland return (v); 9538465Smsmith} 96199714Srnoland 9740555Smsmithstatic __inline void 9869985Srnordierinsb(unsigned int port, void *addr, size_t count) 9940555Smsmith{ 100125537Sru uint8_t *buf = addr; 10142807Smsmith while (count--) 10241821Smsmith *buf++ = inb(port); 103199714Srnoland} 104199714Srnoland 105199714Srnolandstatic __inline void 106199714Srnolandinsw(unsigned int port, void *addr, size_t count) 107199714Srnoland{ 108227726Smiwi uint16_t *buf = addr; 109281843Sdteske while (count--) 11094956Sru *buf++ = inw(port); 11145759Sdcs} 112138186Sru 11345759Sdcsstatic __inline void 114222417Sjulianinsl(unsigned int port, void *addr, size_t count) 115222417Sjulian{ 116199714Srnoland uint32_t *buf = addr; 117222417Sjulian while (count--) 11841821Smsmith *buf++ = inl(port); 119126312Sru} 120227726Smiwi 12140555Smsmithstatic __inline void 122235156Savgoutb(unsigned int port, uint8_t data) 123235156Savg{ 124126312Sru volatile uint8_t *p; 125125621Sru p = __PIO_ADDR(port); 12639441Smsmith ia64_mf(); 127211677Simp *p = data; 128125581Sru ia64_mf_a(); 129125537Sru ia64_mf(); 130241068Sae} 13140338Speter 13240338Speterstatic __inline void 13340555Smsmithoutw(unsigned int port, uint16_t data) 134{ 135 volatile uint16_t *p; 136 p = __PIO_ADDR(port); 137 ia64_mf(); 138 *p = data; 139 ia64_mf_a(); 140 ia64_mf(); 141} 142 143static __inline void 144outl(unsigned int port, uint32_t data) 145{ 146 volatile uint32_t *p; 147 p = __PIO_ADDR(port); 148 ia64_mf(); 149 *p = data; 150 ia64_mf_a(); 151 ia64_mf(); 152} 153 154static __inline void 155outsb(unsigned int port, const void *addr, size_t count) 156{ 157 const uint8_t *buf = addr; 158 while (count--) 159 outb(port, *buf++); 160} 161 162static __inline void 163outsw(unsigned int port, const void *addr, size_t count) 164{ 165 const uint16_t *buf = addr; 166 while (count--) 167 outw(port, *buf++); 168} 169 170static __inline void 171outsl(unsigned int port, const void *addr, size_t count) 172{ 173 const uint32_t *buf = addr; 174 while (count--) 175 outl(port, *buf++); 176} 177 178static __inline void 179disable_intr(void) 180{ 181 __asm __volatile ("rsm psr.i"); 182} 183 184static __inline void 185enable_intr(void) 186{ 187 __asm __volatile ("ssm psr.i;; srlz.d"); 188} 189 190static __inline register_t 191intr_disable(void) 192{ 193 register_t psr; 194 __asm __volatile ("mov %0=psr;;" : "=r"(psr)); 195 disable_intr(); 196 return ((psr & IA64_PSR_I) ? 1 : 0); 197} 198 199static __inline void 200intr_restore(register_t ie) 201{ 202 if (ie) 203 enable_intr(); 204} 205 206#endif /* _KERNEL */ 207 208#endif /* !_MACHINE_CPUFUNC_H_ */ 209