Ben Skeggs | 292da61 | 2011-12-09 16:11:06 +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 | |
Rob Clark | c09dcbc | 2014-09-28 14:19:14 -0400 | [diff] [blame] | 25 | #ifdef HAVE_CONFIG_H |
| 26 | # include <config.h> |
| 27 | #endif |
| 28 | |
Ben Skeggs | 292da61 | 2011-12-09 16:11:06 +1000 | [diff] [blame] | 29 | #include <stdlib.h> |
| 30 | #include <stdint.h> |
Ben Skeggs | c41b494 | 2012-11-23 12:40:30 +1000 | [diff] [blame] | 31 | #include <stddef.h> |
Ben Skeggs | 292da61 | 2011-12-09 16:11:06 +1000 | [diff] [blame] | 32 | |
| 33 | #include "private.h" |
| 34 | |
Ben Skeggs | c41b494 | 2012-11-23 12:40:30 +1000 | [diff] [blame] | 35 | |
Emil Velikov | 76e9799 | 2015-03-23 21:52:00 +0000 | [diff] [blame] | 36 | drm_private int |
Ben Skeggs | 292da61 | 2011-12-09 16:11:06 +1000 | [diff] [blame] | 37 | abi16_chan_nv04(struct nouveau_object *obj) |
| 38 | { |
| 39 | struct nouveau_device *dev = (struct nouveau_device *)obj->parent; |
Ben Skeggs | 292da61 | 2011-12-09 16:11:06 +1000 | [diff] [blame] | 40 | struct nv04_fifo *nv04 = obj->data; |
Marcin Slusarz | 9e0026d | 2012-06-09 20:56:37 +0200 | [diff] [blame] | 41 | struct drm_nouveau_channel_alloc req = {nv04->vram, nv04->gart}; |
Ben Skeggs | 292da61 | 2011-12-09 16:11:06 +1000 | [diff] [blame] | 42 | int ret; |
| 43 | |
Ben Skeggs | 292da61 | 2011-12-09 16:11:06 +1000 | [diff] [blame] | 44 | ret = drmCommandWriteRead(dev->fd, DRM_NOUVEAU_CHANNEL_ALLOC, |
| 45 | &req, sizeof(req)); |
| 46 | if (ret) |
| 47 | return ret; |
| 48 | |
| 49 | nv04->base.channel = req.channel; |
| 50 | nv04->base.pushbuf = req.pushbuf_domains; |
| 51 | nv04->notify = req.notifier_handle; |
| 52 | nv04->base.object->handle = req.channel; |
| 53 | nv04->base.object->length = sizeof(*nv04); |
| 54 | return 0; |
| 55 | } |
| 56 | |
Emil Velikov | 76e9799 | 2015-03-23 21:52:00 +0000 | [diff] [blame] | 57 | drm_private int |
Ben Skeggs | 292da61 | 2011-12-09 16:11:06 +1000 | [diff] [blame] | 58 | abi16_chan_nvc0(struct nouveau_object *obj) |
| 59 | { |
| 60 | struct nouveau_device *dev = (struct nouveau_device *)obj->parent; |
Ben Skeggs | 73b9a28 | 2012-04-17 08:35:43 +1000 | [diff] [blame] | 61 | struct drm_nouveau_channel_alloc req = {}; |
Ben Skeggs | 292da61 | 2011-12-09 16:11:06 +1000 | [diff] [blame] | 62 | struct nvc0_fifo *nvc0 = obj->data; |
| 63 | int ret; |
| 64 | |
| 65 | ret = drmCommandWriteRead(dev->fd, DRM_NOUVEAU_CHANNEL_ALLOC, |
| 66 | &req, sizeof(req)); |
| 67 | if (ret) |
| 68 | return ret; |
| 69 | |
| 70 | nvc0->base.channel = req.channel; |
| 71 | nvc0->base.pushbuf = req.pushbuf_domains; |
Christoph Bumiller | 754655c | 2012-04-19 20:03:39 +0200 | [diff] [blame] | 72 | nvc0->notify = req.notifier_handle; |
Ben Skeggs | 292da61 | 2011-12-09 16:11:06 +1000 | [diff] [blame] | 73 | nvc0->base.object->handle = req.channel; |
| 74 | nvc0->base.object->length = sizeof(*nvc0); |
| 75 | return 0; |
| 76 | } |
| 77 | |
Emil Velikov | 76e9799 | 2015-03-23 21:52:00 +0000 | [diff] [blame] | 78 | drm_private int |
Ben Skeggs | c41b494 | 2012-11-23 12:40:30 +1000 | [diff] [blame] | 79 | abi16_chan_nve0(struct nouveau_object *obj) |
| 80 | { |
| 81 | struct nouveau_device *dev = (struct nouveau_device *)obj->parent; |
| 82 | struct drm_nouveau_channel_alloc req = {}; |
| 83 | struct nve0_fifo *nve0 = obj->data; |
| 84 | int ret; |
| 85 | |
| 86 | if (obj->length > offsetof(struct nve0_fifo, engine)) { |
| 87 | req.fb_ctxdma_handle = 0xffffffff; |
| 88 | req.tt_ctxdma_handle = nve0->engine; |
| 89 | } |
| 90 | |
| 91 | ret = drmCommandWriteRead(dev->fd, DRM_NOUVEAU_CHANNEL_ALLOC, |
| 92 | &req, sizeof(req)); |
| 93 | if (ret) |
| 94 | return ret; |
| 95 | |
| 96 | nve0->base.channel = req.channel; |
| 97 | nve0->base.pushbuf = req.pushbuf_domains; |
| 98 | nve0->notify = req.notifier_handle; |
| 99 | nve0->base.object->handle = req.channel; |
| 100 | nve0->base.object->length = sizeof(*nve0); |
| 101 | return 0; |
| 102 | } |
| 103 | |
Emil Velikov | 76e9799 | 2015-03-23 21:52:00 +0000 | [diff] [blame] | 104 | drm_private int |
Ben Skeggs | 292da61 | 2011-12-09 16:11:06 +1000 | [diff] [blame] | 105 | abi16_engobj(struct nouveau_object *obj) |
| 106 | { |
| 107 | struct drm_nouveau_grobj_alloc req = { |
| 108 | obj->parent->handle, obj->handle, obj->oclass |
| 109 | }; |
| 110 | struct nouveau_device *dev; |
| 111 | int ret; |
| 112 | |
| 113 | dev = nouveau_object_find(obj, NOUVEAU_DEVICE_CLASS); |
| 114 | ret = drmCommandWrite(dev->fd, DRM_NOUVEAU_GROBJ_ALLOC, |
| 115 | &req, sizeof(req)); |
| 116 | if (ret) |
| 117 | return ret; |
| 118 | |
| 119 | obj->length = sizeof(struct nouveau_object *); |
| 120 | return 0; |
| 121 | } |
| 122 | |
Emil Velikov | 76e9799 | 2015-03-23 21:52:00 +0000 | [diff] [blame] | 123 | drm_private int |
Ben Skeggs | 292da61 | 2011-12-09 16:11:06 +1000 | [diff] [blame] | 124 | abi16_ntfy(struct nouveau_object *obj) |
| 125 | { |
| 126 | struct nv04_notify *ntfy = obj->data; |
| 127 | struct drm_nouveau_notifierobj_alloc req = { |
| 128 | obj->parent->handle, ntfy->object->handle, ntfy->length |
| 129 | }; |
| 130 | struct nouveau_device *dev; |
| 131 | int ret; |
| 132 | |
| 133 | dev = nouveau_object_find(obj, NOUVEAU_DEVICE_CLASS); |
| 134 | ret = drmCommandWriteRead(dev->fd, DRM_NOUVEAU_NOTIFIEROBJ_ALLOC, |
| 135 | &req, sizeof(req)); |
| 136 | if (ret) |
| 137 | return ret; |
| 138 | |
| 139 | ntfy->offset = req.offset; |
| 140 | ntfy->object->length = sizeof(*ntfy); |
| 141 | return 0; |
| 142 | } |
| 143 | |
Emil Velikov | 76e9799 | 2015-03-23 21:52:00 +0000 | [diff] [blame] | 144 | drm_private void |
Ben Skeggs | 292da61 | 2011-12-09 16:11:06 +1000 | [diff] [blame] | 145 | abi16_bo_info(struct nouveau_bo *bo, struct drm_nouveau_gem_info *info) |
| 146 | { |
| 147 | struct nouveau_bo_priv *nvbo = nouveau_bo(bo); |
| 148 | |
| 149 | nvbo->map_handle = info->map_handle; |
| 150 | bo->handle = info->handle; |
| 151 | bo->size = info->size; |
| 152 | bo->offset = info->offset; |
| 153 | |
| 154 | bo->flags = 0; |
| 155 | if (info->domain & NOUVEAU_GEM_DOMAIN_VRAM) |
| 156 | bo->flags |= NOUVEAU_BO_VRAM; |
| 157 | if (info->domain & NOUVEAU_GEM_DOMAIN_GART) |
| 158 | bo->flags |= NOUVEAU_BO_GART; |
| 159 | if (!(info->tile_flags & NOUVEAU_GEM_TILE_NONCONTIG)) |
| 160 | bo->flags |= NOUVEAU_BO_CONTIG; |
| 161 | if (nvbo->map_handle) |
| 162 | bo->flags |= NOUVEAU_BO_MAP; |
| 163 | |
| 164 | if (bo->device->chipset >= 0xc0) { |
| 165 | bo->config.nvc0.memtype = (info->tile_flags & 0xff00) >> 8; |
| 166 | bo->config.nvc0.tile_mode = info->tile_mode; |
| 167 | } else |
| 168 | if (bo->device->chipset >= 0x80 || bo->device->chipset == 0x50) { |
| 169 | bo->config.nv50.memtype = (info->tile_flags & 0x07f00) >> 8 | |
| 170 | (info->tile_flags & 0x30000) >> 9; |
| 171 | bo->config.nv50.tile_mode = info->tile_mode << 4; |
| 172 | } else { |
| 173 | bo->config.nv04.surf_flags = info->tile_flags & 7; |
| 174 | bo->config.nv04.surf_pitch = info->tile_mode; |
| 175 | } |
| 176 | } |
| 177 | |
Emil Velikov | 76e9799 | 2015-03-23 21:52:00 +0000 | [diff] [blame] | 178 | drm_private int |
Ben Skeggs | 292da61 | 2011-12-09 16:11:06 +1000 | [diff] [blame] | 179 | abi16_bo_init(struct nouveau_bo *bo, uint32_t alignment, |
| 180 | union nouveau_bo_config *config) |
| 181 | { |
| 182 | struct nouveau_device *dev = bo->device; |
| 183 | struct drm_nouveau_gem_new req = {}; |
| 184 | struct drm_nouveau_gem_info *info = &req.info; |
| 185 | int ret; |
| 186 | |
| 187 | if (bo->flags & NOUVEAU_BO_VRAM) |
| 188 | info->domain |= NOUVEAU_GEM_DOMAIN_VRAM; |
| 189 | if (bo->flags & NOUVEAU_BO_GART) |
| 190 | info->domain |= NOUVEAU_GEM_DOMAIN_GART; |
| 191 | if (!info->domain) |
| 192 | info->domain |= NOUVEAU_GEM_DOMAIN_VRAM | |
| 193 | NOUVEAU_GEM_DOMAIN_GART; |
| 194 | |
| 195 | if (bo->flags & NOUVEAU_BO_MAP) |
| 196 | info->domain |= NOUVEAU_GEM_DOMAIN_MAPPABLE; |
| 197 | |
Alexandre Courbot | a1acffd | 2015-05-21 15:08:28 +0900 | [diff] [blame^] | 198 | if (bo->flags & NOUVEAU_BO_COHERENT) |
| 199 | info->domain |= NOUVEAU_GEM_DOMAIN_COHERENT; |
| 200 | |
Ben Skeggs | 292da61 | 2011-12-09 16:11:06 +1000 | [diff] [blame] | 201 | if (!(bo->flags & NOUVEAU_BO_CONTIG)) |
| 202 | info->tile_flags = NOUVEAU_GEM_TILE_NONCONTIG; |
| 203 | |
| 204 | info->size = bo->size; |
| 205 | req.align = alignment; |
| 206 | |
| 207 | if (config) { |
| 208 | if (dev->chipset >= 0xc0) { |
| 209 | info->tile_flags = (config->nvc0.memtype & 0xff) << 8; |
| 210 | info->tile_mode = config->nvc0.tile_mode; |
| 211 | } else |
| 212 | if (dev->chipset >= 0x80 || dev->chipset == 0x50) { |
| 213 | info->tile_flags = (config->nv50.memtype & 0x07f) << 8 | |
| 214 | (config->nv50.memtype & 0x180) << 9; |
| 215 | info->tile_mode = config->nv50.tile_mode >> 4; |
| 216 | } else { |
| 217 | info->tile_flags = config->nv04.surf_flags & 7; |
| 218 | info->tile_mode = config->nv04.surf_pitch; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | if (!nouveau_device(dev)->have_bo_usage) |
| 223 | info->tile_flags &= 0x0000ff00; |
| 224 | |
| 225 | ret = drmCommandWriteRead(dev->fd, DRM_NOUVEAU_GEM_NEW, |
| 226 | &req, sizeof(req)); |
| 227 | if (ret == 0) |
| 228 | abi16_bo_info(bo, &req.info); |
| 229 | return ret; |
| 230 | } |