All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vikram Garhwal <vikram.garhwal@amd.com>
To: <xen-devel@lists.xenproject.org>
Cc: <michal.orzel@amd.com>, <sstabellini@kernel.org>,
	<vikram.garhwal@amd.com>, <julien@xen.org>,
	Bertrand Marquis <bertrand.marquis@arm.com>,
	Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Subject: [XEN][PATCH v10 15/20] arm/asm/setup.h: Update struct map_range_data to add rangeset.
Date: Fri, 25 Aug 2023 01:02:17 -0700	[thread overview]
Message-ID: <20230825080222.14247-16-vikram.garhwal@amd.com> (raw)
In-Reply-To: <20230825080222.14247-1-vikram.garhwal@amd.com>

Add rangesets for IRQs and IOMEMs. This was done to accommodate dynamic overlay
node addition/removal operations. With overlay operations, new IRQs and IOMEMs
are added in dt_host and routed. While removing overlay nodes, nodes are remove
from dt_host and their IRQs and IOMEMs routing is also removed. Storing IRQs and
IOMEMs in the rangeset will avoid re-parsing the device tree nodes to get the
IOMEM and IRQ ranges for overlay remove ops.

Dynamic overlay node add/remove will be introduced in follow-up patches.

Signed-off-by: Vikram Garhwal <vikram.garhwal@amd.com>
---
 xen/arch/arm/device.c            | 43 +++++++++++++++++++++++++-------
 xen/arch/arm/domain_build.c      |  4 +--
 xen/arch/arm/include/asm/setup.h |  5 +++-
 3 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c
index 857f171a27..9df37abac8 100644
--- a/xen/arch/arm/device.c
+++ b/xen/arch/arm/device.c
@@ -165,6 +165,14 @@ int map_range_to_domain(const struct dt_device_node *dev,
     dt_dprintk("  - MMIO: %010"PRIx64" - %010"PRIx64" P2MType=%x\n",
                addr, addr + len, mr_data->p2mt);
 
+    if ( mr_data->iomem_ranges )
+    {
+        res = rangeset_add_range(mr_data->iomem_ranges, paddr_to_pfn(addr),
+                                 paddr_to_pfn(PAGE_ALIGN(addr + len - 1)));
+        if ( res )
+            return res;
+    }
+
     return 0;
 }
 
@@ -178,9 +186,10 @@ int map_range_to_domain(const struct dt_device_node *dev,
  */
 int handle_device_interrupts(struct domain *d,
                              struct dt_device_node *dev,
-                             bool need_mapping)
+                             bool need_mapping,
+                             struct rangeset *irq_ranges)
 {
-    unsigned int i, nirq;
+    unsigned int i, nirq, irq;
     int res;
     struct dt_raw_irq rirq;
 
@@ -208,17 +217,24 @@ int handle_device_interrupts(struct domain *d,
             continue;
         }
 
-        res = platform_get_irq(dev, i);
-        if ( res < 0 )
+        irq = platform_get_irq(dev, i);
+        if ( irq < 0 )
         {
             printk(XENLOG_ERR "Unable to get irq %u for %s\n",
                    i, dt_node_full_name(dev));
-            return res;
+            return irq;
         }
 
-        res = map_irq_to_domain(d, res, need_mapping, dt_node_name(dev));
+        res = map_irq_to_domain(d, irq, need_mapping, dt_node_name(dev));
         if ( res )
             return res;
+
+        if ( irq_ranges )
+        {
+            res = rangeset_add_singleton(irq_ranges, irq);
+            if ( res )
+                return res;
+        }
     }
 
     return 0;
@@ -249,6 +265,11 @@ static int map_dt_irq_to_domain(const struct dt_device_node *dev,
     }
 
     res = map_irq_to_domain(d, irq, !mr_data->skip_mapping, dt_node_name(dev));
+    if ( res )
+        return res;
+
+    if ( mr_data->irq_ranges )
+        res = rangeset_add_singleton(mr_data->irq_ranges, irq);
 
     return res;
 }
@@ -289,7 +310,8 @@ static int map_device_children(const struct dt_device_node *dev,
  *  - Assign the device to the guest if it's protected by an IOMMU
  *  - Map the IRQs and iomem regions to DOM0
  */
-int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt)
+int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt,
+                  struct rangeset *iomem_ranges, struct rangeset *irq_ranges)
 {
     unsigned int naddr;
     unsigned int i;
@@ -304,10 +326,13 @@ int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt)
      *     pci_host_bridge_mappings().
      */
     struct map_range_data mr_data = {
+        .d = d,
         .p2mt = p2mt,
         .skip_mapping = !own_device ||
                         (is_pci_passthrough_enabled() &&
-                        (device_get_class(dev) == DEVICE_PCI_HOSTBRIDGE))
+                        (device_get_class(dev) == DEVICE_PCI_HOSTBRIDGE)),
+        .iomem_ranges = iomem_ranges,
+        .irq_ranges = irq_ranges
     };
 
     naddr = dt_number_of_address(dev);
@@ -341,7 +366,7 @@ int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt)
         }
     }
 
-    res = handle_device_interrupts(d, dev, own_device);
+    res = handle_device_interrupts(d, dev, own_device, irq_ranges);
     if ( res < 0 )
         return res;
 
diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 63ca9ea5fe..8e9dd0c373 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -2401,7 +2401,7 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,
                "WARNING: Path %s is reserved, skip the node as we may re-use the path.\n",
                path);
 
-    res = handle_device(d, node, p2mt);
+    res = handle_device(d, node, p2mt, NULL, NULL);
     if ( res)
         return res;
 
