linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shawn Guo <shawn.guo@linaro.org>
To: Philipp Zabel <p.zabel@pengutronix.de>
Cc: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Grant Likely <grant.likely@secretlab.ca>,
	Rob Herring <rob.herring@calxeda.com>,
	Paul Gortmaker <paul.gortmaker@windriver.com>,
	Richard Zhao <richard.zhao@freescale.com>,
	Huang Shijie <shijie8@gmail.com>,
	Dong Aisheng <dong.aisheng@linaro.org>,
	kernel@pengutronix.de, devicetree-discuss@lists.ozlabs.org
Subject: Re: [PATCH v2 6/9] misc: Generic on-chip SRAM allocation driver
Date: Mon, 3 Sep 2012 10:19:53 +0800	[thread overview]
Message-ID: <20120903021950.GD2362@S2101-09.ap.freescale.net> (raw)
In-Reply-To: <1346405224-20399-7-git-send-email-p.zabel@pengutronix.de>

On Fri, Aug 31, 2012 at 11:27:01AM +0200, Philipp Zabel wrote:
> This driver requests and remaps a memory region as configured in the
> device tree. It serves memory from this region via the genalloc API.
> 
> Other drivers can retrieve the genalloc pool from a phandle pointing
> to this drivers' device node in the device tree.
> 
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
>  drivers/misc/Kconfig  |    8 ++++
>  drivers/misc/Makefile |    1 +
>  drivers/misc/sram.c   |  105 +++++++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 114 insertions(+)
>  create mode 100644 drivers/misc/sram.c
> 
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index 98a442d..8a55284 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -509,6 +509,14 @@ config USB_SWITCH_FSA9480
>  	  stereo and mono audio, video, microphone and UART data to use
>  	  a common connector port.
>  
> +config SRAM
> +	bool "Generic on-chip SRAM driver\n"

Remove the "\n".

And "depends on HAS_IOMEM"?

> +	select GENERIC_ALLOCATOR
> +	help
> +	  This driver allows to declare a memory region to be managed
> +	  by the genalloc API. It is supposed to be used for small
> +	  on-chip SRAM areas found on many ARM SoCs.
> +
>  source "drivers/misc/c2port/Kconfig"
>  source "drivers/misc/eeprom/Kconfig"
>  source "drivers/misc/cb710/Kconfig"
> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> index b88df7a..ccc759a 100644
> --- a/drivers/misc/Makefile
> +++ b/drivers/misc/Makefile
> @@ -50,3 +50,4 @@ obj-y				+= carma/
>  obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o
>  obj-$(CONFIG_ALTERA_STAPL)	+=altera-stapl/
>  obj-$(CONFIG_INTEL_MEI)		+= mei/
> +obj-$(CONFIG_SRAM)		+= sram.o
> diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c
> new file mode 100644
> index 0000000..c5cf67e
> --- /dev/null
> +++ b/drivers/misc/sram.c
> @@ -0,0 +1,105 @@
> +/*
> + * Generic on-chip SRAM allocation driver
> + *
> + * Copyright (C) 2012 Philipp Zabel, Pengutronix
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
> + * MA 02110-1301, USA.
> + */
> +
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/io.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/spinlock.h>
> +#include <linux/genalloc.h>
> +
> +struct sram_dev {
> +	struct gen_pool *pool;
> +};
> +
> +static int __devinit sram_probe(struct platform_device *pdev)
> +{
> +	void __iomem *virt_base;
> +	struct sram_dev *sram;
> +	struct resource *res;
> +	unsigned long size;
> +	int ret;
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!res)
> +		return -EINVAL;
> +
> +	size = resource_size(res);
> +
> +	virt_base = devm_request_and_ioremap(&pdev->dev, res);
> +	if (!virt_base)
> +		return -ENOMEM;

The kerneldoc of devm_request_and_ioremap suggests -EADDRNOTAVAIL.

Regards,
Shawn

