Subject: NVidia binary driver
To: None <port-i386@netbsd.org>
From: Quentin Garnier <netbsd-port-i386@quatriemek.com>
List: port-i386
Date: 12/05/2002 23:34:07
It's a bit complicated, but it's an early work. Code is ugly and not
likely to work on your system. There are several points I'd be glad to
have some information on some issues :

	o I need to keep a DMA tag for my implementation of
os_alloc_contig_pages, maybe there is a way to avoid that. For
os_map_kernel_space, I call directly the underlying i386 functions. No
info is passed about what card the driver is working on, so I can't get
the matching softc structure where I'd store all the useful tags.

	o My implementation of MTRR manipulation is quite brutal, but it's hard
to understand the differences between FreeBSD and NetBSD code. The
clearing part is less fine grained in NetBSD, and the way I handle it
could lead to issues with multiple devices used by XFree86. I didn't
experienced any though.

	o AGP support is what needs the most immediate work. As of now I get some
weird results, depending on what driver I use (OS or Nv), and if my PCI
card is also present or not (I get APG2X [should be 4X] when both cards
are here, but no xvideo, and a broken display when only the AGP card is
plugged in).

	o I call uvm_fault in nv_get_phys_address, where the FreeBSD code uses a
quicker equivalent (it's like 2 lines of code). I doubt there will be any
performance loss, but maybe it is possible to circumvent some of uvm_fault
code.

	o I use kvm86, I'm not entirely sure it's the best thing to do. My main
concern is that it's not in GENERIC, but maybe I'm misleaded.

Now some extra info:

	o I test my code with a PCI card (Riva TNT2 M64) and an AGP card
(GeForce2 MX/MX 400). I haven't tried any other card.

	o I'm interested in your XFree86 logs and kdumps, along with the FreeBSD
ones in case it's possible.

	o GLX extension and Linux compatibility remain totally untested. There
may be lib issues with libGL.so.

	o There's KGDB support in the NVIDIA config. You may prefer DDB in case
of a panic (I got only one since I've been working on this, and I couldn't
prove it was related to the NVidia driver).

I'll be glad to hear any feedback, even if it's to say my code is bad :
that's the whole point of making it public, it needs to be improved.

Here's the README file :

NVidia drivers under NetBSD
===========================

$Id: README,v 1.3 2002/12/05 21:57:09 cube Exp $

TODO:
o Make NvAGP work
o Make OSAGP work too (OSAGP is less broken than NvAGP)
o Include sysctls
o Make GLX work
o Make Linux compatibility work with Linux GL libraries
o Play UT2003 under NetBSD
o Attach a wsdisplay? device to the nvidia device.

Notes
=====

There is little chance the driver will work with your
configuration. AGP is still far from working here (no
xvideo extension when I'm lucky enough to obtain a
display under XFree86).

Don't try this code unless you're willing to spend some
time on it.

Installation and configuration
==============================

There are several steps needed to install the NVidia binary
drivers distribution.

1. Download the NVidia release 1.0-3203 for FreeBSD. You can
find it here :

	http://www.nvidia.com/view.asp?IO=freebsd_1.0-3203

2. Extract the NVidia tarball somewhere. Let's call it
${NVIDIA_ROOT}. You will only need the object files located
into ${NVIDIA_ROOT}/obj.

3. Download the NetBSD kernel source patch. It is against
1.6K although it should work against 1.6J. You can find it
here :

	http://www.cubidou.net/netbsd/nvidia-kernel-021205.bz2

4. Apply the patch. It modifies the following files :

	o dev/pci/agp.c : see kern/19256
	o arch/i386/i386/mem.c : experimental support
for MEMRANGE_SET and _GET ioctls, as found in FreeBSD.
	o arch/i386/conf/majors.i386
	o arch/i386/conf/files.i386

It also creates a directory called nvidia into the arch/i386
tree and adds the NVIDIA kernel configuration example.

5. Copy ${NVIDIA_ROOT}/obj/Module-nvkernel to
/sys/arch/i386/nvidia/nvidia.o

6. Edit the NVIDIA example configuration file.

7. config and compile the kernel.

8. Create device nodes :

	# cd /dev
	# mknod nvidiactl c 181 0
	# mknod nvidia0 c 180 0
	# mknod nvidia1 c 180 1
	...

9. Download the XFree86 source patch, apply it, and
recompile and reinstall your XFree86 distribution. The patch
only modifies the XFree86 resulting binary, and should not
have any side effect.

You can find the patch here :

	http://www.cubidou.net/netbsd/nvidia-xsrc-021205.bz2

10. Copy ${NVIDIA_ROOT}/obj/nvidia_drv.o to
${X11BASE}/lib/modules/drivers.

11. Edit your XF86Config file and use the driver "nvidia" in
place of "nv". You can use XFree86 -configure and read
NVidia documentation to set up the options available with the
driver.

Contact
=======

Quentin Garnier <cube@cubidou.net>

-- 
Quentin Garnier - cube@cubidou.net
"Feels like I'm fiddling while Rome is burning down.
Should I lay my fiddle down and take a rifle from the ground ?"
Leigh Nash/Sixpence None The Richer, Paralyzed, Divine Discontents, 2002.