All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mykyta Poturai <Mykyta_Poturai@epam.com>
To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: Mykyta Poturai <Mykyta_Poturai@epam.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>,
	Bertrand Marquis <bertrand.marquis@arm.com>,
	Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>,
	Michal Orzel <michal.orzel@amd.com>
Subject: [XEN PATCH v2 15/25] arm: new VGIC: its: Introduce ITS device list
Date: Fri, 10 Nov 2023 12:56:21 +0000	[thread overview]
Message-ID: <0bbd5eb62605243e1ea437e8ca113f8851b1e49e.1699618395.git.mykyta_poturai@epam.com> (raw)
In-Reply-To: <cover.1699618395.git.mykyta_poturai@epam.com>

Add the vgic_its_device structure and the list of devices to the vgic_its.
Implement the functions to allocate, free, add and delete the device from
the list. Add the function to find the device in the list by the device id.
And make them avaliable to the HW ITS code.

Signed-off-by: Mykyta Poturai <mykyta_poturai@epam.com>
---
 xen/arch/arm/include/asm/new_vgic.h | 27 +++++++++
 xen/arch/arm/vgic/vgic-its.c        | 86 +++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+)

diff --git a/xen/arch/arm/include/asm/new_vgic.h b/xen/arch/arm/include/asm/new_vgic.h
index ec2882dcf1..00a5557921 100644
--- a/xen/arch/arm/include/asm/new_vgic.h
+++ b/xen/arch/arm/include/asm/new_vgic.h
@@ -122,9 +122,26 @@ struct vgic_its {
 
     bool enabled;
     struct vgic_io_device iodev;
+    struct list_head device_list;
     paddr_t doorbell_address;
 };
 
