Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +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 | */ |
| 23 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 24 | #include <core/object.h> |
| 25 | #include <core/client.h> |
| 26 | #include <core/device.h> |
| 27 | #include <core/class.h> |
| 28 | #include <core/mm.h> |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 29 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 30 | #include <subdev/fb.h> |
| 31 | #include <subdev/timer.h> |
| 32 | #include <subdev/instmem.h> |
Christoph Bumiller | 7e22e71 | 2013-03-27 22:16:54 +0100 | [diff] [blame] | 33 | #include <engine/graph.h> |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 34 | |
| 35 | #include "nouveau_drm.h" |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 36 | #include "nouveau_dma.h" |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 37 | #include "nouveau_gem.h" |
| 38 | #include "nouveau_chan.h" |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 39 | #include "nouveau_abi16.h" |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 40 | |
| 41 | struct nouveau_abi16 * |
| 42 | nouveau_abi16_get(struct drm_file *file_priv, struct drm_device *dev) |
| 43 | { |
| 44 | struct nouveau_cli *cli = nouveau_cli(file_priv); |
| 45 | mutex_lock(&cli->mutex); |
| 46 | if (!cli->abi16) { |
| 47 | struct nouveau_abi16 *abi16; |
| 48 | cli->abi16 = abi16 = kzalloc(sizeof(*abi16), GFP_KERNEL); |
| 49 | if (cli->abi16) { |
| 50 | INIT_LIST_HEAD(&abi16->channels); |
| 51 | abi16->client = nv_object(cli); |
| 52 | |
| 53 | /* allocate device object targeting client's default |
| 54 | * device (ie. the one that belongs to the fd it |
| 55 | * opened) |
| 56 | */ |
| 57 | if (nouveau_object_new(abi16->client, NVDRM_CLIENT, |
| 58 | NVDRM_DEVICE, 0x0080, |
| 59 | &(struct nv_device_class) { |
| 60 | .device = ~0ULL, |
| 61 | }, |
| 62 | sizeof(struct nv_device_class), |
| 63 | &abi16->device) == 0) |
| 64 | return cli->abi16; |
| 65 | |
| 66 | kfree(cli->abi16); |
| 67 | cli->abi16 = NULL; |
| 68 | } |
| 69 | |
| 70 | mutex_unlock(&cli->mutex); |
| 71 | } |
| 72 | return cli->abi16; |
| 73 | } |
| 74 | |
| 75 | int |
| 76 | nouveau_abi16_put(struct nouveau_abi16 *abi16, int ret) |
| 77 | { |
| 78 | struct nouveau_cli *cli = (void *)abi16->client; |
| 79 | mutex_unlock(&cli->mutex); |
| 80 | return ret; |
| 81 | } |
| 82 | |
| 83 | u16 |
| 84 | nouveau_abi16_swclass(struct nouveau_drm *drm) |
| 85 | { |
| 86 | switch (nv_device(drm->device)->card_type) { |
| 87 | case NV_04: |
| 88 | return 0x006e; |
| 89 | case NV_10: |
Ilia Mirkin | 4a0ff75 | 2013-09-05 04:45:02 -0400 | [diff] [blame] | 90 | case NV_11: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 91 | case NV_20: |
| 92 | case NV_30: |
| 93 | case NV_40: |
| 94 | return 0x016e; |
| 95 | case NV_50: |
| 96 | return 0x506e; |
| 97 | case NV_C0: |
| 98 | case NV_D0: |
| 99 | case NV_E0: |
| 100 | return 0x906e; |
| 101 | } |
| 102 | |
| 103 | return 0x0000; |
| 104 | } |
| 105 | |
| 106 | static void |
| 107 | nouveau_abi16_ntfy_fini(struct nouveau_abi16_chan *chan, |
| 108 | struct nouveau_abi16_ntfy *ntfy) |
| 109 | { |
| 110 | nouveau_mm_free(&chan->heap, &ntfy->node); |
| 111 | list_del(&ntfy->head); |
| 112 | kfree(ntfy); |
| 113 | } |
| 114 | |
| 115 | static void |
| 116 | nouveau_abi16_chan_fini(struct nouveau_abi16 *abi16, |
| 117 | struct nouveau_abi16_chan *chan) |
| 118 | { |
| 119 | struct nouveau_abi16_ntfy *ntfy, *temp; |
| 120 | |
Marcin Slusarz | 2b77c1c | 2013-03-03 18:58:45 +0100 | [diff] [blame] | 121 | /* wait for all activity to stop before releasing notify object, which |
| 122 | * may be still in use */ |
| 123 | if (chan->chan && chan->ntfy) |
| 124 | nouveau_channel_idle(chan->chan); |
| 125 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 126 | /* cleanup notifier state */ |
| 127 | list_for_each_entry_safe(ntfy, temp, &chan->notifiers, head) { |
| 128 | nouveau_abi16_ntfy_fini(chan, ntfy); |
| 129 | } |
| 130 | |
| 131 | if (chan->ntfy) { |
| 132 | nouveau_bo_vma_del(chan->ntfy, &chan->ntfy_vma); |
Maarten Lankhorst | 198c14a0 | 2013-06-27 13:38:20 +0200 | [diff] [blame] | 133 | nouveau_bo_unpin(chan->ntfy); |
David Herrmann | 55fb74a | 2013-10-02 10:15:17 +0200 | [diff] [blame] | 134 | drm_gem_object_unreference_unlocked(&chan->ntfy->gem); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | if (chan->heap.block_size) |
| 138 | nouveau_mm_fini(&chan->heap); |
| 139 | |
| 140 | /* destroy channel object, all children will be killed too */ |
| 141 | if (chan->chan) { |
| 142 | abi16->handles &= ~(1 << (chan->chan->handle & 0xffff)); |
| 143 | nouveau_channel_del(&chan->chan); |
| 144 | } |
| 145 | |
| 146 | list_del(&chan->head); |
| 147 | kfree(chan); |
| 148 | } |
| 149 | |
| 150 | void |
| 151 | nouveau_abi16_fini(struct nouveau_abi16 *abi16) |
| 152 | { |
| 153 | struct nouveau_cli *cli = (void *)abi16->client; |
| 154 | struct nouveau_abi16_chan *chan, *temp; |
| 155 | |
| 156 | /* cleanup channels */ |
| 157 | list_for_each_entry_safe(chan, temp, &abi16->channels, head) { |
| 158 | nouveau_abi16_chan_fini(abi16, chan); |
| 159 | } |
| 160 | |
| 161 | /* destroy the device object */ |
| 162 | nouveau_object_del(abi16->client, NVDRM_CLIENT, NVDRM_DEVICE); |
| 163 | |
| 164 | kfree(cli->abi16); |
| 165 | cli->abi16 = NULL; |
| 166 | } |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 167 | |
| 168 | int |
| 169 | nouveau_abi16_ioctl_getparam(ABI16_IOCTL_ARGS) |
| 170 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 171 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 172 | struct nouveau_device *device = nv_device(drm->device); |
| 173 | struct nouveau_timer *ptimer = nouveau_timer(device); |
Christoph Bumiller | 7e22e71 | 2013-03-27 22:16:54 +0100 | [diff] [blame] | 174 | struct nouveau_graph *graph = (void *)nouveau_engine(device, NVDEV_ENGINE_GR); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 175 | struct drm_nouveau_getparam *getparam = data; |
| 176 | |
| 177 | switch (getparam->param) { |
| 178 | case NOUVEAU_GETPARAM_CHIPSET_ID: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 179 | getparam->value = device->chipset; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 180 | break; |
| 181 | case NOUVEAU_GETPARAM_PCI_VENDOR: |
Ville Syrjälä | ffbab09b | 2013-10-04 14:53:40 +0300 | [diff] [blame] | 182 | getparam->value = dev->pdev->vendor; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 183 | break; |
| 184 | case NOUVEAU_GETPARAM_PCI_DEVICE: |
Ville Syrjälä | ffbab09b | 2013-10-04 14:53:40 +0300 | [diff] [blame] | 185 | getparam->value = dev->pdev->device; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 186 | break; |
| 187 | case NOUVEAU_GETPARAM_BUS_TYPE: |
| 188 | if (drm_pci_device_is_agp(dev)) |
| 189 | getparam->value = 0; |
| 190 | else |
| 191 | if (!pci_is_pcie(dev->pdev)) |
| 192 | getparam->value = 1; |
| 193 | else |
| 194 | getparam->value = 2; |
| 195 | break; |
| 196 | case NOUVEAU_GETPARAM_FB_SIZE: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 197 | getparam->value = drm->gem.vram_available; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 198 | break; |
| 199 | case NOUVEAU_GETPARAM_AGP_SIZE: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 200 | getparam->value = drm->gem.gart_available; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 201 | break; |
| 202 | case NOUVEAU_GETPARAM_VM_VRAM_BASE: |
| 203 | getparam->value = 0; /* deprecated */ |
| 204 | break; |
| 205 | case NOUVEAU_GETPARAM_PTIMER_TIME: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 206 | getparam->value = ptimer->read(ptimer); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 207 | break; |
| 208 | case NOUVEAU_GETPARAM_HAS_BO_USAGE: |
| 209 | getparam->value = 1; |
| 210 | break; |
| 211 | case NOUVEAU_GETPARAM_HAS_PAGEFLIP: |
| 212 | getparam->value = 1; |
| 213 | break; |
| 214 | case NOUVEAU_GETPARAM_GRAPH_UNITS: |
Christoph Bumiller | 7e22e71 | 2013-03-27 22:16:54 +0100 | [diff] [blame] | 215 | getparam->value = graph->units ? graph->units(graph) : 0; |
| 216 | break; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 217 | default: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 218 | nv_debug(device, "unknown parameter %lld\n", getparam->param); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 219 | return -EINVAL; |
| 220 | } |
| 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | int |
| 226 | nouveau_abi16_ioctl_setparam(ABI16_IOCTL_ARGS) |
| 227 | { |
| 228 | return -EINVAL; |
| 229 | } |
| 230 | |
| 231 | int |
| 232 | nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS) |
| 233 | { |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 234 | struct drm_nouveau_channel_alloc *init = data; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 235 | struct nouveau_cli *cli = nouveau_cli(file_priv); |
| 236 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 237 | struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev); |
| 238 | struct nouveau_abi16_chan *chan; |
| 239 | struct nouveau_client *client; |
| 240 | struct nouveau_device *device; |
| 241 | struct nouveau_instmem *imem; |
| 242 | struct nouveau_fb *pfb; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 243 | int ret; |
| 244 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 245 | if (unlikely(!abi16)) |
| 246 | return -ENOMEM; |
Marcin Slusarz | bf7e438 | 2012-11-11 20:00:09 +0100 | [diff] [blame] | 247 | |
| 248 | if (!drm->channel) |
| 249 | return nouveau_abi16_put(abi16, -ENODEV); |
| 250 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 251 | client = nv_client(abi16->client); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 252 | device = nv_device(abi16->device); |
| 253 | imem = nouveau_instmem(device); |
| 254 | pfb = nouveau_fb(device); |
| 255 | |
Ben Skeggs | 4946980 | 2012-11-22 13:43:55 +1000 | [diff] [blame] | 256 | /* hack to allow channel engine type specification on kepler */ |
| 257 | if (device->card_type >= NV_E0) { |
| 258 | if (init->fb_ctxdma_handle != ~0) |
| 259 | init->fb_ctxdma_handle = NVE0_CHANNEL_IND_ENGINE_GR; |
| 260 | else |
| 261 | init->fb_ctxdma_handle = init->tt_ctxdma_handle; |
| 262 | |
| 263 | /* allow flips to be executed if this is a graphics channel */ |
| 264 | init->tt_ctxdma_handle = 0; |
| 265 | if (init->fb_ctxdma_handle == NVE0_CHANNEL_IND_ENGINE_GR) |
| 266 | init->tt_ctxdma_handle = 1; |
| 267 | } |
| 268 | |
| 269 | if (init->fb_ctxdma_handle == ~0 || init->tt_ctxdma_handle == ~0) |
| 270 | return nouveau_abi16_put(abi16, -EINVAL); |
| 271 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 272 | /* allocate "abi16 channel" data and make up a handle for it */ |
| 273 | init->channel = ffsll(~abi16->handles); |
| 274 | if (!init->channel--) |
| 275 | return nouveau_abi16_put(abi16, -ENOSPC); |
| 276 | |
| 277 | chan = kzalloc(sizeof(*chan), GFP_KERNEL); |
| 278 | if (!chan) |
| 279 | return nouveau_abi16_put(abi16, -ENOMEM); |
| 280 | |
| 281 | INIT_LIST_HEAD(&chan->notifiers); |
| 282 | list_add(&chan->head, &abi16->channels); |
| 283 | abi16->handles |= (1 << init->channel); |
| 284 | |
| 285 | /* create channel object and initialise dma and fence management */ |
| 286 | ret = nouveau_channel_new(drm, cli, NVDRM_DEVICE, NVDRM_CHAN | |
| 287 | init->channel, init->fb_ctxdma_handle, |
| 288 | init->tt_ctxdma_handle, &chan->chan); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 289 | if (ret) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 290 | goto done; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 291 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 292 | if (device->card_type >= NV_50) |
| 293 | init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM | |
| 294 | NOUVEAU_GEM_DOMAIN_GART; |
| 295 | else |
| 296 | if (chan->chan->push.buffer->bo.mem.mem_type == TTM_PL_VRAM) |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 297 | init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 298 | else |
| 299 | init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_GART; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 300 | |
Ben Skeggs | 69a6146 | 2013-11-13 10:58:51 +1000 | [diff] [blame] | 301 | if (device->card_type < NV_10) { |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 302 | init->subchan[0].handle = 0x00000000; |
| 303 | init->subchan[0].grclass = 0x0000; |
| 304 | init->subchan[1].handle = NvSw; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 305 | init->subchan[1].grclass = 0x506e; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 306 | init->nr_subchan = 2; |
| 307 | } |
| 308 | |
| 309 | /* Named memory object area */ |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 310 | ret = nouveau_gem_new(dev, PAGE_SIZE, 0, NOUVEAU_GEM_DOMAIN_GART, |
| 311 | 0, 0, &chan->ntfy); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 312 | if (ret == 0) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 313 | ret = nouveau_bo_pin(chan->ntfy, TTM_PL_FLAG_TT); |
| 314 | if (ret) |
| 315 | goto done; |
| 316 | |
| 317 | if (device->card_type >= NV_50) { |
| 318 | ret = nouveau_bo_vma_add(chan->ntfy, client->vm, |
| 319 | &chan->ntfy_vma); |
| 320 | if (ret) |
| 321 | goto done; |
| 322 | } |
| 323 | |
David Herrmann | 55fb74a | 2013-10-02 10:15:17 +0200 | [diff] [blame] | 324 | ret = drm_gem_handle_create(file_priv, &chan->ntfy->gem, |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 325 | &init->notifier_handle); |
| 326 | if (ret) |
| 327 | goto done; |
| 328 | |
| 329 | ret = nouveau_mm_init(&chan->heap, 0, PAGE_SIZE, 1); |
| 330 | done: |
| 331 | if (ret) |
| 332 | nouveau_abi16_chan_fini(abi16, chan); |
| 333 | return nouveau_abi16_put(abi16, ret); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 334 | } |
| 335 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 336 | |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 337 | int |
| 338 | nouveau_abi16_ioctl_channel_free(ABI16_IOCTL_ARGS) |
| 339 | { |
| 340 | struct drm_nouveau_channel_free *req = data; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 341 | struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev); |
| 342 | struct nouveau_abi16_chan *chan; |
| 343 | int ret = -ENOENT; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 344 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 345 | if (unlikely(!abi16)) |
| 346 | return -ENOMEM; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 347 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 348 | list_for_each_entry(chan, &abi16->channels, head) { |
| 349 | if (chan->chan->handle == (NVDRM_CHAN | req->channel)) { |
| 350 | nouveau_abi16_chan_fini(abi16, chan); |
| 351 | return nouveau_abi16_put(abi16, 0); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | return nouveau_abi16_put(abi16, ret); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | int |
| 359 | nouveau_abi16_ioctl_grobj_alloc(ABI16_IOCTL_ARGS) |
| 360 | { |
| 361 | struct drm_nouveau_grobj_alloc *init = data; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 362 | struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev); |
| 363 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 364 | struct nouveau_object *object; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 365 | int ret; |
| 366 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 367 | if (unlikely(!abi16)) |
| 368 | return -ENOMEM; |
| 369 | |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 370 | if (init->handle == ~0) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 371 | return nouveau_abi16_put(abi16, -EINVAL); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 372 | |
| 373 | /* compatibility with userspace that assumes 506e for all chipsets */ |
| 374 | if (init->class == 0x506e) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 375 | init->class = nouveau_abi16_swclass(drm); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 376 | if (init->class == 0x906e) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 377 | return nouveau_abi16_put(abi16, 0); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 378 | } |
| 379 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 380 | ret = nouveau_object_new(abi16->client, NVDRM_CHAN | init->channel, |
| 381 | init->handle, init->class, NULL, 0, &object); |
| 382 | return nouveau_abi16_put(abi16, ret); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | int |
| 386 | nouveau_abi16_ioctl_notifierobj_alloc(ABI16_IOCTL_ARGS) |
| 387 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 388 | struct drm_nouveau_notifierobj_alloc *info = data; |
| 389 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 390 | struct nouveau_device *device = nv_device(drm->device); |
| 391 | struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev); |
Maarten Lankhorst | b43decd | 2013-03-24 15:36:38 +0100 | [diff] [blame] | 392 | struct nouveau_abi16_chan *chan = NULL, *temp; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 393 | struct nouveau_abi16_ntfy *ntfy; |
| 394 | struct nouveau_object *object; |
Ben Skeggs | f756944 | 2012-10-08 14:29:16 +1000 | [diff] [blame] | 395 | struct nv_dma_class args = {}; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 396 | int ret; |
| 397 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 398 | if (unlikely(!abi16)) |
| 399 | return -ENOMEM; |
| 400 | |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 401 | /* completely unnecessary for these chipsets... */ |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 402 | if (unlikely(nv_device(abi16->device)->card_type >= NV_C0)) |
| 403 | return nouveau_abi16_put(abi16, -EINVAL); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 404 | |
Maarten Lankhorst | b43decd | 2013-03-24 15:36:38 +0100 | [diff] [blame] | 405 | list_for_each_entry(temp, &abi16->channels, head) { |
| 406 | if (temp->chan->handle == (NVDRM_CHAN | info->channel)) { |
| 407 | chan = temp; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 408 | break; |
Maarten Lankhorst | b43decd | 2013-03-24 15:36:38 +0100 | [diff] [blame] | 409 | } |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 410 | } |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 411 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 412 | if (!chan) |
| 413 | return nouveau_abi16_put(abi16, -ENOENT); |
| 414 | |
| 415 | ntfy = kzalloc(sizeof(*ntfy), GFP_KERNEL); |
| 416 | if (!ntfy) |
| 417 | return nouveau_abi16_put(abi16, -ENOMEM); |
| 418 | |
| 419 | list_add(&ntfy->head, &chan->notifiers); |
| 420 | ntfy->handle = info->handle; |
| 421 | |
| 422 | ret = nouveau_mm_head(&chan->heap, 1, info->size, info->size, 1, |
| 423 | &ntfy->node); |
| 424 | if (ret) |
| 425 | goto done; |
| 426 | |
| 427 | args.start = ntfy->node->offset; |
| 428 | args.limit = ntfy->node->offset + ntfy->node->length - 1; |
| 429 | if (device->card_type >= NV_50) { |
| 430 | args.flags = NV_DMA_TARGET_VM | NV_DMA_ACCESS_VM; |
| 431 | args.start += chan->ntfy_vma.offset; |
| 432 | args.limit += chan->ntfy_vma.offset; |
| 433 | } else |
| 434 | if (drm->agp.stat == ENABLED) { |
| 435 | args.flags = NV_DMA_TARGET_AGP | NV_DMA_ACCESS_RDWR; |
| 436 | args.start += drm->agp.base + chan->ntfy->bo.offset; |
| 437 | args.limit += drm->agp.base + chan->ntfy->bo.offset; |
| 438 | } else { |
| 439 | args.flags = NV_DMA_TARGET_VM | NV_DMA_ACCESS_RDWR; |
| 440 | args.start += chan->ntfy->bo.offset; |
| 441 | args.limit += chan->ntfy->bo.offset; |
| 442 | } |
| 443 | |
| 444 | ret = nouveau_object_new(abi16->client, chan->chan->handle, |
| 445 | ntfy->handle, 0x003d, &args, |
| 446 | sizeof(args), &object); |
| 447 | if (ret) |
| 448 | goto done; |
| 449 | |
Bob Gleitsmann | c1ccaa6 | 2014-01-06 08:59:07 +1000 | [diff] [blame] | 450 | info->offset = ntfy->node->offset; |
| 451 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 452 | done: |
| 453 | if (ret) |
| 454 | nouveau_abi16_ntfy_fini(chan, ntfy); |
| 455 | return nouveau_abi16_put(abi16, ret); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | int |
| 459 | nouveau_abi16_ioctl_gpuobj_free(ABI16_IOCTL_ARGS) |
| 460 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 461 | struct drm_nouveau_gpuobj_free *fini = data; |
| 462 | struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev); |
Maarten Lankhorst | b43decd | 2013-03-24 15:36:38 +0100 | [diff] [blame] | 463 | struct nouveau_abi16_chan *chan = NULL, *temp; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 464 | struct nouveau_abi16_ntfy *ntfy; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 465 | int ret; |
| 466 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 467 | if (unlikely(!abi16)) |
| 468 | return -ENOMEM; |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 469 | |
Maarten Lankhorst | b43decd | 2013-03-24 15:36:38 +0100 | [diff] [blame] | 470 | list_for_each_entry(temp, &abi16->channels, head) { |
| 471 | if (temp->chan->handle == (NVDRM_CHAN | fini->channel)) { |
| 472 | chan = temp; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 473 | break; |
Maarten Lankhorst | b43decd | 2013-03-24 15:36:38 +0100 | [diff] [blame] | 474 | } |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 475 | } |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 476 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 477 | if (!chan) |
| 478 | return nouveau_abi16_put(abi16, -ENOENT); |
| 479 | |
| 480 | /* synchronize with the user channel and destroy the gpu object */ |
| 481 | nouveau_channel_idle(chan->chan); |
| 482 | |
| 483 | ret = nouveau_object_del(abi16->client, chan->chan->handle, fini->handle); |
| 484 | if (ret) |
| 485 | return nouveau_abi16_put(abi16, ret); |
| 486 | |
| 487 | /* cleanup extra state if this object was a notifier */ |
| 488 | list_for_each_entry(ntfy, &chan->notifiers, head) { |
| 489 | if (ntfy->handle == fini->handle) { |
| 490 | nouveau_mm_free(&chan->heap, &ntfy->node); |
| 491 | list_del(&ntfy->head); |
| 492 | break; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | return nouveau_abi16_put(abi16, 0); |
Ben Skeggs | 2a259a3 | 2012-05-08 10:24:27 +1000 | [diff] [blame] | 497 | } |