Google
  Web www.spinics.net

[PATCH] KVM: Userspace: Make device-assignment work for kvm/ia64.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


>From 45b40eecff85b9a7ae4caf4ae184905a79e5a139 Mon Sep 17 00:00:00 2001
From: Xiantao Zhang <xiantao.zhang@xxxxxxxxx>
Date: Fri, 7 Nov 2008 18:13:13 +0800
Subject: [PATCH] KVM: Userspace: Make device-assignment work for kvm/ia64.

kvm/ia64 have supported vt-d from 2.6.28rc1, this patch
enables its userspace's support.

Signed-off-by: Xiantao Zhang <xiantao.zhang@xxxxxxxxx>
---
 kernel/ia64/Kbuild          |    4 ++++
 qemu/Makefile.target        |    7 ++++---
 qemu/hw/device-assignment.c |    4 ++++
 qemu/hw/ipf.c               |   27 +++++++++++++++++++++++++--
 qemu/hw/pc.h                |    2 ++
 qemu/vl.c                   |    8 ++++----
 6 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/kernel/ia64/Kbuild b/kernel/ia64/Kbuild
index e9660ba..88eaa39 100644
--- a/kernel/ia64/Kbuild
+++ b/kernel/ia64/Kbuild
@@ -3,6 +3,10 @@ obj-m := kvm.o kvm-intel.o
 kvm-objs := kvm_main.o ioapic.o coalesced_mmio.o kvm-ia64.o kvm_fw.o \
 	irq_comm.o ../anon_inodes.o ../external-module-compat.o
 
+ifeq ($(CONFIG_DMAR),y)
+kvm-objs += vtd.o
+endif
+
 EXTRA_CFLAGS_vcpu.o += -mfixed-range=f2-f5,f12-f127
 kvm-intel-objs := vmm.o vmm_ivt.o trampoline.o vcpu.o optvfault.o mmio.o \
                vtlb.o process.o memset.o memcpy.o
diff --git a/qemu/Makefile.target b/qemu/Makefile.target
index d504b75..229b1c6 100644
--- a/qemu/Makefile.target
+++ b/qemu/Makefile.target
@@ -720,15 +720,16 @@ OBJS += virtio.o virtio-net.o virtio-blk.o virtio-balloon.o
 
 OBJS += device-hotplug.o
 
+ifeq ($(USE_KVM_DEVICE_ASSIGNMENT), 1)
+OBJS+= device-assignment.o
+endif
+
 ifeq ($(TARGET_BASE_ARCH), i386)
 # Hardware support
 OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o
 OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
 OBJS+= cirrus_vga.o apic.o parallel.o acpi.o piix_pci.o
 OBJS+= usb-uhci.o vmmouse.o vmport.o vmware_vga.o extboot.o
-ifeq ($(USE_KVM_DEVICE_ASSIGNMENT), 1)
-OBJS+= device-assignment.o
-endif
 ifeq ($(USE_KVM_PIT), 1)
 OBJS+= i8254-kvm.o
 endif
diff --git a/qemu/hw/device-assignment.c b/qemu/hw/device-assignment.c
index 78b7e14..5cda7d9 100644
--- a/qemu/hw/device-assignment.c
+++ b/qemu/hw/device-assignment.c
@@ -457,6 +457,10 @@ void assigned_dev_update_irq(PCIDevice *d)
         irq = pci_map_irq(&assigned_dev->dev, assigned_dev->intpin);
         irq = piix_get_irq(irq);
 
