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