iomap_copy.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2006 PathScale, Inc. All Rights Reserved.
  4. */
  5. #include <linux/export.h>
  6. #include <linux/io.h>
  7. /**
  8. * __iowrite32_copy - copy data to MMIO space, in 32-bit units
  9. * @to: destination, in MMIO space (must be 32-bit aligned)
  10. * @from: source (must be 32-bit aligned)
  11. * @count: number of 32-bit quantities to copy
  12. *
  13. * Copy data from kernel space to MMIO space, in units of 32 bits at a
  14. * time. Order of access is not guaranteed, nor is a memory barrier
  15. * performed afterwards.
  16. */
  17. void __attribute__((weak)) __iowrite32_copy(void __iomem *to,
  18. const void *from,
  19. size_t count)
  20. {
  21. u32 __iomem *dst = to;
  22. const u32 *src = from;
  23. const u32 *end = src + count;
  24. while (src < end)
  25. __raw_writel(*src++, dst++);
  26. }
  27. EXPORT_SYMBOL_GPL(__iowrite32_copy);
  28. /**
  29. * __ioread32_copy - copy data from MMIO space, in 32-bit units
  30. * @to: destination (must be 32-bit aligned)
  31. * @from: source, in MMIO space (must be 32-bit aligned)
  32. * @count: number of 32-bit quantities to copy
  33. *
  34. * Copy data from MMIO space to kernel space, in units of 32 bits at a
  35. * time. Order of access is not guaranteed, nor is a memory barrier
  36. * performed afterwards.
  37. */
  38. void __ioread32_copy(void *to, const void __iomem *from, size_t count)
  39. {
  40. u32 *dst = to;
  41. const u32 __iomem *src = from;
  42. const u32 __iomem *end = src + count;
  43. while (src < end)
  44. *dst++ = __raw_readl(src++);
  45. }
  46. EXPORT_SYMBOL_GPL(__ioread32_copy);
  47. /**
  48. * __iowrite64_copy - copy data to MMIO space, in 64-bit or 32-bit units
  49. * @to: destination, in MMIO space (must be 64-bit aligned)
  50. * @from: source (must be 64-bit aligned)
  51. * @count: number of 64-bit quantities to copy
  52. *
  53. * Copy data from kernel space to MMIO space, in units of 32 or 64 bits at a
  54. * time. Order of access is not guaranteed, nor is a memory barrier
  55. * performed afterwards.
  56. */
  57. void __attribute__((weak)) __iowrite64_copy(void __iomem *to,
  58. const void *from,
  59. size_t count)
  60. {
  61. #ifdef CONFIG_64BIT
  62. u64 __iomem *dst = to;
  63. const u64 *src = from;
  64. const u64 *end = src + count;
  65. while (src < end)
  66. __raw_writeq(*src++, dst++);
  67. #else
  68. __iowrite32_copy(to, from, count * 2);
  69. #endif
  70. }
  71. EXPORT_SYMBOL_GPL(__iowrite64_copy);