Subject: port-sparc/2514: X on cgfour
To: None <gnats-bugs@NetBSD.ORG>
From: None <perseant@hitl.washington.edu>
List: netbsd-bugs
Date: 06/04/1996 09:40:10
>Number:         2514
>Category:       port-sparc
>Synopsis:       X fails under cgfour driver
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jun  4 12:50:01 1996
>Last-Modified:
>Originator:     
>Organization:
-----------------------------------------------------------------------------
  Konrad Schroder      System Administrator, Human Interface Technology Lab
  Snail Mail: Box 352142, University of Washington, Seattle, WA 98195 (USA)
  Voice: (206) 616-1478                                 FAX: (206) 543-5380
  Work: perseant@hitl.washington.edu                Play: perseant@hhhh.org
          WWW: http://www.hitl.washington.edu/people/perseant/
-----------------------------------------------------------------------------
>Release:        ~May 25, 1996
>Environment:
	Sun4/110
>Description:
	
	The X11 server fails to operate using the cgfour device, with the
	following error:

         mapping frame buffer memory: Invalid argument
         Couldn't allocate frame buffer memory: Cannot allocate memory

         Fatal server error:
         no screens found

>How-To-Repeat:
	
	/usr/X11R6/bin/X :0

>Fix:
	
	Brad Spencer suggested substituting the following code for cgfour_mmap
	in dev/cgfour.c; it works for him, works for me, perhaps for others?:

#define CG4REG_CMAP     0x200000
#define CG4REG_OVERLAY  0x400000
#define CG4REG_ENABLE   0x600000
#define CG4REG_COLOUR   0x800000
#define CG4REG_END      0xa00000
int
cgfourmmap(dev, off, prot)
        dev_t dev;
        int off, prot;
{
        register struct cgfour_softc *sc = cgfour_cd.cd_devs[minor(dev)];
        int poff;

#define START_ENABLE    (128*1024)
#define START_COLOUR    (128*1024 + 128*1024)
#define COLOUR_SIZE     (sc->sc_fb.fb_type.fb_width * sc->sc_fb.fb_type.fb_height)
#define END_COLOUR      (START_COLOUR + COLOUR_SIZE)
#define NOOVERLAY       (0x04000000)

        if (off & PGOFSET)
                panic("cgfourmap");

        if ((u_int)off >= NOOVERLAY)
          {
            off = off - NOOVERLAY;

            /*
             * X11 maps a huge chunk of the frame buffer; far more than
             * there really is. We compensate by double-mapping the
             * first page for as many other pages as it wants
             */
            while (off >= COLOUR_SIZE)
              off = 0;
            poff = off + (CG4REG_COLOUR - CG4REG_OVERLAY);
          }
        else
          if ((u_int)off < START_ENABLE)        /* in overlay plane */
            poff = off;
          else
            if ((u_int)off < START_COLOUR)      /* in enable plane */
              poff = off + (CG4REG_ENABLE - CG4REG_OVERLAY) - START_ENABLE;
            else
              if ((u_int)off < (CG4REG_END - CG4REG_OVERLAY))   /* in colour plane */ 
                poff = off + (CG4REG_COLOUR - CG4REG_OVERLAY) - START_COLOUR;
              else
                return (-1);
        return (REG2PHYS(&sc->sc_phys, poff + CG4REG_OVERLAY - 0x300000,
		sc->sc_bustype) | PMAP_NC);
}
>Audit-Trail:
>Unformatted:
>System: NetBSD toast.hitl.washington.edu 1.1B NetBSD 1.1B (HITL_SUN4M) #0: Fri May 31 20:14:28 PDT 1996 perseant@molotov.hitl.washington.edu:/usr/src/sys/arch/sparc/compile/HITL_SUN4M sparc