1775c8a3dSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2c27a0d75SBryan O'Sullivan /*
3c27a0d75SBryan O'Sullivan * Copyright 2006 PathScale, Inc. All Rights Reserved.
4c27a0d75SBryan O'Sullivan */
5c27a0d75SBryan O'Sullivan
68bc3bcc9SPaul Gortmaker #include <linux/export.h>
7ad6b97fcSAl Viro #include <linux/io.h>
8c27a0d75SBryan O'Sullivan
9c27a0d75SBryan O'Sullivan /**
10c27a0d75SBryan O'Sullivan * __iowrite32_copy - copy data to MMIO space, in 32-bit units
11c27a0d75SBryan O'Sullivan * @to: destination, in MMIO space (must be 32-bit aligned)
12c27a0d75SBryan O'Sullivan * @from: source (must be 32-bit aligned)
13c27a0d75SBryan O'Sullivan * @count: number of 32-bit quantities to copy
14c27a0d75SBryan O'Sullivan *
15c27a0d75SBryan O'Sullivan * Copy data from kernel space to MMIO space, in units of 32 bits at a
16c27a0d75SBryan O'Sullivan * time. Order of access is not guaranteed, nor is a memory barrier
17c27a0d75SBryan O'Sullivan * performed afterwards.
18c27a0d75SBryan O'Sullivan */
1920516d6eSJason Gunthorpe #ifndef __iowrite32_copy
__iowrite32_copy(void __iomem * to,const void * from,size_t count)2020516d6eSJason Gunthorpe void __iowrite32_copy(void __iomem *to, const void *from, size_t count)
21c27a0d75SBryan O'Sullivan {
22c27a0d75SBryan O'Sullivan u32 __iomem *dst = to;
23c27a0d75SBryan O'Sullivan const u32 *src = from;
24c27a0d75SBryan O'Sullivan const u32 *end = src + count;
25c27a0d75SBryan O'Sullivan
26c27a0d75SBryan O'Sullivan while (src < end)
27c27a0d75SBryan O'Sullivan __raw_writel(*src++, dst++);
28c27a0d75SBryan O'Sullivan }
29c27a0d75SBryan O'Sullivan EXPORT_SYMBOL_GPL(__iowrite32_copy);
3020516d6eSJason Gunthorpe #endif
3122ae813bSBrice Goglin
3222ae813bSBrice Goglin /**
33a9aec588SStephen Boyd * __ioread32_copy - copy data from MMIO space, in 32-bit units
34a9aec588SStephen Boyd * @to: destination (must be 32-bit aligned)
35a9aec588SStephen Boyd * @from: source, in MMIO space (must be 32-bit aligned)
36a9aec588SStephen Boyd * @count: number of 32-bit quantities to copy
37a9aec588SStephen Boyd *
38a9aec588SStephen Boyd * Copy data from MMIO space to kernel space, in units of 32 bits at a
39a9aec588SStephen Boyd * time. Order of access is not guaranteed, nor is a memory barrier
40a9aec588SStephen Boyd * performed afterwards.
41a9aec588SStephen Boyd */
__ioread32_copy(void * to,const void __iomem * from,size_t count)42a9aec588SStephen Boyd void __ioread32_copy(void *to, const void __iomem *from, size_t count)
43a9aec588SStephen Boyd {
44a9aec588SStephen Boyd u32 *dst = to;
45a9aec588SStephen Boyd const u32 __iomem *src = from;
46a9aec588SStephen Boyd const u32 __iomem *end = src + count;
47a9aec588SStephen Boyd
48a9aec588SStephen Boyd while (src < end)
49a9aec588SStephen Boyd *dst++ = __raw_readl(src++);
50a9aec588SStephen Boyd }
51a9aec588SStephen Boyd EXPORT_SYMBOL_GPL(__ioread32_copy);
52a9aec588SStephen Boyd
53a9aec588SStephen Boyd /**
5422ae813bSBrice Goglin * __iowrite64_copy - copy data to MMIO space, in 64-bit or 32-bit units
5522ae813bSBrice Goglin * @to: destination, in MMIO space (must be 64-bit aligned)
5622ae813bSBrice Goglin * @from: source (must be 64-bit aligned)
5722ae813bSBrice Goglin * @count: number of 64-bit quantities to copy
5822ae813bSBrice Goglin *
5922ae813bSBrice Goglin * Copy data from kernel space to MMIO space, in units of 32 or 64 bits at a
6022ae813bSBrice Goglin * time. Order of access is not guaranteed, nor is a memory barrier
6122ae813bSBrice Goglin * performed afterwards.
6222ae813bSBrice Goglin */
63*e7bc47b1SJason Gunthorpe #ifndef __iowrite64_copy
__iowrite64_copy(void __iomem * to,const void * from,size_t count)64*e7bc47b1SJason Gunthorpe void __iowrite64_copy(void __iomem *to, const void *from, size_t count)
6522ae813bSBrice Goglin {
6622ae813bSBrice Goglin #ifdef CONFIG_64BIT
6722ae813bSBrice Goglin u64 __iomem *dst = to;
6822ae813bSBrice Goglin const u64 *src = from;
6922ae813bSBrice Goglin const u64 *end = src + count;
7022ae813bSBrice Goglin
7122ae813bSBrice Goglin while (src < end)
7222ae813bSBrice Goglin __raw_writeq(*src++, dst++);
7322ae813bSBrice Goglin #else
7422ae813bSBrice Goglin __iowrite32_copy(to, from, count * 2);
7522ae813bSBrice Goglin #endif
7622ae813bSBrice Goglin }
7722ae813bSBrice Goglin EXPORT_SYMBOL_GPL(__iowrite64_copy);
78*e7bc47b1SJason Gunthorpe #endif
79