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