Subject: /dev/vga and /dev/mem XFree problems with UVM
To: None <current-users@NetBSD.ORG, tech-kern@NetBSD.ORG, port-i386@NetBSD.ORG>
From: Thor Lancelot Simon <tls@panix.com>
List: port-i386
Date: 02/09/1998 15:19:17
I'm having some trouble using XFree with UVM.

One one machine, with an S3 764, XFree complains that it can't mmap /dev/vga
and exits.  I can in fact mmap /dev/vga with a test program, so I assume it's
the mapped range that XFree's unhappy about.  Rebuilding with INSECURE so
XFree can use a linear mapping for the framebuffer works.

On another machine with an S3 ViRGE/DX, the problem is worse.  This XFree
server (the ViRGE support in the SVGA server, actually) can't use /dev/vga,
so I was already running with INSECURE.  X finds the card at
0xf8000000, reads out the chipset's configuration, and tries to map the
framebuffer, which fails:

(--) SVGA: Detected S3 ViRGE/DXGX
(--) SVGA: using driver for chipset "s3_virge"
(**) SVGA: videoram:  4096k
(--) SVGA: Ramdac speed: 170 MHz  (135 MHz for 24 bpp)
(--) SVGA: Detected current MCLK value of 47.131 MHz
(--) SVGA: Using Memory Clock value of 55.000 MHz

Fatal server error:
xf86MapVidMem: Address 0xf9000000 outside allowable range

The card has 4MB of memory, so 0xf9000000 should in fact be in the frame
buffer.

