Improved memory detection for cgsix

foo bar <[email protected]>
Newsgroups gmane.os.netbsd.ports.sparc
Message-ID <CAOddDr6B-oSXC3hHBKjR0a8dndwUnhyTZZeTqcg5S6Qix9eDVA@mail.gmail.com>
Hello all

So recently I got my hands on a GX+ (501-2039) and when I tried it out
on netbsd I noticed that it only detected 1M or vram instead of the 4M
the card has. Looking through the source code I found this.

src/sys/dev/sbus/cgsix_sbus.c: line 175

    sc->sc_ramsize = prom_getpropint(node, "fbmapped", 1024 * 1024);

However when I looked at the attributes of the GX+ I saw it didn't
even define an fbmapped at all, but it does have a vmsize = 4. Then I
checked a GX (501-1996) and it also does not have fbmapped but it does
have vmsize = 1. Finally I check a TGX+ clone w/ 2M of vram and it
does have fbmapped = 2M and it also has vmsize = 2. Based on this
limited sample size I believe the fbmapped attribute was added in the
TGX line. Attached below is a patch to check both attributes which
correctly detects the memory size on the cards I have.

After that I ran into a second problem in that the xserver would only
map 2M of ram. Looking at the code I found the xdriver doesn't detect
the memory size at all it just blindly tries to map memory til it
succeeds. I wasn't sure how to add memory detection to the driver so I
just raised the max amount it would try to 4M, patch below.

With these changes my GX+ is now properly detected as shown here.

[     1.000003] cgsix0 at sbus0 slot 1 offset 0x0 level 9:
SUNW,501-1717, 1152 x 900, rev 7
[     1.000003] cgsix0: attached to /dev/fb0
[     1.000003] cgsix0: framebuffer size: 4 MB

[   305.720] (II) SUNCG6(0): mapped 4096 KB video RAM
...
[   305.916] (II) EXA(0): Offscreen pixmap area of 3156480 bytes

Due to the extra ram the GX+ also gives a modest performance increase
over the GX.
ss10 - sm61  x11perf -comppixwin
GX    4510/s   613/s    31/s
GX+  5190/s  1870/s  123/s

Hope this helps.
cgsix_sbus.diff (application/octet-stream, 759 B)
Index: sys/dev/sbus/cgsix_sbus.c
===================================================================
RCS file: /cvsroot/src/sys/dev/sbus/cgsix_sbus.c,v
retrieving revision 1.30
diff -u -r1.30 cgsix_sbus.c
--- sys/dev/sbus/cgsix_sbus.c	17 Sep 2009 16:28:12 -0000	1.30
+++ sys/dev/sbus/cgsix_sbus.c	27 Feb 2022 00:25:21 -0000
@@ -172,7 +172,12 @@
 	 * we need the address of the framebuffer, no matter if we're console or
 	 * not.
 	 */
-	sc->sc_ramsize = prom_getpropint(node, "fbmapped", 1024 * 1024);
+	sc->sc_ramsize = prom_getpropint(node, "fbmapped", 0);
+
+	if (sc->sc_ramsize == 0) {
+		sc->sc_ramsize = 1024 * 1024 * prom_getpropint(node, "vmsize", 1);
+	}		
+	
 	if (sbus_bus_map(sa->sa_bustag,
 			sa->sa_slot,
 			sa->sa_offset + CGSIX_RAM_OFFSET,
cg6_xdriver.diff (application/octet-stream, 1.4 KB)
Index: external/mit/xf86-video-suncg6/dist/src/cg6_driver.c
===================================================================
RCS file: /cvsroot/xsrc/external/mit/xf86-video-suncg6/dist/src/cg6_driver.c,v
retrieving revision 1.14
diff -u -r1.14 cg6_driver.c
--- external/mit/xf86-video-suncg6/dist/src/cg6_driver.c	18 Jul 2019 18:02:10 -0000	1.14
+++ external/mit/xf86-video-suncg6/dist/src/cg6_driver.c	27 Feb 2022 00:24:39 -0000
@@ -456,16 +456,22 @@
      * XXX need something better here - we rely on the OS to allow mmap()ing 
      * usable VRAM ONLY. Works with NetBSD, may crash and burn on other OSes.
      */
-    pCg6->vidmem = 2 * 1024 * 1024;
+    pCg6->vidmem = 4 * 1024 * 1024;
     pCg6->fb = xf86MapSbusMem(psdp, CG6_RAM_VOFF, pCg6->vidmem);
     
     if (pCg6->fb == NULL) {
-        /* mapping 2MB failed - try 1MB */
-        pCg6->vidmem = 1024 * 1024;
+        /* mapping 4MB failed - try 2MB */
+        pCg6->vidmem = 2 * 1024 * 1024;
         pCg6->fb = xf86MapSbusMem(psdp, CG6_RAM_VOFF, pCg6->vidmem);
     }
 
     if (pCg6->fb == NULL) {
+	    /* mapping 2MB faild - try 1MB */
+	    pCg6->vidmem = 1024 * 1024;
+	    pCg6->fb = xf86MapSbusMem(psdp, CG6_RAM_VOFF, pCg6->vidmem);
+    }
+
+    if (pCg6->fb == NULL) {
         /* we can't map all video RAM - fall back to width*height */
         pCg6->vidmem = psdp->width * psdp->height;
         pCg6->fb = xf86MapSbusMem(psdp, CG6_RAM_VOFF, pCg6->vidmem);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.