xref: /openbmc/u-boot/arch/sandbox/include/asm/io.h (revision 7c75f7f1)
1 /*
2  * Copyright (c) 2011 The Chromium OS Authors.
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #ifndef __SANDBOX_ASM_IO_H
8 #define __SANDBOX_ASM_IO_H
9 
10 void *phys_to_virt(phys_addr_t paddr);
11 #define phys_to_virt phys_to_virt
12 
13 phys_addr_t virt_to_phys(void *vaddr);
14 #define virt_to_phys virt_to_phys
15 
16 void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags);
17 #define map_physmem map_physmem
18 
19 /*
20  * Take down a mapping set up by map_physmem().
21  */
22 void unmap_physmem(const void *vaddr, unsigned long flags);
23 #define unmap_physmem unmap_physmem
24 
25 #include <asm-generic/io.h>
26 
27 /* For sandbox, we want addresses to point into our RAM buffer */
28 static inline void *map_sysmem(phys_addr_t paddr, unsigned long len)
29 {
30 	return map_physmem(paddr, len, MAP_WRBACK);
31 }
32 
33 /* Remove a previous mapping */
34 static inline void unmap_sysmem(const void *vaddr)
35 {
36 	unmap_physmem(vaddr, MAP_WRBACK);
37 }
38 
39 /* Map from a pointer to our RAM buffer */
40 phys_addr_t map_to_sysmem(const void *ptr);
41 
42 /* Define nops for sandbox I/O access */
43 #define readb(addr) ((void)addr, 0)
44 #define readw(addr) ((void)addr, 0)
45 #define readl(addr) ((void)addr, 0)
46 #define writeb(v, addr) ((void)addr)
47 #define writew(v, addr) ((void)addr)
48 #define writel(v, addr) ((void)addr)
49 
50 /*
51  * Clear and set bits in one shot. These macros can be used to clear and
52  * set multiple bits in a register using a single call. These macros can
53  * also be used to set a multiple-bit bit pattern using a mask, by
54  * specifying the mask in the 'clear' parameter and the new bit pattern
55  * in the 'set' parameter.
56  */
57 
58 #define out_arch(type,endian,a,v)	write##type(cpu_to_##endian(v),a)
59 #define in_arch(type,endian,a)		endian##_to_cpu(read##type(a))
60 
61 #define out_le64(a,v)	out_arch(q,le64,a,v)
62 #define out_le32(a,v)	out_arch(l,le32,a,v)
63 #define out_le16(a,v)	out_arch(w,le16,a,v)
64 
65 #define in_le64(a)	in_arch(q,le64,a)
66 #define in_le32(a)	in_arch(l,le32,a)
67 #define in_le16(a)	in_arch(w,le16,a)
68 
69 #define out_be32(a,v)	out_arch(l,be32,a,v)
70 #define out_be16(a,v)	out_arch(w,be16,a,v)
71 
72 #define in_be32(a)	in_arch(l,be32,a)
73 #define in_be16(a)	in_arch(w,be16,a)
74 
75 #define out_8(a,v)	writeb(v,a)
76 #define in_8(a)		readb(a)
77 
78 #define clrbits(type, addr, clear) \
79 	out_##type((addr), in_##type(addr) & ~(clear))
80 
81 #define setbits(type, addr, set) \
82 	out_##type((addr), in_##type(addr) | (set))
83 
84 #define clrsetbits(type, addr, clear, set) \
85 	out_##type((addr), (in_##type(addr) & ~(clear)) | (set))
86 
87 #define clrbits_be32(addr, clear) clrbits(be32, addr, clear)
88 #define setbits_be32(addr, set) setbits(be32, addr, set)
89 #define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set)
90 
91 #define clrbits_le32(addr, clear) clrbits(le32, addr, clear)
92 #define setbits_le32(addr, set) setbits(le32, addr, set)
93 #define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set)
94 
95 #define clrbits_be16(addr, clear) clrbits(be16, addr, clear)
96 #define setbits_be16(addr, set) setbits(be16, addr, set)
97 #define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set)
98 
99 #define clrbits_le16(addr, clear) clrbits(le16, addr, clear)
100 #define setbits_le16(addr, set) setbits(le16, addr, set)
101 #define clrsetbits_le16(addr, clear, set) clrsetbits(le16, addr, clear, set)
102 
103 #define clrbits_8(addr, clear) clrbits(8, addr, clear)
104 #define setbits_8(addr, set) setbits(8, addr, set)
105 #define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set)
106 
107 /* I/O access functions */
108 int inl(unsigned int addr);
109 int inw(unsigned int addr);
110 int inb(unsigned int addr);
111 
112 void outl(unsigned int value, unsigned int addr);
113 void outw(unsigned int value, unsigned int addr);
114 void outb(unsigned int value, unsigned int addr);
115 
116 #define out_arch(type,endian,a,v)	write##type(cpu_to_##endian(v),a)
117 #define in_arch(type,endian,a)		endian##_to_cpu(read##type(a))
118 
119 #define out_le32(a,v)	out_arch(l,le32,a,v)
120 #define out_le16(a,v)	out_arch(w,le16,a,v)
121 
122 #define in_le32(a)	in_arch(l,le32,a)
123 #define in_le16(a)	in_arch(w,le16,a)
124 
125 #define out_be32(a,v)	out_arch(l,be32,a,v)
126 #define out_be16(a,v)	out_arch(w,be16,a,v)
127 
128 #define in_be32(a)	in_arch(l,be32,a)
129 #define in_be16(a)	in_arch(w,be16,a)
130 
131 #define out_8(a,v)	writeb(v,a)
132 #define in_8(a)		readb(a)
133 
134 #define clrbits(type, addr, clear) \
135 	out_##type((addr), in_##type(addr) & ~(clear))
136 
137 #define setbits(type, addr, set) \
138 	out_##type((addr), in_##type(addr) | (set))
139 
140 #define clrsetbits(type, addr, clear, set) \
141 	out_##type((addr), (in_##type(addr) & ~(clear)) | (set))
142 
143 #define clrbits_be32(addr, clear) clrbits(be32, addr, clear)
144 #define setbits_be32(addr, set) setbits(be32, addr, set)
145 #define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set)
146 
147 #define clrbits_le32(addr, clear) clrbits(le32, addr, clear)
148 #define setbits_le32(addr, set) setbits(le32, addr, set)
149 #define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set)
150 
151 #define clrbits_be16(addr, clear) clrbits(be16, addr, clear)
152 #define setbits_be16(addr, set) setbits(be16, addr, set)
153 #define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set)
154 
155 #define clrbits_le16(addr, clear) clrbits(le16, addr, clear)
156 #define setbits_le16(addr, set) setbits(le16, addr, set)
157 #define clrsetbits_le16(addr, clear, set) clrsetbits(le16, addr, clear, set)
158 
159 #define clrbits_8(addr, clear) clrbits(8, addr, clear)
160 #define setbits_8(addr, set) setbits(8, addr, set)
161 #define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set)
162 
163 static inline void _insw(volatile u16 *port, void *buf, int ns)
164 {
165 }
166 
167 static inline void _outsw(volatile u16 *port, const void *buf, int ns)
168 {
169 }
170 
171 #define insw(port, buf, ns)		_insw((u16 *)port, buf, ns)
172 #define outsw(port, buf, ns)		_outsw((u16 *)port, buf, ns)
173 
174 /* For systemace.c */
175 #define out16(addr, val)
176 #define in16(addr)		0
177 
178 #include <iotrace.h>
179 #include <asm/types.h>
180 
181 #endif
182