hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
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 -------------------------------------------------------------------------- */
....@@ -1156,7 +1117,7 @@
11561117 }
11571118 EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler);
11581119
1159
-static struct acpi_ec_query *acpi_ec_create_query(u8 *pval)
1120
+static struct acpi_ec_query *acpi_ec_create_query(struct acpi_ec *ec, u8 *pval)
11601121 {
11611122 struct acpi_ec_query *q;
11621123 struct transaction *t;
....@@ -1164,11 +1125,13 @@
11641125 q = kzalloc(sizeof (struct acpi_ec_query), GFP_KERNEL);
11651126 if (!q)
11661127 return NULL;
1128
+
11671129 INIT_WORK(&q->work, acpi_ec_event_processor);
11681130 t = &q->transaction;
11691131 t->command = ACPI_EC_COMMAND_QUERY;
11701132 t->rdata = pval;
11711133 t->rlen = 1;
1134
+ q->ec = ec;
11721135 return q;
11731136 }
11741137
....@@ -1185,13 +1148,21 @@
11851148 {
11861149 struct acpi_ec_query *q = container_of(work, struct acpi_ec_query, work);
11871150 struct acpi_ec_query_handler *handler = q->handler;
1151
+ struct acpi_ec *ec = q->ec;
11881152
11891153 ec_dbg_evt("Query(0x%02x) started", handler->query_bit);
1154
+
11901155 if (handler->func)
11911156 handler->func(handler->data);
11921157 else if (handler->handle)
11931158 acpi_evaluate_object(handler->handle, NULL, NULL, NULL);
1159
+
11941160 ec_dbg_evt("Query(0x%02x) stopped", handler->query_bit);
1161
+
1162
+ spin_lock_irq(&ec->lock);
1163
+ ec->queries_in_progress--;
1164
+ spin_unlock_irq(&ec->lock);
1165
+
11951166 acpi_ec_delete_query(q);
11961167 }
11971168
....@@ -1201,7 +1172,7 @@
12011172 int result;
12021173 struct acpi_ec_query *q;
12031174
1204
- q = acpi_ec_create_query(&value);
1175
+ q = acpi_ec_create_query(ec, &value);
12051176 if (!q)
12061177 return -ENOMEM;
12071178
....@@ -1223,19 +1194,20 @@
12231194 }
12241195
12251196 /*
1226
- * It is reported that _Qxx are evaluated in a parallel way on
1227
- * Windows:
1197
+ * It is reported that _Qxx are evaluated in a parallel way on Windows:
12281198 * https://bugzilla.kernel.org/show_bug.cgi?id=94411
12291199 *
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.
1200
+ * Put this log entry before queue_work() to make it appear in the log
1201
+ * before any other messages emitted during workqueue handling.
12331202 */
12341203 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
- }
1204
+
1205
+ spin_lock_irq(&ec->lock);
1206
+
1207
+ ec->queries_in_progress++;
1208
+ queue_work(ec_query_wq, &q->work);
1209
+
1210
+ spin_unlock_irq(&ec->lock);
12391211
12401212 err_exit:
12411213 if (result)
....@@ -1293,18 +1265,32 @@
12931265 ec_dbg_evt("Event stopped");
12941266
12951267 acpi_ec_check_event(ec);
1268
+
1269
+ spin_lock_irqsave(&ec->lock, flags);
1270
+ ec->events_in_progress--;
1271
+ spin_unlock_irqrestore(&ec->lock, flags);
12961272 }
12971273
1298
-static u32 acpi_ec_gpe_handler(acpi_handle gpe_device,
1299
- u32 gpe_number, void *data)
1274
+static void acpi_ec_handle_interrupt(struct acpi_ec *ec)
13001275 {
13011276 unsigned long flags;
1302
- struct acpi_ec *ec = data;
13031277
13041278 spin_lock_irqsave(&ec->lock, flags);
13051279 advance_transaction(ec);
13061280 spin_unlock_irqrestore(&ec->lock, flags);
1281
+}
1282
+
1283
+static u32 acpi_ec_gpe_handler(acpi_handle gpe_device,
1284
+ u32 gpe_number, void *data)
1285
+{
1286
+ acpi_ec_handle_interrupt(data);
13071287 return ACPI_INTERRUPT_HANDLED;
1288
+}
1289
+
1290
+static irqreturn_t acpi_ec_irq_handler(int irq, void *data)
1291
+{
1292
+ acpi_ec_handle_interrupt(data);
1293
+ return IRQ_HANDLED;
13081294 }
13091295
13101296 /* --------------------------------------------------------------------------
....@@ -1379,6 +1365,8 @@
13791365 ec->timestamp = jiffies;
13801366 ec->busy_polling = true;
13811367 ec->polling_guard = 0;
1368
+ ec->gpe = -1;
1369
+ ec->irq = -1;
13821370 return ec;
13831371 }
13841372
....@@ -1416,20 +1404,16 @@
14161404 if (ec->data_addr == 0 || ec->command_addr == 0)
14171405 return AE_OK;
14181406
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;
1407
+ /* Get GPE bit assignment (EC events). */
1408
+ /* TODO: Add support for _GPE returning a package */
1409
+ status = acpi_evaluate_integer(handle, "_GPE", NULL, &tmp);
1410
+ if (ACPI_SUCCESS(status))
14311411 ec->gpe = tmp;
1432
- }
1412
+ /*
1413
+ * Errors are non-fatal, allowing for ACPI Reduced Hardware
1414
+ * platforms which use GpioInt instead of GPE.
1415
+ */
1416
+
14331417 /* Use the global lock for all EC transactions? */
14341418 tmp = 0;
14351419 acpi_evaluate_integer(handle, "_GLK", NULL, &tmp);
....@@ -1438,12 +1422,45 @@
14381422 return AE_CTRL_TERMINATE;
14391423 }
14401424
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".
1425
+static bool install_gpe_event_handler(struct acpi_ec *ec)
1426
+{
1427
+ acpi_status status;
1428
+
1429
+ status = acpi_install_gpe_raw_handler(NULL, ec->gpe,
1430
+ ACPI_GPE_EDGE_TRIGGERED,
1431
+ &acpi_ec_gpe_handler, ec);
1432
+ if (ACPI_FAILURE(status))
1433
+ return false;
1434
+
1435
+ if (test_bit(EC_FLAGS_STARTED, &ec->flags) && ec->reference_count >= 1)
1436
+ acpi_ec_enable_gpe(ec, true);
1437
+
1438
+ return true;
1439
+}
1440
+
1441
+static bool install_gpio_irq_event_handler(struct acpi_ec *ec)
1442
+{
1443
+ return request_irq(ec->irq, acpi_ec_irq_handler, IRQF_SHARED,
1444
+ "ACPI EC", ec) >= 0;
1445
+}
1446
+
1447
+/**
1448
+ * ec_install_handlers - Install service callbacks and register query methods.
1449
+ * @ec: Target EC.
1450
+ * @device: ACPI device object corresponding to @ec.
1451
+ *
1452
+ * Install a handler for the EC address space type unless it has been installed
1453
+ * already. If @device is not NULL, also look for EC query methods in the
1454
+ * namespace and register them, and install an event (either GPE or GPIO IRQ)
1455
+ * handler for the EC, if possible.
1456
+ *
1457
+ * Return:
1458
+ * -ENODEV if the address space handler cannot be installed, which means
1459
+ * "unable to handle transactions",
1460
+ * -EPROBE_DEFER if GPIO IRQ acquisition needs to be deferred,
1461
+ * or 0 (success) otherwise.
14451462 */
1446
-static int ec_install_handlers(struct acpi_ec *ec, bool handle_events)
1463
+static int ec_install_handlers(struct acpi_ec *ec, struct acpi_device *device)
14471464 {
14481465 acpi_status status;
14491466
....@@ -1456,45 +1473,51 @@
14561473 &acpi_ec_space_handler,
14571474 NULL, ec);
14581475 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
- }
1476
+ acpi_ec_stop(ec, false);
1477
+ return -ENODEV;
14721478 }
14731479 set_bit(EC_FLAGS_EC_HANDLER_INSTALLED, &ec->flags);
14741480 }
14751481
1476
- if (!handle_events)
1482
+ if (!device)
14771483 return 0;
14781484
1479
- if (!test_bit(EC_FLAGS_EVT_HANDLER_INSTALLED, &ec->flags)) {
1485
+ if (ec->gpe < 0) {
1486
+ /* ACPI reduced hardware platforms use a GpioInt from _CRS. */
1487
+ int irq = acpi_dev_gpio_irq_get(device, 0);
1488
+ /*
1489
+ * Bail out right away for deferred probing or complete the
1490
+ * initialization regardless of any other errors.
1491
+ */
1492
+ if (irq == -EPROBE_DEFER)
1493
+ return -EPROBE_DEFER;
1494
+ else if (irq >= 0)
1495
+ ec->irq = irq;
1496
+ }
1497
+
1498
+ if (!test_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags)) {
14801499 /* Find and register all query methods */
14811500 acpi_walk_namespace(ACPI_TYPE_METHOD, ec->handle, 1,
14821501 acpi_ec_register_query_methods,
14831502 NULL, ec, NULL);
1484
- set_bit(EC_FLAGS_EVT_HANDLER_INSTALLED, &ec->flags);
1503
+ set_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags);
14851504 }
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);
1505
+ if (!test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags)) {
1506
+ bool ready = false;
1507
+
1508
+ if (ec->gpe >= 0)
1509
+ ready = install_gpe_event_handler(ec);
1510
+ else if (ec->irq >= 0)
1511
+ ready = install_gpio_irq_event_handler(ec);
1512
+
1513
+ if (ready) {
1514
+ set_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags);
14931515 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);
14971516 }
1517
+ /*
1518
+ * Failures to install an event handler are not fatal, because
1519
+ * the EC can be polled for events.
1520
+ */
14981521 }
14991522 /* EC is fully operational, allow queries */
15001523 acpi_ec_enable_event(ec);
....@@ -1524,137 +1547,76 @@
15241547 */
15251548 acpi_ec_stop(ec, false);
15261549
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)))
1550
+ if (test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags)) {
1551
+ if (ec->gpe >= 0 &&
1552
+ ACPI_FAILURE(acpi_remove_gpe_handler(NULL, ec->gpe,
1553
+ &acpi_ec_gpe_handler)))
15301554 pr_err("failed to remove gpe handler\n");
1531
- clear_bit(EC_FLAGS_GPE_HANDLER_INSTALLED, &ec->flags);
1555
+
1556
+ if (ec->irq >= 0)
1557
+ free_irq(ec->irq, ec);
1558
+
1559
+ clear_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags);
15321560 }
1533
- if (test_bit(EC_FLAGS_EVT_HANDLER_INSTALLED, &ec->flags)) {
1561
+ if (test_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags)) {
15341562 acpi_ec_remove_query_handlers(ec, true, 0);
1535
- clear_bit(EC_FLAGS_EVT_HANDLER_INSTALLED, &ec->flags);
1563
+ clear_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags);
15361564 }
15371565 }
15381566
1539
-static int acpi_ec_setup(struct acpi_ec *ec, bool handle_events)
1567
+static int acpi_ec_setup(struct acpi_ec *ec, struct acpi_device *device)
15401568 {
15411569 int ret;
15421570
1543
- ret = ec_install_handlers(ec, handle_events);
1571
+ ret = ec_install_handlers(ec, device);
15441572 if (ret)
15451573 return ret;
15461574
15471575 /* First EC capable of handling transactions */
1548
- if (!first_ec) {
1576
+ if (!first_ec)
15491577 first_ec = ec;
1550
- acpi_handle_info(first_ec->handle, "Used as first EC\n");
1578
+
1579
+ pr_info("EC_CMD/EC_SC=0x%lx, EC_DATA=0x%lx\n", ec->command_addr,
1580
+ ec->data_addr);
1581
+
1582
+ if (test_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags)) {
1583
+ if (ec->gpe >= 0)
1584
+ pr_info("GPE=0x%x\n", ec->gpe);
1585
+ else
1586
+ pr_info("IRQ=%d\n", ec->irq);
15511587 }
15521588
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);
15561589 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;
16291590 }
16301591
16311592 static int acpi_ec_add(struct acpi_device *device)
16321593 {
1633
- struct acpi_ec *ec = NULL;
1594
+ struct acpi_ec *ec;
16341595 int ret;
1635
- bool is_ecdt = false;
1636
- acpi_status status;
16371596
16381597 strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
16391598 strcpy(acpi_device_class(device), ACPI_EC_CLASS);
16401599
1641
- if (!strcmp(acpi_device_hid(device), ACPI_ECDT_HID)) {
1642
- is_ecdt = true;
1600
+ if (boot_ec && (boot_ec->handle == device->handle ||
1601
+ !strcmp(acpi_device_hid(device), ACPI_ECDT_HID))) {
1602
+ /* Fast path: this device corresponds to the boot EC. */
16431603 ec = boot_ec;
16441604 } else {
1605
+ acpi_status status;
1606
+
16451607 ec = acpi_ec_alloc();
16461608 if (!ec)
16471609 return -ENOMEM;
1610
+
16481611 status = ec_parse_device(device->handle, 0, ec, NULL);
16491612 if (status != AE_CTRL_TERMINATE) {
16501613 ret = -EINVAL;
1651
- goto err_alloc;
1614
+ goto err;
16521615 }
1653
- }
16541616
1655
- if (acpi_is_boot_ec(ec)) {
1656
- boot_ec_is_ecdt = is_ecdt;
1657
- if (!is_ecdt) {
1617
+ if (boot_ec && ec->command_addr == boot_ec->command_addr &&
1618
+ ec->data_addr == boot_ec->data_addr &&
1619
+ !EC_FLAGS_TRUST_DSDT_GPE) {
16581620 /*
16591621 * Trust PNP0C09 namespace location rather than
16601622 * ECDT ID. But trust ECDT GPE rather than _GPE
....@@ -1666,11 +1628,19 @@
16661628 acpi_ec_free(ec);
16671629 ec = boot_ec;
16681630 }
1669
- ret = acpi_config_boot_ec(ec, ec->handle, true, is_ecdt);
1670
- } else
1671
- ret = acpi_ec_setup(ec, true);
1631
+ }
1632
+
1633
+ ret = acpi_ec_setup(ec, device);
16721634 if (ret)
1673
- goto err_query;
1635
+ goto err;
1636
+
1637
+ if (ec == boot_ec)
1638
+ acpi_handle_info(boot_ec->handle,
1639
+ "Boot %s EC initialization complete\n",
1640
+ boot_ec_is_ecdt ? "ECDT" : "DSDT");
1641
+
1642
+ acpi_handle_info(ec->handle,
1643
+ "EC: Used to handle transactions and events\n");
16741644
16751645 device->driver_data = ec;
16761646
....@@ -1679,19 +1649,16 @@
16791649 ret = !!request_region(ec->command_addr, 1, "EC cmd");
16801650 WARN(!ret, "Could not request EC cmd io port 0x%lx", ec->command_addr);
16811651
1682
- if (!is_ecdt) {
1683
- /* Reprobe devices depending on the EC */
1684
- acpi_walk_dep_device_list(ec->handle);
1685
- }
1652
+ /* Reprobe devices depending on the EC */
1653
+ acpi_walk_dep_device_list(ec->handle);
1654
+
16861655 acpi_handle_debug(ec->handle, "enumerated.\n");
16871656 return 0;
16881657
1689
-err_query:
1690
- if (ec != boot_ec)
1691
- acpi_ec_remove_query_handlers(ec, true, 0);
1692
-err_alloc:
1658
+err:
16931659 if (ec != boot_ec)
16941660 acpi_ec_free(ec);
1661
+
16951662 return ret;
16961663 }
16971664
....@@ -1747,10 +1714,10 @@
17471714 * namespace EC before the main ACPI device enumeration process. It is
17481715 * retained for historical reason and will be deprecated in the future.
17491716 */
1750
-int __init acpi_ec_dsdt_probe(void)
1717
+void __init acpi_ec_dsdt_probe(void)
17511718 {
1752
- acpi_status status;
17531719 struct acpi_ec *ec;
1720
+ acpi_status status;
17541721 int ret;
17551722
17561723 /*
....@@ -1760,21 +1727,22 @@
17601727 * picking up an invalid EC device.
17611728 */
17621729 if (boot_ec)
1763
- return -ENODEV;
1730
+ return;
17641731
17651732 ec = acpi_ec_alloc();
17661733 if (!ec)
1767
- return -ENOMEM;
1734
+ return;
1735
+
17681736 /*
17691737 * At this point, the namespace is initialized, so start to find
17701738 * the namespace objects.
17711739 */
1772
- status = acpi_get_devices(ec_device_ids[0].id,
1773
- ec_parse_device, ec, NULL);
1740
+ status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device, ec, NULL);
17741741 if (ACPI_FAILURE(status) || !ec->handle) {
1775
- ret = -ENODEV;
1776
- goto error;
1742
+ acpi_ec_free(ec);
1743
+ return;
17771744 }
1745
+
17781746 /*
17791747 * When the DSDT EC is available, always re-configure boot EC to
17801748 * have _REG evaluated. _REG can only be evaluated after the
....@@ -1782,60 +1750,57 @@
17821750 * At this point, the GPE is not fully initialized, so do not to
17831751 * handle the events.
17841752 */
1785
- ret = acpi_config_boot_ec(ec, ec->handle, false, false);
1786
-error:
1787
- if (ret)
1753
+ ret = acpi_ec_setup(ec, NULL);
1754
+ if (ret) {
17881755 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;
1756
+ return;
18181757 }
18191758
1820
- /* Register to ACPI bus with PM ops attached */
1821
- return acpi_bus_register_early_device(ACPI_BUS_TYPE_ECDT_EC);
1759
+ boot_ec = ec;
1760
+
1761
+ acpi_handle_info(ec->handle,
1762
+ "Boot DSDT EC used to handle transactions\n");
18221763 }
18231764
1824
-#if 0
18251765 /*
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
1766
+ * acpi_ec_ecdt_start - Finalize the boot ECDT EC initialization.
1767
+ *
1768
+ * First, look for an ACPI handle for the boot ECDT EC if acpi_ec_add() has not
1769
+ * found a matching object in the namespace.
1770
+ *
1771
+ * Next, in case the DSDT EC is not functioning, it is still necessary to
1772
+ * provide a functional ECDT EC to handle events, so add an extra device object
1773
+ * to represent it (see https://bugzilla.kernel.org/show_bug.cgi?id=115021).
1774
+ *
1775
+ * This is useful on platforms with valid ECDT and invalid DSDT EC settings,
1776
+ * like ASUS X550ZE (see https://bugzilla.kernel.org/show_bug.cgi?id=196847).
18311777 */
1832
-static int ec_flag_query_handshake(const struct dmi_system_id *id)
1778
+static void __init acpi_ec_ecdt_start(void)
18331779 {
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;
1780
+ struct acpi_table_ecdt *ecdt_ptr;
1781
+ acpi_handle handle;
1782
+ acpi_status status;
1783
+
1784
+ /* Bail out if a matching EC has been found in the namespace. */
1785
+ if (!boot_ec || boot_ec->handle != ACPI_ROOT_OBJECT)
1786
+ return;
1787
+
1788
+ /* Look up the object pointed to from the ECDT in the namespace. */
1789
+ status = acpi_get_table(ACPI_SIG_ECDT, 1,
1790
+ (struct acpi_table_header **)&ecdt_ptr);
1791
+ if (ACPI_FAILURE(status))
1792
+ return;
1793
+
1794
+ status = acpi_get_handle(NULL, ecdt_ptr->id, &handle);
1795
+ if (ACPI_SUCCESS(status)) {
1796
+ boot_ec->handle = handle;
1797
+
1798
+ /* Add a special ACPI device object to represent the boot EC. */
1799
+ acpi_bus_register_early_device(ACPI_BUS_TYPE_ECDT_EC);
1800
+ }
1801
+
1802
+ acpi_put_table((struct acpi_table_header *)ecdt_ptr);
18371803 }
1838
-#endif
18391804
18401805 /*
18411806 * On some hardware it is necessary to clear events accumulated by the EC during
....@@ -1875,14 +1840,14 @@
18751840 }
18761841
18771842 /*
1878
- * Some DSDTs contain wrong GPE setting.
1879
- * Asus FX502VD/VE, GL702VMK, X550VXK, X580VD
1880
- * https://bugzilla.kernel.org/show_bug.cgi?id=195651
1843
+ * Some ECDTs contain wrong GPE setting, but they share the same port addresses
1844
+ * with DSDT EC, don't duplicate the DSDT EC with ECDT EC in this case.
1845
+ * https://bugzilla.kernel.org/show_bug.cgi?id=209989
18811846 */
1882
-static int ec_honor_ecdt_gpe(const struct dmi_system_id *id)
1847
+static int ec_honor_dsdt_gpe(const struct dmi_system_id *id)
18831848 {
1884
- pr_debug("Detected system needing ignore DSDT GPE setting.\n");
1885
- EC_FLAGS_IGNORE_DSDT_GPE = 1;
1849
+ pr_debug("Detected system needing DSDT GPE setting.\n");
1850
+ EC_FLAGS_TRUST_DSDT_GPE = 1;
18861851 return 0;
18871852 }
18881853
....@@ -1892,76 +1857,41 @@
18921857 DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star"),
18931858 DMI_MATCH(DMI_PRODUCT_NAME, "MS-171F"),}, NULL},
18941859 {
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},
1860
+ /* https://bugzilla.kernel.org/show_bug.cgi?id=209989 */
1861
+ ec_honor_dsdt_gpe, "HP Pavilion Gaming Laptop 15-cx0xxx", {
1862
+ DMI_MATCH(DMI_SYS_VENDOR, "HP"),
1863
+ DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion Gaming Laptop 15-cx0xxx"),}, NULL},
19301864 {
19311865 ec_clear_on_resume, "Samsung hardware", {
19321866 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD.")}, NULL},
19331867 {},
19341868 };
19351869
1936
-int __init acpi_ec_ecdt_probe(void)
1870
+void __init acpi_ec_ecdt_probe(void)
19371871 {
1938
- int ret;
1939
- acpi_status status;
19401872 struct acpi_table_ecdt *ecdt_ptr;
19411873 struct acpi_ec *ec;
1874
+ acpi_status status;
1875
+ int ret;
19421876
1943
- ec = acpi_ec_alloc();
1944
- if (!ec)
1945
- return -ENOMEM;
1946
- /*
1947
- * Generate a boot ec context
1948
- */
1877
+ /* Generate a boot ec context. */
19491878 dmi_check_system(ec_dmi_table);
19501879 status = acpi_get_table(ACPI_SIG_ECDT, 1,
19511880 (struct acpi_table_header **)&ecdt_ptr);
1952
- if (ACPI_FAILURE(status)) {
1953
- ret = -ENODEV;
1954
- goto error;
1955
- }
1881
+ if (ACPI_FAILURE(status))
1882
+ return;
19561883
19571884 if (!ecdt_ptr->control.address || !ecdt_ptr->data.address) {
19581885 /*
19591886 * Asus X50GL:
19601887 * https://bugzilla.kernel.org/show_bug.cgi?id=11880
19611888 */
1962
- ret = -ENODEV;
1963
- goto error;
1889
+ goto out;
19641890 }
1891
+
1892
+ ec = acpi_ec_alloc();
1893
+ if (!ec)
1894
+ goto out;
19651895
19661896 if (EC_FLAGS_CORRECT_ECDT) {
19671897 ec->command_addr = ecdt_ptr->data.address;
....@@ -1970,17 +1900,33 @@
19701900 ec->command_addr = ecdt_ptr->control.address;
19711901 ec->data_addr = ecdt_ptr->data.address;
19721902 }
1973
- ec->gpe = ecdt_ptr->gpe;
1903
+
1904
+ /*
1905
+ * Ignore the GPE value on Reduced Hardware platforms.
1906
+ * Some products have this set to an erroneous value.
1907
+ */
1908
+ if (!acpi_gbl_reduced_hardware)
1909
+ ec->gpe = ecdt_ptr->gpe;
1910
+
1911
+ ec->handle = ACPI_ROOT_OBJECT;
19741912
19751913 /*
19761914 * At this point, the namespace is not initialized, so do not find
19771915 * the namespace objects, or handle the events.
19781916 */
1979
- ret = acpi_config_boot_ec(ec, ACPI_ROOT_OBJECT, false, true);
1980
-error:
1981
- if (ret)
1917
+ ret = acpi_ec_setup(ec, NULL);
1918
+ if (ret) {
19821919 acpi_ec_free(ec);
1983
- return ret;
1920
+ goto out;
1921
+ }
1922
+
1923
+ boot_ec = ec;
1924
+ boot_ec_is_ecdt = true;
1925
+
1926
+ pr_info("Boot ECDT EC used to handle transactions\n");
1927
+
1928
+out:
1929
+ acpi_put_table((struct acpi_table_header *)ecdt_ptr);
19841930 }
19851931
19861932 #ifdef CONFIG_PM_SLEEP
....@@ -1989,7 +1935,7 @@
19891935 struct acpi_ec *ec =
19901936 acpi_driver_data(to_acpi_device(dev));
19911937
1992
- if (acpi_sleep_no_ec_events() && ec_freeze_events)
1938
+ if (!pm_suspend_no_platform() && ec_freeze_events)
19931939 acpi_ec_disable_event(ec);
19941940 return 0;
19951941 }
....@@ -2003,11 +1949,10 @@
20031949 * masked at the low level without side effects.
20041950 */
20051951 if (ec_no_wakeup && test_bit(EC_FLAGS_STARTED, &ec->flags) &&
2006
- ec->reference_count >= 1)
1952
+ ec->gpe >= 0 && ec->reference_count >= 1)
20071953 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_DISABLE);
20081954
2009
- if (acpi_sleep_no_ec_events())
2010
- acpi_ec_enter_noirq(ec);
1955
+ acpi_ec_enter_noirq(ec);
20111956
20121957 return 0;
20131958 }
....@@ -2016,11 +1961,10 @@
20161961 {
20171962 struct acpi_ec *ec = acpi_driver_data(to_acpi_device(dev));
20181963
2019
- if (acpi_sleep_no_ec_events())
2020
- acpi_ec_leave_noirq(ec);
1964
+ acpi_ec_leave_noirq(ec);
20211965
20221966 if (ec_no_wakeup && test_bit(EC_FLAGS_STARTED, &ec->flags) &&
2023
- ec->reference_count >= 1)
1967
+ ec->gpe >= 0 && ec->reference_count >= 1)
20241968 acpi_set_gpe(NULL, ec->gpe, ACPI_GPE_ENABLE);
20251969
20261970 return 0;
....@@ -2034,7 +1978,60 @@
20341978 acpi_ec_enable_event(ec);
20351979 return 0;
20361980 }
2037
-#endif
1981
+
1982
+void acpi_ec_mark_gpe_for_wake(void)
1983
+{
1984
+ if (first_ec && !ec_no_wakeup)
1985
+ acpi_mark_gpe_for_wake(NULL, first_ec->gpe);
1986
+}
1987
+EXPORT_SYMBOL_GPL(acpi_ec_mark_gpe_for_wake);
1988
+
1989
+void acpi_ec_set_gpe_wake_mask(u8 action)
1990
+{
1991
+ if (pm_suspend_no_platform() && first_ec && !ec_no_wakeup)
1992
+ acpi_set_gpe_wake_mask(NULL, first_ec->gpe, action);
1993
+}
1994
+
1995
+bool acpi_ec_dispatch_gpe(void)
1996
+{
1997
+ bool work_in_progress;
1998
+ u32 ret;
1999
+
2000
+ if (!first_ec)
2001
+ return acpi_any_gpe_status_set(U32_MAX);
2002
+
2003
+ /*
2004
+ * Report wakeup if the status bit is set for any enabled GPE other
2005
+ * than the EC one.
2006
+ */
2007
+ if (acpi_any_gpe_status_set(first_ec->gpe))
2008
+ return true;
2009
+
2010
+ /*
2011
+ * Dispatch the EC GPE in-band, but do not report wakeup in any case
2012
+ * to allow the caller to process events properly after that.
2013
+ */
2014
+ ret = acpi_dispatch_gpe(NULL, first_ec->gpe);
2015
+ if (ret == ACPI_INTERRUPT_HANDLED)
2016
+ pm_pr_dbg("ACPI EC GPE dispatched\n");
2017
+
2018
+ /* Drain EC work. */
2019
+ do {
2020
+ acpi_ec_flush_work();
2021
+
2022
+ pm_pr_dbg("ACPI EC work flushed\n");
2023
+
2024
+ spin_lock_irq(&first_ec->lock);
2025
+
2026
+ work_in_progress = first_ec->events_in_progress +
2027
+ first_ec->queries_in_progress > 0;
2028
+
2029
+ spin_unlock_irq(&first_ec->lock);
2030
+ } while (work_in_progress && !pm_wakeup_pending());
2031
+
2032
+ return false;
2033
+}
2034
+#endif /* CONFIG_PM_SLEEP */
20382035
20392036 static const struct dev_pm_ops acpi_ec_pm = {
20402037 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(acpi_ec_suspend_noirq, acpi_ec_resume_noirq)
....@@ -2065,13 +2062,13 @@
20652062 {
20662063 switch (ec_event_clearing) {
20672064 case ACPI_EC_EVT_TIMING_STATUS:
2068
- return sprintf(buffer, "status");
2065
+ return sprintf(buffer, "status\n");
20692066 case ACPI_EC_EVT_TIMING_QUERY:
2070
- return sprintf(buffer, "query");
2067
+ return sprintf(buffer, "query\n");
20712068 case ACPI_EC_EVT_TIMING_EVENT:
2072
- return sprintf(buffer, "event");
2069
+ return sprintf(buffer, "event\n");
20732070 default:
2074
- return sprintf(buffer, "invalid");
2071
+ return sprintf(buffer, "invalid\n");
20752072 }
20762073 return 0;
20772074 }
....@@ -2091,23 +2088,31 @@
20912088 .drv.pm = &acpi_ec_pm,
20922089 };
20932090
2094
-static inline int acpi_ec_query_init(void)
2091
+static void acpi_ec_destroy_workqueues(void)
20952092 {
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;
2093
+ if (ec_wq) {
2094
+ destroy_workqueue(ec_wq);
2095
+ ec_wq = NULL;
21012096 }
2102
- return 0;
2103
-}
2104
-
2105
-static inline void acpi_ec_query_exit(void)
2106
-{
21072097 if (ec_query_wq) {
21082098 destroy_workqueue(ec_query_wq);
21092099 ec_query_wq = NULL;
21102100 }
2101
+}
2102
+
2103
+static int acpi_ec_init_workqueues(void)
2104
+{
2105
+ if (!ec_wq)
2106
+ ec_wq = alloc_ordered_workqueue("kec", 0);
2107
+
2108
+ if (!ec_query_wq)
2109
+ ec_query_wq = alloc_workqueue("kec_query", 0, ec_max_queries);
2110
+
2111
+ if (!ec_wq || !ec_query_wq) {
2112
+ acpi_ec_destroy_workqueues();
2113
+ return -ENODEV;
2114
+ }
2115
+ return 0;
21112116 }
21122117
21132118 static const struct dmi_system_id acpi_ec_no_wakeup[] = {
....@@ -2116,13 +2121,6 @@
21162121 .matches = {
21172122 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
21182123 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"),
21262124 },
21272125 },
21282126 {
....@@ -2135,15 +2133,13 @@
21352133 { },
21362134 };
21372135
2138
-int __init acpi_ec_init(void)
2136
+void __init acpi_ec_init(void)
21392137 {
21402138 int result;
2141
- int ecdt_fail, dsdt_fail;
21422139
2143
- /* register workqueue for _Qxx evaluations */
2144
- result = acpi_ec_query_init();
2140
+ result = acpi_ec_init_workqueues();
21452141 if (result)
2146
- return result;
2142
+ return;
21472143
21482144 /*
21492145 * Disable EC wakeup on following systems to prevent periodic
....@@ -2154,16 +2150,10 @@
21542150 pr_debug("Disabling EC wakeup on suspend-to-idle\n");
21552151 }
21562152
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;
2153
+ /* Driver must be registered after acpi_ec_init_workqueues(). */
2154
+ acpi_bus_register_driver(&acpi_ec_driver);
2155
+
2156
+ acpi_ec_ecdt_start();
21672157 }
21682158
21692159 /* EC driver currently not unloadable */
....@@ -2172,6 +2162,6 @@
21722162 {
21732163
21742164 acpi_bus_unregister_driver(&acpi_ec_driver);
2175
- acpi_ec_query_exit();
2165
+ acpi_ec_destroy_workqueues();
21762166 }
21772167 #endif /* 0 */