Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
0004  * 
0005  *  Misc memory accessors
0006  */
0007 
0008 #include <linux/export.h>
0009 #include <linux/io.h>
0010 #include <linux/uaccess.h>
0011 #include <sound/core.h>
0012 
0013 /**
0014  * copy_to_user_fromio - copy data from mmio-space to user-space
0015  * @dst: the destination pointer on user-space
0016  * @src: the source pointer on mmio
0017  * @count: the data size to copy in bytes
0018  *
0019  * Copies the data from mmio-space to user-space.
0020  *
0021  * Return: Zero if successful, or non-zero on failure.
0022  */
0023 int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count)
0024 {
0025 #if defined(__i386__) || defined(CONFIG_SPARC32)
0026     return copy_to_user(dst, (const void __force*)src, count) ? -EFAULT : 0;
0027 #else
0028     char buf[256];
0029     while (count) {
0030         size_t c = count;
0031         if (c > sizeof(buf))
0032             c = sizeof(buf);
0033         memcpy_fromio(buf, (void __iomem *)src, c);
0034         if (copy_to_user(dst, buf, c))
0035             return -EFAULT;
0036         count -= c;
0037         dst += c;
0038         src += c;
0039     }
0040     return 0;
0041 #endif
0042 }
0043 EXPORT_SYMBOL(copy_to_user_fromio);
0044 
0045 /**
0046  * copy_from_user_toio - copy data from user-space to mmio-space
0047  * @dst: the destination pointer on mmio-space
0048  * @src: the source pointer on user-space
0049  * @count: the data size to copy in bytes
0050  *
0051  * Copies the data from user-space to mmio-space.
0052  *
0053  * Return: Zero if successful, or non-zero on failure.
0054  */
0055 int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count)
0056 {
0057 #if defined(__i386__) || defined(CONFIG_SPARC32)
0058     return copy_from_user((void __force *)dst, src, count) ? -EFAULT : 0;
0059 #else
0060     char buf[256];
0061     while (count) {
0062         size_t c = count;
0063         if (c > sizeof(buf))
0064             c = sizeof(buf);
0065         if (copy_from_user(buf, src, c))
0066             return -EFAULT;
0067         memcpy_toio(dst, buf, c);
0068         count -= c;
0069         dst += c;
0070         src += c;
0071     }
0072     return 0;
0073 #endif
0074 }
0075 EXPORT_SYMBOL(copy_from_user_toio);