From: Ian Campbell Date: Wed, 10 Feb 2016 14:47:16 +0000 (+0000) Subject: libxendevicemodel: add ability to inject an emulated MSI X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=3cd9bfd96399969cf3e79af63fc1ad148e9a8420;p=people%2Fliuw%2Flibxenctrl-split%2Fxen.git libxendevicemodel: add ability to inject an emulated MSI XXX underlying hypercall is not stable. Note this with the version of @@UNSTABLE. Also in order to build need to define __XEN_TOOLS__, use a separate source file to avoid accidentally poluting the stable bits of the library. TBD replace hypercall with a stable variant and move to emuirq.c + version as @@1.0 Signed-off-by: Ian Campbell --- diff --git a/tools/libs/devicemodel/Makefile b/tools/libs/devicemodel/Makefile index 86d2b1b821..4293bc06c4 100644 --- a/tools/libs/devicemodel/Makefile +++ b/tools/libs/devicemodel/Makefile @@ -14,7 +14,7 @@ LDLIBS += $(LDLIBS_libxentoollog) LDLIBS += $(LDLIBS_libxencall) SRCS-y += core.c -SRCS-y += emuirq.c +SRCS-y += emuirq.c emuirq_unstable.c LIB_OBJS := $(patsubst %.c,%.o,$(SRCS-y)) PIC_OBJS := $(patsubst %.c,%.opic,$(SRCS-y)) @@ -24,6 +24,9 @@ ifneq ($(nosharedlibs),y) LIB += libxendevicemodel.so endif +# XXX These use unstable hypervisor interfaces +emuirq_unstable.o emuirq_unstable.opic: CFLAGS += -D__XEN_TOOLS__ + .PHONY: all all: build diff --git a/tools/libs/devicemodel/emuirq_unstable.c b/tools/libs/devicemodel/emuirq_unstable.c new file mode 100644 index 0000000000..ecd773dc3a --- /dev/null +++ b/tools/libs/devicemodel/emuirq_unstable.c @@ -0,0 +1,60 @@ +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + */ + +#include +#include +#include + +#include "private.h" + +int xendevicemodel_inject_msi(xendevicemodel_handle *dm, + uint64_t addr, uint32_t data) +{ + xen_hvm_inject_msi_t *arg; + int ret = -1; + + arg = xencall_alloc_buffer(dm->call, sizeof(*arg)); + if ( arg == NULL ) + { + LOGE(ERROR, "unable to allocate memory for inject MSI hypercall"); + goto err; + } + + arg->domid = dm->domid; + arg->addr = addr; + arg->data = data; + + ret = xencall2(dm->call, __HYPERVISOR_hvm_op, + HVMOP_inject_msi, + (uintptr_t)arg); + + if ( ret ) + LOGE(ERROR, "inject MSI hypercall failed"); + + xencall_free_buffer(dm->call, arg); + + err: + return ret; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/tools/libs/devicemodel/include/xendevicemodel.h b/tools/libs/devicemodel/include/xendevicemodel.h index fde7b8d942..c5626d3c2f 100644 --- a/tools/libs/devicemodel/include/xendevicemodel.h +++ b/tools/libs/devicemodel/include/xendevicemodel.h @@ -128,6 +128,9 @@ int xendevicemodel_s3_awaken(xendevicemodel_handle *dm); * @isa_irq ISA IRQ 0..15 (inclusive). * @assert Whether the given interrupt of the given type should be * asserted or deasserted. + * + * For MSI injection is as if a device had written @data to guest + * physical address @addr. */ int xendevicemodel_set_pci_intx_level(xendevicemodel_handle *dm, uint8_t domain, uint8_t bus, uint8_t dev, @@ -137,6 +140,9 @@ int xendevicemodel_route_pci_intx_to_isa_irq(xendevicemodel_handle *dm, int xendevicemodel_set_isa_irq_level(xendevicemodel_handle *dm, uint8_t isa_irq, bool assert); +int xendevicemodel_inject_msi(xendevicemodel_handle *dm, + uint64_t addr, uint32_t data); + /* * Memory handling * =============== diff --git a/tools/libs/devicemodel/libxendevicemodel.map b/tools/libs/devicemodel/libxendevicemodel.map index 2ac9bfb1a9..366363cabb 100644 --- a/tools/libs/devicemodel/libxendevicemodel.map +++ b/tools/libs/devicemodel/libxendevicemodel.map @@ -1,3 +1,9 @@ +/* While this section exists this library is not stable */ +UNSTABLE { + global: + xendevicemodel_inject_msi; +}; + VERS_1.0 { global: xendevicemodel_open;