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