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