Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
4 *
5 * Misc memory accessors
6 */
7
8#include <linux/export.h>
9#include <linux/io.h>
10#include <linux/uaccess.h>
11#include <sound/core.h>
12
13/**
14 * copy_to_user_fromio - copy data from mmio-space to user-space
15 * @dst: the destination pointer on user-space
16 * @src: the source pointer on mmio
17 * @count: the data size to copy in bytes
18 *
19 * Copies the data from mmio-space to user-space.
20 *
21 * Return: Zero if successful, or non-zero on failure.
22 */
23int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count)
24{
25#if defined(__i386__) || defined(CONFIG_SPARC32)
26 return copy_to_user(dst, (const void __force*)src, count) ? -EFAULT : 0;
27#else
28 char buf[256];
29 while (count) {
30 size_t c = count;
31 if (c > sizeof(buf))
32 c = sizeof(buf);
33 memcpy_fromio(buf, (void __iomem *)src, c);
34 if (copy_to_user(dst, buf, c))
35 return -EFAULT;
36 count -= c;
37 dst += c;
38 src += c;
39 }
40 return 0;
41#endif
42}
43EXPORT_SYMBOL(copy_to_user_fromio);
44
45/**
46 * copy_from_user_toio - copy data from user-space to mmio-space
47 * @dst: the destination pointer on mmio-space
48 * @src: the source pointer on user-space
49 * @count: the data size to copy in bytes
50 *
51 * Copies the data from user-space to mmio-space.
52 *
53 * Return: Zero if successful, or non-zero on failure.
54 */
55int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count)
56{
57#if defined(__i386__) || defined(CONFIG_SPARC32)
58 return copy_from_user((void __force *)dst, src, count) ? -EFAULT : 0;
59#else
60 char buf[256];
61 while (count) {
62 size_t c = count;
63 if (c > sizeof(buf))
64 c = sizeof(buf);
65 if (copy_from_user(buf, src, c))
66 return -EFAULT;
67 memcpy_toio(dst, buf, c);
68 count -= c;
69 dst += c;
70 src += c;
71 }
72 return 0;
73#endif
74}
75EXPORT_SYMBOL(copy_from_user_toio);
1/*
2 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
3 *
4 * Misc memory accessors
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23#include <asm/io.h>
24#include <asm/uaccess.h>
25#include <sound/core.h>
26
27/**
28 * copy_to_user_fromio - copy data from mmio-space to user-space
29 * @dst: the destination pointer on user-space
30 * @src: the source pointer on mmio
31 * @count: the data size to copy in bytes
32 *
33 * Copies the data from mmio-space to user-space.
34 *
35 * Returns zero if successful, or non-zero on failure.
36 */
37int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count)
38{
39#if defined(__i386__) || defined(CONFIG_SPARC32)
40 return copy_to_user(dst, (const void __force*)src, count) ? -EFAULT : 0;
41#else
42 char buf[256];
43 while (count) {
44 size_t c = count;
45 if (c > sizeof(buf))
46 c = sizeof(buf);
47 memcpy_fromio(buf, (void __iomem *)src, c);
48 if (copy_to_user(dst, buf, c))
49 return -EFAULT;
50 count -= c;
51 dst += c;
52 src += c;
53 }
54 return 0;
55#endif
56}
57
58EXPORT_SYMBOL(copy_to_user_fromio);
59
60/**
61 * copy_from_user_toio - copy data from user-space to mmio-space
62 * @dst: the destination pointer on mmio-space
63 * @src: the source pointer on user-space
64 * @count: the data size to copy in bytes
65 *
66 * Copies the data from user-space to mmio-space.
67 *
68 * Returns zero if successful, or non-zero on failure.
69 */
70int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count)
71{
72#if defined(__i386__) || defined(CONFIG_SPARC32)
73 return copy_from_user((void __force *)dst, src, count) ? -EFAULT : 0;
74#else
75 char buf[256];
76 while (count) {
77 size_t c = count;
78 if (c > sizeof(buf))
79 c = sizeof(buf);
80 if (copy_from_user(buf, src, c))
81 return -EFAULT;
82 memcpy_toio(dst, buf, c);
83 count -= c;
84 dst += c;
85 src += c;
86 }
87 return 0;
88#endif
89}
90
91EXPORT_SYMBOL(copy_from_user_toio);