Skip to content

Commit c78c43f

Browse files
lvjianmin-loongsonrafaeljw
authored andcommitted
LoongArch: Use acpi_arch_dma_setup() and remove ARCH_HAS_PHYS_TO_DMA
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, , , ) }) Acked-by: Huacai Chen <[email protected]> Signed-off-by: Jianmin Lv <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent bf2ee8d commit c78c43f

File tree

4 files changed

+28
-36
lines changed

4 files changed

+28
-36
lines changed

arch/loongarch/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ config LOONGARCH
1010
select ARCH_ENABLE_MEMORY_HOTPLUG
1111
select ARCH_ENABLE_MEMORY_HOTREMOVE
1212
select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
13-
select ARCH_HAS_PHYS_TO_DMA
1413
select ARCH_HAS_PTE_SPECIAL
1514
select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
1615
select ARCH_INLINE_READ_LOCK if !PREEMPTION

arch/loongarch/kernel/dma.c

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,29 @@
22
/*
33
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
44
*/
5-
#include <linux/init.h>
5+
#include <linux/acpi.h>
66
#include <linux/dma-direct.h>
7-
#include <linux/dma-mapping.h>
8-
#include <linux/dma-map-ops.h>
9-
#include <linux/swiotlb.h>
107

11-
#include <asm/bootinfo.h>
12-
#include <asm/dma.h>
13-
#include <asm/loongson.h>
14-
15-
/*
16-
* We extract 4bit node id (bit 44~47) from Loongson-3's
17-
* 48bit physical address space and embed it into 40bit.
18-
*/
19-
20-
static int node_id_offset;
21-
22-
dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
23-
{
24-
long nid = (paddr >> 44) & 0xf;
25-
26-
return ((nid << 44) ^ paddr) | (nid << node_id_offset);
27-
}
28-
29-
phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
8+
void acpi_arch_dma_setup(struct device *dev)
309
{
31-
long nid = (daddr >> node_id_offset) & 0xf;
10+
int ret;
11+
u64 mask, end = 0;
12+
const struct bus_dma_region *map = NULL;
13+
14+
ret = acpi_dma_get_range(dev, &map);
15+
if (!ret && map) {
16+
const struct bus_dma_region *r = map;
17+
18+
for (end = 0; r->size; r++) {
19+
if (r->dma_start + r->size - 1 > end)
20+
end = r->dma_start + r->size - 1;
21+
}
22+
23+
mask = DMA_BIT_MASK(ilog2(end) + 1);
24+
dev->bus_dma_limit = end;
25+
dev->dma_range_map = map;
26+
dev->coherent_dma_mask = min(dev->coherent_dma_mask, mask);
27+
*dev->dma_mask = min(*dev->dma_mask, mask);
28+
}
3229

33-
return ((nid << node_id_offset) ^ daddr) | (nid << 44);
34-
}
35-
36-
void __init plat_swiotlb_setup(void)
37-
{
38-
swiotlb_init(true, SWIOTLB_VERBOSE);
39-
node_id_offset = ((readl(LS7A_DMA_CFG) & LS7A_DMA_NODE_MASK) >> LS7A_DMA_NODE_SHF) + 36;
4030
}

arch/loongarch/kernel/setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ static void __init arch_mem_init(char **cmdline_p)
247247
sparse_init();
248248
memblock_set_bottom_up(true);
249249

250-
plat_swiotlb_setup();
250+
swiotlb_init(true, SWIOTLB_VERBOSE);
251251

252252
dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
253253

include/linux/acpi.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,17 @@ acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa) { }
279279

280280
void acpi_numa_x2apic_affinity_init(struct acpi_srat_x2apic_cpu_affinity *pa);
281281

282+
#if defined(CONFIG_ARM64) || defined(CONFIG_LOONGARCH)
283+
void acpi_arch_dma_setup(struct device *dev);
284+
#else
285+
static inline void acpi_arch_dma_setup(struct device *dev) { }
286+
#endif
287+
282288
#ifdef CONFIG_ARM64
283289
void acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa);
284-
void acpi_arch_dma_setup(struct device *dev);
285290
#else
286291
static inline void
287292
acpi_numa_gicc_affinity_init(struct acpi_srat_gicc_affinity *pa) { }
288-
static inline void
289-
acpi_arch_dma_setup(struct device *dev) { }
290293
#endif
291294

292295
int acpi_numa_memory_affinity_init (struct acpi_srat_mem_affinity *ma);

0 commit comments

Comments
 (0)