From patchwork Fri Jul 9 05:03:37 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Blanchard X-Patchwork-Id: 58330 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bilbo.ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 15A5AB7096 for ; Fri, 9 Jul 2010 15:11:02 +1000 (EST) Received: by ozlabs.org (Postfix, from userid 1010) id 8BDB21007D1; Fri, 9 Jul 2010 15:11:00 +1000 (EST) Message-Id: <20100709050341.995280062@samba.org> User-Agent: quilt/0.48-1 Date: Fri, 09 Jul 2010 15:03:37 +1000 From: Anton Blanchard To: yaboot-devel@lists.ozlabs.org Subject: [patch 07/14] print available ranges under control of linux, yaboot-debug property References: <20100709050330.507659708@samba.org> Content-Disposition: inline; filename=prom_print_available X-BeenThere: yaboot-devel@lists.ozlabs.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Technical and development discussion regarding yaboot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: yaboot-devel-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Errors-To: yaboot-devel-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Debugging yaboot failures is difficult because we often have to retest with a yaboot built with debug enabled. As a first step to fixing this, look for a linux,yaboot-debug property and dump the available ranges when it is non zero. Signed-off-by: Anton Blanchard Index: yaboot/second/prom.c =================================================================== --- yaboot.orig/second/prom.c 2010-07-08 14:01:33.000000000 +1000 +++ yaboot/second/prom.c 2010-07-08 14:19:43.000000000 +1000 @@ -37,6 +37,8 @@ #define READ_BLOCKS_USE_READ 1 +static int yaboot_debug; + prom_entry prom; ihandle prom_stdin, prom_stdout; @@ -237,6 +239,9 @@ prom_init (prom_entry pp) if (prom_get_chosen ("mmu", &prom_mmu, sizeof(prom_mmu)) <= 0) prom_abort ("\nCan't get mmu handle"); + yaboot_debug = 0; + prom_get_options("linux,yaboot-debug", &yaboot_debug, sizeof(yaboot_debug)); + // move cursor to fresh line prom_printf ("\n"); @@ -646,6 +651,7 @@ prom_getms(void) void prom_pause(void) { + prom_print_available(); call_prom("enter", 0, 0); } @@ -745,6 +751,68 @@ char * prom_get_ip (struct bootp_packet return conf_path; } +/* We call this too early to use malloc, 128 cells should be large enough */ +#define NR_AVAILABLE 128 + +void prom_print_available(void) +{ + prom_handle root; + unsigned int addr_cells, size_cells; + ihandle mem; + unsigned int available[NR_AVAILABLE]; + unsigned int len; + unsigned int *p; + + if (!yaboot_debug) + return; + + root = prom_finddevice("/"); + if (!root) + return; + + addr_cells = 2; + prom_getprop(root, "#address-cells", &addr_cells, sizeof(addr_cells)); + + size_cells = 1; + prom_getprop(root, "#size-cells", &size_cells, sizeof(size_cells)); + + mem = prom_finddevice("/memory@0"); + if (mem == PROM_INVALID_HANDLE) + return; + + len = prom_getprop(mem, "available", available, sizeof(available)); + if (len == -1) + return; + len /= 4; + + prom_printf("\nAvailable memory ranges:\n"); + + p = available; + while (len > 0) { + unsigned int addr, size; + + /* + * Since we are in 32bit mode it should be safe to only print the + * bottom 32bits of each range. + */ + p += (addr_cells - 1); + addr = *p; + p++; + + p += (size_cells - 1); + size = *p; + p++; + + if (size) + prom_printf("0x%08x-0x%08x (%3d MB)\n", addr, addr + size, + size/1024/1024); + + len -= (addr_cells + size_cells); + } + + prom_printf("\n"); +} + /* * Local variables: * c-file-style: "k&r" Index: yaboot/include/prom.h =================================================================== --- yaboot.orig/include/prom.h 2010-07-08 14:01:33.000000000 +1000 +++ yaboot/include/prom.h 2010-07-08 14:19:25.000000000 +1000 @@ -92,6 +92,7 @@ void *prom_claim_chunk(void *virt, unsig void *prom_claim (void *virt, unsigned int size, unsigned int align); void prom_release(void *virt, unsigned int size); void prom_map (void *phys, void *virt, int size); +void prom_print_available(void); /* packages and device nodes */ Index: yaboot/second/yaboot.c =================================================================== --- yaboot.orig/second/yaboot.c 2010-07-08 14:01:33.000000000 +1000 +++ yaboot/second/yaboot.c 2010-07-08 14:19:25.000000000 +1000 @@ -186,6 +186,8 @@ yaboot_start (unsigned long r3, unsigned /* Initialize OF interface */ prom_init ((prom_entry) r5); + prom_print_available(); + /* Allocate some memory for malloc'ator */ for (addr = MALLOCADDR; addr <= MALLOCADDR * 16 ;addr+=0x100000) { malloc_base = prom_claim((void *)addr, MALLOCSIZE, 0); @@ -1205,6 +1207,8 @@ yaboot_text_ui(void) DEBUG_F("Entering kernel...\n"); + prom_print_available(); + /* call the kernel with our stack. */ kernel_entry(initrd_base + loadinfo.load_loc, initrd_size, prom, 0, 0); continue;