Browse Source

Чт май 18 15:21:53 MSK 2017

Mike Tatarko 2 years ago
parent
commit
9b36ee3f6a
26 changed files with 1503 additions and 0 deletions
  1. 30 0
      x11-drivers/nvidia-drivers/Manifest
  2. 1 0
      x11-drivers/nvidia-drivers/files/50nvidia-prelink-blacklist
  3. 2 0
      x11-drivers/nvidia-drivers/files/95-nvidia-settings
  4. 2 0
      x11-drivers/nvidia-drivers/files/95-nvidia-settings-r1
  5. 211 0
      x11-drivers/nvidia-drivers/files/NVIDIA-4.11.patch
  6. 11 0
      x11-drivers/nvidia-drivers/files/NVIDIA_glx-defines.patch
  7. 13 0
      x11-drivers/nvidia-drivers/files/NVIDIA_glx-glheader.patch
  8. 14 0
      x11-drivers/nvidia-drivers/files/nvidia-169.07
  9. 12 0
      x11-drivers/nvidia-drivers/files/nvidia-drivers-304.135-endif.patch
  10. 52 0
      x11-drivers/nvidia-drivers/files/nvidia-drivers-331.13-pax-usercopy.patch
  11. 25 0
      x11-drivers/nvidia-drivers/files/nvidia-drivers-337.12-pax-constify.patch
  12. 406 0
      x11-drivers/nvidia-drivers/files/nvidia-drivers-375.20-pax.patch
  13. 11 0
      x11-drivers/nvidia-drivers/files/nvidia-drivers-375.39-profiles-rc.patch
  14. 11 0
      x11-drivers/nvidia-drivers/files/nvidia-drivers-375.66-profiles-rc.patch
  15. 17 0
      x11-drivers/nvidia-drivers/files/nvidia-drivers-pax-const.patch
  16. 54 0
      x11-drivers/nvidia-drivers/files/nvidia-drivers-pax-usercopy.patch
  17. 8 0
      x11-drivers/nvidia-drivers/files/nvidia-persistenced.conf
  18. 24 0
      x11-drivers/nvidia-drivers/files/nvidia-persistenced.init
  19. 3 0
      x11-drivers/nvidia-drivers/files/nvidia-rmmod.conf
  20. 7 0
      x11-drivers/nvidia-drivers/files/nvidia-settings.desktop
  21. 24 0
      x11-drivers/nvidia-drivers/files/nvidia-smi.init
  22. 17 0
      x11-drivers/nvidia-drivers/files/nvidia-udev.sh
  23. 20 0
      x11-drivers/nvidia-drivers/files/nvidia-udev.sh-r1
  24. 3 0
      x11-drivers/nvidia-drivers/files/nvidia-uvm.conf
  25. 6 0
      x11-drivers/nvidia-drivers/files/nvidia.udev-rule
  26. 519 0
      x11-drivers/nvidia-drivers/nvidia-drivers-340.102.ebuild

+ 30 - 0
x11-drivers/nvidia-drivers/Manifest

