1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2024 Kalray, Inc. All Rights Reserved.
6 #include <linux/align.h>
7 #include <linux/export.h>
9 #include <linux/types.h>
10 #include <linux/unaligned.h>
14 * memset_io() - Set a range of I/O memory to a constant value
15 * @addr: The beginning of the I/O-memory range to set
16 * @val: The value to set the memory to
17 * @count: The number of bytes to set
19 * Set a range of I/O memory to a given value.
21 void memset_io(volatile void __iomem
*addr
, int val
, size_t count
)
27 while (count
&& !IS_ALIGNED((long)addr
, sizeof(long))) {
28 __raw_writeb(val
, addr
);
33 while (count
>= sizeof(long)) {
35 __raw_writeq(qc
, addr
);
37 __raw_writel(qc
, addr
);
41 count
-= sizeof(long);
45 __raw_writeb(val
, addr
);
50 EXPORT_SYMBOL(memset_io
);
55 * memcpy_fromio() - Copy a block of data from I/O memory
56 * @dst: The (RAM) destination for the copy
57 * @src: The (I/O memory) source for the data
58 * @count: The number of bytes to copy
60 * Copy a block of data from I/O memory.
62 void memcpy_fromio(void *dst
, const volatile void __iomem
*src
, size_t count
)
64 while (count
&& !IS_ALIGNED((long)src
, sizeof(long))) {
65 *(u8
*)dst
= __raw_readb(src
);
71 while (count
>= sizeof(long)) {
73 long val
= __raw_readq(src
);
75 long val
= __raw_readl(src
);
77 put_unaligned(val
, (long *)dst
);
82 count
-= sizeof(long);
86 *(u8
*)dst
= __raw_readb(src
);
92 EXPORT_SYMBOL(memcpy_fromio
);
97 * memcpy_toio() -Copy a block of data into I/O memory
98 * @dst: The (I/O memory) destination for the copy
99 * @src: The (RAM) source for the data
100 * @count: The number of bytes to copy
102 * Copy a block of data to I/O memory.
104 void memcpy_toio(volatile void __iomem
*dst
, const void *src
, size_t count
)
106 while (count
&& !IS_ALIGNED((long)dst
, sizeof(long))) {
107 __raw_writeb(*(u8
*)src
, dst
);
113 while (count
>= sizeof(long)) {
114 long val
= get_unaligned((long *)src
);
116 __raw_writeq(val
, dst
);
118 __raw_writel(val
, dst
);
123 count
-= sizeof(long);
127 __raw_writeb(*(u8
*)src
, dst
);
133 EXPORT_SYMBOL(memcpy_toio
);