[Xen-devel] [PATCH] Test code for SMMUv3 setup

2017-09-29 Thread Sameer Goel
DO NOT MERGE

This patch contains test code for programming stream tables for PCIe devices
seen by DOM0. This change can be used on top of [1].

[1] [RFC v2 0/7] SMMUv3 driver and the supporting framework
---
 xen/arch/arm/physdev.c| 41 +--
 xen/drivers/passthrough/arm/smmu-v3.c | 36 ++
 xen/include/asm-arm/device.h  |  5 +++--
 3 files changed, 78 insertions(+), 4 deletions(-)

diff --git a/xen/arch/arm/physdev.c b/xen/arch/arm/physdev.c
index e91355f..18a5786 100644
--- a/xen/arch/arm/physdev.c
+++ b/xen/arch/arm/physdev.c
@@ -8,13 +8,50 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 
+extern void acpi_setup_smmu_for_test(struct domain *d, u16 seg, u8 bus, u8 
devfn);
+
 int do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
-gdprintk(XENLOG_DEBUG, "PHYSDEVOP cmd=%d: not implemented\n", cmd);
-return -ENOSYS;
+int ret = 0;
+
+switch (cmd )
+{
+case PHYSDEVOP_pci_device_add: {
+struct physdev_pci_device_add add;
+struct pci_dev_info pdev_info;
+
+ret = -EFAULT;
+if ( copy_from_guest(, arg, 1) != 0 )
+break;
+
+pdev_info.is_extfn = !!(add.flags & XEN_PCI_DEV_EXTFN);
+if ( add.flags & XEN_PCI_DEV_VIRTFN )
+{
+pdev_info.is_virtfn = 1;
+pdev_info.physfn.bus = add.physfn.bus;
+pdev_info.physfn.devfn = add.physfn.devfn;
+}
+else
+pdev_info.is_virtfn = 0;
+
+gdprintk(XENLOG_DEBUG, "PHYSDEVOP cmd=%d: domain:%d seg:%d bus:%d \
+devfn:%d\n", cmd, hardware_domain->domain_id, add.seg, \
+   add.bus, add.devfn);
+acpi_setup_smmu_for_test(hardware_domain, add.seg, add.bus, add.devfn);
+break;
+}
+
+default:
+gdprintk(XENLOG_DEBUG, "PHYSDEVOP cmd=%d: not implemented\n", cmd);
+ret = -ENOSYS;
+   break;
+}
+
+return ret;
 }
 
 /*
diff --git a/xen/drivers/passthrough/arm/smmu-v3.c 
b/xen/drivers/passthrough/arm/smmu-v3.c
index 0bbf0cd..f5b5d77 100644
--- a/xen/drivers/passthrough/arm/smmu-v3.c
+++ b/xen/drivers/passthrough/arm/smmu-v3.c
@@ -46,6 +46,7 @@
 #include 
 #include 
 #include 
+#include 
 
 typedef paddr_t phys_addr_t;
 typedef paddr_t dma_addr_t;
@@ -3410,3 +3411,38 @@ ACPI_DEVICE_START(asmmuv3, "ARM SMMU V3", DEVICE_IOMMU)
 ACPI_DEVICE_END
 
 #endif
+
+void acpi_setup_smmu_for_test(struct domain *d, u16 seg, u8 bus, u8 devfn)
+{
+   struct pci_dev pci_device;
+   struct device *device;
+   struct arm_smmu_device *smmu;
+
+   arm_smmu_iommu_domain_init(d);
+   memset(_device, 0, sizeof(struct pci_dev));
+   device = &(pci_device.dev);
+
+   pci_device.domain = d;
+   *(u16*) _device.seg = seg;
+   *(u8*) _device.bus = bus;
+   *(u8*) _device.devfn = devfn;
+
+   pci_device.dev.type = DEV_PCI;
+   printk("%d %d %d \n",pci_device.seg,pci_device.bus,pci_device.devfn);
+
+   iort_iommu_configure(device);
+
+   if (device->iommu_fwspec) {
+   printk("num-ids: %d\n", device->iommu_fwspec->num_ids);
+   printk("fwnode: 0x%p\n", device->iommu_fwspec->iommu_fwnode);
+   smmu = arm_smmu_get_by_fwnode( 
device->iommu_fwspec->iommu_fwnode);
+   printk("smmu-device-node: 0x%p\n",smmu);
+   arm_smmu_assign_dev(d, 0, device, 0);
+   } else {
+   printk("Failed to initialize fw_spec\n");
+   }
+
+
+   printk("%s called %d\n", __func__, __LINE__);
+}
+
diff --git a/xen/include/asm-arm/device.h b/xen/include/asm-arm/device.h
index 4eef9ce..57c114b 100644
--- a/xen/include/asm-arm/device.h
+++ b/xen/include/asm-arm/device.h
@@ -8,6 +8,7 @@ enum device_type
 {
 DEV_DT,
 DEV_ACPI,
+DEV_PCI,
 };
 
 struct dev_archdata {
@@ -32,8 +33,8 @@ typedef struct device device_t;
 #include 
 
 /* TODO: Correctly implement dev_is_pci when PCI is supported on ARM */
-#define dev_is_pci(dev) ((void)(dev), 0)
-#define dev_is_dt(dev)  ((dev->type == DEV_DT)
+#define dev_is_pci(dev) (dev->type == DEV_PCI)
+#define dev_is_dt(dev)  (dev->type == DEV_DT)
 
 enum device_class
 {
-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. 
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux 
Foundation Collaborative Project.


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [RFC v2 3/7] xen/passthrough/arm: Introduce iommu_fwspec

2017-09-20 Thread Sameer Goel
Introduce a common structure to hold the fw (ACPI or DT) defined
configuration for SMMU hw. The current use case is for arm SMMUs. So,
making this architecture specific.

Based on Linux kernel commit 57f98d2f61e1: iommu: Introduce iommu_fwspec
Signed-off-by: Sameer Goel <sg...@codeaurora.org>
---
 xen/drivers/passthrough/arm/iommu.c | 66 +
 xen/include/asm-arm/device.h|  1 +
 xen/include/xen/iommu.h | 29 
 3 files changed, 96 insertions(+)

diff --git a/xen/drivers/passthrough/arm/iommu.c 
b/xen/drivers/passthrough/arm/iommu.c
index 95b1abb..41c6497 100644
--- a/xen/drivers/passthrough/arm/iommu.c
+++ b/xen/drivers/passthrough/arm/iommu.c
@@ -73,3 +73,69 @@ int arch_iommu_populate_page_table(struct domain *d)
 /* The IOMMU shares the p2m with the CPU */
 return -ENOSYS;
 }
+
+const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode)
+{
+return iommu_get_ops();
+}
+
+int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode,
+const struct iommu_ops *ops)
+{
+struct iommu_fwspec *fwspec = dev->iommu_fwspec;
+
+if ( fwspec )
+return ops == fwspec->ops ? 0 : -EINVAL;
+
+fwspec = _xzalloc(sizeof(struct iommu_fwspec), sizeof(void *));
+if ( !fwspec )
+return -ENOMEM;
+
+fwspec->iommu_fwnode = iommu_fwnode;
+fwspec->ops = ops;
+dev->iommu_fwspec = fwspec;
+
+return 0;
+}
+
+void iommu_fwspec_free(struct device *dev)
+{
+struct iommu_fwspec *fwspec = dev->iommu_fwspec;
+
+if ( fwspec )
+{
+xfree(fwspec);
+dev->iommu_fwspec = NULL;
+}
+}
+
+int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids)
+{
+struct iommu_fwspec *fwspec = dev->iommu_fwspec;
+struct iommu_fwspec *fwspec_n = NULL;
+size_t size, size_n;
+int i;
+
+if ( !fwspec )
+return -EINVAL;
+
+size = offsetof(struct iommu_fwspec, ids[fwspec->num_ids]);
+size_n = offsetof(struct iommu_fwspec, ids[fwspec->num_ids + num_ids]);
+if ( size_n > size )
+{
+fwspec_n = _xzalloc(size_n, sizeof(void *));
+if ( !fwspec_n )
+return -ENOMEM;
+
+memcpy(fwspec_n, fwspec, size);
+xfree(fwspec);
+}
+
+for (i = 0; i < num_ids; i++)
+fwspec_n->ids[fwspec_n->num_ids + i] = ids[i];
+
+fwspec_n->num_ids += num_ids;
+dev->iommu_fwspec = fwspec_n;
+
+return 0;
+}
diff --git a/xen/include/asm-arm/device.h b/xen/include/asm-arm/device.h
index 78c38fe..5027c87 100644
--- a/xen/include/asm-arm/device.h
+++ b/xen/include/asm-arm/device.h
@@ -21,6 +21,7 @@ struct device
 struct dt_device_node *of_node; /* Used by drivers imported from Linux */
 #endif
 struct fwnode_handle *fwnode; /*fw device node identifier */
+struct iommu_fwspec *iommu_fwspec;
 struct dev_archdata archdata;
 };
 
diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h
index 0dac4f3..34e8d68 100644
--- a/xen/include/xen/iommu.h
+++ b/xen/include/xen/iommu.h
@@ -208,4 +208,33 @@ DECLARE_PER_CPU(bool_t, iommu_dont_flush_iotlb);
 extern struct spinlock iommu_pt_cleanup_lock;
 extern struct page_list_head iommu_pt_cleanup_list;
 
+/**
+ * Following block was ported from Linux to help with the implementation of
+ * arm64 iommu devices. Hence the architecture specific compile
+ */
+
+#if defined(CONFIG_ARM)
+/**
+ * struct iommu_fwspec - per-device IOMMU instance data
+ * @ops: ops for this device's IOMMU
+ * @iommu_fwnode: firmware handle for this device's IOMMU
+ * @iommu_priv: IOMMU driver private data for this device
+ * @num_ids: number of associated device IDs
+ * @ids: IDs which this device may present to the IOMMU
+ */
+struct iommu_fwspec {
+const struct iommu_ops *ops;
+struct fwnode_handle   *iommu_fwnode;
+void   *iommu_priv;
+unsigned int   num_ids;
+u32ids[1];
+};
+
+int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode,
+ const struct iommu_ops *ops);
+void iommu_fwspec_free(struct device *dev);
+int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids);
+const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode);
+
+#endif
 #endif /* _IOMMU_H_ */
-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. 
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux 
Foundation Collaborative Project.


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [RFC v2 6/7] Add verbatim copy of arm-smmu-v3.c from Linux

2017-09-20 Thread Sameer Goel
Based on commit bdf95923086fb359ccb44c815724c3ace1611c90

This is a verbatim snapshot of arm-smmu-v3.c from Linux kernel source
code.

