Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 Ben Skeggs. |
| 3 | * |
| 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining |
| 7 | * a copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial |
| 16 | * portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 21 | * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE |
| 22 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 23 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 24 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | /* |
| 29 | * Authors: |
| 30 | * Ben Skeggs <darktama@iinet.net.au> |
| 31 | */ |
| 32 | |
| 33 | #include "drmP.h" |
| 34 | #include "drm.h" |
| 35 | #include "nouveau_drv.h" |
| 36 | #include "nouveau_drm.h" |
Ben Skeggs | 479dcae | 2010-09-01 15:24:28 +1000 | [diff] [blame] | 37 | #include "nouveau_ramht.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 38 | |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 39 | struct nouveau_gpuobj_method { |
| 40 | struct list_head head; |
| 41 | u32 mthd; |
| 42 | int (*exec)(struct nouveau_channel *, u32 class, u32 mthd, u32 data); |
| 43 | }; |
| 44 | |
| 45 | struct nouveau_gpuobj_class { |
| 46 | struct list_head head; |
| 47 | struct list_head methods; |
| 48 | u32 id; |
| 49 | u32 engine; |
| 50 | }; |
| 51 | |
| 52 | int |
| 53 | nouveau_gpuobj_class_new(struct drm_device *dev, u32 class, u32 engine) |
| 54 | { |
| 55 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 56 | struct nouveau_gpuobj_class *oc; |
| 57 | |
| 58 | oc = kzalloc(sizeof(*oc), GFP_KERNEL); |
| 59 | if (!oc) |
| 60 | return -ENOMEM; |
| 61 | |
| 62 | INIT_LIST_HEAD(&oc->methods); |
| 63 | oc->id = class; |
| 64 | oc->engine = engine; |
| 65 | list_add(&oc->head, &dev_priv->classes); |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | int |
| 70 | nouveau_gpuobj_mthd_new(struct drm_device *dev, u32 class, u32 mthd, |
| 71 | int (*exec)(struct nouveau_channel *, u32, u32, u32)) |
| 72 | { |
| 73 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 74 | struct nouveau_gpuobj_method *om; |
| 75 | struct nouveau_gpuobj_class *oc; |
| 76 | |
| 77 | list_for_each_entry(oc, &dev_priv->classes, head) { |
| 78 | if (oc->id == class) |
| 79 | goto found; |
| 80 | } |
| 81 | |
| 82 | return -EINVAL; |
| 83 | |
| 84 | found: |
| 85 | om = kzalloc(sizeof(*om), GFP_KERNEL); |
| 86 | if (!om) |
| 87 | return -ENOMEM; |
| 88 | |
| 89 | om->mthd = mthd; |
| 90 | om->exec = exec; |
| 91 | list_add(&om->head, &oc->methods); |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | int |
| 96 | nouveau_gpuobj_mthd_call(struct nouveau_channel *chan, |
| 97 | u32 class, u32 mthd, u32 data) |
| 98 | { |
| 99 | struct drm_nouveau_private *dev_priv = chan->dev->dev_private; |
| 100 | struct nouveau_gpuobj_method *om; |
| 101 | struct nouveau_gpuobj_class *oc; |
| 102 | |
| 103 | list_for_each_entry(oc, &dev_priv->classes, head) { |
| 104 | if (oc->id != class) |
| 105 | continue; |
| 106 | |
| 107 | list_for_each_entry(om, &oc->methods, head) { |
| 108 | if (om->mthd == mthd) |
| 109 | return om->exec(chan, class, mthd, data); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return -ENOENT; |
| 114 | } |
| 115 | |
Ben Skeggs | 274fec9 | 2010-11-03 13:16:18 +1000 | [diff] [blame] | 116 | int |
| 117 | nouveau_gpuobj_mthd_call2(struct drm_device *dev, int chid, |
| 118 | u32 class, u32 mthd, u32 data) |
| 119 | { |
| 120 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 121 | struct nouveau_channel *chan = NULL; |
| 122 | unsigned long flags; |
| 123 | int ret = -EINVAL; |
| 124 | |
| 125 | spin_lock_irqsave(&dev_priv->channels.lock, flags); |
| 126 | if (chid > 0 && chid < dev_priv->engine.fifo.channels) |
| 127 | chan = dev_priv->channels.ptr[chid]; |
| 128 | if (chan) |
| 129 | ret = nouveau_gpuobj_mthd_call(chan, class, mthd, data); |
| 130 | spin_unlock_irqrestore(&dev_priv->channels.lock, flags); |
| 131 | return ret; |
| 132 | } |
| 133 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 134 | /* NVidia uses context objects to drive drawing operations. |
| 135 | |
| 136 | Context objects can be selected into 8 subchannels in the FIFO, |
| 137 | and then used via DMA command buffers. |
| 138 | |
| 139 | A context object is referenced by a user defined handle (CARD32). The HW |
| 140 | looks up graphics objects in a hash table in the instance RAM. |
| 141 | |
| 142 | An entry in the hash table consists of 2 CARD32. The first CARD32 contains |
| 143 | the handle, the second one a bitfield, that contains the address of the |
| 144 | object in instance RAM. |
| 145 | |
| 146 | The format of the second CARD32 seems to be: |
| 147 | |
| 148 | NV4 to NV30: |
| 149 | |
| 150 | 15: 0 instance_addr >> 4 |
| 151 | 17:16 engine (here uses 1 = graphics) |
| 152 | 28:24 channel id (here uses 0) |
| 153 | 31 valid (use 1) |
| 154 | |
| 155 | NV40: |
| 156 | |
| 157 | 15: 0 instance_addr >> 4 (maybe 19-0) |
| 158 | 21:20 engine (here uses 1 = graphics) |
| 159 | I'm unsure about the other bits, but using 0 seems to work. |
| 160 | |
| 161 | The key into the hash table depends on the object handle and channel id and |
| 162 | is given as: |
| 163 | */ |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 164 | |
| 165 | int |
| 166 | nouveau_gpuobj_new(struct drm_device *dev, struct nouveau_channel *chan, |
| 167 | uint32_t size, int align, uint32_t flags, |
| 168 | struct nouveau_gpuobj **gpuobj_ret) |
| 169 | { |
| 170 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 171 | struct nouveau_instmem_engine *instmem = &dev_priv->engine.instmem; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 172 | struct nouveau_gpuobj *gpuobj; |
Ben Skeggs | 5125bfd | 2010-09-01 15:24:33 +1000 | [diff] [blame] | 173 | struct drm_mm_node *ramin = NULL; |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 174 | int ret, i; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 175 | |
| 176 | NV_DEBUG(dev, "ch%d size=%u align=%d flags=0x%08x\n", |
| 177 | chan ? chan->id : -1, size, align, flags); |
| 178 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 179 | gpuobj = kzalloc(sizeof(*gpuobj), GFP_KERNEL); |
| 180 | if (!gpuobj) |
| 181 | return -ENOMEM; |
| 182 | NV_DEBUG(dev, "gpuobj %p\n", gpuobj); |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 183 | gpuobj->dev = dev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 184 | gpuobj->flags = flags; |
Ben Skeggs | eb9bcbd | 2010-09-01 15:24:37 +1000 | [diff] [blame] | 185 | kref_init(&gpuobj->refcount); |
Ben Skeggs | 43efc9c | 2010-09-01 15:24:32 +1000 | [diff] [blame] | 186 | gpuobj->size = size; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 187 | |
Ben Skeggs | e05d7ea | 2010-09-01 15:24:38 +1000 | [diff] [blame] | 188 | spin_lock(&dev_priv->ramin_lock); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 189 | list_add_tail(&gpuobj->list, &dev_priv->gpuobj_list); |
Ben Skeggs | e05d7ea | 2010-09-01 15:24:38 +1000 | [diff] [blame] | 190 | spin_unlock(&dev_priv->ramin_lock); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 191 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 192 | if (chan) { |
Ben Skeggs | 5125bfd | 2010-09-01 15:24:33 +1000 | [diff] [blame] | 193 | ramin = drm_mm_search_free(&chan->ramin_heap, size, align, 0); |
| 194 | if (ramin) |
| 195 | ramin = drm_mm_get_block(ramin, size, align); |
Ben Skeggs | 5125bfd | 2010-09-01 15:24:33 +1000 | [diff] [blame] | 196 | if (!ramin) { |
| 197 | nouveau_gpuobj_ref(NULL, &gpuobj); |
| 198 | return -ENOMEM; |
| 199 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 200 | |
Ben Skeggs | 5125bfd | 2010-09-01 15:24:33 +1000 | [diff] [blame] | 201 | gpuobj->pinst = chan->ramin->pinst; |
| 202 | if (gpuobj->pinst != ~0) |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 203 | gpuobj->pinst += ramin->start; |
Ben Skeggs | 5125bfd | 2010-09-01 15:24:33 +1000 | [diff] [blame] | 204 | |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 205 | if (dev_priv->card_type < NV_50) |
Ben Skeggs | de3a6c0 | 2010-09-01 15:24:30 +1000 | [diff] [blame] | 206 | gpuobj->cinst = gpuobj->pinst; |
Ben Skeggs | 5125bfd | 2010-09-01 15:24:33 +1000 | [diff] [blame] | 207 | else |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 208 | gpuobj->cinst = ramin->start; |
| 209 | |
| 210 | gpuobj->vinst = ramin->start + chan->ramin->vinst; |
| 211 | gpuobj->node = ramin; |
| 212 | } else { |
| 213 | ret = instmem->get(gpuobj, size, align); |
| 214 | if (ret) { |
| 215 | nouveau_gpuobj_ref(NULL, &gpuobj); |
| 216 | return ret; |
| 217 | } |
| 218 | |
| 219 | ret = -ENOSYS; |
| 220 | if (dev_priv->ramin_available) |
| 221 | ret = instmem->map(gpuobj); |
| 222 | if (ret) |
Ben Skeggs | 5125bfd | 2010-09-01 15:24:33 +1000 | [diff] [blame] | 223 | gpuobj->pinst = ~0; |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 224 | |
| 225 | gpuobj->cinst = NVOBJ_CINST_GLOBAL; |
Ben Skeggs | de3a6c0 | 2010-09-01 15:24:30 +1000 | [diff] [blame] | 226 | } |
| 227 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 228 | if (gpuobj->flags & NVOBJ_FLAG_ZERO_ALLOC) { |
Ben Skeggs | 43efc9c | 2010-09-01 15:24:32 +1000 | [diff] [blame] | 229 | for (i = 0; i < gpuobj->size; i += 4) |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 230 | nv_wo32(gpuobj, i, 0); |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 231 | instmem->flush(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 232 | } |
| 233 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 234 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 235 | *gpuobj_ret = gpuobj; |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | int |
Ben Skeggs | fbd2895e | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 240 | nouveau_gpuobj_init(struct drm_device *dev) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 241 | { |
| 242 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 243 | |
| 244 | NV_DEBUG(dev, "\n"); |
| 245 | |
| 246 | INIT_LIST_HEAD(&dev_priv->gpuobj_list); |
Ben Skeggs | bd2e597 | 2010-10-19 20:06:01 +1000 | [diff] [blame] | 247 | INIT_LIST_HEAD(&dev_priv->classes); |
Ben Skeggs | 5125bfd | 2010-09-01 15:24:33 +1000 | [diff] [blame] | 248 | spin_lock_init(&dev_priv->ramin_lock); |
| 249 | dev_priv->ramin_base = ~0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 254 | void |
| 255 | nouveau_gpuobj_takedown(struct drm_device *dev) |
| 256 | { |
| 257 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 258 | struct nouveau_gpuobj_method *om, *tm; |
| 259 | struct nouveau_gpuobj_class *oc, *tc; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 260 | |
| 261 | NV_DEBUG(dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 262 | |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 263 | list_for_each_entry_safe(oc, tc, &dev_priv->classes, head) { |
| 264 | list_for_each_entry_safe(om, tm, &oc->methods, head) { |
| 265 | list_del(&om->head); |
| 266 | kfree(om); |
| 267 | } |
| 268 | list_del(&oc->head); |
| 269 | kfree(oc); |
| 270 | } |
| 271 | |
Ben Skeggs | eb9bcbd | 2010-09-01 15:24:37 +1000 | [diff] [blame] | 272 | BUG_ON(!list_empty(&dev_priv->gpuobj_list)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 273 | } |
| 274 | |
Ben Skeggs | 185abec | 2010-09-01 15:24:39 +1000 | [diff] [blame] | 275 | |
Ben Skeggs | eb9bcbd | 2010-09-01 15:24:37 +1000 | [diff] [blame] | 276 | static void |
| 277 | nouveau_gpuobj_del(struct kref *ref) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 278 | { |
Ben Skeggs | eb9bcbd | 2010-09-01 15:24:37 +1000 | [diff] [blame] | 279 | struct nouveau_gpuobj *gpuobj = |
| 280 | container_of(ref, struct nouveau_gpuobj, refcount); |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 281 | struct drm_device *dev = gpuobj->dev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 282 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 283 | struct nouveau_instmem_engine *instmem = &dev_priv->engine.instmem; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 284 | int i; |
| 285 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 286 | NV_DEBUG(dev, "gpuobj %p\n", gpuobj); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 287 | |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 288 | if (gpuobj->node && (gpuobj->flags & NVOBJ_FLAG_ZERO_FREE)) { |
Ben Skeggs | 43efc9c | 2010-09-01 15:24:32 +1000 | [diff] [blame] | 289 | for (i = 0; i < gpuobj->size; i += 4) |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 290 | nv_wo32(gpuobj, i, 0); |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 291 | instmem->flush(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | if (gpuobj->dtor) |
| 295 | gpuobj->dtor(dev, gpuobj); |
| 296 | |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 297 | if (gpuobj->cinst == NVOBJ_CINST_GLOBAL) { |
| 298 | if (gpuobj->node) { |
| 299 | instmem->unmap(gpuobj); |
| 300 | instmem->put(gpuobj); |
| 301 | } |
| 302 | } else { |
| 303 | if (gpuobj->node) { |
| 304 | spin_lock(&dev_priv->ramin_lock); |
| 305 | drm_mm_put_block(gpuobj->node); |
| 306 | spin_unlock(&dev_priv->ramin_lock); |
| 307 | } |
| 308 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 309 | |
Ben Skeggs | e05d7ea | 2010-09-01 15:24:38 +1000 | [diff] [blame] | 310 | spin_lock(&dev_priv->ramin_lock); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 311 | list_del(&gpuobj->list); |
Ben Skeggs | e05d7ea | 2010-09-01 15:24:38 +1000 | [diff] [blame] | 312 | spin_unlock(&dev_priv->ramin_lock); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 313 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 314 | kfree(gpuobj); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 315 | } |
| 316 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 317 | void |
| 318 | nouveau_gpuobj_ref(struct nouveau_gpuobj *ref, struct nouveau_gpuobj **ptr) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 319 | { |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 320 | if (ref) |
Ben Skeggs | eb9bcbd | 2010-09-01 15:24:37 +1000 | [diff] [blame] | 321 | kref_get(&ref->refcount); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 322 | |
Ben Skeggs | eb9bcbd | 2010-09-01 15:24:37 +1000 | [diff] [blame] | 323 | if (*ptr) |
| 324 | kref_put(&(*ptr)->refcount, nouveau_gpuobj_del); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 325 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 326 | *ptr = ref; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | int |
Ben Skeggs | 43efc9c | 2010-09-01 15:24:32 +1000 | [diff] [blame] | 330 | nouveau_gpuobj_new_fake(struct drm_device *dev, u32 pinst, u64 vinst, |
| 331 | u32 size, u32 flags, struct nouveau_gpuobj **pgpuobj) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 332 | { |
| 333 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 334 | struct nouveau_gpuobj *gpuobj = NULL; |
| 335 | int i; |
| 336 | |
| 337 | NV_DEBUG(dev, |
Ben Skeggs | 43efc9c | 2010-09-01 15:24:32 +1000 | [diff] [blame] | 338 | "pinst=0x%08x vinst=0x%010llx size=0x%08x flags=0x%08x\n", |
| 339 | pinst, vinst, size, flags); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 340 | |
| 341 | gpuobj = kzalloc(sizeof(*gpuobj), GFP_KERNEL); |
| 342 | if (!gpuobj) |
| 343 | return -ENOMEM; |
| 344 | NV_DEBUG(dev, "gpuobj %p\n", gpuobj); |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 345 | gpuobj->dev = dev; |
Ben Skeggs | 43efc9c | 2010-09-01 15:24:32 +1000 | [diff] [blame] | 346 | gpuobj->flags = flags; |
Ben Skeggs | eb9bcbd | 2010-09-01 15:24:37 +1000 | [diff] [blame] | 347 | kref_init(&gpuobj->refcount); |
Ben Skeggs | 43efc9c | 2010-09-01 15:24:32 +1000 | [diff] [blame] | 348 | gpuobj->size = size; |
| 349 | gpuobj->pinst = pinst; |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 350 | gpuobj->cinst = NVOBJ_CINST_GLOBAL; |
Ben Skeggs | 43efc9c | 2010-09-01 15:24:32 +1000 | [diff] [blame] | 351 | gpuobj->vinst = vinst; |
Ben Skeggs | de3a6c0 | 2010-09-01 15:24:30 +1000 | [diff] [blame] | 352 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 353 | if (gpuobj->flags & NVOBJ_FLAG_ZERO_ALLOC) { |
Ben Skeggs | 43efc9c | 2010-09-01 15:24:32 +1000 | [diff] [blame] | 354 | for (i = 0; i < gpuobj->size; i += 4) |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 355 | nv_wo32(gpuobj, i, 0); |
Ben Skeggs | f56cb86 | 2010-07-08 11:29:10 +1000 | [diff] [blame] | 356 | dev_priv->engine.instmem.flush(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 357 | } |
| 358 | |
Ben Skeggs | e05d7ea | 2010-09-01 15:24:38 +1000 | [diff] [blame] | 359 | spin_lock(&dev_priv->ramin_lock); |
Ben Skeggs | 43efc9c | 2010-09-01 15:24:32 +1000 | [diff] [blame] | 360 | list_add_tail(&gpuobj->list, &dev_priv->gpuobj_list); |
Ben Skeggs | e05d7ea | 2010-09-01 15:24:38 +1000 | [diff] [blame] | 361 | spin_unlock(&dev_priv->ramin_lock); |
Ben Skeggs | 43efc9c | 2010-09-01 15:24:32 +1000 | [diff] [blame] | 362 | *pgpuobj = gpuobj; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | |
| 367 | static uint32_t |
| 368 | nouveau_gpuobj_class_instmem_size(struct drm_device *dev, int class) |
| 369 | { |
| 370 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 371 | |
| 372 | /*XXX: dodgy hack for now */ |
| 373 | if (dev_priv->card_type >= NV_50) |
| 374 | return 24; |
| 375 | if (dev_priv->card_type >= NV_40) |
| 376 | return 32; |
| 377 | return 16; |
| 378 | } |
| 379 | |
| 380 | /* |
| 381 | DMA objects are used to reference a piece of memory in the |
| 382 | framebuffer, PCI or AGP address space. Each object is 16 bytes big |
| 383 | and looks as follows: |
| 384 | |
| 385 | entry[0] |
| 386 | 11:0 class (seems like I can always use 0 here) |
| 387 | 12 page table present? |
| 388 | 13 page entry linear? |
| 389 | 15:14 access: 0 rw, 1 ro, 2 wo |
| 390 | 17:16 target: 0 NV memory, 1 NV memory tiled, 2 PCI, 3 AGP |
| 391 | 31:20 dma adjust (bits 0-11 of the address) |
| 392 | entry[1] |
| 393 | dma limit (size of transfer) |
| 394 | entry[X] |
| 395 | 1 0 readonly, 1 readwrite |
| 396 | 31:12 dma frame address of the page (bits 12-31 of the address) |
| 397 | entry[N] |
| 398 | page table terminator, same value as the first pte, as does nvidia |
| 399 | rivatv uses 0xffffffff |
| 400 | |
| 401 | Non linear page tables need a list of frame addresses afterwards, |
| 402 | the rivatv project has some info on this. |
| 403 | |
| 404 | The method below creates a DMA object in instance RAM and returns a handle |
| 405 | to it that can be used to set up context objects. |
| 406 | */ |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 407 | |
Ben Skeggs | 7f4a195 | 2010-11-16 11:50:09 +1000 | [diff] [blame^] | 408 | void |
| 409 | nv50_gpuobj_dma_init(struct nouveau_gpuobj *obj, u32 offset, int class, |
| 410 | u64 base, u64 size, int target, int access, |
| 411 | u32 type, u32 comp) |
| 412 | { |
| 413 | struct drm_nouveau_private *dev_priv = obj->dev->dev_private; |
| 414 | struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem; |
| 415 | u32 flags0; |
| 416 | |
| 417 | flags0 = (comp << 29) | (type << 22) | class; |
| 418 | flags0 |= 0x00100000; |
| 419 | |
| 420 | switch (access) { |
| 421 | case NV_MEM_ACCESS_RO: flags0 |= 0x00040000; break; |
| 422 | case NV_MEM_ACCESS_RW: |
| 423 | case NV_MEM_ACCESS_WO: flags0 |= 0x00080000; break; |
| 424 | default: |
| 425 | break; |
| 426 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 427 | |
| 428 | switch (target) { |
Ben Skeggs | 7f4a195 | 2010-11-16 11:50:09 +1000 | [diff] [blame^] | 429 | case NV_MEM_TARGET_VRAM: |
| 430 | flags0 |= 0x00010000; |
| 431 | break; |
| 432 | case NV_MEM_TARGET_PCI: |
| 433 | flags0 |= 0x00020000; |
| 434 | break; |
| 435 | case NV_MEM_TARGET_PCI_NOSNOOP: |
| 436 | flags0 |= 0x00030000; |
| 437 | break; |
| 438 | case NV_MEM_TARGET_GART: |
| 439 | base += dev_priv->vm_gart_base; |
| 440 | default: |
| 441 | flags0 &= ~0x00100000; |
| 442 | break; |
| 443 | } |
| 444 | |
| 445 | /* convert to base + limit */ |
| 446 | size = (base + size) - 1; |
| 447 | |
| 448 | nv_wo32(obj, offset + 0x00, flags0); |
| 449 | nv_wo32(obj, offset + 0x04, lower_32_bits(size)); |
| 450 | nv_wo32(obj, offset + 0x08, lower_32_bits(base)); |
| 451 | nv_wo32(obj, offset + 0x0c, upper_32_bits(size) << 24 | |
| 452 | upper_32_bits(base)); |
| 453 | nv_wo32(obj, offset + 0x10, 0x00000000); |
| 454 | nv_wo32(obj, offset + 0x14, 0x00000000); |
| 455 | |
| 456 | pinstmem->flush(obj->dev); |
| 457 | } |
| 458 | |
| 459 | int |
| 460 | nv50_gpuobj_dma_new(struct nouveau_channel *chan, int class, u64 base, u64 size, |
| 461 | int target, int access, u32 type, u32 comp, |
| 462 | struct nouveau_gpuobj **pobj) |
| 463 | { |
| 464 | struct drm_device *dev = chan->dev; |
| 465 | int ret; |
| 466 | |
| 467 | ret = nouveau_gpuobj_new(dev, chan, 24, 16, NVOBJ_FLAG_ZERO_ALLOC | |
| 468 | NVOBJ_FLAG_ZERO_FREE, pobj); |
| 469 | if (ret) |
| 470 | return ret; |
| 471 | |
| 472 | nv50_gpuobj_dma_init(*pobj, 0, class, base, size, target, |
| 473 | access, type, comp); |
| 474 | return 0; |
| 475 | } |
| 476 | |
| 477 | int |
| 478 | nouveau_gpuobj_dma_new(struct nouveau_channel *chan, int class, u64 base, |
| 479 | u64 size, int access, int target, |
| 480 | struct nouveau_gpuobj **pobj) |
| 481 | { |
| 482 | struct drm_nouveau_private *dev_priv = chan->dev->dev_private; |
| 483 | struct drm_device *dev = chan->dev; |
| 484 | struct nouveau_gpuobj *obj; |
| 485 | u32 page_addr, flags0, flags2; |
| 486 | int ret; |
| 487 | |
| 488 | if (dev_priv->card_type >= NV_50) { |
| 489 | u32 comp = (target == NV_MEM_TARGET_VM) ? NV_MEM_COMP_VM : 0; |
| 490 | u32 type = (target == NV_MEM_TARGET_VM) ? NV_MEM_TYPE_VM : 0; |
| 491 | |
| 492 | return nv50_gpuobj_dma_new(chan, class, base, size, |
| 493 | target, access, type, comp, pobj); |
| 494 | } |
| 495 | |
| 496 | if (target == NV_MEM_TARGET_GART) { |
| 497 | if (dev_priv->gart_info.type == NOUVEAU_GART_AGP) { |
| 498 | target = NV_MEM_TARGET_PCI_NOSNOOP; |
| 499 | base += dev_priv->gart_info.aper_base; |
| 500 | } else |
| 501 | if (base != 0) { |
| 502 | ret = nouveau_sgdma_get_page(dev, base, &page_addr); |
| 503 | if (ret) |
| 504 | return ret; |
| 505 | |
| 506 | target = NV_MEM_TARGET_PCI; |
| 507 | base = page_addr; |
| 508 | } else { |
| 509 | nouveau_gpuobj_ref(dev_priv->gart_info.sg_ctxdma, pobj); |
| 510 | return 0; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | flags0 = class; |
| 515 | flags0 |= 0x00003000; /* PT present, PT linear */ |
| 516 | flags2 = 0; |
| 517 | |
| 518 | switch (target) { |
| 519 | case NV_MEM_TARGET_PCI: |
| 520 | flags0 |= 0x00020000; |
| 521 | break; |
| 522 | case NV_MEM_TARGET_PCI_NOSNOOP: |
| 523 | flags0 |= 0x00030000; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 524 | break; |
| 525 | default: |
| 526 | break; |
| 527 | } |
| 528 | |
Ben Skeggs | 7f4a195 | 2010-11-16 11:50:09 +1000 | [diff] [blame^] | 529 | switch (access) { |
| 530 | case NV_MEM_ACCESS_RO: |
| 531 | flags0 |= 0x00004000; |
| 532 | break; |
| 533 | case NV_MEM_ACCESS_WO: |
| 534 | flags0 |= 0x00008000; |
| 535 | default: |
| 536 | flags2 |= 0x00000002; |
| 537 | break; |
| 538 | } |
| 539 | |
| 540 | flags0 |= (base & 0x00000fff) << 20; |
| 541 | flags2 |= (base & 0xfffff000); |
| 542 | |
| 543 | ret = nouveau_gpuobj_new(dev, chan, (dev_priv->card_type >= NV_40) ? |
| 544 | 32 : 16, 16, NVOBJ_FLAG_ZERO_ALLOC | |
| 545 | NVOBJ_FLAG_ZERO_FREE, &obj); |
| 546 | if (ret) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 547 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 548 | |
Ben Skeggs | 7f4a195 | 2010-11-16 11:50:09 +1000 | [diff] [blame^] | 549 | nv_wo32(obj, 0x00, flags0); |
| 550 | nv_wo32(obj, 0x04, size - 1); |
| 551 | nv_wo32(obj, 0x08, flags2); |
| 552 | nv_wo32(obj, 0x0c, flags2); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 553 | |
Ben Skeggs | 7f4a195 | 2010-11-16 11:50:09 +1000 | [diff] [blame^] | 554 | obj->engine = NVOBJ_ENGINE_SW; |
| 555 | obj->class = class; |
| 556 | *pobj = obj; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 557 | return 0; |
| 558 | } |
| 559 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 560 | /* Context objects in the instance RAM have the following structure. |
| 561 | * On NV40 they are 32 byte long, on NV30 and smaller 16 bytes. |
| 562 | |
| 563 | NV4 - NV30: |
| 564 | |
| 565 | entry[0] |
| 566 | 11:0 class |
| 567 | 12 chroma key enable |
| 568 | 13 user clip enable |
| 569 | 14 swizzle enable |
| 570 | 17:15 patch config: |
| 571 | scrcopy_and, rop_and, blend_and, scrcopy, srccopy_pre, blend_pre |
| 572 | 18 synchronize enable |
| 573 | 19 endian: 1 big, 0 little |
| 574 | 21:20 dither mode |
| 575 | 23 single step enable |
| 576 | 24 patch status: 0 invalid, 1 valid |
| 577 | 25 context_surface 0: 1 valid |
| 578 | 26 context surface 1: 1 valid |
| 579 | 27 context pattern: 1 valid |
| 580 | 28 context rop: 1 valid |
| 581 | 29,30 context beta, beta4 |
| 582 | entry[1] |
| 583 | 7:0 mono format |
| 584 | 15:8 color format |
| 585 | 31:16 notify instance address |
| 586 | entry[2] |
| 587 | 15:0 dma 0 instance address |
| 588 | 31:16 dma 1 instance address |
| 589 | entry[3] |
| 590 | dma method traps |
| 591 | |
| 592 | NV40: |
| 593 | No idea what the exact format is. Here's what can be deducted: |
| 594 | |
| 595 | entry[0]: |
| 596 | 11:0 class (maybe uses more bits here?) |
| 597 | 17 user clip enable |
| 598 | 21:19 patch config |
| 599 | 25 patch status valid ? |
| 600 | entry[1]: |
| 601 | 15:0 DMA notifier (maybe 20:0) |
| 602 | entry[2]: |
| 603 | 15:0 DMA 0 instance (maybe 20:0) |
| 604 | 24 big endian |
| 605 | entry[3]: |
| 606 | 15:0 DMA 1 instance (maybe 20:0) |
| 607 | entry[4]: |
| 608 | entry[5]: |
| 609 | set to 0? |
| 610 | */ |
Ben Skeggs | a6a1a38 | 2010-10-19 19:57:34 +1000 | [diff] [blame] | 611 | static int |
| 612 | nouveau_gpuobj_sw_new(struct nouveau_channel *chan, int class, |
| 613 | struct nouveau_gpuobj **gpuobj_ret) |
| 614 | { |
| 615 | struct drm_nouveau_private *dev_priv; |
| 616 | struct nouveau_gpuobj *gpuobj; |
| 617 | |
| 618 | if (!chan || !gpuobj_ret || *gpuobj_ret != NULL) |
| 619 | return -EINVAL; |
| 620 | dev_priv = chan->dev->dev_private; |
| 621 | |
| 622 | gpuobj = kzalloc(sizeof(*gpuobj), GFP_KERNEL); |
| 623 | if (!gpuobj) |
| 624 | return -ENOMEM; |
| 625 | gpuobj->dev = chan->dev; |
| 626 | gpuobj->engine = NVOBJ_ENGINE_SW; |
| 627 | gpuobj->class = class; |
| 628 | kref_init(&gpuobj->refcount); |
| 629 | gpuobj->cinst = 0x40; |
| 630 | |
| 631 | spin_lock(&dev_priv->ramin_lock); |
| 632 | list_add_tail(&gpuobj->list, &dev_priv->gpuobj_list); |
| 633 | spin_unlock(&dev_priv->ramin_lock); |
| 634 | *gpuobj_ret = gpuobj; |
| 635 | return 0; |
| 636 | } |
| 637 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 638 | int |
| 639 | nouveau_gpuobj_gr_new(struct nouveau_channel *chan, int class, |
| 640 | struct nouveau_gpuobj **gpuobj) |
| 641 | { |
Ben Skeggs | a6a1a38 | 2010-10-19 19:57:34 +1000 | [diff] [blame] | 642 | struct drm_nouveau_private *dev_priv = chan->dev->dev_private; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 643 | struct drm_device *dev = chan->dev; |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 644 | struct nouveau_gpuobj_class *oc; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 645 | int ret; |
| 646 | |
| 647 | NV_DEBUG(dev, "ch%d class=0x%04x\n", chan->id, class); |
| 648 | |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 649 | list_for_each_entry(oc, &dev_priv->classes, head) { |
| 650 | if (oc->id == class) |
| 651 | goto found; |
Ben Skeggs | a6a1a38 | 2010-10-19 19:57:34 +1000 | [diff] [blame] | 652 | } |
| 653 | |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 654 | NV_ERROR(dev, "illegal object class: 0x%x\n", class); |
| 655 | return -EINVAL; |
Ben Skeggs | a6a1a38 | 2010-10-19 19:57:34 +1000 | [diff] [blame] | 656 | |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 657 | found: |
| 658 | if (oc->engine == NVOBJ_ENGINE_SW) |
Ben Skeggs | a6a1a38 | 2010-10-19 19:57:34 +1000 | [diff] [blame] | 659 | return nouveau_gpuobj_sw_new(chan, class, gpuobj); |
| 660 | |
Ben Skeggs | f4512e6 | 2010-10-20 11:47:09 +1000 | [diff] [blame] | 661 | switch (oc->engine) { |
| 662 | case NVOBJ_ENGINE_GR: |
| 663 | if (dev_priv->card_type >= NV_50 && !chan->ramin_grctx) { |
| 664 | struct nouveau_pgraph_engine *pgraph = |
| 665 | &dev_priv->engine.graph; |
| 666 | |
| 667 | ret = pgraph->create_context(chan); |
| 668 | if (ret) |
| 669 | return ret; |
| 670 | } |
| 671 | break; |
| 672 | case NVOBJ_ENGINE_CRYPT: |
| 673 | if (!chan->crypt_ctx) { |
| 674 | struct nouveau_crypt_engine *pcrypt = |
| 675 | &dev_priv->engine.crypt; |
| 676 | |
| 677 | ret = pcrypt->create_context(chan); |
| 678 | if (ret) |
| 679 | return ret; |
| 680 | } |
| 681 | break; |
| 682 | } |
| 683 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 684 | ret = nouveau_gpuobj_new(dev, chan, |
| 685 | nouveau_gpuobj_class_instmem_size(dev, class), |
| 686 | 16, |
| 687 | NVOBJ_FLAG_ZERO_ALLOC | NVOBJ_FLAG_ZERO_FREE, |
| 688 | gpuobj); |
| 689 | if (ret) { |
Ben Skeggs | a6a1a38 | 2010-10-19 19:57:34 +1000 | [diff] [blame] | 690 | NV_ERROR(dev, "error creating gpuobj: %d\n", ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 691 | return ret; |
| 692 | } |
| 693 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 694 | if (dev_priv->card_type >= NV_50) { |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 695 | nv_wo32(*gpuobj, 0, class); |
| 696 | nv_wo32(*gpuobj, 20, 0x00010000); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 697 | } else { |
| 698 | switch (class) { |
| 699 | case NV_CLASS_NULL: |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 700 | nv_wo32(*gpuobj, 0, 0x00001030); |
| 701 | nv_wo32(*gpuobj, 4, 0xFFFFFFFF); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 702 | break; |
| 703 | default: |
| 704 | if (dev_priv->card_type >= NV_40) { |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 705 | nv_wo32(*gpuobj, 0, class); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 706 | #ifdef __BIG_ENDIAN |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 707 | nv_wo32(*gpuobj, 8, 0x01000000); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 708 | #endif |
| 709 | } else { |
| 710 | #ifdef __BIG_ENDIAN |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 711 | nv_wo32(*gpuobj, 0, class | 0x00080000); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 712 | #else |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 713 | nv_wo32(*gpuobj, 0, class); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 714 | #endif |
| 715 | } |
| 716 | } |
| 717 | } |
Ben Skeggs | f56cb86 | 2010-07-08 11:29:10 +1000 | [diff] [blame] | 718 | dev_priv->engine.instmem.flush(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 719 | |
Ben Skeggs | b8c157d | 2010-10-20 10:39:35 +1000 | [diff] [blame] | 720 | (*gpuobj)->engine = oc->engine; |
| 721 | (*gpuobj)->class = oc->id; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 722 | return 0; |
| 723 | } |
| 724 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 725 | static int |
| 726 | nouveau_gpuobj_channel_init_pramin(struct nouveau_channel *chan) |
| 727 | { |
| 728 | struct drm_device *dev = chan->dev; |
| 729 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 730 | uint32_t size; |
| 731 | uint32_t base; |
| 732 | int ret; |
| 733 | |
| 734 | NV_DEBUG(dev, "ch%d\n", chan->id); |
| 735 | |
| 736 | /* Base amount for object storage (4KiB enough?) */ |
Ben Skeggs | bd2e597 | 2010-10-19 20:06:01 +1000 | [diff] [blame] | 737 | size = 0x2000; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 738 | base = 0; |
| 739 | |
| 740 | /* PGRAPH context */ |
Ben Skeggs | 816544b | 2010-07-08 13:15:05 +1000 | [diff] [blame] | 741 | size += dev_priv->engine.graph.grctx_size; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 742 | |
| 743 | if (dev_priv->card_type == NV_50) { |
| 744 | /* Various fixed table thingos */ |
| 745 | size += 0x1400; /* mostly unknown stuff */ |
| 746 | size += 0x4000; /* vm pd */ |
| 747 | base = 0x6000; |
| 748 | /* RAMHT, not sure about setting size yet, 32KiB to be safe */ |
| 749 | size += 0x8000; |
| 750 | /* RAMFC */ |
| 751 | size += 0x1000; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 752 | } |
| 753 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 754 | ret = nouveau_gpuobj_new(dev, NULL, size, 0x1000, 0, &chan->ramin); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 755 | if (ret) { |
| 756 | NV_ERROR(dev, "Error allocating channel PRAMIN: %d\n", ret); |
| 757 | return ret; |
| 758 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 759 | |
Ben Skeggs | de3a6c0 | 2010-09-01 15:24:30 +1000 | [diff] [blame] | 760 | ret = drm_mm_init(&chan->ramin_heap, base, size); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 761 | if (ret) { |
| 762 | NV_ERROR(dev, "Error creating PRAMIN heap: %d\n", ret); |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 763 | nouveau_gpuobj_ref(NULL, &chan->ramin); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 764 | return ret; |
| 765 | } |
| 766 | |
| 767 | return 0; |
| 768 | } |
| 769 | |
| 770 | int |
| 771 | nouveau_gpuobj_channel_init(struct nouveau_channel *chan, |
| 772 | uint32_t vram_h, uint32_t tt_h) |
| 773 | { |
| 774 | struct drm_device *dev = chan->dev; |
| 775 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 776 | struct nouveau_instmem_engine *instmem = &dev_priv->engine.instmem; |
| 777 | struct nouveau_gpuobj *vram = NULL, *tt = NULL; |
| 778 | int ret, i; |
| 779 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 780 | NV_DEBUG(dev, "ch%d vram=0x%08x tt=0x%08x\n", chan->id, vram_h, tt_h); |
| 781 | |
Ben Skeggs | 816544b | 2010-07-08 13:15:05 +1000 | [diff] [blame] | 782 | /* Allocate a chunk of memory for per-channel object storage */ |
| 783 | ret = nouveau_gpuobj_channel_init_pramin(chan); |
| 784 | if (ret) { |
| 785 | NV_ERROR(dev, "init pramin\n"); |
| 786 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | /* NV50 VM |
| 790 | * - Allocate per-channel page-directory |
| 791 | * - Map GART and VRAM into the channel's address space at the |
| 792 | * locations determined during init. |
| 793 | */ |
| 794 | if (dev_priv->card_type >= NV_50) { |
Ben Skeggs | 5125bfd | 2010-09-01 15:24:33 +1000 | [diff] [blame] | 795 | u32 pgd_offs = (dev_priv->chipset == 0x50) ? 0x1400 : 0x0200; |
| 796 | u64 vm_vinst = chan->ramin->vinst + pgd_offs; |
| 797 | u32 vm_pinst = chan->ramin->pinst; |
| 798 | u32 pde; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 799 | |
Ben Skeggs | 5125bfd | 2010-09-01 15:24:33 +1000 | [diff] [blame] | 800 | if (vm_pinst != ~0) |
| 801 | vm_pinst += pgd_offs; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 802 | |
Ben Skeggs | 5125bfd | 2010-09-01 15:24:33 +1000 | [diff] [blame] | 803 | ret = nouveau_gpuobj_new_fake(dev, vm_pinst, vm_vinst, 0x4000, |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 804 | 0, &chan->vm_pd); |
Ben Skeggs | f56cb86 | 2010-07-08 11:29:10 +1000 | [diff] [blame] | 805 | if (ret) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 806 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 807 | for (i = 0; i < 0x4000; i += 8) { |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 808 | nv_wo32(chan->vm_pd, i + 0, 0x00000000); |
| 809 | nv_wo32(chan->vm_pd, i + 4, 0xdeadcafe); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 810 | } |
| 811 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 812 | nouveau_gpuobj_ref(dev_priv->gart_info.sg_ctxdma, |
| 813 | &chan->vm_gart_pt); |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 814 | pde = (dev_priv->vm_gart_base / (512*1024*1024)) * 8; |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 815 | nv_wo32(chan->vm_pd, pde + 0, chan->vm_gart_pt->vinst | 3); |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 816 | nv_wo32(chan->vm_pd, pde + 4, 0x00000000); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 817 | |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 818 | pde = (dev_priv->vm_vram_base / (512*1024*1024)) * 8; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 819 | for (i = 0; i < dev_priv->vm_vram_pt_nr; i++) { |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 820 | nouveau_gpuobj_ref(dev_priv->vm_vram_pt[i], |
| 821 | &chan->vm_vram_pt[i]); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 822 | |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 823 | nv_wo32(chan->vm_pd, pde + 0, |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 824 | chan->vm_vram_pt[i]->vinst | 0x61); |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 825 | nv_wo32(chan->vm_pd, pde + 4, 0x00000000); |
| 826 | pde += 8; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 827 | } |
| 828 | |
Ben Skeggs | f56cb86 | 2010-07-08 11:29:10 +1000 | [diff] [blame] | 829 | instmem->flush(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | /* RAMHT */ |
| 833 | if (dev_priv->card_type < NV_50) { |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 834 | nouveau_ramht_ref(dev_priv->ramht, &chan->ramht, NULL); |
| 835 | } else { |
| 836 | struct nouveau_gpuobj *ramht = NULL; |
| 837 | |
| 838 | ret = nouveau_gpuobj_new(dev, chan, 0x8000, 16, |
| 839 | NVOBJ_FLAG_ZERO_ALLOC, &ramht); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 840 | if (ret) |
| 841 | return ret; |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 842 | |
| 843 | ret = nouveau_ramht_new(dev, ramht, &chan->ramht); |
| 844 | nouveau_gpuobj_ref(NULL, &ramht); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 845 | if (ret) |
| 846 | return ret; |
| 847 | } |
| 848 | |
| 849 | /* VRAM ctxdma */ |
| 850 | if (dev_priv->card_type >= NV_50) { |
| 851 | ret = nouveau_gpuobj_dma_new(chan, NV_CLASS_DMA_IN_MEMORY, |
| 852 | 0, dev_priv->vm_end, |
Ben Skeggs | 7f4a195 | 2010-11-16 11:50:09 +1000 | [diff] [blame^] | 853 | NV_MEM_ACCESS_RW, |
| 854 | NV_MEM_TARGET_VM, &vram); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 855 | if (ret) { |
| 856 | NV_ERROR(dev, "Error creating VRAM ctxdma: %d\n", ret); |
| 857 | return ret; |
| 858 | } |
| 859 | } else { |
| 860 | ret = nouveau_gpuobj_dma_new(chan, NV_CLASS_DMA_IN_MEMORY, |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 861 | 0, dev_priv->fb_available_size, |
Ben Skeggs | 7f4a195 | 2010-11-16 11:50:09 +1000 | [diff] [blame^] | 862 | NV_MEM_ACCESS_RW, |
| 863 | NV_MEM_TARGET_VRAM, &vram); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 864 | if (ret) { |
| 865 | NV_ERROR(dev, "Error creating VRAM ctxdma: %d\n", ret); |
| 866 | return ret; |
| 867 | } |
| 868 | } |
| 869 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 870 | ret = nouveau_ramht_insert(chan, vram_h, vram); |
| 871 | nouveau_gpuobj_ref(NULL, &vram); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 872 | if (ret) { |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 873 | NV_ERROR(dev, "Error adding VRAM ctxdma to RAMHT: %d\n", ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 874 | return ret; |
| 875 | } |
| 876 | |
| 877 | /* TT memory ctxdma */ |
| 878 | if (dev_priv->card_type >= NV_50) { |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 879 | ret = nouveau_gpuobj_dma_new(chan, NV_CLASS_DMA_IN_MEMORY, |
| 880 | 0, dev_priv->vm_end, |
Ben Skeggs | 7f4a195 | 2010-11-16 11:50:09 +1000 | [diff] [blame^] | 881 | NV_MEM_ACCESS_RW, |
| 882 | NV_MEM_TARGET_VM, &tt); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 883 | } else { |
Ben Skeggs | 7f4a195 | 2010-11-16 11:50:09 +1000 | [diff] [blame^] | 884 | ret = nouveau_gpuobj_dma_new(chan, NV_CLASS_DMA_IN_MEMORY, |
| 885 | 0, dev_priv->gart_info.aper_size, |
| 886 | NV_MEM_ACCESS_RW, |
| 887 | NV_MEM_TARGET_GART, &tt); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | if (ret) { |
| 891 | NV_ERROR(dev, "Error creating TT ctxdma: %d\n", ret); |
| 892 | return ret; |
| 893 | } |
| 894 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 895 | ret = nouveau_ramht_insert(chan, tt_h, tt); |
| 896 | nouveau_gpuobj_ref(NULL, &tt); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 897 | if (ret) { |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 898 | NV_ERROR(dev, "Error adding TT ctxdma to RAMHT: %d\n", ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 899 | return ret; |
| 900 | } |
| 901 | |
| 902 | return 0; |
| 903 | } |
| 904 | |
| 905 | void |
| 906 | nouveau_gpuobj_channel_takedown(struct nouveau_channel *chan) |
| 907 | { |
| 908 | struct drm_nouveau_private *dev_priv = chan->dev->dev_private; |
| 909 | struct drm_device *dev = chan->dev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 910 | int i; |
| 911 | |
| 912 | NV_DEBUG(dev, "ch%d\n", chan->id); |
| 913 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 914 | if (!chan->ramht) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 915 | return; |
| 916 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 917 | nouveau_ramht_ref(NULL, &chan->ramht, chan); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 918 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 919 | nouveau_gpuobj_ref(NULL, &chan->vm_pd); |
| 920 | nouveau_gpuobj_ref(NULL, &chan->vm_gart_pt); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 921 | for (i = 0; i < dev_priv->vm_vram_pt_nr; i++) |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 922 | nouveau_gpuobj_ref(NULL, &chan->vm_vram_pt[i]); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 923 | |
Ben Skeggs | b833ac2 | 2010-06-01 15:32:24 +1000 | [diff] [blame] | 924 | if (chan->ramin_heap.free_stack.next) |
| 925 | drm_mm_takedown(&chan->ramin_heap); |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 926 | nouveau_gpuobj_ref(NULL, &chan->ramin); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | int |
| 930 | nouveau_gpuobj_suspend(struct drm_device *dev) |
| 931 | { |
| 932 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 933 | struct nouveau_gpuobj *gpuobj; |
| 934 | int i; |
| 935 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 936 | list_for_each_entry(gpuobj, &dev_priv->gpuobj_list, list) { |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 937 | if (gpuobj->cinst != NVOBJ_CINST_GLOBAL) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 938 | continue; |
| 939 | |
Ben Skeggs | dc1e5c0 | 2010-10-25 15:23:59 +1000 | [diff] [blame] | 940 | gpuobj->suspend = vmalloc(gpuobj->size); |
| 941 | if (!gpuobj->suspend) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 942 | nouveau_gpuobj_resume(dev); |
| 943 | return -ENOMEM; |
| 944 | } |
| 945 | |
Ben Skeggs | 43efc9c | 2010-09-01 15:24:32 +1000 | [diff] [blame] | 946 | for (i = 0; i < gpuobj->size; i += 4) |
Ben Skeggs | dc1e5c0 | 2010-10-25 15:23:59 +1000 | [diff] [blame] | 947 | gpuobj->suspend[i/4] = nv_ro32(gpuobj, i); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | return 0; |
| 951 | } |
| 952 | |
| 953 | void |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 954 | nouveau_gpuobj_resume(struct drm_device *dev) |
| 955 | { |
| 956 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 957 | struct nouveau_gpuobj *gpuobj; |
| 958 | int i; |
| 959 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 960 | list_for_each_entry(gpuobj, &dev_priv->gpuobj_list, list) { |
Ben Skeggs | dc1e5c0 | 2010-10-25 15:23:59 +1000 | [diff] [blame] | 961 | if (!gpuobj->suspend) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 962 | continue; |
| 963 | |
Ben Skeggs | 43efc9c | 2010-09-01 15:24:32 +1000 | [diff] [blame] | 964 | for (i = 0; i < gpuobj->size; i += 4) |
Ben Skeggs | dc1e5c0 | 2010-10-25 15:23:59 +1000 | [diff] [blame] | 965 | nv_wo32(gpuobj, i, gpuobj->suspend[i/4]); |
| 966 | |
| 967 | vfree(gpuobj->suspend); |
| 968 | gpuobj->suspend = NULL; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 969 | } |
| 970 | |
Ben Skeggs | dc1e5c0 | 2010-10-25 15:23:59 +1000 | [diff] [blame] | 971 | dev_priv->engine.instmem.flush(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | int nouveau_ioctl_grobj_alloc(struct drm_device *dev, void *data, |
| 975 | struct drm_file *file_priv) |
| 976 | { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 977 | struct drm_nouveau_grobj_alloc *init = data; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 978 | struct nouveau_gpuobj *gr = NULL; |
| 979 | struct nouveau_channel *chan; |
| 980 | int ret; |
| 981 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 982 | if (init->handle == ~0) |
| 983 | return -EINVAL; |
| 984 | |
Ben Skeggs | cff5c13 | 2010-10-06 16:16:59 +1000 | [diff] [blame] | 985 | chan = nouveau_channel_get(dev, file_priv, init->channel); |
| 986 | if (IS_ERR(chan)) |
| 987 | return PTR_ERR(chan); |
| 988 | |
| 989 | if (nouveau_ramht_find(chan, init->handle)) { |
| 990 | ret = -EEXIST; |
| 991 | goto out; |
| 992 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 993 | |
Ben Skeggs | a6a1a38 | 2010-10-19 19:57:34 +1000 | [diff] [blame] | 994 | ret = nouveau_gpuobj_gr_new(chan, init->class, &gr); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 995 | if (ret) { |
| 996 | NV_ERROR(dev, "Error creating object: %d (%d/0x%08x)\n", |
| 997 | ret, init->channel, init->handle); |
Ben Skeggs | cff5c13 | 2010-10-06 16:16:59 +1000 | [diff] [blame] | 998 | goto out; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 999 | } |
| 1000 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 1001 | ret = nouveau_ramht_insert(chan, init->handle, gr); |
| 1002 | nouveau_gpuobj_ref(NULL, &gr); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1003 | if (ret) { |
| 1004 | NV_ERROR(dev, "Error referencing object: %d (%d/0x%08x)\n", |
| 1005 | ret, init->channel, init->handle); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1006 | } |
| 1007 | |
Ben Skeggs | cff5c13 | 2010-10-06 16:16:59 +1000 | [diff] [blame] | 1008 | out: |
| 1009 | nouveau_channel_put(&chan); |
| 1010 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | int nouveau_ioctl_gpuobj_free(struct drm_device *dev, void *data, |
| 1014 | struct drm_file *file_priv) |
| 1015 | { |
| 1016 | struct drm_nouveau_gpuobj_free *objfree = data; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1017 | struct nouveau_channel *chan; |
Ben Skeggs | 18a16a7 | 2010-10-12 10:11:00 +1000 | [diff] [blame] | 1018 | int ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1019 | |
Ben Skeggs | cff5c13 | 2010-10-06 16:16:59 +1000 | [diff] [blame] | 1020 | chan = nouveau_channel_get(dev, file_priv, objfree->channel); |
| 1021 | if (IS_ERR(chan)) |
| 1022 | return PTR_ERR(chan); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1023 | |
Ben Skeggs | 18a16a7 | 2010-10-12 10:11:00 +1000 | [diff] [blame] | 1024 | ret = nouveau_ramht_remove(chan, objfree->handle); |
Ben Skeggs | cff5c13 | 2010-10-06 16:16:59 +1000 | [diff] [blame] | 1025 | nouveau_channel_put(&chan); |
| 1026 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1027 | } |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 1028 | |
| 1029 | u32 |
| 1030 | nv_ro32(struct nouveau_gpuobj *gpuobj, u32 offset) |
| 1031 | { |
Ben Skeggs | 5125bfd | 2010-09-01 15:24:33 +1000 | [diff] [blame] | 1032 | struct drm_nouveau_private *dev_priv = gpuobj->dev->dev_private; |
| 1033 | struct drm_device *dev = gpuobj->dev; |
| 1034 | |
| 1035 | if (gpuobj->pinst == ~0 || !dev_priv->ramin_available) { |
| 1036 | u64 ptr = gpuobj->vinst + offset; |
| 1037 | u32 base = ptr >> 16; |
| 1038 | u32 val; |
| 1039 | |
| 1040 | spin_lock(&dev_priv->ramin_lock); |
| 1041 | if (dev_priv->ramin_base != base) { |
| 1042 | dev_priv->ramin_base = base; |
| 1043 | nv_wr32(dev, 0x001700, dev_priv->ramin_base); |
| 1044 | } |
| 1045 | val = nv_rd32(dev, 0x700000 + (ptr & 0xffff)); |
| 1046 | spin_unlock(&dev_priv->ramin_lock); |
| 1047 | return val; |
| 1048 | } |
| 1049 | |
| 1050 | return nv_ri32(dev, gpuobj->pinst + offset); |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | void |
| 1054 | nv_wo32(struct nouveau_gpuobj *gpuobj, u32 offset, u32 val) |
| 1055 | { |
Ben Skeggs | 5125bfd | 2010-09-01 15:24:33 +1000 | [diff] [blame] | 1056 | struct drm_nouveau_private *dev_priv = gpuobj->dev->dev_private; |
| 1057 | struct drm_device *dev = gpuobj->dev; |
| 1058 | |
| 1059 | if (gpuobj->pinst == ~0 || !dev_priv->ramin_available) { |
| 1060 | u64 ptr = gpuobj->vinst + offset; |
| 1061 | u32 base = ptr >> 16; |
| 1062 | |
| 1063 | spin_lock(&dev_priv->ramin_lock); |
| 1064 | if (dev_priv->ramin_base != base) { |
| 1065 | dev_priv->ramin_base = base; |
| 1066 | nv_wr32(dev, 0x001700, dev_priv->ramin_base); |
| 1067 | } |
| 1068 | nv_wr32(dev, 0x700000 + (ptr & 0xffff), val); |
| 1069 | spin_unlock(&dev_priv->ramin_lock); |
| 1070 | return; |
| 1071 | } |
| 1072 | |
| 1073 | nv_wi32(dev, gpuobj->pinst + offset, val); |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 1074 | } |