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 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 52 MODULE_PARM_DESC(config, "option string to pass to driver core"); 53 static char *nouveau_config; 54 module_param_named(config, nouveau_config, charp, 0400); 55 56 MODULE_PARM_DESC(debug, "debug string to pass to driver core"); 57 static char *nouveau_debug; 58 module_param_named(debug, nouveau_debug, charp, 0400); 59 60 MODULE_PARM_DESC(noaccel, "disable kernel/abi16 acceleration"); 61 static int nouveau_noaccel = 0; 62 module_param_named(noaccel, nouveau_noaccel, int, 0400); 63 64 MODULE_PARM_DESC(modeset, "enable driver (default: auto, " 65 "0 = disabled, 1 = enabled, 2 = headless)"); 66 int nouveau_modeset = -1; 67 module_param_named(modeset, nouveau_modeset, int, 0400); 68 69 static struct drm_driver driver; 70 71 static u64 72 nouveau_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 80 static int 81 nouveau_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 ret = nouveau_client_create_(name, nouveau_name(pdev), nouveau_config, 88 nouveau_debug, size, pcli); 89 cli = *pcli; 90 if (ret) 91 return ret; 92 93 mutex_init(&cli->mutex); 94 return 0; 95 } 96 97 static void 98 nouveau_cli_destroy(struct nouveau_cli *cli) 99 { 100 struct nouveau_object *client = nv_object(cli); 101 nouveau_vm_ref(NULL, &cli->base.vm, NULL); 102 nouveau_client_fini(&cli->base, false); 103 atomic_set(&client->refcount, 1); 104 nouveau_object_ref(NULL, &client); 105 } 106 107 static void 108 nouveau_accel_fini(struct nouveau_drm *drm) 109 { 110 nouveau_gpuobj_ref(NULL, &drm->notify); 111 nouveau_channel_del(&drm->channel); 112 nouveau_channel_del(&drm->cechan); 113 if (drm->fence) 114 nouveau_fence(drm)->dtor(drm); 115 } 116 117 static void 118 nouveau_accel_init(struct nouveau_drm *drm) 119 { 120 struct nouveau_device *device = nv_device(drm->device); 121 struct nouveau_object *object; 122 u32 arg0, arg1; 123 int ret; 124 125 if (nouveau_noaccel) 126 return; 127 128 /* initialise synchronisation routines */ 129 if (device->card_type < NV_10) ret = nv04_fence_create(drm); 130 else if (device->card_type < NV_50) ret = nv10_fence_create(drm); 131 else if (device->chipset < 0x84) ret = nv50_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 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 = 1; 151 } else { 152 arg0 = NvDmaFB; 153 arg1 = NvDmaTT; 154 } 155 156 ret = nouveau_channel_new(drm, &drm->client, NVDRM_DEVICE, NVDRM_CHAN, 157 arg0, arg1, &drm->channel); 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 189 nouveau_bo_move_init(drm); 190 } 191 192 static int __devinit 193 nouveau_drm_probe(struct pci_dev *pdev, const struct pci_device_id *pent) 194 { 195 struct nouveau_device *device; 196 struct apertures_struct *aper; 197 bool boot = false; 198 int ret; 199 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 kfree(aper); 226 227 ret = nouveau_device_create(pdev, nouveau_name(pdev), pci_name(pdev), 228 nouveau_config, nouveau_debug, &device); 229 if (ret) 230 return ret; 231 232 pci_set_master(pdev); 233 234 ret = drm_get_pci_dev(pdev, pent, &driver); 235 if (ret) { 236 nouveau_object_ref(NULL, (struct nouveau_object **)&device); 237 return ret; 238 } 239 240 return 0; 241 } 242 243 static int 244 nouveau_drm_load(struct drm_device *dev, unsigned long flags) 245 { 246 struct pci_dev *pdev = dev->pdev; 247 struct nouveau_device *device; 248 struct nouveau_drm *drm; 249 int ret; 250 251 ret = nouveau_cli_create(pdev, "DRM", sizeof(*drm), (void**)&drm); 252 if (ret) 253 return ret; 254 255 dev->dev_private = drm; 256 drm->dev = dev; 257 258 INIT_LIST_HEAD(&drm->clients); 259 spin_lock_init(&drm->tile.lock); 260 261 /* make sure AGP controller is in a consistent state before we 262 * (possibly) execute vbios init tables (see nouveau_agp.h) 263 */ 264 if (drm_pci_device_is_agp(dev) && dev->agp) { 265 /* dummy device object, doesn't init anything, but allows 266 * agp code access to registers 267 */ 268 ret = nouveau_object_new(nv_object(drm), NVDRM_CLIENT, 269 NVDRM_DEVICE, 0x0080, 270 &(struct nv_device_class) { 271 .device = ~0, 272 .disable = 273 ~(NV_DEVICE_DISABLE_MMIO | 274 NV_DEVICE_DISABLE_IDENTIFY), 275 .debug0 = ~0, 276 }, sizeof(struct nv_device_class), 277 &drm->device); 278 if (ret) 279 goto fail_device; 280 281 nouveau_agp_reset(drm); 282 nouveau_object_del(nv_object(drm), NVDRM_CLIENT, NVDRM_DEVICE); 283 } 284 285 ret = nouveau_object_new(nv_object(drm), NVDRM_CLIENT, NVDRM_DEVICE, 286 0x0080, &(struct nv_device_class) { 287 .device = ~0, 288 .disable = 0, 289 .debug0 = 0, 290 }, sizeof(struct nv_device_class), 291 &drm->device); 292 if (ret) 293 goto fail_device; 294 295 /* workaround an odd issue on nvc1 by disabling the device's 296 * nosnoop capability. hopefully won't cause issues until a 297 * better fix is found - assuming there is one... 298 */ 299 device = nv_device(drm->device); 300 if (nv_device(drm->device)->chipset == 0xc1) 301 nv_mask(device, 0x00088080, 0x00000800, 0x00000000); 302 303 nouveau_vga_init(drm); 304 nouveau_agp_init(drm); 305 306 if (device->card_type >= NV_50) { 307 ret = nouveau_vm_new(nv_device(drm->device), 0, (1ULL << 40), 308 0x1000, &drm->client.base.vm); 309 if (ret) 310 goto fail_device; 311 } 312 313 ret = nouveau_ttm_init(drm); 314 if (ret) 315 goto fail_ttm; 316 317 ret = nouveau_bios_init(dev); 318 if (ret) 319 goto fail_bios; 320 321 ret = nouveau_irq_init(dev); 322 if (ret) 323 goto fail_irq; 324 325 ret = nouveau_display_create(dev); 326 if (ret) 327 goto fail_dispctor; 328 329 if (dev->mode_config.num_crtc) { 330 ret = nouveau_display_init(dev); 331 if (ret) 332 goto fail_dispinit; 333 } 334 335 nouveau_pm_init(dev); 336 337 nouveau_accel_init(drm); 338 nouveau_fbcon_init(dev); 339 return 0; 340 341 fail_dispinit: 342 nouveau_display_destroy(dev); 343 fail_dispctor: 344 nouveau_irq_fini(dev); 345 fail_irq: 346 nouveau_bios_takedown(dev); 347 fail_bios: 348 nouveau_ttm_fini(drm); 349 fail_ttm: 350 nouveau_agp_fini(drm); 351 nouveau_vga_fini(drm); 352 fail_device: 353 nouveau_cli_destroy(&drm->client); 354 return ret; 355 } 356 357 static int 358 nouveau_drm_unload(struct drm_device *dev) 359 { 360 struct nouveau_drm *drm = nouveau_drm(dev); 361 362 nouveau_fbcon_fini(dev); 363 nouveau_accel_fini(drm); 364 365 nouveau_pm_fini(dev); 366 367 if (dev->mode_config.num_crtc) 368 nouveau_display_fini(dev); 369 nouveau_display_destroy(dev); 370 371 nouveau_irq_fini(dev); 372 nouveau_bios_takedown(dev); 373 374 nouveau_ttm_fini(drm); 375 nouveau_agp_fini(drm); 376 nouveau_vga_fini(drm); 377 378 nouveau_cli_destroy(&drm->client); 379 return 0; 380 } 381 382 static void 383 nouveau_drm_remove(struct pci_dev *pdev) 384 { 385 struct drm_device *dev = pci_get_drvdata(pdev); 386 struct nouveau_drm *drm = nouveau_drm(dev); 387 struct nouveau_object *device; 388 389 device = drm->client.base.device; 390 drm_put_dev(dev); 391 392 nouveau_object_ref(NULL, &device); 393 nouveau_object_debug(); 394 } 395 396 int 397 nouveau_do_suspend(struct drm_device *dev) 398 { 399 struct nouveau_drm *drm = nouveau_drm(dev); 400 struct nouveau_cli *cli; 401 int ret; 402 403 if (dev->mode_config.num_crtc) { 404 NV_INFO(drm, "suspending fbcon...\n"); 405 nouveau_fbcon_set_suspend(dev, 1); 406 407 NV_INFO(drm, "suspending display...\n"); 408 ret = nouveau_display_suspend(dev); 409 if (ret) 410 return ret; 411 } 412 413 NV_INFO(drm, "evicting buffers...\n"); 414 ttm_bo_evict_mm(&drm->ttm.bdev, TTM_PL_VRAM); 415 416 if (drm->fence && nouveau_fence(drm)->suspend) { 417 if (!nouveau_fence(drm)->suspend(drm)) 418 return -ENOMEM; 419 } 420 421 NV_INFO(drm, "suspending client object trees...\n"); 422 list_for_each_entry(cli, &drm->clients, head) { 423 ret = nouveau_client_fini(&cli->base, true); 424 if (ret) 425 goto fail_client; 426 } 427 428 ret = nouveau_client_fini(&drm->client.base, true); 429 if (ret) 430 goto fail_client; 431 432 nouveau_agp_fini(drm); 433 return 0; 434 435 fail_client: 436 list_for_each_entry_continue_reverse(cli, &drm->clients, head) { 437 nouveau_client_init(&cli->base); 438 } 439 440 if (dev->mode_config.num_crtc) { 441 NV_INFO(drm, "resuming display...\n"); 442 nouveau_display_resume(dev); 443 } 444 return ret; 445 } 446 447 int nouveau_pmops_suspend(struct device *dev) 448 { 449 struct pci_dev *pdev = to_pci_dev(dev); 450 struct drm_device *drm_dev = pci_get_drvdata(pdev); 451 int ret; 452 453 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF) 454 return 0; 455 456 ret = nouveau_do_suspend(drm_dev); 457 if (ret) 458 return ret; 459 460 pci_save_state(pdev); 461 pci_disable_device(pdev); 462 pci_set_power_state(pdev, PCI_D3hot); 463 464 return 0; 465 } 466 467 int 468 nouveau_do_resume(struct drm_device *dev) 469 { 470 struct nouveau_drm *drm = nouveau_drm(dev); 471 struct nouveau_cli *cli; 472 473 NV_INFO(drm, "re-enabling device...\n"); 474 475 nouveau_agp_reset(drm); 476 477 NV_INFO(drm, "resuming client object trees...\n"); 478 nouveau_client_init(&drm->client.base); 479 nouveau_agp_init(drm); 480 481 list_for_each_entry(cli, &drm->clients, head) { 482 nouveau_client_init(&cli->base); 483 } 484 485 if (drm->fence && nouveau_fence(drm)->resume) 486 nouveau_fence(drm)->resume(drm); 487 488 nouveau_run_vbios_init(dev); 489 nouveau_irq_postinstall(dev); 490 nouveau_pm_resume(dev); 491 492 if (dev->mode_config.num_crtc) { 493 NV_INFO(drm, "resuming display...\n"); 494 nouveau_display_resume(dev); 495 } 496 return 0; 497 } 498 499 int nouveau_pmops_resume(struct device *dev) 500 { 501 struct pci_dev *pdev = to_pci_dev(dev); 502 struct drm_device *drm_dev = pci_get_drvdata(pdev); 503 int ret; 504 505 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF) 506 return 0; 507 508 pci_set_power_state(pdev, PCI_D0); 509 pci_restore_state(pdev); 510 ret = pci_enable_device(pdev); 511 if (ret) 512 return ret; 513 pci_set_master(pdev); 514 515 return nouveau_do_resume(drm_dev); 516 } 517 518 static int nouveau_pmops_freeze(struct device *dev) 519 { 520 struct pci_dev *pdev = to_pci_dev(dev); 521 struct drm_device *drm_dev = pci_get_drvdata(pdev); 522 523 return nouveau_do_suspend(drm_dev); 524 } 525 526 static int nouveau_pmops_thaw(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_resume(drm_dev); 532 } 533 534 535 static int 536 nouveau_drm_open(struct drm_device *dev, struct drm_file *fpriv) 537 { 538 struct pci_dev *pdev = dev->pdev; 539 struct nouveau_drm *drm = nouveau_drm(dev); 540 struct nouveau_cli *cli; 541 char name[16]; 542 int ret; 543 544 snprintf(name, sizeof(name), "%d", pid_nr(fpriv->pid)); 545 546 ret = nouveau_cli_create(pdev, name, sizeof(*cli), (void **)&cli); 547 if (ret) 548 return ret; 549 550 if (nv_device(drm->device)->card_type >= NV_50) { 551 ret = nouveau_vm_new(nv_device(drm->device), 0, (1ULL << 40), 552 0x1000, &cli->base.vm); 553 if (ret) { 554 nouveau_cli_destroy(cli); 555 return ret; 556 } 557 } 558 559 fpriv->driver_priv = cli; 560 561 mutex_lock(&drm->client.mutex); 562 list_add(&cli->head, &drm->clients); 563 mutex_unlock(&drm->client.mutex); 564 return 0; 565 } 566 567 static void 568 nouveau_drm_preclose(struct drm_device *dev, struct drm_file *fpriv) 569 { 570 struct nouveau_cli *cli = nouveau_cli(fpriv); 571 struct nouveau_drm *drm = nouveau_drm(dev); 572 573 if (cli->abi16) 574 nouveau_abi16_fini(cli->abi16); 575 576 mutex_lock(&drm->client.mutex); 577 list_del(&cli->head); 578 mutex_unlock(&drm->client.mutex); 579 } 580 581 static void 582 nouveau_drm_postclose(struct drm_device *dev, struct drm_file *fpriv) 583 { 584 struct nouveau_cli *cli = nouveau_cli(fpriv); 585 nouveau_cli_destroy(cli); 586 } 587 588 static struct drm_ioctl_desc 589 nouveau_ioctls[] = { 590 DRM_IOCTL_DEF_DRV(NOUVEAU_GETPARAM, nouveau_abi16_ioctl_getparam, DRM_UNLOCKED|DRM_AUTH), 591 DRM_IOCTL_DEF_DRV(NOUVEAU_SETPARAM, nouveau_abi16_ioctl_setparam, DRM_UNLOCKED|DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), 592 DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_ALLOC, nouveau_abi16_ioctl_channel_alloc, DRM_UNLOCKED|DRM_AUTH), 593 DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_FREE, nouveau_abi16_ioctl_channel_free, DRM_UNLOCKED|DRM_AUTH), 594 DRM_IOCTL_DEF_DRV(NOUVEAU_GROBJ_ALLOC, nouveau_abi16_ioctl_grobj_alloc, DRM_UNLOCKED|DRM_AUTH), 595 DRM_IOCTL_DEF_DRV(NOUVEAU_NOTIFIEROBJ_ALLOC, nouveau_abi16_ioctl_notifierobj_alloc, DRM_UNLOCKED|DRM_AUTH), 596 DRM_IOCTL_DEF_DRV(NOUVEAU_GPUOBJ_FREE, nouveau_abi16_ioctl_gpuobj_free, DRM_UNLOCKED|DRM_AUTH), 597 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_NEW, nouveau_gem_ioctl_new, DRM_UNLOCKED|DRM_AUTH), 598 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_PUSHBUF, nouveau_gem_ioctl_pushbuf, DRM_UNLOCKED|DRM_AUTH), 599 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_PREP, nouveau_gem_ioctl_cpu_prep, DRM_UNLOCKED|DRM_AUTH), 600 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_FINI, nouveau_gem_ioctl_cpu_fini, DRM_UNLOCKED|DRM_AUTH), 601 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_INFO, nouveau_gem_ioctl_info, DRM_UNLOCKED|DRM_AUTH), 602 }; 603 604 static const struct file_operations 605 nouveau_driver_fops = { 606 .owner = THIS_MODULE, 607 .open = drm_open, 608 .release = drm_release, 609 .unlocked_ioctl = drm_ioctl, 610 .mmap = nouveau_ttm_mmap, 611 .poll = drm_poll, 612 .fasync = drm_fasync, 613 .read = drm_read, 614 #if defined(CONFIG_COMPAT) 615 .compat_ioctl = nouveau_compat_ioctl, 616 #endif 617 .llseek = noop_llseek, 618 }; 619 620 static struct drm_driver 621 driver = { 622 .driver_features = 623 DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG | 624 DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | 625 DRIVER_MODESET | DRIVER_PRIME, 626 627 .load = nouveau_drm_load, 628 .unload = nouveau_drm_unload, 629 .open = nouveau_drm_open, 630 .preclose = nouveau_drm_preclose, 631 .postclose = nouveau_drm_postclose, 632 .lastclose = nouveau_vga_lastclose, 633 634 .irq_preinstall = nouveau_irq_preinstall, 635 .irq_postinstall = nouveau_irq_postinstall, 636 .irq_uninstall = nouveau_irq_uninstall, 637 .irq_handler = nouveau_irq_handler, 638 639 .get_vblank_counter = drm_vblank_count, 640 .enable_vblank = nouveau_vblank_enable, 641 .disable_vblank = nouveau_vblank_disable, 642 643 .ioctls = nouveau_ioctls, 644 .fops = &nouveau_driver_fops, 645 646 .prime_handle_to_fd = drm_gem_prime_handle_to_fd, 647 .prime_fd_to_handle = drm_gem_prime_fd_to_handle, 648 .gem_prime_export = nouveau_gem_prime_export, 649 .gem_prime_import = nouveau_gem_prime_import, 650 651 .gem_init_object = nouveau_gem_object_new, 652 .gem_free_object = nouveau_gem_object_del, 653 .gem_open_object = nouveau_gem_object_open, 654 .gem_close_object = nouveau_gem_object_close, 655 656 .dumb_create = nouveau_display_dumb_create, 657 .dumb_map_offset = nouveau_display_dumb_map_offset, 658 .dumb_destroy = nouveau_display_dumb_destroy, 659 660 .name = DRIVER_NAME, 661 .desc = DRIVER_DESC, 662 #ifdef GIT_REVISION 663 .date = GIT_REVISION, 664 #else 665 .date = DRIVER_DATE, 666 #endif 667 .major = DRIVER_MAJOR, 668 .minor = DRIVER_MINOR, 669 .patchlevel = DRIVER_PATCHLEVEL, 670 }; 671 672 static struct pci_device_id 673 nouveau_drm_pci_table[] = { 674 { 675 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID), 676 .class = PCI_BASE_CLASS_DISPLAY << 16, 677 .class_mask = 0xff << 16, 678 }, 679 { 680 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA_SGS, PCI_ANY_ID), 681 .class = PCI_BASE_CLASS_DISPLAY << 16, 682 .class_mask = 0xff << 16, 683 }, 684 {} 685 }; 686 687 static const struct dev_pm_ops nouveau_pm_ops = { 688 .suspend = nouveau_pmops_suspend, 689 .resume = nouveau_pmops_resume, 690 .freeze = nouveau_pmops_freeze, 691 .thaw = nouveau_pmops_thaw, 692 .poweroff = nouveau_pmops_freeze, 693 .restore = nouveau_pmops_resume, 694 }; 695 696 static struct pci_driver 697 nouveau_drm_pci_driver = { 698 .name = "nouveau", 699 .id_table = nouveau_drm_pci_table, 700 .probe = nouveau_drm_probe, 701 .remove = nouveau_drm_remove, 702 .driver.pm = &nouveau_pm_ops, 703 }; 704 705 static int __init 706 nouveau_drm_init(void) 707 { 708 driver.num_ioctls = ARRAY_SIZE(nouveau_ioctls); 709 710 if (nouveau_modeset == -1) { 711 #ifdef CONFIG_VGA_CONSOLE 712 if (vgacon_text_force()) 713 nouveau_modeset = 0; 714 #endif 715 } 716 717 if (!nouveau_modeset) 718 return 0; 719 720 nouveau_register_dsm_handler(); 721 return drm_pci_init(&driver, &nouveau_drm_pci_driver); 722 } 723 724 static void __exit 725 nouveau_drm_exit(void) 726 { 727 if (!nouveau_modeset) 728 return; 729 730 drm_pci_exit(&driver, &nouveau_drm_pci_driver); 731 nouveau_unregister_dsm_handler(); 732 } 733 734 module_init(nouveau_drm_init); 735 module_exit(nouveau_drm_exit); 736 737 MODULE_DEVICE_TABLE(pci, nouveau_drm_pci_table); 738 MODULE_AUTHOR(DRIVER_AUTHOR); 739 MODULE_DESCRIPTION(DRIVER_DESC); 740 MODULE_LICENSE("GPL and additional rights"); 741