diff options
Diffstat (limited to 'arch/frv/mb93090-mb00/pci-dma.c')
-rw-r--r-- | arch/frv/mb93090-mb00/pci-dma.c | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/arch/frv/mb93090-mb00/pci-dma.c b/arch/frv/mb93090-mb00/pci-dma.c new file mode 100644 index 000000000000..27eb12066507 --- /dev/null +++ b/arch/frv/mb93090-mb00/pci-dma.c | |||
@@ -0,0 +1,105 @@ | |||
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/slab.h> | ||
14 | #include <linux/dma-mapping.h> | ||
15 | #include <linux/list.h> | ||
16 | #include <linux/pci.h> | ||
17 | #include <linux/highmem.h> | ||
18 | #include <asm/io.h> | ||
19 | |||
20 | void *dma_alloc_coherent(struct device *hwdev, size_t size, dma_addr_t *dma_handle, int gfp) | ||
21 | { | ||
22 | void *ret; | ||
23 | |||
24 | ret = consistent_alloc(gfp, size, dma_handle); | ||
25 | if (ret) | ||
26 | memset(ret, 0, size); | ||
27 | |||
28 | return ret; | ||
29 | } | ||
30 | |||
31 | void dma_free_coherent(struct device *hwdev, size_t size, void *vaddr, dma_addr_t dma_handle) | ||
32 | { | ||
33 | consistent_free(vaddr); | ||
34 | } | ||
35 | |||
36 | /* | ||
37 | * Map a single buffer of the indicated size for DMA in streaming mode. | ||
38 | * The 32-bit bus address to use is returned. | ||
39 | * | ||
40 | * Once the device is given the dma address, the device owns this memory | ||
41 | * until either pci_unmap_single or pci_dma_sync_single is performed. | ||
42 | */ | ||
43 | dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size, | ||
44 | enum dma_data_direction direction) | ||
45 | { | ||
46 | if (direction == DMA_NONE) | ||
47 | BUG(); | ||
48 | |||
49 | frv_cache_wback_inv((unsigned long) ptr, (unsigned long) ptr + size); | ||
50 | |||
51 | return virt_to_bus(ptr); | ||
52 | } | ||
53 | |||
54 | /* | ||
55 | * Map a set of buffers described by scatterlist in streaming | ||
56 | * mode for DMA. This is the scather-gather version of the | ||
57 | * above pci_map_single interface. Here the scatter gather list | ||
58 | * elements are each tagged with the appropriate dma address | ||
59 | * and length. They are obtained via sg_dma_{address,length}(SG). | ||
60 | * | ||
61 | * NOTE: An implementation may be able to use a smaller number of | ||
62 | * DMA address/length pairs than there are SG table elements. | ||
63 | * (for example via virtual mapping capabilities) | ||
64 | * The routine returns the number of addr/length pairs actually | ||
65 | * used, at most nents. | ||
66 | * | ||
67 | * Device ownership issues as mentioned above for pci_map_single are | ||
68 | * the same here. | ||
69 | */ | ||
70 | int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, | ||
71 | enum dma_data_direction direction) | ||
72 | { | ||
73 | unsigned long dampr2; | ||
74 | void *vaddr; | ||
75 | int i; | ||
76 | |||
77 | if (direction == DMA_NONE) | ||
78 | BUG(); | ||
79 | |||
80 | dampr2 = __get_DAMPR(2); | ||
81 | |||
82 | for (i = 0; i < nents; i++) { | ||
83 | vaddr = kmap_atomic(sg[i].page, __KM_CACHE); | ||
84 | |||
85 | frv_dcache_writeback((unsigned long) vaddr, | ||
86 | (unsigned long) vaddr + PAGE_SIZE); | ||
87 | |||
88 | } | ||
89 | |||
90 | kunmap_atomic(vaddr, __KM_CACHE); | ||
91 | if (dampr2) { | ||
92 | __set_DAMPR(2, dampr2); | ||
93 | __set_IAMPR(2, dampr2); | ||
94 | } | ||
95 | |||
96 | return nents; | ||
97 | } | ||
98 | |||
99 | dma_addr_t dma_map_page(struct device *dev, struct page *page, unsigned long offset, | ||
100 | size_t size, enum dma_data_direction direction) | ||
101 | { | ||
102 | BUG_ON(direction == DMA_NONE); | ||
103 | flush_dcache_page(page); | ||
104 | return (dma_addr_t) page_to_phys(page) + offset; | ||
105 | } | ||