1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <linux/console.h>
26#include <linux/module.h>
27#include <linux/pci.h>
28
29#include <core/device.h>
30#include <core/client.h>
31#include <core/gpuobj.h>
32#include <core/class.h>
33
34#include <subdev/device.h>
35#include <subdev/vm.h>
36
37#include "nouveau_drm.h"
38#include "nouveau_irq.h"
39#include "nouveau_dma.h"
40#include "nouveau_ttm.h"
41#include "nouveau_gem.h"
42#include "nouveau_agp.h"
43#include "nouveau_vga.h"
44#include "nouveau_pm.h"
45#include "nouveau_acpi.h"
46#include "nouveau_bios.h"
47#include "nouveau_ioctl.h"
48#include "nouveau_abi16.h"
49#include "nouveau_fbcon.h"
50#include "nouveau_fence.h"
51
52MODULE_PARM_DESC(config, "option string to pass to driver core");
53static char *nouveau_config;
54module_param_named(config, nouveau_config, charp, 0400);
55
56MODULE_PARM_DESC(debug, "debug string to pass to driver core");
57static char *nouveau_debug;
58module_param_named(debug, nouveau_debug, charp, 0400);
59
60MODULE_PARM_DESC(noaccel, "disable kernel/abi16 acceleration");
61static int nouveau_noaccel = 0;
62module_param_named(noaccel, nouveau_noaccel, int, 0400);
63
64MODULE_PARM_DESC(modeset, "enable driver (default: auto, "
65 "0 = disabled, 1 = enabled, 2 = headless)");
66int nouveau_modeset = -1;
67module_param_named(modeset, nouveau_modeset, int, 0400);
68
69static struct drm_driver driver;
70
71static u64
72nouveau_name(struct pci_dev *pdev)
73{
74 u64 name = (u64)pci_domain_nr(pdev->bus) << 32;
75 name |= pdev->bus->number << 16;
76 name |= PCI_SLOT(pdev->devfn) << 8;
77 return name | PCI_FUNC(pdev->devfn);
78}
79
80static int
81nouveau_cli_create(struct pci_dev *pdev, const char *name,
82 int size, void **pcli)
83{
84 struct nouveau_cli *cli;
85 int ret;
86
87 *pcli = NULL;
88 ret = nouveau_client_create_(name, nouveau_name(pdev), nouveau_config,
89 nouveau_debug, size, pcli);
90 cli = *pcli;
91 if (ret) {
92 if (cli)
93 nouveau_client_destroy(&cli->base);
94 *pcli = NULL;
95 return ret;
96 }
97
98 mutex_init(&cli->mutex);
99 return 0;
100}
101
102static void
103nouveau_cli_destroy(struct nouveau_cli *cli)
104{
105 struct nouveau_object *client = nv_object(cli);
106 nouveau_vm_ref(NULL, &cli->base.vm, NULL);
107 nouveau_client_fini(&cli->base, false);
108 atomic_set(&client->refcount, 1);
109 nouveau_object_ref(NULL, &client);
110}
111
112static void
113nouveau_accel_fini(struct nouveau_drm *drm)
114{
115 nouveau_gpuobj_ref(NULL, &drm->notify);
116 nouveau_channel_del(&drm->channel);
117 nouveau_channel_del(&drm->cechan);
118 if (drm->fence)
119 nouveau_fence(drm)->dtor(drm);
120}
121
122static void
123nouveau_accel_init(struct nouveau_drm *drm)
124{
125 struct nouveau_device *device = nv_device(drm->device);
126 struct nouveau_object *object;
127 u32 arg0, arg1;
128 int ret;
129
130 if (nouveau_noaccel)
131 return;
132
133
134 if (device->card_type < NV_10) ret = nv04_fence_create(drm);
135 else if (device->card_type < NV_50) ret = nv10_fence_create(drm);
136 else if (device->chipset < 0x84) ret = nv50_fence_create(drm);
137 else if (device->card_type < NV_C0) ret = nv84_fence_create(drm);
138 else ret = nvc0_fence_create(drm);
139 if (ret) {
140 NV_ERROR(drm, "failed to initialise sync subsystem, %d\n", ret);
141 nouveau_accel_fini(drm);
142 return;
143 }
144
145 if (device->card_type >= NV_E0) {
146 ret = nouveau_channel_new(drm, &drm->client, NVDRM_DEVICE,
147 NVDRM_CHAN + 1,
148 NVE0_CHANNEL_IND_ENGINE_CE0 |
149 NVE0_CHANNEL_IND_ENGINE_CE1, 0,
150 &drm->cechan);
151 if (ret)
152 NV_ERROR(drm, "failed to create ce channel, %d\n", ret);
153
154 arg0 = NVE0_CHANNEL_IND_ENGINE_GR;
155 arg1 = 1;
156 } else {
157 arg0 = NvDmaFB;
158 arg1 = NvDmaTT;
159 }
160
161 ret = nouveau_channel_new(drm, &drm->client, NVDRM_DEVICE, NVDRM_CHAN,
162 arg0, arg1, &drm->channel);
163 if (ret) {
164 NV_ERROR(drm, "failed to create kernel channel, %d\n", ret);
165 nouveau_accel_fini(drm);
166 return;
167 }
168
169 if (device->card_type < NV_C0) {
170 ret = nouveau_gpuobj_new(drm->device, NULL, 32, 0, 0,
171 &drm->notify);
172 if (ret) {
173 NV_ERROR(drm, "failed to allocate notifier, %d\n", ret);
174 nouveau_accel_fini(drm);
175 return;
176 }
177
178 ret = nouveau_object_new(nv_object(drm),
179 drm->channel->handle, NvNotify0,
180 0x003d, &(struct nv_dma_class) {
181 .flags = NV_DMA_TARGET_VRAM |
182 NV_DMA_ACCESS_RDWR,
183 .start = drm->notify->addr,
184 .limit = drm->notify->addr + 31
185 }, sizeof(struct nv_dma_class),
186 &object);
187 if (ret) {
188 nouveau_accel_fini(drm);
189 return;
190 }
191 }
192
193
194 nouveau_bo_move_init(drm);
195}
196
197static int nouveau_drm_probe(struct pci_dev *pdev,
198 const struct pci_device_id *pent)
199{
200 struct nouveau_device *device;
201 struct apertures_struct *aper;
202 bool boot = false;
203 int ret;
204
205
206 aper = alloc_apertures(3);
207 if (!aper)
208 return -ENOMEM;
209
210 aper->ranges[0].base = pci_resource_start(pdev, 1);
211 aper->ranges[0].size = pci_resource_len(pdev, 1);
212 aper->count = 1;
213
214 if (pci_resource_len(pdev, 2)) {
215 aper->ranges[aper->count].base = pci_resource_start(pdev, 2);
216 aper->ranges[aper->count].size = pci_resource_len(pdev, 2);
217 aper->count++;
218 }
219
220 if (pci_resource_len(pdev, 3)) {
221 aper->ranges[aper->count].base = pci_resource_start(pdev, 3);
222 aper->ranges[aper->count].size = pci_resource_len(pdev, 3);
223 aper->count++;
224 }
225
226#ifdef CONFIG_X86
227 boot = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
228#endif
229 remove_conflicting_framebuffers(aper, "nouveaufb", boot);
230 kfree(aper);
231
232 ret = nouveau_device_create(pdev, nouveau_name(pdev), pci_name(pdev),
233 nouveau_config, nouveau_debug, &device);
234 if (ret)
235 return ret;
236
237 pci_set_master(pdev);
238
239 ret = drm_get_pci_dev(pdev, pent, &driver);
240 if (ret) {
241 nouveau_object_ref(NULL, (struct nouveau_object **)&device);
242 return ret;
243 }
244
245 return 0;
246}
247
248static struct lock_class_key drm_client_lock_class_key;
249
250static int
251nouveau_drm_load(struct drm_device *dev, unsigned long flags)
252{
253 struct pci_dev *pdev = dev->pdev;
254 struct nouveau_device *device;
255 struct nouveau_drm *drm;
256 int ret;
257
258 ret = nouveau_cli_create(pdev, "DRM", sizeof(*drm), (void**)&drm);
259 if (ret)
260 return ret;
261 lockdep_set_class(&drm->client.mutex, &drm_client_lock_class_key);
262
263 dev->dev_private = drm;
264 drm->dev = dev;
265
266 INIT_LIST_HEAD(&drm->clients);
267 spin_lock_init(&drm->tile.lock);
268
269
270
271
272 if (drm_pci_device_is_agp(dev) && dev->agp) {
273
274
275
276 ret = nouveau_object_new(nv_object(drm), NVDRM_CLIENT,
277 NVDRM_DEVICE, 0x0080,
278 &(struct nv_device_class) {
279 .device = ~0,
280 .disable =
281 ~(NV_DEVICE_DISABLE_MMIO |
282 NV_DEVICE_DISABLE_IDENTIFY),
283 .debug0 = ~0,
284 }, sizeof(struct nv_device_class),
285 &drm->device);
286 if (ret)
287 goto fail_device;
288
289 nouveau_agp_reset(drm);
290 nouveau_object_del(nv_object(drm), NVDRM_CLIENT, NVDRM_DEVICE);
291 }
292
293 ret = nouveau_object_new(nv_object(drm), NVDRM_CLIENT, NVDRM_DEVICE,
294 0x0080, &(struct nv_device_class) {
295 .device = ~0,
296 .disable = 0,
297 .debug0 = 0,
298 }, sizeof(struct nv_device_class),
299 &drm->device);
300 if (ret)
301 goto fail_device;
302
303
304
305
306
307 device = nv_device(drm->device);
308 if (nv_device(drm->device)->chipset == 0xc1)
309 nv_mask(device, 0x00088080, 0x00000800, 0x00000000);
310
311 nouveau_vga_init(drm);
312 nouveau_agp_init(drm);
313
314 if (device->card_type >= NV_50) {
315 ret = nouveau_vm_new(nv_device(drm->device), 0, (1ULL << 40),
316 0x1000, &drm->client.base.vm);
317 if (ret)
318 goto fail_device;
319 }
320
321 ret = nouveau_ttm_init(drm);
322 if (ret)
323 goto fail_ttm;
324
325 ret = nouveau_bios_init(dev);
326 if (ret)
327 goto fail_bios;
328
329 ret = nouveau_irq_init(dev);
330 if (ret)
331 goto fail_irq;
332
333 ret = nouveau_display_create(dev);
334 if (ret)
335 goto fail_dispctor;
336
337 if (dev->mode_config.num_crtc) {
338 ret = nouveau_display_init(dev);
339 if (ret)
340 goto fail_dispinit;
341 }
342
343 nouveau_pm_init(dev);
344
345 nouveau_accel_init(drm);
346 nouveau_fbcon_init(dev);
347 return 0;
348
349fail_dispinit:
350 nouveau_display_destroy(dev);
351fail_dispctor:
352 nouveau_irq_fini(dev);
353fail_irq:
354 nouveau_bios_takedown(dev);
355fail_bios:
356 nouveau_ttm_fini(drm);
357fail_ttm:
358 nouveau_agp_fini(drm);
359 nouveau_vga_fini(drm);
360fail_device:
361 nouveau_cli_destroy(&drm->client);
362 return ret;
363}
364
365static int
366nouveau_drm_unload(struct drm_device *dev)
367{
368 struct nouveau_drm *drm = nouveau_drm(dev);
369
370 nouveau_fbcon_fini(dev);
371 nouveau_accel_fini(drm);
372
373 nouveau_pm_fini(dev);
374
375 if (dev->mode_config.num_crtc)
376 nouveau_display_fini(dev);
377 nouveau_display_destroy(dev);
378
379 nouveau_irq_fini(dev);
380 nouveau_bios_takedown(dev);
381
382 nouveau_ttm_fini(drm);
383 nouveau_agp_fini(drm);
384 nouveau_vga_fini(drm);
385
386 nouveau_cli_destroy(&drm->client);
387 return 0;
388}
389
390static void
391nouveau_drm_remove(struct pci_dev *pdev)
392{
393 struct drm_device *dev = pci_get_drvdata(pdev);
394 struct nouveau_drm *drm = nouveau_drm(dev);
395 struct nouveau_object *device;
396
397 device = drm->client.base.device;
398 drm_put_dev(dev);
399
400 nouveau_object_ref(NULL, &device);
401 nouveau_object_debug();
402}
403
404int
405nouveau_do_suspend(struct drm_device *dev)
406{
407 struct nouveau_drm *drm = nouveau_drm(dev);
408 struct nouveau_cli *cli;
409 int ret;
410
411 if (dev->mode_config.num_crtc) {
412 NV_INFO(drm, "suspending fbcon...\n");
413 nouveau_fbcon_set_suspend(dev, 1);
414
415 NV_INFO(drm, "suspending display...\n");
416 ret = nouveau_display_suspend(dev);
417 if (ret)
418 return ret;
419 }
420
421 NV_INFO(drm, "evicting buffers...\n");
422 ttm_bo_evict_mm(&drm->ttm.bdev, TTM_PL_VRAM);
423
424 if (drm->fence && nouveau_fence(drm)->suspend) {
425 if (!nouveau_fence(drm)->suspend(drm))
426 return -ENOMEM;
427 }
428
429 NV_INFO(drm, "suspending client object trees...\n");
430 list_for_each_entry(cli, &drm->clients, head) {
431 ret = nouveau_client_fini(&cli->base, true);
432 if (ret)
433 goto fail_client;
434 }
435
436 ret = nouveau_client_fini(&drm->client.base, true);
437 if (ret)
438 goto fail_client;
439
440 nouveau_agp_fini(drm);
441 return 0;
442
443fail_client:
444 list_for_each_entry_continue_reverse(cli, &drm->clients, head) {
445 nouveau_client_init(&cli->base);
446 }
447
448 if (dev->mode_config.num_crtc) {
449 NV_INFO(drm, "resuming display...\n");
450 nouveau_display_resume(dev);
451 }
452 return ret;
453}
454
455int nouveau_pmops_suspend(struct device *dev)
456{
457 struct pci_dev *pdev = to_pci_dev(dev);
458 struct drm_device *drm_dev = pci_get_drvdata(pdev);
459 int ret;
460
461 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
462 return 0;
463
464 ret = nouveau_do_suspend(drm_dev);
465 if (ret)
466 return ret;
467
468 pci_save_state(pdev);
469 pci_disable_device(pdev);
470 pci_set_power_state(pdev, PCI_D3hot);
471
472 return 0;
473}
474
475int
476nouveau_do_resume(struct drm_device *dev)
477{
478 struct nouveau_drm *drm = nouveau_drm(dev);
479 struct nouveau_cli *cli;
480
481 NV_INFO(drm, "re-enabling device...\n");
482
483 nouveau_agp_reset(drm);
484
485 NV_INFO(drm, "resuming client object trees...\n");
486 nouveau_client_init(&drm->client.base);
487 nouveau_agp_init(drm);
488
489 list_for_each_entry(cli, &drm->clients, head) {
490 nouveau_client_init(&cli->base);
491 }
492
493 if (drm->fence && nouveau_fence(drm)->resume)
494 nouveau_fence(drm)->resume(drm);
495
496 nouveau_run_vbios_init(dev);
497 nouveau_irq_postinstall(dev);
498 nouveau_pm_resume(dev);
499
500 if (dev->mode_config.num_crtc) {
501 NV_INFO(drm, "resuming display...\n");
502 nouveau_display_resume(dev);
503 }
504 return 0;
505}
506
507int nouveau_pmops_resume(struct device *dev)
508{
509 struct pci_dev *pdev = to_pci_dev(dev);
510 struct drm_device *drm_dev = pci_get_drvdata(pdev);
511 int ret;
512
513 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF)
514 return 0;
515
516 pci_set_power_state(pdev, PCI_D0);
517 pci_restore_state(pdev);
518 ret = pci_enable_device(pdev);
519 if (ret)
520 return ret;
521 pci_set_master(pdev);
522
523 return nouveau_do_resume(drm_dev);
524}
525
526static int nouveau_pmops_freeze(struct device *dev)
527{
528 struct pci_dev *pdev = to_pci_dev(dev);
529 struct drm_device *drm_dev = pci_get_drvdata(pdev);
530
531 return nouveau_do_suspend(drm_dev);
532}
533
534static int nouveau_pmops_thaw(struct device *dev)
535{
536 struct pci_dev *pdev = to_pci_dev(dev);
537 struct drm_device *drm_dev = pci_get_drvdata(pdev);
538
539 return nouveau_do_resume(drm_dev);
540}
541
542
543static int
544nouveau_drm_open(struct drm_device *dev, struct drm_file *fpriv)
545{
546 struct pci_dev *pdev = dev->pdev;
547 struct nouveau_drm *drm = nouveau_drm(dev);
548 struct nouveau_cli *cli;
549 char name[16];
550 int ret;
551
552 snprintf(name, sizeof(name), "%d", pid_nr(fpriv->pid));
553
554 ret = nouveau_cli_create(pdev, name, sizeof(*cli), (void **)&cli);
555 if (ret)
556 return ret;
557
558 if (nv_device(drm->device)->card_type >= NV_50) {
559 ret = nouveau_vm_new(nv_device(drm->device), 0, (1ULL << 40),
560 0x1000, &cli->base.vm);
561 if (ret) {
562 nouveau_cli_destroy(cli);
563 return ret;
564 }
565 }
566
567 fpriv->driver_priv = cli;
568
569 mutex_lock(&drm->client.mutex);
570 list_add(&cli->head, &drm->clients);
571 mutex_unlock(&drm->client.mutex);
572 return 0;
573}
574
575static void
576nouveau_drm_preclose(struct drm_device *dev, struct drm_file *fpriv)
577{
578 struct nouveau_cli *cli = nouveau_cli(fpriv);
579 struct nouveau_drm *drm = nouveau_drm(dev);
580
581 if (cli->abi16)
582 nouveau_abi16_fini(cli->abi16);
583
584 mutex_lock(&drm->client.mutex);
585 list_del(&cli->head);
586 mutex_unlock(&drm->client.mutex);
587}
588
589static void
590nouveau_drm_postclose(struct drm_device *dev, struct drm_file *fpriv)
591{
592 struct nouveau_cli *cli = nouveau_cli(fpriv);
593 nouveau_cli_destroy(cli);
594}
595
596static struct drm_ioctl_desc
597nouveau_ioctls[] = {
598 DRM_IOCTL_DEF_DRV(NOUVEAU_GETPARAM, nouveau_abi16_ioctl_getparam, DRM_UNLOCKED|DRM_AUTH),
599 DRM_IOCTL_DEF_DRV(NOUVEAU_SETPARAM, nouveau_abi16_ioctl_setparam, DRM_UNLOCKED|DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
600 DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_ALLOC, nouveau_abi16_ioctl_channel_alloc, DRM_UNLOCKED|DRM_AUTH),
601 DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_FREE, nouveau_abi16_ioctl_channel_free, DRM_UNLOCKED|DRM_AUTH),
602 DRM_IOCTL_DEF_DRV(NOUVEAU_GROBJ_ALLOC, nouveau_abi16_ioctl_grobj_alloc, DRM_UNLOCKED|DRM_AUTH),
603 DRM_IOCTL_DEF_DRV(NOUVEAU_NOTIFIEROBJ_ALLOC, nouveau_abi16_ioctl_notifierobj_alloc, DRM_UNLOCKED|DRM_AUTH),
604 DRM_IOCTL_DEF_DRV(NOUVEAU_GPUOBJ_FREE, nouveau_abi16_ioctl_gpuobj_free, DRM_UNLOCKED|DRM_AUTH),
605 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_NEW, nouveau_gem_ioctl_new, DRM_UNLOCKED|DRM_AUTH),
606 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_PUSHBUF, nouveau_gem_ioctl_pushbuf, DRM_UNLOCKED|DRM_AUTH),
607 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_PREP, nouveau_gem_ioctl_cpu_prep, DRM_UNLOCKED|DRM_AUTH),
608 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_FINI, nouveau_gem_ioctl_cpu_fini, DRM_UNLOCKED|DRM_AUTH),
609 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_INFO, nouveau_gem_ioctl_info, DRM_UNLOCKED|DRM_AUTH),
610};
611
612static const struct file_operations
613nouveau_driver_fops = {
614 .owner = THIS_MODULE,
615 .open = drm_open,
616 .release = drm_release,
617 .unlocked_ioctl = drm_ioctl,
618 .mmap = nouveau_ttm_mmap,
619 .poll = drm_poll,
620 .fasync = drm_fasync,
621 .read = drm_read,
622#if defined(CONFIG_COMPAT)
623 .compat_ioctl = nouveau_compat_ioctl,
624#endif
625 .llseek = noop_llseek,
626};
627
628static struct drm_driver
629driver = {
630 .driver_features =
631 DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG |
632 DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM |
633 DRIVER_MODESET | DRIVER_PRIME,
634
635 .load = nouveau_drm_load,
636 .unload = nouveau_drm_unload,
637 .open = nouveau_drm_open,
638 .preclose = nouveau_drm_preclose,
639 .postclose = nouveau_drm_postclose,
640 .lastclose = nouveau_vga_lastclose,
641
642 .irq_preinstall = nouveau_irq_preinstall,
643 .irq_postinstall = nouveau_irq_postinstall,
644 .irq_uninstall = nouveau_irq_uninstall,
645 .irq_handler = nouveau_irq_handler,
646
647 .get_vblank_counter = drm_vblank_count,
648 .enable_vblank = nouveau_vblank_enable,
649 .disable_vblank = nouveau_vblank_disable,
650
651 .ioctls = nouveau_ioctls,
652 .fops = &nouveau_driver_fops,
653
654 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
655 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
656 .gem_prime_export = nouveau_gem_prime_export,
657 .gem_prime_import = nouveau_gem_prime_import,
658
659 .gem_init_object = nouveau_gem_object_new,
660 .gem_free_object = nouveau_gem_object_del,
661 .gem_open_object = nouveau_gem_object_open,
662 .gem_close_object = nouveau_gem_object_close,
663
664 .dumb_create = nouveau_display_dumb_create,
665 .dumb_map_offset = nouveau_display_dumb_map_offset,
666 .dumb_destroy = nouveau_display_dumb_destroy,
667
668 .name = DRIVER_NAME,
669 .desc = DRIVER_DESC,
670#ifdef GIT_REVISION
671 .date = GIT_REVISION,
672#else
673 .date = DRIVER_DATE,
674#endif
675 .major = DRIVER_MAJOR,
676 .minor = DRIVER_MINOR,
677 .patchlevel = DRIVER_PATCHLEVEL,
678};
679
680static struct pci_device_id
681nouveau_drm_pci_table[] = {
682 {
683 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
684 .class = PCI_BASE_CLASS_DISPLAY << 16,
685 .class_mask = 0xff << 16,
686 },
687 {
688 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA_SGS, PCI_ANY_ID),
689 .class = PCI_BASE_CLASS_DISPLAY << 16,
690 .class_mask = 0xff << 16,
691 },
692 {}
693};
694
695static const struct dev_pm_ops nouveau_pm_ops = {
696 .suspend = nouveau_pmops_suspend,
697 .resume = nouveau_pmops_resume,
698 .freeze = nouveau_pmops_freeze,
699 .thaw = nouveau_pmops_thaw,
700 .poweroff = nouveau_pmops_freeze,
701 .restore = nouveau_pmops_resume,
702};
703
704static struct pci_driver
705nouveau_drm_pci_driver = {
706 .name = "nouveau",
707 .id_table = nouveau_drm_pci_table,
708 .probe = nouveau_drm_probe,
709 .remove = nouveau_drm_remove,
710 .driver.pm = &nouveau_pm_ops,
711};
712
713static int __init
714nouveau_drm_init(void)
715{
716 driver.num_ioctls = ARRAY_SIZE(nouveau_ioctls);
717
718 if (nouveau_modeset == -1) {
719#ifdef CONFIG_VGA_CONSOLE
720 if (vgacon_text_force())
721 nouveau_modeset = 0;
722#endif
723 }
724
725 if (!nouveau_modeset)
726 return 0;
727
728 nouveau_register_dsm_handler();
729 return drm_pci_init(&driver, &nouveau_drm_pci_driver);
730}
731
732static void __exit
733nouveau_drm_exit(void)
734{
735 if (!nouveau_modeset)
736 return;
737
738 drm_pci_exit(&driver, &nouveau_drm_pci_driver);
739 nouveau_unregister_dsm_handler();
740}
741
742module_init(nouveau_drm_init);
743module_exit(nouveau_drm_exit);
744
745MODULE_DEVICE_TABLE(pci, nouveau_drm_pci_table);
746MODULE_AUTHOR(DRIVER_AUTHOR);
747MODULE_DESCRIPTION(DRIVER_DESC);
748MODULE_LICENSE("GPL and additional rights");
749