From patchwork Thu Mar 19 10:05:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 46022 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 79B2A2153C for ; Thu, 19 Mar 2015 10:05:55 +0000 (UTC) Received: by wivz2 with SMTP id z2sf12000466wiv.1 for ; Thu, 19 Mar 2015 03:05:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=nkaNAR1gH1V4AabHTdeqRfuPbx6lkXx1iO6zy973qUE=; b=aZIVz4NeFYrM+k9j8X7m1cXmQNsgTtqU++/GEQhTKnTbNdOvFTZ10buVwhMPRJZT2I qbsHSDHLeiFr3ReyMgGxy5t2ry9l36GLWQO+kTA62k04vM/pk5+aMNPWbb8NF6d9Dwal msHvLKTx4Gg7B8JEwEOWyt4F8VCBEJJmIVbYXcFfoI2F0zT8k9KAdIl0Qfg79tFusuOA i9L63SjX1/5hfffmruCCkGF2an7Fng4e4lT9LVLY3FFLAglSJf4hKXHiRyi+dhoEmWAq gEz2zTPeI+OR0uK0c2DcVeYVbU9luNREVOmMZRKsZFmKEkwuvuMjmv5wQmiN+L4HZgAN YAfw== X-Gm-Message-State: ALoCoQmiDQMWzI0DkwaMhF32+X/okHzo+a0RyaKdaSM6vVOGDfl9YmhYtefT3emFTgwSwy7hRDF8 X-Received: by 10.152.3.70 with SMTP id a6mr1082110laa.0.1426759554818; Thu, 19 Mar 2015 03:05:54 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.6 with SMTP id v6ls274015laa.13.gmail; Thu, 19 Mar 2015 03:05:54 -0700 (PDT) X-Received: by 10.112.161.66 with SMTP id xq2mr68269976lbb.103.1426759554385; Thu, 19 Mar 2015 03:05:54 -0700 (PDT) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id jr14si570829lab.166.2015.03.19.03.05.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 03:05:54 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by labjg1 with SMTP id jg1so57814374lab.2 for ; Thu, 19 Mar 2015 03:05:54 -0700 (PDT) X-Received: by 10.152.206.70 with SMTP id lm6mr69388045lac.35.1426759554286; Thu, 19 Mar 2015 03:05:54 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.35.133 with SMTP id h5csp276982lbj; Thu, 19 Mar 2015 03:05:53 -0700 (PDT) X-Received: by 10.180.81.7 with SMTP id v7mr14951569wix.27.1426759551163; Thu, 19 Mar 2015 03:05:51 -0700 (PDT) Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com. [209.85.212.181]) by mx.google.com with ESMTPS id ev20si1479913wjc.79.2015.03.19.03.05.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 03:05:51 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.181 as permitted sender) client-ip=209.85.212.181; Received: by wifj2 with SMTP id j2so64135532wif.1 for ; Thu, 19 Mar 2015 03:05:50 -0700 (PDT) X-Received: by 10.180.72.98 with SMTP id c2mr14814636wiv.87.1426759550892; Thu, 19 Mar 2015 03:05:50 -0700 (PDT) Received: from midway01-04-00.lavalab ([81.128.185.50]) by mx.google.com with ESMTPSA id y14sm1257677wjr.39.2015.03.19.03.05.50 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Mar 2015 03:05:50 -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, b.reynal@virtualopensystems.com Cc: christoffer.dall@linaro.org, kvmarm@lists.cs.columbia.edu, patches@linaro.org, pbonzini@redhat.com, kim.phillips@freescale.com, a.rigo@virtualopensystems.com Subject: [PATCH v11 4/9] hw/vfio/platform: add capability to start IRQ propagation Date: Thu, 19 Mar 2015 10:05:33 +0000 Message-Id: <1426759538-18030-5-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1426759538-18030-1-git-send-email-eric.auger@linaro.org> References: <1426759538-18030-1-git-send-email-eric.auger@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 933940c..59eeca2 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*/