io.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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, 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 defined __UCLIBC_LINUX_SPECIFIC__
  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. #endif /* __UCLIBC_LINUX_SPECIFIC__ */
  32. #if defined __GNUC__ && __GNUC__ >= 2
  33. static __inline unsigned char
  34. inb (unsigned short int port)
  35. {
  36. unsigned char _v;
  37. __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port));
  38. return _v;
  39. }
  40. static __inline unsigned char
  41. inb_p (unsigned short int port)
  42. {
  43. unsigned char _v;
  44. __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
  45. return _v;
  46. }
  47. static __inline unsigned short int
  48. inw (unsigned short int port)
  49. {
  50. unsigned short _v;
  51. __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port));
  52. return _v;
  53. }
  54. static __inline unsigned short int
  55. inw_p (unsigned short int port)
  56. {
  57. unsigned short int _v;
  58. __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
  59. return _v;
  60. }
  61. static __inline unsigned int
  62. inl (unsigned short int port)
  63. {
  64. unsigned int _v;
  65. __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port));
  66. return _v;
  67. }
  68. static __inline unsigned int
  69. inl_p (unsigned short int port)
  70. {
  71. unsigned int _v;
  72. __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (port));
  73. return _v;
  74. }
  75. static __inline void
  76. outb (unsigned char value, unsigned short int port)
  77. {
  78. __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port));
  79. }
  80. static __inline void
  81. outb_p (unsigned char value, unsigned short int port)
  82. {
  83. __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (value),
  84. "Nd" (port));
  85. }
  86. static __inline void
  87. outw (unsigned short int value, unsigned short int port)
  88. {
  89. __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port));
  90. }
  91. static __inline void
  92. outw_p (unsigned short int value, unsigned short int port)
  93. {
  94. __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (value),
  95. "Nd" (port));
  96. }
  97. static __inline void
  98. outl (unsigned int value, unsigned short int port)
  99. {
  100. __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port));
  101. }
  102. static __inline void
  103. outl_p (unsigned int value, unsigned short int port)
  104. {
  105. __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (value),
  106. "Nd" (port));
  107. }
  108. static __inline void
  109. insb (unsigned short int port, void *addr, unsigned long int count)
  110. {
  111. __asm__ __volatile__ ("cld ; rep ; insb":"=D" (addr),
  112. "=c" (count):"d" (port), "0" (addr), "1" (count));
  113. }
  114. static __inline void
  115. insw (unsigned short int port, void *addr, unsigned long int count)
  116. {
  117. __asm__ __volatile__ ("cld ; rep ; insw":"=D" (addr),
  118. "=c" (count):"d" (port), "0" (addr), "1" (count));
  119. }
  120. static __inline void
  121. insl (unsigned short int port, void *addr, unsigned long int count)
  122. {
  123. __asm__ __volatile__ ("cld ; rep ; insl":"=D" (addr),
  124. "=c" (count):"d" (port), "0" (addr), "1" (count));
  125. }
  126. static __inline void
  127. outsb (unsigned short int port, const void *addr, unsigned long int count)
  128. {
  129. __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (addr),
  130. "=c" (count):"d" (port), "0" (addr), "1" (count));
  131. }
  132. static __inline void
  133. outsw (unsigned short int port, const void *addr, unsigned long int count)
  134. {
  135. __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (addr),
  136. "=c" (count):"d" (port), "0" (addr), "1" (count));
  137. }
  138. static __inline void
  139. outsl (unsigned short int port, const void *addr, unsigned long int count)
  140. {
  141. __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (addr),
  142. "=c" (count):"d" (port), "0" (addr), "1" (count));
  143. }
  144. #endif /* GNU C */
  145. __END_DECLS
  146. #endif /* _SYS_IO_H */