NVIDIA/nvidia-drivers/zh-cn

Article description::The package contains the proprietary graphics driver for NVIDIA graphic cards. An open source alternative is nouveau.

This proprietary driver contains some wrapper functions that will compile against the Linux kernel and a binary blob that does the heavy lifting for talking to the card. The driver consists of two parts: a kernel module and an X11 driver. Both parts are included in a single package. Due to the way the drivers are packaged, it is necessary to make some choices before installing the drivers.

The package contains the latest drivers from NVIDIA with support for most NVIDIA graphic cards, with several versions available depending on the age of the card. It uses an eclass to detect what kind of card the system is running so that it installs the proper version.

硬件兼容性
The package supports a range of available NVIDIA cards. Multiple versions are available for installation, depending on the card(s) that the system has. See the official NVIDIA documentation, What's a legacy driver?, to find out what version of should be used. A pretty decent way to find this out through an interactive form. Enter the graphics card that is used by the system (mind the Legacy option in the 'Product Type' field) and the form should end up with the best supported version.

If the card has been identified as a legacy card then mask the more recent releases of, i.e

Note that Gentoo does not provide the 71.86.xx versions. If the system has a card that needs these drivers then it is recommended to use the nouveau driver.

内核
如上所述，NVIDIA内核驱动程序安装并运行对当前内核. 它作为模块建立，所以内核必须支持的内核模块的加载（见下文）.

内核模块 由一个专有部分(通常称为“二进制blob)驱动图形芯片,和一个开源部分(“glue”),在运行时作为专有部分和内核之间的媒介. 这些都需要很好地协同工作,否则用户可能面临数据丢失(通过内核panics, X servers崩溃伴随着未保存数据X的应用程序),甚至是硬件故障(应该想到过热和其他电源管理相关问题).

内核兼容性
不时地，一个新的内核版本改变了内部ABI的驱动程序，这意味着所有使用这些ABI的驱动程序必须相应地改变. 对于开源驱动，尤其是那些随内核，这些变化几乎是可以微不足道的修复，因为驱动程序与内核的其他部分之间的调用整个链条可以很容易地修正. 对于专有的驱动程序nvidia.ko，这是行不通的. 当内部的ABI改变，那么就不可能仅仅修复“glue”，因为没有人知道如何glue所使用的专有的那一部分是很忙. 即使设法修补东西似乎很好地工作,用户仍然存在运行nvidia的风险. 在新的，不支持的内核nvidia.ko运行会导致数据丢失，硬件故障.

当一个新的，不兼容的内核版本发布时，它可能是最好坚持使用最新支持的内核了一段时间. NVIDIA公司通常需要几个星期的时间准备新的专有版本，他们认为适合用于一般用途. 耐心一点. 如果绝对必要，那么就可以使用epatch_user命令和NVIDIA驱动的ebuild：这允许用户打补丁的NVIDIA驱动程序以某种方式适应了最新的，不支持的内核版本. 请注意，即使是NVIDIA驱动维护者，也不NVIDIA将支持这一情况. 硬件保修将最有可能是无效的，Gentoo的维护者不能解决问题，因为它是一个专有的驱动程序，只有NVIDIA官方能够正确调试，内核维护者（包括Gentoo和上游）肯定不会支持专有的驱动程序，或任何“污点“系统，当碰巧遇到麻烦时.

如果  是用于配置内核,那么一切都准备好了. 如果不是,仔细检查内核配置,启用以下支持:

在内核中也开启“Memory Type Range Register（内存类型范围寄存器）”:

If the system has an AGP graphics card, then optionally enable agpgart support to the kernel, either compiled in or as a module. If the in-kernel agpgart module is not used, then the drivers will use its own agpgart implementation, called NvAGP. On certain systems, this performs better than the in-kernel agpgart, and on others, it performs worse. Evaluate either choice on the system to get the best performance. When uncertain what to do, use the in-kernel agpgart:

A framebuffer alternative is uvesafb, which can be installed parallel to.

For (U)EFI systems, uvesafb will not work. Be warned that enabling efifb support in kernel causes intermittent problems with the initialization of the NVIDIA drivers. There is no known alternative framebuffer for (U)EFI systems.

The nvidia-drivers ebuild automatically discovers the kernel version based on the symlink. Please ensure that this symlink is pointing to the correct sources and that the kernel is correctly configured. Please refer to the "Configuring the Kernel" section of the Gentoo Handbook for details on configuring the kernel.

First, choose the right kernel source using. When using version 3.7.10 for instance, the kernel listing might look something like this:

In the above output, notice that the linux-3.7.10-gentoo kernel is marked with an asterisk to show that it is the kernel that the symbolic link points to.

If the symlink is not pointing to the correct sources, update the link by selecting the number of the desired kernel sources, as in the example above.

驱动
Now it's time to install the drivers. First follow the X Server Configuration Guide and set  in. During the installation of the X server, it will then install the right version of.

Once the installation has finished, run to load the kernel module into memory. If this is an upgrade, remove the previous module first.

To prevent from having to manually load the module on every bootup, have this done automatically each time the system is booted, so edit and add   to it.

Kernel module signing (optional)
If secure boot kernel signing is used, then the NVIDIA kernel modules need to be signed before they can be loaded.

This can be accomplished by using the kernel-provided script as follows.

As of driver version 358.09 a new module has been made to handle monitor mode setting and for this driver version this module must also be signed.

Once the modules are signed, the driver will load as expected on boot up. This module signing method can be used to sign other modules too - not only the nvidia-drivers. Just modify the path and corresponding module accordingly.

The X server
Once the appropriate drivers are installed, configure the X server to use the  driver instead of the default   driver.

