From patchwork Fri May 28 20:22:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 102979 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4SKMbvH005544 for ; Fri, 28 May 2010 20:22:42 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756197Ab0E1UWl (ORCPT ); Fri, 28 May 2010 16:22:41 -0400 Received: from fg-out-1718.google.com ([72.14.220.152]:60585 "EHLO fg-out-1718.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755223Ab0E1UWl (ORCPT ); Fri, 28 May 2010 16:22:41 -0400 Received: by fg-out-1718.google.com with SMTP id l26so754689fgb.1 for ; Fri, 28 May 2010 13:22:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:date :message-id:x-mailer:in-reply-to:references; bh=vTffYU3AjYRhC1tdLi5YPtGeW6K+/5PdhhEYruT3/3s=; b=Yz3RK58d2HxACL2he/Hqe+oHaxkuhTxoVrt5FYLPimP6VhZllTheQG1oloisxnZuoi VRTfAjkwic1nMn5H4U6mTwrp6o+uXxACiQBEFkSTFeE1LS0URz24m6ln5AAtmQ5G1KlU KKpn66VQLG8q3MbgDf/T/vfp/CuYwwefcsmog= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=xVEWQs/hLZua0cdwR7+BZEGyuScsB+FiTjekjp1WMzDqNfM80f0FBu7bSgtsYhvyxz dtCqgAaMBxdTXpaH83f5pOvMReSSQ0frB9J0JCgEZfGzAr4r36vbC/IGRkU9ZIwFpxDT UKcmvUtjzn/iaWGv7zRZ4JTMcEdHQrGW0Z/p4= Received: by 10.87.1.2 with SMTP id d2mr3434960fgi.34.1275078159359; Fri, 28 May 2010 13:22:39 -0700 (PDT) Received: from localhost.localdomain (IGLD-84-228-69-131.inter.net.il [84.228.69.131]) by mx.google.com with ESMTPS id e3sm4903301fga.9.2010.05.28.13.22.37 (version=SSLv3 cipher=RC4-MD5); Fri, 28 May 2010 13:22:38 -0700 (PDT) From: Maxim Levitsky To: "linux-acpi@vger.kernel.org" Cc: linux-pm , Matthew Garrett , "Rafael J. Wysocki" Subject: [PATCH 2/2] ACPI / EC / PM: Fix race between EC transactions and system suspend Date: Fri, 28 May 2010 23:22:17 +0300 Message-Id: <1275078137-21139-2-git-send-email-maximlevitsky@gmail.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1275077971.20606.20.camel@maxim-laptop> References: <1275077971.20606.20.camel@maxim-laptop> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 28 May 2010 20:22:42 +0000 (UTC) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index f2234db..2c2b73a 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -485,6 +485,16 @@ void acpi_ec_resume_transactions(void) mutex_unlock(&ec->lock); } +void acpi_ec_resume_transactions_early(void) +{ + /* + * Allow transactions to happen again (this function is called from + * atomic context during wakeup, so we don't need to acquire the mutex). + */ + if (first_ec) + clear_bit(EC_FLAGS_FROZEN, &first_ec->flags); +} + static int acpi_ec_query_unlocked(struct acpi_ec *ec, u8 * data) { int result; diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index e284113..0ec48c7 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h @@ -51,6 +51,7 @@ int acpi_ec_ecdt_probe(void); int acpi_boot_ec_enable(void); void acpi_ec_suspend_transactions(void); void acpi_ec_resume_transactions(void); +void acpi_ec_resume_transactions_early(void); /*-------------------------------------------------------------------------- Suspend/Resume diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c index 18aa074..76ee92c 100644 --- a/drivers/acpi/sleep.c +++ b/drivers/acpi/sleep.c @@ -110,11 +110,13 @@ void __init acpi_old_suspend_ordering(void) } /** - * acpi_pm_disable_gpes - Disable the GPEs. + * acpi_pm_freeze - Disable the GPEs and suspend EC transactions. */ -static int acpi_pm_disable_gpes(void) +static int acpi_pm_freeze(void) { acpi_disable_all_gpes(); + acpi_os_wait_events_complete(NULL); + acpi_ec_suspend_transactions(); return 0; } @@ -144,7 +146,8 @@ static int acpi_pm_prepare(void) int error = __acpi_pm_prepare(); if (!error) - acpi_disable_all_gpes(); + acpi_pm_freeze(); + return error; } @@ -284,6 +287,8 @@ static int acpi_suspend_enter(suspend_state_t pm_state) * acpi_leave_sleep_state will reenable specific GPEs later */ acpi_disable_all_gpes(); + /* Allow EC transactions to happen. */ + acpi_ec_resume_transactions_early(); local_irq_restore(flags); printk(KERN_DEBUG "Back to C!\n"); @@ -297,6 +302,12 @@ static int acpi_suspend_enter(suspend_state_t pm_state) return ACPI_SUCCESS(status) ? 0 : -EFAULT; } +static void acpi_suspend_finish(void) +{ + acpi_ec_resume_transactions(); + acpi_pm_finish(); +} + static int acpi_suspend_state_valid(suspend_state_t pm_state) { u32 acpi_state; @@ -318,7 +329,7 @@ static struct platform_suspend_ops acpi_suspend_ops = { .begin = acpi_suspend_begin, .prepare_late = acpi_pm_prepare, .enter = acpi_suspend_enter, - .wake = acpi_pm_finish, + .wake = acpi_suspend_finish, .end = acpi_pm_end, }; @@ -344,9 +355,9 @@ static int acpi_suspend_begin_old(suspend_state_t pm_state) static struct platform_suspend_ops acpi_suspend_ops_old = { .valid = acpi_suspend_state_valid, .begin = acpi_suspend_begin_old, - .prepare_late = acpi_pm_disable_gpes, + .prepare_late = acpi_pm_freeze, .enter = acpi_suspend_enter, - .wake = acpi_pm_finish, + .wake = acpi_suspend_finish, .end = acpi_pm_end, .recover = acpi_pm_finish, }; @@ -594,6 +605,13 @@ static int acpi_hibernation_enter(void) return ACPI_SUCCESS(status) ? 0 : -EFAULT; } +static void acpi_hibernation_finish(void) +{ + suspend_nvs_free(); + acpi_ec_resume_transactions(); + acpi_pm_finish(); +} + static void acpi_hibernation_leave(void) { /* @@ -611,17 +629,11 @@ static void acpi_hibernation_leave(void) } /* Restore the NVS memory area */ suspend_nvs_restore(); + /* Allow EC transactions to happen. */ + acpi_ec_resume_transactions_early(); } -static int acpi_pm_pre_restore(void) -{ - acpi_disable_all_gpes(); - acpi_os_wait_events_complete(NULL); - acpi_ec_suspend_transactions(); - return 0; -} - -static void acpi_pm_restore_cleanup(void) +static void acpi_pm_thaw(void) { acpi_ec_resume_transactions(); acpi_enable_all_runtime_gpes(); @@ -635,8 +647,8 @@ static struct platform_hibernation_ops acpi_hibernation_ops = { .prepare = acpi_pm_prepare, .enter = acpi_hibernation_enter, .leave = acpi_hibernation_leave, - .pre_restore = acpi_pm_pre_restore, - .restore_cleanup = acpi_pm_restore_cleanup, + .pre_restore = acpi_pm_freeze, + .restore_cleanup = acpi_pm_thaw, }; /** @@ -668,12 +680,9 @@ static int acpi_hibernation_begin_old(void) static int acpi_hibernation_pre_snapshot_old(void) { - int error = acpi_pm_disable_gpes(); - - if (!error) - suspend_nvs_save(); - - return error; + acpi_pm_freeze(); + suspend_nvs_save(); + return 0; } /* @@ -684,12 +693,12 @@ static struct platform_hibernation_ops acpi_hibernation_ops_old = { .begin = acpi_hibernation_begin_old, .end = acpi_pm_end, .pre_snapshot = acpi_hibernation_pre_snapshot_old, - .finish = acpi_pm_finish, - .prepare = acpi_pm_disable_gpes, + .finish = acpi_hibernation_finish, + .prepare = acpi_pm_freeze, .enter = acpi_hibernation_enter, .leave = acpi_hibernation_leave, - .pre_restore = acpi_pm_pre_restore, - .restore_cleanup = acpi_pm_restore_cleanup, + .pre_restore = acpi_pm_freeze, + .restore_cleanup = acpi_pm_thaw, .recover = acpi_pm_finish, }; #endif /* CONFIG_HIBERNATION */