/*1* Copyright (c) by Jaroslav Kysela <[email protected]>2*3* Misc memory accessors4*5*6* This program is free software; you can redistribute it and/or modify7* it under the terms of the GNU General Public License as published by8* the Free Software Foundation; either version 2 of the License, or9* (at your option) any later version.10*11* This program is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14* GNU General Public License for more details.15*16* You should have received a copy of the GNU General Public License17* along with this program; if not, write to the Free Software18* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA19*20*/2122#include <asm/io.h>23#include <asm/uaccess.h>24#include <sound/core.h>2526/**27* copy_to_user_fromio - copy data from mmio-space to user-space28* @dst: the destination pointer on user-space29* @src: the source pointer on mmio30* @count: the data size to copy in bytes31*32* Copies the data from mmio-space to user-space.33*34* Returns zero if successful, or non-zero on failure.35*/36int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count)37{38#if defined(__i386__) || defined(CONFIG_SPARC32)39return copy_to_user(dst, (const void __force*)src, count) ? -EFAULT : 0;40#else41char buf[256];42while (count) {43size_t c = count;44if (c > sizeof(buf))45c = sizeof(buf);46memcpy_fromio(buf, (void __iomem *)src, c);47if (copy_to_user(dst, buf, c))48return -EFAULT;49count -= c;50dst += c;51src += c;52}53return 0;54#endif55}5657EXPORT_SYMBOL(copy_to_user_fromio);5859/**60* copy_from_user_toio - copy data from user-space to mmio-space61* @dst: the destination pointer on mmio-space62* @src: the source pointer on user-space63* @count: the data size to copy in bytes64*65* Copies the data from user-space to mmio-space.66*67* Returns zero if successful, or non-zero on failure.68*/69int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count)70{71#if defined(__i386__) || defined(CONFIG_SPARC32)72return copy_from_user((void __force *)dst, src, count) ? -EFAULT : 0;73#else74char buf[256];75while (count) {76size_t c = count;77if (c > sizeof(buf))78c = sizeof(buf);79if (copy_from_user(buf, src, c))80return -EFAULT;81memcpy_toio(dst, buf, c);82count -= c;83dst += c;84src += c;85}86return 0;87#endif88}8990EXPORT_SYMBOL(copy_from_user_toio);919293