Run so that the X server uses the NVIDIA GLX libraries:

Enabling global nvidia support
Some tools, such as and, use a local USE flag called   which enables XvMCNVIDIA support, useful when watching high resolution movies. Add in  in the USE variable in  or add it as USE flag to  and/or  in.

GeForce 8 series and later GPUs do come with VDPAU support which superseded XvMCNVIDIA support. See the VDPAU article for enabling VDPAU support.

There are also some applications that use the  USE flag, so it might be a good idea to add it to.

Then, run to rebuild the applications that benefit from the USE flag change.

Using the nVidia settings tool
NVIDIA also provides a settings tool. This tool allows the user to monitor and change graphical settings without restarting the X server and is available through Portage as part of with the   USE flag set.

开启 OpenGL/OpenCL
To enable OpenGL and OpenCL though the device, run:

Make sure that the Xorg server is not running during these changes.

测试显卡
To test the NVIDIA card, fire up X and run, which is part of the package. It should say that direct rendering is activated:

要监视 FPS值，运行.

故障解决
For an overview of the currently open bugs reported against the package, take a look at the.

FATAL: modpost: GPL-incompatible module *.ko uses GPL-only symbol
When the ebuild is complaining about the 'mutex_destroy' GPL-only symbol:

Be sure to disable CONFIG_DEBUG_MUTEXES in the kernel's file, as suggested by this forum thread.

当启用MSI中断，驱动程序初始化失败
Linux的NVIDIA驱动程序使用消息信号中断（MSI）在默认情况下. 这提供了兼容性和可扩展性优势，主要是由于避免IRQ共享. 有些系统存在微星的支持问题，工作时virtual wire经常中断. 这些问题表现为NVIDIA驱动程序无法启动X，或CUDA初始化失败.

MSI interrupts can be disabled via the NVIDIA kernel module parameter. This can be set on the command line when loading the module, or more appropriately via the distribution's kernel module configuration files (such as those under ).

例如：

在4GB内存或更大内存的机器上获得2D加速支持
When NVIDIA 2D acceleration is giving problems, then it is likely that the system is unable to set up a write-combining range with MTRR. To verify, check the contents of :

Every line should contain  or. When a line shows up with  in it then it is necessary to change a BIOS setting to fix this.

Reboot and enter the BIOS, then find the MTRR settings (probably under "CPU Settings"). Change the setting from  to   and boot back into Linux. There is now no  entry anymore and 2D acceleration now works without any glitches.

当试图加载内核模块出现"no such device"
这通常是由于以下问题之一引起的:


 * 1) The system does not have a NVIDIA card at all.  Check  output to confirm that the system has a NVIDIA graphics card installed and detected.
 * 2) The currently installed version of  does not support the installed graphics card model.  Check the README file in /usr/share/nvidia-drivers-*/ for a list of supported devices, or use the driver search at http://www.geforce.com/drivers.
 * 3) Another kernel driver has control of the hardware. Check  to see if another driver like "nouveau" is bound to the graphics card. If so, disable or blacklist this driver.

Xorg 说它找不到任何显示器
When after booting the system, it ends up with a black screen or a console prompt instead of the GUI; then press ++ to bring up a virtual console. Next, run:

看看Xorg的输出. 如果第一个错误是Xorg不能找到任何显示屏幕,那么按照下面的步骤来解决问题.

这应该足够在重新启动前，运行下面的命令：

But if that doesn't work, run and notice that the video card starts off like this:

Take the first bit,  and put it in the  file with the   option:

直接渲染未启用
If direct rendering does not work, it may be because the kernel has Direct Rendering Manager enabled, which conflicts with the driver. See the direct rendering status by following instructions in the section Testing the card.

First, disable Direct Rendering Manager in the kernel :

Next, rebuild since the driver may have built against the kernel DRM symbols. It should fix the problem.

视频播放不流畅或缓慢
最近似乎有一些重大的在播放某些类型的NVIDIA二进制驱动的视频，引起慢速视频播放或显著卡顿. 这个问题似乎在英特尔 CPU 空闲更换为某些 CPU 而不是常见的 ACPI CPU 减速规造成的.

Disable the Intel CPU idling method using  on the kernel command line boot method, which should cause the kernel to automatically fall back to the normal or older ACPI CPU idling method. Also, disabling the NVIDIA Powermizer feature, or setting Powermizer to maximum performance within has been said to help. Although the Intel CPU idling method recently was introduced as the default CPU idling method for i5 and i7 CPUs (versus using ACPI CPU idling) is the root cause here. This idling method significantly solves the problem, however some minimal stuttering or slow video is encountered if deinterlacing was enabled; this is when the video is likely already deinterlaced (ie. alias  with something similar to   as a work around.)

No vertical synchronization (no VSync, tearing) in OpenGL applications
Adding the following option to the screen section prevents tearing on GTX 660, 660 Ti, and probably some other GPUs (reference):

文档
The package also comes with comprehensive documentation. This is installed into and can be viewed with the following command:

内核模块参数
The  kernel module accepts a number of parameters (options) which can be used to tweak the behavior of the driver. Most of these are mentioned in the documentation. To add or change the values of these parameters, edit the file. Remember to run after modifying this file, and bear in mind to reload the   module before the new settings take effect.

Edit the file, and afterwards update the module information:

Unload the  module...

…然后加载它再一次:

高级 X 配置
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.

To use any of these options, list them in the relevant Device section of the X config file (usually ). For example, to disable the splash logo:

参考

 * nouveau & nvidia-drivers switching - Hybrid图形模式使用开源驱动.
 * NVIDIA Optimus - 配置系统以使用Hybrid图形的封闭源驱动程序（模式设置）.