I've ktraced the X server; a call to mmap() is in fact failing.  However,
the arguments to the preceding open() look a bit odd, too; is UVM picker
about the mode /dev/mem's opened with?  But then why EINVAL instead of EPERM?

   284 XF86_SVGA RET   write 57/0x39
   284 XF86_SVGA CALL  write(0x2,0xefbfd388,0x22)
   284 XF86_SVGA GIO   fd 2 wrote 34 bytes
       "(--) SVGA: Detected S3 ViRGE/DXGX
       "
   284 XF86_SVGA RET   write 34/0x22
   284 XF86_SVGA CALL  write(0x2,0xefbfd374,0x2f)
   284 XF86_SVGA GIO   fd 2 wrote 47 bytes
       "(--) SVGA: using driver for chipset "s3_virge"
       "
   284 XF86_SVGA RET   write 47/0x2f
   284 XF86_SVGA CALL  sysarch(0x2,0xefbfdaa8)
   284 XF86_SVGA RET   sysarch 0
   284 XF86_SVGA CALL  write(0x2,0xefbfd390,0x1c)
   284 XF86_SVGA GIO   fd 2 wrote 28 bytes
       "(**) SVGA: videoram:  4096k
       "
   284 XF86_SVGA RET   write 28/0x1c
   284 XF86_SVGA CALL  nanosleep(0xefbfdae8,0)
   284 XF86_SVGA RET   nanosleep 0
   284 XF86_SVGA CALL  open(0xae010,0,0x3d5)
   284 XF86_SVGA NAMI  "/dev/mem"
   284 XF86_SVGA RET   open 4
   284 XF86_SVGA CALL  lseek(0x4,0,0xc0000,0,0)
   284 XF86_SVGA RET   lseek 786432/0xc0000
   284 XF86_SVGA CALL  read(0x4,0x26376c,0x400)
   284 XF86_SVGA GIO   fd 4 read 1024 bytes
       "U\M-*@\M-k\^D7400\M-:\M-D\^C\M-8\b\^F\M-o\M-8	\0\M-o\M-i\^S\^[\0D\^A\
	\M-U]\M-Y]IBM VGA COMPATIBLE BIOS. \0\M-;f$\^A\M-x\^A\0\0003S\^A\M^JMD\
	=AM\^A\^AS3 86C375/86C385 Video BIOS. Version 2.01.11\r
	Copyright 1996 S3 Incorporated.\r
	\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\00007/02/9708/08/97\^B\^A\^Q\0\0\0\0\
	\0	\^B\M^@\M-P	\^D\^U\^U\^B\^P\0\M^@\M-~\b\^D\^D\0\0\^D\^D\0\
	\0\^P \0\0\0\0\0`\0NF^F\M^HF\0\0\0\0\0\0\0\0\0\0\^Pa\M^?\^?\M-lF\0\0\\\
	\^A\0\0\^E\^A:\^A\^D\M^P	\^Z8H9\M-%1\^E2@3\0004\0005\0:\^E<\^P@\
	\0B\0C\0E\0Q\0S\0T0U\0X\^C]\0^\0`\^Oe\0f\0g\0i\0j\0\^D\b\^F\v\0\^T\0\
	\^X@\M^PPCIR3S\^A\M^J\0\0\^X\0\0\^C\0\0@\0\0\0\0\M^@\0\0\^Z\M-{\^B\^C\
	\0\0\^BD\^F\^Y;\^C3\0\0\^B;\^FT{\^C\^F\^A\0\^N
	\aD{\^C\^F\^A0\^N\^A\a4{\^C\^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M-#\M^?\0\^A\^B\^C\
	\^D\^E\^T\a89:;<=>?\f\0\^O\0\0\0\0\0\0\M^P\^N\0\M^?\M^D\^X\^P\0 \^A\^C\
	\0\^B/\M^Z\M^C\M^D\M^\\M^H\^Z\M-?\^_\0O\r\^N\0\0\0\0\M^\\M^N\M^OB\^_\
	\M^V\M-9\M-#\M^?\0\^A\^B\^C\^D\^E\^T\a89:;<=>?\f\0\^O\0\0\0\0\0\0\M^P\
	\^N\0\M^?(\^X\^P\0\^P\^A\^O\0\^N/_OQ\M^BR\M^_\M-?\^_\0A\0\0\0\0\M^?\0\
	\M^\\M^N\M^OP@\M^V\M-9\M-#\M^?\0\^A\^B\^C\^D\^E\^F\a\^P\^Q\^R\^S\^T\^U\
	\^V\^WA\0\^O\0\0\0\0\0\0@\^E\^O\M^?(\^]\^P\0\^P\^A\^O\0\^N//'(\^O*\M^M\
	\^F>\0A\0\0\0\0\M^?\0\M-h\M^K\M-_\M^@`\M-_\^F\M-+\M^?\0\^A\^B\^C\^D\^E\
	\^F\a\^P\^Q\^R\^S\^T\^U\^V\^WA\0\^O\0\0\0\0\0\0@\^E\^O\M^?2J\b\0\M-z"
   284 XF86_SVGA RET   read 1024/0x400
   284 XF86_SVGA CALL  close(0x4)
   284 XF86_SVGA RET   close 0
   284 XF86_SVGA CALL  nanosleep(0xefbfdae8,0)
   284 XF86_SVGA RET   nanosleep 0
   284 XF86_SVGA CALL  write(0x2,0xefbfd390,0x20)
   284 XF86_SVGA GIO   fd 2 wrote 32 bytes
       "(--) SVGA: Ramdac speed: 170 MHz"
   284 XF86_SVGA RET   write 32/0x20
   284 XF86_SVGA CALL  write(0x2,0xefbfd394,0x16)
   284 XF86_SVGA GIO   fd 2 wrote 22 bytes
       "  (135 MHz for 24 bpp)"
   284 XF86_SVGA RET   write 22/0x16
   284 XF86_SVGA CALL  write(0x2,0xefbfd39c,0x1)
   284 XF86_SVGA GIO   fd 2 wrote 1 bytes
       "
       "
   284 XF86_SVGA RET   write 1
   284 XF86_SVGA CALL  write(0x2,0xefbfd38c,0x35)
   284 XF86_SVGA GIO   fd 2 wrote 53 bytes
       "(--) SVGA: Detected current MCLK value of 47.131 MHz
       "
   284 XF86_SVGA RET   write 53/0x35
   284 XF86_SVGA CALL  write(0x2,0xefbfd38c,0x32)
   284 XF86_SVGA GIO   fd 2 wrote 50 bytes
       "(--) SVGA: Using Memory Clock value of 55.000 MHz
       "
   284 XF86_SVGA RET   write 50/0x32
   284 XF86_SVGA CALL  open(0xaf26c,0x2,0xf9000000)
   284 XF86_SVGA NAMI  "/dev/mem"
   284 XF86_SVGA RET   open 4
   284 XF86_SVGA CALL  mmap(0,0x1000,0x3,0,0x4,0,0xa0000,0)
   284 XF86_SVGA RET   mmap -1 errno 22 Invalid argument
   284 XF86_SVGA CALL  write(0x2,0xefbfd360,0x15)
   284 XF86_SVGA GIO   fd 2 wrote 21 bytes
       "
	Fatal server error:
       "
   284 XF86_SVGA RET   write 21/0x15
   284 XF86_SVGA CALL  write(0x2,0xefbfd368,0x3a)
   284 XF86_SVGA GIO   fd 2 wrote 58 bytes
       "xf86MapVidMem: Address 0xf9000000 outside allowable range
       "

I'll chase this further myself, but input from others would be useful.

-- 
Thor Lancelot Simon	                                      tls@rek.tjls.com
	"And where do all these highways go, now that we are free?"