[PATCH 02/13] qemu-kvm: Drop some no longer needed #ifdefs

Jan Kiszka
2011-06-27T18:20:24Z

From: Jan Kiszka <jan.kiszka@siemens.com>

Not a complete cleanup, other code has more subtle dependencies. Will be
resolved during upstream merge.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
hw/device-assignment.c | 52 ++++++-----------------------------------------
kvm-all.c | 4 ---
qemu-kvm-x86.c | 20 ------------------
qemu-kvm.h | 23 ---------------------
target-i386/kvm.c | 2 -
5 files changed, 7 insertions(+), 94 deletions(-)

diff --git a/hw/device-assignment.c b/hw/device-assignment.c
index 57d8dc0..6a2a8c9 100644
--- a/hw/device-assignment.c
+++ b/hw/device-assignment.c
@@ -800,7 +800,6 @@ again:

static QLIST_HEAD(, AssignedDevice) devs = QLIST_HEAD_INITIALIZER(devs);

-#ifdef KVM_CAP_IRQ_ROUTING
static void free_dev_irq_entries(AssignedDevice *dev)
{
int i;
@@ -811,7 +810,6 @@ static void free_dev_irq_entries(AssignedDevice *dev)
dev->entry = NULL;
dev->irq_entries_nr = 0;
}
-#endif

static void free_assigned_device(AssignedDevice *dev)
{
@@ -860,9 +858,7 @@ static void free_assigned_device(AssignedDevice *dev)
close(dev->real_device.config_fd);
}

-#ifdef KVM_CAP_IRQ_ROUTING
free_dev_irq_entries(dev);
-#endif
}

static uint32_t calc_assigned_dev_id(uint16_t seg, uint8_t bus, uint8_t devfn)
@@ -922,7 +918,6 @@ static int assign_device(AssignedDevice *dev)
struct kvm_assigned_pci_dev assigned_dev_data;
int r;

-#ifdef KVM_CAP_PCI_SEGMENT
/* Only pass non-zero PCI segment to capable module */
if (!kvm_check_extension(kvm_state, KVM_CAP_PCI_SEGMENT) &&
dev->h_segnr) {
@@ -930,18 +925,14 @@ static int assign_device(AssignedDevice *dev)
"as this KVM module doesn't support it.\n");
return -ENODEV;
}
-#endif

memset(&assigned_dev_data, 0, sizeof(assigned_dev_data));
assigned_dev_data.assigned_dev_id =
calc_assigned_dev_id(dev->h_segnr, dev->h_busnr, dev->h_devfn);
-#ifdef KVM_CAP_PCI_SEGMENT
assigned_dev_data.segnr = dev->h_segnr;
-#endif
assigned_dev_data.busnr = dev->h_busnr;
assigned_dev_data.devfn = dev->h_devfn;

