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