From patchwork Mon Jan 13 14:07:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 11330281 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF32E184C for ; Mon, 13 Jan 2020 14:07:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ADD67207FD for ; Mon, 13 Jan 2020 14:07:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="qZF6AX80" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726943AbgAMOHw (ORCPT ); Mon, 13 Jan 2020 09:07:52 -0500 Received: from forward102j.mail.yandex.net ([5.45.198.243]:58861 "EHLO forward102j.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728801AbgAMOHw (ORCPT ); Mon, 13 Jan 2020 09:07:52 -0500 Received: from mxback13j.mail.yandex.net (mxback13j.mail.yandex.net [IPv6:2a02:6b8:0:1619::88]) by forward102j.mail.yandex.net (Yandex) with ESMTP id 54AD9F21435; Mon, 13 Jan 2020 17:07:49 +0300 (MSK) Received: from myt2-ea6a2e0cbf34.qloud-c.yandex.net (myt2-ea6a2e0cbf34.qloud-c.yandex.net [2a02:6b8:c00:2e8e:0:640:ea6a:2e0c]) by mxback13j.mail.yandex.net (mxback/Yandex) with ESMTP id 7umar6yfM8-7n6888lG; Mon, 13 Jan 2020 17:07:49 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; s=mail; t=1578924469; bh=RmsVJbxfmJIPyEANphpuUuv7UaSpvPm9q6Y+Misk4d8=; h=Subject:To:From:Cc:Date:Message-Id; b=qZF6AX80hM491dl4ZurWUU4lIMkEHWZ2xq6wH4E+iLY5NJlzHN7IPzV5B65nwm7W3 QZ1ChF6oqNs/jIs+8zVyiGAhK6lKva7bSvYf5NWYpzdQsZ/49rItwIoBvBmDq2tIP4 7I+umMjtruhdpvIoUBWt+AOooerJVq3NyBDMuj+Q= Authentication-Results: mxback13j.mail.yandex.net; dkim=pass header.i=@flygoat.com Received: by myt2-ea6a2e0cbf34.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id pGFN2nLtP9-7aV4FhvH; Mon, 13 Jan 2020 17:07:45 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) From: Jiaxun Yang To: linux-mips@vger.kernel.org Cc: chenhc@lemote.com, paul.burton@mips.com, linux-kernel@vger.kernel.org, hch@lst.de, Jiaxun Yang Subject: [PATCH 1/2] MIPS: Define pgprot_dmacoherent according to coherentio status Date: Mon, 13 Jan 2020 22:07:04 +0800 Message-Id: <20200113140705.74605-1-jiaxun.yang@flygoat.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org For MIPS chips that support coherentio DMA, it's always safe to make DMA requests cached. Signed-off-by: Jiaxun Yang --- arch/mips/include/asm/dma-coherence.h | 14 ++++++++++++++ arch/mips/kernel/setup.c | 1 + 2 files changed, 15 insertions(+) diff --git a/arch/mips/include/asm/dma-coherence.h b/arch/mips/include/asm/dma-coherence.h index 5eaa1fcc878a..bc0df7684cae 100644 --- a/arch/mips/include/asm/dma-coherence.h +++ b/arch/mips/include/asm/dma-coherence.h @@ -9,6 +9,8 @@ #ifndef __ASM_DMA_COHERENCE_H #define __ASM_DMA_COHERENCE_H +#include + enum coherent_io_user_state { IO_COHERENCE_DEFAULT, IO_COHERENCE_ENABLED, @@ -35,4 +37,16 @@ static inline bool dev_is_dma_coherent(struct device *dev) #define hw_coherentio 0 #endif /* CONFIG_DMA_MAYBE_COHERENT */ +#if !defined(CONFIG_DMA_PERDEV_COHERENT) +#define pgprot_dmacoherent pgprot_dmacoherent +static inline pgprot_t pgprot_dmacoherent(pgprot_t prot) +{ + if (coherentio == IO_COHERENCE_ENABLED || + (coherentio == IO_COHERENCE_DEFAULT && hw_coherentio)) + return prot; + + return pgprot_noncached(prot); +} +#endif + #endif diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 701f4bc3046f..01f725819df7 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -831,6 +831,7 @@ arch_initcall(debugfs_mips); enum coherent_io_user_state coherentio = IO_COHERENCE_DEFAULT; EXPORT_SYMBOL_GPL(coherentio); int hw_coherentio = 0; /* Actual hardware supported DMA coherency setting. */ +EXPORT_SYMBOL_GPL(hw_coherentio); static int __init setcoherentio(char *str) { From patchwork Mon Jan 13 14:07:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 11330283 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D86236C1 for ; Mon, 13 Jan 2020 14:08:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B713721569 for ; Mon, 13 Jan 2020 14:08:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=flygoat.com header.i=@flygoat.com header.b="Isuc29Uk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726074AbgAMOIG (ORCPT ); Mon, 13 Jan 2020 09:08:06 -0500 Received: from forward102o.mail.yandex.net ([37.140.190.182]:44326 "EHLO forward102o.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727331AbgAMOIF (ORCPT ); Mon, 13 Jan 2020 09:08:05 -0500 Received: from mxback10j.mail.yandex.net (mxback10j.mail.yandex.net [IPv6:2a02:6b8:0:1619::113]) by forward102o.mail.yandex.net (Yandex) with ESMTP id EE0DF66816C5; Mon, 13 Jan 2020 17:08:01 +0300 (MSK) Received: from myt2-ea6a2e0cbf34.qloud-c.yandex.net (myt2-ea6a2e0cbf34.qloud-c.yandex.net [2a02:6b8:c00:2e8e:0:640:ea6a:2e0c]) by mxback10j.mail.yandex.net (mxback/Yandex) with ESMTP id BrUeFl0CRC-81tWxxKR; Mon, 13 Jan 2020 17:08:01 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; s=mail; t=1578924481; bh=jn8kO6Zo5FK80mQbvcSVlvwdlwIvCB39JSX6YNLW/M8=; h=In-Reply-To:Subject:To:From:Cc:References:Date:Message-Id; b=Isuc29UkGeRRoYHM7UwmOyn9olVu70/NRKpLrAfixWNnLSZs4cPF3qYqfedEhrb1t osHjgu1J6aBq5eXqBAw7EwJZKf4/6LzCL/w5yj+DFx+c4d+ooBc7vEhhDe3ux1o9WN GJfOHtQ0kOJm68HBcAkNq8QaExrZpgL5EdxmGrFA= Authentication-Results: mxback10j.mail.yandex.net; dkim=pass header.i=@flygoat.com Received: by myt2-ea6a2e0cbf34.qloud-c.yandex.net (smtp/Yandex) with ESMTPSA id pGFN2nLtP9-7oV4cj99; Mon, 13 Jan 2020 17:07:59 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) From: Jiaxun Yang To: linux-mips@vger.kernel.org Cc: chenhc@lemote.com, paul.burton@mips.com, linux-kernel@vger.kernel.org, hch@lst.de, Jiaxun Yang Subject: [PATCH 2/2] MIPS: Loongson64: Add dma iocoherency detection support Date: Mon, 13 Jan 2020 22:07:05 +0800 Message-Id: <20200113140705.74605-2-jiaxun.yang@flygoat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200113140705.74605-1-jiaxun.yang@flygoat.com> References: <20200113140705.74605-1-jiaxun.yang@flygoat.com> MIME-Version: 1.0 Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org Set hw_iocoherency according to parameter passed from firmware. Signed-off-by: Jiaxun Yang --- arch/mips/Kconfig | 1 + arch/mips/include/asm/mach-loongson64/boot_param.h | 5 +++-- arch/mips/loongson64/env.c | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig index d0b727daddb3..8b0cd692a43f 100644 --- a/arch/mips/Kconfig +++ b/arch/mips/Kconfig @@ -474,6 +474,7 @@ config MACH_LOONGSON64 select CSRC_R4K select CEVT_R4K select CPU_HAS_WB + select DMA_MAYBE_COHERENT select FORCE_PCI select ISA select I8259 diff --git a/arch/mips/include/asm/mach-loongson64/boot_param.h b/arch/mips/include/asm/mach-loongson64/boot_param.h index 8c286bedff3e..2da2be40ad81 100644 --- a/arch/mips/include/asm/mach-loongson64/boot_param.h +++ b/arch/mips/include/asm/mach-loongson64/boot_param.h @@ -115,7 +115,8 @@ struct irq_source_routing_table { u64 pci_io_start_addr; u64 pci_io_end_addr; u64 pci_config_addr; - u32 dma_mask_bits; + u16 dma_mask_bits; + u16 dma_noncoherent; } __packed; struct interface_info { @@ -206,7 +207,7 @@ struct loongson_system_configuration { u64 poweroff_addr; u64 suspend_addr; u64 vgabios_addr; - u32 dma_mask_bits; + u16 dma_mask_bits; char ecname[32]; u32 nr_uarts; struct uart_device uarts[MAX_UARTS]; diff --git a/arch/mips/loongson64/env.c b/arch/mips/loongson64/env.c index 0daeb7bcf023..61e3d4874fe9 100644 --- a/arch/mips/loongson64/env.c +++ b/arch/mips/loongson64/env.c @@ -15,6 +15,7 @@ */ #include #include +#include #include #include #include @@ -128,6 +129,9 @@ void __init prom_init_env(void) loongson_sysconf.dma_mask_bits > 64) loongson_sysconf.dma_mask_bits = 32; + hw_coherentio = !eirq_source->dma_noncoherent; + pr_info("Firmware I/O coherency: %s\n", hw_coherentio?"ON":"OFF"); + loongson_sysconf.restart_addr = boot_p->reset_system.ResetWarm; loongson_sysconf.poweroff_addr = boot_p->reset_system.Shutdown; loongson_sysconf.suspend_addr = boot_p->reset_system.DoSuspend;