xref: /openbmc/linux/arch/sparc/include/asm/io_32.h (revision db181ce0)
1 #ifndef __SPARC_IO_H
2 #define __SPARC_IO_H
3 
4 #include <linux/kernel.h>
5 #include <linux/ioport.h>  /* struct resource */
6 
7 #define readb_relaxed(__addr)	readb(__addr)
8 #define readw_relaxed(__addr)	readw(__addr)
9 #define readl_relaxed(__addr)	readl(__addr)
10 
11 #define IO_SPACE_LIMIT 0xffffffff
12 
13 #define memset_io(d,c,sz)     _memset_io(d,c,sz)
14 #define memcpy_fromio(d,s,sz) _memcpy_fromio(d,s,sz)
15 #define memcpy_toio(d,s,sz)   _memcpy_toio(d,s,sz)
16 
17 #include <asm-generic/io.h>
18 
19 static inline void _memset_io(volatile void __iomem *dst,
20                               int c, __kernel_size_t n)
21 {
22 	volatile void __iomem *d = dst;
23 
24 	while (n--) {
25 		writeb(c, d);
26 		d++;
27 	}
28 }
29 
30 static inline void _memcpy_fromio(void *dst, const volatile void __iomem *src,
31                                   __kernel_size_t n)
32 {
33 	char *d = dst;
34 
35 	while (n--) {
36 		char tmp = readb(src);
37 		*d++ = tmp;
38 		src++;
39 	}
40 }
41 
42 static inline void _memcpy_toio(volatile void __iomem *dst, const void *src,
43                                 __kernel_size_t n)
44 {
45 	const char *s = src;
46 	volatile void __iomem *d = dst;
47 
48 	while (n--) {
49 		char tmp = *s++;
50 		writeb(tmp, d);
51 		d++;
52 	}
53 }
54 
55 /*
56  * SBus accessors.
57  *
58  * SBus has only one, memory mapped, I/O space.
59  * We do not need to flip bytes for SBus of course.
60  */
61 static inline u8 sbus_readb(const volatile void __iomem *addr)
62 {
63 	return *(__force volatile u8 *)addr;
64 }
65 
66 static inline u16 sbus_readw(const volatile void __iomem *addr)
67 {
68 	return *(__force volatile u16 *)addr;
69 }
70 
71 static inline u32 sbus_readl(const volatile void __iomem *addr)
72 {
73 	return *(__force volatile u32 *)addr;
74 }
75 
76 static inline void sbus_writeb(u8 b, volatile void __iomem *addr)
77 {
78 	*(__force volatile u8 *)addr = b;
79 }
80 
81 static inline void sbus_writew(u16 w, volatile void __iomem *addr)
82 {
83 	*(__force volatile u16 *)addr = w;
84 }
85 
86 static inline void sbus_writel(u32 l, volatile void __iomem *addr)
87 {
88 	*(__force volatile u32 *)addr = l;
89 }
90 
91 static inline void sbus_memset_io(volatile void __iomem *__dst, int c,
92                                   __kernel_size_t n)
93 {
94 	while(n--) {
95 		sbus_writeb(c, __dst);
96 		__dst++;
97 	}
98 }
99 
100 static inline void sbus_memcpy_fromio(void *dst,
101                                       const volatile void __iomem *src,
102                                       __kernel_size_t n)
103 {
104 	char *d = dst;
105 
106 	while (n--) {
107 		char tmp = sbus_readb(src);
108 		*d++ = tmp;
109 		src++;
110 	}
111 }
112 
113 static inline void sbus_memcpy_toio(volatile void __iomem *dst,
114                                     const void *src,
115                                     __kernel_size_t n)
116 {
117 	const char *s = src;
118 	volatile void __iomem *d = dst;
119 
120 	while (n--) {
121 		char tmp = *s++;
122 		sbus_writeb(tmp, d);
123 		d++;
124 	}
125 }
126 
127 #ifdef __KERNEL__
128 
129 /*
130  * Bus number may be embedded in the higher bits of the physical address.
131  * This is why we have no bus number argument to ioremap().
132  */
133 void __iomem *ioremap(unsigned long offset, unsigned long size);
134 #define ioremap_nocache(X,Y)	ioremap((X),(Y))
135 #define ioremap_wc(X,Y)		ioremap((X),(Y))
136 void iounmap(volatile void __iomem *addr);
137 
138 /* Create a virtual mapping cookie for an IO port range */
139 void __iomem *ioport_map(unsigned long port, unsigned int nr);
140 void ioport_unmap(void __iomem *);
141 
142 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
143 struct pci_dev;
144 void pci_iounmap(struct pci_dev *dev, void __iomem *);
145 
146 
147 
148 /*
149  * At the moment, we do not use CMOS_READ anywhere outside of rtc.c,
150  * so rtc_port is static in it. This should not change unless a new
151  * hardware pops up.
152  */
153 #define RTC_PORT(x)   (rtc_port + (x))
154 #define RTC_ALWAYS_BCD  0
155 
156 static inline int sbus_can_dma_64bit(void)
157 {
158 	return 0; /* actually, sparc_cpu_model==sun4d */
159 }
160 static inline int sbus_can_burst64(void)
161 {
162 	return 0; /* actually, sparc_cpu_model==sun4d */
163 }
164 struct device;
165 void sbus_set_sbus64(struct device *, int);
166 
167 #endif
168 
169 #define __ARCH_HAS_NO_PAGE_ZERO_MAPPED		1
170 
171 
172 #endif /* !(__SPARC_IO_H) */
173