aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLv Zheng <lv.zheng@intel.com>2015-01-14 06:28:53 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2015-01-23 16:06:49 -0500
commit550b3aac5a72c4209f1ad3bc0ade663d5cb36f7f (patch)
treea348dd2ecfb05cddb5a5de9122d3477792d45690
parent74443bbed72ab22ee005ecb6ecdc657a8018e1db (diff)
ACPI / EC: Cleanup QR_EC related code
The QR_EC related code pieces have redundants, this patch merges them into acpi_ec_query() which invokes acpi_ec_transaction() where EC mutex and the global lock are already held. After doing so, query handler traversal still need to be locked by EC mutex after invoking acpi_ec_transaction(). Note that EC event handling is sequential. We fetch one event from firmware event queue and process it until 0x00 or error returned. So we don't need to hold mutex for whole acpi_ec_clear() process to determine whether we should continue to drain. And for the same reason, we don't need to hold mutex for the whole procedure from the QR_EC transaction to the query handler traversal. Signed-off-by: Lv Zheng <lv.zheng@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/acpi/ec.c70
1 files changed, 20 insertions, 50 deletions
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 89e89b21dd54..c385606bbceb 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -120,7 +120,7 @@ struct transaction {
120 u8 flags; 120 u8 flags;
121}; 121};
122 122
123static int acpi_ec_sync_query(struct acpi_ec *ec, u8 *data); 123static int acpi_ec_query(struct acpi_ec *ec, u8 *data);
124 124
125struct acpi_ec *boot_ec, *first_ec; 125struct acpi_ec *boot_ec, *first_ec;
126EXPORT_SYMBOL(first_ec); 126EXPORT_SYMBOL(first_ec);
@@ -508,7 +508,7 @@ static void acpi_ec_clear(struct acpi_ec *ec)
508 u8 value = 0; 508 u8 value = 0;
509 509
510 for (i = 0; i < ACPI_EC_CLEAR_MAX; i++) { 510 for (i = 0; i < ACPI_EC_CLEAR_MAX; i++) {
511 status = acpi_ec_sync_query(ec, &value); 511 status = acpi_ec_query(ec, &value);
512 if (status || !value) 512 if (status || !value)
513 break; 513 break;
514 } 514 }
@@ -539,14 +539,11 @@ void acpi_ec_unblock_transactions(void)
539 if (!ec) 539 if (!ec)
540 return; 540 return;
541 541
542 mutex_lock(&ec->mutex);
543 /* Allow transactions to be carried out again */ 542 /* Allow transactions to be carried out again */
544 clear_bit(EC_FLAGS_BLOCKED, &ec->flags); 543 clear_bit(EC_FLAGS_BLOCKED, &ec->flags);
545 544
546 if (EC_FLAGS_CLEAR_ON_RESUME) 545 if (EC_FLAGS_CLEAR_ON_RESUME)
547 acpi_ec_clear(ec); 546 acpi_ec_clear(ec);
548
549 mutex_unlock(&ec->mutex);
550} 547}
551 548
552void acpi_ec_unblock_transactions_early(void) 549void acpi_ec_unblock_transactions_early(void)
@@ -559,30 +556,6 @@ void acpi_ec_unblock_transactions_early(void)
559 clear_bit(EC_FLAGS_BLOCKED, &first_ec->flags); 556 clear_bit(EC_FLAGS_BLOCKED, &first_ec->flags);
560} 557}
561 558
562static int acpi_ec_query_unlocked(struct acpi_ec *ec, u8 *data)
563{
564 int result;
565 u8 d;
566 struct transaction t = {.command = ACPI_EC_COMMAND_QUERY,
567 .wdata = NULL, .rdata = &d,
568 .wlen = 0, .rlen = 1};
569
570 if (!ec || !data)
571 return -EINVAL;
572 /*
573 * Query the EC to find out which _Qxx method we need to evaluate.
574 * Note that successful completion of the query causes the ACPI_EC_SCI
575 * bit to be cleared (and thus clearing the interrupt source).
576 */
577 result = acpi_ec_transaction_unlocked(ec, &t);
578 if (result)
579 return result;
580 if (!d)
581 return -ENODATA;
582 *data = d;
583 return 0;
584}
585
586/* -------------------------------------------------------------------------- 559/* --------------------------------------------------------------------------
587 Event Management 560 Event Management
588 -------------------------------------------------------------------------- */ 561 -------------------------------------------------------------------------- */
@@ -662,19 +635,30 @@ static void acpi_ec_run(void *cxt)
662 acpi_ec_put_query_handler(handler); 635 acpi_ec_put_query_handler(handler);
663} 636}
664 637
665static int acpi_ec_sync_query(struct acpi_ec *ec, u8 *data) 638static int acpi_ec_query(struct acpi_ec *ec, u8 *data)
666{ 639{
667 u8 value = 0; 640 u8 value = 0;
668 int result; 641 int result;
669 acpi_status status; 642 acpi_status status;
670 struct acpi_ec_query_handler *handler; 643 struct acpi_ec_query_handler *handler;
644 struct transaction t = {.command = ACPI_EC_COMMAND_QUERY,
645 .wdata = NULL, .rdata = &value,
646 .wlen = 0, .rlen = 1};
671 647
672 result = acpi_ec_query_unlocked(ec, &value); 648 /*
673 if (data) 649 * Query the EC to find out which _Qxx method we need to evaluate.
674 *data = value; 650 * Note that successful completion of the query causes the ACPI_EC_SCI
651 * bit to be cleared (and thus clearing the interrupt source).
652 */
653 result = acpi_ec_transaction(ec, &t);
675 if (result) 654 if (result)
676 return result; 655 return result;
656 if (data)
657 *data = value;
658 if (!value)
659 return -ENODATA;
677 660
661 mutex_lock(&ec->mutex);
678 list_for_each_entry(handler, &ec->list, node) { 662 list_for_each_entry(handler, &ec->list, node) {
679 if (value == handler->query_bit) { 663 if (value == handler->query_bit) {
680 /* have custom handler for this bit */ 664 /* have custom handler for this bit */
@@ -689,26 +673,15 @@ static int acpi_ec_sync_query(struct acpi_ec *ec, u8 *data)
689 break; 673 break;
690 } 674 }
691 } 675 }
676 mutex_unlock(&ec->mutex);
692 return result; 677 return result;
693} 678}
694 679
695static void acpi_ec_gpe_poller(struct work_struct *work) 680static void acpi_ec_gpe_poller(struct work_struct *work)
696{ 681{
697 acpi_status status;
698 u32 glk;
699 struct acpi_ec *ec = container_of(work, struct acpi_ec, work); 682 struct acpi_ec *ec = container_of(work, struct acpi_ec, work);
700 683
701 mutex_lock(&ec->mutex); 684 acpi_ec_query(ec, NULL);
702 if (ec->global_lock) {
703 status = acpi_acquire_global_lock(ACPI_EC_UDELAY_GLK, &glk);
704 if (ACPI_FAILURE(status))
705 goto unlock;
706 }
707 acpi_ec_sync_query(ec, NULL);
708 if (ec->global_lock)
709 acpi_release_global_lock(glk);
710unlock:
711 mutex_unlock(&ec->mutex);
712} 685}
713 686
714static u32 acpi_ec_gpe_handler(acpi_handle gpe_device, 687static u32 acpi_ec_gpe_handler(acpi_handle gpe_device,
@@ -932,11 +905,8 @@ static int acpi_ec_add(struct acpi_device *device)
932 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags); 905 clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
933 906
934 /* Clear stale _Q events if hardware might require that */ 907 /* Clear stale _Q events if hardware might require that */
935 if (EC_FLAGS_CLEAR_ON_RESUME) { 908 if (EC_FLAGS_CLEAR_ON_RESUME)
936 mutex_lock(&ec->mutex);
937 acpi_ec_clear(ec); 909 acpi_ec_clear(ec);
938 mutex_unlock(&ec->mutex);
939 }
940 return ret; 910 return ret;
941} 911}
942 912