1. 14 8月, 2015 2 次提交
    • B
      PCI: Embed ATS info directly into struct pci_dev · d544d75a
      Bjorn Helgaas 提交于
      The pci_ats struct is small and will get smaller, so I don't think it's
      worth allocating it separately from the pci_dev struct.
      
      Embed the ATS fields directly into struct pci_dev.
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: NJoerg Roedel <jroedel@suse.de>
      d544d75a
    • B
      PCI: Allocate ATS struct during enumeration · edc90fee
      Bjorn Helgaas 提交于
      Previously, we allocated pci_ats structures when an IOMMU driver called
      pci_enable_ats().  An SR-IOV VF shares the STU setting with its PF, so when
      enabling ATS on the VF, we allocated a pci_ats struct for the PF if it
      didn't already have one.  We held the sriov->lock to serialize threads
      concurrently enabling ATS on several VFS so only one would allocate the PF
      pci_ats.
      
      Gregor reported a deadlock here:
      
        pci_enable_sriov
          sriov_enable
            virtfn_add
              mutex_lock(dev->sriov->lock)      # acquire sriov->lock
              pci_device_add
                device_add
                  BUS_NOTIFY_ADD_DEVICE notifier chain
                  iommu_bus_notifier
                    amd_iommu_add_device        # iommu_ops.add_device
                      init_iommu_group
                        iommu_group_get_for_dev
                          iommu_group_add_device
                            __iommu_attach_device
                              amd_iommu_attach_device  # iommu_ops.attach_device
                                attach_device
                                  pci_enable_ats
                                    mutex_lock(dev->sriov->lock) # deadlock
      
      There's no reason to delay allocating the pci_ats struct, and if we
      allocate it for each device at enumeration-time, there's no need for
      locking in pci_enable_ats().
      
      Allocate pci_ats struct during enumeration, when we initialize other
      capabilities.
      
      Note that this implementation requires ATS to be enabled on the PF first,
      before on any of the VFs because the PF controls the STU for all the VFs.
      
      Link: http://permalink.gmane.org/gmane.linux.kernel.iommu/9433Reported-by: NGregor Dick <gdick@solarflare.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: NJoerg Roedel <jroedel@suse.de>
      edc90fee
  2. 13 6月, 2015 1 次提交
  3. 08 6月, 2015 1 次提交
  4. 30 5月, 2015 2 次提交
  5. 23 5月, 2015 1 次提交
  6. 22 5月, 2015 1 次提交
    • Y
      PCI: Add dev->has_secondary_link to track downstream PCIe links · d0751b98
      Yijing Wang 提交于
      A PCIe Port is an interface to a Link.  A Root Port is a PCI-PCI bridge in
      a Root Complex and has a Link on its secondary (downstream) side.  For
      other Ports, the Link may be on either the upstream (closer to the Root
      Complex) or downstream side of the Port.
      
      The usual topology has a Root Port connected to an Upstream Port.  We
      previously assumed this was the only possible topology, and that a
      Downstream Port's Link was always on its downstream side, like this:
      
                        +---------------------+
        +------+        |          Downstream |
        | Root |        | Upstream       Port +--Link--
        | Port +--Link--+ Port                |
        +------+        |          Downstream |
                        |                Port +--Link--
                        +---------------------+
      
      But systems do exist (see URL below) where the Root Port is connected to a
      Downstream Port.  In this case, a Downstream Port's Link may be on either
      the upstream or downstream side:
      
                        +---------------------+
        +------+        |            Upstream |
        | Root |        | Downstream     Port +--Link--
        | Port +--Link--+ Port                |
        +------+        |          Downstream |
                        |                Port +--Link--
                        +---------------------+
      
      We can't use the Port type to determine which side the Link is on, so add a
      bit in struct pci_dev to keep track.
      
      A Root Port's Link is always on the Port's secondary side.  A component
      (Endpoint or Port) on the other end of the Link obviously has the Link on
      its upstream side.  If that component is a Port, it is part of a Switch or
      a Bridge.  A Bridge has a PCI or PCI-X bus on its secondary side, not a
      Link.  The internal bus of a Switch connects the Port to another Port whose
      Link is on the downstream side.
      
      [bhelgaas: changelog, comment, cache "type", use if/else]
      Link: http://lkml.kernel.org/r/54EB81B2.4050904@pobox.com
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=94361Suggested-by: NBjorn Helgaas <bhelgaas@google.com>
      Signed-off-by: NYijing Wang <wangyijing@huawei.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      d0751b98
  7. 07 5月, 2015 1 次提交
  8. 09 4月, 2015 1 次提交
  9. 31 3月, 2015 3 次提交
  10. 04 3月, 2015 1 次提交
  11. 05 2月, 2015 1 次提交
  12. 03 2月, 2015 1 次提交
  13. 23 1月, 2015 1 次提交
    • R
      PCI: Add generic config accessors · 1f94a94f
      Rob Herring 提交于
      Many PCI controllers' configuration space accesses are memory-mapped and
      vary only in address calculation and access checks.  There are 2 main
      access methods: a decoded address space such as ECAM or a single address
      and data register similar to x86.  This implementation can support both
      cases as well as be used in cases that need additional pre- or post-access
      handling.
      
      Add a new pci_ops member, map_bus, which can do access checks and any
      necessary setup.  It returns the address to use for the configuration space
      access.  The access types supported are 32-bit only accesses or correct
      byte, word, or dword sized accesses.
      Tested-by: NThierry Reding <treding@nvidia.com>
      Signed-off-by: NRob Herring <robh@kernel.org>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: NThierry Reding <treding@nvidia.com>
      1f94a94f
  14. 17 1月, 2015 3 次提交
    • A
      PCI: Add flag for devices that don't reset on D3hot->D0 transition · 51e53738
      Alex Williamson 提交于
      Per the PCI Power Management spec r1.2, sec 3.2.4, a device that advertises
      No_Soft_Reset == 0 in the PMCSR register (reported by lspci as "NoSoftRst-")
      should perform an internal reset when transitioning from D3hot to D0 via
      software control.  Configuration context is lost and the device requires a
      full reinitialization sequence.
      
      Unfortunately the definition of "internal reset", beyond the application of
      the configuration context, is largely left to the interpretation of the
      specific device.  Some devices don't seem to perform an "internal reset"
      even if they report No_Soft_Reset == 0.
      
      We still need to honor the PCI specification and restore PCI config context
      in the event that we do a PM reset, so we don't cache and modify the
      PCI_PM_CTRL_NO_SOFT_RESET bit for the device, but for interfaces where the
      intention is to reset the device, like pci_reset_function(), we need a
      mechanism to flag that PM reset (a D3hot->D0 transition) doesn't perform
      any significant "internal reset" of the device.
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      51e53738
    • Y
      PCI: Add pci_claim_bridge_resource() to clip window if necessary · 8505e729
      Yinghai Lu 提交于
      Add pci_claim_bridge_resource() to claim a PCI-PCI bridge window.  This is
      like regular pci_claim_resource(), except that if we fail to claim the
      window, we check to see if we can reduce the size of the window and try
      again.
      
      This is for scenarios like this:
      
        pci_bus 0000:00: root bus resource [mem 0xc0000000-0xffffffff]
        pci 0000:00:01.0:   bridge window [mem 0xbdf00000-0xddefffff 64bit pref]
        pci 0000:01:00.0: reg 0x10: [mem 0xc0000000-0xcfffffff pref]
      
      The 00:01.0 window is illegal: it starts before the host bridge window, so
      we have to assume the [0xbdf00000-0xbfffffff] region is inaccessible.  We
      can make it legal by clipping it to [mem 0xc0000000-0xddefffff 64bit pref].
      
      Previously we discarded the 00:01.0 window and tried to reassign that part
      of the hierarchy from scratch.  That is a problem because Linux doesn't
      always assign things optimally.  For example, in this case, BIOS put the
      01:00.0 device in a prefetchable window below 4GB, but after 5b285415,
      Linux puts the prefetchable window above 4GB where the 32-bit 01:00.0
      device can't use it.
      
      Clipping the 00:01.0 window is less intrusive than completely reassigning
      things and is sufficient to let us use most of the BIOS configuration.  Of
      course, it's possible that devices below 00:01.0 will no longer fit.  If
      that's the case, we'll have to reassign things.  But that's a separate
      problem.
      
      [bhelgaas: changelog, split into separate patch]
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=85491Reported-by: NMarek Kordik <kordikmarek@gmail.com>
      Fixes: 5b285415 ("PCI: Restrict 64-bit prefetchable bridge windows to 64-bit resources")
      Signed-off-by: NYinghai Lu <yinghai@kernel.org>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      CC: stable@vger.kernel.org	# v3.16+
      8505e729
    • A
      PCI: Add flag for devices where we can't use bus reset · f331a859
      Alex Williamson 提交于
      Enable a mechanism for devices to quirk that they do not behave when
      doing a PCI bus reset.  We require a modest level of spec compliant
      behavior in order to do a reset, for instance the device should come
      out of reset without throwing errors and PCI config space should be
      accessible after reset.  This is too much to ask for some devices.
      
      Link: http://lkml.kernel.org/r/20140923210318.498dacbd@dualc.maya.orgSigned-off-by: NAlex Williamson <alex.williamson@redhat.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      CC: stable@vger.kernel.org	# v3.14+
      f331a859
  15. 16 12月, 2014 1 次提交
    • J
      x86, irq: Keep balance of IOAPIC pin reference count · cffe0a2b
      Jiang Liu 提交于
      To keep balance of IOAPIC pin reference count, we need to protect
      pirq_enable_irq(), acpi_pci_irq_enable() and intel_mid_pci_irq_enable()
      from reentrance. There are two cases which will cause reentrance.
      
      The first case is caused by suspend/hibernation. If pcibios_disable_irq
      is called during suspending/hibernating, we don't release the assigned
      IRQ number, otherwise it may break the suspend/hibernation. So late when
      pcibios_enable_irq is called during resume, we shouldn't allocate IRQ
      number again.
      
      The second case is that function acpi_pci_irq_enable() may be called
      twice for PCI devices present at boot time as below:
      1) pci_acpi_init()
      	--> acpi_pci_irq_enable() if pci_routeirq is true
      2) pci_enable_device()
      	--> pcibios_enable_device()
      		--> acpi_pci_irq_enable()
      We can't kill kernel parameter pci_routeirq yet because it's still
      needed for debugging purpose.
      
      So flag irq_managed is introduced to track whether IRQ number is
      assigned by OS and to protect pirq_enable_irq(), acpi_pci_irq_enable()
      and intel_mid_pci_irq_enable() from reentrance.
      Signed-off-by: NJiang Liu <jiang.liu@linux.intel.com>
      Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
      Cc: Tony Luck <tony.luck@intel.com>
      Cc: Joerg Roedel <joro@8bytes.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
      Cc: Bjorn Helgaas <bhelgaas@google.com>
      Cc: Randy Dunlap <rdunlap@infradead.org>
      Cc: Yinghai Lu <yinghai@kernel.org>
      Cc: Borislav Petkov <bp@alien8.de>
      Cc: Len Brown <lenb@kernel.org>
      Link: http://lkml.kernel.org/r/1414387308-27148-13-git-send-email-jiang.liu@linux.intel.comSigned-off-by: NThomas Gleixner <tglx@linutronix.de>
      cffe0a2b
  16. 04 12月, 2014 1 次提交
  17. 24 11月, 2014 1 次提交
  18. 12 11月, 2014 1 次提交
  19. 01 10月, 2014 3 次提交
    • L
      PCI: Add pci_remap_iospace() to map bus I/O resources · 8b921acf
      Liviu Dudau 提交于
      Add pci_remap_iospace() to map bus I/O resources into the CPU virtual
      address space.  Architectures with special needs may provide their own
      version, but most should be able to use this one.
      
      This function is useful for PCI host bridge drivers that need to map the
      PCI I/O resources into virtual memory space.
      
      [bhelgaas: phys_addr description, drop temporary "err" variable]
      Signed-off-by: NLiviu Dudau <Liviu.Dudau@arm.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: NRob Herring <robh@kernel.org>
      Reviewed-by: NCatalin Marinas <catalin.marinas@arm.com>
      CC: Arnd Bergmann <arnd@arndb.de>
      8b921acf
    • L
      of/pci: Add pci_get_new_domain_nr() and of_get_pci_domain_nr() · 41e5c0f8
      Liviu Dudau 提交于
      Add pci_get_new_domain_nr() to allocate a new domain number and
      of_get_pci_domain_nr() to retrieve the PCI domain number of a given device
      from DT.  Host bridge drivers or architecture-specific code can choose to
      implement their PCI domain number policy using these two functions.
      
      Using of_get_pci_domain_nr() guarantees a stable PCI domain number on every
      boot provided that all host bridge controllers are assigned a number in the
      device tree using "linux,pci-domain" property.  Mixing use of
      pci_get_new_domain_nr() and of_get_pci_domain_nr() is not recommended as it
      can lead to potentially conflicting domain numbers being assigned to root
      buses behind different host bridges.
      Signed-off-by: NLiviu Dudau <Liviu.Dudau@arm.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      CC: Arnd Bergmann <arnd@arndb.de>
      CC: Grant Likely <grant.likely@linaro.org>
      CC: Rob Herring <robh+dt@kernel.org>
      CC: Catalin Marinas <catalin.marinas@arm.com>
      41e5c0f8
    • C
      PCI: Add generic domain handling · 670ba0c8
      Catalin Marinas 提交于
      The handling of PCI domains (or PCI segments in ACPI speak) is usually a
      straightforward affair but its implementation is currently left to the
      architectural code, with pci_domain_nr(b) querying the value of the domain
      associated with bus b.
      
      This patch introduces CONFIG_PCI_DOMAINS_GENERIC as an option that can be
      selected if an architecture wants a simple implementation where the value
      of the domain associated with a bus is stored in struct pci_bus.
      
      The architectures that select CONFIG_PCI_DOMAINS_GENERIC will then have to
      implement pci_bus_assign_domain_nr() as a way of setting the domain number
      associated with a root bus.  All child buses except the root bus will
      inherit the domain_nr value from their parent.
      Signed-off-by: NCatalin Marinas <Catalin.Marinas@arm.com>
      [Renamed pci_set_domain_nr() to pci_bus_assign_domain_nr()]
      Signed-off-by: NLiviu Dudau <Liviu.Dudau@arm.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      CC: Arnd Bergmann <arnd@arndb.de>
      670ba0c8
  20. 23 9月, 2014 2 次提交
  21. 17 9月, 2014 2 次提交
  22. 11 9月, 2014 1 次提交
    • B
      PCI: Add pci_ignore_hotplug() to ignore hotplug events for a device · b440bde7
      Bjorn Helgaas 提交于
      Powering off a hot-pluggable device, e.g., with pci_set_power_state(D3cold),
      normally generates a hot-remove event that unbinds the driver.
      
      Some drivers expect to remain bound to a device even while they power it
      off and back on again.  This can be dangerous, because if the device is
      removed or replaced while it is powered off, the driver doesn't know that
      anything changed.  But some drivers accept that risk.
      
      Add pci_ignore_hotplug() for use by drivers that know their device cannot
      be removed.  Using pci_ignore_hotplug() tells the PCI core that hot-plug
      events for the device should be ignored.
      
      The radeon and nouveau drivers use this to switch between a low-power,
      integrated GPU and a higher-power, higher-performance discrete GPU.  They
      power off the unused GPU, but they want to remain bound to it.
      
      This is a reimplementation of f244d8b6 ("ACPIPHP / radeon / nouveau:
      Fix VGA switcheroo problem related to hotplug") but extends it to work with
      both acpiphp and pciehp.
      
      This fixes a problem where systems with dual GPUs using the radeon drivers
      become unusable, freezing every few seconds (see bugzillas below).  The
      resume of the radeon device may also fail, e.g.,
      
      This fixes problems on dual GPU systems where the radeon driver becomes
      unusable because of problems while suspending the device, as in bug 79701:
      
          [drm] radeon: finishing device.
          radeon 0000:01:00.0: Userspace still has active objects !
          radeon 0000:01:00.0: ffff8800cb4ec288 ffff8800cb4ec000 16384 4294967297 force free
          ...
          WARNING: CPU: 0 PID: 67 at /home/apw/COD/linux/drivers/gpu/drm/radeon/radeon_gart.c:234 radeon_gart_unbind+0xd2/0xe0 [radeon]()
          trying to unbind memory from uninitialized GART !
      
      or while resuming it, as in bug 77261:
      
          radeon 0000:01:00.0: ring 0 stalled for more than 10158msec
          radeon 0000:01:00.0: GPU lockup ...
          radeon 0000:01:00.0: GPU pci config reset
          pciehp 0000:00:01.0:pcie04: Card not present on Slot(1-1)
          radeon 0000:01:00.0: GPU reset succeeded, trying to resume
          *ERROR* radeon: dpm resume failed
          radeon 0000:01:00.0: Wait for MC idle timedout !
      
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=77261
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=79701Reported-by: NShawn Starr <shawn.starr@rogers.com>
      Reported-by: NJose P. <lbdkmjdf@sharklasers.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Acked-by: NAlex Deucher <alexander.deucher@amd.com>
      Acked-by: NRajat Jain <rajatxjain@gmail.com>
      Acked-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Acked-by: NDave Airlie <airlied@redhat.com>
      CC: stable@vger.kernel.org	# v3.15+
      b440bde7
  23. 17 7月, 2014 1 次提交
  24. 04 7月, 2014 1 次提交
  25. 20 6月, 2014 1 次提交
  26. 30 5月, 2014 1 次提交
  27. 29 5月, 2014 4 次提交
    • A
      PCI: Introduce new device binding path using pci_dev.driver_override · 782a985d
      Alex Williamson 提交于
      The driver_override field allows us to specify the driver for a device
      rather than relying on the driver to provide a positive match of the
      device.  This shortcuts the existing process of looking up the vendor and
      device ID, adding them to the driver new_id, binding the device, then
      removing the ID, but it also provides a couple advantages.
      
      First, the above existing process allows the driver to bind to any device
      matching the new_id for the window where it's enabled.  This is often not
      desired, such as the case of trying to bind a single device to a meta
      driver like pci-stub or vfio-pci.  Using driver_override we can do this
      deterministically using:
      
        echo pci-stub > /sys/bus/pci/devices/0000:03:00.0/driver_override
        echo 0000:03:00.0 > /sys/bus/pci/devices/0000:03:00.0/driver/unbind
        echo 0000:03:00.0 > /sys/bus/pci/drivers_probe
      
      Previously we could not invoke drivers_probe after adding a device to
      new_id for a driver as we get non-deterministic behavior whether the driver
      we intend or the standard driver will claim the device.  Now it becomes a
      deterministic process, only the driver matching driver_override will probe
      the device.
      
      To return the device to the standard driver, we simply clear the
      driver_override and reprobe the device:
      
        echo > /sys/bus/pci/devices/0000:03:00.0/driver_override
        echo 0000:03:00.0 > /sys/bus/pci/devices/0000:03:00.0/driver/unbind
        echo 0000:03:00.0 > /sys/bus/pci/drivers_probe
      
      Another advantage to this approach is that we can specify a driver override
      to force a specific binding or prevent any binding.  For instance when an
      IOMMU group is exposed to userspace through VFIO we require that all
      devices within that group are owned by VFIO.  However, devices can be
      hot-added into an IOMMU group, in which case we want to prevent the device
      from binding to any driver (override driver = "none") or perhaps have it
      automatically bind to vfio-pci.  With driver_override it's a simple matter
      for this field to be set internally when the device is first discovered to
      prevent driver matches.
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      Reviewed-by: NKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
      Reviewed-by: NAlexander Graf <agraf@suse.de>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      782a985d
    • A
      PCI: Add support for PCIe-to-PCI bridge DMA alias quirks · c8fe16e3
      Alex Williamson 提交于
      Several PCIe-to-PCI bridges fail to provide a PCIe capability, causing us
      to handle them as conventional PCI devices when they really use the
      requester ID of the secondary bus.  We need to differentiate these from
      PCIe-to-PCI bridges that actually use the conventional PCI ID when a PCIe
      capability is not present, such as those found on the root complex of may
      Intel chipsets.  Add a dev_flag bit to identify devices to be handled as
      standard PCIe-to-PCI bridges.
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      c8fe16e3
    • A
      PCI: Add support for DMA alias quirks · 31c2b815
      Alex Williamson 提交于
      Some devices are broken and use a requester ID other than their physical
      devfn.  Add a byte, using an existing gap in the pci_dev structure, to
      store an alternate "alias" devfn.  A bit in the dev_flags tells us when
      this is valid.  We then add the alias as one more step in the
      pci_for_each_dma_alias() iterator.
      Tested-by: NGeorge Spelvin <linux@horizon.com>
      Tested-by: NPat Erley <pat-lkml@erley.org>
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      31c2b815
    • A
      PCI: Convert pci_dev_flags definitions to bit shifts · 6b121592
      Alex Williamson 提交于
      Convert the pci_dev_flags definitions from decimal constants to bit shifts.
      We're only a few entries away from where using the decimal value becomes
      cumbersome.  No functional change.
      Tested-by: NGeorge Spelvin <linux@horizon.com>
      Tested-by: NPat Erley <pat-lkml@erley.org>
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      Signed-off-by: NBjorn Helgaas <bhelgaas@google.com>
      6b121592