18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _IO_H
38c2ecf20Sopenharmony_ci#define _IO_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include "types.h"
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci/*
88c2ecf20Sopenharmony_ci * Low-level I/O routines.
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * Copied from <file:arch/powerpc/include/asm/io.h> (which has no copyright)
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_cistatic inline int in_8(const volatile unsigned char *addr)
138c2ecf20Sopenharmony_ci{
148c2ecf20Sopenharmony_ci	int ret;
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci	__asm__ __volatile__("lbz%U1%X1 %0,%1; twi 0,%0,0; isync"
178c2ecf20Sopenharmony_ci			     : "=r" (ret) : "m" (*addr));
188c2ecf20Sopenharmony_ci	return ret;
198c2ecf20Sopenharmony_ci}
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistatic inline void out_8(volatile unsigned char *addr, int val)
228c2ecf20Sopenharmony_ci{
238c2ecf20Sopenharmony_ci	__asm__ __volatile__("stb%U0%X0 %1,%0; sync"
248c2ecf20Sopenharmony_ci			     : "=m" (*addr) : "r" (val));
258c2ecf20Sopenharmony_ci}
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistatic inline unsigned in_le16(const volatile u16 *addr)
288c2ecf20Sopenharmony_ci{
298c2ecf20Sopenharmony_ci	unsigned ret;
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci	__asm__ __volatile__("lhbrx %0,0,%1; twi 0,%0,0; isync"
328c2ecf20Sopenharmony_ci			     : "=r" (ret) : "r" (addr), "m" (*addr));
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	return ret;
358c2ecf20Sopenharmony_ci}
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistatic inline unsigned in_be16(const volatile u16 *addr)
388c2ecf20Sopenharmony_ci{
398c2ecf20Sopenharmony_ci	unsigned ret;
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	__asm__ __volatile__("lhz%U1%X1 %0,%1; twi 0,%0,0; isync"
428c2ecf20Sopenharmony_ci			     : "=r" (ret) : "m" (*addr));
438c2ecf20Sopenharmony_ci	return ret;
448c2ecf20Sopenharmony_ci}
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistatic inline void out_le16(volatile u16 *addr, int val)
478c2ecf20Sopenharmony_ci{
488c2ecf20Sopenharmony_ci	__asm__ __volatile__("sthbrx %1,0,%2; sync" : "=m" (*addr)
498c2ecf20Sopenharmony_ci			     : "r" (val), "r" (addr));
508c2ecf20Sopenharmony_ci}
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cistatic inline void out_be16(volatile u16 *addr, int val)
538c2ecf20Sopenharmony_ci{
548c2ecf20Sopenharmony_ci	__asm__ __volatile__("sth%U0%X0 %1,%0; sync"
558c2ecf20Sopenharmony_ci			     : "=m" (*addr) : "r" (val));
568c2ecf20Sopenharmony_ci}
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistatic inline unsigned in_le32(const volatile unsigned *addr)
598c2ecf20Sopenharmony_ci{
608c2ecf20Sopenharmony_ci	unsigned ret;
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	__asm__ __volatile__("lwbrx %0,0,%1; twi 0,%0,0; isync"
638c2ecf20Sopenharmony_ci			     : "=r" (ret) : "r" (addr), "m" (*addr));
648c2ecf20Sopenharmony_ci	return ret;
658c2ecf20Sopenharmony_ci}
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cistatic inline unsigned in_be32(const volatile unsigned *addr)
688c2ecf20Sopenharmony_ci{
698c2ecf20Sopenharmony_ci	unsigned ret;
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	__asm__ __volatile__("lwz%U1%X1 %0,%1; twi 0,%0,0; isync"
728c2ecf20Sopenharmony_ci			     : "=r" (ret) : "m" (*addr));
738c2ecf20Sopenharmony_ci	return ret;
748c2ecf20Sopenharmony_ci}
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistatic inline void out_le32(volatile unsigned *addr, int val)
778c2ecf20Sopenharmony_ci{
788c2ecf20Sopenharmony_ci	__asm__ __volatile__("stwbrx %1,0,%2; sync" : "=m" (*addr)
798c2ecf20Sopenharmony_ci			     : "r" (val), "r" (addr));
808c2ecf20Sopenharmony_ci}
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_cistatic inline void out_be32(volatile unsigned *addr, int val)
838c2ecf20Sopenharmony_ci{
848c2ecf20Sopenharmony_ci	__asm__ __volatile__("stw%U0%X0 %1,%0; sync"
858c2ecf20Sopenharmony_ci			     : "=m" (*addr) : "r" (val));
868c2ecf20Sopenharmony_ci}
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_cistatic inline void sync(void)
898c2ecf20Sopenharmony_ci{
908c2ecf20Sopenharmony_ci	asm volatile("sync" : : : "memory");
918c2ecf20Sopenharmony_ci}
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cistatic inline void eieio(void)
948c2ecf20Sopenharmony_ci{
958c2ecf20Sopenharmony_ci	asm volatile("eieio" : : : "memory");
968c2ecf20Sopenharmony_ci}
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_cistatic inline void barrier(void)
998c2ecf20Sopenharmony_ci{
1008c2ecf20Sopenharmony_ci	asm volatile("" : : : "memory");
1018c2ecf20Sopenharmony_ci}
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#endif /* _IO_H */
104