OSDN Git Service

6a5d548347ca3061b89e222c1d634c700eb810ea
[uclinux-h8/linux.git] / 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_fence.h"
37 #include "nouveau_pm.h"
38 #include "nv50_display.h"
39 #include "nouveau_acpi.h"
40
41 #include "drm_pciids.h"
42
43 MODULE_PARM_DESC(modeset, "Enable kernel modesetting");
44 int nouveau_modeset = -1;
45 module_param_named(modeset, nouveau_modeset, int, 0400);
46
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
51 MODULE_PARM_DESC(vram_type, "Override detected VRAM type");
52 char *nouveau_vram_type;
53 module_param_named(vram_type, nouveau_vram_type, charp, 0400);
54
55 MODULE_PARM_DESC(duallink, "Allow dual-link TMDS (>=GeForce 8)");
56 int nouveau_duallink = 1;
57 module_param_named(duallink, nouveau_duallink, int, 0400);
58
59 MODULE_PARM_DESC(uscript_lvds, "LVDS output script table ID (>=GeForce 8)");
60 int nouveau_uscript_lvds = -1;
61 module_param_named(uscript_lvds, nouveau_uscript_lvds, int, 0400);
62
63 MODULE_PARM_DESC(uscript_tmds, "TMDS output script table ID (>=GeForce 8)");
64 int nouveau_uscript_tmds = -1;
65 module_param_named(uscript_tmds, nouveau_uscript_tmds, int, 0400);
66
67 MODULE_PARM_DESC(ignorelid, "Ignore ACPI lid status");
68 int nouveau_ignorelid = 0;
69 module_param_named(ignorelid, nouveau_ignorelid, int, 0400);
70
71 MODULE_PARM_DESC(force_post, "Force POST");
72 int nouveau_force_post = 0;
73 module_param_named(force_post, nouveau_force_post, int, 0400);
74
75 MODULE_PARM_DESC(override_conntype, "Ignore DCB connector type");
76 int nouveau_override_conntype = 0;
77 module_param_named(override_conntype, nouveau_override_conntype, int, 0400);
78
79 MODULE_PARM_DESC(tv_disable, "Disable TV-out detection");
80 int nouveau_tv_disable = 0;
81 module_param_named(tv_disable, nouveau_tv_disable, int, 0400);
82
83 MODULE_PARM_DESC(tv_norm, "Default TV norm.\n"
84                  "\t\tSupported: PAL, PAL-M, PAL-N, PAL-Nc, NTSC-M, NTSC-J,\n"
85                  "\t\t\thd480i, hd480p, hd576i, hd576p, hd720p, hd1080i.\n"
86                  "\t\tDefault: PAL\n"
87                  "\t\t*NOTE* Ignored for cards with external TV encoders.");
88 char *nouveau_tv_norm;
89 module_param_named(tv_norm, nouveau_tv_norm, charp, 0400);
90
91 MODULE_PARM_DESC(perflvl, "Performance level (default: boot)");
92 char *nouveau_perflvl;
93 module_param_named(perflvl, nouveau_perflvl, charp, 0400);
94
95 MODULE_PARM_DESC(perflvl_wr, "Allow perflvl changes (warning: dangerous!)");
96 int nouveau_perflvl_wr;
97 module_param_named(perflvl_wr, nouveau_perflvl_wr, int, 0400);
98
99 MODULE_PARM_DESC(msi, "Enable MSI (default: off)");
100 int nouveau_msi;
101 module_param_named(msi, nouveau_msi, int, 0400);
102
103 MODULE_PARM_DESC(ctxfw, "Use external HUB/GPC ucode (fermi)");
104 int nouveau_ctxfw;
105 module_param_named(ctxfw, nouveau_ctxfw, int, 0400);
106
107 MODULE_PARM_DESC(mxmdcb, "Santise DCB table according to MXM-SIS");
108 int nouveau_mxmdcb = 1;
109 module_param_named(mxmdcb, nouveau_mxmdcb, int, 0400);
110
111 int nouveau_fbpercrtc;
112 #if 0
113 module_param_named(fbpercrtc, nouveau_fbpercrtc, int, 0400);
114 #endif
115
116 static struct drm_driver driver;
117
118 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
124 void
125 nouveau_pci_remove(struct pci_dev *pdev)
126 {
127         struct drm_device *dev = pci_get_drvdata(pdev);
128
129         drm_put_dev(dev);
130 }
131
132 int
133 nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state)
134 {
135         struct drm_device *dev = pci_get_drvdata(pdev);
136         struct drm_crtc *crtc;
137
138         NV_INFO(dev, "Disabling display...\n");
139         nouveau_display_fini(dev);
140
141         NV_INFO(dev, "Unpinning framebuffer(s)...\n");
142         list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
143                 struct nouveau_framebuffer *nouveau_fb;
144
145                 nouveau_fb = nouveau_framebuffer(crtc->fb);
146                 if (!nouveau_fb || !nouveau_fb->nvbo)
147                         continue;
148
149                 nouveau_bo_unpin(nouveau_fb->nvbo);
150         }
151
152         list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
153                 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
154
155                 nouveau_bo_unmap(nv_crtc->cursor.nvbo);
156                 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
157         }
158
159         return 0;
160 }
161
162 int
163 nouveau_pci_resume(struct pci_dev *pdev)
164 {
165         struct drm_device *dev = pci_get_drvdata(pdev);
166         struct drm_crtc *crtc;
167         int ret;
168
169         ret = nouveau_run_vbios_init(dev);
170         if (ret)
171                 return ret;
172
173         nouveau_irq_postinstall(dev);
174
175 #if 0
176         /* Re-write SKIPS, they'll have been lost over the suspend */
177         if (nouveau_vram_pushbuf) {
178                 struct nouveau_channel *chan;
179                 int j;
180
181                 for (i = 0; i < (pfifo ? pfifo->channels : 0); i++) {
182                         chan = dev_priv->channels.ptr[i];
183                         if (!chan || !chan->pushbuf_bo)
184                                 continue;
185
186                         for (j = 0; j < NOUVEAU_DMA_SKIPS; j++)
187                                 nouveau_bo_wr32(chan->pushbuf_bo, i, 0);
188                 }
189         }
190 #endif
191
192         nouveau_pm_resume(dev);
193
194         NV_INFO(dev, "Restoring mode...\n");
195         list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
196                 struct nouveau_framebuffer *nouveau_fb;
197
198                 nouveau_fb = nouveau_framebuffer(crtc->fb);
199                 if (!nouveau_fb || !nouveau_fb->nvbo)
200                         continue;
201
202                 nouveau_bo_pin(nouveau_fb->nvbo, TTM_PL_FLAG_VRAM);
203         }
204
205         list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
206                 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
207
208                 ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM);
209                 if (!ret)
210                         ret = nouveau_bo_map(nv_crtc->cursor.nvbo);
211                 if (ret)
212                         NV_ERROR(dev, "Could not pin/map cursor.\n");
213         }
214
215         nouveau_fbcon_set_suspend(dev, 0);
216         nouveau_fbcon_zfill_all(dev);
217
218         nouveau_display_init(dev);
219
220         /* Force CLUT to get re-loaded during modeset */
221         list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
222                 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
223
224                 nv_crtc->lut.depth = 0;
225         }
226
227         drm_helper_resume_force_mode(dev);
228
229         list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
230                 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
231                 u32 offset = nv_crtc->cursor.nvbo->bo.offset;
232
233                 nv_crtc->cursor.set_offset(nv_crtc, offset);
234                 nv_crtc->cursor.set_pos(nv_crtc, nv_crtc->cursor_saved_x,
235                                                  nv_crtc->cursor_saved_y);
236         }
237
238         return 0;
239 }
240
241 static struct drm_ioctl_desc nouveau_ioctls[] = {
242         DRM_IOCTL_DEF_DRV(NOUVEAU_GETPARAM, nouveau_abi16_ioctl_getparam, DRM_UNLOCKED|DRM_AUTH),
243         DRM_IOCTL_DEF_DRV(NOUVEAU_SETPARAM, nouveau_abi16_ioctl_setparam, DRM_UNLOCKED|DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
244         DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_ALLOC, nouveau_abi16_ioctl_channel_alloc, DRM_UNLOCKED|DRM_AUTH),
245         DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_FREE, nouveau_abi16_ioctl_channel_free, DRM_UNLOCKED|DRM_AUTH),
246         DRM_IOCTL_DEF_DRV(NOUVEAU_GROBJ_ALLOC, nouveau_abi16_ioctl_grobj_alloc, DRM_UNLOCKED|DRM_AUTH),
247         DRM_IOCTL_DEF_DRV(NOUVEAU_NOTIFIEROBJ_ALLOC, nouveau_abi16_ioctl_notifierobj_alloc, DRM_UNLOCKED|DRM_AUTH),
248         DRM_IOCTL_DEF_DRV(NOUVEAU_GPUOBJ_FREE, nouveau_abi16_ioctl_gpuobj_free, DRM_UNLOCKED|DRM_AUTH),
249         DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_NEW, nouveau_gem_ioctl_new, DRM_UNLOCKED|DRM_AUTH),
250         DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_PUSHBUF, nouveau_gem_ioctl_pushbuf, DRM_UNLOCKED|DRM_AUTH),
251         DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_PREP, nouveau_gem_ioctl_cpu_prep, DRM_UNLOCKED|DRM_AUTH),
252         DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_FINI, nouveau_gem_ioctl_cpu_fini, DRM_UNLOCKED|DRM_AUTH),
253         DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_INFO, nouveau_gem_ioctl_info, DRM_UNLOCKED|DRM_AUTH),
254 };
255
256 static const struct file_operations nouveau_driver_fops = {
257         .owner = THIS_MODULE,
258         .open = drm_open,
259         .release = drm_release,
260         .unlocked_ioctl = drm_ioctl,
261         .mmap = nouveau_ttm_mmap,
262         .poll = drm_poll,
263         .fasync = drm_fasync,
264         .read = drm_read,
265 #if defined(CONFIG_COMPAT)
266         .compat_ioctl = nouveau_compat_ioctl,
267 #endif
268         .llseek = noop_llseek,
269 };
270
271 int nouveau_drm_load(struct drm_device *, unsigned long);
272 int nouveau_drm_unload(struct drm_device *);
273 int  nouveau_drm_open(struct drm_device *, struct drm_file *);
274 void nouveau_drm_preclose(struct drm_device *dev, struct drm_file *);
275 void nouveau_drm_postclose(struct drm_device *, struct drm_file *);
276
277 static struct drm_driver driver = {
278         .driver_features =
279                 DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG |
280                 DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM |
281                 DRIVER_MODESET | DRIVER_PRIME,
282         .load = nouveau_drm_load,
283         .firstopen = nouveau_firstopen,
284         .lastclose = nouveau_lastclose,
285         .unload = nouveau_drm_unload,
286         .open = nouveau_drm_open,
287         .preclose = nouveau_drm_preclose,
288         .postclose = nouveau_drm_postclose,
289         .irq_preinstall = nouveau_irq_preinstall,
290         .irq_postinstall = nouveau_irq_postinstall,
291         .irq_uninstall = nouveau_irq_uninstall,
292         .irq_handler = nouveau_irq_handler,
293         .get_vblank_counter = drm_vblank_count,
294         .enable_vblank = nouveau_vblank_enable,
295         .disable_vblank = nouveau_vblank_disable,
296         .ioctls = nouveau_ioctls,
297         .fops = &nouveau_driver_fops,
298
299         .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
300         .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
301         .gem_prime_export = nouveau_gem_prime_export,
302         .gem_prime_import = nouveau_gem_prime_import,
303
304         .gem_init_object = nouveau_gem_object_new,
305         .gem_free_object = nouveau_gem_object_del,
306         .gem_open_object = nouveau_gem_object_open,
307         .gem_close_object = nouveau_gem_object_close,
308
309         .dumb_create = nouveau_display_dumb_create,
310         .dumb_map_offset = nouveau_display_dumb_map_offset,
311         .dumb_destroy = nouveau_display_dumb_destroy,
312
313         .name = DRIVER_NAME,
314         .desc = DRIVER_DESC,
315 #ifdef GIT_REVISION
316         .date = GIT_REVISION,
317 #else
318         .date = DRIVER_DATE,
319 #endif
320         .major = DRIVER_MAJOR,
321         .minor = DRIVER_MINOR,
322         .patchlevel = DRIVER_PATCHLEVEL,
323 };
324
325 int __init nouveau_init(struct pci_driver *pdrv)
326 {
327         driver.num_ioctls = ARRAY_SIZE(nouveau_ioctls);
328
329         if (nouveau_modeset == -1) {
330 #ifdef CONFIG_VGA_CONSOLE
331                 if (vgacon_text_force())
332                         nouveau_modeset = 0;
333                 else
334 #endif
335                         nouveau_modeset = 1;
336         }
337
338         if (!nouveau_modeset)
339                 return 0;
340
341         nouveau_register_dsm_handler();
342         return drm_pci_init(&driver, pdrv);
343 }
344
345 void __exit nouveau_exit(struct pci_driver *pdrv)
346 {
347         if (!nouveau_modeset)
348                 return;
349
350         drm_pci_exit(&driver, pdrv);
351         nouveau_unregister_dsm_handler();
352 }