<?xml version='1.0' encoding="UTF-8"?>
<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/nvidia-guide.xml,v 1.34 2006/11/28 20:01:21 nightmorph 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="sven.vermeulen@siphos.be">Sven Vermeulen</mail>
</author>
<author title="Editor">
  <mail link="curtis119@gentoo.org">M Curtis Napier</mail>
</author>
<author title="Editor">
  <mail link="nightmorph@gentoo.org">Joshua Saddler</mail>
</author>
<author title="Editor">
  <mail link="wolf31o2@gentoo.org">Chris Gianelloni</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.29</version>
<date>2006-11-28</date>

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

<p>
nVidia release their own Linux drivers which provide good performance and full
3D acceleration. There are two drivers in Portage. <c>nvidia-drivers</c> is for
newer nVidia graphics cards, while <c>nvidia-legacy-drivers</c> supports older
cards.
</p>

<note>
Previously, Gentoo provided separate ebuilds for the nVidia kernel module
(<c>nvidia-kernel</c>) and the X11 GLX libraries (<c>nvidia-glx</c>). These
ebuilds have since been removed from the Portage tree in favor of
<c>nvidia-drivers</c> and <c>nvidia-legacy-drivers</c>. If you use
<c>nvidia-kernel</c> and <c>nvidia-glx</c>, then you should migrate to the
newer packages.
</note>

</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> Also, if you have an AGP graphics card, you can optionally enable
<c>agpgart</c> support to your kernel, either compiled in or as a module. If
you do not use the in-kernel agpgart, then the drivers will use their own
<c>agpgart</c> implementation, called <c>NvAGP</c>.  On certain systems, this
performs better than the in-kernel agpgart, and on others, it performs worse.
You will need to evaluate this on your own system to get the best performance.
If you are unsure what to do, use the in-kernel agpgart:
</p>

<pre caption="Enabling agpgart">
Device Drivers ---&gt;
Character devices ---&gt;
&lt;*&gt; /dev/agpgart (AGP Support)
</pre> 

</body>
</section>
<section>
<title>Arch-specific notes</title>
<body>

<impo>
For x86 and AMD64 processors, the in-kernel driver conflicts with the binary
driver provided by nVidia. If you will be compiling your kernel for these CPUs,
you must completely remove support for the in-kernel driver as shown:
</impo>

<pre caption="Remove the in-kernel driver">
Device Drivers ---&gt;
Graphics Support ---&gt;
&lt; &gt;   nVidia Framebuffer Support
&lt; &gt;   nVidia Riva support
</pre>

<p>
A good framebuffer alternative is <c>VESA</c>:
</p>

<pre caption="Enable VESA support">
Device Drivers ---&gt; 
Graphics Support ---&gt;
&lt;*&gt;   VESA VGA graphics support
</pre>

<p>
Then, under "VESA driver type" select either <c>vesafb</c> or
<c>vesafb-tng</c>. If you are using an AMD64 processor, you should select
<c>vesafb</c> rather than <c>vesafb-tng</c>:
</p>

<pre caption="Select framebuffer type">
(X) vesafb
( ) vesafb-tng
</pre>

<p>
For more information, you can read up
<path>/usr/src/linux/Documentation/fb/vesafb.txt</path> if you are using
<c>vesafb</c> or look for your framebuffer documentation under
<path>/usr/src/linux/Documentation/fb/</path>.
</p>

</body>
</section>
<section>
<title>Continuing with Kernel Configuration</title>
<body>

<p>
The <c>nvidia-drivers</c> and <c>nvidia-legacy-drivers</c> ebuilds
automatically discover 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-drivers</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 your card is listed in the legacy list, then you will be required to install
the <c>nvidia-legacy-drivers</c> package to get 3D support.
</p>

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

<p>
Now it's time to install the drivers.
</p>

<pre caption="Installing the nVidia drivers">
<comment>(If you have a card not listed in the legacy list above)</comment>
# <i>emerge nvidia-drivers</i>
<comment>(If your card is listed in the legacy list)</comment>
# <i>emerge nvidia-legacy-drivers</i>
</pre>

<impo>
Every time you <uri link="/doc/en/kernel-upgrade.xml">compile a new
kernel</uri> or recompile the current one, you will need to run <c>emerge
nvidia-drivers</c> or <c>emerge nvidia-legacy-drivers</c> to reinstall the
nVidia modules.
</impo>

<p>
Once the installation has finished, run <c>modprobe nvidia</c> to load the
kernel module into memory. If this is an upgrade, you should remove the
previous module first.
</p>

<pre caption="Loading the kernel module">
# <i>lsmod | grep nvidia &amp;&amp; rmmod nvidia</i>
# <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>

<impo>
If you compiled <c>agpgart</c> as a module, you will need to add it to
<path>/etc/modules.autoload.d/kernel-2.6</path> (or <path>kernel-2.4</path>
depending on your kernel version).
</impo>

<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
to use the <c>nvidia</c> driver instead of the default <c>nv</c> driver.
</p>

<p>
Open <path>/etc/X11/xorg.conf</path> 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>eselect</c> so that the X Server uses the nVidia GLX libraries:
</p>

<pre caption="Running eselect">
# <i>eselect opengl set 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>
  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>
</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">
<comment>(for nvidia-drivers)</comment>
$ <i>less /usr/share/doc/nvidia-drivers-*/README.gz</i>
<comment>(for nvidia-legacy-drivers)</comment>
$ <i>less /usr/share/doc/nvidia-legacy-drivers-*/README.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>
