<?xml version='1.0' encoding="UTF-8"?>
<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/nvidia-guide.xml,v 1.22 2006/01/21 12:54:58 swift Exp $ -->
<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">

<guide link="/doc/en/nvidia-guide.xml">
<title>Gentoo Linux nVidia Guide</title>

<author title="Author">
  <mail link="swift@gentoo.org">Sven Vermeulen</mail>
</author>
<author title="Editor">
  <mail link="curtis119@gentoo.org">M Curtis Napier</mail>
</author>
<author title="Editor">
  <mail link="jackdark@gmail.com">Joshua Saddler</mail>
</author>

<abstract>
Many Gentooists have an nVidia chipset on their system. nVidia provides specific
Linux drivers to boost the performance of your card. This guide informs you how
to install and configure these drivers.
</abstract>

<!-- The content of this document is licensed under the CC-BY-SA license -->
<!-- See http://creativecommons.org/licenses/by-sa/2.5 -->
<license/>

<version>1.18</version>
<date>2006-01-21</date>

<chapter>
<title>Introduction</title>
<section>
<body>

<p>
nVidia release their own Linux drivers which provide good performance and full
3D acceleration. The driver releases are split up into two parts:
<c>nvidia-kernel</c> and <c>nvidia-glx</c>.
</p>

<p>
<c>nvidia-kernel</c> is a kernel driver which handles the low-level
communication with your video hardware. This is simply a kernel module, named
<c>nvidia</c>, which installs against your kernel sources and needs to be loaded
whenever you want to use the nvidia drivers.
</p>

<p>
As well as the kernel driver, you need to install the X11 GLX layer
(<c>nvidia-glx</c>). This is used by X to render graphics, which internally
uses the <c>nvidia-kernel</c> kernel driver to interface with the hardware.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Configuring your Card</title>
<section>
<title>Kernel Configuration</title>
<body>

<p>
As mentioned above, the nVidia kernel driver installs and runs against your
current kernel. It builds as a module, so it makes sense that your kernel must
support the loading of kernel modules. If you used <c>genkernel</c> to configure
the kernel for you then you're all set. If not, double check your kernel
configuration so that this support is enabled:
</p>

<pre caption="Enabling the Loading of Kernel Modules">
Loadable module support ---&gt;
  [*] Enable loadable module support
</pre>

<p>
You also need to enable <e>Memory Type Range Register</e> in your kernel:
</p>

<pre caption="Enabling MTRR">
Processor and Features ---&gt;
  [*] MTRR (Memory Type Range Register) support
</pre>

<p>
nVidia's modules and libraries are combined in two packages: <c>nvidia-glx</c>
and <c>nvidia-kernel</c>. The former are the X11 GLX libraries while the latter
are the kernel modules.
</p>

<p>
The nvidia-kernel ebuild auto discovers your kernel version based on the
<path>/usr/src/linux</path> symlink. Please ensure that you have this symlink
pointing to the correct sources and that your kernel is correctly configured.
Please refer to the Configuring the Kernel section of the <uri
link="/doc/en/handbook/">Installation Handbook</uri> for details on configuring
your kernel.
</p>

<p>
If you are using gentoo-sources-2.6.11-r6, your <path>/usr/src</path> directory
might look something like this:
</p>

<pre caption="Check your /usr/src/linux symlink">
# <i>cd /usr/src</i>
# <i>ls -l</i>
<comment>(Check that linux points to the right directory)</comment>
lrwxrwxrwx   1 root root   22 Apr 23 18:33 linux -&gt; linux-2.6.11-gentoo-r6
drwxr-xr-x   4 root root  120 Apr  8 18:56 linux-2.4.26-gentoo-r4
drwxr-xr-x  18 root root  664 Dec 31 16:09 linux-2.6.10
drwxr-xr-x  18 root root  632 Mar  3 12:27 linux-2.6.11
drwxr-xr-x  19 root root 4096 Mar 16 22:00 linux-2.6.11-gentoo-r6
</pre>

<p>
In the above output, you'll notice that the <c>linux</c> symlink is pointing
to the <c>linux-2.6.11-gentoo-r6</c> kernel.
</p>

<p>
If the symlink is not pointing to the correct sources, you must update the link
like this:
</p>

<pre caption="Create/Update /usr/src/linux symlink">
# <i>cd /usr/src</i>
# <i>ln -snf linux-2.6.11-gentoo-r6 linux</i>
</pre>

</body>
</section>
<section>
<title>Optional: Check for Legacy Card Support</title>
<body>

<note>
Unfortunately, certain legacy video cards are not supported by the newer
versions of <c>nvidia-glx</c> and <c>nvidia-kernel</c>. nVidia provides a <uri
link="http://www.nvidia.com/object/IO_18897.html">list of supported cards</uri>.
Please check the list before installing the drivers.
</note>

<p>
The following is a list of <b>unsupported</b> legacy video cards:
</p>

