1. 21 11月, 2019 4 次提交
    • B
      PCI/PM: Make power management op coding style consistent · 6da2f2cc
      Bjorn Helgaas 提交于
      Some of the power management ops use this style:
      
        struct device_driver *drv = dev->driver;
        if (drv && drv->pm && drv->pm->prepare(dev))
          drv->pm->prepare(dev);
      
      while others use this:
      
        const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
        if (pm && pm->runtime_resume)
          pm->runtime_resume(dev);
      
      Convert the first style to the second so they're all consistent.  Remove
      local "error" variables when unnecessary.  No functional change intended.
      
      Link: https://lore.kernel.org/r/20191014230016.240912-6-helgaas@kernel.orgSigned-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      6da2f2cc
    • B
      PCI/PM: Run resume fixups before disabling wakeup events · f7b32a86
      Bjorn Helgaas 提交于
      pci_pm_resume() and pci_pm_restore() call pci_pm_default_resume(), which
      runs resume fixups before disabling wakeup events:
      
        static void pci_pm_default_resume(struct pci_dev *pci_dev)
        {
          pci_fixup_device(pci_fixup_resume, pci_dev);
          pci_enable_wake(pci_dev, PCI_D0, false);
        }
      
      pci_pm_runtime_resume() does both of these, but in the opposite order:
      
        pci_enable_wake(pci_dev, PCI_D0, false);
        pci_fixup_device(pci_fixup_resume, pci_dev);
      
      We should always use the same ordering unless there's a reason to do
      otherwise.  Change pci_pm_runtime_resume() to call pci_pm_default_resume()
      instead of open-coding this, so the fixups are always done before disabling
      wakeup events.
      
      pci_pm_default_resume() is called from pci_pm_runtime_resume(), which is
      under #ifdef CONFIG_PM.  If SUSPEND and HIBERNATION are disabled, PM_SLEEP
      is disabled also, so move pci_pm_default_resume() from #ifdef
      CONFIG_PM_SLEEP to #ifdef CONFIG_PM.
      
      Link: https://lore.kernel.org/r/20191014230016.240912-5-helgaas@kernel.orgSigned-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      f7b32a86
    • B
      PCI/PM: Clear PCIe PME Status even for legacy power management · ec6a75ef
      Bjorn Helgaas 提交于
      Previously, pci_pm_resume_noirq() cleared the PME Status bit in the Root
      Status register only if the device had no driver or the driver did not
      implement legacy power management.  It should clear PME Status regardless
      of what sort of power management the driver supports, so do this before
      checking for legacy power management.
      
      This affects Root Ports and Root Complex Event Collectors, for which the
      usual driver is the PCIe portdrv, which implements new power management, so
      this change is just on principle, not to fix any actual defects.
      
      Fixes: a39bd851 ("PCI/PM: Clear PCIe PME Status bit in core, not PCIe port driver")
      Link: https://lore.kernel.org/r/20191014230016.240912-4-helgaas@kernel.orgSigned-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      ec6a75ef
    • D
      PCI/PM: Always return devices to D0 when thawing · f2c33cca
      Dexuan Cui 提交于
      pci_pm_thaw_noirq() is supposed to return the device to D0 and restore its
      configuration registers, but previously it only did that for devices whose
      drivers implemented the new power management ops.
      
      Hibernation, e.g., via "echo disk > /sys/power/state", involves freezing
      devices, creating a hibernation image, thawing devices, writing the image,
      and powering off.  The fact that thawing did not return devices with legacy
      power management to D0 caused errors, e.g., in this path:
      
        pci_pm_thaw_noirq
          if (pci_has_legacy_pm_support(pci_dev)) # true for Mellanox VF driver
            return pci_legacy_resume_early(dev)   # ... legacy PM skips the rest
          pci_set_power_state(pci_dev, PCI_D0)
          pci_restore_state(pci_dev)
        pci_pm_thaw
          if (pci_has_legacy_pm_support(pci_dev))
            pci_legacy_resume
      	drv->resume
      	  mlx4_resume
      	    ...
      	      pci_enable_msix_range
      	        ...
      		  if (dev->current_state != PCI_D0)  # <---
      		    return -EINVAL;
      
      which caused these warnings:
      
        mlx4_core a6d1:00:02.0: INTx is not supported in multi-function mode, aborting
        PM: dpm_run_callback(): pci_pm_thaw+0x0/0xd7 returns -95
        PM: Device a6d1:00:02.0 failed to thaw: error -95
      
      Return devices to D0 and restore config registers for all devices, not just
      those whose drivers support new power management.
      
      [bhelgaas: also call pci_restore_state() before pci_legacy_resume_early(),
      update comment, add stable tag, commit log]
      Link: https://lore.kernel.org/r/KU1P153MB016637CAEAD346F0AA8E3801BFAD0@KU1P153MB0166.APCP153.PROD.OUTLOOK.COMSigned-off-by: NDexuan Cui <decui@microsoft.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Cc: stable@vger.kernel.org	# v4.13+
      f2c33cca
  2. 03 7月, 2019 2 次提交
  3. 27 6月, 2019 2 次提交
    • R
      PCI: PM/ACPI: Refresh all stale power state data in pci_pm_complete() · b51033e0
      Rafael J. Wysocki 提交于
      In pci_pm_complete() there are checks to decide whether or not to
      resume devices that were left in runtime-suspend during the preceding
      system-wide transition into a sleep state.  They involve checking the
      current power state of the device and comparing it with the power
      state of it set before the preceding system-wide transition, but the
      platform component of the device's power state is not handled
      correctly in there.
      
      Namely, on platforms with ACPI, the device power state information
      needs to be updated with care, so that the reference counters of
      power resources used by the device (if any) are set to ensure that
      the refreshed power state of it will be maintained going forward.
      
      To that end, introduce a new ->refresh_state() platform PM callback
      for PCI devices, for asking the platform to refresh the device power
      state data and ensure that the corresponding power state will be
      maintained going forward, make it invoke acpi_device_update_power()
      (for devices with ACPI PM) on platforms with ACPI and make
      pci_pm_complete() use it, through a new pci_refresh_power_state()
      wrapper function.
      
      Fixes: a0d2a959 (PCI: Avoid unnecessary resume after direct-complete)
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-by: NMika Westerberg <mika.westerberg@linux.intel.com>
      b51033e0
    • R
      PCI: PM: Avoid skipping bus-level PM on platforms without ACPI · 471a739a
      Rafael J. Wysocki 提交于
      There are platforms that do not call pm_set_suspend_via_firmware(),
      so pm_suspend_via_firmware() returns 'false' on them, but the power
      states of PCI devices (PCIe ports in particular) are changed as a
      result of powering down core platform components during system-wide
      suspend.  Thus the pm_suspend_via_firmware() checks in
      pci_pm_suspend_noirq() and pci_pm_resume_noirq() introduced by
      commit 3e26c5fe ("PCI: PM: Skip devices in D0 for suspend-to-
      idle") are not sufficient to determine that devices left in D0
      during suspend will remain in D0 during resume and so the bus-level
      power management can be skipped for them.
      
      For this reason, introduce a new global suspend flag,
      PM_SUSPEND_FLAG_NO_PLATFORM, set it for suspend-to-idle only
      and replace the pm_suspend_via_firmware() checks mentioned above
      with checks against this flag.
      
      Fixes: 3e26c5fe ("PCI: PM: Skip devices in D0 for suspend-to-idle")
      Reported-by: NJon Hunter <jonathanh@nvidia.com>
      Tested-by: NJon Hunter <jonathanh@nvidia.com>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Tested-by: NMika Westerberg <mika.westerberg@linux.intel.com>
      Reviewed-by: NMika Westerberg <mika.westerberg@linux.intel.com>
      471a739a
  4. 17 6月, 2019 1 次提交
    • R
      PCI: PM: Replace pci_dev_keep_suspended() with two functions · 0c7376ad
      Rafael J. Wysocki 提交于
      The code in pci_dev_keep_suspended() is relatively hard to follow due
      to the negative checks in it and in its callers and the function has
      a possible side-effect (disabling the PME) which doesn't really match
      its role.
      
      For this reason, move the PME disabling from pci_dev_keep_suspended()
      to a separate function and change the semantics (and name) of the
      rest of it, so that 'true' is returned when the device needs to be
      resumed (and not the other way around).  Change the callers of
      pci_dev_keep_suspended() accordingly.
      
      While at it, make the code flow in pci_pm_poweroff() reflect the
      pci_pm_suspend() more closely to avoid arbitrary differences between
      them.
      
      This is a cosmetic change with no intention to alter behavior.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-by: NMika Westerberg <mika.westerberg@linux.intel.com>
      0c7376ad
  5. 14 6月, 2019 2 次提交
  6. 30 5月, 2019 1 次提交
    • A
      PCI: Return error if cannot probe VF · 76002d8b
      Alex Williamson 提交于
      Commit 0e7df224 ("PCI: Add sysfs sriov_drivers_autoprobe to control
      VF driver binding") allows the user to specify that drivers for VFs of
      a PF should not be probed, but it actually causes pci_device_probe() to
      return success back to the driver core in this case.  Therefore by all
      sysfs appearances the device is bound to a driver, the driver link from
      the device exists as does the device link back from the driver, yet the
      driver's probe function is never called on the device.  We also fail to
      do any sort of cleanup when we're prohibited from probing the device,
      the IRQ setup remains in place and we even hold a device reference.
      
      Instead, abort with errno before any setup or references are taken when
      pci_device_can_probe() prevents us from trying to probe the device.
      
      Link: https://lore.kernel.org/lkml/155672991496.20698.4279330795743262888.stgit@gimli.home
      Fixes: 0e7df224 ("PCI: Add sysfs sriov_drivers_autoprobe to control VF driver binding")
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      76002d8b
  7. 27 5月, 2019 1 次提交
    • R
      PCI: PM: Avoid possible suspend-to-idle issue · d491f2b7
      Rafael J. Wysocki 提交于
      If a PCI driver leaves the device handled by it in D0 and calls
      pci_save_state() on the device in its ->suspend() or ->suspend_late()
      callback, it can expect the device to stay in D0 over the whole
      s2idle cycle.  However, that may not be the case if there is a
      spurious wakeup while the system is suspended, because in that case
      pci_pm_suspend_noirq() will run again after pci_pm_resume_noirq()
      which calls pci_restore_state(), via pci_pm_default_resume_early(),
      so state_saved is cleared and the second iteration of
      pci_pm_suspend_noirq() will invoke pci_prepare_to_sleep() which
      may change the power state of the device.
      
      To avoid that, add a new internal flag, skip_bus_pm, that will be set
      by pci_pm_suspend_noirq() when it runs for the first time during the
      given system suspend-resume cycle if the state of the device has
      been saved already and the device is still in D0.  Setting that flag
      will cause the next iterations of pci_pm_suspend_noirq() to set
      state_saved for pci_pm_resume_noirq(), so that it always restores the
      device state from the originally saved data, and avoid calling
      pci_prepare_to_sleep() for the device.
      
      Fixes: 33e4f80e ("ACPI / PM: Ignore spurious SCI wakeups from suspend-to-idle")
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-by: NKeith Busch <keith.busch@intel.com>
      Reviewed-by: NMika Westerberg <mika.westerberg@linux.intel.com>
      d491f2b7
  8. 09 4月, 2019 1 次提交
    • S
      treewide: Switch printk users from %pf and %pF to %ps and %pS, respectively · d75f773c
      Sakari Ailus 提交于
      %pF and %pf are functionally equivalent to %pS and %ps conversion
      specifiers. The former are deprecated, therefore switch the current users
      to use the preferred variant.
      
      The changes have been produced by the following command:
      
      	git grep -l '%p[fF]' | grep -v '^\(tools\|Documentation\)/' | \
      	while read i; do perl -i -pe 's/%pf/%ps/g; s/%pF/%pS/g;' $i; done
      
      And verifying the result.
      
      Link: http://lkml.kernel.org/r/20190325193229.23390-1-sakari.ailus@linux.intel.com
      Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: sparclinux@vger.kernel.org
      Cc: linux-um@lists.infradead.org
      Cc: xen-devel@lists.xenproject.org
      Cc: linux-acpi@vger.kernel.org
      Cc: linux-pm@vger.kernel.org
      Cc: drbd-dev@lists.linbit.com
      Cc: linux-block@vger.kernel.org
      Cc: linux-mmc@vger.kernel.org
      Cc: linux-nvdimm@lists.01.org
      Cc: linux-pci@vger.kernel.org
      Cc: linux-scsi@vger.kernel.org
      Cc: linux-btrfs@vger.kernel.org
      Cc: linux-f2fs-devel@lists.sourceforge.net
      Cc: linux-mm@kvack.org
      Cc: ceph-devel@vger.kernel.org
      Cc: netdev@vger.kernel.org
      Signed-off-by: NSakari Ailus <sakari.ailus@linux.intel.com>
      Acked-by: David Sterba <dsterba@suse.com> (for btrfs)
      Acked-by: Mike Rapoport <rppt@linux.ibm.com> (for mm/memblock.c)
      Acked-by: Bjorn Helgaas <bhelgaas@google.com> (for drivers/pci)
      Acked-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Signed-off-by: NPetr Mladek <pmladek@suse.com>
      d75f773c
  9. 09 2月, 2019 1 次提交
  10. 15 12月, 2018 1 次提交
  11. 14 12月, 2018 1 次提交
  12. 13 12月, 2018 1 次提交
    • J
      PCI / PM: Allow runtime PM without callback functions · c5eb1190
      Jarkko Nikula 提交于
      a9c8088c ("i2c: i801: Don't restore config registers on runtime PM")
      nullified the runtime PM suspend/resume callback pointers while keeping the
      runtime PM enabled.
      
      This caused the SMBus PCI device to stay in D0 with
      /sys/devices/.../power/runtime_status showing "error" when the runtime PM
      framework attempted to autosuspend the device.  This is due to PCI bus
      runtime PM, which checks for driver runtime PM callbacks and returns
      -ENOSYS if they are not set.
      
      Since i2c-i801.c doesn't need to do anything device-specific for runtime
      PM, Jean Delvare proposed this be fixed in the PCI core rather than adding
      dummy runtime PM callback functions in the PCI drivers.
      
      Change pci_pm_runtime_suspend()/pci_pm_runtime_resume() so they allow
      changing the PCI device power state during runtime PM transitions even if
      the driver supplies no runtime PM callbacks.
      
      This fixes the runtime PM regression on i2c-i801.c.
      
      It is not obvious why the code previously required the runtime PM
      callbacks.  The test has been there since the code was introduced by
      6cbf8214 ("PCI PM: Run-time callbacks for PCI bus type").
      
      On the other hand, a similar change was done to generic runtime PM
      callbacks in 05aa55dd ("PM / Runtime: Lenient generic runtime pm
      callbacks").
      
      Fixes: a9c8088c ("i2c: i801: Don't restore config registers on runtime PM")
      Reported-by: NMika Westerberg <mika.westerberg@linux.intel.com>
      Signed-off-by: NJarkko Nikula <jarkko.nikula@linux.intel.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: NJean Delvare <jdelvare@suse.de>
      Reviewed-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Cc: stable@vger.kernel.org	# v4.18+
      c5eb1190
  13. 31 7月, 2018 1 次提交
  14. 30 6月, 2018 1 次提交
    • J
      PCI/IOV: Reset total_VFs limit after detaching PF driver · 38972375
      Jakub Kicinski 提交于
      The TotalVFs register in the SR-IOV capability is the hardware limit on the
      number of VFs.  A PF driver can limit the number of VFs further with
      pci_sriov_set_totalvfs().  When the PF driver is removed, reset any VF
      limit that was imposed by the driver because that limit may not apply to
      other drivers.
      
      Before 8d85a7a4 ("PCI/IOV: Allow PF drivers to limit total_VFs to 0"),
      pci_sriov_set_totalvfs(pdev, 0) meant "we can enable TotalVFs virtual
      functions", and the nfp driver used that to remove the VF limit when the
      driver unloads.
      
      8d85a7a4 broke that because instead of removing the VF limit,
      pci_sriov_set_totalvfs(pdev, 0) actually sets the limit to zero, and that
      limit persists even if another driver is loaded.
      
      We could fix that by making the nfp driver reset the limit when it unloads,
      but it seems more robust to do it in the PCI core instead of relying on the
      driver.
      
      The regression scenario is:
      
        nfp_pci_probe (driver 1)
        ...
        nfp_pci_remove
          pci_sriov_set_totalvfs(pf->pdev, 0)   # limits VFs to 0
      
        ...
        nfp_pci_probe (driver 2)
          nfp_rtsym_read_le("nfd_vf_cfg_max_vfs")
          # no VF limit from firmware
      
      Now driver 2 is broken because the VF limit is still 0 from driver 1.
      
      Fixes: 8d85a7a4 ("PCI/IOV: Allow PF drivers to limit total_VFs to 0")
      Signed-off-by: NJakub Kicinski <jakub.kicinski@netronome.com>
      [bhelgaas: changelog, rename functions]
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      38972375
  15. 24 5月, 2018 1 次提交
    • R
      PCI / PM: Do not clear state_saved for devices that remain suspended · 656088aa
      Rafael J. Wysocki 提交于
      The state_saved flag should not be cleared in pci_pm_suspend() if the
      given device is going to remain suspended, or the device's config
      space will not be restored properly during the subsequent resume.
      
      Namely, if the device is going to stay in suspend, both the late
      and noirq callbacks return early for it, so if its state_saved flag
      is cleared in pci_pm_suspend(), it will remain unset throughout the
      remaining part of suspend and resume and pci_restore_state() called
      for the device going forward will return without doing anything.
      
      For this reason, change pci_pm_suspend() to only clear state_saved
      if the given device is not going to remain suspended.  [This is
      analogous to what commit ae860a19 (PCI / PM: Do not clear
      state_saved in pci_pm_freeze() when smart suspend is set) did for
      hibernation.]
      
      Fixes: c4b65157 (PCI / PM: Take SMART_SUSPEND driver flag into account)
      Cc: 4.15+ <stable@vger.kernel.org> # 4.15+
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-by: NMika Westerberg <mika.westerberg@linux.intel.com>
      Acked-by: NBjorn Helgaas <bhelgaas@google.com>
      656088aa
  16. 18 5月, 2018 1 次提交
  17. 03 5月, 2018 2 次提交
  18. 23 4月, 2018 1 次提交
    • M
      PCI / PM: Do not clear state_saved in pci_pm_freeze() when smart suspend is set · ae860a19
      Mika Westerberg 提交于
      If a driver uses DPM_FLAG_SMART_SUSPEND and the device is already
      runtime suspended when hibernate is started PCI core skips runtime
      resuming the device but still clears pci_dev->state_saved. After the
      hibernation image is written pci_pm_thaw_noirq() makes sure subsequent
      thaw phases for the device are also skipped leaving it runtime suspended
      with pci_dev->state_saved == false.
      
      When the device is eventually runtime resumed pci_pm_runtime_resume()
      restores config space by calling pci_restore_standard_config(), however
      because pci_dev->state_saved == false pci_restore_state() never actually
      restores the config space leaving the device in a state that is not what
      the driver might expect.
      
      For example here is what happens for intel-lpss I2C devices once the
      hibernation snapshot is taken:
      
        intel-lpss 0000:00:15.0: power state changed by ACPI to D0
        intel-lpss 0000:00:1e.0: power state changed by ACPI to D3cold
        video LNXVIDEO:00: Restoring backlight state
        PM: hibernation exit
        i2c_designware i2c_designware.1: Unknown Synopsys component type: 0xffffffff
        i2c_designware i2c_designware.0: Unknown Synopsys component type: 0xffffffff
        i2c_designware i2c_designware.1: timeout in disabling adapter
        i2c_designware i2c_designware.0: timeout in disabling adapter
      
      Since PCI config space is not restored the device is still in D3hot
      making MMIO register reads return 0xffffffff.
      
      Fix this by clearing pci_dev->state_saved only if we actually end up
      runtime resuming the device.
      
      Fixes: c4b65157 (PCI / PM: Take SMART_SUSPEND driver flag into account)
      Signed-off-by: NMika Westerberg <mika.westerberg@linux.intel.com>
      Cc: 4.15+ <stable@vger.kernel.org> # 4.15+
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      ae860a19
  19. 31 3月, 2018 2 次提交
    • B
      PCI/portdrv: Remove pcie_port_bus_type link order dependency · c6c889d9
      Bjorn Helgaas 提交于
      The pcie_port_bus_type must be registered before drivers that depend on it
      can be registered.  Those drivers include:
      
        pcied_init()                # PCIe native hotplug driver
        aer_service_init()          # AER driver
        dpc_service_init()          # DPC driver
        pcie_pme_service_init()     # PME driver
      
      Previously we registered pcie_port_bus_type from pcie_portdrv_init(), a
      device_initcall.  The callers of pcie_port_service_register() (above) are
      also device_initcalls.  This is fragile because the device_initcall
      ordering depends on link order, which is not explicit.
      
      Register pcie_port_bus_type from pci_driver_init() along with pci_bus_type.
      This removes the link order dependency between portdrv and the pciehp, AER,
      DPC, and PCIe PME drivers.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-by: NChristoph Hellwig <hch@lst.de>
      c6c889d9
    • B
      PCI/PM: Clear PCIe PME Status bit for Root Complex Event Collectors · 3620c714
      Bjorn Helgaas 提交于
      Per PCIe r4.0, sec 6.1.6, Root Complex Event Collectors can generate PME
      interrupts on behalf of Root Complex Integrated Endpoints.
      
      Linux does not currently enable PME interrupts from RC Event Collectors,
      but fe31e697 ("PCI/PCIe: Clear Root PME Status bits early during system
      resume") suggests PME interrupts may be enabled by the platform for ACPI-
      based runtime wakeup.
      
      Clear the PCIe PME Status bit for Root Complex Event Collectors during
      resume, just like we already do for Root Ports.
      
      If the BIOS enables PME interrupts for an event collector and neglects to
      clear the status bit on resume, this change should fix the same bug as
      fe31e697 (PMEs not working after waking from a sleep state), but for
      Root Complex Integrated Endpoints.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      3620c714
  20. 20 3月, 2018 1 次提交
  21. 14 3月, 2018 1 次提交
    • R
      PCI: Restore config space on runtime resume despite being unbound · 5775b843
      Rafael J. Wysocki 提交于
      We leave PCI devices not bound to a driver in D0 during runtime suspend.
      But they may have a parent which is bound and can be transitioned to
      D3cold at runtime.  Once the parent goes to D3cold, the unbound child
      may go to D3cold as well.  When the child goes to D3cold, its internal
      state, including configuration of BARs, MSI, ASPM, MPS, etc., is lost.
      
      One example are recent hybrid graphics laptops which cut power to the
      discrete GPU when the root port above it goes to ACPI power state D3.
      Users may provoke this by unbinding the GPU driver and allowing runtime
      PM on the GPU via sysfs:  The PM core will then treat the GPU as
      "suspended", which in turn allows the root port to runtime suspend,
      causing the power resources listed in its _PR3 object to be powered off.
      The GPU's BARs will be uninitialized when a driver later probes it.
      
      Another example are hybrid graphics laptops where the GPU itself (rather
      than the root port) is capable of runtime suspending to D3cold.  If the
      GPU's integrated HDA controller is not bound and the GPU's driver
      decides to runtime suspend to D3cold, the HDA controller's BARs will be
      uninitialized when a driver later probes it.
      
      Fix by saving and restoring config space over a runtime suspend cycle
      even if the device is not bound.
      Acked-by: NBjorn Helgaas <bhelgaas@google.com>
      Tested-by: Peter Wu <peter@lekensteyn.nl>              # Nvidia Optimus
      Tested-by: Lukas Wunner <lukas@wunner.de>              # MacBook Pro
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      [lukas: add commit message, bikeshed code comments for clarity]
      Signed-off-by: NLukas Wunner <lukas@wunner.de>
      Link: https://patchwork.freedesktop.org/patch/msgid/92fb6e6ae2730915eb733c08e2f76c6a313e3860.1520068884.git.lukas@wunner.de
      5775b843
  22. 12 3月, 2018 1 次提交
    • B
      PCI/PM: Clear PCIe PME Status bit in core, not PCIe port driver · a39bd851
      Bjorn Helgaas 提交于
      fe31e697 ("PCI/PCIe: Clear Root PME Status bits early during system
      resume") added a .resume_noirq() callback to the PCIe port driver to clear
      the PME Status bit during resume to work around a BIOS issue.
      
      The BIOS evidently enabled PME interrupts for ACPI-based runtime wakeups
      but did not clear the PME Status bit during resume, which meant PMEs after
      resume did not trigger interrupts because PME Status did not transition
      from cleared to set.
      
      The fix was in the PCIe port driver, so it worked when CONFIG_PCIEPORTBUS
      was set.  But I think we *always* want the fix because the platform may use
      PME interrupts even if Linux is built without the PCIe port driver.
      
      Move the fix from the port driver to the PCI core so we can work around
      this "PME doesn't work after waking from a sleep state" issue regardless of
      CONFIG_PCIEPORTBUS.
      
      [bhelgaas: folded in warning fix from Arnd Bergmann <arnd@arndb.de>:
      https://lkml.kernel.org/r/20180328134747.2062348-1-arnd@arndb.de]
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      a39bd851
  23. 23 2月, 2018 1 次提交
  24. 29 1月, 2018 1 次提交
  25. 18 1月, 2018 1 次提交
  26. 18 12月, 2017 1 次提交
  27. 11 12月, 2017 1 次提交
    • R
      PM / sleep: Avoid excess pm_runtime_enable() calls in device_resume() · 3487972d
      Rafael J. Wysocki 提交于
      Middle-layer code doing suspend-time optimizations for devices with
      the DPM_FLAG_SMART_SUSPEND flag set (currently, the PCI bus type and
      the ACPI PM domain) needs to make the core skip ->thaw_early and
      ->thaw callbacks for those devices in some cases and it sets the
      power.direct_complete flag for them for this purpose.
      
      However, it turns out that setting power.direct_complete outside of
      the PM core is a bad idea as it triggers an excess invocation of
      pm_runtime_enable() in device_resume().
      
      For this reason, provide a helper to clear power.is_late_suspended
      and power.is_suspended to be invoked by the middle-layer code in
      question instead of setting power.direct_complete and make that code
      call the new helper.
      
      Fixes: c4b65157 (PCI / PM: Take SMART_SUSPEND driver flag into account)
      Fixes: 05087360 (ACPI / PM: Take SMART_SUSPEND driver flag into account)
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Reviewed-by: NUlf Hansson <ulf.hansson@linaro.org>
      Acked-by: NBjorn Helgaas <bhelgaas@google.com>
      3487972d
  28. 27 11月, 2017 1 次提交
  29. 06 11月, 2017 3 次提交
    • R
      PCI / PM: Take SMART_SUSPEND driver flag into account · c4b65157
      Rafael J. Wysocki 提交于
      Make the PCI bus type take DPM_FLAG_SMART_SUSPEND into account in its
      system-wide PM callbacks and make sure that all code that should not
      run in parallel with pci_pm_runtime_resume() is executed in the "late"
      phases of system suspend, freeze and poweroff transitions.
      
      [Note that the pm_runtime_suspended() check in pci_dev_keep_suspended()
      is an optimization, because if is not passed, all of the subsequent
      checks may be skipped and some of them are much more overhead in
      general.]
      
      Also use the observation that if the device is in runtime suspend
      at the beginning of the "late" phase of a system-wide suspend-like
      transition, its state cannot change going forward (runtime PM is
      disabled for it at that time) until the transition is over and the
      subsequent system-wide PM callbacks should be skipped for it (as
      they generally assume the device to not be suspended), so add checks
      for that in pci_pm_suspend_late/noirq(), pci_pm_freeze_late/noirq()
      and pci_pm_poweroff_late/noirq().
      
      Moreover, if pci_pm_resume_noirq() or pci_pm_restore_noirq() is
      called during the subsequent system-wide resume transition and if
      the device was left in runtime suspend previously, its runtime PM
      status needs to be changed to "active" as it is going to be put
      into the full-power state, so add checks for that too to these
      functions.
      
      In turn, if pci_pm_thaw_noirq() runs after the device has been
      left in runtime suspend, the subsequent "thaw" callbacks need
      to be skipped for it (as they may not work correctly with a
      suspended device), so set the power.direct_complete flag for the
      device then to make the PM core skip those callbacks.
      
      In addition to the above add a core helper for checking if
      DPM_FLAG_SMART_SUSPEND is set and the device runtime PM status is
      "suspended" at the same time, which is done quite often in the new
      code (and will be done elsewhere going forward too).
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Acked-by: NBjorn Helgaas <bhelgaas@google.com>
      c4b65157
    • R
      PCI / PM: Drop unnecessary invocations of pcibios_pm_ops callbacks · 302666d8
      Rafael J. Wysocki 提交于
      The only user of non-empty pcibios_pm_ops is s390 and it only uses
      "noirq" callbacks, so drop the invocations of the other pcibios_pm_ops
      callbacks from the PCI PM code.
      
      That will allow subsequent changes to be somewhat simpler.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Acked-by: NBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: NUlf Hansson <ulf.hansson@linaro.org>
      302666d8
    • R
      PM / core: Add NEVER_SKIP and SMART_PREPARE driver flags · 08810a41
      Rafael J. Wysocki 提交于
      The motivation for this change is to provide a way to work around
      a problem with the direct-complete mechanism used for avoiding
      system suspend/resume handling for devices in runtime suspend.
      
      The problem is that some middle layer code (the PCI bus type and
      the ACPI PM domain in particular) returns positive values from its
      system suspend ->prepare callbacks regardless of whether the driver's
      ->prepare returns a positive value or 0, which effectively prevents
      drivers from being able to control the direct-complete feature.
      Some drivers need that control, however, and the PCI bus type has
      grown its own flag to deal with this issue, but since it is not
      limited to PCI, it is better to address it by adding driver flags at
      the core level.
      
      To that end, add a driver_flags field to struct dev_pm_info for flags
      that can be set by device drivers at the probe time to inform the PM
      core and/or bus types, PM domains and so on on the capabilities and/or
      preferences of device drivers.  Also add two static inline helpers
      for setting that field and testing it against a given set of flags
      and make the driver core clear it automatically on driver remove
      and probe failures.
      
      Define and document two PM driver flags related to the direct-
      complete feature: NEVER_SKIP and SMART_PREPARE that can be used,
      respectively, to indicate to the PM core that the direct-complete
      mechanism should never be used for the device and to inform the
      middle layer code (bus types, PM domains etc) that it can only
      request the PM core to use the direct-complete mechanism for
      the device (by returning a positive value from its ->prepare
      callback) if it also has been requested by the driver.
      
      While at it, make the core check pm_runtime_suspended() when
      setting power.direct_complete so that it doesn't need to be
      checked by ->prepare callbacks.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Acked-by: NBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: NUlf Hansson <ulf.hansson@linaro.org>
      08810a41
  30. 19 10月, 2017 1 次提交
    • R
      drivers: flag buses which demand DMA configuration · d89e2378
      Robin Murphy 提交于
      We do not want the common dma_configure() pathway to apply
      indiscriminately to all devices, since there are plenty of buses which
      do not have DMA capability, and if their child devices were used for
      DMA API calls it would only be indicative of a driver bug. However,
      there are a number of buses for which DMA is implicitly expected even
      when not described by firmware - those we whitelist with an automatic
      opt-in to dma_configure(), assuming that the DMA address space and the
      physical address space are equivalent if not otherwise specified.
      
      Commit 72328883 ("of: restrict DMA configuration") introduced a
      short-term fix by comparing explicit bus types, but this approach is far
      from pretty, doesn't scale well, and fails to cope at all with bus
      drivers which may be built as modules, like host1x. Let's refine things
      by making that opt-in a property of the bus type, which neatly addresses
      those problems and lets the decision of whether firmware description of
      DMA capability should be optional or mandatory stay internal to the bus
      drivers themselves.
      Signed-off-by: NRobin Murphy <robin.murphy@arm.com>
      Acked-by: NRob Herring <robh@kernel.org>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Acked-by: NThierry Reding <treding@nvidia.com>
      Signed-off-by: NChristoph Hellwig <hch@lst.de>
      d89e2378