From patchwork Fri Jan 30 13:46:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baptiste Reynal X-Patchwork-Id: 5750371 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B7DD8BF440 for ; Fri, 30 Jan 2015 13:51:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CDE222027D for ; Fri, 30 Jan 2015 13:51:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C9F1120279 for ; Fri, 30 Jan 2015 13:51:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761965AbbA3Nvc (ORCPT ); Fri, 30 Jan 2015 08:51:32 -0500 Received: from mail-wi0-f171.google.com ([209.85.212.171]:59072 "EHLO mail-wi0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964951AbbA3Ntd (ORCPT ); Fri, 30 Jan 2015 08:49:33 -0500 Received: by mail-wi0-f171.google.com with SMTP id l15so3163498wiw.4 for ; Fri, 30 Jan 2015 05:49:32 -0800 (PST) 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=fYPI3ELYoJ0zHO7PP+6k18PbK/7iafxuZtxTwiqgOLo=; b=kyVYBvurGnJtfLB5Hk5uFuZT7SPKdlj4i52h4lvdH86WFxzxKu6VgRDohvMXHrEbMR /CKOFDo1ezSiTED7JB8+h7kjwWeU4qgHtBCKPMiCcVbsMJO80ZoNnCuxQbVWSQ1C8RPP I+/NTeXhHWdUNWoaQ6iddcurL+0NmXCJTWs8ozqhGvFJbK/MX6ev5y247efgQY2hlPhR GmKRT4wxQyfb4Unglpl5yjm5xJWoGFE1EjV9umZ8+wzVXMWNYIee+jCVpgNJntow4R2D PL4Qs/fYnmIHoC/f0Cte3jeeYrYsp4wn+ykk+1xG9XSIYVxY4biNy8NSPShcu5XfgPJo +FjQ== X-Gm-Message-State: ALoCoQlKnElKNJ0zEsbGOxP3wBohhJR/4Gyn86aoSKQxFB7MyUxx7SACIcoS1dozrdRLQkJn4TJl X-Received: by 10.180.108.239 with SMTP id hn15mr5122379wib.5.1422625771442; Fri, 30 Jan 2015 05:49:31 -0800 (PST) Received: from localhost (LPuteaux-656-1-278-113.w80-15.abo.wanadoo.fr. [80.15.154.113]) by mx.google.com with ESMTPSA id ev7sm15011087wjb.47.2015.01.30.05.49.30 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Jan 2015 05:49:30 -0800 (PST) From: Baptiste Reynal To: kvmarm@lists.cs.columbia.edu, iommu@lists.linux-foundation.org, alex.williamson@redhat.com Cc: will.deacon@arm.com, tech@virtualopensystems.com, christoffer.dall@linaro.org, eric.auger@linaro.org, kim.phillips@freescale.com, marc.zyngier@arm.com, Antonios Motakis , Bjorn Helgaas , Baptiste Reynal , Alexander Gordeev , Gavin Shan , Jiang Liu , kvm@vger.kernel.org (open list:VFIO DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v13 15/18] vfio: pass an opaque pointer on virqfd initialization Date: Fri, 30 Jan 2015 14:46:21 +0100 Message-Id: <1422625584-3741-16-git-send-email-b.reynal@virtualopensystems.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1422625584-3741-1-git-send-email-b.reynal@virtualopensystems.com> References: <1422625584-3741-1-git-send-email-b.reynal@virtualopensystems.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Antonios Motakis VFIO_PCI passes the VFIO device structure *vdev via eventfd to the handler that implements masking/unmasking of IRQs via an eventfd. We can replace it in the virqfd infrastructure with an opaque type so we can make use of the mechanism from other VFIO bus drivers. Signed-off-by: Antonios Motakis --- drivers/vfio/pci/vfio_pci_intrs.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index b35bc16..5b5fc23 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -31,10 +31,10 @@ * IRQfd - generic */ struct virqfd { - struct vfio_pci_device *vdev; + void *opaque; struct eventfd_ctx *eventfd; - int (*handler)(struct vfio_pci_device *, void *); - void (*thread)(struct vfio_pci_device *, void *); + int (*handler)(void *, void *); + void (*thread)(void *, void *); void *data; struct work_struct inject; wait_queue_t wait; @@ -74,7 +74,7 @@ static int virqfd_wakeup(wait_queue_t *wait, unsigned mode, int sync, void *key) if (flags & POLLIN) { /* An event has been signaled, call function */ if ((!virqfd->handler || - virqfd->handler(virqfd->vdev, virqfd->data)) && + virqfd->handler(virqfd->opaque, virqfd->data)) && virqfd->thread) schedule_work(&virqfd->inject); } @@ -124,12 +124,12 @@ static void virqfd_inject(struct work_struct *work) { struct virqfd *virqfd = container_of(work, struct virqfd, inject); if (virqfd->thread) - virqfd->thread(virqfd->vdev, virqfd->data); + virqfd->thread(virqfd->opaque, virqfd->data); } -int vfio_virqfd_enable(struct vfio_pci_device *vdev, - int (*handler)(struct vfio_pci_device *, void *), - void (*thread)(struct vfio_pci_device *, void *), +int vfio_virqfd_enable(void *opaque, + int (*handler)(void *, void *), + void (*thread)(void *, void *), void *data, struct virqfd **pvirqfd, int fd) { struct fd irqfd; @@ -143,7 +143,7 @@ int vfio_virqfd_enable(struct vfio_pci_device *vdev, return -ENOMEM; virqfd->pvirqfd = pvirqfd; - virqfd->vdev = vdev; + virqfd->opaque = opaque; virqfd->handler = handler; virqfd->thread = thread; virqfd->data = data; @@ -196,7 +196,7 @@ int vfio_virqfd_enable(struct vfio_pci_device *vdev, * before we registered and trigger it as if we didn't miss it. */ if (events & POLLIN) { - if ((!handler || handler(vdev, data)) && thread) + if ((!handler || handler(opaque, data)) && thread) schedule_work(&virqfd->inject); } @@ -243,8 +243,10 @@ EXPORT_SYMBOL_GPL(vfio_virqfd_disable); /* * INTx */ -static void vfio_send_intx_eventfd(struct vfio_pci_device *vdev, void *unused) +static void vfio_send_intx_eventfd(void *opaque, void *unused) { + struct vfio_pci_device *vdev = opaque; + if (likely(is_intx(vdev) && !vdev->virq_disabled)) eventfd_signal(vdev->ctx[0].trigger, 1); } @@ -287,9 +289,9 @@ void vfio_pci_intx_mask(struct vfio_pci_device *vdev) * a signal is necessary, which can then be handled via a work queue * or directly depending on the caller. */ -static int vfio_pci_intx_unmask_handler(struct vfio_pci_device *vdev, - void *unused) +static int vfio_pci_intx_unmask_handler(void *opaque, void *unused) { + struct vfio_pci_device *vdev = opaque; struct pci_dev *pdev = vdev->pdev; unsigned long flags; int ret = 0; @@ -641,7 +643,7 @@ static int vfio_pci_set_intx_unmask(struct vfio_pci_device *vdev, } else if (flags & VFIO_IRQ_SET_DATA_EVENTFD) { int32_t fd = *(int32_t *)data; if (fd >= 0) - return vfio_virqfd_enable(vdev, + return vfio_virqfd_enable((void *) vdev, vfio_pci_intx_unmask_handler, vfio_send_intx_eventfd, NULL, &vdev->ctx[0].unmask, fd);