iommu: Move swap_pci_ref function to pci.h.
PATCH v2 1/3 iommu: Move swap_pci_ref function to pci.h.
swap_pci_ref function is used by the IOMMU API code for swapping pci device pointers, while determining the iommu group for the device. Currently this function was being implemented for different IOMMU drivers. This patch moves the function to a new file, drivers/iommu/pci.h so that the implementation can be shared across various IOMMU drivers.
---
v2 changes:
- created a new file drivers/iommu/pci.h.
drivers/iommu/amd_iommu.c | 7 +------ drivers/iommu/intel-iommu.c | 7 +------ drivers/iommu/pci.h | 29 +++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 drivers/iommu/pci.h
drivers/iommu/amd_iommu.c +1 -6
@@ -46,6 +46,7 @@#include "amd_iommu_proto.h" #include "amd_iommu_types.h" #include "irq_remapping.h" +#include "pci.h" #define CMD_SET_TYPE (cmd, t) ((cmd)->data[1] |= ((t) << 28))
@@ -263,12 +264,6 @@ static bool check_device(struct device *dev)return true; } -static void swap_pci_ref (struct pci_dev **from,struct pci_dev *to) -{ -pci_dev_put (*from); - *from = to; -} -static struct pci_bus *find_hosted_bus (struct pci_bus *bus) {while (!bus->self) {
drivers/iommu/intel-iommu.c +1 -6
@@ -47,6 +47,7 @@#include <asm/iommu.h> #include "irq_remapping.h" +#include "pci.h" #define ROOT_SIZE VTD_PAGE_SIZE#define CONTEXT_SIZE VTD_PAGE_SIZE
@@ -4137,12 +4138,6 @@ static int intel_iommu_domain_has_cap(struct iommu_domain *domain,return 0 ; } -static void swap_pci_ref (struct pci_dev **from,struct pci_dev *to) -{ -pci_dev_put (*from); - *from = to; -} -#define REQ_ACS_FLAGS (PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF)static int intel_iommu_add_device (struct device *dev)
drivers/iommu/pci.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +* +* Copyright (C) 2013 Red Hat, Inc. +* Copyright (C) 2013 Freescale Semiconductor, Inc. +* +*/ +#ifndef __PCI_H +#define __PCI_H + +/* Helper function for swapping pci device reference */ +static inline void swap_pci_ref (struct pci_dev **from,struct pci_dev *to) +{ +pci_dev_put (*from); + *from = to; +} + +#endif /* __PCI_H */
Signature · 1 line
1.7.4.1
PATCH v14 2/3 iommu/fsl: Add additional iommu attributes required by the PAMU driver.
Added the following domain attributes for the FSL PAMU driver:
1. Added new iommu stash attribute, which allows setting of the LIODN specific stash id parameter through IOMMU API.
2. Added an attribute for enabling/disabling DMA to a particular memory window.
3. Added domain attribute to check for PAMUV1 specific constraints.
---
v14 changes:
- Add FSL prefix to PAMU attributes.
v13 changes:
- created a new file include/linux/fsl_pamu_stash.h for stash attributes.
v12 changes:
- Moved PAMU specifc stash ids and structures to PAMU header file.
- no change in v11.
- no change in v10.
include/linux/fsl_pamu_stash.h | 39 +++++++++++++++++++++++++++++++++++++++ include/linux/iommu.h | 16 ++++++++++++++++ 2 files changed, 55 insertions(+), 0 deletions(-) create mode 100644 include/linux/fsl_pamu_stash.h
include/linux/fsl_pamu_stash.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +* +* Copyright (C) 2013 Freescale Semiconductor, Inc. +* +*/ + +#ifndef __FSL_PAMU_STASH_H +#define __FSL_PAMU_STASH_H + +/* cache stash targets */ +enum pamu_stash_target { +PAMU_ATTR_CACHE_L1 =1 , +PAMU_ATTR_CACHE_L2 , +PAMU_ATTR_CACHE_L3 , +}; + +/* +* This attribute allows configuring stashig specific parameters +* in the PAMU hardware. +*/ + +struct pamu_stash_attribute { +u32 cpu;/* cpu number */ +u32 cache;/* cache to stash to: L1,L2,L3 */ +}; + +#endif /* __FSL_PAMU_STASH_H */
include/linux/iommu.h +16 -0
@@ -57,10 +57,26 @@ struct iommu_domain {#define IOMMU_CAP_CACHE_COHERENCY 0x1#define IOMMU_CAP_INTR_REMAP 0x2/* isolates device intrs */ +/* +* Following constraints are specifc to FSL_PAMUV1: +* -aperture must be power of 2, and naturally aligned +* -number of windows must be power of 2, and address space size +* of each window is determined by aperture size / # of windows +* -the actual size of the mapped region of a window must be power +* of 2 starting with 4KB and physical address must be naturally +* aligned. +* DOMAIN_ATTR_FSL_PAMUV1 corresponds to the above mentioned contraints. +* The caller can invoke iommu_domain_get_attr to check if the underlying +* iommu implementation supports these constraints. +*/ +enum iommu_attr {DOMAIN_ATTR_GEOMETRY ,DOMAIN_ATTR_PAGING ,DOMAIN_ATTR_WINDOWS , +DOMAIN_ATTR_FSL_PAMU_STASH , +DOMAIN_ATTR_FSL_PAMU_ENABLE , +DOMAIN_ATTR_FSL_PAMUV1 ,DOMAIN_ATTR_MAX , };
Signature · 1 line
1.7.4.1
PATCH v14 3/3 iommu/fsl: Freescale PAMU driver and iommu implementation.
In reply to Varun SethiFollowing is a brief description of the PAMU hardware:
PAMU determines what action to take and whether to authorize the action on the basis of the memory address, a Logical IO Device Number (LIODN), and PAACT table (logically) indexed by LIODN and address. Hardware devices which need to access memory must provide an LIODN in addition to the memory address.
Peripheral Access Authorization and Control Tables (PAACTs) are the primary data structures used by PAMU. A PAACT is a table of peripheral access authorization and control entries (PAACE).Each PAACE defines the range of I/O bus address space that is accessible by the LIOD and the associated access capabilities.
There are two types of PAACTs: primary PAACT (PPAACT) and secondary PAACT (SPAACT).A given physical I/O device may be able to act as one or more independent logical I/O devices (LIODs). Each such logical I/O device is assigned an identifier called logical I/O device number (LIODN). A LIODN is allocated a contiguous portion of the I/O bus address space called the DSA window for performing DSA operations. The DSA window may optionally be divided into multiple sub-windows, each of which may be used to map to a region in system storage space. The first sub-window is referred to as the primary sub-window and the remaining are called secondary sub-windows.
This patch provides the PAMU driver (fsl_pamu.c) and the corresponding IOMMU API implementation (fsl_pamu_domain.c). The PAMU hardware driver (fsl_pamu.c) has been derived from the work done by Ashish Kalra and Timur Tabi.
---
changes in v14:
- Use updated PMAU specific attributes.
changes in v13:
- Use the new header drivers/iommu/pci.h
- fix geometry configured check.
changes in v12:
- Use is_power_of_2 for checking alignement.
- Check for multifucntion PCI device ACS flags for determining device groups.
- Fix get_stash_id function.
- Don't crash in case of access violations, disable the LIODN.
- Don't use list_empty while traversing list using list for each entry.
- Move stash structure and ids to PAMU header files.
- Fix geometry size calculation.
changes in v11:
- changed iova to dma_addr_t in iova_to_phys API.
changes in v10:
- Support for new guts compatibe string for T4 & B4 devices.
- Modified comment about port ID and mentioned the errata number.
- Fixed the issue where data pointer was not freed in case of a an error.
- Pass data pointer while freeing irq.
- Whle initializing the SPAACE entry clear the valid bit.
changes in v9:
- Merged and createad a single function to delete
a device from domain list.
- Refactored the add_device API code.
- Renamed the paace and spaace init fucntions.
- Renamed functions for mapping windows and subwindows.
- Changed the MAX LIODN value to MAX value u-boot can
program.
- Hard coded maximum number of subwindows.
changes in v8:
- implemented the new API for window based IOMMUs.
changes in v7:
- Set max_subwidows in the geometry attribute.
- Add checking for maximum supported LIODN value.
- Use upper_32_bits and lower_32_bits macros while
intializing PAMU data structures.
changes in v6:
- Simplified complex conditional statements.
- Fixed indentation issues.
- Added comments for IOMMU API implementation.
changes in v5:
- Addressed comments from Timur.
changes in v4:
- Addressed comments from Timur and Scott.
changes in v3:
- Addressed comments by Kumar Gala
- dynamic fspi allocation
- fixed alignment check in map and unmap
arch/powerpc/sysdev/fsl_pci.h | 5 + drivers/iommu/Kconfig | 10 + drivers/iommu/Makefile | 1 + drivers/iommu/fsl_pamu.c | 1309 +++++++++++++++++++++++++++++++++++++++ drivers/iommu/fsl_pamu.h | 410 ++++++++++++ drivers/iommu/fsl_pamu_domain.c | 1142 ++++++++++++++++++++++++++++++++++ drivers/iommu/fsl_pamu_domain.h | 85 +++ 7 files changed, 2962 insertions(+), 0 deletions(-) create mode 100644 drivers/iommu/fsl_pamu.c create mode 100644 drivers/iommu/fsl_pamu.h create mode 100644 drivers/iommu/fsl_pamu_domain.c create mode 100644 drivers/iommu/fsl_pamu_domain.h
arch/powerpc/sysdev/fsl_pci.h +5 -0
@@ -14,6 +14,11 @@#ifndef __POWERPC_FSL_PCI_H#define __POWERPC_FSL_PCI_H + +/* FSL PCI controller BRR1 register */ +#define PCI_FSL_BRR1 0xbf8 +#define PCI_FSL_BRR1_VER 0xffff +#define PCIE_LTSSM 0x0404/* PCIE Link Training and Status */ #define PCIE_LTSSM_L0 0x16/* L0 state */ #define PCIE_IP_REV_2_2 0x02080202/* PCIE IP block version Rev2.2 */
drivers/iommu/Kconfig +10 -0
@@ -17,6 +17,16 @@ config OF_IOMMU def_bool y depends on OF +config FSL_PAMU + bool "Freescale IOMMU support" + depends on PPC_E500MC + select IOMMU_API + select GENERIC_ALLOCATOR + help + Freescale PAMU support. PAMU is the IOMMU present on Freescale QorIQ platforms. + PAMU can authorize memory access, remap the memory address, and remap I/O + transaction types. + # MSM IOMMU support config MSM_IOMMU bool "MSM IOMMU Support"
drivers/iommu/Makefile +1 -0
@@ -15,3 +15,4 @@ obj-$(CONFIG_TEGRA_IOMMU_SMMU) += tegra-smmu.o obj-$(CONFIG_EXYNOS_IOMMU) += exynos-iommu.o obj-$(CONFIG_SHMOBILE_IOMMU) += shmobile-iommu.o obj-$(CONFIG_SHMOBILE_IPMMU) += shmobile-ipmmu.o +obj-$(CONFIG_FSL_PAMU) += fsl_pamu.o fsl_pamu_domain.o
drivers/iommu/fsl_pamu.c new file +1309 -0
1,309 lines not on this page · raw message
drivers/iommu/fsl_pamu.h new file +410 -0
410 lines not on this page · raw message
drivers/iommu/fsl_pamu_domain.c new file +1142 -0
1,142 lines not on this page · raw message
drivers/iommu/fsl_pamu_domain.h new file +85 -0
85 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Joerg Roedel
maintainerdrivers/iommu/pci.h line 20
Quoted 2 lines · Varun Sethi
drivers/iommu/pci.h new file +2
-0+#ifndef __PCI_H +#define __PCI_H
Using __PCI_H is not a wise choice, it has certainly a high risk of a collision. Anyway, I changed it to __IOMMU_PCI_H and applied the patch.
Joerg
Thanks.
Quoted 25 lines
-----Original Message-----
From: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org [mailto:iommu- bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org] On Behalf Of Joerg Roedel
Sent: Tuesday, April 23, 2013 6:32 PM
To: Sethi Varun-B16395
Cc: [email protected]; [email protected]; Yoder Stuart- B08248; [email protected]; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; Wood Scott-B07421; linuxppc-dev-uLR06cmDAlY/[email protected]
Subject: Re: [PATCH 1/3 v2] iommu: Moveswap_pci_reffunction topci.h.drivers/iommu/pci.h line 20
Quoted 2 lines · Varun Sethi
drivers/iommu/pci.h new file +2
-0+#ifndef __PCI_H +#define __PCI_HUsing
__PCI_His not a wise choice, it has certainly a high risk of a collision. Anyway, I changed it to__IOMMU_PCI_Hand applied the patch.Joerg
_______________________________________________
iommu mailing list iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Joerg Roedel
maintainerRe: [PATCH 2/3 v14] iommu/fsl: Add additional iommu attributes required by the PAMU driver.
In reply to Varun SethiQuoted 18 lines · Varun Sethi
Added the following domain attributes for the FSL PAMU driver:
1. Added new iommu stash attribute, which allows setting of the LIODN specific stash id parameter through IOMMU API.
2. Added an attribute for enabling/disabling DMA to a particular memory window.
3. Added domain attribute to check for PAMUV1 specific constraints.Signed-off-by Varun Sethi <[email protected]>---
v14 changes:
- Add FSL prefix to PAMU attributes.
v13 changes:
- created a new fileinclude/linux/fsl_pamu_stash.hfor stash attributes.
v12 changes:
- Moved PAMU specifc stash ids and structures to PAMU header file.
- no change in v11.
- no change in v10.
Quoted 1 line
include/linux/fsl_pamu_stash.h | 39 +++++++++++++++++++++++++++++++++++++++
Isn't asm/ for your architecture a better place for that header?
Joerg
RE: [PATCH 2/3 v14] iommu/fsl: Add additional iommu attributes required by the PAMU driver.
Quoted 32 lines
-----Original Message-----
From: Joerg Roedel [mailto:[email protected]]
Sent: Tuesday, April 23, 2013 7:09 PM
To: Sethi Varun-B16395
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linuxppc-dev-uLR06cmDAlY/[email protected]; [email protected]; [email protected]; [email protected]; Yoder Stuart-B08248; Wood Scott-B07421
Subject: Re: [PATCH 2/3 v14] iommu/fsl: Add additional iommu attributes
required by the PAMU driver.Quoted 18 lines · Varun Sethi
Added the following domain attributes for the FSL PAMU driver:
1. Added new iommu stash attribute, which allows setting of the LIODN specific stash id parameter through IOMMU API.
2. Added an attribute for enabling/disabling DMA to a particular memory window.
3. Added domain attribute to check for PAMUV1 specific constraints.Signed-off-by Varun Sethi <[email protected]>---
v14 changes:
- Add FSL prefix to PAMU attributes.
v13 changes:
- created a new fileinclude/linux/fsl_pamu_stash.hfor stash attributes.
v12 changes:
- Moved PAMU specifc stash ids and structures to PAMU header file.
- no change in v11.
- no change in v10.Quoted 1 line
include/linux/fsl_pamu_stash.h | 39
Quoted 4 lines
+++++++++++++++++++++++++++++++++++++++
Isn't asm/ for your architecture a better place for that header?
I think it's fine to have the header under linux, actually I also the intel-iommu header under linux.
-Varun
RE: [PATCH 2/3 v14] iommu/fsl: Add additional iommu attributes required by the PAMU driver.
In reply to Joerg RoedelQuoted 31 lines
-----Original Message-----
From: Joerg Roedel [mailto:[email protected]]
Sent: Tuesday, April 23, 2013 8:39 AM
To: Sethi Varun-B16395
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linuxppc-dev-uLR06cmDAlY/[email protected]; [email protected]; [email protected]; [email protected]; Yoder Stuart-B08248; Wood Scott-B07421
Subject: Re: [PATCH 2/3 v14] iommu/fsl: Add additional iommu attributes required by the PAMU driver.Quoted 18 lines · Varun Sethi
Added the following domain attributes for the FSL PAMU driver:
1. Added new iommu stash attribute, which allows setting of the LIODN specific stash id parameter through IOMMU API.
2. Added an attribute for enabling/disabling DMA to a particular memory window.
3. Added domain attribute to check for PAMUV1 specific constraints.Signed-off-by Varun Sethi <[email protected]>---
v14 changes:
- Add FSL prefix to PAMU attributes.
v13 changes:
- created a new fileinclude/linux/fsl_pamu_stash.hfor stash attributes.
v12 changes:
- Moved PAMU specifc stash ids and structures to PAMU header file.
- no change in v11.
- no change in v10.Quoted 1 line
include/linux/fsl_pamu_stash.h | 39 +++++++++++++++++++++++++++++++++++++++
Quoted 1 line
Isn't asm/ for your architecture a better place for that header?
The PAMU isn't strictly tied to Power architecture, although that is where it is implemented now. It could be implemented on ARM for example.
Stuart
Joerg Roedel
maintainerRe: [PATCH 2/3 v14] iommu/fsl: Add additional iommu attributes required by the PAMU driver.
In reply to Sethi Varun-B16395Quoted 2 lines · On Tue, Apr 23, 2013 at 02:10:25PM +0000, Sethi Varun-B16395 wrote:
I think it's fine to have the header under linux, actually I also the intel-iommu header under linux.
Yes, the difference is that VT-d runs on x86 and on ia64. So there is no single arch where the header could be placed. The amd-iommu.h file on the other hand is x86 only and should also be moved to asm/, as I just found out :)
And as long as PAMU is only needed on a single architecture the header should also be arch-specific. If that changes someday the header can be moved to a generic place.
Joerg
RE: [PATCH 2/3 v14] iommu/fsl: Add additional iommu attributes required by the PAMU driver.
Quoted 16 lines
-----Original Message-----
From: Joerg Roedel [mailto:[email protected]]
Sent: Wednesday, April 24, 2013 4:21 PM
To: Sethi Varun-B16395
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; linuxppc-dev-uLR06cmDAlY/[email protected]; [email protected]; [email protected]; [email protected]; Yoder Stuart-B08248; Wood Scott-B07421
Subject: Re: [PATCH 2/3 v14] iommu/fsl: Add additional iommu attributes
required by the PAMU driver.Quoted 2 lines · On Tue, Apr 23, 2013 at 02:10:25PM +0000, Sethi Varun-B16395 wrote:
I think it's fine to have the header under linux, actually I also the intel-iommu header under linux.
Quoted 9 lines
Yes, the difference is that VT-d runs on x86 and on ia64. So there is no single arch where the header could be placed. The
amd-iommu.hfile on the other hand is x86 only and should also be moved to asm/, as I just found out :)And as long as PAMU is only needed on a single architecture the header should also be arch-specific. If that changes someday the header can be moved to a generic place.
Ok, I will post the next version of the patch set.
-Varun