From c2b0895e2f5d0b3645d124f467bc70cb5394c98f Mon Sep 17 00:00:00 2001 From: Sheng Yang Date: Tue, 17 Mar 2009 11:50:09 +0800 Subject: [PATCH] kvm: libkvm: allocate unused gsi for irq routing Notice here is a simple solution, can be replaced later. Signed-off-by: Sheng Yang Signed-off-by: Avi Kivity --- kvm/libkvm/kvm-common.h | 1 + kvm/libkvm/libkvm.c | 17 ++++++++++++++++- kvm/libkvm/libkvm.h | 8 ++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/kvm/libkvm/kvm-common.h b/kvm/libkvm/kvm-common.h index de1ada2e5f..70a95c207a 100644 --- a/kvm/libkvm/kvm-common.h +++ b/kvm/libkvm/kvm-common.h @@ -66,6 +66,7 @@ struct kvm_context { #ifdef KVM_CAP_IRQ_ROUTING struct kvm_irq_routing *irq_routes; int nr_allocated_irq_routes; + int max_used_gsi; #endif }; diff --git a/kvm/libkvm/libkvm.c b/kvm/libkvm/libkvm.c index 36036b8995..f43e2c516c 100644 --- a/kvm/libkvm/libkvm.c +++ b/kvm/libkvm/libkvm.c @@ -421,7 +421,7 @@ int kvm_check_extension(kvm_context_t kvm, int ext) ret = ioctl(kvm->fd, KVM_CHECK_EXTENSION, ext); if (ret > 0) - return 1; + return ret; return 0; } @@ -1297,6 +1297,9 @@ int kvm_add_routing_entry(kvm_context_t kvm, new->type = entry->type; new->flags = entry->flags; new->u = entry->u; + + if (entry->gsi > kvm->max_used_gsi) + kvm->max_used_gsi = entry->gsi; return 0; #else return -ENOSYS; @@ -1400,3 +1403,15 @@ int kvm_commit_irq_routes(kvm_context_t kvm) return -ENOSYS; #endif } + +int kvm_get_irq_route_gsi(kvm_context_t kvm) +{ + if (kvm->max_used_gsi >= KVM_IOAPIC_NUM_PINS) { + if (kvm->max_used_gsi <= kvm_get_gsi_count(kvm)) + return kvm->max_used_gsi + 1; + else + return -ENOSPC; + } else + return KVM_IOAPIC_NUM_PINS; +} + diff --git a/kvm/libkvm/libkvm.h b/kvm/libkvm/libkvm.h index 51f4d0814b..9a7cbc65c9 100644 --- a/kvm/libkvm/libkvm.h +++ b/kvm/libkvm/libkvm.h @@ -846,4 +846,12 @@ int kvm_del_routing_entry(kvm_context_t kvm, */ int kvm_commit_irq_routes(kvm_context_t kvm); +/*! + * \brief Get unused GSI number for irq routing table + * + * Get unused GSI number for irq routing table + * + * \param kvm Pointer to the current kvm_context + */ +int kvm_get_irq_route_gsi(kvm_context_t kvm); #endif -- 2.11.4.GIT