io.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Based on arch/arm/kernel/io.c
  3. *
  4. * Copyright (C) 2012 ARM Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/export.h>
  19. #include <linux/types.h>
  20. #include <linux/io.h>
  21. /*
  22. * Copy data from IO memory space to "real" memory space.
  23. */
  24. void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count)
  25. {
  26. unsigned char *t = to;
  27. while (count) {
  28. count--;
  29. *t = readb(from);
  30. t++;
  31. from++;
  32. }
  33. }
  34. EXPORT_SYMBOL(__memcpy_fromio);
  35. /*
  36. * Copy data from "real" memory space to IO memory space.
  37. */
  38. void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count)
  39. {
  40. const unsigned char *f = from;
  41. while (count) {
  42. count--;
  43. writeb(*f, to);
  44. f++;
  45. to++;
  46. }
  47. }
  48. EXPORT_SYMBOL(__memcpy_toio);
  49. /*
  50. * "memset" on IO memory space.
  51. */
  52. void __memset_io(volatile void __iomem *dst, int c, size_t count)
  53. {
  54. while (count) {
  55. count--;
  56. writeb(c, dst);
  57. dst++;
  58. }
  59. }
  60. EXPORT_SYMBOL(__memset_io);