Commit a62e8f19 authored by Alexey Starikovskiy's avatar Alexey Starikovskiy Committed by Len Brown

ACPI: EC: Accelerate query execution

Split EC query handling into acknowledge and execution phase.
This allows much smaller pending query lattency and lowers chances
of EC going "wild" and losing events.

Reference: http://bugzilla.kernel.org/show_bug.cgi?id=14858Signed-off-by: default avatarAlexey Starikovskiy <astarikovskiy@suse.de>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent fcb11235
...@@ -201,14 +201,13 @@ unlock: ...@@ -201,14 +201,13 @@ unlock:
spin_unlock_irqrestore(&ec->curr_lock, flags); spin_unlock_irqrestore(&ec->curr_lock, flags);
} }
static void acpi_ec_gpe_query(void *ec_cxt); static int acpi_ec_sync_query(struct acpi_ec *ec);
static int ec_check_sci(struct acpi_ec *ec, u8 state) static int ec_check_sci_sync(struct acpi_ec *ec, u8 state)
{ {
if (state & ACPI_EC_FLAG_SCI) { if (state & ACPI_EC_FLAG_SCI) {
if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags))
return acpi_os_execute(OSL_EC_BURST_HANDLER, return acpi_ec_sync_query(ec);
acpi_ec_gpe_query, ec);
} }
return 0; return 0;
} }
...@@ -249,11 +248,6 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, ...@@ -249,11 +248,6 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec,
{ {
unsigned long tmp; unsigned long tmp;
int ret = 0; int ret = 0;
pr_debug(PREFIX "transaction start\n");
/* disable GPE during transaction if storm is detected */
if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
acpi_disable_gpe(NULL, ec->gpe);
}
if (EC_FLAGS_MSI) if (EC_FLAGS_MSI)
udelay(ACPI_EC_MSI_UDELAY); udelay(ACPI_EC_MSI_UDELAY);
/* start transaction */ /* start transaction */
...@@ -269,16 +263,6 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, ...@@ -269,16 +263,6 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec,
spin_lock_irqsave(&ec->curr_lock, tmp); spin_lock_irqsave(&ec->curr_lock, tmp);
ec->curr = NULL; ec->curr = NULL;
spin_unlock_irqrestore(&ec->curr_lock, tmp); spin_unlock_irqrestore(&ec->curr_lock, tmp);
if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
/* check if we received SCI during transaction */
ec_check_sci(ec, acpi_ec_read_status(ec));
/* it is safe to enable GPE outside of transaction */
acpi_enable_gpe(NULL, ec->gpe);
} else if (t->irq_count > ACPI_EC_STORM_THRESHOLD) {
pr_info(PREFIX "GPE storm detected, "
"transactions will use polling mode\n");
set_bit(EC_FLAGS_GPE_STORM, &ec->flags);
}
return ret; return ret;
} }
...@@ -321,7 +305,24 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t) ...@@ -321,7 +305,24 @@ static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t)
status = -ETIME; status = -ETIME;
goto end; goto end;
} }
pr_debug(PREFIX "transaction start\n");
/* disable GPE during transaction if storm is detected */
if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
acpi_disable_gpe(NULL, ec->gpe);
}
status = acpi_ec_transaction_unlocked(ec, t); status = acpi_ec_transaction_unlocked(ec, t);
/* check if we received SCI during transaction */
ec_check_sci_sync(ec, acpi_ec_read_status(ec));
if (test_bit(EC_FLAGS_GPE_STORM, &ec->flags)) {
/* it is safe to enable GPE outside of transaction */
acpi_enable_gpe(NULL, ec->gpe);
} else if (t->irq_count > ACPI_EC_STORM_THRESHOLD) {
pr_info(PREFIX "GPE storm detected, "
"transactions will use polling mode\n");
set_bit(EC_FLAGS_GPE_STORM, &ec->flags);
}
end: end:
if (ec->global_lock) if (ec->global_lock)
acpi_release_global_lock(glk); acpi_release_global_lock(glk);
...@@ -443,7 +444,7 @@ int ec_transaction(u8 command, ...@@ -443,7 +444,7 @@ int ec_transaction(u8 command,
EXPORT_SYMBOL(ec_transaction); EXPORT_SYMBOL(ec_transaction);
static int acpi_ec_query(struct acpi_ec *ec, u8 * data) static int acpi_ec_query_unlocked(struct acpi_ec *ec, u8 * data)
{ {
int result; int result;
u8 d; u8 d;
...@@ -452,20 +453,16 @@ static int acpi_ec_query(struct acpi_ec *ec, u8 * data) ...@@ -452,20 +453,16 @@ static int acpi_ec_query(struct acpi_ec *ec, u8 * data)
.wlen = 0, .rlen = 1}; .wlen = 0, .rlen = 1};
if (!ec || !data) if (!ec || !data)
return -EINVAL; return -EINVAL;
/* /*
* Query the EC to find out which _Qxx method we need to evaluate. * Query the EC to find out which _Qxx method we need to evaluate.
* Note that successful completion of the query causes the ACPI_EC_SCI * Note that successful completion of the query causes the ACPI_EC_SCI
* bit to be cleared (and thus clearing the interrupt source). * bit to be cleared (and thus clearing the interrupt source).
*/ */
result = acpi_ec_transaction_unlocked(ec, &t);
result = acpi_ec_transaction(ec, &t);
if (result) if (result)
return result; return result;
if (!d) if (!d)
return -ENODATA; return -ENODATA;
*data = d; *data = d;
return 0; return 0;
} }
...@@ -509,43 +506,78 @@ void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit) ...@@ -509,43 +506,78 @@ void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit)
EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler); EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler);
static void acpi_ec_gpe_query(void *ec_cxt) static void acpi_ec_run(void *cxt)
{ {
struct acpi_ec *ec = ec_cxt; struct acpi_ec_query_handler *handler = cxt;
u8 value = 0; if (!handler)
struct acpi_ec_query_handler *handler, copy;
if (!ec || acpi_ec_query(ec, &value))
return; return;
mutex_lock(&ec->lock); pr_debug(PREFIX "start query execution\n");
if (handler->func)
handler->func(handler->data);
else if (handler->handle)
acpi_evaluate_object(handler->handle, NULL, NULL, NULL);
pr_debug(PREFIX "stop query execution\n");
kfree(handler);
}
static int acpi_ec_sync_query(struct acpi_ec *ec)
{
u8 value = 0;
int status;
struct acpi_ec_query_handler *handler, *copy;
if ((status = acpi_ec_query_unlocked(ec, &value)))
return status;
list_for_each_entry(handler, &ec->list, node) { list_for_each_entry(handler, &ec->list, node) {
if (value == handler->query_bit) { if (value == handler->query_bit) {
/* have custom handler for this bit */ /* have custom handler for this bit */
memcpy(&copy, handler, sizeof(copy)); copy = kmalloc(sizeof(*handler), GFP_KERNEL);
mutex_unlock(&ec->lock); if (!copy)
if (copy.func) { return -ENOMEM;
copy.func(copy.data); memcpy(copy, handler, sizeof(*copy));
} else if (copy.handle) { pr_debug(PREFIX "push query execution (0x%2x) on queue\n", value);
acpi_evaluate_object(copy.handle, NULL, NULL, NULL); return acpi_os_execute(OSL_GPE_HANDLER,
} acpi_ec_run, copy);
return;
} }
} }
return 0;
}
static void acpi_ec_gpe_query(void *ec_cxt)
{
struct acpi_ec *ec = ec_cxt;
if (!ec)
return;
mutex_lock(&ec->lock);
acpi_ec_sync_query(ec);
mutex_unlock(&ec->lock); mutex_unlock(&ec->lock);
} }
static void acpi_ec_gpe_query(void *ec_cxt);
static int ec_check_sci(struct acpi_ec *ec, u8 state)
{
if (state & ACPI_EC_FLAG_SCI) {
if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) {
pr_debug(PREFIX "push gpe query to the queue\n");
return acpi_os_execute(OSL_NOTIFY_HANDLER,
acpi_ec_gpe_query, ec);
}
}
return 0;
}
static u32 acpi_ec_gpe_handler(void *data) static u32 acpi_ec_gpe_handler(void *data)
{ {
struct acpi_ec *ec = data; struct acpi_ec *ec = data;
u8 status;
pr_debug(PREFIX "~~~> interrupt\n"); pr_debug(PREFIX "~~~> interrupt\n");
status = acpi_ec_read_status(ec);
advance_transaction(ec, status); advance_transaction(ec, acpi_ec_read_status(ec));
if (ec_transaction_done(ec) && (status & ACPI_EC_FLAG_IBF) == 0) if (ec_transaction_done(ec) &&
(acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF) == 0) {
wake_up(&ec->wait); wake_up(&ec->wait);
ec_check_sci(ec, status); ec_check_sci(ec, acpi_ec_read_status(ec));
}
return ACPI_INTERRUPT_HANDLED; return ACPI_INTERRUPT_HANDLED;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment