From 1ab69f27cbb57e0f970bcd852d9f22ed34259b57 Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Wed, 14 Jun 2017 13:59:09 +0800 Subject: ACPI: EC: Fix an EC event IRQ storming issue The EC event IRQ (SCI_EVT) can only be handled by submitting QR_EC. As the EC driver handles SCI_EVT in a workqueue, after SCI_EVT is flagged and before QR_EC is submitted, there is a period risking IRQ storming. EC IRQ must be masked for this period but linux EC driver never does so. No end user notices the IRQ storming and no developer fixes this known issue because: 1. The EC IRQ is always edge triggered GPE, and 2. The kernel can execute no-op EC IRQ handler very fast. For edge-triggered EC GPE platforms, it is only reported of post-resume EC event lost issues, there won't be an IRQ storming. For level triggered EC GPE platforms, fortunately the kernel is always fast enough to execute such a no-op EC IRQ handler so that the IRQ handler won't be accumulated to starve the task contexts, causing a real IRQ storming. But the IRQ storming actually can still happen when: 1. The EC IRQ performs like level triggered GPE, and 2. The kernel EC debugging log is turned on but the console is slow enough. There are more and more platforms using EC GPE as wake GPE where the EC GPE is likely designed as level triggered. Then when EC debugging log is enabled, the EC IRQ handler is no longer a no-op but dumps IRQ status to the consoles. If the consoles are slow enough, the EC IRQs can arrive much faster than executing the handler. Finally the accumulated EC event IRQ handlers starve the task contexts, causing the IRQ storming to occur, and the kernel hangs can be observed during boot/resume. This patch fixes this issue by masking EC IRQ for this period: 1. Begins when there is an SCI_EVT IRQ pending, and 2. Ends when there is a QR_EC completed (SCI_EVT acknowledged). Tested-by: Wang Wendy Tested-by: Feng Chenzhou Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/ec.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index c24235d8fb52..30d7f8294f90 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -459,8 +459,10 @@ static bool acpi_ec_submit_flushable_request(struct acpi_ec *ec) static void acpi_ec_submit_query(struct acpi_ec *ec) { - if (acpi_ec_event_enabled(ec) && - !test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) { + acpi_ec_set_storm(ec, EC_FLAGS_COMMAND_STORM); + if (!acpi_ec_event_enabled(ec)) + return; + if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) { ec_dbg_evt("Command(%s) submitted/blocked", acpi_ec_cmd_string(ACPI_EC_COMMAND_QUERY)); ec->nr_pending_queries++; @@ -470,11 +472,10 @@ static void acpi_ec_submit_query(struct acpi_ec *ec) static void acpi_ec_complete_query(struct acpi_ec *ec) { - if (test_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) { - clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags); + if (test_and_clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) ec_dbg_evt("Command(%s) unblocked", acpi_ec_cmd_string(ACPI_EC_COMMAND_QUERY)); - } + acpi_ec_clear_storm(ec, EC_FLAGS_COMMAND_STORM); } static inline void __acpi_ec_enable_event(struct acpi_ec *ec) -- cgit v1.2.3 From 4625d752e600c116e6327f9d7fc16e8f5be107e9 Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Wed, 14 Jun 2017 13:59:18 +0800 Subject: ACPI: EC: Fix EC command visibility for dynamic debug acpi_ec_cmd_string() currently is only enabled for "DEBUG" macro, but users trend to use CONFIG_DYNAMIC_DEBUG and enable ec.c pr_debug() print-outs by "dyndbg='file ec.c +p'". In this use case, all command names are turned into UNDEF and the log is confusing. This affects bugzilla triage work. This patch fixes this issue by enabling acpi_ec_cmd_string() for CONFIG_DYNAMIC_DEBUG. Tested-by: Wang Wendy Tested-by: Feng Chenzhou Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/ec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 30d7f8294f90..f3ff5919e399 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -316,7 +316,7 @@ static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data) ec->timestamp = jiffies; } -#ifdef DEBUG +#if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG) static const char *acpi_ec_cmd_string(u8 cmd) { switch (cmd) { -- cgit v1.2.3 From d37efb79bc1cc5763d5ac4a96b9ad2ecbddcbe8a Mon Sep 17 00:00:00 2001 From: "Shih-Yuan Lee (FourDollars)" Date: Wed, 14 Jun 2017 16:29:16 +0800 Subject: ACPI / video: Add quirks for the Dell Precision 7510 The Dell Precision 7510 has a broken acpi-video implementation. The backlight control bits work, but when the brightness is changed via the acpi-video interface the backlight flickers annoyingly before settling at the new brightness, switching to using the native interface fixes the flickering so add a quirk for this (the vendor interface can not change the brightness at all). Signed-off-by: Shih-Yuan Lee (FourDollars) Signed-off-by: Rafael J. Wysocki --- drivers/acpi/video_detect.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c index 7f48156cbc0c..d179e8d9177d 100644 --- a/drivers/acpi/video_detect.c +++ b/drivers/acpi/video_detect.c @@ -305,6 +305,14 @@ static const struct dmi_system_id video_detect_dmi_table[] = { DMI_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L702X"), }, }, + { + .callback = video_detect_force_native, + .ident = "Dell Precision 7510", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "Precision 7510"), + }, + }, { }, }; -- cgit v1.2.3 From ae56c9fd1518f9ac8def938638aebd2d7d289325 Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Thu, 15 Jun 2017 09:41:35 +0800 Subject: ACPI / EC: Enhance boot EC sanity check It's reported that some buggy BIOS tables can contain 2 DSDT ECs, one of them is invalid but acpi_ec_dsdt_probe() fails to pick the valid one. This patch simply enhances sanity checks in ec_parse_device() as a workaround to skip probing wrong namespace ECs. Link: https://bugzilla.kernel.org/show_bug.cgi?id=195651 Tested-by: Daniel Drake Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/ec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index f3ff5919e399..b4fd026c8229 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -1363,6 +1363,8 @@ ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval) ec_parse_io_ports, ec); if (ACPI_FAILURE(status)) return status; + if (ec->data_addr == 0 || ec->command_addr == 0) + return AE_OK; /* Get GPE bit assignment (EC events). */ /* TODO: Add support for _GPE returning a package */ -- cgit v1.2.3 From c712bb58d8278465b1a91f362a08f5c79ad077e4 Mon Sep 17 00:00:00 2001 From: Lv Zheng Date: Thu, 15 Jun 2017 09:41:41 +0800 Subject: ACPI / EC: Add support to skip boot stage DSDT probe We prepared _INI/_STA methods for \_SB, \_SB.PCI0, \_SB.LID0 and \_SB.EC, _HID(PNP0C09)/_CRS/_GPE for \_SB.EC to poke Windows behavior with qemu, we got the following execution sequence: \_SB._INI \_SB.PCI0._STA \_SB.LID0._STA \_SB.EC._STA \_SB.PCI0._INI \_SB.LID0._INI \_SB.EC._INI There is no extra DSDT EC device enumeration process occurring before the main ACPI device enumeration process. That means acpi_ec_dsdt_probe() is not Windows-compatible. Tracking back, it was added by the following commit: Commit: c5279dee26c0e8d7c4200993bfc4b540d2469598 Subject: ACPI: EC: Add some basic check for ECDT data but that commit was misguided. Why we shouldn't enumerate DSDT EC before the main ACPI device enumeration? The only way to know if the DSDT EC is valid would be to evaluate its _STA control method, but it's not safe to evaluate this control method that early and out of the ACPI enumeration process, because _STA may refer to entities (such as resources or ACPI device objects) that may not have been initialized before OSPM starts to enumerate them via the main ACPI device enumeration. But after we had reverted back to the expected behavior, a regression was reported. On that platform, there is no ECDT, but the platform control methods access EC operation region earlier than Linux expects causing some ACPI method execution errors. For this reason, we just go back to old behavior to still probe DSDT EC as the boot EC. However, that turns out to lead to yet another functional breakage and in order to work around all of the problems, we skip boot stage DSDT probe when the ECDT exists so that a later quirk can always use correct ECDT GPE setting. Link: http://bugzilla.kernel.org/show_bug.cgi?id=11880 Link: http://bugzilla.kernel.org/show_bug.cgi?id=119261 Link: http://bugzilla.kernel.org/show_bug.cgi?id=195651 Tested-by: Daniel Drake Signed-off-by: Lv Zheng [ rjw: Changelog & comments massage ] Signed-off-by: Rafael J. Wysocki --- drivers/acpi/ec.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index b4fd026c8229..3243e0801864 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -1668,12 +1668,26 @@ static const struct acpi_device_id ec_device_ids[] = { {"", 0}, }; +/* + * This function is not Windows-compatible as Windows never enumerates the + * namespace EC before the main ACPI device enumeration process. It is + * retained for historical reason and will be deprecated in the future. + */ int __init acpi_ec_dsdt_probe(void) { acpi_status status; struct acpi_ec *ec; int ret; + /* + * If a platform has ECDT, there is no need to proceed as the + * following probe is not a part of the ACPI device enumeration, + * executing _STA is not safe, and thus this probe may risk of + * picking up an invalid EC device. + */ + if (boot_ec) + return -ENODEV; + ec = acpi_ec_alloc(); if (!ec) return -ENOMEM; -- cgit v1.2.3 From 440f53da70875916f1962266a1ff53c40f9573e8 Mon Sep 17 00:00:00 2001 From: Chris Chiu Date: Thu, 15 Jun 2017 09:41:47 +0800 Subject: ACPI / EC: Fix media keys not working problem on some Asus laptops Some Asus laptops (verified on X550VXK/FX502VD/FX502VE) get no interrupts when pressing media keys thus the corresponding functions are not invoked. It's due to the _GPE defines in DSDT for EC returns differnt value compared to the GPE Number in ECDT. Confirmed with Asus that the vale in ECDT is the correct one. This commit uses DMI quirks to prevent calling _GPE when doing ec_parse_device() and keep the ECDT GPE number setting for the EC device. With previous commit, it is ensured that if there is an ECDT, it can always be kept as boot_ec, this patch thus can implement a quirk on top of the determined ECDT boot_ec. Link: https://phabricator.endlessm.com/T16033 Link: https://phabricator.endlessm.com/T16722 Link: https://bugzilla.kernel.org/show_bug.cgi?id=195651 Tested-by: Daniel Drake Signed-off-by: Chris Chiu Signed-off-by: Carlo Caione Signed-off-by: Lv Zheng Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/ec.c | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 3243e0801864..f493ae7b30b1 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -190,6 +190,7 @@ static struct workqueue_struct *ec_query_wq; static int EC_FLAGS_QUERY_HANDSHAKE; /* Needs QR_EC issued when SCI_EVT set */ static int EC_FLAGS_CORRECT_ECDT; /* Needs ECDT port address correction */ +static int EC_FLAGS_IGNORE_DSDT_GPE; /* Needs ECDT GPE as correction setting */ /* -------------------------------------------------------------------------- * Logging/Debugging @@ -1366,12 +1367,20 @@ ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval) if (ec->data_addr == 0 || ec->command_addr == 0) return AE_OK; - /* Get GPE bit assignment (EC events). */ - /* TODO: Add support for _GPE returning a package */ - status = acpi_evaluate_integer(handle, "_GPE", NULL, &tmp); - if (ACPI_FAILURE(status)) - return status; - ec->gpe = tmp; + if (boot_ec && boot_ec_is_ecdt && EC_FLAGS_IGNORE_DSDT_GPE) { + /* + * Always inherit the GPE number setting from the ECDT + * EC. + */ + ec->gpe = boot_ec->gpe; + } else { + /* Get GPE bit assignment (EC events). */ + /* TODO: Add support for _GPE returning a package */ + status = acpi_evaluate_integer(handle, "_GPE", NULL, &tmp); + if (ACPI_FAILURE(status)) + return status; + ec->gpe = tmp; + } /* Use the global lock for all EC transactions? */ tmp = 0; acpi_evaluate_integer(handle, "_GLK", NULL, &tmp); @@ -1770,11 +1779,39 @@ static int ec_correct_ecdt(const struct dmi_system_id *id) return 0; } +/* + * Some DSDTs contain wrong GPE setting. + * Asus FX502VD/VE, X550VXK, X580VD + * https://bugzilla.kernel.org/show_bug.cgi?id=195651 + */ +static int ec_honor_ecdt_gpe(const struct dmi_system_id *id) +{ + pr_debug("Detected system needing ignore DSDT GPE setting.\n"); + EC_FLAGS_IGNORE_DSDT_GPE = 1; + return 0; +} + static struct dmi_system_id ec_dmi_table[] __initdata = { { ec_correct_ecdt, "MSI MS-171F", { DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star"), DMI_MATCH(DMI_PRODUCT_NAME, "MS-171F"),}, NULL}, + { + ec_honor_ecdt_gpe, "ASUS FX502VD", { + DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), + DMI_MATCH(DMI_PRODUCT_NAME, "FX502VD"),}, NULL}, + { + ec_honor_ecdt_gpe, "ASUS FX502VE", { + DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), + DMI_MATCH(DMI_PRODUCT_NAME, "FX502VE"),}, NULL}, + { + ec_honor_ecdt_gpe, "ASUS X550VXK", { + DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), + DMI_MATCH(DMI_PRODUCT_NAME, "X550VXK"),}, NULL}, + { + ec_honor_ecdt_gpe, "ASUS X580VD", { + DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), + DMI_MATCH(DMI_PRODUCT_NAME, "X580VD"),}, NULL}, {}, }; -- cgit v1.2.3 From ef75040ab7f179c30f084653c93bc0bbdbcaf17a Mon Sep 17 00:00:00 2001 From: Carlo Caione Date: Thu, 15 Jun 2017 09:41:53 +0800 Subject: ACPI / EC: Add quirk for GL720VMK ASUS GL720VMK is also affected by the EC GPE preference issue. Signed-off-by: Carlo Caione Signed-off-by: Lv Zheng Signed-off-by: Rafael J. Wysocki --- drivers/acpi/ec.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index f493ae7b30b1..77c18a5547ed 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -1781,7 +1781,7 @@ static int ec_correct_ecdt(const struct dmi_system_id *id) /* * Some DSDTs contain wrong GPE setting. - * Asus FX502VD/VE, X550VXK, X580VD + * Asus FX502VD/VE, GL702VMK, X550VXK, X580VD * https://bugzilla.kernel.org/show_bug.cgi?id=195651 */ static int ec_honor_ecdt_gpe(const struct dmi_system_id *id) @@ -1805,6 +1805,10 @@ static struct dmi_system_id ec_dmi_table[] __initdata = { DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), DMI_MATCH(DMI_PRODUCT_NAME, "FX502VE"),}, NULL}, { + ec_honor_ecdt_gpe, "ASUS GL702VMK", { + DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), + DMI_MATCH(DMI_PRODUCT_NAME, "GL702VMK"),}, NULL}, + { ec_honor_ecdt_gpe, "ASUS X550VXK", { DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), DMI_MATCH(DMI_PRODUCT_NAME, "X550VXK"),}, NULL}, -- cgit v1.2.3