iomap_copy.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/export.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. * __ioread32_copy - copy data from MMIO space, in 32-bit units
  42. * @to: destination (must be 32-bit aligned)
  43. * @from: source, in MMIO space (must be 32-bit aligned)
  44. * @count: number of 32-bit quantities to copy
  45. *
  46. * Copy data from MMIO space to kernel space, in units of 32 bits at a
  47. * time. Order of access is not guaranteed, nor is a memory barrier
  48. * performed afterwards.
  49. */
  50. void __ioread32_copy(void *to, const void __iomem *from, size_t count)
  51. {
  52. u32 *dst = to;
  53. const u32 __iomem *src = from;
  54. const u32 __iomem *end = src + count;
  55. while (src < end)
  56. *dst++ = __raw_readl(src++);
  57. }
  58. EXPORT_SYMBOL_GPL(__ioread32_copy);
  59. /**
  60. * __iowrite64_copy - copy data to MMIO space, in 64-bit or 32-bit units
  61. * @to: destination, in MMIO space (must be 64-bit aligned)
  62. * @from: source (must be 64-bit aligned)
  63. * @count: number of 64-bit quantities to copy
  64. *
  65. * Copy data from kernel space to MMIO space, in units of 32 or 64 bits at a
  66. * time. Order of access is not guaranteed, nor is a memory barrier
  67. * performed afterwards.
  68. */
  69. void __attribute__((weak)) __iowrite64_copy(void __iomem *to,
  70. const void *from,
  71. size_t count)
  72. {
  73. #ifdef CONFIG_64BIT
  74. u64 __iomem *dst = to;
  75. const u64 *src = from;
  76. const u64 *end = src + count;
  77. while (src < end)
  78. __raw_writeq(*src++, dst++);
  79. #else
  80. __iowrite32_copy(to, from, count * 2);
  81. #endif
  82. }
  83. EXPORT_SYMBOL_GPL(__iowrite64_copy);