io.h 4.9 KB

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