blob: 2a350a826c4bc240a61479273f0cb1fc43c4e90a [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass744d9852011-10-10 08:22:14 +00002/*
3 * Copyright (c) 2011 The Chromium OS Authors.
Simon Glass744d9852011-10-10 08:22:14 +00004 */
5
Simon Glassa733b062013-04-26 02:53:43 +00006#ifndef __SANDBOX_ASM_IO_H
7#define __SANDBOX_ASM_IO_H
8
Paul Burtonf7ae1ca2017-09-14 15:05:13 -07009void *phys_to_virt(phys_addr_t paddr);
10#define phys_to_virt phys_to_virt
11
12phys_addr_t virt_to_phys(void *vaddr);
13#define virt_to_phys virt_to_phys
Simon Glass744d9852011-10-10 08:22:14 +000014
15void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags);
Paul Burtonf7ae1ca2017-09-14 15:05:13 -070016#define map_physmem map_physmem
Simon Glass744d9852011-10-10 08:22:14 +000017
18/*
19 * Take down a mapping set up by map_physmem().
20 */
Simon Glass9569c402015-03-05 12:25:26 -070021void unmap_physmem(const void *vaddr, unsigned long flags);
Paul Burtonf7ae1ca2017-09-14 15:05:13 -070022#define unmap_physmem unmap_physmem
23
24#include <asm-generic/io.h>
Simon Glass4213fc22013-02-24 17:33:14 +000025
26/* For sandbox, we want addresses to point into our RAM buffer */
27static inline void *map_sysmem(phys_addr_t paddr, unsigned long len)
28{
29 return map_physmem(paddr, len, MAP_WRBACK);
30}
31
Simon Glass9569c402015-03-05 12:25:26 -070032/* Remove a previous mapping */
Simon Glass4213fc22013-02-24 17:33:14 +000033static inline void unmap_sysmem(const void *vaddr)
34{
Simon Glass9569c402015-03-05 12:25:26 -070035 unmap_physmem(vaddr, MAP_WRBACK);
Simon Glass4213fc22013-02-24 17:33:14 +000036}
Simon Glass781adb52013-04-20 08:42:37 +000037
38/* Map from a pointer to our RAM buffer */
Simon Glassed072b92013-11-07 09:31:58 -070039phys_addr_t map_to_sysmem(const void *ptr);
Simon Glassa733b062013-04-26 02:53:43 +000040
Simon Glass42d3b292014-06-11 23:29:43 -060041/* Define nops for sandbox I/O access */
Simon Glass80793db2016-10-01 14:42:33 -060042#define readb(addr) ((void)addr, 0)
43#define readw(addr) ((void)addr, 0)
44#define readl(addr) ((void)addr, 0)
Mario Sixc6b89f32018-02-12 08:05:57 +010045#ifdef CONFIG_SANDBOX64
46#define readq(addr) ((void)addr, 0)
47#endif
Simon Glass80793db2016-10-01 14:42:33 -060048#define writeb(v, addr) ((void)addr)
49#define writew(v, addr) ((void)addr)
50#define writel(v, addr) ((void)addr)
Mario Sixc6b89f32018-02-12 08:05:57 +010051#ifdef CONFIG_SANDBOX64
52#define writeq(v, addr) ((void)addr)
53#endif
Simon Glass42d3b292014-06-11 23:29:43 -060054
Tom Rini35172cf2017-09-29 08:53:53 -040055/*
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
Simon Glass9569c402015-03-05 12:25:26 -0700112/* I/O access functions */
113int inl(unsigned int addr);
114int inw(unsigned int addr);
115int inb(unsigned int addr);
116
117void outl(unsigned int value, unsigned int addr);
118void outw(unsigned int value, unsigned int addr);
119void outb(unsigned int value, unsigned int addr);
120
Maxime Riparda4dd8722017-10-02 15:25:56 +0200121#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
Simon Glasse54094f2016-05-01 11:35:54 -0600168static inline void _insw(volatile u16 *port, void *buf, int ns)
169{
170}
171
172static inline void _outsw(volatile u16 *port, const void *buf, int ns)
173{
174}
175
Christian GMEINER98144302018-12-04 20:35:24 +0100176static inline void memset_io(volatile void *addr, unsigned char val, int count)
177{
178}
179
180static inline void memcpy_fromio(void *dst, const volatile void *src, int count)
181{
182}
183
184static inline void memcpy_toio(volatile void *dst, const void *src, int count)
185{
186}
187
Simon Glasse54094f2016-05-01 11:35:54 -0600188#define insw(port, buf, ns) _insw((u16 *)port, buf, ns)
189#define outsw(port, buf, ns) _outsw((u16 *)port, buf, ns)
190
Simon Glass42d3b292014-06-11 23:29:43 -0600191#include <iotrace.h>
Tom Rini690d8a92016-03-15 13:20:23 -0400192#include <asm/types.h>
Simon Glass42d3b292014-06-11 23:29:43 -0600193
Simon Glassa733b062013-04-26 02:53:43 +0000194#endif