aboutsummaryrefslogtreecommitdiffstats
path: root/virt/kvm/irq_comm.c
diff options
context:
space:
mode:
authorGleb Natapov <gleb@redhat.com>2009-03-05 09:34:49 -0500
committerAvi Kivity <avi@redhat.com>2009-06-10 04:48:27 -0400
commita53c17d21c46a752f5ac6695376481bc27865b04 (patch)
treef7ece20fcb0adbf4cabc580fb5a16cf5eec0a897 /virt/kvm/irq_comm.c
parent6da7e3f643cf7099965d75fda8606b9d3a8650b9 (diff)
KVM: ioapic/msi interrupt delivery consolidation
ioapic_deliver() and kvm_set_msi() have code duplication. Move the code into ioapic_deliver_entry() function and call it from both places. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'virt/kvm/irq_comm.c')
-rw-r--r--virt/kvm/irq_comm.c32
1 files changed, 3 insertions, 29 deletions
diff --git a/virt/kvm/irq_comm.c b/virt/kvm/irq_comm.c
index 325c6685f206..35397a569b24 100644
--- a/virt/kvm/irq_comm.c
+++ b/virt/kvm/irq_comm.c
@@ -43,12 +43,11 @@ static int kvm_set_ioapic_irq(struct kvm_kernel_irq_routing_entry *e,
43 return kvm_ioapic_set_irq(kvm->arch.vioapic, e->irqchip.pin, level); 43 return kvm_ioapic_set_irq(kvm->arch.vioapic, e->irqchip.pin, level);
44} 44}
45 45
46void kvm_get_intr_delivery_bitmask(struct kvm_ioapic *ioapic, 46void kvm_get_intr_delivery_bitmask(struct kvm *kvm,
47 union kvm_ioapic_redirect_entry *entry, 47 union kvm_ioapic_redirect_entry *entry,
48 unsigned long *deliver_bitmask) 48 unsigned long *deliver_bitmask)
49{ 49{
50 int i; 50 int i;
51 struct kvm *kvm = ioapic->kvm;
52 struct kvm_vcpu *vcpu; 51 struct kvm_vcpu *vcpu;
53 52
54 bitmap_zero(deliver_bitmask, KVM_MAX_VCPUS); 53 bitmap_zero(deliver_bitmask, KVM_MAX_VCPUS);
@@ -90,7 +89,7 @@ void kvm_get_intr_delivery_bitmask(struct kvm_ioapic *ioapic,
90 switch (entry->fields.delivery_mode) { 89 switch (entry->fields.delivery_mode) {
91 case IOAPIC_LOWEST_PRIORITY: 90 case IOAPIC_LOWEST_PRIORITY:
92 /* Select one in deliver_bitmask */ 91 /* Select one in deliver_bitmask */
93 vcpu = kvm_get_lowest_prio_vcpu(ioapic->kvm, 92 vcpu = kvm_get_lowest_prio_vcpu(kvm,
94 entry->fields.vector, deliver_bitmask); 93 entry->fields.vector, deliver_bitmask);
95 bitmap_zero(deliver_bitmask, KVM_MAX_VCPUS); 94 bitmap_zero(deliver_bitmask, KVM_MAX_VCPUS);
96 if (!vcpu) 95 if (!vcpu)
@@ -111,13 +110,7 @@ void kvm_get_intr_delivery_bitmask(struct kvm_ioapic *ioapic,
111static int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, 110static int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e,
112 struct kvm *kvm, int level) 111 struct kvm *kvm, int level)
113{ 112{
114 int vcpu_id, r = -1;
115 struct kvm_vcpu *vcpu;
116 struct kvm_ioapic *ioapic = ioapic_irqchip(kvm);
117 union kvm_ioapic_redirect_entry entry; 113 union kvm_ioapic_redirect_entry entry;
118 DECLARE_BITMAP(deliver_bitmask, KVM_MAX_VCPUS);
119
120 BUG_ON(!ioapic);
121 114
122 entry.bits = 0; 115 entry.bits = 0;
123 entry.fields.dest_id = (e->msi.address_lo & 116 entry.fields.dest_id = (e->msi.address_lo &
@@ -133,26 +126,7 @@ static int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e,
133 (unsigned long *)&e->msi.data); 126 (unsigned long *)&e->msi.data);
134 127
135 /* TODO Deal with RH bit of MSI message address */ 128 /* TODO Deal with RH bit of MSI message address */
136 129 return ioapic_deliver_entry(kvm, &entry);
137 kvm_get_intr_delivery_bitmask(ioapic, &entry, deliver_bitmask);
138
139 if (find_first_bit(deliver_bitmask, KVM_MAX_VCPUS) >= KVM_MAX_VCPUS) {
140 printk(KERN_WARNING "kvm: no destination for MSI delivery!");
141 return -1;
142 }
143 while ((vcpu_id = find_first_bit(deliver_bitmask,
144 KVM_MAX_VCPUS)) < KVM_MAX_VCPUS) {
145 __clear_bit(vcpu_id, deliver_bitmask);
146 vcpu = ioapic->kvm->vcpus[vcpu_id];
147 if (vcpu) {
148 if (r < 0)
149 r = 0;
150 r += kvm_apic_set_irq(vcpu, entry.fields.vector,
151 entry.fields.dest_mode,
152 entry.fields.trig_mode);
153 }
154 }
155 return r;
156} 130}
157 131
158/* This should be called with the kvm->lock mutex held 132/* This should be called with the kvm->lock mutex held