@@ -2744,7 +2744,7 @@ static int __init handle_passthrough_prop(struct kernel_info *kinfo,
         return -EINVAL;
     }
 
-    res = handle_device_interrupts(kinfo->d, node, true);
+    res = handle_device_interrupts(kinfo->d, node, true, NULL);
     if ( res < 0 )
         return res;
 
diff --git a/xen/arch/arm/include/asm/setup.h b/xen/arch/arm/include/asm/setup.h
index 1a052ed924..2dc6d4c1a6 100644
--- a/xen/arch/arm/include/asm/setup.h
+++ b/xen/arch/arm/include/asm/setup.h
@@ -113,6 +113,9 @@ struct map_range_data
     p2m_type_t p2mt;
     /* Set if mapping of the memory ranges must be skipped. */
     bool skip_mapping;
+    /* Rangeset to store IRQs and IOMEM for overlay nodes. */
+    struct rangeset *iomem_ranges;
+    struct rangeset *irq_ranges;
 };
 
 extern struct bootinfo bootinfo;
@@ -169,7 +172,7 @@ int handle_device(struct domain *d, struct dt_device_node *dev, p2m_type_t p2mt,
                   struct rangeset *iomem_ranges, struct rangeset *irq_ranges);
 
 int handle_device_interrupts(struct domain *d, struct dt_device_node *dev,
-                             bool need_mapping);
+                             bool need_mapping, struct rangeset *irq_ranges);
 
 int map_range_to_domain(const struct dt_device_node *dev,
                         uint64_t addr, uint64_t len, void *data);
-- 
2.17.1



  parent reply	other threads:[~2023-08-25  8:03 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-25  8:02 [XEN][PATCH v10 00/20] dynamic node programming using overlay dtbo Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 01/20] common/device_tree: handle memory allocation failure in __unflatten_device_tree() Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 02/20] common/device_tree.c: unflatten_device_tree() propagate errors Vikram Garhwal
2023-08-28  1:41   ` Henry Wang
2023-08-29  7:09   ` Michal Orzel
2023-08-29 22:24   ` Stefano Stabellini
2023-08-25  8:02 ` [XEN][PATCH v10 03/20] xen/arm/device: Remove __init from function type Vikram Garhwal
2023-08-28  1:53   ` Henry Wang
2023-08-28 16:21     ` Vikram Garhwal
2023-08-29  7:17   ` Michal Orzel
2023-08-30 17:16     ` Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 04/20] common/device_tree: Export __unflatten_device_tree() Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 05/20] xen/arm: Add CONFIG_OVERLAY_DTB Vikram Garhwal
2023-08-29  7:23   ` Michal Orzel
2023-08-30 17:16     ` Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 06/20] libfdt: Keep fdt functions after init for CONFIG_OVERLAY_DTB Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 07/20] libfdt: overlay: change overlay_get_target() Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 08/20] xen/device-tree: Add device_tree_find_node_by_path() to find nodes in device tree Vikram Garhwal
2023-08-28  1:59   ` Henry Wang
2023-08-29  7:41   ` Michal Orzel
2023-08-29 22:27   ` Stefano Stabellini
2023-08-25  8:02 ` [XEN][PATCH v10 09/20] xen/iommu: Move spin_lock from iommu_dt_device_is_assigned to caller Vikram Garhwal
2023-08-29  8:05   ` Michal Orzel
2023-08-30 17:20     ` Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 10/20] xen/iommu: protect iommu_add_dt_device() with dtdevs_lock Vikram Garhwal
2023-08-28 16:29   ` Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 11/20] xen/iommu: Introduce iommu_remove_dt_device() Vikram Garhwal
2023-08-29  8:23   ` Michal Orzel
2023-08-30 17:48     ` Vikram Garhwal
2023-08-31  0:35       ` Stefano Stabellini
2023-08-31  7:23       ` Michal Orzel
2023-08-31  7:32         ` Michal Orzel
2023-09-01  2:01           ` Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 12/20] xen/smmu: Add remove_device callback for smmu_iommu ops Vikram Garhwal
2023-08-29  8:51   ` Michal Orzel
2023-08-29 22:45     ` Stefano Stabellini
2023-08-30  9:17       ` Michal Orzel
2023-08-25  8:02 ` [XEN][PATCH v10 13/20] asm/smp.h: Fix circular dependency for device_tree.h and rwlock.h Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 14/20] common/device_tree: Add rwlock for dt_host Vikram Garhwal
2023-08-28 16:26   ` Vikram Garhwal
2023-08-29  9:27   ` Michal Orzel
2023-08-25  8:02 ` Vikram Garhwal [this message]
2023-08-29 12:16   ` [XEN][PATCH v10 15/20] arm/asm/setup.h: Update struct map_range_data to add rangeset Michal Orzel
2023-08-25  8:02 ` [XEN][PATCH v10 16/20] xen/arm: Implement device tree node removal functionalities Vikram Garhwal
2023-08-29 23:45   ` Stefano Stabellini
2023-08-25  8:02 ` [XEN][PATCH v10 17/20] xen/arm: Implement device tree node addition functionalities Vikram Garhwal
2023-08-29 23:45   ` Stefano Stabellini
2023-08-25  8:02 ` [XEN][PATCH v10 18/20] tools/libs/ctrl: Implement new xc interfaces for dt overlay Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 19/20] tools/libs/light: Implement new libxl functions for device tree overlay ops Vikram Garhwal
2023-08-25  8:02 ` [XEN][PATCH v10 20/20] tools/xl: Add new xl command overlay for device tree overlay support Vikram Garhwal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230825080222.14247-16-vikram.garhwal@amd.com \
    --to=vikram.garhwal@amd.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=bertrand.marquis@arm.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.