@@ -0,0 +1,30 @@
+AUX 50nvidia-prelink-blacklist 319 SHA256 61adce61498451898c22fb538151379438729957418eacf4f69195b3e03ec1f4 SHA512 7252b464c45669bb402859ddb2c95f4553a37027870b6aeada3e1dd58fefe7b4713d3486d301177efdcd7559dbc31ceb6078220d5c0187bdc636d817a98e1a41 WHIRLPOOL 93e14ed7c8fb5dba87295c87e1e8906afac290f63dc6ea023fa6c387ed47ff13d488b3b24c400aee42a22737856a7782925d9a3a412ddcd1984dbbd7e51579a5
+AUX 95-nvidia-settings 54 SHA256 c4b293c6c2659bebcbad9cffc1e237c6908a3763599e432aba89d07bc2826ba0 SHA512 0fdaff8701598081eeb78defcd140b78f75309ace998df67569a15d0ff653aca7ad0576912bf9a619f42990e6fb35cdb79e21f8181d3cd04dea719d912da8be9 WHIRLPOOL d71fef01f8c346089ef2556ffe62c5094f89582b73500711a7f18f25424e59baa12f6b0861bd8efd9bf4c5bbf794642927ca322cee218fd2da9fc7baa50fa827
+AUX 95-nvidia-settings-r1 54 SHA256 cbc6e8cae863b768b2ec570390e409476ec3ca1137006888810a9ec7f0029eb0 SHA512 de9edf678c64ca3d10c912397800b2cb651ef9108b33ece97a4cc1e86dad0a9e81986cca6b96cfe80740d9cb433de7ef93f29be45178db714ee408c7f6570ac7 WHIRLPOOL 032fbfd24378659f30b0ca2d653dff8fa09106aa55803740f22f82515251c099e9637310d420d909135e9f7850cb2890cf4abeac9d6a4b5e390a7d061462b13a
+AUX NVIDIA-4.11.patch 6257 SHA256 6edd3579c1fb6b37ff19001609706fcb620139198e0b19976ab6ab207bdf341d SHA512 a993a60c62ac3468550f06f5a9ce04d6faacdabca6bb2e0139ae412f952bf4540715608330eeab9a5e227efcd3d16df1e94d8602e198483eab7071df40554701 WHIRLPOOL 22888e68e6e1793541229c41090ecc387ee98e2fe718f53092b0479bf190dfb274fa5c54911d46e7dc5692a0ff255dbe575b3aab7a9740c66a9fa77fce2036d4
+AUX NVIDIA_glx-defines.patch 437 SHA256 0007f3d962edb87da4788ce58869679c1b10f28223a6bf1c23696fede57305da SHA512 a9cbbe5d5d362db0eb92d5b9fe87f28cccb600df9b44ae2b323ed08da97c32d6a4a0553c7c82ea3777ab91a1a4bf6b74f04d89b6ec28e60565e677cc4af48351 WHIRLPOOL a826b11c86803530346a65612ebd1a12f77f6c6ba1d93af597435993086451648b825fbc245a2c5850e0680c58129924843744d7e29013d5087c3b4dd9fefb14
+AUX NVIDIA_glx-glheader.patch 380 SHA256 f630e24067bf6199a64f8fe8c5d6fc158cb4b153bda65ffc3f97b36a9cb08faf SHA512 366ebbe967001f4d694e9d6ae61fbd8b57e2946bba495894936809634bb87bd6ba6b10689969977e4d0eaba6983c16fe8d78830112b5b28f01c78381a0a095d6 WHIRLPOOL 8609fcedb439299189d9d05606a290a63de8b207bab855f874faa36e892396f41159d26e505dfead89fdac9d7e61aeeb50b16877aa14ad62dc3cd617353d7d60
+AUX nvidia-169.07 639 SHA256 a8c4860f008d53776fda7a17b59524f271236559af688e9a2c9845cbbcba1577 SHA512 3af295c026280dc3a2b73c2cc7772254686b09cad15f1333ab0b4de8cb0ccf78e725ced2a399b10edcf8af6ba42ab1485dc0661af67461b0c3789f786357772f WHIRLPOOL 626ae3c01c879e0cfe05bd373e0b9dfd6f462dd9ef6ae94a7d60276fe2d17c57fbb20aaa4d2a186a0ffc2a860076692aac854d00a3545bc9736e7bb8d0581055
+AUX nvidia-drivers-304.135-endif.patch 296 SHA256 1594904672e75a07caff0c370f32840b723a53ada5e8c5f5134ca54ea0979d4f SHA512 79bcf414b15a01116d2a1685a2052e82a8aadd1ef759ebce2c9781b75ea742383d17b8c7efce67b81112fd33c43ff93afe2ff922e3a9ca64a362709e29d7ec9f WHIRLPOOL ee517164cc6f4e7fb0fb8ce96cc59eeda01da786cb087d20fbb459c594361e7b1b49ded2afdbe81aeed48bca9735f06968d7190bf33a6ec56cea289df28a8a5b
+AUX nvidia-drivers-331.13-pax-usercopy.patch 2127 SHA256 669ffcab77432f116c2b9bc7ed55e2a1f4e208ff19b63d43003af2b346f7c0c0 SHA512 c6ebd534d1e88fe5c1b71ef5ccced8957e34931cab72d1adb4017c703fc2e285f6e36a778bb36a319f505cfe6408be098569944aa5d78c00c8837ffe880d006a WHIRLPOOL 798d3f3edeae2361f039372f5fe13cf9df5aef20ee63c7cdc83e806cbad097b0ddccd6b30968c2b2ceb768ad0425b02aaefe1ba41709e3f0fb79a82f908579a6
+AUX nvidia-drivers-337.12-pax-constify.patch 1042 SHA256 abb0c616a1187fd1958fea3e9fe8d3a9207d393cb9b76ccbf9f25f44c427ffc5 SHA512 203b0baf036e4f301959516ab17b6748814bed850bc79da30ae524a3c902fda57942587aba0803ad25891fb4867d88a003658b630849e12bc2c95015a62661b0 WHIRLPOOL 1ca05ff6737455032babf352ce08fdcefd5a006c3c4bc3607385896a5b0b3961fb9c7e1ff0010a28041ff9f9d49e35210d0d350df534a0e238df3e82f7023c64
+AUX nvidia-drivers-375.20-pax.patch 15901 SHA256 165ba19d91e3ea0bc01dc3ec730ea0bb13f8176fb21db4111da1fcd8f3d6892b SHA512 65ad102cc3c28c6e2d67c4f24c8fe6ca3b9b4b4f57eca6fdf437127ce9caccabebd3049af53b30ba808e68529b5627a7e3add31b42cffb09d648a69bedfa55d9 WHIRLPOOL 7e47edbd0413cc72e72be2272b92c2b913f8329b97d5eb6325686c1b3c68c7ab8be4cdde748bfa44a170a86d7376bad3188e0c7fc4f6e9efc35d3db1d8caf225
+AUX nvidia-drivers-375.39-profiles-rc.patch 299 SHA256 d691b6e7ce49e6d968c1d1331d76028bf50f14f2febc53a6b76cc9ffa8c1bc18 SHA512 5038b47db58f20de26aab237517a0a472917a837f01a9520abd0e86d863302f6cfebeb8841fdf07a4ac6a1dc2249cd19ed79ae598415d7e1c4711b1f68ad660a WHIRLPOOL 17c88b868d5d0a794230e163489774574e5584ddfe6e07a6a75d0f39f6ba869f7063f3a1a44c6aeb63ef472050254f09d3eac3504e535d9c1cefecc3eececede
+AUX nvidia-drivers-375.66-profiles-rc.patch 299 SHA256 916a45b2239d05a473e4320b9b0de444bcced624c9b4bee5c3fa9b4b45afe871 SHA512 d8a205d1b275db88b9d35e2913cd574e8633797da603b6dd4b3b0b97b12ba935cf2f819f1b89b551e159fed7f37b3bccbaff396c19af081c658c544a6be465fa WHIRLPOOL 35f3de67c3d38bd5af0016924f4da7daacd5a2c06853ce02a1982509c5a3177ac8289f1e4a6b3f1a2f577a29ca7c733c078d6b31fdf4e50bbfbe2c4e9ab140bc
+AUX nvidia-drivers-pax-const.patch 833 SHA256 74ba8aa3b03e1b4a0515fd84c159eaeb7635fa1364e77544b01ff6f571f0e6d8 SHA512 6ef94db71cab2dd47273eaed1857209d03ef648d268c7645f3ca4caf6b894590e42a8e716e4354f2eed656e7d55a4c1774b1e6a4be215fbf59fc9d0b1a5762a0 WHIRLPOOL 1b2d737ee7ccee831c85bd8af9605c0633fd025bb209e6d76c13f49a5664aa490bd5b6ce48855e541fe87380cd7b723162e1965b803e1ed630f239bf4dbd0d19
+AUX nvidia-drivers-pax-usercopy.patch 2350 SHA256 56980f43db38d582bc6a9bfd881973fce6e3e056b77ce4f4005bdcf79526a863 SHA512 54a1354ba008d014a608044610027b4d808120f8e77cc7d5ac855c3dcf4f487b0a4c0870ae4e727db0643cb56ee21513b803976e9a30c6838adf2f5414232804 WHIRLPOOL 78ac54bfe52cc3b6dfa28e17020991dfb7056984d667b0fefa41d23372b03e1a8e6d66c74e1dee234733d5b2b36e2c0813f507a89716ae2d8f1f6db917fdf01d
+AUX nvidia-persistenced.conf 250 SHA256 347437868119e8ae12852a574597936e855f534a9ad290fef3f62b4083a38516 SHA512 9c9562bb15bf4552754dd50a1b01dec5df76f7f5666fba2fff642a169f87e9ed421a260f2258ab469f7e4cd9ef8161653355795624387fe7ad5ae6a0d71e5f46 WHIRLPOOL 1422504c6688fce28719146c7d95fe196ca617556942e8dc04c7f8c1412fa80b5b8289c0f86b835eece90eed4b4017093d686779f88d44cd41fa3de1a10e9bbe
+AUX nvidia-persistenced.init 650 SHA256 17664ed958b1d7706e5151201f784d755c60e66239229d2988e186b649756465 SHA512 864c90573a033e30d151c9adb9f0f12c5bcba2b5a7eaaa62f86fc11747f13956825fc5acb4fb1fb453a32acefe850e73264a650fafa6014cc96bbc7e3b56fdaa WHIRLPOOL 52fd8f458d6a7274d332255e9594ba6d7639e6f6ae7bbcdd20205dc9e240718977da3e103a484d1813884b6a268e87088b28b59d5fa3a9fe4a9d50250e1d2fbd
+AUX nvidia-rmmod.conf 108 SHA256 db912faa64e0d1d993006b2a1e886b52f8deb83c7a07f14458875579a1d2c3f0 SHA512 cb6b70ba0fc9c6d81d43f31d724538beff79e7e9b02c610485f1e46757d7bf16410d5cb2853d8d67ea6e4da59e7e1687ad14dc4b494415c6db6fab517a03b28b WHIRLPOOL bbf741abd25c87bada3bb3e5d6aa41c5c8e670a1299612eb7141f93c31734b8e782c320308c929d2a316586ac8cc43dd9600cc06c2c4066603844ba9fbfb3b0e
+AUX nvidia-settings.desktop 185 SHA256 a402fc441e27b6279e38d227d650916a6aa0f872605ade6c539971c70284204f SHA512 30cab269daf282b9716e53ecf2f8993289e8d4ad05c40d6ddaad3ea6e95477c36a4d65a28d0ec3c1c9c7e845fde140df9012944306f70131a02c9ffef0a9f523 WHIRLPOOL 2bea14aed79de7905b41768ca4c4ccd608c41353335607fbc23236471e5b755eb0c0d8d99611949969bf2511ca8d003ce7ed405be0078c2bcf24070ee40a46ec
+AUX nvidia-smi.init 545 SHA256 a64a301feb058ed0e993e44cc2d4a0105735110f8f9cd05aacaaf37e1aa3c85c SHA512 f7f04a73d646b90cdc14a408f53650324d7c1d7754a1d92acc9a8acaef163bda1eef33acb831df77657786e7ceebe0d7f9d25d2edd57d1590be340ce12fea6e5 WHIRLPOOL de2cebf3ddae61348f2f142aefa84a17cb0fcbc903d92d3ca3932577a2a822de7e4b64abeaa91c81738cff8c18927804a027d9c1033e11e1c5ae0fc04caf4aba
+AUX nvidia-udev.sh 185 SHA256 120c0af2b64fbcbd7032217a78eec8b104874c1ca68726367bce22c57944e07e SHA512 166df3a4e7c1862ca2e0f634bf5eed7aad1bdd7e55764ca42371b91a7077c59f0bc243de5616fd38dac9694159d1695d54fbd08ac89d4d3f3649c70c7db5977e WHIRLPOOL cb9995029cdb2fe1bc7fe5ae54041ee5de8da86bf5eb3616d062475e56c44d436e1e66683ecddd986fc5bca5723d88da4b1a42f65f3cd7e15636928bd21fce14
+AUX nvidia-udev.sh-r1 285 SHA256 5ca08a5329cccd9e32dd3cd573525f510edf7b12d8c531cbe781a70b2ceade63 SHA512 493b0d5f2698d299e3b8d5782ac7fb8174e7ee93f1dae66bc1161eb4dd16d4db91048444dc6e7bea344960936c0a5c825041f6909af004438d8009a3d3fe71c9 WHIRLPOOL 14c2d01d8280dc9c4afaacc75b8ef97875553b5ed50e6dba6209280ebea5cd9c607505870ee37d719530428a9f57034511cd080ba0ab3a1d831b767b4cd15305
+AUX nvidia-uvm.conf 82 SHA256 4407c7ceed58ead98492560c07fc44d4285a70ed5165407f1b959e46d6e6d081 SHA512 cbdb946934a0b7c7d0fab0937ead0a161ff20238e0b53f9e05ea18a4fa0507df8d37594bd13402e3ec2001d488daeb2bec718d612f68202768d62a3cec97aacb WHIRLPOOL a79d65d67b0ff446bb2c65f5f3ec16ffaf0268ab0abbc137b413168aa7f5e617e502eaaf00fd21a149778bdd134da532b25bb066fc70bfa601caa97397aaf424
+AUX nvidia.udev-rule 462 SHA256 37b152a5055a16d1947171567178e2841679ddf03dba9d48e7d30f1e3b469ac6 SHA512 96f9edaa0b46bea5fce17596f868bea5265b303d7185af6ba81527bbd7b8fdf92de9311317cbde51a29d222083d451c25ab77c3d6837cbc4072a50d9af89aa86 WHIRLPOOL 89ed95f33db7485a3a1acd91df33ecdfb7d0a249db2d7674f134fb85b35a54653d0458e478503315ce506ae5d3c8dcd4ac20420711fdbdd087ea4bd779627d13
+DIST NVIDIA-FreeBSD-x86-340.102.tar.gz 59991374 SHA256 7b4f66260a1ce6ce35b7a463f8e0ff68fec0f47202af9d243931647f3eeb1dc5 SHA512 8fc2539eda423ff32ed4764cc6ab58a81fbb225a7d937a71914a3a28a15f907fcf782729c55d45d40da61556058570d9c29c295bd3233b7d8f40ad060a05f1b0 WHIRLPOOL edb11fee029929534abf833343d74bdf2424599af13b0fa4f84d7c42aa63fb04e2b78646a168ae246d45e844e242a2e16f7a159e34886525964352248a9f4f3c
+DIST NVIDIA-FreeBSD-x86_64-340.102.tar.gz 60862932 SHA256 6d1108c2e8d1b25eb16cd8dc4eb221f2a20d2e4c39a515c0b5809fb407991f94 SHA512 fddef644937093550f9e5dfc25dc5cb81280785735c2d11f644b5eece8144b23bc88a353534ca95e925f54da9131ed5dd7460b72e554b6625df33e243476588f WHIRLPOOL 0b19ef96124768b8cafb0211a79f8ba6e3d04d9289d5194a59fdaa4eb15ab898c103346892007d9fd6eac75d6d503cd9724ab8f60bd7cf28fee2f9307b03d70b
+DIST NVIDIA-Linux-x86-340.102.run 38779756 SHA256 61b13d5dae0f6f5d788a4d8c4c98e8d971d19cb90b606058060d007946248828 SHA512 bea700c925a6044fcded40324bb389c5fa1aadc40831f685a76e7b0ded11161f492960950c201467e564d157dcbe0c330d13a2014f51d0073002c5a262a6f0ca WHIRLPOOL f7a3e3c5f8bb9eedf0a93104564d3d9c3eabc39a807c47e87f84373f89513afcafecb94e602b12fd24f872971f2d16a5f945326c670a6eebcd9ffcdcb70cb99e
+DIST NVIDIA-Linux-x86_64-340.102.run 69960567 SHA256 2b96d2f26c00405471e0ce10dca0b6639e91aeb43f7c5aadbdae28445a28df5a SHA512 eead5b6f18afd5384f30f36a9ef569dea7d6ca1dbc590f63d603694bcc6a8bf251942b36ca606cfd5e6775ef180cd564f3cf226a3f4c04d7ed354204fec15577 WHIRLPOOL 6596a178aa35ac841bf287fa1372f6748cda0430c6b4bcd18fa63d63030331df59e75d4a3dde63f28a6fa15cdfaa90d27136c96e9abe81fb05202f00430ecaa9
+DIST nvidia-settings-340.102.tar.bz2 1550093 SHA256 2895d4e2597a6ea0c425d74c7a0808775065f5cf58397fbbe6e626b00c60a55a SHA512 1ab190d8bcba7cc39d47f38db2bee28fab48d48c9a6674c9ff29ea3f51103e13746ee1df2d30581bd8259fc1104fed90b36cba88907bb2f202c931d256eab66a WHIRLPOOL 58105b371bc7156c2749f4bf85377f06fca71eb0a933721d70987aa53bb6c94494de3be25363ccf326105ca475405dcd7c884ceb6158df352ac6cc70dcffbf7e
+EBUILD nvidia-drivers-340.102.ebuild 14549 SHA256 5a0af08d8830640ca2f8af0b6db8cb8dde7b78612316d4933806e562493af83b SHA512 1c91b475b6f25d84895a72cce0a639e6ae940ae85bc104bdc8bd17d10d5777d7cba7947c03c6484e3608746e5747ee00ea0261dec36552bedc66f54f75f60cdf WHIRLPOOL 05ce8065e21d34319d423a3214b345a1331ff3c7ae12f7baa6edf75fef4873d36aff4358701e3642d1a9dd2dcbf031c93add6c038220f11ec7f09ae23b26a7b9

+ 1 - 0
x11-drivers/nvidia-drivers/files/50nvidia-prelink-blacklist

@@ -0,0 +1 @@
+PRELINK_PATH_MASK="/usr/lib{,64}/tls/libnvidia-tls*:/usr/lib{,64}/libnvidia*:/usr/lib{,64}/libGL*:/usr/lib{,64}/opengl/nvidia/*:/usr/lib{,64}/OpenCL/vendors/nvidia/*:/usr/lib{,64}/xorg/modules/drivers/nvidia*:/usr/lib{,64}/libvdpau_nvidia*:/usr/lib{,64}/libXvMCNVIDIA*:/usr/lib{,64}/libcuda*:/usr/lib{,64}/libnvcuvid*"

+ 2 - 0
x11-drivers/nvidia-drivers/files/95-nvidia-settings

@@ -0,0 +1,2 @@
+#!/bin/sh
+/opt/bin/nvidia-settings --load-config-only

+ 2 - 0
x11-drivers/nvidia-drivers/files/95-nvidia-settings-r1

@@ -0,0 +1,2 @@
+#!/bin/sh
+/usr/bin/nvidia-settings --load-config-only

+ 211 - 0
x11-drivers/nvidia-drivers/files/NVIDIA-4.11.patch

