From b7eeadf6d58267f343e466ae1e0913425b619d2b Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Wed, 4 Feb 2009 19:10:04 +0100 Subject: [PATCH] kvm: external module: Fix pre-2.6.18 missing pci_dev.msi_enabled pci_dev.msi_enabled was introduced in 2.6.18, thus building against older kernels now fails. Fix via a compat wrapper that reads directly from the PCI config space. Signed-off-by: Jan Kiszka Signed-off-by: Avi Kivity --- kvm/kernel/external-module-compat-comm.h | 13 +++++++++++++ kvm/kernel/external-module-compat.c | 21 +++++++++++++++++++++ kvm/kernel/x86/hack-module.awk | 2 ++ 3 files changed, 36 insertions(+) diff --git a/kvm/kernel/external-module-compat-comm.h b/kvm/kernel/external-module-compat-comm.h index c3c1c0ec1a..ae58c97b30 100644 --- a/kvm/kernel/external-module-compat-comm.h +++ b/kvm/kernel/external-module-compat-comm.h @@ -721,3 +721,16 @@ static inline void cpumask_clear_cpu(int cpu, cpumask_var_t mask) #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) #define marker_synchronize_unregister() synchronize_sched() #endif + +/* pci_dev.msi_enable was introduced in 2.6.18 */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) + +struct pci_dev; + +int kvm_pcidev_msi_enabled(struct pci_dev *dev); + +#else + +#define kvm_pcidev_msi_enabled(dev) (dev)->msi_enabled + +#endif diff --git a/kvm/kernel/external-module-compat.c b/kvm/kernel/external-module-compat.c index 823ce8272f..f425e083c3 100644 --- a/kvm/kernel/external-module-compat.c +++ b/kvm/kernel/external-module-compat.c @@ -313,3 +313,24 @@ struct rchan *kvm_relay_open(const char *base_filename, } #endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) + +#include + +int kvm_pcidev_msi_enabled(struct pci_dev *dev) +{ + int pos; + u16 control; + + if (!(pos = pci_find_capability(dev, PCI_CAP_ID_MSI))) + return 0; + + pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &control); + if (control & PCI_MSI_FLAGS_ENABLE) + return 1; + + return 0; +} + +#endif diff --git a/kvm/kernel/x86/hack-module.awk b/kvm/kernel/x86/hack-module.awk index deb68f43a0..a05c0c399b 100644 --- a/kvm/kernel/x86/hack-module.awk +++ b/kvm/kernel/x86/hack-module.awk @@ -29,6 +29,8 @@ BEGIN { split("INIT_WORK tsc_khz desc_struct ldttss_desc64 desc_ptr " \ printf("MODULE_INFO(version, \"%s\");\n", version) } +{ sub(/match->dev->msi_enabled/, "kvm_pcidev_msi_enabled(match->dev)") } + /^static void __vmx_load_host_state/ { vmx_load_host_state = 1 } -- 2.11.4.GIT