+struct vgic_its_device {
+    struct list_head dev_list;
+    struct domain *d;
+
+    /* the head for the list of ITTEs */
+    struct list_head itt_head;
+    u32 num_eventid_bits;
+    void* itt_addr;
+    struct host_its *hw_its;
+    paddr_t guest_doorbell;             /* Identifies the virtual ITS */
+    uint32_t host_devid;
+    uint32_t guest_devid;
+    uint32_t eventids;                  /* Number of event IDs (MSIs) */
+    uint32_t *host_lpi_blocks;          /* Which LPIs are used on the host */
+};
+
 struct vgic_dist {
     bool                ready;
     bool                initialized;
@@ -171,6 +188,7 @@ struct vgic_dist {
      * GICv3 spec: 6.1.2 "LPI Configuration tables"
      */
     uint64_t            propbaser;
+    spinlock_t          its_devices_lock; /* Protects the its_devices list */
 
     /* Protects the lpi_list and the count value below. */
     spinlock_t          lpi_list_lock;
@@ -227,6 +245,15 @@ static inline paddr_t vgic_dist_base(const struct vgic_dist *vgic)
     return vgic->dbase;
 }
 
+#ifdef CONFIG_HAS_ITS
+struct vgic_its_device *vgic_its_alloc_device(int nr_events);
+void vgic_its_free_device(struct vgic_its_device *its_dev);
+int vgic_its_add_device(struct domain *d, struct vgic_its_device *its_dev);
+void vgic_its_delete_device(struct domain *d, struct vgic_its_device *its_dev);
+struct vgic_its_device* vgic_its_get_device(struct domain *d, paddr_t vdoorbell,
+                                         uint32_t vdevid);
+#endif
+
 #endif /* __ASM_ARM_NEW_VGIC_H */
 
 /*
diff --git a/xen/arch/arm/vgic/vgic-its.c b/xen/arch/arm/vgic/vgic-its.c
index 0ae6048456..3eceadaa79 100644
--- a/xen/arch/arm/vgic/vgic-its.c
+++ b/xen/arch/arm/vgic/vgic-its.c
@@ -33,6 +33,92 @@ static unsigned long its_mmio_read_raz(struct domain *d, struct vgic_its *its,
     return 0;
 }
 
+/*
+ * Find and returns a device in the device table for an ITS.
+ * Must be called with the its_devices_lock mutex held.
+ */
+static struct vgic_its_device *find_its_device(struct vgic_its *its, u32 device_id)
+{
+    struct vgic_its_device *device;
+
+    list_for_each_entry(device, &its->device_list, dev_list)
+        if ( device_id == device->guest_devid )
+            return device;
+
+    return NULL;
+}
+
+/* Requires the its_devices_lock to be held. */
+void vgic_its_free_device(struct vgic_its_device *device)
+{
+    struct domain *d = device->d;
+    
+    BUG_ON(!d);
+    list_del(&device->dev_list);
+    xfree(device);
+}
+
+/* Must be called with its_devices_lock mutex held */
+struct vgic_its_device* vgic_its_get_device(struct domain *d, paddr_t vdoorbell,
+                                         uint32_t vdevid)
+{
+    struct vgic_its *its = d->arch.vgic.its;
+    struct vgic_its_device *device;
+
+    if ( !its )
+        return NULL;
+
+    device = find_its_device(its, vdevid);
+    if ( !device )
+        return NULL;
+
+    return device;
+}
+
+/* Must be called with its_devices_lock mutex held */
+struct vgic_its_device *vgic_its_alloc_device(int nr_events)
+{
+    struct vgic_its_device *device;
+
+    device = xzalloc(struct vgic_its_device);
+    if ( !device )
+        goto fail;
+
+    INIT_LIST_HEAD(&device->itt_head);
+
+    device->host_lpi_blocks = xzalloc_array(uint32_t, nr_events);
+    if ( !device->host_lpi_blocks )
+        goto fail_host_lpi;
+
+    return device;
+fail_host_lpi:
+    xfree(device);
+fail:
+    return NULL;
+}
+
+/* Must be called with its_devices_lock mutex held */
+int vgic_its_add_device(struct domain *d, struct vgic_its_device *its_dev)
+{
+    struct vgic_its *its = d->arch.vgic.its;
+    if ( !its )
+        return -EINVAL;
+
+    list_add_tail(&its_dev->dev_list, &its->device_list);
+
+    return 0;
+}
+
+/* Must be called with its_devices_lock mutex held */
+void vgic_its_delete_device(struct domain *d, struct vgic_its_device *its_dev)
+{
+    struct vgic_its *its = d->arch.vgic.its;
+    if ( !its )
+        return;
+
+    list_del(&its_dev->dev_list);
+}
+
 static void its_mmio_write_wi(struct domain *d, struct vgic_its *its,
                               paddr_t addr, unsigned int len, unsigned long val)
 {
-- 
2.34.1


  parent reply	other threads:[~2023-11-10 12:57 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-10 12:56 [XEN PATCH v2 00/25] arm: Add GICv3 support to the New VGIC Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 01/25] arm: vgic: its: Decouple HW and virtual ITS Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 02/25] arm: new VGIC: Add GICv3 world switch backend Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 03/25] arm: new VGIC: Add GICv3 MMIO handling framework Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 04/25] arm: new VGIC: Add GICv3 CTLR, IIDR, TYPER handlers Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 05/25] arm: new VGIC: Add GICv3 redistributor IIDR and TYPER handler Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 08/25] arm: new VGIC: Add GICv3 SGI system register trap handler Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 07/25] arm: new VGIC: Add GICv3 IROUTER register handlers Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 06/25] arm: new VGIC: Add GICv3 IDREGS register handler Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 10/25] arm: new VGIC: Add vgic_v3_enable Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 11/25] arm: new VGIC: Add alternative redist region storage Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 09/25] arm: new VGIC: vgic_init: implement map_resources Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 14/25] arm: new VGIC: its: Introduce ITS emulation file with MMIO framework Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 13/25] arm: new VGIC: Handle ITS related GICv3 redistributor registers Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 12/25] arm: new VGIC: Wire new GICv3 into the build system Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 17/25] arm: new VGIC: its: Read initial LPI pending table Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 16/25] arm: new VGIC: its: Implement basic ITS register handlers Mykyta Poturai
2023-11-10 12:56 ` Mykyta Poturai [this message]
2023-11-10 12:56 ` [XEN PATCH v2 20/25] arm: new VGIC: its: Implement ITS command queue command handlers Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 18/25] arm: new VGIC: its: Allow updates of LPI configuration table Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 19/25] arm: new VGIC: its: Add LPI translation cache definition Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 23/25] arm: new VGIC: its: Enable ITS emulation as a virtual MSI controller Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 22/25] arm: new VGIC: its: Implement MMIO-based LPI invalidation Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 21/25] arm: new VGIC: its: Implement MSI injection in ITS emulation Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 25/25] arm: new VGIC: Improve MMIO handling Mykyta Poturai
2023-11-10 12:56 ` [XEN PATCH v2 24/25] arm: new VGIC: its: Wire new ITS into the build system Mykyta Poturai

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=0bbd5eb62605243e1ea437e8ca113f8851b1e49e.1699618395.git.mykyta_poturai@epam.com \
    --to=mykyta_poturai@epam.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.