io.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* Copyright (C) 1996, 2000 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #ifndef _SYS_IO_H
  16. #define _SYS_IO_H 1
  17. #include <features.h>
  18. __BEGIN_DECLS
  19. #if defined __UCLIBC_LINUX_SPECIFIC__
  20. /* If TURN_ON is TRUE, request for permission to do direct i/o on the
  21. port numbers in the range [FROM,FROM+NUM-1]. Otherwise, turn I/O
  22. permission off for that range. This call requires root privileges.
  23. Portability note: not all Linux platforms support this call. Most
  24. platforms based on the PC I/O architecture probably will, however.
  25. E.g., Linux/Alpha for Alpha PCs supports this. */
  26. extern int ioperm (unsigned long int __from, unsigned long int __num,
  27. int __turn_on) __THROW;
  28. libc_hidden_proto(ioperm)
  29. /* Set the I/O privilege level to LEVEL. If LEVEL>3, permission to
  30. access any I/O port is granted. This call requires root
  31. privileges. */
  32. extern int iopl (int __level) __THROW;
  33. #endif /* __UCLIBC_LINUX_SPECIFIC__ */
  34. #if defined __GNUC__ && __GNUC__ >= 2
  35. static __inline unsigned char
  36. inb (unsigned short int port)
  37. {
  38. unsigned char _v;
  39. __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
  40. return _v;
  41. }
  42. static __inline unsigned char
  43. inb_p (unsigned short int port)
  44. {
  45. unsigned char _v;
  46. __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
  47. return _v;
  48. }
  49. static __inline unsigned short int
  50. inw (unsigned short int port)
  51. {
  52. unsigned short _v;
  53. __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port));
  54. return _v;
  55. }
  56. static __inline unsigned short int
  57. inw_p (unsigned short int port)
  58. {
  59. unsigned short int _v;
  60. __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
  61. return _v;
  62. }
  63. static __inline unsigned int
  64. inl (unsigned short int port)
  65. {
  66. unsigned int _v;
  67. __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port));
  68. return _v;
  69. }
  70. static __inline unsigned int
  71. inl_p (unsigned short int port)
  72. {
  73. unsigned int _v;
  74. __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
  75. return _v;
  76. }
  77. static __inline void
  78. outb (unsigned char value, unsigned short int port)
  79. {
  80. __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
  81. }
  82. static __inline void
  83. outb_p (unsigned char value, unsigned short int port)
  84. {
  85. __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value),
  86. "Nd" (port));
  87. }
  88. static __inline void
  89. outw (unsigned short int value, unsigned short int port)
  90. {
  91. __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
  92. }
  93. static __inline void
  94. outw_p (unsigned short int value, unsigned short int port)
  95. {
  96. __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value),
  97. "Nd" (port));
  98. }
  99. static __inline void
  100. outl (unsigned int value, unsigned short int port)
  101. {
  102. __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
  103. }
  104. static __inline void
  105. outl_p (unsigned int value, unsigned short int port)
  106. {
  107. __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value),
  108. "Nd" (port));
  109. }
  110. static __inline void
  111. insb (unsigned short int port, void *addr, unsigned long int count)
  112. {
  113. __asm__ __volatile__ ("cld ; rep ; insb":"=D" (addr),
  114. "=c" (count):"d" (port), "0" (addr), "1" (count));
  115. }
  116. static __inline void
  117. insw (unsigned short int port, void *addr, unsigned long int count)
  118. {
  119. __asm__ __volatile__ ("cld ; rep ; insw":"=D" (addr),
  120. "=c" (count):"d" (port), "0" (addr), "1" (count));
  121. }
  122. static __inline void
  123. insl (unsigned short int port, void *addr, unsigned long int count)
  124. {
  125. __asm__ __volatile__ ("cld ; rep ; insl":"=D" (addr),
  126. "=c" (count):"d" (port), "0" (addr), "1" (count));
  127. }
  128. static __inline void
  129. outsb (unsigned short int port, const void *addr, unsigned long int count)
  130. {
  131. __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (addr),
  132. "=c" (count):"d" (port), "0" (addr), "1" (count));
  133. }
  134. static __inline void
  135. outsw (unsigned short int port, const void *addr, unsigned long int count)
  136. {
  137. __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (addr),
  138. "=c" (count):"d" (port), "0" (addr), "1" (count));
  139. }
  140. static __inline void
  141. outsl (unsigned short int port, const void *addr, unsigned long int count)
  142. {
  143. __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (addr),
  144. "=c" (count):"d" (port), "0" (addr), "1" (count));
  145. }
  146. #endif /* GNU C */
  147. __END_DECLS
  148. #endif /* _SYS_IO_H */