From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wei Wang Subject: Re: [PATCH 1 of 6 V5] amd iommu: Add 2 hypercalls for libxc Date: Fri, 10 Feb 2012 16:42:10 +0100 Message-ID: <4F353AD2.7030705@amd.com> References: <9cf24ad61936e5d9a6ac.1328886426@gran.amd.com> <4F3545E8020000780007261B@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4F3545E8020000780007261B@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Jan Beulich Cc: keir@xen.org, xen-devel@lists.xensource.com, Ian.Jackson@eu.citrix.com, Ian.Campbell@citrix.com List-Id: xen-devel@lists.xenproject.org On 02/10/2012 04:29 PM, Jan Beulich wrote: >>>> On 10.02.12 at 16:07, Wei Wang wrote: >> @@ -916,3 +933,45 @@ const struct hvm_mmio_handler iommu_mmio >> .read_handler = guest_iommu_mmio_read, >> .write_handler = guest_iommu_mmio_write >> }; >> + >> +/* iommu hypercall handler */ >> +int iommu_bind_bdf(struct domain* d, uint16_t gseg, uint16_t gbdf, >> + uint16_t mseg, uint16_t mbdf) >> +{ >> + struct pci_dev *pdev; >> + int ret = -ENODEV; >> + >> + if ( !iommu_found() || !iommu_enabled || !iommuv2_enabled ) >> + return ret; >> + >> + spin_lock(&pcidevs_lock); >> + >> + for_each_pdev( d, pdev ) >> + { >> + if ( (pdev->seg != mseg) || (pdev->bus != PCI_BUS(mbdf) ) || >> + (pdev->devfn != PCI_DEVFN2(mbdf)) ) >> + continue; >> + >> + pdev->gseg = gseg; >> + pdev->gbdf = gbdf; >> + ret = 0; >> + } >> + >> + spin_unlock(&pcidevs_lock); >> + return ret; >> +} >> + >> +void iommu_set_msi(struct domain* d, uint16_t vector, uint16_t dest, >> + uint16_t dest_mode, uint16_t delivery_mode, >> + uint16_t trig_mode) > > Why are these all uint16_t? uint8_t might better... I will change it. > >> +{ >> + struct guest_iommu *iommu = domain_iommu(d); >> + >> + if ( !iommu ) >> + return; >> + >> + iommu->msi.vector = vector; >> + iommu->msi.dest = dest; >> + iommu->msi.dest_mode = dest_mode; >> + iommu->msi.trig_mode = trig_mode; >> +} >> diff -r 593deed8f62d -r 9cf24ad61936 xen/drivers/passthrough/iommu.c >> --- a/xen/drivers/passthrough/iommu.c Thu Feb 09 06:09:17 2012 -0800 >> +++ b/xen/drivers/passthrough/iommu.c Fri Feb 10 15:49:09 2012 +0100 >> @@ -648,6 +648,40 @@ int iommu_do_domctl( >> put_domain(d); >> break; >> >> + case XEN_DOMCTL_guest_iommu_op: >> + { >> + xen_domctl_guest_iommu_op_t * guest_op; >> + >> + if ( unlikely((d = get_domain_by_id(domctl->domain)) == NULL) ) >> + { >> + gdprintk(XENLOG_ERR, >> + "XEN_DOMCTL_guest_iommu_op: get_domain_by_id() >> failed\n"); >> + ret = -EINVAL; >> + break; >> + } >> + >> + guest_op =&(domctl->u.guest_iommu_op); >> + switch ( guest_op->op ) >> + { >> + case XEN_DOMCTL_GUEST_IOMMU_OP_SET_MSI: > > Indentation. can be fixed. Thanks, Wei > >> + iommu_set_msi(d, guest_op->u.msi.vector, >> + guest_op->u.msi.dest, >> + guest_op->u.msi.dest_mode, >> + guest_op->u.msi.delivery_mode, >> + guest_op->u.msi.trig_mode); >> + ret = 0; >> + break; >> + case XEN_DOMCTL_GUEST_IOMMU_OP_BIND_BDF: >> + ret = iommu_bind_bdf(d, guest_op->u.bdf_bind.g_seg, >> + guest_op->u.bdf_bind.g_bdf, >> + guest_op->u.bdf_bind.m_seg, >> + guest_op->u.bdf_bind.m_bdf); >> + break; >> + } >> + put_domain(d); >> + break; >> + } >> + >> default: >> ret = -ENOSYS; >> break; >> diff -r 593deed8f62d -r 9cf24ad61936 xen/include/public/domctl.h >> --- a/xen/include/public/domctl.h Thu Feb 09 06:09:17 2012 -0800 >> +++ b/xen/include/public/domctl.h Fri Feb 10 15:49:09 2012 +0100 >> @@ -871,6 +871,31 @@ struct xen_domctl_set_access_required { >> typedef struct xen_domctl_set_access_required >> xen_domctl_set_access_required_t; >> DEFINE_XEN_GUEST_HANDLE(xen_domctl_set_access_required_t); >> >> +/* Support for guest iommu emulation */ >> +struct xen_domctl_guest_iommu_op { >> + /* XEN_DOMCTL_GUEST_IOMMU_OP_* */ >> +#define XEN_DOMCTL_GUEST_IOMMU_OP_SET_MSI 0 >> +#define XEN_DOMCTL_GUEST_IOMMU_OP_BIND_BDF 1 >> + uint8_t op; >> + union { >> + struct iommu_msi { >> + uint8_t vector; >> + uint8_t dest; >> + uint8_t dest_mode; >> + uint8_t delivery_mode; >> + uint8_t trig_mode; > > Indentation again. > > Jan > >> + } msi; >> + struct bdf_bind { >> + uint16_t g_seg; >> + uint16_t g_bdf; >> + uint16_t m_seg; >> + uint16_t m_bdf; >> + } bdf_bind; >> + } u; >> +}; >> +typedef struct xen_domctl_guest_iommu_op xen_domctl_guest_iommu_op_t; >> +DEFINE_XEN_GUEST_HANDLE(xen_domctl_guest_iommu_op_t); >> + >> struct xen_domctl { >> uint32_t cmd; >> #define XEN_DOMCTL_createdomain 1 > >