18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright 2006 PathScale, Inc.  All Rights Reserved.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <linux/export.h>
78c2ecf20Sopenharmony_ci#include <linux/io.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci/**
108c2ecf20Sopenharmony_ci * __iowrite32_copy - copy data to MMIO space, in 32-bit units
118c2ecf20Sopenharmony_ci * @to: destination, in MMIO space (must be 32-bit aligned)
128c2ecf20Sopenharmony_ci * @from: source (must be 32-bit aligned)
138c2ecf20Sopenharmony_ci * @count: number of 32-bit quantities to copy
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * Copy data from kernel space to MMIO space, in units of 32 bits at a
168c2ecf20Sopenharmony_ci * time.  Order of access is not guaranteed, nor is a memory barrier
178c2ecf20Sopenharmony_ci * performed afterwards.
188c2ecf20Sopenharmony_ci */
198c2ecf20Sopenharmony_civoid __attribute__((weak)) __iowrite32_copy(void __iomem *to,
208c2ecf20Sopenharmony_ci					    const void *from,
218c2ecf20Sopenharmony_ci					    size_t count)
228c2ecf20Sopenharmony_ci{
238c2ecf20Sopenharmony_ci	u32 __iomem *dst = to;
248c2ecf20Sopenharmony_ci	const u32 *src = from;
258c2ecf20Sopenharmony_ci	const u32 *end = src + count;
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci	while (src < end)
288c2ecf20Sopenharmony_ci		__raw_writel(*src++, dst++);
298c2ecf20Sopenharmony_ci}
308c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(__iowrite32_copy);
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci/**
338c2ecf20Sopenharmony_ci * __ioread32_copy - copy data from MMIO space, in 32-bit units
348c2ecf20Sopenharmony_ci * @to: destination (must be 32-bit aligned)
358c2ecf20Sopenharmony_ci * @from: source, in MMIO space (must be 32-bit aligned)
368c2ecf20Sopenharmony_ci * @count: number of 32-bit quantities to copy
378c2ecf20Sopenharmony_ci *
388c2ecf20Sopenharmony_ci * Copy data from MMIO space to kernel space, in units of 32 bits at a
398c2ecf20Sopenharmony_ci * time.  Order of access is not guaranteed, nor is a memory barrier
408c2ecf20Sopenharmony_ci * performed afterwards.
418c2ecf20Sopenharmony_ci */
428c2ecf20Sopenharmony_civoid __ioread32_copy(void *to, const void __iomem *from, size_t count)
438c2ecf20Sopenharmony_ci{
448c2ecf20Sopenharmony_ci	u32 *dst = to;
458c2ecf20Sopenharmony_ci	const u32 __iomem *src = from;
468c2ecf20Sopenharmony_ci	const u32 __iomem *end = src + count;
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	while (src < end)
498c2ecf20Sopenharmony_ci		*dst++ = __raw_readl(src++);
508c2ecf20Sopenharmony_ci}
518c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(__ioread32_copy);
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci/**
548c2ecf20Sopenharmony_ci * __iowrite64_copy - copy data to MMIO space, in 64-bit or 32-bit units
558c2ecf20Sopenharmony_ci * @to: destination, in MMIO space (must be 64-bit aligned)
568c2ecf20Sopenharmony_ci * @from: source (must be 64-bit aligned)
578c2ecf20Sopenharmony_ci * @count: number of 64-bit quantities to copy
588c2ecf20Sopenharmony_ci *
598c2ecf20Sopenharmony_ci * Copy data from kernel space to MMIO space, in units of 32 or 64 bits at a
608c2ecf20Sopenharmony_ci * time.  Order of access is not guaranteed, nor is a memory barrier
618c2ecf20Sopenharmony_ci * performed afterwards.
628c2ecf20Sopenharmony_ci */
638c2ecf20Sopenharmony_civoid __attribute__((weak)) __iowrite64_copy(void __iomem *to,
648c2ecf20Sopenharmony_ci					    const void *from,
658c2ecf20Sopenharmony_ci					    size_t count)
668c2ecf20Sopenharmony_ci{
678c2ecf20Sopenharmony_ci#ifdef CONFIG_64BIT
688c2ecf20Sopenharmony_ci	u64 __iomem *dst = to;
698c2ecf20Sopenharmony_ci	const u64 *src = from;
708c2ecf20Sopenharmony_ci	const u64 *end = src + count;
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci	while (src < end)
738c2ecf20Sopenharmony_ci		__raw_writeq(*src++, dst++);
748c2ecf20Sopenharmony_ci#else
758c2ecf20Sopenharmony_ci	__iowrite32_copy(to, from, count * 2);
768c2ecf20Sopenharmony_ci#endif
778c2ecf20Sopenharmony_ci}
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(__iowrite64_copy);
80