mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-20 10:50:01 +07:00
5299709d0a
Most dma_map_ops structures are never modified. Constify these structures such that these can be write-protected. This patch has been generated as follows: git grep -l 'struct dma_map_ops' | xargs -d\\n sed -i \ -e 's/struct dma_map_ops/const struct dma_map_ops/g' \ -e 's/const struct dma_map_ops {/struct dma_map_ops {/g' \ -e 's/^const struct dma_map_ops;$/struct dma_map_ops;/' \ -e 's/const const struct dma_map_ops /const struct dma_map_ops /g'; sed -i -e 's/const \(struct dma_map_ops intel_dma_ops\)/\1/' \ $(git grep -l 'struct dma_map_ops intel_dma_ops'); sed -i -e 's/const \(struct dma_map_ops dma_iommu_ops\)/\1/' \ $(git grep -l 'struct dma_map_ops' | grep ^arch/powerpc); sed -i -e '/^struct vmd_dev {$/,/^};$/ s/const \(struct dma_map_ops[[:blank:]]dma_ops;\)/\1/' \ -e '/^static void vmd_setup_dma_ops/,/^}$/ s/const \(struct dma_map_ops \*dest\)/\1/' \ -e 's/const \(struct dma_map_ops \*dest = \&vmd->dma_ops\)/\1/' \ drivers/pci/host/*.c sed -i -e '/^void __init pci_iommu_alloc(void)$/,/^}$/ s/dma_ops->/intel_dma_ops./' arch/ia64/kernel/pci-dma.c sed -i -e 's/static const struct dma_map_ops sn_dma_ops/static struct dma_map_ops sn_dma_ops/' arch/ia64/sn/pci/pci_dma.c sed -i -e 's/(const struct dma_map_ops \*)//' drivers/misc/mic/bus/vop_bus.c Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Juergen Gross <jgross@suse.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: linux-arch@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Russell King <linux@armlinux.org.uk> Cc: x86@kernel.org Signed-off-by: Doug Ledford <dledford@redhat.com>
150 lines
3.6 KiB
C
150 lines
3.6 KiB
C
/*
|
|
* Copyright (C) 2011 Texas Instruments Incorporated
|
|
* Author: Mark Salter <msalter@redhat.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*/
|
|
#include <linux/module.h>
|
|
#include <linux/dma-mapping.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/mm_types.h>
|
|
#include <linux/scatterlist.h>
|
|
|
|
#include <asm/cacheflush.h>
|
|
|
|
static void c6x_dma_sync(dma_addr_t handle, size_t size,
|
|
enum dma_data_direction dir)
|
|
{
|
|
unsigned long paddr = handle;
|
|
|
|
BUG_ON(!valid_dma_direction(dir));
|
|
|
|
switch (dir) {
|
|
case DMA_FROM_DEVICE:
|
|
L2_cache_block_invalidate(paddr, paddr + size);
|
|
break;
|
|
case DMA_TO_DEVICE:
|
|
L2_cache_block_writeback(paddr, paddr + size);
|
|
break;
|
|
case DMA_BIDIRECTIONAL:
|
|
L2_cache_block_writeback_invalidate(paddr, paddr + size);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
static dma_addr_t c6x_dma_map_page(struct device *dev, struct page *page,
|
|
unsigned long offset, size_t size, enum dma_data_direction dir,
|
|
unsigned long attrs)
|
|
{
|
|
dma_addr_t handle = virt_to_phys(page_address(page) + offset);
|
|
|
|
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
|
|
c6x_dma_sync(handle, size, dir);
|
|
|
|
return handle;
|
|
}
|
|
|
|
static void c6x_dma_unmap_page(struct device *dev, dma_addr_t handle,
|
|
size_t size, enum dma_data_direction dir, unsigned long attrs)
|
|
{
|
|
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
|
|
c6x_dma_sync(handle, size, dir);
|
|
}
|
|
|
|
static int c6x_dma_map_sg(struct device *dev, struct scatterlist *sglist,
|
|
int nents, enum dma_data_direction dir, unsigned long attrs)
|
|
{
|
|
struct scatterlist *sg;
|
|
int i;
|
|
|
|
for_each_sg(sglist, sg, nents, i) {
|
|
sg->dma_address = sg_phys(sg);
|
|
if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC))
|
|
c6x_dma_sync(sg->dma_address, sg->length, dir);
|
|
}
|
|
|
|
return nents;
|
|
}
|
|
|
|
static void c6x_dma_unmap_sg(struct device *dev, struct scatterlist *sglist,
|
|
int nents, enum dma_data_direction dir, unsigned long attrs)
|
|
{
|
|
struct scatterlist *sg;
|
|
int i;
|
|
|
|
if (attrs & DMA_ATTR_SKIP_CPU_SYNC)
|
|
return;
|
|
|
|
for_each_sg(sglist, sg, nents, i)
|
|
c6x_dma_sync(sg_dma_address(sg), sg->length, dir);
|
|
}
|
|
|
|
static void c6x_dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle,
|
|
size_t size, enum dma_data_direction dir)
|
|
{
|
|
c6x_dma_sync(handle, size, dir);
|
|
|
|
}
|
|
|
|
static void c6x_dma_sync_single_for_device(struct device *dev,
|
|
dma_addr_t handle, size_t size, enum dma_data_direction dir)
|
|
{
|
|
c6x_dma_sync(handle, size, dir);
|
|
|
|
}
|
|
|
|
static void c6x_dma_sync_sg_for_cpu(struct device *dev,
|
|
struct scatterlist *sglist, int nents,
|
|
enum dma_data_direction dir)
|
|
{
|
|
struct scatterlist *sg;
|
|
int i;
|
|
|
|
for_each_sg(sglist, sg, nents, i)
|
|
c6x_dma_sync_single_for_cpu(dev, sg_dma_address(sg),
|
|
sg->length, dir);
|
|
|
|
}
|
|
|
|
static void c6x_dma_sync_sg_for_device(struct device *dev,
|
|
struct scatterlist *sglist, int nents,
|
|
enum dma_data_direction dir)
|
|
{
|
|
struct scatterlist *sg;
|
|
int i;
|
|
|
|
for_each_sg(sglist, sg, nents, i)
|
|
c6x_dma_sync_single_for_device(dev, sg_dma_address(sg),
|
|
sg->length, dir);
|
|
|
|
}
|
|
|
|
const struct dma_map_ops c6x_dma_ops = {
|
|
.alloc = c6x_dma_alloc,
|
|
.free = c6x_dma_free,
|
|
.map_page = c6x_dma_map_page,
|
|
.unmap_page = c6x_dma_unmap_page,
|
|
.map_sg = c6x_dma_map_sg,
|
|
.unmap_sg = c6x_dma_unmap_sg,
|
|
.sync_single_for_device = c6x_dma_sync_single_for_device,
|
|
.sync_single_for_cpu = c6x_dma_sync_single_for_cpu,
|
|
.sync_sg_for_device = c6x_dma_sync_sg_for_device,
|
|
.sync_sg_for_cpu = c6x_dma_sync_sg_for_cpu,
|
|
};
|
|
EXPORT_SYMBOL(c6x_dma_ops);
|
|
|
|
/* Number of entries preallocated for DMA-API debugging */
|
|
#define PREALLOC_DMA_DEBUG_ENTRIES (1 << 16)
|
|
|
|
static int __init dma_init(void)
|
|
{
|
|
dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES);
|
|
|
|
return 0;
|
|
}
|
|
fs_initcall(dma_init);
|