Skip to content

Commit

Permalink
LoongArch: use arch specific phys_to_dma
Browse files Browse the repository at this point in the history
To be compatible with OLD firmware which has no _DMA method,
we should use arch specific phys_to_dma.

Signed-off-by: Hongchen Zhang <[email protected]>
Signed-off-by: Yanteng Si <[email protected]>
  • Loading branch information
Yanteng Si committed May 11, 2024
1 parent e5136c9 commit ec2da5f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions arch/loongarch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ config LOONGARCH
select HAVE_SAMPLE_FTRACE_DIRECT_MULTI
select HAVE_SETUP_PER_CPU_AREA if NUMA
select HAVE_STACKPROTECTOR
select ARCH_HAS_PHYS_TO_DMA
select HAVE_SYSCALL_TRACEPOINTS
select HAVE_TIF_NOHZ
select HAVE_VIRT_CPU_ACCOUNTING_GEN if !SMP
Expand Down
27 changes: 27 additions & 0 deletions arch/loongarch/kernel/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,40 @@
*/
#include <linux/acpi.h>
#include <linux/dma-direct.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)
{
long nid = (daddr >> node_id_offset) & 0xf;

return ((nid << node_id_offset) ^ daddr) | (nid << 44);
}

void acpi_arch_dma_setup(struct device *dev)
{
int ret;
u64 mask, end = 0;
const struct bus_dma_region *map = NULL;

if (node_id_offset == 0) {
node_id_offset = ((readl(LS7A_DMA_CFG) & LS7A_DMA_NODE_MASK) >> LS7A_DMA_NODE_SHF);
node_id_offset += 36;
}

ret = acpi_dma_get_range(dev, &map);
if (!ret && map) {
const struct bus_dma_region *r = map;
Expand Down

0 comments on commit ec2da5f

Please sign in to comment.