blob: 632bb236fbbe32182ea550d94c00d1e40b242f97 [file] [log] [blame]
Shreenidhi Shedi359125282018-07-15 02:34:35 +05301/* SPDX-License-Identifier: GPL-2.0+ */
wdenk507bbe32004-04-18 21:13:41 +00002/*
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 Simek53ea9812008-07-11 10:10:31 +020020#include <asm/types.h>
21
wdenk507bbe32004-04-18 21:13:41 +000022#define IO_SPACE_LIMIT 0xFFFFFFFF
23
24#define readb(addr) \
Shreenidhi Shedi359125282018-07-15 02:34:35 +053025 ({ unsigned char __v = (*(volatile unsigned char *)(addr)); __v; })
26
wdenk507bbe32004-04-18 21:13:41 +000027#define readw(addr) \
Shreenidhi Shedi359125282018-07-15 02:34:35 +053028 ({ unsigned short __v = (*(volatile unsigned short *)(addr)); __v; })
29
wdenk507bbe32004-04-18 21:13:41 +000030#define readl(addr) \
Shreenidhi Shedi359125282018-07-15 02:34:35 +053031 ({ unsigned int __v = (*(volatile unsigned int *)(addr)); __v; })
wdenk507bbe32004-04-18 21:13:41 +000032
33#define writeb(b, addr) \
Shreenidhi Shedi359125282018-07-15 02:34:35 +053034 (void)((*(volatile unsigned char *)(addr)) = (b))
35
wdenk507bbe32004-04-18 21:13:41 +000036#define writew(b, addr) \
Shreenidhi Shedi359125282018-07-15 02:34:35 +053037 (void)((*(volatile unsigned short *)(addr)) = (b))
38
wdenk507bbe32004-04-18 21:13:41 +000039#define writel(b, addr) \
Shreenidhi Shedi359125282018-07-15 02:34:35 +053040 (void)((*(volatile unsigned int *)(addr)) = (b))
wdenk507bbe32004-04-18 21:13:41 +000041
Shreenidhi Shedi359125282018-07-15 02:34:35 +053042#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))
wdenk507bbe32004-04-18 21:13:41 +000045
Shreenidhi Shedi359125282018-07-15 02:34:35 +053046#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))
wdenk507bbe32004-04-18 21:13:41 +000052
T Karthik Reddy78d844c2020-08-20 22:35:33 -060053#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)
wdenk507bbe32004-04-18 21:13:41 +000067
Shreenidhi Shedi359125282018-07-15 02:34:35 +053068#define out_8(addr, x) outb(x, addr)
T Karthik Reddy78d844c2020-08-20 22:35:33 -060069#define out_be16(addr, x) out_arch(w, be16, addr, x)
70#define out_be32(addr, x) out_arch(l, be32, addr, x)
wdenk507bbe32004-04-18 21:13:41 +000071
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 Shedi359125282018-07-15 02:34:35 +053088static inline void io_insb(unsigned long port, void *dst, unsigned long count)
wdenk507bbe32004-04-18 21:13:41 +000089{
90 unsigned char *p = dst;
Shreenidhi Shedi359125282018-07-15 02:34:35 +053091
wdenk507bbe32004-04-18 21:13:41 +000092 while (count--)
Shreenidhi Shedi359125282018-07-15 02:34:35 +053093 *p++ = inb(port);
wdenk507bbe32004-04-18 21:13:41 +000094}
Shreenidhi Shedi359125282018-07-15 02:34:35 +053095
96static inline void io_insw(unsigned long port, void *dst, unsigned long count)
wdenk507bbe32004-04-18 21:13:41 +000097{
98 unsigned short *p = dst;
Shreenidhi Shedi359125282018-07-15 02:34:35 +053099
wdenk507bbe32004-04-18 21:13:41 +0000100 while (count--)
Shreenidhi Shedi359125282018-07-15 02:34:35 +0530101 *p++ = inw(port);
wdenk507bbe32004-04-18 21:13:41 +0000102}
Shreenidhi Shedi359125282018-07-15 02:34:35 +0530103
104static inline void io_insl(unsigned long port, void *dst, unsigned long count)
wdenk507bbe32004-04-18 21:13:41 +0000105{
106 unsigned long *p = dst;
Shreenidhi Shedi359125282018-07-15 02:34:35 +0530107
wdenk507bbe32004-04-18 21:13:41 +0000108 while (count--)
Shreenidhi Shedi359125282018-07-15 02:34:35 +0530109 *p++ = inl(port);
wdenk507bbe32004-04-18 21:13:41 +0000110}
111
112static inline void
Shreenidhi Shedi359125282018-07-15 02:34:35 +0530113io_outsb(unsigned long port, const void *src, unsigned long count)
wdenk507bbe32004-04-18 21:13:41 +0000114{
115 const unsigned char *p = src;
Shreenidhi Shedi359125282018-07-15 02:34:35 +0530116
wdenk507bbe32004-04-18 21:13:41 +0000117 while (count--)
Shreenidhi Shedi359125282018-07-15 02:34:35 +0530118 outb(*p++, port);
wdenk507bbe32004-04-18 21:13:41 +0000119}
Shreenidhi Shedi359125282018-07-15 02:34:35 +0530120
wdenk507bbe32004-04-18 21:13:41 +0000121static inline void
Shreenidhi Shedi359125282018-07-15 02:34:35 +0530122io_outsw(unsigned long port, const void *src, unsigned long count)
wdenk507bbe32004-04-18 21:13:41 +0000123{
124 const unsigned short *p = src;
Shreenidhi Shedi359125282018-07-15 02:34:35 +0530125
wdenk507bbe32004-04-18 21:13:41 +0000126 while (count--)
Shreenidhi Shedi359125282018-07-15 02:34:35 +0530127 outw(*p++, port);
wdenk507bbe32004-04-18 21:13:41 +0000128}
Shreenidhi Shedi359125282018-07-15 02:34:35 +0530129
wdenk507bbe32004-04-18 21:13:41 +0000130static inline void
Shreenidhi Shedi359125282018-07-15 02:34:35 +0530131io_outsl(unsigned long port, const void *src, unsigned long count)
wdenk507bbe32004-04-18 21:13:41 +0000132{
133 const unsigned long *p = src;
Shreenidhi Shedi359125282018-07-15 02:34:35 +0530134
wdenk507bbe32004-04-18 21:13:41 +0000135 while (count--)
Shreenidhi Shedi359125282018-07-15 02:34:35 +0530136 outl(*p++, port);
wdenk507bbe32004-04-18 21:13:41 +0000137}
138
Shreenidhi Shedi359125282018-07-15 02:34:35 +0530139#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)
wdenk507bbe32004-04-18 21:13:41 +0000142
Shreenidhi Shedi359125282018-07-15 02:34:35 +0530143#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)
wdenk507bbe32004-04-18 21:13:41 +0000146
wdenk507bbe32004-04-18 21:13:41 +0000147#define ioremap_nocache(physaddr, size) (physaddr)
148#define ioremap_writethrough(physaddr, size) (physaddr)
149#define ioremap_fullcache(physaddr, size) (physaddr)
150
Haiying Wang3a197b22007-02-21 16:52:31 +0100151static inline void sync(void)
152{
153}
154
Paul Burtondbee7152017-09-14 15:05:05 -0700155#include <asm-generic/io.h>
Kumar Gala65e43a12008-12-13 17:20:27 -0600156
wdenk507bbe32004-04-18 21:13:41 +0000157#endif /* __MICROBLAZE_IO_H__ */