nouveau_drv.c 11 KB

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