Subject: drm drivers for NetBSD
To: None <tech-x11@netbsd.org>
From: Yorick Hardy <yhardy@uj.ac.za>
List: tech-x11
Date: 03/19/2007 10:05:30
I managed to get drm working here on NetBSD 4.0_BETA2
using the i915 driver.

No guarantee that it will work for anyone else ;-)

I am sure it can still be improved, but hopefully this
is a good start. Most of the code was already there,
it just needed some cleaning up for the more recent
version of drm (from FreeBSD src/sys/dev/drm).

Please see

 http://issc.uj.ac.za/~yorick/drm/

1) You need to patch your source with netbsd4.patch
2) Add the following lines to your kernel configuration.
    # DRM: direct rendering modules
    options        DRM_DEBUG
    i915drm*       at vga?    # Intel i915, i945 DRM driver
    mach64drm*     at vga?    # mach64 (3D Rage Pro, Rage) DRM driver
    mgadrm*        at vga?    # Matrox G[24]00, G[45]50 DRM driver
    r128drm*       at vga?    # ATI Rage 128 DRM driver
    radeondrm*     at vga?    # ATI Radeon DRM driver
    savagedrm*     at vga?    # S3 Savage DRM driver
    sisdrm*        at vga?    # SiS DRM driver
    tdfxdrm*       at vga?    # 3dfx (voodoo) DRM driver
  
3) X must be compiled with DRI support. I used Xorg7.2
   (with --with-mesa-source).
4) Mesa DRI drivers are needed. Compile mesa using
   netbsd-dri configuration (mesa.patch) which is
   more or less the same as freebsd-dri.
5) Make the device node (mkcard.sh)
    mkdir /dev/dri
    mknod /dev/dri/card0 c 34 0
6) Check your X configuration (xorg.conf, XF86Config):
   Section "Module"
           ...         
           Load  "dri"
           Load  "GLcore"
           Load  "glx"
   EndSection

   ...
   Section "DRI"
           Group "wheel"
           Mode 0660
   EndSection
7) dmesg | grep drm
   i915drm0 at vga0info: [drm] Intel i945GM (unit 0)
   info: [drm] AGP at 0xd0000000 256MB
   info: [drm] Initialized i915 1.5.0 20060119

   or some equivalent.


Things to watch out for:

1) Just in case:
    sysctl -w ddb.onpanic=0
   (so you don't get stuck in ddb after a mode switch
    with no way to issue commands)
2) Until you know it works:
    (sleep 60; reboot)&
    startx
3) When things go wrong you might lose
    /dev/dri/card0
   or it might even change the major number to 0
   (which seems to make it impossible to
    login on console (login on/dev/ttyE1 instead))
   Just use mkcard.sh to fix this.
4) Disable AIGLX if necessary (xorg.conf):
  
   Section "ServerFlags"
           Option  "AIGLX" "off"
   EndSection

   Section "Extensions"
           Option "Composite" "Disable"
   EndSection

   until you know it works.
   AIGLX seems to require the server Xorg
   to be linked against libpthread. Check
   this if you intend to use it.

Remarks:

1) Comment out DRM_DEBUG once everything works,
   it can slow things down quite a bit.
   or sysctl -w hw.dri.debug=0
2) sysctl -a | more
   and search for hw.dri.card0
3) I had to remove the workaround for an
   X server bug in agp_i810.c.
   Is this still true?
   (It does not seem to seem to affect my machine).
   It is a bit messy to accommodate the workaround.
4) I had to fix mtrr_i686.c
   Can someone check this?
5) FreeBSD has sys/dev/drm, while I chose
   sys/dev/pci/drm because most of the drivers
   seem PCI bound.

I hope that covers everything.

-- 
Kind regards,

Yorick Hardy