Simon Glass | b4a905e | 2011-10-10 08:22:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The Chromium OS Authors. |
| 3 | * |
Wolfgang Denk | bd8ec7e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | b4a905e | 2011-10-10 08:22:14 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Simon Glass | 62cf912 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 7 | #ifndef __SANDBOX_ASM_IO_H |
| 8 | #define __SANDBOX_ASM_IO_H |
| 9 | |
Paul Burton | 5136925 | 2017-09-14 15:05:13 -0700 | [diff] [blame] | 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 |
Simon Glass | b4a905e | 2011-10-10 08:22:14 +0000 | [diff] [blame] | 15 | |
| 16 | void *map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags); |
Paul Burton | 5136925 | 2017-09-14 15:05:13 -0700 | [diff] [blame] | 17 | #define map_physmem map_physmem |
Simon Glass | b4a905e | 2011-10-10 08:22:14 +0000 | [diff] [blame] | 18 | |
| 19 | /* |
| 20 | * Take down a mapping set up by map_physmem(). |
| 21 | */ |
Simon Glass | 70778bc | 2015-03-05 12:25:26 -0700 | [diff] [blame] | 22 | void unmap_physmem(const void *vaddr, unsigned long flags); |
Paul Burton | 5136925 | 2017-09-14 15:05:13 -0700 | [diff] [blame] | 23 | #define unmap_physmem unmap_physmem |
| 24 | |
| 25 | #include <asm-generic/io.h> |
Simon Glass | 17dabf0 | 2013-02-24 17:33:14 +0000 | [diff] [blame] | 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 | |
Simon Glass | 70778bc | 2015-03-05 12:25:26 -0700 | [diff] [blame] | 33 | /* Remove a previous mapping */ |
Simon Glass | 17dabf0 | 2013-02-24 17:33:14 +0000 | [diff] [blame] | 34 | static inline void unmap_sysmem(const void *vaddr) |
| 35 | { |
Simon Glass | 70778bc | 2015-03-05 12:25:26 -0700 | [diff] [blame] | 36 | unmap_physmem(vaddr, MAP_WRBACK); |
Simon Glass | 17dabf0 | 2013-02-24 17:33:14 +0000 | [diff] [blame] | 37 | } |
Simon Glass | e23d293 | 2013-04-20 08:42:37 +0000 | [diff] [blame] | 38 | |
| 39 | /* Map from a pointer to our RAM buffer */ |
Simon Glass | 656bfc4 | 2013-11-07 09:31:58 -0700 | [diff] [blame] | 40 | phys_addr_t map_to_sysmem(const void *ptr); |
Simon Glass | 62cf912 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 41 | |
Simon Glass | 125a27b | 2014-06-11 23:29:43 -0600 | [diff] [blame] | 42 | /* Define nops for sandbox I/O access */ |
Simon Glass | 652acc7 | 2016-10-01 14:42:33 -0600 | [diff] [blame] | 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) |
Simon Glass | 125a27b | 2014-06-11 23:29:43 -0600 | [diff] [blame] | 49 | |
Simon Glass | 70778bc | 2015-03-05 12:25:26 -0700 | [diff] [blame] | 50 | /* I/O access functions */ |
| 51 | int inl(unsigned int addr); |
| 52 | int inw(unsigned int addr); |
| 53 | int inb(unsigned int addr); |
| 54 | |
| 55 | void outl(unsigned int value, unsigned int addr); |
| 56 | void outw(unsigned int value, unsigned int addr); |
| 57 | void outb(unsigned int value, unsigned int addr); |
| 58 | |
Maxime Ripard | f768aa8 | 2017-10-02 15:25:56 +0200 | [diff] [blame] | 59 | #define out_arch(type,endian,a,v) write##type(cpu_to_##endian(v),a) |
| 60 | #define in_arch(type,endian,a) endian##_to_cpu(read##type(a)) |
| 61 | |
| 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_le32(a) in_arch(l,le32,a) |
| 66 | #define in_le16(a) in_arch(w,le16,a) |
| 67 | |
| 68 | #define out_be32(a,v) out_arch(l,be32,a,v) |
| 69 | #define out_be16(a,v) out_arch(w,be16,a,v) |
| 70 | |
| 71 | #define in_be32(a) in_arch(l,be32,a) |
| 72 | #define in_be16(a) in_arch(w,be16,a) |
| 73 | |
| 74 | #define out_8(a,v) writeb(v,a) |
| 75 | #define in_8(a) readb(a) |
| 76 | |
| 77 | #define clrbits(type, addr, clear) \ |
| 78 | out_##type((addr), in_##type(addr) & ~(clear)) |
| 79 | |
| 80 | #define setbits(type, addr, set) \ |
| 81 | out_##type((addr), in_##type(addr) | (set)) |
| 82 | |
| 83 | #define clrsetbits(type, addr, clear, set) \ |
| 84 | out_##type((addr), (in_##type(addr) & ~(clear)) | (set)) |
| 85 | |
| 86 | #define clrbits_be32(addr, clear) clrbits(be32, addr, clear) |
| 87 | #define setbits_be32(addr, set) setbits(be32, addr, set) |
| 88 | #define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set) |
| 89 | |
| 90 | #define clrbits_le32(addr, clear) clrbits(le32, addr, clear) |
| 91 | #define setbits_le32(addr, set) setbits(le32, addr, set) |
| 92 | #define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set) |
| 93 | |
| 94 | #define clrbits_be16(addr, clear) clrbits(be16, addr, clear) |
| 95 | #define setbits_be16(addr, set) setbits(be16, addr, set) |
| 96 | #define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set) |
| 97 | |
| 98 | #define clrbits_le16(addr, clear) clrbits(le16, addr, clear) |
| 99 | #define setbits_le16(addr, set) setbits(le16, addr, set) |
| 100 | #define clrsetbits_le16(addr, clear, set) clrsetbits(le16, addr, clear, set) |
| 101 | |
| 102 | #define clrbits_8(addr, clear) clrbits(8, addr, clear) |
| 103 | #define setbits_8(addr, set) setbits(8, addr, set) |
| 104 | #define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set) |
| 105 | |
Simon Glass | 8d5e245 | 2016-05-01 11:35:54 -0600 | [diff] [blame] | 106 | static inline void _insw(volatile u16 *port, void *buf, int ns) |
| 107 | { |
| 108 | } |
| 109 | |
| 110 | static inline void _outsw(volatile u16 *port, const void *buf, int ns) |
| 111 | { |
| 112 | } |
| 113 | |
| 114 | #define insw(port, buf, ns) _insw((u16 *)port, buf, ns) |
| 115 | #define outsw(port, buf, ns) _outsw((u16 *)port, buf, ns) |
| 116 | |
| 117 | /* For systemace.c */ |
| 118 | #define out16(addr, val) |
| 119 | #define in16(addr) 0 |
| 120 | |
Simon Glass | 125a27b | 2014-06-11 23:29:43 -0600 | [diff] [blame] | 121 | #include <iotrace.h> |
Tom Rini | 22e4268 | 2016-03-15 13:20:23 -0400 | [diff] [blame] | 122 | #include <asm/types.h> |
Simon Glass | 125a27b | 2014-06-11 23:29:43 -0600 | [diff] [blame] | 123 | |
Simon Glass | 62cf912 | 2013-04-26 02:53:43 +0000 | [diff] [blame] | 124 | #endif |