-#ifdef KVM_CAP_IOMMU
/* We always enable the IOMMU unless disabled on the command line */
if (dev->features & ASSIGNED_DEVICE_USE_IOMMU_MASK) {
if (!kvm_check_extension(kvm_state, KVM_CAP_IOMMU)) {
@@ -951,9 +942,6 @@ static int assign_device(AssignedDevice *dev)
}
assigned_dev_data.flags |= KVM_DEV_ASSIGN_ENABLE_IOMMU;
}
-#else
- dev->features &= ~ASSIGNED_DEVICE_USE_IOMMU_MASK;
-#endif
if (!(dev->features & ASSIGNED_DEVICE_USE_IOMMU_MASK)) {
fprintf(stderr,
"WARNING: Assigning a device without IOMMU protection can "
@@ -1001,7 +989,6 @@ static int assign_irq(AssignedDevice *dev)
calc_assigned_dev_id(dev->h_segnr, dev->h_busnr, dev->h_devfn);
assigned_irq_data.guest_irq = irq;
assigned_irq_data.host_irq = dev->real_device.irq;
-#ifdef KVM_CAP_ASSIGN_DEV_IRQ
if (dev->irq_requested_type) {
assigned_irq_data.flags = dev->irq_requested_type;
r = kvm_deassign_irq(kvm_state, &assigned_irq_data);
@@ -1016,7 +1003,6 @@ static int assign_irq(AssignedDevice *dev)
assigned_irq_data.flags |= KVM_DEV_IRQ_HOST_MSI;
else
assigned_irq_data.flags |= KVM_DEV_IRQ_HOST_INTX;
-#endif

r = kvm_assign_irq(kvm_state, &assigned_irq_data);
if (r < 0) {
@@ -1034,7 +1020,6 @@ static int assign_irq(AssignedDevice *dev)

static void deassign_device(AssignedDevice *dev)
{
-#ifdef KVM_CAP_DEVICE_DEASSIGNMENT
struct kvm_assigned_pci_dev assigned_dev_data;
int r;

@@ -1046,7 +1031,6 @@ static void deassign_device(AssignedDevice *dev)
if (r < 0)
fprintf(stderr, "Failed to deassign device \"%s\" : %s\n",
dev->dev.qdev.id, strerror(-r));
-#endif
}

#if 0
@@ -1084,9 +1068,6 @@ void assigned_dev_update_irqs(void)
}
}

-#ifdef KVM_CAP_IRQ_ROUTING
-
-#ifdef KVM_CAP_DEVICE_MSI
static void assigned_dev_update_msi(PCIDevice *pci_dev, unsigned int ctrl_pos)
{
struct kvm_assigned_irq assigned_irq_data;
@@ -1151,9 +1132,7 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev, unsigned int ctrl_pos)
assign_irq(assigned_dev);
}
}
-#endif

-#ifdef KVM_CAP_DEVICE_MSIX
static int assigned_dev_update_msix_mmio(PCIDevice *pci_dev)
{
AssignedDevice *adev = DO_UPCAST(AssignedDevice, dev, pci_dev);
@@ -1290,8 +1269,6 @@ static void assigned_dev_update_msix(PCIDevice *pci_dev, unsigned int ctrl_pos)
assign_irq(assigned_dev);
}
}
-#endif
-#endif

/* There can be multiple VNDR capabilities per device, we need to find the
* one that starts closet to the given address without going over. */
@@ -1338,32 +1315,23 @@ static void assigned_device_pci_cap_write_config(PCIDevice *pci_dev,
uint32_t val, int len)
{
uint8_t cap_id = pci_dev->config_map[address];
+ uint8_t cap;

pci_default_write_config(pci_dev, address, val, len);
switch (cap_id) {
-#ifdef KVM_CAP_IRQ_ROUTING
case PCI_CAP_ID_MSI:
-#ifdef KVM_CAP_DEVICE_MSI
- {
- uint8_t cap = pci_find_capability(pci_dev, cap_id);
- if (ranges_overlap(address - cap, len, PCI_MSI_FLAGS, 1)) {
- assigned_dev_update_msi(pci_dev, cap + PCI_MSI_FLAGS);
- }
+ cap = pci_find_capability(pci_dev, cap_id);
+ if (ranges_overlap(address - cap, len, PCI_MSI_FLAGS, 1)) {
+ assigned_dev_update_msi(pci_dev, cap + PCI_MSI_FLAGS);
}
-#endif
break;

case PCI_CAP_ID_MSIX:
-#ifdef KVM_CAP_DEVICE_MSIX
- {
- uint8_t cap = pci_find_capability(pci_dev, cap_id);
- if (ranges_overlap(address - cap, len, PCI_MSIX_FLAGS + 1, 1)) {
- assigned_dev_update_msix(pci_dev, cap + PCI_MSIX_FLAGS);
- }
+ cap = pci_find_capability(pci_dev, cap_id);
+ if (ranges_overlap(address - cap, len, PCI_MSIX_FLAGS + 1, 1)) {
+ assigned_dev_update_msix(pci_dev, cap + PCI_MSIX_FLAGS);
}
-#endif
break;
-#endif

case PCI_CAP_ID_VPD:
case PCI_CAP_ID_VNDR:
@@ -1384,8 +1352,6 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev)
pci_get_word(pci_dev->config + PCI_STATUS) &
~PCI_STATUS_CAP_LIST);

-#ifdef KVM_CAP_IRQ_ROUTING
-#ifdef KVM_CAP_DEVICE_MSI
/* Expose MSI capability
* MSI capability is the 1st capability in capability config */
if ((pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSI, 0))) {
@@ -1407,8 +1373,6 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev)
pci_set_long(pci_dev->wmask + pos + PCI_MSI_ADDRESS_LO, 0xfffffffc);
pci_set_word(pci_dev->wmask + pos + PCI_MSI_DATA_32, 0xffff);
}
-#endif
-#ifdef KVM_CAP_DEVICE_MSIX
/* Expose MSI-X capability */
if ((pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_MSIX, 0))) {
int bar_nr;
@@ -1432,8 +1396,6 @@ static int assigned_device_pci_cap_init(PCIDevice *pci_dev)
msix_table_entry &= ~PCI_MSIX_BIR;
dev->msix_table_addr = pci_region[bar_nr].base_addr + msix_table_entry;
}
-#endif
-#endif

