mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: "Stuart Hayes" <stuart.w.hayes@gmail.com>,
	"Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Andrew Morton" <akpm@osdl.org>,
	"Doug Warzecha" <Douglas_Warzecha@dell.com>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>
Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/4] platform/x86: dell: dcdbas: Actually wait for the host control SMI
Date: Mon, 16 Nov 2026 12:40:49 -0800	[thread overview]
Message-ID: <62690b76d5cb95113b01092c8e3944fbb21a0922.1794861287.git.rosenp@gmail.com> (raw)
In-Reply-To: <cover.1794861287.git.rosenp@gmail.com>

For SMI types 2 and 3, host_control_smi() writes the command status as
-1, raises the SMI and then waits for the BIOS to change the status:

	while (apm_cmd->status == ESM_STATUS_CMD_UNSUCCESSFUL) {

apm_cmd->status is a plain memory read, and neither outb() nor inb()
tells the compiler that memory may have changed, so the compiler
assumes status is still -1. The loop then has no side effects and its
return value is not used, so it is removed entirely: in the generated
code, the read of the control port is followed directly by the return.
The kernel goes on to power off right after raising the host control
SMI, without waiting for the BIOS to accept it.

The type 1 wait polls the APM status port instead, in a loop that
counts down TIMEOUT_USEC_SHORT_SEMA_BLOCKING iterations and relies on
each inb() taking about a microsecond.

Convert both waits to read_poll_timeout_atomic(), using READ_ONCE() for
the status in memory and inb() for the status port, 1us apart for up to
TIMEOUT_USEC_SHORT_SEMA_BLOCKING microseconds as the name suggests, and
return its error. That is -ETIMEDOUT rather than -ETIME, but both
callers ignore the return value. With the delay plus the port read, the
type 1 worst-case wait grows from about 10ms to about 20ms, which only
matters when the BIOS never answers.

This removes the last users of num_ticks and EXPIRED_TIMER.

Fixes: 90563ec4129f ("[PATCH] dcdbas: add Dell Systems Management Base Driver with sysfs support")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/platform/x86/dell/dcdbas.c | 28 ++++++++++++++--------------
 drivers/platform/x86/dell/dcdbas.h |  1 -
 2 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/drivers/platform/x86/dell/dcdbas.c b/drivers/platform/x86/dell/dcdbas.c
index 678f44252a45..69365627fd8f 100644
--- a/drivers/platform/x86/dell/dcdbas.c
+++ b/drivers/platform/x86/dell/dcdbas.c
@@ -20,7 +20,7 @@
 #include <linux/cpu.h>
 #include <linux/gfp.h>
 #include <linux/init.h>
-#include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/kernel.h>
 #include <linux/mc146818rtc.h>
 #include <linux/module.h>
@@ -377,9 +377,9 @@ static int host_control_smi(void)
 	struct apm_cmd *apm_cmd;
 	u8 *data;
 	unsigned long flags;
-	u32 num_ticks;
 	s8 cmd_status;
 	u8 index;
+	int ret;
 
 	apm_cmd = (struct apm_cmd *)smi_buf.virt;
 	apm_cmd->status = ESM_STATUS_CMD_UNSUCCESSFUL;
@@ -407,12 +407,12 @@ static int host_control_smi(void)
 		spin_unlock_irqrestore(&rtc_lock, flags);
 
 		/* wait a few to see if it executed */
-		num_ticks = TIMEOUT_USEC_SHORT_SEMA_BLOCKING;
-		while ((s8)inb(PCAT_APM_STATUS_PORT) == ESM_STATUS_CMD_UNSUCCESSFUL) {
-			num_ticks--;
-			if (num_ticks == EXPIRED_TIMER)
-				return -ETIME;
-		}
+		ret = read_poll_timeout_atomic(inb, cmd_status,
+					       cmd_status != ESM_STATUS_CMD_UNSUCCESSFUL,
+					       1, TIMEOUT_USEC_SHORT_SEMA_BLOCKING,
+					       false, PCAT_APM_STATUS_PORT);
+		if (ret)
+			return ret;
 		break;
 
 	case HC_SMITYPE_TYPE2:
@@ -441,12 +441,12 @@ static int host_control_smi(void)
 		cmd_status = inb(PE1400_APM_CONTROL_PORT);
 
 		/* wait a few to see if it executed */
-		num_ticks = TIMEOUT_USEC_SHORT_SEMA_BLOCKING;
-		while (apm_cmd->status == ESM_STATUS_CMD_UNSUCCESSFUL) {
-			num_ticks--;
-			if (num_ticks == EXPIRED_TIMER)
-				return -ETIME;
-		}
+		ret = read_poll_timeout_atomic(READ_ONCE, cmd_status,
+					       cmd_status != ESM_STATUS_CMD_UNSUCCESSFUL,
+					       1, TIMEOUT_USEC_SHORT_SEMA_BLOCKING,
+					       false, apm_cmd->status);
+		if (ret)
+			return ret;
 		break;
 
 	default:
diff --git a/drivers/platform/x86/dell/dcdbas.h b/drivers/platform/x86/dell/dcdbas.h
index a05d7f667586..d5ad2363dd9e 100644
--- a/drivers/platform/x86/dell/dcdbas.h
+++ b/drivers/platform/x86/dell/dcdbas.h
@@ -42,7 +42,6 @@
 #define MAX_SYSMGMT_LONGCMD_SGENTRY_NUM		(16)
 
 #define TIMEOUT_USEC_SHORT_SEMA_BLOCKING	(10000)
-#define EXPIRED_TIMER				(0)
 
 #define SMI_CMD_MAGIC				(0x534D4931)
 #define SMM_EPS_SIG				"$SCB"
-- 
2.56.1


  reply	other threads:[~2026-11-16 20:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 20:40 [PATCH v2 0/4] platform/x86: dell: dcdbas: Fix SMI completion wait and buffer handling Rosen Penev
2026-11-16 20:40 ` Rosen Penev [this message]
2026-11-16 20:40 ` [PATCH v2 2/4] platform/x86: dell: dcdbas: Suppress bind attributes of the platform driver Rosen Penev
2026-11-16 20:40 ` [PATCH v2 3/4] platform/x86: dell: dcdbas: Release the SMI buffer in remove Rosen Penev
2026-11-16 20:40 ` [PATCH v2 4/4] platform/x86: dell: dcdbas: Validate the WSMT buffer description Rosen Penev

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=62690b76d5cb95113b01092c8e3944fbb21a0922.1794861287.git.rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --cc=Douglas_Warzecha@dell.com \
    --cc=akpm@osdl.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=stuart.w.hayes@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®