nouveau_drv.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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 "drmP.h"
  26. #include "drm.h"
  27. #include "drm_crtc_helper.h"
  28. #include "nouveau_drv.h"
  29. #include "nouveau_hw.h"
  30. #include "nouveau_fb.h"
  31. #include "nouveau_fbcon.h"
  32. #include "nv50_display.h"
  33. #include "drm_pciids.h"
  34. MODULE_PARM_DESC(ctxfw, "Use external firmware blob for grctx init (NV40)");
  35. int nouveau_ctxfw = 0;
  36. module_param_named(ctxfw, nouveau_ctxfw, int, 0400);
  37. MODULE_PARM_DESC(noagp, "Disable AGP");
  38. int nouveau_noagp;
  39. module_param_named(noagp, nouveau_noagp, int, 0400);
  40. MODULE_PARM_DESC(modeset, "Enable kernel modesetting");
  41. static int nouveau_modeset = -1; /* kms */
  42. module_param_named(modeset, nouveau_modeset, int, 0400);
  43. MODULE_PARM_DESC(vbios, "Override default VBIOS location");
  44. char *nouveau_vbios;
  45. module_param_named(vbios, nouveau_vbios, charp, 0400);
  46. MODULE_PARM_DESC(vram_pushbuf, "Force DMA push buffers to be in VRAM");
  47. int nouveau_vram_pushbuf;
  48. module_param_named(vram_pushbuf, nouveau_vram_pushbuf, int, 0400);
  49. MODULE_PARM_DESC(vram_notify, "Force DMA notifiers to be in VRAM");
  50. int nouveau_vram_notify = 0;
  51. module_param_named(vram_notify, nouveau_vram_notify, int, 0400);
  52. MODULE_PARM_DESC(duallink, "Allow dual-link TMDS (>=GeForce 8)");
  53. int nouveau_duallink = 1;
  54. module_param_named(duallink, nouveau_duallink, int, 0400);
  55. MODULE_PARM_DESC(uscript_lvds, "LVDS output script table ID (>=GeForce 8)");
  56. int nouveau_uscript_lvds = -1;
  57. module_param_named(uscript_lvds, nouveau_uscript_lvds, int, 0400);
  58. MODULE_PARM_DESC(uscript_tmds, "TMDS output script table ID (>=GeForce 8)");
  59. int nouveau_uscript_tmds = -1;
  60. module_param_named(uscript_tmds, nouveau_uscript_tmds, int, 0400);
  61. MODULE_PARM_DESC(ignorelid, "Ignore ACPI lid status");
  62. int nouveau_ignorelid = 0;
  63. module_param_named(ignorelid, nouveau_ignorelid, int, 0400);
  64. MODULE_PARM_DESC(noaccel, "Disable all acceleration");
  65. int nouveau_noaccel = 0;
  66. module_param_named(noaccel, nouveau_noaccel, int, 0400);
  67. MODULE_PARM_DESC(nofbaccel, "Disable fbcon acceleration");
  68. int nouveau_nofbaccel = 0;
  69. module_param_named(nofbaccel, nouveau_nofbaccel, int, 0400);
  70. MODULE_PARM_DESC(override_conntype, "Ignore DCB connector type");
  71. int nouveau_override_conntype = 0;
  72. module_param_named(override_conntype, nouveau_override_conntype, int, 0400);
  73. MODULE_PARM_DESC(tv_disable, "Disable TV-out detection\n");
  74. int nouveau_tv_disable = 0;
  75. module_param_named(tv_disable, nouveau_tv_disable, int, 0400);
  76. MODULE_PARM_DESC(tv_norm, "Default TV norm.\n"
  77. "\t\tSupported: PAL, PAL-M, PAL-N, PAL-Nc, NTSC-M, NTSC-J,\n"
  78. "\t\t\thd480i, hd480p, hd576i, hd576p, hd720p, hd1080i.\n"
  79. "\t\tDefault: PAL\n"
  80. "\t\t*NOTE* Ignored for cards with external TV encoders.");
  81. char *nouveau_tv_norm;
  82. module_param_named(tv_norm, nouveau_tv_norm, charp, 0400);
  83. MODULE_PARM_DESC(reg_debug, "Register access debug bitmask:\n"
  84. "\t\t0x1 mc, 0x2 video, 0x4 fb, 0x8 extdev,\n"
  85. "\t\t0x10 crtc, 0x20 ramdac, 0x40 vgacrtc, 0x80 rmvio,\n"
  86. "\t\t0x100 vgaattr, 0x200 EVO (G80+). ");
  87. int nouveau_reg_debug;
  88. module_param_named(reg_debug, nouveau_reg_debug, int, 0600);
  89. int nouveau_fbpercrtc;
  90. #if 0
  91. module_param_named(fbpercrtc, nouveau_fbpercrtc, int, 0400);
  92. #endif
  93. static struct pci_device_id pciidlist[] = {
  94. {
  95. PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
  96. .class = PCI_BASE_CLASS_DISPLAY << 16,
  97. .class_mask = 0xff << 16,
  98. },
  99. {
  100. PCI_DEVICE(PCI_VENDOR_ID_NVIDIA_SGS, PCI_ANY_ID),
  101. .class = PCI_BASE_CLASS_DISPLAY << 16,
  102. .class_mask = 0xff << 16,
  103. },
  104. {}
  105. };
  106. MODULE_DEVICE_TABLE(pci, pciidlist);
  107. static struct drm_driver driver;
  108. static int __devinit
  109. nouveau_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  110. {
  111. return drm_get_pci_dev(pdev, ent, &driver);
  112. }
  113. static void
  114. nouveau_pci_remove(struct pci_dev *pdev)
  115. {
  116. struct drm_device *dev = pci_get_drvdata(pdev);
  117. drm_put_dev(dev);
  118. }
  119. int
  120. nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state)
  121. {
  122. struct drm_device *dev = pci_get_drvdata(pdev);
  123. struct drm_nouveau_private *dev_priv = dev->dev_private;
  124. struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem;
  125. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  126. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  127. struct nouveau_channel *chan;
  128. struct drm_crtc *crtc;
  129. int ret, i;
  130. if (pm_state.event == PM_EVENT_PRETHAW)
  131. return 0;
  132. NV_INFO(dev, "Disabling fbcon acceleration...\n");
  133. nouveau_fbcon_save_disable_accel(dev);
  134. NV_INFO(dev, "Unpinning framebuffer(s)...\n");
  135. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  136. struct nouveau_framebuffer *nouveau_fb;
  137. nouveau_fb = nouveau_framebuffer(crtc->fb);
  138. if (!nouveau_fb || !nouveau_fb->nvbo)
  139. continue;
  140. nouveau_bo_unpin(nouveau_fb->nvbo);
  141. }
  142. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  143. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  144. nouveau_bo_unmap(nv_crtc->cursor.nvbo);
  145. nouveau_bo_unpin(nv_crtc->cursor.nvbo);
  146. }
  147. NV_INFO(dev, "Evicting buffers...\n");
  148. ttm_bo_evict_mm(&dev_priv->ttm.bdev, TTM_PL_VRAM);
  149. NV_INFO(dev, "Idling channels...\n");
  150. for (i = 0; i < pfifo->channels; i++) {
  151. struct nouveau_fence *fence = NULL;
  152. chan = dev_priv->fifos[i];
  153. if (!chan || (dev_priv->card_type >= NV_50 &&
  154. chan == dev_priv->fifos[0]))
  155. continue;
  156. ret = nouveau_fence_new(chan, &fence, true);
  157. if (ret == 0) {
  158. ret = nouveau_fence_wait(fence, NULL, false, false);
  159. nouveau_fence_unref((void *)&fence);
  160. }
  161. if (ret) {
  162. NV_ERROR(dev, "Failed to idle channel %d for suspend\n",
  163. chan->id);
  164. }
  165. }
  166. pgraph->fifo_access(dev, false);
  167. nouveau_wait_for_idle(dev);
  168. pfifo->reassign(dev, false);
  169. pfifo->disable(dev);
  170. pfifo->unload_context(dev);
  171. pgraph->unload_context(dev);
  172. NV_INFO(dev, "Suspending GPU objects...\n");
  173. ret = nouveau_gpuobj_suspend(dev);
  174. if (ret) {
  175. NV_ERROR(dev, "... failed: %d\n", ret);
  176. goto out_abort;
  177. }
  178. ret = pinstmem->suspend(dev);
  179. if (ret) {
  180. NV_ERROR(dev, "... failed: %d\n", ret);
  181. nouveau_gpuobj_suspend_cleanup(dev);
  182. goto out_abort;
  183. }
  184. NV_INFO(dev, "And we're gone!\n");
  185. pci_save_state(pdev);
  186. if (pm_state.event == PM_EVENT_SUSPEND) {
  187. pci_disable_device(pdev);
  188. pci_set_power_state(pdev, PCI_D3hot);
  189. }
  190. acquire_console_sem();
  191. nouveau_fbcon_set_suspend(dev, 1);
  192. release_console_sem();
  193. nouveau_fbcon_restore_accel(dev);
  194. return 0;
  195. out_abort:
  196. NV_INFO(dev, "Re-enabling acceleration..\n");
  197. pfifo->enable(dev);
  198. pfifo->reassign(dev, true);
  199. pgraph->fifo_access(dev, true);
  200. return ret;
  201. }
  202. int
  203. nouveau_pci_resume(struct pci_dev *pdev)
  204. {
  205. struct drm_device *dev = pci_get_drvdata(pdev);
  206. struct drm_nouveau_private *dev_priv = dev->dev_private;
  207. struct nouveau_engine *engine = &dev_priv->engine;
  208. struct drm_crtc *crtc;
  209. int ret, i;
  210. nouveau_fbcon_save_disable_accel(dev);
  211. NV_INFO(dev, "We're back, enabling device...\n");
  212. pci_set_power_state(pdev, PCI_D0);
  213. pci_restore_state(pdev);
  214. if (pci_enable_device(pdev))
  215. return -1;
  216. pci_set_master(dev->pdev);
  217. NV_INFO(dev, "POSTing device...\n");
  218. ret = nouveau_run_vbios_init(dev);
  219. if (ret)
  220. return ret;
  221. if (dev_priv->gart_info.type == NOUVEAU_GART_AGP) {
  222. ret = nouveau_mem_init_agp(dev);
  223. if (ret) {
  224. NV_ERROR(dev, "error reinitialising AGP: %d\n", ret);
  225. return ret;
  226. }
  227. }
  228. NV_INFO(dev, "Reinitialising engines...\n");
  229. engine->instmem.resume(dev);
  230. engine->mc.init(dev);
  231. engine->timer.init(dev);
  232. engine->fb.init(dev);
  233. engine->graph.init(dev);
  234. engine->fifo.init(dev);
  235. NV_INFO(dev, "Restoring GPU objects...\n");
  236. nouveau_gpuobj_resume(dev);
  237. nouveau_irq_postinstall(dev);
  238. /* Re-write SKIPS, they'll have been lost over the suspend */
  239. if (nouveau_vram_pushbuf) {
  240. struct nouveau_channel *chan;
  241. int j;
  242. for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
  243. chan = dev_priv->fifos[i];
  244. if (!chan || !chan->pushbuf_bo)
  245. continue;
  246. for (j = 0; j < NOUVEAU_DMA_SKIPS; j++)
  247. nouveau_bo_wr32(chan->pushbuf_bo, i, 0);
  248. }
  249. }
  250. NV_INFO(dev, "Restoring mode...\n");
  251. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  252. struct nouveau_framebuffer *nouveau_fb;
  253. nouveau_fb = nouveau_framebuffer(crtc->fb);
  254. if (!nouveau_fb || !nouveau_fb->nvbo)
  255. continue;
  256. nouveau_bo_pin(nouveau_fb->nvbo, TTM_PL_FLAG_VRAM);
  257. }
  258. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  259. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  260. int ret;
  261. ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM);
  262. if (!ret)
  263. ret = nouveau_bo_map(nv_crtc->cursor.nvbo);
  264. if (ret)
  265. NV_ERROR(dev, "Could not pin/map cursor.\n");
  266. }
  267. if (dev_priv->card_type < NV_50) {
  268. nv04_display_restore(dev);
  269. NVLockVgaCrtcs(dev, false);
  270. } else
  271. nv50_display_init(dev);
  272. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  273. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  274. nv_crtc->cursor.set_offset(nv_crtc,
  275. nv_crtc->cursor.nvbo->bo.offset -
  276. dev_priv->vm_vram_base);
  277. nv_crtc->cursor.set_pos(nv_crtc, nv_crtc->cursor_saved_x,
  278. nv_crtc->cursor_saved_y);
  279. }
  280. /* Force CLUT to get re-loaded during modeset */
  281. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  282. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  283. nv_crtc->lut.depth = 0;
  284. }
  285. acquire_console_sem();
  286. nouveau_fbcon_set_suspend(dev, 0);
  287. release_console_sem();
  288. nouveau_fbcon_zfill_all(dev);
  289. drm_helper_resume_force_mode(dev);
  290. nouveau_fbcon_restore_accel(dev);
  291. return 0;
  292. }
  293. static struct drm_driver driver = {
  294. .driver_features =
  295. DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG |
  296. DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM |
  297. DRIVER_MODESET,
  298. .load = nouveau_load,
  299. .firstopen = nouveau_firstopen,
  300. .lastclose = nouveau_lastclose,
  301. .unload = nouveau_unload,
  302. .preclose = nouveau_preclose,
  303. #if defined(CONFIG_DRM_NOUVEAU_DEBUG)
  304. .debugfs_init = nouveau_debugfs_init,
  305. .debugfs_cleanup = nouveau_debugfs_takedown,
  306. #endif
  307. .irq_preinstall = nouveau_irq_preinstall,
  308. .irq_postinstall = nouveau_irq_postinstall,
  309. .irq_uninstall = nouveau_irq_uninstall,
  310. .irq_handler = nouveau_irq_handler,
  311. .reclaim_buffers = drm_core_reclaim_buffers,
  312. .get_map_ofs = drm_core_get_map_ofs,
  313. .get_reg_ofs = drm_core_get_reg_ofs,
  314. .ioctls = nouveau_ioctls,
  315. .fops = {
  316. .owner = THIS_MODULE,
  317. .open = drm_open,
  318. .release = drm_release,
  319. .unlocked_ioctl = drm_ioctl,
  320. .mmap = nouveau_ttm_mmap,
  321. .poll = drm_poll,
  322. .fasync = drm_fasync,
  323. #if defined(CONFIG_COMPAT)
  324. .compat_ioctl = nouveau_compat_ioctl,
  325. #endif
  326. },
  327. .pci_driver = {
  328. .name = DRIVER_NAME,
  329. .id_table = pciidlist,
  330. .probe = nouveau_pci_probe,
  331. .remove = nouveau_pci_remove,
  332. .suspend = nouveau_pci_suspend,
  333. .resume = nouveau_pci_resume
  334. },
  335. .gem_init_object = nouveau_gem_object_new,
  336. .gem_free_object = nouveau_gem_object_del,
  337. .name = DRIVER_NAME,
  338. .desc = DRIVER_DESC,
  339. #ifdef GIT_REVISION
  340. .date = GIT_REVISION,
  341. #else
  342. .date = DRIVER_DATE,
  343. #endif
  344. .major = DRIVER_MAJOR,
  345. .minor = DRIVER_MINOR,
  346. .patchlevel = DRIVER_PATCHLEVEL,
  347. };
  348. static int __init nouveau_init(void)
  349. {
  350. driver.num_ioctls = nouveau_max_ioctl;
  351. if (nouveau_modeset == -1) {
  352. #ifdef CONFIG_VGA_CONSOLE
  353. if (vgacon_text_force())
  354. nouveau_modeset = 0;
  355. else
  356. #endif
  357. nouveau_modeset = 1;
  358. }
  359. if (!nouveau_modeset)
  360. return 0;
  361. nouveau_register_dsm_handler();
  362. return drm_init(&driver);
  363. }
  364. static void __exit nouveau_exit(void)
  365. {
  366. if (!nouveau_modeset)
  367. return;
  368. drm_exit(&driver);
  369. nouveau_unregister_dsm_handler();
  370. }
  371. module_init(nouveau_init);
  372. module_exit(nouveau_exit);
  373. MODULE_AUTHOR(DRIVER_AUTHOR);
  374. MODULE_DESCRIPTION(DRIVER_DESC);
  375. MODULE_LICENSE("GPL and additional rights");