Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1177895ybz; Thu, 16 Apr 2020 04:29:53 -0700 (PDT) X-Google-Smtp-Source: APiQypLtochsnRZkwWaPepHtabDgbwep7Mn4xw8Oh9vkIiWcvFb2DGLIR/0GFdhiVJAdi/NkvY3k X-Received: by 2002:aa7:c152:: with SMTP id r18mr28785784edp.378.1587036593547; Thu, 16 Apr 2020 04:29:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587036593; cv=none; d=google.com; s=arc-20160816; b=ypByid7ogQ2Q0YgW43YBLt1PxGmQbe6GEm5sDICFSZewuHLYQdzgbEq2J1utYVAPkj TRyb4P1GgzxlaVtKd5qvwzxhrBWOwswJ5iveKylXtTPLXCNMThlu0co6/ey28wclVdXG Iv7u1sgTinoOYrFA3lpnx6L/8D7hnUgbWv4IeX72ARQvl0sBNy29nwDpP5Jlyljn/gzW 64k7R/5TQy+UWIxJ6YXXA8VzKnTNXKXLgypBMiJ0tQKZ+Mt33qIOsKAn3NjL5570EApS Vx+jGqEXt0uXxHx1t+CcgbYEKsfCqwtp2sJJp53mSuy5KYJPTC0ew/HDQkrOa7hANfnQ RDHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=zieeO/oey8TVUh7z4l4RZok5YqpWNPlCpFK5K5A/8DE=; b=hHpYc9K8klXW9eWbBmOYS1SeiA6m2ojZIT19Wy7DXJHy37xlyQPKGKaWrej54SH52t ohHKjdwdfAgs3HMo+djilKcxjSgUAkkYltw220EhC4llrRDh7EXqScbYA+rXhPYELope uc2uamqo8hQc/yjyalUIh2w3FtsHPTHAk9wnAiC72o4HCfBsyDy7GaikyQqp++hlGJQJ 2z79wWYhr0MMYoMtPP/WSxseNrFs/fFKhq36BwfHRXsq0zkV7PWSSJeiyKdjeviIhqFU P26gd2pr78Mv3Ld7MyYyDwTv9eFmzywmRXxS+O4lnhON8mbIjJNu/wZDE+eB3gBL7RlH xxUw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j23si12691408edt.338.2020.04.16.04.29.30; Thu, 16 Apr 2020 04:29:53 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2633052AbgDPL0E (ORCPT + 99 others); Thu, 16 Apr 2020 07:26:04 -0400 Received: from mail-m127101.qiye.163.com ([115.236.127.101]:36382 "EHLO mail-m127101.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2632869AbgDPLX4 (ORCPT ); Thu, 16 Apr 2020 07:23:56 -0400 X-Greylist: delayed 386 seconds by postgrey-1.27 at vger.kernel.org; Thu, 16 Apr 2020 07:23:52 EDT Received: from ubuntu.localdomain (unknown [58.251.74.226]) by mail-m127101.qiye.163.com (Hmail) with ESMTPA id 30B87483A0; Thu, 16 Apr 2020 19:16:51 +0800 (CST) From: Wang Wenhu To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, oss@buserror.net, christophe.leroy@c-s.fr, linuxppc-dev@lists.ozlabs.org Cc: kernel@vivo.com, Wang Wenhu , Michael Ellerman Subject: [PATCH RESEND,v3,4/4] drivers: uio: new driver for fsl_85xx_cache_sram Date: Thu, 16 Apr 2020 04:16:09 -0700 Message-Id: <20200416111609.4191-5-wenhu.wang@vivo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200416111609.4191-1-wenhu.wang@vivo.com> References: <20200416111609.4191-1-wenhu.wang@vivo.com> X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgYFAkeWUFZSFVDTEhLS0tKT09CTkNOWVdZKFlBSE 83V1ktWUFJV1kJDhceCFlBWTU0KTY6NyQpLjc#WQY+ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6OD46SRw*GTgzDg9PAQ0ZEkJW FQ1PCxRVSlVKTkNMS0hOQ0pKTUhPVTMWGhIXVQweFRMOVQwaFRw7DRINFFUYFBZFWVdZEgtZQVlO Q1VJTkpVTE9VSUlNWVdZCAFZQUNLS043Bg++ X-HM-Tid: 0a7182b4ae8e9865kuuu30b87483a0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A driver for freescale 85xx platforms to access the Cache-Sram form user level. This is extremely helpful for some user-space applications that require high performance memory accesses. Cc: Greg Kroah-Hartman Cc: Christophe Leroy Cc: Scott Wood Cc: Michael Ellerman Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Wang Wenhu --- Changes since v1: * Addressed comments from Greg K-H * Moved kfree(info->name) into uio_info_free_internal() Changes since v2: * Addressed comments from Greg, Scott and Christophe * Use "uiomem->internal_addr" as if condition for sram memory free, and memset the uiomem entry * Modified of_match_table make the driver apart from Cache-Sram HW info which belong to the HW level driver fsl_85xx_cache_sram to match * Use roundup_pow_of_two for align calculation * Remove useless clear block of uiomem entries. * Use UIO_INFO_VER micro for info->version, and define it as "devicetree,pseudo", meaning this is pseudo device and probed from device tree configuration * Select FSL_85XX_CACHE_SRAM rather than depends on it --- drivers/uio/Kconfig | 9 ++ drivers/uio/Makefile | 1 + drivers/uio/uio_fsl_85xx_cache_sram.c | 158 ++++++++++++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 drivers/uio/uio_fsl_85xx_cache_sram.c diff --git a/drivers/uio/Kconfig b/drivers/uio/Kconfig index 202ee81cfc2b..9c3b47461b71 100644 --- a/drivers/uio/Kconfig +++ b/drivers/uio/Kconfig @@ -105,6 +105,15 @@ config UIO_NETX To compile this driver as a module, choose M here; the module will be called uio_netx. +config UIO_FSL_85XX_CACHE_SRAM + tristate "Freescale 85xx Cache-Sram driver" + depends on FSL_SOC_BOOKE && PPC32 + select FSL_85XX_CACHE_SRAM + help + Generic driver for accessing the Cache-Sram form user level. This + is extremely helpful for some user-space applications that require + high performance memory accesses. + config UIO_FSL_ELBC_GPCM tristate "eLBC/GPCM driver" depends on FSL_LBC diff --git a/drivers/uio/Makefile b/drivers/uio/Makefile index c285dd2a4539..be2056cffc21 100644 --- a/drivers/uio/Makefile +++ b/drivers/uio/Makefile @@ -10,4 +10,5 @@ obj-$(CONFIG_UIO_NETX) += uio_netx.o obj-$(CONFIG_UIO_PRUSS) += uio_pruss.o obj-$(CONFIG_UIO_MF624) += uio_mf624.o obj-$(CONFIG_UIO_FSL_ELBC_GPCM) += uio_fsl_elbc_gpcm.o +obj-$(CONFIG_UIO_FSL_85XX_CACHE_SRAM) += uio_fsl_85xx_cache_sram.o obj-$(CONFIG_UIO_HV_GENERIC) += uio_hv_generic.o diff --git a/drivers/uio/uio_fsl_85xx_cache_sram.c b/drivers/uio/uio_fsl_85xx_cache_sram.c new file mode 100644 index 000000000000..8701df695307 --- /dev/null +++ b/drivers/uio/uio_fsl_85xx_cache_sram.c @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2020 Vivo Communication Technology Co. Ltd. + * Copyright (C) 2020 Wang Wenhu + * All rights reserved. + */ + +#include +#include +#include +#include +#include +#include + +#define DRIVER_NAME "uio_fsl_85xx_cache_sram" +#define UIO_INFO_VER "devicetree,pseudo" +#define UIO_NAME "uio_cache_sram" + +static void uio_info_free_internal(struct uio_info *info) +{ + struct uio_mem *uiomem = info->mem; + + while (uiomem < &info->mem[MAX_UIO_MAPS]) { + if (uiomem->internal_addr) { + mpc85xx_cache_sram_free(uiomem->internal_addr); + kfree(uiomem->name); + memset(uiomem, 0, sizeof(*uiomem)); + } + uiomem++; + } + + kfree(info->name); +} + +static int uio_fsl_85xx_cache_sram_probe(struct platform_device *pdev) +{ + struct device_node *parent = pdev->dev.of_node; + struct device_node *node = NULL; + struct uio_info *info; + struct uio_mem *uiomem; + const char *dt_name; + u32 mem_size; + int ret; + + /* alloc uio_info for one device */ + info = kzalloc(sizeof(*info), GFP_KERNEL); + if (!info) + return -ENOMEM; + + /* get optional uio name */ + if (of_property_read_string(parent, "uio_name", &dt_name)) + dt_name = UIO_NAME; + + info->name = kstrdup(dt_name, GFP_KERNEL); + if (!info->name) { + ret = -ENOMEM; + goto err_info_free; + } + + uiomem = info->mem; + for_each_child_of_node(parent, node) { + void *virt; + phys_addr_t phys; + + ret = of_property_read_u32(node, "cache-mem-size", &mem_size); + if (ret) { + ret = -EINVAL; + goto err_info_free_internal; + } + + if (mem_size == 0) { + dev_err(&pdev->dev, "cache-mem-size should not be 0\n"); + ret = -EINVAL; + goto err_info_free_internal; + } + + virt = mpc85xx_cache_sram_alloc(mem_size, + &phys, + roundup_pow_of_two(mem_size)); + if (!virt) { + /* mpc85xx_cache_sram_alloc to define the real cause */ + ret = -ENOMEM; + goto err_info_free_internal; + } + + uiomem->memtype = UIO_MEM_PHYS; + uiomem->addr = phys; + uiomem->size = mem_size; + uiomem->name = kstrdup(node->name, GFP_KERNEL);; + uiomem->internal_addr = virt; + uiomem++; + + if (uiomem >= &info->mem[MAX_UIO_MAPS]) { + dev_warn(&pdev->dev, "more than %d uio-maps for device.\n", + MAX_UIO_MAPS); + break; + } + } + + if (uiomem == info->mem) { + dev_err(&pdev->dev, "error no valid uio-map configured\n"); + ret = -EINVAL; + goto err_info_free_internal; + } + + info->version = UIO_INFO_VER; + + /* register uio device */ + if (uio_register_device(&pdev->dev, info)) { + dev_err(&pdev->dev, "uio registration failed\n"); + ret = -ENODEV; + goto err_info_free_internal; + } + + platform_set_drvdata(pdev, info); + + return 0; +err_info_free_internal: + uio_info_free_internal(info); +err_info_free: + kfree(info); + return ret; +} + +static int uio_fsl_85xx_cache_sram_remove(struct platform_device *pdev) +{ + struct uio_info *info = platform_get_drvdata(pdev); + + uio_unregister_device(info); + + uio_info_free_internal(info); + + kfree(info); + + return 0; +} + +static const struct of_device_id uio_mpc85xx_l2ctlr_of_match[] = { + { .compatible = "uio,mpc85xx-cache-sram", }, + {}, +}; + +static struct platform_driver uio_fsl_85xx_cache_sram = { + .probe = uio_fsl_85xx_cache_sram_probe, + .remove = uio_fsl_85xx_cache_sram_remove, + .driver = { + .name = DRIVER_NAME, + .owner = THIS_MODULE, + .of_match_table = uio_mpc85xx_l2ctlr_of_match, + }, +}; + +module_platform_driver(uio_fsl_85xx_cache_sram); + +MODULE_AUTHOR("Wang Wenhu "); +MODULE_DESCRIPTION("Freescale MPC85xx Cache-Sram UIO Platform Driver"); +MODULE_ALIAS("platform:" DRIVER_NAME); +MODULE_LICENSE("GPL v2"); -- 2.17.1