18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci// Copyright (C) 2005-2017 Andes Technology Corporation
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#ifndef __ASM_NDS32_IO_H
58c2ecf20Sopenharmony_ci#define __ASM_NDS32_IO_H
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/types.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#define __raw_writeb __raw_writeb
108c2ecf20Sopenharmony_cistatic inline void __raw_writeb(u8 val, volatile void __iomem *addr)
118c2ecf20Sopenharmony_ci{
128c2ecf20Sopenharmony_ci	asm volatile("sbi %0, [%1]" : : "r" (val), "r" (addr));
138c2ecf20Sopenharmony_ci}
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#define __raw_writew __raw_writew
168c2ecf20Sopenharmony_cistatic inline void __raw_writew(u16 val, volatile void __iomem *addr)
178c2ecf20Sopenharmony_ci{
188c2ecf20Sopenharmony_ci	asm volatile("shi %0, [%1]" : : "r" (val), "r" (addr));
198c2ecf20Sopenharmony_ci}
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define __raw_writel __raw_writel
228c2ecf20Sopenharmony_cistatic inline void __raw_writel(u32 val, volatile void __iomem *addr)
238c2ecf20Sopenharmony_ci{
248c2ecf20Sopenharmony_ci	asm volatile("swi %0, [%1]" : : "r" (val), "r" (addr));
258c2ecf20Sopenharmony_ci}
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#define __raw_readb __raw_readb
288c2ecf20Sopenharmony_cistatic inline u8 __raw_readb(const volatile void __iomem *addr)
298c2ecf20Sopenharmony_ci{
308c2ecf20Sopenharmony_ci	u8 val;
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci	asm volatile("lbi %0, [%1]" : "=r" (val) : "r" (addr));
338c2ecf20Sopenharmony_ci	return val;
348c2ecf20Sopenharmony_ci}
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define __raw_readw __raw_readw
378c2ecf20Sopenharmony_cistatic inline u16 __raw_readw(const volatile void __iomem *addr)
388c2ecf20Sopenharmony_ci{
398c2ecf20Sopenharmony_ci	u16 val;
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	asm volatile("lhi %0, [%1]" : "=r" (val) : "r" (addr));
428c2ecf20Sopenharmony_ci	return val;
438c2ecf20Sopenharmony_ci}
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#define __raw_readl __raw_readl
468c2ecf20Sopenharmony_cistatic inline u32 __raw_readl(const volatile void __iomem *addr)
478c2ecf20Sopenharmony_ci{
488c2ecf20Sopenharmony_ci	u32 val;
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	asm volatile("lwi %0, [%1]" : "=r" (val) : "r" (addr));
518c2ecf20Sopenharmony_ci	return val;
528c2ecf20Sopenharmony_ci}
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define __iormb()               rmb()
558c2ecf20Sopenharmony_ci#define __iowmb()               wmb()
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/*
588c2ecf20Sopenharmony_ci * {read,write}{b,w,l,q}_relaxed() are like the regular version, but
598c2ecf20Sopenharmony_ci * are not guaranteed to provide ordering against spinlocks or memory
608c2ecf20Sopenharmony_ci * accesses.
618c2ecf20Sopenharmony_ci */
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#define readb_relaxed(c)	({ u8  __v = __raw_readb(c); __v; })
648c2ecf20Sopenharmony_ci#define readw_relaxed(c)	({ u16 __v = le16_to_cpu((__force __le16)__raw_readw(c)); __v; })
658c2ecf20Sopenharmony_ci#define readl_relaxed(c)	({ u32 __v = le32_to_cpu((__force __le32)__raw_readl(c)); __v; })
668c2ecf20Sopenharmony_ci#define writeb_relaxed(v,c)	((void)__raw_writeb((v),(c)))
678c2ecf20Sopenharmony_ci#define writew_relaxed(v,c)	((void)__raw_writew((__force u16)cpu_to_le16(v),(c)))
688c2ecf20Sopenharmony_ci#define writel_relaxed(v,c)	((void)__raw_writel((__force u32)cpu_to_le32(v),(c)))
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci/*
718c2ecf20Sopenharmony_ci * {read,write}{b,w,l,q}() access little endian memory and return result in
728c2ecf20Sopenharmony_ci * native endianness.
738c2ecf20Sopenharmony_ci */
748c2ecf20Sopenharmony_ci#define readb(c)	({ u8  __v = readb_relaxed(c); __iormb(); __v; })
758c2ecf20Sopenharmony_ci#define readw(c)	({ u16 __v = readw_relaxed(c); __iormb(); __v; })
768c2ecf20Sopenharmony_ci#define readl(c)	({ u32 __v = readl_relaxed(c); __iormb(); __v; })
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#define writeb(v,c)	({ __iowmb(); writeb_relaxed((v),(c)); })
798c2ecf20Sopenharmony_ci#define writew(v,c)	({ __iowmb(); writew_relaxed((v),(c)); })
808c2ecf20Sopenharmony_ci#define writel(v,c)	({ __iowmb(); writel_relaxed((v),(c)); })
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci#include <asm-generic/io.h>
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci#endif /* __ASM_NDS32_IO_H */
85