/* Minimal PM support, nothing writable, device appears to NAK changes */
if ((pos = pci_find_cap_offset(pci_dev, PCI_CAP_ID_PM, 0))) {
diff --git a/kvm-all.c b/kvm-all.c
index 34453dc..3ad2459 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1418,7 +1418,6 @@ int kvm_set_ioeventfd_pio_word(int fd, uint16_t addr, uint16_t val, bool assign)

int kvm_set_irqfd(int gsi, int fd, bool assigned)
{
-#if defined(KVM_IRQFD)
struct kvm_irqfd irqfd = {
.fd = fd,
.gsi = gsi,
@@ -1432,9 +1431,6 @@ int kvm_set_irqfd(int gsi, int fd, bool assigned)
if (r < 0)
return r;
return 0;
-#else
- return -ENOSYS;
-#endif
}

int kvm_on_sigbus_vcpu(CPUState *env, int code, void *addr)
diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index 2a01ccc..a7981b1 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -25,7 +25,6 @@

static int kvm_create_pit(KVMState *s)
{
-#ifdef KVM_CAP_PIT
int r;

if (kvm_pit) {
@@ -43,12 +42,9 @@ static int kvm_create_pit(KVMState *s)
}
}
}
-#endif
return 0;
}

-#ifdef KVM_EXIT_TPR_ACCESS
-
int kvm_handle_tpr_access(CPUState *env)
{
struct kvm_run *run = env->kvm_run;
@@ -68,10 +64,6 @@ int kvm_enable_vapic(CPUState *env, uint64_t vapic)
return kvm_vcpu_ioctl(env, KVM_SET_VAPIC_ADDR, &va);
}

-#endif
-
-#ifdef KVM_CAP_IRQCHIP
-
int kvm_get_lapic(CPUState *env, struct kvm_lapic_state *s)
{
int r = 0;
@@ -103,10 +95,6 @@ int kvm_set_lapic(CPUState *env, struct kvm_lapic_state *s)
return r;
}

