Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 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 | #include "drmP.h" |
| 29 | #include "drm.h" |
Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 30 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 31 | #include "nouveau_drv.h" |
Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 32 | #include "nouveau_vm.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 33 | |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 34 | #define BAR1_VM_BASE 0x0020000000ULL |
| 35 | #define BAR1_VM_SIZE pci_resource_len(dev->pdev, 1) |
| 36 | #define BAR3_VM_BASE 0x0000000000ULL |
| 37 | #define BAR3_VM_SIZE pci_resource_len(dev->pdev, 3) |
| 38 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 39 | struct nv50_instmem_priv { |
| 40 | uint32_t save1700[5]; /* 0x1700->0x1710 */ |
| 41 | |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 42 | struct nouveau_gpuobj *bar1_dmaobj; |
| 43 | struct nouveau_gpuobj *bar3_dmaobj; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 44 | }; |
| 45 | |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 46 | static void |
| 47 | nv50_channel_del(struct nouveau_channel **pchan) |
| 48 | { |
| 49 | struct nouveau_channel *chan; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 50 | |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 51 | chan = *pchan; |
| 52 | *pchan = NULL; |
| 53 | if (!chan) |
| 54 | return; |
| 55 | |
| 56 | nouveau_gpuobj_ref(NULL, &chan->ramfc); |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 57 | nouveau_vm_ref(NULL, &chan->vm, chan->vm_pd); |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 58 | nouveau_gpuobj_ref(NULL, &chan->vm_pd); |
Daniel Vetter | 31a5b8c | 2011-02-18 17:59:11 +0100 | [diff] [blame^] | 59 | if (drm_mm_initialized(&chan->ramin_heap)) |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 60 | drm_mm_takedown(&chan->ramin_heap); |
| 61 | nouveau_gpuobj_ref(NULL, &chan->ramin); |
| 62 | kfree(chan); |
| 63 | } |
| 64 | |
| 65 | static int |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 66 | nv50_channel_new(struct drm_device *dev, u32 size, struct nouveau_vm *vm, |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 67 | struct nouveau_channel **pchan) |
| 68 | { |
| 69 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 70 | u32 pgd = (dev_priv->chipset == 0x50) ? 0x1400 : 0x0200; |
| 71 | u32 fc = (dev_priv->chipset == 0x50) ? 0x0000 : 0x4200; |
| 72 | struct nouveau_channel *chan; |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 73 | int ret, i; |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 74 | |
| 75 | chan = kzalloc(sizeof(*chan), GFP_KERNEL); |
| 76 | if (!chan) |
| 77 | return -ENOMEM; |
| 78 | chan->dev = dev; |
| 79 | |
| 80 | ret = nouveau_gpuobj_new(dev, NULL, size, 0x1000, 0, &chan->ramin); |
| 81 | if (ret) { |
| 82 | nv50_channel_del(&chan); |
| 83 | return ret; |
| 84 | } |
| 85 | |
| 86 | ret = drm_mm_init(&chan->ramin_heap, 0x6000, chan->ramin->size); |
| 87 | if (ret) { |
| 88 | nv50_channel_del(&chan); |
| 89 | return ret; |
| 90 | } |
| 91 | |
| 92 | ret = nouveau_gpuobj_new_fake(dev, chan->ramin->pinst == ~0 ? ~0 : |
| 93 | chan->ramin->pinst + pgd, |
| 94 | chan->ramin->vinst + pgd, |
| 95 | 0x4000, NVOBJ_FLAG_ZERO_ALLOC, |
| 96 | &chan->vm_pd); |
| 97 | if (ret) { |
| 98 | nv50_channel_del(&chan); |
| 99 | return ret; |
| 100 | } |
| 101 | |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 102 | for (i = 0; i < 0x4000; i += 8) { |
| 103 | nv_wo32(chan->vm_pd, i + 0, 0x00000000); |
| 104 | nv_wo32(chan->vm_pd, i + 4, 0xdeadcafe); |
| 105 | } |
| 106 | |
| 107 | ret = nouveau_vm_ref(vm, &chan->vm, chan->vm_pd); |
| 108 | if (ret) { |
| 109 | nv50_channel_del(&chan); |
| 110 | return ret; |
| 111 | } |
| 112 | |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 113 | ret = nouveau_gpuobj_new_fake(dev, chan->ramin->pinst == ~0 ? ~0 : |
| 114 | chan->ramin->pinst + fc, |
| 115 | chan->ramin->vinst + fc, 0x100, |
| 116 | NVOBJ_FLAG_ZERO_ALLOC, &chan->ramfc); |
| 117 | if (ret) { |
| 118 | nv50_channel_del(&chan); |
| 119 | return ret; |
| 120 | } |
| 121 | |
| 122 | *pchan = chan; |
| 123 | return 0; |
| 124 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 125 | |
| 126 | int |
| 127 | nv50_instmem_init(struct drm_device *dev) |
| 128 | { |
| 129 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 130 | struct nv50_instmem_priv *priv; |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 131 | struct nouveau_channel *chan; |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 132 | struct nouveau_vm *vm; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 133 | int ret, i; |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 134 | u32 tmp; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 135 | |
| 136 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 137 | if (!priv) |
| 138 | return -ENOMEM; |
| 139 | dev_priv->engine.instmem.priv = priv; |
| 140 | |
| 141 | /* Save state, will restore at takedown. */ |
| 142 | for (i = 0x1700; i <= 0x1710; i += 4) |
| 143 | priv->save1700[(i-0x1700)/4] = nv_rd32(dev, i); |
| 144 | |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 145 | /* Global PRAMIN heap */ |
| 146 | ret = drm_mm_init(&dev_priv->ramin_heap, 0, dev_priv->ramin_size); |
| 147 | if (ret) { |
| 148 | NV_ERROR(dev, "Failed to init RAMIN heap\n"); |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 149 | goto error; |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 150 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 151 | |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 152 | /* BAR3 */ |
| 153 | ret = nouveau_vm_new(dev, BAR3_VM_BASE, BAR3_VM_SIZE, BAR3_VM_BASE, |
Ben Skeggs | 3ee0128 | 2010-12-15 11:04:39 +1000 | [diff] [blame] | 154 | &dev_priv->bar3_vm); |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 155 | if (ret) |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 156 | goto error; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 157 | |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 158 | ret = nouveau_gpuobj_new(dev, NULL, (BAR3_VM_SIZE >> 12) * 8, |
| 159 | 0x1000, NVOBJ_FLAG_DONT_MAP | |
| 160 | NVOBJ_FLAG_ZERO_ALLOC, |
Ben Skeggs | 3ee0128 | 2010-12-15 11:04:39 +1000 | [diff] [blame] | 161 | &dev_priv->bar3_vm->pgt[0].obj[0]); |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 162 | if (ret) |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 163 | goto error; |
Ben Skeggs | 3ee0128 | 2010-12-15 11:04:39 +1000 | [diff] [blame] | 164 | dev_priv->bar3_vm->pgt[0].refcount[0] = 1; |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 165 | |
Ben Skeggs | 3ee0128 | 2010-12-15 11:04:39 +1000 | [diff] [blame] | 166 | nv50_instmem_map(dev_priv->bar3_vm->pgt[0].obj[0]); |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 167 | |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 168 | ret = nv50_channel_new(dev, 128 * 1024, dev_priv->bar3_vm, &chan); |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 169 | if (ret) |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 170 | goto error; |
| 171 | dev_priv->channels.ptr[0] = dev_priv->channels.ptr[127] = chan; |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 172 | |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 173 | ret = nv50_gpuobj_dma_new(chan, 0x0000, BAR3_VM_BASE, BAR3_VM_SIZE, |
| 174 | NV_MEM_TARGET_VM, NV_MEM_ACCESS_VM, |
| 175 | NV_MEM_TYPE_VM, NV_MEM_COMP_VM, |
| 176 | &priv->bar3_dmaobj); |
| 177 | if (ret) |
| 178 | goto error; |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 179 | |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 180 | nv_wr32(dev, 0x001704, 0x00000000 | (chan->ramin->vinst >> 12)); |
| 181 | nv_wr32(dev, 0x001704, 0x40000000 | (chan->ramin->vinst >> 12)); |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 182 | nv_wr32(dev, 0x00170c, 0x80000000 | (priv->bar3_dmaobj->cinst >> 4)); |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 183 | |
Francisco Jerez | c45aada | 2010-12-16 10:30:35 +1000 | [diff] [blame] | 184 | dev_priv->engine.instmem.flush(dev); |
| 185 | dev_priv->ramin_available = true; |
| 186 | |
| 187 | tmp = nv_ro32(chan->ramin, 0); |
| 188 | nv_wo32(chan->ramin, 0, ~tmp); |
| 189 | if (nv_ro32(chan->ramin, 0) != ~tmp) { |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 190 | NV_ERROR(dev, "PRAMIN readback failed\n"); |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 191 | ret = -EIO; |
| 192 | goto error; |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 193 | } |
Francisco Jerez | c45aada | 2010-12-16 10:30:35 +1000 | [diff] [blame] | 194 | nv_wo32(chan->ramin, 0, tmp); |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 195 | |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 196 | /* BAR1 */ |
Ben Skeggs | 3ee0128 | 2010-12-15 11:04:39 +1000 | [diff] [blame] | 197 | ret = nouveau_vm_new(dev, BAR1_VM_BASE, BAR1_VM_SIZE, BAR1_VM_BASE, &vm); |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 198 | if (ret) |
| 199 | goto error; |
| 200 | |
| 201 | ret = nouveau_vm_ref(vm, &dev_priv->bar1_vm, chan->vm_pd); |
| 202 | if (ret) |
| 203 | goto error; |
| 204 | nouveau_vm_ref(NULL, &vm, NULL); |
| 205 | |
| 206 | ret = nv50_gpuobj_dma_new(chan, 0x0000, BAR1_VM_BASE, BAR1_VM_SIZE, |
| 207 | NV_MEM_TARGET_VM, NV_MEM_ACCESS_VM, |
| 208 | NV_MEM_TYPE_VM, NV_MEM_COMP_VM, |
| 209 | &priv->bar1_dmaobj); |
| 210 | if (ret) |
| 211 | goto error; |
| 212 | |
| 213 | nv_wr32(dev, 0x001708, 0x80000000 | (priv->bar1_dmaobj->cinst >> 4)); |
| 214 | for (i = 0; i < 8; i++) |
| 215 | nv_wr32(dev, 0x1900 + (i*4), 0); |
| 216 | |
Ben Skeggs | b571fe2 | 2010-11-16 10:13:05 +1000 | [diff] [blame] | 217 | /* Create shared channel VM, space is reserved at the beginning |
| 218 | * to catch "NULL pointer" references |
Ben Skeggs | 4c136142 | 2010-11-15 11:54:21 +1000 | [diff] [blame] | 219 | */ |
Ben Skeggs | b571fe2 | 2010-11-16 10:13:05 +1000 | [diff] [blame] | 220 | ret = nouveau_vm_new(dev, 0, (1ULL << 40), 0x0020000000ULL, |
Ben Skeggs | 3ee0128 | 2010-12-15 11:04:39 +1000 | [diff] [blame] | 221 | &dev_priv->chan_vm); |
Ben Skeggs | 4c136142 | 2010-11-15 11:54:21 +1000 | [diff] [blame] | 222 | if (ret) |
| 223 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 224 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 225 | return 0; |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 226 | |
| 227 | error: |
| 228 | nv50_instmem_takedown(dev); |
| 229 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | void |
| 233 | nv50_instmem_takedown(struct drm_device *dev) |
| 234 | { |
| 235 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 236 | struct nv50_instmem_priv *priv = dev_priv->engine.instmem.priv; |
Ben Skeggs | cff5c13 | 2010-10-06 16:16:59 +1000 | [diff] [blame] | 237 | struct nouveau_channel *chan = dev_priv->channels.ptr[0]; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 238 | int i; |
| 239 | |
| 240 | NV_DEBUG(dev, "\n"); |
| 241 | |
| 242 | if (!priv) |
| 243 | return; |
| 244 | |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 245 | dev_priv->ramin_available = false; |
| 246 | |
Ben Skeggs | 4c136142 | 2010-11-15 11:54:21 +1000 | [diff] [blame] | 247 | nouveau_vm_ref(NULL, &dev_priv->chan_vm, NULL); |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 248 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 249 | for (i = 0x1700; i <= 0x1710; i += 4) |
| 250 | nv_wr32(dev, i, priv->save1700[(i - 0x1700) / 4]); |
| 251 | |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 252 | nouveau_gpuobj_ref(NULL, &priv->bar3_dmaobj); |
| 253 | nouveau_gpuobj_ref(NULL, &priv->bar1_dmaobj); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 254 | |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 255 | nouveau_vm_ref(NULL, &dev_priv->bar1_vm, chan->vm_pd); |
| 256 | dev_priv->channels.ptr[127] = 0; |
| 257 | nv50_channel_del(&dev_priv->channels.ptr[0]); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 258 | |
Ben Skeggs | 3ee0128 | 2010-12-15 11:04:39 +1000 | [diff] [blame] | 259 | nouveau_gpuobj_ref(NULL, &dev_priv->bar3_vm->pgt[0].obj[0]); |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 260 | nouveau_vm_ref(NULL, &dev_priv->bar3_vm, NULL); |
| 261 | |
Daniel Vetter | 31a5b8c | 2011-02-18 17:59:11 +0100 | [diff] [blame^] | 262 | if (drm_mm_initialized(&dev_priv->ramin_heap)) |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 263 | drm_mm_takedown(&dev_priv->ramin_heap); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 264 | |
| 265 | dev_priv->engine.instmem.priv = NULL; |
| 266 | kfree(priv); |
| 267 | } |
| 268 | |
| 269 | int |
| 270 | nv50_instmem_suspend(struct drm_device *dev) |
| 271 | { |
| 272 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 273 | |
Ben Skeggs | dc1e5c0 | 2010-10-25 15:23:59 +1000 | [diff] [blame] | 274 | dev_priv->ramin_available = false; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | void |
| 279 | nv50_instmem_resume(struct drm_device *dev) |
| 280 | { |
| 281 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 282 | struct nv50_instmem_priv *priv = dev_priv->engine.instmem.priv; |
Ben Skeggs | cff5c13 | 2010-10-06 16:16:59 +1000 | [diff] [blame] | 283 | struct nouveau_channel *chan = dev_priv->channels.ptr[0]; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 284 | int i; |
| 285 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 286 | /* Poke the relevant regs, and pray it works :) */ |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 287 | nv_wr32(dev, NV50_PUNK_BAR_CFG_BASE, (chan->ramin->vinst >> 12)); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 288 | nv_wr32(dev, NV50_PUNK_UNK1710, 0); |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 289 | nv_wr32(dev, NV50_PUNK_BAR_CFG_BASE, (chan->ramin->vinst >> 12) | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 290 | NV50_PUNK_BAR_CFG_BASE_VALID); |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 291 | nv_wr32(dev, NV50_PUNK_BAR1_CTXDMA, (priv->bar1_dmaobj->cinst >> 4) | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 292 | NV50_PUNK_BAR1_CTXDMA_VALID); |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 293 | nv_wr32(dev, NV50_PUNK_BAR3_CTXDMA, (priv->bar3_dmaobj->cinst >> 4) | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 294 | NV50_PUNK_BAR3_CTXDMA_VALID); |
| 295 | |
| 296 | for (i = 0; i < 8; i++) |
| 297 | nv_wr32(dev, 0x1900 + (i*4), 0); |
Ben Skeggs | dc1e5c0 | 2010-10-25 15:23:59 +1000 | [diff] [blame] | 298 | |
| 299 | dev_priv->ramin_available = true; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 300 | } |
| 301 | |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 302 | struct nv50_gpuobj_node { |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 303 | struct nouveau_vram *vram; |
Ben Skeggs | 34cf01b | 2010-11-22 10:48:51 +1000 | [diff] [blame] | 304 | struct nouveau_vma chan_vma; |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 305 | u32 align; |
| 306 | }; |
| 307 | |
| 308 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 309 | int |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 310 | nv50_instmem_get(struct nouveau_gpuobj *gpuobj, u32 size, u32 align) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 311 | { |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 312 | struct drm_device *dev = gpuobj->dev; |
Ben Skeggs | 34cf01b | 2010-11-22 10:48:51 +1000 | [diff] [blame] | 313 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | 60d2a88 | 2010-12-06 15:28:54 +1000 | [diff] [blame] | 314 | struct nouveau_vram_engine *vram = &dev_priv->engine.vram; |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 315 | struct nv50_gpuobj_node *node = NULL; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 316 | int ret; |
| 317 | |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 318 | node = kzalloc(sizeof(*node), GFP_KERNEL); |
| 319 | if (!node) |
| 320 | return -ENOMEM; |
| 321 | node->align = align; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 322 | |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 323 | size = (size + 4095) & ~4095; |
| 324 | align = max(align, (u32)4096); |
| 325 | |
Ben Skeggs | 60d2a88 | 2010-12-06 15:28:54 +1000 | [diff] [blame] | 326 | ret = vram->get(dev, size, align, 0, 0, &node->vram); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 327 | if (ret) { |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 328 | kfree(node); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 329 | return ret; |
| 330 | } |
| 331 | |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 332 | gpuobj->vinst = node->vram->offset; |
Ben Skeggs | 34cf01b | 2010-11-22 10:48:51 +1000 | [diff] [blame] | 333 | |
| 334 | if (gpuobj->flags & NVOBJ_FLAG_VM) { |
Ben Skeggs | c906ca0 | 2011-01-14 10:27:02 +1000 | [diff] [blame] | 335 | u32 flags = NV_MEM_ACCESS_RW; |
| 336 | if (!(gpuobj->flags & NVOBJ_FLAG_VM_USER)) |
| 337 | flags |= NV_MEM_ACCESS_SYS; |
| 338 | |
| 339 | ret = nouveau_vm_get(dev_priv->chan_vm, size, 12, flags, |
Ben Skeggs | 34cf01b | 2010-11-22 10:48:51 +1000 | [diff] [blame] | 340 | &node->chan_vma); |
| 341 | if (ret) { |
Ben Skeggs | 60d2a88 | 2010-12-06 15:28:54 +1000 | [diff] [blame] | 342 | vram->put(dev, &node->vram); |
Ben Skeggs | 34cf01b | 2010-11-22 10:48:51 +1000 | [diff] [blame] | 343 | kfree(node); |
| 344 | return ret; |
| 345 | } |
| 346 | |
| 347 | nouveau_vm_map(&node->chan_vma, node->vram); |
| 348 | gpuobj->vinst = node->chan_vma.offset; |
| 349 | } |
| 350 | |
| 351 | gpuobj->size = size; |
| 352 | gpuobj->node = node; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 353 | return 0; |
| 354 | } |
| 355 | |
| 356 | void |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 357 | nv50_instmem_put(struct nouveau_gpuobj *gpuobj) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 358 | { |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 359 | struct drm_device *dev = gpuobj->dev; |
Ben Skeggs | 60d2a88 | 2010-12-06 15:28:54 +1000 | [diff] [blame] | 360 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 361 | struct nouveau_vram_engine *vram = &dev_priv->engine.vram; |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 362 | struct nv50_gpuobj_node *node; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 363 | |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 364 | node = gpuobj->node; |
| 365 | gpuobj->node = NULL; |
| 366 | |
Ben Skeggs | 34cf01b | 2010-11-22 10:48:51 +1000 | [diff] [blame] | 367 | if (node->chan_vma.node) { |
| 368 | nouveau_vm_unmap(&node->chan_vma); |
| 369 | nouveau_vm_put(&node->chan_vma); |
| 370 | } |
Ben Skeggs | 60d2a88 | 2010-12-06 15:28:54 +1000 | [diff] [blame] | 371 | vram->put(dev, &node->vram); |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 372 | kfree(node); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | int |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 376 | nv50_instmem_map(struct nouveau_gpuobj *gpuobj) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 377 | { |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 378 | struct drm_nouveau_private *dev_priv = gpuobj->dev->dev_private; |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 379 | struct nv50_gpuobj_node *node = gpuobj->node; |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 380 | int ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 381 | |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 382 | ret = nouveau_vm_get(dev_priv->bar3_vm, gpuobj->size, 12, |
| 383 | NV_MEM_ACCESS_RW, &node->vram->bar_vma); |
| 384 | if (ret) |
| 385 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 386 | |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 387 | nouveau_vm_map(&node->vram->bar_vma, node->vram); |
| 388 | gpuobj->pinst = node->vram->bar_vma.offset; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 389 | return 0; |
| 390 | } |
| 391 | |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 392 | void |
| 393 | nv50_instmem_unmap(struct nouveau_gpuobj *gpuobj) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 394 | { |
Ben Skeggs | e41115d | 2010-11-01 11:45:02 +1000 | [diff] [blame] | 395 | struct nv50_gpuobj_node *node = gpuobj->node; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 396 | |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 397 | if (node->vram->bar_vma.node) { |
| 398 | nouveau_vm_unmap(&node->vram->bar_vma); |
| 399 | nouveau_vm_put(&node->vram->bar_vma); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 400 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | void |
Ben Skeggs | f56cb86 | 2010-07-08 11:29:10 +1000 | [diff] [blame] | 404 | nv50_instmem_flush(struct drm_device *dev) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 405 | { |
Ben Skeggs | 734ee83 | 2010-07-15 11:02:54 +1000 | [diff] [blame] | 406 | nv_wr32(dev, 0x00330c, 0x00000001); |
Francisco Jerez | 4b5c152 | 2010-09-07 17:34:44 +0200 | [diff] [blame] | 407 | if (!nv_wait(dev, 0x00330c, 0x00000002, 0x00000000)) |
Ben Skeggs | 734ee83 | 2010-07-15 11:02:54 +1000 | [diff] [blame] | 408 | NV_ERROR(dev, "PRAMIN flush timeout\n"); |
| 409 | } |
| 410 | |
| 411 | void |
| 412 | nv84_instmem_flush(struct drm_device *dev) |
| 413 | { |
Ben Skeggs | f56cb86 | 2010-07-08 11:29:10 +1000 | [diff] [blame] | 414 | nv_wr32(dev, 0x070000, 0x00000001); |
Francisco Jerez | 4b5c152 | 2010-09-07 17:34:44 +0200 | [diff] [blame] | 415 | if (!nv_wait(dev, 0x070000, 0x00000002, 0x00000000)) |
Ben Skeggs | f56cb86 | 2010-07-08 11:29:10 +1000 | [diff] [blame] | 416 | NV_ERROR(dev, "PRAMIN flush timeout\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 417 | } |
| 418 | |