Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
1da177e4 LT |
13 | #include <linux/dma-mapping.h> |
14 | #include <linux/list.h> | |
15 | #include <linux/pci.h> | |
9a78da11 | 16 | #include <linux/export.h> |
1da177e4 | 17 | #include <linux/highmem.h> |
9e6a76b8 | 18 | #include <linux/scatterlist.h> |
1da177e4 LT |
19 | #include <asm/io.h> |
20 | ||
eae07519 CH |
21 | static void *frv_dma_alloc(struct device *hwdev, size_t size, |
22 | dma_addr_t *dma_handle, gfp_t gfp, | |
23 | struct dma_attrs *attrs) | |
1da177e4 LT |
24 | { |
25 | void *ret; | |
26 | ||
27 | ret = consistent_alloc(gfp, size, dma_handle); | |
28 | if (ret) | |
29 | memset(ret, 0, size); | |
30 | ||
31 | return ret; | |
32 | } | |
33 | ||
eae07519 CH |
34 | static void frv_dma_free(struct device *hwdev, size_t size, void *vaddr, |
35 | dma_addr_t dma_handle, struct dma_attrs *attrs) | |
1da177e4 LT |
36 | { |
37 | consistent_free(vaddr); | |
38 | } | |
39 | ||
eae07519 CH |
40 | static int frv_dma_map_sg(struct device *dev, struct scatterlist *sglist, |
41 | int nents, enum dma_data_direction direction, | |
42 | struct dma_attrs *attrs) | |
1da177e4 LT |
43 | { |
44 | unsigned long dampr2; | |
45 | void *vaddr; | |
46 | int i; | |
0989e1f9 | 47 | struct scatterlist *sg; |
1da177e4 | 48 | |
db5c444e | 49 | BUG_ON(direction == DMA_NONE); |
1da177e4 LT |
50 | |
51 | dampr2 = __get_DAMPR(2); | |
52 | ||
0989e1f9 AM |
53 | for_each_sg(sglist, sg, nents, i) { |
54 | vaddr = kmap_atomic_primary(sg_page(sg)); | |
1da177e4 LT |
55 | |
56 | frv_dcache_writeback((unsigned long) vaddr, | |
57 | (unsigned long) vaddr + PAGE_SIZE); | |
58 | ||
59 | } | |
60 | ||
144cf864 | 61 | kunmap_atomic_primary(vaddr); |
1da177e4 LT |
62 | if (dampr2) { |
63 | __set_DAMPR(2, dampr2); | |
64 | __set_IAMPR(2, dampr2); | |
65 | } | |
66 | ||
67 | return nents; | |
68 | } | |
69 | ||
eae07519 CH |
70 | static dma_addr_t frv_dma_map_page(struct device *dev, struct page *page, |
71 | unsigned long offset, size_t size, | |
72 | enum dma_data_direction direction, struct dma_attrs *attrs) | |
1da177e4 | 73 | { |
1da177e4 LT |
74 | flush_dcache_page(page); |
75 | return (dma_addr_t) page_to_phys(page) + offset; | |
76 | } | |
40234401 | 77 | |
eae07519 CH |
78 | static void frv_dma_sync_single_for_device(struct device *dev, |
79 | dma_addr_t dma_handle, size_t size, | |
80 | enum dma_data_direction direction) | |
81 | { | |
82 | flush_write_buffers(); | |
83 | } | |
84 | ||
85 | static void frv_dma_sync_sg_for_device(struct device *dev, | |
86 | struct scatterlist *sg, int nelems, | |
87 | enum dma_data_direction direction) | |
88 | { | |
89 | flush_write_buffers(); | |
90 | } | |
91 | ||
92 | ||
93 | static int frv_dma_supported(struct device *dev, u64 mask) | |
94 | { | |
95 | /* | |
96 | * we fall back to GFP_DMA when the mask isn't all 1s, | |
97 | * so we can't guarantee allocations that must be | |
98 | * within a tighter range than GFP_DMA.. | |
99 | */ | |
100 | if (mask < 0x00ffffff) | |
101 | return 0; | |
102 | return 1; | |
103 | } | |
104 | ||
105 | struct dma_map_ops frv_dma_ops = { | |
106 | .alloc = frv_dma_alloc, | |
107 | .free = frv_dma_free, | |
108 | .map_page = frv_dma_map_page, | |
109 | .map_sg = frv_dma_map_sg, | |
110 | .sync_single_for_device = frv_dma_sync_single_for_device, | |
111 | .sync_sg_for_device = frv_dma_sync_sg_for_device, | |
112 | .dma_supported = frv_dma_supported, | |
113 | }; | |
114 | EXPORT_SYMBOL(frv_dma_ops); |