linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: mina86@mina86.com (Michal Nazarewicz)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 1/4] drivers: dma-contiguous: clean source code and prepare for device tree
Date: Mon, 05 Aug 2013 16:06:17 +0200	[thread overview]
Message-ID: <xa1twqo0ut9i.fsf@mina86.com> (raw)
In-Reply-To: <1375275119-12787-2-git-send-email-m.szyprowski@samsung.com>

On Wed, Jul 31 2013, Marek Szyprowski wrote:
> This patch cleans the initialization of dma contiguous framework. The
> all-in-one dma_declare_contiguous() function is now separated into
> dma_contiguous_reserve_area() which only steals the the memory from
> memblock allocator and dma_contiguous_add_device() function, which
> assigns given device to the specified reserved memory area. This improves
> the flexibility in defining contiguous memory areas and assigning device
> to them, because now it is possible to assign more than one device to
> the given contiguous memory area. Such split in initialization procedure
> is also required for upcoming device tree support.
>
> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Acked-by: Kyungmin Park <kyungmin.park@samsung.com>

Acked-by: Michal Nazarewicz <mina86@mina86.com>

Even though I have some comments.

> @@ -124,22 +124,29 @@ void __init dma_contiguous_reserve(phys_addr_t limit)
>  #endif
>  	}
>  
> -	if (selected_size) {
> +	if (selected_size && !dma_contiguous_default_area) {

Perhaps check this earlier in the function?  Also, maybe WARN would be
in order when dma_contiguous_reserve is called with
dma_contiguous_default_area already reserved.

>  		pr_debug("%s: reserving %ld MiB for global area\n", __func__,
>  			 (unsigned long)selected_size / SZ_1M);
>  
> -		dma_declare_contiguous(NULL, selected_size, 0, limit);
> +		dma_contiguous_reserve_area(selected_size, 0, limit,
> +					    &dma_contiguous_default_area);
>  	}
>  };
>  
>  static DEFINE_MUTEX(cma_mutex);


> -int __init dma_declare_contiguous(struct device *dev, phys_addr_t size,
> -				  phys_addr_t base, phys_addr_t limit)
> +int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base,
> +				       phys_addr_t limit, struct cma **res_cma)

> @@ -277,10 +245,11 @@ int __init dma_declare_contiguous(struct device *dev, phys_addr_t size,
>  	 * Each reserved area must be initialised later, when more kernel
>  	 * subsystems (like slab allocator) are available.
>  	 */
> -	r->start = base;
> -	r->size = size;
> -	r->dev = dev;
> -	cma_reserved_count++;
> +	cma->base_pfn = PFN_DOWN(base);
> +	cma->count = size >> PAGE_SHIFT;
> +	*res_cma = cma;

Alternatively it could return a pointer, but either way?

> +	cma_area_count++;
> +
>  	pr_info("CMA: reserved %ld MiB at %08lx\n", (unsigned long)size / SZ_1M,
>  		(unsigned long)base);
>  

> +int __init dma_contiguous_add_device(struct device *dev, struct cma *cma)
> +{
> +	dev_set_cma_area(dev, cma);
> +	return 0;
> +}

This never fails and it is used in dma_declare_contiguous w/o checking
for errors so perhaps it should return void?  Applies to some other
functions as well.

Moreover, this function is so tiny, it makes me wonder why does it exist
in the first place (why would anyone call it rather then
dev_set_cma_area?  is it just matter of name?), and since it exists, why
not put it to a header file as a static inline.

> +int __init dma_contiguous_set_default_area(struct cma *cma)
> +{
> +	dma_contiguous_default_area = cma;
> +	return 0;
>  }

Ditto.

> +static inline int dma_declare_contiguous(struct device *dev, phys_addr_t size,
> +					 phys_addr_t base, phys_addr_t limit)
> +{
> +	struct cma *cma;
> +	int ret;

+	if (WARN_ON(!dev))
+		return -EINVAL;

> +	ret = dma_contiguous_reserve_area(size, base, limit, &cma);
> +	if (ret == 0)
> +		dma_contiguous_add_device(dev, cma);
> +
> +	return ret;
> +}

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Micha? ?mina86? Nazarewicz    (o o)
ooo +----<email/xmpp: mpn@google.com>--------------ooO--(_)--Ooo--
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20130805/76f09c24/attachment.sig>

  reply	other threads:[~2013-08-05 14:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-31 12:51 [PATCH v4 0/4] Device Tree support for CMA (Contiguous Memory Allocator) Marek Szyprowski
2013-07-31 12:51 ` [PATCH v4 1/4] drivers: dma-contiguous: clean source code and prepare for device tree Marek Szyprowski
2013-08-05 14:06   ` Michal Nazarewicz [this message]
2013-07-31 12:51 ` [PATCH v4 2/4] drivers: of: add function to scan fdt nodes given by path Marek Szyprowski
2013-08-05 14:30   ` Michal Nazarewicz
2013-07-31 12:51 ` [PATCH v4 3/4] drivers: of: add initialization code for dma reserved memory Marek Szyprowski
2013-08-05 18:59   ` Michal Nazarewicz
2013-08-06 13:30   ` Rob Herring
2013-08-06 15:07     ` Michal Nazarewicz
2013-08-06 15:33       ` Sylwester Nawrocki
2013-08-07 12:38         ` Michal Nazarewicz
2013-08-07 13:08       ` Rob Herring
2013-08-07 15:07   ` Kumar Gala
2013-07-31 12:51 ` [PATCH v4 4/4] ARM: init: add support for reserved memory defined by device tree Marek Szyprowski
2013-08-05 14:31   ` Michal Nazarewicz
  -- strict thread matches above, loose matches on Subject: below --
2013-08-05  6:53 [PATCH v4 0/4] [RESEND] Device Tree support for CMA (Contiguous Memory Allocator) Marek Szyprowski
2013-08-05  6:53 ` [PATCH v4 1/4] drivers: dma-contiguous: clean source code and prepare for device tree Marek Szyprowski

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=xa1twqo0ut9i.fsf@mina86.com \
    --to=mina86@mina86.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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).