Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3266466ybb; Sun, 22 Mar 2020 20:01:23 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuuAilS2/kABm60sdZ7n+EY4k604edQXeVK2K2/goXjqhllOmnmGKYWc0gcuiY7zwtUtsx0 X-Received: by 2002:a9d:32a4:: with SMTP id u33mr3454626otb.23.1584932482891; Sun, 22 Mar 2020 20:01:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584932482; cv=none; d=google.com; s=arc-20160816; b=nHRqx4HlLt0OxI0FDXMW3r6Okb3/TqFoIZ/Oc0OVkp6pwYSaQ12ZeiIH3xhzs2MRS9 GxDu+Qa8CxgxJl1wbfLRdC0oq7fz1nQYThUBCDfCUlhOWumzmOdb6UFw2ALY7QFb8i+x 9FX8SL8yBA2GhsfnCd/a6RcruAd4aWDy3WohaEJJ29bq2YNZub2ZJeEjAjHhPzlMk/8F Toap4awv6ACdrcZmRhrmLtigoHMaXbdO0ioKy4qyG2zM5C0UMQOkbGLGrrkYPWKVfBXj EzTCxqyJ/8pxjw0Nj0ttzjfU7GmDZAlECFZP4X7+SbqFxBz5uzhnvFNviI/6ajAXYEtb 8www== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=oKSz5Er/PZGTGwLEZ1Cf70Ae5KO8t70r8jwfvx7oOm4=; b=VMeQYaa5PX/Co1Ydk0ceuqzNqwWz+j5x8n5Dq+dJsyKNnJhDjfLymoYUx1HsrGD1/N G26zddFp8+2Z+aPiR8T6rZqf4nBfWwF14UT2ilqdkTAWtiQ3yXOqxEMceuifguBm4MtP 4fSCxwUffH87jdrrSXgnfoumYx6thaPlJP3RJ+L7cd2NV2xxiMIdy0iX+urdf031BHSj 0ANzRH0Uh8Q2kFs2xvW9SlTb6T/l/c+5DqsptlLu0c/1J4gXeHT6nwJTXZ4thiM8cm4O mLxdLGCHJPxNBrD+rBowpTzfbub2fws2T4MW55MVFuu+GKfPItd/FYhUYB1EHLFkHtMi 6pcg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u191si7179745oia.148.2020.03.22.20.01.10; Sun, 22 Mar 2020 20:01:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727149AbgCWC7Y (ORCPT + 99 others); Sun, 22 Mar 2020 22:59:24 -0400 Received: from mail.loongson.cn ([114.242.206.163]:56012 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726983AbgCWC7Y (ORCPT ); Sun, 22 Mar 2020 22:59:24 -0400 Received: from linux.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxP+gDJnhedaseAA--.407S4; Mon, 23 Mar 2020 10:59:18 +0800 (CST) From: Tiezhu Yang To: Thomas Bogendoerfer , Huacai Chen , Jiaxun Yang Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Xuefeng Li Subject: [PATCH v2 2/3] MIPS: Loongson: Add DMA support for 7A1000 Date: Mon, 23 Mar 2020 10:59:14 +0800 Message-Id: <1584932355-3642-3-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1584932355-3642-1-git-send-email-yangtiezhu@loongson.cn> References: <1584932355-3642-1-git-send-email-yangtiezhu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UMIIF0xvEx4 A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUnqXdUUUUU= X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement __phys_to_dma() and __dma_to_phys() according to the node id offset in the 7A1000 DMA route config register. Signed-off-by: Tiezhu Yang --- arch/mips/include/asm/mach-loongson64/boot_param.h | 5 +++++ arch/mips/loongson64/dma.c | 9 ++++++--- arch/mips/loongson64/env.c | 2 ++ arch/mips/loongson64/init.c | 17 +++++++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/arch/mips/include/asm/mach-loongson64/boot_param.h b/arch/mips/include/asm/mach-loongson64/boot_param.h index 5e8c70d..c759b7c 100644 --- a/arch/mips/include/asm/mach-loongson64/boot_param.h +++ b/arch/mips/include/asm/mach-loongson64/boot_param.h @@ -219,9 +219,14 @@ struct loongson_system_configuration { u32 nr_sensors; struct sensor_device sensors[MAX_SENSORS]; u64 workarounds; + void (*early_config)(void); }; extern struct efi_memory_map_loongson *loongson_memmap; extern struct loongson_system_configuration loongson_sysconf; +extern u32 node_id_offset; +extern void rs780e_early_config(void); +extern void ls7a1000_early_config(void); + #endif diff --git a/arch/mips/loongson64/dma.c b/arch/mips/loongson64/dma.c index 5e86635..dbfe6e8 100644 --- a/arch/mips/loongson64/dma.c +++ b/arch/mips/loongson64/dma.c @@ -2,21 +2,24 @@ #include #include #include +#include dma_addr_t __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); + + return ((nid << 44) ^ paddr) | (nid << node_id_offset); } phys_addr_t __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); + long nid = (daddr >> node_id_offset) & 0x3; + + return ((nid << node_id_offset) ^ daddr) | (nid << 44); } void __init plat_swiotlb_setup(void) diff --git a/arch/mips/loongson64/env.c b/arch/mips/loongson64/env.c index 42542c7..32a3822 100644 --- a/arch/mips/loongson64/env.c +++ b/arch/mips/loongson64/env.c @@ -167,8 +167,10 @@ void __init prom_init_env(void) if (vendor == 0x0014 && device == 0x7a00) { pr_info("The bridge chip is Loongson 7A1000\n"); loongson_sysconf.bridgetype = LS7A1000; + loongson_sysconf.early_config = ls7a1000_early_config; } else { pr_info("The bridge chip is AMD RS780E or SR5690\n"); loongson_sysconf.bridgetype = RS780E; + loongson_sysconf.early_config = rs780e_early_config; } } diff --git a/arch/mips/loongson64/init.c b/arch/mips/loongson64/init.c index 5ac1a0f..0b6493b 100644 --- a/arch/mips/loongson64/init.c +++ b/arch/mips/loongson64/init.c @@ -12,6 +12,11 @@ #include #include +#include + +#define NODE_ID_OFFSET_ADDR 0x90000e001001041c + +u32 node_id_offset; static void __init mips_nmi_setup(void) { @@ -23,6 +28,16 @@ static void __init mips_nmi_setup(void) flush_icache_range((unsigned long)base, (unsigned long)base + 0x80); } +void rs780e_early_config(void) +{ + node_id_offset = 37; +} + +void ls7a1000_early_config(void) +{ + node_id_offset = ((readl((u32 *)NODE_ID_OFFSET_ADDR) >> 8) & 0x1f) + 36; +} + void __init prom_init(void) { fw_init_cmdline(); @@ -32,6 +47,8 @@ void __init prom_init(void) set_io_port_base((unsigned long) ioremap(LOONGSON_PCIIO_BASE, LOONGSON_PCIIO_SIZE)); + loongson_sysconf.early_config(); + prom_init_numa_memory(); /* Hardcode to CPU UART 0 */ -- 2.1.0