mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-09-04 20:19:47 +08:00
- replaceme the force_dma flag with a dma_configure bus method.
(Nipun Gupta, although one patch is іncorrectly attributed to me
due to a git rebase bug)
- use GFP_DMA32 more agressively in dma-direct. (Takashi Iwai)
- remove PCI_DMA_BUS_IS_PHYS and rely on the dma-mapping API to do the
right thing for bounce buffering.
- move dma-debug initialization to common code, and apply a few cleanups
to the dma-debug code.
- cleanup the Kconfig mess around swiotlb selection
- swiotlb comment fixup (Yisheng Xie)
- a trivial swiotlb fix. (Dan Carpenter)
- support swiotlb on RISC-V. (based on a patch from Palmer Dabbelt)
- add a new generic dma-noncoherent dma_map_ops implementation and use
it for arc, c6x and nds32.
- improve scatterlist validity checking in dma-debug. (Robin Murphy)
- add a struct device quirk to limit the dma-mask to 32-bit due to
bridge/system issues, and switch x86 to use it instead of a local
hack for VIA bridges.
- handle devices without a dma_mask more gracefully in the dma-direct
code.
-----BEGIN PGP SIGNATURE-----
iQI/BAABCAApFiEEgdbnc3r/njty3Iq9D55TZVIEUYMFAlsU1hwLHGhjaEBsc3Qu
ZGUACgkQD55TZVIEUYPraxAAocC7JiFKW133/VugCtGA1x9uE8DPHealtsWTAeEq
KOOB3GxWMU2hKqQ4km5tcfdWoGJvvab6hmDXcitzZGi2JajO7Ae0FwIy3yvxSIKm
iH/ON7c4sJt8gKrXYsLVylmwDaimNs4a6xfODoCRgnWuovI2QrrZzupnlzPNsiOC
lv8ezzcW+Ay/gvDD/r72psO+w3QELETif/OzR/qTOtvLrVabM06eHmPQ8Wb98smu
/UPMMv6/3XwQnxpxpdyqN+p/gUdneXithzT261wTeZ+8gDXmcWBwHGcMBCimcoBi
FklW52moazIPIsTysqoNlVFsLGJTeS4p2D3BLAp5NwWYsLv+zHUVZsI1JY/8u5Ox
mM11LIfvu9JtUzaqD9SvxlxIeLhhYZZGnUoV3bQAkpHSQhN/xp2YXd5NWSo5ac2O
dch83+laZkZgd6ryw6USpt/YTPM/UHBYy7IeGGHX/PbmAke0ZlvA6Rae7kA5DG59
7GaLdwQyrHp8uGFgwze8P+R4POSk1ly73HHLBT/pFKnDD7niWCPAnBzuuEQGJs00
0zuyWLQyzOj1l6HCAcMNyGnYSsMp8Fx0fvEmKR/EYs8O83eJKXi6L9aizMZx4v1J
0wTolUWH6SIIdz474YmewhG5YOLY7mfe9E8aNr8zJFdwRZqwaALKoteRGUxa3f6e
zUE=
=6Acj
-----END PGP SIGNATURE-----
Merge tag 'dma-mapping-4.18' of git://git.infradead.org/users/hch/dma-mapping
Pull dma-mapping updates from Christoph Hellwig:
- replace the force_dma flag with a dma_configure bus method. (Nipun
Gupta, although one patch is іncorrectly attributed to me due to a
git rebase bug)
- use GFP_DMA32 more agressively in dma-direct. (Takashi Iwai)
- remove PCI_DMA_BUS_IS_PHYS and rely on the dma-mapping API to do the
right thing for bounce buffering.
- move dma-debug initialization to common code, and apply a few
cleanups to the dma-debug code.
- cleanup the Kconfig mess around swiotlb selection
- swiotlb comment fixup (Yisheng Xie)
- a trivial swiotlb fix. (Dan Carpenter)
- support swiotlb on RISC-V. (based on a patch from Palmer Dabbelt)
- add a new generic dma-noncoherent dma_map_ops implementation and use
it for arc, c6x and nds32.
- improve scatterlist validity checking in dma-debug. (Robin Murphy)
- add a struct device quirk to limit the dma-mask to 32-bit due to
bridge/system issues, and switch x86 to use it instead of a local
hack for VIA bridges.
- handle devices without a dma_mask more gracefully in the dma-direct
code.
* tag 'dma-mapping-4.18' of git://git.infradead.org/users/hch/dma-mapping: (48 commits)
dma-direct: don't crash on device without dma_mask
nds32: use generic dma_noncoherent_ops
nds32: implement the unmap_sg DMA operation
nds32: consolidate DMA cache maintainance routines
x86/pci-dma: switch the VIA 32-bit DMA quirk to use the struct device flag
x86/pci-dma: remove the explicit nodac and allowdac option
x86/pci-dma: remove the experimental forcesac boot option
Documentation/x86: remove a stray reference to pci-nommu.c
core, dma-direct: add a flag 32-bit dma limits
dma-mapping: remove unused gfp_t parameter to arch_dma_alloc_attrs
dma-debug: check scatterlist segments
c6x: use generic dma_noncoherent_ops
arc: use generic dma_noncoherent_ops
arc: fix arc_dma_{map,unmap}_page
arc: fix arc_dma_sync_sg_for_{cpu,device}
arc: simplify arc_dma_sync_single_for_{cpu,device}
dma-mapping: provide a generic dma-noncoherent implementation
dma-mapping: simplify Kconfig dependencies
riscv: add swiotlb support
riscv: only enable ZONE_DMA32 for 64-bit
...
156 lines
3.6 KiB
C
156 lines
3.6 KiB
C
/*
|
|
* arch/sh/mm/consistent.c
|
|
*
|
|
* Copyright (C) 2004 - 2007 Paul Mundt
|
|
*
|
|
* Declared coherent memory functions based on arch/x86/kernel/pci-dma_32.c
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
* for more details.
|
|
*/
|
|
#include <linux/mm.h>
|
|
#include <linux/init.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/dma-mapping.h>
|
|
#include <linux/dma-debug.h>
|
|
#include <linux/io.h>
|
|
#include <linux/module.h>
|
|
#include <linux/gfp.h>
|
|
#include <asm/cacheflush.h>
|
|
#include <asm/addrspace.h>
|
|
|
|
const struct dma_map_ops *dma_ops;
|
|
EXPORT_SYMBOL(dma_ops);
|
|
|
|
void *dma_generic_alloc_coherent(struct device *dev, size_t size,
|
|
dma_addr_t *dma_handle, gfp_t gfp,
|
|
unsigned long attrs)
|
|
{
|
|
void *ret, *ret_nocache;
|
|
int order = get_order(size);
|
|
|
|
gfp |= __GFP_ZERO;
|
|
|
|
ret = (void *)__get_free_pages(gfp, order);
|
|
if (!ret)
|
|
return NULL;
|
|
|
|
/*
|
|
* Pages from the page allocator may have data present in
|
|
* cache. So flush the cache before using uncached memory.
|
|
*/
|
|
sh_sync_dma_for_device(ret, size, DMA_BIDIRECTIONAL);
|
|
|
|
ret_nocache = (void __force *)ioremap_nocache(virt_to_phys(ret), size);
|
|
if (!ret_nocache) {
|
|
free_pages((unsigned long)ret, order);
|
|
return NULL;
|
|
}
|
|
|
|
split_page(pfn_to_page(virt_to_phys(ret) >> PAGE_SHIFT), order);
|
|
|
|
*dma_handle = virt_to_phys(ret);
|
|
if (!WARN_ON(!dev))
|
|
*dma_handle -= PFN_PHYS(dev->dma_pfn_offset);
|
|
|
|
return ret_nocache;
|
|
}
|
|
|
|
void dma_generic_free_coherent(struct device *dev, size_t size,
|
|
void *vaddr, dma_addr_t dma_handle,
|
|
unsigned long attrs)
|
|
{
|
|
int order = get_order(size);
|
|
unsigned long pfn = dma_handle >> PAGE_SHIFT;
|
|
int k;
|
|
|
|
if (!WARN_ON(!dev))
|
|
pfn += dev->dma_pfn_offset;
|
|
|
|
for (k = 0; k < (1 << order); k++)
|
|
__free_pages(pfn_to_page(pfn + k), 0);
|
|
|
|
iounmap(vaddr);
|
|
}
|
|
|
|
void sh_sync_dma_for_device(void *vaddr, size_t size,
|
|
enum dma_data_direction direction)
|
|
{
|
|
void *addr;
|
|
|
|
addr = __in_29bit_mode() ?
|
|
(void *)CAC_ADDR((unsigned long)vaddr) : vaddr;
|
|
|
|
switch (direction) {
|
|
case DMA_FROM_DEVICE: /* invalidate only */
|
|
__flush_invalidate_region(addr, size);
|
|
break;
|
|
case DMA_TO_DEVICE: /* writeback only */
|
|
__flush_wback_region(addr, size);
|
|
break;
|
|
case DMA_BIDIRECTIONAL: /* writeback and invalidate */
|
|
__flush_purge_region(addr, size);
|
|
break;
|
|
default:
|
|
BUG();
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(sh_sync_dma_for_device);
|
|
|
|
static int __init memchunk_setup(char *str)
|
|
{
|
|
return 1; /* accept anything that begins with "memchunk." */
|
|
}
|
|
__setup("memchunk.", memchunk_setup);
|
|
|
|
static void __init memchunk_cmdline_override(char *name, unsigned long *sizep)
|
|
{
|
|
char *p = boot_command_line;
|
|
int k = strlen(name);
|
|
|
|
while ((p = strstr(p, "memchunk."))) {
|
|
p += 9; /* strlen("memchunk.") */
|
|
if (!strncmp(name, p, k) && p[k] == '=') {
|
|
p += k + 1;
|
|
*sizep = memparse(p, NULL);
|
|
pr_info("%s: forcing memory chunk size to 0x%08lx\n",
|
|
name, *sizep);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
int __init platform_resource_setup_memory(struct platform_device *pdev,
|
|
char *name, unsigned long memsize)
|
|
{
|
|
struct resource *r;
|
|
dma_addr_t dma_handle;
|
|
void *buf;
|
|
|
|
r = pdev->resource + pdev->num_resources - 1;
|
|
if (r->flags) {
|
|
pr_warning("%s: unable to find empty space for resource\n",
|
|
name);
|
|
return -EINVAL;
|
|
}
|
|
|
|
memchunk_cmdline_override(name, &memsize);
|
|
if (!memsize)
|
|
return 0;
|
|
|
|
buf = dma_alloc_coherent(&pdev->dev, memsize, &dma_handle, GFP_KERNEL);
|
|
if (!buf) {
|
|
pr_warning("%s: unable to allocate memory\n", name);
|
|
return -ENOMEM;
|
|
}
|
|
|
|
memset(buf, 0, memsize);
|
|
|
|
r->flags = IORESOURCE_MEM;
|
|
r->start = dma_handle;
|
|
r->end = r->start + memsize - 1;
|
|
r->name = name;
|
|
return 0;
|
|
}
|