All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCHv4] [RFC] DM: early_malloc for DM added.
Date: Tue, 18 Sep 2012 12:57:53 +0200	[thread overview]
Message-ID: <201209181257.53329.marex@denx.de> (raw)
In-Reply-To: <1347952436-5722-1-git-send-email-tmshlvck@gmail.com>

Dear Tomas Hlavacek,

> early_malloc for DM with support for more heaps and lightweight
> first heap on stack.
> 
> Adaptation layer for seamless calling of early_malloc or dlmalloc from
> DM based on init stage added (dmmalloc() and related functions).
> 
> Signed-off-by: Tomas Hlavacek <tmshlvck@gmail.com>
> ---

It looks mostly OK, few comments

I'd say, pull out the modification of global data into separate patch and put it 
before this patch. That'd make review of the core code much easier.

[...]

> +
> +#include <common.h> /* for ROUND_UP */
> +#include <asm/u-boot.h>
> +#include <asm/global_data.h> /* for gd_t and gd */
> +#include <asm/types.h> /* for phys_addr_t and size_addt_t */
> +
> +#include <dmmalloc.h>
> +#include <malloc.h>
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +#ifdef CONFIG_SYS_EARLY_MALLOC
> +static struct early_heap_header *def_early_brk(size_t size)
> +{
> +	struct early_heap_header *h =
> +		(struct early_heap_header *)CONFIG_SYS_EARLY_HEAP_ADDR;
> +
> +	h->free_space_pointer = (void *)(roundup(
> +				(phys_addr_t)CONFIG_SYS_EARLY_HEAP_ADDR +
> +				sizeof(struct early_heap_header),
> +				sizeof(phys_addr_t)));
> +	h->free_bytes = size - roundup(sizeof(struct early_heap_header),
> +				sizeof(phys_addr_t));
> +	h->next_early_heap = NULL;
> +
> +	return h;
> +}
> +
> +struct early_heap_header *early_brk(size_t size)
> +	__attribute__((weak, alias("def_early_brk")));

what about using (it needs <linux/compiler.h>):

__weak struct early_heap_header *early_brk(size_t size)
{
...
body
...
}

> +void *early_malloc(size_t size)
> +{
> +	phys_addr_t addr;
> +	struct early_heap_header *h;
> +
> +	/* Align size. */
> +	size = roundup(size, sizeof(phys_addr_t));
> +
> +	/* Choose early_heap with enough space. */
> +	h = gd->early_heap_first;
> +	while ((h->free_bytes < size) && (h->next_early_heap != NULL))
> +		h = h->next_early_heap;
> +
> +	if (h->free_bytes < size) {
> +		debug("Early heap overflow. Heap %p, free %d, required %d.",
> +			h, h->free_bytes, size);
> +		return NULL;
> +	}
> +
> +	/* Choose block beginning address and mark next free space. */
> +	addr = (phys_addr_t)h->free_space_pointer;
> +
> +	h->free_space_pointer += size;
> +	h->free_bytes -= size;
> +
> +	return (void *)addr;
> +}
> +
> +static int is_early_malloc_active(void)
> +{
> +	if (gd->flags & GD_FLG_RELOC)
> +		return 0;
> +
> +	return 1;
> +}
> +
> +#endif /* CONFIG_SYS_EARLY_MALLOC */
> +
> +void *dmmalloc(size_t size)
> +{
> +#ifdef CONFIG_SYS_EARLY_MALLOC
> +	if (is_early_malloc_active())
> +		return early_malloc(size);
> +#endif /* CONFIG_SYS_EARLY_MALLOC */

Or you can implement empty prototypes for these functions in case CONFIG_SYS ... 
isn't defined to punt this preprocessor bloat.

> +	return malloc(size);
> +}

[...]

> diff --git a/include/configs/zipitz2.h b/include/configs/zipitz2.h
> index 26204af..5cd0dcb 100644
> --- a/include/configs/zipitz2.h
> +++ b/include/configs/zipitz2.h
> @@ -176,8 +176,13 @@ unsigned char zipitz2_spi_read(void);
> 
>  #define	CONFIG_SYS_LOAD_ADDR		CONFIG_SYS_DRAM_BASE
> 
> +#define CONFIG_SYS_EARLY_HEAP_ADDR     (GENERATED_GBL_DATA_SIZE + \
> +	PHYS_SDRAM_1)
> +#define CONFIG_SYS_EARLY_HEAP_SIZE     256
> +

