]> git.ozlabs.org Git - yaboot.git/commitdiff
The patch from Scott Moser moves the "search-for-prom_claim'able" routine that
authorPaul Nasrat <pauln@enki.eridu>
Mon, 3 Dec 2007 12:37:10 +0000 (12:37 +0000)
committerPaul Nasrat <pauln@enki.eridu>
Mon, 3 Dec 2007 12:37:10 +0000 (12:37 +0000)
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
second/prom.c
second/yaboot.c

index f5ee88f8c2a09392009736ecf1047aa66a977dad..6e4d890c49b0d28ad2f5dcfe88280b5f61be4829 100644 (file)
@@ -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);
index e9c5843e1efec04b25baa7185e16a9025b8e0905..4ad727761b47a58f2a6b47869df912dd3de04df4 100644 (file)
@@ -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)
 {
index 0232d33153b58da3c9c0fafecde8016437324f17..53643f5c5fff48d56f809712a535e67f2d429810 100644 (file)
@@ -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;