Ben Skeggs | c092432 | 2011-04-04 16:10:00 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 | |
| 25 | #include "drmP.h" |
| 26 | #include "nouveau_drv.h" |
| 27 | #include "nouveau_ramht.h" |
| 28 | |
Ben Skeggs | 9318745 | 2011-04-12 15:19:54 +1000 | [diff] [blame^] | 29 | struct nv50_mpeg_engine { |
Ben Skeggs | c092432 | 2011-04-04 16:10:00 +1000 | [diff] [blame] | 30 | struct nouveau_exec_engine base; |
| 31 | }; |
| 32 | |
| 33 | static int |
Ben Skeggs | 9318745 | 2011-04-12 15:19:54 +1000 | [diff] [blame^] | 34 | nv50_mpeg_context_new(struct nouveau_channel *chan, int engine) |
Ben Skeggs | c092432 | 2011-04-04 16:10:00 +1000 | [diff] [blame] | 35 | { |
| 36 | struct drm_device *dev = chan->dev; |
| 37 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 38 | struct nouveau_gpuobj *ramin = chan->ramin; |
| 39 | struct nouveau_gpuobj *ctx = NULL; |
| 40 | int ret; |
| 41 | |
| 42 | NV_DEBUG(dev, "ch%d\n", chan->id); |
| 43 | |
| 44 | ret = nouveau_gpuobj_new(dev, chan, 128 * 4, 0, NVOBJ_FLAG_ZERO_ALLOC | |
| 45 | NVOBJ_FLAG_ZERO_FREE, &ctx); |
| 46 | if (ret) |
| 47 | return ret; |
| 48 | |
| 49 | nv_wo32(ramin, 0x60, 0x80190002); |
| 50 | nv_wo32(ramin, 0x64, ctx->vinst + ctx->size - 1); |
| 51 | nv_wo32(ramin, 0x68, ctx->vinst); |
| 52 | nv_wo32(ramin, 0x6c, 0); |
| 53 | nv_wo32(ramin, 0x70, 0); |
| 54 | nv_wo32(ramin, 0x74, 0x00010000); |
| 55 | |
| 56 | nv_wo32(ctx, 0x70, 0x00801ec1); |
| 57 | nv_wo32(ctx, 0x7c, 0x0000037c); |
| 58 | dev_priv->engine.instmem.flush(dev); |
| 59 | |
| 60 | chan->engctx[engine] = ctx; |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static void |
Ben Skeggs | 9318745 | 2011-04-12 15:19:54 +1000 | [diff] [blame^] | 65 | nv50_mpeg_context_del(struct nouveau_channel *chan, int engine) |
Ben Skeggs | c092432 | 2011-04-04 16:10:00 +1000 | [diff] [blame] | 66 | { |
| 67 | struct drm_nouveau_private *dev_priv = chan->dev->dev_private; |
| 68 | struct nouveau_gpuobj *ctx = chan->engctx[engine]; |
| 69 | struct drm_device *dev = chan->dev; |
| 70 | unsigned long flags; |
| 71 | u32 inst, i; |
| 72 | |
| 73 | if (!chan->ramin) |
| 74 | return; |
| 75 | |
| 76 | inst = chan->ramin->vinst >> 12; |
| 77 | inst |= 0x80000000; |
| 78 | |
| 79 | spin_lock_irqsave(&dev_priv->context_switch_lock, flags); |
| 80 | nv_mask(dev, 0x00b32c, 0x00000001, 0x00000000); |
| 81 | if (nv_rd32(dev, 0x00b318) == inst) |
| 82 | nv_mask(dev, 0x00b318, 0x80000000, 0x00000000); |
| 83 | nv_mask(dev, 0x00b32c, 0x00000001, 0x00000001); |
| 84 | spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags); |
| 85 | |
| 86 | for (i = 0x60; i <= 0x74; i += 4) |
| 87 | nv_wo32(chan->ramin, i, 0x00000000); |
| 88 | nouveau_gpuobj_ref(NULL, &ctx); |
| 89 | chan->engctx[engine] = NULL; |
| 90 | } |
| 91 | |
| 92 | static int |
Ben Skeggs | 9318745 | 2011-04-12 15:19:54 +1000 | [diff] [blame^] | 93 | nv50_mpeg_object_new(struct nouveau_channel *chan, int engine, |
Ben Skeggs | c092432 | 2011-04-04 16:10:00 +1000 | [diff] [blame] | 94 | u32 handle, u16 class) |
| 95 | { |
| 96 | struct drm_device *dev = chan->dev; |
| 97 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 98 | struct nouveau_gpuobj *obj = NULL; |
| 99 | int ret; |
| 100 | |
| 101 | ret = nouveau_gpuobj_new(dev, chan, 16, 16, NVOBJ_FLAG_ZERO_FREE, &obj); |
| 102 | if (ret) |
| 103 | return ret; |
| 104 | obj->engine = 2; |
| 105 | obj->class = class; |
| 106 | |
| 107 | nv_wo32(obj, 0x00, class); |
| 108 | nv_wo32(obj, 0x04, 0x00000000); |
| 109 | nv_wo32(obj, 0x08, 0x00000000); |
| 110 | nv_wo32(obj, 0x0c, 0x00000000); |
| 111 | dev_priv->engine.instmem.flush(dev); |
| 112 | |
| 113 | ret = nouveau_ramht_insert(chan, handle, obj); |
| 114 | nouveau_gpuobj_ref(NULL, &obj); |
| 115 | return ret; |
| 116 | } |
| 117 | |
| 118 | static void |
Ben Skeggs | 9318745 | 2011-04-12 15:19:54 +1000 | [diff] [blame^] | 119 | nv50_mpeg_tlb_flush(struct drm_device *dev, int engine) |
Ben Skeggs | c092432 | 2011-04-04 16:10:00 +1000 | [diff] [blame] | 120 | { |
| 121 | nv50_vm_flush_engine(dev, 0x08); |
| 122 | } |
| 123 | |
| 124 | static int |
Ben Skeggs | 9318745 | 2011-04-12 15:19:54 +1000 | [diff] [blame^] | 125 | nv50_mpeg_init(struct drm_device *dev, int engine) |
Ben Skeggs | c092432 | 2011-04-04 16:10:00 +1000 | [diff] [blame] | 126 | { |
| 127 | nv_wr32(dev, 0x00b32c, 0x00000000); |
| 128 | nv_wr32(dev, 0x00b314, 0x00000100); |
| 129 | nv_wr32(dev, 0x00b0e0, 0x0000001a); |
| 130 | |
| 131 | nv_wr32(dev, 0x00b220, 0x00000044); |
| 132 | nv_wr32(dev, 0x00b300, 0x00801ec1); |
| 133 | nv_wr32(dev, 0x00b390, 0x00000000); |
| 134 | nv_wr32(dev, 0x00b394, 0x00000000); |
| 135 | nv_wr32(dev, 0x00b398, 0x00000000); |
| 136 | nv_mask(dev, 0x00b32c, 0x00000001, 0x00000001); |
| 137 | |
| 138 | nv_wr32(dev, 0x00b100, 0xffffffff); |
| 139 | nv_wr32(dev, 0x00b140, 0xffffffff); |
| 140 | |
| 141 | if (!nv_wait(dev, 0x00b200, 0x00000001, 0x00000000)) { |
| 142 | NV_ERROR(dev, "PMPEG init: 0x%08x\n", nv_rd32(dev, 0x00b200)); |
| 143 | return -EBUSY; |
| 144 | } |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | static int |
Ben Skeggs | 9318745 | 2011-04-12 15:19:54 +1000 | [diff] [blame^] | 150 | nv50_mpeg_fini(struct drm_device *dev, int engine) |
Ben Skeggs | c092432 | 2011-04-04 16:10:00 +1000 | [diff] [blame] | 151 | { |
| 152 | /*XXX: context save for s/r */ |
| 153 | nv_mask(dev, 0x00b32c, 0x00000001, 0x00000000); |
| 154 | nv_wr32(dev, 0x00b140, 0x00000000); |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | static void |
Ben Skeggs | 9318745 | 2011-04-12 15:19:54 +1000 | [diff] [blame^] | 159 | nv50_mpeg_isr(struct drm_device *dev) |
Ben Skeggs | c092432 | 2011-04-04 16:10:00 +1000 | [diff] [blame] | 160 | { |
| 161 | u32 stat = nv_rd32(dev, 0x00b100); |
| 162 | u32 type = nv_rd32(dev, 0x00b230); |
| 163 | u32 mthd = nv_rd32(dev, 0x00b234); |
| 164 | u32 data = nv_rd32(dev, 0x00b238); |
| 165 | u32 show = stat; |
| 166 | |
| 167 | if (stat & 0x01000000) { |
| 168 | /* happens on initial binding of the object */ |
| 169 | if (type == 0x00000020 && mthd == 0x0000) { |
| 170 | nv_wr32(dev, 0x00b308, 0x00000100); |
| 171 | show &= ~0x01000000; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | if (show && nouveau_ratelimit()) { |
| 176 | NV_INFO(dev, "PMPEG - 0x%08x 0x%08x 0x%08x 0x%08x\n", |
| 177 | stat, type, mthd, data); |
| 178 | } |
| 179 | |
| 180 | nv_wr32(dev, 0x00b100, stat); |
| 181 | nv_wr32(dev, 0x00b230, 0x00000001); |
| 182 | nv50_fb_vm_trap(dev, 1); |
| 183 | } |
| 184 | |
| 185 | static void |
Ben Skeggs | 9318745 | 2011-04-12 15:19:54 +1000 | [diff] [blame^] | 186 | nv50_mpeg_destroy(struct drm_device *dev, int engine) |
Ben Skeggs | c092432 | 2011-04-04 16:10:00 +1000 | [diff] [blame] | 187 | { |
Ben Skeggs | 9318745 | 2011-04-12 15:19:54 +1000 | [diff] [blame^] | 188 | struct nv50_mpeg_engine *pmpeg = nv_engine(dev, engine); |
Ben Skeggs | c092432 | 2011-04-04 16:10:00 +1000 | [diff] [blame] | 189 | |
| 190 | nouveau_irq_unregister(dev, 0); |
| 191 | |
| 192 | NVOBJ_ENGINE_DEL(dev, MPEG); |
| 193 | kfree(pmpeg); |
| 194 | } |
| 195 | |
| 196 | int |
Ben Skeggs | 9318745 | 2011-04-12 15:19:54 +1000 | [diff] [blame^] | 197 | nv50_mpeg_create(struct drm_device *dev) |
Ben Skeggs | c092432 | 2011-04-04 16:10:00 +1000 | [diff] [blame] | 198 | { |
Ben Skeggs | 9318745 | 2011-04-12 15:19:54 +1000 | [diff] [blame^] | 199 | struct nv50_mpeg_engine *pmpeg; |
Ben Skeggs | c092432 | 2011-04-04 16:10:00 +1000 | [diff] [blame] | 200 | |
| 201 | pmpeg = kzalloc(sizeof(*pmpeg), GFP_KERNEL); |
| 202 | if (!pmpeg) |
| 203 | return -ENOMEM; |
| 204 | |
Ben Skeggs | 9318745 | 2011-04-12 15:19:54 +1000 | [diff] [blame^] | 205 | pmpeg->base.destroy = nv50_mpeg_destroy; |
| 206 | pmpeg->base.init = nv50_mpeg_init; |
| 207 | pmpeg->base.fini = nv50_mpeg_fini; |
| 208 | pmpeg->base.context_new = nv50_mpeg_context_new; |
| 209 | pmpeg->base.context_del = nv50_mpeg_context_del; |
| 210 | pmpeg->base.object_new = nv50_mpeg_object_new; |
| 211 | pmpeg->base.tlb_flush = nv50_mpeg_tlb_flush; |
Ben Skeggs | c092432 | 2011-04-04 16:10:00 +1000 | [diff] [blame] | 212 | |
Ben Skeggs | 9318745 | 2011-04-12 15:19:54 +1000 | [diff] [blame^] | 213 | nouveau_irq_register(dev, 0, nv50_mpeg_isr); |
Ben Skeggs | c092432 | 2011-04-04 16:10:00 +1000 | [diff] [blame] | 214 | |
| 215 | NVOBJ_ENGINE_ADD(dev, MPEG, &pmpeg->base); |
| 216 | NVOBJ_CLASS(dev, 0x8274, MPEG); |
| 217 | return 0; |
| 218 | |
| 219 | } |