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