> Date: Thu, 5 Jul 2018 01:12:32 +0200
> From: "Peter J. Philipp" <p...@centroid.eu>
> 
> On Wed, Jul 04, 2018 at 08:19:25PM +0200, Peter J. Philipp wrote:
> > Hi again,
> > 
> > I came up with a fix, but not sure if it's correct.  The problem is that the
> > physical memory here is 32 bits (paddr_t defined in 
> > arch/powerpc/include/_types.h).
> > So when we have 4 banks of 1 GB we end up with 2^32 which wraps around to 0 
> > on
> > the paddr_t so we report as 0MB.  My fix/workaround is simple I steal a 
> > page 
> > upon atop() so that upon wrap-around at 4GB (selfish I know) some pages are 
> > missing and it ends up below MAX of unsigned long.  
> > 
> > According to wikipedia only the PowerMac11,2 supports up to 16 GB the rest
> > are all maximum 4GB, and I don't think the PowerMac11,2 is supported.
> > 
> > https://en.wikipedia.org/wiki/Power_Mac_G5
> > 
> > -peter
> 
> So sorry, it was erroneous... second attempt.  The first attempt wasn't safe 
> for replies from OFW that were of size 0.  Also on my box the dmesg starts 
> like so on this:

Sorry, but this isn't quite right.  What the code should really do is
count all memory below the 4G boundary.  Since part if the phyical
address space is reserved for devices that will be less < 4GB.

Yes that means that dmesg will not report the full amount of memory in
the machine.  But you can't use that memory anyway on a 32-bit OpenBSD
system.  And if the physmem variable includes a lot of memory that
isn't actually usable, the kernel will make bad choices in sizing
various things.

Cheers,

Mark

> OpenBSD 6.3-current (GENERIC.MP) #8: Thu Jul  5 00:59:43 CEST 2018
>     p...@iota.centroid.eu:/usr/src/sys/arch/macppc/compile/GENERIC.MP
> real mem = 4294950912 (4095MB)
> avail mem = 2020478976 (1926MB)
> mpath0 at root
> scsibus0 at mpath0: 256 targets
> mainbus0 at root: model PowerMac7,3
> cpu0 at mainbus0: 970FX (Revision 0x300): 1800 MHz
> cpu1 at mainbus0: 970FX (Revision 0x300): 1800 MHz
> mem0 at mainbus0
> 
> Also to show that a disklabel works it looks like so:
> 
> iota# disklabel -E wd0
> Label editor (enter '?' for help at any prompt)
> > A
> > p
> OpenBSD area: 4096-625142448; size: 625138352; free: 48
> #                size           offset  fstype [fsize bsize   cpg]
>   a:          2097152             4096  4.2BSD   2048 16384     1 # /
>   b:          8912864          2101248    swap                    
>   c:        625142448                0  unused                    
>   d:          8388608         11014112  4.2BSD   2048 16384     1 # /tmp
>   e:         25165760         19402720  4.2BSD   2048 16384     1 # /var
>   f:          4194304         44568480  4.2BSD   2048 16384     1 # /usr
>   g:          2097152         48762784  4.2BSD   2048 16384     1 # /usr/X11R6
>   h:         20971520         50859936  4.2BSD   2048 16384     1 # /usr/local
>   i:             2048                1   MSDOS                    
>   j:          4194304         71831456  4.2BSD   2048 16384     1 # /usr/src
>   k:         12582912         76025760  4.2BSD   2048 16384     1 # /usr/obj
>   l:        536533728         88608672  4.2BSD   4096 32768     1 # /home
> > x
> iota# 
> 
> Which would seem correct.
> 
> Regards,
> 
> -peter
> 
> 
> Index: ofw_machdep.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/macppc/macppc/ofw_machdep.c,v
> retrieving revision 1.56
> diff -u -p -u -r1.56 ofw_machdep.c
> --- ofw_machdep.c     22 Jul 2017 18:33:38 -0000      1.56
> +++ ofw_machdep.c     4 Jul 2018 23:03:05 -0000
> @@ -133,7 +133,7 @@ ofw_read_mem_regions(int phandle, int ad
>  {
>       int nreg, navail;
>       int i, j;
> -     uint physpages;
> +     uint physpages, tmp;
>  
>       switch (address_cells) {
>       default:
> @@ -171,16 +171,22 @@ ofw_read_mem_regions(int phandle, int ad
>       case 2:
>               physpages = 0;
>               for (i = 0, j = 0; i < nreg; i++) {
> -                     if (OFmem64[i].size == 0)
> +                     tmp = OFmem64[i].size;
> +                     if (tmp == 0)
>                               continue;
> -                     physpages += atop(OFmem64[i].size);
> +                     /* 
> +                      * we steal a page here per memory bank if there is
> +                      * some to steal, this will ultimately prevent 
> +                      * wrapover to 0
> +                      */
> +                     physpages += (atop(tmp) ? atop(tmp) - 1 : 0);
>                       if (OFmem64[i].start >= 1ULL << 32)
>                               continue;
>                       OFmem[j].start = OFmem64[i].start;
> -                     if (OFmem64[i].start + OFmem64[i].size >= 1ULL << 32)
> +                     if (OFmem64[i].start + tmp >= 1ULL << 32)
>                               OFmem[j].size = (1ULL << 32) - OFmem64[i].start;
>                       else
> -                             OFmem[j].size = OFmem64[i].size;
> +                             OFmem[j].size = tmp;
>                       j++;
>               }
>               physmem = physpages;
> 
> 

Reply via email to