From patchwork Thu Jul 13 22:36:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Wunner X-Patchwork-Id: 9839657 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 40919602D8 for ; Thu, 13 Jul 2017 22:37:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F4EB27F8F for ; Thu, 13 Jul 2017 22:37:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 540E327FB0; Thu, 13 Jul 2017 22:37:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC35527F97 for ; Thu, 13 Jul 2017 22:37:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752863AbdGMWhR (ORCPT ); Thu, 13 Jul 2017 18:37:17 -0400 Received: from mailout3.hostsharing.net ([176.9.242.54]:59231 "EHLO mailout3.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751828AbdGMWhQ (ORCPT ); Thu, 13 Jul 2017 18:37:16 -0400 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mailout3.hostsharing.net (Postfix) with ESMTPS id 96138100B089F; Fri, 14 Jul 2017 00:37:09 +0200 (CEST) Received: from localhost (5-38-90-81.adsl.cmo.de [81.90.38.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id 75FD4604DB69; Fri, 14 Jul 2017 00:37:06 +0200 (CEST) X-Mailbox-Line: From a0c795358306954294e7fe31ec974f3c51b56f4c Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: References: From: Lukas Wunner Date: Fri, 14 Jul 2017 00:36:19 +0200 Subject: [PATCH v3 2/6] ACPI / x86: Consolidate Apple DMI checks To: "Rafael J. Wysocki" Cc: Ronald Tschalaer , Federico Lorenzi , Mika Westerberg , Andy Shevchenko , Lv Zheng , Leif Liddy , Daniel Roschka , Mark Brown , linux-acpi@vger.kernel.org, linux-spi@vger.kernel.org Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We're about to amend device scan with multiple checks whether we're running on a Mac. Speed that up by performing the DMI match only once and caching the result. Switch over existing Apple DMI checks, thereby fixing two deficiencies: * They only match "Apple Inc." but not "Apple Computer, Inc.", which is used by BIOSes released between January 2006 (when the first x86 Macs started shipping) and January 2007 (when the company name changed upon introduction of the iPhone). * They are now #defined to false on non-x86 arches and can thus be optimized away by the compiler. Suggested-by: Andy Shevchenko Signed-off-by: Lukas Wunner --- Changes v2 -> v3: - Newly inserted patch in v3 to avoid repeated DMI checks for Apple hardware: The result of the first DMI check in osi.c is cached. Two other existing DMI checks are converted to use the result. Because one of them is in a module (sbs.ko), the bool is_apple_system needs to be exported. On non-x86, the DMI checks and Apple-specific code are omitted altogether. (Andy, Rafael) drivers/acpi/osi.c | 4 ++++ drivers/acpi/pci_root.c | 3 +-- drivers/acpi/sbs.c | 24 +----------------------- include/linux/acpi.h | 6 ++++++ 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/drivers/acpi/osi.c b/drivers/acpi/osi.c index cd953ae10238..6c253d4006b4 100644 --- a/drivers/acpi/osi.c +++ b/drivers/acpi/osi.c @@ -258,12 +258,16 @@ bool acpi_osi_is_win8(void) EXPORT_SYMBOL(acpi_osi_is_win8); #ifdef CONFIG_X86 +bool is_apple_system; +EXPORT_SYMBOL(is_apple_system); + static void __init acpi_osi_dmi_darwin(bool enable, const struct dmi_system_id *d) { pr_notice("DMI detected to setup _OSI(\"Darwin\"): %s\n", d->ident); osi_config.darwin_dmi = 1; __acpi_osi_setup_darwin(enable); + is_apple_system = true; } static void __init acpi_osi_dmi_linux(bool enable, diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c index 9eec3095e6c3..1b6341717820 100644 --- a/drivers/acpi/pci_root.c +++ b/drivers/acpi/pci_root.c @@ -431,8 +431,7 @@ static void negotiate_os_control(struct acpi_pci_root *root, int *no_aspm) * been called successfully. We know the feature set supported by the * platform, so avoid calling _OSC at all */ - - if (dmi_match(DMI_SYS_VENDOR, "Apple Inc.")) { + if (is_apple_system) { root->osc_control_set = ~OSC_PCI_EXPRESS_PME_CONTROL; decode_osc_control(root, "OS assumes control of", root->osc_control_set); diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c index ad0b13ad4bbb..9b945ae0037e 100644 --- a/drivers/acpi/sbs.c +++ b/drivers/acpi/sbs.c @@ -31,7 +31,6 @@ #include #include #include -#include #include "sbshc.h" #include "battery.h" @@ -58,8 +57,6 @@ static unsigned int cache_time = 1000; module_param(cache_time, uint, 0644); MODULE_PARM_DESC(cache_time, "cache time in milliseconds"); -static bool sbs_manager_broken; - #define MAX_SBS_BAT 4 #define ACPI_SBS_BLOCK_MAX 32 @@ -632,31 +629,12 @@ static void acpi_sbs_callback(void *context) } } -static int disable_sbs_manager(const struct dmi_system_id *d) -{ - sbs_manager_broken = true; - return 0; -} - -static struct dmi_system_id acpi_sbs_dmi_table[] = { - { - .callback = disable_sbs_manager, - .ident = "Apple", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc.") - }, - }, - { }, -}; - static int acpi_sbs_add(struct acpi_device *device) { struct acpi_sbs *sbs; int result = 0; int id; - dmi_check_system(acpi_sbs_dmi_table); - sbs = kzalloc(sizeof(struct acpi_sbs), GFP_KERNEL); if (!sbs) { result = -ENOMEM; @@ -677,7 +655,7 @@ static int acpi_sbs_add(struct acpi_device *device) result = 0; - if (!sbs_manager_broken) { + if (!is_apple_system) { result = acpi_manager_get_info(sbs); if (!result) { sbs->manager_present = 1; diff --git a/include/linux/acpi.h b/include/linux/acpi.h index cafdfb84ca28..d068cee890ee 100644 --- a/include/linux/acpi.h +++ b/include/linux/acpi.h @@ -389,6 +389,12 @@ extern int acpi_blacklisted(void); extern void acpi_osi_setup(char *str); extern bool acpi_osi_is_win8(void); +#ifdef CONFIG_X86 +extern bool is_apple_system; +#else +#define is_apple_system false +#endif + #ifdef CONFIG_ACPI_NUMA int acpi_map_pxm_to_online_node(int pxm); int acpi_get_node(acpi_handle handle);