]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/gpu/drm/nouveau/nouveau_drm.c
drm/nouveau/nvif: split out perfmon interface definitions
[mirror_ubuntu-bionic-kernel.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>
c5fd936e 26#include <linux/delay.h>
94580299
BS
27#include <linux/module.h>
28#include <linux/pci.h>
5addcf0a
DA
29#include <linux/pm_runtime.h>
30#include <linux/vga_switcheroo.h>
fdb751ef 31
5addcf0a
DA
32#include "drmP.h"
33#include "drm_crtc_helper.h"
fdb751ef 34
ebb945a9 35#include <core/gpuobj.h>
c33e05a1 36#include <core/option.h>
7974dd1b
BS
37#include <core/pci.h>
38#include <core/tegra.h>
94580299 39
8ed1730c 40#include <nvif/cla06f.h>
538b269b
BS
41#include <nvif/if0004.h>
42
94580299 43#include "nouveau_drm.h"
ebb945a9 44#include "nouveau_dma.h"
77145f1c
BS
45#include "nouveau_ttm.h"
46#include "nouveau_gem.h"
77145f1c 47#include "nouveau_vga.h"
26fdd78c 48#include "nouveau_sysfs.h"
b9ed919f 49#include "nouveau_hwmon.h"
77145f1c
BS
50#include "nouveau_acpi.h"
51#include "nouveau_bios.h"
52#include "nouveau_ioctl.h"
ebb945a9
BS
53#include "nouveau_abi16.h"
54#include "nouveau_fbcon.h"
55#include "nouveau_fence.h"
33b903e8 56#include "nouveau_debugfs.h"
27111a23 57#include "nouveau_usif.h"
703fa264 58#include "nouveau_connector.h"
055a65d5 59#include "nouveau_platform.h"
ebb945a9 60
94580299
BS
61MODULE_PARM_DESC(config, "option string to pass to driver core");
62static char *nouveau_config;
63module_param_named(config, nouveau_config, charp, 0400);
64
65MODULE_PARM_DESC(debug, "debug string to pass to driver core");
66static char *nouveau_debug;
67module_param_named(debug, nouveau_debug, charp, 0400);
68
ebb945a9
BS
69MODULE_PARM_DESC(noaccel, "disable kernel/abi16 acceleration");
70static int nouveau_noaccel = 0;
71module_param_named(noaccel, nouveau_noaccel, int, 0400);
72
9430738d
BS
73MODULE_PARM_DESC(modeset, "enable driver (default: auto, "
74 "0 = disabled, 1 = enabled, 2 = headless)");
75int nouveau_modeset = -1;
77145f1c
BS
76module_param_named(modeset, nouveau_modeset, int, 0400);
77
5addcf0a
DA
78MODULE_PARM_DESC(runpm, "disable (0), force enable (1), optimus only default (-1)");
79int nouveau_runtime_pm = -1;
80module_param_named(runpm, nouveau_runtime_pm, int, 0400);
81
915b4d11
DH
82static struct drm_driver driver_stub;
83static struct drm_driver driver_pci;
84static struct drm_driver driver_platform;
77145f1c 85
94580299 86static u64
420b9469 87nouveau_pci_name(struct pci_dev *pdev)
94580299
BS
88{
89 u64 name = (u64)pci_domain_nr(pdev->bus) << 32;
90 name |= pdev->bus->number << 16;
91 name |= PCI_SLOT(pdev->devfn) << 8;
92 return name | PCI_FUNC(pdev->devfn);
93}
94
420b9469
AC
95static u64
96nouveau_platform_name(struct platform_device *platformdev)
97{
98 return platformdev->id;
99}
100
101static u64
102nouveau_name(struct drm_device *dev)
103{
104 if (dev->pdev)
105 return nouveau_pci_name(dev->pdev);
106 else
107 return nouveau_platform_name(dev->platformdev);
108}
109
94580299 110static int
9ad97ede 111nouveau_cli_create(struct drm_device *dev, const char *sname,
fa6df8c1 112 int size, void **pcli)
94580299 113{
0ad72863 114 struct nouveau_cli *cli = *pcli = kzalloc(size, GFP_KERNEL);
9ad97ede 115 int ret;
0ad72863 116 if (cli) {
9ad97ede
BS
117 snprintf(cli->name, sizeof(cli->name), "%s", sname);
118 cli->dev = dev;
119
a01ca78c 120 ret = nvif_client_init(NULL, cli->name, nouveau_name(dev),
9ad97ede
BS
121 nouveau_config, nouveau_debug,
122 &cli->base);
27111a23 123 if (ret == 0) {
0ad72863 124 mutex_init(&cli->mutex);
27111a23
BS
125 usif_client_init(cli);
126 }
94580299 127 return ret;
dd5700ea 128 }
0ad72863 129 return -ENOMEM;
94580299
BS
130}
131
132static void
133nouveau_cli_destroy(struct nouveau_cli *cli)
134{
be83cd4e 135 nvkm_vm_ref(NULL, &nvxx_client(&cli->base)->vm, NULL);
0ad72863 136 nvif_client_fini(&cli->base);
27111a23 137 usif_client_fini(cli);
f5654d95 138 kfree(cli);
94580299
BS
139}
140
ebb945a9
BS
141static void
142nouveau_accel_fini(struct nouveau_drm *drm)
143{
fbd58ebd 144 nouveau_channel_idle(drm->channel);
0ad72863 145 nvif_object_fini(&drm->ntfy);
f027f491 146 nvkm_gpuobj_del(&drm->notify);
fbd58ebd 147 nvif_notify_fini(&drm->flip);
0ad72863 148 nvif_object_fini(&drm->nvsw);
fbd58ebd
BS
149 nouveau_channel_del(&drm->channel);
150
151 nouveau_channel_idle(drm->cechan);
0ad72863 152 nvif_object_fini(&drm->ttm.copy);
fbd58ebd
BS
153 nouveau_channel_del(&drm->cechan);
154
ebb945a9
BS
155 if (drm->fence)
156 nouveau_fence(drm)->dtor(drm);
157}
158
159static void
160nouveau_accel_init(struct nouveau_drm *drm)
161{
967e7bde 162 struct nvif_device *device = &drm->device;
41a63406 163 struct nvif_sclass *sclass;
49981046 164 u32 arg0, arg1;
41a63406 165 int ret, i, n;
ebb945a9 166
967e7bde 167 if (nouveau_noaccel)
ebb945a9
BS
168 return;
169
170 /* initialise synchronisation routines */
967e7bde
BS
171 /*XXX: this is crap, but the fence/channel stuff is a little
172 * backwards in some places. this will be fixed.
173 */
41a63406 174 ret = n = nvif_object_sclass_get(&device->object, &sclass);
967e7bde
BS
175 if (ret < 0)
176 return;
177
41a63406
BS
178 for (ret = -ENOSYS, i = 0; i < n; i++) {
179 switch (sclass[i].oclass) {
bbf8906b 180 case NV03_CHANNEL_DMA:
967e7bde
BS
181 ret = nv04_fence_create(drm);
182 break;
bbf8906b 183 case NV10_CHANNEL_DMA:
967e7bde
BS
184 ret = nv10_fence_create(drm);
185 break;
bbf8906b
BS
186 case NV17_CHANNEL_DMA:
187 case NV40_CHANNEL_DMA:
967e7bde
BS
188 ret = nv17_fence_create(drm);
189 break;
bbf8906b 190 case NV50_CHANNEL_GPFIFO:
967e7bde
BS
191 ret = nv50_fence_create(drm);
192 break;
bbf8906b 193 case G82_CHANNEL_GPFIFO:
967e7bde
BS
194 ret = nv84_fence_create(drm);
195 break;
bbf8906b
BS
196 case FERMI_CHANNEL_GPFIFO:
197 case KEPLER_CHANNEL_GPFIFO_A:
a1020afe 198 case MAXWELL_CHANNEL_GPFIFO_A:
967e7bde
BS
199 ret = nvc0_fence_create(drm);
200 break;
201 default:
202 break;
203 }
204 }
205
41a63406 206 nvif_object_sclass_put(&sclass);
ebb945a9
BS
207 if (ret) {
208 NV_ERROR(drm, "failed to initialise sync subsystem, %d\n", ret);
209 nouveau_accel_fini(drm);
210 return;
211 }
212
967e7bde 213 if (device->info.family >= NV_DEVICE_INFO_V0_KEPLER) {
fcf3f91c 214 ret = nouveau_channel_new(drm, &drm->device,
bbf8906b
BS
215 KEPLER_CHANNEL_GPFIFO_A_V0_ENGINE_CE0|
216 KEPLER_CHANNEL_GPFIFO_A_V0_ENGINE_CE1,
217 0, &drm->cechan);
49981046
BS
218 if (ret)
219 NV_ERROR(drm, "failed to create ce channel, %d\n", ret);
220
bbf8906b 221 arg0 = KEPLER_CHANNEL_GPFIFO_A_V0_ENGINE_GR;
49469800 222 arg1 = 1;
00fc6f6f 223 } else
967e7bde
BS
224 if (device->info.chipset >= 0xa3 &&
225 device->info.chipset != 0xaa &&
226 device->info.chipset != 0xac) {
fcf3f91c 227 ret = nouveau_channel_new(drm, &drm->device,
0ad72863 228 NvDmaFB, NvDmaTT, &drm->cechan);
00fc6f6f
BS
229 if (ret)
230 NV_ERROR(drm, "failed to create ce channel, %d\n", ret);
231
232 arg0 = NvDmaFB;
233 arg1 = NvDmaTT;
49981046
BS
234 } else {
235 arg0 = NvDmaFB;
236 arg1 = NvDmaTT;
237 }
238
fcf3f91c 239 ret = nouveau_channel_new(drm, &drm->device, arg0, arg1, &drm->channel);
ebb945a9
BS
240 if (ret) {
241 NV_ERROR(drm, "failed to create kernel channel, %d\n", ret);
242 nouveau_accel_fini(drm);
243 return;
244 }
245
a01ca78c 246 ret = nvif_object_init(&drm->channel->user, NVDRM_NVSW,
0ad72863 247 nouveau_abi16_swclass(drm), NULL, 0, &drm->nvsw);
69a6146d 248 if (ret == 0) {
69a6146d
BS
249 ret = RING_SPACE(drm->channel, 2);
250 if (ret == 0) {
967e7bde 251 if (device->info.family < NV_DEVICE_INFO_V0_FERMI) {
69a6146d
BS
252 BEGIN_NV04(drm->channel, NvSubSw, 0, 1);
253 OUT_RING (drm->channel, NVDRM_NVSW);
254 } else
967e7bde 255 if (device->info.family < NV_DEVICE_INFO_V0_KEPLER) {
69a6146d
BS
256 BEGIN_NVC0(drm->channel, FermiSw, 0, 1);
257 OUT_RING (drm->channel, 0x001f0000);
258 }
259 }
898a2b32
BS
260
261 ret = nvif_notify_init(&drm->nvsw, nouveau_flip_complete,
538b269b
BS
262 false, NV04_NVSW_NTFY_UEVENT,
263 NULL, 0, 0, &drm->flip);
898a2b32
BS
264 if (ret == 0)
265 ret = nvif_notify_get(&drm->flip);
266 if (ret) {
267 nouveau_accel_fini(drm);
268 return;
269 }
69a6146d
BS
270 }
271
272 if (ret) {
273 NV_ERROR(drm, "failed to allocate software object, %d\n", ret);
274 nouveau_accel_fini(drm);
275 return;
276 }
277
967e7bde 278 if (device->info.family < NV_DEVICE_INFO_V0_FERMI) {
f027f491
BS
279 ret = nvkm_gpuobj_new(nvxx_device(&drm->device), 32, 0, false,
280 NULL, &drm->notify);
ebb945a9
BS
281 if (ret) {
282 NV_ERROR(drm, "failed to allocate notifier, %d\n", ret);
283 nouveau_accel_fini(drm);
284 return;
285 }
286
a01ca78c 287 ret = nvif_object_init(&drm->channel->user, NvNotify0,
4acfd707
BS
288 NV_DMA_IN_MEMORY,
289 &(struct nv_dma_v0) {
290 .target = NV_DMA_V0_TARGET_VRAM,
291 .access = NV_DMA_V0_ACCESS_RDWR,
ebb945a9
BS
292 .start = drm->notify->addr,
293 .limit = drm->notify->addr + 31
4acfd707 294 }, sizeof(struct nv_dma_v0),
0ad72863 295 &drm->ntfy);
ebb945a9
BS
296 if (ret) {
297 nouveau_accel_fini(drm);
298 return;
299 }
300 }
301
302
49981046 303 nouveau_bo_move_init(drm);
ebb945a9
BS
304}
305
56550d94
GKH
306static int nouveau_drm_probe(struct pci_dev *pdev,
307 const struct pci_device_id *pent)
94580299 308{
be83cd4e 309 struct nvkm_device *device;
ebb945a9
BS
310 struct apertures_struct *aper;
311 bool boot = false;
94580299
BS
312 int ret;
313
ebb945a9
BS
314 /* remove conflicting drivers (vesafb, efifb etc) */
315 aper = alloc_apertures(3);
316 if (!aper)
317 return -ENOMEM;
318
319 aper->ranges[0].base = pci_resource_start(pdev, 1);
320 aper->ranges[0].size = pci_resource_len(pdev, 1);
321 aper->count = 1;
322
323 if (pci_resource_len(pdev, 2)) {
324 aper->ranges[aper->count].base = pci_resource_start(pdev, 2);
325 aper->ranges[aper->count].size = pci_resource_len(pdev, 2);
326 aper->count++;
327 }
328
329 if (pci_resource_len(pdev, 3)) {
330 aper->ranges[aper->count].base = pci_resource_start(pdev, 3);
331 aper->ranges[aper->count].size = pci_resource_len(pdev, 3);
332 aper->count++;
333 }
334
335#ifdef CONFIG_X86
336 boot = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
337#endif
771fa0e4
BS
338 if (nouveau_modeset != 2)
339 remove_conflicting_framebuffers(aper, "nouveaufb", boot);
83ef7777 340 kfree(aper);
ebb945a9 341
7974dd1b
BS
342 ret = nvkm_device_pci_new(pdev, nouveau_config, nouveau_debug,
343 true, true, ~0ULL, &device);
94580299
BS
344 if (ret)
345 return ret;
346
347 pci_set_master(pdev);
348
915b4d11 349 ret = drm_get_pci_dev(pdev, pent, &driver_pci);
94580299 350 if (ret) {
e781dc8f 351 nvkm_device_del(&device);
94580299
BS
352 return ret;
353 }
354
355 return 0;
356}
357
5addcf0a
DA
358#define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
359
360static void
46941b0f 361nouveau_get_hdmi_dev(struct nouveau_drm *drm)
5addcf0a 362{
46941b0f 363 struct pci_dev *pdev = drm->dev->pdev;
5addcf0a 364
420b9469 365 if (!pdev) {
40189b0c 366 DRM_INFO("not a PCI device; no HDMI\n");
420b9469
AC
367 drm->hdmi_device = NULL;
368 return;
369 }
370
5addcf0a
DA
371 /* subfunction one is a hdmi audio device? */
372 drm->hdmi_device = pci_get_bus_and_slot((unsigned int)pdev->bus->number,
373 PCI_DEVFN(PCI_SLOT(pdev->devfn), 1));
374
375 if (!drm->hdmi_device) {
46941b0f 376 NV_DEBUG(drm, "hdmi device not found %d %d %d\n", pdev->bus->number, PCI_SLOT(pdev->devfn), 1);
5addcf0a
DA
377 return;
378 }
379
380 if ((drm->hdmi_device->class >> 8) != PCI_CLASS_MULTIMEDIA_HD_AUDIO) {
46941b0f 381 NV_DEBUG(drm, "possible hdmi device not audio %d\n", drm->hdmi_device->class);
5addcf0a
DA
382 pci_dev_put(drm->hdmi_device);
383 drm->hdmi_device = NULL;
384 return;
385 }
386}
387
5b8a43ae 388static int
94580299
BS
389nouveau_drm_load(struct drm_device *dev, unsigned long flags)
390{
94580299
BS
391 struct nouveau_drm *drm;
392 int ret;
393
9ad97ede 394 ret = nouveau_cli_create(dev, "DRM", sizeof(*drm), (void **)&drm);
94580299
BS
395 if (ret)
396 return ret;
397
77145f1c
BS
398 dev->dev_private = drm;
399 drm->dev = dev;
989aa5b7 400 nvxx_client(&drm->client.base)->debug =
be83cd4e 401 nvkm_dbgopt(nouveau_debug, "DRM");
77145f1c 402
94580299 403 INIT_LIST_HEAD(&drm->clients);
ebb945a9 404 spin_lock_init(&drm->tile.lock);
94580299 405
46941b0f 406 nouveau_get_hdmi_dev(drm);
5addcf0a 407
fcf3f91c 408 ret = nvif_device_init(&drm->client.base.object, 0, NV_DEVICE,
586491e6 409 &(struct nv_device_v0) {
94580299 410 .device = ~0,
586491e6 411 }, sizeof(struct nv_device_v0),
0ad72863 412 &drm->device);
94580299
BS
413 if (ret)
414 goto fail_device;
415
7d3428cd
IM
416 dev->irq_enabled = true;
417
77145f1c
BS
418 /* workaround an odd issue on nvc1 by disabling the device's
419 * nosnoop capability. hopefully won't cause issues until a
420 * better fix is found - assuming there is one...
421 */
967e7bde 422 if (drm->device.info.chipset == 0xc1)
a01ca78c 423 nvif_mask(&drm->device.object, 0x00088080, 0x00000800, 0x00000000);
ebb945a9 424
77145f1c 425 nouveau_vga_init(drm);
cb75d97e 426
967e7bde 427 if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
be83cd4e 428 ret = nvkm_vm_new(nvxx_device(&drm->device), 0, (1ULL << 40),
1de68568 429 0x1000, NULL, &drm->client.vm);
ebb945a9
BS
430 if (ret)
431 goto fail_device;
3ee6f5b5 432
989aa5b7 433 nvxx_client(&drm->client.base)->vm = drm->client.vm;
ebb945a9
BS
434 }
435
436 ret = nouveau_ttm_init(drm);
94580299 437 if (ret)
77145f1c
BS
438 goto fail_ttm;
439
440 ret = nouveau_bios_init(dev);
441 if (ret)
442 goto fail_bios;
443
77145f1c 444 ret = nouveau_display_create(dev);
ebb945a9 445 if (ret)
77145f1c
BS
446 goto fail_dispctor;
447
448 if (dev->mode_config.num_crtc) {
449 ret = nouveau_display_init(dev);
450 if (ret)
451 goto fail_dispinit;
452 }
453
26fdd78c 454 nouveau_sysfs_init(dev);
b9ed919f 455 nouveau_hwmon_init(dev);
ebb945a9
BS
456 nouveau_accel_init(drm);
457 nouveau_fbcon_init(dev);
5addcf0a
DA
458
459 if (nouveau_runtime_pm != 0) {
460 pm_runtime_use_autosuspend(dev->dev);
461 pm_runtime_set_autosuspend_delay(dev->dev, 5000);
462 pm_runtime_set_active(dev->dev);
463 pm_runtime_allow(dev->dev);
464 pm_runtime_mark_last_busy(dev->dev);
465 pm_runtime_put(dev->dev);
466 }
94580299
BS
467 return 0;
468
77145f1c
BS
469fail_dispinit:
470 nouveau_display_destroy(dev);
471fail_dispctor:
77145f1c
BS
472 nouveau_bios_takedown(dev);
473fail_bios:
ebb945a9 474 nouveau_ttm_fini(drm);
77145f1c 475fail_ttm:
77145f1c 476 nouveau_vga_fini(drm);
94580299 477fail_device:
0ad72863 478 nvif_device_fini(&drm->device);
94580299
BS
479 nouveau_cli_destroy(&drm->client);
480 return ret;
481}
482
5b8a43ae 483static int
94580299
BS
484nouveau_drm_unload(struct drm_device *dev)
485{
77145f1c 486 struct nouveau_drm *drm = nouveau_drm(dev);
94580299 487
5addcf0a 488 pm_runtime_get_sync(dev->dev);
ebb945a9
BS
489 nouveau_fbcon_fini(dev);
490 nouveau_accel_fini(drm);
b9ed919f 491 nouveau_hwmon_fini(dev);
26fdd78c 492 nouveau_sysfs_fini(dev);
77145f1c 493
9430738d
BS
494 if (dev->mode_config.num_crtc)
495 nouveau_display_fini(dev);
77145f1c
BS
496 nouveau_display_destroy(dev);
497
77145f1c 498 nouveau_bios_takedown(dev);
94580299 499
ebb945a9 500 nouveau_ttm_fini(drm);
77145f1c 501 nouveau_vga_fini(drm);
cb75d97e 502
0ad72863 503 nvif_device_fini(&drm->device);
5addcf0a
DA
504 if (drm->hdmi_device)
505 pci_dev_put(drm->hdmi_device);
94580299
BS
506 nouveau_cli_destroy(&drm->client);
507 return 0;
508}
509
8ba9ff11
AC
510void
511nouveau_drm_device_remove(struct drm_device *dev)
94580299 512{
77145f1c 513 struct nouveau_drm *drm = nouveau_drm(dev);
be83cd4e 514 struct nvkm_client *client;
76ecea5b 515 struct nvkm_device *device;
77145f1c 516
7d3428cd 517 dev->irq_enabled = false;
989aa5b7 518 client = nvxx_client(&drm->client.base);
4e7e62d6 519 device = nvkm_device_find(client->device);
77145f1c
BS
520 drm_put_dev(dev);
521
e781dc8f 522 nvkm_device_del(&device);
94580299 523}
8ba9ff11
AC
524
525static void
526nouveau_drm_remove(struct pci_dev *pdev)
527{
528 struct drm_device *dev = pci_get_drvdata(pdev);
529
530 nouveau_drm_device_remove(dev);
531}
94580299 532
cd897837 533static int
05c63c2f 534nouveau_do_suspend(struct drm_device *dev, bool runtime)
94580299 535{
77145f1c 536 struct nouveau_drm *drm = nouveau_drm(dev);
94580299
BS
537 struct nouveau_cli *cli;
538 int ret;
539
6fbb702e
BS
540 if (dev->mode_config.num_crtc) {
541 NV_INFO(drm, "suspending console...\n");
542 nouveau_fbcon_set_suspend(dev, 1);
c52f4fa6 543 NV_INFO(drm, "suspending display...\n");
6fbb702e 544 ret = nouveau_display_suspend(dev, runtime);
9430738d
BS
545 if (ret)
546 return ret;
547 }
94580299 548
c52f4fa6 549 NV_INFO(drm, "evicting buffers...\n");
ebb945a9
BS
550 ttm_bo_evict_mm(&drm->ttm.bdev, TTM_PL_VRAM);
551
c52f4fa6 552 NV_INFO(drm, "waiting for kernel channels to go idle...\n");
81dff21b
BS
553 if (drm->cechan) {
554 ret = nouveau_channel_idle(drm->cechan);
555 if (ret)
f3980dc5 556 goto fail_display;
81dff21b
BS
557 }
558
559 if (drm->channel) {
560 ret = nouveau_channel_idle(drm->channel);
561 if (ret)
f3980dc5 562 goto fail_display;
81dff21b
BS
563 }
564
c52f4fa6 565 NV_INFO(drm, "suspending client object trees...\n");
ebb945a9 566 if (drm->fence && nouveau_fence(drm)->suspend) {
f3980dc5
IM
567 if (!nouveau_fence(drm)->suspend(drm)) {
568 ret = -ENOMEM;
569 goto fail_display;
570 }
ebb945a9
BS
571 }
572
94580299 573 list_for_each_entry(cli, &drm->clients, head) {
0ad72863 574 ret = nvif_client_suspend(&cli->base);
94580299
BS
575 if (ret)
576 goto fail_client;
577 }
578
c52f4fa6 579 NV_INFO(drm, "suspending kernel object tree...\n");
0ad72863 580 ret = nvif_client_suspend(&drm->client.base);
94580299
BS
581 if (ret)
582 goto fail_client;
583
94580299
BS
584 return 0;
585
586fail_client:
587 list_for_each_entry_continue_reverse(cli, &drm->clients, head) {
0ad72863 588 nvif_client_resume(&cli->base);
94580299
BS
589 }
590
f3980dc5
IM
591 if (drm->fence && nouveau_fence(drm)->resume)
592 nouveau_fence(drm)->resume(drm);
593
594fail_display:
9430738d 595 if (dev->mode_config.num_crtc) {
c52f4fa6 596 NV_INFO(drm, "resuming display...\n");
6fbb702e 597 nouveau_display_resume(dev, runtime);
9430738d 598 }
94580299
BS
599 return ret;
600}
601
cd897837 602static int
6fbb702e 603nouveau_do_resume(struct drm_device *dev, bool runtime)
2d8b9ccb
DA
604{
605 struct nouveau_drm *drm = nouveau_drm(dev);
606 struct nouveau_cli *cli;
607
c52f4fa6 608 NV_INFO(drm, "resuming kernel object tree...\n");
0ad72863 609 nvif_client_resume(&drm->client.base);
94580299 610
c52f4fa6 611 NV_INFO(drm, "resuming client object trees...\n");
81dff21b
BS
612 if (drm->fence && nouveau_fence(drm)->resume)
613 nouveau_fence(drm)->resume(drm);
614
94580299 615 list_for_each_entry(cli, &drm->clients, head) {
0ad72863 616 nvif_client_resume(&cli->base);
94580299 617 }
cb75d97e 618
77145f1c 619 nouveau_run_vbios_init(dev);
77145f1c 620
9430738d 621 if (dev->mode_config.num_crtc) {
c52f4fa6 622 NV_INFO(drm, "resuming display...\n");
6fbb702e
BS
623 nouveau_display_resume(dev, runtime);
624 NV_INFO(drm, "resuming console...\n");
625 nouveau_fbcon_set_suspend(dev, 0);
9430738d 626 }
5addcf0a 627
77145f1c 628 return 0;
94580299
BS
629}
630
7bb6d442
BS
631int
632nouveau_pmops_suspend(struct device *dev)
633{
634 struct pci_dev *pdev = to_pci_dev(dev);
635 struct drm_device *drm_dev = pci_get_drvdata(pdev);
636 int ret;
637
638 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF ||
639 drm_dev->switch_power_state == DRM_SWITCH_POWER_DYNAMIC_OFF)
640 return 0;
641
642 ret = nouveau_do_suspend(drm_dev, false);
643 if (ret)
644 return ret;
645
646 pci_save_state(pdev);
647 pci_disable_device(pdev);
7bb6d442 648 pci_set_power_state(pdev, PCI_D3hot);
c5fd936e 649 udelay(200);
7bb6d442
BS
650 return 0;
651}
652
653int
654nouveau_pmops_resume(struct device *dev)
2d8b9ccb
DA
655{
656 struct pci_dev *pdev = to_pci_dev(dev);
657 struct drm_device *drm_dev = pci_get_drvdata(pdev);
658 int ret;
659
5addcf0a
DA
660 if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF ||
661 drm_dev->switch_power_state == DRM_SWITCH_POWER_DYNAMIC_OFF)
2d8b9ccb
DA
662 return 0;
663
664 pci_set_power_state(pdev, PCI_D0);
665 pci_restore_state(pdev);
666 ret = pci_enable_device(pdev);
667 if (ret)
668 return ret;
669 pci_set_master(pdev);
670
6fbb702e 671 return nouveau_do_resume(drm_dev, false);
2d8b9ccb
DA
672}
673
7bb6d442
BS
674static int
675nouveau_pmops_freeze(struct device *dev)
2d8b9ccb
DA
676{
677 struct pci_dev *pdev = to_pci_dev(dev);
678 struct drm_device *drm_dev = pci_get_drvdata(pdev);
6fbb702e 679 return nouveau_do_suspend(drm_dev, false);
2d8b9ccb
DA
680}
681
7bb6d442
BS
682static int
683nouveau_pmops_thaw(struct device *dev)
2d8b9ccb
DA
684{
685 struct pci_dev *pdev = to_pci_dev(dev);
686 struct drm_device *drm_dev = pci_get_drvdata(pdev);
6fbb702e 687 return nouveau_do_resume(drm_dev, false);
2d8b9ccb
DA
688}
689
7bb6d442
BS
690static int
691nouveau_pmops_runtime_suspend(struct device *dev)
692{
693 struct pci_dev *pdev = to_pci_dev(dev);
694 struct drm_device *drm_dev = pci_get_drvdata(pdev);
695 int ret;
696
697 if (nouveau_runtime_pm == 0) {
698 pm_runtime_forbid(dev);
699 return -EBUSY;
700 }
701
702 /* are we optimus enabled? */
703 if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_is_v1_dsm()) {
704 DRM_DEBUG_DRIVER("failing to power off - not optimus\n");
705 pm_runtime_forbid(dev);
706 return -EBUSY;
707 }
708
7bb6d442
BS
709 drm_kms_helper_poll_disable(drm_dev);
710 vga_switcheroo_set_dynamic_switch(pdev, VGA_SWITCHEROO_OFF);
711 nouveau_switcheroo_optimus_dsm();
712 ret = nouveau_do_suspend(drm_dev, true);
713 pci_save_state(pdev);
714 pci_disable_device(pdev);
8c863944 715 pci_ignore_hotplug(pdev);
7bb6d442
BS
716 pci_set_power_state(pdev, PCI_D3cold);
717 drm_dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF;
718 return ret;
719}
720
721static int
722nouveau_pmops_runtime_resume(struct device *dev)
723{
724 struct pci_dev *pdev = to_pci_dev(dev);
725 struct drm_device *drm_dev = pci_get_drvdata(pdev);
726 struct nvif_device *device = &nouveau_drm(drm_dev)->device;
727 int ret;
728
729 if (nouveau_runtime_pm == 0)
730 return -EINVAL;
731
732 pci_set_power_state(pdev, PCI_D0);
733 pci_restore_state(pdev);
734 ret = pci_enable_device(pdev);
735 if (ret)
736 return ret;
737 pci_set_master(pdev);
738
739 ret = nouveau_do_resume(drm_dev, true);
740 drm_kms_helper_poll_enable(drm_dev);
741 /* do magic */
a01ca78c 742 nvif_mask(&device->object, 0x088488, (1 << 25), (1 << 25));
7bb6d442
BS
743 vga_switcheroo_set_dynamic_switch(pdev, VGA_SWITCHEROO_ON);
744 drm_dev->switch_power_state = DRM_SWITCH_POWER_ON;
7bb6d442
BS
745 return ret;
746}
747
748static int
749nouveau_pmops_runtime_idle(struct device *dev)
750{
751 struct pci_dev *pdev = to_pci_dev(dev);
752 struct drm_device *drm_dev = pci_get_drvdata(pdev);
753 struct nouveau_drm *drm = nouveau_drm(drm_dev);
754 struct drm_crtc *crtc;
755
756 if (nouveau_runtime_pm == 0) {
757 pm_runtime_forbid(dev);
758 return -EBUSY;
759 }
760
761 /* are we optimus enabled? */
762 if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_is_v1_dsm()) {
763 DRM_DEBUG_DRIVER("failing to power off - not optimus\n");
764 pm_runtime_forbid(dev);
765 return -EBUSY;
766 }
767
768 /* if we have a hdmi audio device - make sure it has a driver loaded */
769 if (drm->hdmi_device) {
770 if (!drm->hdmi_device->driver) {
771 DRM_DEBUG_DRIVER("failing to power off - no HDMI audio driver loaded\n");
772 pm_runtime_mark_last_busy(dev);
773 return -EBUSY;
774 }
775 }
776
777 list_for_each_entry(crtc, &drm->dev->mode_config.crtc_list, head) {
778 if (crtc->enabled) {
779 DRM_DEBUG_DRIVER("failing to power off - crtc active\n");
780 return -EBUSY;
781 }
782 }
783 pm_runtime_mark_last_busy(dev);
784 pm_runtime_autosuspend(dev);
785 /* we don't want the main rpm_idle to call suspend - we want to autosuspend */
786 return 1;
787}
2d8b9ccb 788
5b8a43ae 789static int
ebb945a9
BS
790nouveau_drm_open(struct drm_device *dev, struct drm_file *fpriv)
791{
ebb945a9
BS
792 struct nouveau_drm *drm = nouveau_drm(dev);
793 struct nouveau_cli *cli;
a2896ced 794 char name[32], tmpname[TASK_COMM_LEN];
ebb945a9
BS
795 int ret;
796
5addcf0a
DA
797 /* need to bring up power immediately if opening device */
798 ret = pm_runtime_get_sync(dev->dev);
b6c4285a 799 if (ret < 0 && ret != -EACCES)
5addcf0a
DA
800 return ret;
801
a2896ced
MS
802 get_task_comm(tmpname, current);
803 snprintf(name, sizeof(name), "%s[%d]", tmpname, pid_nr(fpriv->pid));
fa6df8c1 804
9ad97ede 805 ret = nouveau_cli_create(dev, name, sizeof(*cli), (void **)&cli);
420b9469 806
ebb945a9 807 if (ret)
5addcf0a 808 goto out_suspend;
ebb945a9 809
0ad72863
BS
810 cli->base.super = false;
811
967e7bde 812 if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
be83cd4e 813 ret = nvkm_vm_new(nvxx_device(&drm->device), 0, (1ULL << 40),
1de68568 814 0x1000, NULL, &cli->vm);
ebb945a9
BS
815 if (ret) {
816 nouveau_cli_destroy(cli);
5addcf0a 817 goto out_suspend;
ebb945a9 818 }
3ee6f5b5 819
989aa5b7 820 nvxx_client(&cli->base)->vm = cli->vm;
ebb945a9
BS
821 }
822
823 fpriv->driver_priv = cli;
824
825 mutex_lock(&drm->client.mutex);
826 list_add(&cli->head, &drm->clients);
827 mutex_unlock(&drm->client.mutex);
5addcf0a
DA
828
829out_suspend:
830 pm_runtime_mark_last_busy(dev->dev);
831 pm_runtime_put_autosuspend(dev->dev);
832
833 return ret;
ebb945a9
BS
834}
835
5b8a43ae 836static void
ebb945a9
BS
837nouveau_drm_preclose(struct drm_device *dev, struct drm_file *fpriv)
838{
839 struct nouveau_cli *cli = nouveau_cli(fpriv);
840 struct nouveau_drm *drm = nouveau_drm(dev);
841
5addcf0a
DA
842 pm_runtime_get_sync(dev->dev);
843
ac8c7930 844 mutex_lock(&cli->mutex);
ebb945a9
BS
845 if (cli->abi16)
846 nouveau_abi16_fini(cli->abi16);
ac8c7930 847 mutex_unlock(&cli->mutex);
ebb945a9
BS
848
849 mutex_lock(&drm->client.mutex);
850 list_del(&cli->head);
851 mutex_unlock(&drm->client.mutex);
5addcf0a 852
ebb945a9
BS
853}
854
5b8a43ae 855static void
ebb945a9
BS
856nouveau_drm_postclose(struct drm_device *dev, struct drm_file *fpriv)
857{
858 struct nouveau_cli *cli = nouveau_cli(fpriv);
859 nouveau_cli_destroy(cli);
5addcf0a
DA
860 pm_runtime_mark_last_busy(dev->dev);
861 pm_runtime_put_autosuspend(dev->dev);
ebb945a9
BS
862}
863
baa70943 864static const struct drm_ioctl_desc
77145f1c 865nouveau_ioctls[] = {
f8c47144
DV
866 DRM_IOCTL_DEF_DRV(NOUVEAU_GETPARAM, nouveau_abi16_ioctl_getparam, DRM_AUTH|DRM_RENDER_ALLOW),
867 DRM_IOCTL_DEF_DRV(NOUVEAU_SETPARAM, nouveau_abi16_ioctl_setparam, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
868 DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_ALLOC, nouveau_abi16_ioctl_channel_alloc, DRM_AUTH|DRM_RENDER_ALLOW),
869 DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_FREE, nouveau_abi16_ioctl_channel_free, DRM_AUTH|DRM_RENDER_ALLOW),
870 DRM_IOCTL_DEF_DRV(NOUVEAU_GROBJ_ALLOC, nouveau_abi16_ioctl_grobj_alloc, DRM_AUTH|DRM_RENDER_ALLOW),
871 DRM_IOCTL_DEF_DRV(NOUVEAU_NOTIFIEROBJ_ALLOC, nouveau_abi16_ioctl_notifierobj_alloc, DRM_AUTH|DRM_RENDER_ALLOW),
872 DRM_IOCTL_DEF_DRV(NOUVEAU_GPUOBJ_FREE, nouveau_abi16_ioctl_gpuobj_free, DRM_AUTH|DRM_RENDER_ALLOW),
873 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_NEW, nouveau_gem_ioctl_new, DRM_AUTH|DRM_RENDER_ALLOW),
874 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_PUSHBUF, nouveau_gem_ioctl_pushbuf, DRM_AUTH|DRM_RENDER_ALLOW),
875 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_PREP, nouveau_gem_ioctl_cpu_prep, DRM_AUTH|DRM_RENDER_ALLOW),
876 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_FINI, nouveau_gem_ioctl_cpu_fini, DRM_AUTH|DRM_RENDER_ALLOW),
877 DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_INFO, nouveau_gem_ioctl_info, DRM_AUTH|DRM_RENDER_ALLOW),
77145f1c
BS
878};
879
27111a23
BS
880long
881nouveau_drm_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
5addcf0a 882{
27111a23
BS
883 struct drm_file *filp = file->private_data;
884 struct drm_device *dev = filp->minor->dev;
5addcf0a 885 long ret;
5addcf0a
DA
886
887 ret = pm_runtime_get_sync(dev->dev);
b6c4285a 888 if (ret < 0 && ret != -EACCES)
5addcf0a
DA
889 return ret;
890
27111a23
BS
891 switch (_IOC_NR(cmd) - DRM_COMMAND_BASE) {
892 case DRM_NOUVEAU_NVIF:
893 ret = usif_ioctl(filp, (void __user *)arg, _IOC_SIZE(cmd));
894 break;
895 default:
896 ret = drm_ioctl(file, cmd, arg);
897 break;
898 }
5addcf0a
DA
899
900 pm_runtime_mark_last_busy(dev->dev);
901 pm_runtime_put_autosuspend(dev->dev);
902 return ret;
903}
27111a23 904
77145f1c
BS
905static const struct file_operations
906nouveau_driver_fops = {
907 .owner = THIS_MODULE,
908 .open = drm_open,
909 .release = drm_release,
5addcf0a 910 .unlocked_ioctl = nouveau_drm_ioctl,
77145f1c
BS
911 .mmap = nouveau_ttm_mmap,
912 .poll = drm_poll,
77145f1c
BS
913 .read = drm_read,
914#if defined(CONFIG_COMPAT)
915 .compat_ioctl = nouveau_compat_ioctl,
916#endif
917 .llseek = noop_llseek,
918};
919
920static struct drm_driver
915b4d11 921driver_stub = {
77145f1c 922 .driver_features =
0e975980
PA
923 DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME | DRIVER_RENDER |
924 DRIVER_KMS_LEGACY_CONTEXT,
77145f1c
BS
925
926 .load = nouveau_drm_load,
927 .unload = nouveau_drm_unload,
928 .open = nouveau_drm_open,
929 .preclose = nouveau_drm_preclose,
930 .postclose = nouveau_drm_postclose,
931 .lastclose = nouveau_vga_lastclose,
932
33b903e8
MS
933#if defined(CONFIG_DEBUG_FS)
934 .debugfs_init = nouveau_debugfs_init,
935 .debugfs_cleanup = nouveau_debugfs_takedown,
936#endif
937
b44f8408 938 .get_vblank_counter = drm_vblank_no_hw_counter,
51cb4b39
BS
939 .enable_vblank = nouveau_display_vblank_enable,
940 .disable_vblank = nouveau_display_vblank_disable,
d83ef853
BS
941 .get_scanout_position = nouveau_display_scanoutpos,
942 .get_vblank_timestamp = nouveau_display_vblstamp,
77145f1c
BS
943
944 .ioctls = nouveau_ioctls,
baa70943 945 .num_ioctls = ARRAY_SIZE(nouveau_ioctls),
77145f1c
BS
946 .fops = &nouveau_driver_fops,
947
948 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
949 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
ab9ccb96
AP
950 .gem_prime_export = drm_gem_prime_export,
951 .gem_prime_import = drm_gem_prime_import,
952 .gem_prime_pin = nouveau_gem_prime_pin,
3aac4502 953 .gem_prime_res_obj = nouveau_gem_prime_res_obj,
1af7c7dd 954 .gem_prime_unpin = nouveau_gem_prime_unpin,
ab9ccb96
AP
955 .gem_prime_get_sg_table = nouveau_gem_prime_get_sg_table,
956 .gem_prime_import_sg_table = nouveau_gem_prime_import_sg_table,
957 .gem_prime_vmap = nouveau_gem_prime_vmap,
958 .gem_prime_vunmap = nouveau_gem_prime_vunmap,
77145f1c 959
77145f1c
BS
960 .gem_free_object = nouveau_gem_object_del,
961 .gem_open_object = nouveau_gem_object_open,
962 .gem_close_object = nouveau_gem_object_close,
963
964 .dumb_create = nouveau_display_dumb_create,
965 .dumb_map_offset = nouveau_display_dumb_map_offset,
43387b37 966 .dumb_destroy = drm_gem_dumb_destroy,
77145f1c
BS
967
968 .name = DRIVER_NAME,
969 .desc = DRIVER_DESC,
970#ifdef GIT_REVISION
971 .date = GIT_REVISION,
972#else
973 .date = DRIVER_DATE,
974#endif
975 .major = DRIVER_MAJOR,
976 .minor = DRIVER_MINOR,
977 .patchlevel = DRIVER_PATCHLEVEL,
978};
979
94580299
BS
980static struct pci_device_id
981nouveau_drm_pci_table[] = {
982 {
983 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID),
984 .class = PCI_BASE_CLASS_DISPLAY << 16,
985 .class_mask = 0xff << 16,
986 },
987 {
988 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA_SGS, PCI_ANY_ID),
989 .class = PCI_BASE_CLASS_DISPLAY << 16,
990 .class_mask = 0xff << 16,
991 },
992 {}
993};
994
703fa264
PM
995static void nouveau_display_options(void)
996{
997 DRM_DEBUG_DRIVER("Loading Nouveau with parameters:\n");
998
999 DRM_DEBUG_DRIVER("... tv_disable : %d\n", nouveau_tv_disable);
1000 DRM_DEBUG_DRIVER("... ignorelid : %d\n", nouveau_ignorelid);
1001 DRM_DEBUG_DRIVER("... duallink : %d\n", nouveau_duallink);
1002 DRM_DEBUG_DRIVER("... nofbaccel : %d\n", nouveau_nofbaccel);
1003 DRM_DEBUG_DRIVER("... config : %s\n", nouveau_config);
1004 DRM_DEBUG_DRIVER("... debug : %s\n", nouveau_debug);
1005 DRM_DEBUG_DRIVER("... noaccel : %d\n", nouveau_noaccel);
1006 DRM_DEBUG_DRIVER("... modeset : %d\n", nouveau_modeset);
1007 DRM_DEBUG_DRIVER("... runpm : %d\n", nouveau_runtime_pm);
1008 DRM_DEBUG_DRIVER("... vram_pushbuf : %d\n", nouveau_vram_pushbuf);
1009 DRM_DEBUG_DRIVER("... pstate : %d\n", nouveau_pstate);
1010}
1011
2d8b9ccb
DA
1012static const struct dev_pm_ops nouveau_pm_ops = {
1013 .suspend = nouveau_pmops_suspend,
1014 .resume = nouveau_pmops_resume,
1015 .freeze = nouveau_pmops_freeze,
1016 .thaw = nouveau_pmops_thaw,
1017 .poweroff = nouveau_pmops_freeze,
1018 .restore = nouveau_pmops_resume,
5addcf0a
DA
1019 .runtime_suspend = nouveau_pmops_runtime_suspend,
1020 .runtime_resume = nouveau_pmops_runtime_resume,
1021 .runtime_idle = nouveau_pmops_runtime_idle,
2d8b9ccb
DA
1022};
1023
94580299
BS
1024static struct pci_driver
1025nouveau_drm_pci_driver = {
1026 .name = "nouveau",
1027 .id_table = nouveau_drm_pci_table,
1028 .probe = nouveau_drm_probe,
1029 .remove = nouveau_drm_remove,
2d8b9ccb 1030 .driver.pm = &nouveau_pm_ops,
94580299
BS
1031};
1032
8ba9ff11 1033struct drm_device *
e396ecd1
AC
1034nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
1035 struct platform_device *pdev,
47b2505e 1036 struct nvkm_device **pdevice)
420b9469 1037{
8ba9ff11
AC
1038 struct drm_device *drm;
1039 int err;
420b9469 1040
e396ecd1 1041 err = nvkm_device_tegra_new(func, pdev, nouveau_config, nouveau_debug,
7974dd1b 1042 true, true, ~0ULL, pdevice);
8ba9ff11 1043 if (err)
e781dc8f 1044 goto err_free;
8ba9ff11 1045
915b4d11 1046 drm = drm_dev_alloc(&driver_platform, &pdev->dev);
8ba9ff11
AC
1047 if (!drm) {
1048 err = -ENOMEM;
1049 goto err_free;
420b9469
AC
1050 }
1051
8ba9ff11
AC
1052 drm->platformdev = pdev;
1053 platform_set_drvdata(pdev, drm);
1054
1055 return drm;
1056
1057err_free:
e781dc8f 1058 nvkm_device_del(pdevice);
8ba9ff11
AC
1059
1060 return ERR_PTR(err);
420b9469
AC
1061}
1062
94580299
BS
1063static int __init
1064nouveau_drm_init(void)
1065{
915b4d11
DH
1066 driver_pci = driver_stub;
1067 driver_pci.set_busid = drm_pci_set_busid;
1068 driver_platform = driver_stub;
1069 driver_platform.set_busid = drm_platform_set_busid;
1070
703fa264
PM
1071 nouveau_display_options();
1072
77145f1c
BS
1073 if (nouveau_modeset == -1) {
1074#ifdef CONFIG_VGA_CONSOLE
1075 if (vgacon_text_force())
1076 nouveau_modeset = 0;
77145f1c 1077#endif
77145f1c
BS
1078 }
1079
1080 if (!nouveau_modeset)
1081 return 0;
1082
055a65d5
AC
1083#ifdef CONFIG_NOUVEAU_PLATFORM_DRIVER
1084 platform_driver_register(&nouveau_platform_driver);
1085#endif
1086
77145f1c 1087 nouveau_register_dsm_handler();
915b4d11 1088 return drm_pci_init(&driver_pci, &nouveau_drm_pci_driver);
94580299
BS
1089}
1090
1091static void __exit
1092nouveau_drm_exit(void)
1093{
77145f1c
BS
1094 if (!nouveau_modeset)
1095 return;
1096
915b4d11 1097 drm_pci_exit(&driver_pci, &nouveau_drm_pci_driver);
77145f1c 1098 nouveau_unregister_dsm_handler();
055a65d5
AC
1099
1100#ifdef CONFIG_NOUVEAU_PLATFORM_DRIVER
1101 platform_driver_unregister(&nouveau_platform_driver);
1102#endif
94580299
BS
1103}
1104
1105module_init(nouveau_drm_init);
1106module_exit(nouveau_drm_exit);
1107
1108MODULE_DEVICE_TABLE(pci, nouveau_drm_pci_table);
77145f1c
BS
1109MODULE_AUTHOR(DRIVER_AUTHOR);
1110MODULE_DESCRIPTION(DRIVER_DESC);
94580299 1111MODULE_LICENSE("GPL and additional rights");