1. 04 9月, 2022 1 次提交
  2. 30 6月, 2022 4 次提交
    • H
      ACPI: EC: Drop unused ident initializers from dmi_system_id tables · 3e6573c5
      Hans de Goede 提交于
      Drop the unused const string ident initializers from
      the dmi_system_id tables to make the object size a bit smaller.
      
      While at it also use proper named struct-member initializers for
      the ec_dmi_table[].
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      3e6573c5
    • H
      ACPI: EC: Re-use boot_ec when possible even when EC_FLAGS_TRUST_DSDT_GPE is set · 81df5f91
      Hans de Goede 提交于
      EC_FLAGS_TRUST_DSDT_GPE only does anything when the:
      
      	if (boot_ec && ec->command_addr == boot_ec->command_addr &&
      	    ec->data_addr == boot_ec->data_addr)
      
      conditions are all true. Normally acpi_ec_add() would re-use the boot_ec
      struct acpi_ec in this case. But when the EC_FLAGS_TRUST_DSDT_GPE flag was
      set the code would continue with a newly allocated (second) struct acpi_ec.
      
      There is no reason to use a second struct acpi_ec if all the above checks
      match. Instead just change boot_ec->gpe to ec->gpe, when the flag is set,
      similar to how this is already one done for boot_ec->handle.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      81df5f91
    • H
      ACPI: EC: Drop the EC_FLAGS_IGNORE_DSDT_GPE quirk · f7090e0e
      Hans de Goede 提交于
      It seems that these quirks are no longer necessary since
      commit 69b957c2 ("ACPI: EC: Fix possible issues related to EC
      initialization order"), which has fixed this in a generic manner.
      
      There are 3 commits adding DMI entries with this quirk (adding multiple
      DMI entries per commit). 2/3 commits are from before the generic fix.
      
      Which leaves commit 6306f043 ("ACPI: EC: Make more Asus laptops
      use ECDT _GPE"), which was committed way after the generic fix.
      But this was just due to slow upstreaming of it. This commit stems
      from Endless from 15 Aug 2017 (committed upstream 20 May 2021):
      https://github.com/endlessm/linux/pull/288
      
      The current code should work fine without this:
      
       1. The EC_FLAGS_IGNORE_DSDT_GPE flag is only checked in ec_parse_device(),
          like this:
      
      	if (boot_ec && boot_ec_is_ecdt && EC_FLAGS_IGNORE_DSDT_GPE) {
      		ec->gpe = boot_ec->gpe;
      	} else {
      		/* parse GPE */
      	}
      
       2. ec_parse_device() is only called from acpi_ec_add() and
          acpi_ec_dsdt_probe()
      
       3. acpi_ec_dsdt_probe() starts with:
      
      	if (boot_ec)
      		return;
      
          so it only calls ec_parse_device() when boot_ec == NULL, meaning that
          the quirk never triggers for this call. So only the call in
          acpi_ec_add() matters.
      
       4. acpi_ec_add() does the following after the ec_parse_device() call:
      
      	if (boot_ec && ec->command_addr == boot_ec->command_addr &&
      	    ec->data_addr == boot_ec->data_addr &&
      	    !EC_FLAGS_TRUST_DSDT_GPE) {
      		/*
      		 * Trust PNP0C09 namespace location rather than
      		 * ECDT ID. But trust ECDT GPE rather than _GPE
      		 * because of ASUS quirks, so do not change
      		 * boot_ec->gpe to ec->gpe.
      		 */
      		boot_ec->handle = ec->handle;
      		acpi_handle_debug(ec->handle, "duplicated.\n");
      		acpi_ec_free(ec);
      		ec = boot_ec;
      	}
      
      The quirk only matters if boot_ec != NULL and EC_FLAGS_TRUST_DSDT_GPE
      is never set at the same time as EC_FLAGS_IGNORE_DSDT_GPE.
      
      That means that if the addresses match we always enter this if block and
      then only the ec->handle part of the data stored in ec by ec_parse_device()
      is used and the rest is thrown away, after which ec is made to point
      to boot_ec, at which point ec->gpe == boot_ec->gpe, so the same result
      as with the quirk set, independent of the value of the quirk.
      
      Also note the comment in this block which indicates that the gpe result
      from ec_parse_device() is deliberately not taken to deal with buggy
      Asus laptops and all DMI quirks setting EC_FLAGS_IGNORE_DSDT_GPE are for
      Asus laptops.
      
      Based on the above I believe that unless on some quirked laptops
      the ECDT and DSDT EC addresses do not match we can drop the quirk.
      
      I've checked dmesg output to ensure the ECDT and DSDT EC addresses match
      for quirked models using https://linux-hardware.org hw-probe reports.
      
      I've been able to confirm that the addresses match for the following
      models this way: GL702VMK, X505BA, X505BP, X550VXK, X580VD.
      Whereas for the following models I could find any dmesg output:
      FX502VD, FX502VE, X542BA, X542BP.
      
      Note the models without dmesg all were submitted in patches with a batch
      of models and other models from the same batch checkout ok.
      
      This, combined with that all the code adding the quirks was written before
      the generic fix makes me believe that it is safe to remove this quirk now.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Reviewed-by: NDaniel Drake <drake@endlessos.org>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      f7090e0e
    • H
      ACPI: EC: Remove duplicate ThinkPad X1 Carbon 6th entry from DMI quirks · 0dd6db35
      Hans de Goede 提交于
      Somehow the "ThinkPad X1 Carbon 6th" entry ended up twice in the
      struct dmi_system_id acpi_ec_no_wakeup[] array. Remove one of
      the entries.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      0dd6db35
  3. 15 2月, 2022 4 次提交
  4. 08 2月, 2022 1 次提交
    • R
      ACPI: PM: s2idle: Cancel wakeup before dispatching EC GPE · dc0075ba
      Rafael J. Wysocki 提交于
      Commit 4a9af6ca ("ACPI: EC: Rework flushing of EC work while
      suspended to idle") made acpi_ec_dispatch_gpe() check
      pm_wakeup_pending(), but that is before canceling the SCI wakeup,
      so pm_wakeup_pending() is always true.  This causes the loop in
      acpi_ec_dispatch_gpe() to always terminate after one iteration which
      may not be correct.
      
      Address this issue by canceling the SCI wakeup earlier, from
      acpi_ec_dispatch_gpe() itself.
      
      Fixes: 4a9af6ca ("ACPI: EC: Rework flushing of EC work while suspended to idle")
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      dc0075ba
  5. 02 12月, 2021 10 次提交
    • R
      ACPI: EC: Relocate acpi_ec_create_query() and drop acpi_ec_delete_query() · befd9b5b
      Rafael J. Wysocki 提交于
      Move acpi_ec_create_query() after acpi_ec_event_processor(), drop the
      no longer needed forward declaration of the latter, and eliminate
      acpi_ec_delete_query() which isn't really necessary.
      
      No intentional functional impact.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      befd9b5b
    • R
      ACPI: EC: Make the event work state machine visible · c33676aa
      Rafael J. Wysocki 提交于
      The EC driver uses a relatively simple state machine for the event
      work handling, but it is not really straightforward to figure out.
      
      The states are as follows:
      
       "Ready": The event handling work can be submitted.
      
        In this state, the EC_FLAGS_QUERY_PENDING flag is clear.
      
       "In progress": The event handling work is pending or is being
                      processed.  It cannot be submitted again.
      
        In ths state, the EC_FLAGS_QUERY_PENDING flag is set and both the
        events_to_process count is nonzero and the EC_FLAGS_QUERY_GUARDING
        flag is clear.
      
       "Complete": The event handling work has been completed, but it still
                   cannot be submitted again.
      
        In ths state, the EC_FLAGS_QUERY_PENDING flag is set and the
        events_to_process count is zero or the EC_FLAGS_QUERY_GUARDING
        flag is set.
      
      The state changes from "Ready" to "In progress" when new event is
      detected by advance_transaction() and acpi_ec_submit_event() is
      called by it.
      
      Next, the state can change from "In progress" directly to "Ready" in
      the following situations:
      
       * ec_event_clearing is ACPI_EC_EVT_TIMING_STATUS and the state of
         an ACPI_EC_COMMAND_QUERY transaction becomes ACPI_EC_COMMAND_POLL.
      
       * ec_event_clearing is ACPI_EC_EVT_TIMING_QUERY and the state of
         an ACPI_EC_COMMAND_QUERY transaction becomes
         ACPI_EC_COMMAND_COMPLETE.
      
       * ec_event_clearing is either ACPI_EC_EVT_TIMING_STATUS or
         ACPI_EC_EVT_TIMING_QUERY and there are no more events to
         process (ie. ec->events_to_process becomes 0).
      
      If ec_event_clearing is ACPI_EC_EVT_TIMING_EVENT, however, the
      state must change from "In progress" to "Complete" before it
      can change to "Ready".  The changes from "In progress" to
      "Complete" in that case occur in the following situations:
      
       * The state of an ACPI_EC_COMMAND_QUERY transaction becomes
         ACPI_EC_COMMAND_COMPLETE.
      
       * There are no more events to process (ie. ec->events_to_process
         becomes 0).
      
      Finally, the state changes from "Complete" to "Ready" when
      advance_transaction() is invoked when the state is "Complete" and
      the state of the current transaction is not ACPI_EC_COMMAND_POLL.
      
      To make this state machine visible in the code, add a new
      event_state field to struct acpi_ec and modify the code to use
      it istead the EC_FLAGS_QUERY_PENDING and EC_FLAGS_QUERY_GUARDING
      flags.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      c33676aa
    • R
      ACPI: EC: Avoid queuing unnecessary work in acpi_ec_submit_event() · c793570d
      Rafael J. Wysocki 提交于
      Notice that it is not necessary to queue up the event work again
      if the while () loop in acpi_ec_event_handler() is still running
      which is the case if nr_pending_queries is greater than 0 at the
      beginning of acpi_ec_submit_event() and modify the code to avoid
      doing that.
      
      While at it, rename nr_pending_queries in struct acpi_ec to
      events_to_process which actually matches the role of that field
      and change its data type to unsigned int which is sufficient.
      
      No expected functional impact.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      c793570d
    • R
      ACPI: EC: Rename three functions · eafe7509
      Rafael J. Wysocki 提交于
      Rename acpi_ec_submit_query() to acpi_ec_submit_event(),
      acpi_ec_query() to acpi_ec_submit_query(), and
      acpi_ec_complete_query() to acpi_ec_close_event() to make
      the names reflect what the functions do.
      
      No expected functional impact.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      eafe7509
    • R
      ACPI: EC: Simplify locking in acpi_ec_event_handler() · a105acd7
      Rafael J. Wysocki 提交于
      Because acpi_ec_event_handler() is a work function, it always
      runs in process context with interrupts enabled, so it can use
      spin_lock_irq() and spin_unlock_irq() for the locking.
      
      Make it do so and adjust white space around those calls.
      
      No expected functional impact.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      a105acd7
    • R
      ACPI: EC: Rearrange the loop in acpi_ec_event_handler() · 388fb77d
      Rafael J. Wysocki 提交于
      It is not necessary to check ec->nr_pending_queries against 0 in the
      while () loop in acpi_ec_event_handler(), because that loop terminates
      when ec->nr_pending_queries is 0 and the code depending on that can be
      run after the loop has ended.
      
      Modify the code accordingly and while at it rewrite the comment
      regarding that code to make it clearer.
      
      No intentional functional impact.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      388fb77d
    • R
      ACPI: EC: Fold acpi_ec_check_event() into acpi_ec_event_handler() · 98d36450
      Rafael J. Wysocki 提交于
      Because acpi_ec_event_handler() is the only caller of
      acpi_ec_check_event() and the separation of these two functions
      makes it harder to follow the code flow, fold the latter into the
      former (and simplify that code while at it).
      
      No expected functional impact.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      98d36450
    • R
      ACPI: EC: Pass one argument to acpi_ec_query() · 1f235044
      Rafael J. Wysocki 提交于
      Notice that the second argument to acpi_ec_query() is redundant,
      because in the only case when it is not NULL, the value passed
      through it is only checked against 0 and it can only be 0 when
      acpi_ec_query() returns an error code, but its return value
      is checked along with the value passed through its second
      argument.
      
      Accordingly, modify acpi_ec_query() to take only one argument
      and while at it, change its handling of the case when
      acpi_ec_transaction() returns an error so as to return that
      error value to the caller right away.
      
      No expected functional impact.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      1f235044
    • R
      ACPI: EC: Call advance_transaction() from acpi_ec_dispatch_gpe() · ca8283dc
      Rafael J. Wysocki 提交于
      Calling acpi_dispatch_gpe() from acpi_ec_dispatch_gpe() is generally
      problematic, because it may cause the spurious interrupt handling in
      advance_transaction() to trigger in theory.
      
      However, instead of calling acpi_dispatch_gpe() to dispatch the EC
      GPE, acpi_ec_dispatch_gpe() can call advance_transaction() directly
      on first_ec and it can pass 'false' as its second argument to indicate
      calling it from process context.
      
      Moreover, if advance_transaction() is modified to return a bool value
      indicating whether or not the EC work needs to be flushed, it can be
      used to avoid unnecessary EC work flushing in acpi_ec_dispatch_gpe(),
      so change the code accordingly.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      ca8283dc
    • R
      ACPI: EC: Rework flushing of EC work while suspended to idle · 4a9af6ca
      Rafael J. Wysocki 提交于
      The flushing of pending work in the EC driver uses drain_workqueue()
      to flush the event handling work that can requeue itself via
      advance_transaction(), but this is problematic, because that
      work may also be requeued from the query workqueue.
      
      Namely, if an EC transaction is carried out during the execution of
      a query handler, it involves calling advance_transaction() which
      may queue up the event handling work again.  This causes the kernel
      to complain about attempts to add a work item to the EC event
      workqueue while it is being drained and worst-case it may cause a
      valid event to be skipped.
      
      To avoid this problem, introduce two new counters, events_in_progress
      and queries_in_progress, incremented when a work item is queued on
      the event workqueue or the query workqueue, respectively, and
      decremented at the end of the corresponding work function, and make
      acpi_ec_dispatch_gpe() the workqueues in a loop until the both of
      these counters are zero (or system wakeup is pending) instead of
      calling acpi_ec_flush_work().
      
      At the same time, change __acpi_ec_flush_work() to call
      flush_workqueue() instead of drain_workqueue() to flush the event
      workqueue.
      
      While at it, use the observation that the work item queued in
      acpi_ec_query() cannot be pending at that time, because it is used
      only once, to simplify the code in there.
      
      Additionally, clean up a comment in acpi_ec_query() and adjust white
      space in acpi_ec_event_processor().
      
      Fixes: f0ac20c3 ("ACPI: EC: Fix flushing of pending work")
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      4a9af6ca
  6. 04 11月, 2021 2 次提交
  7. 22 6月, 2021 1 次提交
  8. 07 6月, 2021 1 次提交
  9. 22 5月, 2021 1 次提交
  10. 24 11月, 2020 5 次提交
  11. 23 11月, 2020 1 次提交
    • S
      ACPI: EC: Eliminate in_interrupt() usage · 2e84ea5a
      Sebastian Andrzej Siewior 提交于
      advance_transaction() is using in_interrupt() to distinguish between
      an invocation from the interrupt handler and an invocation from
      another part of the stack.
      
      This looks misleading because chains like
      
        acpi_update_all_gpes() -> acpi_ev_gpe_detect() ->
        acpi_ev_detect_gpe() -> acpi_ec_gpe_handler()
      
      should probably also behave as if they were called from an interrupt
      handler.
      
      Replace in_interrupt() usage with a function parameter.
      
      Set this parameter to `true' if invoked from an interrupt handler
      (acpi_ec_gpe_handler() and acpi_ec_irq_handler()) and `false'
      otherwise.
      Signed-off-by: NSebastian Andrzej Siewior <bigeasy@linutronix.de>
      [ rjw: Subject edits ]
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      2e84ea5a
  12. 06 10月, 2020 2 次提交
  13. 22 6月, 2020 1 次提交
  14. 25 5月, 2020 1 次提交
  15. 18 5月, 2020 1 次提交
    • R
      ACPI: EC: PM: Avoid flushing EC work when EC GPE is inactive · 607b9df6
      Rafael J. Wysocki 提交于
      Flushing the EC work while suspended to idle when the EC GPE status
      is not set causes some EC wakeup events (notably power button and
      lid ones) to be missed after a series of spurious wakeups on the Dell
      XPS13 9360 in my office.
      
      If that happens, the machine cannot be woken up from suspend-to-idle
      by the power button or lid status change and it needs to be woken up
      in some other way (eg. by a key press).
      
      Flushing the EC work only after successful dispatching the EC GPE,
      which means that its status has been set, avoids the issue, so change
      the code in question accordingly.
      
      Fixes: 7b301750 ("ACPI: EC: PM: Avoid premature returns from acpi_s2idle_wake()")
      Cc: 5.4+ <stable@vger.kernel.org> # 5.4+
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Tested-by: NChris Chiu <chiu@endlessm.com>
      607b9df6
  16. 14 5月, 2020 1 次提交
  17. 11 5月, 2020 1 次提交
  18. 09 5月, 2020 1 次提交
  19. 06 4月, 2020 1 次提交