linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Jeff Garzik <jeff@garzik.org>
Cc: Frans Pop <elendil@planet.nl>,
	tj@kernel.org, akpm@linux-foundation.org,
	torvalds@linux-foundation.org, linux-ide@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 2/6] DMI: Introduce dmi_first_match to make the interface more flexible
Date: Mon, 19 Jan 2009 20:55:50 +0100	[thread overview]
Message-ID: <200901192055.51108.rjw@sisk.pl> (raw)
In-Reply-To: <200901192053.50831.rjw@sisk.pl>

From: Rafael J. Wysocki <rjw@sisk.pl>

Some notebooks from HP have the problem that their BIOSes attempt to
spin down hard drives before entering ACPI system states S4 and S5.
This leads to a yo-yo effect during system power-off shutdown and the
last phase of hibernation when the disk is first spun down by the
kernel and then almost immediately turned on and off by the BIOS.
This, in turn, may result in shortening the disk's life times.

To prevent this from happening we can blacklist the affected systems
using DMI information.  However, only the on-board controlles should
be blacklisted and their PCI slot numbers can be used for this
purpose.  Unfortunately the existing interface for checking DMI
information of the system is not very convenient for this purpose,
because to use it, we would have to define special callback functions
or create a separate struct dmi_system_id table for each blacklisted
system.

To overcome this difficulty introduce a new function
dmi_first_match() returning a pointer to the first entry in an array
of struct dmi_system_id elements that matches the system DMI
information.  Then, we can use this pointer to access the entry's
.driver_data field containing the additional information, such as
the PCI slot number, allowing us to do the desired blacklisting.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/firmware/dmi_scan.c |   72 +++++++++++++++++++++++++++++++++-----------
 include/linux/dmi.h         |    1 
 2 files changed, 55 insertions(+), 18 deletions(-)

