Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1114443pxb; Sat, 16 Jan 2021 19:59:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJyUeJZ4sTCUOZZ989cEfvD4NdyiK74BIqwwdb8SHM2tXCoHUsCc3xLkonDwgSRSVoVCN7TA X-Received: by 2002:a17:906:7090:: with SMTP id b16mr13831189ejk.76.1610855951083; Sat, 16 Jan 2021 19:59:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610855951; cv=none; d=google.com; s=arc-20160816; b=jj6RQ2vnUf6n3L+Atp3LdwJhRT5cqvoEDK1r4LnXT5QfWXE+Tga6tyVrjKQKAE/BqG CZQshs2w+ui1jOFsVTveHpSE3ZsjrLCa+LZpi9UOReXsy6+iTlyfijD8QGP5xh+p9+AN 0xFFt6prOzkh5/1bYDEEXiNQg24ZeVHWfkG9Seb6p/6gUXCJnmYjuuXm9XZowkuBxADi aI9DdnVErfYu2jwl3mpqhuM/cR26Cbau4lH0q+Qr3TeS6gLSxWmWmZfcz8//DUQTkEB/ bjTTe9yv3XgAchzvGEG8Zys4USZw2CrOPCfgZhvVsk8EOlP9i2tamqFBpQ1A9iDwxc/Y CJtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=zL0mAaynA6nRxLJnMHpwyAv/T/0Uk0SnXAzHYCWha18=; b=xtXPNoOyWp7cGZZ/W1BsXwbR6Xxt2Pm5Nkn9S4eof8pOcaJ+maXuP2Y4rTaFelwuVn INzoqXIfpalctqESXurCNTJKC3EwxzqbIAIR2nIMcYdH7oRoSAUu3qnXMfBjCt2KqWPz jwpnoCU86BL4henHPpG+8YMtGsprzQYmf3Q0XHNuAB+FA3/BqoVRCriaIIQYgnah9ugK uBwvxghdUyW00ufG6OKzH/fkEUWAwLJm2hb5ZNFHN40XFb+35yZVqYPwAviatqY3A8NS ybndaBixbF5HDOT6xmINebYpllnam0VPjFP9y2QEWCYOjStZ80dS7MV6jvlAymwvVi92 LvNg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hp19si5558518ejc.733.2021.01.16.19.58.31; Sat, 16 Jan 2021 19:59:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727407AbhAQD44 (ORCPT + 99 others); Sat, 16 Jan 2021 22:56:56 -0500 Received: from mail-pg1-f171.google.com ([209.85.215.171]:35553 "EHLO mail-pg1-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726864AbhAQD4w (ORCPT ); Sat, 16 Jan 2021 22:56:52 -0500 Received: by mail-pg1-f171.google.com with SMTP id n7so8803280pgg.2; Sat, 16 Jan 2021 19:56:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=zL0mAaynA6nRxLJnMHpwyAv/T/0Uk0SnXAzHYCWha18=; b=M12e8ObYzrvEPL566Pm/URYzYLbXvkKwRyznbn3jISbQp7c1mUI2FRzP+LJFilSEw+ AE1wjcG84qmAn7QsMm3DGcSGoPzhHj/guQweyPOLY4Sb6ZH2tjocuf7VGl5i9W1sVTLk OnxEQMkVTWzyAlXyTT0V8uZ6ZG1Guvl4q6PLMJtG/xL8IGS7qHEqKOxbRU/d6FWr+sm4 y2cGO/SEIRhzZjCVhWTs5XWZA+BGcI3B9Axn3GwD/obE70abK/0mOLDF6gpaOtWCNqUN VfEFmzKePZfFEfoF/STysZm6gM0NRRKEVi+Y7hJdl2XOYyKG514JBu63/K/HZkiizcQM yjiA== X-Gm-Message-State: AOAM531lj291NsVdFQA4X3ivZSVp/fBN7E1RboEGRwB6Wrdw7tpdde3J ZitskgAeghRkQZK3anJpoqM= X-Received: by 2002:a63:597:: with SMTP id 145mr20164257pgf.252.1610855771097; Sat, 16 Jan 2021 19:56:11 -0800 (PST) Received: from localhost ([2601:647:5b00:1161:a4cc:eef9:fbc0:2781]) by smtp.gmail.com with ESMTPSA id k16sm12193778pgg.87.2021.01.16.19.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jan 2021 19:56:10 -0800 (PST) Date: Sat, 16 Jan 2021 19:56:08 -0800 From: Moritz Fischer To: Xu Yilun Cc: mdf@kernel.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, trix@redhat.com, lgoncalv@redhat.com, hao.wu@intel.com Subject: Re: [PATCH v6 1/2] fpga: dfl: add the userspace I/O device support for DFL devices Message-ID: References: <1610502848-30345-1-git-send-email-yilun.xu@intel.com> <1610502848-30345-2-git-send-email-yilun.xu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1610502848-30345-2-git-send-email-yilun.xu@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Xu, On Wed, Jan 13, 2021 at 09:54:07AM +0800, Xu Yilun wrote: > This patch supports the DFL drivers be written in userspace. This is > realized by exposing the userspace I/O device interfaces. > > The driver leverages the uio_pdrv_genirq, it adds the uio_pdrv_genirq > platform device with the DFL device's resources, and let the generic UIO > platform device driver provide support to userspace access to kernel > interrupts and memory locations. > > The driver now supports the ether group feature. To support a new DFL > feature been directly accessed via UIO, its feature id should be added to > the driver's id_table. > > Signed-off-by: Xu Yilun > Reviewed-by: Tom Rix > Acked-by: Wu Hao > --- > v2: switch to the new matching algorithem. It matches DFL devices which > could not be handled by other DFL drivers. > refacor the code about device resources filling. > fix some comments. > v3: split the dfl.c changes out of this patch. > some minor fixes > v4: drop the idea of a generic matching algorithem, instead we specify > each matching device in id_table. > to make clear that only one irq is supported, the irq handling code > is refactored. > v5: refactor the irq resource code. > v6: fix the res[] zero initialization issue. > improve the return code for probe(). > --- > drivers/fpga/Kconfig | 10 +++++ > drivers/fpga/Makefile | 1 + > drivers/fpga/dfl-uio-pdev.c | 93 +++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 104 insertions(+) > create mode 100644 drivers/fpga/dfl-uio-pdev.c > > diff --git a/drivers/fpga/Kconfig b/drivers/fpga/Kconfig > index 5ff9438..61445be 100644 > --- a/drivers/fpga/Kconfig > +++ b/drivers/fpga/Kconfig > @@ -203,6 +203,16 @@ config FPGA_DFL_NIOS_INTEL_PAC_N3000 > the card. It also instantiates the SPI master (spi-altera) for > the card's BMC (Board Management Controller). > > +config FPGA_DFL_UIO_PDEV > + tristate "FPGA DFL Driver for Userspace I/O platform devices" > + depends on FPGA_DFL && UIO_PDRV_GENIRQ > + help > + Enable this to allow some DFL drivers be written in userspace. It Nit: Enable this to allow DFL drivers to be written in userspace. > + adds the uio_pdrv_genirq platform device with the DFL feature's > + resources, and lets the generic UIO platform device driver provide > + support for userspace access to kernel interrupts and memory > + locations. > + > config FPGA_DFL_PCI > tristate "FPGA DFL PCIe Device Driver" > depends on PCI && FPGA_DFL > diff --git a/drivers/fpga/Makefile b/drivers/fpga/Makefile > index 18dc9885..8847fe0 100644 > --- a/drivers/fpga/Makefile > +++ b/drivers/fpga/Makefile > @@ -45,6 +45,7 @@ dfl-afu-objs := dfl-afu-main.o dfl-afu-region.o dfl-afu-dma-region.o > dfl-afu-objs += dfl-afu-error.o > > obj-$(CONFIG_FPGA_DFL_NIOS_INTEL_PAC_N3000) += dfl-n3000-nios.o > +obj-$(CONFIG_FPGA_DFL_UIO_PDEV) += dfl-uio-pdev.o > > # Drivers for FPGAs which implement DFL > obj-$(CONFIG_FPGA_DFL_PCI) += dfl-pci.o > diff --git a/drivers/fpga/dfl-uio-pdev.c b/drivers/fpga/dfl-uio-pdev.c > new file mode 100644 > index 0000000..12b47bf > --- /dev/null > +++ b/drivers/fpga/dfl-uio-pdev.c > @@ -0,0 +1,93 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * DFL driver for Userspace I/O platform devices > + * > + * Copyright (C) 2020 Intel Corporation, Inc. > + */ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define DRIVER_NAME "dfl-uio-pdev" > + > +static int dfl_uio_pdev_probe(struct dfl_device *ddev) > +{ > + struct platform_device_info pdevinfo = { 0 }; > + struct resource res[2] = { { 0 } }; > + struct uio_info uio_pdata = { 0 }; > + struct platform_device *uio_pdev; > + struct device *dev = &ddev->dev; > + unsigned int num_res = 1; > + > + res[0].parent = &ddev->mmio_res; > + res[0].flags = IORESOURCE_MEM; > + res[0].start = ddev->mmio_res.start; > + res[0].end = ddev->mmio_res.end; > + > + if (ddev->num_irqs) { > + if (ddev->num_irqs > 1) > + dev_warn(&ddev->dev, > + "%d irqs for %s, but UIO only supports the first one\n", > + ddev->num_irqs, dev_name(&ddev->dev)); > + > + res[1].flags = IORESOURCE_IRQ; > + res[1].start = ddev->irqs[0]; > + res[1].end = ddev->irqs[0]; > + num_res++; > + } > + > + uio_pdata.name = DRIVER_NAME; > + uio_pdata.version = "0"; > + > + pdevinfo.name = "uio_pdrv_genirq"; > + pdevinfo.res = res; > + pdevinfo.num_res = num_res; > + pdevinfo.parent = &ddev->dev; > + pdevinfo.id = PLATFORM_DEVID_AUTO; > + pdevinfo.data = &uio_pdata; > + pdevinfo.size_data = sizeof(uio_pdata); > + > + uio_pdev = platform_device_register_full(&pdevinfo); It looks like: platform_device_register_resndata(&ddev->dev, "uio_pdrv_genirq", PLATFORM_DEVID_AUTO, res, num_res, &uio_pdata, sizeof(uio_pdata)) would work? > + if (IS_ERR(uio_pdev)) > + return PTR_ERR(uio_pdev); > + > + dev_set_drvdata(dev, uio_pdev); > + > + return 0; > +} > + > +static void dfl_uio_pdev_remove(struct dfl_device *ddev) > +{ > + struct platform_device *uio_pdev = dev_get_drvdata(&ddev->dev); > + > + platform_device_unregister(uio_pdev); > +} > + > +#define FME_FEATURE_ID_ETH_GROUP 0x10 > + > +static const struct dfl_device_id dfl_uio_pdev_ids[] = { > + { FME_ID, FME_FEATURE_ID_ETH_GROUP }, > + > + /* Add your new id entries here to support uio for more dfl features */ This is fairly common, we can maybe drop this comment? > + > + { } > +}; > +MODULE_DEVICE_TABLE(dfl, dfl_uio_pdev_ids); > + > +static struct dfl_driver dfl_uio_pdev_driver = { > + .drv = { > + .name = DRIVER_NAME, > + }, > + .id_table = dfl_uio_pdev_ids, > + .probe = dfl_uio_pdev_probe, > + .remove = dfl_uio_pdev_remove, > +}; > +module_dfl_driver(dfl_uio_pdev_driver); > + > +MODULE_DESCRIPTION("DFL driver for Userspace I/O platform devices"); > +MODULE_AUTHOR("Intel Corporation"); > +MODULE_LICENSE("GPL v2"); > -- > 2.7.4 > Otherwise, looks good to me. - Moritz