Home | History | Annotate | Line # | Download | only in include
pio.h revision 1.13
      1  1.13      cgd /*	$NetBSD: pio.h,v 1.13 1996/03/08 20:15:23 cgd Exp $	*/
      2   1.8      cgd 
      3   1.4  mycroft /*
      4  1.11  mycroft  * Copyright (c) 1993, 1995 Charles M. Hannum.  All rights reserved.
      5   1.3      cgd  *
      6   1.4  mycroft  * Redistribution and use in source and binary forms, with or without
      7   1.4  mycroft  * modification, are permitted provided that the following conditions
      8   1.4  mycroft  * are met:
      9   1.4  mycroft  * 1. Redistributions of source code must retain the above copyright
     10   1.4  mycroft  *    notice, this list of conditions and the following disclaimer.
     11   1.4  mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.4  mycroft  *    notice, this list of conditions and the following disclaimer in the
     13   1.4  mycroft  *    documentation and/or other materials provided with the distribution.
     14   1.4  mycroft  * 3. All advertising materials mentioning features or use of this software
     15   1.4  mycroft  *    must display the following acknowledgement:
     16  1.11  mycroft  *      This product includes software developed by Charles M. Hannum.
     17   1.4  mycroft  * 4. The name of the author may not be used to endorse or promote products
     18   1.7      jtc  *    derived from this software without specific prior written permission
     19   1.2      cgd  *
     20   1.4  mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21   1.4  mycroft  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22   1.4  mycroft  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23   1.4  mycroft  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24   1.4  mycroft  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25   1.4  mycroft  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26   1.4  mycroft  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27   1.4  mycroft  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28   1.4  mycroft  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29   1.4  mycroft  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30   1.1      cgd  */
     31   1.1      cgd 
     32  1.13      cgd #ifndef _I386_PIO_H_
     33  1.13      cgd #define _I386_PIO_H_
     34  1.13      cgd 
     35   1.3      cgd /*
     36   1.4  mycroft  * Functions to provide access to i386 programmed I/O instructions.
     37  1.11  mycroft  *
     38  1.11  mycroft  * The in[bwl]() and out[bwl]() functions are split into two varieties: one to
     39  1.11  mycroft  * use a small, constant, 8-bit port number, and another to use a large or
     40  1.11  mycroft  * variable port number.  The former can be compiled as a smaller instruction.
     41   1.3      cgd  */
     42   1.1      cgd 
     43  1.11  mycroft 
     44  1.11  mycroft #ifdef __OPTIMIZE__
     45  1.11  mycroft 
     46  1.11  mycroft #define	__use_immediate_port(port) \
     47  1.11  mycroft 	(__builtin_constant_p((port)) && (port) < 0x100)
     48  1.11  mycroft 
     49  1.11  mycroft #else
     50  1.11  mycroft 
     51  1.11  mycroft #define	__use_immediate_port(port)	0
     52  1.11  mycroft 
     53  1.11  mycroft #endif
     54  1.11  mycroft 
     55  1.11  mycroft 
     56  1.10  mycroft #define	inb(port) \
     57  1.11  mycroft 	(__use_immediate_port(port) ? __inbc(port) : __inb(port))
     58  1.10  mycroft 
     59  1.12  mycroft static __inline u_int8_t
     60  1.10  mycroft __inbc(int port)
     61  1.10  mycroft {
     62  1.12  mycroft 	u_int8_t data;
     63  1.12  mycroft 	__asm __volatile("inb %1,%0" : "=a" (data) : "id" (port));
     64  1.10  mycroft 	return data;
     65  1.10  mycroft }
     66  1.10  mycroft 
     67  1.12  mycroft static __inline u_int8_t
     68  1.10  mycroft __inb(int port)
     69   1.4  mycroft {
     70  1.12  mycroft 	u_int8_t data;
     71  1.12  mycroft 	__asm __volatile("inb %w1,%0" : "=a" (data) : "d" (port));
     72   1.4  mycroft 	return data;
     73   1.4  mycroft }
     74   1.4  mycroft 
     75   1.4  mycroft static __inline void
     76   1.9  mycroft insb(int port, void *addr, int cnt)
     77   1.4  mycroft {
     78  1.11  mycroft 	__asm __volatile("cld\n\trepne\n\tinsb"			:
     79  1.11  mycroft 								:
     80  1.11  mycroft 			 "d" (port), "D" (addr), "c" (cnt)	:
     81  1.11  mycroft 			 "%edi", "%ecx", "memory");
     82   1.4  mycroft }
     83   1.4  mycroft 
     84  1.10  mycroft #define	inw(port) \
     85  1.11  mycroft 	(__use_immediate_port(port) ? __inwc(port) : __inw(port))
     86  1.10  mycroft 
     87  1.12  mycroft static __inline u_int16_t
     88  1.10  mycroft __inwc(int port)
     89  1.10  mycroft {
     90  1.12  mycroft 	u_int16_t data;
     91  1.12  mycroft 	__asm __volatile("inw %1,%0" : "=a" (data) : "id" (port));
     92  1.10  mycroft 	return data;
     93  1.10  mycroft }
     94  1.10  mycroft 
     95  1.12  mycroft static __inline u_int16_t
     96  1.10  mycroft __inw(int port)
     97   1.4  mycroft {
     98  1.12  mycroft 	u_int16_t data;
     99  1.12  mycroft 	__asm __volatile("inw %w1,%0" : "=a" (data) : "d" (port));
    100   1.4  mycroft 	return data;
    101   1.4  mycroft }
    102   1.4  mycroft 
    103   1.4  mycroft static __inline void
    104   1.9  mycroft insw(int port, void *addr, int cnt)
    105   1.4  mycroft {
    106  1.11  mycroft 	__asm __volatile("cld\n\trepne\n\tinsw"			:
    107  1.11  mycroft 								:
    108  1.11  mycroft 			 "d" (port), "D" (addr), "c" (cnt)	:
    109  1.11  mycroft 			 "%edi", "%ecx", "memory");
    110   1.4  mycroft }
    111   1.4  mycroft 
    112  1.10  mycroft #define	inl(port) \
    113  1.11  mycroft 	(__use_immediate_port(port) ? __inlc(port) : __inl(port))
    114  1.10  mycroft 
    115  1.12  mycroft static __inline u_int32_t
    116  1.10  mycroft __inlc(int port)
    117  1.10  mycroft {
    118  1.12  mycroft 	u_int32_t data;
    119  1.12  mycroft 	__asm __volatile("inl %1,%0" : "=a" (data) : "id" (port));
    120  1.10  mycroft 	return data;
    121  1.10  mycroft }
    122  1.10  mycroft 
    123  1.12  mycroft static __inline u_int32_t
    124  1.10  mycroft __inl(int port)
    125   1.4  mycroft {
    126  1.12  mycroft 	u_int32_t data;
    127  1.12  mycroft 	__asm __volatile("inl %w1,%0" : "=a" (data) : "d" (port));
    128   1.4  mycroft 	return data;
    129   1.4  mycroft }
    130   1.4  mycroft 
    131   1.4  mycroft static __inline void
    132   1.9  mycroft insl(int port, void *addr, int cnt)
    133   1.4  mycroft {
    134  1.11  mycroft 	__asm __volatile("cld\n\trepne\n\tinsl"			:
    135  1.11  mycroft 								:
    136  1.11  mycroft 			 "d" (port), "D" (addr), "c" (cnt)	:
    137  1.11  mycroft 			 "%edi", "%ecx", "memory");
    138   1.4  mycroft }
    139   1.4  mycroft 
    140  1.10  mycroft #define	outb(port, data) \
    141  1.11  mycroft 	(__use_immediate_port(port) ? __outbc(port, data) : __outb(port, data))
    142  1.10  mycroft 
    143   1.4  mycroft static __inline void
    144  1.12  mycroft __outbc(int port, u_int8_t data)
    145  1.10  mycroft {
    146  1.12  mycroft 	__asm __volatile("outb %0,%1" : : "a" (data), "id" (port));
    147  1.10  mycroft }
    148  1.10  mycroft 
    149  1.10  mycroft static __inline void
    150  1.12  mycroft __outb(int port, u_int8_t data)
    151   1.4  mycroft {
    152  1.12  mycroft 	__asm __volatile("outb %0,%w1" : : "a" (data), "d" (port));
    153   1.4  mycroft }
    154   1.4  mycroft 
    155   1.4  mycroft static __inline void
    156   1.9  mycroft outsb(int port, void *addr, int cnt)
    157   1.4  mycroft {
    158  1.11  mycroft 	__asm __volatile("cld\n\trepne\n\toutsb"		:
    159  1.11  mycroft 								:
    160  1.11  mycroft 			 "d" (port), "S" (addr), "c" (cnt)	:
    161  1.11  mycroft 			 "%esi", "%ecx");
    162   1.4  mycroft }
    163   1.4  mycroft 
    164  1.10  mycroft #define	outw(port, data) \
    165  1.11  mycroft 	(__use_immediate_port(port) ? __outwc(port, data) : __outw(port, data))
    166  1.10  mycroft 
    167  1.10  mycroft static __inline void
    168  1.12  mycroft __outwc(int port, u_int16_t data)
    169  1.10  mycroft {
    170  1.12  mycroft 	__asm __volatile("outw %0,%1" : : "a" (data), "id" (port));
    171  1.10  mycroft }
    172  1.10  mycroft 
    173   1.4  mycroft static __inline void
    174  1.12  mycroft __outw(int port, u_int16_t data)
    175   1.4  mycroft {
    176  1.12  mycroft 	__asm __volatile("outw %0,%w1" : : "a" (data), "d" (port));
    177   1.4  mycroft }
    178   1.4  mycroft 
    179   1.4  mycroft static __inline void
    180   1.9  mycroft outsw(int port, void *addr, int cnt)
    181   1.4  mycroft {
    182  1.11  mycroft 	__asm __volatile("cld\n\trepne\n\toutsw"		:
    183  1.11  mycroft 								:
    184  1.11  mycroft 			 "d" (port), "S" (addr), "c" (cnt)	:
    185  1.11  mycroft 			 "%esi", "%ecx");
    186   1.4  mycroft }
    187   1.4  mycroft 
    188  1.10  mycroft #define	outl(port, data) \
    189  1.11  mycroft 	(__use_immediate_port(port) ? __outlc(port, data) : __outl(port, data))
    190  1.10  mycroft 
    191  1.10  mycroft static __inline void
    192  1.12  mycroft __outlc(int port, u_int32_t data)
    193  1.10  mycroft {
    194  1.12  mycroft 	__asm __volatile("outl %0,%1" : : "a" (data), "id" (port));
    195  1.10  mycroft }
    196  1.10  mycroft 
    197   1.4  mycroft static __inline void
    198  1.12  mycroft __outl(int port, u_int32_t data)
    199   1.4  mycroft {
    200  1.12  mycroft 	__asm __volatile("outl %0,%w1" : : "a" (data), "d" (port));
    201   1.4  mycroft }
    202   1.4  mycroft 
    203   1.4  mycroft static __inline void
    204   1.9  mycroft outsl(int port, void *addr, int cnt)
    205   1.4  mycroft {
    206  1.11  mycroft 	__asm __volatile("cld\n\trepne\n\toutsl"		:
    207  1.11  mycroft 								:
    208  1.11  mycroft 			 "d" (port), "S" (addr), "c" (cnt)	:
    209  1.11  mycroft 			 "%esi", "%ecx");
    210   1.4  mycroft }
    211  1.13      cgd 
    212  1.13      cgd #endif /* _I386_PIO_H_ */
    213