io.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 Library General Public License as
  5. published by the Free Software Foundation; either version 2 of the
  6. 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. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with the GNU C Library; see the file COPYING.LIB. If not,
  13. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. Boston, MA 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 __P ((unsigned long int __from, unsigned long int __num,
  26. int __turn_on));
  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 __P ((int __level));
  31. extern inline unsigned char
  32. inb (unsigned short port)
  33. {
  34. unsigned char _v;
  35. __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
  36. return _v;
  37. }
  38. extern inline unsigned char
  39. inb_p (unsigned short port)
  40. {
  41. unsigned char _v;
  42. __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
  43. return _v;
  44. }
  45. extern inline unsigned short
  46. inw (unsigned short port)
  47. {
  48. unsigned short _v;
  49. __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port));
  50. return _v;
  51. }
  52. extern inline unsigned short
  53. inw_p (unsigned short port)
  54. {
  55. unsigned short _v;
  56. __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
  57. return _v;
  58. }
  59. extern inline unsigned int
  60. inl (unsigned short port)
  61. {
  62. unsigned int _v;
  63. __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port));
  64. return _v;
  65. }
  66. extern inline unsigned int
  67. inl_p (unsigned short port)
  68. {
  69. unsigned int _v;
  70. __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
  71. return _v;
  72. }
  73. extern inline void
  74. outb (unsigned char value, unsigned short port)
  75. {
  76. __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
  77. }
  78. extern inline void
  79. outb_p (unsigned char value, unsigned short port)
  80. {
  81. __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value),
  82. "Nd" (port));
  83. }
  84. extern inline void
  85. outw (unsigned short value, unsigned short port)
  86. {
  87. __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
  88. }
  89. extern inline void
  90. outw_p (unsigned short value, unsigned short port)
  91. {
  92. __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value),
  93. "Nd" (port));
  94. }
  95. extern inline void
  96. outl (unsigned int value, unsigned short port)
  97. {
  98. __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
  99. }
  100. extern inline void
  101. outl_p (unsigned int value, unsigned short port)
  102. {
  103. __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value),
  104. "Nd" (port));
  105. }
  106. extern inline void
  107. insb (unsigned short port, void *addr, unsigned long count)
  108. {
  109. __asm__ __volatile__ ("cld ; rep ; insb":"=D" (addr),
  110. "=c" (count):"d" (port), "0" (addr), "1" (count));
  111. }
  112. extern inline void
  113. insw (unsigned short port, void *addr, unsigned long count)
  114. {
  115. __asm__ __volatile__ ("cld ; rep ; insw":"=D" (addr),
  116. "=c" (count):"d" (port), "0" (addr), "1" (count));
  117. }
  118. extern inline void
  119. insl (unsigned short port, void *addr, unsigned long count)
  120. {
  121. __asm__ __volatile__ ("cld ; rep ; insl":"=D" (addr),
  122. "=c" (count):"d" (port), "0" (addr), "1" (count));
  123. }
  124. extern inline void
  125. outsb (unsigned short port, const void *addr, unsigned long count)
  126. {
  127. __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (addr),
  128. "=c" (count):"d" (port), "0" (addr), "1" (count));
  129. }
  130. extern inline void
  131. outsw (unsigned short port, const void *addr, unsigned long count)
  132. {
  133. __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (addr),
  134. "=c" (count):"d" (port), "0" (addr), "1" (count));
  135. }
  136. extern inline void
  137. outsl (unsigned short port, const void *addr, unsigned long count)
  138. {
  139. __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (addr),
  140. "=c" (count):"d" (port), "0" (addr), "1" (count));
  141. }
  142. __END_DECLS
  143. #endif /* _SYS_IO_H */