From: Wei Wang Subject: [PATCH 3 of 5] ats: Add new ATS helper functions Date: Thu, 3 Nov 2011 11:13:03 +0100 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: JBeulich@novell.com List-Id: xen-devel@lists.xenproject.org # HG changeset patch # User Wei Wang # Date 1320314663 -3600 # Node ID c839972486f86a0833595bebae0baa0cd2c0d15e # Parent d0c38cb215cd96e01de27eadf5ec0a5e711de448 ats: Add new ATS helper functions Signed-off-by Wei Wang diff -r d0c38cb215cd -r c839972486f8 xen/drivers/passthrough/ats.h --- a/xen/drivers/passthrough/ats.h Thu Nov 03 11:03:37 2011 +0100 +++ b/xen/drivers/passthrough/ats.h Thu Nov 03 11:04:23 2011 +0100 @@ -21,6 +21,8 @@ #define ATS_QUEUE_DEPTH_MASK 0xF #define ATS_ENABLE (1<<15) +#include + struct pci_ats_dev { struct list_head list; u16 seg; @@ -34,6 +36,27 @@ extern bool_t ats_enabled; int enable_ats_device(int seg, int bus, int devfn); void disable_ats_device(int seg, int bus, int devfn); +struct pci_ats_dev *get_ats_device(int seg, int bus, int devfn); +static inline int pci_ats_enabled(int seg, int bus, int devfn) +{ + u32 value; + int pos; + + pos = pci_find_ext_capability(seg, bus, devfn, PCI_EXT_CAP_ID_ATS); + BUG_ON(!pos); + + value = pci_conf_read16(seg, bus, PCI_SLOT(devfn), + PCI_FUNC(devfn), pos + ATS_REG_CTL); + return value & ATS_ENABLE; +} + +static inline int pci_ats_device(int seg, int bus, int devfn) +{ + if ( !ats_enabled ) + return 0; + + return pci_find_ext_capability(seg, bus, devfn, PCI_EXT_CAP_ID_ATS); +} #endif /* _ATS_H_ */ diff -r d0c38cb215cd -r c839972486f8 xen/drivers/passthrough/x86/ats.c --- a/xen/drivers/passthrough/x86/ats.c Thu Nov 03 11:03:37 2011 +0100 +++ b/xen/drivers/passthrough/x86/ats.c Thu Nov 03 11:04:23 2011 +0100 @@ -137,3 +137,19 @@ void disable_ats_device(int seg, int bus "%04x:%02x:%02x.%u: ATS is disabled\n", seg, bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); } + +struct pci_ats_dev *get_ats_device(int seg, int bus, int devfn) +{ + struct pci_ats_dev *pdev; + + if ( !pci_ats_device(seg, bus, devfn) ) + return NULL; + + list_for_each_entry ( pdev, &ats_devices, list ) + { + if ( pdev->seg == seg && pdev->bus == bus && pdev->devfn == devfn ) + return pdev; + } + + return NULL; +}