Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Ben Skeggs. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining |
| 6 | * a copy of this software and associated documentation files (the |
| 7 | * "Software"), to deal in the Software without restriction, including |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, |
| 9 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 10 | * permit persons to whom the Software is furnished to do so, subject to |
| 11 | * the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice (including the |
| 14 | * next paragraph) shall be included in all copies or substantial |
| 15 | * portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 | * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE |
| 21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #include "drmP.h" |
| 28 | #include "drm.h" |
| 29 | #include "nouveau_drv.h" |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 30 | #include "nouveau_ramht.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 31 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 32 | static void |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 33 | nv50_fifo_playlist_update(struct drm_device *dev) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 34 | { |
| 35 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 36 | struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo; |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 37 | struct nouveau_gpuobj *cur; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 38 | int i, nr; |
| 39 | |
| 40 | NV_DEBUG(dev, "\n"); |
| 41 | |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 42 | cur = pfifo->playlist[pfifo->cur_playlist]; |
| 43 | pfifo->cur_playlist = !pfifo->cur_playlist; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 44 | |
| 45 | /* We never schedule channel 0 or 127 */ |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 46 | for (i = 1, nr = 0; i < 127; i++) { |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 47 | if (dev_priv->fifos[i] && dev_priv->fifos[i]->ramfc) { |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 48 | nv_wo32(cur, (nr * 4), i); |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 49 | nr++; |
| 50 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 51 | } |
Ben Skeggs | f56cb86 | 2010-07-08 11:29:10 +1000 | [diff] [blame] | 52 | dev_priv->engine.instmem.flush(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 53 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 54 | nv_wr32(dev, 0x32f4, cur->vinst >> 12); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 55 | nv_wr32(dev, 0x32ec, nr); |
| 56 | nv_wr32(dev, 0x2500, 0x101); |
| 57 | } |
| 58 | |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 59 | static void |
| 60 | nv50_fifo_channel_enable(struct drm_device *dev, int channel) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 61 | { |
| 62 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 63 | struct nouveau_channel *chan = dev_priv->fifos[channel]; |
| 64 | uint32_t inst; |
| 65 | |
| 66 | NV_DEBUG(dev, "ch%d\n", channel); |
| 67 | |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 68 | if (dev_priv->chipset == 0x50) |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 69 | inst = chan->ramfc->vinst >> 12; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 70 | else |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 71 | inst = chan->ramfc->vinst >> 8; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 72 | |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 73 | nv_wr32(dev, NV50_PFIFO_CTX_TABLE(channel), inst | |
| 74 | NV50_PFIFO_CTX_TABLE_CHANNEL_ENABLED); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | static void |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 78 | nv50_fifo_channel_disable(struct drm_device *dev, int channel) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 79 | { |
| 80 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 81 | uint32_t inst; |
| 82 | |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 83 | NV_DEBUG(dev, "ch%d\n", channel); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 84 | |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 85 | if (dev_priv->chipset == 0x50) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 86 | inst = NV50_PFIFO_CTX_TABLE_INSTANCE_MASK_G80; |
| 87 | else |
| 88 | inst = NV50_PFIFO_CTX_TABLE_INSTANCE_MASK_G84; |
| 89 | nv_wr32(dev, NV50_PFIFO_CTX_TABLE(channel), inst); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static void |
| 93 | nv50_fifo_init_reset(struct drm_device *dev) |
| 94 | { |
| 95 | uint32_t pmc_e = NV_PMC_ENABLE_PFIFO; |
| 96 | |
| 97 | NV_DEBUG(dev, "\n"); |
| 98 | |
| 99 | nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) & ~pmc_e); |
| 100 | nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) | pmc_e); |
| 101 | } |
| 102 | |
| 103 | static void |
| 104 | nv50_fifo_init_intr(struct drm_device *dev) |
| 105 | { |
| 106 | NV_DEBUG(dev, "\n"); |
| 107 | |
| 108 | nv_wr32(dev, NV03_PFIFO_INTR_0, 0xFFFFFFFF); |
| 109 | nv_wr32(dev, NV03_PFIFO_INTR_EN_0, 0xFFFFFFFF); |
| 110 | } |
| 111 | |
| 112 | static void |
| 113 | nv50_fifo_init_context_table(struct drm_device *dev) |
| 114 | { |
| 115 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 116 | int i; |
| 117 | |
| 118 | NV_DEBUG(dev, "\n"); |
| 119 | |
| 120 | for (i = 0; i < NV50_PFIFO_CTX_TABLE__SIZE; i++) { |
| 121 | if (dev_priv->fifos[i]) |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 122 | nv50_fifo_channel_enable(dev, i); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 123 | else |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 124 | nv50_fifo_channel_disable(dev, i); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 125 | } |
| 126 | |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 127 | nv50_fifo_playlist_update(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static void |
| 131 | nv50_fifo_init_regs__nv(struct drm_device *dev) |
| 132 | { |
| 133 | NV_DEBUG(dev, "\n"); |
| 134 | |
| 135 | nv_wr32(dev, 0x250c, 0x6f3cfc34); |
| 136 | } |
| 137 | |
| 138 | static void |
| 139 | nv50_fifo_init_regs(struct drm_device *dev) |
| 140 | { |
| 141 | NV_DEBUG(dev, "\n"); |
| 142 | |
| 143 | nv_wr32(dev, 0x2500, 0); |
| 144 | nv_wr32(dev, 0x3250, 0); |
| 145 | nv_wr32(dev, 0x3220, 0); |
| 146 | nv_wr32(dev, 0x3204, 0); |
| 147 | nv_wr32(dev, 0x3210, 0); |
| 148 | nv_wr32(dev, 0x3270, 0); |
| 149 | |
| 150 | /* Enable dummy channels setup by nv50_instmem.c */ |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 151 | nv50_fifo_channel_enable(dev, 0); |
| 152 | nv50_fifo_channel_enable(dev, 127); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | int |
| 156 | nv50_fifo_init(struct drm_device *dev) |
| 157 | { |
| 158 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 159 | struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 160 | int ret; |
| 161 | |
| 162 | NV_DEBUG(dev, "\n"); |
| 163 | |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 164 | if (pfifo->playlist[0]) { |
| 165 | pfifo->cur_playlist = !pfifo->cur_playlist; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 166 | goto just_reset; |
| 167 | } |
| 168 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 169 | ret = nouveau_gpuobj_new(dev, NULL, 128*4, 0x1000, |
| 170 | NVOBJ_FLAG_ZERO_ALLOC, |
| 171 | &pfifo->playlist[0]); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 172 | if (ret) { |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 173 | NV_ERROR(dev, "error creating playlist 0: %d\n", ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 174 | return ret; |
| 175 | } |
| 176 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 177 | ret = nouveau_gpuobj_new(dev, NULL, 128*4, 0x1000, |
| 178 | NVOBJ_FLAG_ZERO_ALLOC, |
| 179 | &pfifo->playlist[1]); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 180 | if (ret) { |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 181 | nouveau_gpuobj_ref(NULL, &pfifo->playlist[0]); |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 182 | NV_ERROR(dev, "error creating playlist 1: %d\n", ret); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 183 | return ret; |
| 184 | } |
| 185 | |
| 186 | just_reset: |
| 187 | nv50_fifo_init_reset(dev); |
| 188 | nv50_fifo_init_intr(dev); |
| 189 | nv50_fifo_init_context_table(dev); |
| 190 | nv50_fifo_init_regs__nv(dev); |
| 191 | nv50_fifo_init_regs(dev); |
| 192 | dev_priv->engine.fifo.enable(dev); |
| 193 | dev_priv->engine.fifo.reassign(dev, true); |
| 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | void |
| 199 | nv50_fifo_takedown(struct drm_device *dev) |
| 200 | { |
| 201 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 202 | struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 203 | |
| 204 | NV_DEBUG(dev, "\n"); |
| 205 | |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 206 | if (!pfifo->playlist[0]) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 207 | return; |
| 208 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 209 | nouveau_gpuobj_ref(NULL, &pfifo->playlist[0]); |
| 210 | nouveau_gpuobj_ref(NULL, &pfifo->playlist[1]); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | int |
| 214 | nv50_fifo_channel_id(struct drm_device *dev) |
| 215 | { |
| 216 | return nv_rd32(dev, NV03_PFIFO_CACHE1_PUSH1) & |
| 217 | NV50_PFIFO_CACHE1_PUSH1_CHID_MASK; |
| 218 | } |
| 219 | |
| 220 | int |
| 221 | nv50_fifo_create_context(struct nouveau_channel *chan) |
| 222 | { |
| 223 | struct drm_device *dev = chan->dev; |
| 224 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 225 | struct nouveau_gpuobj *ramfc = NULL; |
Maarten Maathuis | ff9e527 | 2010-02-01 20:58:27 +0100 | [diff] [blame] | 226 | unsigned long flags; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 227 | int ret; |
| 228 | |
| 229 | NV_DEBUG(dev, "ch%d\n", chan->id); |
| 230 | |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 231 | if (dev_priv->chipset == 0x50) { |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 232 | ret = nouveau_gpuobj_new_fake(dev, chan->ramin->pinst, |
| 233 | chan->ramin->vinst, 0x100, |
Ben Skeggs | de3a6c0 | 2010-09-01 15:24:30 +1000 | [diff] [blame] | 234 | NVOBJ_FLAG_ZERO_ALLOC | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 235 | NVOBJ_FLAG_ZERO_FREE, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 236 | &chan->ramfc); |
| 237 | if (ret) |
| 238 | return ret; |
| 239 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 240 | ret = nouveau_gpuobj_new_fake(dev, chan->ramin->pinst + 0x0400, |
| 241 | chan->ramin->vinst + 0x0400, |
| 242 | 4096, 0, &chan->cache); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 243 | if (ret) |
| 244 | return ret; |
| 245 | } else { |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 246 | ret = nouveau_gpuobj_new(dev, chan, 0x100, 256, |
| 247 | NVOBJ_FLAG_ZERO_ALLOC | |
| 248 | NVOBJ_FLAG_ZERO_FREE, &chan->ramfc); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 249 | if (ret) |
| 250 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 251 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 252 | ret = nouveau_gpuobj_new(dev, chan, 4096, 1024, |
| 253 | 0, &chan->cache); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 254 | if (ret) |
| 255 | return ret; |
| 256 | } |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 257 | ramfc = chan->ramfc; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 258 | |
Maarten Maathuis | ff9e527 | 2010-02-01 20:58:27 +0100 | [diff] [blame] | 259 | spin_lock_irqsave(&dev_priv->context_switch_lock, flags); |
| 260 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 261 | nv_wo32(ramfc, 0x48, chan->pushbuf->cinst >> 4); |
Ben Skeggs | e05c5a3 | 2010-09-01 15:24:35 +1000 | [diff] [blame] | 262 | nv_wo32(ramfc, 0x80, ((chan->ramht->bits - 9) << 27) | |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 263 | (4 << 24) /* SEARCH_FULL */ | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 264 | (chan->ramht->gpuobj->cinst >> 4)); |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 265 | nv_wo32(ramfc, 0x44, 0x2101ffff); |
| 266 | nv_wo32(ramfc, 0x60, 0x7fffffff); |
| 267 | nv_wo32(ramfc, 0x40, 0x00000000); |
| 268 | nv_wo32(ramfc, 0x7c, 0x30000001); |
| 269 | nv_wo32(ramfc, 0x78, 0x00000000); |
| 270 | nv_wo32(ramfc, 0x3c, 0x403f6078); |
| 271 | nv_wo32(ramfc, 0x50, chan->pushbuf_base + chan->dma.ib_base * 4); |
| 272 | nv_wo32(ramfc, 0x54, drm_order(chan->dma.ib_max + 1) << 16); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 273 | |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 274 | if (dev_priv->chipset != 0x50) { |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 275 | nv_wo32(chan->ramin, 0, chan->id); |
| 276 | nv_wo32(chan->ramin, 4, chan->ramfc->vinst >> 8); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 277 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 278 | nv_wo32(ramfc, 0x88, chan->cache->vinst >> 10); |
| 279 | nv_wo32(ramfc, 0x98, chan->ramin->vinst >> 12); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 280 | } |
| 281 | |
Ben Skeggs | f56cb86 | 2010-07-08 11:29:10 +1000 | [diff] [blame] | 282 | dev_priv->engine.instmem.flush(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 283 | |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 284 | nv50_fifo_channel_enable(dev, chan->id); |
| 285 | nv50_fifo_playlist_update(dev); |
Maarten Maathuis | ff9e527 | 2010-02-01 20:58:27 +0100 | [diff] [blame] | 286 | spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | void |
| 291 | nv50_fifo_destroy_context(struct nouveau_channel *chan) |
| 292 | { |
| 293 | struct drm_device *dev = chan->dev; |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 294 | struct nouveau_gpuobj *ramfc = NULL; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 295 | |
| 296 | NV_DEBUG(dev, "ch%d\n", chan->id); |
| 297 | |
Maarten Maathuis | a87ff62 | 2010-02-01 18:47:52 +0100 | [diff] [blame] | 298 | /* This will ensure the channel is seen as disabled. */ |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 299 | nouveau_gpuobj_ref(chan->ramfc, &ramfc); |
| 300 | nouveau_gpuobj_ref(NULL, &chan->ramfc); |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 301 | nv50_fifo_channel_disable(dev, chan->id); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 302 | |
| 303 | /* Dummy channel, also used on ch 127 */ |
| 304 | if (chan->id == 0) |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 305 | nv50_fifo_channel_disable(dev, 127); |
| 306 | nv50_fifo_playlist_update(dev); |
Maarten Maathuis | a87ff62 | 2010-02-01 18:47:52 +0100 | [diff] [blame] | 307 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 308 | nouveau_gpuobj_ref(NULL, &ramfc); |
| 309 | nouveau_gpuobj_ref(NULL, &chan->cache); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | int |
| 313 | nv50_fifo_load_context(struct nouveau_channel *chan) |
| 314 | { |
| 315 | struct drm_device *dev = chan->dev; |
| 316 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 317 | struct nouveau_gpuobj *ramfc = chan->ramfc; |
| 318 | struct nouveau_gpuobj *cache = chan->cache; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 319 | int ptr, cnt; |
| 320 | |
| 321 | NV_DEBUG(dev, "ch%d\n", chan->id); |
| 322 | |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 323 | nv_wr32(dev, 0x3330, nv_ro32(ramfc, 0x00)); |
| 324 | nv_wr32(dev, 0x3334, nv_ro32(ramfc, 0x04)); |
| 325 | nv_wr32(dev, 0x3240, nv_ro32(ramfc, 0x08)); |
| 326 | nv_wr32(dev, 0x3320, nv_ro32(ramfc, 0x0c)); |
| 327 | nv_wr32(dev, 0x3244, nv_ro32(ramfc, 0x10)); |
| 328 | nv_wr32(dev, 0x3328, nv_ro32(ramfc, 0x14)); |
| 329 | nv_wr32(dev, 0x3368, nv_ro32(ramfc, 0x18)); |
| 330 | nv_wr32(dev, 0x336c, nv_ro32(ramfc, 0x1c)); |
| 331 | nv_wr32(dev, 0x3370, nv_ro32(ramfc, 0x20)); |
| 332 | nv_wr32(dev, 0x3374, nv_ro32(ramfc, 0x24)); |
| 333 | nv_wr32(dev, 0x3378, nv_ro32(ramfc, 0x28)); |
| 334 | nv_wr32(dev, 0x337c, nv_ro32(ramfc, 0x2c)); |
| 335 | nv_wr32(dev, 0x3228, nv_ro32(ramfc, 0x30)); |
| 336 | nv_wr32(dev, 0x3364, nv_ro32(ramfc, 0x34)); |
| 337 | nv_wr32(dev, 0x32a0, nv_ro32(ramfc, 0x38)); |
| 338 | nv_wr32(dev, 0x3224, nv_ro32(ramfc, 0x3c)); |
| 339 | nv_wr32(dev, 0x324c, nv_ro32(ramfc, 0x40)); |
| 340 | nv_wr32(dev, 0x2044, nv_ro32(ramfc, 0x44)); |
| 341 | nv_wr32(dev, 0x322c, nv_ro32(ramfc, 0x48)); |
| 342 | nv_wr32(dev, 0x3234, nv_ro32(ramfc, 0x4c)); |
| 343 | nv_wr32(dev, 0x3340, nv_ro32(ramfc, 0x50)); |
| 344 | nv_wr32(dev, 0x3344, nv_ro32(ramfc, 0x54)); |
| 345 | nv_wr32(dev, 0x3280, nv_ro32(ramfc, 0x58)); |
| 346 | nv_wr32(dev, 0x3254, nv_ro32(ramfc, 0x5c)); |
| 347 | nv_wr32(dev, 0x3260, nv_ro32(ramfc, 0x60)); |
| 348 | nv_wr32(dev, 0x3264, nv_ro32(ramfc, 0x64)); |
| 349 | nv_wr32(dev, 0x3268, nv_ro32(ramfc, 0x68)); |
| 350 | nv_wr32(dev, 0x326c, nv_ro32(ramfc, 0x6c)); |
| 351 | nv_wr32(dev, 0x32e4, nv_ro32(ramfc, 0x70)); |
| 352 | nv_wr32(dev, 0x3248, nv_ro32(ramfc, 0x74)); |
| 353 | nv_wr32(dev, 0x2088, nv_ro32(ramfc, 0x78)); |
| 354 | nv_wr32(dev, 0x2058, nv_ro32(ramfc, 0x7c)); |
| 355 | nv_wr32(dev, 0x2210, nv_ro32(ramfc, 0x80)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 356 | |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 357 | cnt = nv_ro32(ramfc, 0x84); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 358 | for (ptr = 0; ptr < cnt; ptr++) { |
| 359 | nv_wr32(dev, NV40_PFIFO_CACHE1_METHOD(ptr), |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 360 | nv_ro32(cache, (ptr * 8) + 0)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 361 | nv_wr32(dev, NV40_PFIFO_CACHE1_DATA(ptr), |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 362 | nv_ro32(cache, (ptr * 8) + 4)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 363 | } |
Ben Skeggs | 7fb8ec8 | 2010-01-05 09:41:05 +1000 | [diff] [blame] | 364 | nv_wr32(dev, NV03_PFIFO_CACHE1_PUT, cnt << 2); |
| 365 | nv_wr32(dev, NV03_PFIFO_CACHE1_GET, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 366 | |
| 367 | /* guessing that all the 0x34xx regs aren't on NV50 */ |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 368 | if (dev_priv->chipset != 0x50) { |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 369 | nv_wr32(dev, 0x340c, nv_ro32(ramfc, 0x88)); |
| 370 | nv_wr32(dev, 0x3400, nv_ro32(ramfc, 0x8c)); |
| 371 | nv_wr32(dev, 0x3404, nv_ro32(ramfc, 0x90)); |
| 372 | nv_wr32(dev, 0x3408, nv_ro32(ramfc, 0x94)); |
| 373 | nv_wr32(dev, 0x3410, nv_ro32(ramfc, 0x98)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 374 | } |
| 375 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 376 | nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1, chan->id | (1<<16)); |
| 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | int |
| 381 | nv50_fifo_unload_context(struct drm_device *dev) |
| 382 | { |
| 383 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 384 | struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo; |
| 385 | struct nouveau_gpuobj *ramfc, *cache; |
| 386 | struct nouveau_channel *chan = NULL; |
| 387 | int chid, get, put, ptr; |
| 388 | |
| 389 | NV_DEBUG(dev, "\n"); |
| 390 | |
| 391 | chid = pfifo->channel_id(dev); |
Ben Skeggs | 3c8868d | 2009-12-16 14:51:13 +1000 | [diff] [blame] | 392 | if (chid < 1 || chid >= dev_priv->engine.fifo.channels - 1) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 393 | return 0; |
| 394 | |
| 395 | chan = dev_priv->fifos[chid]; |
| 396 | if (!chan) { |
| 397 | NV_ERROR(dev, "Inactive channel on PFIFO: %d\n", chid); |
| 398 | return -EINVAL; |
| 399 | } |
| 400 | NV_DEBUG(dev, "ch%d\n", chan->id); |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 401 | ramfc = chan->ramfc; |
| 402 | cache = chan->cache; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 403 | |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 404 | nv_wo32(ramfc, 0x00, nv_rd32(dev, 0x3330)); |
| 405 | nv_wo32(ramfc, 0x04, nv_rd32(dev, 0x3334)); |
| 406 | nv_wo32(ramfc, 0x08, nv_rd32(dev, 0x3240)); |
| 407 | nv_wo32(ramfc, 0x0c, nv_rd32(dev, 0x3320)); |
| 408 | nv_wo32(ramfc, 0x10, nv_rd32(dev, 0x3244)); |
| 409 | nv_wo32(ramfc, 0x14, nv_rd32(dev, 0x3328)); |
| 410 | nv_wo32(ramfc, 0x18, nv_rd32(dev, 0x3368)); |
| 411 | nv_wo32(ramfc, 0x1c, nv_rd32(dev, 0x336c)); |
| 412 | nv_wo32(ramfc, 0x20, nv_rd32(dev, 0x3370)); |
| 413 | nv_wo32(ramfc, 0x24, nv_rd32(dev, 0x3374)); |
| 414 | nv_wo32(ramfc, 0x28, nv_rd32(dev, 0x3378)); |
| 415 | nv_wo32(ramfc, 0x2c, nv_rd32(dev, 0x337c)); |
| 416 | nv_wo32(ramfc, 0x30, nv_rd32(dev, 0x3228)); |
| 417 | nv_wo32(ramfc, 0x34, nv_rd32(dev, 0x3364)); |
| 418 | nv_wo32(ramfc, 0x38, nv_rd32(dev, 0x32a0)); |
| 419 | nv_wo32(ramfc, 0x3c, nv_rd32(dev, 0x3224)); |
| 420 | nv_wo32(ramfc, 0x40, nv_rd32(dev, 0x324c)); |
| 421 | nv_wo32(ramfc, 0x44, nv_rd32(dev, 0x2044)); |
| 422 | nv_wo32(ramfc, 0x48, nv_rd32(dev, 0x322c)); |
| 423 | nv_wo32(ramfc, 0x4c, nv_rd32(dev, 0x3234)); |
| 424 | nv_wo32(ramfc, 0x50, nv_rd32(dev, 0x3340)); |
| 425 | nv_wo32(ramfc, 0x54, nv_rd32(dev, 0x3344)); |
| 426 | nv_wo32(ramfc, 0x58, nv_rd32(dev, 0x3280)); |
| 427 | nv_wo32(ramfc, 0x5c, nv_rd32(dev, 0x3254)); |
| 428 | nv_wo32(ramfc, 0x60, nv_rd32(dev, 0x3260)); |
| 429 | nv_wo32(ramfc, 0x64, nv_rd32(dev, 0x3264)); |
| 430 | nv_wo32(ramfc, 0x68, nv_rd32(dev, 0x3268)); |
| 431 | nv_wo32(ramfc, 0x6c, nv_rd32(dev, 0x326c)); |
| 432 | nv_wo32(ramfc, 0x70, nv_rd32(dev, 0x32e4)); |
| 433 | nv_wo32(ramfc, 0x74, nv_rd32(dev, 0x3248)); |
| 434 | nv_wo32(ramfc, 0x78, nv_rd32(dev, 0x2088)); |
| 435 | nv_wo32(ramfc, 0x7c, nv_rd32(dev, 0x2058)); |
| 436 | nv_wo32(ramfc, 0x80, nv_rd32(dev, 0x2210)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 437 | |
| 438 | put = (nv_rd32(dev, NV03_PFIFO_CACHE1_PUT) & 0x7ff) >> 2; |
| 439 | get = (nv_rd32(dev, NV03_PFIFO_CACHE1_GET) & 0x7ff) >> 2; |
| 440 | ptr = 0; |
| 441 | while (put != get) { |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 442 | nv_wo32(cache, ptr + 0, |
| 443 | nv_rd32(dev, NV40_PFIFO_CACHE1_METHOD(get))); |
| 444 | nv_wo32(cache, ptr + 4, |
| 445 | nv_rd32(dev, NV40_PFIFO_CACHE1_DATA(get))); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 446 | get = (get + 1) & 0x1ff; |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 447 | ptr += 8; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | /* guessing that all the 0x34xx regs aren't on NV50 */ |
Ben Skeggs | ac94a34 | 2010-07-08 15:28:48 +1000 | [diff] [blame] | 451 | if (dev_priv->chipset != 0x50) { |
Ben Skeggs | b3beb16 | 2010-09-01 15:24:29 +1000 | [diff] [blame] | 452 | nv_wo32(ramfc, 0x84, ptr >> 3); |
| 453 | nv_wo32(ramfc, 0x88, nv_rd32(dev, 0x340c)); |
| 454 | nv_wo32(ramfc, 0x8c, nv_rd32(dev, 0x3400)); |
| 455 | nv_wo32(ramfc, 0x90, nv_rd32(dev, 0x3404)); |
| 456 | nv_wo32(ramfc, 0x94, nv_rd32(dev, 0x3408)); |
| 457 | nv_wo32(ramfc, 0x98, nv_rd32(dev, 0x3410)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 458 | } |
| 459 | |
Ben Skeggs | f56cb86 | 2010-07-08 11:29:10 +1000 | [diff] [blame] | 460 | dev_priv->engine.instmem.flush(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 461 | |
| 462 | /*XXX: probably reload ch127 (NULL) state back too */ |
| 463 | nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1, 127); |
| 464 | return 0; |
| 465 | } |
| 466 | |