Commit | Line | Data |
---|---|---|
db59e1b6 JPB |
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> | |
6 | ||
bf2ee8d0 | 7 | void acpi_arch_dma_setup(struct device *dev) |
db59e1b6 JPB |
8 | { |
9 | int ret; | |
10 | u64 end, mask; | |
bf2ee8d0 | 11 | const struct bus_dma_region *map = NULL; |
db59e1b6 JPB |
12 | |
13 | /* | |
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. | |
18 | */ | |
19 | if (!dev->dma_mask) { | |
20 | dev_warn(dev, "DMA mask not set\n"); | |
21 | dev->dma_mask = &dev->coherent_dma_mask; | |
22 | } | |
23 | ||
24 | if (dev->coherent_dma_mask) | |
91cfd679 | 25 | end = dev->coherent_dma_mask; |
db59e1b6 | 26 | else |
91cfd679 | 27 | end = (1ULL << 32) - 1; |
db59e1b6 | 28 | |
bf2ee8d0 JL |
29 | ret = acpi_dma_get_range(dev, &map); |
30 | if (!ret && map) { | |
fece6530 | 31 | end = dma_range_map_max(map); |
bf2ee8d0 JL |
32 | dev->dma_range_map = map; |
33 | } | |
34 | ||
db59e1b6 | 35 | if (ret == -ENODEV) |
91cfd679 | 36 | ret = iort_dma_get_ranges(dev, &end); |
db59e1b6 JPB |
37 | if (!ret) { |
38 | /* | |
39 | * Limit coherent and dma mask based on size retrieved from | |
40 | * firmware. | |
41 | */ | |
db59e1b6 JPB |
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); | |
46 | } | |
db59e1b6 | 47 | } |