1. 22 Dec, 2021 2 commits
  2. 17 Dec, 2021 8 commits
    • Paul Cercueil's avatar
      mmc: mxc: Use the new PM macros · 2cdbd92c
      Paul Cercueil authored
      Use DEFINE_SIMPLE_DEV_PM_OPS() instead of the SIMPLE_DEV_PM_OPS()
      macro, along with using pm_sleep_ptr() as this driver doesn't handle
      runtime PM.
      
      This makes it possible to remove the #ifdef CONFIG_PM guard around
      the suspend/resume functions.
      Signed-off-by: default avatarPaul Cercueil <paul@crapouillou.net>
      Acked-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      2cdbd92c
    • Paul Cercueil's avatar
      mmc: jz4740: Use the new PM macros · e0d64ecc
      Paul Cercueil authored
       - Use DEFINE_SIMPLE_DEV_PM_OPS() instead of the SIMPLE_DEV_PM_OPS()
         macro. This makes it possible to remove the __maybe_unused flags
         on the callback functions.
      
       - Since we only have callbacks for suspend/resume, we can conditionally
         compile the dev_pm_ops structure for when CONFIG_PM_SLEEP is enabled;
         so use the pm_sleep_ptr() macro instead of pm_ptr().
      Signed-off-by: default avatarPaul Cercueil <paul@crapouillou.net>
      Acked-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      e0d64ecc
    • Rafael J. Wysocki's avatar
      PM: sleep: Fix error handling in dpm_prepare() · 544e737d
      Rafael J. Wysocki authored
      Commit 2aa36604 ("PM: sleep: Avoid calling put_device() under
      dpm_list_mtx") forgot to update the while () loop termination
      condition to also break the loop if error is nonzero, which
      causes the loop to become infinite if device_prepare() returns
      an error for one device.
      
      Add the missing !error check.
      
      Fixes: 2aa36604 ("PM: sleep: Avoid calling put_device() under dpm_list_mtx")
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reported-by: default avatarThomas Hellström <thomas.hellstrom@linux.intel.com>
      Reviewed-by: default avatarThomas Hellström <thomas.hellstrom@linux.intel.com>
      Reviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Cc: All applicable <stable@vger.kernel.org>
      544e737d
    • Rafael J. Wysocki's avatar
      PM: runtime: Add safety net to supplier device release · d1579e61
      Rafael J. Wysocki authored
      Because refcount_dec_not_one() returns true if the target refcount
      becomes saturated, it is generally unsafe to use its return value as
      a loop termination condition, but that is what happens when a device
      link's supplier device is released during runtime PM suspend
      operations and on device link removal.
      
      To address this, introduce pm_runtime_release_supplier() to be used
      in the above cases which will check the supplier device's runtime
      PM usage counter in addition to the refcount_dec_not_one() return
      value, so the loop can be terminated in case the rpm_active refcount
      value becomes invalid, and update the code in question to use it as
      appropriate.
      
      This change is not expected to have any visible functional impact.
      Reported-by: default avatarPeter Zijlstra <peterz@infradead.org>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      d1579e61
    • Rafael J. Wysocki's avatar
      PM: runtime: Capture device status before disabling runtime PM · c24efa67
      Rafael J. Wysocki authored
      In some cases (for example, during system-wide suspend and resume of
      devices) it is useful to know whether or not runtime PM has ever been
      enabled for a given device and, if so, what the runtime PM status of
      it had been right before runtime PM was disabled for it last time.
      
      For this reason, introduce a new struct dev_pm_info field called
      last_status that will be used for capturing the runtime PM status of
      the device when its power.disable_depth counter changes from 0 to 1.
      
      The new field will be set to RPM_INVALID to start with and whenever
      power.disable_depth changes from 1 to 0, so it will be valid only
      when runtime PM of the device is currently disabled, but it has been
      enabled at least once.
      
      Immediately use power.last_status in rpm_resume() to make it handle
      the case when PM runtime is disabled for the device, but its runtime
      PM status is RPM_ACTIVE more consistently.  Namely, make it return 1
      if power.last_status is also equal to RPM_ACTIVE in that case (the
      idea being that if the status was RPM_ACTIVE last time when
      power.disable_depth was changing from 0 to 1 and it is still
      RPM_ACTIVE, it can be assumed to reflect what happened to the device
      last time when it was using runtime PM) and -EACCES otherwise.
      
      Update the documentation to provide a description of last_status and
      change the description of pm_runtime_resume() in it to reflect the
      new behavior of rpm_active().
      
      While at it, rearrange the code in pm_runtime_enable() to be more
      straightforward and replace the WARN() macro in it with a pr_warn()
      invocation which is less disruptive.
      
      Link: https://lore.kernel.org/linux-pm/20211026222626.39222-1-ulf.hansson@linaro.org/t/#uReviewed-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      c24efa67
    • Paul Cercueil's avatar
      PM: core: Add new *_PM_OPS macros, deprecate old ones · 1a3c7bb0
      Paul Cercueil authored
      This commit introduces the following macros:
      
      SYSTEM_SLEEP_PM_OPS()
      LATE_SYSTEM_SLEEP_PM_OPS()
      NOIRQ_SYSTEM_SLEEP_PM_OPS()
      RUNTIME_PM_OPS()
      
      These new macros are very similar to their SET_*_PM_OPS() equivalent.
      They however differ in the fact that the callbacks they set will always
      be seen as referenced by the compiler. This means that the callback
      functions don't need to be wrapped with a #ifdef CONFIG_PM guard, or
      tagged with __maybe_unused, to prevent the compiler from complaining
      about unused static symbols. The compiler will then simply evaluate at
      compile time whether or not these symbols are dead code.
      
      The callbacks that are only useful with CONFIG_PM_SLEEP is enabled, are
      now also wrapped with a new pm_sleep_ptr() macro, which is inspired from
      pm_ptr(). This is needed for drivers that use different callbacks for
      sleep and runtime PM, to handle the case where CONFIG_PM is set and
      CONFIG_PM_SLEEP is not.
      
      This commit also deprecates the following macros:
      
      SIMPLE_DEV_PM_OPS()
      UNIVERSAL_DEV_PM_OPS()
      
      And introduces the following macros:
      
      DEFINE_SIMPLE_DEV_PM_OPS()
      DEFINE_UNIVERSAL_DEV_PM_OPS()
      
      These macros are similar to the functions they were created to replace,
      with the following differences:
      
       - They use the new macros introduced above, and as such always
         reference the provided callback functions.
      
       - They are not tagged with __maybe_unused. They are meant to be used
         with pm_ptr() or pm_sleep_ptr() for DEFINE_UNIVERSAL_DEV_PM_OPS()
         and DEFINE_SIMPLE_DEV_PM_OPS() respectively.
      
       - They declare the symbol static, since every driver seems to do that
         anyway; and if a non-static use-case is needed an indirection pointer
         could be used.
      
      The point of this change, is to progressively switch from a code model
      where PM callbacks are all protected behind CONFIG_PM guards, to a code
      model where the PM callbacks are always seen by the compiler, but
      discarded if not used.
      Signed-off-by: default avatarPaul Cercueil <paul@crapouillou.net>
      Reviewed-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      1a3c7bb0
    • Paul Cercueil's avatar
      PM: core: Redefine pm_ptr() macro · c06ef740
      Paul Cercueil authored
      The pm_ptr() macro was previously conditionally defined, according to
      the value of the CONFIG_PM option. This meant that the pointed structure
      was either referenced (if CONFIG_PM was set), or never referenced (if
      CONFIG_PM was not set), causing it to be detected as unused by the
      compiler.
      
      This worked fine, but required the __maybe_unused compiler attribute to
      be used to every symbol pointed to by a pointer wrapped with pm_ptr().
      
      We can do better. With this change, the pm_ptr() is now defined the
      same, independently of the value of CONFIG_PM. It now uses the (?:)
      ternary operator to conditionally resolve to its argument. Since the
      condition is known at compile time, the compiler will then choose to
      discard the unused symbols, which won't need to be tagged with
      __maybe_unused anymore.
      
      This pm_ptr() macro is usually used with pointers to dev_pm_ops
      structures created with SIMPLE_DEV_PM_OPS() or similar macros. These do
      use a __maybe_unused flag, which is now useless with this change, so it
      later can be removed. However in the meantime it causes no harm, and all
      the drivers still compile fine with the new pm_ptr() macro.
      Signed-off-by: default avatarPaul Cercueil <paul@crapouillou.net>
      Reviewed-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
      Reviewed-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      c06ef740
    • Paul Cercueil's avatar
      r8169: Avoid misuse of pm_ptr() macro · 5ef11c56
      Paul Cercueil authored
      The pm_ptr() macro should be used when the suspend and resume functions
      can be compiled independently of the CONFIG_PM Kconfig option.
      
      In the case of this driver, the suspend and resume functions are inside
      a section protected by a #ifdef CONFIG_PM guard. Therefore pm_ptr()
      should not be used.
      Signed-off-by: default avatarPaul Cercueil <paul@crapouillou.net>
      Reviewed-by: default avatarArnd Bergmann <arnd@arndb.de>
      Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
      5ef11c56
  3. 12 Dec, 2021 14 commits
  4. 11 Dec, 2021 16 commits