[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC PATCH 5/23] Tools/libxc: Add viommu operations in libxc
From: Chao Gao <chao.gao@xxxxxxxxx> In previous patch, we introduce a common vIOMMU layer. In our design, we create/destroy vIOMMU through DMOP interface instead of creating it according to a config flag of domain. It makes it is possible to create vIOMMU in device model or in tool stack. The following toolstack code is to add XEN_DMOP_viommu_XXX syscalls: - query capabilities of vIOMMU emulated by Xen - create vIOMMU in Xen hypervisor with base address, capability - destroy vIOMMU specified by viommu_id Signed-off-by: Chao Gao <chao.gao@xxxxxxxxx> Signed-off-by: Lan Tianyu <tianyu.lan@xxxxxxxxx> --- tools/libs/devicemodel/core.c | 69 +++++++++++++++++++++++++ tools/libs/devicemodel/include/xendevicemodel.h | 35 +++++++++++++ tools/libs/devicemodel/libxendevicemodel.map | 3 ++ tools/libxc/include/xenctrl_compat.h | 5 ++ tools/libxc/xc_devicemodel_compat.c | 18 +++++++ 5 files changed, 130 insertions(+) diff --git a/tools/libs/devicemodel/core.c b/tools/libs/devicemodel/core.c index a85cb49..aee1150 100644 --- a/tools/libs/devicemodel/core.c +++ b/tools/libs/devicemodel/core.c @@ -498,6 +498,75 @@ int xendevicemodel_restrict(xendevicemodel_handle *dmod, domid_t domid) return osdep_xendevicemodel_restrict(dmod, domid); } +int xendevicemodel_viommu_query_cap( + xendevicemodel_handle *dmod, domid_t dom, uint64_t *cap) +{ + struct xen_dm_op op; + struct xen_dm_op_query_viommu_caps *data; + int rc; + + if ( !cap ) + return -EINVAL; + + memset(&op, 0, sizeof(op)); + + op.op = XEN_DMOP_query_viommu_caps; + data = &op.u.query_viommu_caps; + + rc = xendevicemodel_op(dmod, dom, 1, &op, sizeof(op)); + if ( rc ) + return rc; + + *cap = data->caps; + return 0; +} + +int xendevicemodel_viommu_create( + xendevicemodel_handle *dmod, domid_t dom, uint64_t base_addr, + uint64_t cap, uint32_t *viommu_id) +{ + struct xen_dm_op op; + struct xen_dm_op_create_viommu *data; + int rc; + + if ( !viommu_id ) + return -EINVAL; + + memset(&op, 0, sizeof(op)); + + op.op = XEN_DMOP_create_viommu; + data = &op.u.create_viommu; + + data->base_address = base_addr; + data->capabilities = cap; + + rc = xendevicemodel_op(dmod, dom, 1, &op, sizeof(op)); + if ( rc ) + return rc; + + *viommu_id = data->viommu_id; + return 0; +} + +int xendevicemodel_viommu_destroy( + xendevicemodel_handle *dmod, domid_t dom, uint32_t viommu_id) +{ + struct xen_dm_op op; + struct xen_dm_op_destroy_viommu *data; + + if ( !viommu_id ) + return -EINVAL; + + memset(&op, 0, sizeof(op)); + + op.op = XEN_DMOP_destroy_viommu; + data = &op.u.destroy_viommu; + + data->viommu_id = viommu_id; + + return xendevicemodel_op(dmod, dom, 1, &op, sizeof(op)); +} + /* * Local variables: * mode: C diff --git a/tools/libs/devicemodel/include/xendevicemodel.h b/tools/libs/devicemodel/include/xendevicemodel.h index b3f600e..e133dd5 100644 --- a/tools/libs/devicemodel/include/xendevicemodel.h +++ b/tools/libs/devicemodel/include/xendevicemodel.h @@ -293,6 +293,41 @@ int xendevicemodel_inject_event( */ int xendevicemodel_restrict(xendevicemodel_handle *dmod, domid_t domid); +/** + * This function queries the capabilitites of vIOMMU emulated by Xen. + * + * @parm dmod a handle to an open devicemodel interface. + * @parm dom the domain id to be serviced. + * @parm cap points to memory to store the capability. + * @return 0 on success, -1 on failure. + */ +int xendevicemodel_viommu_query_cap( + xendevicemodel_handle *dmod, domid_t dom, uint64_t *cap); + +/** + * This function creates vIOMMU in Xen hypervisor with base_addr, capability. + * + * @parm dmod a handle to an open devicemodel interface. + * @parm dom the domain id to be serviced. + * @parm base_addr base address of register set of the vIOMMU. + * @parm cap the capability owned by the vIOMMU to be created. + * @parm viommu_id points to memory to store the vIOMMU id. + * @return 0 on success, -1 on failure. + */ +int xendevicemodel_viommu_create( + xendevicemodel_handle *dmod, domid_t dom, uint64_t base_addr, + uint64_t cap, uint32_t *viommu_id); + +/** + * This function destroies vIOMMU specified by viommu_id. + * + * @parm dmod a handle to an open devicemodel interface. + * @parm dom the domain id to be serviced. + * @parm viommu_id spcifies the id of the vIOMMU to be destroied. + * @return 0 on success, -1 on failure. + */ +int xendevicemodel_viommu_destroy( + xendevicemodel_handle *dmod, domid_t dom, uint32_t viommu_id); #endif /* __XEN_TOOLS__ */ #endif /* XENDEVICEMODEL_H */ diff --git a/tools/libs/devicemodel/libxendevicemodel.map b/tools/libs/devicemodel/libxendevicemodel.map index 45c773e..c2e0968 100644 --- a/tools/libs/devicemodel/libxendevicemodel.map +++ b/tools/libs/devicemodel/libxendevicemodel.map @@ -17,6 +17,9 @@ VERS_1.0 { xendevicemodel_modified_memory; xendevicemodel_set_mem_type; xendevicemodel_inject_event; + xendevicemodel_viommu_query_cap; + xendevicemodel_viommu_create; + xendevicemodel_viommu_destroy; xendevicemodel_restrict; xendevicemodel_close; local: *; /* Do not expose anything by default */ diff --git a/tools/libxc/include/xenctrl_compat.h b/tools/libxc/include/xenctrl_compat.h index 040e7b2..315c45d 100644 --- a/tools/libxc/include/xenctrl_compat.h +++ b/tools/libxc/include/xenctrl_compat.h @@ -164,6 +164,11 @@ int xc_hvm_set_mem_type( int xc_hvm_inject_trap( xc_interface *xch, domid_t domid, int vcpu, uint8_t vector, uint8_t type, uint32_t error_code, uint8_t insn_len, uint64_t cr2); +int xc_viommu_query_cap(xc_interface *xch, domid_t dom, uint64_t *cap); +int xc_viommu_create( + xc_interface *xch, domid_t dom, uint64_t base_addr, uint64_t cap, + uint32_t *viommu_id); +int xc_viommu_destroy(xc_interface *xch, domid_t dom, uint32_t viommu_id); #endif /* XC_WANT_COMPAT_DEVICEMODEL_API */ diff --git a/tools/libxc/xc_devicemodel_compat.c b/tools/libxc/xc_devicemodel_compat.c index e4edeea..62f703a 100644 --- a/tools/libxc/xc_devicemodel_compat.c +++ b/tools/libxc/xc_devicemodel_compat.c @@ -128,6 +128,24 @@ int xc_hvm_inject_trap( type, error_code, insn_len, cr2); } +int xc_viommu_query_cap(xc_interface *xch, domid_t dom, uint64_t *cap) +{ + return xendevicemodel_viommu_query_cap(xch->dmod, dom, cap); +} + +int xc_viommu_create( + xc_interface *xch, domid_t dom, uint64_t base_addr, uint64_t cap, + uint32_t *viommu_id) +{ + return xendevicemodel_viommu_create(xch->dmod, dom, base_addr, cap, + viommu_id); +} + +int xc_viommu_destroy(xc_interface *xch, domid_t dom, uint32_t viommu_id) +{ + return xendevicemodel_viommu_destroy(xch->dmod, dom, viommu_id); +} + /* * Local variables: * mode: C -- 1.8.3.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |