From: Paul Durrant Date: Tue, 7 Nov 2017 17:52:10 +0000 (+0000) Subject: iommu op boilerplate X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=9d65597d42667d5ad6eaeea55a37086c191590e7;p=people%2Fpauldu%2Flinux.git iommu op boilerplate Signed-off-by: Paul Durrant --- diff --git a/arch/x86/include/asm/xen/hypercall.h b/arch/x86/include/asm/xen/hypercall.h index ef05bea7010d..e8aed1cd507a 100644 --- a/arch/x86/include/asm/xen/hypercall.h +++ b/arch/x86/include/asm/xen/hypercall.h @@ -51,6 +51,7 @@ #include #include #include +#include struct xen_dm_op_buf; @@ -436,6 +437,12 @@ HYPERVISOR_dm_op( return ret; } +static inline int +HYPERVISOR_iommu_op(unsigned int nr_bufs, struct xen_iommu_op_buf *bufs) +{ + return _hypercall2(int, iommu_op, nr_bufs, bufs); +} + static inline void MULTI_fpu_taskswitch(struct multicall_entry *mcl, int set) { diff --git a/include/xen/interface/iommu_op.h b/include/xen/interface/iommu_op.h new file mode 100644 index 000000000000..80f313ed2b71 --- /dev/null +++ b/include/xen/interface/iommu_op.h @@ -0,0 +1,222 @@ +/* + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Copyright (C) 2018 Citrix Systems Inc + */ + +#ifndef XEN_PUBLIC_IOMMU_OP_H +#define XEN_PUBLIC_IOMMU_OP_H + +#include "xen.h" +#include "grant_table.h" + +typedef uint64_t xen_dfn_t; + +/* Structure describing a single range reserved in the IOMMU */ +struct xen_iommu_reserved_range { + xen_dfn_t start_dfn; + uint32_t nr_frames; + uint32_t pad; +}; +typedef struct xen_iommu_reserved_range xen_iommu_reserved_range_t; +DEFINE_GUEST_HANDLE(xen_iommu_reserved_range_t); + +/* + * XEN_IOMMUOP_query_reserved: Query ranges reserved in the IOMMU. + */ +#define XEN_IOMMUOP_query_reserved 1 + +struct xen_iommu_op_query_reserved { + /* + * IN/OUT - On entry this is the number of entries available + * in the ranges array below. + * On exit this is the actual number of reserved ranges. + */ + uint32_t nr_entries; + uint32_t pad; + /* + * OUT - This array is populated with reserved ranges. If it is + * not sufficiently large then available entries are populated, + * but the op status code will be set to -ENOBUFS. + * It is permissable to set this to NULL if nr_entries is also + * set to zero. In this case, on exit, nr_entries will still be + * set to the actual number of reserved ranges but the status + * code will be set to zero. + */ + GUEST_HANDLE(xen_iommu_reserved_range_t) ranges; +}; + +/* + * XEN_IOMMUOP_enable_modification: Enable operations that modify IOMMU + * mappings. + */ +#define XEN_IOMMUOP_enable_modification 2 + +struct xen_iommu_op_enable_modification { + /* + * OUT - On successful return this is set to the bitwise OR of capabilities + * defined below. On entry this must be set to zero. + */ + uint32_t cap; + uint32_t pad; + + /* Does the implementation support per-device mappings? */ +#define _XEN_IOMMU_CAP_per_device_mappings 0 +#define XEN_IOMMU_CAP_per_device_mappings (1u << _XEN_IOMMU_CAP_per_device_mappings) +}; + +/* + * XEN_IOMMUOP_map: Map a guest page in the IOMMU. + */ +#define XEN_IOMMUOP_map 3 + +struct xen_iommu_op_map { + /* IN - The domid of the guest */ + domid_t domid; + /* + * IN - flags controlling the mapping. This should be a bitwise OR of the + * flags defined below. + */ + uint16_t flags; + + /* + * Should the mapping be created for all initiators? + * + * NOTE: This flag is currently required as the implementation does not yet + * support pre-device mappings. + */ +#define _XEN_IOMMUOP_map_all 0 +#define XEN_IOMMUOP_map_all (1 << (_XEN_IOMMUOP_map_all)) + + /* Should the mapping be read-only to the initiator(s)? */ +#define _XEN_IOMMUOP_map_readonly 1 +#define XEN_IOMMUOP_map_readonly (1 << (_XEN_IOMMUOP_map_readonly)) + + /* Is the memory specified by gfn or grant reference? */ +#define _XEN_IOMMUOP_map_gref 2 +#define XEN_IOMMUOP_map_gref (1 << (_XEN_IOMMUOP_map_gref)) + + uint32_t pad; + /* + * IN - Segment/Bus/Device/Function of the initiator. + * + * NOTE: This is ignored if XEN_IOMMUOP_map_all is set. + */ + uint64_t sbdf; + /* IN - The IOMMU frame number which will hold the new mapping */ + xen_dfn_t dfn; + /* + * IN - The guest frame number or grant reference of the page to + * be mapped. + */ + union { + xen_pfn_t gfn; + grant_ref_t gref; + } u; +}; + +/* + * XEN_IOMMUOP_unmap_gfn: Remove a mapping in the IOMMU. + */ +#define XEN_IOMMUOP_unmap 4 + +struct xen_iommu_op_unmap { + /* IN - The domid of the guest */ + domid_t domid; + /* + * IN - flags controlling the unmapping. This should be a bitwise OR of the + * flags defined below. + */ + uint16_t flags; + + /* + * Should the mapping be destroyed for all initiators? + * + * NOTE: This flag is currently required as the implementation does not yet + * support pre-device mappings. + */ +#define _XEN_IOMMUOP_unmap_all 0 +#define XEN_IOMMUOP_unmap_all (1 << (_XEN_IOMMUOP_unmap_all)) + + /* Is the memory specified by gfn or grant reference? */ +#define _XEN_IOMMUOP_unmap_gref 1 +#define XEN_IOMMUOP_unmap_gref (1 << (_XEN_IOMMUOP_unmap_gref)) + + uint32_t pad; + /* + * IN - Segment/Bus/Device/Function of the initiator. + * + * NOTE: This is ignored if XEN_IOMMUOP_unmap_all is set. + */ + uint64_t sbdf; + /* IN - The IOMMU frame number which holds the mapping to be removed */ + xen_dfn_t dfn; + /* + * IN - The guest frame number or grant reference of the page that + * is mapped. + */ + union { + xen_pfn_t gfn; + grant_ref_t gref; + } u; +}; + +struct xen_iommu_op { + uint16_t op; /* op type */ + uint16_t pad; + int32_t status; /* op completion status: */ + /* 0 for success otherwise, negative errno */ + union { + struct xen_iommu_op_query_reserved query_reserved; + struct xen_iommu_op_enable_modification enable_modification; + struct xen_iommu_op_map map; + struct xen_iommu_op_unmap unmap; + } u; +}; +typedef struct xen_iommu_op xen_iommu_op_t; +DEFINE_GUEST_HANDLE(xen_iommu_op_t); + +struct xen_iommu_op_buf { + GUEST_HANDLE(void) h; + xen_ulong_t size; +}; +typedef struct xen_iommu_op_buf xen_iommu_op_buf_t; +DEFINE_GUEST_HANDLE(xen_iommu_op_buf_t); + +/* ` enum neg_errnoval + * ` HYPERVISOR_iommu_op(unsigned int nr_bufs, + * ` xen_iommu_op_buf_t bufs[]) + * ` + * + * @nr_bufs is the number of buffers in the @bufs array. + * @bufs points to an array of buffers where each contains a struct + * xen_iommu_op. + */ + +#endif /* XEN_PUBLIC_IOMMU_OP_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/include/xen/interface/xen.h b/include/xen/interface/xen.h index 8bfb242f433e..39cd79689f05 100644 --- a/include/xen/interface/xen.h +++ b/include/xen/interface/xen.h @@ -82,6 +82,7 @@ #define __HYPERVISOR_xc_reserved_op 39 /* reserved for XenClient */ #define __HYPERVISOR_xenpmu_op 40 #define __HYPERVISOR_dm_op 41 +#define __HYPERVISOR_iommu_op 42 /* Architecture-specific hypercall definitions. */ #define __HYPERVISOR_arch_0 48