18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __SPARC_IO_H
38c2ecf20Sopenharmony_ci#define __SPARC_IO_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/kernel.h>
68c2ecf20Sopenharmony_ci#include <linux/ioport.h>  /* struct resource */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#define IO_SPACE_LIMIT 0xffffffff
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#define memset_io(d,c,sz)     _memset_io(d,c,sz)
118c2ecf20Sopenharmony_ci#define memcpy_fromio(d,s,sz) _memcpy_fromio(d,s,sz)
128c2ecf20Sopenharmony_ci#define memcpy_toio(d,s,sz)   _memcpy_toio(d,s,sz)
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/*
158c2ecf20Sopenharmony_ci * Bus number may be embedded in the higher bits of the physical address.
168c2ecf20Sopenharmony_ci * This is why we have no bus number argument to ioremap().
178c2ecf20Sopenharmony_ci */
188c2ecf20Sopenharmony_civoid __iomem *ioremap(phys_addr_t offset, size_t size);
198c2ecf20Sopenharmony_civoid iounmap(volatile void __iomem *addr);
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include <asm-generic/io.h>
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistatic inline void _memset_io(volatile void __iomem *dst,
248c2ecf20Sopenharmony_ci                              int c, __kernel_size_t n)
258c2ecf20Sopenharmony_ci{
268c2ecf20Sopenharmony_ci	volatile void __iomem *d = dst;
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci	while (n--) {
298c2ecf20Sopenharmony_ci		writeb(c, d);
308c2ecf20Sopenharmony_ci		d++;
318c2ecf20Sopenharmony_ci	}
328c2ecf20Sopenharmony_ci}
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cistatic inline void _memcpy_fromio(void *dst, const volatile void __iomem *src,
358c2ecf20Sopenharmony_ci                                  __kernel_size_t n)
368c2ecf20Sopenharmony_ci{
378c2ecf20Sopenharmony_ci	char *d = dst;
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	while (n--) {
408c2ecf20Sopenharmony_ci		char tmp = readb(src);
418c2ecf20Sopenharmony_ci		*d++ = tmp;
428c2ecf20Sopenharmony_ci		src++;
438c2ecf20Sopenharmony_ci	}
448c2ecf20Sopenharmony_ci}
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistatic inline void _memcpy_toio(volatile void __iomem *dst, const void *src,
478c2ecf20Sopenharmony_ci                                __kernel_size_t n)
488c2ecf20Sopenharmony_ci{
498c2ecf20Sopenharmony_ci	const char *s = src;
508c2ecf20Sopenharmony_ci	volatile void __iomem *d = dst;
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	while (n--) {
538c2ecf20Sopenharmony_ci		char tmp = *s++;
548c2ecf20Sopenharmony_ci		writeb(tmp, d);
558c2ecf20Sopenharmony_ci		d++;
568c2ecf20Sopenharmony_ci	}
578c2ecf20Sopenharmony_ci}
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/*
608c2ecf20Sopenharmony_ci * SBus accessors.
618c2ecf20Sopenharmony_ci *
628c2ecf20Sopenharmony_ci * SBus has only one, memory mapped, I/O space.
638c2ecf20Sopenharmony_ci * We do not need to flip bytes for SBus of course.
648c2ecf20Sopenharmony_ci */
658c2ecf20Sopenharmony_cistatic inline u8 sbus_readb(const volatile void __iomem *addr)
668c2ecf20Sopenharmony_ci{
678c2ecf20Sopenharmony_ci	return *(__force volatile u8 *)addr;
688c2ecf20Sopenharmony_ci}
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cistatic inline u16 sbus_readw(const volatile void __iomem *addr)
718c2ecf20Sopenharmony_ci{
728c2ecf20Sopenharmony_ci	return *(__force volatile u16 *)addr;
738c2ecf20Sopenharmony_ci}
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cistatic inline u32 sbus_readl(const volatile void __iomem *addr)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci	return *(__force volatile u32 *)addr;
788c2ecf20Sopenharmony_ci}
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistatic inline void sbus_writeb(u8 b, volatile void __iomem *addr)
818c2ecf20Sopenharmony_ci{
828c2ecf20Sopenharmony_ci	*(__force volatile u8 *)addr = b;
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistatic inline void sbus_writew(u16 w, volatile void __iomem *addr)
868c2ecf20Sopenharmony_ci{
878c2ecf20Sopenharmony_ci	*(__force volatile u16 *)addr = w;
888c2ecf20Sopenharmony_ci}
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_cistatic inline void sbus_writel(u32 l, volatile void __iomem *addr)
918c2ecf20Sopenharmony_ci{
928c2ecf20Sopenharmony_ci	*(__force volatile u32 *)addr = l;
938c2ecf20Sopenharmony_ci}
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_cistatic inline void sbus_memset_io(volatile void __iomem *__dst, int c,
968c2ecf20Sopenharmony_ci                                  __kernel_size_t n)
978c2ecf20Sopenharmony_ci{
988c2ecf20Sopenharmony_ci	while(n--) {
998c2ecf20Sopenharmony_ci		sbus_writeb(c, __dst);
1008c2ecf20Sopenharmony_ci		__dst++;
1018c2ecf20Sopenharmony_ci	}
1028c2ecf20Sopenharmony_ci}
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cistatic inline void sbus_memcpy_fromio(void *dst,
1058c2ecf20Sopenharmony_ci                                      const volatile void __iomem *src,
1068c2ecf20Sopenharmony_ci                                      __kernel_size_t n)
1078c2ecf20Sopenharmony_ci{
1088c2ecf20Sopenharmony_ci	char *d = dst;
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	while (n--) {
1118c2ecf20Sopenharmony_ci		char tmp = sbus_readb(src);
1128c2ecf20Sopenharmony_ci		*d++ = tmp;
1138c2ecf20Sopenharmony_ci		src++;
1148c2ecf20Sopenharmony_ci	}
1158c2ecf20Sopenharmony_ci}
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_cistatic inline void sbus_memcpy_toio(volatile void __iomem *dst,
1188c2ecf20Sopenharmony_ci                                    const void *src,
1198c2ecf20Sopenharmony_ci                                    __kernel_size_t n)
1208c2ecf20Sopenharmony_ci{
1218c2ecf20Sopenharmony_ci	const char *s = src;
1228c2ecf20Sopenharmony_ci	volatile void __iomem *d = dst;
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci	while (n--) {
1258c2ecf20Sopenharmony_ci		char tmp = *s++;
1268c2ecf20Sopenharmony_ci		sbus_writeb(tmp, d);
1278c2ecf20Sopenharmony_ci		d++;
1288c2ecf20Sopenharmony_ci	}
1298c2ecf20Sopenharmony_ci}
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci/* Create a virtual mapping cookie for an IO port range */
1328c2ecf20Sopenharmony_civoid __iomem *ioport_map(unsigned long port, unsigned int nr);
1338c2ecf20Sopenharmony_civoid ioport_unmap(void __iomem *);
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci/* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
1368c2ecf20Sopenharmony_cistruct pci_dev;
1378c2ecf20Sopenharmony_civoid pci_iounmap(struct pci_dev *dev, void __iomem *);
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_cistatic inline int sbus_can_dma_64bit(void)
1408c2ecf20Sopenharmony_ci{
1418c2ecf20Sopenharmony_ci	return 0; /* actually, sparc_cpu_model==sun4d */
1428c2ecf20Sopenharmony_ci}
1438c2ecf20Sopenharmony_cistatic inline int sbus_can_burst64(void)
1448c2ecf20Sopenharmony_ci{
1458c2ecf20Sopenharmony_ci	return 0; /* actually, sparc_cpu_model==sun4d */
1468c2ecf20Sopenharmony_ci}
1478c2ecf20Sopenharmony_cistruct device;
1488c2ecf20Sopenharmony_civoid sbus_set_sbus64(struct device *, int);
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci#define __ARCH_HAS_NO_PAGE_ZERO_MAPPED		1
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci#endif /* !(__SPARC_IO_H) */
154