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
)
11 const struct bus_dma_region
*map
= NULL
;
14 * If @dev is expected to be DMA-capable then the bus code that created
15 * it should have initialised its dma_mask pointer by this point. For
16 * now, we'll continue the legacy behaviour of coercing it to the
17 * coherent mask if not, but we'll no longer do so quietly.
20 dev_warn(dev
, "DMA mask not set\n");
21 dev
->dma_mask
= &dev
->coherent_dma_mask
;
24 if (dev
->coherent_dma_mask
)
25 end
= dev
->coherent_dma_mask
;
27 end
= (1ULL << 32) - 1;
29 ret
= acpi_dma_get_range(dev
, &map
);
31 end
= dma_range_map_max(map
);
32 dev
->dma_range_map
= map
;
36 ret
= iort_dma_get_ranges(dev
, &end
);
39 * Limit coherent and dma mask based on size retrieved from
42 mask
= DMA_BIT_MASK(ilog2(end
) + 1);
43 dev
->bus_dma_limit
= end
;
44 dev
->coherent_dma_mask
= min(dev
->coherent_dma_mask
, mask
);
45 *dev
->dma_mask
= min(*dev
->dma_mask
, mask
);