1*4494ce4fSKuninori Morimoto // SPDX-License-Identifier: GPL-2.0
262d6b66eSPaul Mundt /*
362d6b66eSPaul Mundt * arch/sh/lib/io.c - SH32 optimized I/O routines
462d6b66eSPaul Mundt *
562d6b66eSPaul Mundt * Copyright (C) 2000 Stuart Menefy
662d6b66eSPaul Mundt * Copyright (C) 2005 Paul Mundt
762d6b66eSPaul Mundt *
862d6b66eSPaul Mundt * Provide real functions which expand to whatever the header file defined.
962d6b66eSPaul Mundt * Also definitions of machine independent IO functions.
1062d6b66eSPaul Mundt */
1162d6b66eSPaul Mundt #include <linux/module.h>
1262d6b66eSPaul Mundt #include <linux/io.h>
1362d6b66eSPaul Mundt
__raw_readsl(const void __iomem * addr,void * datap,int len)1464c9627cSPaul Mundt void __raw_readsl(const void __iomem *addr, void *datap, int len)
1562d6b66eSPaul Mundt {
1662d6b66eSPaul Mundt u32 *data;
1762d6b66eSPaul Mundt
1862d6b66eSPaul Mundt for (data = datap; (len != 0) && (((u32)data & 0x1f) != 0); len--)
1964c9627cSPaul Mundt *data++ = __raw_readl(addr);
2062d6b66eSPaul Mundt
2162d6b66eSPaul Mundt if (likely(len >= (0x20 >> 2))) {
2262d6b66eSPaul Mundt int tmp2, tmp3, tmp4, tmp5, tmp6;
2362d6b66eSPaul Mundt
2462d6b66eSPaul Mundt __asm__ __volatile__(
2562d6b66eSPaul Mundt "1: \n\t"
2662d6b66eSPaul Mundt "mov.l @%7, r0 \n\t"
2762d6b66eSPaul Mundt "mov.l @%7, %2 \n\t"
2862d6b66eSPaul Mundt #ifdef CONFIG_CPU_SH4
2962d6b66eSPaul Mundt "movca.l r0, @%0 \n\t"
3062d6b66eSPaul Mundt #else
3162d6b66eSPaul Mundt "mov.l r0, @%0 \n\t"
3262d6b66eSPaul Mundt #endif
3362d6b66eSPaul Mundt "mov.l @%7, %3 \n\t"
3462d6b66eSPaul Mundt "mov.l @%7, %4 \n\t"
3562d6b66eSPaul Mundt "mov.l @%7, %5 \n\t"
3662d6b66eSPaul Mundt "mov.l @%7, %6 \n\t"
3762d6b66eSPaul Mundt "mov.l @%7, r7 \n\t"
3862d6b66eSPaul Mundt "mov.l @%7, r0 \n\t"
3962d6b66eSPaul Mundt "mov.l %2, @(0x04,%0) \n\t"
4062d6b66eSPaul Mundt "mov #0x20>>2, %2 \n\t"
4162d6b66eSPaul Mundt "mov.l %3, @(0x08,%0) \n\t"
4262d6b66eSPaul Mundt "sub %2, %1 \n\t"
4362d6b66eSPaul Mundt "mov.l %4, @(0x0c,%0) \n\t"
4462d6b66eSPaul Mundt "cmp/hi %1, %2 ! T if 32 > len \n\t"
4562d6b66eSPaul Mundt "mov.l %5, @(0x10,%0) \n\t"
4662d6b66eSPaul Mundt "mov.l %6, @(0x14,%0) \n\t"
4762d6b66eSPaul Mundt "mov.l r7, @(0x18,%0) \n\t"
4862d6b66eSPaul Mundt "mov.l r0, @(0x1c,%0) \n\t"
4962d6b66eSPaul Mundt "bf.s 1b \n\t"
5062d6b66eSPaul Mundt " add #0x20, %0 \n\t"
5162d6b66eSPaul Mundt : "=&r" (data), "=&r" (len),
5262d6b66eSPaul Mundt "=&r" (tmp2), "=&r" (tmp3), "=&r" (tmp4),
5362d6b66eSPaul Mundt "=&r" (tmp5), "=&r" (tmp6)
5462d6b66eSPaul Mundt : "r"(addr), "0" (data), "1" (len)
5562d6b66eSPaul Mundt : "r0", "r7", "t", "memory");
5662d6b66eSPaul Mundt }
5762d6b66eSPaul Mundt
5862d6b66eSPaul Mundt for (; len != 0; len--)
5964c9627cSPaul Mundt *data++ = __raw_readl(addr);
6062d6b66eSPaul Mundt }
6162d6b66eSPaul Mundt EXPORT_SYMBOL(__raw_readsl);
6262d6b66eSPaul Mundt
__raw_writesl(void __iomem * addr,const void * data,int len)6364c9627cSPaul Mundt void __raw_writesl(void __iomem *addr, const void *data, int len)
6462d6b66eSPaul Mundt {
6562d6b66eSPaul Mundt if (likely(len != 0)) {
6662d6b66eSPaul Mundt int tmp1;
6762d6b66eSPaul Mundt
6862d6b66eSPaul Mundt __asm__ __volatile__ (
6962d6b66eSPaul Mundt "1: \n\t"
7062d6b66eSPaul Mundt "mov.l @%0+, %1 \n\t"
7162d6b66eSPaul Mundt "dt %3 \n\t"
7262d6b66eSPaul Mundt "bf.s 1b \n\t"
7362d6b66eSPaul Mundt " mov.l %1, @%4 \n\t"
7462d6b66eSPaul Mundt : "=&r" (data), "=&r" (tmp1)
7562d6b66eSPaul Mundt : "0" (data), "r" (len), "r"(addr)
7662d6b66eSPaul Mundt : "t", "memory");
7762d6b66eSPaul Mundt }
7862d6b66eSPaul Mundt }
7962d6b66eSPaul Mundt EXPORT_SYMBOL(__raw_writesl);
80