From patchwork Mon Aug 27 06:28:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 1376371 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 48DA3E007B for ; Mon, 27 Aug 2012 06:29:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752455Ab2H0G3L (ORCPT ); Mon, 27 Aug 2012 02:29:11 -0400 Received: from mout.web.de ([212.227.15.4]:60565 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752336Ab2H0G2z (ORCPT ); Mon, 27 Aug 2012 02:28:55 -0400 Received: from localhost.localdomain ([95.157.56.37]) by smtp.web.de (mrweb103) with ESMTPSA (Nemesis) id 0M8iPI-1Sw1yo47bw-00CfeI; Mon, 27 Aug 2012 08:28:51 +0200 From: Jan Kiszka To: Avi Kivity , Marcelo Tosatti Cc: kvm@vger.kernel.org, qemu-devel@nongnu.org, Alex Williamson , "Michael S. Tsirkin" Subject: [PATCH 1/4] kvm: Introduce kvm_irqchip_update_msi_route Date: Mon, 27 Aug 2012 08:28:38 +0200 Message-Id: <7bda3d33b8f13175c4148eb90e9279e4050a6824.1346048917.git.jan.kiszka@web.de> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: References: In-Reply-To: References: X-Provags-ID: V02:K0:C5mPNPthniZe94uYSFzfixODYBCS/TlM5DJ9V+qHiIJ bTdNtFD1u1tJY0M4XdrdBg/gvSkp25aMxtpUJT4eOWR0Ip89MU nBgaqGL/lduSJEq8kI6W2xWU9jGmHVfMp0TgQEcr8k9lkqxk0u 7Jo/HAZpcV82bR+fNSMt95BRFdwDhrx5FMUbKn7RhDBN702fjR +ouhfrvmoAdDjsx9HdiOw== Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Jan Kiszka This service allows to update an MSI route without releasing/reacquiring the associated VIRQ. Will be used by PCI device assignment, later on likely also by virtio/vhost and VFIO. Signed-off-by: Jan Kiszka --- kvm-all.c | 42 ++++++++++++++++++++++++++++++++++++++++++ kvm.h | 1 + 2 files changed, 43 insertions(+), 0 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index d4d8a1f..fd9d9b4 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -963,6 +963,30 @@ static void kvm_add_routing_entry(KVMState *s, kvm_irqchip_commit_routes(s); } +static int kvm_update_routing_entry(KVMState *s, + struct kvm_irq_routing_entry *new_entry) +{ + struct kvm_irq_routing_entry *entry; + int n; + + for (n = 0; n < s->irq_routes->nr; n++) { + entry = &s->irq_routes->entries[n]; + if (entry->gsi != new_entry->gsi) { + continue; + } + + entry->type = new_entry->type; + entry->flags = new_entry->flags; + entry->u = new_entry->u; + + kvm_irqchip_commit_routes(s); + + return 0; + } + + return -ESRCH; +} + void kvm_irqchip_add_irq_route(KVMState *s, int irq, int irqchip, int pin) { struct kvm_irq_routing_entry e; @@ -1125,6 +1149,24 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg) return virq; } +int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg) +{ + struct kvm_irq_routing_entry kroute; + + if (!kvm_irqchip_in_kernel()) { + return -ENOSYS; + } + + kroute.gsi = virq; + kroute.type = KVM_IRQ_ROUTING_MSI; + kroute.flags = 0; + kroute.u.msi.address_lo = (uint32_t)msg.address; + kroute.u.msi.address_hi = msg.address >> 32; + kroute.u.msi.data = msg.data; + + return kvm_update_routing_entry(s, &kroute); +} + static int kvm_irqchip_assign_irqfd(KVMState *s, int fd, int virq, bool assign) { struct kvm_irqfd irqfd = { diff --git a/kvm.h b/kvm.h index 37d1f81..5cefe3a 100644 --- a/kvm.h +++ b/kvm.h @@ -270,6 +270,7 @@ int kvm_set_ioeventfd_mmio(int fd, uint32_t adr, uint32_t val, bool assign, int kvm_set_ioeventfd_pio_word(int fd, uint16_t adr, uint16_t val, bool assign); int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg); +int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg); void kvm_irqchip_release_virq(KVMState *s, int virq); int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);