1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * This file is subject to the terms and conditions of the GNU General Public 4 * License. See the file "COPYING" in the main directory of this archive 5 * for more details. 6 * 7 * Copyright (C) 2020 Loongson Technology Corporation Limited 8 * 9 */ 10 #include <linux/acpi.h> 11 #include <linux/dma-direct.h> 12 acpi_arch_dma_setup(struct device *dev)13void acpi_arch_dma_setup(struct device *dev) 14 { 15 int ret; 16 u64 mask, end = 0; 17 const struct bus_dma_region *map = NULL; 18 19 ret = acpi_dma_get_range(dev, &map); 20 if (!ret && map) { 21 const struct bus_dma_region *r = map; 22 23 for (end = 0; r->size; r++) { 24 if (r->dma_start + r->size - 1 > end) 25 end = r->dma_start + r->size - 1; 26 } 27 28 mask = DMA_BIT_MASK(ilog2(end) + 1); 29 dev->bus_dma_limit = end; 30 dev->dma_range_map = map; 31 dev->coherent_dma_mask = min(dev->coherent_dma_mask, mask); 32 *dev->dma_mask = min(*dev->dma_mask, mask); 33 } 34 35 } 36