From: Paul Durrant <paul.durrant@citrix.com>
To: xen-devel@lists.xenproject.org, qemu-devel@nongnu.org
Cc: Paul Durrant <paul.durrant@citrix.com>,
Stefano Stabellini <sstabellini@kernel.org>,
Anthony Perard <anthony.perard@citrix.com>
Subject: [Qemu-devel] [PATCH 5/5] xen: use libxendevicemodel when available
Date: Thu, 23 Feb 2017 14:53:55 +0000 [thread overview]
Message-ID: <1487861635-17560-6-git-send-email-paul.durrant@citrix.com> (raw)
In-Reply-To: <1487861635-17560-1-git-send-email-paul.durrant@citrix.com>
This patch modifies the wrapper functions in xen_common.h to use the
new xendevicemodel interface if it is available along with compatibility
code to use the old libxenctrl interface if it is not.
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
---
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Anthony Perard <anthony.perard@citrix.com>
---
include/hw/xen/xen_common.h | 114 +++++++++++++++++++++++++++++++-------------
xen-common.c | 8 ++++
2 files changed, 89 insertions(+), 33 deletions(-)
diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h
index 31cf25f..2c2a61b 100644
--- a/include/hw/xen/xen_common.h
+++ b/include/hw/xen/xen_common.h
@@ -9,6 +9,7 @@
#undef XC_WANT_COMPAT_EVTCHN_API
#undef XC_WANT_COMPAT_GNTTAB_API
#undef XC_WANT_COMPAT_MAP_FOREIGN_API
+#undef XC_WANT_COMPAT_DEVICEMODEL_API
#include <xenctrl.h>
#include <xenstore.h>
@@ -26,48 +27,95 @@ extern xc_interface *xen_xc;
* We don't support Xen prior to 4.2.0.
*/
+#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 490
+
+typedef xc_interface xendevicemodel_handle;
+
+#define xendevicemodel_open(l, f) xen_xc
+
+#define xendevicemodel_map_io_range_to_ioreq_server \
+ xc_hvm_map_io_range_to_ioreq_server
+#define xendevicemodel_unmap_io_range_from_ioreq_server \
+ xc_hvm_unmap_io_range_from_ioreq_server
+#define xendevicemodel_map_pcidev_to_ioreq_server \
+ xc_hvm_map_pcidev_to_ioreq_server
+#define xendevicemodel_unmap_pcidev_from_ioreq_server \
+ xc_hvm_unmap_pcidev_from_ioreq_server
+#define xendevicemodel_create_ioreq_server \
+ xc_hvm_create_ioreq_server
+#define xendevicemodel_destroy_ioreq_server \
+ xc_hvm_destroy_ioreq_server
+#define xendevicemodel_get_ioreq_server_info \
+ xc_hvm_get_ioreq_server_info
+#define xendevicemodel_set_ioreq_server_state \
+ xc_hvm_set_ioreq_server_state
+#define xendevicemodel_set_pci_intx_level \
+ xc_hvm_set_pci_intx_level
+#define xendevicemodel_set_pci_link_route \
+ xc_hvm_set_pci_link_route
+#define xendevicemodel_set_isa_irq_level \
+ xc_hvm_set_isa_irq_level
+#define xendevicemodel_inject_msi \
+ xc_hvm_inject_msi
+#define xendevicemodel_set_mem_type \
+ xc_hvm_set_mem_type
+#define xendevicemodel_track_dirty_vram \
+ xc_hvm_track_dirty_vram
+#define xendevicemodel_modified_memory \
+ xc_hvm_modified_memory
+
+#else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >= 490 */
+
+#include <xendevicemodel.h>
+
+#endif
+
+extern xendevicemodel_handle *xen_dmod;
+
static inline int xen_set_mem_type(domid_t domid, hvmmem_type_t type,
uint64_t first_pfn, uint32_t nr)
{
- return xc_hvm_set_mem_type(xen_xc, domid, type, first_pfn, nr);
+ return xendevicemodel_set_mem_type(xen_dmod, domid, type, first_pfn,
+ nr);
}
static inline int xen_set_pci_intx_level(domid_t domid, uint16_t segment,
uint8_t bus, uint8_t device,
uint8_t intx, unsigned int level)
{
- return xc_hvm_set_pci_intx_level(xen_xc, domid, segment, bus, device,
- intx, level);
+ return xendevicemodel_set_pci_intx_level(xen_dmod, domid, segment, bus,
+ device, intx, level);
}
static inline int xen_set_pci_link_route(domid_t domid, uint8_t link,
uint8_t irq)
{
- return xc_hvm_set_pci_link_route(xen_xc, domid, link, irq);
+ return xendevicemodel_set_pci_link_route(xen_dmod, domid, link, irq);
}
static inline int xen_inject_msi(domid_t domid, uint64_t msi_addr,
uint32_t msi_data)
{
- return xc_hvm_inject_msi(xen_xc, domid, msi_addr, msi_data);
+ return xendevicemodel_inject_msi(xen_dmod, domid, msi_addr, msi_data);
}
static inline int xen_set_isa_irq_level(domid_t domid, uint8_t irq,
unsigned int level)
{
- return xc_hvm_set_isa_irq_level(xen_xc, domid, irq, level);
+ return xendevicemodel_set_isa_irq_level(xen_dmod, domid, irq, level);
}
static inline int xen_track_dirty_vram(domid_t domid, uint64_t first_pfn,
uint32_t nr, unsigned long *bitmap)
{
- return xc_hvm_track_dirty_vram(xen_xc, domid, first_pfn, nr, bitmap);
+ return xendevicemodel_track_dirty_vram(xen_dmod, domid, first_pfn, nr,
+ bitmap);
}
static inline int xen_modified_memory(domid_t domid, uint64_t first_pfn,
uint32_t nr)
{
- return xc_hvm_modified_memory(xen_xc, domid, first_pfn, nr);
+ return xendevicemodel_modified_memory(xen_dmod, domid, first_pfn, nr);
}
/* Xen 4.2 through 4.6 */
@@ -285,8 +333,8 @@ static inline void xen_map_memory_section(domid_t dom,
}
trace_xen_map_mmio_range(ioservid, start_addr, end_addr);
- xc_hvm_map_io_range_to_ioreq_server(xen_xc, dom, ioservid, 1,
- start_addr, end_addr);
+ xendevicemodel_map_io_range_to_ioreq_server(xen_dmod, dom, ioservid, 1,
+ start_addr, end_addr);
}
static inline void xen_unmap_memory_section(domid_t dom,
@@ -302,8 +350,8 @@ static inline void xen_unmap_memory_section(domid_t dom,
}
trace_xen_unmap_mmio_range(ioservid, start_addr, end_addr);
- xc_hvm_unmap_io_range_from_ioreq_server(xen_xc, dom, ioservid,
- 1, start_addr, end_addr);
+ xendevicemodel_unmap_io_range_from_ioreq_server(xen_dmod, dom, ioservid,
+ 1, start_addr, end_addr);
}
static inline void xen_map_io_section(domid_t dom,
@@ -319,8 +367,8 @@ static inline void xen_map_io_section(domid_t dom,
}
trace_xen_map_portio_range(ioservid, start_addr, end_addr);
- xc_hvm_map_io_range_to_ioreq_server(xen_xc, dom, ioservid, 0,
- start_addr, end_addr);
+ xendevicemodel_map_io_range_to_ioreq_server(xen_dmod, dom, ioservid, 0,
+ start_addr, end_addr);
}
static inline void xen_unmap_io_section(domid_t dom,
@@ -336,8 +384,8 @@ static inline void xen_unmap_io_section(domid_t dom,
}
trace_xen_unmap_portio_range(ioservid, start_addr, end_addr);
- xc_hvm_unmap_io_range_from_ioreq_server(xen_xc, dom, ioservid,
- 0, start_addr, end_addr);
+ xendevicemodel_unmap_io_range_from_ioreq_server(xen_dmod, dom, ioservid,
+ 0, start_addr, end_addr);
}
static inline void xen_map_pcidev(domid_t dom,
@@ -350,10 +398,10 @@ static inline void xen_map_pcidev(domid_t dom,
trace_xen_map_pcidev(ioservid, pci_bus_num(pci_dev->bus),
PCI_SLOT(pci_dev->devfn), PCI_FUNC(pci_dev->devfn));
- xc_hvm_map_pcidev_to_ioreq_server(xen_xc, dom, ioservid, 0,
- pci_bus_num(pci_dev->bus),
- PCI_SLOT(pci_dev->devfn),
- PCI_FUNC(pci_dev->devfn));
+ xendevicemodel_map_pcidev_to_ioreq_server(xen_dmod, dom, ioservid, 0,
+ pci_bus_num(pci_dev->bus),
+ PCI_SLOT(pci_dev->devfn),
+ PCI_FUNC(pci_dev->devfn));
}
static inline void xen_unmap_pcidev(domid_t dom,
@@ -366,18 +414,18 @@ static inline void xen_unmap_pcidev(domid_t dom,
trace_xen_unmap_pcidev(ioservid, pci_bus_num(pci_dev->bus),
PCI_SLOT(pci_dev->devfn), PCI_FUNC(pci_dev->devfn));
- xc_hvm_unmap_pcidev_from_ioreq_server(xen_xc, dom, ioservid, 0,
- pci_bus_num(pci_dev->bus),
- PCI_SLOT(pci_dev->devfn),
- PCI_FUNC(pci_dev->devfn));
+ xendevicemodel_unmap_pcidev_from_ioreq_server(xen_dmod, dom, ioservid, 0,
+ pci_bus_num(pci_dev->bus),
+ PCI_SLOT(pci_dev->devfn),
+ PCI_FUNC(pci_dev->devfn));
}
static inline void xen_create_ioreq_server(domid_t dom,
ioservid_t *ioservid)
{
- int rc = xc_hvm_create_ioreq_server(xen_xc, dom,
- HVM_IOREQSRV_BUFIOREQ_ATOMIC,
- ioservid);
+ int rc = xendevicemodel_create_ioreq_server(xen_dmod, dom,
+ HVM_IOREQSRV_BUFIOREQ_ATOMIC,
+ ioservid);
if (rc == 0) {
trace_xen_ioreq_server_create(*ioservid);
@@ -397,7 +445,7 @@ static inline void xen_destroy_ioreq_server(domid_t dom,
}
trace_xen_ioreq_server_destroy(ioservid);
- xc_hvm_destroy_ioreq_server(xen_xc, dom, ioservid);
+ xendevicemodel_destroy_ioreq_server(xen_dmod, dom, ioservid);
}
static inline int xen_get_ioreq_server_info(domid_t dom,
@@ -412,9 +460,9 @@ static inline int xen_get_ioreq_server_info(domid_t dom,
bufioreq_evtchn);
}
- return xc_hvm_get_ioreq_server_info(xen_xc, dom, ioservid,
- ioreq_pfn, bufioreq_pfn,
- bufioreq_evtchn);
+ return xendevicemodel_get_ioreq_server_info(xen_dmod, dom, ioservid,
+ ioreq_pfn, bufioreq_pfn,
+ bufioreq_evtchn);
}
static inline int xen_set_ioreq_server_state(domid_t dom,
@@ -426,8 +474,8 @@ static inline int xen_set_ioreq_server_state(domid_t dom,
}
trace_xen_ioreq_server_state(ioservid, enable);
- return xc_hvm_set_ioreq_server_state(xen_xc, dom, ioservid,
- enable);
+ return xendevicemodel_set_ioreq_server_state(xen_dmod, dom, ioservid,
+ enable);
}
#endif
diff --git a/xen-common.c b/xen-common.c
index 703e7a5..ae76150 100644
--- a/xen-common.c
+++ b/xen-common.c
@@ -27,6 +27,7 @@
xc_interface *xen_xc;
xenforeignmemory_handle *xen_fmem;
+xendevicemodel_handle *xen_dmod;
static int store_dev_info(int domid, Chardev *cs, const char *string)
{
@@ -128,6 +129,13 @@ static int xen_init(MachineState *ms)
xc_interface_close(xen_xc);
return -1;
}
+ xen_dmod = xendevicemodel_open(0, 0);
+ if (xen_dmod == NULL) {
+ xen_pv_printf(NULL, 0, "can't open xen devicemodel interface\n");
+ xenforeignmemory_close(xen_fmem);
+ xc_interface_close(xen_xc);
+ return -1;
+ }
qemu_add_vm_change_state_handler(xen_change_state_handler, NULL);
global_state_set_optional();
--
2.1.4
next prev parent reply other threads:[~2017-02-23 14:54 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-23 14:53 [Qemu-devel] [PATCH 0/5] xen: use new xendevicemodel library Paul Durrant
2017-02-23 14:53 ` [Qemu-devel] [PATCH 1/5] xen: make use of xen_xc implicit in xen_common.h inlines Paul Durrant
2017-03-01 15:19 ` Anthony PERARD
2017-02-23 14:53 ` [Qemu-devel] [PATCH 2/5] xen: rename xen_modified_memory() to xen_hvm_modified_memory() Paul Durrant
2017-03-01 15:24 ` Anthony PERARD
2017-02-23 14:53 ` [Qemu-devel] [PATCH 3/5] xen: create wrappers for all other uses of xc_hvm_XXX() functions Paul Durrant
2017-03-01 16:13 ` Anthony PERARD
2017-03-01 16:16 ` Paul Durrant
2017-03-02 10:44 ` Anthony PERARD
2017-02-23 14:53 ` [Qemu-devel] [PATCH 4/5] configure: detect presence of libxendevicemodel Paul Durrant
2017-03-01 17:17 ` Anthony PERARD
2017-03-02 9:06 ` Paul Durrant
2017-03-02 10:54 ` Anthony PERARD
2017-03-02 10:55 ` Paul Durrant
2017-03-02 11:01 ` [Qemu-devel] [Xen-devel] " Juergen Gross
2017-03-02 11:06 ` Paul Durrant
2017-03-02 11:26 ` Juergen Gross
2017-02-23 14:53 ` Paul Durrant [this message]
2017-03-02 2:05 ` [Qemu-devel] [PATCH 5/5] xen: use libxendevicemodel when available Stefano Stabellini
2017-03-02 8:58 ` Paul Durrant
2017-02-23 14:55 ` [Qemu-devel] [PATCH 0/5] xen: use new xendevicemodel library Paul Durrant
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=1487861635-17560-6-git-send-email-paul.durrant@citrix.com \
--to=paul.durrant@citrix.com \
--cc=anthony.perard@citrix.com \
--cc=qemu-devel@nongnu.org \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).