All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Fenkart <afenkart@gmail.com>
To: Tony Lindgren <tony@atomide.com>
Cc: Chris Ball <chris@printf.net>,
	Grant Likely <grant.likely@secretlab.ca>,
	Felipe Balbi <balbi@ti.com>, Balaji T K <balajitk@ti.com>,
	Andreas Mueller <schnitzeltony@googlemail.com>,
	zonque@gmail.com, galak@codeaurora.org,
	linux-doc@vger.kernel.org, linux-mmc@vger.kernel.org,
	linux-omap@vger.kernel.org, Andreas Fenkart <afenkart@gmail.com>
Subject: [PATCH v11 5/7] mmc: omap_hsmmc: abort runtime suspend if pending sdio irq detected
Date: Fri,  9 May 2014 01:20:32 +0200	[thread overview]
Message-ID: <1399591234-13089-5-git-send-email-afenkart@gmail.com> (raw)
In-Reply-To: <1399591234-13089-1-git-send-email-afenkart@gmail.com>

On multicores, an sdio irq handler could be running in parallel to
runtime suspend. In the worst case it could be waiting for the spinlock
held by the runtime suspend. When runtime suspend is complete and the
functional clock (fclk) turned off, the irq handler will continue and
cause a SIGBUS on the first register access.

Signed-off-by: Andreas Fenkart <afenkart@gmail.com>

diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index 14857d7..47a5982 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -134,6 +134,9 @@ static void apply_clk_hack(struct device *dev)
 #define SRD			(1 << 26)
 #define SOFTRESET		(1 << 1)
 
+/* PSTATE */
+#define DLEV_DAT(x)		(1 << (20 + (x)))
+
 /* Interrupt masks for IE and ISE register */
 #define CC_EN			(1 << 0)
 #define TC_EN			(1 << 1)
@@ -2455,6 +2458,7 @@ static int omap_hsmmc_runtime_suspend(struct device *dev)
 {
 	struct omap_hsmmc_host *host;
 	unsigned long flags;
+	int ret = 0;
 
 	host = platform_get_drvdata(to_platform_device(dev));
 	omap_hsmmc_context_save(host);
@@ -2466,14 +2470,29 @@ static int omap_hsmmc_runtime_suspend(struct device *dev)
 		/* disable sdio irq handling to prevent race */
 		OMAP_HSMMC_WRITE(host->base, ISE, 0);
 		OMAP_HSMMC_WRITE(host->base, IE, 0);
-		OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
+
+		if (!(OMAP_HSMMC_READ(host->base, PSTATE) & DLEV_DAT(1))) {
+			/*
+			 * dat1 line low, pending sdio irq
+			 * race condition: possible irq handler running on
+			 * multi-core, abort
+			 */
+			dev_dbg(dev, "pending sdio irq, abort suspend\n");
+			OMAP_HSMMC_WRITE(host->base, STAT, STAT_CLEAR);
+			OMAP_HSMMC_WRITE(host->base, ISE, CIRQ_EN);
+			OMAP_HSMMC_WRITE(host->base, IE, CIRQ_EN);
+			pm_runtime_mark_last_busy(dev);
+			ret = -EBUSY;
+			goto abort;
+		}
 
 		WARN_ON(host->flags & HSMMC_WAKE_IRQ_ENABLED);
 		enable_irq(host->wake_irq);
 		host->flags |= HSMMC_WAKE_IRQ_ENABLED;
 	}
+abort:
 	spin_unlock_irqrestore(&host->irq_lock, flags);
-	return 0;
+	return ret;
 }
 
 static int omap_hsmmc_runtime_resume(struct device *dev)
-- 
1.7.10.4


  parent reply	other threads:[~2014-05-08 23:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-08 23:16 [PATCH v11 0/7] mmc: omap_hsmmc: Enable SDIO IRQ Andreas Fenkart
2014-05-08 23:20 ` [PATCH v11 1/7] mmc: omap_hsmmc: compile fix for !CONFIG_OF build Andreas Fenkart
2014-05-08 23:20   ` [PATCH v11 2/7] mmc: omap_hsmmc: Enable SDIO interrupt Andreas Fenkart
2014-05-09 17:09     ` Balaji T K
2014-05-08 23:20   ` [PATCH v11 3/7] mmc: omap_hsmmc: enable wakeup event for sdio OMAP4 Andreas Fenkart
2014-05-08 23:20   ` [PATCH v11 4/7] mmc: omap_hsmmc: Extend debugfs by SDIO IRQ handling, runtime state Andreas Fenkart
2014-05-09 17:10     ` Balaji T K
2014-05-08 23:20   ` Andreas Fenkart [this message]
2014-05-09 17:10     ` [PATCH v11 5/7] mmc: omap_hsmmc: abort runtime suspend if pending sdio irq detected Balaji T K
2014-05-08 23:20   ` [PATCH v11 6/7] mmc: omap_hsmmc: switch default/idle pinctrl states in runtime hooks Andreas Fenkart
2014-05-09 17:11     ` Balaji T K
2014-05-08 23:20   ` [PATCH v11 7/7] mmc: omap_hsmmc: Pin remux workaround to support SDIO interrupt on AM335x Andreas Fenkart
2014-05-09 17:11     ` Balaji T K
2014-05-08 23:48   ` [PATCH v11 1/7] mmc: omap_hsmmc: compile fix for !CONFIG_OF build Sebastian Reichel

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=1399591234-13089-5-git-send-email-afenkart@gmail.com \
    --to=afenkart@gmail.com \
    --cc=balajitk@ti.com \
    --cc=balbi@ti.com \
    --cc=chris@printf.net \
    --cc=galak@codeaurora.org \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=schnitzeltony@googlemail.com \
    --cc=tony@atomide.com \
    --cc=zonque@gmail.com \
    /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.