Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 2 | /* |
| 3 | * include/asm-microblaze/io.h -- Misc I/O operations |
| 4 | * |
| 5 | * Copyright (C) 2003 John Williams <jwilliams@itee.uq.edu.au> |
| 6 | * Copyright (C) 2001,02 NEC Corporation |
| 7 | * Copyright (C) 2001,02 Miles Bader <miles@gnu.org> |
| 8 | * |
| 9 | * This file is subject to the terms and conditions of the GNU General |
| 10 | * Public License. See the file COPYING in the main directory of this |
| 11 | * archive for more details. |
| 12 | * |
| 13 | * Written by Miles Bader <miles@gnu.org> |
| 14 | * Microblaze port by John Williams |
| 15 | */ |
| 16 | |
| 17 | #ifndef __MICROBLAZE_IO_H__ |
| 18 | #define __MICROBLAZE_IO_H__ |
| 19 | |
Michal Simek | 403d619 | 2008-07-11 10:10:31 +0200 | [diff] [blame] | 20 | #include <asm/types.h> |
| 21 | |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 22 | #define IO_SPACE_LIMIT 0xFFFFFFFF |
| 23 | |
| 24 | #define readb(addr) \ |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 25 | ({ unsigned char __v = (*(volatile unsigned char *)(addr)); __v; }) |
| 26 | |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 27 | #define readw(addr) \ |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 28 | ({ unsigned short __v = (*(volatile unsigned short *)(addr)); __v; }) |
| 29 | |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 30 | #define readl(addr) \ |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 31 | ({ unsigned int __v = (*(volatile unsigned int *)(addr)); __v; }) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 32 | |
| 33 | #define writeb(b, addr) \ |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 34 | (void)((*(volatile unsigned char *)(addr)) = (b)) |
| 35 | |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 36 | #define writew(b, addr) \ |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 37 | (void)((*(volatile unsigned short *)(addr)) = (b)) |
| 38 | |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 39 | #define writel(b, addr) \ |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 40 | (void)((*(volatile unsigned int *)(addr)) = (b)) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 41 | |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 42 | #define memset_io(a, b, c) memset((void *)(a), (b), (c)) |
| 43 | #define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c)) |
| 44 | #define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c)) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 45 | |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 46 | #define inb(addr) readb(addr) |
| 47 | #define inw(addr) readw(addr) |
| 48 | #define inl(addr) readl(addr) |
| 49 | #define outb(x, addr) ((void)writeb(x, addr)) |
| 50 | #define outw(x, addr) ((void)writew(x, addr)) |
| 51 | #define outl(x, addr) ((void)writel(x, addr)) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 52 | |
T Karthik Reddy | 04680aa | 2020-08-20 22:35:33 -0600 | [diff] [blame^] | 53 | #define out_arch(type, endian, addr, x) \ |
| 54 | __raw_write##type(cpu_to_##endian(x), addr) |
| 55 | #define in_arch(type, endian, addr) \ |
| 56 | endian##_to_cpu(__raw_read##type(addr)) |
| 57 | |
| 58 | #define out_le16(addr, x) out_arch(w, le16, addr, x) |
| 59 | #define out_le32(addr, x) out_arch(l, le32, addr, x) |
| 60 | |
| 61 | #define in_le16(addr) in_arch(w, le16, addr) |
| 62 | #define in_le32(addr) in_arch(l, le32, addr) |
| 63 | |
| 64 | #define in_8(addr) readb(addr) |
| 65 | #define in_be16(addr) in_arch(w, be16, addr) |
| 66 | #define in_be32(addr) in_arch(l, be32, addr) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 67 | |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 68 | #define out_8(addr, x) outb(x, addr) |
T Karthik Reddy | 04680aa | 2020-08-20 22:35:33 -0600 | [diff] [blame^] | 69 | #define out_be16(addr, x) out_arch(w, be16, addr, x) |
| 70 | #define out_be32(addr, x) out_arch(l, be32, addr, x) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 71 | |
| 72 | #define inb_p(port) inb((port)) |
| 73 | #define outb_p(val, port) outb((val), (port)) |
| 74 | #define inw_p(port) inw((port)) |
| 75 | #define outw_p(val, port) outw((val), (port)) |
| 76 | #define inl_p(port) inl((port)) |
| 77 | #define outl_p(val, port) outl((val), (port)) |
| 78 | |
| 79 | /* Some defines to keep the MTD flash drivers happy */ |
| 80 | |
| 81 | #define __raw_readb readb |
| 82 | #define __raw_readw readw |
| 83 | #define __raw_readl readl |
| 84 | #define __raw_writeb writeb |
| 85 | #define __raw_writew writew |
| 86 | #define __raw_writel writel |
| 87 | |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 88 | static inline void io_insb(unsigned long port, void *dst, unsigned long count) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 89 | { |
| 90 | unsigned char *p = dst; |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 91 | |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 92 | while (count--) |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 93 | *p++ = inb(port); |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 94 | } |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 95 | |
| 96 | static inline void io_insw(unsigned long port, void *dst, unsigned long count) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 97 | { |
| 98 | unsigned short *p = dst; |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 99 | |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 100 | while (count--) |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 101 | *p++ = inw(port); |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 102 | } |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 103 | |
| 104 | static inline void io_insl(unsigned long port, void *dst, unsigned long count) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 105 | { |
| 106 | unsigned long *p = dst; |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 107 | |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 108 | while (count--) |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 109 | *p++ = inl(port); |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static inline void |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 113 | io_outsb(unsigned long port, const void *src, unsigned long count) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 114 | { |
| 115 | const unsigned char *p = src; |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 116 | |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 117 | while (count--) |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 118 | outb(*p++, port); |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 119 | } |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 120 | |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 121 | static inline void |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 122 | io_outsw(unsigned long port, const void *src, unsigned long count) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 123 | { |
| 124 | const unsigned short *p = src; |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 125 | |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 126 | while (count--) |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 127 | outw(*p++, port); |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 128 | } |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 129 | |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 130 | static inline void |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 131 | io_outsl(unsigned long port, const void *src, unsigned long count) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 132 | { |
| 133 | const unsigned long *p = src; |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 134 | |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 135 | while (count--) |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 136 | outl(*p++, port); |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 137 | } |
| 138 | |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 139 | #define outsb(a, b, l) io_outsb(a, b, l) |
| 140 | #define outsw(a, b, l) io_outsw(a, b, l) |
| 141 | #define outsl(a, b, l) io_outsl(a, b, l) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 142 | |
Shreenidhi Shedi | ffced40 | 2018-07-15 02:34:35 +0530 | [diff] [blame] | 143 | #define insb(a, b, l) io_insb(a, b, l) |
| 144 | #define insw(a, b, l) io_insw(a, b, l) |
| 145 | #define insl(a, b, l) io_insl(a, b, l) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 146 | |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 147 | #define ioremap_nocache(physaddr, size) (physaddr) |
| 148 | #define ioremap_writethrough(physaddr, size) (physaddr) |
| 149 | #define ioremap_fullcache(physaddr, size) (physaddr) |
| 150 | |
Haiying Wang | c123a38 | 2007-02-21 16:52:31 +0100 | [diff] [blame] | 151 | static inline void sync(void) |
| 152 | { |
| 153 | } |
| 154 | |
Paul Burton | a974ec6 | 2017-09-14 15:05:05 -0700 | [diff] [blame] | 155 | #include <asm-generic/io.h> |
Kumar Gala | 9364a67 | 2008-12-13 17:20:27 -0600 | [diff] [blame] | 156 | |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 157 | #endif /* __MICROBLAZE_IO_H__ */ |