nouveau_drv.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. /*
  2. * Copyright 2005 Stephane Marchesin.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. #include <linux/console.h>
  25. #include <linux/module.h>
  26. #include "drmP.h"
  27. #include "drm.h"
  28. #include "drm_crtc_helper.h"
  29. #include "nouveau_drv.h"
  30. #include "nouveau_abi16.h"
  31. #include "nouveau_hw.h"
  32. #include "nouveau_fb.h"
  33. #include "nouveau_fbcon.h"
  34. #include "nouveau_pm.h"
  35. #include <engine/fifo.h>
  36. #include "nv50_display.h"
  37. #include "drm_pciids.h"
  38. MODULE_PARM_DESC(modeset, "Enable kernel modesetting");
  39. int nouveau_modeset = -1;
  40. module_param_named(modeset, nouveau_modeset, int, 0400);
  41. MODULE_PARM_DESC(vram_pushbuf, "Force DMA push buffers to be in VRAM");
  42. int nouveau_vram_pushbuf;
  43. module_param_named(vram_pushbuf, nouveau_vram_pushbuf, int, 0400);
  44. MODULE_PARM_DESC(vram_notify, "Force DMA notifiers to be in VRAM");
  45. int nouveau_vram_notify = 0;
  46. module_param_named(vram_notify, nouveau_vram_notify, int, 0400);
  47. MODULE_PARM_DESC(vram_type, "Override detected VRAM type");
  48. char *nouveau_vram_type;
  49. module_param_named(vram_type, nouveau_vram_type, charp, 0400);
  50. MODULE_PARM_DESC(duallink, "Allow dual-link TMDS (>=GeForce 8)");
  51. int nouveau_duallink = 1;
  52. module_param_named(duallink, nouveau_duallink, int, 0400);
  53. MODULE_PARM_DESC(uscript_lvds, "LVDS output script table ID (>=GeForce 8)");
  54. int nouveau_uscript_lvds = -1;
  55. module_param_named(uscript_lvds, nouveau_uscript_lvds, int, 0400);
  56. MODULE_PARM_DESC(uscript_tmds, "TMDS output script table ID (>=GeForce 8)");
  57. int nouveau_uscript_tmds = -1;
  58. module_param_named(uscript_tmds, nouveau_uscript_tmds, int, 0400);
  59. MODULE_PARM_DESC(ignorelid, "Ignore ACPI lid status");
  60. int nouveau_ignorelid = 0;
  61. module_param_named(ignorelid, nouveau_ignorelid, int, 0400);
  62. MODULE_PARM_DESC(noaccel, "Disable all acceleration");
  63. int nouveau_noaccel = -1;
  64. module_param_named(noaccel, nouveau_noaccel, int, 0400);
  65. MODULE_PARM_DESC(nofbaccel, "Disable fbcon acceleration");
  66. int nouveau_nofbaccel = 0;
  67. module_param_named(nofbaccel, nouveau_nofbaccel, int, 0400);
  68. MODULE_PARM_DESC(force_post, "Force POST");
  69. int nouveau_force_post = 0;
  70. module_param_named(force_post, nouveau_force_post, int, 0400);
  71. MODULE_PARM_DESC(override_conntype, "Ignore DCB connector type");
  72. int nouveau_override_conntype = 0;
  73. module_param_named(override_conntype, nouveau_override_conntype, int, 0400);
  74. MODULE_PARM_DESC(tv_disable, "Disable TV-out detection");
  75. int nouveau_tv_disable = 0;
  76. module_param_named(tv_disable, nouveau_tv_disable, int, 0400);
  77. MODULE_PARM_DESC(tv_norm, "Default TV norm.\n"
  78. "\t\tSupported: PAL, PAL-M, PAL-N, PAL-Nc, NTSC-M, NTSC-J,\n"
  79. "\t\t\thd480i, hd480p, hd576i, hd576p, hd720p, hd1080i.\n"
  80. "\t\tDefault: PAL\n"
  81. "\t\t*NOTE* Ignored for cards with external TV encoders.");
  82. char *nouveau_tv_norm;
  83. module_param_named(tv_norm, nouveau_tv_norm, charp, 0400);
  84. MODULE_PARM_DESC(reg_debug, "Register access debug bitmask:\n"
  85. "\t\t0x1 mc, 0x2 video, 0x4 fb, 0x8 extdev,\n"
  86. "\t\t0x10 crtc, 0x20 ramdac, 0x40 vgacrtc, 0x80 rmvio,\n"
  87. "\t\t0x100 vgaattr, 0x200 EVO (G80+)");
  88. int nouveau_reg_debug;
  89. module_param_named(reg_debug, nouveau_reg_debug, int, 0600);
  90. MODULE_PARM_DESC(perflvl, "Performance level (default: boot)");
  91. char *nouveau_perflvl;
  92. module_param_named(perflvl, nouveau_perflvl, charp, 0400);
  93. MODULE_PARM_DESC(perflvl_wr, "Allow perflvl changes (warning: dangerous!)");
  94. int nouveau_perflvl_wr;
  95. module_param_named(perflvl_wr, nouveau_perflvl_wr, int, 0400);
  96. MODULE_PARM_DESC(msi, "Enable MSI (default: off)");
  97. int nouveau_msi;
  98. module_param_named(msi, nouveau_msi, int, 0400);
  99. MODULE_PARM_DESC(ctxfw, "Use external HUB/GPC ucode (fermi)");
  100. int nouveau_ctxfw;
  101. module_param_named(ctxfw, nouveau_ctxfw, int, 0400);
  102. MODULE_PARM_DESC(mxmdcb, "Santise DCB table according to MXM-SIS");
  103. int nouveau_mxmdcb = 1;
  104. module_param_named(mxmdcb, nouveau_mxmdcb, int, 0400);
  105. int nouveau_fbpercrtc;
  106. #if 0
  107. module_param_named(fbpercrtc, nouveau_fbpercrtc, int, 0400);
  108. #endif
  109. static struct drm_driver driver;
  110. int __devinit
  111. nouveau_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  112. {
  113. return drm_get_pci_dev(pdev, ent, &driver);
  114. }
  115. void
  116. nouveau_pci_remove(struct pci_dev *pdev)
  117. {
  118. struct drm_device *dev = pci_get_drvdata(pdev);
  119. drm_put_dev(dev);
  120. }
  121. int
  122. nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state)
  123. {
  124. struct drm_device *dev = pci_get_drvdata(pdev);
  125. struct drm_nouveau_private *dev_priv = dev->dev_private;
  126. struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem;
  127. struct nouveau_fifo_priv *pfifo = nv_engine(dev, NVOBJ_ENGINE_FIFO);
  128. struct nouveau_channel *chan;
  129. struct drm_crtc *crtc;
  130. int ret, i, e;
  131. NV_INFO(dev, "Disabling display...\n");
  132. nouveau_display_fini(dev);
  133. NV_INFO(dev, "Disabling fbcon...\n");
  134. nouveau_fbcon_set_suspend(dev, 1);
  135. NV_INFO(dev, "Unpinning framebuffer(s)...\n");
  136. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  137. struct nouveau_framebuffer *nouveau_fb;
  138. nouveau_fb = nouveau_framebuffer(crtc->fb);
  139. if (!nouveau_fb || !nouveau_fb->nvbo)
  140. continue;
  141. nouveau_bo_unpin(nouveau_fb->nvbo);
  142. }
  143. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  144. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  145. nouveau_bo_unmap(nv_crtc->cursor.nvbo);
  146. nouveau_bo_unpin(nv_crtc->cursor.nvbo);
  147. }
  148. NV_INFO(dev, "Evicting buffers...\n");
  149. ttm_bo_evict_mm(&dev_priv->ttm.bdev, TTM_PL_VRAM);
  150. NV_INFO(dev, "Idling channels...\n");
  151. for (i = 0; i < (pfifo ? pfifo->channels : 0); i++) {
  152. chan = dev_priv->channels.ptr[i];
  153. if (chan && chan->pushbuf_bo)
  154. nouveau_channel_idle(chan);
  155. }
  156. for (e = NVOBJ_ENGINE_NR - 1; e >= 0; e--) {
  157. if (!dev_priv->eng[e])
  158. continue;
  159. ret = dev_priv->eng[e]->fini(dev, e, true);
  160. if (ret) {
  161. NV_ERROR(dev, "... engine %d failed: %d\n", e, ret);
  162. goto out_abort;
  163. }
  164. }
  165. ret = pinstmem->suspend(dev);
  166. if (ret) {
  167. NV_ERROR(dev, "... failed: %d\n", ret);
  168. goto out_abort;
  169. }
  170. NV_INFO(dev, "Suspending GPU objects...\n");
  171. ret = nouveau_gpuobj_suspend(dev);
  172. if (ret) {
  173. NV_ERROR(dev, "... failed: %d\n", ret);
  174. pinstmem->resume(dev);
  175. goto out_abort;
  176. }
  177. return 0;
  178. out_abort:
  179. NV_INFO(dev, "Re-enabling acceleration..\n");
  180. for (e = e + 1; e < NVOBJ_ENGINE_NR; e++) {
  181. if (dev_priv->eng[e])
  182. dev_priv->eng[e]->init(dev, e);
  183. }
  184. return ret;
  185. }
  186. int
  187. nouveau_pci_resume(struct pci_dev *pdev)
  188. {
  189. struct drm_device *dev = pci_get_drvdata(pdev);
  190. struct nouveau_fifo_priv *pfifo = nv_engine(dev, NVOBJ_ENGINE_FIFO);
  191. struct drm_nouveau_private *dev_priv = dev->dev_private;
  192. struct nouveau_engine *engine = &dev_priv->engine;
  193. struct drm_crtc *crtc;
  194. int ret, i;
  195. /* Make the CRTCs accessible */
  196. engine->display.early_init(dev);
  197. NV_INFO(dev, "POSTing device...\n");
  198. ret = nouveau_run_vbios_init(dev);
  199. if (ret)
  200. return ret;
  201. NV_INFO(dev, "Restoring GPU objects...\n");
  202. nouveau_gpuobj_resume(dev);
  203. NV_INFO(dev, "Reinitialising engines...\n");
  204. engine->instmem.resume(dev);
  205. engine->fb.init(dev);
  206. for (i = 0; i < NVOBJ_ENGINE_NR; i++) {
  207. if (dev_priv->eng[i])
  208. dev_priv->eng[i]->init(dev, i);
  209. }
  210. nouveau_irq_postinstall(dev);
  211. /* Re-write SKIPS, they'll have been lost over the suspend */
  212. if (nouveau_vram_pushbuf) {
  213. struct nouveau_channel *chan;
  214. int j;
  215. for (i = 0; i < (pfifo ? pfifo->channels : 0); i++) {
  216. chan = dev_priv->channels.ptr[i];
  217. if (!chan || !chan->pushbuf_bo)
  218. continue;
  219. for (j = 0; j < NOUVEAU_DMA_SKIPS; j++)
  220. nouveau_bo_wr32(chan->pushbuf_bo, i, 0);
  221. }
  222. }
  223. nouveau_pm_resume(dev);
  224. NV_INFO(dev, "Restoring mode...\n");
  225. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  226. struct nouveau_framebuffer *nouveau_fb;
  227. nouveau_fb = nouveau_framebuffer(crtc->fb);
  228. if (!nouveau_fb || !nouveau_fb->nvbo)
  229. continue;
  230. nouveau_bo_pin(nouveau_fb->nvbo, TTM_PL_FLAG_VRAM);
  231. }
  232. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  233. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  234. ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM);
  235. if (!ret)
  236. ret = nouveau_bo_map(nv_crtc->cursor.nvbo);
  237. if (ret)
  238. NV_ERROR(dev, "Could not pin/map cursor.\n");
  239. }
  240. nouveau_fbcon_set_suspend(dev, 0);
  241. nouveau_fbcon_zfill_all(dev);
  242. nouveau_display_init(dev);
  243. /* Force CLUT to get re-loaded during modeset */
  244. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  245. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  246. nv_crtc->lut.depth = 0;
  247. }
  248. drm_helper_resume_force_mode(dev);
  249. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  250. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  251. u32 offset = nv_crtc->cursor.nvbo->bo.offset;
  252. nv_crtc->cursor.set_offset(nv_crtc, offset);
  253. nv_crtc->cursor.set_pos(nv_crtc, nv_crtc->cursor_saved_x,
  254. nv_crtc->cursor_saved_y);
  255. }
  256. return 0;
  257. }
  258. static struct drm_ioctl_desc nouveau_ioctls[] = {
  259. DRM_IOCTL_DEF_DRV(NOUVEAU_GETPARAM, nouveau_abi16_ioctl_getparam, DRM_UNLOCKED|DRM_AUTH),
  260. DRM_IOCTL_DEF_DRV(NOUVEAU_SETPARAM, nouveau_abi16_ioctl_setparam, DRM_UNLOCKED|DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
  261. DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_ALLOC, nouveau_abi16_ioctl_channel_alloc, DRM_UNLOCKED|DRM_AUTH),
  262. DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_FREE, nouveau_abi16_ioctl_channel_free, DRM_UNLOCKED|DRM_AUTH),
  263. DRM_IOCTL_DEF_DRV(NOUVEAU_GROBJ_ALLOC, nouveau_abi16_ioctl_grobj_alloc, DRM_UNLOCKED|DRM_AUTH),
  264. DRM_IOCTL_DEF_DRV(NOUVEAU_NOTIFIEROBJ_ALLOC, nouveau_abi16_ioctl_notifierobj_alloc, DRM_UNLOCKED|DRM_AUTH),
  265. DRM_IOCTL_DEF_DRV(NOUVEAU_GPUOBJ_FREE, nouveau_abi16_ioctl_gpuobj_free, DRM_UNLOCKED|DRM_AUTH),
  266. DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_NEW, nouveau_gem_ioctl_new, DRM_UNLOCKED|DRM_AUTH),
  267. DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_PUSHBUF, nouveau_gem_ioctl_pushbuf, DRM_UNLOCKED|DRM_AUTH),
  268. DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_PREP, nouveau_gem_ioctl_cpu_prep, DRM_UNLOCKED|DRM_AUTH),
  269. DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_FINI, nouveau_gem_ioctl_cpu_fini, DRM_UNLOCKED|DRM_AUTH),
  270. DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_INFO, nouveau_gem_ioctl_info, DRM_UNLOCKED|DRM_AUTH),
  271. };
  272. static const struct file_operations nouveau_driver_fops = {
  273. .owner = THIS_MODULE,
  274. .open = drm_open,
  275. .release = drm_release,
  276. .unlocked_ioctl = drm_ioctl,
  277. .mmap = nouveau_ttm_mmap,
  278. .poll = drm_poll,
  279. .fasync = drm_fasync,
  280. .read = drm_read,
  281. #if defined(CONFIG_COMPAT)
  282. .compat_ioctl = nouveau_compat_ioctl,
  283. #endif
  284. .llseek = noop_llseek,
  285. };
  286. int nouveau_drm_load(struct drm_device *, unsigned long);
  287. int nouveau_drm_unload(struct drm_device *);
  288. static struct drm_driver driver = {
  289. .driver_features =
  290. DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG |
  291. DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM |
  292. DRIVER_MODESET | DRIVER_PRIME,
  293. .load = nouveau_drm_load,
  294. .firstopen = nouveau_firstopen,
  295. .lastclose = nouveau_lastclose,
  296. .unload = nouveau_drm_unload,
  297. .open = nouveau_open,
  298. .preclose = nouveau_preclose,
  299. .postclose = nouveau_postclose,
  300. #if defined(CONFIG_DRM_NOUVEAU_DEBUG)
  301. .debugfs_init = nouveau_debugfs_init,
  302. .debugfs_cleanup = nouveau_debugfs_takedown,
  303. #endif
  304. .irq_preinstall = nouveau_irq_preinstall,
  305. .irq_postinstall = nouveau_irq_postinstall,
  306. .irq_uninstall = nouveau_irq_uninstall,
  307. .irq_handler = nouveau_irq_handler,
  308. .get_vblank_counter = drm_vblank_count,
  309. .enable_vblank = nouveau_vblank_enable,
  310. .disable_vblank = nouveau_vblank_disable,
  311. .ioctls = nouveau_ioctls,
  312. .fops = &nouveau_driver_fops,
  313. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  314. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  315. .gem_prime_export = nouveau_gem_prime_export,
  316. .gem_prime_import = nouveau_gem_prime_import,
  317. .gem_init_object = nouveau_gem_object_new,
  318. .gem_free_object = nouveau_gem_object_del,
  319. .gem_open_object = nouveau_gem_object_open,
  320. .gem_close_object = nouveau_gem_object_close,
  321. .dumb_create = nouveau_display_dumb_create,
  322. .dumb_map_offset = nouveau_display_dumb_map_offset,
  323. .dumb_destroy = nouveau_display_dumb_destroy,
  324. .name = DRIVER_NAME,
  325. .desc = DRIVER_DESC,
  326. #ifdef GIT_REVISION
  327. .date = GIT_REVISION,
  328. #else
  329. .date = DRIVER_DATE,
  330. #endif
  331. .major = DRIVER_MAJOR,
  332. .minor = DRIVER_MINOR,
  333. .patchlevel = DRIVER_PATCHLEVEL,
  334. };
  335. int __init nouveau_init(struct pci_driver *pdrv)
  336. {
  337. driver.num_ioctls = ARRAY_SIZE(nouveau_ioctls);
  338. if (nouveau_modeset == -1) {
  339. #ifdef CONFIG_VGA_CONSOLE
  340. if (vgacon_text_force())
  341. nouveau_modeset = 0;
  342. else
  343. #endif
  344. nouveau_modeset = 1;
  345. }
  346. if (!nouveau_modeset)
  347. return 0;
  348. nouveau_register_dsm_handler();
  349. return drm_pci_init(&driver, pdrv);
  350. }
  351. void __exit nouveau_exit(struct pci_driver *pdrv)
  352. {
  353. if (!nouveau_modeset)
  354. return;
  355. drm_pci_exit(&driver, pdrv);
  356. nouveau_unregister_dsm_handler();
  357. }