1) Pull this file into separate patch and order it afterwards this patch.
2) You're putting your early thingie into SDRAM, which works on PXA (sadly) ... 
looking through the PXA init code, it needs cleanup, damn

... there's no real hint so far, just a rant.

>  #define CONFIG_SYS_SDRAM_BASE		PHYS_SDRAM_1
> -#define	CONFIG_SYS_INIT_SP_ADDR		(GENERATED_GBL_DATA_SIZE + 
PHYS_SDRAM_1 +
> 2048) +#define CONFIG_SYS_INIT_SP_ADDR		(GENERATED_GBL_DATA_SIZE 
+ \
> +	CONFIG_SYS_EARLY_HEAP_SIZE + PHYS_SDRAM_1 + 2048)
> 
>  /*
>   * NOR FLASH
> @@ -260,4 +265,9 @@ unsigned char zipitz2_spi_read(void);
>  #define CONFIG_SYS_MCIO0_VAL	0x0001430f
>  #define CONFIG_SYS_MCIO1_VAL	0x0001430f

[...]

  reply	other threads:[~2012-09-18 10:57 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-27 12:12 [U-Boot] [PATCH 1/1] [RFC] DM: early_malloc for DM added Tomas Hlavacek
2012-08-27 12:18 ` Marek Vasut
2012-08-27 12:37   ` Tomas Hlavacek
2012-08-27 12:42 ` [U-Boot] [PATCHv2 " Tomas Hlavacek
2012-08-27 23:02   ` Graeme Russ
2012-08-28  0:11     ` Graeme Russ
2012-08-28  0:18     ` Graeme Russ
2012-09-18  7:13 ` [U-Boot] [PATCHv4] " Tomas Hlavacek
2012-09-18 10:57   ` Marek Vasut [this message]
2012-09-18 23:29     ` Graeme Russ
2012-09-18 23:33       ` Marek Vasut
2012-09-18 23:44         ` Graeme Russ
2012-09-18 23:53           ` Marek Vasut
2012-09-19 18:29       ` Tom Rini
2012-09-22  0:37       ` Tomas Hlavacek
2012-09-18 23:25   ` Graeme Russ
2012-09-22  0:25 ` [U-Boot] [PATCH v5] [RFC] " Tomas Hlavacek
2012-09-22  0:28   ` Marek Vasut
2012-09-22  7:52     ` Tomas Hlavacek
2012-09-22 13:19       ` Marek Vasut
2012-09-22 22:09 ` [U-Boot] [PATCH v6] " Tomas Hlavacek
2012-09-23 13:06   ` Graeme Russ
2012-09-23 15:30     ` Tomas Hlavacek
2012-09-23 15:38 ` [U-Boot] [PATCH v7] " Tomas Hlavacek
2012-09-23 16:15 ` [U-Boot] [PATCH v8] " Tomas Hlavacek
2012-09-23 16:32   ` Wolfgang Denk
2012-09-23 16:47     ` Tomas Hlavacek
2012-09-24 21:48       ` Tom Rini
2012-09-23 23:11   ` Marek Vasut
2012-09-24 14:16     ` Tomas Hlavacek
2012-09-24 14:19       ` Marek Vasut
2012-09-25  0:37         ` Graeme Russ
2012-09-25  8:43           ` Tomas Hlavacek
2012-09-25  9:09             ` Graeme Russ
2012-09-25 23:04               ` Graeme Russ
2012-09-26 10:16                 ` Tomas Hlavacek
2012-09-26 23:03                   ` Graeme Russ
2012-09-24  0:00   ` Graeme Russ
2012-09-24  0:35     ` Tomas Hlavacek
2012-09-24  0:46       ` Graeme Russ
2012-10-24 23:49 ` [U-Boot] [PATCH v9] [RFC] Add dmmalloc module for DM Tomas Hlavacek
2012-10-25  1:40   ` Graeme Russ
2012-10-25 19:16     ` Tomas Hlavacek
2012-10-25 23:04       ` Graeme Russ
2012-10-28 23:20 ` [U-Boot] [PATCH v10] " Tomas Hlavacek
2013-11-05 15:26   ` Mateusz Zalega
2013-11-05 17:17     ` Tom Rini
2013-11-05 17:26       ` Mateusz Zalega

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=201209181257.53329.marex@denx.de \
    --to=marex@denx.de \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.