blob: fd8214caedeedcdcfc4b44a660669ee2a9cda543 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * ppc64 "iomap" interface implementation.
3 *
4 * (C) Copyright 2004 Linus Torvalds
5 */
6#include <linux/init.h>
7#include <linux/pci.h>
8#include <linux/mm.h>
9#include <asm/io.h>
10
11/*
12 * Here comes the ppc64 implementation of the IOMAP
13 * interfaces.
14 */
15unsigned int fastcall ioread8(void __iomem *addr)
16{
17 return readb(addr);
18}
19unsigned int fastcall ioread16(void __iomem *addr)
20{
21 return readw(addr);
22}
Arthur Othieno76637532005-08-20 21:48:47 -040023unsigned int fastcall ioread16be(void __iomem *addr)
24{
25 return in_be16(addr);
26}
Linus Torvalds1da177e2005-04-16 15:20:36 -070027unsigned int fastcall ioread32(void __iomem *addr)
28{
29 return readl(addr);
30}
Arthur Othieno76637532005-08-20 21:48:47 -040031unsigned int fastcall ioread32be(void __iomem *addr)
32{
33 return in_be32(addr);
34}
Linus Torvalds1da177e2005-04-16 15:20:36 -070035EXPORT_SYMBOL(ioread8);
36EXPORT_SYMBOL(ioread16);
Arthur Othieno76637532005-08-20 21:48:47 -040037EXPORT_SYMBOL(ioread16be);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038EXPORT_SYMBOL(ioread32);
Arthur Othieno76637532005-08-20 21:48:47 -040039EXPORT_SYMBOL(ioread32be);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41void fastcall iowrite8(u8 val, void __iomem *addr)
42{
43 writeb(val, addr);
44}
45void fastcall iowrite16(u16 val, void __iomem *addr)
46{
47 writew(val, addr);
48}
Arthur Othieno76637532005-08-20 21:48:47 -040049void fastcall iowrite16be(u16 val, void __iomem *addr)
50{
51 out_be16(addr, val);
52}
Linus Torvalds1da177e2005-04-16 15:20:36 -070053void fastcall iowrite32(u32 val, void __iomem *addr)
54{
55 writel(val, addr);
56}
Arthur Othieno76637532005-08-20 21:48:47 -040057void fastcall iowrite32be(u32 val, void __iomem *addr)
58{
59 out_be32(addr, val);
60}
Linus Torvalds1da177e2005-04-16 15:20:36 -070061EXPORT_SYMBOL(iowrite8);
62EXPORT_SYMBOL(iowrite16);
Arthur Othieno76637532005-08-20 21:48:47 -040063EXPORT_SYMBOL(iowrite16be);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064EXPORT_SYMBOL(iowrite32);
Arthur Othieno76637532005-08-20 21:48:47 -040065EXPORT_SYMBOL(iowrite32be);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67/*
68 * These are the "repeat read/write" functions. Note the
69 * non-CPU byte order. We do things in "IO byteorder"
70 * here.
71 *
72 * FIXME! We could make these do EEH handling if we really
73 * wanted. Not clear if we do.
74 */
75void ioread8_rep(void __iomem *addr, void *dst, unsigned long count)
76{
viro@ZenIV.linux.org.uk6c9afc62005-09-09 16:50:43 +010077 _insb((u8 __iomem *) addr, dst, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
79void ioread16_rep(void __iomem *addr, void *dst, unsigned long count)
80{
viro@ZenIV.linux.org.uk6c9afc62005-09-09 16:50:43 +010081 _insw_ns((u16 __iomem *) addr, dst, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}
83void ioread32_rep(void __iomem *addr, void *dst, unsigned long count)
84{
viro@ZenIV.linux.org.uk6c9afc62005-09-09 16:50:43 +010085 _insl_ns((u32 __iomem *) addr, dst, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87EXPORT_SYMBOL(ioread8_rep);
88EXPORT_SYMBOL(ioread16_rep);
89EXPORT_SYMBOL(ioread32_rep);
90
91void iowrite8_rep(void __iomem *addr, const void *src, unsigned long count)
92{
viro@ZenIV.linux.org.uk6c9afc62005-09-09 16:50:43 +010093 _outsb((u8 __iomem *) addr, src, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094}
95void iowrite16_rep(void __iomem *addr, const void *src, unsigned long count)
96{
viro@ZenIV.linux.org.uk6c9afc62005-09-09 16:50:43 +010097 _outsw_ns((u16 __iomem *) addr, src, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
99void iowrite32_rep(void __iomem *addr, const void *src, unsigned long count)
100{
viro@ZenIV.linux.org.uk6c9afc62005-09-09 16:50:43 +0100101 _outsl_ns((u32 __iomem *) addr, src, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
103EXPORT_SYMBOL(iowrite8_rep);
104EXPORT_SYMBOL(iowrite16_rep);
105EXPORT_SYMBOL(iowrite32_rep);
106
107void __iomem *ioport_map(unsigned long port, unsigned int len)
108{
109 if (!_IO_IS_VALID(port))
110 return NULL;
111 return (void __iomem *) (port+pci_io_base);
112}
113
114void ioport_unmap(void __iomem *addr)
115{
116 /* Nothing to do */
117}
118EXPORT_SYMBOL(ioport_map);
119EXPORT_SYMBOL(ioport_unmap);
120
121void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max)
122{
123 unsigned long start = pci_resource_start(dev, bar);
124 unsigned long len = pci_resource_len(dev, bar);
125 unsigned long flags = pci_resource_flags(dev, bar);
126
127 if (!len)
128 return NULL;
129 if (max && len > max)
130 len = max;
131 if (flags & IORESOURCE_IO)
132 return ioport_map(start, len);
133 if (flags & IORESOURCE_MEM)
134 return ioremap(start, len);
135 /* What? */
136 return NULL;
137}
138
139void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
140{
141 /* Nothing to do */
142}
143EXPORT_SYMBOL(pci_iomap);
144EXPORT_SYMBOL(pci_iounmap);