cpufunc.h revision 83511
166458Sdfr/*- 266458Sdfr * Copyright (c) 1998 Doug Rabson 366458Sdfr * All rights reserved. 466458Sdfr * 566458Sdfr * Redistribution and use in source and binary forms, with or without 666458Sdfr * modification, are permitted provided that the following conditions 766458Sdfr * are met: 866458Sdfr * 1. Redistributions of source code must retain the above copyright 966458Sdfr * notice, this list of conditions and the following disclaimer. 1066458Sdfr * 2. Redistributions in binary form must reproduce the above copyright 1166458Sdfr * notice, this list of conditions and the following disclaimer in the 1266458Sdfr * documentation and/or other materials provided with the distribution. 1366458Sdfr * 1466458Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1566458Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1666458Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1766458Sdfr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1866458Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1966458Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2066458Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2166458Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2266458Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2366458Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2466458Sdfr * SUCH DAMAGE. 2566458Sdfr * 2666458Sdfr * $FreeBSD: head/sys/ia64/include/cpufunc.h 83511 2001-09-15 12:30:56Z dfr $ 2766458Sdfr */ 2866458Sdfr 2966458Sdfr#ifndef _MACHINE_CPUFUNC_H_ 3066458Sdfr#define _MACHINE_CPUFUNC_H_ 3166458Sdfr 3266458Sdfr#ifdef _KERNEL 3366458Sdfr 3466458Sdfr#include <sys/types.h> 3583511Sdfr#include <machine/ia64_cpu.h> 3666458Sdfr 3766458Sdfr#ifdef __GNUC__ 3866458Sdfr 3966458Sdfrstatic __inline void 4066458Sdfrbreakpoint(void) 4166458Sdfr{ 4266458Sdfr __asm __volatile("break 0x80100"); /* XXX use linux value */ 4366458Sdfr} 4466458Sdfr 4566458Sdfr#endif 4666458Sdfr 4783511Sdfrextern u_int64_t ia64_port_base; 4883511Sdfr 4983511Sdfrstatic __inline volatile void * 5083511Sdfria64_port_address(u_int port) 5183511Sdfr{ 5283511Sdfr return (volatile void *)(ia64_port_base 5383511Sdfr | ((port >> 2) << 12) 5483511Sdfr | (port & ((1 << 12) - 1))); 5583511Sdfr} 5683511Sdfr 5766458Sdfrstatic __inline u_int8_t 5866458Sdfrinb(u_int port) 5966458Sdfr{ 6083511Sdfr volatile u_int8_t *p = ia64_port_address(port); 6183511Sdfr u_int8_t v = *p; 6283511Sdfr ia64_mf_a(); 6383511Sdfr ia64_mf(); 6483511Sdfr return v; 6566458Sdfr} 6666458Sdfr 6766458Sdfrstatic __inline u_int16_t 6866458Sdfrinw(u_int port) 6966458Sdfr{ 7083511Sdfr volatile u_int16_t *p = ia64_port_address(port); 7183511Sdfr u_int16_t v = *p; 7283511Sdfr ia64_mf_a(); 7383511Sdfr ia64_mf(); 7483511Sdfr return v; 7566458Sdfr} 7666458Sdfr 7766458Sdfrstatic __inline u_int32_t 7866458Sdfrinl(u_int port) 7966458Sdfr{ 8083511Sdfr volatile u_int32_t *p = ia64_port_address(port); 8183511Sdfr u_int32_t v = *p; 8283511Sdfr ia64_mf_a(); 8383511Sdfr ia64_mf(); 8483511Sdfr return v; 8566458Sdfr} 8666458Sdfr 8766458Sdfrstatic __inline void 8866458Sdfrinsb(u_int port, void *addr, size_t count) 8966458Sdfr{ 9066458Sdfr u_int8_t *p = addr; 9166458Sdfr while (count--) 9266458Sdfr *p++ = inb(port); 9366458Sdfr} 9466458Sdfr 9566458Sdfrstatic __inline void 9666458Sdfrinsw(u_int port, void *addr, size_t count) 9766458Sdfr{ 9866458Sdfr u_int16_t *p = addr; 9966458Sdfr while (count--) 10066458Sdfr *p++ = inw(port); 10166458Sdfr} 10266458Sdfr 10366458Sdfrstatic __inline void 10466458Sdfrinsl(u_int port, void *addr, size_t count) 10566458Sdfr{ 10666458Sdfr u_int32_t *p = addr; 10766458Sdfr while (count--) 10866458Sdfr *p++ = inl(port); 10966458Sdfr} 11066458Sdfr 11166458Sdfrstatic __inline void 11266458Sdfroutb(u_int port, u_int8_t data) 11366458Sdfr{ 11483511Sdfr volatile u_int8_t *p = ia64_port_address(port); 11583511Sdfr *p = data; 11683511Sdfr ia64_mf_a(); 11783511Sdfr ia64_mf(); 11866458Sdfr} 11966458Sdfr 12066458Sdfrstatic __inline void 12166458Sdfroutw(u_int port, u_int16_t data) 12266458Sdfr{ 12383511Sdfr volatile u_int16_t *p = ia64_port_address(port); 12483511Sdfr *p = data; 12583511Sdfr ia64_mf_a(); 12683511Sdfr ia64_mf(); 12766458Sdfr} 12866458Sdfr 12966458Sdfrstatic __inline void 13066458Sdfroutl(u_int port, u_int32_t data) 13166458Sdfr{ 13283511Sdfr volatile u_int32_t *p = ia64_port_address(port); 13383511Sdfr *p = data; 13483511Sdfr ia64_mf_a(); 13583511Sdfr ia64_mf(); 13666458Sdfr} 13766458Sdfr 13866458Sdfrstatic __inline void 13966458Sdfroutsb(u_int port, const void *addr, size_t count) 14066458Sdfr{ 14166458Sdfr const u_int8_t *p = addr; 14266458Sdfr while (count--) 14366458Sdfr outb(port, *p++); 14466458Sdfr} 14566458Sdfr 14666458Sdfrstatic __inline void 14766458Sdfroutsw(u_int port, const void *addr, size_t count) 14866458Sdfr{ 14966458Sdfr const u_int16_t *p = addr; 15066458Sdfr while (count--) 15166458Sdfr outw(port, *p++); 15266458Sdfr} 15366458Sdfr 15466458Sdfrstatic __inline void 15566458Sdfroutsl(u_int port, const void *addr, size_t count) 15666458Sdfr{ 15766458Sdfr const u_int32_t *p = addr; 15866458Sdfr while (count--) 15966458Sdfr outl(port, *p++); 16066458Sdfr} 16166458Sdfr 16266458Sdfrstatic __inline u_int8_t 16366458Sdfrreadb(u_int addr) 16466458Sdfr{ 16566458Sdfr return 0; /* TODO: implement this */ 16666458Sdfr} 16766458Sdfr 16866458Sdfrstatic __inline u_int16_t 16966458Sdfrreadw(u_int addr) 17066458Sdfr{ 17166458Sdfr return 0; /* TODO: implement this */ 17266458Sdfr} 17366458Sdfr 17466458Sdfrstatic __inline u_int32_t 17566458Sdfrreadl(u_int addr) 17666458Sdfr{ 17766458Sdfr return 0; /* TODO: implement this */ 17866458Sdfr} 17966458Sdfr 18066458Sdfrstatic __inline void 18166458Sdfrwriteb(u_int addr, u_int8_t data) 18266458Sdfr{ 18366458Sdfr return; /* TODO: implement this */ 18466458Sdfr} 18566458Sdfr 18666458Sdfrstatic __inline void 18766458Sdfrwritew(u_int addr, u_int16_t data) 18866458Sdfr{ 18966458Sdfr return; /* TODO: implement this */ 19066458Sdfr} 19166458Sdfr 19266458Sdfrstatic __inline void 19366458Sdfrwritel(u_int addr, u_int32_t data) 19466458Sdfr{ 19566458Sdfr return; /* TODO: implement this */ 19666458Sdfr} 19766458Sdfr 19866458Sdfrstatic __inline void 19966458Sdfrdisable_intr(void) 20066458Sdfr{ 20166458Sdfr __asm __volatile ("rsm psr.i;;"); 20266458Sdfr} 20366458Sdfr 20466458Sdfrstatic __inline void 20566458Sdfrenable_intr(void) 20666458Sdfr{ 20766458Sdfr __asm __volatile (";; ssm psr.i;; srlz.d"); 20866458Sdfr} 20966458Sdfr 21074897Sjhbstatic __inline critical_t 21174897Sjhbcritical_enter(void) 21266458Sdfr{ 21374897Sjhb critical_t psr; 21474897Sjhb 21566458Sdfr __asm __volatile ("mov %0=psr;;" : "=r" (psr)); 21674897Sjhb disable_intr(); 21774897Sjhb return (psr); 21866458Sdfr} 21966458Sdfr 22066458Sdfrstatic __inline void 22174897Sjhbcritical_exit(critical_t psr) 22266458Sdfr{ 22366458Sdfr __asm __volatile ("mov psr.l=%0;; srlz.d" :: "r" (psr)); 22466458Sdfr} 22566458Sdfr 22666458Sdfr#endif /* _KERNEL */ 22766458Sdfr 22866458Sdfr#endif /* !_MACHINE_CPUFUNC_H_ */ 229