From 9225dfbdf08bb1d9583d88f3b07c15b93b94fdb7 Mon Sep 17 00:00:00 2001 From: Justin Hibbits Date: Wed, 4 Apr 2018 02:13:27 +0000 Subject: [PATCH] Correct the ilog2() for calculating memory sizes. TLB1 can handle ranges up to 4GB (through e5500, larger in e6500), but ilog2() took a unsigned int, which maxes out at 4GB-1, but truncates silently. Increase the input range to the largest supported, at least for 64-bit targets. This lets the DMAP be completely mapped, instead of only 1GB blocks with it assuming being fully mapped. --- sys/powerpc/booke/pmap.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sys/powerpc/booke/pmap.c b/sys/powerpc/booke/pmap.c index c9c9d15f9f26..759f9f115647 100644 --- a/sys/powerpc/booke/pmap.c +++ b/sys/powerpc/booke/pmap.c @@ -234,7 +234,7 @@ static vm_size_t tlb1_mapin_region(vm_offset_t, vm_paddr_t, vm_size_t); static vm_size_t tsize2size(unsigned int); static unsigned int size2tsize(vm_size_t); -static unsigned int ilog2(unsigned int); +static unsigned int ilog2(unsigned long); static void set_mas4_defaults(void); @@ -4020,12 +4020,17 @@ tlb1_write_entry(tlb_entry_t *e, unsigned int idx) * Return the largest uint value log such that 2^log <= num. */ static unsigned int -ilog2(unsigned int num) +ilog2(unsigned long num) { - int lz; + long lz; +#ifdef __powerpc64__ + __asm ("cntlzd %0, %1" : "=r" (lz) : "r" (num)); + return (63 - lz); +#else __asm ("cntlzw %0, %1" : "=r" (lz) : "r" (num)); return (31 - lz); +#endif } /* @@ -4163,7 +4168,8 @@ tlb1_mapin_region(vm_offset_t va, vm_paddr_t pa, vm_size_t size) for (idx = 0; idx < nents; idx++) { pgsz = pgs[idx]; - debugf("%u: %llx -> %x, size=%x\n", idx, pa, va, pgsz); + debugf("%u: %llx -> %jx, size=%jx\n", idx, pa, + (uintmax_t)va, (uintmax_t)pgsz); tlb1_set_entry(va, pa, pgsz, _TLB_ENTRY_SHARED | _TLB_ENTRY_MEM); pa += pgsz;