1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/acpi.h>
3 #include <linux/acpi_iort.h>
4 #include <linux/device.h>
5 #include <linux/dma-direct.h>
7 void acpi_arch_dma_setup(struct device *dev)
12 const struct bus_dma_region *map = NULL;
15 * If @dev is expected to be DMA-capable then the bus code that created
16 * it should have initialised its dma_mask pointer by this point. For
17 * now, we'll continue the legacy behaviour of coercing it to the
18 * coherent mask if not, but we'll no longer do so quietly.
21 dev_warn(dev, "DMA mask not set\n");
22 dev->dma_mask = &dev->coherent_dma_mask;
25 if (dev->coherent_dma_mask)
26 size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1);
30 ret = acpi_dma_get_range(dev, &map);
32 const struct bus_dma_region *r = map;
34 for (end = 0; r->size; r++) {
35 if (r->dma_start + r->size - 1 > end)
36 end = r->dma_start + r->size - 1;
40 dev->dma_range_map = map;
44 ret = iort_dma_get_ranges(dev, &size);
47 * Limit coherent and dma mask based on size retrieved from
51 mask = DMA_BIT_MASK(ilog2(end) + 1);
52 dev->bus_dma_limit = end;
53 dev->coherent_dma_mask = min(dev->coherent_dma_mask, mask);
54 *dev->dma_mask = min(*dev->dma_mask, mask);