xref: /linux/arch/loongarch/kernel/dma.c (revision 46ff24efe04ac96a129dd01138640c3447a525e1)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4  */
5 #include <linux/acpi.h>
6 #include <linux/dma-direct.h>
7 
8 void acpi_arch_dma_setup(struct device *dev)
9 {
10 	int ret;
11 	u64 mask, end = 0;
12 	const struct bus_dma_region *map = NULL;
13 
14 	ret = acpi_dma_get_range(dev, &map);
15 	if (!ret && map) {
16 		const struct bus_dma_region *r = map;
17 
18 		for (end = 0; r->size; r++) {
19 			if (r->dma_start + r->size - 1 > end)
20 				end = r->dma_start + r->size - 1;
21 		}
22 
23 		mask = DMA_BIT_MASK(ilog2(end) + 1);
24 		dev->bus_dma_limit = end;
25 		dev->dma_range_map = map;
26 		dev->coherent_dma_mask = min(dev->coherent_dma_mask, mask);
27 		*dev->dma_mask = min(*dev->dma_mask, mask);
28 	}
29 
30 }
31