Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 744d985 | 2011-10-10 08:22:14 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 The Chromium OS Authors. |
Simon Glass | 744d985 | 2011-10-10 08:22:14 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 6 | #ifndef __SANDBOX_ASM_IO_H |
| 7 | #define __SANDBOX_ASM_IO_H |
| 8 | |
Paul Burton | f7ae1ca | 2017-09-14 15:05:13 -0700 | [diff] [blame] | 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 |
Simon Glass | 744d985 | 2011-10-10 08:22:14 +0000 | [diff] [blame] | 14 | |
| 15 | void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags); |
Paul Burton | f7ae1ca | 2017-09-14 15:05:13 -0700 | [diff] [blame] | 16 | #define map_physmem map_physmem |
Simon Glass | 744d985 | 2011-10-10 08:22:14 +0000 | [diff] [blame] | 17 | |
| 18 | /* |
| 19 | * Take down a mapping set up by map_physmem(). |
| 20 | */ |
Simon Glass | 9569c40 | 2015-03-05 12:25:26 -0700 | [diff] [blame] | 21 | void unmap_physmem(const void *vaddr, unsigned long flags); |
Paul Burton | f7ae1ca | 2017-09-14 15:05:13 -0700 | [diff] [blame] | 22 | #define unmap_physmem unmap_physmem |
| 23 | |
| 24 | #include <asm-generic/io.h> |
Simon Glass | 4213fc2 | 2013-02-24 17:33:14 +0000 | [diff] [blame] | 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 | |
Simon Glass | 9569c40 | 2015-03-05 12:25:26 -0700 | [diff] [blame] | 32 | /* Remove a previous mapping */ |
Simon Glass | 4213fc2 | 2013-02-24 17:33:14 +0000 | [diff] [blame] | 33 | static inline void unmap_sysmem(const void *vaddr) |
| 34 | { |
Simon Glass | 9569c40 | 2015-03-05 12:25:26 -0700 | [diff] [blame] | 35 | unmap_physmem(vaddr, MAP_WRBACK); |
Simon Glass | 4213fc2 | 2013-02-24 17:33:14 +0000 | [diff] [blame] | 36 | } |
Simon Glass | 781adb5 | 2013-04-20 08:42:37 +0000 | [diff] [blame] | 37 | |
| 38 | /* Map from a pointer to our RAM buffer */ |
Simon Glass | ed072b9 | 2013-11-07 09:31:58 -0700 | [diff] [blame] | 39 | phys_addr_t map_to_sysmem(const void *ptr); |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 40 | |
Simon Glass | 42d3b29 | 2014-06-11 23:29:43 -0600 | [diff] [blame] | 41 | /* Define nops for sandbox I/O access */ |
Simon Glass | 80793db | 2016-10-01 14:42:33 -0600 | [diff] [blame] | 42 | #define readb(addr) ((void)addr, 0) |
| 43 | #define readw(addr) ((void)addr, 0) |
| 44 | #define readl(addr) ((void)addr, 0) |
Mario Six | c6b89f3 | 2018-02-12 08:05:57 +0100 | [diff] [blame] | 45 | #ifdef CONFIG_SANDBOX64 |
| 46 | #define readq(addr) ((void)addr, 0) |
| 47 | #endif |
Simon Glass | 80793db | 2016-10-01 14:42:33 -0600 | [diff] [blame] | 48 | #define writeb(v, addr) ((void)addr) |
| 49 | #define writew(v, addr) ((void)addr) |
| 50 | #define writel(v, addr) ((void)addr) |
Mario Six | c6b89f3 | 2018-02-12 08:05:57 +0100 | [diff] [blame] | 51 | #ifdef CONFIG_SANDBOX64 |
| 52 | #define writeq(v, addr) ((void)addr) |
| 53 | #endif |
Simon Glass | 42d3b29 | 2014-06-11 23:29:43 -0600 | [diff] [blame] | 54 | |
Tom Rini | 35172cf | 2017-09-29 08:53:53 -0400 | [diff] [blame] | 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 | |
Simon Glass | 9569c40 | 2015-03-05 12:25:26 -0700 | [diff] [blame] | 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 | |
Maxime Ripard | a4dd872 | 2017-10-02 15:25:56 +0200 | [diff] [blame] | 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 | |
Simon Glass | e54094f | 2016-05-01 11:35:54 -0600 | [diff] [blame] | 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 | |
Simon Glass | 42d3b29 | 2014-06-11 23:29:43 -0600 | [diff] [blame] | 179 | #include <iotrace.h> |
Tom Rini | 690d8a9 | 2016-03-15 13:20:23 -0400 | [diff] [blame] | 180 | #include <asm/types.h> |
Simon Glass | 42d3b29 | 2014-06-11 23:29:43 -0600 | [diff] [blame] | 181 | |
Simon Glass | a733b06 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 182 | #endif |