From patchwork Thu Mar 19 17:16:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 452072 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 767811400B7 for ; Fri, 20 Mar 2015 04:17:47 +1100 (AEDT) Received: from localhost ([::1]:40297 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYe4n-0001zn-Ib for incoming@patchwork.ozlabs.org; Thu, 19 Mar 2015 13:17:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47265) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYe45-0000gA-RH for qemu-devel@nongnu.org; Thu, 19 Mar 2015 13:17:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYe3x-000595-6N for qemu-devel@nongnu.org; Thu, 19 Mar 2015 13:17:01 -0400 Received: from mail-wg0-f48.google.com ([74.125.82.48]:34874) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYe3x-000590-0l for qemu-devel@nongnu.org; Thu, 19 Mar 2015 13:16:53 -0400 Received: by wgdm6 with SMTP id m6so68339840wgd.2 for ; Thu, 19 Mar 2015 10:16:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OM7YPo5sJ9QkPJdUlma6sGQlv9jSgFU2gU2F903H0FQ=; b=diC6Hv2EMAPFnolJLDAkU5s24nizsRgOJuvc1OGj+SlpHaSMts++eY1Q94MP+kTm/M KfiDb2aH3xMwrr0A7+Kr9TC+VzLGLQ0CPN+JfOhbB5bXch9RMjfrFRjZzGC1aCOC9QPf 7w88pR+CtGyps8h1WtxUckl1xhb8JmDf+WxoGj3y3GOMvi04TEk8vOsZQ1gA1l6hfnoN Y0EBnrJ8psAC/GveD/lmcCnstoxrPzm7dHzWR9qNW8h6H5MxPtvViZriQP/R/WfQ8dvM tAPk8VyF4tVq6RUT4MD+b4mwI5IhMv6SJKBj/fSpkRaO6WUBc+Bik3B+W/IiCddiNi1a t3qQ== X-Gm-Message-State: ALoCoQlLUFkiB11VgbyM0oYD498GrdOdJS/UNrh1SxxHIFO0XRRFAB54XFhpKw2L0sSleeHp5NQX X-Received: by 10.180.93.165 with SMTP id cv5mr17458467wib.51.1426785412517; Thu, 19 Mar 2015 10:16:52 -0700 (PDT) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id pa4sm2767071wjb.11.2015.03.19.10.16.51 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Mar 2015 10:16:51 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, qemu-devel@nongnu.org, alex.williamson@redhat.com, peter.maydell@linaro.org, agraf@suse.de Date: Thu, 19 Mar 2015 17:16:36 +0000 Message-Id: <1426785402-2091-5-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1426785402-2091-1-git-send-email-eric.auger@linaro.org> References: <1426785402-2091-1-git-send-email-eric.auger@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.48 Cc: kim.phillips@freescale.com, b.reynal@virtualopensystems.com, patches@linaro.org, a.rigo@virtualopensystems.com, pbonzini@redhat.com, alex.bennee@linaro.org, kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org Subject: [Qemu-devel] [PATCH v12 4/9] hw/vfio/platform: add capability to start IRQ propagation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add a reset notify function that enables to start the propagation of interrupts to the guest. Signed-off-by: Eric Auger --- v10 -> v11: - comment reword v8 -> v9: - handle failure in vfio_irq_starter --- hw/vfio/platform.c | 64 +++++++++++++++++++++++++++++++++++++++++ include/hw/vfio/vfio-platform.h | 8 ++++++ 2 files changed, 72 insertions(+) diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index 31c2701..361e01b 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -572,6 +572,70 @@ static void vfio_platform_realize(DeviceState *dev, Error **errp) } } +/** + * vfio_irq_starter: Start IRQ forwarding for a specific VFIO device + * @sbdev: Sysbus device handle + * @opaque: DeviceState handle of the interrupt controller the device + * is attached to + * + * The function retrieves the absolute GSI number each VFIO IRQ + * corresponds to and start forwarding. + */ +static int vfio_irq_starter(SysBusDevice *sbdev, void *opaque) +{ + DeviceState *intc = (DeviceState *)opaque; + VFIOPlatformDevice *vdev; + VFIOINTp *intp; + qemu_irq irq; + int gsi, ret; + + if (object_dynamic_cast(OBJECT(sbdev), TYPE_VFIO_PLATFORM)) { + vdev = VFIO_PLATFORM_DEVICE(sbdev); + + QLIST_FOREACH(intp, &vdev->intp_list, next) { + gsi = 0; + while (1) { + irq = qdev_get_gpio_in(intc, gsi); + if (irq == intp->qemuirq) { + break; + } + gsi++; + } + intp->virtualID = gsi; + ret = vdev->start_irq_fn(intp); + if (ret) { + error_report("%s unable to start propagation of IRQ index %d", + vdev->vbasedev.name, intp->pin); + exit(1); + } + } + } + return 0; +} + +/** + * vfio_kick_irqs: start IRQ forwarding for all the VFIO devices + * attached to the platform bus + * @data: Device state handle of the interrupt controller the VFIO IRQs + * must be bound to + * + * Binding to the platform bus IRQs happens on a machine init done + * notifier registered by the platform bus. Only at that time the + * absolute virtual IRQ = GSI is known and allows to setup IRQFD. + * This function typically can be called in a reset notifier registered + * by the machine file. + */ +void vfio_kick_irqs(void *data) +{ + DeviceState *intc = (DeviceState *)data; + DeviceState *dev = + qdev_find_recursive(sysbus_get_default(), TYPE_PLATFORM_BUS_DEVICE); + PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(dev); + + assert(pbus->done_gathering); + foreach_dynamic_sysbus_device(vfio_irq_starter, intc); +} + static const VMStateDescription vfio_platform_vmstate = { .name = TYPE_VFIO_PLATFORM, .unmigratable = 1, diff --git a/include/hw/vfio/vfio-platform.h b/include/hw/vfio/vfio-platform.h index 31893a3..c9ee898 100644 --- a/include/hw/vfio/vfio-platform.h +++ b/include/hw/vfio/vfio-platform.h @@ -77,4 +77,12 @@ typedef struct VFIOPlatformDeviceClass { #define VFIO_PLATFORM_DEVICE_GET_CLASS(obj) \ OBJECT_GET_CLASS(VFIOPlatformDeviceClass, (obj), TYPE_VFIO_PLATFORM) +/** + * vfio_kick_irqs - reset notifier that starts IRQ injection + * for all VFIO dynamic sysbus devices attached to the platform bus. + * + * @opaque: handle to the interrupt controller DeviceState + */ +void vfio_kick_irqs(void *opaque); + #endif /*HW_VFIO_VFIO_PLATFORM_H*/