]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * 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> | |
50747cb8 | 10 | #include <asm/pci-bridge.h> |
1da177e4 LT |
11 | |
12 | /* | |
13 | * Here comes the ppc64 implementation of the IOMAP | |
14 | * interfaces. | |
15 | */ | |
8943212c | 16 | unsigned int ioread8(void __iomem *addr) |
1da177e4 LT |
17 | { |
18 | return readb(addr); | |
19 | } | |
8943212c | 20 | unsigned int ioread16(void __iomem *addr) |
1da177e4 LT |
21 | { |
22 | return readw(addr); | |
23 | } | |
8943212c | 24 | unsigned int ioread16be(void __iomem *addr) |
76637536 AO |
25 | { |
26 | return in_be16(addr); | |
27 | } | |
8943212c | 28 | unsigned int ioread32(void __iomem *addr) |
1da177e4 LT |
29 | { |
30 | return readl(addr); | |
31 | } | |
8943212c | 32 | unsigned int ioread32be(void __iomem *addr) |
76637536 AO |
33 | { |
34 | return in_be32(addr); | |
35 | } | |
1da177e4 LT |
36 | EXPORT_SYMBOL(ioread8); |
37 | EXPORT_SYMBOL(ioread16); | |
76637536 | 38 | EXPORT_SYMBOL(ioread16be); |
1da177e4 | 39 | EXPORT_SYMBOL(ioread32); |
76637536 | 40 | EXPORT_SYMBOL(ioread32be); |
1da177e4 | 41 | |
8943212c | 42 | void iowrite8(u8 val, void __iomem *addr) |
1da177e4 LT |
43 | { |
44 | writeb(val, addr); | |
45 | } | |
8943212c | 46 | void iowrite16(u16 val, void __iomem *addr) |
1da177e4 LT |
47 | { |
48 | writew(val, addr); | |
49 | } | |
8943212c | 50 | void iowrite16be(u16 val, void __iomem *addr) |
76637536 AO |
51 | { |
52 | out_be16(addr, val); | |
53 | } | |
8943212c | 54 | void iowrite32(u32 val, void __iomem *addr) |
1da177e4 LT |
55 | { |
56 | writel(val, addr); | |
57 | } | |
8943212c | 58 | void iowrite32be(u32 val, void __iomem *addr) |
76637536 AO |
59 | { |
60 | out_be32(addr, val); | |
61 | } | |
1da177e4 LT |
62 | EXPORT_SYMBOL(iowrite8); |
63 | EXPORT_SYMBOL(iowrite16); | |
76637536 | 64 | EXPORT_SYMBOL(iowrite16be); |
1da177e4 | 65 | EXPORT_SYMBOL(iowrite32); |
76637536 | 66 | EXPORT_SYMBOL(iowrite32be); |
1da177e4 LT |
67 | |
68 | /* | |
69 | * These are the "repeat read/write" functions. Note the | |
70 | * non-CPU byte order. We do things in "IO byteorder" | |
71 | * here. | |
72 | * | |
73 | * FIXME! We could make these do EEH handling if we really | |
74 | * wanted. Not clear if we do. | |
75 | */ | |
76 | void ioread8_rep(void __iomem *addr, void *dst, unsigned long count) | |
77 | { | |
6c9afc65 | 78 | _insb((u8 __iomem *) addr, dst, count); |
1da177e4 LT |
79 | } |
80 | void ioread16_rep(void __iomem *addr, void *dst, unsigned long count) | |
81 | { | |
6c9afc65 | 82 | _insw_ns((u16 __iomem *) addr, dst, count); |
1da177e4 LT |
83 | } |
84 | void ioread32_rep(void __iomem *addr, void *dst, unsigned long count) | |
85 | { | |
6c9afc65 | 86 | _insl_ns((u32 __iomem *) addr, dst, count); |
1da177e4 LT |
87 | } |
88 | EXPORT_SYMBOL(ioread8_rep); | |
89 | EXPORT_SYMBOL(ioread16_rep); | |
90 | EXPORT_SYMBOL(ioread32_rep); | |
91 | ||
92 | void iowrite8_rep(void __iomem *addr, const void *src, unsigned long count) | |
93 | { | |
6c9afc65 | 94 | _outsb((u8 __iomem *) addr, src, count); |
1da177e4 LT |
95 | } |
96 | void iowrite16_rep(void __iomem *addr, const void *src, unsigned long count) | |
97 | { | |
6c9afc65 | 98 | _outsw_ns((u16 __iomem *) addr, src, count); |
1da177e4 LT |
99 | } |
100 | void iowrite32_rep(void __iomem *addr, const void *src, unsigned long count) | |
101 | { | |
6c9afc65 | 102 | _outsl_ns((u32 __iomem *) addr, src, count); |
1da177e4 LT |
103 | } |
104 | EXPORT_SYMBOL(iowrite8_rep); | |
105 | EXPORT_SYMBOL(iowrite16_rep); | |
106 | EXPORT_SYMBOL(iowrite32_rep); | |
107 | ||
108 | void __iomem *ioport_map(unsigned long port, unsigned int len) | |
109 | { | |
68a64357 | 110 | return (void __iomem *) (port + _IO_BASE); |
1da177e4 LT |
111 | } |
112 | ||
113 | void ioport_unmap(void __iomem *addr) | |
114 | { | |
115 | /* Nothing to do */ | |
116 | } | |
117 | EXPORT_SYMBOL(ioport_map); | |
118 | EXPORT_SYMBOL(ioport_unmap); | |
119 | ||
81210c20 | 120 | #ifdef CONFIG_PCI |
1da177e4 LT |
121 | void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max) |
122 | { | |
472b5b43 VB |
123 | resource_size_t start = pci_resource_start(dev, bar); |
124 | resource_size_t len = pci_resource_len(dev, bar); | |
1da177e4 LT |
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 | ||
139 | void pci_iounmap(struct pci_dev *dev, void __iomem *addr) | |
140 | { | |
50747cb8 BH |
141 | if (isa_vaddr_is_ioport(addr)) |
142 | return; | |
143 | if (pcibios_vaddr_is_ioport(addr)) | |
144 | return; | |
145 | iounmap(addr); | |
1da177e4 | 146 | } |
50747cb8 | 147 | |
1da177e4 LT |
148 | EXPORT_SYMBOL(pci_iomap); |
149 | EXPORT_SYMBOL(pci_iounmap); | |
a85fe3fc | 150 | #endif /* CONFIG_PCI */ |