Commit | Line | Data |
---|---|---|
7153c3cb HC |
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 | ||
7153c3cb HC |
8 | #include <linux/kernel.h> |
9 | #include <linux/types.h> | |
10 | ||
11 | #include <asm/addrspace.h> | |
7153c3cb HC |
12 | #include <asm/cpu.h> |
13 | #include <asm/page.h> | |
14 | #include <asm/pgtable-bits.h> | |
15 | #include <asm/string.h> | |
16 | ||
7153c3cb HC |
17 | /* |
18 | * Change "struct page" to physical address. | |
19 | */ | |
20 | #define page_to_phys(page) ((phys_addr_t)page_to_pfn(page) << PAGE_SHIFT) | |
21 | ||
22 | extern void __init __iomem *early_ioremap(u64 phys_addr, unsigned long size); | |
23 | extern void __init early_iounmap(void __iomem *addr, unsigned long size); | |
24 | ||
25 | #define early_memremap early_ioremap | |
26 | #define early_memunmap early_iounmap | |
27 | ||
d2791341 HC |
28 | #ifdef CONFIG_ARCH_IOREMAP |
29 | ||
7153c3cb HC |
30 | static inline void __iomem *ioremap_prot(phys_addr_t offset, unsigned long size, |
31 | unsigned long prot_val) | |
32 | { | |
d2791341 | 33 | if (prot_val & _CACHE_CC) |
7153c3cb HC |
34 | return (void __iomem *)(unsigned long)(CACHE_BASE + offset); |
35 | else | |
36 | return (void __iomem *)(unsigned long)(UNCACHE_BASE + offset); | |
37 | } | |
38 | ||
d2791341 HC |
39 | #define ioremap(offset, size) \ |
40 | ioremap_prot((offset), (size), pgprot_val(PAGE_KERNEL_SUC)) | |
7153c3cb | 41 | |
d2791341 HC |
42 | #define iounmap(addr) ((void)(addr)) |
43 | ||
44 | #endif | |
7153c3cb HC |
45 | |
46 | /* | |
d2791341 HC |
47 | * On LoongArch, ioremap() has two variants, ioremap_wc() and ioremap_cache(). |
48 | * They map bus memory into CPU space, the mapped memory is marked uncachable | |
49 | * (_CACHE_SUC), uncachable but accelerated by write-combine (_CACHE_WUC) and | |
50 | * cachable (_CACHE_CC) respectively for CPU access. | |
7153c3cb | 51 | * |
d2791341 HC |
52 | * @offset: bus address of the memory |
53 | * @size: size of the resource to map | |
7153c3cb | 54 | */ |
d2791341 | 55 | #define ioremap_wc(offset, size) \ |
278be836 IZ |
56 | ioremap_prot((offset), (size), \ |
57 | pgprot_val(wc_enabled ? PAGE_KERNEL_WUC : PAGE_KERNEL_SUC)) | |
7153c3cb | 58 | |
d2791341 HC |
59 | #define ioremap_cache(offset, size) \ |
60 | ioremap_prot((offset), (size), pgprot_val(PAGE_KERNEL)) | |
7153c3cb | 61 | |
e031a5f3 | 62 | #define mmiowb() wmb() |
7153c3cb HC |
63 | |
64 | /* | |
65 | * String version of I/O memory access operations. | |
66 | */ | |
67 | extern void __memset_io(volatile void __iomem *dst, int c, size_t count); | |
68 | extern void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count); | |
69 | extern void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count); | |
70 | #define memset_io(c, v, l) __memset_io((c), (v), (l)) | |
71 | #define memcpy_fromio(a, c, l) __memcpy_fromio((a), (c), (l)) | |
72 | #define memcpy_toio(c, a, l) __memcpy_toio((c), (a), (l)) | |
73 | ||
74 | #include <asm-generic/io.h> | |
75 | ||
235d074f HC |
76 | #define ARCH_HAS_VALID_PHYS_ADDR_RANGE |
77 | extern int valid_phys_addr_range(phys_addr_t addr, size_t size); | |
78 | extern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size); | |
79 | ||
7153c3cb | 80 | #endif /* _ASM_IO_H */ |