18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __SPARC64_IO_H
38c2ecf20Sopenharmony_ci#define __SPARC64_IO_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/kernel.h>
68c2ecf20Sopenharmony_ci#include <linux/compiler.h>
78c2ecf20Sopenharmony_ci#include <linux/types.h>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <asm/page.h>      /* IO address mapping routines need this */
108c2ecf20Sopenharmony_ci#include <asm/asi.h>
118c2ecf20Sopenharmony_ci#include <asm-generic/pci_iomap.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/* BIO layer definitions. */
148c2ecf20Sopenharmony_ciextern unsigned long kern_base, kern_size;
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci/* __raw_{read,write}{b,w,l,q} uses direct access.
178c2ecf20Sopenharmony_ci * Access the memory as big endian bypassing the cache
188c2ecf20Sopenharmony_ci * by using ASI_PHYS_BYPASS_EC_E
198c2ecf20Sopenharmony_ci */
208c2ecf20Sopenharmony_ci#define __raw_readb __raw_readb
218c2ecf20Sopenharmony_cistatic inline u8 __raw_readb(const volatile void __iomem *addr)
228c2ecf20Sopenharmony_ci{
238c2ecf20Sopenharmony_ci	u8 ret;
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci	__asm__ __volatile__("lduba\t[%1] %2, %0\t/* pci_raw_readb */"
268c2ecf20Sopenharmony_ci			     : "=r" (ret)
278c2ecf20Sopenharmony_ci			     : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci	return ret;
308c2ecf20Sopenharmony_ci}
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define __raw_readw __raw_readw
338c2ecf20Sopenharmony_cistatic inline u16 __raw_readw(const volatile void __iomem *addr)
348c2ecf20Sopenharmony_ci{
358c2ecf20Sopenharmony_ci	u16 ret;
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci	__asm__ __volatile__("lduha\t[%1] %2, %0\t/* pci_raw_readw */"
388c2ecf20Sopenharmony_ci			     : "=r" (ret)
398c2ecf20Sopenharmony_ci			     : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	return ret;
428c2ecf20Sopenharmony_ci}
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define __raw_readl __raw_readl
458c2ecf20Sopenharmony_cistatic inline u32 __raw_readl(const volatile void __iomem *addr)
468c2ecf20Sopenharmony_ci{
478c2ecf20Sopenharmony_ci	u32 ret;
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	__asm__ __volatile__("lduwa\t[%1] %2, %0\t/* pci_raw_readl */"
508c2ecf20Sopenharmony_ci			     : "=r" (ret)
518c2ecf20Sopenharmony_ci			     : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci	return ret;
548c2ecf20Sopenharmony_ci}
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci#define __raw_readq __raw_readq
578c2ecf20Sopenharmony_cistatic inline u64 __raw_readq(const volatile void __iomem *addr)
588c2ecf20Sopenharmony_ci{
598c2ecf20Sopenharmony_ci	u64 ret;
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	__asm__ __volatile__("ldxa\t[%1] %2, %0\t/* pci_raw_readq */"
628c2ecf20Sopenharmony_ci			     : "=r" (ret)
638c2ecf20Sopenharmony_ci			     : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	return ret;
668c2ecf20Sopenharmony_ci}
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#define __raw_writeb __raw_writeb
698c2ecf20Sopenharmony_cistatic inline void __raw_writeb(u8 b, const volatile void __iomem *addr)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	__asm__ __volatile__("stba\t%r0, [%1] %2\t/* pci_raw_writeb */"
728c2ecf20Sopenharmony_ci			     : /* no outputs */
738c2ecf20Sopenharmony_ci			     : "Jr" (b), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
748c2ecf20Sopenharmony_ci}
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci#define __raw_writew __raw_writew
778c2ecf20Sopenharmony_cistatic inline void __raw_writew(u16 w, const volatile void __iomem *addr)
788c2ecf20Sopenharmony_ci{
798c2ecf20Sopenharmony_ci	__asm__ __volatile__("stha\t%r0, [%1] %2\t/* pci_raw_writew */"
808c2ecf20Sopenharmony_ci			     : /* no outputs */
818c2ecf20Sopenharmony_ci			     : "Jr" (w), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
828c2ecf20Sopenharmony_ci}
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci#define __raw_writel __raw_writel
858c2ecf20Sopenharmony_cistatic inline void __raw_writel(u32 l, const volatile void __iomem *addr)
868c2ecf20Sopenharmony_ci{
878c2ecf20Sopenharmony_ci	__asm__ __volatile__("stwa\t%r0, [%1] %2\t/* pci_raw_writel */"
888c2ecf20Sopenharmony_ci			     : /* no outputs */
898c2ecf20Sopenharmony_ci			     : "Jr" (l), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
908c2ecf20Sopenharmony_ci}
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#define __raw_writeq __raw_writeq
938c2ecf20Sopenharmony_cistatic inline void __raw_writeq(u64 q, const volatile void __iomem *addr)
948c2ecf20Sopenharmony_ci{
958c2ecf20Sopenharmony_ci	__asm__ __volatile__("stxa\t%r0, [%1] %2\t/* pci_raw_writeq */"
968c2ecf20Sopenharmony_ci			     : /* no outputs */
978c2ecf20Sopenharmony_ci			     : "Jr" (q), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E));
988c2ecf20Sopenharmony_ci}
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/* Memory functions, same as I/O accesses on Ultra.
1018c2ecf20Sopenharmony_ci * Access memory as little endian bypassing
1028c2ecf20Sopenharmony_ci * the cache by using ASI_PHYS_BYPASS_EC_E_L
1038c2ecf20Sopenharmony_ci */
1048c2ecf20Sopenharmony_ci#define readb readb
1058c2ecf20Sopenharmony_ci#define readb_relaxed readb
1068c2ecf20Sopenharmony_cistatic inline u8 readb(const volatile void __iomem *addr)
1078c2ecf20Sopenharmony_ci{	u8 ret;
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci	__asm__ __volatile__("lduba\t[%1] %2, %0\t/* pci_readb */"
1108c2ecf20Sopenharmony_ci			     : "=r" (ret)
1118c2ecf20Sopenharmony_ci			     : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
1128c2ecf20Sopenharmony_ci			     : "memory");
1138c2ecf20Sopenharmony_ci	return ret;
1148c2ecf20Sopenharmony_ci}
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci#define readw readw
1178c2ecf20Sopenharmony_ci#define readw_relaxed readw
1188c2ecf20Sopenharmony_cistatic inline u16 readw(const volatile void __iomem *addr)
1198c2ecf20Sopenharmony_ci{	u16 ret;
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci	__asm__ __volatile__("lduha\t[%1] %2, %0\t/* pci_readw */"
1228c2ecf20Sopenharmony_ci			     : "=r" (ret)
1238c2ecf20Sopenharmony_ci			     : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
1248c2ecf20Sopenharmony_ci			     : "memory");
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	return ret;
1278c2ecf20Sopenharmony_ci}
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci#define readl readl
1308c2ecf20Sopenharmony_ci#define readl_relaxed readl
1318c2ecf20Sopenharmony_cistatic inline u32 readl(const volatile void __iomem *addr)
1328c2ecf20Sopenharmony_ci{	u32 ret;
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci	__asm__ __volatile__("lduwa\t[%1] %2, %0\t/* pci_readl */"
1358c2ecf20Sopenharmony_ci			     : "=r" (ret)
1368c2ecf20Sopenharmony_ci			     : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
1378c2ecf20Sopenharmony_ci			     : "memory");
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci	return ret;
1408c2ecf20Sopenharmony_ci}
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci#define readq readq
1438c2ecf20Sopenharmony_ci#define readq_relaxed readq
1448c2ecf20Sopenharmony_cistatic inline u64 readq(const volatile void __iomem *addr)
1458c2ecf20Sopenharmony_ci{	u64 ret;
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci	__asm__ __volatile__("ldxa\t[%1] %2, %0\t/* pci_readq */"
1488c2ecf20Sopenharmony_ci			     : "=r" (ret)
1498c2ecf20Sopenharmony_ci			     : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
1508c2ecf20Sopenharmony_ci			     : "memory");
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci	return ret;
1538c2ecf20Sopenharmony_ci}
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci#define writeb writeb
1568c2ecf20Sopenharmony_ci#define writeb_relaxed writeb
1578c2ecf20Sopenharmony_cistatic inline void writeb(u8 b, volatile void __iomem *addr)
1588c2ecf20Sopenharmony_ci{
1598c2ecf20Sopenharmony_ci	__asm__ __volatile__("stba\t%r0, [%1] %2\t/* pci_writeb */"
1608c2ecf20Sopenharmony_ci			     : /* no outputs */
1618c2ecf20Sopenharmony_ci			     : "Jr" (b), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
1628c2ecf20Sopenharmony_ci			     : "memory");
1638c2ecf20Sopenharmony_ci}
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci#define writew writew
1668c2ecf20Sopenharmony_ci#define writew_relaxed writew
1678c2ecf20Sopenharmony_cistatic inline void writew(u16 w, volatile void __iomem *addr)
1688c2ecf20Sopenharmony_ci{
1698c2ecf20Sopenharmony_ci	__asm__ __volatile__("stha\t%r0, [%1] %2\t/* pci_writew */"
1708c2ecf20Sopenharmony_ci			     : /* no outputs */
1718c2ecf20Sopenharmony_ci			     : "Jr" (w), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
1728c2ecf20Sopenharmony_ci			     : "memory");
1738c2ecf20Sopenharmony_ci}
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci#define writel writel
1768c2ecf20Sopenharmony_ci#define writel_relaxed writel
1778c2ecf20Sopenharmony_cistatic inline void writel(u32 l, volatile void __iomem *addr)
1788c2ecf20Sopenharmony_ci{
1798c2ecf20Sopenharmony_ci	__asm__ __volatile__("stwa\t%r0, [%1] %2\t/* pci_writel */"
1808c2ecf20Sopenharmony_ci			     : /* no outputs */
1818c2ecf20Sopenharmony_ci			     : "Jr" (l), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
1828c2ecf20Sopenharmony_ci			     : "memory");
1838c2ecf20Sopenharmony_ci}
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci#define writeq writeq
1868c2ecf20Sopenharmony_ci#define writeq_relaxed writeq
1878c2ecf20Sopenharmony_cistatic inline void writeq(u64 q, volatile void __iomem *addr)
1888c2ecf20Sopenharmony_ci{
1898c2ecf20Sopenharmony_ci	__asm__ __volatile__("stxa\t%r0, [%1] %2\t/* pci_writeq */"
1908c2ecf20Sopenharmony_ci			     : /* no outputs */
1918c2ecf20Sopenharmony_ci			     : "Jr" (q), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L)
1928c2ecf20Sopenharmony_ci			     : "memory");
1938c2ecf20Sopenharmony_ci}
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci#define inb inb
1968c2ecf20Sopenharmony_cistatic inline u8 inb(unsigned long addr)
1978c2ecf20Sopenharmony_ci{
1988c2ecf20Sopenharmony_ci	return readb((volatile void __iomem *)addr);
1998c2ecf20Sopenharmony_ci}
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci#define inw inw
2028c2ecf20Sopenharmony_cistatic inline u16 inw(unsigned long addr)
2038c2ecf20Sopenharmony_ci{
2048c2ecf20Sopenharmony_ci	return readw((volatile void __iomem *)addr);
2058c2ecf20Sopenharmony_ci}
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci#define inl inl
2088c2ecf20Sopenharmony_cistatic inline u32 inl(unsigned long addr)
2098c2ecf20Sopenharmony_ci{
2108c2ecf20Sopenharmony_ci	return readl((volatile void __iomem *)addr);
2118c2ecf20Sopenharmony_ci}
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci#define outb outb
2148c2ecf20Sopenharmony_cistatic inline void outb(u8 b, unsigned long addr)
2158c2ecf20Sopenharmony_ci{
2168c2ecf20Sopenharmony_ci	writeb(b, (volatile void __iomem *)addr);
2178c2ecf20Sopenharmony_ci}
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci#define outw outw
2208c2ecf20Sopenharmony_cistatic inline void outw(u16 w, unsigned long addr)
2218c2ecf20Sopenharmony_ci{
2228c2ecf20Sopenharmony_ci	writew(w, (volatile void __iomem *)addr);
2238c2ecf20Sopenharmony_ci}
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci#define outl outl
2268c2ecf20Sopenharmony_cistatic inline void outl(u32 l, unsigned long addr)
2278c2ecf20Sopenharmony_ci{
2288c2ecf20Sopenharmony_ci	writel(l, (volatile void __iomem *)addr);
2298c2ecf20Sopenharmony_ci}
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci#define inb_p(__addr) 		inb(__addr)
2338c2ecf20Sopenharmony_ci#define outb_p(__b, __addr)	outb(__b, __addr)
2348c2ecf20Sopenharmony_ci#define inw_p(__addr)		inw(__addr)
2358c2ecf20Sopenharmony_ci#define outw_p(__w, __addr)	outw(__w, __addr)
2368c2ecf20Sopenharmony_ci#define inl_p(__addr)		inl(__addr)
2378c2ecf20Sopenharmony_ci#define outl_p(__l, __addr)	outl(__l, __addr)
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_civoid outsb(unsigned long, const void *, unsigned long);
2408c2ecf20Sopenharmony_civoid outsw(unsigned long, const void *, unsigned long);
2418c2ecf20Sopenharmony_civoid outsl(unsigned long, const void *, unsigned long);
2428c2ecf20Sopenharmony_civoid insb(unsigned long, void *, unsigned long);
2438c2ecf20Sopenharmony_civoid insw(unsigned long, void *, unsigned long);
2448c2ecf20Sopenharmony_civoid insl(unsigned long, void *, unsigned long);
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_cistatic inline void readsb(void __iomem *port, void *buf, unsigned long count)
2478c2ecf20Sopenharmony_ci{
2488c2ecf20Sopenharmony_ci	insb((unsigned long __force)port, buf, count);
2498c2ecf20Sopenharmony_ci}
2508c2ecf20Sopenharmony_cistatic inline void readsw(void __iomem *port, void *buf, unsigned long count)
2518c2ecf20Sopenharmony_ci{
2528c2ecf20Sopenharmony_ci	insw((unsigned long __force)port, buf, count);
2538c2ecf20Sopenharmony_ci}
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_cistatic inline void readsl(void __iomem *port, void *buf, unsigned long count)
2568c2ecf20Sopenharmony_ci{
2578c2ecf20Sopenharmony_ci	insl((unsigned long __force)port, buf, count);
2588c2ecf20Sopenharmony_ci}
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_cistatic inline void writesb(void __iomem *port, const void *buf, unsigned long count)
2618c2ecf20Sopenharmony_ci{
2628c2ecf20Sopenharmony_ci	outsb((unsigned long __force)port, buf, count);
2638c2ecf20Sopenharmony_ci}
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_cistatic inline void writesw(void __iomem *port, const void *buf, unsigned long count)
2668c2ecf20Sopenharmony_ci{
2678c2ecf20Sopenharmony_ci	outsw((unsigned long __force)port, buf, count);
2688c2ecf20Sopenharmony_ci}
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_cistatic inline void writesl(void __iomem *port, const void *buf, unsigned long count)
2718c2ecf20Sopenharmony_ci{
2728c2ecf20Sopenharmony_ci	outsl((unsigned long __force)port, buf, count);
2738c2ecf20Sopenharmony_ci}
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci#define ioread8_rep(p,d,l)	readsb(p,d,l)
2768c2ecf20Sopenharmony_ci#define ioread16_rep(p,d,l)	readsw(p,d,l)
2778c2ecf20Sopenharmony_ci#define ioread32_rep(p,d,l)	readsl(p,d,l)
2788c2ecf20Sopenharmony_ci#define iowrite8_rep(p,d,l)	writesb(p,d,l)
2798c2ecf20Sopenharmony_ci#define iowrite16_rep(p,d,l)	writesw(p,d,l)
2808c2ecf20Sopenharmony_ci#define iowrite32_rep(p,d,l)	writesl(p,d,l)
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci/* Valid I/O Space regions are anywhere, because each PCI bus supported
2838c2ecf20Sopenharmony_ci * can live in an arbitrary area of the physical address range.
2848c2ecf20Sopenharmony_ci */
2858c2ecf20Sopenharmony_ci#define IO_SPACE_LIMIT 0xffffffffffffffffUL
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci/* Now, SBUS variants, only difference from PCI is that we do
2888c2ecf20Sopenharmony_ci * not use little-endian ASIs.
2898c2ecf20Sopenharmony_ci */
2908c2ecf20Sopenharmony_cistatic inline u8 sbus_readb(const volatile void __iomem *addr)
2918c2ecf20Sopenharmony_ci{
2928c2ecf20Sopenharmony_ci	return __raw_readb(addr);
2938c2ecf20Sopenharmony_ci}
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_cistatic inline u16 sbus_readw(const volatile void __iomem *addr)
2968c2ecf20Sopenharmony_ci{
2978c2ecf20Sopenharmony_ci	return __raw_readw(addr);
2988c2ecf20Sopenharmony_ci}
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_cistatic inline u32 sbus_readl(const volatile void __iomem *addr)
3018c2ecf20Sopenharmony_ci{
3028c2ecf20Sopenharmony_ci	return __raw_readl(addr);
3038c2ecf20Sopenharmony_ci}
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_cistatic inline u64 sbus_readq(const volatile void __iomem *addr)
3068c2ecf20Sopenharmony_ci{
3078c2ecf20Sopenharmony_ci	return __raw_readq(addr);
3088c2ecf20Sopenharmony_ci}
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_cistatic inline void sbus_writeb(u8 b, volatile void __iomem *addr)
3118c2ecf20Sopenharmony_ci{
3128c2ecf20Sopenharmony_ci	__raw_writeb(b, addr);
3138c2ecf20Sopenharmony_ci}
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_cistatic inline void sbus_writew(u16 w, volatile void __iomem *addr)
3168c2ecf20Sopenharmony_ci{
3178c2ecf20Sopenharmony_ci	__raw_writew(w, addr);
3188c2ecf20Sopenharmony_ci}
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_cistatic inline void sbus_writel(u32 l, volatile void __iomem *addr)
3218c2ecf20Sopenharmony_ci{
3228c2ecf20Sopenharmony_ci	__raw_writel(l, addr);
3238c2ecf20Sopenharmony_ci}
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_cistatic inline void sbus_writeq(u64 q, volatile void __iomem *addr)
3268c2ecf20Sopenharmony_ci{
3278c2ecf20Sopenharmony_ci	__raw_writeq(q, addr);
3288c2ecf20Sopenharmony_ci}
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_cistatic inline void sbus_memset_io(volatile void __iomem *dst, int c, __kernel_size_t n)
3318c2ecf20Sopenharmony_ci{
3328c2ecf20Sopenharmony_ci	while(n--) {
3338c2ecf20Sopenharmony_ci		sbus_writeb(c, dst);
3348c2ecf20Sopenharmony_ci		dst++;
3358c2ecf20Sopenharmony_ci	}
3368c2ecf20Sopenharmony_ci}
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_cistatic inline void memset_io(volatile void __iomem *dst, int c, __kernel_size_t n)
3398c2ecf20Sopenharmony_ci{
3408c2ecf20Sopenharmony_ci	volatile void __iomem *d = dst;
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci	while (n--) {
3438c2ecf20Sopenharmony_ci		writeb(c, d);
3448c2ecf20Sopenharmony_ci		d++;
3458c2ecf20Sopenharmony_ci	}
3468c2ecf20Sopenharmony_ci}
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_cistatic inline void sbus_memcpy_fromio(void *dst, const volatile void __iomem *src,
3498c2ecf20Sopenharmony_ci				      __kernel_size_t n)
3508c2ecf20Sopenharmony_ci{
3518c2ecf20Sopenharmony_ci	char *d = dst;
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci	while (n--) {
3548c2ecf20Sopenharmony_ci		char tmp = sbus_readb(src);
3558c2ecf20Sopenharmony_ci		*d++ = tmp;
3568c2ecf20Sopenharmony_ci		src++;
3578c2ecf20Sopenharmony_ci	}
3588c2ecf20Sopenharmony_ci}
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_cistatic inline void memcpy_fromio(void *dst, const volatile void __iomem *src,
3628c2ecf20Sopenharmony_ci				 __kernel_size_t n)
3638c2ecf20Sopenharmony_ci{
3648c2ecf20Sopenharmony_ci	char *d = dst;
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_ci	while (n--) {
3678c2ecf20Sopenharmony_ci		char tmp = readb(src);
3688c2ecf20Sopenharmony_ci		*d++ = tmp;
3698c2ecf20Sopenharmony_ci		src++;
3708c2ecf20Sopenharmony_ci	}
3718c2ecf20Sopenharmony_ci}
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_cistatic inline void sbus_memcpy_toio(volatile void __iomem *dst, const void *src,
3748c2ecf20Sopenharmony_ci				    __kernel_size_t n)
3758c2ecf20Sopenharmony_ci{
3768c2ecf20Sopenharmony_ci	const char *s = src;
3778c2ecf20Sopenharmony_ci	volatile void __iomem *d = dst;
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci	while (n--) {
3808c2ecf20Sopenharmony_ci		char tmp = *s++;
3818c2ecf20Sopenharmony_ci		sbus_writeb(tmp, d);
3828c2ecf20Sopenharmony_ci		d++;
3838c2ecf20Sopenharmony_ci	}
3848c2ecf20Sopenharmony_ci}
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_cistatic inline void memcpy_toio(volatile void __iomem *dst, const void *src,
3878c2ecf20Sopenharmony_ci			       __kernel_size_t n)
3888c2ecf20Sopenharmony_ci{
3898c2ecf20Sopenharmony_ci	const char *s = src;
3908c2ecf20Sopenharmony_ci	volatile void __iomem *d = dst;
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_ci	while (n--) {
3938c2ecf20Sopenharmony_ci		char tmp = *s++;
3948c2ecf20Sopenharmony_ci		writeb(tmp, d);
3958c2ecf20Sopenharmony_ci		d++;
3968c2ecf20Sopenharmony_ci	}
3978c2ecf20Sopenharmony_ci}
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ci#ifdef __KERNEL__
4008c2ecf20Sopenharmony_ci
4018c2ecf20Sopenharmony_ci/* On sparc64 we have the whole physical IO address space accessible
4028c2ecf20Sopenharmony_ci * using physically addressed loads and stores, so this does nothing.
4038c2ecf20Sopenharmony_ci */
4048c2ecf20Sopenharmony_cistatic inline void __iomem *ioremap(unsigned long offset, unsigned long size)
4058c2ecf20Sopenharmony_ci{
4068c2ecf20Sopenharmony_ci	return (void __iomem *)offset;
4078c2ecf20Sopenharmony_ci}
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_ci#define ioremap_uc(X,Y)			ioremap((X),(Y))
4108c2ecf20Sopenharmony_ci#define ioremap_wc(X,Y)			ioremap((X),(Y))
4118c2ecf20Sopenharmony_ci#define ioremap_wt(X,Y)			ioremap((X),(Y))
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_cistatic inline void iounmap(volatile void __iomem *addr)
4148c2ecf20Sopenharmony_ci{
4158c2ecf20Sopenharmony_ci}
4168c2ecf20Sopenharmony_ci
4178c2ecf20Sopenharmony_ci#define ioread8			readb
4188c2ecf20Sopenharmony_ci#define ioread16		readw
4198c2ecf20Sopenharmony_ci#define ioread16be		__raw_readw
4208c2ecf20Sopenharmony_ci#define ioread32		readl
4218c2ecf20Sopenharmony_ci#define ioread32be		__raw_readl
4228c2ecf20Sopenharmony_ci#define iowrite8		writeb
4238c2ecf20Sopenharmony_ci#define iowrite16		writew
4248c2ecf20Sopenharmony_ci#define iowrite16be		__raw_writew
4258c2ecf20Sopenharmony_ci#define iowrite32		writel
4268c2ecf20Sopenharmony_ci#define iowrite32be		__raw_writel
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci/* Create a virtual mapping cookie for an IO port range */
4298c2ecf20Sopenharmony_civoid __iomem *ioport_map(unsigned long port, unsigned int nr);
4308c2ecf20Sopenharmony_civoid ioport_unmap(void __iomem *);
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_ci/* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
4338c2ecf20Sopenharmony_cistruct pci_dev;
4348c2ecf20Sopenharmony_civoid pci_iounmap(struct pci_dev *dev, void __iomem *);
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_cistatic inline int sbus_can_dma_64bit(void)
4378c2ecf20Sopenharmony_ci{
4388c2ecf20Sopenharmony_ci	return 1;
4398c2ecf20Sopenharmony_ci}
4408c2ecf20Sopenharmony_cistatic inline int sbus_can_burst64(void)
4418c2ecf20Sopenharmony_ci{
4428c2ecf20Sopenharmony_ci	return 1;
4438c2ecf20Sopenharmony_ci}
4448c2ecf20Sopenharmony_cistruct device;
4458c2ecf20Sopenharmony_civoid sbus_set_sbus64(struct device *, int);
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci/*
4488c2ecf20Sopenharmony_ci * Convert a physical pointer to a virtual kernel pointer for /dev/mem
4498c2ecf20Sopenharmony_ci * access
4508c2ecf20Sopenharmony_ci */
4518c2ecf20Sopenharmony_ci#define xlate_dev_mem_ptr(p)	__va(p)
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci/*
4548c2ecf20Sopenharmony_ci * Convert a virtual cached pointer to an uncached pointer
4558c2ecf20Sopenharmony_ci */
4568c2ecf20Sopenharmony_ci#define xlate_dev_kmem_ptr(p)	p
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_ci#endif
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci#endif /* !(__SPARC64_IO_H) */
461