inout_bwl.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Phil Blundell, based on the Alpha version by
  4. David Mosberger.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with the GNU C Library; see the file COPYING.LIB. If not,
  15. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. Boston, MA 02111-1307, USA. */
  17. /* I/O port access on the ARM is something of a fiction. What we do is to
  18. map an appropriate area of /dev/mem into user space so that a program
  19. can blast away at the hardware in such a way as to generate I/O cycles
  20. on the bus. To insulate user code from dependencies on particular
  21. hardware we don't allow calls to inb() and friends to be inlined, but
  22. force them to come through code in here every time. Performance-critical
  23. registers tend to be memory mapped these days so this should be no big
  24. problem. */
  25. /* Once upon a time this file used mprotect to enable and disable
  26. access to particular areas of I/O space. Unfortunately the
  27. mprotect syscall also has the side effect of enabling caching for
  28. the area affected (this is a kernel limitation). So we now just
  29. enable all the ports all of the time. */
  30. #include <errno.h>
  31. #include <fcntl.h>
  32. #include <stdio.h>
  33. #include <ctype.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #include <unistd.h>
  37. #include <sys/types.h>
  38. #include <sys/types.h>
  39. #include <sys/mman.h>
  40. #define IO_BASE 0x7c000000
  41. #define IO_SHIFT 0
  42. #define IO_ADDR(port) (IO_BASE + ((port) << IO_SHIFT))
  43. void outb (unsigned char b, unsigned long int port)
  44. {
  45. *((volatile unsigned char *)(IO_ADDR (port))) = b;
  46. }
  47. void outw (unsigned short b, unsigned long int port)
  48. {
  49. *((volatile unsigned short *)(IO_ADDR (port))) = b;
  50. }
  51. void outl (unsigned int b, unsigned long int port)
  52. {
  53. *((volatile unsigned long *)(IO_ADDR (port))) = b;
  54. }
  55. unsigned int inb (unsigned long int port)
  56. {
  57. return *((volatile unsigned char *)(IO_ADDR (port)));
  58. }
  59. unsigned int inw (unsigned long int port)
  60. {
  61. return *((volatile unsigned short *)(IO_ADDR (port)));
  62. }
  63. unsigned int inl (unsigned long int port)
  64. {
  65. return *((volatile unsigned long *)(IO_ADDR (port)));
  66. }