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