-#endif
-
-#ifdef KVM_CAP_PIT
-
int kvm_get_pit(KVMState *s, struct kvm_pit_state *pit_state)
{
if (!kvm_pit_in_kernel()) {
@@ -123,7 +111,6 @@ int kvm_set_pit(KVMState *s, struct kvm_pit_state *pit_state)
return kvm_vm_ioctl(s, KVM_SET_PIT, pit_state);
}

-#ifdef KVM_CAP_PIT_STATE2
int kvm_get_pit2(KVMState *s, struct kvm_pit_state2 *ps2)
{
if (!kvm_pit_in_kernel()) {
@@ -140,10 +127,6 @@ int kvm_set_pit2(KVMState *s, struct kvm_pit_state2 *ps2)
return kvm_vm_ioctl(s, KVM_SET_PIT2, ps2);
}

-#endif
-#endif
-
-#ifdef KVM_CAP_VAPIC
static int kvm_enable_tpr_access_reporting(CPUState *env)
{
int r;
@@ -155,15 +138,12 @@ static int kvm_enable_tpr_access_reporting(CPUState *env)
}
return kvm_vcpu_ioctl(env, KVM_TPR_ACCESS_REPORTING, &tac);
}
-#endif

static int _kvm_arch_init_vcpu(CPUState *env)
{
kvm_arch_reset_vcpu(env);

-#ifdef KVM_EXIT_TPR_ACCESS
kvm_enable_tpr_access_reporting(env);
-#endif

return kvm_update_ioport_access(env);
}
diff --git a/qemu-kvm.h b/qemu-kvm.h
index 09d07d0..f3f775c 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -39,7 +39,6 @@

int kvm_create_irqchip(KVMState *s);

-#ifdef KVM_CAP_IRQCHIP
/*!
* \brief Dump in kernel IRQCHIP contents
*
@@ -86,13 +85,6 @@ int kvm_get_lapic(CPUState *env, struct kvm_lapic_state *s);
*/
int kvm_set_lapic(CPUState *env, struct kvm_lapic_state *s);

-#endif
-
-#endif
-
-#ifdef KVM_CAP_PIT
-
-#if defined(__i386__) || defined(__x86_64__)
/*!
* \brief Get in kernel PIT of the virtual domain
*
@@ -116,7 +108,6 @@ int kvm_set_pit(KVMState *s, struct kvm_pit_state *pit_state);

int kvm_reinject_control(KVMState *s, int pit_reinject);

-#ifdef KVM_CAP_PIT_STATE2
/*!
* \brief Set in kernel PIT state2 of the virtual domain
*
@@ -138,16 +129,9 @@ int kvm_set_pit2(KVMState *s, struct kvm_pit_state2 *ps2);
int kvm_get_pit2(KVMState *s, struct kvm_pit_state2 *ps2);

#endif
-#endif
-#endif
-
-#ifdef KVM_CAP_VAPIC

int kvm_enable_vapic(CPUState *env, uint64_t vapic);

-#endif
-
-#ifdef KVM_CAP_DEVICE_ASSIGNMENT
/*!
* \brief Notifies host kernel about a PCI device to be assigned to a guest
*
@@ -171,7 +155,6 @@ int kvm_assign_pci_device(KVMState *s,
*/
int kvm_assign_irq(KVMState *s, struct kvm_assigned_irq *assigned_irq);

-#ifdef KVM_CAP_ASSIGN_DEV_IRQ
/*!
* \brief Deassign IRQ for an assigned device
*
@@ -182,10 +165,7 @@ int kvm_assign_irq(KVMState *s, struct kvm_assigned_irq *assigned_irq);
* \param assigned_irq Parameters, like dev id, host irq, guest irq, etc
*/
int kvm_deassign_irq(KVMState *s, struct kvm_assigned_irq *assigned_irq);
-#endif
-#endif

-#ifdef KVM_CAP_DEVICE_DEASSIGNMENT
/*!
* \brief Notifies host kernel about a PCI device to be deassigned from a guest
*
@@ -197,7 +177,6 @@ int kvm_deassign_irq(KVMState *s, struct kvm_assigned_irq *assigned_irq);
*/
int kvm_deassign_pci_device(KVMState *s,
struct kvm_assigned_pci_dev *assigned_dev);
-#endif

/*!
* \brief Clears the temporary irq routing table
@@ -252,11 +231,9 @@ int kvm_update_routing_entry(struct kvm_irq_routing_entry *entry,
struct kvm_irq_routing_entry *newentry);

-#ifdef KVM_CAP_DEVICE_MSIX
int kvm_assign_set_msix_nr(KVMState *s, struct kvm_assigned_msix_nr *msix_nr);
int kvm_assign_set_msix_entry(KVMState *s,
struct kvm_assigned_msix_entry *entry);
-#endif

#else /* !CONFIG_KVM */

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index cfc6c78..aa843f0 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -512,13 +512,11 @@ int kvm_arch_init_vcpu(CPUState *env)

static void kvm_clear_vapic(CPUState *env)
{
-#ifdef KVM_SET_VAPIC_ADDR
struct kvm_vapic_addr va = {
.vapic_addr = 0,
};

kvm_vcpu_ioctl(env, KVM_SET_VAPIC_ADDR, &va);
-#endif
}

void kvm_arch_reset_vcpu(CPUState *env)
--
1.7.1