xref: /openbmc/u-boot/arch/sandbox/include/asm/io.h (revision 3949d2a7)
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 #ifdef CONFIG_SANDBOX64
47 #define readq(addr) ((void)addr, 0)
48 #endif
49 #define writeb(v, addr) ((void)addr)
50 #define writew(v, addr) ((void)addr)
51 #define writel(v, addr) ((void)addr)
52 #ifdef CONFIG_SANDBOX64
53 #define writeq(v, addr) ((void)addr)
54 #endif
55 
56 /*
57  * Clear and set bits in one shot. These macros can be used to clear and
58  * set multiple bits in a register using a single call. These macros can
59  * also be used to set a multiple-bit bit pattern using a mask, by
60  * specifying the mask in the 'clear' parameter and the new bit pattern
61  * in the 'set' parameter.
62  */
63 
64 #define out_arch(type,endian,a,v)	write##type(cpu_to_##endian(v),a)
65 #define in_arch(type,endian,a)		endian##_to_cpu(read##type(a))
66 
67 #define out_le64(a,v)	out_arch(q,le64,a,v)
68 #define out_le32(a,v)	out_arch(l,le32,a,v)
69 #define out_le16(a,v)	out_arch(w,le16,a,v)
70 
71 #define in_le64(a)	in_arch(q,le64,a)
72 #define in_le32(a)	in_arch(l,le32,a)
73 #define in_le16(a)	in_arch(w,le16,a)
74 
75 #define out_be32(a,v)	out_arch(l,be32,a,v)
76 #define out_be16(a,v)	out_arch(w,be16,a,v)
77 
78 #define in_be32(a)	in_arch(l,be32,a)
79 #define in_be16(a)	in_arch(w,be16,a)
80 
81 #define out_8(a,v)	writeb(v,a)
82 #define in_8(a)		readb(a)
83 
84 #define clrbits(type, addr, clear) \
85 	out_##type((addr), in_##type(addr) & ~(clear))
86 
87 #define setbits(type, addr, set) \
88 	out_##type((addr), in_##type(addr) | (set))
89 
90 #define clrsetbits(type, addr, clear, set) \
91 	out_##type((addr), (in_##type(addr) & ~(clear)) | (set))
92 
93 #define clrbits_be32(addr, clear) clrbits(be32, addr, clear)
94 #define setbits_be32(addr, set) setbits(be32, addr, set)
95 #define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set)
96 
97 #define clrbits_le32(addr, clear) clrbits(le32, addr, clear)
98 #define setbits_le32(addr, set) setbits(le32, addr, set)
99 #define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set)
100 
101 #define clrbits_be16(addr, clear) clrbits(be16, addr, clear)
102 #define setbits_be16(addr, set) setbits(be16, addr, set)
103 #define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set)
104 
105 #define clrbits_le16(addr, clear) clrbits(le16, addr, clear)
106 #define setbits_le16(addr, set) setbits(le16, addr, set)
107 #define clrsetbits_le16(addr, clear, set) clrsetbits(le16, addr, clear, set)
108 
109 #define clrbits_8(addr, clear) clrbits(8, addr, clear)
110 #define setbits_8(addr, set) setbits(8, addr, set)
111 #define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set)
112 
113 /* I/O access functions */
114 int inl(unsigned int addr);
115 int inw(unsigned int addr);
116 int inb(unsigned int addr);
117 
118 void outl(unsigned int value, unsigned int addr);
119 void outw(unsigned int value, unsigned int addr);
120 void outb(unsigned int value, unsigned int addr);
121 
122 #define out_arch(type,endian,a,v)	write##type(cpu_to_##endian(v),a)
123 #define in_arch(type,endian,a)		endian##_to_cpu(read##type(a))
124 
125 #define out_le32(a,v)	out_arch(l,le32,a,v)
126 #define out_le16(a,v)	out_arch(w,le16,a,v)
127 
128 #define in_le32(a)	in_arch(l,le32,a)
129 #define in_le16(a)	in_arch(w,le16,a)
130 
131 #define out_be32(a,v)	out_arch(l,be32,a,v)
132 #define out_be16(a,v)	out_arch(w,be16,a,v)
133 
134 #define in_be32(a)	in_arch(l,be32,a)
135 #define in_be16(a)	in_arch(w,be16,a)
136 
137 #define out_8(a,v)	writeb(v,a)
138 #define in_8(a)		readb(a)
139 
140 #define clrbits(type, addr, clear) \
141 	out_##type((addr), in_##type(addr) & ~(clear))
142 
143 #define setbits(type, addr, set) \
144 	out_##type((addr), in_##type(addr) | (set))
145 
146 #define clrsetbits(type, addr, clear, set) \
147 	out_##type((addr), (in_##type(addr) & ~(clear)) | (set))
148 
149 #define clrbits_be32(addr, clear) clrbits(be32, addr, clear)
150 #define setbits_be32(addr, set) setbits(be32, addr, set)
151 #define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set)
152 
153 #define clrbits_le32(addr, clear) clrbits(le32, addr, clear)
154 #define setbits_le32(addr, set) setbits(le32, addr, set)
155 #define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set)
156 
157 #define clrbits_be16(addr, clear) clrbits(be16, addr, clear)
158 #define setbits_be16(addr, set) setbits(be16, addr, set)
159 #define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set)
160 
161 #define clrbits_le16(addr, clear) clrbits(le16, addr, clear)
162 #define setbits_le16(addr, set) setbits(le16, addr, set)
163 #define clrsetbits_le16(addr, clear, set) clrsetbits(le16, addr, clear, set)
164 
165 #define clrbits_8(addr, clear) clrbits(8, addr, clear)
166 #define setbits_8(addr, set) setbits(8, addr, set)
167 #define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set)
168 
169 static inline void _insw(volatile u16 *port, void *buf, int ns)
170 {
171 }
172 
173 static inline void _outsw(volatile u16 *port, const void *buf, int ns)
174 {
175 }
176 
177 #define insw(port, buf, ns)		_insw((u16 *)port, buf, ns)
178 #define outsw(port, buf, ns)		_outsw((u16 *)port, buf, ns)
179 
180 #include <iotrace.h>
181 #include <asm/types.h>
182 
183 #endif
184