Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 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 | |
| 25 | #include <linux/console.h> |
Paul Gortmaker | e0cd360 | 2011-08-30 11:04:30 -0400 | [diff] [blame] | 26 | #include <linux/module.h> |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 27 | |
| 28 | #include "drmP.h" |
| 29 | #include "drm.h" |
| 30 | #include "drm_crtc_helper.h" |
| 31 | #include "nouveau_drv.h" |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 32 | #include "nouveau_abi16.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 33 | #include "nouveau_hw.h" |
| 34 | #include "nouveau_fb.h" |
| 35 | #include "nouveau_fbcon.h" |
Ben Skeggs | 64f1c11 | 2010-09-17 13:35:25 +1000 | [diff] [blame] | 36 | #include "nouveau_pm.h" |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 37 | #include "nouveau_fifo.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 38 | #include "nv50_display.h" |
| 39 | |
| 40 | #include "drm_pciids.h" |
| 41 | |
Francisco Jerez | de5899b | 2010-09-08 02:28:23 +0200 | [diff] [blame] | 42 | MODULE_PARM_DESC(agpmode, "AGP mode (0 to disable AGP)"); |
| 43 | int nouveau_agpmode = -1; |
| 44 | module_param_named(agpmode, nouveau_agpmode, int, 0400); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 45 | |
| 46 | MODULE_PARM_DESC(modeset, "Enable kernel modesetting"); |
Ben Skeggs | 03bc967 | 2011-07-04 13:14:05 +1000 | [diff] [blame] | 47 | int nouveau_modeset = -1; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 48 | module_param_named(modeset, nouveau_modeset, int, 0400); |
| 49 | |
| 50 | MODULE_PARM_DESC(vbios, "Override default VBIOS location"); |
| 51 | char *nouveau_vbios; |
| 52 | module_param_named(vbios, nouveau_vbios, charp, 0400); |
| 53 | |
| 54 | MODULE_PARM_DESC(vram_pushbuf, "Force DMA push buffers to be in VRAM"); |
| 55 | int nouveau_vram_pushbuf; |
| 56 | module_param_named(vram_pushbuf, nouveau_vram_pushbuf, int, 0400); |
| 57 | |
| 58 | MODULE_PARM_DESC(vram_notify, "Force DMA notifiers to be in VRAM"); |
Ben Skeggs | 2dfe36b | 2010-06-01 09:47:43 +1000 | [diff] [blame] | 59 | int nouveau_vram_notify = 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 60 | module_param_named(vram_notify, nouveau_vram_notify, int, 0400); |
| 61 | |
Ben Skeggs | 7ad2d31 | 2011-12-11 00:30:05 +1000 | [diff] [blame] | 62 | MODULE_PARM_DESC(vram_type, "Override detected VRAM type"); |
| 63 | char *nouveau_vram_type; |
| 64 | module_param_named(vram_type, nouveau_vram_type, charp, 0400); |
| 65 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 66 | MODULE_PARM_DESC(duallink, "Allow dual-link TMDS (>=GeForce 8)"); |
| 67 | int nouveau_duallink = 1; |
| 68 | module_param_named(duallink, nouveau_duallink, int, 0400); |
| 69 | |
| 70 | MODULE_PARM_DESC(uscript_lvds, "LVDS output script table ID (>=GeForce 8)"); |
| 71 | int nouveau_uscript_lvds = -1; |
| 72 | module_param_named(uscript_lvds, nouveau_uscript_lvds, int, 0400); |
| 73 | |
| 74 | MODULE_PARM_DESC(uscript_tmds, "TMDS output script table ID (>=GeForce 8)"); |
| 75 | int nouveau_uscript_tmds = -1; |
| 76 | module_param_named(uscript_tmds, nouveau_uscript_tmds, int, 0400); |
| 77 | |
Ben Skeggs | a147089 | 2010-01-18 11:42:37 +1000 | [diff] [blame] | 78 | MODULE_PARM_DESC(ignorelid, "Ignore ACPI lid status"); |
| 79 | int nouveau_ignorelid = 0; |
| 80 | module_param_named(ignorelid, nouveau_ignorelid, int, 0400); |
| 81 | |
Marcin Kościelnicki | 81e2d42 | 2010-02-25 00:54:04 +0000 | [diff] [blame] | 82 | MODULE_PARM_DESC(noaccel, "Disable all acceleration"); |
Ben Skeggs | aba99a8 | 2011-05-25 14:48:50 +1000 | [diff] [blame] | 83 | int nouveau_noaccel = -1; |
Marcin Kościelnicki | a32ed69 | 2010-01-26 14:00:42 +0000 | [diff] [blame] | 84 | module_param_named(noaccel, nouveau_noaccel, int, 0400); |
| 85 | |
Marcin Kościelnicki | 81e2d42 | 2010-02-25 00:54:04 +0000 | [diff] [blame] | 86 | MODULE_PARM_DESC(nofbaccel, "Disable fbcon acceleration"); |
Marcin Kościelnicki | a32ed69 | 2010-01-26 14:00:42 +0000 | [diff] [blame] | 87 | int nouveau_nofbaccel = 0; |
| 88 | module_param_named(nofbaccel, nouveau_nofbaccel, int, 0400); |
| 89 | |
Marcin Kościelnicki | 0cba1b7 | 2010-09-29 11:15:01 +0000 | [diff] [blame] | 90 | MODULE_PARM_DESC(force_post, "Force POST"); |
| 91 | int nouveau_force_post = 0; |
| 92 | module_param_named(force_post, nouveau_force_post, int, 0400); |
| 93 | |
Ben Skeggs | da647d5 | 2010-03-04 12:00:39 +1000 | [diff] [blame] | 94 | MODULE_PARM_DESC(override_conntype, "Ignore DCB connector type"); |
| 95 | int nouveau_override_conntype = 0; |
| 96 | module_param_named(override_conntype, nouveau_override_conntype, int, 0400); |
| 97 | |
Jean Delvare | 1a5f985 | 2011-11-30 17:23:55 +0100 | [diff] [blame] | 98 | MODULE_PARM_DESC(tv_disable, "Disable TV-out detection"); |
Ben Skeggs | f405350 | 2010-03-15 09:43:51 +1000 | [diff] [blame] | 99 | int nouveau_tv_disable = 0; |
| 100 | module_param_named(tv_disable, nouveau_tv_disable, int, 0400); |
| 101 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 102 | MODULE_PARM_DESC(tv_norm, "Default TV norm.\n" |
| 103 | "\t\tSupported: PAL, PAL-M, PAL-N, PAL-Nc, NTSC-M, NTSC-J,\n" |
| 104 | "\t\t\thd480i, hd480p, hd576i, hd576p, hd720p, hd1080i.\n" |
| 105 | "\t\tDefault: PAL\n" |
| 106 | "\t\t*NOTE* Ignored for cards with external TV encoders."); |
| 107 | char *nouveau_tv_norm; |
| 108 | module_param_named(tv_norm, nouveau_tv_norm, charp, 0400); |
| 109 | |
| 110 | MODULE_PARM_DESC(reg_debug, "Register access debug bitmask:\n" |
| 111 | "\t\t0x1 mc, 0x2 video, 0x4 fb, 0x8 extdev,\n" |
| 112 | "\t\t0x10 crtc, 0x20 ramdac, 0x40 vgacrtc, 0x80 rmvio,\n" |
Jean Delvare | 1a5f985 | 2011-11-30 17:23:55 +0100 | [diff] [blame] | 113 | "\t\t0x100 vgaattr, 0x200 EVO (G80+)"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 114 | int nouveau_reg_debug; |
| 115 | module_param_named(reg_debug, nouveau_reg_debug, int, 0600); |
| 116 | |
Jean Delvare | 1a5f985 | 2011-11-30 17:23:55 +0100 | [diff] [blame] | 117 | MODULE_PARM_DESC(perflvl, "Performance level (default: boot)"); |
Ben Skeggs | 6f87698 | 2010-09-16 16:47:14 +1000 | [diff] [blame] | 118 | char *nouveau_perflvl; |
| 119 | module_param_named(perflvl, nouveau_perflvl, charp, 0400); |
| 120 | |
Jean Delvare | 1a5f985 | 2011-11-30 17:23:55 +0100 | [diff] [blame] | 121 | MODULE_PARM_DESC(perflvl_wr, "Allow perflvl changes (warning: dangerous!)"); |
Ben Skeggs | 6f87698 | 2010-09-16 16:47:14 +1000 | [diff] [blame] | 122 | int nouveau_perflvl_wr; |
| 123 | module_param_named(perflvl_wr, nouveau_perflvl_wr, int, 0400); |
| 124 | |
Jean Delvare | 1a5f985 | 2011-11-30 17:23:55 +0100 | [diff] [blame] | 125 | MODULE_PARM_DESC(msi, "Enable MSI (default: off)"); |
Ben Skeggs | 35fa2f2 | 2010-10-21 14:07:03 +1000 | [diff] [blame] | 126 | int nouveau_msi; |
| 127 | module_param_named(msi, nouveau_msi, int, 0400); |
| 128 | |
Jean Delvare | 1a5f985 | 2011-11-30 17:23:55 +0100 | [diff] [blame] | 129 | MODULE_PARM_DESC(ctxfw, "Use external HUB/GPC ucode (fermi)"); |
Ben Skeggs | 0411de8 | 2011-05-25 18:32:44 +1000 | [diff] [blame] | 130 | int nouveau_ctxfw; |
| 131 | module_param_named(ctxfw, nouveau_ctxfw, int, 0400); |
| 132 | |
Jean Delvare | 1a5f985 | 2011-11-30 17:23:55 +0100 | [diff] [blame] | 133 | MODULE_PARM_DESC(mxmdcb, "Santise DCB table according to MXM-SIS"); |
Ben Skeggs | b4c2681 | 2011-10-12 16:36:42 +1000 | [diff] [blame] | 134 | int nouveau_mxmdcb = 1; |
| 135 | module_param_named(mxmdcb, nouveau_mxmdcb, int, 0400); |
| 136 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 137 | int nouveau_fbpercrtc; |
| 138 | #if 0 |
| 139 | module_param_named(fbpercrtc, nouveau_fbpercrtc, int, 0400); |
| 140 | #endif |
| 141 | |
| 142 | static struct pci_device_id pciidlist[] = { |
| 143 | { |
| 144 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID), |
| 145 | .class = PCI_BASE_CLASS_DISPLAY << 16, |
| 146 | .class_mask = 0xff << 16, |
| 147 | }, |
| 148 | { |
| 149 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA_SGS, PCI_ANY_ID), |
| 150 | .class = PCI_BASE_CLASS_DISPLAY << 16, |
| 151 | .class_mask = 0xff << 16, |
| 152 | }, |
| 153 | {} |
| 154 | }; |
| 155 | |
| 156 | MODULE_DEVICE_TABLE(pci, pciidlist); |
| 157 | |
| 158 | static struct drm_driver driver; |
| 159 | |
| 160 | static int __devinit |
| 161 | nouveau_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 162 | { |
Jordan Crouse | dcdb167 | 2010-05-27 13:40:25 -0600 | [diff] [blame] | 163 | return drm_get_pci_dev(pdev, ent, &driver); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | static void |
| 167 | nouveau_pci_remove(struct pci_dev *pdev) |
| 168 | { |
| 169 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 170 | |
| 171 | drm_put_dev(dev); |
| 172 | } |
| 173 | |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 174 | int |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 175 | nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state) |
| 176 | { |
| 177 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 178 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 179 | struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem; |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 180 | struct nouveau_fifo_priv *pfifo = nv_engine(dev, NVOBJ_ENGINE_FIFO); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 181 | struct nouveau_channel *chan; |
| 182 | struct drm_crtc *crtc; |
Ben Skeggs | 92abe74 | 2011-04-01 13:26:35 +1000 | [diff] [blame] | 183 | int ret, i, e; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 184 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 185 | if (pm_state.event == PM_EVENT_PRETHAW) |
| 186 | return 0; |
| 187 | |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 188 | if (dev->switch_power_state == DRM_SWITCH_POWER_OFF) |
| 189 | return 0; |
| 190 | |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 191 | NV_INFO(dev, "Disabling display...\n"); |
| 192 | nouveau_display_fini(dev); |
Maxim Levitsky | 4bfb94a | 2011-10-09 22:58:33 +0200 | [diff] [blame] | 193 | |
Ben Skeggs | cf41d53 | 2011-11-09 14:31:16 +1000 | [diff] [blame] | 194 | NV_INFO(dev, "Disabling fbcon...\n"); |
| 195 | nouveau_fbcon_set_suspend(dev, 1); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 196 | |
Maarten Maathuis | 81441570 | 2010-02-21 13:28:35 +0100 | [diff] [blame] | 197 | NV_INFO(dev, "Unpinning framebuffer(s)...\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 198 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 199 | struct nouveau_framebuffer *nouveau_fb; |
| 200 | |
| 201 | nouveau_fb = nouveau_framebuffer(crtc->fb); |
| 202 | if (!nouveau_fb || !nouveau_fb->nvbo) |
| 203 | continue; |
| 204 | |
| 205 | nouveau_bo_unpin(nouveau_fb->nvbo); |
| 206 | } |
| 207 | |
Maarten Maathuis | b334f2b | 2010-05-09 14:49:52 +0200 | [diff] [blame] | 208 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 209 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 210 | |
| 211 | nouveau_bo_unmap(nv_crtc->cursor.nvbo); |
| 212 | nouveau_bo_unpin(nv_crtc->cursor.nvbo); |
| 213 | } |
| 214 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 215 | NV_INFO(dev, "Evicting buffers...\n"); |
| 216 | ttm_bo_evict_mm(&dev_priv->ttm.bdev, TTM_PL_VRAM); |
| 217 | |
| 218 | NV_INFO(dev, "Idling channels...\n"); |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 219 | for (i = 0; i < (pfifo ? pfifo->channels : 0); i++) { |
Ben Skeggs | cff5c13 | 2010-10-06 16:16:59 +1000 | [diff] [blame] | 220 | chan = dev_priv->channels.ptr[i]; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 221 | |
Francisco Jerez | 6dccd31 | 2010-11-18 23:57:46 +0100 | [diff] [blame] | 222 | if (chan && chan->pushbuf_bo) |
| 223 | nouveau_channel_idle(chan); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 224 | } |
| 225 | |
Ben Skeggs | 92abe74 | 2011-04-01 13:26:35 +1000 | [diff] [blame] | 226 | for (e = NVOBJ_ENGINE_NR - 1; e >= 0; e--) { |
Ben Skeggs | 6c320fe | 2011-07-20 11:22:33 +1000 | [diff] [blame] | 227 | if (!dev_priv->eng[e]) |
| 228 | continue; |
| 229 | |
| 230 | ret = dev_priv->eng[e]->fini(dev, e, true); |
| 231 | if (ret) { |
Marcin Slusarz | 13f9012 | 2011-11-06 20:32:03 +0100 | [diff] [blame] | 232 | NV_ERROR(dev, "... engine %d failed: %d\n", e, ret); |
Ben Skeggs | 6c320fe | 2011-07-20 11:22:33 +1000 | [diff] [blame] | 233 | goto out_abort; |
Ben Skeggs | 92abe74 | 2011-04-01 13:26:35 +1000 | [diff] [blame] | 234 | } |
| 235 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 236 | |
Ben Skeggs | dc1e5c0 | 2010-10-25 15:23:59 +1000 | [diff] [blame] | 237 | ret = pinstmem->suspend(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 238 | if (ret) { |
| 239 | NV_ERROR(dev, "... failed: %d\n", ret); |
| 240 | goto out_abort; |
| 241 | } |
| 242 | |
Ben Skeggs | dc1e5c0 | 2010-10-25 15:23:59 +1000 | [diff] [blame] | 243 | NV_INFO(dev, "Suspending GPU objects...\n"); |
| 244 | ret = nouveau_gpuobj_suspend(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 245 | if (ret) { |
| 246 | NV_ERROR(dev, "... failed: %d\n", ret); |
Ben Skeggs | dc1e5c0 | 2010-10-25 15:23:59 +1000 | [diff] [blame] | 247 | pinstmem->resume(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 248 | goto out_abort; |
| 249 | } |
| 250 | |
| 251 | NV_INFO(dev, "And we're gone!\n"); |
| 252 | pci_save_state(pdev); |
| 253 | if (pm_state.event == PM_EVENT_SUSPEND) { |
| 254 | pci_disable_device(pdev); |
| 255 | pci_set_power_state(pdev, PCI_D3hot); |
| 256 | } |
| 257 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 258 | return 0; |
| 259 | |
| 260 | out_abort: |
| 261 | NV_INFO(dev, "Re-enabling acceleration..\n"); |
Ben Skeggs | 92abe74 | 2011-04-01 13:26:35 +1000 | [diff] [blame] | 262 | for (e = e + 1; e < NVOBJ_ENGINE_NR; e++) { |
| 263 | if (dev_priv->eng[e]) |
| 264 | dev_priv->eng[e]->init(dev, e); |
| 265 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 266 | return ret; |
| 267 | } |
| 268 | |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 269 | int |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 270 | nouveau_pci_resume(struct pci_dev *pdev) |
| 271 | { |
| 272 | struct drm_device *dev = pci_get_drvdata(pdev); |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 273 | struct nouveau_fifo_priv *pfifo = nv_engine(dev, NVOBJ_ENGINE_FIFO); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 274 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 275 | struct nouveau_engine *engine = &dev_priv->engine; |
| 276 | struct drm_crtc *crtc; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 277 | int ret, i; |
| 278 | |
Dave Airlie | 5bcf719 | 2010-12-07 09:20:40 +1000 | [diff] [blame] | 279 | if (dev->switch_power_state == DRM_SWITCH_POWER_OFF) |
| 280 | return 0; |
| 281 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 282 | NV_INFO(dev, "We're back, enabling device...\n"); |
| 283 | pci_set_power_state(pdev, PCI_D0); |
| 284 | pci_restore_state(pdev); |
| 285 | if (pci_enable_device(pdev)) |
| 286 | return -1; |
| 287 | pci_set_master(dev->pdev); |
| 288 | |
Francisco Jerez | e04d8e8 | 2010-07-23 20:29:13 +0200 | [diff] [blame] | 289 | /* Make sure the AGP controller is in a consistent state */ |
| 290 | if (dev_priv->gart_info.type == NOUVEAU_GART_AGP) |
| 291 | nouveau_mem_reset_agp(dev); |
| 292 | |
Francisco Jerez | c88c2e0 | 2010-07-24 17:37:33 +0200 | [diff] [blame] | 293 | /* Make the CRTCs accessible */ |
| 294 | engine->display.early_init(dev); |
| 295 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 296 | NV_INFO(dev, "POSTing device...\n"); |
| 297 | ret = nouveau_run_vbios_init(dev); |
| 298 | if (ret) |
| 299 | return ret; |
| 300 | |
| 301 | if (dev_priv->gart_info.type == NOUVEAU_GART_AGP) { |
| 302 | ret = nouveau_mem_init_agp(dev); |
| 303 | if (ret) { |
| 304 | NV_ERROR(dev, "error reinitialising AGP: %d\n", ret); |
| 305 | return ret; |
| 306 | } |
| 307 | } |
| 308 | |
Ben Skeggs | dc1e5c0 | 2010-10-25 15:23:59 +1000 | [diff] [blame] | 309 | NV_INFO(dev, "Restoring GPU objects...\n"); |
| 310 | nouveau_gpuobj_resume(dev); |
| 311 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 312 | NV_INFO(dev, "Reinitialising engines...\n"); |
| 313 | engine->instmem.resume(dev); |
| 314 | engine->mc.init(dev); |
| 315 | engine->timer.init(dev); |
| 316 | engine->fb.init(dev); |
Ben Skeggs | 6dfdd7a | 2011-03-31 15:40:43 +1000 | [diff] [blame] | 317 | for (i = 0; i < NVOBJ_ENGINE_NR; i++) { |
| 318 | if (dev_priv->eng[i]) |
| 319 | dev_priv->eng[i]->init(dev, i); |
| 320 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 321 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 322 | nouveau_irq_postinstall(dev); |
| 323 | |
| 324 | /* Re-write SKIPS, they'll have been lost over the suspend */ |
| 325 | if (nouveau_vram_pushbuf) { |
| 326 | struct nouveau_channel *chan; |
| 327 | int j; |
| 328 | |
Ben Skeggs | c420b2d | 2012-05-01 20:48:08 +1000 | [diff] [blame] | 329 | for (i = 0; i < (pfifo ? pfifo->channels : 0); i++) { |
Ben Skeggs | cff5c13 | 2010-10-06 16:16:59 +1000 | [diff] [blame] | 330 | chan = dev_priv->channels.ptr[i]; |
Ben Skeggs | 3c8868d | 2009-12-16 14:51:13 +1000 | [diff] [blame] | 331 | if (!chan || !chan->pushbuf_bo) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 332 | continue; |
| 333 | |
| 334 | for (j = 0; j < NOUVEAU_DMA_SKIPS; j++) |
| 335 | nouveau_bo_wr32(chan->pushbuf_bo, i, 0); |
| 336 | } |
| 337 | } |
| 338 | |
Maxim Levitsky | 71d91f6 | 2011-10-09 22:58:35 +0200 | [diff] [blame] | 339 | nouveau_pm_resume(dev); |
| 340 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 341 | NV_INFO(dev, "Restoring mode...\n"); |
| 342 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 343 | struct nouveau_framebuffer *nouveau_fb; |
| 344 | |
| 345 | nouveau_fb = nouveau_framebuffer(crtc->fb); |
| 346 | if (!nouveau_fb || !nouveau_fb->nvbo) |
| 347 | continue; |
| 348 | |
| 349 | nouveau_bo_pin(nouveau_fb->nvbo, TTM_PL_FLAG_VRAM); |
| 350 | } |
| 351 | |
Maarten Maathuis | b334f2b | 2010-05-09 14:49:52 +0200 | [diff] [blame] | 352 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 353 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Maarten Maathuis | b334f2b | 2010-05-09 14:49:52 +0200 | [diff] [blame] | 354 | |
| 355 | ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM); |
| 356 | if (!ret) |
| 357 | ret = nouveau_bo_map(nv_crtc->cursor.nvbo); |
| 358 | if (ret) |
| 359 | NV_ERROR(dev, "Could not pin/map cursor.\n"); |
| 360 | } |
| 361 | |
Ben Skeggs | cf41d53 | 2011-11-09 14:31:16 +1000 | [diff] [blame] | 362 | nouveau_fbcon_set_suspend(dev, 0); |
| 363 | nouveau_fbcon_zfill_all(dev); |
| 364 | |
Ben Skeggs | f62b27d | 2011-11-09 15:18:47 +1000 | [diff] [blame] | 365 | nouveau_display_init(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 366 | |
| 367 | /* Force CLUT to get re-loaded during modeset */ |
| 368 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 369 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 370 | |
| 371 | nv_crtc->lut.depth = 0; |
| 372 | } |
| 373 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 374 | drm_helper_resume_force_mode(dev); |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 375 | |
Maxim Levitsky | a4eaa0a | 2011-10-09 22:58:34 +0200 | [diff] [blame] | 376 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 377 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 378 | u32 offset = nv_crtc->cursor.nvbo->bo.offset; |
| 379 | |
| 380 | nv_crtc->cursor.set_offset(nv_crtc, offset); |
| 381 | nv_crtc->cursor.set_pos(nv_crtc, nv_crtc->cursor_saved_x, |
| 382 | nv_crtc->cursor_saved_y); |
| 383 | } |
| 384 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 385 | return 0; |
| 386 | } |
| 387 | |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 388 | static struct drm_ioctl_desc nouveau_ioctls[] = { |
| 389 | DRM_IOCTL_DEF_DRV(NOUVEAU_GETPARAM, nouveau_abi16_ioctl_getparam, DRM_UNLOCKED|DRM_AUTH), |
| 390 | DRM_IOCTL_DEF_DRV(NOUVEAU_SETPARAM, nouveau_abi16_ioctl_setparam, DRM_UNLOCKED|DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 391 | DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_ALLOC, nouveau_abi16_ioctl_channel_alloc, DRM_UNLOCKED|DRM_AUTH), |
| 392 | DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_FREE, nouveau_abi16_ioctl_channel_free, DRM_UNLOCKED|DRM_AUTH), |
| 393 | DRM_IOCTL_DEF_DRV(NOUVEAU_GROBJ_ALLOC, nouveau_abi16_ioctl_grobj_alloc, DRM_UNLOCKED|DRM_AUTH), |
| 394 | DRM_IOCTL_DEF_DRV(NOUVEAU_NOTIFIEROBJ_ALLOC, nouveau_abi16_ioctl_notifierobj_alloc, DRM_UNLOCKED|DRM_AUTH), |
| 395 | DRM_IOCTL_DEF_DRV(NOUVEAU_GPUOBJ_FREE, nouveau_abi16_ioctl_gpuobj_free, DRM_UNLOCKED|DRM_AUTH), |
| 396 | DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_NEW, nouveau_gem_ioctl_new, DRM_UNLOCKED|DRM_AUTH), |
| 397 | DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_PUSHBUF, nouveau_gem_ioctl_pushbuf, DRM_UNLOCKED|DRM_AUTH), |
| 398 | DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_PREP, nouveau_gem_ioctl_cpu_prep, DRM_UNLOCKED|DRM_AUTH), |
| 399 | DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_FINI, nouveau_gem_ioctl_cpu_fini, DRM_UNLOCKED|DRM_AUTH), |
| 400 | DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_INFO, nouveau_gem_ioctl_info, DRM_UNLOCKED|DRM_AUTH), |
| 401 | }; |
| 402 | |
Arjan van de Ven | e08e96d | 2011-10-31 07:28:57 -0700 | [diff] [blame] | 403 | static const struct file_operations nouveau_driver_fops = { |
| 404 | .owner = THIS_MODULE, |
| 405 | .open = drm_open, |
| 406 | .release = drm_release, |
| 407 | .unlocked_ioctl = drm_ioctl, |
| 408 | .mmap = nouveau_ttm_mmap, |
| 409 | .poll = drm_poll, |
| 410 | .fasync = drm_fasync, |
| 411 | .read = drm_read, |
| 412 | #if defined(CONFIG_COMPAT) |
| 413 | .compat_ioctl = nouveau_compat_ioctl, |
| 414 | #endif |
| 415 | .llseek = noop_llseek, |
| 416 | }; |
| 417 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 418 | static struct drm_driver driver = { |
| 419 | .driver_features = |
| 420 | DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG | |
Ben Skeggs | cd0b072 | 2010-06-01 15:56:22 +1000 | [diff] [blame] | 421 | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 422 | DRIVER_MODESET | DRIVER_PRIME, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 423 | .load = nouveau_load, |
| 424 | .firstopen = nouveau_firstopen, |
| 425 | .lastclose = nouveau_lastclose, |
| 426 | .unload = nouveau_unload, |
Ben Skeggs | 3f0a68d | 2011-05-31 11:11:28 +1000 | [diff] [blame] | 427 | .open = nouveau_open, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 428 | .preclose = nouveau_preclose, |
Ben Skeggs | 3f0a68d | 2011-05-31 11:11:28 +1000 | [diff] [blame] | 429 | .postclose = nouveau_postclose, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 430 | #if defined(CONFIG_DRM_NOUVEAU_DEBUG) |
| 431 | .debugfs_init = nouveau_debugfs_init, |
| 432 | .debugfs_cleanup = nouveau_debugfs_takedown, |
| 433 | #endif |
| 434 | .irq_preinstall = nouveau_irq_preinstall, |
| 435 | .irq_postinstall = nouveau_irq_postinstall, |
| 436 | .irq_uninstall = nouveau_irq_uninstall, |
| 437 | .irq_handler = nouveau_irq_handler, |
Francisco Jerez | 042206c | 2010-10-21 18:19:29 +0200 | [diff] [blame] | 438 | .get_vblank_counter = drm_vblank_count, |
| 439 | .enable_vblank = nouveau_vblank_enable, |
| 440 | .disable_vblank = nouveau_vblank_disable, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 441 | .ioctls = nouveau_ioctls, |
Arjan van de Ven | e08e96d | 2011-10-31 07:28:57 -0700 | [diff] [blame] | 442 | .fops = &nouveau_driver_fops, |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 443 | |
| 444 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
| 445 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
| 446 | .gem_prime_export = nouveau_gem_prime_export, |
| 447 | .gem_prime_import = nouveau_gem_prime_import, |
| 448 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 449 | .gem_init_object = nouveau_gem_object_new, |
| 450 | .gem_free_object = nouveau_gem_object_del, |
Ben Skeggs | 639212d | 2011-06-03 16:18:26 +1000 | [diff] [blame] | 451 | .gem_open_object = nouveau_gem_object_open, |
| 452 | .gem_close_object = nouveau_gem_object_close, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 453 | |
Ben Skeggs | 33dbc27 | 2011-09-30 08:55:50 +1000 | [diff] [blame] | 454 | .dumb_create = nouveau_display_dumb_create, |
| 455 | .dumb_map_offset = nouveau_display_dumb_map_offset, |
| 456 | .dumb_destroy = nouveau_display_dumb_destroy, |
| 457 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 458 | .name = DRIVER_NAME, |
| 459 | .desc = DRIVER_DESC, |
| 460 | #ifdef GIT_REVISION |
| 461 | .date = GIT_REVISION, |
| 462 | #else |
| 463 | .date = DRIVER_DATE, |
| 464 | #endif |
| 465 | .major = DRIVER_MAJOR, |
| 466 | .minor = DRIVER_MINOR, |
| 467 | .patchlevel = DRIVER_PATCHLEVEL, |
| 468 | }; |
| 469 | |
Dave Airlie | 8410ea3 | 2010-12-15 03:16:38 +1000 | [diff] [blame] | 470 | static struct pci_driver nouveau_pci_driver = { |
| 471 | .name = DRIVER_NAME, |
| 472 | .id_table = pciidlist, |
| 473 | .probe = nouveau_pci_probe, |
| 474 | .remove = nouveau_pci_remove, |
| 475 | .suspend = nouveau_pci_suspend, |
| 476 | .resume = nouveau_pci_resume |
| 477 | }; |
| 478 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 479 | static int __init nouveau_init(void) |
| 480 | { |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 481 | driver.num_ioctls = ARRAY_SIZE(nouveau_ioctls); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 482 | |
| 483 | if (nouveau_modeset == -1) { |
| 484 | #ifdef CONFIG_VGA_CONSOLE |
| 485 | if (vgacon_text_force()) |
| 486 | nouveau_modeset = 0; |
| 487 | else |
| 488 | #endif |
| 489 | nouveau_modeset = 1; |
| 490 | } |
| 491 | |
Ben Skeggs | cd0b072 | 2010-06-01 15:56:22 +1000 | [diff] [blame] | 492 | if (!nouveau_modeset) |
| 493 | return 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 494 | |
Ben Skeggs | cd0b072 | 2010-06-01 15:56:22 +1000 | [diff] [blame] | 495 | nouveau_register_dsm_handler(); |
Dave Airlie | 8410ea3 | 2010-12-15 03:16:38 +1000 | [diff] [blame] | 496 | return drm_pci_init(&driver, &nouveau_pci_driver); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | static void __exit nouveau_exit(void) |
| 500 | { |
Ben Skeggs | cd0b072 | 2010-06-01 15:56:22 +1000 | [diff] [blame] | 501 | if (!nouveau_modeset) |
| 502 | return; |
| 503 | |
Dave Airlie | 8410ea3 | 2010-12-15 03:16:38 +1000 | [diff] [blame] | 504 | drm_pci_exit(&driver, &nouveau_pci_driver); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 505 | nouveau_unregister_dsm_handler(); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | module_init(nouveau_init); |
| 509 | module_exit(nouveau_exit); |
| 510 | |
| 511 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 512 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 513 | MODULE_LICENSE("GPL and additional rights"); |