iomap_copy.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 2006 PathScale, Inc. All Rights Reserved.
  3. *
  4. * This file is free software; you can redistribute it and/or modify
  5. * it under the terms of version 2 of the GNU General Public License
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software Foundation,
  15. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  16. */
  17. #include <linux/module.h>
  18. #include <linux/io.h>
  19. /**
  20. * __iowrite32_copy - copy data to MMIO space, in 32-bit units
  21. * @to: destination, in MMIO space (must be 32-bit aligned)
  22. * @from: source (must be 32-bit aligned)
  23. * @count: number of 32-bit quantities to copy
  24. *
  25. * Copy data from kernel space to MMIO space, in units of 32 bits at a
  26. * time. Order of access is not guaranteed, nor is a memory barrier
  27. * performed afterwards.
  28. */
  29. void __attribute__((weak)) __iowrite32_copy(void __iomem *to,
  30. const void *from,
  31. size_t count)
  32. {
  33. u32 __iomem *dst = to;
  34. const u32 *src = from;
  35. const u32 *end = src + count;
  36. while (src < end)
  37. __raw_writel(*src++, dst++);
  38. }
  39. EXPORT_SYMBOL_GPL(__iowrite32_copy);
  40. /**
  41. * __iowrite64_copy - copy data to MMIO space, in 64-bit or 32-bit units
  42. * @to: destination, in MMIO space (must be 64-bit aligned)
  43. * @from: source (must be 64-bit aligned)
  44. * @count: number of 64-bit quantities to copy
  45. *
  46. * Copy data from kernel space to MMIO space, in units of 32 or 64 bits at a
  47. * time. Order of access is not guaranteed, nor is a memory barrier
  48. * performed afterwards.
  49. */
  50. void __attribute__((weak)) __iowrite64_copy(void __iomem *to,
  51. const void *from,
  52. size_t count)
  53. {
  54. #ifdef CONFIG_64BIT
  55. u64 __iomem *dst = to;
  56. const u64 *src = from;
  57. const u64 *end = src + count;
  58. while (src < end)
  59. __raw_writeq(*src++, dst++);
  60. #else
  61. __iowrite32_copy(to, from, count * 2);
  62. #endif
  63. }
  64. EXPORT_SYMBOL_GPL(__iowrite64_copy);