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