@@ -0,0 +1,211 @@
+--- kernel/nv-linux.h
++++ kernel/nv-linux.h
+@@ -2082,6 +2082,8 @@ static inline NvU64 nv_node_end_pfn(int nid)
+  *    2016 Dec 14:5b56d49fc31dbb0487e14ead790fc81ca9fb2c99
+  */
+
++#include <linux/version.h>
++
+ #if defined(NV_GET_USER_PAGES_REMOTE_PRESENT)
+     #if defined(NV_GET_USER_PAGES_HAS_WRITE_AND_FORCE_ARGS)
+         #define NV_GET_USER_PAGES           get_user_pages
+@@ -2129,8 +2131,13 @@ static inline NvU64 nv_node_end_pfn(int nid)
+
+         #else
+
++#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
+                return get_user_pages_remote(tsk, mm, start, nr_pages, flags,
+                                             pages, vmas);
++#else
++               return get_user_pages_remote(tsk, mm, start, nr_pages, flags,
++                                            pages, vmas, NULL);
++#endif
+
+         #endif
+
+--- kernel/nv-pat.c
++++ kernel/nv-pat.c
+@@ -203,6 +203,7 @@ void nv_disable_pat_support(void)
+ }
+
+ #if defined(NV_ENABLE_PAT_SUPPORT) && defined(NV_ENABLE_HOTPLUG_CPU)
++#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
+ static int
+ nvidia_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
+ {
+@@ -234,6 +235,34 @@ static struct notifier_block nv_hotcpu_nfb = {
+     .notifier_call = nvidia_cpu_callback,
+     .priority = 0
+ };
++#else
++static int nvidia_cpu_online(unsigned int hcpu)
++{
++    unsigned int cpu = get_cpu();
++    if (cpu == hcpu)
++        nv_setup_pat_entries(NULL);
++    else
++        NV_SMP_CALL_FUNCTION(nv_setup_pat_entries, (void *)(long int)hcpu, 1);
++
++    put_cpu();
++
++    return 0;
++}
++
++static int nvidia_cpu_down_prep(unsigned int hcpu)
++{
++    unsigned int cpu = get_cpu();
++    if (cpu == hcpu)
++        nv_restore_pat_entries(NULL);
++    else
++        NV_SMP_CALL_FUNCTION(nv_restore_pat_entries, (void *)(long int)hcpu, 1);
++
++    put_cpu();
++
++    return 0;
++}
++#endif
++
+ #endif
+
+ int nv_init_pat_support(nv_stack_t *sp)
+@@ -255,7 +284,14 @@ int nv_init_pat_support(nv_stack_t *sp)
+ #if defined(NV_ENABLE_PAT_SUPPORT) && defined(NV_ENABLE_HOTPLUG_CPU)
+         if (nv_pat_mode == NV_PAT_MODE_BUILTIN)
+         {
++#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
+             if (register_hotcpu_notifier(&nv_hotcpu_nfb) != 0)
++#else
++            if (cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
++                                  "gpu/nvidia:online",
++                                  nvidia_cpu_online,
++                                  nvidia_cpu_down_prep) != 0)
++#endif
+             {
+                 nv_disable_pat_support();
+                 nv_printf(NV_DBG_ERRORS,
+@@ -280,7 +316,11 @@ void nv_teardown_pat_support(void)
+     {
+         nv_disable_pat_support();
+ #if defined(NV_ENABLE_PAT_SUPPORT) && defined(NV_ENABLE_HOTPLUG_CPU)
++#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
+         unregister_hotcpu_notifier(&nv_hotcpu_nfb);
++#else
++        cpuhp_remove_state_nocalls(CPUHP_AP_ONLINE_DYN);
++#endif
+ #endif
+     }
+ }
+--- kernel/uvm/nvidia_uvm_lite.c
++++ kernel/uvm/nvidia_uvm_lite.c
+@@ -820,7 +820,11 @@ done:
+ #if defined(NV_VM_OPERATIONS_STRUCT_HAS_FAULT)
+ int _fault(struct vm_area_struct *vma, struct vm_fault *vmf)
+ {
++#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0)
+     unsigned long vaddr = (unsigned long)vmf->virtual_address;
++#else
++    unsigned long vaddr = (unsigned long)vmf->address;
++#endif
+     struct page *page = NULL;
+     int retval;
+
+--- kernel/nv-drm.c	2017-03-31 03:42:21.000000000 +0200
++++ kernel/nv-drm.c	2017-04-06 23:53:14.273356795 +0200
+@@ -48,7 +48,7 @@
+     return -ENODEV;
+ }
+
+-static int nv_drm_unload(
++static void nv_drm_unload(
+     struct drm_device *dev
+ )
+ {
+@@ -60,7 +60,7 @@
+         {
+             BUG_ON(nvl->drm != dev);
+             nvl->drm = NULL;
+-            return 0;
++            return;
+         }
+     }
+
+@@ -64,7 +64,7 @@
+         }
+     }
+
+-    return -ENODEV;
++    return;
+ }
+
+ static void nv_gem_free(
+--- kernel/uvm/nvidia_uvm_linux.h  2017-03-31 03:42:21.000000000 +0200
++++ kernel/uvm/nvidia_uvm_linux.h  2017-04-06 23:53:14.273356795 +0200
+@@ -124,6 +124,7 @@
+ #include <linux/delay.h>            /* mdelay, udelay                   */
+
+ #include <linux/sched.h>            /* suser(), capable() replacement   */
++#include <linux/sched/signal.h>
+ #include <linux/moduleparam.h>      /* module_param()                   */
+ #if !defined(NV_VMWARE)
+ #include <asm/tlbflush.h>           /* flush_tlb(), flush_tlb_all()     */
+@@ -362,17 +363,6 @@
+     void address_space_init_once(struct address_space *mapping);
+ #endif
+
+-#if !defined(NV_FATAL_SIGNAL_PENDING_PRESENT)
+-    static inline int __fatal_signal_pending(struct task_struct *p)
+-    {
+-        return unlikely(sigismember(&p->pending.signal, SIGKILL));
+-    }
+-
+-    static inline int fatal_signal_pending(struct task_struct *p)
+-    {
+-        return signal_pending(p) && __fatal_signal_pending(p);
+-    }
+-#endif
+
+ //
+ // Before the current->cred structure was introduced, current->euid,
+--- kernel/uvm/nvidia_uvm_lite.c  2017-03-31 03:42:21.000000000 +0200
++++ kernel/uvm/nvidia_uvm_lite.c  2017-04-06 23:53:14.273356795 +0200
+@@ -818,7 +818,7 @@
+ }
+
+ #if defined(NV_VM_OPERATIONS_STRUCT_HAS_FAULT)
+-int _fault(struct vm_area_struct *vma, struct vm_fault *vmf)
++int _fault(struct vm_fault *vmf)
+ {
+     unsigned long vaddr = (unsigned long)vmf->virtual_address;
+     struct page *page = NULL;
+@@ -828,7 +828,7 @@
+     struct page *page = NULL;
+     int retval;
+
+-    retval = _fault_common(vma, vaddr, &page, vmf->flags);
++    retval = _fault_common(NULL, vaddr, &page, vmf->flags);
+
+     vmf->page = page;
+
+@@ -866,7 +866,7 @@
+ // it's dealing with anonymous mapping (see handle_pte_fault).
+ //
+ #if defined(NV_VM_OPERATIONS_STRUCT_HAS_FAULT)
+-int _sigbus_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
++int _sigbus_fault(struct vm_fault *vmf)
+ {
+     vmf->page = NULL;
+     return VM_FAULT_SIGBUS;
+--- kernel/nv-drm.c
++++ kernel/nv-drm.c
+@@ -115,7 +115,11 @@ static const struct file_operations nv_drm_fops = {
+ };
+
+ static struct drm_driver nv_drm_driver = {
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0)
++    .driver_features = DRIVER_GEM | DRIVER_PRIME | DRIVER_LEGACY,
++#else
+     .driver_features = DRIVER_GEM | DRIVER_PRIME,
++#endif
+     .load = nv_drm_load,
+     .unload = nv_drm_unload,
+     .fops = &nv_drm_fops,

+ 11 - 0
x11-drivers/nvidia-drivers/files/NVIDIA_glx-defines.patch

@@ -0,0 +1,11 @@
+diff -ur NVIDIA_GLX-1.0-4191/usr/include/GL/glx.h NVIDIA_GLX-1.0-4191.new/usr/include/GL/glx.h
+--- NVIDIA_GLX-1.0-4191/usr/include/GL/glx.h	2002-12-09 21:26:55.000000000 +0100
++++ NVIDIA_GLX-1.0-4191.new/usr/include/GL/glx.h	2003-01-30 18:20:23.000000000 +0100
+@@ -39,6 +39,7 @@
+ typedef XID GLXPixmap;
+ typedef XID GLXDrawable;
+ typedef XID GLXPbuffer;
++typedef XID GLXPbufferSGIX;
+ typedef XID GLXWindow;
+ typedef XID GLXFBConfigID;
+ 

+ 13 - 0
x11-drivers/nvidia-drivers/files/NVIDIA_glx-glheader.patch

@@ -0,0 +1,13 @@
+--- usr/include/GL/gl.g.orig	2004-07-17 19:56:59.789410584 +1000
++++ usr/include/GL/gl.h	2004-07-17 19:59:08.844791184 +1000
+@@ -66,6 +66,10 @@
+ typedef double GLclampd;
+ typedef void GLvoid;
+ 
++/* Patching for some better defines in the global system */
++#ifndef GL_GLEXT_LEGACY
++#include <GL/glext.h>
++#endif
+ 
+ /*************************************************************/
+ 

+ 14 - 0
x11-drivers/nvidia-drivers/files/nvidia-169.07

@@ -0,0 +1,14 @@
+# Nvidia drivers support
+alias char-major-195 nvidia
+alias /dev/nvidiactl char-major-195
+
+# To tweak the driver the following options can be used, note that
+# you should be careful, as it could cause instability!! For more 
+# options see /usr/share/doc/PACKAGE/README 
+#
+# !!! SECURITY WARNING !!!
+# DO NOT MODIFY OR REMOVE THE DEVICE FILE RELATED OPTIONS UNLESS YOU KNOW
+# WHAT YOU ARE DOING.
+# ONLY ADD TRUSTED USERS TO THE VIDEO GROUP, THESE USERS MAY BE ABLE TO CRASH,
+# COMPROMISE, OR IRREPARABLY DAMAGE THE MACHINE.
+options nvidia NVreg_DeviceFileMode=432 NVreg_DeviceFileUID=0 NVreg_DeviceFileGID=VIDEOGID NVreg_ModifyDeviceFiles=1

+ 12 - 0
x11-drivers/nvidia-drivers/files/nvidia-drivers-304.135-endif.patch

@@ -0,0 +1,12 @@
+--- a/kernel/os-agp.c
++++ b/kernel/os-agp.c
+@@ -180,8 +180,8 @@
+     {
+         nv_mtrr_del(nv->agp.arch_phys_wc_add_token, agp_info.aper_base,
+                     agp_info.aper_size << 20);
+-#endif
+     }
++#endif
+ release:
+     NV_AGPGART_BACKEND_RELEASE(drm_agp_p, nvl->agp_bridge);
+ bailout:

+ 52 - 0
x11-drivers/nvidia-drivers/files/nvidia-drivers-331.13-pax-usercopy.patch

@@ -0,0 +1,52 @@
+--- a/kernel/nv-linux.h
++++ b/kernel/nv-linux.h
+@@ -757,16 +757,16 @@
+ 
+ #if defined(NV_KMEM_CACHE_CREATE_PRESENT)
+ #if (NV_KMEM_CACHE_CREATE_ARGUMENT_COUNT == 6)
+-#define NV_KMEM_CACHE_CREATE(kmem_cache, name, type)            \
++#define NV_KMEM_CACHE_CREATE(kmem_cache, name, type, flags)     \
+     {                                                           \
+         kmem_cache = kmem_cache_create(name, sizeof(type),      \
+-                        0, 0, NULL, NULL);                      \
++                        0, flags, NULL, NULL);                  \
+     }
+ #elif (NV_KMEM_CACHE_CREATE_ARGUMENT_COUNT == 5)
+-#define NV_KMEM_CACHE_CREATE(kmem_cache, name, type)            \
++#define NV_KMEM_CACHE_CREATE(kmem_cache, name, type, flags)     \
+     {                                                           \
+         kmem_cache = kmem_cache_create(name, sizeof(type),      \
+-                        0, 0, NULL);                            \
++                        0, flags, NULL);                        \
+     }
+ #else
+ #error "NV_KMEM_CACHE_CREATE_ARGUMENT_COUNT value unrecognized!"
+--- a/kernel/nv.c
++++ b/kernel/nv.c
+@@ -794,7 +794,7 @@
+     NV_SPIN_LOCK_INIT(&km_lock);
+ #endif
+ 
+-    NV_KMEM_CACHE_CREATE(nv_stack_t_cache, NV_STACK_CACHE_STR, nv_stack_t);
++    NV_KMEM_CACHE_CREATE(nv_stack_t_cache, NV_STACK_CACHE_STR, nv_stack_t, SLAB_USERCOPY);
+     if (nv_stack_t_cache == NULL)
+     {
+         nv_printf(NV_DBG_ERRORS, "NVRM: stack cache allocation failed!\n");
+@@ -924,7 +924,7 @@
+     nv->os_state = (void *) &nv_ctl_device;
+     nv_lock_init_locks(nv);
+ 
+-    NV_KMEM_CACHE_CREATE(nv_pte_t_cache, NV_PTE_CACHE_STR, nv_pte_t);
++    NV_KMEM_CACHE_CREATE(nv_pte_t_cache, NV_PTE_CACHE_STR, nv_pte_t, 0);
+     if (nv_pte_t_cache == NULL)
+     {
+         rc = -ENOMEM;
+@@ -935,7 +935,7 @@
+     if (NV_BUILD_MODULE_INSTANCES == 0)
+     {
+         NV_KMEM_CACHE_CREATE(nvidia_p2p_page_t_cache, "nvidia_p2p_page_t",
+-                             nvidia_p2p_page_t);
++                             nvidia_p2p_page_t, 0);
+         if (nvidia_p2p_page_t_cache == NULL)
+         {
+             rc = -ENOMEM;

+ 25 - 0
x11-drivers/nvidia-drivers/files/nvidia-drivers-337.12-pax-constify.patch

@@ -0,0 +1,25 @@
+--- a/kernel/uvm/nvidia_uvm_common.c
++++ b/kernel/uvm/nvidia_uvm_common.c
+@@ -95,7 +95,6 @@ static RM_STATUS uvmnext_gpu_event_stop_
+ #endif // NVIDIA_UVM_NEXT_ENABLED
+ 
+ static dev_t g_uvmBaseDev;
+-struct UvmOpsUvmEvents g_exportedUvmOps;
+ 
+ // TODO: This would be easier if RM allowed for multiple registrations, since we
+ //       could register UVM-Lite and UVM-Next separately (bug 1372835).
+@@ -147,9 +146,11 @@ static RM_STATUS uvmSetupGpuProvider(voi
+     RM_STATUS status = RM_OK;
+ 
+ #ifdef NVIDIA_UVM_RM_ENABLED
+-    g_exportedUvmOps.startDevice = uvm_gpu_event_start_device;
+-    g_exportedUvmOps.stopDevice  = uvm_gpu_event_stop_device;
+-    g_exportedUvmOps.isrTopHalf  = uvmnext_isr_top_half;
++    static struct UvmOpsUvmEvents g_exportedUvmOps = {
++        .startDevice = uvm_gpu_event_start_device,
++        .stopDevice  = uvm_gpu_event_stop_device,
++        .isrTopHalf  = uvmnext_isr_top_half,
++    };
+ 
+     // call RM to exchange the function pointers.
+     status = nvUvmInterfaceRegisterUvmCallbacks(&g_exportedUvmOps);

+ 406 - 0
x11-drivers/nvidia-drivers/files/nvidia-drivers-375.20-pax.patch

@@ -0,0 +1,406 @@
+diff -urp work.orig/kernel/common/inc/nv-linux.h work/kernel/common/inc/nv-linux.h
+--- work.orig/kernel/common/inc/nv-linux.h	2016-11-27 21:56:50.391617167 +0100
++++ work/kernel/common/inc/nv-linux.h	2016-11-27 22:04:14.045516163 +0100
+@@ -1310,7 +1310,8 @@ extern void *nvidia_stack_t_cache;
+ #if (NV_KMEM_CACHE_CREATE_ARGUMENT_COUNT == 5)
+ #define NV_KMEM_CACHE_CREATE_FULL(name, size, align, flags, ctor) \
+     kmem_cache_create(name, size, align, flags, ctor)
+-
++#define NV_KMEM_CACHE_CREATE_FULL_USERCOPY(name, size, align, flags, useroffset, usersize, ctor) \
++    kmem_cache_create_usercopy(name, size, align, flags, useroffset, usersize, ctor)
+ #else
+ #define NV_KMEM_CACHE_CREATE_FULL(name, size, align, flags, ctor) \
+     kmem_cache_create(name, size, align, flags, ctor, NULL)
+@@ -1319,6 +1320,14 @@ extern void *nvidia_stack_t_cache;
+ #define NV_KMEM_CACHE_CREATE(name, type)    \
+     NV_KMEM_CACHE_CREATE_FULL(name, sizeof(type), 0, 0, NULL)
+ 
++#ifdef SLAB_USERCOPY
++#define NV_KMEM_CACHE_CREATE_USERCOPY(name, type)    \
++    NV_KMEM_CACHE_CREATE_FULL(name, sizeof(type), 0, SLAB_USERCOPY, NULL)
++#else
++#define NV_KMEM_CACHE_CREATE_USERCOPY(name, type)    \
++    NV_KMEM_CACHE_CREATE_FULL_USERCOPY(name, sizeof(type), 0, 0, 0, sizeof(type), NULL)
++#endif
++
+ #define NV_KMEM_CACHE_DESTROY(kmem_cache)   \
+     kmem_cache_destroy(kmem_cache)
+ 
+diff -urp work.orig/kernel/common/inc/nv-modeset-interface.h work/kernel/common/inc/nv-modeset-interface.h
+--- work.orig/kernel/common/inc/nv-modeset-interface.h	2016-11-27 21:56:50.391617167 +0100
++++ work/kernel/common/inc/nv-modeset-interface.h	2016-11-27 21:54:23.971706350 +0100
+@@ -72,7 +72,7 @@ typedef struct {
+      * mix nvidia and nvidia-modeset kernel modules from different
+      * releases.
+      */
+-    const char *version_string;
++//    const char *version_string;
+ 
+     /*
+      * Return system information.
+@@ -117,6 +117,6 @@ typedef struct {
+ 
+ } nvidia_modeset_rm_ops_t;
+ 
+-NV_STATUS nvidia_get_rm_ops(nvidia_modeset_rm_ops_t *rm_ops);
++NV_STATUS nvidia_get_rm_ops(const nvidia_modeset_rm_ops_t **rm_ops, const char **version_string);
+ 
+ #endif /* _NV_MODESET_INTERFACE_H_ */
+diff -urp work.orig/kernel/common/inc/nv-register-module.h work/kernel/common/inc/nv-register-module.h
+--- work.orig/kernel/common/inc/nv-register-module.h	2016-11-27 21:56:50.391617167 +0100
++++ work/kernel/common/inc/nv-register-module.h	2016-11-27 21:54:23.971706350 +0100
+@@ -34,7 +34,7 @@ typedef struct nvidia_module_s {
+     int (*ioctl)(struct inode *, struct file * file, unsigned int cmd, unsigned long arg);
+     unsigned int (*poll)(struct file * file, poll_table *wait);
+ 
+-} nvidia_module_t;
++} __do_const nvidia_module_t;
+ 
+ int nvidia_register_module(nvidia_module_t *);
+ int nvidia_unregister_module(nvidia_module_t *);
+diff -urp work.orig/kernel/nvidia/nv.c work/kernel/nvidia/nv.c
+--- work.orig/kernel/nvidia/nv.c	2016-11-27 21:56:50.395629748 +0100
++++ work/kernel/nvidia/nv.c	2016-11-27 21:54:23.971706350 +0100
+@@ -666,7 +666,7 @@ int __init nvidia_init_module(void)
+     NV_SPIN_LOCK_INIT(&km_lock);
+ #endif
+ 
+-    nvidia_stack_t_cache = NV_KMEM_CACHE_CREATE(nvidia_stack_cache_name,
++    nvidia_stack_t_cache = NV_KMEM_CACHE_CREATE_USERCOPY(nvidia_stack_cache_name,
+                                                 nvidia_stack_t);
+     if (nvidia_stack_t_cache == NULL)
+     {
+diff -urp work.orig/kernel/nvidia/nv-chrdev.c work/kernel/nvidia/nv-chrdev.c
+--- work.orig/kernel/nvidia/nv-chrdev.c	2016-11-27 21:56:50.395629748 +0100
++++ work/kernel/nvidia/nv-chrdev.c	2016-11-27 21:54:23.971706350 +0100
+@@ -20,8 +20,6 @@ int nv_register_chrdev(void *param)
+ {
+     nvidia_module_t *module = (nvidia_module_t *)param;
+ 
+-    module->instance = nv_module_instance;
+-
+     return (nvidia_register_module(module));
+ }
+ 
+diff -urp work.orig/kernel/nvidia/nv-instance.c work/kernel/nvidia/nv-instance.c
+--- work.orig/kernel/nvidia/nv-instance.c	2016-11-27 21:56:50.395629748 +0100
++++ work/kernel/nvidia/nv-instance.c	2016-11-27 21:54:23.971706350 +0100
+@@ -51,6 +51,7 @@ struct pci_driver nv_pci_driver = {
+ nvidia_module_t nv_fops = {
+     .owner       = THIS_MODULE,
+     .module_name = MODULE_NAME,
++    .instance    = MODULE_INSTANCE_NUMBER,
+     .open        = nvidia_open,
+     .close       = nvidia_close,
+     .ioctl       = nvidia_ioctl,
+diff -urp work.orig/kernel/nvidia/nv-mmap.c work/kernel/nvidia/nv-mmap.c
+--- work.orig/kernel/nvidia/nv-mmap.c	2016-11-27 21:56:50.395629748 +0100
++++ work/kernel/nvidia/nv-mmap.c	2016-11-27 21:54:23.971706350 +0100
+@@ -102,12 +102,12 @@ nvidia_vma_release(struct vm_area_struct
+ }
+ 
+ #if defined(NV_VM_OPERATIONS_STRUCT_HAS_ACCESS)
+-static int
++static ssize_t
+ nvidia_vma_access(
+     struct vm_area_struct *vma,
+     unsigned long addr,
+     void *buffer,
+-    int length,
++    size_t length,
+     int write
+ )
+ {
+diff -urp work.orig/kernel/nvidia/nv-modeset-interface.c work/kernel/nvidia/nv-modeset-interface.c
+--- work.orig/kernel/nvidia/nv-modeset-interface.c	2016-11-27 21:56:50.395629748 +0100
++++ work/kernel/nvidia/nv-modeset-interface.c	2016-11-27 21:54:23.971706350 +0100
+@@ -100,10 +100,9 @@ static NvU32 nvidia_modeset_enumerate_gp
+     return count;
+ }
+ 
+-NV_STATUS nvidia_get_rm_ops(nvidia_modeset_rm_ops_t *rm_ops)
++NV_STATUS nvidia_get_rm_ops(const nvidia_modeset_rm_ops_t **rm_ops, const char **version_string)
+ {
+-    const nvidia_modeset_rm_ops_t local_rm_ops = {
+-        .version_string = NV_VERSION_STRING,
++    static const nvidia_modeset_rm_ops_t local_rm_ops = {
+         .system_info    = {
+             .allow_write_combining = NV_FALSE,
+         },
+@@ -116,17 +115,26 @@ NV_STATUS nvidia_get_rm_ops(nvidia_modes
+         .set_callbacks  = nvidia_modeset_set_callbacks,
+     };
+ 
+-    if (strcmp(rm_ops->version_string, NV_VERSION_STRING) != 0)
++    static const nvidia_modeset_rm_ops_t local_rm_ops_wc = {
++        .system_info    = {
++            .allow_write_combining = NV_TRUE,
++        },
++        .alloc_stack    = nvidia_modeset_rm_ops_alloc_stack,
++        .free_stack     = nvidia_modeset_rm_ops_free_stack,
++        .enumerate_gpus = nvidia_modeset_enumerate_gpus,
++        .open_gpu       = nvidia_dev_get,
++        .close_gpu      = nvidia_dev_put,
++        .op             = rm_kernel_rmapi_op, /* provided by nv-kernel.o */
++        .set_callbacks  = nvidia_modeset_set_callbacks,
++    };
++
++    if (strcmp(*version_string, NV_VERSION_STRING) != 0)
+     {
+-        rm_ops->version_string = NV_VERSION_STRING;
++        *version_string = NV_VERSION_STRING;
+         return NV_ERR_GENERIC;
+     }
+ 
+-    *rm_ops = local_rm_ops;
+-
+-    if (NV_ALLOW_WRITE_COMBINING(NV_MEMORY_TYPE_FRAMEBUFFER)) {
+-        rm_ops->system_info.allow_write_combining = NV_TRUE;
+-    }
++    *rm_ops = NV_ALLOW_WRITE_COMBINING(NV_MEMORY_TYPE_FRAMEBUFFER) ? &local_rm_ops_wc : &local_rm_ops;
+ 
+     return NV_OK;
+ }
+diff -urp work.orig/kernel/nvidia-drm/nvidia-drm-drv.c work/kernel/nvidia-drm/nvidia-drm-drv.c
+--- work.orig/kernel/nvidia-drm/nvidia-drm-drv.c	2016-11-27 21:56:50.395629748 +0100
++++ work/kernel/nvidia-drm/nvidia-drm-drv.c	2016-11-27 21:54:23.971706350 +0100
+@@ -594,7 +594,7 @@ static const struct drm_ioctl_desc nv_dr
+                       DRM_CONTROL_ALLOW|DRM_RENDER_ALLOW|DRM_UNLOCKED),
+ };
+ 
+-static struct drm_driver nv_drm_driver = {
++static drm_driver_no_const nv_drm_driver __read_only = {
+ 
+     .driver_features        = DRIVER_GEM | DRIVER_PRIME | DRIVER_RENDER,
+ 
+@@ -654,6 +654,7 @@ static void nvidia_update_drm_driver_fea
+         return;
+     }
+ 
++    pax_open_kernel();
+     nv_drm_driver.driver_features |= DRIVER_MODESET | DRIVER_ATOMIC;
+ 
+     nv_drm_driver.master_set       = nvidia_drm_master_set;
+@@ -664,6 +665,7 @@ static void nvidia_update_drm_driver_fea
+     nv_drm_driver.dumb_destroy     = drm_gem_dumb_destroy;
+ 
+     nv_drm_driver.gem_vm_ops       = &nv_drm_gem_vma_ops;
++    pax_close_kernel();
+ #endif /* NV_DRM_ATOMIC_MODESET_AVAILABLE */
+ }
+ 
+diff -urp work.orig/kernel/nvidia-modeset/nvidia-modeset-linux.c work/kernel/nvidia-modeset/nvidia-modeset-linux.c
+--- work.orig/kernel/nvidia-modeset/nvidia-modeset-linux.c	2016-11-27 21:56:50.395629748 +0100
++++ work/kernel/nvidia-modeset/nvidia-modeset-linux.c	2016-11-27 21:54:23.971706350 +0100
+@@ -335,29 +335,28 @@ static void nvkms_resume(NvU32 gpuId)
+  * Interface with resman.
+  *************************************************************************/
+ 
+-static nvidia_modeset_rm_ops_t __rm_ops = { 0 };
++static const nvidia_modeset_rm_ops_t *__rm_ops;
+ static nvidia_modeset_callbacks_t nvkms_rm_callbacks = {
+-    nvkms_suspend,
+-    nvkms_resume
++    .suspend = nvkms_suspend,
++    .resume = nvkms_resume
+ };
+ 
+ static int nvkms_alloc_rm(void)
+ {
+     NV_STATUS nvstatus;
+     int ret;
++    const char *version_string = NV_VERSION_STRING;
+ 
+-    __rm_ops.version_string = NV_VERSION_STRING;
+-
+-    nvstatus = nvidia_get_rm_ops(&__rm_ops);
++    nvstatus = nvidia_get_rm_ops(&__rm_ops, &version_string);
+ 
+     if (nvstatus != NV_OK) {
+         printk(KERN_ERR NVKMS_LOG_PREFIX "Version mismatch: "
+                "nvidia.ko(%s) nvidia-modeset.ko(%s)\n",
+-               __rm_ops.version_string, NV_VERSION_STRING);
++               version_string, NV_VERSION_STRING);
+         return -EINVAL;
+     }
+ 
+-    ret = __rm_ops.set_callbacks(&nvkms_rm_callbacks);
++    ret = __rm_ops->set_callbacks(&nvkms_rm_callbacks);
+     if (ret < 0) {
+         printk(KERN_ERR NVKMS_LOG_PREFIX "Failed to register callbacks\n");
+         return ret;
+@@ -368,20 +367,20 @@ static int nvkms_alloc_rm(void)
+ 
+ static void nvkms_free_rm(void)
+ {
+-    __rm_ops.set_callbacks(NULL);
++    __rm_ops->set_callbacks(NULL);
+ }
+ 
+ void NVKMS_API_CALL nvkms_call_rm(void *ops)
+ {
+     nvidia_modeset_stack_ptr stack = NULL;
+ 
+-    if (__rm_ops.alloc_stack(&stack) != 0) {
++    if (__rm_ops->alloc_stack(&stack) != 0) {
+         return;
+     }
+ 
+-    __rm_ops.op(stack, ops);
++    __rm_ops->op(stack, ops);
+ 
+-    __rm_ops.free_stack(stack);
++    __rm_ops->free_stack(stack);
+ }
+ 
+ /*************************************************************************
+@@ -705,13 +704,13 @@ NvBool NVKMS_API_CALL nvkms_open_gpu(NvU
+     nvidia_modeset_stack_ptr stack = NULL;
+     NvBool ret;
+ 
+-    if (__rm_ops.alloc_stack(&stack) != 0) {
++    if (__rm_ops->alloc_stack(&stack) != 0) {
+         return NV_FALSE;
+     }
+ 
+-    ret = __rm_ops.open_gpu(gpuId, stack) == 0;
++    ret = __rm_ops->open_gpu(gpuId, stack) == 0;
+ 
+-    __rm_ops.free_stack(stack);
++    __rm_ops->free_stack(stack);
+ 
+     return ret;
+ }
+@@ -720,23 +719,23 @@ void NVKMS_API_CALL nvkms_close_gpu(NvU3
+ {
+     nvidia_modeset_stack_ptr stack = NULL;
+ 
+-    if (__rm_ops.alloc_stack(&stack) != 0) {
++    if (__rm_ops->alloc_stack(&stack) != 0) {
+         return;
+     }
+ 
+-    __rm_ops.close_gpu(gpuId, stack);
++    __rm_ops->close_gpu(gpuId, stack);
+ 
+-    __rm_ops.free_stack(stack);
++    __rm_ops->free_stack(stack);
+ }
+ 
+ NvU32 NVKMS_API_CALL nvkms_enumerate_gpus(nv_gpu_info_t *gpu_info)
+ {
+-    return __rm_ops.enumerate_gpus(gpu_info);
++    return __rm_ops->enumerate_gpus(gpu_info);
+ }
+ 
+ NvBool NVKMS_API_CALL nvkms_allow_write_combining(void)
+ {
+-    return __rm_ops.system_info.allow_write_combining;
++    return __rm_ops->system_info.allow_write_combining;
+ }
+ 
+ /*************************************************************************
+diff -urp work.orig/kernel/nvidia-uvm/uvm8_global.c work/kernel/nvidia-uvm/uvm8_global.c
+--- work.orig/kernel/nvidia-uvm/uvm8_global.c	2016-11-27 21:56:50.399642330 +0100
++++ work/kernel/nvidia-uvm/uvm8_global.c	2016-11-27 21:54:23.975709978 +0100
+@@ -35,17 +35,17 @@
+ #include "nv_uvm_interface.h"
+ 
+ uvm_global_t g_uvm_global;
+-static struct UvmOpsUvmEvents g_exported_uvm8_ops;
++static struct UvmOpsUvmEvents g_exported_uvm8_ops = {
++    .startDevice = NULL,
++    .stopDevice  = NULL,
++    .isrTopHalf  = uvm8_isr_top_half,
++};
+ static bool g_ops_registered = false;
+ 
+ static NV_STATUS uvm8_register_callbacks(void)
+ {
+     NV_STATUS status = NV_OK;
+ 
+-    g_exported_uvm8_ops.startDevice = NULL;
+-    g_exported_uvm8_ops.stopDevice  = NULL;
+-    g_exported_uvm8_ops.isrTopHalf  = uvm8_isr_top_half;
+-
+     // Register the UVM callbacks with the main GPU driver:
+     status = uvm_rm_locked_call(nvUvmInterfaceRegisterUvmCallbacks(&g_exported_uvm8_ops));
+     if (status != NV_OK)
+diff -urp work.orig/kernel/nvidia-uvm/uvm8_gpu_semaphore.c work/kernel/nvidia-uvm/uvm8_gpu_semaphore.c
+--- work.orig/kernel/nvidia-uvm/uvm8_gpu_semaphore.c	2016-11-27 21:56:50.399642330 +0100
++++ work/kernel/nvidia-uvm/uvm8_gpu_semaphore.c	2016-11-27 21:54:23.975709978 +0100
+@@ -368,7 +368,7 @@ void uvm_gpu_semaphore_set_payload(uvm_g
+     // being optimized out on non-SMP configs (we need them for interacting with
+     // the GPU correctly even on non-SMP).
+     mb();
+-    ACCESS_ONCE(*semaphore->payload) = payload;
++    ACCESS_ONCE_RW(*semaphore->payload) = payload;
+ }
+ 
+ // This function is intended to catch channels which have been left dangling in
+diff -urp work.orig/kernel/nvidia-uvm/uvm8_hal.h work/kernel/nvidia-uvm/uvm8_hal.h
+--- work.orig/kernel/nvidia-uvm/uvm8_hal.h	2016-11-27 21:56:50.399642330 +0100
++++ work/kernel/nvidia-uvm/uvm8_hal.h	2016-11-27 21:54:23.975709978 +0100
+@@ -316,7 +316,7 @@ typedef struct
+         // fault_buffer_ops: id is a hardware class
+         uvm_fault_buffer_hal_t fault_buffer_ops;
+     } u;
+-} uvm_hal_class_ops_t;
++} __do_const uvm_hal_class_ops_t;
+ 
+ // When UVM next support is enabled support for future chips in the hal is
+ // enabled by providing additional hal table entries below.
+diff -urp work.orig/kernel/nvidia-uvm/uvm8_mmu.h work/kernel/nvidia-uvm/uvm8_mmu.h
+--- work.orig/kernel/nvidia-uvm/uvm8_mmu.h	2016-11-27 21:56:50.399642330 +0100
++++ work/kernel/nvidia-uvm/uvm8_mmu.h	2016-11-27 21:54:23.975709978 +0100
+@@ -24,7 +24,6 @@
+ #ifndef __UVM8_MMU_H__
+ #define __UVM8_MMU_H__
+ 
+-#include "uvm8_forward_decl.h"
+ #include "uvm8_hal_types.h"
+ #include "uvm8_pmm_gpu.h"
+ #include "uvmtypes.h"
+diff -urp work.orig/kernel/nvidia-uvm/uvm_common.c work/kernel/nvidia-uvm/uvm_common.c
+--- work.orig/kernel/nvidia-uvm/uvm_common.c	2016-11-27 21:56:50.399642330 +0100
++++ work/kernel/nvidia-uvm/uvm_common.c	2016-11-27 21:54:23.975709978 +0100
+@@ -42,7 +42,6 @@
+ #define UVM_SPIN_LOOP_PRINT_TIMEOUT_SEC     30ULL
+ 
+ static dev_t g_uvmBaseDev;
+-struct UvmOpsUvmEvents g_exportedUvmOps;
+ 
+ static char* uvm_driver_mode = "8";
+ 
+diff -urp work.orig/kernel/nvidia-uvm/uvm_full_fault_buffer.h work/kernel/nvidia-uvm/uvm_full_fault_buffer.h
+--- work.orig/kernel/nvidia-uvm/uvm_full_fault_buffer.h	2016-11-27 21:56:50.399642330 +0100
++++ work/kernel/nvidia-uvm/uvm_full_fault_buffer.h	2016-11-27 21:54:23.975709978 +0100
+@@ -31,6 +31,7 @@
+ #define _UVM_FULL_FAULT_BUFFER_H_
+ 
+ #include "uvmtypes.h"
++#include "linux/compiler.h"
+ 
+ #define MAXWELL_FAULT_BUFFER_A (0xb069)
+ #define MEM_RD32(a) (*(const volatile NvU32 *)(a)) 
+@@ -303,7 +304,7 @@ typedef struct
+     NvUvmControlPrefetch_t              controlPrefetch;
+     NvUvmTestFaultBufferOverflow_t      testFaultBufferOverflow;
+     NvUvmClearFaultBufferOverflow_t     clearFaultBufferOverflow;
+-} UvmFaultBufferOps;
++} __no_const UvmFaultBufferOps;
+ 
+ /******************************************************************************
+     uvmfull_fault_buffer_init
+diff -urp work.orig/kernel/nvidia-uvm/uvm_linux.h work/kernel/nvidia-uvm/uvm_linux.h
+--- work.orig/kernel/nvidia-uvm/uvm_linux.h	2016-11-27 21:56:50.399642330 +0100
++++ work/kernel/nvidia-uvm/uvm_linux.h	2016-11-27 21:54:23.975709978 +0100
+@@ -420,7 +420,7 @@ static inline NvU64 NV_GETTIME(void)
+ 
+ // WRITE_ONCE/READ_ONCE have incompatible definitions across versions, which produces warnings.
+ // Therefore, we define our own macros
+-#define UVM_WRITE_ONCE(x, val) (ACCESS_ONCE(x) = (val))
++#define UVM_WRITE_ONCE(x, val) (ACCESS_ONCE_RW(x) = (val))
+ #define UVM_READ_ONCE(x) ACCESS_ONCE(x)
+ 
+ // Added in 3.11

+ 11 - 0
x11-drivers/nvidia-drivers/files/nvidia-drivers-375.39-profiles-rc.patch

@@ -0,0 +1,11 @@
+--- a/nvidia-application-profiles-375.39-rc
++++ b/nvidia-application-profiles-375.39-rc
+@@ -48,7 +48,7 @@
+         {
+           "name" : "NoEnforceShaderInputOutputMatching",
+           "settings" : [ "GLShaderPortabilityWarnings", false ]
+-        },
++        }
+     ],
+     "rules" : [
+         {

+ 11 - 0
x11-drivers/nvidia-drivers/files/nvidia-drivers-375.66-profiles-rc.patch

@@ -0,0 +1,11 @@
+--- a/nvidia-application-profiles-375.66-rc
++++ b/nvidia-application-profiles-375.66-rc
+@@ -48,7 +48,7 @@
+         {
+           "name" : "NoEnforceShaderInputOutputMatching",
+           "settings" : [ "GLShaderPortabilityWarnings", false ]
+-        },
++        }
+     ],
+     "rules" : [
+         {

+ 17 - 0
x11-drivers/nvidia-drivers/files/nvidia-drivers-pax-const.patch

@@ -0,0 +1,17 @@
+Binary files kernel.orig/.nv-procfs.c.swp and kernel/.nv-procfs.c.swp differ
+diff -urp kernel.orig/nv-procfs.c kernel/nv-procfs.c
+--- kernel.orig/nv-procfs.c	2011-07-13 03:29:30.000000000 +0200
++++ kernel/nv-procfs.c	2011-07-19 15:45:27.982993911 +0200
+@@ -707,8 +707,10 @@ int nv_register_procfs(void)
+      * However, in preparation for this, we need to preserve
+      * the procfs read() and write() operations.
+      */
+-    nv_procfs_registry_fops.read = entry->proc_fops->read;
+-    nv_procfs_registry_fops.write = entry->proc_fops->write;
++    pax_open_kernel();
++    *(void **)&nv_procfs_registry_fops.read = entry->proc_fops->read;
++    *(void **)&nv_procfs_registry_fops.write = entry->proc_fops->write;
++    pax_close_kernel();
+ 
+     entry = NV_CREATE_PROC_FILE("registry", proc_nvidia,
+         nv_procfs_read_registry,

+ 54 - 0
x11-drivers/nvidia-drivers/files/nvidia-drivers-pax-usercopy.patch

@@ -0,0 +1,54 @@
+diff -urp kernel.orig/nv.c kernel/nv.c
+--- kernel.orig/nv.c	2011-09-24 02:32:09.000000000 +0200
++++ kernel/nv.c	2011-10-05 19:13:41.474242252 +0200
+@@ -1105,7 +1105,7 @@ static int __init nvidia_init_module(voi
+     NV_SPIN_LOCK_INIT(&km_lock);
+ #endif
+ 
+-    NV_KMEM_CACHE_CREATE(nv_stack_t_cache, "nv_stack_t", nv_stack_t);
++    NV_KMEM_CACHE_CREATE(nv_stack_t_cache, "nv_stack_t", nv_stack_t, SLAB_USERCOPY);
+     if (nv_stack_t_cache == NULL)
+     {
+         nv_printf(NV_DBG_ERRORS, "NVRM: stack cache allocation failed!\n");
+@@ -1220,7 +1220,7 @@ static int __init nvidia_init_module(voi
+     }
+ #endif
+ 
+-    NV_KMEM_CACHE_CREATE(nv_pte_t_cache, "nv_pte_t", nv_pte_t);
++    NV_KMEM_CACHE_CREATE(nv_pte_t_cache, "nv_pte_t", nv_pte_t, 0);
+     if (nv_pte_t_cache == NULL)
+     {
+         rc = -ENOMEM;
+@@ -1229,7 +1229,7 @@ static int __init nvidia_init_module(voi
+     }
+ 
+     NV_KMEM_CACHE_CREATE(nvidia_p2p_page_t_cache, "nvidia_p2p_page_t",
+-            nvidia_p2p_page_t);
++            nvidia_p2p_page_t, 0);
+     if (nvidia_p2p_page_t_cache == NULL)
+     {
+         rc = -ENOMEM;
+diff -urp kernel.orig/nv-linux.h kernel/nv-linux.h
+--- kernel.orig/nv-linux.h	2011-09-24 02:32:09.000000000 +0200
++++ kernel/nv-linux.h	2011-10-05 19:14:42.522238996 +0200
+@@ -695,16 +695,16 @@ extern nv_spinlock_t km_lock;
+ 
+ #if defined(NV_KMEM_CACHE_CREATE_PRESENT)
+ #if (NV_KMEM_CACHE_CREATE_ARGUMENT_COUNT == 6)
+-#define NV_KMEM_CACHE_CREATE(kmem_cache, name, type)            \
++#define NV_KMEM_CACHE_CREATE(kmem_cache, name, type, flags)     \
+     {                                                           \
+         kmem_cache = kmem_cache_create(name, sizeof(type),      \
+-                        0, 0, NULL, NULL);                      \
++                        0, flags, NULL, NULL);                  \
+     }
+ #elif (NV_KMEM_CACHE_CREATE_ARGUMENT_COUNT == 5)
+-#define NV_KMEM_CACHE_CREATE(kmem_cache, name, type)            \
++#define NV_KMEM_CACHE_CREATE(kmem_cache, name, type, flags)     \
+     {                                                           \
+         kmem_cache = kmem_cache_create(name, sizeof(type),      \
+-                        0, 0, NULL);                            \
++                        0, flags, NULL);                        \
+     }
+ #else
+ #error "NV_KMEM_CACHE_CREATE_ARGUMENT_COUNT value unrecognized!"

+ 8 - 0
x11-drivers/nvidia-drivers/files/nvidia-persistenced.conf

@@ -0,0 +1,8 @@
+# run-time configuration file for /etc/init.d/nvidia-persistenced
+
+# NVPD_USER: The user nvidia-persistenced is intended to run for
+NVPD_USER=""
+
+# ARGS: Additional arguments to set the default persistence mode
+# (see nvidia-persistenced(1))
+ARGS=""

+ 24 - 0
x11-drivers/nvidia-drivers/files/nvidia-persistenced.init

@@ -0,0 +1,24 @@
+#!/sbin/openrc-run
+# Copyright 1999-2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+pidfile="/var/run/nvidia-persistenced/nvidia-persistenced.pid"
+
+start() {
+	if ! [ "${NVPD_USER}x" = x ]; then
+		ebegin "Starting nvidia-persistenced for ${NVPD_USER}"
+		NVPD_USER_ARG="--user ${NVPD_USER}"
+	else
+		ebegin "Starting nvidia-persistenced"
+	fi
+	start-stop-daemon --start --quiet --pidfile ${pidfile} \
+		--background --exec /opt/bin/nvidia-persistenced \
+		-- ${NVPD_USER_ARG} ${ARGS}
+	eend $?	
+}
+
+stop() {
+	ebegin "Stopping nvidia-persistenced"
+	start-stop-daemon --stop --quiet --pidfile ${pidfile}
+	eend $?
+}

+ 3 - 0
x11-drivers/nvidia-drivers/files/nvidia-rmmod.conf

@@ -0,0 +1,3 @@
+# Nvidia UVM support
+
+remove nvidia modprobe -r --ignore-remove nvidia-drm nvidia-modeset nvidia-uvm nvidia

+ 7 - 0
x11-drivers/nvidia-drivers/files/nvidia-settings.desktop

@@ -0,0 +1,7 @@
+[Desktop Entry]
+Type=Application
+Name=NVIDIA X Server Settings
+Comment=Configure NVIDIA X Server Settings
+Exec=/usr/bin/nvidia-settings
+Icon=nvidia-settings
+Categories=System;Settings;

+ 24 - 0
x11-drivers/nvidia-drivers/files/nvidia-smi.init

@@ -0,0 +1,24 @@
+#!/sbin/openrc-run
+# Copyright 1999-2013 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+pidfile="/run/nvidia-smi.pid"
+
+depend() {
+    after modules
+}
+
+start() {
+	ebegin "Starting NVIDIA System Management Interface"
+	rm -f ${pidfile}
+	start-stop-daemon --start --quiet --pidfile ${pidfile} \
+		--make-pidfile --background --exec /opt/bin/nvidia-smi -- \
+		-q -l 300
+	eend $?
+}
+
+stop() {
+	ebegin "Stopping NVIDIA System Management Interface"
+	start-stop-daemon --stop --quiet --pidfile ${pidfile}
+	eend $?
+}

+ 17 - 0
x11-drivers/nvidia-drivers/files/nvidia-udev.sh

@@ -0,0 +1,17 @@
+#!/bin/sh
+
+if [ $# -ne 1 ]; then
+	echo "Invalid args" >&2
+	exit 1
+fi
+
+case $1 in
+	add|ADD)
+		/opt/bin/nvidia-smi > /dev/null
+		;;
+	remove|REMOVE)
+		rm -f /dev/nvidia*
+		;;
+esac
+
+exit 0

+ 20 - 0
x11-drivers/nvidia-drivers/files/nvidia-udev.sh-r1

@@ -0,0 +1,20 @@
+#!/bin/sh
+
+if [ $# -ne 1 ]; then
+	echo "Invalid args" >&2
+	exit 1
+fi
+
+case $1 in
+	add|ADD)
+		#hopefully this prevents infinite loops like bug #454740
+		if lsmod | grep -iq nvidia; then
+			/opt/bin/nvidia-smi > /dev/null
+		fi
+		;;
+	remove|REMOVE)
+		rm -f /dev/nvidia*
+		;;
+esac
+
+exit 0

+ 3 - 0
x11-drivers/nvidia-drivers/files/nvidia-uvm.conf

@@ -0,0 +1,3 @@
+# Nvidia UVM support
+
+remove nvidia modprobe -r --ignore-remove nvidia-uvm nvidia

+ 6 - 0
x11-drivers/nvidia-drivers/files/nvidia.udev-rule

@@ -0,0 +1,6 @@
+ACTION=="add", DEVPATH=="/module/nvidia", SUBSYSTEM=="module", RUN+="nvidia-udev.sh $env{ACTION}"
+# Previously the ACTION was "add|remove" but one user on bug #376527 had a
+# problem until he recompiled udev-171-r5, which is one of the versions I
+# tested with and it was fine. I'm breaking the rules out just to be safe
+# so someone else doesn't have an issue
+ACTION=="remove", DEVPATH=="/module/nvidia", SUBSYSTEM=="module", RUN+="nvidia-udev.sh $env{ACTION}"

+ 519 - 0
x11-drivers/nvidia-drivers/nvidia-drivers-340.102.ebuild

@@ -0,0 +1,519 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+inherit eutils flag-o-matic linux-info linux-mod multilib-minimal nvidia-driver \
+	portability toolchain-funcs unpacker user udev
+
+NV_URI="http://http.download.nvidia.com/XFree86/"
+X86_NV_PACKAGE="NVIDIA-Linux-x86-${PV}"
+AMD64_NV_PACKAGE="NVIDIA-Linux-x86_64-${PV}"
+X86_FBSD_NV_PACKAGE="NVIDIA-FreeBSD-x86-${PV}"
+AMD64_FBSD_NV_PACKAGE="NVIDIA-FreeBSD-x86_64-${PV}"
+
+DESCRIPTION="NVIDIA Accelerated Graphics Driver"
+HOMEPAGE="http://www.nvidia.com/ http://www.nvidia.com/Download/Find.aspx"
+SRC_URI="
+	amd64-fbsd? ( ${NV_URI}FreeBSD-x86_64/${PV}/${AMD64_FBSD_NV_PACKAGE}.tar.gz )
+	amd64? ( ${NV_URI}Linux-x86_64/${PV}/${AMD64_NV_PACKAGE}.run )
+	x86-fbsd? ( ${NV_URI}FreeBSD-x86/${PV}/${X86_FBSD_NV_PACKAGE}.tar.gz )
+	x86? ( ${NV_URI}Linux-x86/${PV}/${X86_NV_PACKAGE}.run )
+	tools? ( ${NV_URI}nvidia-settings/nvidia-settings-${PV}.tar.bz2 )
+"
+
+LICENSE="GPL-2 NVIDIA-r2"
+SLOT="0/${PV%.*}"
+KEYWORDS="-* amd64 x86 ~amd64-fbsd ~x86-fbsd"
+IUSE="acpi multilib kernel_FreeBSD kernel_linux pax_kernel static-libs +tools +X uvm"
+RESTRICT="bindist mirror"
+EMULTILIB_PKG="true"
+
+COMMON="
+	app-eselect/eselect-opencl
+	kernel_linux? ( >=sys-libs/glibc-2.6.1 )
+	tools? (
+		dev-libs/atk
+		dev-libs/glib:2
+		dev-libs/jansson
+		x11-libs/gdk-pixbuf[X]
+		>=x11-libs/gtk+-2.4:2
+		x11-libs/libX11
+		x11-libs/libXext
+		x11-libs/pango[X]
+	)
+	X? (
+		>=app-eselect/eselect-opengl-1.0.9
+	)
+"
+DEPEND="
+	${COMMON}
+	app-arch/xz-utils
+	kernel_linux? ( virtual/linux-sources )
+"
+RDEPEND="
+	${COMMON}
+	acpi? ( sys-power/acpid )
+	tools? ( !media-video/nvidia-settings )
+	X? (
+		<x11-base/xorg-server-1.19.99:=
+		>=x11-libs/libvdpau-0.3-r1
+		sys-libs/zlib[${MULTILIB_USEDEP}]
+		multilib? (
+			>=x11-libs/libX11-1.6.2[${MULTILIB_USEDEP}]
+			>=x11-libs/libXext-1.3.2[${MULTILIB_USEDEP}]
+		)
+	)
+"
+
+REQUIRED_USE="tools? ( X )"
+
+QA_PREBUILT="opt/* usr/lib*"
+
+S=${WORKDIR}/
+
+pkg_pretend() {
+	if use amd64 && has_multilib_profile && \
+		[ "${DEFAULT_ABI}" != "amd64" ]; then
+		eerror "This ebuild doesn't currently support changing your default ABI"
+		die "Unexpected \${DEFAULT_ABI} = ${DEFAULT_ABI}"
+	fi
+
+	if use kernel_linux && kernel_is ge 4 11; then
+		ewarn "Gentoo supports kernels which are supported by NVIDIA"
+		ewarn "which are limited to the following kernels:"
+		ewarn "<sys-kernel/gentoo-sources-4.11"
+		ewarn "<sys-kernel/vanilla-sources-4.11"
+		ewarn ""
+		ewarn "You are free to utilize eapply_user to provide whatever"
+		ewarn "support you feel is appropriate, but will not receive"
+		ewarn "support as a result of those changes."
+		ewarn ""
+		ewarn "Do not file a bug report about this."
+		ewarn ""
+	fi
+
+	# Since Nvidia ships many different series of drivers, we need to give the user
+	# some kind of guidance as to what version they should install. This tries
+	# to point the user in the right direction but can't be perfect. check
+	# nvidia-driver.eclass
+	nvidia-driver-check-warning
+
+	# Kernel features/options to check for
+	CONFIG_CHECK="~ZONE_DMA ~MTRR ~SYSVIPC ~!LOCKDEP"
+	use x86 && CONFIG_CHECK+=" ~HIGHMEM ~X86_PAT"
+
+	# Now do the above checks
+	use kernel_linux && check_extra_config
+}
+
+pkg_setup() {
+	# try to turn off distcc and ccache for people that have a problem with it
+	export DISTCC_DISABLE=1
+	export CCACHE_DISABLE=1
+
+	if use kernel_linux; then
+		MODULE_NAMES="nvidia(video:${S}/kernel)"
+		use uvm && MODULE_NAMES+=" nvidia-uvm(video:${S}/kernel/uvm)"
+
+		# This needs to run after MODULE_NAMES (so that the eclass checks
+		# whether the kernel supports loadable modules) but before BUILD_PARAMS
+		# is set (so that KV_DIR is populated).
+		linux-mod_pkg_setup
+
+		BUILD_PARAMS="IGNORE_CC_MISMATCH=yes V=1 SYSSRC=${KV_DIR} \
+		SYSOUT=${KV_OUT_DIR} CC=$(tc-getBUILD_CC)"
+
+		# linux-mod_src_compile calls set_arch_to_kernel, which
+		# sets the ARCH to x86 but NVIDIA's wrapping Makefile
+		# expects x86_64 or i386 and then converts it to x86
+		# later on in the build process
+		BUILD_FIXES="ARCH=$(uname -m | sed -e 's/i.86/i386/')"
+	fi
+
+	# set variables to where files are in the package structure
+	if use kernel_FreeBSD; then
+		use x86-fbsd   && S="${WORKDIR}/${X86_FBSD_NV_PACKAGE}"
+		use amd64-fbsd && S="${WORKDIR}/${AMD64_FBSD_NV_PACKAGE}"
+		NV_DOC="${S}/doc"
+		NV_OBJ="${S}/obj"
+		NV_SRC="${S}/src"
+		NV_MAN="${S}/x11/man"
+		NV_X11="${S}/obj"
+		NV_SOVER=1
+	elif use kernel_linux; then
+		NV_DOC="${S}"
+		NV_OBJ="${S}"
+		NV_SRC="${S}/kernel"
+		NV_MAN="${S}"
+		NV_X11="${S}"
+		NV_SOVER=${PV}
+	else
+		die "Could not determine proper NVIDIA package"
+	fi
+}
+
+src_prepare() {
+	# Please add a brief description for every added patch
+
+	if use kernel_linux; then
+		if kernel_is lt 2 6 9 ; then
+			eerror "You must build this against 2.6.9 or higher kernels."
+		fi
+
+		# If greater than 2.6.5 use M= instead of SUBDIR=
+#		convert_to_m "${NV_SRC}"/Makefile.kbuild
+	fi
+	epatch "${FILESDIR}"/NVIDIA-4.11.patch
+
+	if use pax_kernel; then
+		ewarn "Using PAX patches is not supported. You will be asked to"
+		ewarn "use a standard kernel should you have issues. Should you"
+		ewarn "need support with these patches, contact the PaX team."
+		eapply "${FILESDIR}"/${PN}-331.13-pax-usercopy.patch
+		eapply "${FILESDIR}"/${PN}-337.12-pax-constify.patch
+	fi
+
+	# Allow user patches so they can support RC kernels and whatever else
+	eapply_user
+}
+
+src_compile() {
+	# This is already the default on Linux, as there's no toplevel Makefile, but
+	# on FreeBSD there's one and triggers the kernel module build, as we install
+	# it by itself, pass this.
+
+	cd "${NV_SRC}"
+	if use kernel_FreeBSD; then
+		MAKE="$(get_bmake)" CFLAGS="-Wno-sign-compare" emake CC="$(tc-getCC)" \
+			LD="$(tc-getLD)" LDFLAGS="$(raw-ldflags)" || die
+	elif use kernel_linux; then
+		use uvm && MAKEOPTS=-j1
+		linux-mod_src_compile
+	fi
+
+	if use tools; then
+		emake -C "${S}"/nvidia-settings-${PV}/src/libXNVCtrl clean
+		emake -C "${S}"/nvidia-settings-${PV}/src/libXNVCtrl \
+			AR="$(tc-getAR)" \
+			CC="$(tc-getCC)" \
+			RANLIB="$(tc-getRANLIB)" \
+			libXNVCtrl.a
+		emake -C "${S}"/nvidia-settings-${PV}/src \
+			AR="$(tc-getAR)" \
+			CC="$(tc-getCC)" \
+			LD="$(tc-getCC)" \
+			LIBDIR="$(get_libdir)" \
+			NVML_ENABLED=0 \
+			NV_USE_BUNDLED_LIBJANSSON=0 \
+			NV_VERBOSE=1 \
+			RANLIB="$(tc-getRANLIB)" \
+			STRIP_CMD=true
+	fi
+}
+
+# Install nvidia library:
+# the first parameter is the library to install
+# the second parameter is the provided soversion
+# the third parameter is the target directory if its not /usr/lib
+donvidia() {
+	# Full path to library minus SOVER
+	MY_LIB="$1"
+
+	# SOVER to use
+	MY_SOVER="$2"
+
+	# Where to install
+	MY_DEST="$3"
+
+	if [[ -z "${MY_DEST}" ]]; then
+		MY_DEST="/usr/$(get_libdir)"
+		action="dolib.so"
+	else
+		exeinto ${MY_DEST}
+		action="doexe"
+	fi
+
+	# Get just the library name
+	libname=$(basename $1)
+
+	# Install the library with the correct SOVER
+	${action} ${MY_LIB}.${MY_SOVER} || \
+		die "failed to install ${libname}"
+
+	# If SOVER wasn't 1, then we need to create a .1 symlink
+	if [[ "${MY_SOVER}" != "1" ]]; then
+		dosym ${libname}.${MY_SOVER} \
+			${MY_DEST}/${libname}.1 || \
+			die "failed to create ${libname} symlink"
+	fi
+
+	# Always create the symlink from the raw lib to the .1
+	dosym ${libname}.1 \
+		${MY_DEST}/${libname} || \
+		die "failed to create ${libname} symlink"
+}
+
+src_install() {
+	if use kernel_linux; then
+		linux-mod_src_install
+
+		# Add the aliases
+		# This file is tweaked with the appropriate video group in
+		# pkg_preinst, see bug #491414
+		insinto /etc/modprobe.d
+		newins "${FILESDIR}"/nvidia-169.07 nvidia.conf
+		use uvm && doins "${FILESDIR}"/nvidia-uvm.conf
+
+		# Ensures that our device nodes are created when not using X
+		exeinto "$(get_udevdir)"
+		newexe "${FILESDIR}"/nvidia-udev.sh-r1 nvidia-udev.sh
+		udev_newrules "${FILESDIR}"/nvidia.udev-rule 99-nvidia.rules
+	elif use kernel_FreeBSD; then
+		if use x86-fbsd; then
+			insinto /boot/modules
+			doins "${S}/src/nvidia.kld"
+		fi
+
+		exeinto /boot/modules
+		doexe "${S}/src/nvidia.ko"
+	fi
+
+	# NVIDIA kernel <-> userspace driver config lib
+	donvidia ${NV_OBJ}/libnvidia-cfg.so ${NV_SOVER}
+
+	# NVIDIA framebuffer capture library
+	donvidia ${NV_OBJ}/libnvidia-fbc.so ${NV_SOVER}
+
+	# NVIDIA video encode/decode <-> CUDA
+	if use kernel_linux; then
+		donvidia ${NV_OBJ}/libnvcuvid.so ${NV_SOVER}
+		donvidia ${NV_OBJ}/libnvidia-encode.so ${NV_SOVER}
+	fi
+
+	if use X; then
+		# Xorg DDX driver
+		insinto /usr/$(get_libdir)/xorg/modules/drivers
+		doins ${NV_X11}/nvidia_drv.so
+
+		# Xorg GLX driver
+		donvidia ${NV_X11}/libglx.so ${NV_SOVER} \
+			/usr/$(get_libdir)/opengl/nvidia/extensions
+	fi
+
+	# OpenCL ICD for NVIDIA
+	if use kernel_linux; then
+		insinto /etc/OpenCL/vendors
+		doins ${NV_OBJ}/nvidia.icd
+	fi
+
+	# Documentation
+	if use kernel_FreeBSD; then
+		dodoc "${NV_DOC}/README"
+		use X && doman "${NV_MAN}/nvidia-xconfig.1"
+		use tools && doman "${NV_MAN}/nvidia-settings.1"
+	else
+		# Docs
+		newdoc "${NV_DOC}/README.txt" README
+		dodoc "${NV_DOC}/NVIDIA_Changelog"
+		doman "${NV_MAN}/nvidia-smi.1.gz"
+		use X && doman "${NV_MAN}/nvidia-xconfig.1.gz"
+		use tools && doman "${NV_MAN}/nvidia-settings.1.gz"
+		doman "${NV_MAN}/nvidia-cuda-mps-control.1.gz"
+	fi
+
+	docinto html
+	dodoc -r ${NV_DOC}/html/*
+
+	# Helper Apps
+	exeinto /opt/bin/
+
+	if use X; then
+		doexe ${NV_OBJ}/nvidia-xconfig
+	fi
+
+	if use kernel_linux ; then
+		doexe ${NV_OBJ}/nvidia-cuda-mps-control
+		doexe ${NV_OBJ}/nvidia-cuda-mps-server
+		doexe ${NV_OBJ}/nvidia-debugdump
+		doexe ${NV_OBJ}/nvidia-persistenced
+		doexe ${NV_OBJ}/nvidia-smi
+
+		# install nvidia-modprobe setuid and symlink in /usr/bin (bug #505092)
+		doexe ${NV_OBJ}/nvidia-modprobe
+		fowners root:video /opt/bin/nvidia-modprobe
+		fperms 4710 /opt/bin/nvidia-modprobe
+		dosym /{opt,usr}/bin/nvidia-modprobe
+
+		doman nvidia-cuda-mps-control.1.gz
+		doman nvidia-modprobe.1.gz
+		doman nvidia-persistenced.1.gz
+		newinitd "${FILESDIR}/nvidia-smi.init" nvidia-smi
+		newconfd "${FILESDIR}/nvidia-persistenced.conf" nvidia-persistenced
+		newinitd "${FILESDIR}/nvidia-persistenced.init" nvidia-persistenced
+	fi
+
+	if use tools; then
+		emake -C "${S}"/nvidia-settings-${PV}/src/ \
+			DESTDIR="${D}" \
+			LIBDIR="${D}/usr/$(get_libdir)" \
+			PREFIX=/usr \
+			NV_USE_BUNDLED_LIBJANSSON=0 \
+			install
+
+		if use static-libs; then
+			dolib.a "${S}"/nvidia-settings-${PV}/src/libXNVCtrl/libXNVCtrl.a
+
+			insinto /usr/include/NVCtrl
+			doins "${S}"/nvidia-settings-${PV}/src/libXNVCtrl/*.h
+		fi
+
+		insinto /usr/share/nvidia/
+		doins nvidia-application-profiles-${PV}-key-documentation
+
+		insinto /etc/nvidia
+		newins \
+			nvidia-application-profiles-${PV}-rc nvidia-application-profiles-rc
+
+		# There is no icon in the FreeBSD tarball.
+		use kernel_FreeBSD || \
+			doicon ${NV_OBJ}/nvidia-settings.png
+
+		domenu "${FILESDIR}"/nvidia-settings.desktop
+
+		exeinto /etc/X11/xinit/xinitrc.d
+		newexe "${FILESDIR}"/95-nvidia-settings-r1 95-nvidia-settings
+
+	fi
+
+	dobin ${NV_OBJ}/nvidia-bug-report.sh
+
+	#doenvd "${FILESDIR}"/50nvidia-prelink-blacklist
+
+	if has_multilib_profile && use multilib ; then
+		local OABI=${ABI}
+		for ABI in $(get_install_abis) ; do
+			src_install-libs
+		done
+		ABI=${OABI}
+		unset OABI
+	else
+		src_install-libs
+	fi
+
+	is_final_abi || die "failed to iterate through all ABIs"
+
+	readme.gentoo_create_doc
+}
+
+src_install-libs() {
+	local inslibdir=$(get_libdir)
+	local GL_ROOT="/usr/$(get_libdir)/opengl/nvidia/lib"
+	local CL_ROOT="/usr/$(get_libdir)/OpenCL/vendors/nvidia"
+	local libdir=${NV_OBJ}
+
+	if use kernel_linux && has_multilib_profile && \
+			[[ ${ABI} == "x86" ]] ; then
+		libdir=${NV_OBJ}/32
+	fi
+
+	if use X; then
+		# The GLX libraries
+		donvidia ${libdir}/libEGL.so ${NV_SOVER} ${GL_ROOT}
+		donvidia ${libdir}/libGL.so ${NV_SOVER} ${GL_ROOT}
+		donvidia ${libdir}/libGLESv1_CM.so ${NV_SOVER} ${GL_ROOT}
+		donvidia ${libdir}/libnvidia-eglcore.so ${NV_SOVER}
+		donvidia ${libdir}/libnvidia-glcore.so ${NV_SOVER}
+		donvidia ${libdir}/libnvidia-glsi.so ${NV_SOVER}
+		donvidia ${libdir}/libnvidia-ifr.so ${NV_SOVER}
+		if use kernel_FreeBSD; then
+			donvidia ${libdir}/libnvidia-tls.so ${NV_SOVER}
+		else
+			donvidia ${libdir}/tls/libnvidia-tls.so ${NV_SOVER}
+		fi
+
+		# VDPAU
+		donvidia ${libdir}/libvdpau_nvidia.so ${NV_SOVER}
+
+		# GLES v2 libraries
+		insinto ${GL_ROOT}
+		doexe ${libdir}/libGLESv2.so.${PV}
+		dosym libGLESv2.so.${PV} ${GL_ROOT}/libGLESv2.so.2
+		dosym libGLESv2.so.2 ${GL_ROOT}/libGLESv2.so
+	fi
+
+	# NVIDIA monitoring library
+	if use kernel_linux ; then
+		donvidia ${libdir}/libnvidia-ml.so ${NV_SOVER}
+	fi
+
+	# CUDA & OpenCL
+	if use kernel_linux; then
+		donvidia ${libdir}/libcuda.so ${NV_SOVER}
+		donvidia ${libdir}/libnvidia-compiler.so ${NV_SOVER}
+		donvidia ${libdir}/libOpenCL.so 1.0.0 ${CL_ROOT}
+		donvidia ${libdir}/libnvidia-opencl.so ${NV_SOVER}
+	fi
+}
+
+pkg_preinst() {
+	if use kernel_linux; then
+		linux-mod_pkg_preinst
+
+		local videogroup="$(egetent group video | cut -d ':' -f 3)"
+		if [ -z "${videogroup}" ]; then
+			eerror "Failed to determine the video group gid"
+			die "Failed to determine the video group gid"
+		else
+			sed -i \
+				-e "s:PACKAGE:${PF}:g" \
+				-e "s:VIDEOGID:${videogroup}:" \
+				"${D}"/etc/modprobe.d/nvidia.conf || die
+		fi
+	fi
+
+	# Clean the dynamic libGL stuff's home to ensure
+	# we dont have stale libs floating around
+	if [ -d "${ROOT}"/usr/lib/opengl/nvidia ] ; then
+		rm -rf "${ROOT}"/usr/lib/opengl/nvidia/*
+	fi
+	# Make sure we nuke the old nvidia-glx's env.d file
+	if [ -e "${ROOT}"/etc/env.d/09nvidia ] ; then
+		rm -f "${ROOT}"/etc/env.d/09nvidia
+	fi
+}
+
+pkg_postinst() {
+	use kernel_linux && linux-mod_pkg_postinst
+
+	# Switch to the nvidia implementation
+	use X && "${ROOT}"/usr/bin/eselect opengl set --use-old nvidia
+	"${ROOT}"/usr/bin/eselect opencl set --use-old nvidia
+
+	readme.gentoo_print_elog
+
+	if ! use X; then
+		elog "You have elected to not install the X.org driver. Along with"
+		elog "this the OpenGL libraries and VDPAU libraries were not"
+		elog "installed. Additionally, once the driver is loaded your card"
+		elog "and fan will run at max speed which may not be desirable."
+		elog "Use the 'nvidia-smi' init script to have your card and fan"
+		elog "speed scale appropriately."
+		elog
+	fi
+	if ! use tools; then
+		elog "USE=tools controls whether the nvidia-settings application"
+		elog "is installed. If you would like to use it, enable that"
+		elog "flag and re-emerge this ebuild. Optionally you can install"
+		elog "media-video/nvidia-settings"
+		elog
+	fi
+}
+
+pkg_prerm() {
+	use X && "${ROOT}"/usr/bin/eselect opengl set --use-old xorg-x11
+}
+
+pkg_postrm() {
+	use kernel_linux && linux-mod_pkg_postrm
+	use X && "${ROOT}"/usr/bin/eselect opengl set --use-old xorg-x11
+}