Linux Audio

Check our new training course

Loading...
 1/* pci-dma.c: Dynamic DMA mapping support for the FRV CPUs that have MMUs
 2 *
 3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
 4 * Written by David Howells (dhowells@redhat.com)
 5 *
 6 * This program is free software; you can redistribute it and/or
 7 * modify it under the terms of the GNU General Public License
 8 * as published by the Free Software Foundation; either version
 9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/types.h>
13#include <linux/dma-mapping.h>
14#include <linux/list.h>
15#include <linux/pci.h>
16#include <linux/export.h>
17#include <linux/highmem.h>
18#include <linux/scatterlist.h>
19#include <asm/io.h>
20
21void *dma_alloc_coherent(struct device *hwdev, size_t size, dma_addr_t *dma_handle, gfp_t gfp)
22{
23	void *ret;
24
25	ret = consistent_alloc(gfp, size, dma_handle);
26	if (ret)
27		memset(ret, 0, size);
28
29	return ret;
30}
31
32EXPORT_SYMBOL(dma_alloc_coherent);
33
34void dma_free_coherent(struct device *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle)
35{
36	consistent_free(vaddr);
37}
38
39EXPORT_SYMBOL(dma_free_coherent);
40
41dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
42			  enum dma_data_direction direction)
43{
44	BUG_ON(direction == DMA_NONE);
45
46	frv_cache_wback_inv((unsigned long) ptr, (unsigned long) ptr + size);
47
48	return virt_to_bus(ptr);
49}
50
51EXPORT_SYMBOL(dma_map_single);
52
53int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
54	       enum dma_data_direction direction)
55{
56	unsigned long dampr2;
57	void *vaddr;
58	int i;
59
60	BUG_ON(direction == DMA_NONE);
61
62	dampr2 = __get_DAMPR(2);
63
64	for (i = 0; i < nents; i++) {
65		vaddr = kmap_atomic_primary(sg_page(&sg[i]), __KM_CACHE);
66
67		frv_dcache_writeback((unsigned long) vaddr,
68				     (unsigned long) vaddr + PAGE_SIZE);
69
70	}
71
72	kunmap_atomic_primary(vaddr, __KM_CACHE);
73	if (dampr2) {
74		__set_DAMPR(2, dampr2);
75		__set_IAMPR(2, dampr2);
76	}
77
78	return nents;
79}
80
81EXPORT_SYMBOL(dma_map_sg);
82
83dma_addr_t dma_map_page(struct device *dev, struct page *page, unsigned long offset,
84			size_t size, enum dma_data_direction direction)
85{
86	BUG_ON(direction == DMA_NONE);
87	flush_dcache_page(page);
88	return (dma_addr_t) page_to_phys(page) + offset;
89}
90
91EXPORT_SYMBOL(dma_map_page);