<pre caption="Unsupported cards">
TNT2
TNT2 Pro
TNT2 Ultra
TNT2 Model 64 (M64)
TNT2 Model 64 (M64) Pro
Vanta
Vanta LT
GeForce 256
GeForce DDR
GeForce2 GTS
GeForce2 Pro
GeForce2 Ti
GeForce2 Ultra
GeForce2 MX Integrated graphics
Quadro
Quadro2 Pro
Quadro2 EX
</pre>

<p>
If you own one of these cards, you will have to mask the newer versions of the
nVidia drivers, and install an older version:
</p>

<pre caption="Masking newer drivers">
# <i>echo "&gt;media-video/nvidia-kernel-1.0.6629-r4" &gt;&gt; /etc/portage/package.mask</i>
# <i>echo "&gt;media-video/nvidia-glx-1.0.6629-r7" &gt;&gt; /etc/portage/package.mask</i>
</pre>

</body>
</section>
<section>
<title>Installing the Appropriate Drivers</title>
<body>

<p>
Now it's time to install <c>nvidia-kernel</c> and <c>nvidia-glx</c>. Since
<c>nvidia-glx</c> depends on <c>nvidia-kernel</c>, installing <c>nvidia-glx</c>
is sufficient.
</p>

<pre caption="Installing the nVidia modules">
# <i>emerge nvidia-glx</i>
</pre>

<impo>
Every time you <uri link="/doc/en/kernel-upgrade.xml">compile a new
kernel</uri> or recompile the current one, you have to run <c>emerge
nvidia-kernel</c> to reinstall the nVidia modules. <c>nvidia-glx</c> is
unaffected by a kernel change and doesn't even need to be rebuilt when you
recompile/upgrade X.
</impo>

<p>
Once the installation has finished, run <c>modprobe nvidia</c> to load the
kernel module into memory.
</p>

<pre caption="Loading the kernel module">
# <i>modprobe nvidia</i>
</pre>

<p>
To prevent you having to manually load the module on every bootup, you probably
want to have this done automatically each time you boot your system, so edit
<path>/etc/modules.autoload.d/kernel-2.6</path> (or <path>kernel-2.4</path>,
depending on which kernel version you use) and add <c>nvidia</c> to it. Don't
forget to run <c>modules-update</c> afterwards.
</p>

<pre caption="Running modules-update">
# <i>modules-update</i>
</pre>

</body>
</section>
<section>
<title>Configuring the X Server</title>
<body>

<p>
Once the appropriate drivers are installed you need to configure your X Server
(XFree86 or Xorg) to use the <c>nvidia</c> driver instead of the default
<c>nv</c> driver.
</p>

<p>
Open <path>/etc/X11/xorg.conf</path> (or <path>/etc/X11/XF86Config</path> if you
still use the older configuration file location) with your favorite editor
(such as <c>nano</c> or <c>vim</c>) and go to the <c>Device</c> section. In that
section, change the <c>Driver</c> line:
</p>

<pre caption="Changing nv to nvidia in the X Server configuration">
Section "Device"
  Identifier "nVidia Inc. GeForce2"
  <i>Driver     "nvidia"</i>
  VideoRam   65536
EndSection
</pre>

<p>
Then go to the <c>Module</c> section and make sure the <c>glx</c> module gets
loaded while the <c>dri</c> module doesn't:
</p>

<pre caption="Updating the Module section">
Section "Module"
  <comment>(...)</comment>
  <i># Load  "dri"
  Load  "glx"</i>
  <comment>(...)</comment>
EndSection
</pre>

<p>
Next, in section <c>Screen</c>, make sure that either the <c>DefaultDepth</c>
directive is set to 16 or 24, or that you only have <c>Display</c> subsections
with <c>Depth</c> settings of 16 or 24. Without it, the nvidia-glx extensions
will not start.
</p>

<pre caption="Updating the Screen section">
Section "Screen"
  <comment>(...)</comment>
  <i>DefaultDepth 16</i>
  Subsection "Display"
  <comment>(...)</comment>
EndSection
</pre>

<p>
Run <c>opengl-update</c> so that the X Server uses the nVidia GLX libraries:
</p>

<pre caption="Running opengl-update">
# <i>opengl-update nvidia</i>
</pre>

</body>
</section>
<section>
<title>Adding your Users to the video Group</title>
<body>

<p>
You have to add your user to the <c>video</c> group so he has access to the
nvidia device files:
</p>

<pre caption="Adding your user to the video group">
# <i>gpasswd -a youruser video</i>
</pre>

<p>
This might not be totally necessary if you aren't using <c>udev</c> but it
doesn't hurt either and makes your system future-proof :)
</p>

</body>
</section>
<section>
<title>Testing your Card</title>
<body>

<p>
To test your nVidia card, fire up X and run the <c>glxinfo | grep direct</c>
command. It should say that direct rendering is activated:
</p>

<pre caption="Checking the direct rendering status">
$ <i>glxinfo | grep direct</i>
direct rendering: Yes
</pre>

<p>
To monitor your FPS, run <c>glxgears</c>.
</p>

</body>
</section>
<section>
<title>Enabling nvidia Support</title>
<body>

