]> Git Repo - linux.git/blob - arch/loongarch/include/asm/io.h
Merge tag 'amd-drm-next-6.5-2023-06-09' of https://gitlab.freedesktop.org/agd5f/linux...
[linux.git] / arch / loongarch / include / asm / io.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4  */
5 #ifndef _ASM_IO_H
6 #define _ASM_IO_H
7
8 #define ARCH_HAS_IOREMAP_WC
9
10 #include <linux/kernel.h>
11 #include <linux/types.h>
12
13 #include <asm/addrspace.h>
14 #include <asm/cpu.h>
15 #include <asm/page.h>
16 #include <asm/pgtable-bits.h>
17 #include <asm/string.h>
18
19 /*
20  * Change "struct page" to physical address.
21  */
22 #define page_to_phys(page)      ((phys_addr_t)page_to_pfn(page) << PAGE_SHIFT)
23
24 extern void __init __iomem *early_ioremap(u64 phys_addr, unsigned long size);
25 extern void __init early_iounmap(void __iomem *addr, unsigned long size);
26
27 #define early_memremap early_ioremap
28 #define early_memunmap early_iounmap
29
30 #ifdef CONFIG_ARCH_IOREMAP
31
32 static inline void __iomem *ioremap_prot(phys_addr_t offset, unsigned long size,
33                                          unsigned long prot_val)
34 {
35         if (prot_val & _CACHE_CC)
36                 return (void __iomem *)(unsigned long)(CACHE_BASE + offset);
37         else
38                 return (void __iomem *)(unsigned long)(UNCACHE_BASE + offset);
39 }
40
41 #define ioremap(offset, size)           \
42         ioremap_prot((offset), (size), pgprot_val(PAGE_KERNEL_SUC))
43
44 #define iounmap(addr)                   ((void)(addr))
45
46 #endif
47
48 /*
49  * On LoongArch, ioremap() has two variants, ioremap_wc() and ioremap_cache().
50  * They map bus memory into CPU space, the mapped memory is marked uncachable
51  * (_CACHE_SUC), uncachable but accelerated by write-combine (_CACHE_WUC) and
52  * cachable (_CACHE_CC) respectively for CPU access.
53  *
54  * @offset:    bus address of the memory
55  * @size:      size of the resource to map
56  */
57 extern pgprot_t pgprot_wc;
58
59 #define ioremap_wc(offset, size)        \
60         ioremap_prot((offset), (size), pgprot_val(pgprot_wc))
61
62 #define ioremap_cache(offset, size)     \
63         ioremap_prot((offset), (size), pgprot_val(PAGE_KERNEL))
64
65 #define mmiowb() asm volatile ("dbar 0" ::: "memory")
66
67 /*
68  * String version of I/O memory access operations.
69  */
70 extern void __memset_io(volatile void __iomem *dst, int c, size_t count);
71 extern void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count);
72 extern void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count);
73 #define memset_io(c, v, l)     __memset_io((c), (v), (l))
74 #define memcpy_fromio(a, c, l) __memcpy_fromio((a), (c), (l))
75 #define memcpy_toio(c, a, l)   __memcpy_toio((c), (a), (l))
76
77 #include <asm-generic/io.h>
78
79 #define ARCH_HAS_VALID_PHYS_ADDR_RANGE
80 extern int valid_phys_addr_range(phys_addr_t addr, size_t size);
81 extern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
82
83 #endif /* _ASM_IO_H */
This page took 0.036603 seconds and 4 git commands to generate.