It calls iommufd_backend_get_device_info() to get host IOMMU
related information.
Define a common structure HIOD_IOMMUFD_INFO to describe the info
returned from kernel. Currently only vtd, but easy to add arm smmu
when kernel supports.
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
include/sysemu/iommufd.h | 7 +++++++
backends/iommufd.c | 17 +++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h
index fa1a866237..44ec1335b2 100644
--- a/include/sysemu/iommufd.h
+++ b/include/sysemu/iommufd.h
@@ -39,6 +39,13 @@ int iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid,
enum iommu_hw_info_type *type,
void *data, uint32_t len, Error **errp);
+typedef struct HIOD_IOMMUFD_INFO {
+ enum iommu_hw_info_type type;
+ union {
+ struct iommu_hw_info_vtd vtd;
+ } data;
+} HIOD_IOMMUFD_INFO;
+
#define TYPE_HIOD_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd"
OBJECT_DECLARE_TYPE(HIODIOMMUFD, HIODIOMMUFDClass, HIOD_IOMMUFD)
diff --git a/backends/iommufd.c b/backends/iommufd.c
index 559affa9ec..1e9c469e65 100644
--- a/backends/iommufd.c
+++ b/backends/iommufd.c
@@ -240,8 +240,25 @@ void hiod_iommufd_init(HIODIOMMUFD *idev, IOMMUFDBackend *iommufd,
idev->devid = devid;
}
+static int hiod_iommufd_get_host_iommu_info(HostIOMMUDevice *hiod,
+ void *data, uint32_t len,
+ Error **errp)
+{
+ HIODIOMMUFD *idev = HIOD_IOMMUFD(hiod);
+ HIOD_IOMMUFD_INFO *info = data;
+
+ assert(sizeof(HIOD_IOMMUFD_INFO) <= len);
+
+ return iommufd_backend_get_device_info(idev->iommufd, idev->devid,
+ &info->type, &info->data,
+ sizeof(info->data), errp);
+}
+
static void hiod_iommufd_class_init(ObjectClass *oc, void *data)
{
+ HostIOMMUDeviceClass *hiodc = HOST_IOMMU_DEVICE_CLASS(oc);
+
+ hiodc->get_host_iommu_info = hiod_iommufd_get_host_iommu_info;
}
static const TypeInfo types[] = {
--
2.34.1
On 4/8/24 10:12, Zhenzhong Duan wrote:
> It calls iommufd_backend_get_device_info() to get host IOMMU
> related information.
>
> Define a common structure HIOD_IOMMUFD_INFO to describe the info
> returned from kernel. Currently only vtd, but easy to add arm smmu
> when kernel supports.
I think you can merge the previous patch and this one.
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> ---
> include/sysemu/iommufd.h | 7 +++++++
> backends/iommufd.c | 17 +++++++++++++++++
> 2 files changed, 24 insertions(+)
>
> diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h
> index fa1a866237..44ec1335b2 100644
> --- a/include/sysemu/iommufd.h
> +++ b/include/sysemu/iommufd.h
I just noticed that include/sysemu/iommufd.h lacks a header. Could you fix
that please ?
> @@ -39,6 +39,13 @@ int iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid,
> enum iommu_hw_info_type *type,
> void *data, uint32_t len, Error **errp);
>
> +typedef struct HIOD_IOMMUFD_INFO {
Please use CamelCase names.
Thanks,
C.
> + enum iommu_hw_info_type type;
> + union {
> + struct iommu_hw_info_vtd vtd;
> + } data;
> +} HIOD_IOMMUFD_INFO;
> +
> #define TYPE_HIOD_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd"
> OBJECT_DECLARE_TYPE(HIODIOMMUFD, HIODIOMMUFDClass, HIOD_IOMMUFD)
>
> diff --git a/backends/iommufd.c b/backends/iommufd.c
> index 559affa9ec..1e9c469e65 100644
> --- a/backends/iommufd.c
> +++ b/backends/iommufd.c
> @@ -240,8 +240,25 @@ void hiod_iommufd_init(HIODIOMMUFD *idev, IOMMUFDBackend *iommufd,
> idev->devid = devid;
> }
>
> +static int hiod_iommufd_get_host_iommu_info(HostIOMMUDevice *hiod,
> + void *data, uint32_t len,
> + Error **errp)
> +{
> + HIODIOMMUFD *idev = HIOD_IOMMUFD(hiod);
> + HIOD_IOMMUFD_INFO *info = data;
> +
> + assert(sizeof(HIOD_IOMMUFD_INFO) <= len);
> +
> + return iommufd_backend_get_device_info(idev->iommufd, idev->devid,
> + &info->type, &info->data,
> + sizeof(info->data), errp);
> +}
> +
> static void hiod_iommufd_class_init(ObjectClass *oc, void *data)
> {
> + HostIOMMUDeviceClass *hiodc = HOST_IOMMU_DEVICE_CLASS(oc);
> +
> + hiodc->get_host_iommu_info = hiod_iommufd_get_host_iommu_info;
> }
>
> static const TypeInfo types[] = {
>-----Original Message-----
>From: Cédric Le Goater <clg@redhat.com>
>Subject: Re: [PATCH v2 07/10] backends/iommufd: Implement
>get_host_iommu_info() callback
>
>On 4/8/24 10:12, Zhenzhong Duan wrote:
>> It calls iommufd_backend_get_device_info() to get host IOMMU
>> related information.
>>
>> Define a common structure HIOD_IOMMUFD_INFO to describe the info
>> returned from kernel. Currently only vtd, but easy to add arm smmu
>> when kernel supports.
>
>I think you can merge the previous patch and this one.
Sure.
>
>
>> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
>> ---
>> include/sysemu/iommufd.h | 7 +++++++
>> backends/iommufd.c | 17 +++++++++++++++++
>> 2 files changed, 24 insertions(+)
>>
>> diff --git a/include/sysemu/iommufd.h b/include/sysemu/iommufd.h
>> index fa1a866237..44ec1335b2 100644
>> --- a/include/sysemu/iommufd.h
>> +++ b/include/sysemu/iommufd.h
>
>I just noticed that include/sysemu/iommufd.h lacks a header. Could you fix
>that please ?
Sure. Presume you means the copyright header. Fix me if you mean others.
>
>> @@ -39,6 +39,13 @@ int
>iommufd_backend_get_device_info(IOMMUFDBackend *be, uint32_t devid,
>> enum iommu_hw_info_type *type,
>> void *data, uint32_t len, Error **errp);
>>
>> +typedef struct HIOD_IOMMUFD_INFO {
>
>Please use CamelCase names.
Sure.
Thanks
Zhenzhong
>
>
>Thanks,
>
>C.
>
>
>> + enum iommu_hw_info_type type;
>> + union {
>> + struct iommu_hw_info_vtd vtd;
>> + } data;
>> +} HIOD_IOMMUFD_INFO;
>> +
>> #define TYPE_HIOD_IOMMUFD TYPE_HOST_IOMMU_DEVICE "-iommufd"
>> OBJECT_DECLARE_TYPE(HIODIOMMUFD, HIODIOMMUFDClass,
>HIOD_IOMMUFD)
>>
>> diff --git a/backends/iommufd.c b/backends/iommufd.c
>> index 559affa9ec..1e9c469e65 100644
>> --- a/backends/iommufd.c
>> +++ b/backends/iommufd.c
>> @@ -240,8 +240,25 @@ void hiod_iommufd_init(HIODIOMMUFD *idev,
>IOMMUFDBackend *iommufd,
>> idev->devid = devid;
>> }
>>
>> +static int hiod_iommufd_get_host_iommu_info(HostIOMMUDevice
>*hiod,
>> + void *data, uint32_t len,
>> + Error **errp)
>> +{
>> + HIODIOMMUFD *idev = HIOD_IOMMUFD(hiod);
>> + HIOD_IOMMUFD_INFO *info = data;
>> +
>> + assert(sizeof(HIOD_IOMMUFD_INFO) <= len);
>> +
>> + return iommufd_backend_get_device_info(idev->iommufd, idev-
>>devid,
>> + &info->type, &info->data,
>> + sizeof(info->data), errp);
>> +}
>> +
>> static void hiod_iommufd_class_init(ObjectClass *oc, void *data)
>> {
>> + HostIOMMUDeviceClass *hiodc = HOST_IOMMU_DEVICE_CLASS(oc);
>> +
>> + hiodc->get_host_iommu_info = hiod_iommufd_get_host_iommu_info;
>> }
>>
>> static const TypeInfo types[] = {
© 2016 - 2026 Red Hat, Inc.