From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Alexey Starikovskiy <astarikovskiy@suse.de>
Cc: ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
Len Brown <lenb@kernel.org>
Subject: Re: [PATCH 04/12] ACPI: EC: Replace atomic variables with bits
Date: Thu, 25 Oct 2007 00:14:22 +0200 [thread overview]
Message-ID: <200710250014.22828.rjw@sisk.pl> (raw)
In-Reply-To: <20071022101830.2937.52617.stgit@samsung>
On Monday, 22 October 2007 12:18, Alexey Starikovskiy wrote:
> Number of flags is about to be increased, so it is better to
> put them all into bits.
> No functional changes.
>
> Signed-off-by: Alexey Starikovskiy <astarikovskiy@suse.de>
> ---
Looks ok.
Acked-by: Rafael J. Wysocki <rjw@sisk.pl>
> drivers/acpi/ec.c | 79 +++++++++++++++++++++++++----------------------------
> 1 files changed, 38 insertions(+), 41 deletions(-)
>
> diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
> index 7b41783..08fbe62 100644
> --- a/drivers/acpi/ec.c
> +++ b/drivers/acpi/ec.c
> @@ -65,7 +65,7 @@ enum ec_command {
> /* EC events */
> enum ec_event {
> ACPI_EC_EVENT_OBF_1 = 1, /* Output buffer full */
> - ACPI_EC_EVENT_IBF_0, /* Input buffer empty */
> + ACPI_EC_EVENT_IBF_0, /* Input buffer empty */
> };
>
> #define ACPI_EC_DELAY 500 /* Wait 500ms max. during EC ops */
> @@ -76,6 +76,11 @@ static enum ec_mode {
> EC_POLL, /* Input buffer empty */
> } acpi_ec_mode = EC_INTR;
>
> +enum {
> + EC_FLAGS_WAIT_GPE = 0, /* Don't check status until GPE arrives */
> + EC_FLAGS_QUERY_PENDING, /* Query is pending */
> +};
> +
> static int acpi_ec_remove(struct acpi_device *device, int type);
> static int acpi_ec_start(struct acpi_device *device);
> static int acpi_ec_stop(struct acpi_device *device, int type);
> @@ -116,9 +121,8 @@ static struct acpi_ec {
> unsigned long command_addr;
> unsigned long data_addr;
> unsigned long global_lock;
> + unsigned long flags;
> struct mutex lock;
> - atomic_t query_pending;
> - atomic_t event_count;
> wait_queue_head_t wait;
> struct list_head list;
> u8 handlers_installed;
> @@ -148,45 +152,42 @@ static inline void acpi_ec_write_data(struct acpi_ec *ec, u8 data)
> outb(data, ec->data_addr);
> }
>
> -static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event,
> - unsigned old_count)
> +static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event)
> {
> - u8 status = acpi_ec_read_status(ec);
> - if (old_count == atomic_read(&ec->event_count))
> + if (test_bit(EC_FLAGS_WAIT_GPE, &ec->flags))
> return 0;
> if (event == ACPI_EC_EVENT_OBF_1) {
> - if (status & ACPI_EC_FLAG_OBF)
> + if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_OBF)
> return 1;
> } else if (event == ACPI_EC_EVENT_IBF_0) {
> - if (!(status & ACPI_EC_FLAG_IBF))
> + if (!(acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF))
> return 1;
> }
>
> return 0;
> }
>
> -static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event,
> - unsigned count, int force_poll)
> +static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, int force_poll)
> {
> if (unlikely(force_poll) || acpi_ec_mode == EC_POLL) {
> unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
> + clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
> while (time_before(jiffies, delay)) {
> - if (acpi_ec_check_status(ec, event, 0))
> + if (acpi_ec_check_status(ec, event))
> return 0;
> }
> } else {
> - if (wait_event_timeout(ec->wait,
> - acpi_ec_check_status(ec, event, count),
> - msecs_to_jiffies(ACPI_EC_DELAY)) ||
> - acpi_ec_check_status(ec, event, 0)) {
> + if (wait_event_timeout(ec->wait, acpi_ec_check_status(ec, event),
> + msecs_to_jiffies(ACPI_EC_DELAY)))
> + return 0;
> + clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
> + if (acpi_ec_check_status(ec, event)) {
> return 0;
> - } else {
> - printk(KERN_ERR PREFIX "acpi_ec_wait timeout,"
> - " status = %d, expect_event = %d\n",
> - acpi_ec_read_status(ec), event);
> }
> }
> -
> + printk(KERN_ERR PREFIX "acpi_ec_wait timeout,"
> + " status = %d, expect_event = %d\n",
> + acpi_ec_read_status(ec), event);
> return -ETIME;
> }
>
> @@ -196,39 +197,38 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
> int force_poll)
> {
> int result = 0;
> - unsigned count = atomic_read(&ec->event_count);
> + set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
> acpi_ec_write_cmd(ec, command);
>
> for (; wdata_len > 0; --wdata_len) {
> - result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count, force_poll);
> + result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
> if (result) {
> printk(KERN_ERR PREFIX
> "write_cmd timeout, command = %d\n", command);
> goto end;
> }
> - count = atomic_read(&ec->event_count);
> + set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
> acpi_ec_write_data(ec, *(wdata++));
> }
>
> if (!rdata_len) {
> - result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count, force_poll);
> + result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, force_poll);
> if (result) {
> printk(KERN_ERR PREFIX
> "finish-write timeout, command = %d\n", command);
> goto end;
> }
> - } else if (command == ACPI_EC_COMMAND_QUERY) {
> - atomic_set(&ec->query_pending, 0);
> - }
> + } else if (command == ACPI_EC_COMMAND_QUERY)
> + clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
>
> for (; rdata_len > 0; --rdata_len) {
> - result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, count, force_poll);
> + result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, force_poll);
> if (result) {
> printk(KERN_ERR PREFIX "read timeout, command = %d\n",
> command);
> goto end;
> }
> - count = atomic_read(&ec->event_count);
> + set_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
> *(rdata++) = acpi_ec_read_data(ec);
> }
> end:
> @@ -261,7 +261,7 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
> /* Make sure GPE is enabled before doing transaction */
> acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
>
> - status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0, 0);
> + status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0);
> if (status) {
> printk(KERN_ERR PREFIX
> "input buffer is not empty, aborting transaction\n");
> @@ -476,20 +476,18 @@ static void acpi_ec_gpe_query(void *ec_cxt)
> static u32 acpi_ec_gpe_handler(void *data)
> {
> acpi_status status = AE_OK;
> - u8 value;
> struct acpi_ec *ec = data;
>
> - atomic_inc(&ec->event_count);
> + clear_bit(EC_FLAGS_WAIT_GPE, &ec->flags);
>
> if (acpi_ec_mode == EC_INTR) {
> wake_up(&ec->wait);
> }
>
> - value = acpi_ec_read_status(ec);
> - if ((value & ACPI_EC_FLAG_SCI) && !atomic_read(&ec->query_pending)) {
> - atomic_set(&ec->query_pending, 1);
> - status =
> - acpi_os_execute(OSL_EC_BURST_HANDLER, acpi_ec_gpe_query, ec);
> + if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_SCI) {
> + if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags))
> + status = acpi_os_execute(OSL_EC_BURST_HANDLER,
> + acpi_ec_gpe_query, ec);
> }
>
> return status == AE_OK ?
> @@ -642,8 +640,7 @@ static struct acpi_ec *make_acpi_ec(void)
> if (!ec)
> return NULL;
>
> - atomic_set(&ec->query_pending, 1);
> - atomic_set(&ec->event_count, 1);
> + ec->flags = 1 << EC_FLAGS_QUERY_PENDING;
> mutex_init(&ec->lock);
> init_waitqueue_head(&ec->wait);
> INIT_LIST_HEAD(&ec->list);
> @@ -833,7 +830,7 @@ static int acpi_ec_start(struct acpi_device *device)
> ret = ec_install_handlers(ec);
>
> /* EC is fully operational, allow queries */
> - atomic_set(&ec->query_pending, 0);
> + clear_bit(EC_FLAGS_QUERY_PENDING, &ec->flags);
> return ret;
> }
>
>
>
>
--
"Premature optimization is the root of all evil." - Donald Knuth
prev parent reply other threads:[~2007-10-24 21:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20071022101535.2937.79385.stgit@samsung>
[not found] ` <20071022101921.2937.66363.stgit@samsung>
2007-10-24 21:51 ` [PATCH 12/12] ACPI: Fan: Drop force_power_state acpi_device option Rafael J. Wysocki
[not found] ` <20071022101915.2937.5590.stgit@samsung>
2007-10-24 21:52 ` [PATCH 11/12] ACPI: Fan: fan device does not need own structure Rafael J. Wysocki
[not found] ` <20071022101909.2937.14958.stgit@samsung>
2007-10-24 21:57 ` [PATCH 10/12] ACPI: power: don't cache power resource state Rafael J. Wysocki
[not found] ` <20071022101903.2937.29352.stgit@samsung>
2007-10-24 21:59 ` [PATCH 09/12] ACPI: EC: Output changes to operational mode Rafael J. Wysocki
[not found] ` <20071022101850.2937.81791.stgit@samsung>
2007-10-24 22:05 ` [PATCH 07/12] ACPI: EC: Don't re-enable GPE for each transaction Rafael J. Wysocki
[not found] ` <20071022101812.2937.49361.stgit@samsung>
2007-10-24 22:07 ` [PATCH 02/12] ACPI: suspend: Wrong order of GPE restore Rafael J. Wysocki
[not found] ` <20071022101805.2937.92527.stgit@samsung>
2007-10-24 22:10 ` [PATCH 01/12] ACPI: sleep: Fix GPE suspend cleanup Rafael J. Wysocki
[not found] ` <20071022101818.2937.8977.stgit@samsung>
2007-10-24 22:11 ` [PATCH 03/12] ACPI: button: send initial lid state after add and resume Rafael J. Wysocki
[not found] ` <20071022101830.2937.52617.stgit@samsung>
2007-10-24 22:14 ` Rafael J. Wysocki [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200710250014.22828.rjw@sisk.pl \
--to=rjw@sisk.pl \
--cc=astarikovskiy@suse.de \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox