drm/nouveau/fence: un-port from nouveau_exec_engine interfaces
[linux-2.6-block.git] / drivers / gpu / drm / nouveau / nouveau_drv.c
CommitLineData
6ee73861
BS
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>
e0cd3608 26#include <linux/module.h>
6ee73861
BS
27
28#include "drmP.h"
29#include "drm.h"
30#include "drm_crtc_helper.h"
31#include "nouveau_drv.h"
2a259a3d 32#include "nouveau_abi16.h"
6ee73861
BS
33#include "nouveau_hw.h"
34#include "nouveau_fb.h"
35#include "nouveau_fbcon.h"
e193b1d4 36#include "nouveau_fence.h"
64f1c11a 37#include "nouveau_pm.h"
02a841d4 38#include <engine/fifo.h>
6ee73861
BS
39#include "nv50_display.h"
40
41#include "drm_pciids.h"
42
6ee73861 43MODULE_PARM_DESC(modeset, "Enable kernel modesetting");
03bc9675 44int nouveau_modeset = -1;
6ee73861 45module_param_named(modeset, nouveau_modeset, int, 0400);
6ee73861
BS
46
47MODULE_PARM_DESC(vram_notify, "Force DMA notifiers to be in VRAM");
2dfe36b1 48int nouveau_vram_notify = 0;
6ee73861
BS
49module_param_named(vram_notify, nouveau_vram_notify, int, 0400);
50
7ad2d31c
BS
51MODULE_PARM_DESC(vram_type, "Override detected VRAM type");
52char *nouveau_vram_type;
53module_param_named(vram_type, nouveau_vram_type, charp, 0400);
54
6ee73861
BS
55MODULE_PARM_DESC(duallink, "Allow dual-link TMDS (>=GeForce 8)");
56int nouveau_duallink = 1;
57module_param_named(duallink, nouveau_duallink, int, 0400);
58
59MODULE_PARM_DESC(uscript_lvds, "LVDS output script table ID (>=GeForce 8)");
60int nouveau_uscript_lvds = -1;
61module_param_named(uscript_lvds, nouveau_uscript_lvds, int, 0400);
62
63MODULE_PARM_DESC(uscript_tmds, "TMDS output script table ID (>=GeForce 8)");
64int nouveau_uscript_tmds = -1;
65module_param_named(uscript_tmds, nouveau_uscript_tmds, int, 0400);
66
a1470890
BS
67MODULE_PARM_DESC(ignorelid, "Ignore ACPI lid status");
68int nouveau_ignorelid = 0;
69module_param_named(ignorelid, nouveau_ignorelid, int, 0400);
70
81e2d422 71MODULE_PARM_DESC(noaccel, "Disable all acceleration");
aba99a84 72int nouveau_noaccel = -1;
a32ed69d
MK
73module_param_named(noaccel, nouveau_noaccel, int, 0400);
74
81e2d422 75MODULE_PARM_DESC(nofbaccel, "Disable fbcon acceleration");
a32ed69d
MK
76int nouveau_nofbaccel = 0;
77module_param_named(nofbaccel, nouveau_nofbaccel, int, 0400);
78
0cba1b76
MK
79MODULE_PARM_DESC(force_post, "Force POST");
80int nouveau_force_post = 0;
81module_param_named(force_post, nouveau_force_post, int, 0400);
82
da647d5b
BS
83MODULE_PARM_DESC(override_conntype, "Ignore DCB connector type");
84int nouveau_override_conntype = 0;
85module_param_named(override_conntype, nouveau_override_conntype, int, 0400);
86
1a5f985c 87MODULE_PARM_DESC(tv_disable, "Disable TV-out detection");
f4053509
BS
88int nouveau_tv_disable = 0;
89module_param_named(tv_disable, nouveau_tv_disable, int, 0400);
90
6ee73861
BS
91MODULE_PARM_DESC(tv_norm, "Default TV norm.\n"
92 "\t\tSupported: PAL, PAL-M, PAL-N, PAL-Nc, NTSC-M, NTSC-J,\n"
93 "\t\t\thd480i, hd480p, hd576i, hd576p, hd720p, hd1080i.\n"
94 "\t\tDefault: PAL\n"
95 "\t\t*NOTE* Ignored for cards with external TV encoders.");
96char *nouveau_tv_norm;
97module_param_named(tv_norm, nouveau_tv_norm, charp, 0400);
98
99MODULE_PARM_DESC(reg_debug, "Register access debug bitmask:\n"
100 "\t\t0x1 mc, 0x2 video, 0x4 fb, 0x8 extdev,\n"
101 "\t\t0x10 crtc, 0x20 ramdac, 0x40 vgacrtc, 0x80 rmvio,\n"
1a5f985c 102 "\t\t0x100 vgaattr, 0x200 EVO (G80+)");
6ee73861
BS
103int nouveau_reg_debug;
104module_param_named(reg_debug, nouveau_reg_debug, int, 0600);
105
1a5f985c 106MODULE_PARM_DESC(perflvl, "Performance level (default: boot)");
6f876986
BS
107char *nouveau_perflvl;
108module_param_named(perflvl, nouveau_perflvl, charp, 0400);
109
1a5f985c 110MODULE_PARM_DESC(perflvl_wr, "Allow perflvl changes (warning: dangerous!)");
6f876986
BS
111int nouveau_perflvl_wr;
112module_param_named(perflvl_wr, nouveau_perflvl_wr, int, 0400);
113
1a5f985c 114MODULE_PARM_DESC(msi, "Enable MSI (default: off)");
35fa2f2a
BS
115int nouveau_msi;
116module_param_named(msi, nouveau_msi, int, 0400);
117
1a5f985c 118MODULE_PARM_DESC(ctxfw, "Use external HUB/GPC ucode (fermi)");
0411de85
BS
119int nouveau_ctxfw;
120module_param_named(ctxfw, nouveau_ctxfw, int, 0400);
121
1a5f985c 122MODULE_PARM_DESC(mxmdcb, "Santise DCB table according to MXM-SIS");
b4c26818
BS
123int nouveau_mxmdcb = 1;
124module_param_named(mxmdcb, nouveau_mxmdcb, int, 0400);
125
6ee73861
BS
126int nouveau_fbpercrtc;
127#if 0
128module_param_named(fbpercrtc, nouveau_fbpercrtc, int, 0400);
129#endif
130
6ee73861
BS
131static struct drm_driver driver;
132
94580299 133int __devinit
6ee73861
BS
134nouveau_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
135{
dcdb1674 136 return drm_get_pci_dev(pdev, ent, &driver);
6ee73861
BS
137}
138
94580299 139void
6ee73861
BS
140nouveau_pci_remove(struct pci_dev *pdev)
141{
142 struct drm_device *dev = pci_get_drvdata(pdev);
143
144 drm_put_dev(dev);
145}
146
6a9ee8af 147int
6ee73861
BS
148nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state)
149{
150 struct drm_device *dev = pci_get_drvdata(pdev);
151 struct drm_nouveau_private *dev_priv = dev->dev_private;
c420b2dc 152 struct nouveau_fifo_priv *pfifo = nv_engine(dev, NVOBJ_ENGINE_FIFO);
e193b1d4 153 struct nouveau_fence_priv *fence = dev_priv->fence.func;
6ee73861
BS
154 struct nouveau_channel *chan;
155 struct drm_crtc *crtc;
92abe749 156 int ret, i, e;
6ee73861 157
f62b27db
BS
158 NV_INFO(dev, "Disabling display...\n");
159 nouveau_display_fini(dev);
4bfb94a1 160
cf41d53b
BS
161 NV_INFO(dev, "Disabling fbcon...\n");
162 nouveau_fbcon_set_suspend(dev, 1);
6ee73861 163
81441570 164 NV_INFO(dev, "Unpinning framebuffer(s)...\n");
6ee73861
BS
165 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
166 struct nouveau_framebuffer *nouveau_fb;
167
168 nouveau_fb = nouveau_framebuffer(crtc->fb);
169 if (!nouveau_fb || !nouveau_fb->nvbo)
170 continue;
171
172 nouveau_bo_unpin(nouveau_fb->nvbo);
173 }
174
b334f2b3
MM
175 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
176 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
177
178 nouveau_bo_unmap(nv_crtc->cursor.nvbo);
179 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
180 }
181
6ee73861
BS
182 NV_INFO(dev, "Evicting buffers...\n");
183 ttm_bo_evict_mm(&dev_priv->ttm.bdev, TTM_PL_VRAM);
184
185 NV_INFO(dev, "Idling channels...\n");
c420b2dc 186 for (i = 0; i < (pfifo ? pfifo->channels : 0); i++) {
cff5c133 187 chan = dev_priv->channels.ptr[i];
6ee73861 188
6dccd311
FJ
189 if (chan && chan->pushbuf_bo)
190 nouveau_channel_idle(chan);
6ee73861
BS
191 }
192
e193b1d4
BS
193 if (fence->suspend) {
194 if (!fence->suspend(dev))
195 return -ENOMEM;
196 }
197
92abe749 198 for (e = NVOBJ_ENGINE_NR - 1; e >= 0; e--) {
6c320fef
BS
199 if (!dev_priv->eng[e])
200 continue;
201
202 ret = dev_priv->eng[e]->fini(dev, e, true);
203 if (ret) {
13f90122 204 NV_ERROR(dev, "... engine %d failed: %d\n", e, ret);
6c320fef 205 goto out_abort;
92abe749
BS
206 }
207 }
6ee73861 208
6ee73861
BS
209 return 0;
210
211out_abort:
212 NV_INFO(dev, "Re-enabling acceleration..\n");
92abe749
BS
213 for (e = e + 1; e < NVOBJ_ENGINE_NR; e++) {
214 if (dev_priv->eng[e])
215 dev_priv->eng[e]->init(dev, e);
216 }
6ee73861
BS
217 return ret;
218}
219
6a9ee8af 220int
6ee73861
BS
221nouveau_pci_resume(struct pci_dev *pdev)
222{
223 struct drm_device *dev = pci_get_drvdata(pdev);
c420b2dc 224 struct nouveau_fifo_priv *pfifo = nv_engine(dev, NVOBJ_ENGINE_FIFO);
6ee73861 225 struct drm_nouveau_private *dev_priv = dev->dev_private;
e193b1d4 226 struct nouveau_fence_priv *fence = dev_priv->fence.func;
6ee73861
BS
227 struct nouveau_engine *engine = &dev_priv->engine;
228 struct drm_crtc *crtc;
6ee73861
BS
229 int ret, i;
230
c88c2e06
FJ
231 /* Make the CRTCs accessible */
232 engine->display.early_init(dev);
233
6ee73861
BS
234 NV_INFO(dev, "POSTing device...\n");
235 ret = nouveau_run_vbios_init(dev);
236 if (ret)
237 return ret;
238
6ee73861 239 NV_INFO(dev, "Reinitialising engines...\n");
6dfdd7a6
BS
240 for (i = 0; i < NVOBJ_ENGINE_NR; i++) {
241 if (dev_priv->eng[i])
242 dev_priv->eng[i]->init(dev, i);
243 }
6ee73861 244
e193b1d4
BS
245 if (fence->resume)
246 fence->resume(dev);
247
6ee73861
BS
248 nouveau_irq_postinstall(dev);
249
250 /* Re-write SKIPS, they'll have been lost over the suspend */
251 if (nouveau_vram_pushbuf) {
252 struct nouveau_channel *chan;
253 int j;
254
c420b2dc 255 for (i = 0; i < (pfifo ? pfifo->channels : 0); i++) {
cff5c133 256 chan = dev_priv->channels.ptr[i];
3c8868d3 257 if (!chan || !chan->pushbuf_bo)
6ee73861
BS
258 continue;
259
260 for (j = 0; j < NOUVEAU_DMA_SKIPS; j++)
261 nouveau_bo_wr32(chan->pushbuf_bo, i, 0);
262 }
263 }
264
71d91f65
ML
265 nouveau_pm_resume(dev);
266
6ee73861
BS
267 NV_INFO(dev, "Restoring mode...\n");
268 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
269 struct nouveau_framebuffer *nouveau_fb;
270
271 nouveau_fb = nouveau_framebuffer(crtc->fb);
272 if (!nouveau_fb || !nouveau_fb->nvbo)
273 continue;
274
275 nouveau_bo_pin(nouveau_fb->nvbo, TTM_PL_FLAG_VRAM);
276 }
277
b334f2b3
MM
278 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
279 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
b334f2b3
MM
280
281 ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM);
282 if (!ret)
283 ret = nouveau_bo_map(nv_crtc->cursor.nvbo);
284 if (ret)
285 NV_ERROR(dev, "Could not pin/map cursor.\n");
286 }
287
cf41d53b
BS
288 nouveau_fbcon_set_suspend(dev, 0);
289 nouveau_fbcon_zfill_all(dev);
290
f62b27db 291 nouveau_display_init(dev);
6ee73861
BS
292
293 /* Force CLUT to get re-loaded during modeset */
294 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
295 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
296
297 nv_crtc->lut.depth = 0;
298 }
299
6ee73861 300 drm_helper_resume_force_mode(dev);
38651674 301
a4eaa0a0
ML
302 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
303 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
304 u32 offset = nv_crtc->cursor.nvbo->bo.offset;
305
306 nv_crtc->cursor.set_offset(nv_crtc, offset);
307 nv_crtc->cursor.set_pos(nv_crtc, nv_crtc->cursor_saved_x,
308 nv_crtc->cursor_saved_y);
309 }
310
6ee73861
BS
311 return 0;
312}
313
2a259a3d
BS
314static struct drm_ioctl_desc nouveau_ioctls[] = {
315 DRM_IOCTL_DEF_DRV(NOUVEAU_GETPARAM, nouveau_abi16_ioctl_getparam, DRM_UNLOCKED|DRM_AUTH),
316 DRM_IOCTL_DEF_DRV(NOUVEAU_SETPARAM, nouveau_abi16_ioctl_setparam, DRM_UNLOCKED|DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
317 DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_ALLOC, nouveau_abi16_ioctl_channel_alloc, DRM_UNLOCKED|DRM_AUTH),
318 DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_FREE, nouveau_abi16_ioctl_channel_free, DRM_UNLOCKED|DRM_AUTH),
319 DRM_IOCTL_DEF_DRV(NOUVEAU_GROBJ_ALLOC, nouveau_abi16_ioctl_grobj_alloc, DRM_UNLOCKED|DRM_AUTH),
320 DRM_IOCTL_DEF_DRV(NOUVEAU_NOTIFIEROBJ_ALLOC, nouveau_abi16_ioctl_notifierobj_alloc, DRM_UNLOCKED|DRM_AUTH),
321 DRM_IOCTL_DEF_DRV(NOUVEAU_GPUOBJ_FREE, nouveau_abi16_ioctl_gpuobj_free, DRM_UNLOCKED|DRM_AUTH),
322 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_NEW, nouveau_gem_ioctl_new, DRM_UNLOCKED|DRM_AUTH),
323 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_PUSHBUF, nouveau_gem_ioctl_pushbuf, DRM_UNLOCKED|DRM_AUTH),
324 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_PREP, nouveau_gem_ioctl_cpu_prep, DRM_UNLOCKED|DRM_AUTH),
325 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_FINI, nouveau_gem_ioctl_cpu_fini, DRM_UNLOCKED|DRM_AUTH),
326 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_INFO, nouveau_gem_ioctl_info, DRM_UNLOCKED|DRM_AUTH),
327};
328
e08e96de
AV
329static const struct file_operations nouveau_driver_fops = {
330 .owner = THIS_MODULE,
331 .open = drm_open,
332 .release = drm_release,
333 .unlocked_ioctl = drm_ioctl,
334 .mmap = nouveau_ttm_mmap,
335 .poll = drm_poll,
336 .fasync = drm_fasync,
337 .read = drm_read,
338#if defined(CONFIG_COMPAT)
339 .compat_ioctl = nouveau_compat_ioctl,
340#endif
341 .llseek = noop_llseek,
342};
343
94580299
BS
344int nouveau_drm_load(struct drm_device *, unsigned long);
345int nouveau_drm_unload(struct drm_device *);
346
6ee73861
BS
347static struct drm_driver driver = {
348 .driver_features =
349 DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG |
cd0b072f 350 DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM |
22b33e8e 351 DRIVER_MODESET | DRIVER_PRIME,
94580299 352 .load = nouveau_drm_load,
6ee73861
BS
353 .firstopen = nouveau_firstopen,
354 .lastclose = nouveau_lastclose,
94580299 355 .unload = nouveau_drm_unload,
3f0a68d8 356 .open = nouveau_open,
6ee73861 357 .preclose = nouveau_preclose,
3f0a68d8 358 .postclose = nouveau_postclose,
6ee73861
BS
359#if defined(CONFIG_DRM_NOUVEAU_DEBUG)
360 .debugfs_init = nouveau_debugfs_init,
361 .debugfs_cleanup = nouveau_debugfs_takedown,
362#endif
363 .irq_preinstall = nouveau_irq_preinstall,
364 .irq_postinstall = nouveau_irq_postinstall,
365 .irq_uninstall = nouveau_irq_uninstall,
366 .irq_handler = nouveau_irq_handler,
042206c0
FJ
367 .get_vblank_counter = drm_vblank_count,
368 .enable_vblank = nouveau_vblank_enable,
369 .disable_vblank = nouveau_vblank_disable,
6ee73861 370 .ioctls = nouveau_ioctls,
e08e96de 371 .fops = &nouveau_driver_fops,
22b33e8e
DA
372
373 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
374 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
375 .gem_prime_export = nouveau_gem_prime_export,
376 .gem_prime_import = nouveau_gem_prime_import,
377
6ee73861
BS
378 .gem_init_object = nouveau_gem_object_new,
379 .gem_free_object = nouveau_gem_object_del,
639212d0
BS
380 .gem_open_object = nouveau_gem_object_open,
381 .gem_close_object = nouveau_gem_object_close,
6ee73861 382
33dbc27f
BS
383 .dumb_create = nouveau_display_dumb_create,
384 .dumb_map_offset = nouveau_display_dumb_map_offset,
385 .dumb_destroy = nouveau_display_dumb_destroy,
386
6ee73861
BS
387 .name = DRIVER_NAME,
388 .desc = DRIVER_DESC,
389#ifdef GIT_REVISION
390 .date = GIT_REVISION,
391#else
392 .date = DRIVER_DATE,
393#endif
394 .major = DRIVER_MAJOR,
395 .minor = DRIVER_MINOR,
396 .patchlevel = DRIVER_PATCHLEVEL,
397};
398
94580299 399int __init nouveau_init(struct pci_driver *pdrv)
6ee73861 400{
2a259a3d 401 driver.num_ioctls = ARRAY_SIZE(nouveau_ioctls);
6ee73861
BS
402
403 if (nouveau_modeset == -1) {
404#ifdef CONFIG_VGA_CONSOLE
405 if (vgacon_text_force())
406 nouveau_modeset = 0;
407 else
408#endif
409 nouveau_modeset = 1;
410 }
411
cd0b072f
BS
412 if (!nouveau_modeset)
413 return 0;
6ee73861 414
cd0b072f 415 nouveau_register_dsm_handler();
94580299 416 return drm_pci_init(&driver, pdrv);
6ee73861
BS
417}
418
94580299 419void __exit nouveau_exit(struct pci_driver *pdrv)
6ee73861 420{
cd0b072f
BS
421 if (!nouveau_modeset)
422 return;
423
94580299 424 drm_pci_exit(&driver, pdrv);
6a9ee8af 425 nouveau_unregister_dsm_handler();
6ee73861 426}