blob: 59fb020718a34a7be28a1feb2acdaee140440965 [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
Paul Mundtb66c1a32006-01-16 22:14:15 -080065void __iomem *ioport_map(unsigned long port, unsigned int nr)
66{
Magnus Damme7cc9a72008-02-07 20:18:21 +090067 void __iomem *ret;
68
69 ret = __ioport_map_trapped(port, nr);
70 if (ret)
71 return ret;
72
Magnus Damm8ce01432008-02-19 21:35:31 +090073 ret = __get_pci_io_base(port, nr);
74 if (ret)
75 return ret;
76
Magnus Damme7cc9a72008-02-07 20:18:21 +090077 return __ioport_map(port, nr);
Paul Mundtb66c1a32006-01-16 22:14:15 -080078}
79EXPORT_SYMBOL(ioport_map);
80
81void ioport_unmap(void __iomem *addr)
82{
83 sh_mv.mv_ioport_unmap(addr);
84}
85EXPORT_SYMBOL(ioport_unmap);