Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Apr 2018 02:13:27 +0000 (UTC)
From:      Justin Hibbits <jhibbits@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r331970 - head/sys/powerpc/booke
Message-ID:  <201804040213.w342DRG8043970@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhibbits
Date: Wed Apr  4 02:13:27 2018
New Revision: 331970
URL: https://svnweb.freebsd.org/changeset/base/331970

Log:
  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.

Modified:
  head/sys/powerpc/booke/pmap.c

Modified: head/sys/powerpc/booke/pmap.c
==============================================================================
--- head/sys/powerpc/booke/pmap.c	Wed Apr  4 02:00:10 2018	(r331969)
+++ head/sys/powerpc/booke/pmap.c	Wed Apr  4 02:13:27 2018	(r331970)
@@ -234,7 +234,7 @@ static vm_size_t tlb1_mapin_region(vm_offset_t, vm_pad
 
 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_si
 
 	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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201804040213.w342DRG8043970>