From: Tiezhu Yang <yangtiezhu@loongson.cn>
To: Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
Huacai Chen <chenhc@lemote.com>,
Jiaxun Yang <jiaxun.yang@flygoat.com>,
Bjorn Helgaas <bhelgaas@google.com>, Jens Axboe <axboe@kernel.dk>
Cc: linux-mips@vger.kernel.org, linux-pci@vger.kernel.org,
linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org,
Xuefeng Li <lixuefeng@loongson.cn>
Subject: [PATCH 4/6] MIPS: Loongson: Add DMA support for 7A1000
Date: Mon, 9 Mar 2020 16:23:24 +0800 [thread overview]
Message-ID: <1583742206-29163-5-git-send-email-yangtiezhu@loongson.cn> (raw)
In-Reply-To: <1583742206-29163-1-git-send-email-yangtiezhu@loongson.cn>
Implement __phys_to_dma() and __dma_to_phys() according to the
node id offset in 7A1000 DMA route config register.
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
arch/mips/include/asm/mach-loongson64/boot_param.h | 1 +
arch/mips/loongson64/dma.c | 49 +++++++++++++++++++++-
arch/mips/loongson64/init.c | 13 ++++++
3 files changed, 61 insertions(+), 2 deletions(-)
diff --git a/arch/mips/include/asm/mach-loongson64/boot_param.h b/arch/mips/include/asm/mach-loongson64/boot_param.h
index 225a563..60e7a7e 100644
--- a/arch/mips/include/asm/mach-loongson64/boot_param.h
+++ b/arch/mips/include/asm/mach-loongson64/boot_param.h
@@ -218,5 +218,6 @@ struct loongson_system_configuration {
extern struct efi_memory_map_loongson *loongson_memmap;
extern struct loongson_system_configuration loongson_sysconf;
extern struct board_devices *eboard;
+extern u32 node_id_offset;
#endif
diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c
index 5e86635..997c257 100644
--- a/arch/mips/loongson64/dma.c
+++ b/arch/mips/loongson64/dma.c
@@ -2,24 +2,69 @@
#include <linux/dma-direct.h>
#include <linux/init.h>
#include <linux/swiotlb.h>
+#include <boot_param.h>
-dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
+struct loongson_dma_ops {
+ dma_addr_t (*phys_to_dma)(struct device *dev, phys_addr_t paddr);
+ phys_addr_t (*dma_to_phys)(struct device *dev, dma_addr_t daddr);
+};
+
+struct loongson_dma_ops loongson_dma;
+
+dma_addr_t __rs780e_phys_to_dma(struct device *dev, phys_addr_t paddr)
{
/* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
* Loongson-3's 48bit address space and embed it into 40bit */
long nid = (paddr >> 44) & 0x3;
+
return ((nid << 44) ^ paddr) | (nid << 37);
}
-phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
+dma_addr_t __ls7a_phys_to_dma(struct device *dev, phys_addr_t paddr)
+{
+ long nid = (paddr >> 44) & 0x3;
+
+ return ((nid << 44) ^ paddr) | (nid << (36 + node_id_offset));
+}
+
+
+dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
+{
+ return loongson_dma.phys_to_dma(dev, paddr);
+}
+
+phys_addr_t __rs780e_dma_to_phys(struct device *dev, dma_addr_t daddr)
{
/* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
* Loongson-3's 48bit address space and embed it into 40bit */
long nid = (daddr >> 37) & 0x3;
+
return ((nid << 37) ^ daddr) | (nid << 44);
}
+phys_addr_t __ls7a_dma_to_phys(struct device *dev, dma_addr_t daddr)
+{
+ long nid = (daddr >> (36 + node_id_offset)) & 0x3;
+
+ return ((nid << (36 + node_id_offset)) ^ daddr) | (nid << 44);
+}
+
+phys_addr_t __dma_to_phys(struct device *dev, dma_addr_t daddr)
+{
+ return loongson_dma.dma_to_phys(dev, daddr);
+}
+
void __init plat_swiotlb_setup(void)
{
swiotlb_init(1);
+
+ if (strstr(eboard->name, "780E")) {
+ loongson_dma.phys_to_dma = __rs780e_phys_to_dma;
+ loongson_dma.dma_to_phys = __rs780e_dma_to_phys;
+ }
+
+ if (strstr(eboard->name, "7A1000")) {
+ loongson_dma.phys_to_dma = __ls7a_phys_to_dma;
+ loongson_dma.dma_to_phys = __ls7a_dma_to_phys;
+ }
}
diff --git a/arch/mips/loongson64/init.c b/arch/mips/loongson64/init.c
index 5ac1a0f..dd8463d 100644
--- a/arch/mips/loongson64/init.c
+++ b/arch/mips/loongson64/init.c
@@ -12,6 +12,11 @@
#include <asm/fw/fw.h>
#include <loongson.h>
+#include <boot_param.h>
+
+#define NODE_ID_OFFSET_ADDR 0x90000E001001041CULL
+
+u32 node_id_offset;
static void __init mips_nmi_setup(void)
{
@@ -23,6 +28,11 @@ static void __init mips_nmi_setup(void)
flush_icache_range((unsigned long)base, (unsigned long)base + 0x80);
}
+static void ls7a_early_config(void)
+{
+ node_id_offset = (*(u32 *)NODE_ID_OFFSET_ADDR >> 8) & 0x1F;
+}
+
void __init prom_init(void)
{
fw_init_cmdline();
@@ -32,6 +42,9 @@ void __init prom_init(void)
set_io_port_base((unsigned long)
ioremap(LOONGSON_PCIIO_BASE, LOONGSON_PCIIO_SIZE));
+ if (strstr(eboard->name, "7A1000"))
+ ls7a_early_config();
+
prom_init_numa_memory();
/* Hardcode to CPU UART 0 */
--
2.1.0
next prev parent reply other threads:[~2020-03-09 8:23 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-09 8:23 [PATCH 0/6] Add basic support for Loongson 7A1000 bridge chip Tiezhu Yang
2020-03-09 8:23 ` [PATCH 1/6] PCI: Add Loongson vendor ID and 7A1000 device IDs Tiezhu Yang
2020-03-09 8:50 ` 回复:[PATCH " Jiaxun Yang
2020-03-10 2:31 ` Tiezhu Yang
2020-03-10 2:37 ` Jiaxun Yang
2020-03-10 9:28 ` Tiezhu Yang
2020-03-09 8:23 ` [PATCH 2/6] AHCI: Add support for Loongson 7A1000 SATA controller Tiezhu Yang
2020-03-09 8:23 ` [PATCH 3/6] MIPS: Loongson: Use firmware arguments to get board name Tiezhu Yang
2020-03-09 8:36 ` 回复:[PATCH " Jiaxun Yang
2020-03-10 2:38 ` Tiezhu Yang
2020-03-09 8:23 ` Tiezhu Yang [this message]
2020-03-09 8:44 ` 回复:[PATCH 4/6] MIPS: Loongson: Add DMA support for 7A1000 Jiaxun Yang
2020-03-10 2:40 ` Tiezhu Yang
2020-03-13 8:24 ` [PATCH " Christoph Hellwig
2020-03-13 9:03 ` Tiezhu Yang
2020-03-09 8:23 ` [PATCH 5/6] MIPS: Loongson: Add PCI " Tiezhu Yang
2020-03-09 8:47 ` 回复:[PATCH " Jiaxun Yang
2020-03-10 3:03 ` Tiezhu Yang
2020-03-09 8:23 ` [PATCH 6/6] MIPS: Loongson: Add support for 7A1000 interrupt controller Tiezhu Yang
2020-03-09 9:07 ` 回复:[PATCH " Jiaxun Yang
2020-03-10 4:28 ` Tiezhu Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1583742206-29163-5-git-send-email-yangtiezhu@loongson.cn \
--to=yangtiezhu@loongson.cn \
--cc=axboe@kernel.dk \
--cc=bhelgaas@google.com \
--cc=chenhc@lemote.com \
--cc=jiaxun.yang@flygoat.com \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lixuefeng@loongson.cn \
--cc=tsbogend@alpha.franken.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.