xref: /openbmc/linux/arch/csky/include/asm/io.h (revision a44e4f3a)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3 
4 #ifndef __ASM_CSKY_IO_H
5 #define __ASM_CSKY_IO_H
6 
7 #include <asm/pgtable.h>
8 #include <linux/types.h>
9 #include <linux/version.h>
10 
11 /*
12  * I/O memory access primitives. Reads are ordered relative to any
13  * following Normal memory access. Writes are ordered relative to any prior
14  * Normal memory access.
15  *
16  * For CACHEV1 (807, 810), store instruction could fast retire, so we need
17  * another mb() to prevent st fast retire.
18  *
19  * For CACHEV2 (860), store instruction with PAGE_ATTR_NO_BUFFERABLE won't
20  * fast retire.
21  */
22 #define readb(c)		({ u8  __v = readb_relaxed(c); rmb(); __v; })
23 #define readw(c)		({ u16 __v = readw_relaxed(c); rmb(); __v; })
24 #define readl(c)		({ u32 __v = readl_relaxed(c); rmb(); __v; })
25 
26 #ifdef CONFIG_CPU_HAS_CACHEV2
27 #define writeb(v,c)		({ wmb(); writeb_relaxed((v),(c)); })
28 #define writew(v,c)		({ wmb(); writew_relaxed((v),(c)); })
29 #define writel(v,c)		({ wmb(); writel_relaxed((v),(c)); })
30 #else
31 #define writeb(v,c)		({ wmb(); writeb_relaxed((v),(c)); mb(); })
32 #define writew(v,c)		({ wmb(); writew_relaxed((v),(c)); mb(); })
33 #define writel(v,c)		({ wmb(); writel_relaxed((v),(c)); mb(); })
34 #endif
35 
36 /*
37  * I/O memory mapping functions.
38  */
39 extern void __iomem *ioremap_cache(phys_addr_t addr, size_t size);
40 extern void __iomem *__ioremap(phys_addr_t addr, size_t size, pgprot_t prot);
41 extern void iounmap(void *addr);
42 
43 #define ioremap(addr, size)		__ioremap((addr), (size), pgprot_noncached(PAGE_KERNEL))
44 #define ioremap_wc(addr, size)		__ioremap((addr), (size), pgprot_writecombine(PAGE_KERNEL))
45 #define ioremap_nocache(addr, size)	ioremap((addr), (size))
46 #define ioremap_cache			ioremap_cache
47 
48 #include <asm-generic/io.h>
49 
50 #endif /* __ASM_CSKY_IO_H */
51