| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Port on Texas Instruments TMS320C6x architecture |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated |
|---|
| 5 | 6 | * Author: Aurelien Jacquiot <aurelien.jacquiot@ti.com> |
|---|
| 6 | 7 | * |
|---|
| 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 | | - * |
|---|
| 11 | 8 | * DMA uncached mapping support. |
|---|
| 12 | 9 | * |
|---|
| 13 | 10 | * Using code pulled from ARM |
|---|
| 14 | 11 | * Copyright (C) 2000-2004 Russell King |
|---|
| 15 | | - * |
|---|
| 16 | 12 | */ |
|---|
| 17 | 13 | #include <linux/slab.h> |
|---|
| 18 | 14 | #include <linux/bitmap.h> |
|---|
| 19 | 15 | #include <linux/bitops.h> |
|---|
| 20 | 16 | #include <linux/module.h> |
|---|
| 21 | 17 | #include <linux/interrupt.h> |
|---|
| 22 | | -#include <linux/dma-noncoherent.h> |
|---|
| 18 | +#include <linux/dma-map-ops.h> |
|---|
| 23 | 19 | #include <linux/memblock.h> |
|---|
| 24 | 20 | |
|---|
| 25 | 21 | #include <asm/cacheflush.h> |
|---|
| .. | .. |
|---|
| 78 | 74 | void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, |
|---|
| 79 | 75 | gfp_t gfp, unsigned long attrs) |
|---|
| 80 | 76 | { |
|---|
| 77 | + void *ret; |
|---|
| 81 | 78 | u32 paddr; |
|---|
| 82 | 79 | int order; |
|---|
| 83 | 80 | |
|---|
| .. | .. |
|---|
| 94 | 91 | if (!paddr) |
|---|
| 95 | 92 | return NULL; |
|---|
| 96 | 93 | |
|---|
| 97 | | - return phys_to_virt(paddr); |
|---|
| 94 | + ret = phys_to_virt(paddr); |
|---|
| 95 | + memset(ret, 0, 1 << order); |
|---|
| 96 | + return ret; |
|---|
| 98 | 97 | } |
|---|
| 99 | 98 | |
|---|
| 100 | 99 | /* |
|---|
| .. | .. |
|---|
| 118 | 117 | */ |
|---|
| 119 | 118 | void __init coherent_mem_init(phys_addr_t start, u32 size) |
|---|
| 120 | 119 | { |
|---|
| 121 | | - phys_addr_t bitmap_phys; |
|---|
| 122 | | - |
|---|
| 123 | 120 | if (!size) |
|---|
| 124 | 121 | return; |
|---|
| 125 | 122 | |
|---|
| .. | .. |
|---|
| 135 | 132 | if (dma_size & (PAGE_SIZE - 1)) |
|---|
| 136 | 133 | ++dma_pages; |
|---|
| 137 | 134 | |
|---|
| 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)); |
|---|
| 143 | 141 | } |
|---|
| 144 | 142 | |
|---|
| 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, |
|---|
| 146 | 144 | enum dma_data_direction dir) |
|---|
| 147 | 145 | { |
|---|
| 148 | 146 | BUG_ON(!valid_dma_direction(dir)); |
|---|
| .. | .. |
|---|
| 162 | 160 | } |
|---|
| 163 | 161 | } |
|---|
| 164 | 162 | |
|---|
| 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) |
|---|
| 167 | 165 | { |
|---|
| 168 | | - return c6x_dma_sync(dev, paddr, size, dir); |
|---|
| 166 | + return c6x_dma_sync(paddr, size, dir); |
|---|
| 169 | 167 | } |
|---|
| 170 | 168 | |
|---|
| 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) |
|---|
| 173 | 171 | { |
|---|
| 174 | | - return c6x_dma_sync(dev, paddr, size, dir); |
|---|
| 172 | + return c6x_dma_sync(paddr, size, dir); |
|---|
| 175 | 173 | } |
|---|