1 // SPDX-License-Identifier: GPL-2.0-only
3 * Based on arch/arm/kernel/io.c
5 * Copyright (C) 2012 ARM Ltd.
8 #include <linux/export.h>
9 #include <linux/types.h>
13 * This generates a memcpy that works on a from/to address which is aligned to
14 * bits. Count is in terms of the number of bits sized quantities to copy. It
15 * optimizes to use the STR groupings when possible so that it is WC friendly.
17 #define memcpy_toio_aligned(to, from, count, bits) \
19 volatile u##bits __iomem *_to = to; \
20 const u##bits *_from = from; \
21 size_t _count = count; \
22 const u##bits *_end_from = _from + ALIGN_DOWN(_count, 8); \
24 for (; _from < _end_from; _from += 8, _to += 8) \
25 __const_memcpy_toio_aligned##bits(_to, _from, 8); \
26 if ((_count % 8) >= 4) { \
27 __const_memcpy_toio_aligned##bits(_to, _from, 4); \
31 if ((_count % 4) >= 2) { \
32 __const_memcpy_toio_aligned##bits(_to, _from, 2); \
37 __const_memcpy_toio_aligned##bits(_to, _from, 1); \
40 void __iowrite64_copy_full(void __iomem
*to
, const void *from
, size_t count
)
42 memcpy_toio_aligned(to
, from
, count
, 64);
45 EXPORT_SYMBOL(__iowrite64_copy_full
);
47 void __iowrite32_copy_full(void __iomem
*to
, const void *from
, size_t count
)
49 memcpy_toio_aligned(to
, from
, count
, 32);
52 EXPORT_SYMBOL(__iowrite32_copy_full
);