xref: /openbmc/linux/arch/powerpc/kernel/iomap.c (revision a36954f5)
1 /*
2  * ppc64 "iomap" interface implementation.
3  *
4  * (C) Copyright 2004 Linus Torvalds
5  */
6 #include <linux/pci.h>
7 #include <linux/mm.h>
8 #include <linux/export.h>
9 #include <asm/io.h>
10 #include <asm/pci-bridge.h>
11 #include <asm/isa-bridge.h>
12 
13 /*
14  * Here comes the ppc64 implementation of the IOMAP
15  * interfaces.
16  */
17 unsigned int ioread8(void __iomem *addr)
18 {
19 	return readb(addr);
20 }
21 unsigned int ioread16(void __iomem *addr)
22 {
23 	return readw(addr);
24 }
25 unsigned int ioread16be(void __iomem *addr)
26 {
27 	return readw_be(addr);
28 }
29 unsigned int ioread32(void __iomem *addr)
30 {
31 	return readl(addr);
32 }
33 unsigned int ioread32be(void __iomem *addr)
34 {
35 	return readl_be(addr);
36 }
37 EXPORT_SYMBOL(ioread8);
38 EXPORT_SYMBOL(ioread16);
39 EXPORT_SYMBOL(ioread16be);
40 EXPORT_SYMBOL(ioread32);
41 EXPORT_SYMBOL(ioread32be);
42 #ifdef __powerpc64__
43 u64 ioread64(void __iomem *addr)
44 {
45 	return readq(addr);
46 }
47 u64 ioread64be(void __iomem *addr)
48 {
49 	return readq_be(addr);
50 }
51 EXPORT_SYMBOL(ioread64);
52 EXPORT_SYMBOL(ioread64be);
53 #endif /* __powerpc64__ */
54 
55 void iowrite8(u8 val, void __iomem *addr)
56 {
57 	writeb(val, addr);
58 }
59 void iowrite16(u16 val, void __iomem *addr)
60 {
61 	writew(val, addr);
62 }
63 void iowrite16be(u16 val, void __iomem *addr)
64 {
65 	writew_be(val, addr);
66 }
67 void iowrite32(u32 val, void __iomem *addr)
68 {
69 	writel(val, addr);
70 }
71 void iowrite32be(u32 val, void __iomem *addr)
72 {
73 	writel_be(val, addr);
74 }
75 EXPORT_SYMBOL(iowrite8);
76 EXPORT_SYMBOL(iowrite16);
77 EXPORT_SYMBOL(iowrite16be);
78 EXPORT_SYMBOL(iowrite32);
79 EXPORT_SYMBOL(iowrite32be);
80 #ifdef __powerpc64__
81 void iowrite64(u64 val, void __iomem *addr)
82 {
83 	writeq(val, addr);
84 }
85 void iowrite64be(u64 val, void __iomem *addr)
86 {
87 	writeq_be(val, addr);
88 }
89 EXPORT_SYMBOL(iowrite64);
90 EXPORT_SYMBOL(iowrite64be);
91 #endif /* __powerpc64__ */
92 
93 /*
94  * These are the "repeat read/write" functions. Note the
95  * non-CPU byte order. We do things in "IO byteorder"
96  * here.
97  *
98  * FIXME! We could make these do EEH handling if we really
99  * wanted. Not clear if we do.
100  */
101 void ioread8_rep(void __iomem *addr, void *dst, unsigned long count)
102 {
103 	readsb(addr, dst, count);
104 }
105 void ioread16_rep(void __iomem *addr, void *dst, unsigned long count)
106 {
107 	readsw(addr, dst, count);
108 }
109 void ioread32_rep(void __iomem *addr, void *dst, unsigned long count)
110 {
111 	readsl(addr, dst, count);
112 }
113 EXPORT_SYMBOL(ioread8_rep);
114 EXPORT_SYMBOL(ioread16_rep);
115 EXPORT_SYMBOL(ioread32_rep);
116 
117 void iowrite8_rep(void __iomem *addr, const void *src, unsigned long count)
118 {
119 	writesb(addr, src, count);
120 }
121 void iowrite16_rep(void __iomem *addr, const void *src, unsigned long count)
122 {
123 	writesw(addr, src, count);
124 }
125 void iowrite32_rep(void __iomem *addr, const void *src, unsigned long count)
126 {
127 	writesl(addr, src, count);
128 }
129 EXPORT_SYMBOL(iowrite8_rep);
130 EXPORT_SYMBOL(iowrite16_rep);
131 EXPORT_SYMBOL(iowrite32_rep);
132 
133 void __iomem *ioport_map(unsigned long port, unsigned int len)
134 {
135 	return (void __iomem *) (port + _IO_BASE);
136 }
137 
138 void ioport_unmap(void __iomem *addr)
139 {
140 	/* Nothing to do */
141 }
142 EXPORT_SYMBOL(ioport_map);
143 EXPORT_SYMBOL(ioport_unmap);
144 
145 #ifdef CONFIG_PCI
146 void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
147 {
148 	if (isa_vaddr_is_ioport(addr))
149 		return;
150 	if (pcibios_vaddr_is_ioport(addr))
151 		return;
152 	iounmap(addr);
153 }
154 
155 EXPORT_SYMBOL(pci_iounmap);
156 #endif /* CONFIG_PCI */
157