ATS support for AMD IOMMU driver
PATCH 2/5 x86/amd-iommu: Select PCI_IOV with AMD IOMMU driver
In reply to Joerg RoedelIn order to support ATS in the AMD IOMMU driver this patch makes sure that the generic support for ATS is compiled in.
--- arch/x86/Kconfig | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/Kconfig +1 -0
@@ -690,6 +690,7 @@ config AMD_IOMMU bool "AMD IOMMU support" select SWIOTLB select PCI_MSI + select PCI_IOV depends on X86_64 && PCI && ACPI ---help--- With this option you can enable support for AMD IOMMU hardware in
Signature · 1 line
1.7.1
PATCH 4/5 x86/amd-iommu: Add flag to indicate IOTLB support
In reply to Joerg RoedelThis patch adds a flag to the AMD IOMMU driver to indicate that all IOMMUs present in the system support device IOTLBs.
--- arch/x86/include/asm/amd_iommu_types.h | 2 ++ arch/x86/kernel/amd_iommu_init.c | 4 ++++ 2 files changed, 6 insertions(+), 0 deletions(-)
arch/x86/include/asm/amd_iommu_types.h +2 -0
@@ -250,6 +250,8 @@ extern bool amd_iommu_dump;/* global flag if IOMMUs cache non-present entries */ extern bool amd_iommu_np_cache; +/* Only true if all IOMMUs support device IOTLBs */ +extern bool amd_iommu_iotlb_sup;/* * Make iterating over all IOMMUs easier
arch/x86/kernel/amd_iommu_init.c +4 -0
@@ -137,6 +137,7 @@ int amd_iommus_present;/* IOMMUs have a non-present cache? */ bool amd_iommu_np_cache__read_mostly ; +bool amd_iommu_iotlb_sup__read_mostly = true;/* * The ACPI table parsing functions set this variable on an error
@@ -673,6 +674,9 @@ static void __init init_iommu_from_pci(struct amd_iommu *iommu) MMIO_GET_LD(range)); iommu->evt_msi_num =MMIO_MSI_NUM (misc); +if (!(iommu->cap & (1 <<IOMMU_CAP_IOTLB ))) + amd_iommu_iotlb_sup = false; +if (!is_rd890_iommu (iommu->dev))return ;
Signature · 1 line
1.7.1
PATCH 5/5 x86/amd-iommu: Add ATS enable/disable code
In reply to Joerg RoedelThis patch adds the necessary code to the AMD IOMMU driver for enabling and disabling the ATS capability on a device and to setup the IOMMU data structures correctly.
--- arch/x86/include/asm/amd_iommu_types.h | 2 ++ arch/x86/kernel/amd_iommu.c | 29 +++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-)
arch/x86/include/asm/amd_iommu_types.h +2 -0
@@ -216,6 +216,8 @@#define IOMMU_PTE_IR (1ULL << 61)#define IOMMU_PTE_IW (1ULL << 62) +#define DTE_FLAG_IOTLB 0x01 +#define IOMMU_PAGE_MASK (((1ULL << 52) - 1) & ~0xfffULL)#define IOMMU_PTE_PRESENT (pte) ((pte) & IOMMU_PTE_P)#define IOMMU_PTE_PAGE (pte) (phys_to_virt((pte) & IOMMU_PAGE_MASK))
arch/x86/kernel/amd_iommu.c +23 -6
@@ -1452,17 +1452,22 @@ static bool dma_ops_domain(struct protection_domain *domain)return domain->flags &PD_DMA_OPS_MASK ; } -static void set_dte_entry (u16 devid,struct protection_domain *domain) +static void set_dte_entry (u16 devid,struct protection_domain *domain,bool ats) {u64 pte_root =virt_to_phys (domain->pt_root); +u32 flags =0 ; pte_root |= (domain->mode &DEV_ENTRY_MODE_MASK ) <<DEV_ENTRY_MODE_SHIFT ; pte_root |=IOMMU_PTE_IR |IOMMU_PTE_IW |IOMMU_PTE_P |IOMMU_PTE_TV ; - amd_iommu_dev_table[devid].data[2 ] = domain->id; - amd_iommu_dev_table[devid].data[1 ] =upper_32_bits (pte_root); - amd_iommu_dev_table[devid].data[0 ] =lower_32_bits (pte_root); +if (ats) + flags |=DTE_FLAG_IOTLB ; + + amd_iommu_dev_table[devid].data[3 ] |= flags; + amd_iommu_dev_table[devid].data[2 ] = domain->id; + amd_iommu_dev_table[devid].data[1 ] =upper_32_bits (pte_root); + amd_iommu_dev_table[devid].data[0 ] =lower_32_bits (pte_root); }static void clear_dte_entry (u16 devid)
@@ -1479,16 +1484,22 @@ static void do_attach(struct device *dev, struct protection_domain *domain) {struct iommu_dev_data *dev_data;struct amd_iommu *iommu; +struct pci_dev *pdev; +bool ats = false;u16 devid; devid =get_device_id (dev); iommu = amd_iommu_rlookup_table[devid]; dev_data =get_dev_data (dev); + pdev =to_pci_dev (dev); + +if (amd_iommu_iotlb_sup) + ats =pci_enable_ats (pdev,PAGE_SHIFT ) ==0 ;/* Update data structures */ dev_data->domain = domain;list_add (&dev_data->list, &domain->dev_list); -set_dte_entry (devid, domain); +set_dte_entry (devid, domain, ats);/* Do reference counting */ domain->dev_iommu[iommu->index] +=1 ;
@@ -1502,11 +1513,13 @@ static void do_detach(struct device *dev) {struct iommu_dev_data *dev_data;struct amd_iommu *iommu; +struct pci_dev *pdev;u16 devid; devid =get_device_id (dev); iommu = amd_iommu_rlookup_table[devid]; dev_data =get_dev_data (dev); + pdev =to_pci_dev (dev);/* decrease reference counters */ dev_data->domain->dev_iommu[iommu->index] -=1 ;
@@ -1517,6 +1530,9 @@ static void do_detach(struct device *dev)list_del (&dev_data->list);clear_dte_entry (devid); +if (amd_iommu_iotlb_sup &&pci_ats_enabled (pdev)) +pci_disable_ats (pdev); +/* Flush the DTE entry */ device_flush_dte (dev); }
@@ -1795,8 +1811,9 @@ static void update_device_table(struct protection_domain *domain)struct iommu_dev_data *dev_data;list_for_each_entry (dev_data, &domain->dev_list, list) { +struct pci_dev *pdev =to_pci_dev (dev_data->dev);u16 devid =get_device_id (dev_data->dev); -set_dte_entry (devid, domain); +set_dte_entry (devid, domain,pci_ats_enabled (pdev)); } }
Signature · 1 line
1.7.1
PATCH 3/5 x86/amd-iommu: Flush device IOTLB if ATS is enabled
In reply to Joerg RoedelThis patch implements a function to flush the IOTLB on devices supporting ATS and makes sure that this TLB is also flushed if necessary.
--- arch/x86/include/asm/amd_iommu_types.h | 3 +- arch/x86/kernel/amd_iommu.c | 74 +++++++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 2 deletions(-)
arch/x86/include/asm/amd_iommu_types.h +2 -1
@@ -113,7 +113,8 @@/* command specific defines */ #define CMD_COMPL_WAIT 0x01#define CMD_INV_DEV_ENTRY 0x02 -#define CMD_INV_IOMMU_PAGES 0x03 +#define CMD_INV_IOMMU_PAGES 0x03 +#define CMD_INV_IOTLB_PAGES 0x04#define CMD_COMPL_WAIT_STORE_MASK 0x01#define CMD_COMPL_WAIT_INT_MASK 0x02
arch/x86/kernel/amd_iommu.c +73 -1
114 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 1/5 PCI: Move ATS declarations in seperate header file
In reply to Joerg RoedelThis patch moves the relevant declarations from the local header file in drivers/pci to a more accessible locations so that it can be used by the AMD IOMMU driver too. The file is named pci-ats-pri.h because support for the PCI PRI capability will also be added there in a later patch-set.
--- drivers/pci/intel-iommu.c | 1 + drivers/pci/iov.c | 1 + drivers/pci/pci.h | 37 -------------------------------- include/linux/pci-ats.h | 52 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 37 deletions(-) create mode 100644 include/linux/pci-ats.h
drivers/pci/intel-iommu.c +1 -0
@@ -39,6 +39,7 @@#include <linux/syscore_ops.h> #include <linux/tboot.h> #include <linux/dmi.h> +#include <linux/pci-ats.h> #include <asm/cacheflush.h> #include <asm/iommu.h> #include "pci.h"
drivers/pci/iov.c +1 -0
@@ -13,6 +13,7 @@#include <linux/mutex.h> #include <linux/string.h> #include <linux/delay.h> +#include <linux/pci-ats.h> #include "pci.h" #define VIRTFN_ID_LEN 16
drivers/pci/pci.h +0 -37
@@ -250,15 +250,6 @@ struct pci_sriov {u8 __iomem *mstate;/* VF Migration State Array */ }; -/* Address Translation Service */ -struct pci_ats { -int pos;/* capability position */ -int stu;/* Smallest Translation Unit */ -int qdep;/* Invalidate Queue Depth */ -int ref_cnt;/* Physical Function reference count */ -unsigned int is_enabled:1 ;/* Enable bit is set */ -}; -#ifdef CONFIG_PCI_IOV extern int pci_iov_init (struct pci_dev *dev);extern void pci_iov_release (struct pci_dev *dev);
@@ -269,19 +260,6 @@ extern resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev,extern void pci_restore_iov_state (struct pci_dev *dev);extern int pci_iov_bus_range (struct pci_bus *bus); -extern int pci_enable_ats (struct pci_dev *dev,int ps); -extern void pci_disable_ats (struct pci_dev *dev); -extern int pci_ats_queue_depth (struct pci_dev *dev); -/** -* pci_ats_enabled - query the ATS status -* @dev: the PCI device -* -* Returns 1 if ATS capability is enabled, or 0 if not. -*/ -static inline int pci_ats_enabled (struct pci_dev *dev) -{ -return dev->ats && dev->ats->is_enabled; -}#else static inline int pci_iov_init (struct pci_dev *dev) {
@@ -304,21 +282,6 @@ static inline int pci_iov_bus_range(struct pci_bus *bus)return 0 ; } -static inline int pci_enable_ats (struct pci_dev *dev,int ps) -{ -return -ENODEV ; -} -static inline void pci_disable_ats (struct pci_dev *dev) -{ -} -static inline int pci_ats_queue_depth (struct pci_dev *dev) -{ -return -ENODEV ; -} -static inline int pci_ats_enabled (struct pci_dev *dev) -{ -return 0 ; -}#endif /* CONFIG_PCI_IOV */ static inline resource_size_t pci_resource_alignment(struct pci_dev *dev,
include/linux/pci-ats.h new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
1.7.1
cover ATS support for AMD IOMMU driver
Hi,
this patch-set implements support for ATS devices in the AMD IOMMU driver. For that it uses the ATS capability implementation already present in the core PCI code.
Jesse, patch 1/5 touches generic PCI code, can you please have a look at it an ACK it if you think it is ok? The change basically move out the declarations relevant for ATS into a header file under include/linux. This header file will also be used later to put declarations for PRI support there (which is also part of the ATS spec).
Any feedback appreciated.
Regards,
Joerg
Diffstat:
arch/x86/Kconfig | 1 + arch/x86/include/asm/amd_iommu_types.h | 7 ++- arch/x86/kernel/amd_iommu.c | 103 +++++++++++++++++++++++++++++-- arch/x86/kernel/amd_iommu_init.c | 4 + drivers/pci/intel-iommu.c | 1 + drivers/pci/iov.c | 1 + drivers/pci/pci.h | 37 ----------- include/linux/pci-ats.h | 52 ++++++++++++++++ 8 files changed, 161 insertions(+), 45 deletions(-)
Shortlog:
Joerg Roedel (5):
PCI: Move ATS declarations in seperate header file x86/amd-iommu: Select PCI_IOV with AMD IOMMU driver x86/amd-iommu: Flush device IOTLB if ATS is enabled x86/amd-iommu: Add flag to indicate IOTLB support x86/amd-iommu: Add ATS enable/disable code
Re: [PATCH 1/5] PCI: Move ATS declarations in seperate header file
In reply to Joerg RoedelQuoted 7 lines · On Fri, 8 Apr 2011 10:17:06 +0200 Joerg Roedel <[email protected]> wrote:
This patch moves the relevant declarations from the local header file in
drivers/pcito a more accessible locations so that it can be used by the AMD IOMMU driver too. The file is namedpci-ats-pri.hbecause support for the PCI PRI capability will also be added there in a later patch-set.
Quoted 8 lines
Signed-off-by Joerg Roedel <[email protected]>--- drivers/pci/intel-iommu.c | 1 + drivers/pci/iov.c | 1 + drivers/pci/pci.h | 37 -------------------------------- include/linux/pci-ats.h | 52 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 37 deletions(-) create mode 100644 include/linux/pci-ats.h
Looks fine.
Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center
Re: [PATCH 1/5] PCI: Move ATS declarations in seperate header file
In reply to Joerg RoedelAm Freitag, 8. April 2011, 10:17:06 schrieb Joerg Roedel:
Quoted 4 lines
This patch moves the relevant declarations from the local header file in
drivers/pcito a more accessible locations so that it can be used by the AMD IOMMU driver too. The file is namedpci-ats-pri.hbecause support for the PCI
^^^^^^^^^^^^^
Quoted 1 line
include/linux/pci-ats.h | 52
^^^^^^^^^
Ehm, no, it is not ;)
Eike
Re: [PATCH 1/5] PCI: Move ATS declarations in seperate header file
Quoted 11 lines · Rolf Eike Beer
Am Freitag, 8. April 2011, 10:17:06 schrieb Joerg Roedel:
Quoted 4 lines
This patch moves the relevant declarations from the local header file in
drivers/pcito a more accessible locations so that it can be used by the AMD IOMMU driver too. The file is namedpci-ats-pri.hbecause support for the PCI^^^^^^^^^^^^^Quoted 1 line
include/linux/pci-ats.h | 52^^^^^^^^^Ehm, no, it is not ;)
Right, I renamed the file at some point and forgot to change it in the commit-msg too. I'll fix that on the next rebase :)
Joerg
Signature · 5 lines
AMD Operating System Research Center Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach General Managers: Alberto Bozzo, Andrew Bowd Registration: Dornach, Landkr. Muenchen; Registerger. Muenchen, HRB Nr. 43632