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> |
| 28 | |
| 29 | #include <core/device.h> |
| 30 | #include <core/client.h> |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 31 | #include <core/gpuobj.h> |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 32 | #include <core/class.h> |
| 33 | |
| 34 | #include <subdev/device.h> |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 35 | #include <subdev/vm.h> |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 36 | |
| 37 | #include "nouveau_drm.h" |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 38 | #include "nouveau_irq.h" |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 39 | #include "nouveau_dma.h" |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 40 | #include "nouveau_ttm.h" |
| 41 | #include "nouveau_gem.h" |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 42 | #include "nouveau_agp.h" |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 43 | #include "nouveau_vga.h" |
| 44 | #include "nouveau_pm.h" |
| 45 | #include "nouveau_acpi.h" |
| 46 | #include "nouveau_bios.h" |
| 47 | #include "nouveau_ioctl.h" |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 48 | #include "nouveau_abi16.h" |
| 49 | #include "nouveau_fbcon.h" |
| 50 | #include "nouveau_fence.h" |
| 51 | |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 52 | MODULE_PARM_DESC(config, "option string to pass to driver core"); |
| 53 | static char *nouveau_config; |
| 54 | module_param_named(config, nouveau_config, charp, 0400); |
| 55 | |
| 56 | MODULE_PARM_DESC(debug, "debug string to pass to driver core"); |
| 57 | static char *nouveau_debug; |
| 58 | module_param_named(debug, nouveau_debug, charp, 0400); |
| 59 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 60 | MODULE_PARM_DESC(noaccel, "disable kernel/abi16 acceleration"); |
| 61 | static int nouveau_noaccel = 0; |
| 62 | module_param_named(noaccel, nouveau_noaccel, int, 0400); |
| 63 | |
Ben Skeggs | 9430738 | 2012-10-31 12:11:15 +1000 | [diff] [blame] | 64 | MODULE_PARM_DESC(modeset, "enable driver (default: auto, " |
| 65 | "0 = disabled, 1 = enabled, 2 = headless)"); |
| 66 | int nouveau_modeset = -1; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 67 | module_param_named(modeset, nouveau_modeset, int, 0400); |
| 68 | |
| 69 | static struct drm_driver driver; |
| 70 | |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 71 | static u64 |
| 72 | nouveau_name(struct pci_dev *pdev) |
| 73 | { |
| 74 | u64 name = (u64)pci_domain_nr(pdev->bus) << 32; |
| 75 | name |= pdev->bus->number << 16; |
| 76 | name |= PCI_SLOT(pdev->devfn) << 8; |
| 77 | return name | PCI_FUNC(pdev->devfn); |
| 78 | } |
| 79 | |
| 80 | static int |
Ben Skeggs | fa6df8c | 2012-09-12 13:09:23 +1000 | [diff] [blame] | 81 | nouveau_cli_create(struct pci_dev *pdev, const char *name, |
| 82 | int size, void **pcli) |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 83 | { |
| 84 | struct nouveau_cli *cli; |
| 85 | int ret; |
| 86 | |
Marcin Slusarz | dd5700e | 2012-12-10 21:59:52 +0100 | [diff] [blame] | 87 | *pcli = NULL; |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 88 | ret = nouveau_client_create_(name, nouveau_name(pdev), nouveau_config, |
| 89 | nouveau_debug, size, pcli); |
| 90 | cli = *pcli; |
Marcin Slusarz | dd5700e | 2012-12-10 21:59:52 +0100 | [diff] [blame] | 91 | if (ret) { |
| 92 | if (cli) |
| 93 | nouveau_client_destroy(&cli->base); |
| 94 | *pcli = NULL; |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 95 | return ret; |
Marcin Slusarz | dd5700e | 2012-12-10 21:59:52 +0100 | [diff] [blame] | 96 | } |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 97 | |
| 98 | mutex_init(&cli->mutex); |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | static void |
| 103 | nouveau_cli_destroy(struct nouveau_cli *cli) |
| 104 | { |
| 105 | struct nouveau_object *client = nv_object(cli); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 106 | nouveau_vm_ref(NULL, &cli->base.vm, NULL); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 107 | nouveau_client_fini(&cli->base, false); |
| 108 | atomic_set(&client->refcount, 1); |
| 109 | nouveau_object_ref(NULL, &client); |
| 110 | } |
| 111 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 112 | static void |
| 113 | nouveau_accel_fini(struct nouveau_drm *drm) |
| 114 | { |
| 115 | nouveau_gpuobj_ref(NULL, &drm->notify); |
| 116 | nouveau_channel_del(&drm->channel); |
Ben Skeggs | 4998104 | 2012-08-06 19:38:25 +1000 | [diff] [blame] | 117 | nouveau_channel_del(&drm->cechan); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 118 | if (drm->fence) |
| 119 | nouveau_fence(drm)->dtor(drm); |
| 120 | } |
| 121 | |
| 122 | static void |
| 123 | nouveau_accel_init(struct nouveau_drm *drm) |
| 124 | { |
| 125 | struct nouveau_device *device = nv_device(drm->device); |
| 126 | struct nouveau_object *object; |
Ben Skeggs | 4998104 | 2012-08-06 19:38:25 +1000 | [diff] [blame] | 127 | u32 arg0, arg1; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 128 | int ret; |
| 129 | |
| 130 | if (nouveau_noaccel) |
| 131 | return; |
| 132 | |
| 133 | /* initialise synchronisation routines */ |
| 134 | if (device->card_type < NV_10) ret = nv04_fence_create(drm); |
Maarten Lankhorst | ace5a9b | 2012-11-21 13:21:12 +0100 | [diff] [blame] | 135 | else if (device->card_type < NV_50) ret = nv10_fence_create(drm); |
| 136 | else if (device->chipset < 0x84) ret = nv50_fence_create(drm); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 137 | else if (device->card_type < NV_C0) ret = nv84_fence_create(drm); |
| 138 | else ret = nvc0_fence_create(drm); |
| 139 | if (ret) { |
| 140 | NV_ERROR(drm, "failed to initialise sync subsystem, %d\n", ret); |
| 141 | nouveau_accel_fini(drm); |
| 142 | return; |
| 143 | } |
| 144 | |
Ben Skeggs | 4998104 | 2012-08-06 19:38:25 +1000 | [diff] [blame] | 145 | if (device->card_type >= NV_E0) { |
| 146 | ret = nouveau_channel_new(drm, &drm->client, NVDRM_DEVICE, |
| 147 | NVDRM_CHAN + 1, |
| 148 | NVE0_CHANNEL_IND_ENGINE_CE0 | |
| 149 | NVE0_CHANNEL_IND_ENGINE_CE1, 0, |
| 150 | &drm->cechan); |
| 151 | if (ret) |
| 152 | NV_ERROR(drm, "failed to create ce channel, %d\n", ret); |
| 153 | |
| 154 | arg0 = NVE0_CHANNEL_IND_ENGINE_GR; |
Ben Skeggs | 4946980 | 2012-11-22 13:43:55 +1000 | [diff] [blame] | 155 | arg1 = 1; |
Ben Skeggs | 4998104 | 2012-08-06 19:38:25 +1000 | [diff] [blame] | 156 | } else { |
| 157 | arg0 = NvDmaFB; |
| 158 | arg1 = NvDmaTT; |
| 159 | } |
| 160 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 161 | ret = nouveau_channel_new(drm, &drm->client, NVDRM_DEVICE, NVDRM_CHAN, |
Ben Skeggs | 4998104 | 2012-08-06 19:38:25 +1000 | [diff] [blame] | 162 | arg0, arg1, &drm->channel); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 163 | if (ret) { |
| 164 | NV_ERROR(drm, "failed to create kernel channel, %d\n", ret); |
| 165 | nouveau_accel_fini(drm); |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | if (device->card_type < NV_C0) { |
| 170 | ret = nouveau_gpuobj_new(drm->device, NULL, 32, 0, 0, |
| 171 | &drm->notify); |
| 172 | if (ret) { |
| 173 | NV_ERROR(drm, "failed to allocate notifier, %d\n", ret); |
| 174 | nouveau_accel_fini(drm); |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | ret = nouveau_object_new(nv_object(drm), |
| 179 | drm->channel->handle, NvNotify0, |
| 180 | 0x003d, &(struct nv_dma_class) { |
| 181 | .flags = NV_DMA_TARGET_VRAM | |
| 182 | NV_DMA_ACCESS_RDWR, |
| 183 | .start = drm->notify->addr, |
| 184 | .limit = drm->notify->addr + 31 |
| 185 | }, sizeof(struct nv_dma_class), |
| 186 | &object); |
| 187 | if (ret) { |
| 188 | nouveau_accel_fini(drm); |
| 189 | return; |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | |
Ben Skeggs | 4998104 | 2012-08-06 19:38:25 +1000 | [diff] [blame] | 194 | nouveau_bo_move_init(drm); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 195 | } |
| 196 | |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 197 | static int nouveau_drm_probe(struct pci_dev *pdev, |
| 198 | const struct pci_device_id *pent) |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 199 | { |
| 200 | struct nouveau_device *device; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 201 | struct apertures_struct *aper; |
| 202 | bool boot = false; |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 203 | int ret; |
| 204 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 205 | /* remove conflicting drivers (vesafb, efifb etc) */ |
| 206 | aper = alloc_apertures(3); |
| 207 | if (!aper) |
| 208 | return -ENOMEM; |
| 209 | |
| 210 | aper->ranges[0].base = pci_resource_start(pdev, 1); |
| 211 | aper->ranges[0].size = pci_resource_len(pdev, 1); |
| 212 | aper->count = 1; |
| 213 | |
| 214 | if (pci_resource_len(pdev, 2)) { |
| 215 | aper->ranges[aper->count].base = pci_resource_start(pdev, 2); |
| 216 | aper->ranges[aper->count].size = pci_resource_len(pdev, 2); |
| 217 | aper->count++; |
| 218 | } |
| 219 | |
| 220 | if (pci_resource_len(pdev, 3)) { |
| 221 | aper->ranges[aper->count].base = pci_resource_start(pdev, 3); |
| 222 | aper->ranges[aper->count].size = pci_resource_len(pdev, 3); |
| 223 | aper->count++; |
| 224 | } |
| 225 | |
| 226 | #ifdef CONFIG_X86 |
| 227 | boot = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW; |
| 228 | #endif |
| 229 | remove_conflicting_framebuffers(aper, "nouveaufb", boot); |
Tommi Rantala | 83ef777 | 2012-11-09 09:19:40 +0000 | [diff] [blame] | 230 | kfree(aper); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 231 | |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 232 | ret = nouveau_device_create(pdev, nouveau_name(pdev), pci_name(pdev), |
| 233 | nouveau_config, nouveau_debug, &device); |
| 234 | if (ret) |
| 235 | return ret; |
| 236 | |
| 237 | pci_set_master(pdev); |
| 238 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 239 | ret = drm_get_pci_dev(pdev, pent, &driver); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 240 | if (ret) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 241 | nouveau_object_ref(NULL, (struct nouveau_object **)&device); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 242 | return ret; |
| 243 | } |
| 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
Marcin Slusarz | 5b8a43a | 2012-08-19 23:00:00 +0200 | [diff] [blame] | 248 | static int |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 249 | nouveau_drm_load(struct drm_device *dev, unsigned long flags) |
| 250 | { |
| 251 | struct pci_dev *pdev = dev->pdev; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 252 | struct nouveau_device *device; |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 253 | struct nouveau_drm *drm; |
| 254 | int ret; |
| 255 | |
Ben Skeggs | fa6df8c | 2012-09-12 13:09:23 +1000 | [diff] [blame] | 256 | ret = nouveau_cli_create(pdev, "DRM", sizeof(*drm), (void**)&drm); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 257 | if (ret) |
| 258 | return ret; |
| 259 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 260 | dev->dev_private = drm; |
| 261 | drm->dev = dev; |
| 262 | |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 263 | INIT_LIST_HEAD(&drm->clients); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 264 | spin_lock_init(&drm->tile.lock); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 265 | |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 266 | /* make sure AGP controller is in a consistent state before we |
| 267 | * (possibly) execute vbios init tables (see nouveau_agp.h) |
| 268 | */ |
| 269 | if (drm_pci_device_is_agp(dev) && dev->agp) { |
| 270 | /* dummy device object, doesn't init anything, but allows |
| 271 | * agp code access to registers |
| 272 | */ |
| 273 | ret = nouveau_object_new(nv_object(drm), NVDRM_CLIENT, |
| 274 | NVDRM_DEVICE, 0x0080, |
| 275 | &(struct nv_device_class) { |
| 276 | .device = ~0, |
| 277 | .disable = |
| 278 | ~(NV_DEVICE_DISABLE_MMIO | |
| 279 | NV_DEVICE_DISABLE_IDENTIFY), |
| 280 | .debug0 = ~0, |
| 281 | }, sizeof(struct nv_device_class), |
| 282 | &drm->device); |
| 283 | if (ret) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 284 | goto fail_device; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 285 | |
| 286 | nouveau_agp_reset(drm); |
| 287 | nouveau_object_del(nv_object(drm), NVDRM_CLIENT, NVDRM_DEVICE); |
| 288 | } |
| 289 | |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 290 | ret = nouveau_object_new(nv_object(drm), NVDRM_CLIENT, NVDRM_DEVICE, |
| 291 | 0x0080, &(struct nv_device_class) { |
| 292 | .device = ~0, |
| 293 | .disable = 0, |
| 294 | .debug0 = 0, |
| 295 | }, sizeof(struct nv_device_class), |
| 296 | &drm->device); |
| 297 | if (ret) |
| 298 | goto fail_device; |
| 299 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 300 | /* workaround an odd issue on nvc1 by disabling the device's |
| 301 | * nosnoop capability. hopefully won't cause issues until a |
| 302 | * better fix is found - assuming there is one... |
| 303 | */ |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 304 | device = nv_device(drm->device); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 305 | if (nv_device(drm->device)->chipset == 0xc1) |
| 306 | nv_mask(device, 0x00088080, 0x00000800, 0x00000000); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 307 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 308 | nouveau_vga_init(drm); |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 309 | nouveau_agp_init(drm); |
| 310 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 311 | if (device->card_type >= NV_50) { |
| 312 | ret = nouveau_vm_new(nv_device(drm->device), 0, (1ULL << 40), |
| 313 | 0x1000, &drm->client.base.vm); |
| 314 | if (ret) |
| 315 | goto fail_device; |
| 316 | } |
| 317 | |
| 318 | ret = nouveau_ttm_init(drm); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 319 | if (ret) |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 320 | goto fail_ttm; |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 321 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 322 | ret = nouveau_bios_init(dev); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 323 | if (ret) |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 324 | goto fail_bios; |
| 325 | |
| 326 | ret = nouveau_irq_init(dev); |
| 327 | if (ret) |
| 328 | goto fail_irq; |
| 329 | |
| 330 | ret = nouveau_display_create(dev); |
| 331 | if (ret) |
| 332 | goto fail_dispctor; |
| 333 | |
| 334 | if (dev->mode_config.num_crtc) { |
| 335 | ret = nouveau_display_init(dev); |
| 336 | if (ret) |
| 337 | goto fail_dispinit; |
| 338 | } |
| 339 | |
| 340 | nouveau_pm_init(dev); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 341 | |
| 342 | nouveau_accel_init(drm); |
| 343 | nouveau_fbcon_init(dev); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 344 | return 0; |
| 345 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 346 | fail_dispinit: |
| 347 | nouveau_display_destroy(dev); |
| 348 | fail_dispctor: |
| 349 | nouveau_irq_fini(dev); |
| 350 | fail_irq: |
| 351 | nouveau_bios_takedown(dev); |
| 352 | fail_bios: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 353 | nouveau_ttm_fini(drm); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 354 | fail_ttm: |
| 355 | nouveau_agp_fini(drm); |
| 356 | nouveau_vga_fini(drm); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 357 | fail_device: |
| 358 | nouveau_cli_destroy(&drm->client); |
| 359 | return ret; |
| 360 | } |
| 361 | |
Marcin Slusarz | 5b8a43a | 2012-08-19 23:00:00 +0200 | [diff] [blame] | 362 | static int |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 363 | nouveau_drm_unload(struct drm_device *dev) |
| 364 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 365 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 366 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 367 | nouveau_fbcon_fini(dev); |
| 368 | nouveau_accel_fini(drm); |
| 369 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 370 | nouveau_pm_fini(dev); |
| 371 | |
Ben Skeggs | 9430738 | 2012-10-31 12:11:15 +1000 | [diff] [blame] | 372 | if (dev->mode_config.num_crtc) |
| 373 | nouveau_display_fini(dev); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 374 | nouveau_display_destroy(dev); |
| 375 | |
| 376 | nouveau_irq_fini(dev); |
| 377 | nouveau_bios_takedown(dev); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 378 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 379 | nouveau_ttm_fini(drm); |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 380 | nouveau_agp_fini(drm); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 381 | nouveau_vga_fini(drm); |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 382 | |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 383 | nouveau_cli_destroy(&drm->client); |
| 384 | return 0; |
| 385 | } |
| 386 | |
| 387 | static void |
| 388 | nouveau_drm_remove(struct pci_dev *pdev) |
| 389 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 390 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 391 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 392 | struct nouveau_object *device; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 393 | |
| 394 | device = drm->client.base.device; |
| 395 | drm_put_dev(dev); |
| 396 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 397 | nouveau_object_ref(NULL, &device); |
| 398 | nouveau_object_debug(); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | int |
Dave Airlie | 2d8b9cc | 2012-11-02 11:04:28 +1000 | [diff] [blame] | 402 | nouveau_do_suspend(struct drm_device *dev) |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 403 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 404 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 405 | struct nouveau_cli *cli; |
| 406 | int ret; |
| 407 | |
Ben Skeggs | 9430738 | 2012-10-31 12:11:15 +1000 | [diff] [blame] | 408 | if (dev->mode_config.num_crtc) { |
| 409 | NV_INFO(drm, "suspending fbcon...\n"); |
| 410 | nouveau_fbcon_set_suspend(dev, 1); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 411 | |
Ben Skeggs | 9430738 | 2012-10-31 12:11:15 +1000 | [diff] [blame] | 412 | NV_INFO(drm, "suspending display...\n"); |
| 413 | ret = nouveau_display_suspend(dev); |
| 414 | if (ret) |
| 415 | return ret; |
| 416 | } |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 417 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 418 | NV_INFO(drm, "evicting buffers...\n"); |
| 419 | ttm_bo_evict_mm(&drm->ttm.bdev, TTM_PL_VRAM); |
| 420 | |
| 421 | if (drm->fence && nouveau_fence(drm)->suspend) { |
| 422 | if (!nouveau_fence(drm)->suspend(drm)) |
| 423 | return -ENOMEM; |
| 424 | } |
| 425 | |
| 426 | NV_INFO(drm, "suspending client object trees...\n"); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 427 | list_for_each_entry(cli, &drm->clients, head) { |
| 428 | ret = nouveau_client_fini(&cli->base, true); |
| 429 | if (ret) |
| 430 | goto fail_client; |
| 431 | } |
| 432 | |
| 433 | ret = nouveau_client_fini(&drm->client.base, true); |
| 434 | if (ret) |
| 435 | goto fail_client; |
| 436 | |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 437 | nouveau_agp_fini(drm); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 438 | return 0; |
| 439 | |
| 440 | fail_client: |
| 441 | list_for_each_entry_continue_reverse(cli, &drm->clients, head) { |
| 442 | nouveau_client_init(&cli->base); |
| 443 | } |
| 444 | |
Ben Skeggs | 9430738 | 2012-10-31 12:11:15 +1000 | [diff] [blame] | 445 | if (dev->mode_config.num_crtc) { |
| 446 | NV_INFO(drm, "resuming display...\n"); |
| 447 | nouveau_display_resume(dev); |
| 448 | } |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 449 | return ret; |
| 450 | } |
| 451 | |
Dave Airlie | 2d8b9cc | 2012-11-02 11:04:28 +1000 | [diff] [blame] | 452 | int nouveau_pmops_suspend(struct device *dev) |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 453 | { |
Dave Airlie | 2d8b9cc | 2012-11-02 11:04:28 +1000 | [diff] [blame] | 454 | struct pci_dev *pdev = to_pci_dev(dev); |
| 455 | struct drm_device *drm_dev = pci_get_drvdata(pdev); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 456 | int ret; |
| 457 | |
Dave Airlie | 2d8b9cc | 2012-11-02 11:04:28 +1000 | [diff] [blame] | 458 | if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF) |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 459 | return 0; |
| 460 | |
Dave Airlie | 2d8b9cc | 2012-11-02 11:04:28 +1000 | [diff] [blame] | 461 | ret = nouveau_do_suspend(drm_dev); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 462 | if (ret) |
| 463 | return ret; |
Dave Airlie | 2d8b9cc | 2012-11-02 11:04:28 +1000 | [diff] [blame] | 464 | |
| 465 | pci_save_state(pdev); |
| 466 | pci_disable_device(pdev); |
| 467 | pci_set_power_state(pdev, PCI_D3hot); |
| 468 | |
| 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | int |
| 473 | nouveau_do_resume(struct drm_device *dev) |
| 474 | { |
| 475 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 476 | struct nouveau_cli *cli; |
| 477 | |
| 478 | NV_INFO(drm, "re-enabling device...\n"); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 479 | |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 480 | nouveau_agp_reset(drm); |
| 481 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 482 | NV_INFO(drm, "resuming client object trees...\n"); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 483 | nouveau_client_init(&drm->client.base); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 484 | nouveau_agp_init(drm); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 485 | |
| 486 | list_for_each_entry(cli, &drm->clients, head) { |
| 487 | nouveau_client_init(&cli->base); |
| 488 | } |
| 489 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 490 | if (drm->fence && nouveau_fence(drm)->resume) |
| 491 | nouveau_fence(drm)->resume(drm); |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 492 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 493 | nouveau_run_vbios_init(dev); |
| 494 | nouveau_irq_postinstall(dev); |
| 495 | nouveau_pm_resume(dev); |
| 496 | |
Ben Skeggs | 9430738 | 2012-10-31 12:11:15 +1000 | [diff] [blame] | 497 | if (dev->mode_config.num_crtc) { |
| 498 | NV_INFO(drm, "resuming display...\n"); |
| 499 | nouveau_display_resume(dev); |
| 500 | } |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 501 | return 0; |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 502 | } |
| 503 | |
Dave Airlie | 2d8b9cc | 2012-11-02 11:04:28 +1000 | [diff] [blame] | 504 | int nouveau_pmops_resume(struct device *dev) |
| 505 | { |
| 506 | struct pci_dev *pdev = to_pci_dev(dev); |
| 507 | struct drm_device *drm_dev = pci_get_drvdata(pdev); |
| 508 | int ret; |
| 509 | |
| 510 | if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF) |
| 511 | return 0; |
| 512 | |
| 513 | pci_set_power_state(pdev, PCI_D0); |
| 514 | pci_restore_state(pdev); |
| 515 | ret = pci_enable_device(pdev); |
| 516 | if (ret) |
| 517 | return ret; |
| 518 | pci_set_master(pdev); |
| 519 | |
| 520 | return nouveau_do_resume(drm_dev); |
| 521 | } |
| 522 | |
| 523 | static int nouveau_pmops_freeze(struct device *dev) |
| 524 | { |
| 525 | struct pci_dev *pdev = to_pci_dev(dev); |
| 526 | struct drm_device *drm_dev = pci_get_drvdata(pdev); |
| 527 | |
| 528 | return nouveau_do_suspend(drm_dev); |
| 529 | } |
| 530 | |
| 531 | static int nouveau_pmops_thaw(struct device *dev) |
| 532 | { |
| 533 | struct pci_dev *pdev = to_pci_dev(dev); |
| 534 | struct drm_device *drm_dev = pci_get_drvdata(pdev); |
| 535 | |
| 536 | return nouveau_do_resume(drm_dev); |
| 537 | } |
| 538 | |
| 539 | |
Marcin Slusarz | 5b8a43a | 2012-08-19 23:00:00 +0200 | [diff] [blame] | 540 | static int |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 541 | nouveau_drm_open(struct drm_device *dev, struct drm_file *fpriv) |
| 542 | { |
| 543 | struct pci_dev *pdev = dev->pdev; |
| 544 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 545 | struct nouveau_cli *cli; |
Ben Skeggs | fa6df8c | 2012-09-12 13:09:23 +1000 | [diff] [blame] | 546 | char name[16]; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 547 | int ret; |
| 548 | |
Linus Torvalds | 612a9aa | 2012-10-03 23:29:23 -0700 | [diff] [blame] | 549 | snprintf(name, sizeof(name), "%d", pid_nr(fpriv->pid)); |
Ben Skeggs | fa6df8c | 2012-09-12 13:09:23 +1000 | [diff] [blame] | 550 | |
| 551 | ret = nouveau_cli_create(pdev, name, sizeof(*cli), (void **)&cli); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 552 | if (ret) |
| 553 | return ret; |
| 554 | |
| 555 | if (nv_device(drm->device)->card_type >= NV_50) { |
| 556 | ret = nouveau_vm_new(nv_device(drm->device), 0, (1ULL << 40), |
| 557 | 0x1000, &cli->base.vm); |
| 558 | if (ret) { |
| 559 | nouveau_cli_destroy(cli); |
| 560 | return ret; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | fpriv->driver_priv = cli; |
| 565 | |
| 566 | mutex_lock(&drm->client.mutex); |
| 567 | list_add(&cli->head, &drm->clients); |
| 568 | mutex_unlock(&drm->client.mutex); |
| 569 | return 0; |
| 570 | } |
| 571 | |
Marcin Slusarz | 5b8a43a | 2012-08-19 23:00:00 +0200 | [diff] [blame] | 572 | static void |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 573 | nouveau_drm_preclose(struct drm_device *dev, struct drm_file *fpriv) |
| 574 | { |
| 575 | struct nouveau_cli *cli = nouveau_cli(fpriv); |
| 576 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 577 | |
| 578 | if (cli->abi16) |
| 579 | nouveau_abi16_fini(cli->abi16); |
| 580 | |
| 581 | mutex_lock(&drm->client.mutex); |
| 582 | list_del(&cli->head); |
| 583 | mutex_unlock(&drm->client.mutex); |
| 584 | } |
| 585 | |
Marcin Slusarz | 5b8a43a | 2012-08-19 23:00:00 +0200 | [diff] [blame] | 586 | static void |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 587 | nouveau_drm_postclose(struct drm_device *dev, struct drm_file *fpriv) |
| 588 | { |
| 589 | struct nouveau_cli *cli = nouveau_cli(fpriv); |
| 590 | nouveau_cli_destroy(cli); |
| 591 | } |
| 592 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 593 | static struct drm_ioctl_desc |
| 594 | nouveau_ioctls[] = { |
| 595 | DRM_IOCTL_DEF_DRV(NOUVEAU_GETPARAM, nouveau_abi16_ioctl_getparam, DRM_UNLOCKED|DRM_AUTH), |
| 596 | DRM_IOCTL_DEF_DRV(NOUVEAU_SETPARAM, nouveau_abi16_ioctl_setparam, DRM_UNLOCKED|DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), |
| 597 | DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_ALLOC, nouveau_abi16_ioctl_channel_alloc, DRM_UNLOCKED|DRM_AUTH), |
| 598 | DRM_IOCTL_DEF_DRV(NOUVEAU_CHANNEL_FREE, nouveau_abi16_ioctl_channel_free, DRM_UNLOCKED|DRM_AUTH), |
| 599 | DRM_IOCTL_DEF_DRV(NOUVEAU_GROBJ_ALLOC, nouveau_abi16_ioctl_grobj_alloc, DRM_UNLOCKED|DRM_AUTH), |
| 600 | DRM_IOCTL_DEF_DRV(NOUVEAU_NOTIFIEROBJ_ALLOC, nouveau_abi16_ioctl_notifierobj_alloc, DRM_UNLOCKED|DRM_AUTH), |
| 601 | DRM_IOCTL_DEF_DRV(NOUVEAU_GPUOBJ_FREE, nouveau_abi16_ioctl_gpuobj_free, DRM_UNLOCKED|DRM_AUTH), |
| 602 | DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_NEW, nouveau_gem_ioctl_new, DRM_UNLOCKED|DRM_AUTH), |
| 603 | DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_PUSHBUF, nouveau_gem_ioctl_pushbuf, DRM_UNLOCKED|DRM_AUTH), |
| 604 | DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_PREP, nouveau_gem_ioctl_cpu_prep, DRM_UNLOCKED|DRM_AUTH), |
| 605 | DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_CPU_FINI, nouveau_gem_ioctl_cpu_fini, DRM_UNLOCKED|DRM_AUTH), |
| 606 | DRM_IOCTL_DEF_DRV(NOUVEAU_GEM_INFO, nouveau_gem_ioctl_info, DRM_UNLOCKED|DRM_AUTH), |
| 607 | }; |
| 608 | |
| 609 | static const struct file_operations |
| 610 | nouveau_driver_fops = { |
| 611 | .owner = THIS_MODULE, |
| 612 | .open = drm_open, |
| 613 | .release = drm_release, |
| 614 | .unlocked_ioctl = drm_ioctl, |
| 615 | .mmap = nouveau_ttm_mmap, |
| 616 | .poll = drm_poll, |
| 617 | .fasync = drm_fasync, |
| 618 | .read = drm_read, |
| 619 | #if defined(CONFIG_COMPAT) |
| 620 | .compat_ioctl = nouveau_compat_ioctl, |
| 621 | #endif |
| 622 | .llseek = noop_llseek, |
| 623 | }; |
| 624 | |
| 625 | static struct drm_driver |
| 626 | driver = { |
| 627 | .driver_features = |
| 628 | DRIVER_USE_AGP | DRIVER_PCI_DMA | DRIVER_SG | |
| 629 | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | |
| 630 | DRIVER_MODESET | DRIVER_PRIME, |
| 631 | |
| 632 | .load = nouveau_drm_load, |
| 633 | .unload = nouveau_drm_unload, |
| 634 | .open = nouveau_drm_open, |
| 635 | .preclose = nouveau_drm_preclose, |
| 636 | .postclose = nouveau_drm_postclose, |
| 637 | .lastclose = nouveau_vga_lastclose, |
| 638 | |
| 639 | .irq_preinstall = nouveau_irq_preinstall, |
| 640 | .irq_postinstall = nouveau_irq_postinstall, |
| 641 | .irq_uninstall = nouveau_irq_uninstall, |
| 642 | .irq_handler = nouveau_irq_handler, |
| 643 | |
| 644 | .get_vblank_counter = drm_vblank_count, |
| 645 | .enable_vblank = nouveau_vblank_enable, |
| 646 | .disable_vblank = nouveau_vblank_disable, |
| 647 | |
| 648 | .ioctls = nouveau_ioctls, |
| 649 | .fops = &nouveau_driver_fops, |
| 650 | |
| 651 | .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
| 652 | .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
| 653 | .gem_prime_export = nouveau_gem_prime_export, |
| 654 | .gem_prime_import = nouveau_gem_prime_import, |
| 655 | |
| 656 | .gem_init_object = nouveau_gem_object_new, |
| 657 | .gem_free_object = nouveau_gem_object_del, |
| 658 | .gem_open_object = nouveau_gem_object_open, |
| 659 | .gem_close_object = nouveau_gem_object_close, |
| 660 | |
| 661 | .dumb_create = nouveau_display_dumb_create, |
| 662 | .dumb_map_offset = nouveau_display_dumb_map_offset, |
| 663 | .dumb_destroy = nouveau_display_dumb_destroy, |
| 664 | |
| 665 | .name = DRIVER_NAME, |
| 666 | .desc = DRIVER_DESC, |
| 667 | #ifdef GIT_REVISION |
| 668 | .date = GIT_REVISION, |
| 669 | #else |
| 670 | .date = DRIVER_DATE, |
| 671 | #endif |
| 672 | .major = DRIVER_MAJOR, |
| 673 | .minor = DRIVER_MINOR, |
| 674 | .patchlevel = DRIVER_PATCHLEVEL, |
| 675 | }; |
| 676 | |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 677 | static struct pci_device_id |
| 678 | nouveau_drm_pci_table[] = { |
| 679 | { |
| 680 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID), |
| 681 | .class = PCI_BASE_CLASS_DISPLAY << 16, |
| 682 | .class_mask = 0xff << 16, |
| 683 | }, |
| 684 | { |
| 685 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA_SGS, PCI_ANY_ID), |
| 686 | .class = PCI_BASE_CLASS_DISPLAY << 16, |
| 687 | .class_mask = 0xff << 16, |
| 688 | }, |
| 689 | {} |
| 690 | }; |
| 691 | |
Dave Airlie | 2d8b9cc | 2012-11-02 11:04:28 +1000 | [diff] [blame] | 692 | static const struct dev_pm_ops nouveau_pm_ops = { |
| 693 | .suspend = nouveau_pmops_suspend, |
| 694 | .resume = nouveau_pmops_resume, |
| 695 | .freeze = nouveau_pmops_freeze, |
| 696 | .thaw = nouveau_pmops_thaw, |
| 697 | .poweroff = nouveau_pmops_freeze, |
| 698 | .restore = nouveau_pmops_resume, |
| 699 | }; |
| 700 | |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 701 | static struct pci_driver |
| 702 | nouveau_drm_pci_driver = { |
| 703 | .name = "nouveau", |
| 704 | .id_table = nouveau_drm_pci_table, |
| 705 | .probe = nouveau_drm_probe, |
| 706 | .remove = nouveau_drm_remove, |
Dave Airlie | 2d8b9cc | 2012-11-02 11:04:28 +1000 | [diff] [blame] | 707 | .driver.pm = &nouveau_pm_ops, |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 708 | }; |
| 709 | |
| 710 | static int __init |
| 711 | nouveau_drm_init(void) |
| 712 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 713 | driver.num_ioctls = ARRAY_SIZE(nouveau_ioctls); |
| 714 | |
| 715 | if (nouveau_modeset == -1) { |
| 716 | #ifdef CONFIG_VGA_CONSOLE |
| 717 | if (vgacon_text_force()) |
| 718 | nouveau_modeset = 0; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 719 | #endif |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | if (!nouveau_modeset) |
| 723 | return 0; |
| 724 | |
| 725 | nouveau_register_dsm_handler(); |
| 726 | return drm_pci_init(&driver, &nouveau_drm_pci_driver); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | static void __exit |
| 730 | nouveau_drm_exit(void) |
| 731 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 732 | if (!nouveau_modeset) |
| 733 | return; |
| 734 | |
| 735 | drm_pci_exit(&driver, &nouveau_drm_pci_driver); |
| 736 | nouveau_unregister_dsm_handler(); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | module_init(nouveau_drm_init); |
| 740 | module_exit(nouveau_drm_exit); |
| 741 | |
| 742 | MODULE_DEVICE_TABLE(pci, nouveau_drm_pci_table); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 743 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 744 | MODULE_DESCRIPTION(DRIVER_DESC); |
Ben Skeggs | 9458029 | 2012-07-06 12:14:00 +1000 | [diff] [blame] | 745 | MODULE_LICENSE("GPL and additional rights"); |