io.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* Copyright (C) 1996, 2000, 2002 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 TURN_ON is TRUE, request for permission to do direct i/o on the
  20. port numbers in the range [FROM,FROM+NUM-1]. Otherwise, turn I/O
  21. permission off for that range. This call requires root privileges.
  22. Portability note: not all Linux platforms support this call. Most
  23. platforms based on the PC I/O architecture probably will, however.
  24. E.g., Linux/Alpha for Alpha PCs supports this. */
  25. extern int ioperm (unsigned long int __from, unsigned long int __num,
  26. int __turn_on) __THROW;
  27. /* Set the I/O privilege level to LEVEL. If LEVEL>3, permission to
  28. access any I/O port is granted. This call requires root
  29. privileges. */
  30. extern int iopl (int __level) __THROW;
  31. #if defined __GNUC__ && __GNUC__ >= 2
  32. static __inline unsigned char
  33. inb (unsigned short int port)
  34. {
  35. unsigned char _v;
  36. __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
  37. return _v;
  38. }
  39. static __inline unsigned char
  40. inb_p (unsigned short int port)
  41. {
  42. unsigned char _v;
  43. __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
  44. return _v;
  45. }
  46. static __inline unsigned short int
  47. inw (unsigned short int port)
  48. {
  49. unsigned short _v;
  50. __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port));
  51. return _v;
  52. }
  53. static __inline unsigned short int
  54. inw_p (unsigned short int port)
  55. {
  56. unsigned short int _v;
  57. __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
  58. return _v;
  59. }
  60. static __inline unsigned int
  61. inl (unsigned short int port)
  62. {
  63. unsigned int _v;
  64. __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port));
  65. return _v;
  66. }
  67. static __inline unsigned int
  68. inl_p (unsigned short int port)
  69. {
  70. unsigned int _v;
  71. __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
  72. return _v;
  73. }
  74. static __inline void
  75. outb (unsigned char value, unsigned short int port)
  76. {
  77. __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
  78. }
  79. static __inline void
  80. outb_p (unsigned char value, unsigned short int port)
  81. {
  82. __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value),
  83. "Nd" (port));
  84. }
  85. static __inline void
  86. outw (unsigned short int value, unsigned short int port)
  87. {
  88. __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
  89. }
  90. static __inline void
  91. outw_p (unsigned short int value, unsigned short int port)
  92. {
  93. __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value),
  94. "Nd" (port));
  95. }
  96. static __inline void
  97. outl (unsigned int value, unsigned short int port)
  98. {
  99. __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
  100. }
  101. static __inline void
  102. outl_p (unsigned int value, unsigned short int port)
  103. {
  104. __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value),
  105. "Nd" (port));
  106. }
  107. static __inline void
  108. insb (unsigned short int port, void *addr, unsigned long int count)
  109. {
  110. __asm__ __volatile__ ("cld ; rep ; insb":"=D" (addr),
  111. "=c" (count):"d" (port), "0" (addr), "1" (count));
  112. }
  113. static __inline void
  114. insw (unsigned short int port, void *addr, unsigned long int count)
  115. {
  116. __asm__ __volatile__ ("cld ; rep ; insw":"=D" (addr),
  117. "=c" (count):"d" (port), "0" (addr), "1" (count));
  118. }
  119. static __inline void
  120. insl (unsigned short int port, void *addr, unsigned long int count)
  121. {
  122. __asm__ __volatile__ ("cld ; rep ; insl":"=D" (addr),
  123. "=c" (count):"d" (port), "0" (addr), "1" (count));
  124. }
  125. static __inline void
  126. outsb (unsigned short int port, const void *addr, unsigned long int count)
  127. {
  128. __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (addr),
  129. "=c" (count):"d" (port), "0" (addr), "1" (count));
  130. }
  131. static __inline void
  132. outsw (unsigned short int port, const void *addr, unsigned long int count)
  133. {
  134. __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (addr),
  135. "=c" (count):"d" (port), "0" (addr), "1" (count));
  136. }
  137. static __inline void
  138. outsl (unsigned short int port, const void *addr, unsigned long int count)
  139. {
  140. __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (addr),
  141. "=c" (count):"d" (port), "0" (addr), "1" (count));
  142. }
  143. #endif /* GNU C */
  144. __END_DECLS
  145. #endif /* _SYS_IO_H */