blob: 29cf4588fc050a996d2e62f95aa4f3ada2ad9733 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/sh/kernel/io.c
3 *
4 * Copyright (C) 2000 Stuart Menefy
Paul Mundtb66c1a32006-01-16 22:14:15 -08005 * Copyright (C) 2005 Paul Mundt
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * Provide real functions which expand to whatever the header file defined.
8 * Also definitions of machine independent IO functions.
Paul Mundtb66c1a32006-01-16 22:14:15 -08009 *
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
12 * for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/module.h>
Paul Mundtb66c1a32006-01-16 22:14:15 -080015#include <asm/machvec.h>
16#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18/*
19 * Copy data from IO memory space to "real" memory space.
20 * This needs to be optimized.
21 */
Paul Mundt14866542008-10-04 05:25:52 +090022void memcpy_fromio(void *to, const volatile void __iomem *from, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070023{
Paul Mundt14866542008-10-04 05:25:52 +090024 unsigned char *p = to;
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 while (count) {
26 count--;
Paul Mundt14866542008-10-04 05:25:52 +090027 *p = readb(from);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 p++;
29 from++;
30 }
31}
Paul Mundtb66c1a32006-01-16 22:14:15 -080032EXPORT_SYMBOL(memcpy_fromio);
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034/*
35 * Copy data from "real" memory space to IO memory space.
36 * This needs to be optimized.
37 */
Paul Mundtb66c1a32006-01-16 22:14:15 -080038void memcpy_toio(volatile void __iomem *to, const void *from, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
Paul Mundt14866542008-10-04 05:25:52 +090040 const unsigned char *p = from;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 while (count) {
42 count--;
Paul Mundt14866542008-10-04 05:25:52 +090043 writeb(*p, to);
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 p++;
45 to++;
46 }
47}
Paul Mundtb66c1a32006-01-16 22:14:15 -080048EXPORT_SYMBOL(memcpy_toio);
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050/*
51 * "memset" on IO memory space.
52 * This needs to be optimized.
53 */
Paul Mundtb66c1a32006-01-16 22:14:15 -080054void memset_io(volatile void __iomem *dst, int c, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
56 while (count) {
57 count--;
Paul Mundt14866542008-10-04 05:25:52 +090058 writeb(c, dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 dst++;
60 }
61}
Linus Torvalds1da177e2005-04-16 15:20:36 -070062EXPORT_SYMBOL(memset_io);
63
Paul Mundtb66c1a32006-01-16 22:14:15 -080064void __iomem *ioport_map(unsigned long port, unsigned int nr)
65{
Magnus Damme7cc9a72008-02-07 20:18:21 +090066 void __iomem *ret;
67
68 ret = __ioport_map_trapped(port, nr);
69 if (ret)
70 return ret;
71
72 return __ioport_map(port, nr);
Paul Mundtb66c1a32006-01-16 22:14:15 -080073}
74EXPORT_SYMBOL(ioport_map);
75
76void ioport_unmap(void __iomem *addr)
77{
78 sh_mv.mv_ioport_unmap(addr);
79}
80EXPORT_SYMBOL(ioport_unmap);