From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Jean-Philippe Brucker <jean-philippe@linaro.org>,
Peter Xu <peterx@redhat.com>, Eric Auger <eric.auger@redhat.com>
Subject: [PULL v2 13/30] virtio-iommu: Decode the command payload
Date: Wed, 26 Feb 2020 04:06:41 -0500 [thread overview]
Message-ID: <20200226090010.708934-14-mst@redhat.com> (raw)
In-Reply-To: <20200226090010.708934-1-mst@redhat.com>
From: Eric Auger <eric.auger@redhat.com>
This patch adds the command payload decoding and
introduces the functions that will do the actual
command handling. Those functions are not yet implemented.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Message-Id: <20200214132745.23392-3-eric.auger@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/virtio/virtio-iommu.c | 76 +++++++++++++++++++++++++++++++++-------
hw/virtio/trace-events | 4 +++
2 files changed, 68 insertions(+), 12 deletions(-)
diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index 30579267d5..86dcdc09a1 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -34,31 +34,83 @@
/* Max size */
#define VIOMMU_DEFAULT_QUEUE_SIZE 256
-static int virtio_iommu_handle_attach(VirtIOIOMMU *s,
- struct iovec *iov,
- unsigned int iov_cnt)
+static int virtio_iommu_attach(VirtIOIOMMU *s,
+ struct virtio_iommu_req_attach *req)
{
+ uint32_t domain_id = le32_to_cpu(req->domain);
+ uint32_t ep_id = le32_to_cpu(req->endpoint);
+
+ trace_virtio_iommu_attach(domain_id, ep_id);
+
return VIRTIO_IOMMU_S_UNSUPP;
}
-static int virtio_iommu_handle_detach(VirtIOIOMMU *s,
- struct iovec *iov,
- unsigned int iov_cnt)
+
+static int virtio_iommu_detach(VirtIOIOMMU *s,
+ struct virtio_iommu_req_detach *req)
{
+ uint32_t domain_id = le32_to_cpu(req->domain);
+ uint32_t ep_id = le32_to_cpu(req->endpoint);
+
+ trace_virtio_iommu_detach(domain_id, ep_id);
+
return VIRTIO_IOMMU_S_UNSUPP;
}
-static int virtio_iommu_handle_map(VirtIOIOMMU *s,
- struct iovec *iov,
- unsigned int iov_cnt)
+
+static int virtio_iommu_map(VirtIOIOMMU *s,
+ struct virtio_iommu_req_map *req)
{
+ uint32_t domain_id = le32_to_cpu(req->domain);
+ uint64_t phys_start = le64_to_cpu(req->phys_start);
+ uint64_t virt_start = le64_to_cpu(req->virt_start);
+ uint64_t virt_end = le64_to_cpu(req->virt_end);
+ uint32_t flags = le32_to_cpu(req->flags);
+
+ trace_virtio_iommu_map(domain_id, virt_start, virt_end, phys_start, flags);
+
return VIRTIO_IOMMU_S_UNSUPP;
}
-static int virtio_iommu_handle_unmap(VirtIOIOMMU *s,
- struct iovec *iov,
- unsigned int iov_cnt)
+
+static int virtio_iommu_unmap(VirtIOIOMMU *s,
+ struct virtio_iommu_req_unmap *req)
{
+ uint32_t domain_id = le32_to_cpu(req->domain);
+ uint64_t virt_start = le64_to_cpu(req->virt_start);
+ uint64_t virt_end = le64_to_cpu(req->virt_end);
+
+ trace_virtio_iommu_unmap(domain_id, virt_start, virt_end);
+
return VIRTIO_IOMMU_S_UNSUPP;
}
+static int virtio_iommu_iov_to_req(struct iovec *iov,
+ unsigned int iov_cnt,
+ void *req, size_t req_sz)
+{
+ size_t sz, payload_sz = req_sz - sizeof(struct virtio_iommu_req_tail);
+
+ sz = iov_to_buf(iov, iov_cnt, 0, req, payload_sz);
+ if (unlikely(sz != payload_sz)) {
+ return VIRTIO_IOMMU_S_INVAL;
+ }
+ return 0;
+}
+
+#define virtio_iommu_handle_req(__req) \
+static int virtio_iommu_handle_ ## __req(VirtIOIOMMU *s, \
+ struct iovec *iov, \
+ unsigned int iov_cnt) \
+{ \
+ struct virtio_iommu_req_ ## __req req; \
+ int ret = virtio_iommu_iov_to_req(iov, iov_cnt, &req, sizeof(req)); \
+ \
+ return ret ? ret : virtio_iommu_ ## __req(s, &req); \
+}
+
+virtio_iommu_handle_req(attach)
+virtio_iommu_handle_req(detach)
+virtio_iommu_handle_req(map)
+virtio_iommu_handle_req(unmap)
+
static void virtio_iommu_handle_command(VirtIODevice *vdev, VirtQueue *vq)
{
VirtIOIOMMU *s = VIRTIO_IOMMU(vdev);
diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events
index 02d93d7f63..f7141aa2f6 100644
--- a/hw/virtio/trace-events
+++ b/hw/virtio/trace-events
@@ -60,3 +60,7 @@ virtio_iommu_get_features(uint64_t features) "device supports features=0x%"PRIx6
virtio_iommu_device_status(uint8_t status) "driver status = %d"
virtio_iommu_get_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint32_t domain_range, uint32_t probe_size) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" domain_range=%d probe_size=0x%x"
virtio_iommu_set_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint32_t domain_range, uint32_t probe_size) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" domain_bits=%d probe_size=0x%x"
+virtio_iommu_attach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d"
+virtio_iommu_detach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d"
+virtio_iommu_map(uint32_t domain_id, uint64_t virt_start, uint64_t virt_end, uint64_t phys_start, uint32_t flags) "domain=%d virt_start=0x%"PRIx64" virt_end=0x%"PRIx64 " phys_start=0x%"PRIx64" flags=%d"
+virtio_iommu_unmap(uint32_t domain_id, uint64_t virt_start, uint64_t virt_end) "domain=%d virt_start=0x%"PRIx64" virt_end=0x%"PRIx64
--
MST
next prev parent reply other threads:[~2020-02-26 9:09 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-26 9:00 [PULL v2 00/30] virtio, pc: fixes, features Michael S. Tsirkin
2020-02-26 9:01 ` [PULL v2 01/30] bios-tables-test: tell people how to update Michael S. Tsirkin
2020-02-26 9:01 ` [PULL v2 02/30] bios-tables-test: fix up DIFF generation Michael S. Tsirkin
2020-02-26 9:01 ` [PULL v2 03/30] bios-tables-test: default diff command Michael S. Tsirkin
2020-02-26 9:01 ` [PULL v2 04/30] rebuild-expected-aml.sh: remind about the process Michael S. Tsirkin
2020-02-26 9:01 ` [PULL v2 05/30] vhost-user-fs: do delete virtio_queues in unrealize Michael S. Tsirkin
2020-02-26 9:01 ` [PULL v2 06/30] vhost-user-fs: convert to the new virtio_delete_queue function Michael S. Tsirkin
2020-02-26 9:01 ` [PULL v2 07/30] virtio-pmem: do delete rq_vq in virtio_pmem_unrealize Michael S. Tsirkin
2020-02-26 9:06 ` [PULL v2 08/30] virtio-crypto: do delete ctrl_vq in virtio_crypto_device_unrealize Michael S. Tsirkin
2020-02-26 9:06 ` [PULL v2 09/30] vhost-user-blk: delete virtioqueues in unrealize to fix memleaks Michael S. Tsirkin
2020-02-26 9:06 ` [PULL v2 10/30] vhost-user-blk: convert to new virtio_delete_queue Michael S. Tsirkin
2020-02-26 9:06 ` [PULL v2 11/30] virtio: gracefully handle invalid region caches Michael S. Tsirkin
2020-02-26 9:06 ` [PULL v2 12/30] virtio-iommu: Add skeleton Michael S. Tsirkin
2020-02-26 9:06 ` Michael S. Tsirkin [this message]
2020-02-26 9:06 ` [PULL v2 14/30] virtio-iommu: Implement attach/detach command Michael S. Tsirkin
2020-02-26 9:06 ` [PULL v2 15/30] virtio-iommu: Implement map/unmap Michael S. Tsirkin
2020-02-26 9:06 ` [PULL v2 16/30] virtio-iommu: Implement translate Michael S. Tsirkin
2020-02-26 9:07 ` [PULL v2 17/30] virtio-iommu: Implement fault reporting Michael S. Tsirkin
2020-02-26 9:07 ` [PULL v2 18/30] virtio-iommu: Support migration Michael S. Tsirkin
2020-02-26 9:07 ` [PULL v2 19/30] virtio-iommu-pci: Add virtio iommu pci support Michael S. Tsirkin
2020-02-26 9:07 ` [PULL v2 20/30] hw/arm/virt: Add the virtio-iommu device tree mappings Michael S. Tsirkin
2020-02-26 9:07 ` [PULL v2 21/30] MAINTAINERS: add virtio-iommu related files Michael S. Tsirkin
2020-02-26 9:07 ` [PULL v2 22/30] libvhost-user: implement VHOST_USER_PROTOCOL_F_REPLY_ACK Michael S. Tsirkin
2020-02-26 9:07 ` [PULL v2 23/30] libvhost-user-glib: fix VugDev main fd cleanup Michael S. Tsirkin
2020-02-26 9:07 ` [PULL v2 24/30] libvhost-user-glib: use g_main_context_get_thread_default() Michael S. Tsirkin
2020-02-26 9:07 ` [PULL v2 25/30] libvhost-user: handle NOFD flag in call/kick/err better Michael S. Tsirkin
2020-02-26 9:07 ` [PULL v2 26/30] docs: vhost-user: add in-band kick/call messages Michael S. Tsirkin
2020-02-26 9:07 ` [PULL v2 27/30] libvhost-user: implement in-band notifications Michael S. Tsirkin
2020-02-26 9:07 ` [PULL v2 28/30] acpi: cpuhp: document CPHP_GET_CPU_ID_CMD command Michael S. Tsirkin
2020-02-26 9:07 ` [PULL v2 29/30] vhost-user: only set slave channel for first vq Michael S. Tsirkin
2020-02-26 9:08 ` [PULL v2 30/30] Fixed assert in vhost_user_set_mem_table_postcopy Michael S. Tsirkin
2020-02-27 8:54 ` [PULL v2 00/30] virtio, pc: fixes, features Michael S. Tsirkin
2020-02-27 19:56 ` Peter Maydell
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=20200226090010.708934-14-mst@redhat.com \
--to=mst@redhat.com \
--cc=eric.auger@redhat.com \
--cc=jean-philippe@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).