No Xen code has been added and the file is not built.

Signed-off-by: Sameer Goel <sg...@codeaurora.org>
---
 xen/drivers/passthrough/arm/smmu-v3.c | 2791 +
 1 file changed, 2791 insertions(+)
 create mode 100644 xen/drivers/passthrough/arm/smmu-v3.c

diff --git a/xen/drivers/passthrough/arm/smmu-v3.c 
b/xen/drivers/passthrough/arm/smmu-v3.c
new file mode 100644
index 000..380969a
--- /dev/null
+++ b/xen/drivers/passthrough/arm/smmu-v3.c
@@ -0,0 +1,2791 @@
+/*
+ * IOMMU API for ARM architected SMMUv3 implementations.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2015 ARM Limited
+ *
+ * Author: Will Deacon <will.dea...@arm.com>
+ *
+ * This driver is powered by bad coffee and bombay mix.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "io-pgtable.h"
+
+/* MMIO registers */
+#define ARM_SMMU_IDR0  0x0
+#define IDR0_ST_LVL_SHIFT  27
+#define IDR0_ST_LVL_MASK   0x3
+#define IDR0_ST_LVL_2LVL   (1 << IDR0_ST_LVL_SHIFT)
+#define IDR0_STALL_MODEL_SHIFT 24
+#define IDR0_STALL_MODEL_MASK  0x3
+#define IDR0_STALL_MODEL_STALL (0 << IDR0_STALL_MODEL_SHIFT)
+#define IDR0_STALL_MODEL_FORCE (2 << IDR0_STALL_MODEL_SHIFT)
+#define IDR0_TTENDIAN_SHIFT21
+#define IDR0_TTENDIAN_MASK 0x3
+#define IDR0_TTENDIAN_LE   (2 << IDR0_TTENDIAN_SHIFT)
+#define IDR0_TTENDIAN_BE   (3 << IDR0_TTENDIAN_SHIFT)
+#define IDR0_TTENDIAN_MIXED(0 << IDR0_TTENDIAN_SHIFT)
+#define IDR0_CD2L  (1 << 19)
+#define IDR0_VMID16(1 << 18)
+#define IDR0_PRI   (1 << 16)
+#define IDR0_SEV   (1 << 14)
+#define IDR0_MSI   (1 << 13)
+#define IDR0_ASID16(1 << 12)
+#define IDR0_ATS   (1 << 10)
+#define IDR0_HYP   (1 << 9)
+#define IDR0_COHACC(1 << 4)
+#define IDR0_TTF_SHIFT 2
+#define IDR0_TTF_MASK  0x3
+#define IDR0_TTF_AARCH64   (2 << IDR0_TTF_SHIFT)
+#define IDR0_TTF_AARCH32_64(3 << IDR0_TTF_SHIFT)
+#define IDR0_S1P   (1 << 1)
+#define IDR0_S2P   (1 << 0)
+
+#define ARM_SMMU_IDR1  0x4
+#define IDR1_TABLES_PRESET (1 << 30)
+#define IDR1_QUEUES_PRESET (1 << 29)
+#define IDR1_REL   (1 << 28)
+#define IDR1_CMDQ_SHIFT21
+#define IDR1_CMDQ_MASK 0x1f
+#define IDR1_EVTQ_SHIFT16
+#define IDR1_EVTQ_MASK 0x1f
+#define IDR1_PRIQ_SHIFT11
+#define IDR1_PRIQ_MASK 0x1f
+#define IDR1_SSID_SHIFT6
+#define IDR1_SSID_MASK 0x1f
+#define IDR1_SID_SHIFT 0
+#define IDR1_SID_MASK  0x3f
+
+#define ARM_SMMU_IDR5  0x14
+#define IDR5_STALL_MAX_SHIFT   16
+#define IDR5_STALL_MAX_MASK0x
+#define IDR5_GRAN64K   (1 << 6)
+#define IDR5_GRAN16K   (1 << 5)
+#define IDR5_GRAN4K(1 << 4)
+#define IDR5_OAS_SHIFT 0
+#define IDR5_OAS_MASK  0x7
+#define IDR5_OAS_32_BIT(0 << IDR5_OAS_SHIFT)
+#define IDR5_OAS_36_BIT(1 << IDR5_OAS_SHIFT)
+#define IDR5_OAS_40_BIT(2 << IDR5_OAS_SHIFT)
+#define IDR5_OAS_42_BIT(3 << IDR5_OAS_SHIFT)
+#define IDR5_OAS_44_BIT(4 << IDR5_OAS_SHIFT)
+#define IDR5_OAS_48_BIT(5 << IDR5_OAS_SHIFT)
+
+#define ARM_SMMU_CR0   0x20
+#define CR0_CMDQEN (1 << 3)
+#define CR0_EVTQEN (1 << 2)
+#define CR0_PR

[Xen-devel] [RFC v2 7/7] xen/iommu: smmu-v3: Add Xen specific code to enable the ported driver

2017-09-20 Thread Sameer Goel
This driver follows an approach similar to smmu driver. The intent here
is to reuse as much Linux code as possible.
- Glue code has been introduced to bridge the API calls.
- Called Linux functions from the Xen IOMMU function calls.
- Xen modifications are preceded by /*Xen: comment */

Signed-off-by: Sameer Goel <sg...@codeaurora.org>
---
 xen/drivers/passthrough/arm/Makefile  |   1 +
 xen/drivers/passthrough/arm/smmu-v3.c | 853 +-
 2 files changed, 738 insertions(+), 116 deletions(-)

diff --git a/xen/drivers/passthrough/arm/Makefile 
b/xen/drivers/passthrough/arm/Makefile
index f4cd26e..57a6da6 100644
--- a/xen/drivers/passthrough/arm/Makefile
+++ b/xen/drivers/passthrough/arm/Makefile
@@ -1,2 +1,3 @@
 obj-y += iommu.o
 obj-y += smmu.o
+obj-y += smmu-v3.o
diff --git a/xen/drivers/passthrough/arm/smmu-v3.c 
b/xen/drivers/passthrough/arm/smmu-v3.c
index 380969a..8f3b43d 100644
--- a/xen/drivers/passthrough/arm/smmu-v3.c
+++ b/xen/drivers/passthrough/arm/smmu-v3.c
@@ -18,28 +18,266 @@
  * Author: Will Deacon <will.dea...@arm.com>
  *
  * This driver is powered by bad coffee and bombay mix.
+ *
+ *
+ * Based on Linux drivers/iommu/arm-smmu-v3.c
+ * => commit bdf95923086fb359ccb44c815724c3ace1611c90
+ *
+ * Xen modifications:
+ * Sameer Goel <sg...@codeaurora.org>
+ * Copyright (C) 2017, The Linux Foundation, All rights reserved.
+ *
  */
 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-
