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