2 * arch/ubicom32/mach-common/io.c
3 * PCI I/O memory read/write support functions.
5 * (C) Copyright 2009, Ubicom, Inc.
7 * This file is part of the Ubicom32 Linux Kernel Port.
9 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
10 * it and/or modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation, either version 2 of the
12 * License, or (at your option) any later version.
14 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with the Ubicom32 Linux Kernel Port. If not,
21 * see <http://www.gnu.org/licenses/>.
23 * Ubicom32 implementation derived from (with many thanks):
28 #include <linux/module.h>
29 #include <linux/kernel.h>
33 unsigned char ioread8(void __iomem
*addr
)
35 if (IS_PCI_ADDRESS(addr
))
36 return ubi32_pci_read_u8(addr
);
38 return (unsigned char)(*(volatile unsigned char *)addr
);
40 EXPORT_SYMBOL(ioread8
);
42 unsigned short ioread16(void __iomem
*addr
)
44 if (IS_PCI_ADDRESS(addr
))
45 return ubi32_pci_read_u16(addr
);
47 return (unsigned short)(*(volatile unsigned short *)addr
);
49 EXPORT_SYMBOL(ioread16
);
51 unsigned int ioread32(void __iomem
*addr
)
53 if (IS_PCI_ADDRESS(addr
))
54 return ubi32_pci_read_u32(addr
);
56 return (unsigned int)(*(volatile unsigned int *)addr
);
58 EXPORT_SYMBOL(ioread32
);
60 void iowrite32(unsigned int val
, void __iomem
*addr
)
62 if (IS_PCI_ADDRESS(addr
))
63 ubi32_pci_write_u32(val
, addr
);
65 *(volatile unsigned int *)addr
= val
;
67 EXPORT_SYMBOL(iowrite32
);
69 void iowrite16(unsigned short val
, void __iomem
*addr
)
71 if (IS_PCI_ADDRESS(addr
))
72 ubi32_pci_write_u16(val
, addr
);
74 *(volatile unsigned short *)addr
= val
;
76 EXPORT_SYMBOL(iowrite16
);
78 void iowrite8(unsigned char val
, void __iomem
*addr
)
80 if (IS_PCI_ADDRESS(addr
))
81 ubi32_pci_write_u8(val
, addr
);
83 *(volatile unsigned char *)addr
= val
;
85 EXPORT_SYMBOL(iowrite8
);
87 void memcpy_fromio(void *to
, const volatile void __iomem
*from
, unsigned len
)
89 if (IS_PCI_ADDRESS(from
)) {
90 if ((((u32_t
)from
& 0x3) == 0) && (((u32_t
)to
& 0x3) == 0)) {
91 while ((int)len
>= 4) {
92 *(u32_t
*)to
= ubi32_pci_read_u32(from
);
97 } else if ((((u32_t
)from
& 0x1) == 0) &&
98 (((u32_t
)to
& 0x1) == 0)) {
99 while ((int)len
>= 2) {
100 *(u16_t
*)to
= ubi32_pci_read_u16(from
);
108 *(u8_t
*)to
= ubi32_pci_read_u8(from
);
114 memcpy(to
, (void *)from
, len
);
116 EXPORT_SYMBOL(memcpy_fromio
);
118 void memcpy_toio(volatile void __iomem
*to
, const void *from
, unsigned len
)
120 if (IS_PCI_ADDRESS(to
)) {
121 if ((((u32_t
)from
& 0x3) == 0) && (((u32_t
)to
& 0x3) == 0)) {
122 while ((int)len
>= 4) {
123 ubi32_pci_write_u32(*(u32_t
*)from
, to
);
128 } else if ((((u32_t
)from
& 0x1) == 0) &&
129 (((u32_t
)to
& 0x1) == 0)) {
130 while ((int)len
>= 2) {
131 ubi32_pci_write_u16(*(u16_t
*)from
, to
);
139 ubi32_pci_write_u8(*(u8_t
*)from
, to
);
145 memcpy((void *)to
, from
, len
);
148 EXPORT_SYMBOL(memcpy_toio
);
150 void memset_io(volatile void __iomem
*addr
, int val
, size_t len
)
152 if (IS_PCI_ADDRESS(addr
)) {
154 ubi32_pci_write_u8((unsigned char)val
, addr
);
159 memset((void *)addr
, val
, len
);
162 EXPORT_SYMBOL(memset_io
);
164 void ioread8_rep(void __iomem
*port
, void *buf
, unsigned long count
)
166 if (IS_PCI_ADDRESS(port
)) {
168 *(u8_t
*)buf
= ioread8(port
);
173 insb((unsigned int)port
, buf
, count
);
177 EXPORT_SYMBOL(ioread8_rep
);
179 void ioread16_rep(void __iomem
*port
, void *buf
, unsigned long count
)
181 if (IS_PCI_ADDRESS(port
)) {
183 *(u16_t
*)buf
= ioread16(port
);
188 insw((unsigned int)port
, buf
, count
);
191 EXPORT_SYMBOL(ioread16_rep
);
193 void ioread32_rep(void __iomem
*port
, void *buf
, unsigned long count
)
195 if (IS_PCI_ADDRESS(port
)) {
197 *(u32_t
*)buf
= ioread32(port
);
202 insl((unsigned int)port
, buf
, count
);
205 EXPORT_SYMBOL(ioread32_rep
);
207 void iowrite8_rep(void __iomem
*port
, const void *buf
, unsigned long count
)
209 if (IS_PCI_ADDRESS(port
)) {
211 iowrite8(*(u8_t
*)buf
, port
);
216 outsb((unsigned int)port
, buf
, count
);
220 EXPORT_SYMBOL(iowrite8_rep
);
222 void iowrite16_rep(void __iomem
*port
, const void *buf
, unsigned long count
)
224 if (IS_PCI_ADDRESS(port
)) {
226 iowrite16(*(u16_t
*)buf
, port
);
231 outsw((unsigned int)port
, buf
, count
);
234 EXPORT_SYMBOL(iowrite16_rep
);
236 void iowrite32_rep(void __iomem
*port
, const void *buf
, unsigned long count
)
238 if (IS_PCI_ADDRESS(port
)) {
240 iowrite32(*(u32_t
*)buf
, port
);
245 outsl((unsigned int)port
, buf
, count
);
248 EXPORT_SYMBOL(iowrite32_rep
);
250 #endif /* CONFIG_PCI */