nouveau_drv.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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 "nouveau_pm.h"
  33. #include "nv50_display.h"
  34. #include "drm_pciids.h"
  35. MODULE_PARM_DESC(agpmode, "AGP mode (0 to disable AGP)");
  36. int nouveau_agpmode = -1;
  37. module_param_named(agpmode, nouveau_agpmode, int, 0400);
  38. MODULE_PARM_DESC(modeset, "Enable kernel modesetting");
  39. static int nouveau_modeset = -1; /* kms */
  40. module_param_named(modeset, nouveau_modeset, int, 0400);
  41. MODULE_PARM_DESC(vbios, "Override default VBIOS location");
  42. char *nouveau_vbios;
  43. module_param_named(vbios, nouveau_vbios, charp, 0400);
  44. MODULE_PARM_DESC(vram_pushbuf, "Force DMA push buffers to be in VRAM");
  45. int nouveau_vram_pushbuf;
  46. module_param_named(vram_pushbuf, nouveau_vram_pushbuf, int, 0400);
  47. MODULE_PARM_DESC(vram_notify, "Force DMA notifiers to be in VRAM");
  48. int nouveau_vram_notify = 0;
  49. module_param_named(vram_notify, nouveau_vram_notify, int, 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 = 0;
  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\n");
  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)\n");
  91. char *nouveau_perflvl;
  92. module_param_named(perflvl, nouveau_perflvl, charp, 0400);
  93. MODULE_PARM_DESC(perflvl_wr, "Allow perflvl changes (warning: dangerous!)\n");
  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)\n");
  97. int nouveau_msi;
  98. module_param_named(msi, nouveau_msi, int, 0400);
  99. int nouveau_fbpercrtc;
  100. #if 0
  101. module_param_named(fbpercrtc, nouveau_fbpercrtc, int, 0400);
  102. #endif
  103. static struct pci_device_id pciidlist[] = {
  104. {
  105. PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
  106. .class = PCI_BASE_CLASS_DISPLAY << 16,
  107. .class_mask = 0xff << 16,
  108. },
  109. {
  110. PCI_DEVICE(PCI_VENDOR_ID_NVIDIA_SGS, PCI_ANY_ID),
  111. .class = PCI_BASE_CLASS_DISPLAY << 16,
  112. .class_mask = 0xff << 16,
  113. },
  114. {}
  115. };
  116. MODULE_DEVICE_TABLE(pci, pciidlist);
  117. static struct drm_driver driver;
  118. static int __devinit
  119. nouveau_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  120. {
  121. return drm_get_pci_dev(pdev, ent, &driver);
  122. }
  123. static void
  124. nouveau_pci_remove(struct pci_dev *pdev)
  125. {
  126. struct drm_device *dev = pci_get_drvdata(pdev);
  127. drm_put_dev(dev);
  128. }
  129. int
  130. nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state)
  131. {
  132. struct drm_device *dev = pci_get_drvdata(pdev);
  133. struct drm_nouveau_private *dev_priv = dev->dev_private;
  134. struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem;
  135. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  136. struct nouveau_channel *chan;
  137. struct drm_crtc *crtc;
  138. int ret, i, e;
  139. if (pm_state.event == PM_EVENT_PRETHAW)
  140. return 0;
  141. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  142. return 0;
  143. NV_INFO(dev, "Disabling fbcon acceleration...\n");
  144. nouveau_fbcon_save_disable_accel(dev);
  145. NV_INFO(dev, "Unpinning framebuffer(s)...\n");
  146. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  147. struct nouveau_framebuffer *nouveau_fb;
  148. nouveau_fb = nouveau_framebuffer(crtc->fb);
  149. if (!nouveau_fb || !nouveau_fb->nvbo)
  150. continue;
  151. nouveau_bo_unpin(nouveau_fb->nvbo);
  152. }
  153. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  154. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  155. nouveau_bo_unmap(nv_crtc->cursor.nvbo);
  156. nouveau_bo_unpin(nv_crtc->cursor.nvbo);
  157. }
  158. NV_INFO(dev, "Evicting buffers...\n");
  159. ttm_bo_evict_mm(&dev_priv->ttm.bdev, TTM_PL_VRAM);
  160. NV_INFO(dev, "Idling channels...\n");
  161. for (i = 0; i < pfifo->channels; i++) {
  162. chan = dev_priv->channels.ptr[i];
  163. if (chan && chan->pushbuf_bo)
  164. nouveau_channel_idle(chan);
  165. }
  166. pfifo->reassign(dev, false);
  167. pfifo->disable(dev);
  168. pfifo->unload_context(dev);
  169. for (e = NVOBJ_ENGINE_NR - 1; e >= 0; e--) {
  170. if (dev_priv->eng[e]) {
  171. ret = dev_priv->eng[e]->fini(dev, e);
  172. if (ret)
  173. goto out_abort;
  174. }
  175. }
  176. ret = pinstmem->suspend(dev);
  177. if (ret) {
  178. NV_ERROR(dev, "... failed: %d\n", ret);
  179. goto out_abort;
  180. }
  181. NV_INFO(dev, "Suspending GPU objects...\n");
  182. ret = nouveau_gpuobj_suspend(dev);
  183. if (ret) {
  184. NV_ERROR(dev, "... failed: %d\n", ret);
  185. pinstmem->resume(dev);
  186. goto out_abort;
  187. }
  188. NV_INFO(dev, "And we're gone!\n");
  189. pci_save_state(pdev);
  190. if (pm_state.event == PM_EVENT_SUSPEND) {
  191. pci_disable_device(pdev);
  192. pci_set_power_state(pdev, PCI_D3hot);
  193. }
  194. console_lock();
  195. nouveau_fbcon_set_suspend(dev, 1);
  196. console_unlock();
  197. nouveau_fbcon_restore_accel(dev);
  198. return 0;
  199. out_abort:
  200. NV_INFO(dev, "Re-enabling acceleration..\n");
  201. for (e = e + 1; e < NVOBJ_ENGINE_NR; e++) {
  202. if (dev_priv->eng[e])
  203. dev_priv->eng[e]->init(dev, e);
  204. }
  205. pfifo->enable(dev);
  206. pfifo->reassign(dev, true);
  207. return ret;
  208. }
  209. int
  210. nouveau_pci_resume(struct pci_dev *pdev)
  211. {
  212. struct drm_device *dev = pci_get_drvdata(pdev);
  213. struct drm_nouveau_private *dev_priv = dev->dev_private;
  214. struct nouveau_engine *engine = &dev_priv->engine;
  215. struct drm_crtc *crtc;
  216. int ret, i;
  217. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  218. return 0;
  219. nouveau_fbcon_save_disable_accel(dev);
  220. NV_INFO(dev, "We're back, enabling device...\n");
  221. pci_set_power_state(pdev, PCI_D0);
  222. pci_restore_state(pdev);
  223. if (pci_enable_device(pdev))
  224. return -1;
  225. pci_set_master(dev->pdev);
  226. /* Make sure the AGP controller is in a consistent state */
  227. if (dev_priv->gart_info.type == NOUVEAU_GART_AGP)
  228. nouveau_mem_reset_agp(dev);
  229. /* Make the CRTCs accessible */
  230. engine->display.early_init(dev);
  231. NV_INFO(dev, "POSTing device...\n");
  232. ret = nouveau_run_vbios_init(dev);
  233. if (ret)
  234. return ret;
  235. nouveau_pm_resume(dev);
  236. if (dev_priv->gart_info.type == NOUVEAU_GART_AGP) {
  237. ret = nouveau_mem_init_agp(dev);
  238. if (ret) {
  239. NV_ERROR(dev, "error reinitialising AGP: %d\n", ret);
  240. return ret;
  241. }
  242. }
  243. NV_INFO(dev, "Restoring GPU objects...\n");
  244. nouveau_gpuobj_resume(dev);
  245. NV_INFO(dev, "Reinitialising engines...\n");
  246. engine->instmem.resume(dev);
  247. engine->mc.init(dev);
  248. engine->timer.init(dev);
  249. engine->fb.init(dev);
  250. for (i = 0; i < NVOBJ_ENGINE_NR; i++) {
  251. if (dev_priv->eng[i])
  252. dev_priv->eng[i]->init(dev, i);
  253. }
  254. engine->fifo.init(dev);
  255. nouveau_irq_postinstall(dev);
  256. /* Re-write SKIPS, they'll have been lost over the suspend */
  257. if (nouveau_vram_pushbuf) {
  258. struct nouveau_channel *chan;
  259. int j;
  260. for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
  261. chan = dev_priv->channels.ptr[i];
  262. if (!chan || !chan->pushbuf_bo)
  263. continue;
  264. for (j = 0; j < NOUVEAU_DMA_SKIPS; j++)
  265. nouveau_bo_wr32(chan->pushbuf_bo, i, 0);
  266. }
  267. }
  268. NV_INFO(dev, "Restoring mode...\n");
  269. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  270. struct nouveau_framebuffer *nouveau_fb;
  271. nouveau_fb = nouveau_framebuffer(crtc->fb);
  272. if (!nouveau_fb || !nouveau_fb->nvbo)
  273. continue;
  274. nouveau_bo_pin(nouveau_fb->nvbo, TTM_PL_FLAG_VRAM);
  275. }
  276. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  277. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  278. ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM);
  279. if (!ret)
  280. ret = nouveau_bo_map(nv_crtc->cursor.nvbo);
  281. if (ret)
  282. NV_ERROR(dev, "Could not pin/map cursor.\n");
  283. }
  284. engine->display.init(dev);
  285. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  286. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  287. u32 offset = nv_crtc->cursor.nvbo->bo.mem.start << PAGE_SHIFT;
  288. nv_crtc->cursor.set_offset(nv_crtc, offset);
  289. nv_crtc->cursor.set_pos(nv_crtc, nv_crtc->cursor_saved_x,
  290. nv_crtc->cursor_saved_y);
  291. }
  292. /* Force CLUT to get re-loaded during modeset */
  293. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  294. struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
  295. nv_crtc->lut.depth = 0;
  296. }
  297. console_lock();
  298. nouveau_fbcon_set_suspend(dev, 0);
  299. console_unlock();
  300. nouveau_fbcon_zfill_all(dev);
  301. drm_helper_resume_force_mode(dev);
  302. nouveau_fbcon_restore_accel(dev);
  303. return 0;
  304. }
  305. static struct drm_driver driver = {
  306. .driver_features =
  307. DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG |
  308. DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM |
  309. DRIVER_MODESET,
  310. .load = nouveau_load,
  311. .firstopen = nouveau_firstopen,
  312. .lastclose = nouveau_lastclose,
  313. .unload = nouveau_unload,
  314. .preclose = nouveau_preclose,
  315. #if defined(CONFIG_DRM_NOUVEAU_DEBUG)
  316. .debugfs_init = nouveau_debugfs_init,
  317. .debugfs_cleanup = nouveau_debugfs_takedown,
  318. #endif
  319. .irq_preinstall = nouveau_irq_preinstall,
  320. .irq_postinstall = nouveau_irq_postinstall,
  321. .irq_uninstall = nouveau_irq_uninstall,
  322. .irq_handler = nouveau_irq_handler,
  323. .get_vblank_counter = drm_vblank_count,
  324. .enable_vblank = nouveau_vblank_enable,
  325. .disable_vblank = nouveau_vblank_disable,
  326. .reclaim_buffers = drm_core_reclaim_buffers,
  327. .ioctls = nouveau_ioctls,
  328. .fops = {
  329. .owner = THIS_MODULE,
  330. .open = drm_open,
  331. .release = drm_release,
  332. .unlocked_ioctl = drm_ioctl,
  333. .mmap = nouveau_ttm_mmap,
  334. .poll = drm_poll,
  335. .fasync = drm_fasync,
  336. .read = drm_read,
  337. #if defined(CONFIG_COMPAT)
  338. .compat_ioctl = nouveau_compat_ioctl,
  339. #endif
  340. .llseek = noop_llseek,
  341. },
  342. .gem_init_object = nouveau_gem_object_new,
  343. .gem_free_object = nouveau_gem_object_del,
  344. .name = DRIVER_NAME,
  345. .desc = DRIVER_DESC,
  346. #ifdef GIT_REVISION
  347. .date = GIT_REVISION,
  348. #else
  349. .date = DRIVER_DATE,
  350. #endif
  351. .major = DRIVER_MAJOR,
  352. .minor = DRIVER_MINOR,
  353. .patchlevel = DRIVER_PATCHLEVEL,
  354. };
  355. static struct pci_driver nouveau_pci_driver = {
  356. .name = DRIVER_NAME,
  357. .id_table = pciidlist,
  358. .probe = nouveau_pci_probe,
  359. .remove = nouveau_pci_remove,
  360. .suspend = nouveau_pci_suspend,
  361. .resume = nouveau_pci_resume
  362. };
  363. static int __init nouveau_init(void)
  364. {
  365. driver.num_ioctls = nouveau_max_ioctl;
  366. if (nouveau_modeset == -1) {
  367. #ifdef CONFIG_VGA_CONSOLE
  368. if (vgacon_text_force())
  369. nouveau_modeset = 0;
  370. else
  371. #endif
  372. nouveau_modeset = 1;
  373. }
  374. if (!nouveau_modeset)
  375. return 0;
  376. nouveau_register_dsm_handler();
  377. return drm_pci_init(&driver, &nouveau_pci_driver);
  378. }
  379. static void __exit nouveau_exit(void)
  380. {
  381. if (!nouveau_modeset)
  382. return;
  383. drm_pci_exit(&driver, &nouveau_pci_driver);
  384. nouveau_unregister_dsm_handler();
  385. }
  386. module_init(nouveau_init);
  387. module_exit(nouveau_exit);
  388. MODULE_AUTHOR(DRIVER_AUTHOR);
  389. MODULE_DESCRIPTION(DRIVER_DESC);
  390. MODULE_LICENSE("GPL and additional rights");