/usr/share/jockey/handlers/nvidia.py is in jockey-common 0.9.7-0ubuntu7.16.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | # (c) 2008 Canonical Ltd.
# Authors: Martin Pitt <martin.pitt@ubuntu.com>
# Alberto Milone <alberto.milone@canonical.com>
# License: GPL v2 or later
import logging, os, os.path
from jockey.handlers import KernelModuleHandler
from jockey.xorg_driver import XorgDriverHandler
from jockey.oslib import OSLib
import XKit
from NvidiaDetector.nvidiadetector import NvidiaDetection
from NvidiaDetector.alternatives import Alternatives
from NvidiaDetector.alternatives import MultiArchUtils
import subprocess
# dummy stub for xgettext
def _(x): return x
class _NvidiaDriverBase(XorgDriverHandler):
'''Abstract base class for a particular NVidia driver version.'''
def __init__(self, backend, version):
self._free = False
name=_('NVIDIA accelerated graphics driver')
description=_('3D-accelerated proprietary graphics driver for '
'NVIDIA cards. Required if you want to run Unity.')
rationale=_('This driver is required to fully utilise '
'the 3D potential of NVIDIA graphics cards, as well as provide '
'2D acceleration of newer cards.\n\n'
'You need to install this driver if you wish to use the Unity '
'desktop, enable desktop effects, or run software that '
'requires 3D acceleration, such as some games.')
if 'update' in version:
name=_('NVIDIA accelerated graphics driver (post-release updates)')
elif 'experimental' in version:
name=_('NVIDIA accelerated graphics driver (**experimental** beta)')
description = None
rationale = None
XorgDriverHandler.__init__(self, backend, 'nvidia_' + version.replace('-', '_'),
'nvidia-' + version,
None, None, {'NoLogo': 'True'},
remove_modules=['dri', 'GLcore'],
name=name,
description=description,
rationale=rationale)
self._module_alias = 'nvidia'
self._recommended = None
self._do_rebind = False
(self._alternatives, self._other_alternatives) = self._get_alternatives()
self.version = version
self.needs_kernel_headers = True
def _get_alternatives(self):
'''Get multi-arch alternatives names'''
arch_utils = MultiArchUtils()
main_name = arch_utils.get_main_alternative_name()
other_name = arch_utils.get_other_alternative_name()
return Alternatives(main_name), Alternatives(other_name)
def available(self):
# we don't offer this driver in a life CD environment, as we will run
# out of RAM trying to download and install all the packages in the RAM
# disk.
if os.path.isdir('/rofs'):
logging.debug('Disabling Nvidia driver on live system')
return False
if self.has_hybrid_graphics:
# We disable Hybrid Graphics by default unless a specific
# driver allows it
logging.debug('Disabling nvidia-%s on a hybrid graphics system' % (self.version))
return False
logging.debug('nvidia.available: falling back to default')
return XorgDriverHandler.available(self)
def enable_config_hook(self):
# make sure that RGB path is not in the xorg.conf otherwise xorg will crash
it = 0
for section in self.xorg_conf.globaldict['Files']:
try:
self.xorg_conf.removeOption('Files', 'RgbPath', position=it)
except (XKit.xorgparser.OptionException):
pass
it += 1
# remove any Disable "dri2" otherwise nvidia-settings and nvidia-xconfig will fail
module_sections = self.xorg_conf.globaldict['Module']
have_modules = len(module_sections) > 0
if have_modules:
for section in module_sections:
self.xorg_conf.removeOption('Module', 'Disable', value='dri2', position=section)
def enable(self):
if self.has_hybrid_graphics:
# Do not touch xorg.conf on hybrid graphics
KernelModuleHandler.enable(self)
else:
XorgDriverHandler.enable(self)
# Set the alternative to NVIDIA
nvidia_alternative = self._alternatives.get_alternative_by_name(self.package)
if not nvidia_alternative:
logging.error('%s: get_alternative_by_name(%s) returned nothing' % (
self.id(), self.package))
return
self._alternatives.set_alternative(nvidia_alternative)
other_nvidia_alternative = self._other_alternatives.get_alternative_by_name(self.package)
self._other_alternatives.set_alternative(other_nvidia_alternative)
subprocess.call(['update-initramfs', '-u'])
subprocess.call(['update-initramfs', '-u', '-k', os.uname()[2]])
def disable(self):
if self.has_hybrid_graphics:
# Do not touch xorg.conf on hybrid graphics
KernelModuleHandler.disable(self)
else:
XorgDriverHandler.disable(self)
if self.package:
try:
self.backend.remove_package('nvidia-settings-' + self.version)
except (ValueError, SystemError):
pass
# Set the alternative back to open drivers
open_drivers = self._alternatives.get_open_drivers_alternative()
logging.debug('NVidia.disable(%s): open_drivers: %s', self.module, open_drivers)
if open_drivers:
self._alternatives.set_alternative(open_drivers)
other_open_drivers = self._other_alternatives.get_open_drivers_alternative()
logging.debug('NVidia.disable(%s): other_open_drivers: %s', self.module, other_open_drivers)
if other_open_drivers:
self._other_alternatives.set_alternative(other_open_drivers)
subprocess.call(['update-initramfs', '-u'])
subprocess.call(['update-initramfs', '-u', '-k', os.uname()[2]])
return False
def recommended(self):
if self._recommended == None:
nd = NvidiaDetection()
self._recommended = self.package == nd.selectDriver()
return self._recommended
def enabled(self):
# See if nvidia (e.g. nvidia-current) is the current alternative
target_alternative = self._alternatives.get_alternative_by_name(self.package)
current_alternative = self._alternatives.get_current_alternative()
other_target_alternative = self._other_alternatives.get_alternative_by_name(self.package)
other_current_alternative = self._other_alternatives.get_current_alternative()
logging.debug('NVidia(%s).enabled(): target_alt %s current_alt %s other target alt %s other current alt %s',
self.module, target_alternative, current_alternative,
other_target_alternative, other_current_alternative)
if current_alternative is None:
return False
if current_alternative != target_alternative or \
other_current_alternative != other_target_alternative:
logging.debug('%s is not the alternative in use', self.module)
return False
#if self.xorg_conf has NoneType, AttributeError will be raised
if not self.xorg_conf:
logging.debug('%s: xkit object does not exist!', self.module)
return False
# Make sure that neither the alias nor the actual module are blacklisted
if OSLib.inst.module_blacklisted(self._module_alias) or OSLib.inst.module_blacklisted(self.module):
logging.debug('%s is blacklisted, so not treating as enabled', self.module)
return False
kmh_enabled = KernelModuleHandler.enabled(self)
logging.debug('KMH enabled: %s', str(kmh_enabled))
return KernelModuleHandler.enabled(self)
def used(self):
'''Return if the handler is currently in use.'''
if self.changed() and self.enabled():
return False
# See if "nvidia" is loaded and if the alias corresponds to nvidia_$flavour
return KernelModuleHandler.module_loaded(self._module_alias) and \
self._alternatives.resolve_module_alias(self._module_alias) == self.module and \
(self.package is None or OSLib.inst.package_installed(self.package))
def enables_composite(self):
'''Return whether this driver supports the composite extension.'''
# When using an upstream installation, or -new/-legacy etc., we already
# have composite
if KernelModuleHandler.module_loaded('nvidia'):
logging.debug('enables_composite(): already using nvidia driver from nondefault package')
return False
# neither vesa nor nv support composite, so safe to say yes here
return True
class _NvidiaDriverHybridBase(_NvidiaDriverBase):
'''Abstract base class for NVidia drivers which support Hybrid graphics.'''
def __init__(self, backend, version):
_NvidiaDriverBase.__init__(self, backend, version)
self.hybrid_gfx_pkg = 'nvidia-prime'
def hybrid_available(self):
'''See if the OS supports Hybrid Graphics'''
# Do not provide a driver if Hybrid graphics is available but
# unsupported (we need at least the lts-raring stack)
if not self.supports_hybrid_graphics:
logging.debug('Hybrid graphics system not supported by the OS')
return False
# Check that the extra package to enable Hybrid graphics is available
if not OSLib.inst.package_available(self.hybrid_gfx_pkg):
logging.debug('prime package not found')
return False
return True
def available(self):
# we don't offer this driver in a life CD environment, as we will run
# out of RAM trying to download and install all the packages in the RAM
# disk.
if os.path.isdir('/rofs'):
logging.debug('Disabling Nvidia driver on live system')
return False
# See if it's all ready for Hybrid Graphics
if self.has_hybrid_graphics and not self.hybrid_available():
return False
logging.debug('nvidia.available: falling back to default')
return XorgDriverHandler.available(self)
def enable(self):
# First ensure that the package for Hybrid Graphics is
# installed, if the system supports it
if self.has_hybrid_graphics:
try:
self.backend.install_package(self.hybrid_gfx_pkg)
except (ValueError, SystemError):
# Package not available
logging.error('%s: Unable to install the %s package. '
'Hybrid graphics won\'t work.',
self.id(), self.hybrid_gfx_pkg)
return
_NvidiaDriverBase.enable(self)
def enabled(self):
# Check that the extra package to enable Hybrid graphics is
# installed
if (self.has_hybrid_graphics and
not OSLib.inst.package_installed(self.hybrid_gfx_pkg)):
return False
return _NvidiaDriverBase.enabled(self)
def enable_config_hook(self):
# Do not touch xorg.conf
pass
def disable(self):
# Try to remove the package for Hybrid Graphics if any
if self.has_hybrid_graphics:
try:
self.backend.remove_package(self.hybrid_gfx_pkg)
except (ValueError, SystemError):
pass
_NvidiaDriverBase.disable(self)
class NvidiaDriver340(_NvidiaDriverHybridBase):
def __init__(self, backend):
_NvidiaDriverHybridBase.__init__(self, backend, '340')
class NvidiaDriver340Updates(_NvidiaDriverHybridBase):
def __init__(self, backend):
_NvidiaDriverHybridBase.__init__(self, backend, '340-updates')
class NvidiaDriver331(_NvidiaDriverHybridBase):
def __init__(self, backend):
_NvidiaDriverHybridBase.__init__(self, backend, '331')
class NvidiaDriver331Updates(_NvidiaDriverHybridBase):
def __init__(self, backend):
_NvidiaDriverHybridBase.__init__(self, backend, '331-updates')
class NvidiaDriver319(_NvidiaDriverHybridBase):
def __init__(self, backend):
_NvidiaDriverHybridBase.__init__(self, backend, '319')
class NvidiaDriver319Updates(_NvidiaDriverHybridBase):
def __init__(self, backend):
_NvidiaDriverHybridBase.__init__(self, backend, '319-updates')
class NvidiaDriver304(_NvidiaDriverBase):
def __init__(self, backend):
_NvidiaDriverBase.__init__(self, backend, '304')
class NvidiaDriver304Updates(_NvidiaDriverBase):
def __init__(self, backend):
_NvidiaDriverBase.__init__(self, backend, '304-updates')
class NvidiaDriverExperimental310(_NvidiaDriverBase):
def __init__(self, backend):
_NvidiaDriverBase.__init__(self, backend, 'experimental-310')
class NvidiaDriverExperimental304(_NvidiaDriverBase):
def __init__(self, backend):
_NvidiaDriverBase.__init__(self, backend, 'experimental-304')
class NvidiaDriverCurrent(_NvidiaDriverBase):
def __init__(self, backend):
_NvidiaDriverBase.__init__(self, backend, 'current')
class NvidiaDriverCurrentUpdates(_NvidiaDriverBase):
def __init__(self, backend):
_NvidiaDriverBase.__init__(self, backend, 'current-updates')
class NvidiaDriver173(_NvidiaDriverBase):
def __init__(self, backend):
_NvidiaDriverBase.__init__(self, backend, '173')
class NvidiaDriver173Updates(_NvidiaDriverBase):
def __init__(self, backend):
_NvidiaDriverBase.__init__(self, backend, '173-updates')
class NvidiaDriver96(_NvidiaDriverBase):
def __init__(self, backend):
_NvidiaDriverBase.__init__(self, backend, '96')
def enable_config_hook(self):
_NvidiaDriverBase.enable_config_hook(self)
# ensure we have a screen section
if len(self.xorg_conf.globaldict['Screen']) == 0:
screen = self.xorg_conf.makeSection('Screen', identifier='Default Screen')
# version 96 needs AddARGBGLXVisuals
if self.version == '96':
self.xorg_conf.addOption('Screen', 'AddARGBGLXVisuals', 'True', optiontype='Option', position=0)
class NvidiaDriver96Updates(NvidiaDriver96):
def __init__(self, backend):
_NvidiaDriverBase.__init__(self, backend, '96-updates')
|