<?xml version='1.0' encoding="UTF-8"?>
<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/nvidia-guide.xml,v 1.52 2012/07/24 12:12:51 swift Exp $ -->
<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">

<guide>
<title>Gentoo Linux nVidia Guide</title>

<author title="Author">
  <mail link="swift@gentoo.org">Sven Vermeulen</mail>
</author>
<author title="Author">
  <mail link="nightmorph@gentoo.org">Joshua Saddler</mail>
</author>
<author title="Editor">
  <mail link="curtis119@gentoo.org">M Curtis Napier</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>3</version>
<date>2012-07-24</date>

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

<p>
The nVidia drivers in the tree are released by nVidia and are built against the
Linux kernel. They contain a binary blob that does the heavy lifting for talking
to the card. The drivers consist of two parts, a kernel module, and an X11
driver. Both parts are included in a single package. Due to the way nVidia has
been packaging their drivers, you will need to make some choices before you
install the drivers.
</p>

<p>
The <c>nvidia-drivers</c> package contains the latest drivers from nVidia with
support for <e>all</e> cards, with several versions available depending on how
old your card is. It uses an eclass to detect what kind of card you're running
so that it installs the proper version.
</p>

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

<chapter>
<title>Driver compatibility</title>
<section>
<title>Which version?</title>
<body>

<p>
The <c>nvidia-drivers</c> package supports the full range of available nVidia
cards. Multiple versions are available for installation, depending on the
card(s) you have.
</p>

<p>
Newer cards such as the GeForce 400, 300, 200, 100, 9, 8, 7, and 6 series should
use the latest drivers.
</p>

<p>
Older cards such as the GeForce FX 5 series should use the 173.x drivers, such
as <c>nvidia-drivers-173.14.15</c>. For these cards, you should mask
<c>>=x11-drivers/nvidia-drivers-174.00</c> in your
<path>/etc/portage/package.mask</path> file. This will prevent newer versions of
the driver which are incompatible with your card from being installed.
</p>

<p>
Old cards such as the GeForce 3 or GeForce 4 series require the 96.x drivers.
For these cards, you should mask <c>>=x11-drivers/nvidia-drivers-97.00</c> in
your <path>/etc/portage/package.mask</path> file.
</p>

<p>
The oldest NV2x-based cards (such as TNT, TNT2, GeForce, and GeForce 2) are no
longer supported by <c>nvidia-drivers</c>. Instead, use an open-source driver:
<c>xf86-video-nouveau</c> (recommended) or <c>xf86-video-nv</c> (old,
deprecated).
</p>

<p>
You can check for driver compatibility for your card at to determine which
driver supports it by viewing the README at its appropriate x86 or x86-64
<uri link="http://www.nvidia.com/object/unix.html">release page</uri>.
</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 all</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 --->
Graphics Support --->
-*- /dev/agpgart (AGP Support) --->
</pre> 

<note>
On amd64, the IOMMU controls the agpgart setting.
</note>

</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 --->
Graphics Support --->
&lt;*&gt; Support for frame buffer devices --->
&lt; &gt;   nVidia Framebuffer Support
&lt; &gt;   nVidia Riva support
</pre>

<p>
A framebuffer alternative is <c>uvesafb</c>, an <uri
link="http://dev.gentoo.org/~spock/projects/uvesafb/">advanced
framebuffer</uri>. Note that you can choose to compile it into your kernel, or
as a module. The following example compiles uvesafb into the kernel.
</p>

<pre caption="Enable uvesafb support">
Device Drivers --->
Graphics Support --->
&lt;*&gt; Support for frame buffer devices --->
&lt;*&gt;   Userspace VESA VGA graphics support
</pre>


<p>
Or you can try <c>VESA</c>:
</p>

<pre caption="Enable VESA support">
Device Drivers --->
Graphics Support --->
&lt;*&gt; Support for frame buffer devices --->
[*]   VESA VGA graphics support
</pre>


<p>
For more information, you can look up the documentation for your chosen
framebuffer in <path>/usr/src/linux/Documentation/fb/</path>.
</p>

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

<p>
The <c>nvidia-drivers</c> ebuild automatically 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>
First, you'll need to choose the right kernel source using <c>eselect</c>. If
you are using <c>gentoo-sources-2.6.34-r1</c>, your kernel listing might look
something like this:
</p>

<pre caption="Check your /usr/src/linux symlink">
# <i>eselect kernel list</i>
Available kernel symlink targets:
  [1]   linux-2.6.34-gentoo-r1 *
  [2]   linux-2.6.33-gentoo-r2
  [3]   linux-2.6.32.9
<comment>(Verify that the right kernel is marked with an asterisk</comment>
</pre>

<p>
In the above output, you'll notice that the <c>linux-2.6.34-gentoo-r1</c> kernel
is marked with an asterisk (<b>*</b>) to show that it is the symlinked kernel.
</p>

<p>
If the symlink is not pointing to the correct sources, you must update the link
by selecting the number of your desired kernel sources, as in the example
above.
</p>

<pre caption="Create/Update /usr/src/linux symlink">
<comment>(Select the correct kernel)</comment>
# <i>eselect kernel set 1</i>
</pre>

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

<p>
Now it's time to install the drivers. You can do this by first following the
<uri link="/doc/en/xorg-config.xml">X Server Configuration HOWTO</uri> and
setting <c>VIDEO_CARDS="nvidia"</c> in <path>/etc/portage/make.conf</path>. When you
install the X server, it will then install the right version of
<c>nvidia-drivers</c> for you.
</p>

<note>
The drivers can be installed with the <c>gtk</c> USE flag set in
<path>/etc/portage/make.conf</path>. This will install
<c>media-video/nvidia-settings</c>, a handy graphical tool for monitoring and
configuring several aspects of your nVidia card.
</note>

<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 reinstall the nVidia kernel
modules. An easy way to keep track of modules installed by ebuilds (such as
<c>nvidia-drivers</c>) is to install <c>sys-kernel/module-rebuild</c>. Once
you've installed it, simply run <c>module-rebuild populate</c> to populate its
database with a list of packages to be rebuilt. Once you've finished compiling
or recompiling a kernel, just run <c>module-rebuild rebuild</c> to rebuild the
drivers for your new kernel.
</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/conf.d/modules</path> and add <c>nvidia</c> to it.
</p>

<impo>
If you compiled <c>agpgart</c> as a module, you will need to add it to
<path>/etc/conf.d/modules</path> as well.
</impo>

</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 <c>glxinfo</c>, which is part of the
<c>mesa-progs</c> package. 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 <c>xvmc</c> which enables XvMCNVIDIA support, useful when watching high
resolution movies. Add in <c>xvmc</c> in your USE variable in
<path>/etc/portage/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>
There are also some applications that use the <c>nvidia</c> USE flag, so you
may want to add it to <path>/etc/portage/make.conf</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>
nVidia also provides you with a settings tool. This tool allows you to monitor
and change graphical settings without restarting the X server and is available
through Portage as <c>media-video/nvidia-settings</c>. As mentioned earlier, it
will be pulled in automatically if you install the drivers with the <c>gtk</c>
USE flag set in <path>/etc/portage/make.conf</path> or in
<path>/etc/portage/package.use</path>.
</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">
$ <i>less /usr/share/doc/nvidia-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/modprobe.d/nvidia.conf</c>. Remember to run <c>update-modules</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/modprobe.d/nvidia.conf in your favourite editor)</comment>
# <i>nano -w /etc/modprobe.d/nvidia.conf</i>
<comment>(Update module information)</comment>
# <i>update-modules</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>
