io.h 5.0 KB

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