linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Brodkin <Alexey.Brodkin@synopsys.com>
To: linux-snps-arc@lists.infradead.org
Cc: linux-kernel@vger.kernel.org,
	Vineet Gupta <Vineet.Gupta1@synopsys.com>,
	Alexey Brodkin <Alexey.Brodkin@synopsys.com>
Subject: [PATCH v2] ARC: Force disable IOC if we don't want to use it
Date: Mon, 18 Dec 2017 18:29:20 +0300	[thread overview]
Message-ID: <20171218152920.4696-1-abrodkin@synopsys.com> (raw)

If software that was executed before Linux kernel [like boot-ROM or
bootloader] enabled IOC but we'd like to not use it [mostly for
debugging of weird DMA issues] we essentially need to disable IOC.
So we do here.

Note we will only disable IOC if "ioc_enable" variable is force set to 0.
As of today that's only possible either before building right in
arch/arc/mm/cache.c or via debugger on target reght before execution of
the kernel starts.

We may make "ioc_enable" a boot-parameter later though.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
---

Chnages in v2:
 * Now disabling really works as in v1 we never entered
   disabling code if ioc_enable=0.
 * Do nothing if IOC was not enabled

 arch/arc/mm/cache.c | 42 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 40 insertions(+), 2 deletions(-)

diff --git a/arch/arc/mm/cache.c b/arch/arc/mm/cache.c
index 69f77c113875..9cadf7b779ed 100644
--- a/arch/arc/mm/cache.c
+++ b/arch/arc/mm/cache.c
@@ -1186,6 +1186,40 @@ noinline void __init arc_ioc_setup(void)
 	__dc_enable();
 }
 
+/*
+ * Disabling of IOC is quite a tricky action because
+ * nobody knows what happens if there're IOC-ahndled tarnsactions in flight
+ * when we're disabling IOC.
+ *
+ * And the problem is external DMA masters [that were initialized and set in a
+ * bootlaoder that was executed before we got here] might continue to send data
+ * to memory even at this point and we have no way to prevent that.
+ *
+ * That said it's much safer to not enable IOC at all anywhere before
+ * in boot-ROM, bootloader etc but if we do need to disable it in Linux kernel
+ * it should be done as early as possible and made by master core while all
+ * slaves aren't active.
+ *
+ */
+noinline void __init arc_ioc_disable(void)
+{
+	/* Exit if IOC was never enabled */
+	if (!read_aux_reg(ARC_REG_IO_COH_ENABLE))
+		return;
+
+	/* Flush + invalidate + disable L1 dcache */
+	__dc_disable();
+
+	/* Flush + invalidate SLC */
+	if (read_aux_reg(ARC_REG_SLC_BCR))
+		slc_entire_op(OP_FLUSH_N_INV);
+
+	write_aux_reg(ARC_REG_IO_COH_ENABLE, 0);
+
+	/* Re-enable L1 dcache */
+	__dc_enable();
+}
+
 /*
  * Cache related boot time checks/setups only needed on master CPU:
  *  - Geometry checks (kernel build and hardware agree: e.g. L1_CACHE_BYTES)
@@ -1247,8 +1281,12 @@ void __init arc_cache_init_master(void)
 	if (is_isa_arcv2() && l2_line_sz && !slc_enable)
 		arc_slc_disable();
 
-	if (is_isa_arcv2() && ioc_enable)
-		arc_ioc_setup();
+	if (is_isa_arcv2()) {
+		if (ioc_enable)
+			arc_ioc_setup();
+		else if (ioc_exists)
+			arc_ioc_disable();
+	}
 
 	if (is_isa_arcv2() && ioc_enable) {
 		__dma_cache_wback_inv = __dma_cache_wback_inv_ioc;
-- 
2.14.3

             reply	other threads:[~2017-12-18 15:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-18 15:29 Alexey Brodkin [this message]
2018-01-19 19:17 ` [PATCH v2] ARC: Force disable IOC if we don't want to use it Vineet Gupta
2018-01-19 19:23   ` Alexey Brodkin

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=20171218152920.4696-1-abrodkin@synopsys.com \
    --to=alexey.brodkin@synopsys.com \
    --cc=Vineet.Gupta1@synopsys.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-snps-arc@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).