* [PATCH V3 0/2] DMA: update acpi_dma_get_range to return dma map regions
@ 2022-08-30 3:01 Jianmin Lv
2022-08-30 3:01 ` [PATCH V3 1/2] ACPI / scan: Support multiple dma windows with different offsets Jianmin Lv
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Jianmin Lv @ 2022-08-30 3:01 UTC (permalink / raw)
To: lpieralisi, robin.murphy, chenhuacai
Cc: guohanjun, sudeep.holla, rafael, lenb, robert.moore,
linux-kernel, linux-acpi, loongarch
The patch series changed acpi_dma_get_range to return dma regions
as of_dma_get_range, so that dev->dma_range_map can be initialized
conveniently.
And acpi_arch_dma_setup for ARM64 is changed wih removing dma_base
and size from it's parameters.
Remove ARCH_HAS_PHYS_TO_DMA for LoongArch and use generic
phys_to_dma/dma_to_phys in include/linux/dma-direct.h.
V1 -> V2
- Removed dma_base and size from acpi_arch_dma_setup' parameters
- Add patch to remove ARCH_HAS_PHYS_TO_DMA for LoongArch
V2 -> V3
- Add kerneldoc for acpi_dma_get_range changing
- Remove redundant code in acpi_arch_dma_setup, and check map
Jianmin Lv (2):
ACPI / scan: Support multiple dma windows with different offsets
LoongArch: Remove ARCH_HAS_PHYS_TO_DMA
arch/loongarch/Kconfig | 1 -
arch/loongarch/kernel/dma.c | 52 +++++++++++++++++-------------------------
arch/loongarch/kernel/setup.c | 2 +-
drivers/acpi/arm64/dma.c | 29 ++++++++++++++---------
drivers/acpi/scan.c | 53 +++++++++++++++++++------------------------
include/acpi/acpi_bus.h | 3 +--
include/linux/acpi.h | 12 ++++++----
7 files changed, 71 insertions(+), 81 deletions(-)
--
1.8.3.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH V3 1/2] ACPI / scan: Support multiple dma windows with different offsets
2022-08-30 3:01 [PATCH V3 0/2] DMA: update acpi_dma_get_range to return dma map regions Jianmin Lv
@ 2022-08-30 3:01 ` Jianmin Lv
2022-09-05 12:20 ` Robin Murphy
2022-08-30 3:01 ` [PATCH V3 2/2] LoongArch: Remove ARCH_HAS_PHYS_TO_DMA Jianmin Lv
2022-09-05 2:55 ` [PATCH V3 0/2] DMA: update acpi_dma_get_range to return dma map regions Jianmin Lv
2 siblings, 1 reply; 10+ messages in thread
From: Jianmin Lv @ 2022-08-30 3:01 UTC (permalink / raw)
To: lpieralisi, robin.murphy, chenhuacai
Cc: guohanjun, sudeep.holla, rafael, lenb, robert.moore,
linux-kernel, linux-acpi, loongarch
For DT, of_dma_get_range returns bus_dma_region typed dma regions,
which makes multiple dma windows with different offset available
for translation between dma address and cpu address.
But for ACPI, acpi_dma_get_range doesn't return similar dma regions,
causing no path for setting dev->dma_range_map conveniently. So the
patch changes acpi_dma_get_range and returns bus_dma_region typed
dma regions according to of_dma_get_range.
After changing acpi_dma_get_range, acpi_arch_dma_setup is changed for
ARM64, where 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, so this is a simplification consistent
with what other ACPI architectures also pass to iommu_setup_dma_ops().
Signed-off-by: Jianmin Lv <lvjianmin@loongson.cn>
---
drivers/acpi/arm64/dma.c | 29 ++++++++++++++++----------
drivers/acpi/scan.c | 53 +++++++++++++++++++++---------------------------
include/acpi/acpi_bus.h | 3 +--
include/linux/acpi.h | 7 +++----
4 files changed, 45 insertions(+), 47 deletions(-)
diff --git a/drivers/acpi/arm64/dma.c b/drivers/acpi/arm64/dma.c
index f16739a..1ef8e7d 100644
--- a/drivers/acpi/arm64/dma.c
+++ b/drivers/acpi/arm64/dma.c
@@ -4,11 +4,12 @@
#include <linux/device.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;
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
@@ -26,25 +27,31 @@ void acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size)
else
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)
ret = iort_dma_get_ranges(dev, &size);
+
if (!ret) {
/*
* Limit coherent and dma mask based on size retrieved from
* firmware.
*/
- end = dmaaddr + size - 1;
+ end = size - 1;
mask = DMA_BIT_MASK(ilog2(end) + 1);
dev->bus_dma_limit = end;
dev->coherent_dma_mask = min(dev->coherent_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!" : "");
}
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 762b61f..8c0c2ca 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -20,6 +20,7 @@
#include <linux/platform_data/x86/apple.h>
#include <linux/pgtable.h>
#include <linux/crc32.h>
+#include <linux/dma-direct.h>
#include "internal.h"
@@ -1482,25 +1483,21 @@ enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev)
* acpi_dma_get_range() - Get device DMA parameters.
*
* @dev: device to configure
- * @dma_addr: pointer device DMA address result
- * @offset: pointer to the DMA offset result
- * @size: pointer to DMA range size result
+ * @map: pointer to DMA ranges result
*
- * Evaluate DMA regions and return respectively DMA region start, offset
- * and size in dma_addr, offset and size on parsing success; it does not
- * update the passed in values on failure.
+ * Evaluate DMA regions and return pointer to DMA regions on
+ * parsing success; it does not update the passed in values on failure.
*
* Return 0 on success, < 0 on failure.
*/
-int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
- u64 *size)
+int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
{
struct acpi_device *adev;
LIST_HEAD(list);
struct resource_entry *rentry;
int ret;
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
@@ -1525,31 +1522,28 @@ int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
ret = acpi_dev_get_dma_resources(adev, &list);
if (ret > 0) {
+ r = kcalloc(ret + 1, sizeof(*r), GFP_KERNEL);
+ if (!r) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ *map = r;
+
list_for_each_entry(rentry, &list, node) {
- if (dma_offset && rentry->offset != dma_offset) {
+ if (rentry->res->start >= rentry->res->end) {
ret = -EINVAL;
- dev_warn(dma_dev, "Can't handle multiple windows with different offsets\n");
+ dev_dbg(dma_dev, "Invalid DMA regions configuration\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;
+ r->cpu_start = rentry->res->start;
+ r->dma_start = rentry->res->start - rentry->offset;
+ r->size = rentry->res->end - rentry->res->start + 1;
+ r->offset = rentry->offset;
+ r++;
}
- *dma_addr = dma_start - dma_offset;
- len = dma_end - dma_start;
- *size = max(len, len + 1);
- *offset = dma_offset;
}
out:
acpi_dev_free_resource_list(&list);
@@ -1639,20 +1633,19 @@ int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
const u32 *input_id)
{
const struct iommu_ops *iommu;
- u64 dma_addr = 0, size = 0;
if (attr == DEV_DMA_NOT_SUPPORTED) {
set_dma_ops(dev, &dma_dummy_ops);
return 0;
}
- acpi_arch_dma_setup(dev, &dma_addr, &size);
+ acpi_arch_dma_setup(dev);
iommu = acpi_iommu_configure_id(dev, input_id);
if (PTR_ERR(iommu) == -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);
return 0;
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 0dc1ea0b..e106073 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -611,8 +611,7 @@ struct acpi_pci_root {
int acpi_iommu_fwspec_init(struct device *dev, u32 id,
struct fwnode_handle *fwnode,
const struct iommu_ops *ops);
-int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
- u64 *size);
+int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map);
int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
const u32 *input_id);
static inline int acpi_dma_configure(struct device *dev,
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 44975c1..34e0545 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -280,12 +280,12 @@ int acpi_table_parse_madt(enum acpi_madt_type id,
#ifdef CONFIG_ARM64
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
static inline void
acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }
static inline void
-acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size) { }
+acpi_arch_dma_setup(struct device *dev) { }
#endif
int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
@@ -974,8 +974,7 @@ static inline enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev)
return DEV_DMA_NOT_SUPPORTED;
}
-static inline int acpi_dma_get_range(struct device *dev, u64 *dma_addr,
- u64 *offset, u64 *size)
+static inline int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
{
return -ENODEV;
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH V3 2/2] LoongArch: Remove ARCH_HAS_PHYS_TO_DMA
2022-08-30 3:01 [PATCH V3 0/2] DMA: update acpi_dma_get_range to return dma map regions Jianmin Lv
2022-08-30 3:01 ` [PATCH V3 1/2] ACPI / scan: Support multiple dma windows with different offsets Jianmin Lv
@ 2022-08-30 3:01 ` Jianmin Lv
2022-09-05 14:42 ` Huacai Chen
2022-09-05 2:55 ` [PATCH V3 0/2] DMA: update acpi_dma_get_range to return dma map regions Jianmin Lv
2 siblings, 1 reply; 10+ messages in thread
From: Jianmin Lv @ 2022-08-30 3:01 UTC (permalink / raw)
To: lpieralisi, robin.murphy, chenhuacai
Cc: guohanjun, sudeep.holla, rafael, lenb, robert.moore,
linux-kernel, linux-acpi, loongarch
Use _DMA defined in ACPI spec for translation between
DMA address and CPU address, and implement acpi_arch_dma_setup
for initializing dev->dma_range_map, where acpi_dma_get_range
is called for parsing _DMA.
e.g.
If we have two dma ranges:
cpu address dma address size offset
0x200080000000 0x2080000000 0x400000000 0x1fe000000000
0x400080000000 0x4080000000 0x400000000 0x3fc000000000
_DMA for pci devices should be declared in host bridge as
flowing:
Name (_DMA, ResourceTemplate() {
QWordMemory (ResourceProducer,
PosDecode,
MinFixed,
MaxFixed,
NonCacheable,
ReadWrite,
0x0,
0x4080000000,
0x447fffffff,
0x3fc000000000,
0x400000000,
,
,
)
QWordMemory (ResourceProducer,
PosDecode,
MinFixed,
MaxFixed,
NonCacheable,
ReadWrite,
0x0,
0x2080000000,
0x247fffffff,
0x1fe000000000,
0x400000000,
,
,
)
})
Signed-off-by: Jianmin Lv <lvjianmin@loongson.cn>
---
arch/loongarch/Kconfig | 1 -
arch/loongarch/kernel/dma.c | 52 +++++++++++++++++--------------------------
arch/loongarch/kernel/setup.c | 2 +-
include/linux/acpi.h | 9 +++++---
4 files changed, 28 insertions(+), 36 deletions(-)
diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
index b57daee..9dedcf9 100644
--- a/arch/loongarch/Kconfig
+++ b/arch/loongarch/Kconfig
@@ -7,7 +7,6 @@ config LOONGARCH
select ARCH_ENABLE_MEMORY_HOTPLUG
select ARCH_ENABLE_MEMORY_HOTREMOVE
select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
- select ARCH_HAS_PHYS_TO_DMA
select ARCH_HAS_PTE_SPECIAL
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
select ARCH_INLINE_READ_LOCK if !PREEMPTION
diff --git a/arch/loongarch/kernel/dma.c b/arch/loongarch/kernel/dma.c
index 8c9b531..7a9c6a9 100644
--- a/arch/loongarch/kernel/dma.c
+++ b/arch/loongarch/kernel/dma.c
@@ -2,39 +2,29 @@
/*
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
*/
-#include <linux/init.h>
+#include <linux/acpi.h>
#include <linux/dma-direct.h>
-#include <linux/dma-mapping.h>
-#include <linux/dma-map-ops.h>
-#include <linux/swiotlb.h>
-#include <asm/bootinfo.h>
-#include <asm/dma.h>
-#include <asm/loongson.h>
-
-/*
- * We extract 4bit node id (bit 44~47) from Loongson-3's
- * 48bit physical address space and embed it into 40bit.
- */
-
-static int node_id_offset;
-
-dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
-{
- long nid = (paddr >> 44) & 0xf;
-
- return ((nid << 44) ^ paddr) | (nid << node_id_offset);
-}
-
-phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
+void acpi_arch_dma_setup(struct device *dev)
{
- long nid = (daddr >> node_id_offset) & 0xf;
+ int ret;
+ u64 mask, end = 0;
+ const struct bus_dma_region *map = NULL;
+
+ 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;
+ }
+
+ mask = DMA_BIT_MASK(ilog2(end) + 1);
+ dev->bus_dma_limit = end;
+ dev->dma_range_map = map;
+ dev->coherent_dma_mask = min(dev->coherent_dma_mask, mask);
+ *dev->dma_mask = min(*dev->dma_mask, mask);
+ }
- return ((nid << node_id_offset) ^ daddr) | (nid << 44);
-}
-
-void __init plat_swiotlb_setup(void)
-{
- swiotlb_init(true, SWIOTLB_VERBOSE);
- node_id_offset = ((readl(LS7A_DMA_CFG) & LS7A_DMA_NODE_MASK) >> LS7A_DMA_NODE_SHF) + 36;
}
diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c
index c74860b..974f085 100644
--- a/arch/loongarch/kernel/setup.c
+++ b/arch/loongarch/kernel/setup.c
@@ -247,7 +247,7 @@ static void __init arch_mem_init(char **cmdline_p)
sparse_init();
memblock_set_bottom_up(true);
- plat_swiotlb_setup();
+ swiotlb_init(true, SWIOTLB_VERBOSE);
dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 34e0545..33977b87 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -278,14 +278,17 @@ int acpi_table_parse_madt(enum acpi_madt_type id,
void acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa);
+#if defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH)
+void acpi_arch_dma_setup(struct device *dev);
+#else
+static inline void acpi_arch_dma_setup(struct device *dev) { }
+#endif
+
#ifdef CONFIG_ARM64
void acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa);
-void acpi_arch_dma_setup(struct device *dev);
#else
static inline void
acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }
-static inline void
-acpi_arch_dma_setup(struct device *dev) { }
#endif
int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
--
1.8.3.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH V3 0/2] DMA: update acpi_dma_get_range to return dma map regions
2022-08-30 3:01 [PATCH V3 0/2] DMA: update acpi_dma_get_range to return dma map regions Jianmin Lv
2022-08-30 3:01 ` [PATCH V3 1/2] ACPI / scan: Support multiple dma windows with different offsets Jianmin Lv
2022-08-30 3:01 ` [PATCH V3 2/2] LoongArch: Remove ARCH_HAS_PHYS_TO_DMA Jianmin Lv
@ 2022-09-05 2:55 ` Jianmin Lv
2 siblings, 0 replies; 10+ messages in thread
From: Jianmin Lv @ 2022-09-05 2:55 UTC (permalink / raw)
To: lpieralisi, robin.murphy, chenhuacai
Cc: guohanjun, sudeep.holla, rafael, lenb, robert.moore,
linux-kernel, linux-acpi, loongarch
Hi, all,
Is there anything else in this patch series that needs to be modified?
Thanks.
Jianmin.
On 2022/8/30 上午11:01, Jianmin Lv wrote:
> The patch series changed acpi_dma_get_range to return dma regions
> as of_dma_get_range, so that dev->dma_range_map can be initialized
> conveniently.
>
> And acpi_arch_dma_setup for ARM64 is changed wih removing dma_base
> and size from it's parameters.
>
> Remove ARCH_HAS_PHYS_TO_DMA for LoongArch and use generic
> phys_to_dma/dma_to_phys in include/linux/dma-direct.h.
>
> V1 -> V2
> - Removed dma_base and size from acpi_arch_dma_setup' parameters
> - Add patch to remove ARCH_HAS_PHYS_TO_DMA for LoongArch
>
> V2 -> V3
> - Add kerneldoc for acpi_dma_get_range changing
> - Remove redundant code in acpi_arch_dma_setup, and check map
>
>
> Jianmin Lv (2):
> ACPI / scan: Support multiple dma windows with different offsets
> LoongArch: Remove ARCH_HAS_PHYS_TO_DMA
>
> arch/loongarch/Kconfig | 1 -
> arch/loongarch/kernel/dma.c | 52 +++++++++++++++++-------------------------
> arch/loongarch/kernel/setup.c | 2 +-
> drivers/acpi/arm64/dma.c | 29 ++++++++++++++---------
> drivers/acpi/scan.c | 53 +++++++++++++++++++------------------------
> include/acpi/acpi_bus.h | 3 +--
> include/linux/acpi.h | 12 ++++++----
> 7 files changed, 71 insertions(+), 81 deletions(-)
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH V3 1/2] ACPI / scan: Support multiple dma windows with different offsets
2022-08-30 3:01 ` [PATCH V3 1/2] ACPI / scan: Support multiple dma windows with different offsets Jianmin Lv
@ 2022-09-05 12:20 ` Robin Murphy
2022-09-06 12:40 ` Jianmin Lv
0 siblings, 1 reply; 10+ messages in thread
From: Robin Murphy @ 2022-09-05 12:20 UTC (permalink / raw)
To: Jianmin Lv, lpieralisi, chenhuacai
Cc: guohanjun, sudeep.holla, rafael, lenb, robert.moore,
linux-kernel, linux-acpi, loongarch
On 2022-08-30 04:01, Jianmin Lv wrote:
> For DT, of_dma_get_range returns bus_dma_region typed dma regions,
> which makes multiple dma windows with different offset available
> for translation between dma address and cpu address.
>
> But for ACPI, acpi_dma_get_range doesn't return similar dma regions,
> causing no path for setting dev->dma_range_map conveniently. So the
> patch changes acpi_dma_get_range and returns bus_dma_region typed
> dma regions according to of_dma_get_range.
>
> After changing acpi_dma_get_range, acpi_arch_dma_setup is changed for
> ARM64, where 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, so this is a simplification consistent
> with what other ACPI architectures also pass to iommu_setup_dma_ops().
Other than a micro-nit that acpi_dma_get_range() could probably use
resource_size(),
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
It took me longer than I care to admit to figure out where the implicit
declaration of struct bus_dma_region in the scope of acpi.h and
acpi_bus.h comes from, but in the end I guess it's sufficiently
well-defined by the C spec to be reliable.
Thanks for getting this done!
Robin.
> Signed-off-by: Jianmin Lv <lvjianmin@loongson.cn>
> ---
> drivers/acpi/arm64/dma.c | 29 ++++++++++++++++----------
> drivers/acpi/scan.c | 53 +++++++++++++++++++++---------------------------
> include/acpi/acpi_bus.h | 3 +--
> include/linux/acpi.h | 7 +++----
> 4 files changed, 45 insertions(+), 47 deletions(-)
>
> diff --git a/drivers/acpi/arm64/dma.c b/drivers/acpi/arm64/dma.c
> index f16739a..1ef8e7d 100644
> --- a/drivers/acpi/arm64/dma.c
> +++ b/drivers/acpi/arm64/dma.c
> @@ -4,11 +4,12 @@
> #include <linux/device.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;
> 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
> @@ -26,25 +27,31 @@ void acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size)
> else
> 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)
> ret = iort_dma_get_ranges(dev, &size);
> +
> if (!ret) {
> /*
> * Limit coherent and dma mask based on size retrieved from
> * firmware.
> */
> - end = dmaaddr + size - 1;
> + end = size - 1;
> mask = DMA_BIT_MASK(ilog2(end) + 1);
> dev->bus_dma_limit = end;
> dev->coherent_dma_mask = min(dev->coherent_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!" : "");
> }
> diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
> index 762b61f..8c0c2ca 100644
> --- a/drivers/acpi/scan.c
> +++ b/drivers/acpi/scan.c
> @@ -20,6 +20,7 @@
> #include <linux/platform_data/x86/apple.h>
> #include <linux/pgtable.h>
> #include <linux/crc32.h>
> +#include <linux/dma-direct.h>
>
> #include "internal.h"
>
> @@ -1482,25 +1483,21 @@ enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev)
> * acpi_dma_get_range() - Get device DMA parameters.
> *
> * @dev: device to configure
> - * @dma_addr: pointer device DMA address result
> - * @offset: pointer to the DMA offset result
> - * @size: pointer to DMA range size result
> + * @map: pointer to DMA ranges result
> *
> - * Evaluate DMA regions and return respectively DMA region start, offset
> - * and size in dma_addr, offset and size on parsing success; it does not
> - * update the passed in values on failure.
> + * Evaluate DMA regions and return pointer to DMA regions on
> + * parsing success; it does not update the passed in values on failure.
> *
> * Return 0 on success, < 0 on failure.
> */
> -int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
> - u64 *size)
> +int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
> {
> struct acpi_device *adev;
> LIST_HEAD(list);
> struct resource_entry *rentry;
> int ret;
> 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
> @@ -1525,31 +1522,28 @@ int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
>
> ret = acpi_dev_get_dma_resources(adev, &list);
> if (ret > 0) {
> + r = kcalloc(ret + 1, sizeof(*r), GFP_KERNEL);
> + if (!r) {
> + ret = -ENOMEM;
> + goto out;
> + }
> +
> + *map = r;
> +
> list_for_each_entry(rentry, &list, node) {
> - if (dma_offset && rentry->offset != dma_offset) {
> + if (rentry->res->start >= rentry->res->end) {
> ret = -EINVAL;
> - dev_warn(dma_dev, "Can't handle multiple windows with different offsets\n");
> + dev_dbg(dma_dev, "Invalid DMA regions configuration\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;
> + r->cpu_start = rentry->res->start;
> + r->dma_start = rentry->res->start - rentry->offset;
> + r->size = rentry->res->end - rentry->res->start + 1;
> + r->offset = rentry->offset;
> + r++;
> }
>
> - *dma_addr = dma_start - dma_offset;
> - len = dma_end - dma_start;
> - *size = max(len, len + 1);
> - *offset = dma_offset;
> }
> out:
> acpi_dev_free_resource_list(&list);
> @@ -1639,20 +1633,19 @@ int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
> const u32 *input_id)
> {
> const struct iommu_ops *iommu;
> - u64 dma_addr = 0, size = 0;
>
> if (attr == DEV_DMA_NOT_SUPPORTED) {
> set_dma_ops(dev, &dma_dummy_ops);
> return 0;
> }
>
> - acpi_arch_dma_setup(dev, &dma_addr, &size);
> + acpi_arch_dma_setup(dev);
>
> iommu = acpi_iommu_configure_id(dev, input_id);
> if (PTR_ERR(iommu) == -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);
>
> return 0;
> diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
> index 0dc1ea0b..e106073 100644
> --- a/include/acpi/acpi_bus.h
> +++ b/include/acpi/acpi_bus.h
> @@ -611,8 +611,7 @@ struct acpi_pci_root {
> int acpi_iommu_fwspec_init(struct device *dev, u32 id,
> struct fwnode_handle *fwnode,
> const struct iommu_ops *ops);
> -int acpi_dma_get_range(struct device *dev, u64 *dma_addr, u64 *offset,
> - u64 *size);
> +int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map);
> int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr,
> const u32 *input_id);
> static inline int acpi_dma_configure(struct device *dev,
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 44975c1..34e0545 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -280,12 +280,12 @@ int acpi_table_parse_madt(enum acpi_madt_type id,
>
> #ifdef CONFIG_ARM64
> 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
> static inline void
> acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }
> static inline void
> -acpi_arch_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size) { }
> +acpi_arch_dma_setup(struct device *dev) { }
> #endif
>
> int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
> @@ -974,8 +974,7 @@ static inline enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev)
> return DEV_DMA_NOT_SUPPORTED;
> }
>
> -static inline int acpi_dma_get_range(struct device *dev, u64 *dma_addr,
> - u64 *offset, u64 *size)
> +static inline int acpi_dma_get_range(struct device *dev, const struct bus_dma_region **map)
> {
> return -ENODEV;
> }
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH V3 2/2] LoongArch: Remove ARCH_HAS_PHYS_TO_DMA
2022-08-30 3:01 ` [PATCH V3 2/2] LoongArch: Remove ARCH_HAS_PHYS_TO_DMA Jianmin Lv
@ 2022-09-05 14:42 ` Huacai Chen
2022-09-06 12:34 ` Jianmin Lv
0 siblings, 1 reply; 10+ messages in thread
From: Huacai Chen @ 2022-09-05 14:42 UTC (permalink / raw)
To: Jianmin Lv
Cc: lpieralisi, Robin Murphy, Huacai Chen, Hanjun Guo, Sudeep Holla,
Rafael J . Wysocki, Len Brown, Robert Moore, LKML,
ACPI Devel Maling List, loongarch
Hi, Jianmin,
The title can be "LoongArch: Use acpi_arch_dma_setup() and remove
ARCH_HAS_PHYS_TO_DMA", and please use resource_size() as arm64.
Acked-by: Huacai Chen <chenhuacai@loongson.cn>
Huacai
On Tue, Aug 30, 2022 at 11:01 AM Jianmin Lv <lvjianmin@loongson.cn> wrote:
>
> Use _DMA defined in ACPI spec for translation between
> DMA address and CPU address, and implement acpi_arch_dma_setup
> for initializing dev->dma_range_map, where acpi_dma_get_range
> is called for parsing _DMA.
>
> e.g.
> If we have two dma ranges:
> cpu address dma address size offset
> 0x200080000000 0x2080000000 0x400000000 0x1fe000000000
> 0x400080000000 0x4080000000 0x400000000 0x3fc000000000
>
> _DMA for pci devices should be declared in host bridge as
> flowing:
>
> Name (_DMA, ResourceTemplate() {
> QWordMemory (ResourceProducer,
> PosDecode,
> MinFixed,
> MaxFixed,
> NonCacheable,
> ReadWrite,
> 0x0,
> 0x4080000000,
> 0x447fffffff,
> 0x3fc000000000,
> 0x400000000,
> ,
> ,
> )
>
> QWordMemory (ResourceProducer,
> PosDecode,
> MinFixed,
> MaxFixed,
> NonCacheable,
> ReadWrite,
> 0x0,
> 0x2080000000,
> 0x247fffffff,
> 0x1fe000000000,
> 0x400000000,
> ,
> ,
> )
> })
>
> Signed-off-by: Jianmin Lv <lvjianmin@loongson.cn>
> ---
> arch/loongarch/Kconfig | 1 -
> arch/loongarch/kernel/dma.c | 52 +++++++++++++++++--------------------------
> arch/loongarch/kernel/setup.c | 2 +-
> include/linux/acpi.h | 9 +++++---
> 4 files changed, 28 insertions(+), 36 deletions(-)
>
> diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
> index b57daee..9dedcf9 100644
> --- a/arch/loongarch/Kconfig
> +++ b/arch/loongarch/Kconfig
> @@ -7,7 +7,6 @@ config LOONGARCH
> select ARCH_ENABLE_MEMORY_HOTPLUG
> select ARCH_ENABLE_MEMORY_HOTREMOVE
> select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
> - select ARCH_HAS_PHYS_TO_DMA
> select ARCH_HAS_PTE_SPECIAL
> select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
> select ARCH_INLINE_READ_LOCK if !PREEMPTION
> diff --git a/arch/loongarch/kernel/dma.c b/arch/loongarch/kernel/dma.c
> index 8c9b531..7a9c6a9 100644
> --- a/arch/loongarch/kernel/dma.c
> +++ b/arch/loongarch/kernel/dma.c
> @@ -2,39 +2,29 @@
> /*
> * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
> */
> -#include <linux/init.h>
> +#include <linux/acpi.h>
> #include <linux/dma-direct.h>
> -#include <linux/dma-mapping.h>
> -#include <linux/dma-map-ops.h>
> -#include <linux/swiotlb.h>
>
> -#include <asm/bootinfo.h>
> -#include <asm/dma.h>
> -#include <asm/loongson.h>
> -
> -/*
> - * We extract 4bit node id (bit 44~47) from Loongson-3's
> - * 48bit physical address space and embed it into 40bit.
> - */
> -
> -static int node_id_offset;
> -
> -dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
> -{
> - long nid = (paddr >> 44) & 0xf;
> -
> - return ((nid << 44) ^ paddr) | (nid << node_id_offset);
> -}
> -
> -phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
> +void acpi_arch_dma_setup(struct device *dev)
> {
> - long nid = (daddr >> node_id_offset) & 0xf;
> + int ret;
> + u64 mask, end = 0;
> + const struct bus_dma_region *map = NULL;
> +
> + 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;
> + }
> +
> + mask = DMA_BIT_MASK(ilog2(end) + 1);
> + dev->bus_dma_limit = end;
> + dev->dma_range_map = map;
> + dev->coherent_dma_mask = min(dev->coherent_dma_mask, mask);
> + *dev->dma_mask = min(*dev->dma_mask, mask);
> + }
>
> - return ((nid << node_id_offset) ^ daddr) | (nid << 44);
> -}
> -
> -void __init plat_swiotlb_setup(void)
> -{
> - swiotlb_init(true, SWIOTLB_VERBOSE);
> - node_id_offset = ((readl(LS7A_DMA_CFG) & LS7A_DMA_NODE_MASK) >> LS7A_DMA_NODE_SHF) + 36;
> }
> diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c
> index c74860b..974f085 100644
> --- a/arch/loongarch/kernel/setup.c
> +++ b/arch/loongarch/kernel/setup.c
> @@ -247,7 +247,7 @@ static void __init arch_mem_init(char **cmdline_p)
> sparse_init();
> memblock_set_bottom_up(true);
>
> - plat_swiotlb_setup();
> + swiotlb_init(true, SWIOTLB_VERBOSE);
>
> dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
>
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 34e0545..33977b87 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -278,14 +278,17 @@ int acpi_table_parse_madt(enum acpi_madt_type id,
>
> void acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa);
>
> +#if defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH)
> +void acpi_arch_dma_setup(struct device *dev);
> +#else
> +static inline void acpi_arch_dma_setup(struct device *dev) { }
> +#endif
> +
> #ifdef CONFIG_ARM64
> void acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa);
> -void acpi_arch_dma_setup(struct device *dev);
> #else
> static inline void
> acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }
> -static inline void
> -acpi_arch_dma_setup(struct device *dev) { }
> #endif
>
> int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
> --
> 1.8.3.1
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH V3 2/2] LoongArch: Remove ARCH_HAS_PHYS_TO_DMA
2022-09-05 14:42 ` Huacai Chen
@ 2022-09-06 12:34 ` Jianmin Lv
0 siblings, 0 replies; 10+ messages in thread
From: Jianmin Lv @ 2022-09-06 12:34 UTC (permalink / raw)
To: Huacai Chen
Cc: lpieralisi, Robin Murphy, Huacai Chen, Hanjun Guo, Sudeep Holla,
Rafael J . Wysocki, Len Brown, Robert Moore, LKML,
ACPI Devel Maling List, loongarch
Hi, Huacai
Ok, thanks, I'll change title in V4. There is *not* size calculation in
this patch, so the patch does not need resource_size() as in
acpi_dma_get_range().
On 2022/9/5 下午10:42, Huacai Chen wrote:
> Hi, Jianmin,
>
> The title can be "LoongArch: Use acpi_arch_dma_setup() and remove
> ARCH_HAS_PHYS_TO_DMA", and please use resource_size() as arm64.
>
> Acked-by: Huacai Chen <chenhuacai@loongson.cn>
>
>
> Huacai
>
>
> On Tue, Aug 30, 2022 at 11:01 AM Jianmin Lv <lvjianmin@loongson.cn> wrote:
>>
>> Use _DMA defined in ACPI spec for translation between
>> DMA address and CPU address, and implement acpi_arch_dma_setup
>> for initializing dev->dma_range_map, where acpi_dma_get_range
>> is called for parsing _DMA.
>>
>> e.g.
>> If we have two dma ranges:
>> cpu address dma address size offset
>> 0x200080000000 0x2080000000 0x400000000 0x1fe000000000
>> 0x400080000000 0x4080000000 0x400000000 0x3fc000000000
>>
>> _DMA for pci devices should be declared in host bridge as
>> flowing:
>>
>> Name (_DMA, ResourceTemplate() {
>> QWordMemory (ResourceProducer,
>> PosDecode,
>> MinFixed,
>> MaxFixed,
>> NonCacheable,
>> ReadWrite,
>> 0x0,
>> 0x4080000000,
>> 0x447fffffff,
>> 0x3fc000000000,
>> 0x400000000,
>> ,
>> ,
>> )
>>
>> QWordMemory (ResourceProducer,
>> PosDecode,
>> MinFixed,
>> MaxFixed,
>> NonCacheable,
>> ReadWrite,
>> 0x0,
>> 0x2080000000,
>> 0x247fffffff,
>> 0x1fe000000000,
>> 0x400000000,
>> ,
>> ,
>> )
>> })
>>
>> Signed-off-by: Jianmin Lv <lvjianmin@loongson.cn>
>> ---
>> arch/loongarch/Kconfig | 1 -
>> arch/loongarch/kernel/dma.c | 52 +++++++++++++++++--------------------------
>> arch/loongarch/kernel/setup.c | 2 +-
>> include/linux/acpi.h | 9 +++++---
>> 4 files changed, 28 insertions(+), 36 deletions(-)
>>
>> diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
>> index b57daee..9dedcf9 100644
>> --- a/arch/loongarch/Kconfig
>> +++ b/arch/loongarch/Kconfig
>> @@ -7,7 +7,6 @@ config LOONGARCH
>> select ARCH_ENABLE_MEMORY_HOTPLUG
>> select ARCH_ENABLE_MEMORY_HOTREMOVE
>> select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
>> - select ARCH_HAS_PHYS_TO_DMA
>> select ARCH_HAS_PTE_SPECIAL
>> select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
>> select ARCH_INLINE_READ_LOCK if !PREEMPTION
>> diff --git a/arch/loongarch/kernel/dma.c b/arch/loongarch/kernel/dma.c
>> index 8c9b531..7a9c6a9 100644
>> --- a/arch/loongarch/kernel/dma.c
>> +++ b/arch/loongarch/kernel/dma.c
>> @@ -2,39 +2,29 @@
>> /*
>> * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
>> */
>> -#include <linux/init.h>
>> +#include <linux/acpi.h>
>> #include <linux/dma-direct.h>
>> -#include <linux/dma-mapping.h>
>> -#include <linux/dma-map-ops.h>
>> -#include <linux/swiotlb.h>
>>
>> -#include <asm/bootinfo.h>
>> -#include <asm/dma.h>
>> -#include <asm/loongson.h>
>> -
>> -/*
>> - * We extract 4bit node id (bit 44~47) from Loongson-3's
>> - * 48bit physical address space and embed it into 40bit.
>> - */
>> -
>> -static int node_id_offset;
>> -
>> -dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
>> -{
>> - long nid = (paddr >> 44) & 0xf;
>> -
>> - return ((nid << 44) ^ paddr) | (nid << node_id_offset);
>> -}
>> -
>> -phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
>> +void acpi_arch_dma_setup(struct device *dev)
>> {
>> - long nid = (daddr >> node_id_offset) & 0xf;
>> + int ret;
>> + u64 mask, end = 0;
>> + const struct bus_dma_region *map = NULL;
>> +
>> + 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;
>> + }
>> +
>> + mask = DMA_BIT_MASK(ilog2(end) + 1);
>> + dev->bus_dma_limit = end;
>> + dev->dma_range_map = map;
>> + dev->coherent_dma_mask = min(dev->coherent_dma_mask, mask);
>> + *dev->dma_mask = min(*dev->dma_mask, mask);
>> + }
>>
>> - return ((nid << node_id_offset) ^ daddr) | (nid << 44);
>> -}
>> -
>> -void __init plat_swiotlb_setup(void)
>> -{
>> - swiotlb_init(true, SWIOTLB_VERBOSE);
>> - node_id_offset = ((readl(LS7A_DMA_CFG) & LS7A_DMA_NODE_MASK) >> LS7A_DMA_NODE_SHF) + 36;
>> }
>> diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c
>> index c74860b..974f085 100644
>> --- a/arch/loongarch/kernel/setup.c
>> +++ b/arch/loongarch/kernel/setup.c
>> @@ -247,7 +247,7 @@ static void __init arch_mem_init(char **cmdline_p)
>> sparse_init();
>> memblock_set_bottom_up(true);
>>
>> - plat_swiotlb_setup();
>> + swiotlb_init(true, SWIOTLB_VERBOSE);
>>
>> dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
>>
>> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
>> index 34e0545..33977b87 100644
>> --- a/include/linux/acpi.h
>> +++ b/include/linux/acpi.h
>> @@ -278,14 +278,17 @@ int acpi_table_parse_madt(enum acpi_madt_type id,
>>
>> void acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa);
>>
>> +#if defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH)
>> +void acpi_arch_dma_setup(struct device *dev);
>> +#else
>> +static inline void acpi_arch_dma_setup(struct device *dev) { }
>> +#endif
>> +
>> #ifdef CONFIG_ARM64
>> void acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa);
>> -void acpi_arch_dma_setup(struct device *dev);
>> #else
>> static inline void
>> acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }
>> -static inline void
>> -acpi_arch_dma_setup(struct device *dev) { }
>> #endif
>>
>> int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);
>> --
>> 1.8.3.1
>>
>>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH V3 1/2] ACPI / scan: Support multiple dma windows with different offsets
2022-09-05 12:20 ` Robin Murphy
@ 2022-09-06 12:40 ` Jianmin Lv
2022-09-09 8:04 ` Lorenzo Pieralisi
0 siblings, 1 reply; 10+ messages in thread
From: Jianmin Lv @ 2022-09-06 12:40 UTC (permalink / raw)
To: Robin Murphy, lpieralisi, chenhuacai
Cc: guohanjun, sudeep.holla, rafael, lenb, robert.moore,
linux-kernel, linux-acpi, loongarch
On 2022/9/5 下午8:20, Robin Murphy wrote:
> On 2022-08-30 04:01, Jianmin Lv wrote:
>> For DT, of_dma_get_range returns bus_dma_region typed dma regions,
>> which makes multiple dma windows with different offset available
>> for translation between dma address and cpu address.
>>
>> But for ACPI, acpi_dma_get_range doesn't return similar dma regions,
>> causing no path for setting dev->dma_range_map conveniently. So the
>> patch changes acpi_dma_get_range and returns bus_dma_region typed
>> dma regions according to of_dma_get_range.
>>
>> After changing acpi_dma_get_range, acpi_arch_dma_setup is changed for
>> ARM64, where 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, so this is a simplification consistent
>> with what other ACPI architectures also pass to iommu_setup_dma_ops().
>
> Other than a micro-nit that acpi_dma_get_range() could probably use
> resource_size(),
>
Ok, thanks, I'll use resource_size() in acpi_dma_get_range().
> Reviewed-by: Robin Murphy <robin.murphy@arm.com>
>
> It took me longer than I care to admit to figure out where the implicit
> declaration of struct bus_dma_region in the scope of acpi.h and
> acpi_bus.h comes from, but in the end I guess it's sufficiently
> well-defined by the C spec to be reliable.
>
> Thanks for getting this done!
>
It's a pleasure!
> Robin.
>
[...]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH V3 1/2] ACPI / scan: Support multiple dma windows with different offsets
2022-09-06 12:40 ` Jianmin Lv
@ 2022-09-09 8:04 ` Lorenzo Pieralisi
2022-09-09 9:23 ` Jianmin Lv
0 siblings, 1 reply; 10+ messages in thread
From: Lorenzo Pieralisi @ 2022-09-09 8:04 UTC (permalink / raw)
To: Jianmin Lv
Cc: Robin Murphy, chenhuacai, guohanjun, sudeep.holla, rafael, lenb,
robert.moore, linux-kernel, linux-acpi, loongarch
On Tue, Sep 06, 2022 at 08:40:48PM +0800, Jianmin Lv wrote:
>
>
> On 2022/9/5 下午8:20, Robin Murphy wrote:
> > On 2022-08-30 04:01, Jianmin Lv wrote:
> > > For DT, of_dma_get_range returns bus_dma_region typed dma regions,
> > > which makes multiple dma windows with different offset available
> > > for translation between dma address and cpu address.
> > >
> > > But for ACPI, acpi_dma_get_range doesn't return similar dma regions,
> > > causing no path for setting dev->dma_range_map conveniently. So the
> > > patch changes acpi_dma_get_range and returns bus_dma_region typed
> > > dma regions according to of_dma_get_range.
> > >
> > > After changing acpi_dma_get_range, acpi_arch_dma_setup is changed for
> > > ARM64, where 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, so this is a simplification consistent
> > > with what other ACPI architectures also pass to iommu_setup_dma_ops().
> >
> > Other than a micro-nit that acpi_dma_get_range() could probably use
> > resource_size(),
> >
>
> Ok, thanks, I'll use resource_size() in acpi_dma_get_range().
Are you reposting this shortly ? We are almost at -rc5, it would
be good if we can proceed promptly.
Thanks,
Lorenzo
> > Reviewed-by: Robin Murphy <robin.murphy@arm.com>
> >
> > It took me longer than I care to admit to figure out where the implicit
> > declaration of struct bus_dma_region in the scope of acpi.h and
> > acpi_bus.h comes from, but in the end I guess it's sufficiently
> > well-defined by the C spec to be reliable.
> >
> > Thanks for getting this done!
> >
>
> It's a pleasure!
>
>
> > Robin.
> >
>
> [...]
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH V3 1/2] ACPI / scan: Support multiple dma windows with different offsets
2022-09-09 8:04 ` Lorenzo Pieralisi
@ 2022-09-09 9:23 ` Jianmin Lv
0 siblings, 0 replies; 10+ messages in thread
From: Jianmin Lv @ 2022-09-09 9:23 UTC (permalink / raw)
To: Lorenzo Pieralisi
Cc: Robin Murphy, chenhuacai, guohanjun, sudeep.holla, rafael, lenb,
robert.moore, linux-kernel, linux-acpi, loongarch
On 2022/9/9 下午4:04, Lorenzo Pieralisi wrote:
> On Tue, Sep 06, 2022 at 08:40:48PM +0800, Jianmin Lv wrote:
>>
>>
>> On 2022/9/5 下午8:20, Robin Murphy wrote:
>>> On 2022-08-30 04:01, Jianmin Lv wrote:
>>>> For DT, of_dma_get_range returns bus_dma_region typed dma regions,
>>>> which makes multiple dma windows with different offset available
>>>> for translation between dma address and cpu address.
>>>>
>>>> But for ACPI, acpi_dma_get_range doesn't return similar dma regions,
>>>> causing no path for setting dev->dma_range_map conveniently. So the
>>>> patch changes acpi_dma_get_range and returns bus_dma_region typed
>>>> dma regions according to of_dma_get_range.
>>>>
>>>> After changing acpi_dma_get_range, acpi_arch_dma_setup is changed for
>>>> ARM64, where 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, so this is a simplification consistent
>>>> with what other ACPI architectures also pass to iommu_setup_dma_ops().
>>>
>>> Other than a micro-nit that acpi_dma_get_range() could probably use
>>> resource_size(),
>>>
>>
>> Ok, thanks, I'll use resource_size() in acpi_dma_get_range().
>
> Are you reposting this shortly ? We are almost at -rc5, it would
> be good if we can proceed promptly.
>
> Thanks,
> Lorenzo
>
Ok, I'll send V4 today.
Thanks,
Jianmin
>>> Reviewed-by: Robin Murphy <robin.murphy@arm.com>
>>>
>>> It took me longer than I care to admit to figure out where the implicit
>>> declaration of struct bus_dma_region in the scope of acpi.h and
>>> acpi_bus.h comes from, but in the end I guess it's sufficiently
>>> well-defined by the C spec to be reliable.
>>>
>>> Thanks for getting this done!
>>>
>>
>> It's a pleasure!
>>
>>
>>> Robin.
>>>
>>
>> [...]
>>
>>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-09-09 9:23 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-30 3:01 [PATCH V3 0/2] DMA: update acpi_dma_get_range to return dma map regions Jianmin Lv
2022-08-30 3:01 ` [PATCH V3 1/2] ACPI / scan: Support multiple dma windows with different offsets Jianmin Lv
2022-09-05 12:20 ` Robin Murphy
2022-09-06 12:40 ` Jianmin Lv
2022-09-09 8:04 ` Lorenzo Pieralisi
2022-09-09 9:23 ` Jianmin Lv
2022-08-30 3:01 ` [PATCH V3 2/2] LoongArch: Remove ARCH_HAS_PHYS_TO_DMA Jianmin Lv
2022-09-05 14:42 ` Huacai Chen
2022-09-06 12:34 ` Jianmin Lv
2022-09-05 2:55 ` [PATCH V3 0/2] DMA: update acpi_dma_get_range to return dma map regions Jianmin Lv
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).