Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved. |
| 3 | * Copyright 2005 Stephane Marchesin |
| 4 | * |
| 5 | * The Weather Channel (TM) funded Tungsten Graphics to develop the |
| 6 | * initial release of the Radeon 8500 driver under the XFree86 license. |
| 7 | * This notice must be preserved. |
| 8 | * |
| 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | * copy of this software and associated documentation files (the "Software"), |
| 11 | * to deal in the Software without restriction, including without limitation |
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | * and/or sell copies of the Software, and to permit persons to whom the |
| 14 | * Software is furnished to do so, subject to the following conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice (including the next |
| 17 | * paragraph) shall be included in all copies or substantial portions of the |
| 18 | * Software. |
| 19 | * |
| 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 23 | * THE AUTHORS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 24 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 25 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 26 | * DEALINGS IN THE SOFTWARE. |
| 27 | * |
| 28 | * Authors: |
| 29 | * Keith Whitwell <keith@tungstengraphics.com> |
| 30 | */ |
| 31 | |
| 32 | |
| 33 | #include "drmP.h" |
| 34 | #include "drm.h" |
| 35 | #include "drm_sarea.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 36 | |
Francisco Jerez | cbab95db | 2010-10-11 03:43:58 +0200 | [diff] [blame] | 37 | #include "nouveau_drv.h" |
| 38 | #include "nouveau_pm.h" |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 39 | #include "nouveau_mm.h" |
Ben Skeggs | a11c319 | 2010-08-27 10:00:25 +1000 | [diff] [blame] | 40 | #include "nouveau_vm.h" |
Roy Spliet | a845fff | 2010-10-04 23:01:08 +0200 | [diff] [blame] | 41 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 42 | /* |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 43 | * NV10-NV40 tiling helpers |
| 44 | */ |
| 45 | |
| 46 | static void |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 47 | nv10_mem_update_tile_region(struct drm_device *dev, |
| 48 | struct nouveau_tile_reg *tile, uint32_t addr, |
| 49 | uint32_t size, uint32_t pitch, uint32_t flags) |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 50 | { |
| 51 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 52 | struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo; |
| 53 | struct nouveau_fb_engine *pfb = &dev_priv->engine.fb; |
Ben Skeggs | 96c5008 | 2011-04-01 13:10:45 +1000 | [diff] [blame] | 54 | int i = tile - dev_priv->tile.reg, j; |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 55 | unsigned long save; |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 56 | |
Marcin Slusarz | 382d62e | 2010-10-20 21:50:24 +0200 | [diff] [blame] | 57 | nouveau_fence_unref(&tile->fence); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 58 | |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 59 | if (tile->pitch) |
| 60 | pfb->free_tile_region(dev, i); |
| 61 | |
| 62 | if (pitch) |
| 63 | pfb->init_tile_region(dev, i, addr, size, pitch, flags); |
| 64 | |
| 65 | spin_lock_irqsave(&dev_priv->context_switch_lock, save); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 66 | pfifo->reassign(dev, false); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 67 | pfifo->cache_pull(dev, false); |
| 68 | |
| 69 | nouveau_wait_for_idle(dev); |
| 70 | |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 71 | pfb->set_tile_region(dev, i); |
Ben Skeggs | 96c5008 | 2011-04-01 13:10:45 +1000 | [diff] [blame] | 72 | for (j = 0; j < NVOBJ_ENGINE_NR; j++) { |
| 73 | if (dev_priv->eng[j] && dev_priv->eng[j]->set_tile_region) |
| 74 | dev_priv->eng[j]->set_tile_region(dev, i); |
| 75 | } |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 76 | |
| 77 | pfifo->cache_pull(dev, true); |
| 78 | pfifo->reassign(dev, true); |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 79 | spin_unlock_irqrestore(&dev_priv->context_switch_lock, save); |
| 80 | } |
| 81 | |
| 82 | static struct nouveau_tile_reg * |
| 83 | nv10_mem_get_tile_region(struct drm_device *dev, int i) |
| 84 | { |
| 85 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 86 | struct nouveau_tile_reg *tile = &dev_priv->tile.reg[i]; |
| 87 | |
| 88 | spin_lock(&dev_priv->tile.lock); |
| 89 | |
| 90 | if (!tile->used && |
| 91 | (!tile->fence || nouveau_fence_signalled(tile->fence))) |
| 92 | tile->used = true; |
| 93 | else |
| 94 | tile = NULL; |
| 95 | |
| 96 | spin_unlock(&dev_priv->tile.lock); |
| 97 | return tile; |
| 98 | } |
| 99 | |
| 100 | void |
| 101 | nv10_mem_put_tile_region(struct drm_device *dev, struct nouveau_tile_reg *tile, |
| 102 | struct nouveau_fence *fence) |
| 103 | { |
| 104 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 105 | |
| 106 | if (tile) { |
| 107 | spin_lock(&dev_priv->tile.lock); |
| 108 | if (fence) { |
| 109 | /* Mark it as pending. */ |
| 110 | tile->fence = fence; |
| 111 | nouveau_fence_ref(fence); |
| 112 | } |
| 113 | |
| 114 | tile->used = false; |
| 115 | spin_unlock(&dev_priv->tile.lock); |
| 116 | } |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | struct nouveau_tile_reg * |
| 120 | nv10_mem_set_tiling(struct drm_device *dev, uint32_t addr, uint32_t size, |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 121 | uint32_t pitch, uint32_t flags) |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 122 | { |
| 123 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 124 | struct nouveau_fb_engine *pfb = &dev_priv->engine.fb; |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 125 | struct nouveau_tile_reg *tile, *found = NULL; |
| 126 | int i; |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 127 | |
| 128 | for (i = 0; i < pfb->num_tiles; i++) { |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 129 | tile = nv10_mem_get_tile_region(dev, i); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 130 | |
| 131 | if (pitch && !found) { |
Francisco Jerez | 9f56b12 | 2010-09-07 18:24:52 +0200 | [diff] [blame] | 132 | found = tile; |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 133 | continue; |
| 134 | |
| 135 | } else if (tile && tile->pitch) { |
| 136 | /* Kill an unused tile region. */ |
| 137 | nv10_mem_update_tile_region(dev, tile, 0, 0, 0, 0); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 138 | } |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 139 | |
| 140 | nv10_mem_put_tile_region(dev, tile, NULL); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 141 | } |
| 142 | |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 143 | if (found) |
| 144 | nv10_mem_update_tile_region(dev, found, addr, size, |
| 145 | pitch, flags); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 146 | return found; |
| 147 | } |
| 148 | |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 149 | /* |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 150 | * Cleanup everything |
| 151 | */ |
Ben Skeggs | b833ac2 | 2010-06-01 15:32:24 +1000 | [diff] [blame] | 152 | void |
Ben Skeggs | fbd2895e | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 153 | nouveau_mem_vram_fini(struct drm_device *dev) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 154 | { |
| 155 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 156 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 157 | ttm_bo_device_release(&dev_priv->ttm.bdev); |
| 158 | |
| 159 | nouveau_ttm_global_release(dev_priv); |
| 160 | |
Ben Skeggs | fbd2895e | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 161 | if (dev_priv->fb_mtrr >= 0) { |
| 162 | drm_mtrr_del(dev_priv->fb_mtrr, |
| 163 | pci_resource_start(dev->pdev, 1), |
| 164 | pci_resource_len(dev->pdev, 1), DRM_MTRR_WC); |
| 165 | dev_priv->fb_mtrr = -1; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | void |
| 170 | nouveau_mem_gart_fini(struct drm_device *dev) |
| 171 | { |
| 172 | nouveau_sgdma_takedown(dev); |
| 173 | |
Ben Skeggs | cd0b072 | 2010-06-01 15:56:22 +1000 | [diff] [blame] | 174 | if (drm_core_has_AGP(dev) && dev->agp) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 175 | struct drm_agp_mem *entry, *tempe; |
| 176 | |
| 177 | /* Remove AGP resources, but leave dev->agp |
| 178 | intact until drv_cleanup is called. */ |
| 179 | list_for_each_entry_safe(entry, tempe, &dev->agp->memory, head) { |
| 180 | if (entry->bound) |
| 181 | drm_unbind_agp(entry->memory); |
| 182 | drm_free_agp(entry->memory, entry->pages); |
| 183 | kfree(entry); |
| 184 | } |
| 185 | INIT_LIST_HEAD(&dev->agp->memory); |
| 186 | |
| 187 | if (dev->agp->acquired) |
| 188 | drm_agp_release(dev); |
| 189 | |
| 190 | dev->agp->acquired = 0; |
| 191 | dev->agp->enabled = 0; |
| 192 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 193 | } |
| 194 | |
Ben Skeggs | 60d2a88 | 2010-12-06 15:28:54 +1000 | [diff] [blame] | 195 | bool |
| 196 | nouveau_mem_flags_valid(struct drm_device *dev, u32 tile_flags) |
| 197 | { |
| 198 | if (!(tile_flags & NOUVEAU_GEM_TILE_LAYOUT_MASK)) |
| 199 | return true; |
| 200 | |
| 201 | return false; |
| 202 | } |
| 203 | |
Francisco Jerez | 71d0618 | 2010-09-08 02:23:20 +0200 | [diff] [blame] | 204 | #if __OS_HAS_AGP |
| 205 | static unsigned long |
| 206 | get_agp_mode(struct drm_device *dev, unsigned long mode) |
| 207 | { |
| 208 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 209 | |
| 210 | /* |
| 211 | * FW seems to be broken on nv18, it makes the card lock up |
| 212 | * randomly. |
| 213 | */ |
| 214 | if (dev_priv->chipset == 0x18) |
| 215 | mode &= ~PCI_AGP_COMMAND_FW; |
| 216 | |
Francisco Jerez | de5899b | 2010-09-08 02:28:23 +0200 | [diff] [blame] | 217 | /* |
| 218 | * AGP mode set in the command line. |
| 219 | */ |
| 220 | if (nouveau_agpmode > 0) { |
| 221 | bool agpv3 = mode & 0x8; |
| 222 | int rate = agpv3 ? nouveau_agpmode / 4 : nouveau_agpmode; |
| 223 | |
| 224 | mode = (mode & ~0x7) | (rate & 0x7); |
| 225 | } |
| 226 | |
Francisco Jerez | 71d0618 | 2010-09-08 02:23:20 +0200 | [diff] [blame] | 227 | return mode; |
| 228 | } |
| 229 | #endif |
| 230 | |
Francisco Jerez | e04d8e8 | 2010-07-23 20:29:13 +0200 | [diff] [blame] | 231 | int |
| 232 | nouveau_mem_reset_agp(struct drm_device *dev) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 233 | { |
Francisco Jerez | e04d8e8 | 2010-07-23 20:29:13 +0200 | [diff] [blame] | 234 | #if __OS_HAS_AGP |
| 235 | uint32_t saved_pci_nv_1, pmc_enable; |
| 236 | int ret; |
| 237 | |
| 238 | /* First of all, disable fast writes, otherwise if it's |
| 239 | * already enabled in the AGP bridge and we disable the card's |
| 240 | * AGP controller we might be locking ourselves out of it. */ |
Francisco Jerez | 316f60a | 2010-08-26 16:13:49 +0200 | [diff] [blame] | 241 | if ((nv_rd32(dev, NV04_PBUS_PCI_NV_19) | |
| 242 | dev->agp->mode) & PCI_AGP_COMMAND_FW) { |
Francisco Jerez | e04d8e8 | 2010-07-23 20:29:13 +0200 | [diff] [blame] | 243 | struct drm_agp_info info; |
| 244 | struct drm_agp_mode mode; |
| 245 | |
| 246 | ret = drm_agp_info(dev, &info); |
| 247 | if (ret) |
| 248 | return ret; |
| 249 | |
Francisco Jerez | 71d0618 | 2010-09-08 02:23:20 +0200 | [diff] [blame] | 250 | mode.mode = get_agp_mode(dev, info.mode) & ~PCI_AGP_COMMAND_FW; |
Francisco Jerez | e04d8e8 | 2010-07-23 20:29:13 +0200 | [diff] [blame] | 251 | ret = drm_agp_enable(dev, mode); |
| 252 | if (ret) |
| 253 | return ret; |
| 254 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 255 | |
| 256 | saved_pci_nv_1 = nv_rd32(dev, NV04_PBUS_PCI_NV_1); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 257 | |
| 258 | /* clear busmaster bit */ |
| 259 | nv_wr32(dev, NV04_PBUS_PCI_NV_1, saved_pci_nv_1 & ~0x4); |
Francisco Jerez | e04d8e8 | 2010-07-23 20:29:13 +0200 | [diff] [blame] | 260 | /* disable AGP */ |
| 261 | nv_wr32(dev, NV04_PBUS_PCI_NV_19, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 262 | |
| 263 | /* power cycle pgraph, if enabled */ |
| 264 | pmc_enable = nv_rd32(dev, NV03_PMC_ENABLE); |
| 265 | if (pmc_enable & NV_PMC_ENABLE_PGRAPH) { |
| 266 | nv_wr32(dev, NV03_PMC_ENABLE, |
| 267 | pmc_enable & ~NV_PMC_ENABLE_PGRAPH); |
| 268 | nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) | |
| 269 | NV_PMC_ENABLE_PGRAPH); |
| 270 | } |
| 271 | |
| 272 | /* and restore (gives effect of resetting AGP) */ |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 273 | nv_wr32(dev, NV04_PBUS_PCI_NV_1, saved_pci_nv_1); |
Ben Skeggs | b694dfb | 2009-12-15 10:38:32 +1000 | [diff] [blame] | 274 | #endif |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 275 | |
Francisco Jerez | e04d8e8 | 2010-07-23 20:29:13 +0200 | [diff] [blame] | 276 | return 0; |
| 277 | } |
| 278 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 279 | int |
| 280 | nouveau_mem_init_agp(struct drm_device *dev) |
| 281 | { |
Ben Skeggs | b694dfb | 2009-12-15 10:38:32 +1000 | [diff] [blame] | 282 | #if __OS_HAS_AGP |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 283 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 284 | struct drm_agp_info info; |
| 285 | struct drm_agp_mode mode; |
| 286 | int ret; |
| 287 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 288 | if (!dev->agp->acquired) { |
| 289 | ret = drm_agp_acquire(dev); |
| 290 | if (ret) { |
| 291 | NV_ERROR(dev, "Unable to acquire AGP: %d\n", ret); |
| 292 | return ret; |
| 293 | } |
| 294 | } |
| 295 | |
Francisco Jerez | 2b49526 | 2010-07-30 13:57:54 +0200 | [diff] [blame] | 296 | nouveau_mem_reset_agp(dev); |
| 297 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 298 | ret = drm_agp_info(dev, &info); |
| 299 | if (ret) { |
| 300 | NV_ERROR(dev, "Unable to get AGP info: %d\n", ret); |
| 301 | return ret; |
| 302 | } |
| 303 | |
| 304 | /* see agp.h for the AGPSTAT_* modes available */ |
Francisco Jerez | 71d0618 | 2010-09-08 02:23:20 +0200 | [diff] [blame] | 305 | mode.mode = get_agp_mode(dev, info.mode); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 306 | ret = drm_agp_enable(dev, mode); |
| 307 | if (ret) { |
| 308 | NV_ERROR(dev, "Unable to enable AGP: %d\n", ret); |
| 309 | return ret; |
| 310 | } |
| 311 | |
| 312 | dev_priv->gart_info.type = NOUVEAU_GART_AGP; |
| 313 | dev_priv->gart_info.aper_base = info.aperture_base; |
| 314 | dev_priv->gart_info.aper_size = info.aperture_size; |
Ben Skeggs | b694dfb | 2009-12-15 10:38:32 +1000 | [diff] [blame] | 315 | #endif |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 316 | return 0; |
| 317 | } |
| 318 | |
Ben Skeggs | 7ad2d31 | 2011-12-11 00:30:05 +1000 | [diff] [blame] | 319 | static const struct vram_types { |
| 320 | int value; |
| 321 | const char *name; |
| 322 | } vram_type_map[] = { |
| 323 | { NV_MEM_TYPE_STOLEN , "stolen system memory" }, |
| 324 | { NV_MEM_TYPE_SGRAM , "SGRAM" }, |
| 325 | { NV_MEM_TYPE_SDRAM , "SDRAM" }, |
| 326 | { NV_MEM_TYPE_DDR1 , "DDR1" }, |
| 327 | { NV_MEM_TYPE_DDR2 , "DDR2" }, |
| 328 | { NV_MEM_TYPE_DDR3 , "DDR3" }, |
| 329 | { NV_MEM_TYPE_GDDR2 , "GDDR2" }, |
| 330 | { NV_MEM_TYPE_GDDR3 , "GDDR3" }, |
| 331 | { NV_MEM_TYPE_GDDR4 , "GDDR4" }, |
| 332 | { NV_MEM_TYPE_GDDR5 , "GDDR5" }, |
| 333 | { NV_MEM_TYPE_UNKNOWN, "unknown type" } |
| 334 | }; |
| 335 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 336 | int |
Ben Skeggs | fbd2895e | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 337 | nouveau_mem_vram_init(struct drm_device *dev) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 338 | { |
| 339 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 340 | struct ttm_bo_device *bdev = &dev_priv->ttm.bdev; |
Ben Skeggs | 7ad2d31 | 2011-12-11 00:30:05 +1000 | [diff] [blame] | 341 | const struct vram_types *vram_type; |
Ben Skeggs | fbd2895e | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 342 | int ret, dma_bits; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 343 | |
Ben Skeggs | e043512 | 2011-01-11 15:50:26 +1000 | [diff] [blame] | 344 | dma_bits = 32; |
| 345 | if (dev_priv->card_type >= NV_50) { |
| 346 | if (pci_dma_supported(dev->pdev, DMA_BIT_MASK(40))) |
| 347 | dma_bits = 40; |
| 348 | } else |
Jon Mason | 58b6542 | 2011-06-27 16:07:50 +0000 | [diff] [blame] | 349 | if (0 && pci_is_pcie(dev->pdev) && |
Ben Skeggs | 01d1533 | 2011-04-08 10:07:34 +1000 | [diff] [blame] | 350 | dev_priv->chipset > 0x40 && |
Ben Skeggs | e043512 | 2011-01-11 15:50:26 +1000 | [diff] [blame] | 351 | dev_priv->chipset != 0x45) { |
| 352 | if (pci_dma_supported(dev->pdev, DMA_BIT_MASK(39))) |
| 353 | dma_bits = 39; |
| 354 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 355 | |
| 356 | ret = pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(dma_bits)); |
Ben Skeggs | fbd2895e | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 357 | if (ret) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 358 | return ret; |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 359 | ret = pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(dma_bits)); |
| 360 | if (ret) { |
| 361 | /* Reset to default value. */ |
| 362 | pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(32)); |
| 363 | } |
| 364 | |
Ben Skeggs | fbd2895e | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 365 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 366 | ret = nouveau_ttm_global_init(dev_priv); |
| 367 | if (ret) |
| 368 | return ret; |
| 369 | |
| 370 | ret = ttm_bo_device_init(&dev_priv->ttm.bdev, |
| 371 | dev_priv->ttm.bo_global_ref.ref.object, |
| 372 | &nouveau_bo_driver, DRM_FILE_PAGE_OFFSET, |
| 373 | dma_bits <= 32 ? true : false); |
| 374 | if (ret) { |
| 375 | NV_ERROR(dev, "Error initialising bo driver: %d\n", ret); |
| 376 | return ret; |
| 377 | } |
| 378 | |
Ben Skeggs | 7ad2d31 | 2011-12-11 00:30:05 +1000 | [diff] [blame] | 379 | vram_type = vram_type_map; |
| 380 | while (vram_type->value != NV_MEM_TYPE_UNKNOWN) { |
| 381 | if (nouveau_vram_type) { |
| 382 | if (!strcasecmp(nouveau_vram_type, vram_type->name)) |
| 383 | break; |
| 384 | dev_priv->vram_type = vram_type->value; |
| 385 | } else { |
| 386 | if (vram_type->value == dev_priv->vram_type) |
| 387 | break; |
| 388 | } |
| 389 | vram_type++; |
| 390 | } |
| 391 | |
| 392 | NV_INFO(dev, "Detected %dMiB VRAM (%s)\n", |
| 393 | (int)(dev_priv->vram_size >> 20), vram_type->name); |
Ben Skeggs | 60d2a88 | 2010-12-06 15:28:54 +1000 | [diff] [blame] | 394 | if (dev_priv->vram_sys_base) { |
| 395 | NV_INFO(dev, "Stolen system memory at: 0x%010llx\n", |
| 396 | dev_priv->vram_sys_base); |
| 397 | } |
| 398 | |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 399 | dev_priv->fb_available_size = dev_priv->vram_size; |
| 400 | dev_priv->fb_mappable_pages = dev_priv->fb_available_size; |
| 401 | if (dev_priv->fb_mappable_pages > pci_resource_len(dev->pdev, 1)) |
| 402 | dev_priv->fb_mappable_pages = pci_resource_len(dev->pdev, 1); |
| 403 | dev_priv->fb_mappable_pages >>= PAGE_SHIFT; |
| 404 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 405 | dev_priv->fb_available_size -= dev_priv->ramin_rsvd_vram; |
| 406 | dev_priv->fb_aper_free = dev_priv->fb_available_size; |
| 407 | |
| 408 | /* mappable vram */ |
| 409 | ret = ttm_bo_init_mm(bdev, TTM_PL_VRAM, |
| 410 | dev_priv->fb_available_size >> PAGE_SHIFT); |
| 411 | if (ret) { |
| 412 | NV_ERROR(dev, "Failed VRAM mm init: %d\n", ret); |
| 413 | return ret; |
| 414 | } |
| 415 | |
Ben Skeggs | d550c41 | 2011-02-16 08:41:56 +1000 | [diff] [blame] | 416 | if (dev_priv->card_type < NV_50) { |
Ben Skeggs | 7375c95 | 2011-06-07 14:21:29 +1000 | [diff] [blame] | 417 | ret = nouveau_bo_new(dev, 256*1024, 0, TTM_PL_FLAG_VRAM, |
Ben Skeggs | d550c41 | 2011-02-16 08:41:56 +1000 | [diff] [blame] | 418 | 0, 0, &dev_priv->vga_ram); |
| 419 | if (ret == 0) |
| 420 | ret = nouveau_bo_pin(dev_priv->vga_ram, |
| 421 | TTM_PL_FLAG_VRAM); |
| 422 | |
| 423 | if (ret) { |
| 424 | NV_WARN(dev, "failed to reserve VGA memory\n"); |
| 425 | nouveau_bo_ref(NULL, &dev_priv->vga_ram); |
| 426 | } |
Ben Skeggs | ac8fb97 | 2010-01-15 09:24:20 +1000 | [diff] [blame] | 427 | } |
| 428 | |
Ben Skeggs | fbd2895e | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 429 | dev_priv->fb_mtrr = drm_mtrr_add(pci_resource_start(dev->pdev, 1), |
| 430 | pci_resource_len(dev->pdev, 1), |
| 431 | DRM_MTRR_WC); |
| 432 | return 0; |
| 433 | } |
| 434 | |
| 435 | int |
| 436 | nouveau_mem_gart_init(struct drm_device *dev) |
| 437 | { |
| 438 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 439 | struct ttm_bo_device *bdev = &dev_priv->ttm.bdev; |
| 440 | int ret; |
| 441 | |
| 442 | dev_priv->gart_info.type = NOUVEAU_GART_NONE; |
| 443 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 444 | #if !defined(__powerpc__) && !defined(__ia64__) |
Dave Airlie | 8410ea3 | 2010-12-15 03:16:38 +1000 | [diff] [blame] | 445 | if (drm_pci_device_is_agp(dev) && dev->agp && nouveau_agpmode) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 446 | ret = nouveau_mem_init_agp(dev); |
| 447 | if (ret) |
| 448 | NV_ERROR(dev, "Error initialising AGP: %d\n", ret); |
| 449 | } |
| 450 | #endif |
| 451 | |
| 452 | if (dev_priv->gart_info.type == NOUVEAU_GART_NONE) { |
| 453 | ret = nouveau_sgdma_init(dev); |
| 454 | if (ret) { |
| 455 | NV_ERROR(dev, "Error initialising PCI(E): %d\n", ret); |
| 456 | return ret; |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | NV_INFO(dev, "%d MiB GART (aperture)\n", |
| 461 | (int)(dev_priv->gart_info.aper_size >> 20)); |
| 462 | dev_priv->gart_info.aper_free = dev_priv->gart_info.aper_size; |
| 463 | |
| 464 | ret = ttm_bo_init_mm(bdev, TTM_PL_TT, |
| 465 | dev_priv->gart_info.aper_size >> PAGE_SHIFT); |
| 466 | if (ret) { |
| 467 | NV_ERROR(dev, "Failed TT mm init: %d\n", ret); |
| 468 | return ret; |
| 469 | } |
| 470 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 471 | return 0; |
| 472 | } |
| 473 | |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 474 | static int |
| 475 | nv40_mem_timing_calc(struct drm_device *dev, u32 freq, |
| 476 | struct nouveau_pm_tbl_entry *e, u8 len, |
| 477 | struct nouveau_pm_memtiming *boot, |
| 478 | struct nouveau_pm_memtiming *t) |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 479 | { |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 480 | t->reg[0] = (e->tRP << 24 | e->tRAS << 16 | e->tRFC << 8 | e->tRC); |
Roy Spliet | 9a78248 | 2011-07-09 21:18:11 +0200 | [diff] [blame] | 481 | |
| 482 | /* XXX: I don't trust the -1's and +1's... they must come |
| 483 | * from somewhere! */ |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 484 | t->reg[1] = (e->tWR + 2 + (t->tCWL - 1)) << 24 | |
| 485 | 1 << 16 | |
| 486 | (e->tWTR + 2 + (t->tCWL - 1)) << 8 | |
| 487 | (e->tCL + 2 - (t->tCWL - 1)); |
Roy Spliet | bfb3146 | 2011-11-25 15:52:22 +0100 | [diff] [blame] | 488 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 489 | t->reg[2] = 0x20200000 | |
| 490 | ((t->tCWL - 1) << 24 | |
| 491 | e->tRRD << 16 | |
| 492 | e->tRCDWR << 8 | |
| 493 | e->tRCDRD); |
Roy Spliet | 9a78248 | 2011-07-09 21:18:11 +0200 | [diff] [blame] | 494 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 495 | NV_DEBUG(dev, "Entry %d: 220: %08x %08x %08x\n", t->id, |
| 496 | t->reg[0], t->reg[1], t->reg[2]); |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 497 | return 0; |
Roy Spliet | 9a78248 | 2011-07-09 21:18:11 +0200 | [diff] [blame] | 498 | } |
| 499 | |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 500 | static int |
| 501 | nv50_mem_timing_calc(struct drm_device *dev, u32 freq, |
| 502 | struct nouveau_pm_tbl_entry *e, u8 len, |
| 503 | struct nouveau_pm_memtiming *boot, |
| 504 | struct nouveau_pm_memtiming *t) |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 505 | { |
Roy Spliet | 9a78248 | 2011-07-09 21:18:11 +0200 | [diff] [blame] | 506 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 507 | struct bit_entry P; |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 508 | uint8_t unk18 = 1, unk20 = 0, unk21 = 0, tmp7_3; |
Roy Spliet | 9a78248 | 2011-07-09 21:18:11 +0200 | [diff] [blame] | 509 | |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 510 | if (bit_table(dev, 'P', &P)) |
| 511 | return -EINVAL; |
| 512 | |
| 513 | switch (min(len, (u8) 22)) { |
Roy Spliet | 9a78248 | 2011-07-09 21:18:11 +0200 | [diff] [blame] | 514 | case 22: |
| 515 | unk21 = e->tUNK_21; |
| 516 | case 21: |
| 517 | unk20 = e->tUNK_20; |
| 518 | case 20: |
Roy Spliet | bfb3146 | 2011-11-25 15:52:22 +0100 | [diff] [blame] | 519 | if (e->tCWL > 0) |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 520 | t->tCWL = e->tCWL; |
Roy Spliet | 9a78248 | 2011-07-09 21:18:11 +0200 | [diff] [blame] | 521 | case 19: |
| 522 | unk18 = e->tUNK_18; |
| 523 | break; |
| 524 | } |
| 525 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 526 | t->reg[0] = (e->tRP << 24 | e->tRAS << 16 | e->tRFC << 8 | e->tRC); |
Roy Spliet | 9a78248 | 2011-07-09 21:18:11 +0200 | [diff] [blame] | 527 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 528 | t->reg[1] = (e->tWR + 2 + (t->tCWL - 1)) << 24 | |
Roy Spliet | bfb3146 | 2011-11-25 15:52:22 +0100 | [diff] [blame] | 529 | max(unk18, (u8) 1) << 16 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 530 | (e->tWTR + 2 + (t->tCWL - 1)) << 8; |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 531 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 532 | t->reg[2] = ((t->tCWL - 1) << 24 | |
| 533 | e->tRRD << 16 | |
| 534 | e->tRCDWR << 8 | |
| 535 | e->tRCDRD); |
Roy Spliet | 9a78248 | 2011-07-09 21:18:11 +0200 | [diff] [blame] | 536 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 537 | t->reg[4] = e->tUNK_13 << 8 | e->tUNK_13; |
Roy Spliet | bfb3146 | 2011-11-25 15:52:22 +0100 | [diff] [blame] | 538 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 539 | t->reg[5] = (e->tRFC << 24 | max(e->tRCDRD, e->tRCDWR) << 16 | e->tRP); |
Roy Spliet | bfb3146 | 2011-11-25 15:52:22 +0100 | [diff] [blame] | 540 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 541 | t->reg[8] = boot->reg[8] & 0xffffff00; |
Roy Spliet | 9a78248 | 2011-07-09 21:18:11 +0200 | [diff] [blame] | 542 | |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 543 | if (P.version == 1) { |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 544 | t->reg[1] |= (e->tCL + 2 - (t->tCWL - 1)); |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 545 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 546 | t->reg[3] = (0x14 + e->tCL) << 24 | |
| 547 | 0x16 << 16 | |
| 548 | (e->tCL - 1) << 8 | |
| 549 | (e->tCL - 1); |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 550 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 551 | t->reg[4] |= boot->reg[4] & 0xffff0000; |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 552 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 553 | t->reg[6] = (0x33 - t->tCWL) << 16 | |
| 554 | t->tCWL << 8 | |
| 555 | (0x2e + e->tCL - t->tCWL); |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 556 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 557 | t->reg[7] = 0x4000202 | (e->tCL - 1) << 16; |
Roy Spliet | 9a78248 | 2011-07-09 21:18:11 +0200 | [diff] [blame] | 558 | |
Roy Spliet | bfb3146 | 2011-11-25 15:52:22 +0100 | [diff] [blame] | 559 | /* XXX: P.version == 1 only has DDR2 and GDDR3? */ |
| 560 | if (dev_priv->vram_type == NV_MEM_TYPE_DDR2) { |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 561 | t->reg[5] |= (e->tCL + 3) << 8; |
| 562 | t->reg[6] |= (t->tCWL - 2) << 8; |
| 563 | t->reg[8] |= (e->tCL - 4); |
Roy Spliet | bfb3146 | 2011-11-25 15:52:22 +0100 | [diff] [blame] | 564 | } else { |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 565 | t->reg[5] |= (e->tCL + 2) << 8; |
| 566 | t->reg[6] |= t->tCWL << 8; |
| 567 | t->reg[8] |= (e->tCL - 2); |
Roy Spliet | bfb3146 | 2011-11-25 15:52:22 +0100 | [diff] [blame] | 568 | } |
| 569 | } else { |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 570 | t->reg[1] |= (5 + e->tCL - (t->tCWL)); |
Roy Spliet | bfb3146 | 2011-11-25 15:52:22 +0100 | [diff] [blame] | 571 | |
| 572 | /* XXX: 0xb? 0x30? */ |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 573 | t->reg[3] = (0x30 + e->tCL) << 24 | |
| 574 | (boot->reg[3] & 0x00ff0000)| |
| 575 | (0xb + e->tCL) << 8 | |
| 576 | (e->tCL - 1); |
Roy Spliet | bfb3146 | 2011-11-25 15:52:22 +0100 | [diff] [blame] | 577 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 578 | t->reg[4] |= (unk20 << 24 | unk21 << 16); |
Roy Spliet | bfb3146 | 2011-11-25 15:52:22 +0100 | [diff] [blame] | 579 | |
| 580 | /* XXX: +6? */ |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 581 | t->reg[5] |= (t->tCWL + 6) << 8; |
Roy Spliet | bfb3146 | 2011-11-25 15:52:22 +0100 | [diff] [blame] | 582 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 583 | t->reg[6] = (0x5a + e->tCL) << 16 | |
| 584 | (6 - e->tCL + t->tCWL) << 8 | |
| 585 | (0x50 + e->tCL - t->tCWL); |
Roy Spliet | bfb3146 | 2011-11-25 15:52:22 +0100 | [diff] [blame] | 586 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 587 | tmp7_3 = (boot->reg[7] & 0xff000000) >> 24; |
| 588 | t->reg[7] = (tmp7_3 << 24) | |
| 589 | ((tmp7_3 - 6 + e->tCL) << 16) | |
| 590 | 0x202; |
Roy Spliet | 9a78248 | 2011-07-09 21:18:11 +0200 | [diff] [blame] | 591 | } |
| 592 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 593 | NV_DEBUG(dev, "Entry %d: 220: %08x %08x %08x %08x\n", t->id, |
| 594 | t->reg[0], t->reg[1], t->reg[2], t->reg[3]); |
Roy Spliet | 9a78248 | 2011-07-09 21:18:11 +0200 | [diff] [blame] | 595 | NV_DEBUG(dev, " 230: %08x %08x %08x %08x\n", |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 596 | t->reg[4], t->reg[5], t->reg[6], t->reg[7]); |
| 597 | NV_DEBUG(dev, " 240: %08x\n", t->reg[8]); |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 598 | return 0; |
Roy Spliet | 9a78248 | 2011-07-09 21:18:11 +0200 | [diff] [blame] | 599 | } |
| 600 | |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 601 | static int |
| 602 | nvc0_mem_timing_calc(struct drm_device *dev, u32 freq, |
| 603 | struct nouveau_pm_tbl_entry *e, u8 len, |
| 604 | struct nouveau_pm_memtiming *boot, |
| 605 | struct nouveau_pm_memtiming *t) |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 606 | { |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 607 | if (e->tCWL > 0) |
| 608 | t->tCWL = e->tCWL; |
Roy Spliet | bfb3146 | 2011-11-25 15:52:22 +0100 | [diff] [blame] | 609 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 610 | t->reg[0] = (e->tRP << 24 | (e->tRAS & 0x7f) << 17 | |
| 611 | e->tRFC << 8 | e->tRC); |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 612 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 613 | t->reg[1] = (boot->reg[1] & 0xff000000) | |
| 614 | (e->tRCDWR & 0x0f) << 20 | |
| 615 | (e->tRCDRD & 0x0f) << 14 | |
| 616 | (e->tCWL << 7) | |
| 617 | (e->tCL & 0x0f); |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 618 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 619 | t->reg[2] = (boot->reg[2] & 0xff0000ff) | |
| 620 | e->tWR << 16 | e->tWTR << 8; |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 621 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 622 | t->reg[3] = (e->tUNK_20 & 0xf) << 9 | |
| 623 | (e->tUNK_21 & 0xf) << 5 | |
| 624 | (e->tUNK_13 & 0x1f); |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 625 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 626 | t->reg[4] = (boot->reg[4] & 0xfff00fff) | |
| 627 | (e->tRRD&0x1f) << 15; |
Martin Peres | ddb2005 | 2011-12-17 12:24:59 +0100 | [diff] [blame] | 628 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 629 | NV_DEBUG(dev, "Entry %d: 290: %08x %08x %08x %08x\n", t->id, |
| 630 | t->reg[0], t->reg[1], t->reg[2], t->reg[3]); |
| 631 | NV_DEBUG(dev, " 2a0: %08x\n", t->reg[4]); |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 632 | return 0; |
Roy Spliet | bfb3146 | 2011-11-25 15:52:22 +0100 | [diff] [blame] | 633 | } |
| 634 | |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 635 | /** |
| 636 | * MR generation methods |
| 637 | */ |
| 638 | |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 639 | static int |
| 640 | nouveau_mem_ddr2_mr(struct drm_device *dev, u32 freq, |
| 641 | struct nouveau_pm_tbl_entry *e, u8 len, |
| 642 | struct nouveau_pm_memtiming *boot, |
| 643 | struct nouveau_pm_memtiming *t) |
Roy Spliet | bfb3146 | 2011-11-25 15:52:22 +0100 | [diff] [blame] | 644 | { |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 645 | t->drive_strength = 0; |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 646 | if (len < 15) { |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 647 | t->odt = boot->odt; |
| 648 | } else { |
| 649 | t->odt = e->RAM_FT1 & 0x07; |
Roy Spliet | bfb3146 | 2011-11-25 15:52:22 +0100 | [diff] [blame] | 650 | } |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 651 | |
| 652 | if (e->tCL >= NV_MEM_CL_DDR2_MAX) { |
| 653 | NV_WARN(dev, "(%u) Invalid tCL: %u", t->id, e->tCL); |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 654 | return -ERANGE; |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | if (e->tWR >= NV_MEM_WR_DDR2_MAX) { |
| 658 | NV_WARN(dev, "(%u) Invalid tWR: %u", t->id, e->tWR); |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 659 | return -ERANGE; |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | if (t->odt > 3) { |
| 663 | NV_WARN(dev, "(%u) Invalid odt value, assuming disabled: %x", |
| 664 | t->id, t->odt); |
| 665 | t->odt = 0; |
| 666 | } |
| 667 | |
| 668 | t->mr[0] = (boot->mr[0] & 0x100f) | |
| 669 | (e->tCL) << 4 | |
| 670 | (e->tWR - 1) << 9; |
| 671 | t->mr[1] = (boot->mr[1] & 0x101fbb) | |
| 672 | (t->odt & 0x1) << 2 | |
| 673 | (t->odt & 0x2) << 5; |
| 674 | |
| 675 | NV_DEBUG(dev, "(%u) MR: %08x", t->id, t->mr[0]); |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 676 | return 0; |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | uint8_t nv_mem_wr_lut_ddr3[NV_MEM_WR_DDR3_MAX] = { |
| 680 | 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 5, 6, 6, 7, 7, 0, 0}; |
| 681 | |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 682 | static int |
| 683 | nouveau_mem_ddr3_mr(struct drm_device *dev, u32 freq, |
| 684 | struct nouveau_pm_tbl_entry *e, u8 len, |
| 685 | struct nouveau_pm_memtiming *boot, |
| 686 | struct nouveau_pm_memtiming *t) |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 687 | { |
| 688 | u8 cl = e->tCL - 4; |
| 689 | |
| 690 | t->drive_strength = 0; |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 691 | if (len < 15) { |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 692 | t->odt = boot->odt; |
| 693 | } else { |
| 694 | t->odt = e->RAM_FT1 & 0x07; |
| 695 | } |
| 696 | |
| 697 | if (e->tCL >= NV_MEM_CL_DDR3_MAX || e->tCL < 4) { |
| 698 | NV_WARN(dev, "(%u) Invalid tCL: %u", t->id, e->tCL); |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 699 | return -ERANGE; |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | if (e->tWR >= NV_MEM_WR_DDR3_MAX || e->tWR < 4) { |
| 703 | NV_WARN(dev, "(%u) Invalid tWR: %u", t->id, e->tWR); |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 704 | return -ERANGE; |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | if (e->tCWL < 5) { |
| 708 | NV_WARN(dev, "(%u) Invalid tCWL: %u", t->id, e->tCWL); |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 709 | return -ERANGE; |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | t->mr[0] = (boot->mr[0] & 0x180b) | |
| 713 | /* CAS */ |
| 714 | (cl & 0x7) << 4 | |
| 715 | (cl & 0x8) >> 1 | |
| 716 | (nv_mem_wr_lut_ddr3[e->tWR]) << 9; |
| 717 | t->mr[1] = (boot->mr[1] & 0x101dbb) | |
| 718 | (t->odt & 0x1) << 2 | |
| 719 | (t->odt & 0x2) << 5 | |
| 720 | (t->odt & 0x4) << 7; |
| 721 | t->mr[2] = (boot->mr[2] & 0x20ffb7) | (e->tCWL - 5) << 3; |
| 722 | |
| 723 | NV_DEBUG(dev, "(%u) MR: %08x %08x", t->id, t->mr[0], t->mr[2]); |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 724 | return 0; |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | uint8_t nv_mem_cl_lut_gddr3[NV_MEM_CL_GDDR3_MAX] = { |
| 728 | 0, 0, 0, 0, 4, 5, 6, 7, 0, 1, 2, 3, 8, 9, 10, 11}; |
| 729 | uint8_t nv_mem_wr_lut_gddr3[NV_MEM_WR_GDDR3_MAX] = { |
| 730 | 0, 0, 0, 0, 0, 2, 3, 8, 9, 10, 11, 0, 0, 1, 1, 0, 3}; |
| 731 | |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 732 | static int |
| 733 | nouveau_mem_gddr3_mr(struct drm_device *dev, u32 freq, |
| 734 | struct nouveau_pm_tbl_entry *e, u8 len, |
| 735 | struct nouveau_pm_memtiming *boot, |
| 736 | struct nouveau_pm_memtiming *t) |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 737 | { |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 738 | if (len < 15) { |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 739 | t->drive_strength = boot->drive_strength; |
| 740 | t->odt = boot->odt; |
| 741 | } else { |
| 742 | t->drive_strength = (e->RAM_FT1 & 0x30) >> 4; |
| 743 | t->odt = e->RAM_FT1 & 0x07; |
| 744 | } |
| 745 | |
| 746 | if (e->tCL >= NV_MEM_CL_GDDR3_MAX) { |
| 747 | NV_WARN(dev, "(%u) Invalid tCL: %u", t->id, e->tCL); |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 748 | return -ERANGE; |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | if (e->tWR >= NV_MEM_WR_GDDR3_MAX) { |
| 752 | NV_WARN(dev, "(%u) Invalid tWR: %u", t->id, e->tWR); |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 753 | return -ERANGE; |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | if (t->odt > 3) { |
| 757 | NV_WARN(dev, "(%u) Invalid odt value, assuming autocal: %x", |
| 758 | t->id, t->odt); |
| 759 | t->odt = 0; |
| 760 | } |
| 761 | |
| 762 | t->mr[0] = (boot->mr[0] & 0xe0b) | |
| 763 | /* CAS */ |
| 764 | ((nv_mem_cl_lut_gddr3[e->tCL] & 0x7) << 4) | |
| 765 | ((nv_mem_cl_lut_gddr3[e->tCL] & 0x8) >> 2); |
| 766 | t->mr[1] = (boot->mr[1] & 0x100f40) | t->drive_strength | |
| 767 | (t->odt << 2) | |
| 768 | (nv_mem_wr_lut_gddr3[e->tWR] & 0xf) << 4; |
| 769 | |
| 770 | NV_DEBUG(dev, "(%u) MR: %08x %08x", t->id, t->mr[0], t->mr[1]); |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 771 | return 0; |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 772 | } |
| 773 | |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 774 | static int |
| 775 | nouveau_mem_gddr5_mr(struct drm_device *dev, u32 freq, |
| 776 | struct nouveau_pm_tbl_entry *e, u8 len, |
| 777 | struct nouveau_pm_memtiming *boot, |
| 778 | struct nouveau_pm_memtiming *t) |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 779 | { |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 780 | if (len < 15) { |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 781 | t->drive_strength = boot->drive_strength; |
| 782 | t->odt = boot->odt; |
| 783 | } else { |
| 784 | t->drive_strength = (e->RAM_FT1 & 0x30) >> 4; |
| 785 | t->odt = e->RAM_FT1 & 0x03; |
| 786 | } |
| 787 | |
| 788 | if (e->tCL >= NV_MEM_CL_GDDR5_MAX) { |
| 789 | NV_WARN(dev, "(%u) Invalid tCL: %u", t->id, e->tCL); |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 790 | return -ERANGE; |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | if (e->tWR >= NV_MEM_WR_GDDR5_MAX) { |
| 794 | NV_WARN(dev, "(%u) Invalid tWR: %u", t->id, e->tWR); |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 795 | return -ERANGE; |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | if (t->odt > 3) { |
| 799 | NV_WARN(dev, "(%u) Invalid odt value, assuming autocal: %x", |
| 800 | t->id, t->odt); |
| 801 | t->odt = 0; |
| 802 | } |
| 803 | |
| 804 | t->mr[0] = (boot->mr[0] & 0x007) | |
| 805 | ((e->tCL - 5) << 3) | |
| 806 | ((e->tWR - 4) << 8); |
| 807 | t->mr[1] = (boot->mr[1] & 0x1007f0) | |
| 808 | t->drive_strength | |
| 809 | (t->odt << 2); |
| 810 | |
| 811 | NV_DEBUG(dev, "(%u) MR: %08x %08x", t->id, t->mr[0], t->mr[1]); |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 812 | return 0; |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 813 | } |
| 814 | |
Ben Skeggs | 085028c | 2012-01-18 09:02:28 +1000 | [diff] [blame] | 815 | int |
| 816 | nouveau_mem_timing_calc(struct drm_device *dev, u32 freq, |
| 817 | struct nouveau_pm_memtiming *t) |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 818 | { |
| 819 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 820 | struct nouveau_pm_engine *pm = &dev_priv->engine.pm; |
Ben Skeggs | 085028c | 2012-01-18 09:02:28 +1000 | [diff] [blame] | 821 | struct nouveau_pm_memtiming *boot = &pm->boot.timing; |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 822 | struct nouveau_pm_tbl_entry *e; |
| 823 | u8 ver, len, *ptr; |
| 824 | int ret; |
| 825 | |
| 826 | ptr = nouveau_perf_timing(dev, freq, &ver, &len); |
Ben Skeggs | 085028c | 2012-01-18 09:02:28 +1000 | [diff] [blame] | 827 | if (!ptr || ptr[0] == 0x00) { |
| 828 | *t = *boot; |
| 829 | return 0; |
| 830 | } |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 831 | e = (struct nouveau_pm_tbl_entry *)ptr; |
| 832 | |
Ben Skeggs | 085028c | 2012-01-18 09:02:28 +1000 | [diff] [blame] | 833 | t->tCWL = boot->tCWL; |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 834 | |
Ben Skeggs | 085028c | 2012-01-18 09:02:28 +1000 | [diff] [blame] | 835 | switch (dev_priv->card_type) { |
| 836 | case NV_40: |
| 837 | ret = nv40_mem_timing_calc(dev, freq, e, len, boot, t); |
| 838 | break; |
| 839 | case NV_50: |
| 840 | ret = nv50_mem_timing_calc(dev, freq, e, len, boot, t); |
| 841 | break; |
| 842 | case NV_C0: |
| 843 | ret = nvc0_mem_timing_calc(dev, freq, e, len, boot, t); |
| 844 | break; |
| 845 | default: |
| 846 | ret = -ENODEV; |
| 847 | break; |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 848 | } |
| 849 | |
Ben Skeggs | 085028c | 2012-01-18 09:02:28 +1000 | [diff] [blame] | 850 | switch (dev_priv->vram_type * !ret) { |
| 851 | case NV_MEM_TYPE_GDDR3: |
| 852 | ret = nouveau_mem_gddr3_mr(dev, freq, e, len, boot, t); |
| 853 | break; |
| 854 | case NV_MEM_TYPE_GDDR5: |
| 855 | ret = nouveau_mem_gddr5_mr(dev, freq, e, len, boot, t); |
| 856 | break; |
| 857 | case NV_MEM_TYPE_DDR2: |
| 858 | ret = nouveau_mem_ddr2_mr(dev, freq, e, len, boot, t); |
| 859 | break; |
| 860 | case NV_MEM_TYPE_DDR3: |
| 861 | ret = nouveau_mem_ddr3_mr(dev, freq, e, len, boot, t); |
| 862 | break; |
| 863 | default: |
| 864 | ret = -EINVAL; |
| 865 | } |
| 866 | |
| 867 | return ret; |
Ben Skeggs | fd99fd6 | 2012-01-17 21:10:58 +1000 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | void |
| 871 | nouveau_mem_timing_read(struct drm_device *dev, struct nouveau_pm_memtiming *t) |
Roy Spliet | c7c039f | 2012-01-09 15:23:07 +1000 | [diff] [blame] | 872 | { |
| 873 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 874 | u32 timing_base, timing_regs, mr_base; |
| 875 | int i; |
| 876 | |
| 877 | if (dev_priv->card_type >= 0xC0) { |
| 878 | timing_base = 0x10f290; |
| 879 | mr_base = 0x10f300; |
| 880 | } else { |
| 881 | timing_base = 0x100220; |
| 882 | mr_base = 0x1002c0; |
| 883 | } |
| 884 | |
| 885 | t->id = -1; |
| 886 | |
| 887 | switch (dev_priv->card_type) { |
| 888 | case NV_50: |
| 889 | timing_regs = 9; |
| 890 | break; |
| 891 | case NV_C0: |
| 892 | case NV_D0: |
| 893 | timing_regs = 5; |
| 894 | break; |
| 895 | case NV_30: |
| 896 | case NV_40: |
| 897 | timing_regs = 3; |
| 898 | break; |
| 899 | default: |
| 900 | timing_regs = 0; |
| 901 | return; |
| 902 | } |
| 903 | for(i = 0; i < timing_regs; i++) |
| 904 | t->reg[i] = nv_rd32(dev, timing_base + (0x04 * i)); |
| 905 | |
| 906 | t->tCWL = 0; |
| 907 | if (dev_priv->card_type < NV_C0) { |
| 908 | t->tCWL = ((nv_rd32(dev, 0x100228) & 0x0f000000) >> 24) + 1; |
| 909 | } |
| 910 | |
| 911 | t->mr[0] = nv_rd32(dev, mr_base); |
| 912 | t->mr[1] = nv_rd32(dev, mr_base + 0x04); |
| 913 | t->mr[2] = nv_rd32(dev, mr_base + 0x20); |
| 914 | t->mr[3] = nv_rd32(dev, mr_base + 0x24); |
| 915 | |
| 916 | t->odt = 0; |
| 917 | t->drive_strength = 0; |
| 918 | |
| 919 | switch (dev_priv->vram_type) { |
| 920 | case NV_MEM_TYPE_DDR3: |
| 921 | t->odt |= (t->mr[1] & 0x200) >> 7; |
| 922 | case NV_MEM_TYPE_DDR2: |
| 923 | t->odt |= (t->mr[1] & 0x04) >> 2 | |
| 924 | (t->mr[1] & 0x40) >> 5; |
| 925 | break; |
| 926 | case NV_MEM_TYPE_GDDR3: |
| 927 | case NV_MEM_TYPE_GDDR5: |
| 928 | t->drive_strength = t->mr[1] & 0x03; |
| 929 | t->odt = (t->mr[1] & 0x0c) >> 2; |
| 930 | break; |
| 931 | default: |
| 932 | break; |
| 933 | } |
| 934 | } |
| 935 | |
Ben Skeggs | c70c41e | 2011-12-13 11:57:55 +1000 | [diff] [blame] | 936 | int |
Ben Skeggs | 2d85bc8 | 2012-01-23 13:12:09 +1000 | [diff] [blame^] | 937 | nouveau_mem_exec(struct nouveau_mem_exec_func *exec, |
| 938 | struct nouveau_pm_level *perflvl) |
| 939 | { |
| 940 | struct drm_nouveau_private *dev_priv = exec->dev->dev_private; |
| 941 | struct nouveau_pm_memtiming *info = &perflvl->timing; |
| 942 | u32 tMRD = 1000, tCKSRE = 0, tCKSRX = 0, tXS = 0, tDLLK = 0; |
| 943 | u32 mr[3] = { info->mr[0], info->mr[1], info->mr[2] }; |
| 944 | u32 mr1_dlloff; |
| 945 | |
| 946 | switch (dev_priv->vram_type) { |
| 947 | case NV_MEM_TYPE_DDR2: |
| 948 | tDLLK = 2000; |
| 949 | mr1_dlloff = 0x00000001; |
| 950 | break; |
| 951 | case NV_MEM_TYPE_DDR3: |
| 952 | tDLLK = 12000; |
| 953 | mr1_dlloff = 0x00000001; |
| 954 | break; |
| 955 | case NV_MEM_TYPE_GDDR3: |
| 956 | tDLLK = 40000; |
| 957 | mr1_dlloff = 0x00000040; |
| 958 | break; |
| 959 | default: |
| 960 | NV_ERROR(exec->dev, "cannot reclock unsupported memtype\n"); |
| 961 | return -ENODEV; |
| 962 | } |
| 963 | |
| 964 | /* fetch current MRs */ |
| 965 | switch (dev_priv->vram_type) { |
| 966 | case NV_MEM_TYPE_DDR3: |
| 967 | mr[2] = exec->mrg(exec, 2); |
| 968 | default: |
| 969 | mr[1] = exec->mrg(exec, 1); |
| 970 | mr[0] = exec->mrg(exec, 0); |
| 971 | break; |
| 972 | } |
| 973 | |
| 974 | /* DLL 'on' -> DLL 'off' mode, disable before entering self-refresh */ |
| 975 | if (!(mr[1] & mr1_dlloff) && (info->mr[1] & mr1_dlloff)) { |
| 976 | exec->precharge(exec); |
| 977 | exec->mrs (exec, 1, mr[1] | mr1_dlloff); |
| 978 | exec->wait(exec, tMRD); |
| 979 | } |
| 980 | |
| 981 | /* enter self-refresh mode */ |
| 982 | exec->precharge(exec); |
| 983 | exec->refresh(exec); |
| 984 | exec->refresh(exec); |
| 985 | exec->refresh_auto(exec, false); |
| 986 | exec->refresh_self(exec, true); |
| 987 | exec->wait(exec, tCKSRE); |
| 988 | |
| 989 | /* modify input clock frequency */ |
| 990 | exec->clock_set(exec); |
| 991 | |
| 992 | /* exit self-refresh mode */ |
| 993 | exec->wait(exec, tCKSRX); |
| 994 | exec->precharge(exec); |
| 995 | exec->refresh_self(exec, false); |
| 996 | exec->refresh_auto(exec, true); |
| 997 | exec->wait(exec, tXS); |
| 998 | |
| 999 | /* update MRs */ |
| 1000 | if (mr[2] != info->mr[2]) { |
| 1001 | exec->mrs (exec, 2, info->mr[2]); |
| 1002 | exec->wait(exec, tMRD); |
| 1003 | } |
| 1004 | |
| 1005 | if (mr[1] != info->mr[1]) { |
| 1006 | exec->mrs (exec, 1, info->mr[1]); |
| 1007 | exec->wait(exec, tMRD); |
| 1008 | } |
| 1009 | |
| 1010 | if (mr[0] != info->mr[0]) { |
| 1011 | exec->mrs (exec, 0, info->mr[0]); |
| 1012 | exec->wait(exec, tMRD); |
| 1013 | } |
| 1014 | |
| 1015 | /* update PFB timing registers */ |
| 1016 | exec->timing_set(exec); |
| 1017 | |
| 1018 | /* DLL reset */ |
| 1019 | if (!(info->mr[1] & mr1_dlloff)) { |
| 1020 | exec->mrs (exec, 0, info->mr[0] | 0x00000100); |
| 1021 | exec->wait(exec, tMRD); |
| 1022 | exec->mrs (exec, 0, info->mr[0] | 0x00000000); |
| 1023 | exec->wait(exec, tMRD); |
| 1024 | exec->wait(exec, tDLLK); |
| 1025 | if (dev_priv->vram_type == NV_MEM_TYPE_GDDR3) |
| 1026 | exec->precharge(exec); |
| 1027 | } |
| 1028 | |
| 1029 | return 0; |
| 1030 | } |
| 1031 | |
| 1032 | int |
Ben Skeggs | c70c41e | 2011-12-13 11:57:55 +1000 | [diff] [blame] | 1033 | nouveau_mem_vbios_type(struct drm_device *dev) |
| 1034 | { |
| 1035 | struct bit_entry M; |
| 1036 | u8 ramcfg = (nv_rd32(dev, 0x101000) & 0x0000003c) >> 2; |
| 1037 | if (!bit_table(dev, 'M', &M) || M.version != 2 || M.length < 5) { |
| 1038 | u8 *table = ROMPTR(dev, M.data[3]); |
| 1039 | if (table && table[0] == 0x10 && ramcfg < table[3]) { |
| 1040 | u8 *entry = table + table[1] + (ramcfg * table[2]); |
| 1041 | switch (entry[0] & 0x0f) { |
| 1042 | case 0: return NV_MEM_TYPE_DDR2; |
| 1043 | case 1: return NV_MEM_TYPE_DDR3; |
| 1044 | case 2: return NV_MEM_TYPE_GDDR3; |
| 1045 | case 3: return NV_MEM_TYPE_GDDR5; |
| 1046 | default: |
| 1047 | break; |
| 1048 | } |
| 1049 | |
| 1050 | } |
| 1051 | } |
| 1052 | return NV_MEM_TYPE_UNKNOWN; |
| 1053 | } |
| 1054 | |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 1055 | static int |
Ben Skeggs | 24f246a | 2011-06-10 13:36:08 +1000 | [diff] [blame] | 1056 | nouveau_vram_manager_init(struct ttm_mem_type_manager *man, unsigned long psize) |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 1057 | { |
Ben Skeggs | 24f246a | 2011-06-10 13:36:08 +1000 | [diff] [blame] | 1058 | /* nothing to do */ |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 1059 | return 0; |
| 1060 | } |
| 1061 | |
| 1062 | static int |
| 1063 | nouveau_vram_manager_fini(struct ttm_mem_type_manager *man) |
| 1064 | { |
Ben Skeggs | 24f246a | 2011-06-10 13:36:08 +1000 | [diff] [blame] | 1065 | /* nothing to do */ |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 1066 | return 0; |
| 1067 | } |
| 1068 | |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 1069 | static inline void |
| 1070 | nouveau_mem_node_cleanup(struct nouveau_mem *node) |
| 1071 | { |
| 1072 | if (node->vma[0].node) { |
| 1073 | nouveau_vm_unmap(&node->vma[0]); |
| 1074 | nouveau_vm_put(&node->vma[0]); |
| 1075 | } |
| 1076 | |
| 1077 | if (node->vma[1].node) { |
| 1078 | nouveau_vm_unmap(&node->vma[1]); |
| 1079 | nouveau_vm_put(&node->vma[1]); |
| 1080 | } |
| 1081 | } |
| 1082 | |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 1083 | static void |
| 1084 | nouveau_vram_manager_del(struct ttm_mem_type_manager *man, |
| 1085 | struct ttm_mem_reg *mem) |
| 1086 | { |
| 1087 | struct drm_nouveau_private *dev_priv = nouveau_bdev(man->bdev); |
Ben Skeggs | 60d2a88 | 2010-12-06 15:28:54 +1000 | [diff] [blame] | 1088 | struct nouveau_vram_engine *vram = &dev_priv->engine.vram; |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 1089 | struct drm_device *dev = dev_priv->dev; |
| 1090 | |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 1091 | nouveau_mem_node_cleanup(mem->mm_node); |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 1092 | vram->put(dev, (struct nouveau_mem **)&mem->mm_node); |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | static int |
| 1096 | nouveau_vram_manager_new(struct ttm_mem_type_manager *man, |
| 1097 | struct ttm_buffer_object *bo, |
| 1098 | struct ttm_placement *placement, |
| 1099 | struct ttm_mem_reg *mem) |
| 1100 | { |
| 1101 | struct drm_nouveau_private *dev_priv = nouveau_bdev(man->bdev); |
Ben Skeggs | 60d2a88 | 2010-12-06 15:28:54 +1000 | [diff] [blame] | 1102 | struct nouveau_vram_engine *vram = &dev_priv->engine.vram; |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 1103 | struct drm_device *dev = dev_priv->dev; |
| 1104 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 1105 | struct nouveau_mem *node; |
Ben Skeggs | 5f6fdca | 2010-11-12 15:13:59 +1000 | [diff] [blame] | 1106 | u32 size_nc = 0; |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 1107 | int ret; |
| 1108 | |
Ben Skeggs | 5f6fdca | 2010-11-12 15:13:59 +1000 | [diff] [blame] | 1109 | if (nvbo->tile_flags & NOUVEAU_GEM_TILE_NONCONTIG) |
Ben Skeggs | f91bac5 | 2011-06-06 14:15:46 +1000 | [diff] [blame] | 1110 | size_nc = 1 << nvbo->page_shift; |
Ben Skeggs | 5f6fdca | 2010-11-12 15:13:59 +1000 | [diff] [blame] | 1111 | |
Ben Skeggs | 60d2a88 | 2010-12-06 15:28:54 +1000 | [diff] [blame] | 1112 | ret = vram->get(dev, mem->num_pages << PAGE_SHIFT, |
| 1113 | mem->page_alignment << PAGE_SHIFT, size_nc, |
Ben Skeggs | 8f7286f | 2011-02-14 09:57:35 +1000 | [diff] [blame] | 1114 | (nvbo->tile_flags >> 8) & 0x3ff, &node); |
Ben Skeggs | ef1b287 | 2011-03-07 17:18:03 +1000 | [diff] [blame] | 1115 | if (ret) { |
| 1116 | mem->mm_node = NULL; |
| 1117 | return (ret == -ENOSPC) ? 0 : ret; |
| 1118 | } |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 1119 | |
Ben Skeggs | f91bac5 | 2011-06-06 14:15:46 +1000 | [diff] [blame] | 1120 | node->page_shift = nvbo->page_shift; |
Ben Skeggs | 4c74eb7 | 2010-11-10 14:10:04 +1000 | [diff] [blame] | 1121 | |
Ben Skeggs | 60d2a88 | 2010-12-06 15:28:54 +1000 | [diff] [blame] | 1122 | mem->mm_node = node; |
| 1123 | mem->start = node->offset >> PAGE_SHIFT; |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 1124 | return 0; |
| 1125 | } |
| 1126 | |
| 1127 | void |
| 1128 | nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix) |
| 1129 | { |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 1130 | struct nouveau_mm *mm = man->priv; |
| 1131 | struct nouveau_mm_node *r; |
Ben Skeggs | 8b464bf | 2011-01-14 15:46:30 +1000 | [diff] [blame] | 1132 | u32 total = 0, free = 0; |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 1133 | |
| 1134 | mutex_lock(&mm->mutex); |
| 1135 | list_for_each_entry(r, &mm->nodes, nl_entry) { |
Ben Skeggs | 8b464bf | 2011-01-14 15:46:30 +1000 | [diff] [blame] | 1136 | printk(KERN_DEBUG "%s %d: 0x%010llx 0x%010llx\n", |
| 1137 | prefix, r->type, ((u64)r->offset << 12), |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 1138 | (((u64)r->offset + r->length) << 12)); |
Ben Skeggs | 8b464bf | 2011-01-14 15:46:30 +1000 | [diff] [blame] | 1139 | |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 1140 | total += r->length; |
Ben Skeggs | 8b464bf | 2011-01-14 15:46:30 +1000 | [diff] [blame] | 1141 | if (!r->type) |
| 1142 | free += r->length; |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 1143 | } |
| 1144 | mutex_unlock(&mm->mutex); |
| 1145 | |
Ben Skeggs | 8b464bf | 2011-01-14 15:46:30 +1000 | [diff] [blame] | 1146 | printk(KERN_DEBUG "%s total: 0x%010llx free: 0x%010llx\n", |
| 1147 | prefix, (u64)total << 12, (u64)free << 12); |
| 1148 | printk(KERN_DEBUG "%s block: 0x%08x\n", |
| 1149 | prefix, mm->block_size << 12); |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | const struct ttm_mem_type_manager_func nouveau_vram_manager = { |
| 1153 | nouveau_vram_manager_init, |
| 1154 | nouveau_vram_manager_fini, |
| 1155 | nouveau_vram_manager_new, |
| 1156 | nouveau_vram_manager_del, |
| 1157 | nouveau_vram_manager_debug |
| 1158 | }; |
Ben Skeggs | 26c0c9e | 2011-02-10 12:59:51 +1000 | [diff] [blame] | 1159 | |
| 1160 | static int |
| 1161 | nouveau_gart_manager_init(struct ttm_mem_type_manager *man, unsigned long psize) |
| 1162 | { |
| 1163 | return 0; |
| 1164 | } |
| 1165 | |
| 1166 | static int |
| 1167 | nouveau_gart_manager_fini(struct ttm_mem_type_manager *man) |
| 1168 | { |
| 1169 | return 0; |
| 1170 | } |
| 1171 | |
| 1172 | static void |
| 1173 | nouveau_gart_manager_del(struct ttm_mem_type_manager *man, |
| 1174 | struct ttm_mem_reg *mem) |
| 1175 | { |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 1176 | nouveau_mem_node_cleanup(mem->mm_node); |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 1177 | kfree(mem->mm_node); |
Marcin Slusarz | 0de53a5 | 2011-06-23 16:35:31 +0200 | [diff] [blame] | 1178 | mem->mm_node = NULL; |
Ben Skeggs | 26c0c9e | 2011-02-10 12:59:51 +1000 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | static int |
| 1182 | nouveau_gart_manager_new(struct ttm_mem_type_manager *man, |
| 1183 | struct ttm_buffer_object *bo, |
| 1184 | struct ttm_placement *placement, |
| 1185 | struct ttm_mem_reg *mem) |
| 1186 | { |
| 1187 | struct drm_nouveau_private *dev_priv = nouveau_bdev(bo->bdev); |
Ben Skeggs | 26c0c9e | 2011-02-10 12:59:51 +1000 | [diff] [blame] | 1188 | struct nouveau_mem *node; |
Ben Skeggs | 26c0c9e | 2011-02-10 12:59:51 +1000 | [diff] [blame] | 1189 | |
| 1190 | if (unlikely((mem->num_pages << PAGE_SHIFT) >= |
| 1191 | dev_priv->gart_info.aper_size)) |
| 1192 | return -ENOMEM; |
| 1193 | |
| 1194 | node = kzalloc(sizeof(*node), GFP_KERNEL); |
| 1195 | if (!node) |
| 1196 | return -ENOMEM; |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 1197 | node->page_shift = 12; |
Ben Skeggs | 26c0c9e | 2011-02-10 12:59:51 +1000 | [diff] [blame] | 1198 | |
Ben Skeggs | 26c0c9e | 2011-02-10 12:59:51 +1000 | [diff] [blame] | 1199 | mem->mm_node = node; |
| 1200 | mem->start = 0; |
| 1201 | return 0; |
| 1202 | } |
| 1203 | |
| 1204 | void |
| 1205 | nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix) |
| 1206 | { |
| 1207 | } |
| 1208 | |
| 1209 | const struct ttm_mem_type_manager_func nouveau_gart_manager = { |
| 1210 | nouveau_gart_manager_init, |
| 1211 | nouveau_gart_manager_fini, |
| 1212 | nouveau_gart_manager_new, |
| 1213 | nouveau_gart_manager_del, |
| 1214 | nouveau_gart_manager_debug |
| 1215 | }; |