1c06b6b69Smrg/* 2c06b6b69Smrg * (c) Copyright 1993,1994 by David Wexelblat <dwex@xfree86.org> 3c06b6b69Smrg * 4c06b6b69Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5c06b6b69Smrg * copy of this software and associated documentation files (the "Software"), 6c06b6b69Smrg * to deal in the Software without restriction, including without limitation 7c06b6b69Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8c06b6b69Smrg * and/or sell copies of the Software, and to permit persons to whom the 9c06b6b69Smrg * Software is furnished to do so, subject to the following conditions: 10c06b6b69Smrg * 11c06b6b69Smrg * The above copyright notice and this permission notice shall be included in 12c06b6b69Smrg * all copies or substantial portions of the Software. 13c06b6b69Smrg * 14c06b6b69Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15c06b6b69Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16c06b6b69Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17c06b6b69Smrg * DAVID WEXELBLAT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18c06b6b69Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 19c06b6b69Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20c06b6b69Smrg * SOFTWARE. 21c06b6b69Smrg * 22c06b6b69Smrg * Except as contained in this notice, the name of David Wexelblat shall not be 23c06b6b69Smrg * used in advertising or otherwise to promote the sale, use or other dealings 24c06b6b69Smrg * in this Software without prior written authorization from David Wexelblat. 25c06b6b69Smrg * 26c06b6b69Smrg */ 27c06b6b69Smrg/* 28c06b6b69Smrg * Copyright 1997 29c06b6b69Smrg * Digital Equipment Corporation. All rights reserved. 30c06b6b69Smrg * This software is furnished under license and may be used and copied only in 31c06b6b69Smrg * accordance with the following terms and conditions. Subject to these 32c06b6b69Smrg * conditions, you may download, copy, install, use, modify and distribute 33c06b6b69Smrg * this software in source and/or binary form. No title or ownership is 34c06b6b69Smrg * transferred hereby. 35c06b6b69Smrg * 36c06b6b69Smrg * 1) Any source code used, modified or distributed must reproduce and retain 37c06b6b69Smrg * this copyright notice and list of conditions as they appear in the source 38c06b6b69Smrg * file. 39c06b6b69Smrg * 40c06b6b69Smrg * 2) No right is granted to use any trade name, trademark, or logo of Digital 41c06b6b69Smrg * Equipment Corporation. Neither the "Digital Equipment Corporation" name 42c06b6b69Smrg * nor any trademark or logo of Digital Equipment Corporation may be used 43c06b6b69Smrg * to endorse or promote products derived from this software without the 44c06b6b69Smrg * prior written permission of Digital Equipment Corporation. 45c06b6b69Smrg * 46c06b6b69Smrg * 3) This software is provided "AS-IS" and any express or implied warranties, 47c06b6b69Smrg * including but not limited to, any implied warranties of merchantability, 48c06b6b69Smrg * fitness for a particular purpose, or non-infringement are disclaimed. In 49c06b6b69Smrg * no event shall DIGITAL be liable for any damages whatsoever, and in 50c06b6b69Smrg * particular, DIGITAL shall not be liable for special, indirect, 51c06b6b69Smrg * consequential, or incidental damages or damages for 52c06b6b69Smrg * lost profits, loss of revenue or loss of use, whether such damages arise 53c06b6b69Smrg * in contract, 54c06b6b69Smrg * negligence, tort, under statute, in equity, at law or otherwise, even if 55c06b6b69Smrg * advised of the possibility of such damage. 56c06b6b69Smrg * 57c06b6b69Smrg */ 58c06b6b69Smrg 59c06b6b69Smrg 60c06b6b69Smrg#if defined(__GNUC__) 61c06b6b69Smrg#if defined(linux) && (defined(__alpha__) || defined(__ia64__)) 62c06b6b69Smrg#undef inb 63c06b6b69Smrg#undef inw 64c06b6b69Smrg#undef inl 65c06b6b69Smrg#undef outb 66c06b6b69Smrg#undef outw 67c06b6b69Smrg#undef outl 68c06b6b69Smrg#define inb _inb 69c06b6b69Smrg#define inw _inw 70c06b6b69Smrg#define inl _inl 71c06b6b69Smrg#define outb(p,v) _outb((v),(p)) 72c06b6b69Smrg#define outw(p,v) _outw((v),(p)) 73c06b6b69Smrg#define outl(p,v) _outl((v),(p)) 74c06b6b69Smrg#else 75c06b6b69Smrg#if defined(__sparc__) 76c06b6b69Smrg#ifndef ASI_PL 77c06b6b69Smrg#define ASI_PL 0x88 78c06b6b69Smrg#endif 79c06b6b69Smrg 80c06b6b69Smrgstatic __inline__ void 8172320d7bSmrgoutb(unsigned long port, char val) 82c06b6b69Smrg{ 83c06b6b69Smrg __asm__ __volatile__("stba %0, [%1] %2" : : "r" (val), "r" (port), "i" (ASI_PL)); 84c06b6b69Smrg} 85c06b6b69Smrg 86c06b6b69Smrgstatic __inline__ void 8772320d7bSmrgoutw(unsigned long port, char val) 88c06b6b69Smrg{ 89c06b6b69Smrg __asm__ __volatile__("stha %0, [%1] %2" : : "r" (val), "r" (port), "i" (ASI_PL)); 90c06b6b69Smrg} 91c06b6b69Smrg 92c06b6b69Smrgstatic __inline__ void 9372320d7bSmrgoutl(unsigned long port, char val) 94c06b6b69Smrg{ 95c06b6b69Smrg __asm__ __volatile__("sta %0, [%1] %2" : : "r" (val), "r" (port), "i" (ASI_PL)); 96c06b6b69Smrg} 97c06b6b69Smrg 98c06b6b69Smrgstatic __inline__ unsigned int 9972320d7bSmrginb(unsigned long port) 100c06b6b69Smrg{ 101c06b6b69Smrg unsigned char ret; 102c06b6b69Smrg __asm__ __volatile__("lduba [%1] %2, %0" : "=r" (ret) : "r" (port), "i" (ASI_PL)); 103c06b6b69Smrg return ret; 104c06b6b69Smrg} 105c06b6b69Smrg 106c06b6b69Smrgstatic __inline__ unsigned int 10772320d7bSmrginw(unsigned long port) 108c06b6b69Smrg{ 109c06b6b69Smrg unsigned char ret; 110c06b6b69Smrg __asm__ __volatile__("lduha [%1] %2, %0" : "=r" (ret) : "r" (port), "i" (ASI_PL)); 111c06b6b69Smrg return ret; 112c06b6b69Smrg} 113c06b6b69Smrg 114c06b6b69Smrgstatic __inline__ unsigned int 11572320d7bSmrginl(unsigned long port) 116c06b6b69Smrg{ 117c06b6b69Smrg unsigned char ret; 118c06b6b69Smrg __asm__ __volatile__("lda [%1] %2, %0" : "=r" (ret) : "r" (port), "i" (ASI_PL)); 119c06b6b69Smrg return ret; 120c06b6b69Smrg} 121c06b6b69Smrg#else 122c06b6b69Smrg#ifdef __arm32__ 123ad01e365Sjoergextern unsigned int IOPortBase; /* Memory mapped I/O port area */ 124c06b6b69Smrg 125c06b6b69Smrgstatic __inline__ void 12672320d7bSmrgoutb(short port, char val) 127c06b6b69Smrg{ 128c06b6b69Smrg if ((unsigned short)port >= 0x400) return; 129c06b6b69Smrg 130c06b6b69Smrg *(volatile unsigned char*)(((unsigned short)(port))+IOPortBase) = val; 131c06b6b69Smrg} 132c06b6b69Smrg 133c06b6b69Smrgstatic __inline__ void 13472320d7bSmrgoutw(short port, short val) 135c06b6b69Smrg{ 136c06b6b69Smrg if ((unsigned short)port >= 0x400) return; 137c06b6b69Smrg 138c06b6b69Smrg *(volatile unsigned short*)(((unsigned short)(port))+IOPortBase) = val; 139c06b6b69Smrg} 140c06b6b69Smrg 141c06b6b69Smrgstatic __inline__ void 14272320d7bSmrgoutl(short port, int val) 143c06b6b69Smrg{ 144c06b6b69Smrg if ((unsigned short)port >= 0x400) return; 145c06b6b69Smrg 146c06b6b69Smrg *(volatile unsigned long*)(((unsigned short)(port))+IOPortBase) = val; 147c06b6b69Smrg} 148c06b6b69Smrg 149c06b6b69Smrgstatic __inline__ unsigned int 15072320d7bSmrginb(short port) 151c06b6b69Smrg{ 152c06b6b69Smrg if ((unsigned short)port >= 0x400) return((unsigned int)-1); 153c06b6b69Smrg 154c06b6b69Smrg return(*(volatile unsigned char*)(((unsigned short)(port))+IOPortBase)); 155c06b6b69Smrg} 156c06b6b69Smrg 157c06b6b69Smrgstatic __inline__ unsigned int 15872320d7bSmrginw(short port) 159c06b6b69Smrg{ 160c06b6b69Smrg if ((unsigned short)port >= 0x400) return((unsigned int)-1); 161c06b6b69Smrg 162c06b6b69Smrg return(*(volatile unsigned short*)(((unsigned short)(port))+IOPortBase)); 163c06b6b69Smrg} 164c06b6b69Smrg 165c06b6b69Smrgstatic __inline__ unsigned int 16672320d7bSmrginl(short port) 167c06b6b69Smrg{ 168c06b6b69Smrg if ((unsigned short)port >= 0x400) return((unsigned int)-1); 169c06b6b69Smrg 170c06b6b69Smrg return(*(volatile unsigned long*)(((unsigned short)(port))+IOPortBase)); 171c06b6b69Smrg} 172c06b6b69Smrg#else /* __arm32__ */ 173c06b6b69Smrg#if defined(__FreeBSD__) && defined(__alpha__) 174c06b6b69Smrg 175c06b6b69Smrg#include <sys/types.h> 176c06b6b69Smrg 177c06b6b69Smrgextern void outb(u_int32_t port, u_int8_t val); 178c06b6b69Smrgextern void outw(u_int32_t port, u_int16_t val); 179c06b6b69Smrgextern void outl(u_int32_t port, u_int32_t val); 180c06b6b69Smrgextern u_int8_t inb(u_int32_t port); 181c06b6b69Smrgextern u_int16_t inw(u_int32_t port); 182c06b6b69Smrgextern u_int32_t inl(u_int32_t port); 183c06b6b69Smrg 184c06b6b69Smrg#else 185c06b6b69Smrg#ifdef GCCUSESGAS 186c06b6b69Smrgstatic __inline__ void 18772320d7bSmrgoutb(short port, char val) 188c06b6b69Smrg{ 189c06b6b69Smrg __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port)); 190c06b6b69Smrg} 191c06b6b69Smrg 192c06b6b69Smrgstatic __inline__ void 19372320d7bSmrgoutw(short portm, short val) 194c06b6b69Smrg{ 195c06b6b69Smrg __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port)); 196c06b6b69Smrg} 197c06b6b69Smrg 198c06b6b69Smrgstatic __inline__ void 19972320d7bSmrgoutl(short port, unsigned int val) 200c06b6b69Smrg{ 201c06b6b69Smrg __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port)); 202c06b6b69Smrg} 203c06b6b69Smrg 204c06b6b69Smrgstatic __inline__ unsigned int 20572320d7bSmrginb(short port) 206c06b6b69Smrg{ 207c06b6b69Smrg unsigned char ret; 208c06b6b69Smrg __asm__ __volatile__("inb %1,%0" : 209c06b6b69Smrg "=a" (ret) : 210c06b6b69Smrg "d" (port)); 211c06b6b69Smrg return ret; 212c06b6b69Smrg} 213c06b6b69Smrg 214c06b6b69Smrgstatic __inline__ unsigned int 21572320d7bSmrginw(short port) 216c06b6b69Smrg{ 217c06b6b69Smrg unsigned short ret; 218c06b6b69Smrg __asm__ __volatile__("inw %1,%0" : 219c06b6b69Smrg "=a" (ret) : 220c06b6b69Smrg "d" (port)); 221c06b6b69Smrg return ret; 222c06b6b69Smrg} 223c06b6b69Smrg 224c06b6b69Smrgstatic __inline__ unsigned int 22572320d7bSmrginl(short port) 226c06b6b69Smrg{ 227c06b6b69Smrg unsigned int ret; 228c06b6b69Smrg __asm__ __volatile__("inl %1,%0" : 229c06b6b69Smrg "=a" (ret) : 230c06b6b69Smrg "d" (port)); 231c06b6b69Smrg return ret; 232c06b6b69Smrg} 233c06b6b69Smrg 234c06b6b69Smrg#else /* GCCUSESGAS */ 235c06b6b69Smrg 236c06b6b69Smrgstatic __inline__ void 23772320d7bSmrgoutb(short port, char val) 238c06b6b69Smrg{ 239c06b6b69Smrg __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port)); 240c06b6b69Smrg} 241c06b6b69Smrg 242c06b6b69Smrgstatic __inline__ void 24372320d7bSmrgoutw(short port, short val) 244c06b6b69Smrg{ 245c06b6b69Smrg __asm__ __volatile__("out%W0 (%1)" : :"a" (val), "d" (port)); 246c06b6b69Smrg} 247c06b6b69Smrg 248c06b6b69Smrgstatic __inline__ void 24972320d7bSmrgoutl(short port, unsigned int val) 250c06b6b69Smrg{ 251c06b6b69Smrg __asm__ __volatile__("out%L0 (%1)" : :"a" (val), "d" (port)); 252c06b6b69Smrg} 253c06b6b69Smrg 254c06b6b69Smrgstatic __inline__ unsigned int 25572320d7bSmrginb(short port) 256c06b6b69Smrg{ 257c06b6b69Smrg unsigned int ret; 258c06b6b69Smrg __asm__ __volatile__("in%B0 (%1)" : 259c06b6b69Smrg "=a" (ret) : 260c06b6b69Smrg "d" (port)); 261c06b6b69Smrg return ret; 262c06b6b69Smrg} 263c06b6b69Smrg 264c06b6b69Smrgstatic __inline__ unsigned int 26572320d7bSmrginw(short port) 266c06b6b69Smrg{ 267c06b6b69Smrg unsigned int ret; 268c06b6b69Smrg __asm__ __volatile__("in%W0 (%1)" : 269c06b6b69Smrg "=a" (ret) : 270c06b6b69Smrg "d" (port)); 271c06b6b69Smrg return ret; 272c06b6b69Smrg} 273c06b6b69Smrg 274c06b6b69Smrgstatic __inline__ unsigned int 27572320d7bSmrginl(short port) 276c06b6b69Smrg{ 277c06b6b69Smrg unsigned int ret; 278c06b6b69Smrg __asm__ __volatile__("in%L0 (%1)" : 279c06b6b69Smrg "=a" (ret) : 280c06b6b69Smrg "d" (port)); 281c06b6b69Smrg return ret; 282c06b6b69Smrg} 283c06b6b69Smrg 284c06b6b69Smrg#endif /* GCCUSESGAS */ 285c06b6b69Smrg#endif /* arm32 */ 286c06b6b69Smrg#endif /* linux && __sparc__ */ 287c06b6b69Smrg#endif /* linux && __alpha__ */ 288c06b6b69Smrg#endif /* __FreeBSD__ && __alpha__ */ 289c06b6b69Smrg 29072320d7bSmrg#if defined(linux) || defined(__arm32__) 291c06b6b69Smrg 292c06b6b69Smrg#define intr_disable() 293c06b6b69Smrg#define intr_enable() 294c06b6b69Smrg 295c06b6b69Smrg#else 296c06b6b69Smrg 297c06b6b69Smrgstatic __inline__ void 29872320d7bSmrgintr_disable(void) 299c06b6b69Smrg{ 300c06b6b69Smrg __asm__ __volatile__("cli"); 301c06b6b69Smrg} 302c06b6b69Smrg 303c06b6b69Smrgstatic __inline__ void 30472320d7bSmrgintr_enable(void) 305c06b6b69Smrg{ 306c06b6b69Smrg __asm__ __volatile__("sti"); 307c06b6b69Smrg} 308c06b6b69Smrg 309c06b6b69Smrg#endif /* else !linux && !__arm32__ */ 310c06b6b69Smrg 311c06b6b69Smrg#else /* __GNUC__ */ 312c06b6b69Smrg 313c06b6b69Smrg#if defined(_MINIX) && defined(_ACK) 314c06b6b69Smrg 315c06b6b69Smrg/* inb, outb, inw and outw are defined in the library */ 316c06b6b69Smrg/* ... but I've no idea if the same is true for inl & outl */ 317c06b6b69Smrg 318c06b6b69Smrgu8_t inb(U16_t); 319c06b6b69Smrgvoid outb(U16_t, U8_t); 320c06b6b69Smrgu16_t inw(U16_t); 321c06b6b69Smrgvoid outw(U16_t, U16_t); 322c06b6b69Smrgu32_t inl(U16_t); 323c06b6b69Smrgvoid outl(U16_t, U32_t); 324c06b6b69Smrg 325c06b6b69Smrg#else /* not _MINIX and _ACK */ 326c06b6b69Smrg 327c06b6b69Smrg# if defined(__STDC__) && (__STDC__ == 1) 328c06b6b69Smrg# define asm __asm 329c06b6b69Smrg# endif 330c06b6b69Smrg# ifdef SVR4 331c06b6b69Smrg# include <sys/types.h> 332c06b6b69Smrg# endif 33372320d7bSmrg# include <sys/inline.h> 334c06b6b69Smrg# define intr_disable() asm("cli") 335c06b6b69Smrg# define intr_enable() asm("sti") 336c06b6b69Smrg 337c06b6b69Smrg#endif /* _MINIX and _ACK */ 338c06b6b69Smrg#endif /* __GNUC__ */ 339