[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH for-5.0 v11 06/20] virtio-iommu: Implement attach/detach command
From: |
Eric Auger |
Subject: |
[PATCH for-5.0 v11 06/20] virtio-iommu: Implement attach/detach command |
Date: |
Fri, 22 Nov 2019 19:29:29 +0100 |
This patch implements the endpoint attach/detach to/from
a domain.
Signed-off-by: Eric Auger <address@hidden>
---
---
hw/virtio/virtio-iommu.c | 43 ++++++++++++++++++++++++++++++++--------
1 file changed, 35 insertions(+), 8 deletions(-)
diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index 235bde2203..138d5b2a9c 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -77,11 +77,12 @@ static gint interval_cmp(gconstpointer a, gconstpointer b,
gpointer user_data)
static void virtio_iommu_detach_endpoint_from_domain(viommu_endpoint *ep)
{
QLIST_REMOVE(ep, next);
+ g_tree_unref(ep->domain->mappings);
ep->domain = NULL;
}
-viommu_endpoint *virtio_iommu_get_endpoint(VirtIOIOMMU *s, uint32_t ep_id);
-viommu_endpoint *virtio_iommu_get_endpoint(VirtIOIOMMU *s, uint32_t ep_id)
+static viommu_endpoint *virtio_iommu_get_endpoint(VirtIOIOMMU *s,
+ uint32_t ep_id)
{
viommu_endpoint *ep;
@@ -102,15 +103,14 @@ static void virtio_iommu_put_endpoint(gpointer data)
if (ep->domain) {
virtio_iommu_detach_endpoint_from_domain(ep);
- g_tree_unref(ep->domain->mappings);
}
trace_virtio_iommu_put_endpoint(ep->id);
g_free(ep);
}
-viommu_domain *virtio_iommu_get_domain(VirtIOIOMMU *s, uint32_t domain_id);
-viommu_domain *virtio_iommu_get_domain(VirtIOIOMMU *s, uint32_t domain_id)
+static viommu_domain *virtio_iommu_get_domain(VirtIOIOMMU *s,
+ uint32_t domain_id)
{
viommu_domain *domain;
@@ -137,7 +137,6 @@ static void virtio_iommu_put_domain(gpointer data)
QLIST_FOREACH_SAFE(iter, &domain->endpoint_list, next, tmp) {
virtio_iommu_detach_endpoint_from_domain(iter);
}
- g_tree_destroy(domain->mappings);
trace_virtio_iommu_put_domain(domain->id);
g_free(domain);
}
@@ -186,10 +185,27 @@ static int virtio_iommu_attach(VirtIOIOMMU *s,
{
uint32_t domain_id = le32_to_cpu(req->domain);
uint32_t ep_id = le32_to_cpu(req->endpoint);
+ viommu_domain *domain;
+ viommu_endpoint *ep;
trace_virtio_iommu_attach(domain_id, ep_id);
- return VIRTIO_IOMMU_S_UNSUPP;
+ ep = virtio_iommu_get_endpoint(s, ep_id);
+ if (ep->domain) {
+ /*
+ * the device is already attached to a domain,
+ * detach it first
+ */
+ virtio_iommu_detach_endpoint_from_domain(ep);
+ }
+
+ domain = virtio_iommu_get_domain(s, domain_id);
+ QLIST_INSERT_HEAD(&domain->endpoint_list, ep, next);
+
+ ep->domain = domain;
+ g_tree_ref(domain->mappings);
+
+ return VIRTIO_IOMMU_S_OK;
}
static int virtio_iommu_detach(VirtIOIOMMU *s,
@@ -197,10 +213,21 @@ static int virtio_iommu_detach(VirtIOIOMMU *s,
{
uint32_t domain_id = le32_to_cpu(req->domain);
uint32_t ep_id = le32_to_cpu(req->endpoint);
+ viommu_endpoint *ep;
trace_virtio_iommu_detach(domain_id, ep_id);
- return VIRTIO_IOMMU_S_UNSUPP;
+ ep = g_tree_lookup(s->endpoints, GUINT_TO_POINTER(ep_id));
+ if (!ep) {
+ return VIRTIO_IOMMU_S_NOENT;
+ }
+
+ if (!ep->domain) {
+ return VIRTIO_IOMMU_S_INVAL;
+ }
+
+ virtio_iommu_detach_endpoint_from_domain(ep);
+ return VIRTIO_IOMMU_S_OK;
}
static int virtio_iommu_map(VirtIOIOMMU *s,
--
2.20.1
- [PATCH for-5.0 v11 00/20] VIRTIO-IOMMU device, Eric Auger, 2019/11/22
- [PATCH for-5.0 v11 01/20] migration: Support QLIST migration, Eric Auger, 2019/11/22
- [PATCH for-5.0 v11 04/20] virtio-iommu: Add the iommu regions, Eric Auger, 2019/11/22
- [PATCH for-5.0 v11 03/20] virtio-iommu: Decode the command payload, Eric Auger, 2019/11/22
- [PATCH for-5.0 v11 02/20] virtio-iommu: Add skeleton, Eric Auger, 2019/11/22
- [PATCH for-5.0 v11 05/20] virtio-iommu: Endpoint and domains structs and helpers, Eric Auger, 2019/11/22
- [PATCH for-5.0 v11 06/20] virtio-iommu: Implement attach/detach command,
Eric Auger <=
- [PATCH for-5.0 v11 07/20] virtio-iommu: Implement map/unmap, Eric Auger, 2019/11/22
- [PATCH for-5.0 v11 08/20] virtio-iommu: Implement translate, Eric Auger, 2019/11/22
- [PATCH for-5.0 v11 09/20] virtio-iommu: Implement fault reporting, Eric Auger, 2019/11/22
- [PATCH for-5.0 v11 10/20] virtio-iommu-pci: Add virtio iommu pci support, Eric Auger, 2019/11/22
- [PATCH for-5.0 v11 11/20] hw/arm/virt: Add the virtio-iommu device tree mappings, Eric Auger, 2019/11/22
- [PATCH for-5.0 v11 12/20] qapi: Introduce DEFINE_PROP_INTERVAL, Eric Auger, 2019/11/22
- [PATCH for-5.0 v11 13/20] virtio-iommu: Implement probe request, Eric Auger, 2019/11/22
- [PATCH for-5.0 v11 14/20] virtio-iommu: Handle reserved regions in the translation process, Eric Auger, 2019/11/22