hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/arch/c6x/mm/dma-coherent.c
....@@ -1,25 +1,21 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Port on Texas Instruments TMS320C6x architecture
34 *
45 * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
56 * Author: Aurelien Jacquiot <aurelien.jacquiot@ti.com>
67 *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
10
- *
118 * DMA uncached mapping support.
129 *
1310 * Using code pulled from ARM
1411 * Copyright (C) 2000-2004 Russell King
15
- *
1612 */
1713 #include <linux/slab.h>
1814 #include <linux/bitmap.h>
1915 #include <linux/bitops.h>
2016 #include <linux/module.h>
2117 #include <linux/interrupt.h>
22
-#include <linux/dma-noncoherent.h>
18
+#include <linux/dma-map-ops.h>
2319 #include <linux/memblock.h>
2420
2521 #include <asm/cacheflush.h>
....@@ -78,6 +74,7 @@
7874 void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
7975 gfp_t gfp, unsigned long attrs)
8076 {
77
+ void *ret;
8178 u32 paddr;
8279 int order;
8380
....@@ -94,7 +91,9 @@
9491 if (!paddr)
9592 return NULL;
9693
97
- return phys_to_virt(paddr);
94
+ ret = phys_to_virt(paddr);
95
+ memset(ret, 0, 1 << order);
96
+ return ret;
9897 }
9998
10099 /*
....@@ -118,8 +117,6 @@
118117 */
119118 void __init coherent_mem_init(phys_addr_t start, u32 size)
120119 {
121
- phys_addr_t bitmap_phys;
122
-
123120 if (!size)
124121 return;
125122
....@@ -135,14 +132,15 @@
135132 if (dma_size & (PAGE_SIZE - 1))
136133 ++dma_pages;
137134
138
- bitmap_phys = memblock_alloc(BITS_TO_LONGS(dma_pages) * sizeof(long),
139
- sizeof(long));
140
-
141
- dma_bitmap = phys_to_virt(bitmap_phys);
142
- memset(dma_bitmap, 0, dma_pages * PAGE_SIZE);
135
+ dma_bitmap = memblock_alloc(BITS_TO_LONGS(dma_pages) * sizeof(long),
136
+ sizeof(long));
137
+ if (!dma_bitmap)
138
+ panic("%s: Failed to allocate %zu bytes align=0x%zx\n",
139
+ __func__, BITS_TO_LONGS(dma_pages) * sizeof(long),
140
+ sizeof(long));
143141 }
144142
145
-static void c6x_dma_sync(struct device *dev, phys_addr_t paddr, size_t size,
143
+static void c6x_dma_sync(phys_addr_t paddr, size_t size,
146144 enum dma_data_direction dir)
147145 {
148146 BUG_ON(!valid_dma_direction(dir));
....@@ -162,14 +160,14 @@
162160 }
163161 }
164162
165
-void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr,
166
- size_t size, enum dma_data_direction dir)
163
+void arch_sync_dma_for_device(phys_addr_t paddr, size_t size,
164
+ enum dma_data_direction dir)
167165 {
168
- return c6x_dma_sync(dev, paddr, size, dir);
166
+ return c6x_dma_sync(paddr, size, dir);
169167 }
170168
171
-void arch_sync_dma_for_cpu(struct device *dev, phys_addr_t paddr,
172
- size_t size, enum dma_data_direction dir)
169
+void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size,
170
+ enum dma_data_direction dir)
173171 {
174
- return c6x_dma_sync(dev, paddr, size, dir);
172
+ return c6x_dma_sync(paddr, size, dir);
175173 }