-#include "io-pgtable.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+typedef paddr_t phys_addr_t;
+typedef paddr_t dma_addr_t;
+
+/* Alias to Xen device tree helpers */
+#define device_node dt_device_node
+#define of_phandle_args dt_phandle_args
+#define of_device_id dt_device_match
+#define of_match_node dt_match_node
+#define of_property_read_u32(np, pname, out) (!dt_property_read_u32(np, pname, 
out))
+#define of_property_read_bool dt_property_read_bool
+#define of_parse_phandle_with_args dt_parse_phandle_with_args
+#define mutex spinlock_t
+#define mutex_init spin_lock_init
+#define mutex_lock spin_lock
+#define mutex_unlock spin_unlock
+
+/* Xen: Helpers to get device MMIO and IRQs */
+struct resource {
+   u64 addr;
+   u64 size;
+   unsigned int type;
+};
+
+#define resource_size(res) ((res)->size)
+
+#define platform_device device
+
+#define IORESOURCE_MEM 0
+#define IORESOURCE_IRQ 1
+
+static struct resource *platform_get_resource(struct platform_device *pdev,
+ unsigned int type,
+ unsigned int num)
+{
+   /*
+* The resource is only used between 2 calls of platform_get_resource.
+* It's quite ugly but it's avoid to add too much code in the part
+* imported from Linux
+*/
+   static struct resource res;
+   struct acpi_iort_node *iort_node;
+   struct acpi_iort_smmu_v3 *node_smmu_data;
+   int ret = 0;
+
+   res.type = type;
+
+   switch (type) {
+   case IORESOURCE_MEM:
+   if (pdev->type == DEV_ACPI) {
+   ret = 1;
+   iort_node = pdev->acpi_node;
+   node_smmu_data =
+   (struct acpi_iort_smmu_v3 
*)iort_node->node_data;
+
+   if (node_smmu_data != NULL) {
+   res.addr = node_smmu_data->base_address;
+   res.size = SZ_128K;
+   ret = 0;
+   }
+   } else {
+   ret = dt_device_get_address(dev_to_dt(pdev), num,
+   , );
+   }
+
+   return ((ret) ? NULL : );
+
+   case IORESOURCE_IRQ:
+   ret = platform_get_irq(dev_to_dt(pdev), num);
+
+   if (ret < 0)
+   return NULL;
+
+   res.addr = ret;
+   res.size = 1;
+
+   return 
+
+   default:
+   return NULL;
+   }
+}
+
+static int platform_get_irq_byname(struct platform_device *pdev, const char 
*name)
+{
+   const struct dt_property *dtprop;
+   struct acpi_iort_node *iort_node;
+   struct acpi_iort_smmu_v3 *node_smmu_data;
+   int ret = 0;
+
+   if (pdev->type == DEV_ACPI) {
+   iort_node = pdev->acpi_node;
+   node_smmu_data = (struct acpi_iort_smmu_v3 
*)iort_node->node_data;
+
+   if (node_smmu_data != NULL) {
+   if (!strcmp(name, "eventq"))
+   ret = node_smmu_da

[Xen-devel] [RFC v2 4/7] ACPI: arm: Support for IORT

2017-09-20 Thread Sameer Goel
Verbatim files from Linux kernel.
iort.c: commit d89cf2e41826: ACPI/IORT: Fix the indentation in
iort_scan_node()
acpi_iort.h: commit 18b709beb503:ACPI/IORT: Make dma masks set-up IORT
specific

Signed-off-by: Sameer Goel <sg...@codeaurora.org>
---
 xen/drivers/acpi/arm/iort.c  | 961 +++
 xen/include/acpi/acpi_iort.h |  58 +++
 2 files changed, 1019 insertions(+)
 create mode 100644 xen/drivers/acpi/arm/iort.c
 create mode 100644 xen/include/acpi/acpi_iort.h

diff --git a/xen/drivers/acpi/arm/iort.c b/xen/drivers/acpi/arm/iort.c
new file mode 100644
index 000..2e368a6
--- /dev/null
+++ b/xen/drivers/acpi/arm/iort.c
@@ -0,0 +1,961 @@
+/*
+ * Copyright (C) 2016, Semihalf
+ * Author: Tomasz Nowicki <t...@semihalf.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * This file implements early detection/parsing of I/O mapping
+ * reported to OS through firmware via I/O Remapping Table (IORT)
+ * IORT document number: ARM DEN 0049A
+ */
+
+#define pr_fmt(fmt)"ACPI: IORT: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define IORT_TYPE_MASK(type)   (1 << (type))
+#define IORT_MSI_TYPE  (1 << ACPI_IORT_NODE_ITS_GROUP)
+#define IORT_IOMMU_TYPE((1 << ACPI_IORT_NODE_SMMU) |   \
+   (1 << ACPI_IORT_NODE_SMMU_V3))
+
+struct iort_its_msi_chip {
+   struct list_headlist;
+   struct fwnode_handle*fw_node;
+   u32 translation_id;
+};
+
+struct iort_fwnode {
+   struct list_head list;
+   struct acpi_iort_node *iort_node;
+   struct fwnode_handle *fwnode;
+};
+static LIST_HEAD(iort_fwnode_list);
+static DEFINE_SPINLOCK(iort_fwnode_lock);
+
+/**
+ * iort_set_fwnode() - Create iort_fwnode and use it to register
+ *iommu data in the iort_fwnode_list
+ *
+ * @node: IORT table node associated with the IOMMU
+ * @fwnode: fwnode associated with the IORT node
+ *
+ * Returns: 0 on success
+ *  <0 on failure
+ */
+static inline int iort_set_fwnode(struct acpi_iort_node *iort_node,
+ struct fwnode_handle *fwnode)
+{
+   struct iort_fwnode *np;
+
+   np = kzalloc(sizeof(struct iort_fwnode), GFP_ATOMIC);
+
+   if (WARN_ON(!np))
+   return -ENOMEM;
+
+   INIT_LIST_HEAD(>list);
+   np->iort_node = iort_node;
+   np->fwnode = fwnode;
+
+   spin_lock(_fwnode_lock);
+   list_add_tail(>list, _fwnode_list);
+   spin_unlock(_fwnode_lock);
+
+   return 0;
+}
+
+/**
+ * iort_get_fwnode() - Retrieve fwnode associated with an IORT node
+ *
+ * @node: IORT table node to be looked-up
+ *
+ * Returns: fwnode_handle pointer on success, NULL on failure
+ */
+static inline
+struct fwnode_handle *iort_get_fwnode(struct acpi_iort_node *node)
+{
+   struct iort_fwnode *curr;
+   struct fwnode_handle *fwnode = NULL;
+
+   spin_lock(_fwnode_lock);
+   list_for_each_entry(curr, _fwnode_list, list) {
+   if (curr->iort_node == node) {
+   fwnode = curr->fwnode;
+   break;
+   }
+   }
+   spin_unlock(_fwnode_lock);
+
+   return fwnode;
+}
+
+/**
+ * iort_delete_fwnode() - Delete fwnode associated with an IORT node
+ *
+ * @node: IORT table node associated with fwnode to delete
+ */
+static inline void iort_delete_fwnode(struct acpi_iort_node *node)
+{
+   struct iort_fwnode *curr, *tmp;
+
+   spin_lock(_fwnode_lock);
+   list_for_each_entry_safe(curr, tmp, _fwnode_list, list) {
+   if (curr->iort_node == node) {
+   list_del(>list);
+   kfree(curr);
+   break;
+   }
+   }
+   spin_unlock(_fwnode_lock);
+}
+
+typedef acpi_status (*iort_find_node_callback)
+   (struct acpi_iort_node *node, void *context);
+
+/* Root pointer to the mapped IORT table */
+static struct acpi_table_header *iort_table;
+
+static LIST_HEAD(iort_msi_chip_list);
+static DEFINE_SPINLOCK(iort_msi_chip_lock);
+
+/**
+ * iort_register_domain_token() - register domain token and related ITS ID
+ * to the list from where we can get it back later on.
+ * @trans_id: ITS ID.
+ * @fw_node: Domain token.
+ *
+ * Returns: 0 on success, -ENOMEM if no memory when allocating list element
+ */
+int iort_register_domain_token(int trans_id, struct fwnode_handle *fw_node)
+{
+   struct iort_its_msi_chip *its_msi

[Xen-devel] [RFC v2 1/7] passthrough/arm: Modify SMMU driver to use generic device definition

2017-09-20 Thread Sameer Goel
Modify the SMMU code to use generic device instead of dt_device_node for
functions that can be used for ACPI based systems too.

Signed-off-by: Sameer Goel <sg...@codeaurora.org>
---
 xen/drivers/passthrough/arm/smmu.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/xen/drivers/passthrough/arm/smmu.c 
b/xen/drivers/passthrough/arm/smmu.c
index 74c09b0..362d578 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -76,7 +76,7 @@ struct resource
 
 #define resource_size(res) (res)->size;
 
-#define platform_device dt_device_node
+#define platform_device device
 
 #define IORESOURCE_MEM 0
 #define IORESOURCE_IRQ 1
@@ -97,12 +97,12 @@ static struct resource *platform_get_resource(struct 
platform_device *pdev,
 
switch (type) {
case IORESOURCE_MEM:
-   ret = dt_device_get_address(pdev, num, , );
+   ret = dt_device_get_address(dev_to_dt(pdev), num, , 
);
 
return ((ret) ? NULL : );
 
case IORESOURCE_IRQ:
-   ret = platform_get_irq(pdev, num);
+   ret = platform_get_irq(dev_to_dt(pdev), num);
if (ret < 0)
return NULL;
 
@@ -2285,7 +2285,7 @@ static int arm_smmu_device_dt_probe(struct 
platform_device *pdev)
const struct of_device_id *of_id;
struct resource *res;
struct arm_smmu_device *smmu;
-   struct device *dev = >dev;
+   struct device *dev = pdev;
struct rb_node *node;
struct of_phandle_args masterspec;
int num_irqs, i, err;
@@ -2338,7 +2338,7 @@ static int arm_smmu_device_dt_probe(struct 
platform_device *pdev)
}
 
for (i = 0; i < num_irqs; ++i) {
-   int irq = platform_get_irq(pdev, i);
+   int irq = platform_get_irq(dev_to_dt(pdev), i);
 
if (irq < 0) {
dev_err(dev, "failed to get irq index %d\n", i);
@@ -2819,7 +2819,7 @@ static __init int arm_smmu_dt_init(struct dt_device_node 
*dev,
 */
dt_device_set_used_by(dev, DOMID_XEN);
 
-   rc = arm_smmu_device_dt_probe(dev);
+   rc = arm_smmu_device_dt_probe(dt_to_dev(dev));
if (rc)
return rc;
 
-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. 
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux 
Foundation Collaborative Project.


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [RFC v2 5/7] acpi:arm64: Add support for parsing IORT table

2017-09-20 Thread Sameer Goel
Add support for parsing IORT table to initialize SMMU devices.
* The code for creating an SMMU device has been modified, so that the SMMU
device can be initialized.
* The NAMED NODE code has been commented out as this will need DOM0 kernel
support.
* ITS code has been included but it has not been tested.

Signed-off-by: Sameer Goel <sg...@codeaurora.org>
---
 xen/arch/arm/setup.c   |   3 +
 xen/drivers/acpi/Makefile  |   1 +
 xen/drivers/acpi/arm/Makefile  |   1 +
 xen/drivers/acpi/arm/iort.c| 173 +
 xen/drivers/passthrough/arm/smmu.c |   1 +
 xen/include/acpi/acpi_iort.h   |  17 ++--
 xen/include/asm-arm/device.h   |   2 +
 xen/include/xen/acpi.h |  21 +
 xen/include/xen/pci.h  |   8 ++
 9 files changed, 146 insertions(+), 81 deletions(-)
 create mode 100644 xen/drivers/acpi/arm/Makefile

diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index 92f173b..4ba09b2 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -49,6 +49,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct bootinfo __initdata bootinfo;
 
@@ -796,6 +797,8 @@ void __init start_xen(unsigned long boot_phys_offset,
 
 tasklet_subsys_init();
 
+/* Parse the ACPI iort data */
+acpi_iort_init();
 
 xsm_dt_init();
 
diff --git a/xen/drivers/acpi/Makefile b/xen/drivers/acpi/Makefile
index 444b11d..e7ffd82 100644
--- a/xen/drivers/acpi/Makefile
+++ b/xen/drivers/acpi/Makefile
@@ -1,5 +1,6 @@
 subdir-y += tables
 subdir-y += utilities
+subdir-$(CONFIG_ARM) += arm
 subdir-$(CONFIG_X86) += apei
 
 obj-bin-y += tables.init.o
diff --git a/xen/drivers/acpi/arm/Makefile b/xen/drivers/acpi/arm/Makefile
new file mode 100644
index 000..7c039bb
--- /dev/null
+++ b/xen/drivers/acpi/arm/Makefile
@@ -0,0 +1 @@
+obj-y += iort.o
diff --git a/xen/drivers/acpi/arm/iort.c b/xen/drivers/acpi/arm/iort.c
index 2e368a6..7f54062 100644
--- a/xen/drivers/acpi/arm/iort.c
+++ b/xen/drivers/acpi/arm/iort.c
@@ -14,17 +14,47 @@
  * This file implements early detection/parsing of I/O mapping
  * reported to OS through firmware via I/O Remapping Table (IORT)
  * IORT document number: ARM DEN 0049A
+ *
+ * Based on Linux drivers/acpi/arm64/iort.c
+ * => commit ca78d3173cff3503bcd15723b049757f75762d15
+ *
+ * Xen modification:
+ * Sameer Goel <sg...@codeaurora.org>
+ * Copyright (C) 2017, The Linux Foundation, All rights reserved.
+ *
  */
 
-#define pr_fmt(fmt)"ACPI: IORT: " fmt
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+/* Xen: Define compatibility functions */
+#define FW_BUG "[Firmware Bug]: "
+#define pr_err(fmt, ...) printk(XENLOG_ERR fmt, ## __VA_ARGS__)
+#define pr_warn(fmt, ...) printk(XENLOG_WARNING fmt, ## __VA_ARGS__)
+
+/* Alias to Xen allocation helpers */
+#define kfree xfree
+#define kmalloc(size, flags)_xmalloc(size, sizeof(void *))
+#define kzalloc(size, flags)_xzalloc(size, sizeof(void *))
+
+/* Redefine WARN macros */
+#undef WARN
+#undef WARN_ON
+#define WARN(condition, format...) ({  \
+   int __ret_warn_on = !!(condition);  \
+   if (unlikely(__ret_warn_on))\
+   printk(format); \
+   unlikely(__ret_warn_on);\
+})
+#define WARN_TAINT(cond, taint, format...) WARN(cond, format)
+#define WARN_ON(cond)  (!!cond)
 
 #define IORT_TYPE_MASK(type)   (1 << (type))
 #define IORT_MSI_TYPE  (1 << ACPI_IORT_NODE_ITS_GROUP)
@@ -256,6 +286,13 @@ static acpi_status iort_match_node_callback(struct 
acpi_iort_node *node,
acpi_status status;
 
if (node->type == ACPI_IORT_NODE_NAMED_COMPONENT) {
+   status = AE_NOT_IMPLEMENTED;
+/*
+ * We need the namespace object name from dsdt to match the iort node, this
+ * will need additions to the kernel xen bus notifiers.
+ * So, disabling the named node code till a proposal is approved.
+ */
+#if 0
struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL };
struct acpi_device *adev = to_acpi_device_node(dev->fwnode);
struct acpi_iort_named_component *ncomp;
@@ -275,11 +312,12 @@ static acpi_status iort_match_node_callback(struct 
acpi_iort_node *node,
status = !strcmp(ncomp->device_name, buf.pointer) ?
AE_OK : AE_NOT_FOUND;
acpi_os_free(buf.pointer);
+#endif
} else if (node->type == ACPI_IORT_NODE_PCI_ROOT_COMPLEX) {
struct acpi_iort_root_complex *pci_rc;
-   struct pci_bus *bus;
+   struct pci_dev *pci_dev;
 
-   bus 

[Xen-devel] [RFC v2 0/7] SMMUv3 driver and the supporting framework

2017-09-20 Thread Sameer Goel
This change incoporates most of the review comments from [1] and adds the
proposed SMMUv3 driver.

List of changes:
- Introduce the iommu_fwspec implementation - No change from the last RFC
- IORT port from linux. The differences are as under:
* Modified the code for creating the SMMU devices. This code also
  initializes the discoverd SMMU devices.
* MSI code is left as is, but this code is untested.
* IORT node data parsing is delegated to the driver. Looking for 
comments
  on enabling the code in IORT driver. This will need a standard resource
  object. (Direct port from Linux or a new define for Xen?)
* Assumptions on PCI IORT SMMU interaction. PCI assign device will call
  iort_iommu_configure to setup the streamids.Then it will call SMMU
  assign device with the right struct device argument.
- SMMUv3 port from Linux. The list of changes are as under:
* The Xen iommu_ops list is at parity with SMMUv2.
* There is generally no need for an IOMMU group, but have kept a dummy
  define for now.
* Have commented out the S1 translation code.
* MSI code is commented out.
* Page table ops are commented out as the driver shares the page tables
  with the cpu.
* The list of SMMU devices is maintained from the driver code.

Open questions:
- IORT regeneration for DOM0. I was hoping to get some update on [2].
- We also need a notification framework to get the Named node information from 
DSDT.
- Should we port over code for non-hsared page tables from the kernel or 
leverage [3].


[1] "[RFC 0/6] IORT support and introduce fwspec"
[2] "[Xen-devel] [RFC] [PATCH] arm-acpi: Hide SMMU from IORT for hardware 
domain"
[3] "Non-shared" IOMMU support on ARM"

Sameer Goel (7):
  passthrough/arm: Modify SMMU driver to use generic device definition
  arm64: Add definitions for fwnode_handle
  xen/passthrough/arm: Introduce iommu_fwspec
  ACPI: arm: Support for IORT
  acpi:arm64: Add support for parsing IORT table
  Add verbatim copy of arm-smmu-v3.c from Linux
  xen/iommu: smmu-v3: Add Xen specific code to enable the ported driver

 xen/arch/arm/setup.c  |3 +
 xen/drivers/acpi/Makefile |1 +
 xen/drivers/acpi/arm/Makefile |1 +
 xen/drivers/acpi/arm/iort.c   |  986 ++
 xen/drivers/passthrough/arm/Makefile  |1 +
 xen/drivers/passthrough/arm/iommu.c   |   66 +
 xen/drivers/passthrough/arm/smmu-v3.c | 3412 +
 xen/drivers/passthrough/arm/smmu.c|   13 +-
 xen/include/acpi/acpi_iort.h  |   61 +
 xen/include/asm-arm/device.h  |5 +
 xen/include/xen/acpi.h|   21 +
 xen/include/xen/fwnode.h  |   33 +
 xen/include/xen/iommu.h   |   29 +
 xen/include/xen/pci.h |8 +
 14 files changed, 4634 insertions(+), 6 deletions(-)
 create mode 100644 xen/drivers/acpi/arm/Makefile
 create mode 100644 xen/drivers/acpi/arm/iort.c
 create mode 100644 xen/drivers/passthrough/arm/smmu-v3.c
 create mode 100644 xen/include/acpi/acpi_iort.h
 create mode 100644 xen/include/xen/fwnode.h

-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. 
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux 
Foundation Collaborative Project.


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [RFC v2 2/7] arm64: Add definitions for fwnode_handle

2017-09-20 Thread Sameer Goel
This will be used as a device property to match the DMA capable devices
with the associated SMMU. The header file is a port from linux. The code
was changed to remove the types that were not needed for Xen.

Linux ChangeId:ce793486e23e: driver core / ACPI: Represent ACPI
companions using fwnode_handle

Signed-off-by: Sameer Goel <sg...@codeaurora.org>
---
 xen/include/asm-arm/device.h |  2 ++
 xen/include/xen/fwnode.h | 33 +
 2 files changed, 35 insertions(+)
 create mode 100644 xen/include/xen/fwnode.h

diff --git a/xen/include/asm-arm/device.h b/xen/include/asm-arm/device.h
index 6734ae8..78c38fe 100644
--- a/xen/include/asm-arm/device.h
+++ b/xen/include/asm-arm/device.h
@@ -2,6 +2,7 @@
 #define __ASM_ARM_DEVICE_H
 
 #include 
+#include 
 
 enum device_type
 {
@@ -19,6 +20,7 @@ struct device
 #ifdef CONFIG_HAS_DEVICE_TREE
 struct dt_device_node *of_node; /* Used by drivers imported from Linux */
 #endif
+struct fwnode_handle *fwnode; /*fw device node identifier */
 struct dev_archdata archdata;
 };
 
diff --git a/xen/include/xen/fwnode.h b/xen/include/xen/fwnode.h
new file mode 100644
index 000..0fed958
--- /dev/null
+++ b/xen/include/xen/fwnode.h
@@ -0,0 +1,33 @@
+/*
+ * fwnode.h - Firmware device node object handle type definition.
+ *
+ * Copyright (C) 2015, Intel Corporation
+ * Author: Rafael J. Wysocki <rafael.j.wyso...@intel.com>
+ *
+ * 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.
+ *
+ * Ported from Linux include/linux/fwnode.h
+ *  => commit ce793486e23e0162a732c605189c8028e0910e86
+ *
+ * No functional Xen modifications.
+ */
+
+#ifndef __XEN_FWNODE_H_
+#define __XEN_FWNODE_H_
+
+enum fwnode_type {
+   FWNODE_INVALID = 0,
+   FWNODE_OF,
+   FWNODE_ACPI,
+   FWNODE_ACPI_STATIC,
+   FWNODE_IRQCHIP
+};
+
+struct fwnode_handle {
+   enum fwnode_type type;
+   struct fwnode_handle *secondary;
+};
+
+#endif
-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. 
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux 
Foundation Collaborative Project.


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [RFC 1/6] passthrough/arm: Modify SMMU driver to use generic device definition

2017-06-08 Thread Sameer Goel
Modify the SMMU code to use generic device instead of dt_device_node for
functions that can be used for ACPI based systems too.

Signed-off-by: Sameer Goel <sg...@codeaurora.org>
---
 xen/drivers/passthrough/arm/smmu.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/xen/drivers/passthrough/arm/smmu.c 
b/xen/drivers/passthrough/arm/smmu.c
index 1082fcf..a298661 100644
--- a/xen/drivers/passthrough/arm/smmu.c
+++ b/xen/drivers/passthrough/arm/smmu.c
@@ -76,7 +76,7 @@ struct resource
 
 #define resource_size(res) (res)->size;
 
-#define platform_device dt_device_node
+#define platform_device device
 
 #define IORESOURCE_MEM 0
 #define IORESOURCE_IRQ 1
@@ -97,12 +97,12 @@ static struct resource *platform_get_resource(struct 
platform_device *pdev,
 
switch (type) {
case IORESOURCE_MEM:
-   ret = dt_device_get_address(pdev, num, , );
+   ret = dt_device_get_address(dev_to_dt(pdev), num, , 
);
 
return ((ret) ? NULL : );
 
case IORESOURCE_IRQ:
-   ret = platform_get_irq(pdev, num);
+   ret = platform_get_irq(dev_to_dt(pdev), num);
if (ret < 0)
return NULL;
 
@@ -2285,7 +2285,7 @@ static int arm_smmu_device_dt_probe(struct 
platform_device *pdev)
const struct of_device_id *of_id;
struct resource *res;
struct arm_smmu_device *smmu;
-   struct device *dev = >dev;
+   struct device *dev = pdev;
struct rb_node *node;
struct of_phandle_args masterspec;
int num_irqs, i, err;
@@ -2338,7 +2338,7 @@ static int arm_smmu_device_dt_probe(struct 
platform_device *pdev)
}
 
for (i = 0; i < num_irqs; ++i) {
-   int irq = platform_get_irq(pdev, i);
+   int irq = platform_get_irq(dev_to_dt(pdev), i);
 
if (irq < 0) {
dev_err(dev, "failed to get irq index %d\n", i);
@@ -2821,7 +2821,7 @@ static __init int arm_smmu_dt_init(struct dt_device_node 
*dev,
 */
dt_device_set_used_by(dev, DOMID_XEN);
 
-   rc = arm_smmu_device_dt_probe(dev);
+   rc = arm_smmu_device_dt_probe(dt_to_dev(dev));
if (rc)
return rc;
 
-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. 
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux 
Foundation Collaborative Project.


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [RFC 4/6] xen/passthrough/arm: Introduce iommu_fwspec

2017-06-08 Thread Sameer Goel
Introduce a common structure to hold the fw (ACPI or DT) defined
configuration for SMMU hw. The current use case is for arm SMMUs. So,
making this architecture specific.

Based on Linux kernel commit 57f98d2f61e1: iommu: Introduce iommu_fwspec
Signed-off-by: Sameer Goel <sg...@codeaurora.org>
---
 xen/drivers/passthrough/arm/iommu.c | 57 +
 xen/include/asm-arm/device.h|  1 +
 xen/include/xen/iommu.h | 28 ++
 3 files changed, 86 insertions(+)

diff --git a/xen/drivers/passthrough/arm/iommu.c 
b/xen/drivers/passthrough/arm/iommu.c
index 95b1abb..edf70c2 100644
--- a/xen/drivers/passthrough/arm/iommu.c
+++ b/xen/drivers/passthrough/arm/iommu.c
@@ -73,3 +73,60 @@ int arch_iommu_populate_page_table(struct domain *d)
 /* The IOMMU shares the p2m with the CPU */
 return -ENOSYS;
 }
+
+int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode,
+const struct iommu_ops *ops)
+{
+struct iommu_fwspec *fwspec = dev->iommu_fwspec;
+
+if (fwspec)
+return ops == fwspec->ops ? 0 : -EINVAL;
+
+fwspec = xzalloc(struct iommu_fwspec);
+if (!fwspec)
+return -ENOMEM;
+
+/* Ref counting for the dt device node is not needed */
+
+/*of_node_get(to_of_node(iommu_fwnode));*/
+
+fwspec->iommu_fwnode = iommu_fwnode;
+fwspec->ops = ops;
+dev->iommu_fwspec = fwspec;
+return 0;
+}
+
+void iommu_fwspec_free(struct device *dev)
+{
+struct iommu_fwspec *fwspec = dev->iommu_fwspec;
+
+if (fwspec) {
+/*fwnode_handle_put(fwspec->iommu_fwnode);*/
+xfree(fwspec);
+dev->iommu_fwspec = NULL;
+}
+}
+
+int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids)
+{
+struct iommu_fwspec *fwspec = dev->iommu_fwspec;
+size_t size;
+int i;
+
+if (!fwspec)
+return -EINVAL;
+
+size = offsetof(struct iommu_fwspec, ids[fwspec->num_ids + num_ids]);
+if (size > sizeof(*fwspec)) {
+fwspec = _xrealloc(dev->iommu_fwspec, size, sizeof(void *));
+if (!fwspec)
+return -ENOMEM;
+}
+
+for (i = 0; i < num_ids; i++)
+fwspec->ids[fwspec->num_ids + i] = ids[i];
+
+fwspec->num_ids += num_ids;
+dev->iommu_fwspec = fwspec;
+return 0;
+}
diff --git a/xen/include/asm-arm/device.h b/xen/include/asm-arm/device.h
index 78c38fe..5027c87 100644
--- a/xen/include/asm-arm/device.h
+++ b/xen/include/asm-arm/device.h
@@ -21,6 +21,7 @@ struct device
 struct dt_device_node *of_node; /* Used by drivers imported from Linux */
 #endif
 struct fwnode_handle *fwnode; /*fw device node identifier */
+struct iommu_fwspec *iommu_fwspec;
 struct dev_archdata archdata;
 };
 
diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h
index 5803e3f..7ef9b93 100644
--- a/xen/include/xen/iommu.h
+++ b/xen/include/xen/iommu.h
@@ -224,4 +224,32 @@ DECLARE_PER_CPU(bool_t, iommu_dont_flush_iotlb);
 extern struct spinlock iommu_pt_cleanup_lock;
 extern struct page_list_head iommu_pt_cleanup_list;
 
+/**
+ * Following block was ported from Linux to help with the implementation of
+ * arm64 iommu devices. Hence the architecture specific compile
+ */
+
+#if defined(CONFIG_ARM_64) || defined(CONFIG_ARM)
+/**
+ * struct iommu_fwspec - per-device IOMMU instance data
+ * @ops: ops for this device's IOMMU
+ * @iommu_fwnode: firmware handle for this device's IOMMU
+ * @iommu_priv: IOMMU driver private data for this device
+ * @num_ids: number of associated device IDs
+ * @ids: IDs which this device may present to the IOMMU
+ */
+struct iommu_fwspec {
+   const struct iommu_ops  *ops;
+   struct fwnode_handle*iommu_fwnode;
+   void*iommu_priv;
+   unsigned intnum_ids;
+   u32 ids[1];
+};
+
+int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode,
+ const struct iommu_ops *ops);
+void iommu_fwspec_free(struct device *dev);
+int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids);
+
+#endif
 #endif /* _IOMMU_H_ */
-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. 
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux 
Foundation Collaborative Project.


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [RFC 5/6] ACPI: arm: Support for IORT

2017-06-08 Thread Sameer Goel
Verbatim files from Linux kernel.
iort.c: commit ca78d3173cff:Merge tag 'arm64-upstream'
acpi_iort.h: commit 18b709beb503:ACPI/IORT: Make dma masks set-up IORT
specific

Signed-off-by: Sameer Goel <sg...@codeaurora.org>
---
 xen/drivers/acpi/arm/iort.c  | 961 +++
 xen/include/acpi/acpi_iort.h |  58 +++
 2 files changed, 1019 insertions(+)
 create mode 100644 xen/drivers/acpi/arm/iort.c
 create mode 100644 xen/include/acpi/acpi_iort.h

diff --git a/xen/drivers/acpi/arm/iort.c b/xen/drivers/acpi/arm/iort.c
new file mode 100644
index 000..4a5bb96
--- /dev/null
+++ b/xen/drivers/acpi/arm/iort.c
@@ -0,0 +1,961 @@
+/*
+ * Copyright (C) 2016, Semihalf
+ * Author: Tomasz Nowicki <t...@semihalf.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope 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.
+ *
+ * This file implements early detection/parsing of I/O mapping
+ * reported to OS through firmware via I/O Remapping Table (IORT)
+ * IORT document number: ARM DEN 0049A
+ */
+
+#define pr_fmt(fmt)"ACPI: IORT: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define IORT_TYPE_MASK(type)   (1 << (type))
+#define IORT_MSI_TYPE  (1 << ACPI_IORT_NODE_ITS_GROUP)
+#define IORT_IOMMU_TYPE((1 << ACPI_IORT_NODE_SMMU) |   \
+   (1 << ACPI_IORT_NODE_SMMU_V3))
+
+struct iort_its_msi_chip {
+   struct list_headlist;
+   struct fwnode_handle*fw_node;
+   u32 translation_id;
+};
+
+struct iort_fwnode {
+   struct list_head list;
+   struct acpi_iort_node *iort_node;
+   struct fwnode_handle *fwnode;
+};
+static LIST_HEAD(iort_fwnode_list);
+static DEFINE_SPINLOCK(iort_fwnode_lock);
+
+/**
+ * iort_set_fwnode() - Create iort_fwnode and use it to register
+ *iommu data in the iort_fwnode_list
+ *
+ * @node: IORT table node associated with the IOMMU
+ * @fwnode: fwnode associated with the IORT node
+ *
+ * Returns: 0 on success
+ *  <0 on failure
+ */
+static inline int iort_set_fwnode(struct acpi_iort_node *iort_node,
+ struct fwnode_handle *fwnode)
+{
+   struct iort_fwnode *np;
+
+   np = kzalloc(sizeof(struct iort_fwnode), GFP_ATOMIC);
+
+   if (WARN_ON(!np))
+   return -ENOMEM;
+
+   INIT_LIST_HEAD(>list);
+   np->iort_node = iort_node;
+   np->fwnode = fwnode;
+
+   spin_lock(_fwnode_lock);
+   list_add_tail(>list, _fwnode_list);
+   spin_unlock(_fwnode_lock);
+
+   return 0;
+}
+
+/**
+ * iort_get_fwnode() - Retrieve fwnode associated with an IORT node
+ *
+ * @node: IORT table node to be looked-up
+ *
+ * Returns: fwnode_handle pointer on success, NULL on failure
+ */
+static inline
+struct fwnode_handle *iort_get_fwnode(struct acpi_iort_node *node)
+{
+   struct iort_fwnode *curr;
+   struct fwnode_handle *fwnode = NULL;
+
+   spin_lock(_fwnode_lock);
+   list_for_each_entry(curr, _fwnode_list, list) {
+   if (curr->iort_node == node) {
+   fwnode = curr->fwnode;
+   break;
+   }
+   }
+   spin_unlock(_fwnode_lock);
+
+   return fwnode;
+}
+
+/**
+ * iort_delete_fwnode() - Delete fwnode associated with an IORT node
+ *
+ * @node: IORT table node associated with fwnode to delete
+ */
+static inline void iort_delete_fwnode(struct acpi_iort_node *node)
+{
+   struct iort_fwnode *curr, *tmp;
+
+   spin_lock(_fwnode_lock);
+   list_for_each_entry_safe(curr, tmp, _fwnode_list, list) {
+   if (curr->iort_node == node) {
+   list_del(>list);
+   kfree(curr);
+   break;
+   }
+   }
+   spin_unlock(_fwnode_lock);
+}
+
+typedef acpi_status (*iort_find_node_callback)
+   (struct acpi_iort_node *node, void *context);
+
+/* Root pointer to the mapped IORT table */
+static struct acpi_table_header *iort_table;
+
+static LIST_HEAD(iort_msi_chip_list);
+static DEFINE_SPINLOCK(iort_msi_chip_lock);
+
+/**
+ * iort_register_domain_token() - register domain token and related ITS ID
+ * to the list from where we can get it back later on.
+ * @trans_id: ITS ID.
+ * @fw_node: Domain token.
+ *
+ * Returns: 0 on success, -ENOMEM if no memory when allocating list element
+ */
+int iort_register_domain_token(int trans_id, struct fwnode_handle *fw_node)
+{
+   struct iort_its_msi_chip *its_msi_chip;
+
+   its_msi_chi

[Xen-devel] [RFC 6/6] acpi:arm64: Add support for parsing IORT table

2017-06-08 Thread Sameer Goel
Add limited support for parsing IORT table to initialize SMMU devices.

Signed-off-by: Sameer Goel <sg...@codeaurora.org>
---
 xen/arch/arm/setup.c|   3 +
 xen/drivers/acpi/Makefile   |   1 +
 xen/drivers/acpi/arm/Makefile   |   1 +
 xen/drivers/acpi/arm/iort.c | 232 +++-
 xen/drivers/passthrough/arm/iommu.c |  15 +--
 xen/include/acpi/acpi.h |   1 +
 xen/include/acpi/acpi_iort.h|  25 ++--
 xen/include/asm-arm/device.h|   2 +
 xen/include/xen/acpi.h  |  21 
 xen/include/xen/lib.h   |   7 +-
 xen/include/xen/pci.h   |   1 +
 11 files changed, 184 insertions(+), 125 deletions(-)
 create mode 100644 xen/drivers/acpi/arm/Makefile

diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index 92a2de6..5dc93ff 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -753,6 +753,9 @@ void __init start_xen(unsigned long boot_phys_offset,
 /* Parse the ACPI tables for possible boot-time configuration */
 acpi_boot_table_init();
 
+/* Initialize the IORT tables */
+acpi_iort_init();
+
 if ( acpi_disabled )
 printk("Booting using Device Tree\n");
 else
diff --git a/xen/drivers/acpi/Makefile b/xen/drivers/acpi/Makefile
index 444b11d..4165318 100644
--- a/xen/drivers/acpi/Makefile
+++ b/xen/drivers/acpi/Makefile
@@ -1,5 +1,6 @@
 subdir-y += tables
 subdir-y += utilities
+subdir-$(CONFIG_ARM_64) += arm
 subdir-$(CONFIG_X86) += apei
 
 obj-bin-y += tables.init.o
diff --git a/xen/drivers/acpi/arm/Makefile b/xen/drivers/acpi/arm/Makefile
new file mode 100644
index 000..7c039bb
--- /dev/null
+++ b/xen/drivers/acpi/arm/Makefile
@@ -0,0 +1 @@
+obj-y += iort.o
diff --git a/xen/drivers/acpi/arm/iort.c b/xen/drivers/acpi/arm/iort.c
index 4a5bb96..c22ec31 100644
--- a/xen/drivers/acpi/arm/iort.c
+++ b/xen/drivers/acpi/arm/iort.c
@@ -14,29 +14,40 @@
  * This file implements early detection/parsing of I/O mapping
  * reported to OS through firmware via I/O Remapping Table (IORT)
  * IORT document number: ARM DEN 0049A
+ *
+ * Based on Linux drivers/acpi/arm64/iort.c
+ * => commit ca78d3173cff3503bcd15723b049757f75762d15
+ *
+ * Xen modification:
+ * Sameer Goel <sg...@codeaurora.org>
+ * Copyright (C) 2017, The Linux Foundation, All rights reserved.
+ *
  */
 
-#define pr_fmt(fmt)"ACPI: IORT: " fmt
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
 
 #define IORT_TYPE_MASK(type)   (1 << (type))
 #define IORT_MSI_TYPE  (1 << ACPI_IORT_NODE_ITS_GROUP)
 #define IORT_IOMMU_TYPE((1 << ACPI_IORT_NODE_SMMU) |   \
(1 << ACPI_IORT_NODE_SMMU_V3))
 
+#if 0
 struct iort_its_msi_chip {
struct list_headlist;
struct fwnode_handle*fw_node;
u32 translation_id;
 };
 
+#endif
+
 struct iort_fwnode {
struct list_head list;
struct acpi_iort_node *iort_node;
@@ -60,7 +71,7 @@ static inline int iort_set_fwnode(struct acpi_iort_node 
*iort_node,
 {
struct iort_fwnode *np;
 
-   np = kzalloc(sizeof(struct iort_fwnode), GFP_ATOMIC);
+   np = xzalloc(struct iort_fwnode);
 
if (WARN_ON(!np))
return -ENOMEM;
@@ -114,7 +125,7 @@ static inline void iort_delete_fwnode(struct acpi_iort_node 
*node)
list_for_each_entry_safe(curr, tmp, _fwnode_list, list) {
if (curr->iort_node == node) {
list_del(>list);
-   kfree(curr);
+   xfree(curr);
break;
}
}
@@ -127,6 +138,7 @@ typedef acpi_status (*iort_find_node_callback)
 /* Root pointer to the mapped IORT table */
 static struct acpi_table_header *iort_table;
 
+#if 0
 static LIST_HEAD(iort_msi_chip_list);
 static DEFINE_SPINLOCK(iort_msi_chip_lock);
 
@@ -199,7 +211,7 @@ struct fwnode_handle *iort_find_domain_token(int trans_id)
 
return fw_node;
 }
-
+#endif
 static struct acpi_iort_node *iort_scan_node(enum acpi_iort_node_type type,
 iort_find_node_callback callback,
 void *context)
@@ -219,9 +231,10 @@ static struct acpi_iort_node *iort_scan_node(enum 
acpi_iort_node_type type,
iort_table->length);
 
for (i = 0; i < iort->node_count; i++) {
-   if (WARN_TAINT(iort_node >= iort_end, TAINT_FIRMWARE_WORKAROUND,
-  "IORT node pointer overflows, bad table!\n"))
+   if (iort_node >= iort_end) {
+   printk(XENLOG_ERR "IORT node pointer overflows, bad 
table!\n");
return NULL;
+   }
 
   

[Xen-devel] [RFC 0/6] IORT support and introduce fwspec

2017-06-08 Thread Sameer Goel
This changelist is in preparation for porting the latest SMMUv3 driver from
Linux kernel  4.11 release.

Scope of the changes:
- Introduce the iommu_fwspec implementation
* This implementation is a direct port from Linux. The code that is not
  needed for Xen is removed.
- IORT port from Linux. The differences are as under:
* The DMA ops are removed.
* Modified the code for creating the SMMU devices. This also initializes
  the discoverd SMMU devices.
* MSI code is commented out till the MSI framework API usage is clearer.
* IORT node data parsing is delegated to the driver. Looking for comments
  on enabling the code in IORT driver. This will need a standard resource
  object. (Direct port from Linux or a new define for Xen?)
* Assumptions on PCI IORT SMMU interaction. PCI assign device will call
  iort_iommu_configure to setup the streamids.Then it will call SMMU
  assign device with the right struct device argument.

Sameer Goel (6):
  passthrough/arm: Modify SMMU driver to use generic device definition
  arm64: Add definitions for fwnode_handle
  Introduce _xrealloc
  xen/passthrough/arm: Introduce iommu_fwspec
  ACPI: arm: Support for IORT
  acpi:arm64: Add support for parsing IORT table

 xen/arch/arm/setup.c|   3 +
 xen/common/xmalloc_tlsf.c   |  13 +
 xen/drivers/acpi/Makefile   |   1 +
 xen/drivers/acpi/arm/Makefile   |   1 +
 xen/drivers/acpi/arm/iort.c | 977 
 xen/drivers/passthrough/arm/iommu.c |  58 +++
 xen/drivers/passthrough/arm/smmu.c  |  12 +-
 xen/include/acpi/acpi.h |   1 +
 xen/include/acpi/acpi_iort.h|  65 +++
 xen/include/asm-arm/device.h|   5 +
 xen/include/xen/acpi.h  |  21 +
 xen/include/xen/fwnode.h|  35 ++
 xen/include/xen/iommu.h |  28 ++
 xen/include/xen/lib.h   |   7 +-
 xen/include/xen/pci.h   |   1 +
 xen/include/xen/xmalloc.h   |   1 +
 16 files changed, 1222 insertions(+), 7 deletions(-)
 create mode 100644 xen/drivers/acpi/arm/Makefile
 create mode 100644 xen/drivers/acpi/arm/iort.c
 create mode 100644 xen/include/acpi/acpi_iort.h
 create mode 100644 xen/include/xen/fwnode.h

-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. 
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux 
Foundation Collaborative Project.

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [RFC 3/6] Introduce _xrealloc

2017-06-08 Thread Sameer Goel
Introduce a memory realloc function.

Signed-off-by: Sameer Goel <sg...@codeaurora.org>
---
 xen/common/xmalloc_tlsf.c | 13 +
 xen/include/xen/xmalloc.h |  1 +
 2 files changed, 14 insertions(+)

diff --git a/xen/common/xmalloc_tlsf.c b/xen/common/xmalloc_tlsf.c
index b256dc5..52385a8 100644
--- a/xen/common/xmalloc_tlsf.c
+++ b/xen/common/xmalloc_tlsf.c
@@ -612,6 +612,19 @@ void *_xzalloc(unsigned long size, unsigned long align)
 return p ? memset(p, 0, size) : p;
 }
 
+void *_xrealloc(void *p, unsigned long new_size, unsigned long align)
+{
+void *new_p = _xmalloc(new_size, align);
+
+if(new_p && p)
+{
+memcpy(new_p, p, new_size);
+xfree(p);
+}
+
+return new_p;
+}
+
 void xfree(void *p)
 {
 struct bhdr *b;
diff --git a/xen/include/xen/xmalloc.h b/xen/include/xen/xmalloc.h
index 24a99ac..41a9b2f 100644
--- a/xen/include/xen/xmalloc.h
+++ b/xen/include/xen/xmalloc.h
@@ -29,6 +29,7 @@ extern void xfree(void *);
 /* Underlying functions */
 extern void *_xmalloc(unsigned long size, unsigned long align);
 extern void *_xzalloc(unsigned long size, unsigned long align);
+extern void *_xrealloc(void *p, unsigned long new_size, unsigned long align);
 
 static inline void *_xmalloc_array(
 unsigned long size, unsigned long align, unsigned long num)
-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. 
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux 
Foundation Collaborative Project.


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [RFC 2/6] arm64: Add definitions for fwnode_handle

2017-06-08 Thread Sameer Goel
This will be used as a device property to match the DMA capable devices
with the associated SMMU. The header file is a port from linux.

Linux ChangeId:ce793486e23e: driver core / ACPI: Represent ACPI
companions using fwnode_handle

Signed-off-by: Sameer Goel <sg...@codeaurora.org>
---
 xen/include/asm-arm/device.h |  2 ++
 xen/include/xen/fwnode.h | 35 +++
 2 files changed, 37 insertions(+)
 create mode 100644 xen/include/xen/fwnode.h

diff --git a/xen/include/asm-arm/device.h b/xen/include/asm-arm/device.h
index 6734ae8..78c38fe 100644
--- a/xen/include/asm-arm/device.h
+++ b/xen/include/asm-arm/device.h
@@ -2,6 +2,7 @@
 #define __ASM_ARM_DEVICE_H
 
 #include 
+#include 
 
 enum device_type
 {
@@ -19,6 +20,7 @@ struct device
 #ifdef CONFIG_HAS_DEVICE_TREE
 struct dt_device_node *of_node; /* Used by drivers imported from Linux */
 #endif
+struct fwnode_handle *fwnode; /*fw device node identifier */
 struct dev_archdata archdata;
 };
 
diff --git a/xen/include/xen/fwnode.h b/xen/include/xen/fwnode.h
new file mode 100644
index 000..db65b15
--- /dev/null
+++ b/xen/include/xen/fwnode.h
@@ -0,0 +1,35 @@
+/*
+ * fwnode.h - Firmware device node object handle type definition.
+ *
+ * Copyright (C) 2015, Intel Corporation
+ * Author: Rafael J. Wysocki <rafael.j.wyso...@intel.com>
+ *
+ * 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.
+ *
+ * Ported from Linux include/linux/fwnode.h
+ *  => commit ce793486e23e0162a732c605189c8028e0910e86
+ *
+ * No functional Xen modifications.
+ */
+
+#ifndef __XEN_FWNODE_H_
+#define __XEN_FWNODE_H_
+
+enum fwnode_type {
+   FWNODE_INVALID = 0,
+   FWNODE_OF,
+   FWNODE_ACPI,
+   FWNODE_ACPI_DATA,
+   FWNODE_ACPI_STATIC,
+   FWNODE_PDATA,
+   FWNODE_IRQCHIP
+};
+
+struct fwnode_handle {
+   enum fwnode_type type;
+   struct fwnode_handle *secondary;
+};
+
+#endif
-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. 
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux 
Foundation Collaborative Project.


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v2 2/2] ACPICA: IORT: Add in support for the SMMUv3 subtable

2017-03-30 Thread Sameer Goel
From: Al Stone <a...@redhat.com>

ACPICA commit 9f7c3e148f440049615e2791d73b292f65692d7e

The most recent version of the IORT specification adds in a definition
for a subtable to describe SMMUv3 devices; there is already a subtable
for SMMUv1/v2 devices.

Add in the definition of the subtable, add in the code to compile it,
and add in a template for it.

Link: https://github.com/acpica/acpica/commit/9f7c3e14
Signed-off-by: Al Stone <a...@redhat.com>
Signed-off-by: Bob Moore <robert.mo...@intel.com>
Signed-off-by: Lv Zheng <lv.zh...@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wyso...@intel.com>
[Linux commit 4ac78baf88d85c49883fcc87d31198ebe408e54d]
Signed-off-by: Sameer Goel <sg...@codeaurora.org>
---
 xen/include/acpi/actbl2.h | 22 --
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/xen/include/acpi/actbl2.h b/xen/include/acpi/actbl2.h
index 7d66014..d1cd148 100644
--- a/xen/include/acpi/actbl2.h
+++ b/xen/include/acpi/actbl2.h
@@ -560,7 +560,7 @@ struct acpi_ibft_target {
  * IORT - IO Remapping Table
  *
  * Conforms to "IO Remapping Table System Software on ARM Platforms",
- * Document number: ARM DEN 0049A, 2015
+ * Document number: ARM DEN 0049B, October 2015
  *
  
**/
 
@@ -590,7 +590,8 @@ enum acpi_iort_node_type {
ACPI_IORT_NODE_ITS_GROUP = 0x00,
ACPI_IORT_NODE_NAMED_COMPONENT = 0x01,
ACPI_IORT_NODE_PCI_ROOT_COMPLEX = 0x02,
-   ACPI_IORT_NODE_SMMU = 0x03
+   ACPI_IORT_NODE_SMMU = 0x03,
+   ACPI_IORT_NODE_SMMU_V3 = 0x04
 };
 
 struct acpi_iort_id_mapping {
@@ -680,6 +681,23 @@ struct acpi_iort_smmu {
 #define ACPI_IORT_SMMU_DVM_SUPPORTED(1)
 #define ACPI_IORT_SMMU_COHERENT_WALK(1<<1)
 
+struct acpi_iort_smmu_v3 {
+   u64 base_address;   /* SMMUv3 base address */
+   u32 flags;
+   u32 reserved;
+   u64 vatos_address;
+   u32 model;  /* O: generic SMMUv3 */
+   u32 event_gsiv;
+   u32 pri_gsiv;
+   u32 gerr_gsiv;
+   u32 sync_gsiv;
+};
+
+/* Masks for Flags field above */
+
+#define ACPI_IORT_SMMU_V3_COHACC_OVERRIDE   (1)
+#define ACPI_IORT_SMMU_V3_HTTU_OVERRIDE (1<<1)
+
 
/***
  *
  * IVRS - I/O Virtualization Reporting Structure
-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. 
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux 
Foundation Collaborative Project.


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v2 0/2] Support for IORT table

2017-03-30 Thread Sameer Goel
This patch set adds definitions for IORT ACPI table. The header file
definitions are ported from Linux Kernel source.

Al Stone (1):
  ACPICA: IORT: Add in support for the SMMUv3 subtable

Lv Zheng (1):
  ACPICA: ACPI 6.0: Add support for IORT table.

 xen/include/acpi/actbl2.h | 144 ++
 1 file changed, 144 insertions(+)

-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. 
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux 
Foundation Collaborative Project.


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v2 1/2] ACPICA: ACPI 6.0: Add support for IORT table.

2017-03-30 Thread Sameer Goel
From: Lv Zheng <lv.zh...@intel.com>

ACPICA commit 5de82757aef5d6163e37064033aacbce193abbca

This patch adds support for IORT (IO Remapping Table) in iasl.

Note that some field names are modified to shrink their length or the
decompiled IORT ASL will contain fields with ugly ":" alignment.

The IORT contains field definitions around "Memory Access Properties". This
patch also adds support to encode/decode it using inline table.

This patch doesn't add inline table support for the SMMU interrupt fields
due to a limitation in current ACPICA data table support. Lv Zheng.

Link: https://github.com/acpica/acpica/commit/5de82757
Signed-off-by: Lv Zheng <lv.zh...@intel.com>
Signed-off-by: Bob Moore <robert.mo...@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wyso...@intel.com>
[Linux commit 874f6a723e56d0da9e481629b17482bcd3801ecf]
Signed-off-by: Sameer Goel <sg...@codeaurora.org>
---
 xen/include/acpi/actbl2.h | 126 ++
 1 file changed, 126 insertions(+)

diff --git a/xen/include/acpi/actbl2.h b/xen/include/acpi/actbl2.h
index d2327d2..7d66014 100644
--- a/xen/include/acpi/actbl2.h
+++ b/xen/include/acpi/actbl2.h
@@ -69,6 +69,7 @@
 #define ACPI_SIG_HPET   "HPET" /* High Precision Event Timer table */
 #define ACPI_SIG_IBFT   "IBFT" /* i_sCSI Boot Firmware Table */
 #define ACPI_SIG_IVRS   "IVRS" /* I/O Virtualization Reporting 
Structure */
+#define ACPI_SIG_IORT   "IORT" /* IO Remapping Table */
 #define ACPI_SIG_MCFG   "MCFG" /* PCI Memory Mapped Configuration 
table */
 #define ACPI_SIG_MCHI   "MCHI" /* Management Controller Host Interface 
table */
 #define ACPI_SIG_SLIC   "SLIC" /* Software Licensing Description Table 
*/
@@ -556,6 +557,131 @@ struct acpi_ibft_target {
 
 
/***
  *
+ * IORT - IO Remapping Table
+ *
+ * Conforms to "IO Remapping Table System Software on ARM Platforms",
+ * Document number: ARM DEN 0049A, 2015
+ *
+ 
**/
+
+struct acpi_table_iort {
+   struct acpi_table_header header;
+   u32 node_count;
+   u32 node_offset;
+   u32 reserved;
+};
+
+/*
+ * IORT subtables
+ */
+struct acpi_iort_node {
+   u8 type;
+   u16 length;
+   u8 revision;
+   u32 reserved;
+   u32 mapping_count;
+   u32 mapping_offset;
+   char node_data[1];
+};
+
+/* Values for subtable Type above */
+
+enum acpi_iort_node_type {
+   ACPI_IORT_NODE_ITS_GROUP = 0x00,
+   ACPI_IORT_NODE_NAMED_COMPONENT = 0x01,
+   ACPI_IORT_NODE_PCI_ROOT_COMPLEX = 0x02,
+   ACPI_IORT_NODE_SMMU = 0x03
+};
+
+struct acpi_iort_id_mapping {
+   u32 input_base; /* Lowest value in input range */
+   u32 id_count;   /* Number of IDs */
+   u32 output_base;/* Lowest value in output range */
+   u32 output_reference;   /* A reference to the output node */
+   u32 flags;
+};
+
+/* Masks for Flags field above for IORT subtable */
+
+#define ACPI_IORT_ID_SINGLE_MAPPING (1)
+
+struct acpi_iort_memory_access {
+   u32 cache_coherency;
+   u8 hints;
+   u16 reserved;
+   u8 memory_flags;
+};
+
+/* Values for cache_coherency field above */
+
+#define ACPI_IORT_NODE_COHERENT 0x0001 /* The device node is 
fully coherent */
+#define ACPI_IORT_NODE_NOT_COHERENT 0x /* The device node is 
not coherent */
+
+/* Masks for Hints field above */
+
+#define ACPI_IORT_HT_TRANSIENT  (1)
+#define ACPI_IORT_HT_WRITE  (1<<1)
+#define ACPI_IORT_HT_READ   (1<<2)
+#define ACPI_IORT_HT_OVERRIDE   (1<<3)
+
+/* Masks for memory_flags field above */
+
+#define ACPI_IORT_MF_COHERENCY  (1)
+#define ACPI_IORT_MF_ATTRIBUTES (1<<1)
+
+/*
+ * IORT node specific subtables
+ */
+struct acpi_iort_its_group {
+   u32 its_count;
+   u32 identifiers[1]; /* GIC ITS identifier arrary */
+};
+
+struct acpi_iort_named_component {
+   u32 node_flags;
+   u64 memory_properties;  /* Memory access properties */
+   u8 memory_address_limit;/* Memory address size limit */
+   char device_name[1];/* Path of namespace object */
+};
+
+struct acpi_iort_root_complex {
+   u64 memory_properties;  /* Memory access properties */
+   u32 ats_attribute;
+   u32 pci_segment_number;
+};
+
+/* Values for ats_attribute field above */
+
+#define ACPI_IORT_ATS_SUPPORTED 0x0001 /* The root complex 
supports ATS */
+#define ACPI_IORT_ATS_UNSUPPORTED   0x /* The root complex 
doesn't support ATS */
+
+struct acpi_iort_smmu {
+   u64 base_address;   /* SMMU base address */
+   u64 span; 

[Xen-devel] [PATCH] ACPICA: ACPI 6.0: Add support for IORT table.

2017-02-15 Thread Sameer Goel
From: Lv Zheng <lv.zh...@intel.com>

ACPICA commit 5de82757aef5d6163e37064033aacbce193abbca

This patch adds support for IORT (IO Remapping Table) in iasl.

Note that some field names are modified to shrink their length or the
decompiled IORT ASL will contain fields with ugly ":" alignment.

The IORT contains field definitions around "Memory Access Properties". This
patch also adds support to encode/decode it using inline table.

This patch doesn't add inline table support for the SMMU interrupt fields
due to a limitation in current ACPICA data table support. Lv Zheng.

Link: https://github.com/acpica/acpica/commit/5de82757
Signed-off-by: Lv Zheng <lv.zh...@intel.com>
Signed-off-by: Bob Moore <robert.mo...@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wyso...@intel.com>
[Linux commit 874f6a723e56d0da9e481629b17482bcd3801ecf]
[only port the IORT changes]
Signed-off-by: Sameer Goel <sg...@codeaurora.org>
---
 xen/include/acpi/actbl2.h | 148 +-
 1 file changed, 146 insertions(+), 2 deletions(-)

diff --git a/xen/include/acpi/actbl2.h b/xen/include/acpi/actbl2.h
index d2327d2..e13c823 100644
--- a/xen/include/acpi/actbl2.h
+++ b/xen/include/acpi/actbl2.h
@@ -5,7 +5,7 @@
  */
 
 /*
- * Copyright (C) 2000 - 2011, Intel Corp.
+ * Copyright (C) 2000 - 2016, Intel Corp.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -67,7 +67,8 @@
 #define ACPI_SIG_DBGP   "DBGP" /* Debug Port table */
 #define ACPI_SIG_DMAR   "DMAR" /* DMA Remapping table */
 #define ACPI_SIG_HPET   "HPET" /* High Precision Event Timer table */
-#define ACPI_SIG_IBFT   "IBFT" /* i_sCSI Boot Firmware Table */
+#define ACPI_SIG_IBFT   "IBFT" /* iSCSI Boot Firmware Table */
+#define ACPI_SIG_IORT   "IORT" /* IO Remapping Table */
 #define ACPI_SIG_IVRS   "IVRS" /* I/O Virtualization Reporting 
Structure */
 #define ACPI_SIG_MCFG   "MCFG" /* PCI Memory Mapped Configuration 
table */
 #define ACPI_SIG_MCHI   "MCHI" /* Management Controller Host Interface 
table */
@@ -556,6 +557,149 @@ struct acpi_ibft_target {
 
 
/***
  *
+ * IORT - IO Remapping Table
+ *
+ * Conforms to "IO Remapping Table System Software on ARM Platforms",
+ * Document number: ARM DEN 0049B, October 2015
+ *
+ 
**/
+
+struct acpi_table_iort {
+   struct acpi_table_header header;
+   u32 node_count;
+   u32 node_offset;
+   u32 reserved;
+};
+
+/*
+ * IORT subtables
+ */
+struct acpi_iort_node {
+   u8 type;
+   u16 length;
+   u8 revision;
+   u32 reserved;
+   u32 mapping_count;
+   u32 mapping_offset;
+   char node_data[1];
+};
+
+/* Values for subtable Type above */
+
+enum acpi_iort_node_type {
+   ACPI_IORT_NODE_ITS_GROUP = 0x00,
+   ACPI_IORT_NODE_NAMED_COMPONENT = 0x01,
+   ACPI_IORT_NODE_PCI_ROOT_COMPLEX = 0x02,
+   ACPI_IORT_NODE_SMMU = 0x03,
+   ACPI_IORT_NODE_SMMU_V3 = 0x04
+};
+
+struct acpi_iort_id_mapping {
+   u32 input_base; /* Lowest value in input range */
+   u32 id_count;   /* Number of IDs */
+   u32 output_base;/* Lowest value in output range */
+   u32 output_reference;   /* A reference to the output node */
+   u32 flags;
+};
+
+/* Masks for Flags field above for IORT subtable */
+
+#define ACPI_IORT_ID_SINGLE_MAPPING (1)
+
+struct acpi_iort_memory_access {
+   u32 cache_coherency;
+   u8 hints;
+   u16 reserved;
+   u8 memory_flags;
+};
+
+/* Values for cache_coherency field above */
+
+#define ACPI_IORT_NODE_COHERENT 0x0001 /* The device node is 
fully coherent */
+#define ACPI_IORT_NODE_NOT_COHERENT 0x /* The device node is 
not coherent */
+
+/* Masks for Hints field above */
+
+#define ACPI_IORT_HT_TRANSIENT  (1)
+#define ACPI_IORT_HT_WRITE  (1<<1)
+#define ACPI_IORT_HT_READ   (1<<2)
+#define ACPI_IORT_HT_OVERRIDE   (1<<3)
+
+/* Masks for memory_flags field above */
+
+#define ACPI_IORT_MF_COHERENCY  (1)
+#define ACPI_IORT_MF_ATTRIBUTES (1<<1)
+
+/*
+ * IORT node specific subtables
+ */
+struct acpi_iort_its_group {
+   u32 its_count;
+   u32 identifiers[1]; /* GIC ITS identifier arrary */
+};
+
+struct acpi_iort_named_component {
+   u32 node_flags;
+   u64 memory_properties;  /* Memory access properties */
+   u8 memory_address_limit;/* Memory address size limit */
+   char device_name[1];/* Path of namespace object */
+};

[Xen-devel] [PATCH V2] Revert "xen/arm: do not relocate Xen outside of visible RAM"

2016-10-25 Thread Sameer Goel
This reverts commit db92b1ac55cd5e193ae22b0b6f01fb47bc9e5d2f.

The restriction on non contiguous memory was resolved by commit
2d02b05c77fc5e7c76bf6f112db84bbaa44fdcb5:
"xen: arm: improve handling of system with non-contiguous RAM regions"

So, reverting this change,to enable Xen image placement at the end of the
useable system RAM.

Signed-off-by: Sameer Goel <sg...@codeaurora.org>
---
The load restriction placed in the above reverted patch resulted in a crash
when booting DOM0 on a Qualcomm platform with non contiguous system RAM.

(XEN) DOM0: [ 0.00] bootmem alloc of 64 bytes failed!
(XEN) DOM0: [ 0.00] Kernel panic - not syncing: Out of memory
(XEN) DOM0: [ 0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 4.7.0-rc7+ #19
(XEN) DOM0: [ 0.00] Hardware name: (null) (DT)
(XEN) DOM0: [ 0.00] Call trace:
(XEN) DOM0: [ 0.00] [] dump_backtrace+0x0/0x1e4
(XEN) DOM0: [ 0.00] [] show_stack+0x24/0x2c
(XEN) DOM0: [ 0.00] [] dump_stack+0x8c/0xb0
(XEN) DOM0: [ 0.00] [] panic+0x128/0x268
(XEN) DOM0: [ 0.00] [] __alloc_bootmem_low+0x40/0x4c
(XEN) DOM0: [ 0.00] [] setup_arch+0x2d8/0x560
(XEN) DOM0: [ 0.00] [] start_kernel+0x60/0x3b4
(XEN) DOM0: [ 0.00] [] __primary_switched+0x30/0x74
(XEN) DOM0: [ 0.00] ---[ end Kernel panic - not syncing: Out of memory

The root cause for the crash was >4GB difference between the arm grant table
(lower address) and the kernel start address. The kernel sees the grant table
region as the start of system RAM.

Since, the grant table is a reuse of the text region of Xen image this issue
would not be seen if Xen is loaded high enough in memory.

 xen/arch/arm/setup.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index 38eb888..1678871 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -392,25 +392,17 @@ static paddr_t __init get_xen_paddr(void)
 {
 struct meminfo *mi = 
 paddr_t min_size;
-paddr_t paddr = 0, last_end;
+paddr_t paddr = 0;
 int i;
 
 min_size = (_end - _start + (XEN_PADDR_ALIGN-1)) & ~(XEN_PADDR_ALIGN-1);
 
-last_end = mi->bank[0].start;
-
 /* Find the highest bank with enough space. */
 for ( i = 0; i < mi->nr_banks; i++ )
 {
 const struct membank *bank = >bank[i];
 paddr_t s, e;
 
-/* We can only deal with contiguous memory at the moment */
-if ( last_end != bank->start )
-break;
-
-last_end = bank->start + bank->size;
-
 if ( bank->size >= min_size )
 {
 e = consider_modules(bank->start, bank->start + bank->size,
-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. 
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux 
Foundation Collaborative Project.


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH] Revert "xen/arm: do not relocate Xen outside of visible RAM"

2016-10-24 Thread Sameer Goel
This reverts commit db92b1ac55cd5e193ae22b0b6f01fb47bc9e5d2f.

There does not seem to be a restriction on non contiguous memory anymore . So,
reverting this change, so that Xen is placed at the end of the useable
system RAM even if the partitions are not contiguous.

Signed-off-by: Sameer Goel <sg...@codeaurora.org>
---
The load restriction placed in the above reverted patch resulted in a crash
when booting DOM0 on a Qualcomm platform with non contiguous system RAM.

(XEN) DOM0: [ 0.00] bootmem alloc of 64 bytes failed!
(XEN) DOM0: [ 0.00] Kernel panic - not syncing: Out of memory
(XEN) DOM0: [ 0.00] CPU: 0 PID: 0 Comm: swapper Not tainted 4.7.0-rc7+ #19
(XEN) DOM0: [ 0.00] Hardware name: (null) (DT)
(XEN) DOM0: [ 0.00] Call trace:
(XEN) DOM0: [ 0.00] [] dump_backtrace+0x0/0x1e4
(XEN) DOM0: [ 0.00] [] show_stack+0x24/0x2c
(XEN) DOM0: [ 0.00] [] dump_stack+0x8c/0xb0
(XEN) DOM0: [ 0.00] [] panic+0x128/0x268
(XEN) DOM0: [ 0.00] [] __alloc_bootmem_low+0x40/0x4c
(XEN) DOM0: [ 0.00] [] setup_arch+0x2d8/0x560
(XEN) DOM0: [ 0.00] [] start_kernel+0x60/0x3b4
(XEN) DOM0: [ 0.00] [] __primary_switched+0x30/0x74
(XEN) DOM0: [ 0.00] ---[ end Kernel panic - not syncing: Out of memory

The root cause for the crash was >4GB difference between the arm grant table
(lower address) and the kernel start address. The kernel sees the grant table
region as the start of system RAM.

Since, the grant table is a reuse of the text region of Xen image this issue
would not be seen if Xen is loaded high enough in memory.

 xen/arch/arm/setup.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index 38eb888..1678871 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -392,25 +392,17 @@ static paddr_t __init get_xen_paddr(void)
 {
 struct meminfo *mi = 
 paddr_t min_size;
-paddr_t paddr = 0, last_end;
+paddr_t paddr = 0;
 int i;
 
 min_size = (_end - _start + (XEN_PADDR_ALIGN-1)) & ~(XEN_PADDR_ALIGN-1);
 
-last_end = mi->bank[0].start;
-
 /* Find the highest bank with enough space. */
 for ( i = 0; i < mi->nr_banks; i++ )
 {
 const struct membank *bank = >bank[i];
 paddr_t s, e;
 
-/* We can only deal with contiguous memory at the moment */
-if ( last_end != bank->start )
-break;
-
-last_end = bank->start + bank->size;
-
 if ( bank->size >= min_size )
 {
 e = consider_modules(bank->start, bank->start + bank->size,
-- 
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. 
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux 
Foundation Collaborative Project.


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel