ACPI: scan: Support multiple DMA windows with different offsets
In DT systems configurations, of_dma_get_range() returns struct bus_dma_region DMA regions; they are used to set-up devices DMA windows with different offset available for translation between DMA address and CPU address. In ACPI systems configuration, acpi_dma_get_range() does not return DMA regions yet and that precludes setting up the dev->dma_range_map pointer and therefore DMA regions with multiple offsets. Update acpi_dma_get_range() to return struct bus_dma_region DMA regions like of_dma_get_range() does. After updating acpi_dma_get_range(), acpi_arch_dma_setup() is changed for ARM64, where the original dma_addr and size are removed as these arguments are now redundant, and pass 0 and U64_MAX for dma_base and size of arch_setup_dma_ops; this is a simplification consistent with what other ACPI architectures also pass to iommu_setup_dma_ops(). Reviewed-by: Robin Murphy <robin.murphy@arm.com> Signed-off-by: Jianmin Lv <lvjianmin@loongson.cn> Reviewed-by: Lorenzo Pieralisi <lpieralisi@kernel.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
parent
521a547ced
commit
bf2ee8d0c3
@ -4,11 +4,12 @@
|
|||||||
#include <linux/device.h>
|
#include <linux/device.h>
|
||||||
#include <linux/dma-direct.h>
|
#include <linux/dma-direct.h>
|
||||||
|
|
||||||
void acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size)
|
void acpi_arch_dma_setup(struct device *dev)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
u64 end, mask;
|
u64 end, mask;
|
||||||
u64 dmaaddr = 0, size = 0, offset = 0;
|
u64 size = 0;
|
||||||
|
const struct bus_dma_region *map = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If @dev is expected to be DMA-capable then the bus code that created
|
* If @dev is expected to be DMA-capable then the bus code that created
|
||||||
@ -26,7 +27,19 @@ void acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size)
|
|||||||
else
|
else
|
||||||
size = 1ULL << 32;
|
size = 1ULL << 32;
|
||||||
|
|
||||||
ret = acpi_dma_get_range(dev, &dmaaddr, &offset, &size);
|
ret = acpi_dma_get_range(dev, &map);
|
||||||
|
if (!ret && map) {
|
||||||
|
const struct bus_dma_region *r = map;
|
||||||
|
|
||||||
|
for (end = 0; r->size; r++) {
|
||||||
|
if (r->dma_start + r->size - 1 > end)
|
||||||
|
end = r->dma_start + r->size - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
size = end + 1;
|
||||||
|
dev->dma_range_map = map;
|
||||||
|
}
|
||||||
|
|
||||||
if (ret == -ENODEV)
|
if (ret == -ENODEV)
|
||||||
ret = iort_dma_get_ranges(dev, &size);
|
ret = iort_dma_get_ranges(dev, &size);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
@ -34,17 +47,10 @@ void acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size)
|
|||||||
* Limit coherent and dma mask based on size retrieved from
|
* Limit coherent and dma mask based on size retrieved from
|
||||||
* firmware.
|
* firmware.
|
||||||
*/
|
*/
|
||||||
end = dmaaddr + size - 1;
|
end = size - 1;
|
||||||
mask = DMA_BIT_MASK(ilog2(end) + 1);
|
mask = DMA_BIT_MASK(ilog2(end) + 1);
|
||||||
dev->bus_dma_limit = end;
|
dev->bus_dma_limit = end;
|
||||||
dev->coherent_dma_mask = min(dev->coherent_dma_mask, mask);
|
dev->coherent_dma_mask = min(dev->coherent_dma_mask, mask);
|
||||||
*dev->dma_mask = min(*dev->dma_mask, mask);
|
*dev->dma_mask = min(*dev->dma_mask, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
*dma_addr = dmaaddr;
|
|
||||||
*dma_size = size;
|
|
||||||
|
|
||||||
ret = dma_direct_set_offset(dev, dmaaddr + offset, dmaaddr, size);
|
|
||||||
|
|
||||||
dev_dbg(dev, "dma_offset(%#08llx)%s\n", offset, ret ? " failed!" : "");
|
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include <linux/platform_data/x86/apple.h>
|
#include <linux/platform_data/x86/apple.h>
|
||||||
#include <linux/pgtable.h>
|
#include <linux/pgtable.h>
|
||||||
#include <linux/crc32.h>
|
#include <linux/crc32.h>
|
||||||
|
#include <linux/dma-direct.h>
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
@ -1467,25 +1468,21 @@ enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev)
|
|||||||
* acpi_dma_get_range() - Get device DMA parameters.
|
* acpi_dma_get_range() - Get device DMA parameters.
|
||||||
*
|
*
|
||||||
* @dev: device to configure
|
* @dev: device to configure
|
||||||
* @dma_addr: pointer device DMA address result
|
* @map: pointer to DMA ranges result
|
||||||
* @offset: pointer to the DMA offset result
|
|
||||||
* @size: pointer to DMA range size result
|
|
||||||
*
|
*
|
||||||
* Evaluate DMA regions and return respectively DMA region start, offset
|
* Evaluate DMA regions and return pointer to DMA regions on
|
||||||
* and size in dma_addr, offset and size on parsing success; it does not
|
* parsing success; it does not update the passed in values on failure.
|
||||||
* update the passed in values on failure.
|
|
||||||
*
|
*
|
||||||
* Return 0 on success, < 0 on failure.
|
* Return 0 on success, < 0 on failure.
|
||||||
*/
|
*/
|
||||||
int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
|
int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
|
||||||
u64 *size)
|
|
||||||
{
|
{
|
||||||
struct acpi_device *adev;
|
struct acpi_device *adev;
|
||||||
LIST_HEAD(list);
|
LIST_HEAD(list);
|
||||||
struct resource_entry *rentry;
|
struct resource_entry *rentry;
|
||||||
int ret;
|
int ret;
|
||||||
struct device *dma_dev = dev;
|
struct device *dma_dev = dev;
|
||||||
u64 len, dma_start = U64_MAX, dma_end = 0, dma_offset = 0;
|
struct bus_dma_region *r;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Walk the device tree chasing an ACPI companion with a _DMA
|
* Walk the device tree chasing an ACPI companion with a _DMA
|
||||||
@ -1510,31 +1507,28 @@ int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
|
|||||||
|
|
||||||
ret = acpi_dev_get_dma_resources(adev, &list);
|
ret = acpi_dev_get_dma_resources(adev, &list);
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
list_for_each_entry(rentry, &list, node) {
|
r = kcalloc(ret + 1, sizeof(*r), GFP_KERNEL);
|
||||||
if (dma_offset && rentry->offset != dma_offset) {
|
if (!r) {
|
||||||
ret = -EINVAL;
|
ret = -ENOMEM;
|
||||||
dev_warn(dma_dev, "Can't handle multiple windows with different offsets\n");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
dma_offset = rentry->offset;
|
|
||||||
|
|
||||||
/* Take lower and upper limits */
|
|
||||||
if (rentry->res->start < dma_start)
|
|
||||||
dma_start = rentry->res->start;
|
|
||||||
if (rentry->res->end > dma_end)
|
|
||||||
dma_end = rentry->res->end;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dma_start >= dma_end) {
|
|
||||||
ret = -EINVAL;
|
|
||||||
dev_dbg(dma_dev, "Invalid DMA regions configuration\n");
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
*dma_addr = dma_start - dma_offset;
|
list_for_each_entry(rentry, &list, node) {
|
||||||
len = dma_end - dma_start;
|
if (rentry->res->start >= rentry->res->end) {
|
||||||
*size = max(len, len + 1);
|
kfree(r);
|
||||||
*offset = dma_offset;
|
ret = -EINVAL;
|
||||||
|
dev_dbg(dma_dev, "Invalid DMA regions configuration\n");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
r->cpu_start = rentry->res->start;
|
||||||
|
r->dma_start = rentry->res->start - rentry->offset;
|
||||||
|
r->size = resource_size(rentry->res);
|
||||||
|
r->offset = rentry->offset;
|
||||||
|
r++;
|
||||||
|
}
|
||||||
|
|
||||||
|
*map = r;
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
acpi_dev_free_resource_list(&list);
|
acpi_dev_free_resource_list(&list);
|
||||||
@ -1624,20 +1618,19 @@ int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
|
|||||||
const u32 *input_id)
|
const u32 *input_id)
|
||||||
{
|
{
|
||||||
const struct iommu_ops *iommu;
|
const struct iommu_ops *iommu;
|
||||||
u64 dma_addr = 0, size = 0;
|
|
||||||
|
|
||||||
if (attr == DEV_DMA_NOT_SUPPORTED) {
|
if (attr == DEV_DMA_NOT_SUPPORTED) {
|
||||||
set_dma_ops(dev, &dma_dummy_ops);
|
set_dma_ops(dev, &dma_dummy_ops);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
acpi_arch_dma_setup(dev, &dma_addr, &size);
|
acpi_arch_dma_setup(dev);
|
||||||
|
|
||||||
iommu = acpi_iommu_configure_id(dev, input_id);
|
iommu = acpi_iommu_configure_id(dev, input_id);
|
||||||
if (PTR_ERR(iommu) == -EPROBE_DEFER)
|
if (PTR_ERR(iommu) == -EPROBE_DEFER)
|
||||||
return -EPROBE_DEFER;
|
return -EPROBE_DEFER;
|
||||||
|
|
||||||
arch_setup_dma_ops(dev, dma_addr, size,
|
arch_setup_dma_ops(dev, 0, U64_MAX,
|
||||||
iommu, attr == DEV_DMA_COHERENT);
|
iommu, attr == DEV_DMA_COHERENT);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -613,8 +613,7 @@ enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev);
|
|||||||
int acpi_iommu_fwspec_init(struct device *dev, u32 id,
|
int acpi_iommu_fwspec_init(struct device *dev, u32 id,
|
||||||
struct fwnode_handle *fwnode,
|
struct fwnode_handle *fwnode,
|
||||||
const struct iommu_ops *ops);
|
const struct iommu_ops *ops);
|
||||||
int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
|
int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map);
|
||||||
u64 *size);
|
|
||||||
int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
|
int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
|
||||||
const u32 *input_id);
|
const u32 *input_id);
|
||||||
static inline int acpi_dma_configure(struct device *dev,
|
static inline int acpi_dma_configure(struct device *dev,
|
||||||
|
@ -281,12 +281,12 @@ void acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa);
|
|||||||
|
|
||||||
#ifdef CONFIG_ARM64
|
#ifdef CONFIG_ARM64
|
||||||
void acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa);
|
void acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa);
|
||||||
void acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size);
|
void acpi_arch_dma_setup(struct device *dev);
|
||||||
#else
|
#else
|
||||||
static inline void
|
static inline void
|
||||||
acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }
|
acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }
|
||||||
static inline void
|
static inline void
|
||||||
acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size) { }
|
acpi_arch_dma_setup(struct device *dev) { }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
|
int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
|
||||||
@ -977,8 +977,7 @@ static inline enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev)
|
|||||||
return DEV_DMA_NOT_SUPPORTED;
|
return DEV_DMA_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int acpi_dma_get_range(struct device *dev, u64 *dma_addr,
|
static inline int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
|
||||||
u64 *offset, u64 *size)
|
|
||||||
{
|
{
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user