Merge branch 'drm-next' of git://people.freedesktop.org/~airlied/linux
[GitHub/exynos8895/android_kernel_samsung_universal8895.git] / drivers / gpu / drm / nouveau / nouveau_drm.c
CommitLineData
94580299
BS
1/*
2 * Copyright 2012 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 */
24
77145f1c 25#include <linux/console.h>
94580299
BS
26#include <linux/module.h>
27#include <linux/pci.h>
28
29#include <core/device.h>
30#include <core/client.h>
ebb945a9 31#include <core/gpuobj.h>
94580299
BS
32#include <core/class.h>
33
34#include <subdev/device.h>
ebb945a9 35#include <subdev/vm.h>
94580299
BS
36
37#include "nouveau_drm.h"
77145f1c 38#include "nouveau_irq.h"
ebb945a9 39#include "nouveau_dma.h"
77145f1c
BS
40#include "nouveau_ttm.h"
41#include "nouveau_gem.h"
cb75d97e 42#include "nouveau_agp.h"
77145f1c
BS
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"
ebb945a9
BS
48#include "nouveau_abi16.h"
49#include "nouveau_fbcon.h"
50#include "nouveau_fence.h"
51
52#include "nouveau_ttm.h"
94580299 53
94580299
BS
54MODULE_PARM_DESC(config, "option string to pass to driver core");
55static char *nouveau_config;
56module_param_named(config, nouveau_config, charp, 0400);
57
58MODULE_PARM_DESC(debug, "debug string to pass to driver core");
59static char *nouveau_debug;
60module_param_named(debug, nouveau_debug, charp, 0400);
61
ebb945a9
BS
62MODULE_PARM_DESC(noaccel, "disable kernel/abi16 acceleration");
63static int nouveau_noaccel = 0;
64module_param_named(noaccel, nouveau_noaccel, int, 0400);
65
77145f1c 66MODULE_PARM_DESC(modeset, "enable driver");
5b8a43ae 67static int nouveau_modeset = -1;
77145f1c
BS
68module_param_named(modeset, nouveau_modeset, int, 0400);
69
70static struct drm_driver driver;
71
94580299
BS
72static u64
73nouveau_name(struct pci_dev *pdev)
74{
75 u64 name = (u64)pci_domain_nr(pdev->bus) << 32;
76 name |= pdev->bus->number << 16;
77 name |= PCI_SLOT(pdev->devfn) << 8;
78 return name | PCI_FUNC(pdev->devfn);
79}
80
81static int
fa6df8c1
BS
82nouveau_cli_create(struct pci_dev *pdev, const char *name,
83 int size, void **pcli)
94580299
BS
84{
85 struct nouveau_cli *cli;
86 int ret;
87
88 ret = nouveau_client_create_(name, nouveau_name(pdev), nouveau_config,
89 nouveau_debug, size, pcli);
90 cli = *pcli;
91 if (ret)
92 return ret;
93
94 mutex_init(&cli->mutex);
95 return 0;
96}
97
98static void
99nouveau_cli_destroy(struct nouveau_cli *cli)
100{
101 struct nouveau_object *client = nv_object(cli);
ebb945a9 102 nouveau_vm_ref(NULL, &cli->base.vm, NULL);
94580299
BS
103 nouveau_client_fini(&cli->base, false);
104 atomic_set(&client->refcount, 1);
105 nouveau_object_ref(NULL, &client);
106}
107
ebb945a9
BS
108static void
109nouveau_accel_fini(struct nouveau_drm *drm)
110{
111 nouveau_gpuobj_ref(NULL, &drm->notify);
112 nouveau_channel_del(&drm->channel);
49981046 113 nouveau_channel_del(&drm->cechan);
ebb945a9
BS
114 if (drm->fence)
115 nouveau_fence(drm)->dtor(drm);
116}
117
118static void
119nouveau_accel_init(struct nouveau_drm *drm)
120{
121 struct nouveau_device *device = nv_device(drm->device);
122 struct nouveau_object *object;
49981046 123 u32 arg0, arg1;
ebb945a9
BS
124 int ret;
125
126 if (nouveau_noaccel)
127 return;
128
129 /* initialise synchronisation routines */
130 if (device->card_type < NV_10) ret = nv04_fence_create(drm);
131 else if (device->chipset < 0x84) ret = nv10_fence_create(drm);
132 else if (device->card_type < NV_C0) ret = nv84_fence_create(drm);
133 else ret = nvc0_fence_create(drm);
134 if (ret) {
135 NV_ERROR(drm, "failed to initialise sync subsystem, %d\n", ret);
136 nouveau_accel_fini(drm);
137 return;
138 }
139
49981046
BS
140 if (device->card_type >= NV_E0) {
141 ret = nouveau_channel_new(drm, &drm->client, NVDRM_DEVICE,
142 NVDRM_CHAN + 1,
143 NVE0_CHANNEL_IND_ENGINE_CE0 |
144 NVE0_CHANNEL_IND_ENGINE_CE1, 0,
145 &drm->cechan);
146 if (ret)
147 NV_ERROR(drm, "failed to create ce channel, %d\n", ret);
148
149 arg0 = NVE0_CHANNEL_IND_ENGINE_GR;
150 arg1 = 0;
151 } else {
152 arg0 = NvDmaFB;
153 arg1 = NvDmaTT;
154 }
155
ebb945a9 156 ret = nouveau_channel_new(drm, &drm->client, NVDRM_DEVICE, NVDRM_CHAN,
49981046 157 arg0, arg1, &drm->channel);
ebb945a9
BS
158 if (ret) {
159 NV_ERROR(drm, "failed to create kernel channel, %d\n", ret);
160 nouveau_accel_fini(drm);
161 return;
162 }
163
164 if (device->card_type < NV_C0) {
165 ret = nouveau_gpuobj_new(drm->device, NULL, 32, 0, 0,
166 &drm->notify);
167 if (ret) {
168 NV_ERROR(drm, "failed to allocate notifier, %d\n", ret);
169 nouveau_accel_fini(drm);
170 return;
171 }
172
173 ret = nouveau_object_new(nv_object(drm),
174 drm->channel->handle, NvNotify0,
175 0x003d, &(struct nv_dma_class) {
176 .flags = NV_DMA_TARGET_VRAM |
177 NV_DMA_ACCESS_RDWR,
178 .start = drm->notify->addr,
179 .limit = drm->notify->addr + 31
180 }, sizeof(struct nv_dma_class),
181 &object);
182 if (ret) {
183 nouveau_accel_fini(drm);
184 return;
185 }
186 }
187
188
49981046 189 nouveau_bo_move_init(drm);
ebb945a9
BS
190}
191
94580299
BS
192static int __devinit
193nouveau_drm_probe(struct pci_dev *pdev, const struct pci_device_id *pent)
194{
195 struct nouveau_device *device;
ebb945a9
BS
196 struct apertures_struct *aper;
197 bool boot = false;
94580299
BS
198 int ret;
199
ebb945a9
BS
200 /* remove conflicting drivers (vesafb, efifb etc) */
201 aper = alloc_apertures(3);
202 if (!aper)
203 return -ENOMEM;
204
205 aper->ranges[0].base = pci_resource_start(pdev, 1);
206 aper->ranges[0].size = pci_resource_len(pdev, 1);
207 aper->count = 1;
208
209 if (pci_resource_len(pdev, 2)) {
210 aper->ranges[aper->count].base = pci_resource_start(pdev, 2);
211 aper->ranges[aper->count].size = pci_resource_len(pdev, 2);
212 aper->count++;
213 }
214
215 if (pci_resource_len(pdev, 3)) {
216 aper->ranges[aper->count].base = pci_resource_start(pdev, 3);
217 aper->ranges[aper->count].size = pci_resource_len(pdev, 3);
218 aper->count++;
219 }
220
221#ifdef CONFIG_X86
222 boot = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
223#endif
224 remove_conflicting_framebuffers(aper, "nouveaufb", boot);
225
94580299
BS
226 ret = nouveau_device_create(pdev, nouveau_name(pdev), pci_name(pdev),
227 nouveau_config, nouveau_debug, &device);
228 if (ret)
229 return ret;
230
231 pci_set_master(pdev);
232
77145f1c 233 ret = drm_get_pci_dev(pdev, pent, &driver);
94580299 234 if (ret) {
ebb945a9 235 nouveau_object_ref(NULL, (struct nouveau_object **)&device);
94580299
BS
236 return ret;
237 }
238
239 return 0;
240}
241
5b8a43ae 242static int
94580299
BS
243nouveau_drm_load(struct drm_device *dev, unsigned long flags)
244{
245 struct pci_dev *pdev = dev->pdev;
ebb945a9 246 struct nouveau_device *device;
94580299
BS
247 struct nouveau_drm *drm;
248 int ret;
249
fa6df8c1 250 ret = nouveau_cli_create(pdev, "DRM", sizeof(*drm), (void**)&drm);
94580299
BS
251 if (ret)
252 return ret;
253
77145f1c
BS
254 dev->dev_private = drm;
255 drm->dev = dev;
256
94580299 257 INIT_LIST_HEAD(&drm->clients);
ebb945a9 258 spin_lock_init(&drm->tile.lock);
94580299 259
cb75d97e
BS
260 /* make sure AGP controller is in a consistent state before we
261 * (possibly) execute vbios init tables (see nouveau_agp.h)
262 */
263 if (drm_pci_device_is_agp(dev) && dev->agp) {
264 /* dummy device object, doesn't init anything, but allows
265 * agp code access to registers
266 */
267 ret = nouveau_object_new(nv_object(drm), NVDRM_CLIENT,
268 NVDRM_DEVICE, 0x0080,
269 &(struct nv_device_class) {
270 .device = ~0,
271 .disable =
272 ~(NV_DEVICE_DISABLE_MMIO |
273 NV_DEVICE_DISABLE_IDENTIFY),
274 .debug0 = ~0,
275 }, sizeof(struct nv_device_class),
276 &drm->device);
277 if (ret)
ebb945a9 278 goto fail_device;
cb75d97e
BS
279
280 nouveau_agp_reset(drm);
281 nouveau_object_del(nv_object(drm), NVDRM_CLIENT, NVDRM_DEVICE);
282 }
283
94580299
BS
284 ret = nouveau_object_new(nv_object(drm), NVDRM_CLIENT, NVDRM_DEVICE,
285 0x0080, &(struct nv_device_class) {
286 .device = ~0,
287 .disable = 0,
288 .debug0 = 0,
289 }, sizeof(struct nv_device_class),
290 &drm->device);
291 if (ret)
292 goto fail_device;
293
77145f1c
BS
294 /* workaround an odd issue on nvc1 by disabling the device's
295 * nosnoop capability. hopefully won't cause issues until a
296 * better fix is found - assuming there is one...
297 */
ebb945a9 298 device = nv_device(drm->device);
77145f1c
BS
299 if (nv_device(drm->device)->chipset == 0xc1)
300 nv_mask(device, 0x00088080, 0x00000800, 0x00000000);
ebb945a9 301
77145f1c 302 nouveau_vga_init(drm);
cb75d97e
BS
303 nouveau_agp_init(drm);
304
ebb945a9
BS
305 if (device->card_type >= NV_50) {
306 ret = nouveau_vm_new(nv_device(drm->device), 0, (1ULL << 40),
307 0x1000, &drm->client.base.vm);
308 if (ret)
309 goto fail_device;
310 }
311
312 ret = nouveau_ttm_init(drm);
94580299 313 if (ret)
77145f1c
BS
314 goto fail_ttm;
315
316 ret = nouveau_bios_init(dev);
317 if (ret)
318 goto fail_bios;
319
320 ret = nouveau_irq_init(dev);
321 if (ret)
322 goto fail_irq;
94580299 323
77145f1c 324 ret = nouveau_display_create(dev);
ebb945a9 325 if (ret)
77145f1c
BS
326 goto fail_dispctor;
327
328 if (dev->mode_config.num_crtc) {
329 ret = nouveau_display_init(dev);
330 if (ret)
331 goto fail_dispinit;
332 }
333
334 nouveau_pm_init(dev);
ebb945a9
BS
335
336 nouveau_accel_init(drm);
337 nouveau_fbcon_init(dev);
94580299
BS
338 return 0;
339
77145f1c
BS
340fail_dispinit:
341 nouveau_display_destroy(dev);
342fail_dispctor:
343 nouveau_irq_fini(dev);
344fail_irq:
345 nouveau_bios_takedown(dev);
346fail_bios:
ebb945a9 347 nouveau_ttm_fini(drm);
77145f1c
BS
348fail_ttm:
349 nouveau_agp_fini(drm);
350 nouveau_vga_fini(drm);
94580299
BS
351fail_device:
352 nouveau_cli_destroy(&drm->client);
353 return ret;
354}
355
5b8a43ae 356static int
94580299
BS
357nouveau_drm_unload(struct drm_device *dev)
358{
77145f1c 359 struct nouveau_drm *drm = nouveau_drm(dev);
94580299 360
ebb945a9
BS
361 nouveau_fbcon_fini(dev);
362 nouveau_accel_fini(drm);
363
77145f1c
BS
364 nouveau_pm_fini(dev);
365
366 nouveau_display_fini(dev);
367 nouveau_display_destroy(dev);
368
369 nouveau_irq_fini(dev);
370 nouveau_bios_takedown(dev);
94580299 371
ebb945a9 372 nouveau_ttm_fini(drm);
cb75d97e 373 nouveau_agp_fini(drm);
77145f1c 374 nouveau_vga_fini(drm);
cb75d97e 375
94580299
BS
376 nouveau_cli_destroy(&drm->client);
377 return 0;
378}
379
380static void
381nouveau_drm_remove(struct pci_dev *pdev)
382{
77145f1c
BS
383 struct drm_device *dev = pci_get_drvdata(pdev);
384 struct nouveau_drm *drm = nouveau_drm(dev);
ebb945a9 385 struct nouveau_object *device;
77145f1c
BS
386
387 device = drm->client.base.device;
388 drm_put_dev(dev);
389
ebb945a9
BS
390 nouveau_object_ref(NULL, &device);
391 nouveau_object_debug();
94580299
BS
392}
393
394int
395nouveau_drm_suspend(struct pci_dev *pdev, pm_message_t pm_state)
396{
397 struct drm_device *dev = pci_get_drvdata(pdev);
77145f1c 398 struct nouveau_drm *drm = nouveau_drm(dev);
94580299
BS
399 struct nouveau_cli *cli;
400 int ret;
401
402 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF ||
403 pm_state.event == PM_EVENT_PRETHAW)
404 return 0;
405
ebb945a9
BS
406 NV_INFO(drm, "suspending fbcon...\n");
407 nouveau_fbcon_set_suspend(dev, 1);
408
77145f1c
BS
409 NV_INFO(drm, "suspending display...\n");
410 ret = nouveau_display_suspend(dev);
94580299
BS
411 if (ret)
412 return ret;
413
ebb945a9
BS
414 NV_INFO(drm, "evicting buffers...\n");
415 ttm_bo_evict_mm(&drm->ttm.bdev, TTM_PL_VRAM);
416
417 if (drm->fence && nouveau_fence(drm)->suspend) {
418 if (!nouveau_fence(drm)->suspend(drm))
419 return -ENOMEM;
420 }
421
422 NV_INFO(drm, "suspending client object trees...\n");
94580299
BS
423 list_for_each_entry(cli, &drm->clients, head) {
424 ret = nouveau_client_fini(&cli->base, true);
425 if (ret)
426 goto fail_client;
427 }
428
429 ret = nouveau_client_fini(&drm->client.base, true);
430 if (ret)
431 goto fail_client;
432
cb75d97e
BS
433 nouveau_agp_fini(drm);
434
94580299
BS
435 pci_save_state(pdev);
436 if (pm_state.event == PM_EVENT_SUSPEND) {
437 pci_disable_device(pdev);
438 pci_set_power_state(pdev, PCI_D3hot);
439 }
440
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
77145f1c
BS
448 NV_INFO(drm, "resuming display...\n");
449 nouveau_display_resume(dev);
94580299
BS
450 return ret;
451}
452
453int
454nouveau_drm_resume(struct pci_dev *pdev)
455{
456 struct drm_device *dev = pci_get_drvdata(pdev);
77145f1c 457 struct nouveau_drm *drm = nouveau_drm(dev);
94580299
BS
458 struct nouveau_cli *cli;
459 int ret;
460
461 if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
462 return 0;
463
ebb945a9 464 NV_INFO(drm, "re-enabling device...\n");
94580299
BS
465 pci_set_power_state(pdev, PCI_D0);
466 pci_restore_state(pdev);
467 ret = pci_enable_device(pdev);
468 if (ret)
469 return ret;
470 pci_set_master(pdev);
471
cb75d97e
BS
472 nouveau_agp_reset(drm);
473
ebb945a9 474 NV_INFO(drm, "resuming client object trees...\n");
94580299 475 nouveau_client_init(&drm->client.base);
ebb945a9 476 nouveau_agp_init(drm);
94580299
BS
477
478 list_for_each_entry(cli, &drm->clients, head) {
479 nouveau_client_init(&cli->base);
480 }
cb75d97e 481
ebb945a9
BS
482 if (drm->fence && nouveau_fence(drm)->resume)
483 nouveau_fence(drm)->resume(drm);
94580299 484
77145f1c
BS
485 nouveau_run_vbios_init(dev);
486 nouveau_irq_postinstall(dev);
487 nouveau_pm_resume(dev);
488
489 NV_INFO(drm, "resuming display...\n");
490 nouveau_display_resume(dev);
491 return 0;
94580299
BS
492}
493
5b8a43ae 494static int
ebb945a9
BS
495nouveau_drm_open(struct drm_device *dev, struct drm_file *fpriv)
496{
497 struct pci_dev *pdev = dev->pdev;
498 struct nouveau_drm *drm = nouveau_drm(dev);
499 struct nouveau_cli *cli;
fa6df8c1 500 char name[16];
ebb945a9
BS
501 int ret;
502
612a9aab 503 snprintf(name, sizeof(name), "%d", pid_nr(fpriv->pid));
fa6df8c1
BS
504
505 ret = nouveau_cli_create(pdev, name, sizeof(*cli), (void **)&cli);
ebb945a9
BS
506 if (ret)
507 return ret;
508
509 if (nv_device(drm->device)->card_type >= NV_50) {
510 ret = nouveau_vm_new(nv_device(drm->device), 0, (1ULL << 40),
511 0x1000, &cli->base.vm);
512 if (ret) {
513 nouveau_cli_destroy(cli);
514 return ret;
515 }
516 }
517
518 fpriv->driver_priv = cli;
519
520 mutex_lock(&drm->client.mutex);
521 list_add(&cli->head, &drm->clients);
522 mutex_unlock(&drm->client.mutex);
523 return 0;
524}
525
5b8a43ae 526static void
ebb945a9
BS
527nouveau_drm_preclose(struct drm_device *dev, struct drm_file *fpriv)
528{
529 struct nouveau_cli *cli = nouveau_cli(fpriv);
530 struct nouveau_drm *drm = nouveau_drm(dev);
531
532 if (cli->abi16)
533 nouveau_abi16_fini(cli->abi16);
534
535 mutex_lock(&drm->client.mutex);
536 list_del(&cli->head);
537 mutex_unlock(&drm->client.mutex);
538}
539
5b8a43ae 540static void
ebb945a9
BS
541nouveau_drm_postclose(struct drm_device *dev, struct drm_file *fpriv)
542{
543 struct nouveau_cli *cli = nouveau_cli(fpriv);
544 nouveau_cli_destroy(cli);
545}
546
77145f1c
BS
547static struct drm_ioctl_desc
548nouveau_ioctls[] = {
549 DRM_IOCTL_DEF_DRV(NOUVEAU_GETPARAM, nouveau_abi16_ioctl_getparam, DRM_UNLOCKED|DRM_AUTH),
550 DRM_IOCTL_DEF_DRV(NOUVEAU_SETPARAM, nouveau_abi16_ioctl_setparam, DRM_UNLOCKED|DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
551 DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_ALLOC, nouveau_abi16_ioctl_channel_alloc, DRM_UNLOCKED|DRM_AUTH),
552 DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_FREE, nouveau_abi16_ioctl_channel_free, DRM_UNLOCKED|DRM_AUTH),
553 DRM_IOCTL_DEF_DRV(NOUVEAU_GROBJ_ALLOC, nouveau_abi16_ioctl_grobj_alloc, DRM_UNLOCKED|DRM_AUTH),
554 DRM_IOCTL_DEF_DRV(NOUVEAU_NOTIFIEROBJ_ALLOC, nouveau_abi16_ioctl_notifierobj_alloc, DRM_UNLOCKED|DRM_AUTH),
555 DRM_IOCTL_DEF_DRV(NOUVEAU_GPUOBJ_FREE, nouveau_abi16_ioctl_gpuobj_free, DRM_UNLOCKED|DRM_AUTH),
556 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_NEW, nouveau_gem_ioctl_new, DRM_UNLOCKED|DRM_AUTH),
557 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_PUSHBUF, nouveau_gem_ioctl_pushbuf, DRM_UNLOCKED|DRM_AUTH),
558 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_PREP, nouveau_gem_ioctl_cpu_prep, DRM_UNLOCKED|DRM_AUTH),
559 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_FINI, nouveau_gem_ioctl_cpu_fini, DRM_UNLOCKED|DRM_AUTH),
560 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_INFO, nouveau_gem_ioctl_info, DRM_UNLOCKED|DRM_AUTH),
561};
562
563static const struct file_operations
564nouveau_driver_fops = {
565 .owner = THIS_MODULE,
566 .open = drm_open,
567 .release = drm_release,
568 .unlocked_ioctl = drm_ioctl,
569 .mmap = nouveau_ttm_mmap,
570 .poll = drm_poll,
571 .fasync = drm_fasync,
572 .read = drm_read,
573#if defined(CONFIG_COMPAT)
574 .compat_ioctl = nouveau_compat_ioctl,
575#endif
576 .llseek = noop_llseek,
577};
578
579static struct drm_driver
580driver = {
581 .driver_features =
582 DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG |
583 DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM |
584 DRIVER_MODESET | DRIVER_PRIME,
585
586 .load = nouveau_drm_load,
587 .unload = nouveau_drm_unload,
588 .open = nouveau_drm_open,
589 .preclose = nouveau_drm_preclose,
590 .postclose = nouveau_drm_postclose,
591 .lastclose = nouveau_vga_lastclose,
592
593 .irq_preinstall = nouveau_irq_preinstall,
594 .irq_postinstall = nouveau_irq_postinstall,
595 .irq_uninstall = nouveau_irq_uninstall,
596 .irq_handler = nouveau_irq_handler,
597
598 .get_vblank_counter = drm_vblank_count,
599 .enable_vblank = nouveau_vblank_enable,
600 .disable_vblank = nouveau_vblank_disable,
601
602 .ioctls = nouveau_ioctls,
603 .fops = &nouveau_driver_fops,
604
605 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
606 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
607 .gem_prime_export = nouveau_gem_prime_export,
608 .gem_prime_import = nouveau_gem_prime_import,
609
610 .gem_init_object = nouveau_gem_object_new,
611 .gem_free_object = nouveau_gem_object_del,
612 .gem_open_object = nouveau_gem_object_open,
613 .gem_close_object = nouveau_gem_object_close,
614
615 .dumb_create = nouveau_display_dumb_create,
616 .dumb_map_offset = nouveau_display_dumb_map_offset,
617 .dumb_destroy = nouveau_display_dumb_destroy,
618
619 .name = DRIVER_NAME,
620 .desc = DRIVER_DESC,
621#ifdef GIT_REVISION
622 .date = GIT_REVISION,
623#else
624 .date = DRIVER_DATE,
625#endif
626 .major = DRIVER_MAJOR,
627 .minor = DRIVER_MINOR,
628 .patchlevel = DRIVER_PATCHLEVEL,
629};
630
94580299
BS
631static struct pci_device_id
632nouveau_drm_pci_table[] = {
633 {
634 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
635 .class = PCI_BASE_CLASS_DISPLAY << 16,
636 .class_mask = 0xff << 16,
637 },
638 {
639 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA_SGS, PCI_ANY_ID),
640 .class = PCI_BASE_CLASS_DISPLAY << 16,
641 .class_mask = 0xff << 16,
642 },
643 {}
644};
645
646static struct pci_driver
647nouveau_drm_pci_driver = {
648 .name = "nouveau",
649 .id_table = nouveau_drm_pci_table,
650 .probe = nouveau_drm_probe,
651 .remove = nouveau_drm_remove,
652 .suspend = nouveau_drm_suspend,
653 .resume = nouveau_drm_resume,
654};
655
656static int __init
657nouveau_drm_init(void)
658{
77145f1c
BS
659 driver.num_ioctls = ARRAY_SIZE(nouveau_ioctls);
660
661 if (nouveau_modeset == -1) {
662#ifdef CONFIG_VGA_CONSOLE
663 if (vgacon_text_force())
664 nouveau_modeset = 0;
665 else
666#endif
667 nouveau_modeset = 1;
668 }
669
670 if (!nouveau_modeset)
671 return 0;
672
673 nouveau_register_dsm_handler();
674 return drm_pci_init(&driver, &nouveau_drm_pci_driver);
94580299
BS
675}
676
677static void __exit
678nouveau_drm_exit(void)
679{
77145f1c
BS
680 if (!nouveau_modeset)
681 return;
682
683 drm_pci_exit(&driver, &nouveau_drm_pci_driver);
684 nouveau_unregister_dsm_handler();
94580299
BS
685}
686
687module_init(nouveau_drm_init);
688module_exit(nouveau_drm_exit);
689
690MODULE_DEVICE_TABLE(pci, nouveau_drm_pci_table);
77145f1c
BS
691MODULE_AUTHOR(DRIVER_AUTHOR);
692MODULE_DESCRIPTION(DRIVER_DESC);
94580299 693MODULE_LICENSE("GPL and additional rights");