101 lines
4.3 KiB
Diff
101 lines
4.3 KiB
Diff
|
|
From 207259b8f08e87b4a741a8b7884e699c95641a2e Mon Sep 17 00:00:00 2001
|
||
|
|
From: Nicolin Chen <nicolinc@nvidia.com>
|
||
|
|
Date: Sat, 13 Apr 2024 00:15:17 +0000
|
||
|
|
Subject: [PATCH] backends/iommufd: Introduce iommufd_backend_alloc_viommu
|
||
|
|
|
||
|
|
Add a helper to allocate a viommu object.
|
||
|
|
|
||
|
|
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
|
||
|
|
---
|
||
|
|
backends/iommufd.c | 35 +++++++++++++++++++++++++++++++++++
|
||
|
|
backends/trace-events | 1 +
|
||
|
|
include/sysemu/iommufd.h | 10 ++++++++++
|
||
|
|
3 files changed, 46 insertions(+)
|
||
|
|
|
||
|
|
diff --git a/backends/iommufd.c b/backends/iommufd.c
|
||
|
|
index c10aa9b011..82368a3918 100644
|
||
|
|
--- a/backends/iommufd.c
|
||
|
|
+++ b/backends/iommufd.c
|
||
|
|
@@ -360,6 +360,41 @@ int iommufd_backend_invalidate_cache(IOMMUFDBackend *be, uint32_t hwpt_id,
|
||
|
|
return ret;
|
||
|
|
}
|
||
|
|
|
||
|
|
+struct IOMMUFDViommu *iommufd_backend_alloc_viommu(IOMMUFDBackend *be,
|
||
|
|
+ uint32_t dev_id,
|
||
|
|
+ uint32_t viommu_type,
|
||
|
|
+ uint32_t hwpt_id)
|
||
|
|
+{
|
||
|
|
+ int ret, fd = be->fd;
|
||
|
|
+ struct IOMMUFDViommu *viommu = g_malloc(sizeof(*viommu));
|
||
|
|
+ struct iommu_viommu_alloc alloc_viommu = {
|
||
|
|
+ .size = sizeof(alloc_viommu),
|
||
|
|
+ .type = viommu_type,
|
||
|
|
+ .dev_id = dev_id,
|
||
|
|
+ .hwpt_id = hwpt_id,
|
||
|
|
+ };
|
||
|
|
+
|
||
|
|
+ if (!viommu) {
|
||
|
|
+ error_report("failed to allocate viommu object");
|
||
|
|
+ return NULL;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ ret = ioctl(fd, IOMMU_VIOMMU_ALLOC, &alloc_viommu);
|
||
|
|
+
|
||
|
|
+ trace_iommufd_backend_alloc_viommu(fd, viommu_type, dev_id, hwpt_id,
|
||
|
|
+ alloc_viommu.out_viommu_id, ret);
|
||
|
|
+ if (ret) {
|
||
|
|
+ error_report("IOMMU_VIOMMU_ALLOC failed: %s", strerror(errno));
|
||
|
|
+ g_free(viommu);
|
||
|
|
+ return NULL;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ viommu->viommu_id = alloc_viommu.out_viommu_id;
|
||
|
|
+ viommu->s2_hwpt_id = hwpt_id;
|
||
|
|
+ viommu->iommufd = be;
|
||
|
|
+ return viommu;
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *idev,
|
||
|
|
uint32_t hwpt_id, Error **errp)
|
||
|
|
{
|
||
|
|
diff --git a/backends/trace-events b/backends/trace-events
|
||
|
|
index ef0ff98921..c24cd378df 100644
|
||
|
|
--- a/backends/trace-events
|
||
|
|
+++ b/backends/trace-events
|
||
|
|
@@ -19,3 +19,4 @@ iommufd_backend_free_id(int iommufd, uint32_t id, int ret) " iommufd=%d id=%d (%
|
||
|
|
iommufd_backend_set_dirty(int iommufd, uint32_t hwpt_id, bool start, int ret) " iommufd=%d hwpt=%u enable=%d (%d)"
|
||
|
|
iommufd_backend_get_dirty_bitmap(int iommufd, uint32_t hwpt_id, uint64_t iova, uint64_t size, uint64_t page_size, int ret) " iommufd=%d hwpt=%u iova=0x%"PRIx64" size=0x%"PRIx64" page_size=0x%"PRIx64" (%d)"
|
||
|
|
iommufd_backend_invalidate_cache(int iommufd, uint32_t hwpt_id, uint32_t data_type, uint32_t entry_len, uint32_t entry_num, uint32_t done_num, uint64_t data_ptr, int ret) " iommufd=%d hwpt_id=%u data_type=%u entry_len=%u entry_num=%u done_num=%u data_ptr=0x%"PRIx64" (%d)"
|
||
|
|
+iommufd_backend_alloc_viommu(int iommufd, uint32_t type, uint32_t dev_id, uint32_t hwpt_id, uint32_t viommu_id, int ret) " iommufd=%d type=%u dev_id=%u hwpt_id=%u viommu_id=%u (%d)"
|
||
|
|
diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h
|
||
|
|
index 3dc6934144..05a08c49c2 100644
|
||
|
|
--- a/include/sysemu/iommufd.h
|
||
|
|
+++ b/include/sysemu/iommufd.h
|
||
|
|
@@ -39,6 +39,12 @@ struct IOMMUFDBackend {
|
||
|
|
/*< public >*/
|
||
|
|
};
|
||
|
|
|
||
|
|
+typedef struct IOMMUFDViommu {
|
||
|
|
+ IOMMUFDBackend *iommufd;
|
||
|
|
+ uint32_t s2_hwpt_id;
|
||
|
|
+ uint32_t viommu_id;
|
||
|
|
+} IOMMUFDViommu;
|
||
|
|
+
|
||
|
|
int iommufd_backend_connect(IOMMUFDBackend *be, Error **errp);
|
||
|
|
void iommufd_backend_disconnect(IOMMUFDBackend *be);
|
||
|
|
|
||
|
|
@@ -66,6 +72,10 @@ bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be, uint32_t hwpt_id,
|
||
|
|
int iommufd_backend_invalidate_cache(IOMMUFDBackend *be, uint32_t hwpt_id,
|
||
|
|
uint32_t data_type, uint32_t entry_len,
|
||
|
|
uint32_t *entry_num, void *data_ptr);
|
||
|
|
+struct IOMMUFDViommu *iommufd_backend_alloc_viommu(IOMMUFDBackend *be,
|
||
|
|
+ uint32_t dev_id,
|
||
|
|
+ uint32_t viommu_type,
|
||
|
|
+ uint32_t hwpt_id);
|
||
|
|
|
||
|
|
#define TYPE_HOST_IOMMU_DEVICE_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd"
|
||
|
|
OBJECT_DECLARE_TYPE(HostIOMMUDeviceIOMMUFD, HostIOMMUDeviceIOMMUFDClass,
|
||
|
|
--
|
||
|
|
2.41.0.windows.1
|
||
|
|
|