From patchwork Wed Jan 26 16:57:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 80530 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3DBF3B7113 for ; Thu, 27 Jan 2011 03:57:38 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B09EC2808F; Wed, 26 Jan 2011 17:57:33 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VwtfzkkgvCbH; Wed, 26 Jan 2011 17:57:33 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5A12428097; Wed, 26 Jan 2011 17:57:31 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 314B628097 for ; Wed, 26 Jan 2011 17:57:29 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TCnUw87Dm21J for ; Wed, 26 Jan 2011 17:57:27 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pv0-f172.google.com (mail-pv0-f172.google.com [74.125.83.172]) by theia.denx.de (Postfix) with ESMTPS id 0C7922808F for ; Wed, 26 Jan 2011 17:57:24 +0100 (CET) Received: by pvc21 with SMTP id 21so112289pvc.3 for ; Wed, 26 Jan 2011 08:57:22 -0800 (PST) Received: by 10.142.144.14 with SMTP id r14mr826wfd.429.1296061042301; Wed, 26 Jan 2011 08:57:22 -0800 (PST) Received: from angua (S01060002b3d79728.cg.shawcable.net [70.72.87.49]) by mx.google.com with ESMTPS id w42sm20484622wfh.3.2011.01.26.08.57.20 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 26 Jan 2011 08:57:21 -0800 (PST) Received: from localhost6.localdomain6 (unknown [IPv6:::1]) by angua (Postfix) with ESMTP id 78E653C00DD; Wed, 26 Jan 2011 09:57:19 -0700 (MST) To: u-boot@lists.denx.de, john.rigby@linaro.org, wd@denx.de From: Grant Likely Date: Wed, 26 Jan 2011 09:57:19 -0700 Message-ID: <20110126165340.14306.98359.stgit@localhost6.localdomain6> User-Agent: StGit/0.15 MIME-Version: 1.0 Subject: [U-Boot] [PATCH] Make it possible to allocate physical address 0 with lmb X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de LMB doesn't currently handle allocating regions based at physical address 0. This patch reworks the lmb_alloc functions to return all ones when allocation fails instead of zero so that callers can differentiate between a region allocated at zero and a failed allocation Signed-off-by: Grant Likely --- common/image.c | 8 ++++---- include/lmb.h | 1 + lib/lmb.c | 21 ++++++++++++++++----- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/common/image.c b/common/image.c index 11504de..c1757bd 100644 --- a/common/image.c +++ b/common/image.c @@ -1053,7 +1053,7 @@ int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len, else *initrd_start = (ulong)lmb_alloc (lmb, rd_len, 0x1000); - if (*initrd_start == 0) { + if (*initrd_start == LMB_ALLOC_ERROR) { puts ("ramdisk - allocation error\n"); goto error; } @@ -1228,7 +1228,7 @@ int boot_relocate_fdt (struct lmb *lmb, ulong bootmap_base, of_start = (unsigned long)lmb_alloc_base(lmb, of_len, 0x1000, (CONFIG_SYS_BOOTMAPSZ + bootmap_base)); - if (of_start == 0) { + if (of_start == (unsigned long)LMB_ALLOC_ERROR) { puts("device tree - allocation error\n"); goto error; } @@ -1614,7 +1614,7 @@ int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end, cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf, CONFIG_SYS_BOOTMAPSZ + bootmap_base); - if (cmdline == NULL) + if (cmdline == (char*)(ulong)LMB_ALLOC_ERROR) return -1; if ((s = getenv("bootargs")) == NULL) @@ -1651,7 +1651,7 @@ int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base) { *kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf, CONFIG_SYS_BOOTMAPSZ + bootmap_base); - if (*kbd == NULL) + if (*kbd == (bd_t *)(ulong)LMB_ALLOC_ERROR) return -1; **kbd = *(gd->bd); diff --git a/include/lmb.h b/include/lmb.h index 43082a3..f927b86 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -15,6 +15,7 @@ */ #define MAX_LMB_REGIONS 8 +#define LMB_ALLOC_ERROR ((phys_addr_t) ~0) struct lmb_property { phys_addr_t base; diff --git a/lib/lmb.c b/lib/lmb.c index c5e75fb..de3c325 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -114,6 +114,9 @@ static long lmb_add_region(struct lmb_region *rgn, phys_addr_t base, phys_size_t unsigned long coalesced = 0; long adjacent, i; + debug("lmb_add_region(lmb=%x, base=%.8lx, size=%.8lx)\n", + (ulong)rgn, (ulong)base, (ulong)size); + if ((rgn->cnt == 1) && (rgn->region[0].size == 0)) { rgn->region[0].base = base; rgn->region[0].size = size; @@ -266,9 +269,11 @@ phys_addr_t lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align, phys_ alloc = __lmb_alloc_base(lmb, size, align, max_addr); - if (alloc == 0) - printf("ERROR: Failed to allocate 0x%lx bytes below 0x%lx.\n", + if (alloc == LMB_ALLOC_ERROR) { + debug("ERROR: Failed to allocate 0x%lx bytes below 0x%lx.\n", (ulong)size, (ulong)max_addr); + lmb_dump_all(lmb); + } return alloc; } @@ -289,10 +294,15 @@ phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align, phy phys_addr_t base = 0; phys_addr_t res_base; + debug("lmb_alloc_base(lmb=%lx, size=%lx, align=%li, max_addr=%lx)\n", + (ulong)lmb, (ulong)size, (ulong)align, (ulong)max_addr); + for (i = lmb->memory.cnt-1; i >= 0; i--) { phys_addr_t lmbbase = lmb->memory.region[i].base; phys_size_t lmbsize = lmb->memory.region[i].size; + debug("--loop i=%i, lmbbase=%lx, lmbsize=%lx\n", + i, (ulong)lmbbase, (ulong)lmbsize); if (lmbsize < size) continue; if (max_addr == LMB_ALLOC_ANYWHERE) @@ -303,14 +313,15 @@ phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align, phy } else continue; - while (base && lmbbase <= base) { + while (lmbbase <= base) { j = lmb_overlaps_region(&lmb->reserved, base, size); + debug("----loop base=%lx, j=%i\n", (ulong)base, j); if (j < 0) { /* This area isn't reserved, take it */ if (lmb_add_region(&lmb->reserved, base, lmb_align_up(size, align)) < 0) - return 0; + return LMB_ALLOC_ERROR; return base; } res_base = lmb->reserved.region[j].base; @@ -319,7 +330,7 @@ phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align, phy base = lmb_align_down(res_base - size, align); } } - return 0; + return LMB_ALLOC_ERROR; } int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr)