Linux Audio

Check our new training course

Loading...
v4.10.11
 
 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 <linux/export.h>
24#include <linux/io.h>
25#include <linux/uaccess.h>
26#include <sound/core.h>
 
27
28/**
29 * copy_to_user_fromio - copy data from mmio-space to user-space
30 * @dst: the destination pointer on user-space
31 * @src: the source pointer on mmio
32 * @count: the data size to copy in bytes
33 *
34 * Copies the data from mmio-space to user-space.
35 *
36 * Return: Zero if successful, or non-zero on failure.
37 */
38int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count)
39{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40#if defined(__i386__) || defined(CONFIG_SPARC32)
41	return copy_to_user(dst, (const void __force*)src, count) ? -EFAULT : 0;
42#else
43	char buf[256];
44	while (count) {
45		size_t c = count;
46		if (c > sizeof(buf))
47			c = sizeof(buf);
48		memcpy_fromio(buf, (void __iomem *)src, c);
49		if (copy_to_user(dst, buf, c))
50			return -EFAULT;
51		count -= c;
52		dst += c;
53		src += c;
54	}
55	return 0;
56#endif
57}
58
59EXPORT_SYMBOL(copy_to_user_fromio);
60
61/**
62 * copy_from_user_toio - copy data from user-space to mmio-space
63 * @dst: the destination pointer on mmio-space
64 * @src: the source pointer on user-space
65 * @count: the data size to copy in bytes
66 *
67 * Copies the data from user-space to mmio-space.
68 *
69 * Return: Zero if successful, or non-zero on failure.
70 */
71int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count)
72{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73#if defined(__i386__) || defined(CONFIG_SPARC32)
74	return copy_from_user((void __force *)dst, src, count) ? -EFAULT : 0;
75#else
76	char buf[256];
77	while (count) {
78		size_t c = count;
79		if (c > sizeof(buf))
80			c = sizeof(buf);
81		if (copy_from_user(buf, src, c))
82			return -EFAULT;
83		memcpy_toio(dst, buf, c);
84		count -= c;
85		dst += c;
86		src += c;
87	}
88	return 0;
89#endif
90}
91
92EXPORT_SYMBOL(copy_from_user_toio);
v6.8
  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#include <sound/pcm.h>
 13
 14/**
 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
 19 *
 20 * Copies the data from mmio-space to user-space.
 21 *
 22 * Return: Zero if successful, or non-zero on failure.
 23 */
 24int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count)
 25{
 26	struct iov_iter iter;
 27
 28	if (import_ubuf(ITER_DEST, dst, count, &iter))
 29		return -EFAULT;
 30	return copy_to_iter_fromio(&iter, (const void __iomem *)src, count);
 31}
 32EXPORT_SYMBOL(copy_to_user_fromio);
 33
 34/**
 35 * copy_to_iter_fromio - copy data from mmio-space to iov_iter
 36 * @dst: the destination iov_iter
 37 * @src: the source pointer on mmio
 38 * @count: the data size to copy in bytes
 39 *
 40 * Copies the data from mmio-space to iov_iter.
 41 *
 42 * Return: Zero if successful, or non-zero on failure.
 43 */
 44int copy_to_iter_fromio(struct iov_iter *dst, const void __iomem *src,
 45			size_t count)
 46{
 47#if defined(__i386__) || defined(CONFIG_SPARC32)
 48	return copy_to_iter((const void __force *)src, count, dst) == count ? 0 : -EFAULT;
 49#else
 50	char buf[256];
 51	while (count) {
 52		size_t c = count;
 53		if (c > sizeof(buf))
 54			c = sizeof(buf);
 55		memcpy_fromio(buf, (void __iomem *)src, c);
 56		if (copy_to_iter(buf, c, dst) != c)
 57			return -EFAULT;
 58		count -= c;
 
 59		src += c;
 60	}
 61	return 0;
 62#endif
 63}
 64EXPORT_SYMBOL(copy_to_iter_fromio);
 
 65
 66/**
 67 * copy_from_user_toio - copy data from user-space to mmio-space
 68 * @dst: the destination pointer on mmio-space
 69 * @src: the source pointer on user-space
 70 * @count: the data size to copy in bytes
 71 *
 72 * Copies the data from user-space to mmio-space.
 73 *
 74 * Return: Zero if successful, or non-zero on failure.
 75 */
 76int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count)
 77{
 78	struct iov_iter iter;
 79
 80	if (import_ubuf(ITER_SOURCE, (void __user *)src, count, &iter))
 81		return -EFAULT;
 82	return copy_from_iter_toio((void __iomem *)dst, &iter, count);
 83}
 84EXPORT_SYMBOL(copy_from_user_toio);
 85
 86/**
 87 * copy_from_iter_toio - copy data from iov_iter to mmio-space
 88 * @dst: the destination pointer on mmio-space
 89 * @src: the source iov_iter
 90 * @count: the data size to copy in bytes
 91 *
 92 * Copies the data from iov_iter to mmio-space.
 93 *
 94 * Return: Zero if successful, or non-zero on failure.
 95 */
 96int copy_from_iter_toio(void __iomem *dst, struct iov_iter *src, size_t count)
 97{
 98#if defined(__i386__) || defined(CONFIG_SPARC32)
 99	return copy_from_iter((void __force *)dst, count, src) == count ? 0 : -EFAULT;
100#else
101	char buf[256];
102	while (count) {
103		size_t c = count;
104		if (c > sizeof(buf))
105			c = sizeof(buf);
106		if (copy_from_iter(buf, c, src) != c)
107			return -EFAULT;
108		memcpy_toio(dst, buf, c);
109		count -= c;
110		dst += c;
 
111	}
112	return 0;
113#endif
114}
115EXPORT_SYMBOL(copy_from_iter_toio);