1. 17 Dec, 2021 4 commits
    • 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
  2. 12 Dec, 2021 14 commits
  3. 11 Dec, 2021 22 commits