cpufunc.h revision 84581
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 84581 2001-10-06 09:31:43Z marcel $ 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 5783836Sdfrstatic __inline volatile void * 5884581Smarcelia64_memory_address(u_int64_t addr) 5983836Sdfr{ 6084581Smarcel return (volatile void *) IA64_PHYS_TO_RR6(addr); 6183836Sdfr} 6283836Sdfr 6366458Sdfrstatic __inline u_int8_t 6466458Sdfrinb(u_int port) 6566458Sdfr{ 6683511Sdfr volatile u_int8_t *p = ia64_port_address(port); 6783511Sdfr u_int8_t v = *p; 6883511Sdfr ia64_mf_a(); 6983511Sdfr ia64_mf(); 7083511Sdfr return v; 7166458Sdfr} 7266458Sdfr 7366458Sdfrstatic __inline u_int16_t 7466458Sdfrinw(u_int port) 7566458Sdfr{ 7683511Sdfr volatile u_int16_t *p = ia64_port_address(port); 7783511Sdfr u_int16_t v = *p; 7883511Sdfr ia64_mf_a(); 7983511Sdfr ia64_mf(); 8083511Sdfr return v; 8166458Sdfr} 8266458Sdfr 8366458Sdfrstatic __inline u_int32_t 8466458Sdfrinl(u_int port) 8566458Sdfr{ 8683511Sdfr volatile u_int32_t *p = ia64_port_address(port); 8783511Sdfr u_int32_t v = *p; 8883511Sdfr ia64_mf_a(); 8983511Sdfr ia64_mf(); 9083511Sdfr return v; 9166458Sdfr} 9266458Sdfr 9366458Sdfrstatic __inline void 9466458Sdfrinsb(u_int port, void *addr, size_t count) 9566458Sdfr{ 9666458Sdfr u_int8_t *p = addr; 9766458Sdfr while (count--) 9866458Sdfr *p++ = inb(port); 9966458Sdfr} 10066458Sdfr 10166458Sdfrstatic __inline void 10266458Sdfrinsw(u_int port, void *addr, size_t count) 10366458Sdfr{ 10466458Sdfr u_int16_t *p = addr; 10566458Sdfr while (count--) 10666458Sdfr *p++ = inw(port); 10766458Sdfr} 10866458Sdfr 10966458Sdfrstatic __inline void 11066458Sdfrinsl(u_int port, void *addr, size_t count) 11166458Sdfr{ 11266458Sdfr u_int32_t *p = addr; 11366458Sdfr while (count--) 11466458Sdfr *p++ = inl(port); 11566458Sdfr} 11666458Sdfr 11766458Sdfrstatic __inline void 11866458Sdfroutb(u_int port, u_int8_t data) 11966458Sdfr{ 12083511Sdfr volatile u_int8_t *p = ia64_port_address(port); 12183511Sdfr *p = data; 12283511Sdfr ia64_mf_a(); 12383511Sdfr ia64_mf(); 12466458Sdfr} 12566458Sdfr 12666458Sdfrstatic __inline void 12766458Sdfroutw(u_int port, u_int16_t data) 12866458Sdfr{ 12983511Sdfr volatile u_int16_t *p = ia64_port_address(port); 13083511Sdfr *p = data; 13183511Sdfr ia64_mf_a(); 13283511Sdfr ia64_mf(); 13366458Sdfr} 13466458Sdfr 13566458Sdfrstatic __inline void 13666458Sdfroutl(u_int port, u_int32_t data) 13766458Sdfr{ 13883511Sdfr volatile u_int32_t *p = ia64_port_address(port); 13983511Sdfr *p = data; 14083511Sdfr ia64_mf_a(); 14183511Sdfr ia64_mf(); 14266458Sdfr} 14366458Sdfr 14466458Sdfrstatic __inline void 14566458Sdfroutsb(u_int port, const void *addr, size_t count) 14666458Sdfr{ 14766458Sdfr const u_int8_t *p = addr; 14866458Sdfr while (count--) 14966458Sdfr outb(port, *p++); 15066458Sdfr} 15166458Sdfr 15266458Sdfrstatic __inline void 15366458Sdfroutsw(u_int port, const void *addr, size_t count) 15466458Sdfr{ 15566458Sdfr const u_int16_t *p = addr; 15666458Sdfr while (count--) 15766458Sdfr outw(port, *p++); 15866458Sdfr} 15966458Sdfr 16066458Sdfrstatic __inline void 16166458Sdfroutsl(u_int port, const void *addr, size_t count) 16266458Sdfr{ 16366458Sdfr const u_int32_t *p = addr; 16466458Sdfr while (count--) 16566458Sdfr outl(port, *p++); 16666458Sdfr} 16766458Sdfr 16866458Sdfrstatic __inline u_int8_t 16966458Sdfrreadb(u_int addr) 17066458Sdfr{ 17183836Sdfr volatile u_int8_t *p = ia64_memory_address(addr); 17283836Sdfr u_int8_t v = *p; 17383836Sdfr ia64_mf_a(); 17483836Sdfr ia64_mf(); 17583836Sdfr return v; 17666458Sdfr} 17766458Sdfr 17866458Sdfrstatic __inline u_int16_t 17966458Sdfrreadw(u_int addr) 18066458Sdfr{ 18183836Sdfr volatile u_int16_t *p = ia64_memory_address(addr); 18283836Sdfr u_int16_t v = *p; 18383836Sdfr ia64_mf_a(); 18483836Sdfr ia64_mf(); 18583836Sdfr return v; 18666458Sdfr} 18766458Sdfr 18866458Sdfrstatic __inline u_int32_t 18966458Sdfrreadl(u_int addr) 19066458Sdfr{ 19183836Sdfr volatile u_int32_t *p = ia64_memory_address(addr); 19283836Sdfr u_int32_t v = *p; 19383836Sdfr ia64_mf_a(); 19483836Sdfr ia64_mf(); 19583836Sdfr return v; 19666458Sdfr} 19766458Sdfr 19866458Sdfrstatic __inline void 19966458Sdfrwriteb(u_int addr, u_int8_t data) 20066458Sdfr{ 20183836Sdfr volatile u_int8_t *p = ia64_memory_address(addr); 20283836Sdfr *p = data; 20383836Sdfr ia64_mf_a(); 20483836Sdfr ia64_mf(); 20566458Sdfr} 20666458Sdfr 20766458Sdfrstatic __inline void 20866458Sdfrwritew(u_int addr, u_int16_t data) 20966458Sdfr{ 21083836Sdfr volatile u_int16_t *p = ia64_memory_address(addr); 21183836Sdfr *p = data; 21283836Sdfr ia64_mf_a(); 21383836Sdfr ia64_mf(); 21466458Sdfr} 21566458Sdfr 21666458Sdfrstatic __inline void 21766458Sdfrwritel(u_int addr, u_int32_t data) 21866458Sdfr{ 21983836Sdfr volatile u_int32_t *p = ia64_memory_address(addr); 22083836Sdfr *p = data; 22183836Sdfr ia64_mf_a(); 22283836Sdfr ia64_mf(); 22366458Sdfr} 22466458Sdfr 22566458Sdfrstatic __inline void 22684581Smarcelmemcpy_fromio(u_int8_t *addr, size_t ofs, size_t count) 22784581Smarcel{ 22884581Smarcel volatile u_int8_t *p = ia64_memory_address(ofs); 22984581Smarcel while (count--) 23084581Smarcel *addr++ = *p++; 23184581Smarcel} 23284581Smarcel 23384581Smarcelstatic __inline void 23484581Smarcelmemcpy_io(size_t dst, size_t src, size_t count) 23584581Smarcel{ 23684581Smarcel volatile u_int8_t *dp = ia64_memory_address(dst); 23784581Smarcel volatile u_int8_t *sp = ia64_memory_address(src); 23884581Smarcel while (count--) 23984581Smarcel *dp++ = *sp++; 24084581Smarcel} 24184581Smarcel 24284581Smarcelstatic __inline void 24384581Smarcelmemcpy_toio(size_t ofs, u_int8_t *addr, size_t count) 24484581Smarcel{ 24584581Smarcel volatile u_int8_t *p = ia64_memory_address(ofs); 24684581Smarcel while (count--) 24784581Smarcel *p++ = *addr++; 24884581Smarcel} 24984581Smarcel 25084581Smarcelstatic __inline void 25184581Smarcelmemset_io(size_t ofs, u_int8_t value, size_t count) 25284581Smarcel{ 25384581Smarcel volatile u_int8_t *p = ia64_memory_address(ofs); 25484581Smarcel while (count--) 25584581Smarcel *p++ = value; 25684581Smarcel} 25784581Smarcel 25884581Smarcelstatic __inline void 25984581Smarcelmemsetw(u_int16_t *addr, int val, size_t size) 26084581Smarcel{ 26184581Smarcel while (size--) 26284581Smarcel *addr++ = val; 26384581Smarcel} 26484581Smarcel 26584581Smarcelstatic __inline void 26684581Smarcelmemsetw_io(size_t ofs, u_int16_t value, size_t count) 26784581Smarcel{ 26884581Smarcel volatile u_int16_t *p = ia64_memory_address(ofs); 26984581Smarcel while (count--) 27084581Smarcel *p++ = value; 27184581Smarcel} 27284581Smarcel 27384581Smarcelstatic __inline void 27466458Sdfrdisable_intr(void) 27566458Sdfr{ 27666458Sdfr __asm __volatile ("rsm psr.i;;"); 27766458Sdfr} 27866458Sdfr 27966458Sdfrstatic __inline void 28066458Sdfrenable_intr(void) 28166458Sdfr{ 28266458Sdfr __asm __volatile (";; ssm psr.i;; srlz.d"); 28366458Sdfr} 28466458Sdfr 28574897Sjhbstatic __inline critical_t 28674897Sjhbcritical_enter(void) 28766458Sdfr{ 28874897Sjhb critical_t psr; 28974897Sjhb 29066458Sdfr __asm __volatile ("mov %0=psr;;" : "=r" (psr)); 29174897Sjhb disable_intr(); 29274897Sjhb return (psr); 29366458Sdfr} 29466458Sdfr 29566458Sdfrstatic __inline void 29674897Sjhbcritical_exit(critical_t psr) 29766458Sdfr{ 29866458Sdfr __asm __volatile ("mov psr.l=%0;; srlz.d" :: "r" (psr)); 29966458Sdfr} 30066458Sdfr 30166458Sdfr#endif /* _KERNEL */ 30266458Sdfr 30366458Sdfr#endif /* !_MACHINE_CPUFUNC_H_ */ 304