<p>
Some tools, such as <c>mplayer</c> and <c>xine-lib</c>, use a local USE flag
called "nvidia" which enables XvMCNVIDIA support, useful when watching high
resolution movies. Add in "nvidia" in your USE variable in
<path>/etc/make.conf</path> or add it as USE flag to <c>media-video/mplayer</c>
and/or <c>media-libs/xine-lib</c> in <path>/etc/portage/package.use</path>.
</p>

<p>
Then, run <c>emerge -uD --newuse world</c> to rebuild the applications that
benefit from the USE flag change.
</p>

</body>
</section>
<section>
<title>Using NVidia Settings Tool</title>
<body>

<p>
Since NVidia released version 1.0.6106 it also provides you with a settings
tool. This tool allows you to change graphical settings without restarting the X
server and is available through Portage as <c>media-video/nvidia-settings</c>.
</p>

</body>
</section>
</chapter>

<chapter>
<title>Troubleshooting</title>
<section>
<title>Getting 2D to work on machines with 4Gb or more memory</title>
<body>

<p>
If you are having troubles with the nVidia 2D acceleration it is likely that you
are unable to set up a write-combining range with MTRR. To verify, check the
contents of <path>/proc/mtrr</path>:
</p>

<pre caption="Checking if you have write-combining enabled">
# <i>cat /proc/mtrr</i>
</pre>

<p>
Every line should contain "write-back" or "write-combining". If you see a line
with "uncachable" in it you will need to change a BIOS setting to fix this.
</p>

<p>
Reboot and enter the BIOS, then find the MTRR settings (probably under "CPU
Settings"). Change the setting from "continuous" to "discrete" and boot back
into Linux. You will now find out that there is no "uncachable" entry anymore
and 2D acceleration now works without any glitches.
</p>

</body>
</section>
<section>
<title>I receive warnings about unsupported 4K stack sizes</title>
<body>

<p>
<c>nvidia-kernel</c> packages older than 1.0.6106 only support kernels using an
8K stack size. More recent kernels (2.6.6 and higher) have support for 4K stack
size's as well. Do not select 4K stack size in your kernel configuration if you
are using such an <c>nvidia-kernel</c> package. You can find this option in the
section <c>Kernel Hacking</c>.
</p>

</body>
</section>
<section>
<title>
  When I attempt to load the kernel module I receive a "no such device"
</title>
<body>

<p>
This usually occurs when you don't have a matching video card. Make sure that
you have an nVidia-powered graphical card (you can double-check this using
<c>lspci</c>).
</p>

<p>
If you are confident that you have an nVidia card, check your BIOS and see if
the directive <e>Assign IRQ to VGA</e> is set.
</p>

</body>
</section>
<section>
<title>
  I get "no screens found" and the logs state "Failed to initialize the NVIDIA 
  kernel module!"
</title>
<body>

<p>
You're most likely missing the <path>/dev/nvidia*</path> device files. Create
them using <c>NVmakedevices.sh</c>:
</p>

<pre caption="Creating the nvidia device drivers">
# <i>/sbin/NVmakedevices.sh</i>
</pre>

</body>
</section>
</chapter>

<chapter>
<title>Expert Configuration</title>
<section>
<title>Documentation</title>
<body>

<p>
The nVidia driver package also comes with comprehensive documentation. This is
installed into <c>/usr/share/doc</c> and can be viewed with the following
command:
</p>

<pre caption="Viewing the NVIDIA documentation">
# <i>less /usr/share/doc/nvidia-glx-*/README.txt.gz</i>
</pre>

</body>
</section>
<section>
<title>Kernel module parameters</title>
<body>

<p>
The <c>nvidia</c> kernel module accepts a number of parameters (options) which
you can use to tweak the behaviour of the driver. Most of these are mentioned in
the documentation. To add or change the values of these parameters, edit the
file <c>/etc/modules.d/nvidia</c>. Remember to run <c>modules-update</c> after
modifying this file, and bear in mind that you will need to reload the
<c>nvidia</c> module before the new settings take effect.
</p>

<pre caption="Adjusting nvidia options">
<comment>(Edit /etc/modules.d/nvidia in your favourite editor)</comment>
# <i>nano -w /etc/modules.d/nvidia</i>
<comment>(Update module information)</comment>
# <i>modules-update</i>
<comment>(Unload the nvidia module...)</comment>
# <i>modprobe -r nvidia</i>
<comment>(...and load it once again)</comment>
# <i>modprobe nvidia</i>
</pre>

</body>
</section>
<section>
<title>Advanced X configuration</title>
<body>

<p>
The GLX layer also has a plethora of options which can be configured. These
control the configuration of TV out, dual displays, monitor frequency detection,
etc. Again, all of the available options are detailed in the documentation.
</p>

<p>
If you wish to use any of these options, you need to list them in the relevant
Device section of your X config file (usually <c>/etc/X11/xorg.conf</c>). For
example, suppose I wanted to disable the splash logo:
</p>

<pre caption="Advanced nvidia configuration in the X configuration">
Section "Device"
  Identifier "nVidia Inc. GeForce2"
  Driver     "nvidia"
  <i>Option     "NoLogo" "true"</i>
  VideoRam   65536
EndSection
</pre>

</body>
</section>
</chapter>

</guide>
