Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/sh/kernel/io.c |
| 3 | * |
| 4 | * Copyright (C) 2000 Stuart Menefy |
Paul Mundt | b66c1a3 | 2006-01-16 22:14:15 -0800 | [diff] [blame] | 5 | * Copyright (C) 2005 Paul Mundt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * Provide real functions which expand to whatever the header file defined. |
| 8 | * Also definitions of machine independent IO functions. |
Paul Mundt | b66c1a3 | 2006-01-16 22:14:15 -0800 | [diff] [blame] | 9 | * |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
Magnus Damm | 8ce0143 | 2008-02-19 21:35:31 +0900 | [diff] [blame^] | 15 | #include <linux/pci.h> |
Paul Mundt | b66c1a3 | 2006-01-16 22:14:15 -0800 | [diff] [blame] | 16 | #include <asm/machvec.h> |
| 17 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | /* |
| 20 | * Copy data from IO memory space to "real" memory space. |
| 21 | * This needs to be optimized. |
| 22 | */ |
Paul Mundt | 1486654 | 2008-10-04 05:25:52 +0900 | [diff] [blame] | 23 | void memcpy_fromio(void *to, const volatile void __iomem *from, unsigned long count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | { |
Paul Mundt | 1486654 | 2008-10-04 05:25:52 +0900 | [diff] [blame] | 25 | unsigned char *p = to; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | while (count) { |
| 27 | count--; |
Paul Mundt | 1486654 | 2008-10-04 05:25:52 +0900 | [diff] [blame] | 28 | *p = readb(from); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | p++; |
| 30 | from++; |
| 31 | } |
| 32 | } |
Paul Mundt | b66c1a3 | 2006-01-16 22:14:15 -0800 | [diff] [blame] | 33 | EXPORT_SYMBOL(memcpy_fromio); |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | /* |
| 36 | * Copy data from "real" memory space to IO memory space. |
| 37 | * This needs to be optimized. |
| 38 | */ |
Paul Mundt | b66c1a3 | 2006-01-16 22:14:15 -0800 | [diff] [blame] | 39 | void memcpy_toio(volatile void __iomem *to, const void *from, unsigned long count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | { |
Paul Mundt | 1486654 | 2008-10-04 05:25:52 +0900 | [diff] [blame] | 41 | const unsigned char *p = from; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | while (count) { |
| 43 | count--; |
Paul Mundt | 1486654 | 2008-10-04 05:25:52 +0900 | [diff] [blame] | 44 | writeb(*p, to); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | p++; |
| 46 | to++; |
| 47 | } |
| 48 | } |
Paul Mundt | b66c1a3 | 2006-01-16 22:14:15 -0800 | [diff] [blame] | 49 | EXPORT_SYMBOL(memcpy_toio); |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | /* |
| 52 | * "memset" on IO memory space. |
| 53 | * This needs to be optimized. |
| 54 | */ |
Paul Mundt | b66c1a3 | 2006-01-16 22:14:15 -0800 | [diff] [blame] | 55 | void memset_io(volatile void __iomem *dst, int c, unsigned long count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | { |
| 57 | while (count) { |
| 58 | count--; |
Paul Mundt | 1486654 | 2008-10-04 05:25:52 +0900 | [diff] [blame] | 59 | writeb(c, dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | dst++; |
| 61 | } |
| 62 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | EXPORT_SYMBOL(memset_io); |
| 64 | |
Paul Mundt | b66c1a3 | 2006-01-16 22:14:15 -0800 | [diff] [blame] | 65 | void __iomem *ioport_map(unsigned long port, unsigned int nr) |
| 66 | { |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 67 | void __iomem *ret; |
| 68 | |
| 69 | ret = __ioport_map_trapped(port, nr); |
| 70 | if (ret) |
| 71 | return ret; |
| 72 | |
Magnus Damm | 8ce0143 | 2008-02-19 21:35:31 +0900 | [diff] [blame^] | 73 | ret = __get_pci_io_base(port, nr); |
| 74 | if (ret) |
| 75 | return ret; |
| 76 | |
Magnus Damm | e7cc9a7 | 2008-02-07 20:18:21 +0900 | [diff] [blame] | 77 | return __ioport_map(port, nr); |
Paul Mundt | b66c1a3 | 2006-01-16 22:14:15 -0800 | [diff] [blame] | 78 | } |
| 79 | EXPORT_SYMBOL(ioport_map); |
| 80 | |
| 81 | void ioport_unmap(void __iomem *addr) |
| 82 | { |
| 83 | sh_mv.mv_ioport_unmap(addr); |
| 84 | } |
| 85 | EXPORT_SYMBOL(ioport_unmap); |