dma-mapping: clear harmful GFP_* flags in common code
[linux-2.6-block.git] / arch / cris / arch-v32 / drivers / pci / dma.c
CommitLineData
b2441318 1// SPDX-License-Identifier: GPL-2.0
51533b61
MS
2/*
3 * Dynamic DMA mapping support.
4 *
5 * On cris there is no hardware dynamic DMA address translation,
6 * so consistent alloc/free are merely page allocation/freeing.
7 * The rest of the dynamic DMA mapping interface is implemented
8 * in asm/pci.h.
9 *
10 * Borrowed from i386.
11 */
12
13#include <linux/types.h>
14#include <linux/mm.h>
15#include <linux/string.h>
16#include <linux/pci.h>
5a0e3ad6 17#include <linux/gfp.h>
51533b61
MS
18#include <asm/io.h>
19
e20dd889 20static void *v32_dma_alloc(struct device *dev, size_t size,
00085f1e 21 dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs)
51533b61
MS
22{
23 void *ret;
e20dd889 24
51533b61
MS
25 if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
26 gfp |= GFP_DMA;
27
e20dd889 28 ret = (void *)__get_free_pages(gfp, get_order(size));
51533b61
MS
29
30 if (ret != NULL) {
31 memset(ret, 0, size);
32 *dma_handle = virt_to_phys(ret);
33 }
34 return ret;
35}
36
e20dd889 37static void v32_dma_free(struct device *dev, size_t size, void *vaddr,
00085f1e 38 dma_addr_t dma_handle, unsigned long attrs)
e20dd889
CH
39{
40 free_pages((unsigned long)vaddr, get_order(size));
41}
42
43static inline dma_addr_t v32_dma_map_page(struct device *dev,
44 struct page *page, unsigned long offset, size_t size,
00085f1e 45 enum dma_data_direction direction, unsigned long attrs)
51533b61 46{
e20dd889
CH
47 return page_to_phys(page) + offset;
48}
51533b61 49
e20dd889
CH
50static inline int v32_dma_map_sg(struct device *dev, struct scatterlist *sg,
51 int nents, enum dma_data_direction direction,
00085f1e 52 unsigned long attrs)
e20dd889
CH
53{
54 printk("Map sg\n");
55 return nents;
56}
57
58static inline int v32_dma_supported(struct device *dev, u64 mask)
59{
60 /*
61 * we fall back to GFP_DMA when the mask isn't all 1s,
62 * so we can't guarantee allocations that must be
63 * within a tighter range than GFP_DMA..
64 */
65 if (mask < 0x00ffffff)
66 return 0;
67 return 1;
51533b61
MS
68}
69
5299709d 70const struct dma_map_ops v32_dma_ops = {
e20dd889
CH
71 .alloc = v32_dma_alloc,
72 .free = v32_dma_free,
73 .map_page = v32_dma_map_page,
74 .map_sg = v32_dma_map_sg,
75 .dma_supported = v32_dma_supported,
76};
77EXPORT_SYMBOL(v32_dma_ops);