adralloc() now returns the pa of the allocated memory, else ~0ull on error. before it returned 0 on error, which means that any allocation of address 0 (a right proper physical address) could have been confused with an error. Reference: /n/atom/patch/applied/adralloc0 Date: Sat Mar 8 04:30:56 CET 2014 Signed-off-by: quanstro@quanstro.net --- /sys/src/nix/k10/adr.c Sat Mar 8 04:29:16 2014 +++ /sys/src/nix/k10/adr.c Sat Mar 8 04:29:17 2014 @@ -290,23 +290,25 @@ trymerge(a-1, a); return base; } - return 0; + return ~0ull; } uintmem adralloc(uintmem base, uintmem len, int align, int type, int use, uint memflags) { + uintmem r; + DBG("adralloc: %#P:%#P, %s flags %#ux\n", base, len, tnam(type), memflags); lock(&adr); - base = intadralloc(base, len, align, type, use, Cnone, memflags); + r = intadralloc(base, len, align, type, use, Cnone, memflags); unlock(&adr); - if(base == 0){ + if(r == ~0ull){ print("adralloc: fail %#P len %#P type %s use %s align %d flags %#ux from %#p\n", base, len, tnam(type), uname[use], align, memflags, getcallerpc(&base)); - adrdump(); + // adrdump(); } - return base; + return r; } void @@ -375,9 +377,9 @@ if(b >= e) continue; - print("adrsetcolor: split range [%#P %#P) ⊂ [%#P %#P)\n", + DBG("adrsetcolor: split range [%#P %#P) ⊂ [%#P %#P)\n", b, e, a->base, aend); - if(intadralloc(b, e-b, 0, a->type, a->use, color, a->memflags) == 0) + if(intadralloc(b, e-b, 0, a->type, a->use, color, a->memflags) == ~0ull) print("adrsetcolor: no such memory [%#P %#P) ⊂ [%#P %#P)\n", b, e, a->base, aend); } @@ -402,7 +404,7 @@ else{ m->type = type; unlock(&adr); - adralloc(base, len, 0, type, use, 0); + intadralloc(base, len, 0, type, use, color, 0); } } @@ -474,7 +476,7 @@ /* can pick any pa; expect INIMAP */ pa = adralloc(0, sys->vmend - sys->vmunmapped, 0, Amemory, Mkpage, 0); - if(pa == 0) + if(pa == ~0ull) panic("adr: insufficient contiguous memory for kernel %#P", pa); print("pa %#P (%#P %#P)\n", pa, sys->vmend, sys->vmunmapped); --- /sys/src/nix/k10/mmu.c Sat Mar 8 04:29:19 2014 +++ /sys/src/nix/k10/mmu.c Sat Mar 8 04:29:20 2014 @@ -621,7 +621,7 @@ * only adralloc the actual request. pci bars can be less than 1 page. * take it on faith that they don't overlap. */ - if(pa == 0 || adralloc(pa+o, size, 0, -1, Mvmap, flags) == 0){ + if(pa == 0 || adralloc(pa+o, size, 0, -1, Mvmap, flags) == ~0ull){ print("vmapflags(0, %lud) pc=%#p\n", size, getcallerpc(&pa)); return nil; } @@ -683,7 +683,7 @@ return nil; if(pa+sz < 1ull*MiB) - return KADDR(pa); + return KADDR(pa+o); if(pa < 1ull*MiB) return nil; for(p = pa; p < pa+sz; p += PGSZ){ --- /sys/src/nix/k10/screen.c Sat Mar 8 04:29:21 2014 +++ /sys/src/nix/k10/screen.c Sat Mar 8 04:29:22 2014 @@ -129,7 +129,7 @@ */ size = ROUNDUP(size, PGSZ); scr->paddr = adralloc(0, size, PGSZ, Amemory, Mfree, 0); - if(scr->paddr == 0) + if(scr->paddr == ~0ull) return -1; if(scr->paddr > 0xffffffffull) print("screen mapped high %#P\n", scr->paddr);