From: Wei Wang <wei.wang2@amd.com>
To: JBeulich@suse.com, Ian.Jackson@eu.citrix.com,
Ian.Campbell@citrix.com, keir@xen.org
Cc: xen-devel@lists.xensource.com
Subject: [PATCH 07 of 14 V3] amd iommu: Add 2 hypercalls for libxc
Date: Tue, 10 Jan 2012 18:07:13 +0100 [thread overview]
Message-ID: <31e61ed495ae1429e331.1326215233@gran.amd.com> (raw)
In-Reply-To: <patchbomb.1326215226@gran.amd.com>
# HG changeset patch
# User Wei Wang <wei.wang2@amd.com>
# Date 1326213601 -3600
# Node ID 31e61ed495ae1429e3317f8b0359ff37fdcbb6cd
# Parent 3d252e3969bae12e85e5a1f2f339dad169d0d892
amd iommu: Add 2 hypercalls for libxc
iommu_set_msi: used by qemu to inform hypervisor iommu vector number in guest
space. Hypervisor needs this vector to inject msi into guest when PPR logging
happens.
iommu_bind_bdf: used by xl to bind guest bdf number to machine bdf number.
IOMMU emulations codes receives commands from guest iommu driver and forwards
them to host iommu. But virtual device id from guest should be converted into
physical before sending to real hardware.
Signed -off-by: Wei Wang <wei.wang2@amd.com>
diff -r 3d252e3969ba -r 31e61ed495ae xen/drivers/passthrough/amd/iommu_guest.c
--- a/xen/drivers/passthrough/amd/iommu_guest.c Tue Jan 10 17:39:57 2012 +0100
+++ b/xen/drivers/passthrough/amd/iommu_guest.c Tue Jan 10 17:40:01 2012 +0100
@@ -48,14 +48,31 @@
(reg)->hi = (val >> 32) & 0xFFFFFFFF; \
} while(0)
-static unsigned int machine_bdf(struct domain *d, uint16_t guest_bdf)
+static unsigned int machine_bdf(struct domain *d, uint16_t guest_seg,
+ uint16_t guest_bdf)
{
- return guest_bdf;
+ struct pci_dev *pdev;
+ uint16_t mbdf = 0;
+
+ for_each_pdev( d, pdev )
+ {
+ if ( (pdev->gbdf == guest_bdf) && (pdev->gseg == guest_seg) )
+ {
+ mbdf = PCI_BDF2(pdev->bus, pdev->devfn);
+ break;
+ }
+ }
+ return mbdf;
}
-static uint16_t guest_bdf(struct domain *d, uint16_t machine_bdf)
+static uint16_t guest_bdf(struct domain *d, uint16_t machine_seg,
+ uint16_t machine_bdf)
{
- return machine_bdf;
+ struct pci_dev *pdev;
+
+ pdev = pci_get_pdev_by_domain(d, machine_seg, PCI_BUS(machine_bdf),
+ PCI_DEVFN2(machine_bdf));
+ return pdev->gbdf;
}
static inline struct guest_iommu *domain_iommu(struct domain *d)
@@ -207,7 +224,7 @@ void guest_iommu_add_ppr_log(struct doma
log = log_base + tail % (PAGE_SIZE / sizeof(ppr_entry_t));
/* Convert physical device id back into virtual device id */
- gdev_id = guest_bdf(d, iommu_get_devid_from_cmd(entry[0]));
+ gdev_id = guest_bdf(d, 0, iommu_get_devid_from_cmd(entry[0]));
iommu_set_devid_to_cmd(&entry[0], gdev_id);
memcpy(log, entry, sizeof(ppr_entry_t));
@@ -250,7 +267,7 @@ void guest_iommu_add_event_log(struct do
log = log_base + tail % (PAGE_SIZE / sizeof(event_entry_t));
/* re-write physical device id into virtual device id */
- dev_id = guest_bdf(d, iommu_get_devid_from_cmd(entry[0]));
+ dev_id = guest_bdf(d, 0, iommu_get_devid_from_cmd(entry[0]));
iommu_set_devid_to_cmd(&entry[0], dev_id);
memcpy(log, entry, sizeof(event_entry_t));
@@ -272,7 +289,7 @@ static int do_complete_ppr_request(struc
uint16_t dev_id;
struct amd_iommu *iommu;
- dev_id = machine_bdf(d, iommu_get_devid_from_cmd(cmd->data[0]));
+ dev_id = machine_bdf(d, 0, iommu_get_devid_from_cmd(cmd->data[0]));
iommu = find_iommu_for_device(0, dev_id);
if ( !iommu )
@@ -324,7 +341,7 @@ static int do_invalidate_iotlb_pages(str
struct amd_iommu *iommu;
uint16_t dev_id;
- dev_id = machine_bdf(d, iommu_get_devid_from_cmd(cmd->data[0]));
+ dev_id = machine_bdf(d, 0, iommu_get_devid_from_cmd(cmd->data[0]));
iommu = find_iommu_for_device(0, dev_id);
if ( !iommu )
@@ -402,7 +419,7 @@ static int do_invalidate_dte(struct doma
g_iommu = domain_iommu(d);
gbdf = iommu_get_devid_from_cmd(cmd->data[0]);
- mbdf = machine_bdf(d, gbdf);
+ mbdf = machine_bdf(d, 0, gbdf);
/* Guest can only update DTEs for its passthru devices */
if ( mbdf == 0 || gbdf == 0 )
@@ -913,3 +930,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() )
+ return 0;
+
+ 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)
+{
+ struct guest_iommu *iommu = domain_iommu(d);
+
+ if ( !iommu_found() )
+ return;
+
+ iommu->msi.vector = vector;
+ iommu->msi.dest = dest;
+ iommu->msi.dest_mode = dest_mode;
+ iommu->msi.trig_mode = trig_mode;
+}
diff -r 3d252e3969ba -r 31e61ed495ae xen/drivers/passthrough/iommu.c
--- a/xen/drivers/passthrough/iommu.c Tue Jan 10 17:39:57 2012 +0100
+++ b/xen/drivers/passthrough/iommu.c Tue Jan 10 17:40:01 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:
+ 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 3d252e3969ba -r 31e61ed495ae xen/include/public/domctl.h
--- a/xen/include/public/domctl.h Tue Jan 10 17:39:57 2012 +0100
+++ b/xen/include/public/domctl.h Tue Jan 10 17:40:01 2012 +0100
@@ -848,6 +848,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;
+ } 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
@@ -912,6 +937,7 @@ struct xen_domctl {
#define XEN_DOMCTL_getvcpuextstate 63
#define XEN_DOMCTL_set_access_required 64
#define XEN_DOMCTL_audit_p2m 65
+#define XEN_DOMCTL_guest_iommu_op 66
#define XEN_DOMCTL_gdbsx_guestmemio 1000
#define XEN_DOMCTL_gdbsx_pausevcpu 1001
#define XEN_DOMCTL_gdbsx_unpausevcpu 1002
@@ -960,6 +986,7 @@ struct xen_domctl {
struct xen_domctl_debug_op debug_op;
struct xen_domctl_mem_event_op mem_event_op;
struct xen_domctl_mem_sharing_op mem_sharing_op;
+ struct xen_domctl_guest_iommu_op guest_iommu_op;
#if defined(__i386__) || defined(__x86_64__)
struct xen_domctl_cpuid cpuid;
struct xen_domctl_vcpuextstate vcpuextstate;
diff -r 3d252e3969ba -r 31e61ed495ae xen/include/xen/iommu.h
--- a/xen/include/xen/iommu.h Tue Jan 10 17:39:57 2012 +0100
+++ b/xen/include/xen/iommu.h Tue Jan 10 17:40:01 2012 +0100
@@ -164,6 +164,12 @@ int iommu_do_domctl(struct xen_domctl *,
void iommu_iotlb_flush(struct domain *d, unsigned long gfn, unsigned int page_count);
void iommu_iotlb_flush_all(struct domain *d);
+/* Only used by AMD IOMMU so far */
+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);
+int iommu_bind_bdf(struct domain* d, uint16_t gseg, uint16_t gbdf,
+ uint16_t mseg, uint16_t mbdf);
/*
* The purpose of the iommu_dont_flush_iotlb optional cpu flag is to
* avoid unecessary iotlb_flush in the low level IOMMU code.
diff -r 3d252e3969ba -r 31e61ed495ae xen/include/xen/pci.h
--- a/xen/include/xen/pci.h Tue Jan 10 17:39:57 2012 +0100
+++ b/xen/include/xen/pci.h Tue Jan 10 17:40:01 2012 +0100
@@ -59,6 +59,11 @@ struct pci_dev {
const u16 seg;
const u8 bus;
const u8 devfn;
+
+ /* Used by iommu to represent virtual seg and bdf value in guest space */
+ u16 gseg;
+ u16 gbdf;
+
struct pci_dev_info info;
struct arch_pci_dev arch;
u64 vf_rlen[6];
next prev parent reply other threads:[~2012-01-10 17:07 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-10 17:07 [PATCH 00 of 14 V3] amd iommu: support ATS device passthru on IOMMUv2 systems Wei Wang
2011-12-23 11:29 ` [PATCH 00 of 16] [V2] " Wei Wang
2011-12-23 11:29 ` [PATCH 01 of 16] amd iommu: Refactoring iommu ring buffer definition Wei Wang
2012-01-02 12:44 ` Jan Beulich
2011-12-23 11:29 ` [PATCH 02 of 16] amd iommu: Introduces new helper functions to simplify iommu bitwise operations Wei Wang
2012-01-02 12:52 ` Jan Beulich
2011-12-23 11:29 ` [PATCH 03 of 16] amd iommu: Add iommu emulation for hvm guest Wei Wang
2011-12-23 11:29 ` [PATCH 04 of 16] amd iommu: Enable ppr log Wei Wang
2012-01-02 13:10 ` Jan Beulich
2011-12-23 11:29 ` [PATCH 05 of 16] amd iommu: Enable guest level translation Wei Wang
2011-12-23 11:29 ` [PATCH 06 of 16] amd iommu: add ppr log processing into iommu interrupt handling Wei Wang
2012-01-02 13:13 ` Jan Beulich
2012-01-03 8:58 ` Wei Wang2
2011-12-23 11:29 ` [PATCH 07 of 16] amd iommu: Add 2 hypercalls for libxc Wei Wang
2012-01-02 12:15 ` Jan Beulich
2011-12-23 11:29 ` [PATCH 08 of 16] amd iommu: Add a hypercall for hvmloader Wei Wang
2012-01-02 11:41 ` Jan Beulich
2011-12-23 11:29 ` [PATCH 09 of 16] amd iommu: add iommu mmio handler Wei Wang
2012-01-02 11:39 ` Jan Beulich
2011-12-23 11:29 ` [PATCH 10 of 16] amd iommu: Enable FC bit in iommu host level PTE Wei Wang
2012-01-02 11:36 ` Jan Beulich
2012-01-03 10:05 ` Wei Wang2
2012-01-03 10:12 ` Jan Beulich
2012-01-03 10:37 ` Wei Wang2
2011-12-23 11:29 ` [PATCH 11 of 16] amd iommu: Add a new flag to indication iommuv2 feature enabled or not Wei Wang
2012-01-02 11:29 ` Jan Beulich
2011-12-23 11:29 ` [PATCH 12 of 16] hvmloader: Build IVRS table Wei Wang
2011-12-23 11:36 ` Ian Campbell
2011-12-23 11:52 ` Wei Wang2
2011-12-23 11:29 ` [PATCH 13 of 16] libxc: add wrappers for new hypercalls Wei Wang
2011-12-23 11:29 ` [PATCH 14 of 16] libxl: bind virtual bdf to physical bdf after device assignment Wei Wang
2011-12-23 11:37 ` Ian Campbell
2011-12-23 11:56 ` Wei Wang2
2012-01-03 16:03 ` Ian Jackson
2011-12-23 11:29 ` [PATCH 15 of 16] libxl: Introduce a new guest config file parameter Wei Wang
2012-01-03 16:02 ` Ian Jackson
2011-12-23 11:29 ` [PATCH 16 of 16] libxl: pass iommu parameter to qemu-dm Wei Wang
2012-01-10 17:07 ` [PATCH 01 of 14 V3] amd iommu: Refactoring iommu ring buffer definition Wei Wang
2012-01-10 17:07 ` [PATCH 02 of 14 V3] amd iommu: Introduces new helper functions to simplify bitwise operations Wei Wang
2012-01-10 17:07 ` [PATCH 03 of 14 V3] amd iommu: Add iommu emulation for hvm guest Wei Wang
2012-01-12 11:36 ` Jan Beulich
2012-01-16 10:29 ` Wei Wang
2012-01-10 17:07 ` [PATCH 04 of 14 V3] amd iommu: Enable ppr log Wei Wang
2012-01-10 17:07 ` [PATCH 05 of 14 V3] amd iommu: Enable guest level translation Wei Wang
2012-01-10 17:07 ` [PATCH 06 of 14 V3] amd iommu: add ppr log processing into iommu interrupt handling Wei Wang
2012-01-10 17:07 ` Wei Wang [this message]
2012-01-10 17:07 ` [PATCH 08 of 14 V3] amd iommu: Add a new flag to indication iommuv2 feature enabled or not Wei Wang
2012-01-10 17:07 ` [PATCH 09 of 14 V3] amd iommu: Add a hypercall for hvmloader Wei Wang
2012-01-10 17:07 ` [PATCH 10 of 14 V3] amd iommu: Enable FC bit in iommu host level PTE Wei Wang
2012-01-10 17:07 ` [PATCH 11 of 14 V3] hvmloader: Build IVRS table Wei Wang
2012-01-10 17:07 ` [PATCH 12 of 14 V3] libxc: add wrappers for new hypercalls Wei Wang
2012-01-10 17:07 ` [PATCH 13 of 14 V3] libxl: bind virtual bdf to physical bdf after device assignment Wei Wang
2012-01-10 17:13 ` Ian Jackson
2012-01-10 17:35 ` Wei Wang2
2012-01-10 17:07 ` [PATCH 14 of 14 V3] libxl: Introduce a new guest config file parameter Wei Wang
2012-01-10 17:12 ` [PATCH 15 of 16] libxl: Introduce a new guest config file parameter [and 1 more messages] Ian Jackson
2012-01-11 10:20 ` Wei Wang2
2012-01-23 13:59 ` Ian Jackson
2012-01-11 8:43 ` [PATCH 14 of 14 V3] libxl: Introduce a new guest config file parameter Ian Campbell
2012-01-11 10:47 ` Wei Wang2
2012-01-11 15:04 ` [PATCH 00 of 14 V3] amd iommu: support ATS device passthru on IOMMUv2 systems Jan Beulich
2012-01-11 17:36 ` Wei Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=31e61ed495ae1429e331.1326215233@gran.amd.com \
--to=wei.wang2@amd.com \
--cc=Ian.Campbell@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=JBeulich@suse.com \
--cc=keir@xen.org \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.