blob: d0ca9684b781ec79b9cce855d135ea624cd450fb [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>
Magnus Damm8ce01432008-02-19 21:35:31 +090015#include <linux/pci.h>
Paul Mundtb66c1a32006-01-16 22:14:15 -080016#include <asm/machvec.h>
17#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19/*
20 * Copy data from IO memory space to "real" memory space.
21 * This needs to be optimized.
22 */
Paul Mundt14866542008-10-04 05:25:52 +090023void memcpy_fromio(void *to, const volatile void __iomem *from, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024{
Paul Mundt14866542008-10-04 05:25:52 +090025 unsigned char *p = to;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 while (count) {
27 count--;
Paul Mundt14866542008-10-04 05:25:52 +090028 *p = readb(from);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 p++;
30 from++;
31 }
32}
Paul Mundtb66c1a32006-01-16 22:14:15 -080033EXPORT_SYMBOL(memcpy_fromio);
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035/*
36 * Copy data from "real" memory space to IO memory space.
37 * This needs to be optimized.
38 */
Paul Mundtb66c1a32006-01-16 22:14:15 -080039void memcpy_toio(volatile void __iomem *to, const void *from, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
Paul Mundt14866542008-10-04 05:25:52 +090041 const unsigned char *p = from;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 while (count) {
43 count--;
Paul Mundt14866542008-10-04 05:25:52 +090044 writeb(*p, to);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 p++;
46 to++;
47 }
48}
Paul Mundtb66c1a32006-01-16 22:14:15 -080049EXPORT_SYMBOL(memcpy_toio);
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051/*
52 * "memset" on IO memory space.
53 * This needs to be optimized.
54 */
Paul Mundtb66c1a32006-01-16 22:14:15 -080055void memset_io(volatile void __iomem *dst, int c, unsigned long count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
57 while (count) {
58 count--;
Paul Mundt14866542008-10-04 05:25:52 +090059 writeb(c, dst);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 dst++;
61 }
62}
Linus Torvalds1da177e2005-04-16 15:20:36 -070063EXPORT_SYMBOL(memset_io);
64
David McKay15444a82009-08-24 16:10:40 +090065#ifndef CONFIG_GENERIC_IOMAP
66
Paul Mundtb66c1a32006-01-16 22:14:15 -080067void __iomem *ioport_map(unsigned long port, unsigned int nr)
68{
Magnus Damme7cc9a72008-02-07 20:18:21 +090069 void __iomem *ret;
70
71 ret = __ioport_map_trapped(port, nr);
72 if (ret)
73 return ret;
74
75 return __ioport_map(port, nr);
Paul Mundtb66c1a32006-01-16 22:14:15 -080076}
77EXPORT_SYMBOL(ioport_map);
78
79void ioport_unmap(void __iomem *addr)
80{
81 sh_mv.mv_ioport_unmap(addr);
82}
83EXPORT_SYMBOL(ioport_unmap);
David McKay15444a82009-08-24 16:10:40 +090084
85#endif /* CONFIG_GENERIC_IOMAP */