Index: linux-2.6/drivers/firmware/dmi_scan.c
===================================================================
--- linux-2.6.orig/drivers/firmware/dmi_scan.c
+++ linux-2.6/drivers/firmware/dmi_scan.c
@@ -415,6 +415,29 @@ void __init dmi_scan_machine(void)
 }
 
 /**
+ *	dmi_matches - check if dmi_system_id structure matches system DMI data
+ *	@dmi: pointer to the dmi_system_id structure to check
+ */
+static bool dmi_matches(const struct dmi_system_id *dmi)
+{
+	int i;
+
+	WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n");
+
+	for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) {
+		int s = dmi->matches[i].slot;
+		if (s == DMI_NONE)
+			continue;
+		if (dmi_ident[s]
+		    && strstr(dmi_ident[s], dmi->matches[i].substr))
+			continue;
+		/* No match */
+		return false;
+	}
+	return true;
+}
+
+/**
  *	dmi_check_system - check system DMI data
  *	@list: array of dmi_system_id structures to match against
  *		All non-null elements of the list must match
@@ -429,32 +452,45 @@ void __init dmi_scan_machine(void)
  */
 int dmi_check_system(const struct dmi_system_id *list)
 {
-	int i, count = 0;
-	const struct dmi_system_id *d = list;
+	int count = 0;
+	const struct dmi_system_id *d;
 
-	WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n");
-
-	while (d->ident) {
-		for (i = 0; i < ARRAY_SIZE(d->matches); i++) {
-			int s = d->matches[i].slot;
-			if (s == DMI_NONE)
-				continue;
-			if (dmi_ident[s] && strstr(dmi_ident[s], d->matches[i].substr))
-				continue;
-			/* No match */
-			goto fail;
+	for (d = list; d->ident; d++)
+		if (dmi_matches(d)) {
+			count++;
+			if (d->callback && d->callback(d))
+				break;
 		}
-		count++;
-		if (d->callback && d->callback(d))
-			break;
-fail:		d++;
-	}
 
 	return count;
 }
 EXPORT_SYMBOL(dmi_check_system);
 
 /**
+ *	dmi_first_match - find dmi_system_id structure matching system DMI data
+ *	@list: array of dmi_system_id structures to match against
+ *		All non-null elements of the list must match
+ *		their slot's (field index's) data (i.e., each
+ *		list string must be a substring of the specified
+ *		DMI slot's string data) to be considered a
+ *		successful match.
+ *
+ *	Walk the blacklist table until the first match is found.  Return the
+ *	pointer to the matching entry or NULL if there's no match.
+ */
+const struct dmi_system_id *dmi_first_match(const struct dmi_system_id *list)
+{
+	const struct dmi_system_id *d;
+
+	for (d = list; d->ident; d++)
+		if (dmi_matches(d))
+			return d;
+
+	return NULL;
+}
+EXPORT_SYMBOL(dmi_first_match);
+
+/**
  *	dmi_get_system_info - return DMI data value
  *	@field: data index (see enum dmi_field)
  *
Index: linux-2.6/include/linux/dmi.h
===================================================================
--- linux-2.6.orig/include/linux/dmi.h
+++ linux-2.6/include/linux/dmi.h
@@ -38,6 +38,7 @@ struct dmi_device {
 #ifdef CONFIG_DMI
 
 extern int dmi_check_system(const struct dmi_system_id *list);
+const struct dmi_system_id *dmi_first_match(const struct dmi_system_id *list);
 extern const char * dmi_get_system_info(int field);
 extern const struct dmi_device * dmi_find_device(int type, const char *name,
 	const struct dmi_device *from);


  parent reply	other threads:[~2009-01-19 20:01 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-04  6:27 [git patches] libata hibernation fixes Jeff Garzik
2008-11-04 16:29 ` Linus Torvalds
2008-11-04 16:53   ` Rafael J. Wysocki
2008-11-04 16:59     ` Mark Lord
2008-11-04 17:07       ` Rafael J. Wysocki
2008-11-05  2:17         ` Tejun Heo
2008-11-04 20:30   ` Pavel Machek
2008-11-04 21:08     ` Rafael J. Wysocki
2008-11-04 21:12     ` Linus Torvalds
2008-11-05  2:23       ` Tejun Heo
2008-11-05  2:42   ` Tejun Heo
2008-11-10  8:52     ` Tejun Heo
2009-01-02  2:36 ` Tejun Heo
2009-01-05  8:34   ` Jeff Garzik
2009-01-11  5:44   ` Jeff Garzik
2009-01-11 12:43     ` Rafael J. Wysocki
2009-01-18 10:20       ` Frans Pop
2009-01-18 20:25         ` Rafael J. Wysocki
2009-01-18 20:39           ` Jeff Garzik
2009-01-19 19:53             ` [PATCH 0/6] Hibernation/poweroff quirks (was: Re: [git patches] libata hibernation fixes) Rafael J. Wysocki
2009-01-19 19:54               ` [PATCH 1/6] Hibernation: Introduce system_entering_hibernation Rafael J. Wysocki
2009-01-19 21:25                 ` Frederic Weisbecker
2009-01-19 21:35                   ` Rafael J. Wysocki
2009-01-19 21:48                     ` Frederic Weisbecker
2009-01-20  7:30                 ` Maciej Rutecki
2009-01-29 13:04                 ` Pavel Machek
2009-01-29 14:51                   ` Rafael J. Wysocki
2009-01-19 19:55               ` Rafael J. Wysocki [this message]
2009-01-19 21:15                 ` [PATCH 2/6] DMI: Introduce dmi_first_match to make the interface more flexible Frans Pop
2009-01-20  7:30                 ` Maciej Rutecki
2009-01-19 19:56               ` [PATCH 3/6] SATA: Blacklisting of systems that spin off disks during ACPI power off Rafael J. Wysocki
2009-01-20  7:31                 ` Maciej Rutecki
2009-01-19 19:57               ` [PATCH 4/6] SATA AHCI: Blacklist system that spins " Rafael J. Wysocki
2009-01-20  7:31                 ` Maciej Rutecki
2009-01-19 19:58               ` [PATCH 5/6] SATA Sil: " Rafael J. Wysocki
2009-01-20  7:32                 ` Maciej Rutecki
2009-01-19 19:59               ` [PATCH 6/6] SATA PIIX: " Rafael J. Wysocki
2009-01-19 22:08                 ` Frans Pop
2009-01-20  7:33                 ` Maciej Rutecki
2009-01-18 20:59           ` [git patches] libata hibernation fixes Frans Pop
2009-01-18 22:52             ` Rafael J. Wysocki
2009-01-20 20:54               ` STR/STD OK with -rc2 + selected pending patches (was: [git patches] libata hibernation fixes) Frans Pop
2009-01-20 21:12                 ` Rafael J. Wysocki
  -- strict thread matches above, loose matches on Subject: below --
2008-08-28 22:02 Regression: SATA disk double spin-off during hibernation on hp nx6325 Rafael J. Wysocki
2008-09-17 21:50 ` [PATCH] SATA: Blacklist systems that spin off disks during ACPI power off Jeff Garzik
2008-09-29 22:06   ` [PATCH 0/6] " Rafael J. Wysocki
2008-09-29 22:13     ` [PATCH 2/6] DMI: Introduce dmi_first_match to make the interface more flexible Rafael J. Wysocki
2008-10-01  3:31       ` Tejun Heo
2008-10-03 15:03 ` [PATCH 1/6] Hibernation: Introduce new system state for the last phase of hibernation Rafael J. Wysocki
2008-10-03 21:48   ` [PATCH 0/6] SATA: Blacklist systems that spin off disks during ACPI power off (rev. 2) Rafael J. Wysocki
2008-10-03 21:52     ` [PATCH 2/6] DMI: Introduce dmi_first_match to make the interface more flexible Rafael J. Wysocki

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=200901192055.51108.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=akpm@linux-foundation.org \
    --cc=elendil@planet.nl \
    --cc=jeff@garzik.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tj@kernel.org \
    --cc=torvalds@linux-foundation.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).