From: Ashok Raj <ashok.raj@intel.com>
To: linux-kernel@vger.kernel.org
Cc: akpm@osdl.org, ak@suse.de, gregkh@suse.de, muli@il.ibm.com,
asit.k.mallick@intel.com, suresh.b.siddha@intel.com,
anil.s.keshavamurthy@intel.com, arjan@linux.intel.com,
ashok.raj@intel.com, shaohua.li@intel.com
Subject: [Intel IOMMU][patch 2/8] Some generic search functions required to lookup device relationships.
Date: Mon, 23 Apr 2007 23:03:01 -0700 [thread overview]
Message-ID: <20070424061037.508715000@intel.com> (raw)
In-Reply-To: 20070424060259.426374000@intel.com
[-- Attachment #1: pci-exp.patch --]
[-- Type: text/plain, Size: 4105 bytes --]
PCI support functions for DMAR, to find parent bridge.
When devices are under a p2p bridge, upstream
transactions get replaced by the device id of the bridge as it owns the
PCIE transaction. Hence its necessary to setup translations on behalf of the
bridge as well. Due to this limitation all devices under a p2p share the same
domain in a DMAR.
We just cache the type of device, if its a native PCIe device
or not for later use.
Signed-off-by: Ashok Raj <ashok.raj@intel.com>
Signed-off-by: Shaohua Li <shaohua.li@intel.com>
-------------------------------------------------
Index: 2.6.21-rc6/drivers/pci/pci.h
===================================================================
--- 2.6.21-rc6.orig/drivers/pci/pci.h 2007-04-06 10:36:56.000000000 +0800
+++ 2.6.21-rc6/drivers/pci/pci.h 2007-04-11 13:52:29.000000000 +0800
@@ -90,3 +90,4 @@ pci_match_one_device(const struct pci_de
return NULL;
}
+struct pci_dev *pci_find_upstream_pcie_bridge(struct pci_dev *pdev);
Index: 2.6.21-rc6/drivers/pci/probe.c
===================================================================
--- 2.6.21-rc6.orig/drivers/pci/probe.c 2007-04-06 10:36:56.000000000 +0800
+++ 2.6.21-rc6/drivers/pci/probe.c 2007-04-11 13:52:29.000000000 +0800
@@ -822,6 +822,19 @@ static void pci_release_dev(struct devic
kfree(pci_dev);
}
+static void set_pcie_port_type(struct pci_dev *pdev)
+{
+ int pos;
+ u16 reg16;
+
+ pos = pci_find_capability(pdev, PCI_CAP_ID_EXP);
+ if (!pos)
+ return;
+ pdev->is_pcie = 1;
+ pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, ®16);
+ pdev->pcie_type = (reg16 & PCI_EXP_FLAGS_TYPE) >> 4;
+}
+
/**
* pci_cfg_space_size - get the configuration space size of the PCI device.
* @dev: PCI device
@@ -919,6 +932,7 @@ pci_scan_device(struct pci_bus *bus, int
dev->device = (l >> 16) & 0xffff;
dev->cfg_size = pci_cfg_space_size(dev);
dev->error_state = pci_channel_io_normal;
+ set_pcie_port_type(dev);
/* Assume 32-bit PCI; let 64-bit PCI cards (which are far rarer)
set this higher, assuming the system even supports it. */
Index: 2.6.21-rc6/drivers/pci/search.c
===================================================================
--- 2.6.21-rc6.orig/drivers/pci/search.c 2007-04-06 10:36:56.000000000 +0800
+++ 2.6.21-rc6/drivers/pci/search.c 2007-04-11 13:52:29.000000000 +0800
@@ -14,6 +14,36 @@
#include "pci.h"
DECLARE_RWSEM(pci_bus_sem);
+/*
+ * find the upstream PCIE-to-PCI bridge of a PCI device
+ * if the device is PCIE, return NULL
+ * if the device isn't connected to a PCIE bridge (that is its parent is a
+ * legacy PCI bridge and the bridge is directly connected to bus 0), return its
+ * parent
+ */
+struct pci_dev *
+pci_find_upstream_pcie_bridge(struct pci_dev *pdev)
+{
+ struct pci_dev *tmp = NULL;
+
+ if (pdev->is_pcie)
+ return NULL;
+ while (1) {
+ if (!pdev->bus->self)
+ break;
+ pdev = pdev->bus->self;
+ /* a p2p bridge */
+ if (!pdev->is_pcie) {
+ tmp = pdev;
+ continue;
+ }
+ /* PCI device should connect to a PCIE bridge */
+ BUG_ON(pdev->pcie_type != PCI_EXP_TYPE_PCI_BRIDGE);
+ return pdev;
+ }
+
+ return tmp;
+}
static struct pci_bus *
pci_do_find_bus(struct pci_bus* bus, unsigned char busnr)
Index: 2.6.21-rc6/include/linux/pci.h
===================================================================
--- 2.6.21-rc6.orig/include/linux/pci.h 2007-04-06 10:36:56.000000000 +0800
+++ 2.6.21-rc6/include/linux/pci.h 2007-04-11 13:52:29.000000000 +0800
@@ -126,6 +126,7 @@ struct pci_dev {
unsigned short subsystem_device;
unsigned int class; /* 3 bytes: (base,sub,prog-if) */
u8 hdr_type; /* PCI header type (`multi' flag masked out) */
+ u8 pcie_type; /* PCI-E device/port type */
u8 rom_base_reg; /* which config register controls the ROM */
u8 pin; /* which interrupt pin this device uses */
@@ -168,6 +169,7 @@ struct pci_dev {
unsigned int msi_enabled:1;
unsigned int msix_enabled:1;
unsigned int is_managed:1;
+ unsigned int is_pcie:1;
atomic_t enable_cnt; /* pci_enable_device has been called */
u32 saved_config_space[16]; /* config space saved at suspend time */
--
next prev parent reply other threads:[~2007-04-24 15:08 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-24 6:02 [Intel IOMMU][patch 0/8] Intel IOMMU Support Ashok Raj
2007-04-24 6:03 ` [Intel IOMMU][patch 1/8] ACPI support for Intel Virtualization Technology for Directed I/O Ashok Raj
2007-04-24 18:50 ` Andi Kleen
2007-04-24 20:17 ` Ashok Raj
2007-04-24 6:03 ` Ashok Raj [this message]
2007-04-24 6:03 ` [Intel IOMMU][patch 3/8] Generic hardware support for Intel IOMMU Ashok Raj
2007-04-24 19:27 ` Andi Kleen
2007-04-24 20:59 ` Ashok Raj
2007-04-25 1:17 ` Shaohua Li
2007-04-25 6:53 ` Andi Kleen
2007-04-24 6:03 ` [Intel IOMMU][patch 4/8] Supporting Zero Length Reads in " Ashok Raj
2007-04-24 19:28 ` Andi Kleen
2007-04-24 20:42 ` Ashok Raj
2007-04-24 21:00 ` David Miller
2007-04-24 6:03 ` [Intel IOMMU][patch 5/8] Graphics driver workarounds to provide unity map Ashok Raj
2007-04-24 6:03 ` [Intel IOMMU][patch 6/8] Doc updates for Intel Virtualization Technology for Directed I/O Ashok Raj
2007-04-24 6:03 ` [Intel IOMMU][patch 7/8] Support for legacy ISA devices Ashok Raj
2007-04-24 19:31 ` Andi Kleen
2007-04-24 20:33 ` Arjan van de Ven
2007-04-24 20:39 ` Ashok Raj
2007-04-24 6:03 ` [Intel IOMMU][patch 8/8] Preserve some Virtual Address when devices cannot address entire range Ashok Raj
2007-04-24 19:33 ` Andi Kleen
2007-04-24 20:33 ` Ashok Raj
2007-04-24 21:12 ` Andi Kleen
2007-04-24 21:23 ` David Miller
2007-04-24 21:32 ` Roland Dreier
2007-04-24 21:47 ` David Miller
2007-04-24 21:38 ` Ashok Raj
2007-04-24 21:50 ` David Miller
2007-04-24 22:03 ` Andi Kleen
2007-04-24 22:26 ` Ashok Raj
2007-04-25 1:12 ` H. Peter Anvin
2007-04-25 6:55 ` Andi Kleen
2007-04-24 23:22 ` Alan Cox
-- strict thread matches above, loose matches on Subject: below --
2007-04-23 16:38 [Intel IOMMU][patch 0/8] Intel IOMMU Support Ashok Raj
2007-04-23 16:38 ` [Intel IOMMU][patch 2/8] Some generic search functions required to lookup device relationships Ashok Raj
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070424061037.508715000@intel.com \
--to=ashok.raj@intel.com \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=anil.s.keshavamurthy@intel.com \
--cc=arjan@linux.intel.com \
--cc=asit.k.mallick@intel.com \
--cc=gregkh@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=muli@il.ibm.com \
--cc=shaohua.li@intel.com \
--cc=suresh.b.siddha@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox