From f3d8af0e0ac4642499d5430c202ac57d1d4c5ceb Mon Sep 17 00:00:00 2001 From: Paul Nasrat Date: Mon, 3 Dec 2007 12:37:10 +0000 Subject: [PATCH] The patch from Scott Moser moves the "search-for-prom_claim'able" routine that was present in load_elf64 and load_elf32 to a function named prom_claim_chunk. This reduces the code-snippit duplication and makes the function available for of_net_open. Scott Moser ssmoser@us.ibm.com --- include/prom.h | 2 ++ second/prom.c | 19 +++++++++++++++++++ second/yaboot.c | 20 ++++---------------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/include/prom.h b/include/prom.h index f5ee88f..6e4d890 100644 --- a/include/prom.h +++ b/include/prom.h @@ -37,6 +37,7 @@ typedef void *phandle; #define PROM_INVALID_HANDLE ((prom_handle)-1UL) #define BOOTDEVSZ (2048) /* iscsi args can be in excess of 1040 bytes */ #define TOK_ISCSI "iscsi" +#define PROM_CLAIM_MAX_ADDR 0x8000000 struct prom_args; typedef int (*prom_entry)(struct prom_args *); @@ -85,6 +86,7 @@ int prom_set_color(prom_handle device, int color, int r, int g, int b); /* memory */ +void *prom_claim_chunk(void *virt, unsigned int size, unsigned int align); 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); diff --git a/second/prom.c b/second/prom.c index e9c5843..4ad7277 100644 --- a/second/prom.c +++ b/second/prom.c @@ -568,6 +568,25 @@ prom_sleep (int seconds) while (prom_getms() <= end); } +/* if address given is claimed look for other addresses to get the needed + * space before giving up + */ +void * +prom_claim_chunk(void *virt, unsigned int size, unsigned int align) +{ + void *found, *addr; + for(addr=virt; addr <= (void*)PROM_CLAIM_MAX_ADDR; + addr+=(0x100000/sizeof(addr))) { + found = prom_claim(addr, size, 0); + if (found != (void *)-1) { + DEBUG_F("claimed %i at 0x%x (0x%x)\n",size,(int)found,(int)virt); + return(found); + } + } + prom_printf("Claim error, can't allocate %x at 0x%x\n",size,(int)virt); + return((void*)-1); +} + void * prom_claim (void *virt, unsigned int size, unsigned int align) { diff --git a/second/yaboot.c b/second/yaboot.c index 0232d33..53643f5 100644 --- a/second/yaboot.c +++ b/second/yaboot.c @@ -1233,7 +1233,7 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo) Elf32_Ehdr *e = &(loadinfo->elf.elf32hdr); Elf32_Phdr *p, *ph; int size = sizeof(Elf32_Ehdr) - sizeof(Elf_Ident); - unsigned long addr, loadaddr; + unsigned long loadaddr; /* Read the rest of the Elf header... */ if ((*(file->fs->read))(file, size, &e->e_version) < size) { @@ -1321,13 +1321,7 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo) loadaddr = loadinfo->load_loc; } - /* On some systems, loadaddr may already be claimed, so try some - * other nearby addresses before giving up. - */ - for(addr=loadaddr; addr <= loadaddr * 8 ;addr+=0x100000) { - loadinfo->base = prom_claim((void *)addr, loadinfo->memsize, 0); - if (loadinfo->base != (void *)-1) break; - } + loadinfo->base = prom_claim_chunk((void *)loadaddr, loadinfo->memsize, 0); if (loadinfo->base == (void *)-1) { prom_printf("Claim error, can't allocate kernel memory\n"); goto bail; @@ -1377,7 +1371,7 @@ load_elf64(struct boot_file_t *file, loadinfo_t *loadinfo) Elf64_Ehdr *e = &(loadinfo->elf.elf64hdr); Elf64_Phdr *p, *ph; int size = sizeof(Elf64_Ehdr) - sizeof(Elf_Ident); - unsigned long addr, loadaddr; + unsigned long loadaddr; /* Read the rest of the Elf header... */ if ((*(file->fs->read))(file, size, &e->e_version) < size) { @@ -1465,13 +1459,7 @@ load_elf64(struct boot_file_t *file, loadinfo_t *loadinfo) loadaddr = e->e_entry; } - /* On some systems, loadaddr may already be claimed, so try some - * other nearby addresses before giving up. - */ - for(addr=loadaddr; addr <= loadaddr * 8 ;addr+=0x100000) { - loadinfo->base = prom_claim((void *)addr, loadinfo->memsize, 0); - if (loadinfo->base != (void *)-1) break; - } + loadinfo->base = prom_claim_chunk((void *)loadaddr, loadinfo->memsize, 0); if (loadinfo->base == (void *)-1) { prom_printf("Claim error, can't allocate kernel memory\n"); goto bail; -- 2.39.2