forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-09-20 a36159eec6ca17402b0e146b86efaf76568dc353
kernel/arch/openrisc/kernel/dma.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * OpenRISC Linux
34 *
....@@ -9,17 +10,11 @@
910 * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
1011 * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
1112 *
12
- * This program is free software; you can redistribute it and/or
13
- * modify it under the terms of the GNU General Public License
14
- * as published by the Free Software Foundation; either version
15
- * 2 of the License, or (at your option) any later version.
16
- *
1713 * DMA mapping callbacks...
18
- * As alloc_coherent is the only DMA callback being used currently, that's
19
- * the only thing implemented properly. The rest need looking into...
2014 */
2115
22
-#include <linux/dma-noncoherent.h>
16
+#include <linux/dma-map-ops.h>
17
+#include <linux/pagewalk.h>
2318
2419 #include <asm/cpuinfo.h>
2520 #include <asm/spr_defs.h>
....@@ -38,7 +33,7 @@
3833 * Flush the page out of the TLB so that the new page flags get
3934 * picked up next time there's an access
4035 */
41
- flush_tlb_page(NULL, addr);
36
+ flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
4237
4338 /* Flush page out of dcache */
4439 for (cl = __pa(addr); cl < __pa(next); cl += cpuinfo->dcache_block_size)
....@@ -46,6 +41,10 @@
4641
4742 return 0;
4843 }
44
+
45
+static const struct mm_walk_ops set_nocache_walk_ops = {
46
+ .pte_entry = page_set_nocache,
47
+};
4948
5049 static int
5150 page_clear_nocache(pte_t *pte, unsigned long addr,
....@@ -57,80 +56,46 @@
5756 * Flush the page out of the TLB so that the new page flags get
5857 * picked up next time there's an access
5958 */
60
- flush_tlb_page(NULL, addr);
59
+ flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
6160
6261 return 0;
6362 }
6463
65
-/*
66
- * Alloc "coherent" memory, which for OpenRISC means simply uncached.
67
- *
68
- * This function effectively just calls __get_free_pages, sets the
69
- * cache-inhibit bit on those pages, and makes sure that the pages are
70
- * flushed out of the cache before they are used.
71
- *
72
- * If the NON_CONSISTENT attribute is set, then this function just
73
- * returns "normal", cachable memory.
74
- *
75
- * There are additional flags WEAK_ORDERING and WRITE_COMBINE to take
76
- * into consideration here, too. All current known implementations of
77
- * the OR1K support only strongly ordered memory accesses, so that flag
78
- * is being ignored for now; uncached but write-combined memory is a
79
- * missing feature of the OR1K.
80
- */
81
-void *
82
-arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
83
- gfp_t gfp, unsigned long attrs)
64
+static const struct mm_walk_ops clear_nocache_walk_ops = {
65
+ .pte_entry = page_clear_nocache,
66
+};
67
+
68
+void *arch_dma_set_uncached(void *cpu_addr, size_t size)
8469 {
85
- unsigned long va;
86
- void *page;
87
- struct mm_walk walk = {
88
- .pte_entry = page_set_nocache,
89
- .mm = &init_mm
90
- };
70
+ unsigned long va = (unsigned long)cpu_addr;
71
+ int error;
9172
92
- page = alloc_pages_exact(size, gfp);
93
- if (!page)
94
- return NULL;
73
+ /*
74
+ * We need to iterate through the pages, clearing the dcache for
75
+ * them and setting the cache-inhibit bit.
76
+ */
77
+ mmap_read_lock(&init_mm);
78
+ error = walk_page_range(&init_mm, va, va + size, &set_nocache_walk_ops,
79
+ NULL);
80
+ mmap_read_unlock(&init_mm);
9581
96
- /* This gives us the real physical address of the first page. */
97
- *dma_handle = __pa(page);
98
-
99
- va = (unsigned long)page;
100
-
101
- if ((attrs & DMA_ATTR_NON_CONSISTENT) == 0) {
102
- /*
103
- * We need to iterate through the pages, clearing the dcache for
104
- * them and setting the cache-inhibit bit.
105
- */
106
- if (walk_page_range(va, va + size, &walk)) {
107
- free_pages_exact(page, size);
108
- return NULL;
109
- }
110
- }
111
-
112
- return (void *)va;
82
+ if (error)
83
+ return ERR_PTR(error);
84
+ return cpu_addr;
11385 }
11486
115
-void
116
-arch_dma_free(struct device *dev, size_t size, void *vaddr,
117
- dma_addr_t dma_handle, unsigned long attrs)
87
+void arch_dma_clear_uncached(void *cpu_addr, size_t size)
11888 {
119
- unsigned long va = (unsigned long)vaddr;
120
- struct mm_walk walk = {
121
- .pte_entry = page_clear_nocache,
122
- .mm = &init_mm
123
- };
89
+ unsigned long va = (unsigned long)cpu_addr;
12490
125
- if ((attrs & DMA_ATTR_NON_CONSISTENT) == 0) {
126
- /* walk_page_range shouldn't be able to fail here */
127
- WARN_ON(walk_page_range(va, va + size, &walk));
128
- }
129
-
130
- free_pages_exact(vaddr, size);
91
+ mmap_read_lock(&init_mm);
92
+ /* walk_page_range shouldn't be able to fail here */
93
+ WARN_ON(walk_page_range(&init_mm, va, va + size,
94
+ &clear_nocache_walk_ops, NULL));
95
+ mmap_read_unlock(&init_mm);
13196 }
13297
133
-void arch_sync_dma_for_device(struct device *dev, phys_addr_t addr, size_t size,
98
+void arch_sync_dma_for_device(phys_addr_t addr, size_t size,
13499 enum dma_data_direction dir)
135100 {
136101 unsigned long cl;