From patchwork Fri Jul 15 09:04:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 9231409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7CB3760865 for ; Fri, 15 Jul 2016 09:10:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6774127B16 for ; Fri, 15 Jul 2016 09:10:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5AA5328319; Fri, 15 Jul 2016 09:10:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9B33627B16 for ; Fri, 15 Jul 2016 09:10:06 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bNz6n-0005RG-Ac; Fri, 15 Jul 2016 09:08:33 +0000 Received: from mail-pa0-x230.google.com ([2607:f8b0:400e:c03::230]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bNz3i-0001Wr-PK for linux-arm-kernel@lists.infradead.org; Fri, 15 Jul 2016 09:05:28 +0000 Received: by mail-pa0-x230.google.com with SMTP id dx3so37840194pab.2 for ; Fri, 15 Jul 2016 02:05:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bvloTsAsViLInMFKRJ9AV0fWvP36bC0ZKl2IjMGVvwg=; b=E+FpHdkVcDPe/0PqZeJg0fFZFeuuUPpV1dgox/eHVr4ni5TisIDSrMb8d7Wx4xWvIB guYhMo4Rj2DQKrE4gAtO9xbgXfAeV7zS1ZKvTnZ1QmC1U2xKM+/mdsihttmj2tftb9wH bR2RmwXGaodcmRYmsCpNpxIS03SaJKM7Yk5sM= 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=bvloTsAsViLInMFKRJ9AV0fWvP36bC0ZKl2IjMGVvwg=; b=PI7AgOK41TMEHyYh9HxhP5z0dx9IF1A5wldDzVEsJqmWqws3i+UluvOmAhJka7H8HZ LpR/wY3XEKXWXAbPX56VBW/evcqku+dzc8Xw+b/4b15OxrBpkksfE51SSIZmBRk0iOke A1TlMlh69HHF1RV3DZYmuxE3K3yQC7AXCIRGlbZas/cbkUZuNB0qIi7UNkT+5kUCKida sn18p4h14bQmY5Y8BqsorZBMsLzMRG7Ng49M48QvKh/wXuyuvxsLUT/f2c0gHEg/QeI0 lgLWgL7+YRx3WjcZDRS3OepiLULA3cSeOlclzg8PJR15SC5OyLt4W2T0LZHvMqcIt8H5 EqEA== X-Gm-Message-State: ALyK8tI1yLdTv3YRn3uJo8n26wuvxBSRG8MfXU4+hnTAvrT2vA+S2G6CLNVWhmVByUA6x9YL X-Received: by 10.67.7.98 with SMTP id db2mr29614611pad.156.1468573500885; Fri, 15 Jul 2016 02:05:00 -0700 (PDT) Received: from anup-HP-Compaq-8100-Elite-CMT-PC.ban.broadcom.com ([202.140.56.34]) by smtp.gmail.com with ESMTPSA id m78sm6811923pfj.66.2016.07.15.02.04.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Jul 2016 02:05:00 -0700 (PDT) From: Anup Patel To: "Hans J. Koch" , Greg Kroah-Hartman , Jonathan Corbet Subject: [PATCH 7/8] uio: bind uio_dmem_genirq via OF Date: Fri, 15 Jul 2016 14:34:02 +0530 Message-Id: <1468573443-4670-8-git-send-email-anup.patel@broadcom.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468573443-4670-1-git-send-email-anup.patel@broadcom.com> References: <1468573443-4670-1-git-send-email-anup.patel@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160715_020523_165179_176D5F1E X-CRM114-Status: GOOD ( 19.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anup Patel , Scott Branden , linux-doc@vger.kernel.org, Ray Jui , linux-kernel@vger.kernel.org, Rob Herring , bcm-kernel-feedback-list@broadcom.com, Ankit Jindal , linux-arm-kernel@lists.infradead.org, Jan Viktorin MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jan Viktorin The uio_dmem_genirq works in a similar ways as uio_pdrv_genirq now. It accepts the of_id module parameter to specify UIO compatible string as module parameter. There are few other module parameters to specify DT property name for number bits in DMA mask and details about dynamic regions. Following are the newly added module parameters: 1) of_id: The UIO compatible string to be used for DT probing 2) of_dma_bits_prot: This is name of OF property which will be used to specify number of DMA mask bits in UIO DT node. 3) of_dmem_count_prop: This is name of OF property which will be used to specify number of dynamic regions in UIO DT node. 4) of_dmem_sizes_prop: This is name of OF property which will be used to specify sizes of each dynamic regions in UIO DT node. Signed-off-by: Jan Viktorin Signed-off-by: Anup Patel --- drivers/uio/uio_dmem_genirq.c | 113 +++++++++++++++++++++++++++++++++--------- 1 file changed, 89 insertions(+), 24 deletions(-) diff --git a/drivers/uio/uio_dmem_genirq.c b/drivers/uio/uio_dmem_genirq.c index a4d6d81..0a0cc19 100644 --- a/drivers/uio/uio_dmem_genirq.c +++ b/drivers/uio/uio_dmem_genirq.c @@ -144,46 +144,107 @@ static int uio_dmem_genirq_irqcontrol(struct uio_info *dev_info, s32 irq_on) return 0; } +static char uio_of_dma_bits_prop[128] = "uio,dma-bits"; +static char uio_of_dmem_count_prop[128] = "uio,number-of-dynamic-regions"; +static char uio_of_dmem_sizes_prop[128] = "uio,dynamic-regions-sizes"; + +static int uio_dmem_genirq_alloc_platdata(struct platform_device *pdev) +{ + struct uio_dmem_genirq_pdata pdata; + u32 dma_bits, regions; + u32 sizes[MAX_UIO_MAPS]; + int ret; + + memset(&pdata, 0, sizeof(pdata)); + + ret = of_property_read_u32(pdev->dev.of_node, + uio_of_dma_bits_prop, &dma_bits); + if (ret) { + dev_err(&pdev->dev, + "Missing property %s\n", uio_of_dma_bits_prop); + return ret; + } + if (dma_bits > 64) + dma_bits = 64; + + dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(dma_bits)); + + ret = of_property_read_u32(pdev->dev.of_node, + uio_of_dmem_count_prop, ®ions); + if (ret) { + dev_err(&pdev->dev, + "Missing property %s\n", uio_of_dmem_count_prop); + return ret; + } + + regions = min_t(u32, regions, MAX_UIO_MAPS); + + ret = of_property_read_u32_array(pdev->dev.of_node, + uio_of_dmem_sizes_prop, sizes, + regions); + if (ret) { + dev_err(&pdev->dev, "Missing or invalid property %s\n", + uio_of_dmem_sizes_prop); + return ret; + } + + pdata.dynamic_region_sizes = devm_kzalloc(&pdev->dev, + sizeof(*pdata.dynamic_region_sizes) * + pdata.num_dynamic_regions, GFP_KERNEL); + if (!pdata.dynamic_region_sizes) { + dev_err(&pdev->dev, "Unable to alloc dynamic_region_sizes\n"); + ret = -ENOMEM; + return ret; + } + + pdata.num_dynamic_regions = regions; + while (regions--) + pdata.dynamic_region_sizes[regions] = sizes[regions]; + + pdata.uioinfo.name = pdev->dev.of_node->name; + pdata.uioinfo.version = "devicetree"; + + return platform_device_add_data(pdev, &pdata, sizeof(pdata)); +} + static int uio_dmem_genirq_probe(struct platform_device *pdev) { - struct uio_dmem_genirq_pdata *pdata = dev_get_platdata(&pdev->dev); - struct uio_info *uioinfo = &pdata->uioinfo; + struct uio_dmem_genirq_pdata *pdata; + struct uio_info *uioinfo; struct uio_dmem_genirq_platdata *priv; struct uio_mem *uiomem; int ret = -EINVAL; int i; if (pdev->dev.of_node) { - /* alloc uioinfo for one device */ - uioinfo = kzalloc(sizeof(*uioinfo), GFP_KERNEL); - if (!uioinfo) { - ret = -ENOMEM; - dev_err(&pdev->dev, "unable to kmalloc\n"); + ret = uio_dmem_genirq_alloc_platdata(pdev); + if (ret) goto bad2; - } - uioinfo->name = pdev->dev.of_node->name; - uioinfo->version = "devicetree"; } + pdata = dev_get_platdata(&pdev->dev); + uioinfo = &pdata->uioinfo; + if (!uioinfo || !uioinfo->name || !uioinfo->version) { dev_err(&pdev->dev, "missing platform_data\n"); - goto bad0; + goto bad2; } if (uioinfo->handler || uioinfo->irqcontrol || uioinfo->irq_flags & IRQF_SHARED) { dev_err(&pdev->dev, "interrupt configuration error\n"); - goto bad0; + goto bad2; } priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) { ret = -ENOMEM; dev_err(&pdev->dev, "unable to kmalloc\n"); - goto bad0; + goto bad2; } - dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); + if (!pdev->dev.of_node) + dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); priv->uioinfo = uioinfo; spin_lock_init(&priv->lock); @@ -278,10 +339,6 @@ static int uio_dmem_genirq_probe(struct platform_device *pdev) return 0; bad1: kfree(priv); - bad0: - /* kfree uioinfo for OF */ - if (pdev->dev.of_node) - kfree(uioinfo); bad2: return ret; } @@ -296,10 +353,6 @@ static int uio_dmem_genirq_remove(struct platform_device *pdev) priv->uioinfo->handler = NULL; priv->uioinfo->irqcontrol = NULL; - /* kfree uioinfo for OF */ - if (pdev->dev.of_node) - kfree(priv->uioinfo); - kfree(priv); return 0; } @@ -327,10 +380,22 @@ static const struct dev_pm_ops uio_dmem_genirq_dev_pm_ops = { }; #ifdef CONFIG_OF -static const struct of_device_id uio_of_genirq_match[] = { - { /* empty for now */ }, +static struct of_device_id uio_of_genirq_match[] = { + { /* This is filled with module_parm */ }, + { /* end of list */ }, }; MODULE_DEVICE_TABLE(of, uio_of_genirq_match); +module_param_string(of_id, uio_of_genirq_match[0].compatible, 128, 0); +MODULE_PARM_DESC(of_id, "Openfirmware id of the device to be handled by uio"); +module_param_string(of_dma_bits_prop, uio_of_dma_bits_prop, 128, 0); +MODULE_PARM_DESC(of_dma_bits_prop, + "Openfirmware property for number of bits in DMA mask"); +module_param_string(of_dmem_count_prop, uio_of_dmem_count_prop, 128, 0); +MODULE_PARM_DESC(of_dmem_count_prop, + "Openfirmware property for dynamic region count"); +module_param_string(of_dmem_sizes_prop, uio_of_dmem_sizes_prop, 128, 0); +MODULE_PARM_DESC(of_dmem_sizes_prop, + "Openfirmware property for dynamic region sizes"); #endif static struct platform_driver uio_dmem_genirq = {