> +
> +	sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL);
> +	if (!sram)
> +		return -ENOMEM;
> +
> +	sram->pool = gen_pool_create(PAGE_SHIFT, -1);
> +	if (!sram->pool)
> +		return -ENOMEM;
> +
> +	ret = gen_pool_add_virt(sram->pool, (unsigned long)virt_base,
> +				res->start, size, -1);
> +	if (ret < 0) {
> +		gen_pool_destroy(sram->pool);
> +		return ret;
> +	}
> +
> +	platform_set_drvdata(pdev, sram);
> +
> +	dev_dbg(&pdev->dev, "SRAM pool: %ld KiB @ 0x%p\n", size / 1024, virt_base);
> +
> +	return 0;
> +}
> +
> +static int __devexit sram_remove(struct platform_device *pdev)
> +{
> +	struct sram_dev *sram = platform_get_drvdata(pdev);
> +
> +	if (gen_pool_avail(sram->pool) < gen_pool_size(sram->pool))
> +		dev_dbg(&pdev->dev, "removed while SRAM allocated\n");
> +
> +	gen_pool_destroy(sram->pool);
> +
> +	return 0;
> +}
> +
> +#ifdef CONFIG_OF
> +static struct of_device_id sram_dt_ids[] = {
> +	{ .compatible = "sram" },
> +	{ /* sentinel */ }
> +};
> +#endif
> +
> +static struct platform_driver sram_driver = {
> +	.driver = {
> +		.name = "sram",
> +		.of_match_table = of_match_ptr(sram_dt_ids),
> +	},
> +	.probe = sram_probe,
> +	.remove = __devexit_p(sram_remove),
> +};
> +
> +module_platform_driver(sram_driver);
> +
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Philipp Zabel, Pengutronix");
> +MODULE_DESCRIPTION("Generic SRAM allocator driver");
> -- 
> 1.7.10.4
> 

  parent reply	other threads:[~2012-09-03  2:20 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-31  9:26 [PATCH v2 0/9] Add device tree support for on-chip SRAM Philipp Zabel
2012-08-31  9:26 ` [PATCH v2 1/9] ARM i.MX: Switch IRAM allocator to device tree initialization Philipp Zabel
2012-08-31  9:26 ` [PATCH v2 2/9] ARM i.MX53: Add OCRAM to device tree Philipp Zabel
2012-08-31  9:26 ` [PATCH v2 3/9] ARM i.MX6: " Philipp Zabel
2012-08-31  9:26 ` [PATCH v2 4/9] iram_alloc: store the virt and phys mem address in gen_pool chunks Philipp Zabel
2012-08-31  9:27 ` [PATCH v2 5/9] genalloc: add a global pool list, allow to find pools by phys address Philipp Zabel
2012-09-03  2:09   ` Shawn Guo
2012-08-31  9:27 ` [PATCH v2 6/9] misc: Generic on-chip SRAM allocation driver Philipp Zabel
2012-08-31  9:37   ` Jan Lübbe
2012-08-31  9:40     ` Shilimkar, Santosh
2012-09-03  2:19   ` Shawn Guo [this message]
2012-08-31  9:27 ` [PATCH v2 7/9] ARM: i.MX53: use generic on-chip SRAM allocator driver for OCRAM Philipp Zabel
2012-08-31  9:27 ` [PATCH v2 8/9] ARM: i.MX6: " Philipp Zabel
2012-08-31  9:27 ` [PATCH v2 9/9] ARM i.MX: remove IRAM_ALLOC facility Philipp Zabel
2012-09-03  1:53 ` [PATCH v2 0/9] Add device tree support for on-chip SRAM Shawn Guo
2012-09-03 15:42   ` Philipp Zabel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120903021950.GD2362@S2101-09.ap.freescale.net \
    --to=shawn.guo@linaro.org \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=dong.aisheng@linaro.org \
    --cc=grant.likely@secretlab.ca \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=paul.gortmaker@windriver.com \
    --cc=richard.zhao@freescale.com \
    --cc=rob.herring@calxeda.com \
    --cc=shijie8@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).