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