From patchwork Mon Aug 1 15:24:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Len Brown X-Patchwork-Id: 1026132 Received: from smtp1.linux-foundation.org (smtp1.linux-foundation.org [140.211.169.13]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p71FQcn2022364 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Mon, 1 Aug 2011 15:26:59 GMT Received: from daredevil.linux-foundation.org (localhost [127.0.0.1]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p71FOq73024259; Mon, 1 Aug 2011 08:24:53 -0700 Received: from vms173003pub.verizon.net (vms173003pub.verizon.net [206.46.173.3]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p71FOoFI024246 for ; Mon, 1 Aug 2011 08:24:52 -0700 Received: from localhost.localdomain ([unknown] [65.175.195.226]) by vms173003.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0LP9000FV9HBS069@vms173003.mailsrvcs.net> for linux-pm@lists.linux-foundation.org; Mon, 01 Aug 2011 10:24:50 -0500 (CDT) Received: from localhost.localdomain (x980 [127.0.0.1]) by localhost.localdomain (8.14.4/8.14.4) with ESMTP id p71FOkej023774; Mon, 01 Aug 2011 11:24:46 -0400 Received: from localhost (lenb@localhost) by localhost.localdomain (8.14.4/8.14.4/Submit) with ESMTP id p71FOjSC023769; Mon, 01 Aug 2011 11:24:45 -0400 X-Authentication-warning: localhost.localdomain: lenb owned process doing -bs Date: Mon, 01 Aug 2011 11:24:45 -0400 (EDT) From: Len Brown X-X-Sender: lenb@x980 To: Alan Cox In-reply-to: <20110713105105.63e2fbcb@lxorguk.ukuu.org.uk> Message-id: References: <20110713105105.63e2fbcb@lxorguk.ukuu.org.uk> User-Agent: Alpine 2.02 (LFD 1266 2009-07-14) MIME-version: 1.0 Received-SPF: pass (localhost is always allowed.) X-Spam-Status: No, hits=-5.554 required=5 tests=AWL, BAYES_00, OSDL_HEADER_SUBJECT_BRACKETED, PATCH_SUBJECT_OSDL X-Spam-Checker-Version: SpamAssassin 3.2.4-osdl_revision__1.47__ X-MIMEDefang-Filter: lf$Revision: 1.188 $ X-Scanned-By: MIMEDefang 2.63 on 140.211.169.21 Cc: linux-pm@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [linux-pm] [PATCH] mrst_pmu: driver for Intel Moorestown Power Management Unit X-BeenThere: linux-pm@lists.linux-foundation.org X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux power management List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-pm-bounces@lists.linux-foundation.org Errors-To: linux-pm-bounces@lists.linux-foundation.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Mon, 01 Aug 2011 15:26:59 +0000 (UTC) > > + BUG_ON(pci_dev_num != mrst_devs[index].pci_dev_num); > > That strikes me as needlessly unfriendly, you could warn/return NULL and > propogate a WARN_ONCE back to the user. If a fit of friendlyness, I wrote the patch below. Let me know if it is not what you had in mind. thanks -Len From 0f72ff0114695d48ecdd7270998148d61236341d Mon Sep 17 00:00:00 2001 From: Len Brown Date: Mon, 1 Aug 2011 11:13:37 -0400 Subject: [PATCH] msrt_pmu: add friendly firmware debugging code MRST firmware has already been debugged, but this patch makes the kernel fail more gently should somebody break it in the future by inventing a device that is not in the SOC. Signed-off-by: Len Brown --- arch/x86/platform/mrst/pmu.c | 30 +++++++++++++++++++++++++----- 1 files changed, 25 insertions(+), 5 deletions(-) diff --git a/arch/x86/platform/mrst/pmu.c b/arch/x86/platform/mrst/pmu.c index f8c6d8f..ee3afb1 100644 --- a/arch/x86/platform/mrst/pmu.c +++ b/arch/x86/platform/mrst/pmu.c @@ -96,7 +96,7 @@ static u32 pmu_set_power_state_send_cmd; static struct mrst_device *pci_id_2_mrst_dev(u16 pci_dev_num) { - int index; + int index = 0; if ((pci_dev_num >= 0x0800) && (pci_dev_num <= 0x815)) index = pci_dev_num - 0x800; @@ -106,10 +106,11 @@ static struct mrst_device *pci_id_2_mrst_dev(u16 pci_dev_num) index = 23; else if (pci_dev_num == 0x4110) index = 24; - else - BUG(); - BUG_ON(pci_dev_num != mrst_devs[index].pci_dev_num); + if (pci_dev_num != mrst_devs[index].pci_dev_num) { + WARN_ONCE(1, FW_BUG "Unknown PCI device 0x%04X\n", pci_dev_num); + return 0; + } return &mrst_devs[index]; } @@ -356,7 +357,13 @@ static u16 pmu_min_lss_pci_req(u16 *ids, u16 pci_state) int i; for (i = 0; ids[i]; ++i) { - existing_request = pci_id_2_mrst_dev(ids[i])->latest_request; + struct mrst_device *mrst_dev; + + mrst_dev = pci_id_2_mrst_dev(ids[i]); + if (unlikely(!mrst_dev)) + continue; + + existing_request = mrst_dev->latest_request; if (existing_request < pci_state) pci_state = existing_request; } @@ -380,6 +387,9 @@ int pmu_pci_set_power_state(struct pci_dev *pdev, pci_power_t pci_state) BUG_ON(pci_state < PCI_D0 || pci_state > PCI_D3cold); mrst_dev = pci_id_2_mrst_dev(pdev->device); + if (unlikely(!mrst_dev)) + return -ENODEV; + mrst_dev->pci_state_counts[pci_state]++; /* count invocations */ /* PMU driver calls self as part of PCI initialization, ignore */ @@ -499,6 +509,10 @@ static int debug_mrst_pmu_show(struct seq_file *s, void *unused) pdev->vendor, pdev->device, dev_driver_string(&pdev->dev)); + if (unlikely (!mrst_dev)) { + seq_printf(s, " UNKNOWN\n"); + continue; + } if (mrst_dev->lss) seq_printf(s, "LSS %2d %-4s ", mrst_dev->lss, @@ -598,6 +612,12 @@ static void pmu_scu_firmware_debug(void) int pos; mrst_dev = pci_id_2_mrst_dev(pdev->device); + if (unlikely(!mrst_dev)) { + printk(KERN_ERR FW_BUG "pmu: Unknown " + "PCI device 0x%04X\n", pdev->device); + continue; + } + if (mrst_dev->lss == 0) continue; /* no LSS in our table */