1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
5 * Misc memory accessors
8 #include <linux/export.h>
10 #include <linux/uaccess.h>
11 #include <sound/core.h>
12 #include <sound/pcm.h>
15 * copy_to_user_fromio - copy data from mmio-space to user-space
16 * @dst: the destination pointer on user-space
17 * @src: the source pointer on mmio
18 * @count: the data size to copy in bytes
20 * Copies the data from mmio-space to user-space.
22 * Return: Zero if successful, or non-zero on failure.
24 int copy_to_user_fromio(void __user
*dst
, const volatile void __iomem
*src
, size_t count
)
28 if (import_ubuf(ITER_DEST
, dst
, count
, &iter
))
30 if (copy_to_iter_fromio((const void __iomem
*)src
, count
, &iter
) != count
)
34 EXPORT_SYMBOL(copy_to_user_fromio
);
37 * copy_to_iter_fromio - copy data from mmio-space to iov_iter
38 * @src: the source pointer on mmio
39 * @count: the data size to copy in bytes
40 * @dst: the destination iov_iter
42 * Copies the data from mmio-space to iov_iter.
44 * Return: number of bytes to be copied
46 size_t copy_to_iter_fromio(const void __iomem
*src
, size_t count
,
49 #if defined(__i386__) || defined(CONFIG_SPARC32)
50 return copy_to_iter((const void __force
*)src
, count
, dst
);
59 memcpy_fromio(buf
, (void __iomem
*)src
, c
);
60 if (copy_to_iter(buf
, c
, dst
) != c
)
69 EXPORT_SYMBOL(copy_to_iter_fromio
);
72 * copy_from_user_toio - copy data from user-space to mmio-space
73 * @dst: the destination pointer on mmio-space
74 * @src: the source pointer on user-space
75 * @count: the data size to copy in bytes
77 * Copies the data from user-space to mmio-space.
79 * Return: Zero if successful, or non-zero on failure.
81 int copy_from_user_toio(volatile void __iomem
*dst
, const void __user
*src
, size_t count
)
85 if (import_ubuf(ITER_SOURCE
, (void __user
*)src
, count
, &iter
))
87 if (copy_from_iter_toio((void __iomem
*)dst
, count
, &iter
) != count
)
91 EXPORT_SYMBOL(copy_from_user_toio
);
94 * copy_from_iter_toio - copy data from iov_iter to mmio-space
95 * @dst: the destination pointer on mmio-space
96 * @count: the data size to copy in bytes
97 * @src: the source iov_iter
99 * Copies the data from iov_iter to mmio-space.
101 * Return: number of bytes to be copied
103 size_t copy_from_iter_toio(void __iomem
*dst
, size_t count
,
104 struct iov_iter
*src
)
106 #if defined(__i386__) || defined(CONFIG_SPARC32)
107 return copy_from_iter((void __force
*)dst
, count
, src
);
116 if (copy_from_iter(buf
, c
, src
) != c
)
118 memcpy_toio(dst
, buf
, c
);
126 EXPORT_SYMBOL(copy_from_iter_toio
);