18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/* Trivial implementations of basic i/o routines.  Assumes that all
38c2ecf20Sopenharmony_ci   of the hard work has been done by ioremap and ioportmap, and that
48c2ecf20Sopenharmony_ci   access to i/o space is linear.  */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci/* This file may be included multiple times.  */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#if IO_CONCAT(__IO_PREFIX,trivial_io_bw)
98c2ecf20Sopenharmony_ci__EXTERN_INLINE unsigned int
108c2ecf20Sopenharmony_ciIO_CONCAT(__IO_PREFIX,ioread8)(const void __iomem *a)
118c2ecf20Sopenharmony_ci{
128c2ecf20Sopenharmony_ci	return __kernel_ldbu(*(const volatile u8 __force *)a);
138c2ecf20Sopenharmony_ci}
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci__EXTERN_INLINE unsigned int
168c2ecf20Sopenharmony_ciIO_CONCAT(__IO_PREFIX,ioread16)(const void __iomem *a)
178c2ecf20Sopenharmony_ci{
188c2ecf20Sopenharmony_ci	return __kernel_ldwu(*(const volatile u16 __force *)a);
198c2ecf20Sopenharmony_ci}
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci__EXTERN_INLINE void
228c2ecf20Sopenharmony_ciIO_CONCAT(__IO_PREFIX,iowrite8)(u8 b, void __iomem *a)
238c2ecf20Sopenharmony_ci{
248c2ecf20Sopenharmony_ci	__kernel_stb(b, *(volatile u8 __force *)a);
258c2ecf20Sopenharmony_ci}
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci__EXTERN_INLINE void
288c2ecf20Sopenharmony_ciIO_CONCAT(__IO_PREFIX,iowrite16)(u16 b, void __iomem *a)
298c2ecf20Sopenharmony_ci{
308c2ecf20Sopenharmony_ci	__kernel_stw(b, *(volatile u16 __force *)a);
318c2ecf20Sopenharmony_ci}
328c2ecf20Sopenharmony_ci#endif
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#if IO_CONCAT(__IO_PREFIX,trivial_io_lq)
358c2ecf20Sopenharmony_ci__EXTERN_INLINE unsigned int
368c2ecf20Sopenharmony_ciIO_CONCAT(__IO_PREFIX,ioread32)(const void __iomem *a)
378c2ecf20Sopenharmony_ci{
388c2ecf20Sopenharmony_ci	return *(const volatile u32 __force *)a;
398c2ecf20Sopenharmony_ci}
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci__EXTERN_INLINE void
428c2ecf20Sopenharmony_ciIO_CONCAT(__IO_PREFIX,iowrite32)(u32 b, void __iomem *a)
438c2ecf20Sopenharmony_ci{
448c2ecf20Sopenharmony_ci	*(volatile u32 __force *)a = b;
458c2ecf20Sopenharmony_ci}
468c2ecf20Sopenharmony_ci#endif
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#if IO_CONCAT(__IO_PREFIX,trivial_rw_bw) == 1
498c2ecf20Sopenharmony_ci__EXTERN_INLINE u8
508c2ecf20Sopenharmony_ciIO_CONCAT(__IO_PREFIX,readb)(const volatile void __iomem *a)
518c2ecf20Sopenharmony_ci{
528c2ecf20Sopenharmony_ci	return __kernel_ldbu(*(const volatile u8 __force *)a);
538c2ecf20Sopenharmony_ci}
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci__EXTERN_INLINE u16
568c2ecf20Sopenharmony_ciIO_CONCAT(__IO_PREFIX,readw)(const volatile void __iomem *a)
578c2ecf20Sopenharmony_ci{
588c2ecf20Sopenharmony_ci	return __kernel_ldwu(*(const volatile u16 __force *)a);
598c2ecf20Sopenharmony_ci}
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci__EXTERN_INLINE void
628c2ecf20Sopenharmony_ciIO_CONCAT(__IO_PREFIX,writeb)(u8 b, volatile void __iomem *a)
638c2ecf20Sopenharmony_ci{
648c2ecf20Sopenharmony_ci	__kernel_stb(b, *(volatile u8 __force *)a);
658c2ecf20Sopenharmony_ci}
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci__EXTERN_INLINE void
688c2ecf20Sopenharmony_ciIO_CONCAT(__IO_PREFIX,writew)(u16 b, volatile void __iomem *a)
698c2ecf20Sopenharmony_ci{
708c2ecf20Sopenharmony_ci	__kernel_stw(b, *(volatile u16 __force *)a);
718c2ecf20Sopenharmony_ci}
728c2ecf20Sopenharmony_ci#elif IO_CONCAT(__IO_PREFIX,trivial_rw_bw) == 2
738c2ecf20Sopenharmony_ci__EXTERN_INLINE u8
748c2ecf20Sopenharmony_ciIO_CONCAT(__IO_PREFIX,readb)(const volatile void __iomem *a)
758c2ecf20Sopenharmony_ci{
768c2ecf20Sopenharmony_ci	const void __iomem *addr = (const void __iomem *)a;
778c2ecf20Sopenharmony_ci	return IO_CONCAT(__IO_PREFIX,ioread8)(addr);
788c2ecf20Sopenharmony_ci}
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci__EXTERN_INLINE u16
818c2ecf20Sopenharmony_ciIO_CONCAT(__IO_PREFIX,readw)(const volatile void __iomem *a)
828c2ecf20Sopenharmony_ci{
838c2ecf20Sopenharmony_ci	const void __iomem *addr = (const void __iomem *)a;
848c2ecf20Sopenharmony_ci	return IO_CONCAT(__IO_PREFIX,ioread16)(addr);
858c2ecf20Sopenharmony_ci}
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci__EXTERN_INLINE void
888c2ecf20Sopenharmony_ciIO_CONCAT(__IO_PREFIX,writeb)(u8 b, volatile void __iomem *a)
898c2ecf20Sopenharmony_ci{
908c2ecf20Sopenharmony_ci	void __iomem *addr = (void __iomem *)a;
918c2ecf20Sopenharmony_ci	IO_CONCAT(__IO_PREFIX,iowrite8)(b, addr);
928c2ecf20Sopenharmony_ci}
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci__EXTERN_INLINE void
958c2ecf20Sopenharmony_ciIO_CONCAT(__IO_PREFIX,writew)(u16 b, volatile void __iomem *a)
968c2ecf20Sopenharmony_ci{
978c2ecf20Sopenharmony_ci	void __iomem *addr = (void __iomem *)a;
988c2ecf20Sopenharmony_ci	IO_CONCAT(__IO_PREFIX,iowrite16)(b, addr);
998c2ecf20Sopenharmony_ci}
1008c2ecf20Sopenharmony_ci#endif
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci#if IO_CONCAT(__IO_PREFIX,trivial_rw_lq) == 1
1038c2ecf20Sopenharmony_ci__EXTERN_INLINE u32
1048c2ecf20Sopenharmony_ciIO_CONCAT(__IO_PREFIX,readl)(const volatile void __iomem *a)
1058c2ecf20Sopenharmony_ci{
1068c2ecf20Sopenharmony_ci	return *(const volatile u32 __force *)a;
1078c2ecf20Sopenharmony_ci}
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci__EXTERN_INLINE u64
1108c2ecf20Sopenharmony_ciIO_CONCAT(__IO_PREFIX,readq)(const volatile void __iomem *a)
1118c2ecf20Sopenharmony_ci{
1128c2ecf20Sopenharmony_ci	return *(const volatile u64 __force *)a;
1138c2ecf20Sopenharmony_ci}
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci__EXTERN_INLINE void
1168c2ecf20Sopenharmony_ciIO_CONCAT(__IO_PREFIX,writel)(u32 b, volatile void __iomem *a)
1178c2ecf20Sopenharmony_ci{
1188c2ecf20Sopenharmony_ci	*(volatile u32 __force *)a = b;
1198c2ecf20Sopenharmony_ci}
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci__EXTERN_INLINE void
1228c2ecf20Sopenharmony_ciIO_CONCAT(__IO_PREFIX,writeq)(u64 b, volatile void __iomem *a)
1238c2ecf20Sopenharmony_ci{
1248c2ecf20Sopenharmony_ci	*(volatile u64 __force *)a = b;
1258c2ecf20Sopenharmony_ci}
1268c2ecf20Sopenharmony_ci#endif
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#if IO_CONCAT(__IO_PREFIX,trivial_iounmap)
1298c2ecf20Sopenharmony_ci__EXTERN_INLINE void IO_CONCAT(__IO_PREFIX,iounmap)(volatile void __iomem *a)
1308c2ecf20Sopenharmony_ci{
1318c2ecf20Sopenharmony_ci}
1328c2ecf20Sopenharmony_ci#endif
133