hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/drivers/acpi/ec.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * ec.c - ACPI Embedded Controller Driver (v3)
34 *
....@@ -9,20 +10,6 @@
910 * 2001, 2002 Andy Grover <andrew.grover@intel.com>
1011 * 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
1112 * Copyright (C) 2008 Alexey Starikovskiy <astarikovskiy@suse.de>
12
- *
13
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14
- *
15
- * This program is free software; you can redistribute it and/or modify
16
- * it under the terms of the GNU General Public License as published by
17
- * the Free Software Foundation; either version 2 of the License, or (at
18
- * your option) any later version.
19
- *
20
- * This program is distributed in the hope that it will be useful, but
21
- * WITHOUT ANY WARRANTY; without even the implied warranty of
22
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
- * General Public License for more details.
24
- *
25
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2613 */
2714
2815 /* Uncomment next line to get verbose printout */
....@@ -38,6 +25,7 @@
3825 #include <linux/list.h>
3926 #include <linux/spinlock.h>
4027 #include <linux/slab.h>
28
+#include <linux/suspend.h>
4129 #include <linux/acpi.h>
4230 #include <linux/dmi.h>
4331 #include <asm/io.h>
....@@ -46,7 +34,6 @@
4634
4735 #define ACPI_EC_CLASS "embedded_controller"
4836 #define ACPI_EC_DEVICE_NAME "Embedded Controller"
49
-#define ACPI_EC_FILE_INFO "info"
5037
5138 /* EC status register */
5239 #define ACPI_EC_FLAG_OBF 0x01 /* Output buffer full */
....@@ -107,12 +94,12 @@
10794 EC_FLAGS_QUERY_ENABLED, /* Query is enabled */
10895 EC_FLAGS_QUERY_PENDING, /* Query is pending */
10996 EC_FLAGS_QUERY_GUARDING, /* Guard for SCI_EVT check */
110
- EC_FLAGS_GPE_HANDLER_INSTALLED, /* GPE handler installed */
97
+ EC_FLAGS_EVENT_HANDLER_INSTALLED, /* Event handler installed */
11198 EC_FLAGS_EC_HANDLER_INSTALLED, /* OpReg handler installed */
112
- EC_FLAGS_EVT_HANDLER_INSTALLED, /* _Qxx handlers installed */
99
+ EC_FLAGS_QUERY_METHODS_INSTALLED, /* _Qxx handlers installed */
113100 EC_FLAGS_STARTED, /* Driver is started */
114101 EC_FLAGS_STOPPED, /* Driver is stopped */
115
- EC_FLAGS_GPE_MASKED, /* GPE masked */
102
+ EC_FLAGS_EVENTS_MASKED, /* Events masked */
116103 };
117104
118105 #define ACPI_EC_COMMAND_POLL 0x01 /* Available for command byte */
....@@ -179,6 +166,7 @@
179166 struct transaction transaction;
180167 struct work_struct work;
181168 struct acpi_ec_query_handler *handler;
169
+ struct acpi_ec *ec;
182170 };
183171
184172 static int acpi_ec_query(struct acpi_ec *ec, u8 *data);
....@@ -186,14 +174,16 @@
186174 static void acpi_ec_event_handler(struct work_struct *work);
187175 static void acpi_ec_event_processor(struct work_struct *work);
188176
189
-struct acpi_ec *boot_ec, *first_ec;
177
+struct acpi_ec *first_ec;
190178 EXPORT_SYMBOL(first_ec);
179
+
180
+static struct acpi_ec *boot_ec;
191181 static bool boot_ec_is_ecdt = false;
182
+static struct workqueue_struct *ec_wq;
192183 static struct workqueue_struct *ec_query_wq;
193184
194
-static int EC_FLAGS_QUERY_HANDSHAKE; /* Needs QR_EC issued when SCI_EVT set */
195185 static int EC_FLAGS_CORRECT_ECDT; /* Needs ECDT port address correction */
196
-static int EC_FLAGS_IGNORE_DSDT_GPE; /* Needs ECDT GPE as correction setting */
186
+static int EC_FLAGS_TRUST_DSDT_GPE; /* Needs DSDT GPE as correction setting */
197187 static int EC_FLAGS_CLEAR_ON_RESUME; /* Needs acpi_ec_clear() on boot/resume */
198188
199189 /* --------------------------------------------------------------------------
....@@ -407,8 +397,8 @@
407397 static void acpi_ec_submit_request(struct acpi_ec *ec)
408398 {
409399 ec->reference_count++;
410
- if (test_bit(EC_FLAGS_GPE_HANDLER_INSTALLED, &ec->flags) &&
411
- ec->reference_count == 1)
400
+ if (test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags) &&
401
+ ec->gpe >= 0 && ec->reference_count == 1)
412402 acpi_ec_enable_gpe(ec, true);
413403 }
414404
....@@ -417,28 +407,36 @@
417407 bool flushed = false;
418408
419409 ec->reference_count--;
420
- if (test_bit(EC_FLAGS_GPE_HANDLER_INSTALLED, &ec->flags) &&
421
- ec->reference_count == 0)
410
+ if (test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags) &&
411
+ ec->gpe >= 0 && ec->reference_count == 0)
422412 acpi_ec_disable_gpe(ec, true);
423413 flushed = acpi_ec_flushed(ec);
424414 if (flushed)
425415 wake_up(&ec->wait);
426416 }
427417
428
-static void acpi_ec_mask_gpe(struct acpi_ec *ec)
418
+static void acpi_ec_mask_events(struct acpi_ec *ec)
429419 {
430
- if (!test_bit(EC_FLAGS_GPE_MASKED, &ec->flags)) {
431
- acpi_ec_disable_gpe(ec, false);
420
+ if (!test_bit(EC_FLAGS_EVENTS_MASKED, &ec->flags)) {
421
+ if (ec->gpe >= 0)
422
+ acpi_ec_disable_gpe(ec, false);
423
+ else
424
+ disable_irq_nosync(ec->irq);
425
+
432426 ec_dbg_drv("Polling enabled");
433
- set_bit(EC_FLAGS_GPE_MASKED, &ec->flags);
427
+ set_bit(EC_FLAGS_EVENTS_MASKED, &ec->flags);
434428 }
435429 }
436430
437
-static void acpi_ec_unmask_gpe(struct acpi_ec *ec)
431
+static void acpi_ec_unmask_events(struct acpi_ec *ec)
438432 {
439
- if (test_bit(EC_FLAGS_GPE_MASKED, &ec->flags)) {
440
- clear_bit(EC_FLAGS_GPE_MASKED, &ec->flags);
441
- acpi_ec_enable_gpe(ec, false);
433
+ if (test_bit(EC_FLAGS_EVENTS_MASKED, &ec->flags)) {
434
+ clear_bit(EC_FLAGS_EVENTS_MASKED, &ec->flags);
435
+ if (ec->gpe >= 0)
436
+ acpi_ec_enable_gpe(ec, false);
437
+ else
438
+ enable_irq(ec->irq);
439
+
442440 ec_dbg_drv("Polling disabled");
443441 }
444442 }
....@@ -464,14 +462,15 @@
464462
465463 static void acpi_ec_submit_query(struct acpi_ec *ec)
466464 {
467
- acpi_ec_mask_gpe(ec);
465
+ acpi_ec_mask_events(ec);
468466 if (!acpi_ec_event_enabled(ec))
469467 return;
470468 if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) {
471469 ec_dbg_evt("Command(%s) submitted/blocked",
472470 acpi_ec_cmd_string(ACPI_EC_COMMAND_QUERY));
473471 ec->nr_pending_queries++;
474
- schedule_work(&ec->work);
472
+ ec->events_in_progress++;
473
+ queue_work(ec_wq, &ec->work);
475474 }
476475 }
477476
....@@ -480,7 +479,7 @@
480479 if (test_and_clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags))
481480 ec_dbg_evt("Command(%s) unblocked",
482481 acpi_ec_cmd_string(ACPI_EC_COMMAND_QUERY));
483
- acpi_ec_unmask_gpe(ec);
482
+ acpi_ec_unmask_events(ec);
484483 }
485484
486485 static inline void __acpi_ec_enable_event(struct acpi_ec *ec)
....@@ -535,26 +534,10 @@
535534 }
536535
537536 #ifdef CONFIG_PM_SLEEP
538
-static bool acpi_ec_query_flushed(struct acpi_ec *ec)
537
+static void __acpi_ec_flush_work(void)
539538 {
540
- bool flushed;
541
- unsigned long flags;
542
-
543
- spin_lock_irqsave(&ec->lock, flags);
544
- flushed = !ec->nr_pending_queries;
545
- spin_unlock_irqrestore(&ec->lock, flags);
546
- return flushed;
547
-}
548
-
549
-static void __acpi_ec_flush_event(struct acpi_ec *ec)
550
-{
551
- /*
552
- * When ec_freeze_events is true, we need to flush events in
553
- * the proper position before entering the noirq stage.
554
- */
555
- wait_event(ec->wait, acpi_ec_query_flushed(ec));
556
- if (ec_query_wq)
557
- flush_workqueue(ec_query_wq);
539
+ flush_workqueue(ec_wq); /* flush ec->work */
540
+ flush_workqueue(ec_query_wq); /* flush queries */
558541 }
559542
560543 static void acpi_ec_disable_event(struct acpi_ec *ec)
....@@ -564,15 +547,21 @@
564547 spin_lock_irqsave(&ec->lock, flags);
565548 __acpi_ec_disable_event(ec);
566549 spin_unlock_irqrestore(&ec->lock, flags);
567
- __acpi_ec_flush_event(ec);
550
+
551
+ /*
552
+ * When ec_freeze_events is true, we need to flush events in
553
+ * the proper position before entering the noirq stage.
554
+ */
555
+ __acpi_ec_flush_work();
568556 }
569557
570558 void acpi_ec_flush_work(void)
571559 {
572
- if (first_ec)
573
- __acpi_ec_flush_event(first_ec);
560
+ /* Without ec_wq there is nothing to flush. */
561
+ if (!ec_wq)
562
+ return;
574563
575
- flush_scheduled_work();
564
+ __acpi_ec_flush_work();
576565 }
577566 #endif /* CONFIG_PM_SLEEP */
578567
....@@ -658,7 +647,9 @@
658647 * ensure a hardware STS 0->1 change after this clearing can always
659648 * trigger a GPE interrupt.
660649 */
661
- acpi_ec_clear_gpe(ec);
650
+ if (ec->gpe >= 0)
651
+ acpi_ec_clear_gpe(ec);
652
+
662653 status = acpi_ec_read_status(ec);
663654 t = ec->curr;
664655 /*
....@@ -699,21 +690,9 @@
699690 wakeup = true;
700691 }
701692 goto out;
702
- } else {
703
- if (EC_FLAGS_QUERY_HANDSHAKE &&
704
- !(status & ACPI_EC_FLAG_SCI) &&
705
- (t->command == ACPI_EC_COMMAND_QUERY)) {
706
- ec_transaction_transition(ec, ACPI_EC_COMMAND_POLL);
707
- t->rdata[t->ri++] = 0x00;
708
- ec_transaction_transition(ec, ACPI_EC_COMMAND_COMPLETE);
709
- ec_dbg_evt("Command(%s) completed by software",
710
- acpi_ec_cmd_string(ACPI_EC_COMMAND_QUERY));
711
- wakeup = true;
712
- } else if ((status & ACPI_EC_FLAG_IBF) == 0) {
713
- acpi_ec_write_cmd(ec, t->command);
714
- ec_transaction_transition(ec, ACPI_EC_COMMAND_POLL);
715
- } else
716
- goto err;
693
+ } else if (!(status & ACPI_EC_FLAG_IBF)) {
694
+ acpi_ec_write_cmd(ec, t->command);
695
+ ec_transaction_transition(ec, ACPI_EC_COMMAND_POLL);
717696 goto out;
718697 }
719698 err:
....@@ -727,7 +706,7 @@
727706 ++t->irq_count;
728707 /* Allow triggering on 0 threshold */
729708 if (t->irq_count == ec_storm_threshold)
730
- acpi_ec_mask_gpe(ec);
709
+ acpi_ec_mask_events(ec);
731710 }
732711 }
733712 out:
....@@ -825,7 +804,7 @@
825804
826805 spin_lock_irqsave(&ec->lock, tmp);
827806 if (t->irq_count == ec_storm_threshold)
828
- acpi_ec_unmask_gpe(ec);
807
+ acpi_ec_unmask_events(ec);
829808 ec_dbg_req("Command(%s) stopped", acpi_ec_cmd_string(t->command));
830809 ec->curr = NULL;
831810 /* Disable GPE for command processing (IBF=0/OBF=1) */
....@@ -1059,24 +1038,6 @@
10591038 acpi_ec_start(first_ec, true);
10601039 }
10611040
1062
-void acpi_ec_mark_gpe_for_wake(void)
1063
-{
1064
- if (first_ec && !ec_no_wakeup)
1065
- acpi_mark_gpe_for_wake(NULL, first_ec->gpe);
1066
-}
1067
-
1068
-void acpi_ec_set_gpe_wake_mask(u8 action)
1069
-{
1070
- if (first_ec && !ec_no_wakeup)
1071
- acpi_set_gpe_wake_mask(NULL, first_ec->gpe, action);
1072
-}
1073
-
1074
-void acpi_ec_dispatch_gpe(void)
1075
-{
1076
- if (first_ec)
1077
- acpi_dispatch_gpe(NULL, first_ec->gpe);
1078
-}
1079
-
10801041 /* --------------------------------------------------------------------------
10811042 Event Management
10821043 -------------------------------------------------------------------------- */
....@@ -1153,10 +1114,11 @@
11531114 void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit)
11541115 {
11551116 acpi_ec_remove_query_handlers(ec, false, query_bit);
1117
+ flush_workqueue(ec_query_wq);
11561118 }
11571119 EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler);
11581120
1159
-static struct acpi_ec_query *acpi_ec_create_query(u8 *pval)
1121
+static struct acpi_ec_query *acpi_ec_create_query(struct acpi_ec *ec, u8 *pval)
11601122 {
11611123 struct acpi_ec_query *q;
11621124 struct transaction *t;
....@@ -1164,11 +1126,13 @@
11641126 q = kzalloc(sizeof (struct acpi_ec_query), GFP_KERNEL);
11651127 if (!q)
11661128 return NULL;
1129
+
11671130 INIT_WORK(&q->work, acpi_ec_event_processor);
11681131 t = &q->transaction;
11691132 t->command = ACPI_EC_COMMAND_QUERY;
11701133 t->rdata = pval;
11711134 t->rlen = 1;
1135
+ q->ec = ec;
11721136 return q;
11731137 }
11741138
....@@ -1185,13 +1149,21 @@
11851149 {
11861150 struct acpi_ec_query *q = container_of(work, struct acpi_ec_query, work);
11871151 struct acpi_ec_query_handler *handler = q->handler;
1152
+ struct acpi_ec *ec = q->ec;
11881153
11891154 ec_dbg_evt("Query(0x%02x) started", handler->query_bit);
1155
+
11901156 if (handler->func)
11911157 handler->func(handler->data);
11921158 else if (handler->handle)
11931159 acpi_evaluate_object(handler->handle, NULL, NULL, NULL);
1160
+
11941161 ec_dbg_evt("Query(0x%02x) stopped", handler->query_bit);
1162
+
1163
+ spin_lock_irq(&ec->lock);
1164
+ ec->queries_in_progress--;
1165
+ spin_unlock_irq(&ec->lock);
1166
+
11951167 acpi_ec_delete_query(q);
11961168 }
11971169
....@@ -1201,7 +1173,7 @@
12011173 int result;
12021174 struct acpi_ec_query *q;
12031175
1204
- q = acpi_ec_create_query(&value);
1176
+ q = acpi_ec_create_query(ec, &value);
12051177 if (!q)
12061178 return -ENOMEM;
12071179
....@@ -1223,19 +1195,20 @@
12231195 }
12241196
12251197 /*
1226
- * It is reported that _Qxx are evaluated in a parallel way on
1227
- * Windows:
1198
+ * It is reported that _Qxx are evaluated in a parallel way on Windows:
12281199 * https://bugzilla.kernel.org/show_bug.cgi?id=94411
12291200 *
1230
- * Put this log entry before schedule_work() in order to make
1231
- * it appearing before any other log entries occurred during the
1232
- * work queue execution.
1201
+ * Put this log entry before queue_work() to make it appear in the log
1202
+ * before any other messages emitted during workqueue handling.
12331203 */
12341204 ec_dbg_evt("Query(0x%02x) scheduled", value);
1235
- if (!queue_work(ec_query_wq, &q->work)) {
1236
- ec_dbg_evt("Query(0x%02x) overlapped", value);
1237
- result = -EBUSY;
1238
- }
1205
+
1206
+ spin_lock_irq(&ec->lock);
1207
+
1208
+ ec->queries_in_progress++;
1209
+ queue_work(ec_query_wq, &q->work);
1210
+
1211
+ spin_unlock_irq(&ec->lock);
12391212
12401213 err_exit:
12411214 if (result)
....@@ -1293,18 +1266,32 @@
12931266 ec_dbg_evt("Event stopped");
12941267
12951268 acpi_ec_check_event(ec);
1269
+
1270
+ spin_lock_irqsave(&ec->lock, flags);
1271
+ ec->events_in_progress--;
1272
+ spin_unlock_irqrestore(&ec->lock, flags);
12961273 }
12971274
1298
-static u32 acpi_ec_gpe_handler(acpi_handle gpe_device,
1299
- u32 gpe_number, void *data)
1275
+static void acpi_ec_handle_interrupt(struct acpi_ec *ec)
13001276 {
13011277 unsigned long flags;
1302
- struct acpi_ec *ec = data;
13031278
13041279 spin_lock_irqsave(&ec->lock, flags);
13051280 advance_transaction(ec);
13061281 spin_unlock_irqrestore(&ec->lock, flags);
1282
+}
1283
+
1284
+static u32 acpi_ec_gpe_handler(acpi_handle gpe_device,
1285
+ u32 gpe_number, void *data)
1286
+{
1287
+ acpi_ec_handle_interrupt(data);
13071288 return ACPI_INTERRUPT_HANDLED;
1289
+}
1290
+
1291
+static irqreturn_t acpi_ec_irq_handler(int irq, void *data)
1292
+{
1293
+ acpi_ec_handle_interrupt(data);
1294
+ return IRQ_HANDLED;
13081295 }
13091296
13101297 /* --------------------------------------------------------------------------
....@@ -1379,6 +1366,8 @@
13791366 ec->timestamp = jiffies;
13801367 ec->busy_polling = true;
13811368 ec->polling_guard = 0;
1369
+ ec->gpe = -1;
1370
+ ec->irq = -1;
13821371 return ec;
13831372 }
13841373
....@@ -1416,20 +1405,16 @@
14161405 if (ec->data_addr == 0 || ec->command_addr == 0)
14171406 return AE_OK;
14181407
1419
- if (boot_ec && boot_ec_is_ecdt && EC_FLAGS_IGNORE_DSDT_GPE) {
1420
- /*
1421
- * Always inherit the GPE number setting from the ECDT
1422
- * EC.
1423
- */
1424
- ec->gpe = boot_ec->gpe;
1425
- } else {
1426
- /* Get GPE bit assignment (EC events). */
1427
- /* TODO: Add support for _GPE returning a package */
1428
- status = acpi_evaluate_integer(handle, "_GPE", NULL, &tmp);
1429
- if (ACPI_FAILURE(status))
1430
- return status;
1408
+ /* Get GPE bit assignment (EC events). */
1409
+ /* TODO: Add support for _GPE returning a package */
1410
+ status = acpi_evaluate_integer(handle, "_GPE", NULL, &tmp);
1411
+ if (ACPI_SUCCESS(status))
14311412 ec->gpe = tmp;
1432
- }
1413
+ /*
1414
+ * Errors are non-fatal, allowing for ACPI Reduced Hardware
1415
+ * platforms which use GpioInt instead of GPE.
1416
+ */
1417
+
14331418 /* Use the global lock for all EC transactions? */
14341419 tmp = 0;
14351420 acpi_evaluate_integer(handle, "_GLK", NULL, &tmp);
....@@ -1438,12 +1423,45 @@
14381423 return AE_CTRL_TERMINATE;
14391424 }
14401425
1441
-/*
1442
- * Note: This function returns an error code only when the address space
1443
- * handler is not installed, which means "not able to handle
1444
- * transactions".
1426
+static bool install_gpe_event_handler(struct acpi_ec *ec)
1427
+{
1428
+ acpi_status status;
1429
+
1430
+ status = acpi_install_gpe_raw_handler(NULL, ec->gpe,
1431
+ ACPI_GPE_EDGE_TRIGGERED,
1432
+ &acpi_ec_gpe_handler, ec);
1433
+ if (ACPI_FAILURE(status))
1434
+ return false;
1435
+
1436
+ if (test_bit(EC_FLAGS_STARTED, &ec->flags) && ec->reference_count >= 1)
1437
+ acpi_ec_enable_gpe(ec, true);
1438
+
1439
+ return true;
1440
+}
1441
+
1442
+static bool install_gpio_irq_event_handler(struct acpi_ec *ec)
1443
+{
1444
+ return request_irq(ec->irq, acpi_ec_irq_handler, IRQF_SHARED,
1445
+ "ACPI EC", ec) >= 0;
1446
+}
1447
+
1448
+/**
1449
+ * ec_install_handlers - Install service callbacks and register query methods.
1450
+ * @ec: Target EC.
1451
+ * @device: ACPI device object corresponding to @ec.
1452
+ *
1453
+ * Install a handler for the EC address space type unless it has been installed
1454
+ * already. If @device is not NULL, also look for EC query methods in the
1455
+ * namespace and register them, and install an event (either GPE or GPIO IRQ)
1456
+ * handler for the EC, if possible.
1457
+ *
1458
+ * Return:
1459
+ * -ENODEV if the address space handler cannot be installed, which means
1460
+ * "unable to handle transactions",
1461
+ * -EPROBE_DEFER if GPIO IRQ acquisition needs to be deferred,
1462
+ * or 0 (success) otherwise.
14451463 */
1446
-static int ec_install_handlers(struct acpi_ec *ec, bool handle_events)
1464
+static int ec_install_handlers(struct acpi_ec *ec, struct acpi_device *device)
14471465 {
14481466 acpi_status status;
14491467
....@@ -1456,45 +1474,51 @@
14561474 &acpi_ec_space_handler,
14571475 NULL, ec);
14581476 if (ACPI_FAILURE(status)) {
1459
- if (status == AE_NOT_FOUND) {
1460
- /*
1461
- * Maybe OS fails in evaluating the _REG
1462
- * object. The AE_NOT_FOUND error will be
1463
- * ignored and OS * continue to initialize
1464
- * EC.
1465
- */
1466
- pr_err("Fail in evaluating the _REG object"
1467
- " of EC device. Broken bios is suspected.\n");
1468
- } else {
1469
- acpi_ec_stop(ec, false);
1470
- return -ENODEV;
1471
- }
1477
+ acpi_ec_stop(ec, false);
1478
+ return -ENODEV;
14721479 }
14731480 set_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags);
14741481 }
14751482
1476
- if (!handle_events)
1483
+ if (!device)
14771484 return 0;
14781485
1479
- if (!test_bit(EC_FLAGS_EVT_HANDLER_INSTALLED, &ec->flags)) {
1486
+ if (ec->gpe < 0) {
1487
+ /* ACPI reduced hardware platforms use a GpioInt from _CRS. */
1488
+ int irq = acpi_dev_gpio_irq_get(device, 0);
1489
+ /*
1490
+ * Bail out right away for deferred probing or complete the
1491
+ * initialization regardless of any other errors.
1492
+ */
1493
+ if (irq == -EPROBE_DEFER)
1494
+ return -EPROBE_DEFER;
1495
+ else if (irq >= 0)
1496
+ ec->irq = irq;
1497
+ }
1498
+
1499
+ if (!test_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags)) {
14801500 /* Find and register all query methods */
14811501 acpi_walk_namespace(ACPI_TYPE_METHOD, ec->handle, 1,
14821502 acpi_ec_register_query_methods,
14831503 NULL, ec, NULL);
1484
- set_bit(EC_FLAGS_EVT_HANDLER_INSTALLED, &ec->flags);
1504
+ set_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags);
14851505 }
1486
- if (!test_bit(EC_FLAGS_GPE_HANDLER_INSTALLED, &ec->flags)) {
1487
- status = acpi_install_gpe_raw_handler(NULL, ec->gpe,
1488
- ACPI_GPE_EDGE_TRIGGERED,
1489
- &acpi_ec_gpe_handler, ec);
1490
- /* This is not fatal as we can poll EC events */
1491
- if (ACPI_SUCCESS(status)) {
1492
- set_bit(EC_FLAGS_GPE_HANDLER_INSTALLED, &ec->flags);
1506
+ if (!test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags)) {
1507
+ bool ready = false;
1508
+
1509
+ if (ec->gpe >= 0)
1510
+ ready = install_gpe_event_handler(ec);
1511
+ else if (ec->irq >= 0)
1512
+ ready = install_gpio_irq_event_handler(ec);
1513
+
1514
+ if (ready) {
1515
+ set_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags);
14931516 acpi_ec_leave_noirq(ec);
1494
- if (test_bit(EC_FLAGS_STARTED, &ec->flags) &&
1495
- ec->reference_count >= 1)
1496
- acpi_ec_enable_gpe(ec, true);
14971517 }
1518
+ /*
1519
+ * Failures to install an event handler are not fatal, because
1520
+ * the EC can be polled for events.
1521
+ */
14981522 }
14991523 /* EC is fully operational, allow queries */
15001524 acpi_ec_enable_event(ec);
....@@ -1524,137 +1548,76 @@
15241548 */
15251549 acpi_ec_stop(ec, false);
15261550
1527
- if (test_bit(EC_FLAGS_GPE_HANDLER_INSTALLED, &ec->flags)) {
1528
- if (ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe,
1529
- &acpi_ec_gpe_handler)))
1551
+ if (test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags)) {
1552
+ if (ec->gpe >= 0 &&
1553
+ ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe,
1554
+ &acpi_ec_gpe_handler)))
15301555 pr_err("failed to remove gpe handler\n");
1531
- clear_bit(EC_FLAGS_GPE_HANDLER_INSTALLED, &ec->flags);
1556
+
1557
+ if (ec->irq >= 0)
1558
+ free_irq(ec->irq, ec);
1559
+
1560
+ clear_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags);
15321561 }
1533
- if (test_bit(EC_FLAGS_EVT_HANDLER_INSTALLED, &ec->flags)) {
1562
+ if (test_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags)) {
15341563 acpi_ec_remove_query_handlers(ec, true, 0);
1535
- clear_bit(EC_FLAGS_EVT_HANDLER_INSTALLED, &ec->flags);
1564
+ clear_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags);
15361565 }
15371566 }
15381567
1539
-static int acpi_ec_setup(struct acpi_ec *ec, bool handle_events)
1568
+static int acpi_ec_setup(struct acpi_ec *ec, struct acpi_device *device)
15401569 {
15411570 int ret;
15421571
1543
- ret = ec_install_handlers(ec, handle_events);
1572
+ ret = ec_install_handlers(ec, device);
15441573 if (ret)
15451574 return ret;
15461575
15471576 /* First EC capable of handling transactions */
1548
- if (!first_ec) {
1577
+ if (!first_ec)
15491578 first_ec = ec;
1550
- acpi_handle_info(first_ec->handle, "Used as first EC\n");
1579
+
1580
+ pr_info("EC_CMD/EC_SC=0x%lx, EC_DATA=0x%lx\n", ec->command_addr,
1581
+ ec->data_addr);
1582
+
1583
+ if (test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags)) {
1584
+ if (ec->gpe >= 0)
1585
+ pr_info("GPE=0x%x\n", ec->gpe);
1586
+ else
1587
+ pr_info("IRQ=%d\n", ec->irq);
15511588 }
15521589
1553
- acpi_handle_info(ec->handle,
1554
- "GPE=0x%x, EC_CMD/EC_SC=0x%lx, EC_DATA=0x%lx\n",
1555
- ec->gpe, ec->command_addr, ec->data_addr);
15561590 return ret;
1557
-}
1558
-
1559
-static int acpi_config_boot_ec(struct acpi_ec *ec, acpi_handle handle,
1560
- bool handle_events, bool is_ecdt)
1561
-{
1562
- int ret;
1563
-
1564
- /*
1565
- * Changing the ACPI handle results in a re-configuration of the
1566
- * boot EC. And if it happens after the namespace initialization,
1567
- * it causes _REG evaluations.
1568
- */
1569
- if (boot_ec && boot_ec->handle != handle)
1570
- ec_remove_handlers(boot_ec);
1571
-
1572
- /* Unset old boot EC */
1573
- if (boot_ec != ec)
1574
- acpi_ec_free(boot_ec);
1575
-
1576
- /*
1577
- * ECDT device creation is split into acpi_ec_ecdt_probe() and
1578
- * acpi_ec_ecdt_start(). This function takes care of completing the
1579
- * ECDT parsing logic as the handle update should be performed
1580
- * between the installation/uninstallation of the handlers.
1581
- */
1582
- if (ec->handle != handle)
1583
- ec->handle = handle;
1584
-
1585
- ret = acpi_ec_setup(ec, handle_events);
1586
- if (ret)
1587
- return ret;
1588
-
1589
- /* Set new boot EC */
1590
- if (!boot_ec) {
1591
- boot_ec = ec;
1592
- boot_ec_is_ecdt = is_ecdt;
1593
- }
1594
-
1595
- acpi_handle_info(boot_ec->handle,
1596
- "Used as boot %s EC to handle transactions%s\n",
1597
- is_ecdt ? "ECDT" : "DSDT",
1598
- handle_events ? " and events" : "");
1599
- return ret;
1600
-}
1601
-
1602
-static bool acpi_ec_ecdt_get_handle(acpi_handle *phandle)
1603
-{
1604
- struct acpi_table_ecdt *ecdt_ptr;
1605
- acpi_status status;
1606
- acpi_handle handle;
1607
-
1608
- status = acpi_get_table(ACPI_SIG_ECDT, 1,
1609
- (struct acpi_table_header **)&ecdt_ptr);
1610
- if (ACPI_FAILURE(status))
1611
- return false;
1612
-
1613
- status = acpi_get_handle(NULL, ecdt_ptr->id, &handle);
1614
- if (ACPI_FAILURE(status))
1615
- return false;
1616
-
1617
- *phandle = handle;
1618
- return true;
1619
-}
1620
-
1621
-static bool acpi_is_boot_ec(struct acpi_ec *ec)
1622
-{
1623
- if (!boot_ec)
1624
- return false;
1625
- if (ec->command_addr == boot_ec->command_addr &&
1626
- ec->data_addr == boot_ec->data_addr)
1627
- return true;
1628
- return false;
16291591 }
16301592
16311593 static int acpi_ec_add(struct acpi_device *device)
16321594 {
1633
- struct acpi_ec *ec = NULL;
1595
+ struct acpi_ec *ec;
16341596 int ret;
1635
- bool is_ecdt = false;
1636
- acpi_status status;
16371597
16381598 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
16391599 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
16401600
1641
- if (!strcmp(acpi_device_hid(device), ACPI_ECDT_HID)) {
1642
- is_ecdt = true;
1601
+ if (boot_ec && (boot_ec->handle == device->handle ||
1602
+ !strcmp(acpi_device_hid(device), ACPI_ECDT_HID))) {
1603
+ /* Fast path: this device corresponds to the boot EC. */
16431604 ec = boot_ec;
16441605 } else {
1606
+ acpi_status status;
1607
+
16451608 ec = acpi_ec_alloc();
16461609 if (!ec)
16471610 return -ENOMEM;
1611
+
16481612 status = ec_parse_device(device->handle, 0, ec, NULL);
16491613 if (status != AE_CTRL_TERMINATE) {
16501614 ret = -EINVAL;
1651
- goto err_alloc;
1615
+ goto err;
16521616 }
1653
- }
16541617
1655
- if (acpi_is_boot_ec(ec)) {
1656
- boot_ec_is_ecdt = is_ecdt;
1657
- if (!is_ecdt) {
1618
+ if (boot_ec && ec->command_addr == boot_ec->command_addr &&
1619
+ ec->data_addr == boot_ec->data_addr &&
1620
+ !EC_FLAGS_TRUST_DSDT_GPE) {
16581621 /*
16591622 * Trust PNP0C09 namespace location rather than
16601623 * ECDT ID. But trust ECDT GPE rather than _GPE
....@@ -1666,11 +1629,19 @@
16661629 acpi_ec_free(ec);
16671630 ec = boot_ec;
16681631 }
1669
- ret = acpi_config_boot_ec(ec, ec->handle, true, is_ecdt);
1670
- } else
1671
- ret = acpi_ec_setup(ec, true);
1632
+ }
1633
+
1634
+ ret = acpi_ec_setup(ec, device);
16721635 if (ret)
1673
- goto err_query;
1636
+ goto err;
1637
+
1638
+ if (ec == boot_ec)
1639
+ acpi_handle_info(boot_ec->handle,
1640
+ "Boot %s EC initialization complete\n",
1641
+ boot_ec_is_ecdt ? "ECDT" : "DSDT");
1642
+
1643
+ acpi_handle_info(ec->handle,
1644
+ "EC: Used to handle transactions and events\n");
16741645
16751646 device->driver_data = ec;
16761647
....@@ -1679,19 +1650,16 @@
16791650 ret = !!request_region(ec->command_addr, 1, "EC cmd");
16801651 WARN(!ret, "Could not request EC cmd io port 0x%lx", ec->command_addr);
16811652
1682
- if (!is_ecdt) {
1683
- /* Reprobe devices depending on the EC */
1684
- acpi_walk_dep_device_list(ec->handle);
1685
- }
1653
+ /* Reprobe devices depending on the EC */
1654
+ acpi_walk_dep_device_list(ec->handle);
1655
+
16861656 acpi_handle_debug(ec->handle, "enumerated.\n");
16871657 return 0;
16881658
1689
-err_query:
1690
- if (ec != boot_ec)
1691
- acpi_ec_remove_query_handlers(ec, true, 0);
1692
-err_alloc:
1659
+err:
16931660 if (ec != boot_ec)
16941661 acpi_ec_free(ec);
1662
+
16951663 return ret;
16961664 }
16971665
....@@ -1747,10 +1715,10 @@
17471715 * namespace EC before the main ACPI device enumeration process. It is
17481716 * retained for historical reason and will be deprecated in the future.
17491717 */
1750
-int __init acpi_ec_dsdt_probe(void)
1718
+void __init acpi_ec_dsdt_probe(void)
17511719 {
1752
- acpi_status status;
17531720 struct acpi_ec *ec;
1721
+ acpi_status status;
17541722 int ret;
17551723
17561724 /*
....@@ -1760,21 +1728,22 @@
17601728 * picking up an invalid EC device.
17611729 */
17621730 if (boot_ec)
1763
- return -ENODEV;
1731
+ return;
17641732
17651733 ec = acpi_ec_alloc();
17661734 if (!ec)
1767
- return -ENOMEM;
1735
+ return;
1736
+
17681737 /*
17691738 * At this point, the namespace is initialized, so start to find
17701739 * the namespace objects.
17711740 */
1772
- status = acpi_get_devices(ec_device_ids[0].id,
1773
- ec_parse_device, ec, NULL);
1741
+ status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device, ec, NULL);
17741742 if (ACPI_FAILURE(status) || !ec->handle) {
1775
- ret = -ENODEV;
1776
- goto error;
1743
+ acpi_ec_free(ec);
1744
+ return;
17771745 }
1746
+
17781747 /*
17791748 * When the DSDT EC is available, always re-configure boot EC to
17801749 * have _REG evaluated. _REG can only be evaluated after the
....@@ -1782,60 +1751,57 @@
17821751 * At this point, the GPE is not fully initialized, so do not to
17831752 * handle the events.
17841753 */
1785
- ret = acpi_config_boot_ec(ec, ec->handle, false, false);
1786
-error:
1787
- if (ret)
1754
+ ret = acpi_ec_setup(ec, NULL);
1755
+ if (ret) {
17881756 acpi_ec_free(ec);
1789
- return ret;
1790
-}
1791
-
1792
-/*
1793
- * If the DSDT EC is not functioning, we still need to prepare a fully
1794
- * functioning ECDT EC first in order to handle the events.
1795
- * https://bugzilla.kernel.org/show_bug.cgi?id=115021
1796
- */
1797
-static int __init acpi_ec_ecdt_start(void)
1798
-{
1799
- acpi_handle handle;
1800
-
1801
- if (!boot_ec)
1802
- return -ENODEV;
1803
- /* In case acpi_ec_ecdt_start() is called after acpi_ec_add() */
1804
- if (!boot_ec_is_ecdt)
1805
- return -ENODEV;
1806
-
1807
- /*
1808
- * At this point, the namespace and the GPE is initialized, so
1809
- * start to find the namespace objects and handle the events.
1810
- *
1811
- * Note: ec->handle can be valid if this function is called after
1812
- * acpi_ec_add(), hence the fast path.
1813
- */
1814
- if (boot_ec->handle == ACPI_ROOT_OBJECT) {
1815
- if (!acpi_ec_ecdt_get_handle(&handle))
1816
- return -ENODEV;
1817
- boot_ec->handle = handle;
1757
+ return;
18181758 }
18191759
1820
- /* Register to ACPI bus with PM ops attached */
1821
- return acpi_bus_register_early_device(ACPI_BUS_TYPE_ECDT_EC);
1760
+ boot_ec = ec;
1761
+
1762
+ acpi_handle_info(ec->handle,
1763
+ "Boot DSDT EC used to handle transactions\n");
18221764 }
18231765
1824
-#if 0
18251766 /*
1826
- * Some EC firmware variations refuses to respond QR_EC when SCI_EVT is not
1827
- * set, for which case, we complete the QR_EC without issuing it to the
1828
- * firmware.
1829
- * https://bugzilla.kernel.org/show_bug.cgi?id=82611
1830
- * https://bugzilla.kernel.org/show_bug.cgi?id=97381
1767
+ * acpi_ec_ecdt_start - Finalize the boot ECDT EC initialization.
1768
+ *
1769
+ * First, look for an ACPI handle for the boot ECDT EC if acpi_ec_add() has not
1770
+ * found a matching object in the namespace.
1771
+ *
1772
+ * Next, in case the DSDT EC is not functioning, it is still necessary to
1773
+ * provide a functional ECDT EC to handle events, so add an extra device object
1774
+ * to represent it (see https://bugzilla.kernel.org/show_bug.cgi?id=115021).
1775
+ *
1776
+ * This is useful on platforms with valid ECDT and invalid DSDT EC settings,
1777
+ * like ASUS X550ZE (see https://bugzilla.kernel.org/show_bug.cgi?id=196847).
18311778 */
1832
-static int ec_flag_query_handshake(const struct dmi_system_id *id)
1779
+static void __init acpi_ec_ecdt_start(void)
18331780 {
1834
- pr_debug("Detected the EC firmware requiring QR_EC issued when SCI_EVT set\n");
1835
- EC_FLAGS_QUERY_HANDSHAKE = 1;
1836
- return 0;
1781
+ struct acpi_table_ecdt *ecdt_ptr;
1782
+ acpi_handle handle;
1783
+ acpi_status status;
1784
+
1785
+ /* Bail out if a matching EC has been found in the namespace. */
1786
+ if (!boot_ec || boot_ec->handle != ACPI_ROOT_OBJECT)
1787
+ return;
1788
+
1789
+ /* Look up the object pointed to from the ECDT in the namespace. */
1790
+ status = acpi_get_table(ACPI_SIG_ECDT, 1,
1791
+ (struct acpi_table_header **)&ecdt_ptr);
1792
+ if (ACPI_FAILURE(status))
1793
+ return;
1794
+
1795
+ status = acpi_get_handle(NULL, ecdt_ptr->id, &handle);
1796
+ if (ACPI_SUCCESS(status)) {
1797
+ boot_ec->handle = handle;
1798
+
1799
+ /* Add a special ACPI device object to represent the boot EC. */
1800
+ acpi_bus_register_early_device(ACPI_BUS_TYPE_ECDT_EC);
1801
+ }
1802
+
1803
+ acpi_put_table((struct acpi_table_header *)ecdt_ptr);
18371804 }
1838
-#endif
18391805
18401806 /*
18411807 * On some hardware it is necessary to clear events accumulated by the EC during
....@@ -1875,14 +1841,14 @@
18751841 }
18761842
18771843 /*
1878
- * Some DSDTs contain wrong GPE setting.
1879
- * Asus FX502VD/VE, GL702VMK, X550VXK, X580VD
1880
- * https://bugzilla.kernel.org/show_bug.cgi?id=195651
1844
+ * Some ECDTs contain wrong GPE setting, but they share the same port addresses
1845
+ * with DSDT EC, don't duplicate the DSDT EC with ECDT EC in this case.
1846
+ * https://bugzilla.kernel.org/show_bug.cgi?id=209989
18811847 */
1882
-static int ec_honor_ecdt_gpe(const struct dmi_system_id *id)
1848
+static int ec_honor_dsdt_gpe(const struct dmi_system_id *id)
18831849 {
1884
- pr_debug("Detected system needing ignore DSDT GPE setting.\n");
1885
- EC_FLAGS_IGNORE_DSDT_GPE = 1;
1850
+ pr_debug("Detected system needing DSDT GPE setting.\n");
1851
+ EC_FLAGS_TRUST_DSDT_GPE = 1;
18861852 return 0;
18871853 }
18881854
....@@ -1892,76 +1858,41 @@
18921858 DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star"),
18931859 DMI_MATCH(DMI_PRODUCT_NAME, "MS-171F"),}, NULL},
18941860 {
1895
- ec_honor_ecdt_gpe, "ASUS FX502VD", {
1896
- DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
1897
- DMI_MATCH(DMI_PRODUCT_NAME, "FX502VD"),}, NULL},
1898
- {
1899
- ec_honor_ecdt_gpe, "ASUS FX502VE", {
1900
- DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
1901
- DMI_MATCH(DMI_PRODUCT_NAME, "FX502VE"),}, NULL},
1902
- {
1903
- ec_honor_ecdt_gpe, "ASUS GL702VMK", {
1904
- DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
1905
- DMI_MATCH(DMI_PRODUCT_NAME, "GL702VMK"),}, NULL},
1906
- {
1907
- ec_honor_ecdt_gpe, "ASUSTeK COMPUTER INC. X505BA", {
1908
- DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
1909
- DMI_MATCH(DMI_PRODUCT_NAME, "X505BA"),}, NULL},
1910
- {
1911
- ec_honor_ecdt_gpe, "ASUSTeK COMPUTER INC. X505BP", {
1912
- DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
1913
- DMI_MATCH(DMI_PRODUCT_NAME, "X505BP"),}, NULL},
1914
- {
1915
- ec_honor_ecdt_gpe, "ASUSTeK COMPUTER INC. X542BA", {
1916
- DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
1917
- DMI_MATCH(DMI_PRODUCT_NAME, "X542BA"),}, NULL},
1918
- {
1919
- ec_honor_ecdt_gpe, "ASUSTeK COMPUTER INC. X542BP", {
1920
- DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
1921
- DMI_MATCH(DMI_PRODUCT_NAME, "X542BP"),}, NULL},
1922
- {
1923
- ec_honor_ecdt_gpe, "ASUS X550VXK", {
1924
- DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
1925
- DMI_MATCH(DMI_PRODUCT_NAME, "X550VXK"),}, NULL},
1926
- {
1927
- ec_honor_ecdt_gpe, "ASUS X580VD", {
1928
- DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
1929
- DMI_MATCH(DMI_PRODUCT_NAME, "X580VD"),}, NULL},
1861
+ /* https://bugzilla.kernel.org/show_bug.cgi?id=209989 */
1862
+ ec_honor_dsdt_gpe, "HP Pavilion Gaming Laptop 15-cx0xxx", {
1863
+ DMI_MATCH(DMI_SYS_VENDOR, "HP"),
1864
+ DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion Gaming Laptop 15-cx0xxx"),}, NULL},
19301865 {
19311866 ec_clear_on_resume, "Samsung hardware", {
19321867 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD.")}, NULL},
19331868 {},
19341869 };
19351870
1936
-int __init acpi_ec_ecdt_probe(void)
1871
+void __init acpi_ec_ecdt_probe(void)
19371872 {
1938
- int ret;
1939
- acpi_status status;
19401873 struct acpi_table_ecdt *ecdt_ptr;
19411874 struct acpi_ec *ec;
1875
+ acpi_status status;
1876
+ int ret;
19421877
1943
- ec = acpi_ec_alloc();
1944
- if (!ec)
1945
- return -ENOMEM;
1946
- /*
1947
- * Generate a boot ec context
1948
- */
1878
+ /* Generate a boot ec context. */
19491879 dmi_check_system(ec_dmi_table);
19501880 status = acpi_get_table(ACPI_SIG_ECDT, 1,
19511881 (struct acpi_table_header **)&ecdt_ptr);
1952
- if (ACPI_FAILURE(status)) {
1953
- ret = -ENODEV;
1954
- goto error;
1955
- }
1882
+ if (ACPI_FAILURE(status))
1883
+ return;
19561884
19571885 if (!ecdt_ptr->control.address || !ecdt_ptr->data.address) {
19581886 /*
19591887 * Asus X50GL:
19601888 * https://bugzilla.kernel.org/show_bug.cgi?id=11880
19611889 */
1962
- ret = -ENODEV;
1963
- goto error;
1890
+ goto out;
19641891 }
1892
+
1893
+ ec = acpi_ec_alloc();
1894
+ if (!ec)
1895
+ goto out;
19651896
19661897 if (EC_FLAGS_CORRECT_ECDT) {
19671898 ec->command_addr = ecdt_ptr->data.address;
....@@ -1970,17 +1901,33 @@
19701901 ec->command_addr = ecdt_ptr->control.address;
19711902 ec->data_addr = ecdt_ptr->data.address;
19721903 }
1973
- ec->gpe = ecdt_ptr->gpe;
1904
+
1905
+ /*
1906
+ * Ignore the GPE value on Reduced Hardware platforms.
1907
+ * Some products have this set to an erroneous value.
1908
+ */
1909
+ if (!acpi_gbl_reduced_hardware)
1910
+ ec->gpe = ecdt_ptr->gpe;
1911
+
1912
+ ec->handle = ACPI_ROOT_OBJECT;
19741913
19751914 /*
19761915 * At this point, the namespace is not initialized, so do not find
19771916 * the namespace objects, or handle the events.
19781917 */
1979
- ret = acpi_config_boot_ec(ec, ACPI_ROOT_OBJECT, false, true);
1980
-error:
1981
- if (ret)
1918
+ ret = acpi_ec_setup(ec, NULL);
1919
+ if (ret) {
19821920 acpi_ec_free(ec);
1983
- return ret;
1921
+ goto out;
1922
+ }
1923
+
1924
+ boot_ec = ec;
1925
+ boot_ec_is_ecdt = true;
1926
+
1927
+ pr_info("Boot ECDT EC used to handle transactions\n");
1928
+
1929
+out:
1930
+ acpi_put_table((struct acpi_table_header *)ecdt_ptr);
19841931 }
19851932
19861933 #ifdef CONFIG_PM_SLEEP
....@@ -1989,7 +1936,7 @@
19891936 struct acpi_ec *ec =
19901937 acpi_driver_data(to_acpi_device(dev));
19911938
1992
- if (acpi_sleep_no_ec_events() && ec_freeze_events)
1939
+ if (!pm_suspend_no_platform() && ec_freeze_events)
19931940 acpi_ec_disable_event(ec);
19941941 return 0;
19951942 }
....@@ -2003,11 +1950,10 @@
20031950 * masked at the low level without side effects.
20041951 */
20051952 if (ec_no_wakeup && test_bit(EC_FLAGS_STARTED, &ec->flags) &&
2006
- ec->reference_count >= 1)
1953
+ ec->gpe >= 0 && ec->reference_count >= 1)
20071954 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_DISABLE);
20081955
2009
- if (acpi_sleep_no_ec_events())
2010
- acpi_ec_enter_noirq(ec);
1956
+ acpi_ec_enter_noirq(ec);
20111957
20121958 return 0;
20131959 }
....@@ -2016,11 +1962,10 @@
20161962 {
20171963 struct acpi_ec *ec = acpi_driver_data(to_acpi_device(dev));
20181964
2019
- if (acpi_sleep_no_ec_events())
2020
- acpi_ec_leave_noirq(ec);
1965
+ acpi_ec_leave_noirq(ec);
20211966
20221967 if (ec_no_wakeup && test_bit(EC_FLAGS_STARTED, &ec->flags) &&
2023
- ec->reference_count >= 1)
1968
+ ec->gpe >= 0 && ec->reference_count >= 1)
20241969 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_ENABLE);
20251970
20261971 return 0;
....@@ -2034,7 +1979,60 @@
20341979 acpi_ec_enable_event(ec);
20351980 return 0;
20361981 }
2037
-#endif
1982
+
1983
+void acpi_ec_mark_gpe_for_wake(void)
1984
+{
1985
+ if (first_ec && !ec_no_wakeup)
1986
+ acpi_mark_gpe_for_wake(NULL, first_ec->gpe);
1987
+}
1988
+EXPORT_SYMBOL_GPL(acpi_ec_mark_gpe_for_wake);
1989
+
1990
+void acpi_ec_set_gpe_wake_mask(u8 action)
1991
+{
1992
+ if (pm_suspend_no_platform() && first_ec && !ec_no_wakeup)
1993
+ acpi_set_gpe_wake_mask(NULL, first_ec->gpe, action);
1994
+}
1995
+
1996
+bool acpi_ec_dispatch_gpe(void)
1997
+{
1998
+ bool work_in_progress;
1999
+ u32 ret;
2000
+
2001
+ if (!first_ec)
2002
+ return acpi_any_gpe_status_set(U32_MAX);
2003
+
2004
+ /*
2005
+ * Report wakeup if the status bit is set for any enabled GPE other
2006
+ * than the EC one.
2007
+ */
2008
+ if (acpi_any_gpe_status_set(first_ec->gpe))
2009
+ return true;
2010
+
2011
+ /*
2012
+ * Dispatch the EC GPE in-band, but do not report wakeup in any case
2013
+ * to allow the caller to process events properly after that.
2014
+ */
2015
+ ret = acpi_dispatch_gpe(NULL, first_ec->gpe);
2016
+ if (ret == ACPI_INTERRUPT_HANDLED)
2017
+ pm_pr_dbg("ACPI EC GPE dispatched\n");
2018
+
2019
+ /* Drain EC work. */
2020
+ do {
2021
+ acpi_ec_flush_work();
2022
+
2023
+ pm_pr_dbg("ACPI EC work flushed\n");
2024
+
2025
+ spin_lock_irq(&first_ec->lock);
2026
+
2027
+ work_in_progress = first_ec->events_in_progress +
2028
+ first_ec->queries_in_progress > 0;
2029
+
2030
+ spin_unlock_irq(&first_ec->lock);
2031
+ } while (work_in_progress && !pm_wakeup_pending());
2032
+
2033
+ return false;
2034
+}
2035
+#endif /* CONFIG_PM_SLEEP */
20382036
20392037 static const struct dev_pm_ops acpi_ec_pm = {
20402038 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(acpi_ec_suspend_noirq, acpi_ec_resume_noirq)
....@@ -2065,13 +2063,13 @@
20652063 {
20662064 switch (ec_event_clearing) {
20672065 case ACPI_EC_EVT_TIMING_STATUS:
2068
- return sprintf(buffer, "status");
2066
+ return sprintf(buffer, "status\n");
20692067 case ACPI_EC_EVT_TIMING_QUERY:
2070
- return sprintf(buffer, "query");
2068
+ return sprintf(buffer, "query\n");
20712069 case ACPI_EC_EVT_TIMING_EVENT:
2072
- return sprintf(buffer, "event");
2070
+ return sprintf(buffer, "event\n");
20732071 default:
2074
- return sprintf(buffer, "invalid");
2072
+ return sprintf(buffer, "invalid\n");
20752073 }
20762074 return 0;
20772075 }
....@@ -2091,23 +2089,31 @@
20912089 .drv.pm = &acpi_ec_pm,
20922090 };
20932091
2094
-static inline int acpi_ec_query_init(void)
2092
+static void acpi_ec_destroy_workqueues(void)
20952093 {
2096
- if (!ec_query_wq) {
2097
- ec_query_wq = alloc_workqueue("kec_query", 0,
2098
- ec_max_queries);
2099
- if (!ec_query_wq)
2100
- return -ENODEV;
2094
+ if (ec_wq) {
2095
+ destroy_workqueue(ec_wq);
2096
+ ec_wq = NULL;
21012097 }
2102
- return 0;
2103
-}
2104
-
2105
-static inline void acpi_ec_query_exit(void)
2106
-{
21072098 if (ec_query_wq) {
21082099 destroy_workqueue(ec_query_wq);
21092100 ec_query_wq = NULL;
21102101 }
2102
+}
2103
+
2104
+static int acpi_ec_init_workqueues(void)
2105
+{
2106
+ if (!ec_wq)
2107
+ ec_wq = alloc_ordered_workqueue("kec", 0);
2108
+
2109
+ if (!ec_query_wq)
2110
+ ec_query_wq = alloc_workqueue("kec_query", 0, ec_max_queries);
2111
+
2112
+ if (!ec_wq || !ec_query_wq) {
2113
+ acpi_ec_destroy_workqueues();
2114
+ return -ENODEV;
2115
+ }
2116
+ return 0;
21112117 }
21122118
21132119 static const struct dmi_system_id acpi_ec_no_wakeup[] = {
....@@ -2116,13 +2122,6 @@
21162122 .matches = {
21172123 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
21182124 DMI_MATCH(DMI_PRODUCT_FAMILY, "Thinkpad X1 Carbon 6th"),
2119
- },
2120
- },
2121
- {
2122
- .ident = "ThinkPad X1 Carbon 6th",
2123
- .matches = {
2124
- DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
2125
- DMI_MATCH(DMI_PRODUCT_FAMILY, "ThinkPad X1 Carbon 6th"),
21262125 },
21272126 },
21282127 {
....@@ -2135,15 +2134,13 @@
21352134 { },
21362135 };
21372136
2138
-int __init acpi_ec_init(void)
2137
+void __init acpi_ec_init(void)
21392138 {
21402139 int result;
2141
- int ecdt_fail, dsdt_fail;
21422140
2143
- /* register workqueue for _Qxx evaluations */
2144
- result = acpi_ec_query_init();
2141
+ result = acpi_ec_init_workqueues();
21452142 if (result)
2146
- return result;
2143
+ return;
21472144
21482145 /*
21492146 * Disable EC wakeup on following systems to prevent periodic
....@@ -2154,16 +2151,10 @@
21542151 pr_debug("Disabling EC wakeup on suspend-to-idle\n");
21552152 }
21562153
2157
- /* Drivers must be started after acpi_ec_query_init() */
2158
- dsdt_fail = acpi_bus_register_driver(&acpi_ec_driver);
2159
- /*
2160
- * Register ECDT to ACPI bus only when PNP0C09 probe fails. This is
2161
- * useful for platforms (confirmed on ASUS X550ZE) with valid ECDT
2162
- * settings but invalid DSDT settings.
2163
- * https://bugzilla.kernel.org/show_bug.cgi?id=196847
2164
- */
2165
- ecdt_fail = acpi_ec_ecdt_start();
2166
- return ecdt_fail && dsdt_fail ? -ENODEV : 0;
2154
+ /* Driver must be registered after acpi_ec_init_workqueues(). */
2155
+ acpi_bus_register_driver(&acpi_ec_driver);
2156
+
2157
+ acpi_ec_ecdt_start();
21672158 }
21682159
21692160 /* EC driver currently not unloadable */
....@@ -2172,6 +2163,6 @@
21722163 {
21732164
21742165 acpi_bus_unregister_driver(&acpi_ec_driver);
2175
- acpi_ec_query_exit();
2166
+ acpi_ec_destroy_workqueues();
21762167 }
21772168 #endif /* 0 */