1. 06 5月, 2012 1 次提交
    • R
      PM / Domains: Make device removal more straightforward · efa69025
      Rafael J. Wysocki 提交于
      The removal of a device from a PM domain doesn't have to browse
      the domain's device list, because it can check directly if the
      device belongs to the given domain.  Moreover, it should clear
      the domain_data pointer in dev->power.subsys_data, because
      dev_pm_put_subsys_data(dev) may not remove dev->power.subsys_data
      and the stale domain data pointer may cause problems to happen.
      
      Rework pm_genpd_remove_device() taking the above observations into
      account.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      efa69025
  2. 02 5月, 2012 3 次提交
    • R
      PM / Runtime: Remove device fields related to suspend time, v2 · 76e267d8
      Rafael J. Wysocki 提交于
      After the previous changes in default_stop_ok() and
      default_power_down_ok() for PM domains, there are two fields in
      struct dev_pm_info that aren't necessary any more,  suspend_time
      and max_time_suspended_ns.
      
      Remove those fields along with all of the code that accesses them,
      which simplifies the runtime PM framework quite a bit.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      76e267d8
    • R
      PM / Domains: Rework default domain power off governor function, v2 · dd8683e9
      Rafael J. Wysocki 提交于
      The existing default domain power down governor function for PM
      domains, default_power_down_ok(), is supposed to check whether or not
      the PM QoS latency constraints of the devices in the domain will be
      violated if the domain is turned off by pm_genpd_poweroff().
      However, the computations carried out by it don't reflect the
      definition of the PM QoS latency constrait in
      Documentation/ABI/testing/sysfs-devices-power.
      
      Make default_power_down_ok() follow the definition of the PM QoS
      latency constrait.  In particular, make it only take latencies into
      account, because it doesn't matter how much time has elapsed since
      the domain's devices were suspended for the computation.
      
      Remove the break_even_ns and power_off_time fields from
      struct generic_pm_domain, because they are not necessary any more.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      dd8683e9
    • R
      PM / Domains: Rework default device stop governor function, v2 · a5bef810
      Rafael J. Wysocki 提交于
      The existing default device stop governor function for PM domains,
      default_stop_ok(), is supposed to check whether or not the device's
      PM QoS latency constraint will be violated if the device is stopped
      by pm_genpd_runtime_suspend().  However, the computations carried out
      by it don't reflect the definition of the PM QoS latency constrait in
      Documentation/ABI/testing/sysfs-devices-power.
      
      Make default_stop_ok() follow the definition of the PM QoS latency
      constrait.  In particular, make it take the device's start and stop
      latencies correctly.
      
      Add a new field, effective_constraint_ns, to struct gpd_timing_data
      and use it to store the difference between the device's PM QoS
      constraint and its resume latency for use by the device's parent
      (the effective_constraint_ns values for the children are used for
      computing the parent's one along with its PM QoS constraint).
      
      Remove the break_even_ns field from struct gpd_timing_data, because
      it's not used any more.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      a5bef810
  3. 19 3月, 2012 1 次提交
  4. 17 3月, 2012 3 次提交
    • R
      PM / Domains: Introduce "always on" device flag · 1e78a0c7
      Rafael J. Wysocki 提交于
      The TMU device on the Mackerel board belongs to the A4R power domain
      and loses power when the domain is turned off.  Unfortunately, the
      TMU driver is not prepared to cope with such situations and crashes
      the system when that happens.  To work around this problem introduce
      a new helper function, pm_genpd_dev_always_on(), allowing a device
      driver to mark its device as "always on" in case it belongs to a PM
      domain, which will make the generic PM domains core code avoid
      powering off the domain containing the device, both at run time and
      during system suspend.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      Tested-by: NSimon Horman <horms@verge.net.au>
      Acked-by: NPaul Mundt <lethal@linux-sh.org>
      Cc: stable@vger.kernel.org
      1e78a0c7
    • R
      PM / Domains: Fix hibernation restore of devices, v2 · 65533bbf
      Rafael J. Wysocki 提交于
      During resume from hibernation pm_genpd_restore_noirq() should only
      power off domains whose suspend_power_off flags are set once and
      not every time it is called for a device in the given domain.
      Moreover, it shouldn't decrement genpd->suspended_count, because
      that field is not touched during device freezing and therefore it is
      always equal to 0 when pm_genpd_restore_noirq() runs for the first
      device in the given domain.
      
      This means pm_genpd_restore_noirq() may use genpd->suspended_count
      to determine whether or not it it has been called for the domain in
      question already in this cycle (it only needs to increment that
      field every time it runs for this purpose) and whether or not it
      should check if the domain needs to be powered off.  For that to
      work, though, pm_genpd_prepare() has to clear genpd->suspended_count
      when it runs for the first device in the given domain (in which case
      that flag need not be cleared during domain initialization).
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      Cc: stable@vger.kernel.org
      65533bbf
    • R
      PM / Domains: Fix handling of wakeup devices during system resume · cc85b207
      Rafael J. Wysocki 提交于
      During system suspend pm_genpd_suspend_noirq() checks if the given
      device is in a wakeup path (i.e. it appears to be needed for one or
      more wakeup devices to work or is a wakeup device itself) and if it
      needs to be "active" for wakeup to work.  If that is the case, the
      function returns 0 without incrementing the device domain's counter
      of suspended devices and without executing genpd_stop_dev() for the
      device.  In consequence, the device is not stopped (e.g. its clock
      isn't disabled) and power is always supplied to its domain in the
      resulting system sleep state.
      
      However, pm_genpd_resume_noirq() doesn't repeat that check and it
      runs genpd_start_dev() and decrements the domain's counter of
      suspended devices even for the wakeup device that weren't stopped by
      pm_genpd_suspend_noirq().  As a result, the start callback may be run
      unnecessarily for them and their domains' counters of suspended
      devices may become negative.  Both outcomes aren't desirable, so fix
      pm_genpd_resume_noirq() to look for wakeup devices that might not be
      stopped by during system suspend.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      Tested-by: NSimon Horman <horms@verge.net.au>
      Cc: stable@vger.kernel.org
      cc85b207
  5. 30 1月, 2012 1 次提交
    • R
      PM / Domains: Run late/early device suspend callbacks at the right time · 0496c8ae
      Rafael J. Wysocki 提交于
      After the introduction of the late/early phases of device
      suspend/resume during system-wide power transitions it is possible
      to make the generic PM domains code execute its default late/early
      device suspend/resume callbacks during those phases instead of the
      corresponding _noirq phases.  The _noirq device suspend/resume
      phases were only used for executing those callbacks, because this
      was the only way it could be done, but now we can do better.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      0496c8ae
  6. 27 1月, 2012 1 次提交
    • T
      PM / Domains: Add OF support · c8aa130b
      Thomas Abraham 提交于
      A device node pointer is added to generic pm domain structure to associate
      the domain with a node in the device tree. The platform code parses the
      device tree to find available nodes representing the generic power domain,
      instantiates the available domains and initializes them by calling
      pm_genpd_init().
      
      Nodes representing the devices include a phandle of the power domain to
      which it belongs. As these devices get instantiated, the driver code
      checkes for availability of a power domain phandle, converts the phandle
      to a device node and uses the new pm_genpd_of_add_device() api to
      associate the device with a power domain.
      
      pm_genpd_of_add_device() runs through its list of registered power domains
      and matches the OF node of the domain with the one specified as the
      parameter. If a match is found, the device is associated with the matched
      domain.
      
      Cc: Rob Herring <rob.herring@calxeda.com>
      Cc: Grant Likely <grant.likely@secretlab.ca>
      Signed-off-by: NThomas Abraham <thomas.abraham@linaro.org>
      Acked-by: NRafael J. Wysocki <rjw@sisk.pl>
      Signed-off-by: NKukjin Kim <kgene.kim@samsung.com>
      c8aa130b
  7. 14 1月, 2012 1 次提交
  8. 09 12月, 2011 1 次提交
  9. 07 12月, 2011 1 次提交
  10. 02 12月, 2011 6 次提交
    • R
      PM / Domains: Automatically update overoptimistic latency information · 0140d8bd
      Rafael J. Wysocki 提交于
      Measure the time of execution of the .stop(), .start(), .save_state()
      and .restore_state() PM domain device callbacks and if the result
      is greater than the corresponding latency value stored in the
      device's struct generic_pm_domain_data object, replace the inaccurate
      value with the measured time.
      
      Do analogously for the PM domains' .power_off() and .power_off()
      callbacks.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      0140d8bd
    • R
      PM / Domains: Add default power off governor function (v4) · 221e9b58
      Rafael J. Wysocki 提交于
      Add a function deciding whether or not a given PM domain should
      be powered off on the basis of the PM QoS constraints of devices
      belonging to it and their PM QoS timing data.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      221e9b58
    • R
      PM / Domains: Add device stop governor function (v4) · b02c999a
      Rafael J. Wysocki 提交于
      Add a function deciding whether or not devices should be stopped in
      pm_genpd_runtime_suspend() depending on their PM QoS constraints
      and stop/start timing values.  Make it possible to add information
      used by this function to device objects.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      Acked-by: NMagnus Damm <damm@opensource.se>
      b02c999a
    • R
      PM / Domains: Rework system suspend callback routines (v2) · d23b9b00
      Rafael J. Wysocki 提交于
      The current generic PM domains code attempts to use the generic
      system suspend operations along with the domains' device stop/start
      routines, which requires device drivers to assume that their
      system suspend/resume (and hibernation/restore) callbacks will always
      be used with generic PM domains.  However, in theory, the same
      hardware may be used in devices that don't belong to any PM domain,
      in which case it would be necessary to add "fake" PM domains to
      satisfy the above assumption.  Also, the domain the hardware belongs
      to may not be handled with the help of the generic code.
      
      To allow device drivers that may be used along with the generic PM
      domains code of more flexibility, add new device callbacks,
      .suspend(), .suspend_late(), .resume_early(), .resume(), .freeze(),
      .freeze_late(), .thaw_early(), and .thaw(), that can be supplied by
      the drivers in addition to their "standard" system suspend and
      hibernation callbacks.  These new callbacks, if defined, will be used
      by the generic PM domains code for the handling of system suspend and
      hibernation instead of the "standard" ones.  This will allow drivers
      to be designed to work with generic PM domains as well as without
      them.
      
      For backwards compatibility, introduce default implementations of the
      new callbacks for PM domains that will execute pm_generic_suspend(),
      pm_generic_suspend_noirq(), pm_generic_resume_noirq(),
      pm_generic_resume(), pm_generic_freeze(), pm_generic_freeze_noirq(),
      pm_generic_thaw_noirq(), and pm_generic_thaw(), respectively, for the
      given device if its driver doesn't define those callbacks.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      d23b9b00
    • R
      PM / Domains: Introduce "save/restore state" device callbacks · ecf00475
      Rafael J. Wysocki 提交于
      The current PM domains code uses device drivers' .runtime_suspend()
      and .runtime_resume() callbacks as the "save device state" and
      "restore device state" operations, which may not be appropriate in
      general, because it forces drivers to assume that they always will
      be used with generic PM domains.  However, in theory, the same
      hardware may be used in devices that don't belong to any PM
      domain, in which case it would be necessary to add "fake" PM
      domains to satisfy the above assumption.  It also may be located in
      a PM domain that's not handled with the help of the generic code.
      
      To allow device drivers that may be used along with the generic PM
      domains code of more flexibility, introduce new device callbacks,
      .save_state() and .restore_state(), that can be supplied by the
      drivers in addition to their "standard" runtime PM callbacks.  This
      will allow the drivers to be designed to work with generic PM domains
      as well as without them.
      
      For backwards compatibility, introduce default .save_state() and
      .restore_state() callback routines for PM domains that will execute
      a device driver's .runtime_suspend() and .runtime_resume() callbacks,
      respectively, for the given device if the driver doesn't provide its
      own implementations of .save_state() and .restore_state().
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      ecf00475
    • R
      PM / Domains: Make it possible to use per-device domain callbacks · d5e4cbfe
      Rafael J. Wysocki 提交于
      The current generic PM domains code requires that the same .stop(),
      .start() and .active_wakeup() device callback routines be used for
      all devices in the given domain, which is inflexible and may not
      cover some specific use cases.  For this reason, make it possible to
      use device specific .start()/.stop() and .active_wakeup() callback
      routines by adding corresponding callback pointers to struct
      generic_pm_domain_data.  Add a new helper routine,
      pm_genpd_register_callbacks(), that can be used to populate
      the new per-device callback pointers.
      
      Modify the shmobile's power domains code to allow drivers to add
      their own code to be run during the device stop and start operations
      with the help of the new callback pointers.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      Acked-by: NMagnus Damm <damm@opensource.se>
      d5e4cbfe
  11. 22 10月, 2011 1 次提交
    • R
      PM / Sleep: Mark devices involved in wakeup signaling during suspend · 4ca46ff3
      Rafael J. Wysocki 提交于
      The generic PM domains code in drivers/base/power/domain.c has
      to avoid powering off domains that provide power to wakeup devices
      during system suspend.  Currently, however, this only works for
      wakeup devices directly belonging to the given domain and not for
      their children (or the children of their children and so on).
      Thus, if there's a wakeup device whose parent belongs to a power
      domain handled by the generic PM domains code, the domain will be
      powered off during system suspend preventing the device from
      signaling wakeup.
      
      To address this problem introduce a device flag, power.wakeup_path,
      that will be set during system suspend for all wakeup devices,
      their parents, the parents of their parents and so on.  This way,
      all wakeup paths in the device hierarchy will be marked and the
      generic PM domains code will only need to avoid powering off
      domains containing devices whose power.wakeup_path is set.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      4ca46ff3
  12. 27 9月, 2011 1 次提交
    • R
      PM / Domains: Split device PM domain data into base and need_restore · cd0ea672
      Rafael J. Wysocki 提交于
      The struct pm_domain_data data type is defined in such a way that
      adding new fields specific to the generic PM domains code will
      require include/linux/pm.h to be modified.  As a result, data types
      used only by the generic PM domains code will be defined in two
      headers, although they all should be defined in pm_domain.h and
      pm.h will need to include more headers, which won't be very nice.
      
      For this reason change the definition of struct pm_subsys_data
      so that its domain_data member is a pointer, which will allow
      struct pm_domain_data to be subclassed by various PM domains
      implementations.  Remove the need_restore member from
      struct pm_domain_data and make the generic PM domains code
      subclass it by adding the need_restore member to the new data type.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      cd0ea672
  13. 25 8月, 2011 9 次提交
    • R
      PM / Domains: Preliminary support for devices with power.irq_safe set · 0aa2a221
      Rafael J. Wysocki 提交于
      The generic PM domains framework currently doesn't work with devices
      whose power.irq_safe flag is set, because runtime PM callbacks for
      such devices are run with interrupts disabled and the callbacks
      provided by the generic PM domains framework use domain mutexes
      and may sleep.  However, such devices very well may belong to
      power domains on some systems, so the generic PM domains framework
      should take them into account.
      
      For this reason, modify the generic PM domains framework so that the
      domain .power_off() and .power_on() callbacks are never executed for
      a domain containing devices with power.irq_safe set, although the
      .stop_device() and .start_device() callbacks are still run for them.
      
      Additionally, introduce a flag allowing the creator of a
      struct generic_pm_domain object to indicate that its .stop_device()
      and .start_device() callbacks may be run in interrupt context
      (might_sleep_if() triggers if that flag is not set and one of those
      callbacks is run in interrupt context).
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      0aa2a221
    • R
      PM / Domains: Use power.sybsys_data to reduce overhead · 4605ab65
      Rafael J. Wysocki 提交于
      Currently pm_genpd_runtime_resume() has to walk the list of devices
      from the device's PM domain to find the corresponding device list
      object containing the need_restore field to check if the driver's
      .runtime_resume() callback should be executed for the device.
      This is suboptimal and can be simplified by using power.sybsys_data
      to store device information used by the generic PM domains code.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      4605ab65
    • R
      PM / Domains: Rename argument of pm_genpd_add_subdomain() · bc0403ff
      Rafael J. Wysocki 提交于
      Change the name of the second argument of pm_genpd_add_subdomain()
      so that it is (a) shorter and (b) in agreement with the name of
      the second argument of pm_genpd_add_subdomain().
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      bc0403ff
    • R
      PM / Domains: Rename GPD_STATE_WAIT_PARENT to GPD_STATE_WAIT_MASTER · 17877eb5
      Rafael J. Wysocki 提交于
      Since it is now possible for a PM domain to have multiple masters
      instead of one parent, rename the "wait for parent" status to reflect
      the new situation.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      17877eb5
    • R
      PM / Domains: Allow generic PM domains to have multiple masters · 5063ce15
      Rafael J. Wysocki 提交于
      Currently, for a given generic PM domain there may be only one parent
      domain (i.e. a PM domain it depends on).  However, there is at least
      one real-life case in which there should be two parents (masters) for
      one PM domain (the A3RV domain on SH7372 turns out to depend on the
      A4LC domain and it depends on the A4R domain and the same time). For
      this reason, allow a PM domain to have multiple parents (masters) by
      introducing objects representing links between PM domains.
      
      The (logical) links between PM domains represent relationships in
      which one domain is a master (i.e. it is depended on) and another
      domain is a slave (i.e. it depends on the master) with the rule that
      the slave cannot be powered on if the master is not powered on and
      the master cannot be powered off if the slave is not powered off.
      Each struct generic_pm_domain object representing a PM domain has
      two lists of links, a list of links in which it is a master and
      a list of links in which it is a slave.  The first of these lists
      replaces the list of subdomains and the second one is used in place
      of the parent pointer.
      
      Each link is represented by struct gpd_link object containing
      pointers to the master and the slave and two struct list_head
      members allowing it to hook into two lists (the master's list
      of "master" links and the slave's list of "slave" links).  This
      allows the code to get to the link from each side (either from
      the master or from the slave) and follow it in each direction.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      5063ce15
    • R
      PM / Domains: Add "wait for parent" status for generic PM domains · 3f241775
      Rafael J. Wysocki 提交于
      The next patch will make it possible for a generic PM domain to have
      multiple parents (i.e. multiple PM domains it depends on).  To
      prepare for that change it is necessary to change pm_genpd_poweron()
      so that it doesn't jump to the start label after running itself
      recursively for the parent domain.  For this purpose, introduce a new
      PM domain status value GPD_STATE_WAIT_PARENT that will be set by
      pm_genpd_poweron() before calling itself recursively for the parent
      domain and modify the code in drivers/base/power/domain.c so that
      the GPD_STATE_WAIT_PARENT status is guaranteed to be preserved during
      the execution of pm_genpd_poweron() for the parent.
      
      This change also causes pm_genpd_add_subdomain() and
      pm_genpd_remove_subdomain() to wait for started pm_genpd_poweron() to
      complete and allows pm_genpd_runtime_resume() to avoid dropping the
      lock after powering on the PM domain.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      3f241775
    • R
      PM / Domains: Make pm_genpd_poweron() always survive parent removal · 9e08cf42
      Rafael J. Wysocki 提交于
      If pm_genpd_remove_subdomain() is called to remove a PM domain's
      subdomain and pm_genpd_poweron() is called for that subdomain at
      the same time, and the pm_genpd_poweron() called by it recursively
      for the parent returns an error, the first pm_genpd_poweron()'s
      error code path will attempt to decrement the subdomain counter of
      a PM domain that it's not a subdomain of any more.
      
      Rearrange the code in pm_genpd_poweron() to prevent this from
      happening.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      9e08cf42
    • R
      PM / Domains: Do not take parent locks to modify subdomain counters · 3c07cbc4
      Rafael J. Wysocki 提交于
      After the subdomain counter in struct generic_pm_domain has been
      changed into an atomic_t field, it is possible to modify
      pm_genpd_poweron() and pm_genpd_poweroff() so that they don't take
      the parents locks.  This requires pm_genpd_poweron() to increment
      the parent's subdomain counter before calling itself recursively
      for the parent and to decrement it if an error is to be returned.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      3c07cbc4
    • 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
  14. 14 8月, 2011 1 次提交
  15. 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
  16. 15 7月, 2011 2 次提交
  17. 13 7月, 2011 1 次提交
  18. 12 7月, 2011 5 次提交
    • 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