1. 25 8月, 2011 1 次提交
    • R
      PM / Domains: Implement subdomain counters as atomic fields · c4bb3160
      Rafael J. Wysocki 提交于
      Currently, pm_genpd_poweron() and pm_genpd_poweroff() need to take
      the parent PM domain's lock in order to modify the parent's counter
      of active subdomains in a nonracy way.  This causes the locking to be
      considerably complex and in fact is not necessary, because the
      subdomain counters may be implemented as atomic fields and they
      won't have to be modified under a lock.
      
      Replace the unsigned in sd_count field in struct generic_pm_domain
      by an atomic_t one and modify the code in drivers/base/power/domain.c
      to take this change into account.
      
      This patch doesn't change the locking yet, that is going to be done
      in a separate subsequent patch.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      c4bb3160
  2. 14 8月, 2011 1 次提交
  3. 06 8月, 2011 1 次提交
    • R
      PM / Domains: Fix pm_genpd_poweron() · fe202fde
      Rafael J. Wysocki 提交于
      The local variable ret is defined twice in pm_genpd_poweron(), which
      causes this function to always return 0, even if the PM domain's
      .power_on() callback fails, in which case an error code should be
      returned.
      
      Remove the wrong second definition of ret and additionally remove an
      unnecessary definition of wait from pm_genpd_poweron().
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      fe202fde
  4. 15 7月, 2011 2 次提交
  5. 13 7月, 2011 1 次提交
  6. 12 7月, 2011 7 次提交
    • R
      PM / Domains: Queue up power off work only if it is not pending · 56375fd4
      Rafael J. Wysocki 提交于
      In theory it is possible that pm_genpd_poweroff() for two different
      subdomains of the same parent domain will attempt to queue up the
      execution of pm_genpd_poweroff() for the parent twice in a row.  This
      would lead to unpleasant consequences, so prevent it from happening
      by checking if genpd->power_off_work is pending before attempting to
      queue it up.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      56375fd4
    • R
      PM / Domains: Improve handling of wakeup devices during system suspend · 4ecd6e65
      Rafael J. Wysocki 提交于
      Kevin points out that if there's a device that can wake up the system
      from sleep states, but it doesn't generate wakeup signals by itself
      (they are generated on its behalf by other parts of the system) and
      it currently is not enabled to wake up the system (that is,
      device_may_wakeup() returns "false" for it), we may need to change
      its wakeup settings during system suspend (for example, the device
      might have been configured to signal remote wakeup from the system's
      working state, as needed by runtime PM).  Therefore the generic PM
      domains code should invoke the system suspend callbacks provided by
      the device's driver, which it doesn't do if the PM domain is powered
      off during the system suspend's "prepare" stage.  This is a valid
      point.  Moreover, this code also should make sure that system wakeup
      devices that are enabled to wake up the system from sleep states and
      have to remain active for this purpose are not suspended while the
      system is in a sleep state.
      
      To avoid the above issues, make the generic PM domains' .prepare()
      routine, pm_genpd_prepare(), force runtime resume of devices whose
      system wakeup settings may need to be changed during system suspend
      or that should remain active while the system is in a sleep state to
      be able to wake it up from that state.
      Reported-by: NKevin Hilman <khilman@ti.com>
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      4ecd6e65
    • R
      PM / Domains: Do not restore all devices on power off error · 697a7f37
      Rafael J. Wysocki 提交于
      Since every device in a PM domain has its own need_restore
      flag, which is set by __pm_genpd_save_device(), there's no need to
      walk the domain's device list and restore all devices on an error
      from one of the drivers' .runtime_suspend() callbacks.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      697a7f37
    • R
      PM / Domains: Allow callbacks to execute all runtime PM helpers · c6d22b37
      Rafael J. Wysocki 提交于
      A deadlock may occur if one of the PM domains' .start_device() or
      .stop_device() callbacks or a device driver's .runtime_suspend() or
      .runtime_resume() callback executed by the core generic PM domain
      code uses a "wrong" runtime PM helper function.  This happens, for
      example, if .runtime_resume() from one device's driver calls
      pm_runtime_resume() for another device in the same PM domain.
      A similar situation may take place if a device's parent is in the
      same PM domain, in which case the runtime PM framework may execute
      pm_genpd_runtime_resume() automatically for the parent (if it is
      suspended at the moment).  This, of course, is undesirable, so
      the generic PM domains code should be modified to prevent it from
      happening.
      
      The runtime PM framework guarantees that pm_genpd_runtime_suspend()
      and pm_genpd_runtime_resume() won't be executed in parallel for
      the same device, so the generic PM domains code need not worry
      about those cases.  Still, it needs to prevent the other possible
      race conditions between pm_genpd_runtime_suspend(),
      pm_genpd_runtime_resume(), pm_genpd_poweron() and pm_genpd_poweroff()
      from happening and it needs to avoid deadlocks at the same time.
      To this end, modify the generic PM domains code to relax
      synchronization rules so that:
      
      * pm_genpd_poweron() doesn't wait for the PM domain status to
        change from GPD_STATE_BUSY.  If it finds that the status is
        not GPD_STATE_POWER_OFF, it returns without powering the domain on
        (it may modify the status depending on the circumstances).
      
      * pm_genpd_poweroff() returns as soon as it finds that the PM
        domain's status changed from GPD_STATE_BUSY after it's released
        the PM domain's lock.
      
      * pm_genpd_runtime_suspend() doesn't wait for the PM domain status
        to change from GPD_STATE_BUSY after executing the domain's
        .stop_device() callback and executes pm_genpd_poweroff() only
        if pm_genpd_runtime_resume() is not executed in parallel.
      
      * pm_genpd_runtime_resume() doesn't wait for the PM domain status
        to change from GPD_STATE_BUSY after executing pm_genpd_poweron()
        and sets the domain's status to GPD_STATE_BUSY and increments its
        counter of resuming devices (introduced by this change) immediately
        after acquiring the lock.  The counter of resuming devices is then
        decremented after executing __pm_genpd_runtime_resume() for the
        device and the domain's status is reset to GPD_STATE_ACTIVE (unless
        there are more resuming devices in the domain, in which case the
        status remains GPD_STATE_BUSY).
      
      This way, for example, if a device driver's .runtime_resume()
      callback executes pm_runtime_resume() for another device in the same
      PM domain, pm_genpd_poweron() called by pm_genpd_runtime_resume()
      invoked by the runtime PM framework will not block and it will see
      that there's nothing to do for it.  Next, the PM domain's lock will
      be acquired without waiting for its status to change from
      GPD_STATE_BUSY and the device driver's .runtime_resume() callback
      will be executed.  In turn, if pm_runtime_suspend() is executed by
      one device driver's .runtime_resume() callback for another device in
      the same PM domain, pm_genpd_poweroff() executed by
      pm_genpd_runtime_suspend() invoked by the runtime PM framework as a
      result will notice that one of the devices in the domain is being
      resumed, so it will return immediately.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      c6d22b37
    • R
      PM / Domains: Do not execute device callbacks under locks · 17b75eca
      Rafael J. Wysocki 提交于
      Currently, the .start_device() and .stop_device() callbacks from
      struct generic_pm_domain() as well as the device drivers' runtime PM
      callbacks used by the generic PM domains code are executed under
      the generic PM domain lock.  This, unfortunately, is prone to
      deadlocks, for example if a device and its parent are boths members
      of the same PM domain.  For this reason, it would be better if the
      PM domains code didn't execute device callbacks under the lock.
      
      Rework the locking in the generic PM domains code so that the lock
      is dropped for the execution of device callbacks.  To this end,
      introduce PM domains states reflecting the current status of a PM
      domain and such that the PM domain lock cannot be acquired if the
      status is GPD_STATE_BUSY.  Make threads attempting to acquire a PM
      domain's lock wait until the status changes to either
      GPD_STATE_ACTIVE or GPD_STATE_POWER_OFF.
      
      This change by itself doesn't fix the deadlock problem mentioned
      above, but the mechanism introduced by it will be used for for this
      purpose by a subsequent patch.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      17b75eca
    • R
      PM / Domains: Make failing pm_genpd_prepare() clean up properly · b6c10c84
      Rafael J. Wysocki 提交于
      If pm_generic_prepare() in pm_genpd_prepare() returns error code,
      the PM domains counter of "prepared" devices should be decremented
      and its suspend_power_off flag should be reset if this counter drops
      down to zero.  Otherwise, the PM domain runtime PM code will not
      handle the domain correctly (it will permanently think that system
      suspend is in progress).
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      b6c10c84
    • R
      PM / Domains: Set device state to "active" during system resume · 6f00ff78
      Rafael J. Wysocki 提交于
      The runtime PM status of devices in a power domain that is not
      powered off in pm_genpd_complete() should be set to "active", because
      those devices are operational at this point.  Some of them may not be
      in use, though, so make pm_genpd_complete() call pm_runtime_idle()
      in addition to pm_runtime_set_active() for each of them.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      6f00ff78
  7. 10 7月, 2011 1 次提交
  8. 02 7月, 2011 4 次提交
    • R
      PM / Domains: Wakeup devices support for system sleep transitions · d4f2d87a
      Rafael J. Wysocki 提交于
      There is the problem how to handle devices set up to wake up the
      system from sleep states during system-wide power transitions.
      In some cases, those devices can be turned off entirely, because the
      wakeup signals will be generated on their behalf anyway.  In some
      other cases, they will generate wakeup signals if their clocks are
      stopped, but only if power is not removed from them.  Finally, in
      some cases, they can only generate wakeup signals if power is not
      removed from them and their clocks are enabled.
      
      To allow platform-specific code to decide whether or not to put
      wakeup devices (and their PM domains) into low-power state during
      system-wide transitions, such as system suspend, introduce a new
      generic PM domain callback, .active_wakeup(), that will be used
      during the "noirq" phase of system suspend and hibernation (after
      image creation) to decide what to do with wakeup devices.
      Specifically, if this callback is present and returns "true", the
      generic PM domain code will not execute .stop_device() for the
      given wakeup device and its PM domain won't be powered off.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      Acked-by: NKevin Hilman <khilman@ti.com>
      d4f2d87a
    • R
      PM / Domains: System-wide transitions support for generic domains (v5) · 596ba34b
      Rafael J. Wysocki 提交于
      Make generic PM domains support system-wide power transitions
      (system suspend and hibernation).  Add suspend, resume, freeze, thaw,
      poweroff and restore callbacks to be associated with struct
      generic_pm_domain objects and make pm_genpd_init() use them as
      appropriate.
      
      The new callbacks do nothing for devices belonging to power domains
      that were powered down at run time (before the transition).  For the
      other devices the action carried out depends on the type of the
      transition.  During system suspend the power domain .suspend()
      callback executes pm_generic_suspend() for the device, while the
      PM domain .suspend_noirq() callback runs pm_generic_suspend_noirq()
      for it, stops it and eventually removes power from the PM domain it
      belongs to (after all devices in the domain have been stopped and its
      subdomains have been powered off).
      
      During system resume the PM domain .resume_noirq() callback
      restores power to the PM domain (when executed for it first time),
      starts the device and executes pm_generic_resume_noirq() for it,
      while the .resume() callback executes pm_generic_resume() for the
      device.  Finally, the .complete() callback executes pm_runtime_idle()
      for the device which should put it back into the suspended state if
      its runtime PM usage count is equal to zero at that time.
      
      The actions carried out during hibernation and resume from it are
      analogous to the ones described above.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      Reviewed-by: NKevin Hilman <khilman@ti.com>
      596ba34b
    • R
      PM / Domains: Move code from under #ifdef CONFIG_PM_RUNTIME (v2) · 5248051b
      Rafael J. Wysocki 提交于
      There is some code in drivers/base/power/domain.c that will be useful
      for both runtime PM and system-wide power transitions, so make it
      depend on CONFIG_PM instead of CONFIG_PM_RUNTIME.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      Reviewed-by: NKevin Hilman <khilman@ti.com>
      5248051b
    • R
      PM / Domains: Support for generic I/O PM domains (v8) · f721889f
      Rafael J. Wysocki 提交于
      Introduce common headers, helper functions and callbacks allowing
      platforms to use simple generic power domains for runtime power
      management.
      
      Introduce struct generic_pm_domain to be used for representing
      power domains that each contain a number of devices and may be
      parent domains or subdomains with respect to other power domains.
      Among other things, this structure includes callbacks to be
      provided by platforms for performing specific tasks related to
      power management (i.e. ->stop_device() may disable a device's
      clocks, while ->start_device() may enable them, ->power_off() is
      supposed to remove power from the entire power domain
      and ->power_on() is supposed to restore it).
      
      Introduce functions that can be used as power domain runtime PM
      callbacks, pm_genpd_runtime_suspend() and pm_genpd_runtime_resume(),
      as well as helper functions for the initialization of a power
      domain represented by a struct generic_power_domain object,
      adding a device to or removing a device from it and adding or
      removing subdomains.
      
      Introduce configuration option CONFIG_PM_GENERIC_DOMAINS to be
      selected by the platforms that want to use the new code.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      Acked-by: NGreg Kroah-Hartman <gregkh@suse.de>
      Reviewed-by: NKevin Hilman <khilman@ti.com>
      f721889f