]> git.ipfire.org Git - thirdparty/kernel/linux.git/blame - arch/cris/arch-v32/drivers/pci/dma.c
License cleanup: add SPDX GPL-2.0 license identifier to files with no license
[thirdparty/kernel/linux.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 /* ignore region specifiers */
26 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
27
51533b61
MS
28 if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
29 gfp |= GFP_DMA;
30
e20dd889 31 ret = (void *)__get_free_pages(gfp, get_order(size));
51533b61
MS
32
33 if (ret != NULL) {
34 memset(ret, 0, size);
35 *dma_handle = virt_to_phys(ret);
36 }
37 return ret;
38}
39
e20dd889 40static void v32_dma_free(struct device *dev, size_t size, void *vaddr,
00085f1e 41 dma_addr_t dma_handle, unsigned long attrs)
e20dd889
CH
42{
43 free_pages((unsigned long)vaddr, get_order(size));
44}
45
46static inline dma_addr_t v32_dma_map_page(struct device *dev,
47 struct page *page, unsigned long offset, size_t size,
00085f1e 48 enum dma_data_direction direction, unsigned long attrs)
51533b61 49{
e20dd889
CH
50 return page_to_phys(page) + offset;
51}
51533b61 52
e20dd889
CH
53static inline int v32_dma_map_sg(struct device *dev, struct scatterlist *sg,
54 int nents, enum dma_data_direction direction,
00085f1e 55 unsigned long attrs)
e20dd889
CH
56{
57 printk("Map sg\n");
58 return nents;
59}
60
61static inline int v32_dma_supported(struct device *dev, u64 mask)
62{
63 /*
64 * we fall back to GFP_DMA when the mask isn't all 1s,
65 * so we can't guarantee allocations that must be
66 * within a tighter range than GFP_DMA..
67 */
68 if (mask < 0x00ffffff)
69 return 0;
70 return 1;
51533b61
MS
71}
72
5299709d 73const struct dma_map_ops v32_dma_ops = {
e20dd889
CH
74 .alloc = v32_dma_alloc,
75 .free = v32_dma_free,
76 .map_page = v32_dma_map_page,
77 .map_sg = v32_dma_map_sg,
78 .dma_supported = v32_dma_supported,
79};
80EXPORT_SYMBOL(v32_dma_ops);