+#ifdef TARGET_IA64
+	irq = ipf_map_irq(d, irq);
+#endif
+
         if (irq != assigned_dev->girq) {
             struct kvm_assigned_irq assigned_irq_data;
 
diff --git a/qemu/hw/ipf.c b/qemu/hw/ipf.c
index 337c854..f4a2853 100644
--- a/qemu/hw/ipf.c
+++ b/qemu/hw/ipf.c
@@ -38,6 +38,7 @@
 #include "firmware.h"
 #include "ia64intrin.h"
 #include <unistd.h>
+#include "device-assignment.h"
 
 #include "qemu-kvm.h"
 
@@ -450,7 +451,6 @@ static void ipf_init1(ram_addr_t ram_size, int vga_ram_size,
 
     /*Load firware to its proper position.*/
     if (kvm_enabled()) {
-        int r;
         unsigned long  image_size;
         char *image = NULL;
         uint8_t *fw_image_start;
@@ -645,8 +645,26 @@ static void ipf_init1(ram_addr_t ram_size, int vga_ram_size,
 	    unit_id++;
 	}
     }
-}
 
+#ifdef USE_KVM_DEVICE_ASSIGNMENT
+    if (kvm_enabled()) {
+	int i;
+        for (i = 0; i < assigned_devices_index; i++) {
+            if (add_assigned_device(assigned_devices[i]) < 0) {
+                fprintf(stderr, "Warning: could not add assigned device %s\n",
+                        assigned_devices[i]);
+            }
+        }
+
+	if (init_all_assigned_devices(pci_bus)) {
+	    fprintf(stderr, "Failed to initialize assigned devices\n");
+	    exit (1);
+	}
+    }
+#endif /* USE_KVM_DEVICE_ASSIGNMENT */
+
+}
+ 
 static void ipf_init_pci(ram_addr_t ram_size, int vga_ram_size,
                          const char *boot_device, DisplayState *ds,
                          const char *kernel_filename,
@@ -695,3 +713,8 @@ void ioapic_set_irq(void *opaque, int irq_num, int level)
 	    return;
     }
 }
+
+int ipf_map_irq(PCIDevice *pci_dev, int irq_num)
+{
+	return ioapic_map_irq(pci_dev->devfn, irq_num);
+}
diff --git a/qemu/hw/pc.h b/qemu/hw/pc.h
index fddfdfa..074195d 100644
--- a/qemu/hw/pc.h
+++ b/qemu/hw/pc.h
@@ -118,6 +118,8 @@ int piix4_init(PCIBus *bus, int devfn);
 
 int piix_get_irq(int pin);
 
+int ipf_map_irq(PCIDevice *pci_dev, int irq_num);
+
 /* vga.c */
 enum vga_retrace_method {
     VGA_RETRACE_DUMB,
diff --git a/qemu/vl.c b/qemu/vl.c
index 561e254..c383587 100644
--- a/qemu/vl.c
+++ b/qemu/vl.c
@@ -8694,7 +8694,7 @@ static void help(int exitcode)
 #endif
 	   "-no-kvm-irqchip disable KVM kernel mode PIC/IOAPIC/LAPIC\n"
 	   "-no-kvm-pit	    disable KVM kernel mode PIT\n"
-#if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(__linux__)
+#if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_IA64) || defined(__linux__)
            "-pcidevice host=bus:dev.func[,dma=none][,name=string]\n"
            "                expose a PCI device to the guest OS.\n"
            "                dma=none: don't perform any dma translations (default is to use an iommu)\n"
@@ -8819,7 +8819,7 @@ enum {
     QEMU_OPTION_no_kvm,
     QEMU_OPTION_no_kvm_irqchip,
     QEMU_OPTION_no_kvm_pit,
-#if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(__linux__)
+#if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_IA64) || defined(__linux__)
     QEMU_OPTION_pcidevice,
 #endif
     QEMU_OPTION_no_reboot,
@@ -8911,7 +8911,7 @@ static const QEMUOption qemu_options[] = {
 #endif
     { "no-kvm-irqchip", 0, QEMU_OPTION_no_kvm_irqchip },
     { "no-kvm-pit", 0, QEMU_OPTION_no_kvm_pit },
-#if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(__linux__)
+#if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_IA64) || defined(__linux__)
     { "pcidevice", HAS_ARG, QEMU_OPTION_pcidevice },
 #endif
 #endif
@@ -9859,7 +9859,7 @@ int main(int argc, char **argv)
 		kvm_pit = 0;
 		break;
 	    }
-#if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(__linux__)
+#if defined(TARGET_I386) || defined(TARGET_X86_64) || defined(TARGET_IA64) || defined(__linux__)
             case QEMU_OPTION_pcidevice:
 		if (assigned_devices_index >= MAX_DEV_ASSIGN_CMDLINE) {
                     fprintf(stderr, "Too many assigned devices\n");
-- 
1.6.0

Attachment: 0001-KVM-Userspace-Make-device-assignment-work-for-kvm.patch
Description: 0001-KVM-Userspace-Make-device-assignment-work-for-kvm.patch


[Home]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Video Projectors]     [PDAs]     [Free Online Dating]     [Hacking TiVo]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Devices]     [Big List of Linux Books]     [16.7MP]

  Powered by Linux