Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2005 Stephane Marchesin |
| 3 | * Copyright 2008 Stuart Bennett |
| 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice (including the next |
| 14 | * paragraph) shall be included in all copies or substantial portions of the |
| 15 | * Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 21 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 22 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 | * DEALINGS IN THE SOFTWARE. |
| 24 | */ |
| 25 | |
| 26 | #include <linux/swab.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 28 | #include "drmP.h" |
| 29 | #include "drm.h" |
| 30 | #include "drm_sarea.h" |
| 31 | #include "drm_crtc_helper.h" |
| 32 | #include <linux/vgaarb.h> |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 33 | #include <linux/vga_switcheroo.h> |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 34 | |
| 35 | #include "nouveau_drv.h" |
| 36 | #include "nouveau_drm.h" |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 37 | #include "nouveau_fbcon.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 38 | #include "nv50_display.h" |
| 39 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 40 | static void nouveau_stub_takedown(struct drm_device *dev) {} |
| 41 | |
| 42 | static int nouveau_init_engine_ptrs(struct drm_device *dev) |
| 43 | { |
| 44 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 45 | struct nouveau_engine *engine = &dev_priv->engine; |
| 46 | |
| 47 | switch (dev_priv->chipset & 0xf0) { |
| 48 | case 0x00: |
| 49 | engine->instmem.init = nv04_instmem_init; |
| 50 | engine->instmem.takedown = nv04_instmem_takedown; |
| 51 | engine->instmem.suspend = nv04_instmem_suspend; |
| 52 | engine->instmem.resume = nv04_instmem_resume; |
| 53 | engine->instmem.populate = nv04_instmem_populate; |
| 54 | engine->instmem.clear = nv04_instmem_clear; |
| 55 | engine->instmem.bind = nv04_instmem_bind; |
| 56 | engine->instmem.unbind = nv04_instmem_unbind; |
| 57 | engine->instmem.prepare_access = nv04_instmem_prepare_access; |
| 58 | engine->instmem.finish_access = nv04_instmem_finish_access; |
| 59 | engine->mc.init = nv04_mc_init; |
| 60 | engine->mc.takedown = nv04_mc_takedown; |
| 61 | engine->timer.init = nv04_timer_init; |
| 62 | engine->timer.read = nv04_timer_read; |
| 63 | engine->timer.takedown = nv04_timer_takedown; |
| 64 | engine->fb.init = nv04_fb_init; |
| 65 | engine->fb.takedown = nv04_fb_takedown; |
| 66 | engine->graph.grclass = nv04_graph_grclass; |
| 67 | engine->graph.init = nv04_graph_init; |
| 68 | engine->graph.takedown = nv04_graph_takedown; |
| 69 | engine->graph.fifo_access = nv04_graph_fifo_access; |
| 70 | engine->graph.channel = nv04_graph_channel; |
| 71 | engine->graph.create_context = nv04_graph_create_context; |
| 72 | engine->graph.destroy_context = nv04_graph_destroy_context; |
| 73 | engine->graph.load_context = nv04_graph_load_context; |
| 74 | engine->graph.unload_context = nv04_graph_unload_context; |
| 75 | engine->fifo.channels = 16; |
| 76 | engine->fifo.init = nv04_fifo_init; |
| 77 | engine->fifo.takedown = nouveau_stub_takedown; |
| 78 | engine->fifo.disable = nv04_fifo_disable; |
| 79 | engine->fifo.enable = nv04_fifo_enable; |
| 80 | engine->fifo.reassign = nv04_fifo_reassign; |
Francisco Jerez | 588d7d1 | 2009-12-13 20:07:42 +0100 | [diff] [blame] | 81 | engine->fifo.cache_flush = nv04_fifo_cache_flush; |
| 82 | engine->fifo.cache_pull = nv04_fifo_cache_pull; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 83 | engine->fifo.channel_id = nv04_fifo_channel_id; |
| 84 | engine->fifo.create_context = nv04_fifo_create_context; |
| 85 | engine->fifo.destroy_context = nv04_fifo_destroy_context; |
| 86 | engine->fifo.load_context = nv04_fifo_load_context; |
| 87 | engine->fifo.unload_context = nv04_fifo_unload_context; |
| 88 | break; |
| 89 | case 0x10: |
| 90 | engine->instmem.init = nv04_instmem_init; |
| 91 | engine->instmem.takedown = nv04_instmem_takedown; |
| 92 | engine->instmem.suspend = nv04_instmem_suspend; |
| 93 | engine->instmem.resume = nv04_instmem_resume; |
| 94 | engine->instmem.populate = nv04_instmem_populate; |
| 95 | engine->instmem.clear = nv04_instmem_clear; |
| 96 | engine->instmem.bind = nv04_instmem_bind; |
| 97 | engine->instmem.unbind = nv04_instmem_unbind; |
| 98 | engine->instmem.prepare_access = nv04_instmem_prepare_access; |
| 99 | engine->instmem.finish_access = nv04_instmem_finish_access; |
| 100 | engine->mc.init = nv04_mc_init; |
| 101 | engine->mc.takedown = nv04_mc_takedown; |
| 102 | engine->timer.init = nv04_timer_init; |
| 103 | engine->timer.read = nv04_timer_read; |
| 104 | engine->timer.takedown = nv04_timer_takedown; |
| 105 | engine->fb.init = nv10_fb_init; |
| 106 | engine->fb.takedown = nv10_fb_takedown; |
Francisco Jerez | cb00f7c | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 107 | engine->fb.set_region_tiling = nv10_fb_set_region_tiling; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 108 | engine->graph.grclass = nv10_graph_grclass; |
| 109 | engine->graph.init = nv10_graph_init; |
| 110 | engine->graph.takedown = nv10_graph_takedown; |
| 111 | engine->graph.channel = nv10_graph_channel; |
| 112 | engine->graph.create_context = nv10_graph_create_context; |
| 113 | engine->graph.destroy_context = nv10_graph_destroy_context; |
| 114 | engine->graph.fifo_access = nv04_graph_fifo_access; |
| 115 | engine->graph.load_context = nv10_graph_load_context; |
| 116 | engine->graph.unload_context = nv10_graph_unload_context; |
Francisco Jerez | cb00f7c | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 117 | engine->graph.set_region_tiling = nv10_graph_set_region_tiling; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 118 | engine->fifo.channels = 32; |
| 119 | engine->fifo.init = nv10_fifo_init; |
| 120 | engine->fifo.takedown = nouveau_stub_takedown; |
| 121 | engine->fifo.disable = nv04_fifo_disable; |
| 122 | engine->fifo.enable = nv04_fifo_enable; |
| 123 | engine->fifo.reassign = nv04_fifo_reassign; |
Francisco Jerez | 588d7d1 | 2009-12-13 20:07:42 +0100 | [diff] [blame] | 124 | engine->fifo.cache_flush = nv04_fifo_cache_flush; |
| 125 | engine->fifo.cache_pull = nv04_fifo_cache_pull; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 126 | engine->fifo.channel_id = nv10_fifo_channel_id; |
| 127 | engine->fifo.create_context = nv10_fifo_create_context; |
| 128 | engine->fifo.destroy_context = nv10_fifo_destroy_context; |
| 129 | engine->fifo.load_context = nv10_fifo_load_context; |
| 130 | engine->fifo.unload_context = nv10_fifo_unload_context; |
| 131 | break; |
| 132 | case 0x20: |
| 133 | engine->instmem.init = nv04_instmem_init; |
| 134 | engine->instmem.takedown = nv04_instmem_takedown; |
| 135 | engine->instmem.suspend = nv04_instmem_suspend; |
| 136 | engine->instmem.resume = nv04_instmem_resume; |
| 137 | engine->instmem.populate = nv04_instmem_populate; |
| 138 | engine->instmem.clear = nv04_instmem_clear; |
| 139 | engine->instmem.bind = nv04_instmem_bind; |
| 140 | engine->instmem.unbind = nv04_instmem_unbind; |
| 141 | engine->instmem.prepare_access = nv04_instmem_prepare_access; |
| 142 | engine->instmem.finish_access = nv04_instmem_finish_access; |
| 143 | engine->mc.init = nv04_mc_init; |
| 144 | engine->mc.takedown = nv04_mc_takedown; |
| 145 | engine->timer.init = nv04_timer_init; |
| 146 | engine->timer.read = nv04_timer_read; |
| 147 | engine->timer.takedown = nv04_timer_takedown; |
| 148 | engine->fb.init = nv10_fb_init; |
| 149 | engine->fb.takedown = nv10_fb_takedown; |
Francisco Jerez | cb00f7c | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 150 | engine->fb.set_region_tiling = nv10_fb_set_region_tiling; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 151 | engine->graph.grclass = nv20_graph_grclass; |
| 152 | engine->graph.init = nv20_graph_init; |
| 153 | engine->graph.takedown = nv20_graph_takedown; |
| 154 | engine->graph.channel = nv10_graph_channel; |
| 155 | engine->graph.create_context = nv20_graph_create_context; |
| 156 | engine->graph.destroy_context = nv20_graph_destroy_context; |
| 157 | engine->graph.fifo_access = nv04_graph_fifo_access; |
| 158 | engine->graph.load_context = nv20_graph_load_context; |
| 159 | engine->graph.unload_context = nv20_graph_unload_context; |
Francisco Jerez | cb00f7c | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 160 | engine->graph.set_region_tiling = nv20_graph_set_region_tiling; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 161 | engine->fifo.channels = 32; |
| 162 | engine->fifo.init = nv10_fifo_init; |
| 163 | engine->fifo.takedown = nouveau_stub_takedown; |
| 164 | engine->fifo.disable = nv04_fifo_disable; |
| 165 | engine->fifo.enable = nv04_fifo_enable; |
| 166 | engine->fifo.reassign = nv04_fifo_reassign; |
Francisco Jerez | 588d7d1 | 2009-12-13 20:07:42 +0100 | [diff] [blame] | 167 | engine->fifo.cache_flush = nv04_fifo_cache_flush; |
| 168 | engine->fifo.cache_pull = nv04_fifo_cache_pull; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 169 | engine->fifo.channel_id = nv10_fifo_channel_id; |
| 170 | engine->fifo.create_context = nv10_fifo_create_context; |
| 171 | engine->fifo.destroy_context = nv10_fifo_destroy_context; |
| 172 | engine->fifo.load_context = nv10_fifo_load_context; |
| 173 | engine->fifo.unload_context = nv10_fifo_unload_context; |
| 174 | break; |
| 175 | case 0x30: |
| 176 | engine->instmem.init = nv04_instmem_init; |
| 177 | engine->instmem.takedown = nv04_instmem_takedown; |
| 178 | engine->instmem.suspend = nv04_instmem_suspend; |
| 179 | engine->instmem.resume = nv04_instmem_resume; |
| 180 | engine->instmem.populate = nv04_instmem_populate; |
| 181 | engine->instmem.clear = nv04_instmem_clear; |
| 182 | engine->instmem.bind = nv04_instmem_bind; |
| 183 | engine->instmem.unbind = nv04_instmem_unbind; |
| 184 | engine->instmem.prepare_access = nv04_instmem_prepare_access; |
| 185 | engine->instmem.finish_access = nv04_instmem_finish_access; |
| 186 | engine->mc.init = nv04_mc_init; |
| 187 | engine->mc.takedown = nv04_mc_takedown; |
| 188 | engine->timer.init = nv04_timer_init; |
| 189 | engine->timer.read = nv04_timer_read; |
| 190 | engine->timer.takedown = nv04_timer_takedown; |
| 191 | engine->fb.init = nv10_fb_init; |
| 192 | engine->fb.takedown = nv10_fb_takedown; |
Francisco Jerez | cb00f7c | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 193 | engine->fb.set_region_tiling = nv10_fb_set_region_tiling; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 194 | engine->graph.grclass = nv30_graph_grclass; |
| 195 | engine->graph.init = nv30_graph_init; |
| 196 | engine->graph.takedown = nv20_graph_takedown; |
| 197 | engine->graph.fifo_access = nv04_graph_fifo_access; |
| 198 | engine->graph.channel = nv10_graph_channel; |
| 199 | engine->graph.create_context = nv20_graph_create_context; |
| 200 | engine->graph.destroy_context = nv20_graph_destroy_context; |
| 201 | engine->graph.load_context = nv20_graph_load_context; |
| 202 | engine->graph.unload_context = nv20_graph_unload_context; |
Francisco Jerez | cb00f7c | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 203 | engine->graph.set_region_tiling = nv20_graph_set_region_tiling; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 204 | engine->fifo.channels = 32; |
| 205 | engine->fifo.init = nv10_fifo_init; |
| 206 | engine->fifo.takedown = nouveau_stub_takedown; |
| 207 | engine->fifo.disable = nv04_fifo_disable; |
| 208 | engine->fifo.enable = nv04_fifo_enable; |
| 209 | engine->fifo.reassign = nv04_fifo_reassign; |
Francisco Jerez | 588d7d1 | 2009-12-13 20:07:42 +0100 | [diff] [blame] | 210 | engine->fifo.cache_flush = nv04_fifo_cache_flush; |
| 211 | engine->fifo.cache_pull = nv04_fifo_cache_pull; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 212 | engine->fifo.channel_id = nv10_fifo_channel_id; |
| 213 | engine->fifo.create_context = nv10_fifo_create_context; |
| 214 | engine->fifo.destroy_context = nv10_fifo_destroy_context; |
| 215 | engine->fifo.load_context = nv10_fifo_load_context; |
| 216 | engine->fifo.unload_context = nv10_fifo_unload_context; |
| 217 | break; |
| 218 | case 0x40: |
| 219 | case 0x60: |
| 220 | engine->instmem.init = nv04_instmem_init; |
| 221 | engine->instmem.takedown = nv04_instmem_takedown; |
| 222 | engine->instmem.suspend = nv04_instmem_suspend; |
| 223 | engine->instmem.resume = nv04_instmem_resume; |
| 224 | engine->instmem.populate = nv04_instmem_populate; |
| 225 | engine->instmem.clear = nv04_instmem_clear; |
| 226 | engine->instmem.bind = nv04_instmem_bind; |
| 227 | engine->instmem.unbind = nv04_instmem_unbind; |
| 228 | engine->instmem.prepare_access = nv04_instmem_prepare_access; |
| 229 | engine->instmem.finish_access = nv04_instmem_finish_access; |
| 230 | engine->mc.init = nv40_mc_init; |
| 231 | engine->mc.takedown = nv40_mc_takedown; |
| 232 | engine->timer.init = nv04_timer_init; |
| 233 | engine->timer.read = nv04_timer_read; |
| 234 | engine->timer.takedown = nv04_timer_takedown; |
| 235 | engine->fb.init = nv40_fb_init; |
| 236 | engine->fb.takedown = nv40_fb_takedown; |
Francisco Jerez | cb00f7c | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 237 | engine->fb.set_region_tiling = nv40_fb_set_region_tiling; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 238 | engine->graph.grclass = nv40_graph_grclass; |
| 239 | engine->graph.init = nv40_graph_init; |
| 240 | engine->graph.takedown = nv40_graph_takedown; |
| 241 | engine->graph.fifo_access = nv04_graph_fifo_access; |
| 242 | engine->graph.channel = nv40_graph_channel; |
| 243 | engine->graph.create_context = nv40_graph_create_context; |
| 244 | engine->graph.destroy_context = nv40_graph_destroy_context; |
| 245 | engine->graph.load_context = nv40_graph_load_context; |
| 246 | engine->graph.unload_context = nv40_graph_unload_context; |
Francisco Jerez | cb00f7c | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 247 | engine->graph.set_region_tiling = nv40_graph_set_region_tiling; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 248 | engine->fifo.channels = 32; |
| 249 | engine->fifo.init = nv40_fifo_init; |
| 250 | engine->fifo.takedown = nouveau_stub_takedown; |
| 251 | engine->fifo.disable = nv04_fifo_disable; |
| 252 | engine->fifo.enable = nv04_fifo_enable; |
| 253 | engine->fifo.reassign = nv04_fifo_reassign; |
Francisco Jerez | 588d7d1 | 2009-12-13 20:07:42 +0100 | [diff] [blame] | 254 | engine->fifo.cache_flush = nv04_fifo_cache_flush; |
| 255 | engine->fifo.cache_pull = nv04_fifo_cache_pull; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 256 | engine->fifo.channel_id = nv10_fifo_channel_id; |
| 257 | engine->fifo.create_context = nv40_fifo_create_context; |
| 258 | engine->fifo.destroy_context = nv40_fifo_destroy_context; |
| 259 | engine->fifo.load_context = nv40_fifo_load_context; |
| 260 | engine->fifo.unload_context = nv40_fifo_unload_context; |
| 261 | break; |
| 262 | case 0x50: |
| 263 | case 0x80: /* gotta love NVIDIA's consistency.. */ |
| 264 | case 0x90: |
| 265 | case 0xA0: |
| 266 | engine->instmem.init = nv50_instmem_init; |
| 267 | engine->instmem.takedown = nv50_instmem_takedown; |
| 268 | engine->instmem.suspend = nv50_instmem_suspend; |
| 269 | engine->instmem.resume = nv50_instmem_resume; |
| 270 | engine->instmem.populate = nv50_instmem_populate; |
| 271 | engine->instmem.clear = nv50_instmem_clear; |
| 272 | engine->instmem.bind = nv50_instmem_bind; |
| 273 | engine->instmem.unbind = nv50_instmem_unbind; |
| 274 | engine->instmem.prepare_access = nv50_instmem_prepare_access; |
| 275 | engine->instmem.finish_access = nv50_instmem_finish_access; |
| 276 | engine->mc.init = nv50_mc_init; |
| 277 | engine->mc.takedown = nv50_mc_takedown; |
| 278 | engine->timer.init = nv04_timer_init; |
| 279 | engine->timer.read = nv04_timer_read; |
| 280 | engine->timer.takedown = nv04_timer_takedown; |
Marcin KoĆcielnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 281 | engine->fb.init = nv50_fb_init; |
| 282 | engine->fb.takedown = nv50_fb_takedown; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 283 | engine->graph.grclass = nv50_graph_grclass; |
| 284 | engine->graph.init = nv50_graph_init; |
| 285 | engine->graph.takedown = nv50_graph_takedown; |
| 286 | engine->graph.fifo_access = nv50_graph_fifo_access; |
| 287 | engine->graph.channel = nv50_graph_channel; |
| 288 | engine->graph.create_context = nv50_graph_create_context; |
| 289 | engine->graph.destroy_context = nv50_graph_destroy_context; |
| 290 | engine->graph.load_context = nv50_graph_load_context; |
| 291 | engine->graph.unload_context = nv50_graph_unload_context; |
| 292 | engine->fifo.channels = 128; |
| 293 | engine->fifo.init = nv50_fifo_init; |
| 294 | engine->fifo.takedown = nv50_fifo_takedown; |
| 295 | engine->fifo.disable = nv04_fifo_disable; |
| 296 | engine->fifo.enable = nv04_fifo_enable; |
| 297 | engine->fifo.reassign = nv04_fifo_reassign; |
| 298 | engine->fifo.channel_id = nv50_fifo_channel_id; |
| 299 | engine->fifo.create_context = nv50_fifo_create_context; |
| 300 | engine->fifo.destroy_context = nv50_fifo_destroy_context; |
| 301 | engine->fifo.load_context = nv50_fifo_load_context; |
| 302 | engine->fifo.unload_context = nv50_fifo_unload_context; |
| 303 | break; |
| 304 | default: |
| 305 | NV_ERROR(dev, "NV%02x unsupported\n", dev_priv->chipset); |
| 306 | return 1; |
| 307 | } |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | static unsigned int |
| 313 | nouveau_vga_set_decode(void *priv, bool state) |
| 314 | { |
Marcin KoĆcielnicki | 9967b94 | 2010-02-08 00:20:17 +0000 | [diff] [blame] | 315 | struct drm_device *dev = priv; |
| 316 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 317 | |
| 318 | if (dev_priv->chipset >= 0x40) |
| 319 | nv_wr32(dev, 0x88054, state); |
| 320 | else |
| 321 | nv_wr32(dev, 0x1854, state); |
| 322 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 323 | if (state) |
| 324 | return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM | |
| 325 | VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
| 326 | else |
| 327 | return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
| 328 | } |
| 329 | |
Ben Skeggs | 0735f62 | 2009-12-16 14:28:55 +1000 | [diff] [blame] | 330 | static int |
| 331 | nouveau_card_init_channel(struct drm_device *dev) |
| 332 | { |
| 333 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 334 | struct nouveau_gpuobj *gpuobj; |
| 335 | int ret; |
| 336 | |
| 337 | ret = nouveau_channel_alloc(dev, &dev_priv->channel, |
| 338 | (struct drm_file *)-2, |
| 339 | NvDmaFB, NvDmaTT); |
| 340 | if (ret) |
| 341 | return ret; |
| 342 | |
| 343 | gpuobj = NULL; |
| 344 | ret = nouveau_gpuobj_dma_new(dev_priv->channel, NV_CLASS_DMA_IN_MEMORY, |
Ben Skeggs | a76fb4e | 2010-03-18 09:45:20 +1000 | [diff] [blame] | 345 | 0, dev_priv->vram_size, |
Ben Skeggs | 0735f62 | 2009-12-16 14:28:55 +1000 | [diff] [blame] | 346 | NV_DMA_ACCESS_RW, NV_DMA_TARGET_VIDMEM, |
| 347 | &gpuobj); |
| 348 | if (ret) |
| 349 | goto out_err; |
| 350 | |
| 351 | ret = nouveau_gpuobj_ref_add(dev, dev_priv->channel, NvDmaVRAM, |
| 352 | gpuobj, NULL); |
| 353 | if (ret) |
| 354 | goto out_err; |
| 355 | |
| 356 | gpuobj = NULL; |
| 357 | ret = nouveau_gpuobj_gart_dma_new(dev_priv->channel, 0, |
| 358 | dev_priv->gart_info.aper_size, |
| 359 | NV_DMA_ACCESS_RW, &gpuobj, NULL); |
| 360 | if (ret) |
| 361 | goto out_err; |
| 362 | |
| 363 | ret = nouveau_gpuobj_ref_add(dev, dev_priv->channel, NvDmaGART, |
| 364 | gpuobj, NULL); |
| 365 | if (ret) |
| 366 | goto out_err; |
| 367 | |
| 368 | return 0; |
| 369 | out_err: |
| 370 | nouveau_gpuobj_del(dev, &gpuobj); |
| 371 | nouveau_channel_free(dev_priv->channel); |
| 372 | dev_priv->channel = NULL; |
| 373 | return ret; |
| 374 | } |
| 375 | |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 376 | static void nouveau_switcheroo_set_state(struct pci_dev *pdev, |
| 377 | enum vga_switcheroo_state state) |
| 378 | { |
| 379 | pm_message_t pmm = { .event = PM_EVENT_SUSPEND }; |
| 380 | if (state == VGA_SWITCHEROO_ON) { |
| 381 | printk(KERN_ERR "VGA switcheroo: switched nouveau on\n"); |
| 382 | nouveau_pci_resume(pdev); |
| 383 | } else { |
| 384 | printk(KERN_ERR "VGA switcheroo: switched nouveau off\n"); |
| 385 | nouveau_pci_suspend(pdev, pmm); |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev) |
| 390 | { |
| 391 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 392 | bool can_switch; |
| 393 | |
| 394 | spin_lock(&dev->count_lock); |
| 395 | can_switch = (dev->open_count == 0); |
| 396 | spin_unlock(&dev->count_lock); |
| 397 | return can_switch; |
| 398 | } |
| 399 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 400 | int |
| 401 | nouveau_card_init(struct drm_device *dev) |
| 402 | { |
| 403 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 404 | struct nouveau_engine *engine; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 405 | int ret; |
| 406 | |
| 407 | NV_DEBUG(dev, "prev state = %d\n", dev_priv->init_state); |
| 408 | |
| 409 | if (dev_priv->init_state == NOUVEAU_CARD_INIT_DONE) |
| 410 | return 0; |
| 411 | |
| 412 | vga_client_register(dev->pdev, dev, NULL, nouveau_vga_set_decode); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 413 | vga_switcheroo_register_client(dev->pdev, nouveau_switcheroo_set_state, |
| 414 | nouveau_switcheroo_can_switch); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 415 | |
| 416 | /* Initialise internal driver API hooks */ |
| 417 | ret = nouveau_init_engine_ptrs(dev); |
| 418 | if (ret) |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 419 | goto out; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 420 | engine = &dev_priv->engine; |
| 421 | dev_priv->init_state = NOUVEAU_CARD_INIT_FAILED; |
Maarten Maathuis | ff9e527 | 2010-02-01 20:58:27 +0100 | [diff] [blame] | 422 | spin_lock_init(&dev_priv->context_switch_lock); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 423 | |
| 424 | /* Parse BIOS tables / Run init tables if card not POSTed */ |
| 425 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
| 426 | ret = nouveau_bios_init(dev); |
| 427 | if (ret) |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 428 | goto out; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 429 | } |
| 430 | |
Ben Skeggs | a76fb4e | 2010-03-18 09:45:20 +1000 | [diff] [blame] | 431 | ret = nouveau_mem_detect(dev); |
| 432 | if (ret) |
| 433 | goto out_bios; |
| 434 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 435 | ret = nouveau_gpuobj_early_init(dev); |
| 436 | if (ret) |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 437 | goto out_bios; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 438 | |
| 439 | /* Initialise instance memory, must happen before mem_init so we |
| 440 | * know exactly how much VRAM we're able to use for "normal" |
| 441 | * purposes. |
| 442 | */ |
| 443 | ret = engine->instmem.init(dev); |
| 444 | if (ret) |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 445 | goto out_gpuobj_early; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 446 | |
| 447 | /* Setup the memory manager */ |
| 448 | ret = nouveau_mem_init(dev); |
| 449 | if (ret) |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 450 | goto out_instmem; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 451 | |
| 452 | ret = nouveau_gpuobj_init(dev); |
| 453 | if (ret) |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 454 | goto out_mem; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 455 | |
| 456 | /* PMC */ |
| 457 | ret = engine->mc.init(dev); |
| 458 | if (ret) |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 459 | goto out_gpuobj; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 460 | |
| 461 | /* PTIMER */ |
| 462 | ret = engine->timer.init(dev); |
| 463 | if (ret) |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 464 | goto out_mc; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 465 | |
| 466 | /* PFB */ |
| 467 | ret = engine->fb.init(dev); |
| 468 | if (ret) |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 469 | goto out_timer; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 470 | |
Marcin KoĆcielnicki | a32ed69 | 2010-01-26 14:00:42 +0000 | [diff] [blame] | 471 | if (nouveau_noaccel) |
| 472 | engine->graph.accel_blocked = true; |
| 473 | else { |
| 474 | /* PGRAPH */ |
| 475 | ret = engine->graph.init(dev); |
| 476 | if (ret) |
| 477 | goto out_fb; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 478 | |
Marcin KoĆcielnicki | a32ed69 | 2010-01-26 14:00:42 +0000 | [diff] [blame] | 479 | /* PFIFO */ |
| 480 | ret = engine->fifo.init(dev); |
| 481 | if (ret) |
| 482 | goto out_graph; |
| 483 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 484 | |
| 485 | /* this call irq_preinstall, register irq handler and |
| 486 | * call irq_postinstall |
| 487 | */ |
| 488 | ret = drm_irq_install(dev); |
| 489 | if (ret) |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 490 | goto out_fifo; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 491 | |
| 492 | ret = drm_vblank_init(dev, 0); |
| 493 | if (ret) |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 494 | goto out_irq; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 495 | |
| 496 | /* what about PVIDEO/PCRTC/PRAMDAC etc? */ |
| 497 | |
Ben Skeggs | 0735f62 | 2009-12-16 14:28:55 +1000 | [diff] [blame] | 498 | if (!engine->graph.accel_blocked) { |
| 499 | ret = nouveau_card_init_channel(dev); |
| 500 | if (ret) |
| 501 | goto out_irq; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 505 | if (dev_priv->card_type >= NV_50) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 506 | ret = nv50_display_create(dev); |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 507 | else |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 508 | ret = nv04_display_create(dev); |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 509 | if (ret) |
Ben Skeggs | 78bb351 | 2010-03-25 16:00:09 +1000 | [diff] [blame] | 510 | goto out_channel; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | ret = nouveau_backlight_init(dev); |
| 514 | if (ret) |
| 515 | NV_ERROR(dev, "Error %d registering backlight\n", ret); |
| 516 | |
| 517 | dev_priv->init_state = NOUVEAU_CARD_INIT_DONE; |
| 518 | |
| 519 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 520 | nouveau_fbcon_init(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 521 | |
| 522 | return 0; |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 523 | |
Ben Skeggs | 78bb351 | 2010-03-25 16:00:09 +1000 | [diff] [blame] | 524 | out_channel: |
| 525 | if (dev_priv->channel) { |
| 526 | nouveau_channel_free(dev_priv->channel); |
| 527 | dev_priv->channel = NULL; |
| 528 | } |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 529 | out_irq: |
| 530 | drm_irq_uninstall(dev); |
| 531 | out_fifo: |
Marcin KoĆcielnicki | a32ed69 | 2010-01-26 14:00:42 +0000 | [diff] [blame] | 532 | if (!nouveau_noaccel) |
| 533 | engine->fifo.takedown(dev); |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 534 | out_graph: |
Marcin KoĆcielnicki | a32ed69 | 2010-01-26 14:00:42 +0000 | [diff] [blame] | 535 | if (!nouveau_noaccel) |
| 536 | engine->graph.takedown(dev); |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 537 | out_fb: |
| 538 | engine->fb.takedown(dev); |
| 539 | out_timer: |
| 540 | engine->timer.takedown(dev); |
| 541 | out_mc: |
| 542 | engine->mc.takedown(dev); |
| 543 | out_gpuobj: |
| 544 | nouveau_gpuobj_takedown(dev); |
| 545 | out_mem: |
Ben Skeggs | 78bb351 | 2010-03-25 16:00:09 +1000 | [diff] [blame] | 546 | nouveau_sgdma_takedown(dev); |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 547 | nouveau_mem_close(dev); |
| 548 | out_instmem: |
| 549 | engine->instmem.takedown(dev); |
| 550 | out_gpuobj_early: |
| 551 | nouveau_gpuobj_late_takedown(dev); |
| 552 | out_bios: |
| 553 | nouveau_bios_takedown(dev); |
| 554 | out: |
| 555 | vga_client_register(dev->pdev, NULL, NULL, NULL); |
| 556 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | static void nouveau_card_takedown(struct drm_device *dev) |
| 560 | { |
| 561 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 562 | struct nouveau_engine *engine = &dev_priv->engine; |
| 563 | |
| 564 | NV_DEBUG(dev, "prev state = %d\n", dev_priv->init_state); |
| 565 | |
| 566 | if (dev_priv->init_state != NOUVEAU_CARD_INIT_DOWN) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 567 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 568 | nouveau_backlight_exit(dev); |
| 569 | |
| 570 | if (dev_priv->channel) { |
| 571 | nouveau_channel_free(dev_priv->channel); |
| 572 | dev_priv->channel = NULL; |
| 573 | } |
| 574 | |
Marcin KoĆcielnicki | a32ed69 | 2010-01-26 14:00:42 +0000 | [diff] [blame] | 575 | if (!nouveau_noaccel) { |
| 576 | engine->fifo.takedown(dev); |
| 577 | engine->graph.takedown(dev); |
| 578 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 579 | engine->fb.takedown(dev); |
| 580 | engine->timer.takedown(dev); |
| 581 | engine->mc.takedown(dev); |
| 582 | |
| 583 | mutex_lock(&dev->struct_mutex); |
Luca Barbieri | 7166647 | 2010-01-16 15:30:15 +0100 | [diff] [blame] | 584 | ttm_bo_clean_mm(&dev_priv->ttm.bdev, TTM_PL_VRAM); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 585 | ttm_bo_clean_mm(&dev_priv->ttm.bdev, TTM_PL_TT); |
| 586 | mutex_unlock(&dev->struct_mutex); |
| 587 | nouveau_sgdma_takedown(dev); |
| 588 | |
| 589 | nouveau_gpuobj_takedown(dev); |
| 590 | nouveau_mem_close(dev); |
| 591 | engine->instmem.takedown(dev); |
| 592 | |
| 593 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 594 | drm_irq_uninstall(dev); |
| 595 | |
| 596 | nouveau_gpuobj_late_takedown(dev); |
| 597 | nouveau_bios_takedown(dev); |
| 598 | |
| 599 | vga_client_register(dev->pdev, NULL, NULL, NULL); |
| 600 | |
| 601 | dev_priv->init_state = NOUVEAU_CARD_INIT_DOWN; |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | /* here a client dies, release the stuff that was allocated for its |
| 606 | * file_priv */ |
| 607 | void nouveau_preclose(struct drm_device *dev, struct drm_file *file_priv) |
| 608 | { |
| 609 | nouveau_channel_cleanup(dev, file_priv); |
| 610 | } |
| 611 | |
| 612 | /* first module load, setup the mmio/fb mapping */ |
| 613 | /* KMS: we need mmio at load time, not when the first drm client opens. */ |
| 614 | int nouveau_firstopen(struct drm_device *dev) |
| 615 | { |
| 616 | return 0; |
| 617 | } |
| 618 | |
| 619 | /* if we have an OF card, copy vbios to RAMIN */ |
| 620 | static void nouveau_OF_copy_vbios_to_ramin(struct drm_device *dev) |
| 621 | { |
| 622 | #if defined(__powerpc__) |
| 623 | int size, i; |
| 624 | const uint32_t *bios; |
| 625 | struct device_node *dn = pci_device_to_OF_node(dev->pdev); |
| 626 | if (!dn) { |
| 627 | NV_INFO(dev, "Unable to get the OF node\n"); |
| 628 | return; |
| 629 | } |
| 630 | |
| 631 | bios = of_get_property(dn, "NVDA,BMP", &size); |
| 632 | if (bios) { |
| 633 | for (i = 0; i < size; i += 4) |
| 634 | nv_wi32(dev, i, bios[i/4]); |
| 635 | NV_INFO(dev, "OF bios successfully copied (%d bytes)\n", size); |
| 636 | } else { |
| 637 | NV_INFO(dev, "Unable to get the OF bios\n"); |
| 638 | } |
| 639 | #endif |
| 640 | } |
| 641 | |
Marcin Slusarz | 06415c5 | 2010-05-16 17:29:56 +0200 | [diff] [blame^] | 642 | static struct apertures_struct *nouveau_get_apertures(struct drm_device *dev) |
| 643 | { |
| 644 | struct pci_dev *pdev = dev->pdev; |
| 645 | struct apertures_struct *aper = alloc_apertures(3); |
| 646 | if (!aper) |
| 647 | return NULL; |
| 648 | |
| 649 | aper->ranges[0].base = pci_resource_start(pdev, 1); |
| 650 | aper->ranges[0].size = pci_resource_len(pdev, 1); |
| 651 | aper->count = 1; |
| 652 | |
| 653 | if (pci_resource_len(pdev, 2)) { |
| 654 | aper->ranges[aper->count].base = pci_resource_start(pdev, 2); |
| 655 | aper->ranges[aper->count].size = pci_resource_len(pdev, 2); |
| 656 | aper->count++; |
| 657 | } |
| 658 | |
| 659 | if (pci_resource_len(pdev, 3)) { |
| 660 | aper->ranges[aper->count].base = pci_resource_start(pdev, 3); |
| 661 | aper->ranges[aper->count].size = pci_resource_len(pdev, 3); |
| 662 | aper->count++; |
| 663 | } |
| 664 | |
| 665 | return aper; |
| 666 | } |
| 667 | |
| 668 | static int nouveau_remove_conflicting_drivers(struct drm_device *dev) |
| 669 | { |
| 670 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 671 | dev_priv->apertures = nouveau_get_apertures(dev); |
| 672 | if (!dev_priv->apertures) |
| 673 | return -ENOMEM; |
| 674 | |
| 675 | remove_conflicting_framebuffers(dev_priv->apertures, "nouveaufb"); |
| 676 | return 0; |
| 677 | } |
| 678 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 679 | int nouveau_load(struct drm_device *dev, unsigned long flags) |
| 680 | { |
| 681 | struct drm_nouveau_private *dev_priv; |
| 682 | uint32_t reg0; |
| 683 | resource_size_t mmio_start_offs; |
| 684 | |
| 685 | dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL); |
| 686 | if (!dev_priv) |
| 687 | return -ENOMEM; |
| 688 | dev->dev_private = dev_priv; |
| 689 | dev_priv->dev = dev; |
| 690 | |
| 691 | dev_priv->flags = flags & NOUVEAU_FLAGS; |
| 692 | dev_priv->init_state = NOUVEAU_CARD_INIT_DOWN; |
| 693 | |
| 694 | NV_DEBUG(dev, "vendor: 0x%X device: 0x%X class: 0x%X\n", |
| 695 | dev->pci_vendor, dev->pci_device, dev->pdev->class); |
| 696 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 697 | dev_priv->wq = create_workqueue("nouveau"); |
| 698 | if (!dev_priv->wq) |
| 699 | return -EINVAL; |
| 700 | |
| 701 | /* resource 0 is mmio regs */ |
| 702 | /* resource 1 is linear FB */ |
| 703 | /* resource 2 is RAMIN (mmio regs + 0x1000000) */ |
| 704 | /* resource 6 is bios */ |
| 705 | |
| 706 | /* map the mmio regs */ |
| 707 | mmio_start_offs = pci_resource_start(dev->pdev, 0); |
| 708 | dev_priv->mmio = ioremap(mmio_start_offs, 0x00800000); |
| 709 | if (!dev_priv->mmio) { |
| 710 | NV_ERROR(dev, "Unable to initialize the mmio mapping. " |
| 711 | "Please report your setup to " DRIVER_EMAIL "\n"); |
| 712 | return -EINVAL; |
| 713 | } |
| 714 | NV_DEBUG(dev, "regs mapped ok at 0x%llx\n", |
| 715 | (unsigned long long)mmio_start_offs); |
| 716 | |
| 717 | #ifdef __BIG_ENDIAN |
| 718 | /* Put the card in BE mode if it's not */ |
| 719 | if (nv_rd32(dev, NV03_PMC_BOOT_1)) |
| 720 | nv_wr32(dev, NV03_PMC_BOOT_1, 0x00000001); |
| 721 | |
| 722 | DRM_MEMORYBARRIER(); |
| 723 | #endif |
| 724 | |
| 725 | /* Time to determine the card architecture */ |
| 726 | reg0 = nv_rd32(dev, NV03_PMC_BOOT_0); |
| 727 | |
| 728 | /* We're dealing with >=NV10 */ |
| 729 | if ((reg0 & 0x0f000000) > 0) { |
| 730 | /* Bit 27-20 contain the architecture in hex */ |
| 731 | dev_priv->chipset = (reg0 & 0xff00000) >> 20; |
| 732 | /* NV04 or NV05 */ |
| 733 | } else if ((reg0 & 0xff00fff0) == 0x20004000) { |
Ben Skeggs | 1dee7a9 | 2010-01-07 13:47:57 +1000 | [diff] [blame] | 734 | if (reg0 & 0x00f00000) |
| 735 | dev_priv->chipset = 0x05; |
| 736 | else |
| 737 | dev_priv->chipset = 0x04; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 738 | } else |
| 739 | dev_priv->chipset = 0xff; |
| 740 | |
| 741 | switch (dev_priv->chipset & 0xf0) { |
| 742 | case 0x00: |
| 743 | case 0x10: |
| 744 | case 0x20: |
| 745 | case 0x30: |
| 746 | dev_priv->card_type = dev_priv->chipset & 0xf0; |
| 747 | break; |
| 748 | case 0x40: |
| 749 | case 0x60: |
| 750 | dev_priv->card_type = NV_40; |
| 751 | break; |
| 752 | case 0x50: |
| 753 | case 0x80: |
| 754 | case 0x90: |
| 755 | case 0xa0: |
| 756 | dev_priv->card_type = NV_50; |
| 757 | break; |
| 758 | default: |
| 759 | NV_INFO(dev, "Unsupported chipset 0x%08x\n", reg0); |
| 760 | return -EINVAL; |
| 761 | } |
| 762 | |
| 763 | NV_INFO(dev, "Detected an NV%2x generation card (0x%08x)\n", |
| 764 | dev_priv->card_type, reg0); |
| 765 | |
Marcin Slusarz | 06415c5 | 2010-05-16 17:29:56 +0200 | [diff] [blame^] | 766 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
| 767 | int ret = nouveau_remove_conflicting_drivers(dev); |
| 768 | if (ret) |
| 769 | return ret; |
| 770 | } |
| 771 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 772 | /* map larger RAMIN aperture on NV40 cards */ |
| 773 | dev_priv->ramin = NULL; |
| 774 | if (dev_priv->card_type >= NV_40) { |
| 775 | int ramin_bar = 2; |
| 776 | if (pci_resource_len(dev->pdev, ramin_bar) == 0) |
| 777 | ramin_bar = 3; |
| 778 | |
| 779 | dev_priv->ramin_size = pci_resource_len(dev->pdev, ramin_bar); |
| 780 | dev_priv->ramin = ioremap( |
| 781 | pci_resource_start(dev->pdev, ramin_bar), |
| 782 | dev_priv->ramin_size); |
| 783 | if (!dev_priv->ramin) { |
| 784 | NV_ERROR(dev, "Failed to init RAMIN mapping, " |
| 785 | "limited instance memory available\n"); |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | /* On older cards (or if the above failed), create a map covering |
| 790 | * the BAR0 PRAMIN aperture */ |
| 791 | if (!dev_priv->ramin) { |
| 792 | dev_priv->ramin_size = 1 * 1024 * 1024; |
| 793 | dev_priv->ramin = ioremap(mmio_start_offs + NV_RAMIN, |
| 794 | dev_priv->ramin_size); |
| 795 | if (!dev_priv->ramin) { |
| 796 | NV_ERROR(dev, "Failed to map BAR0 PRAMIN.\n"); |
| 797 | return -ENOMEM; |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | nouveau_OF_copy_vbios_to_ramin(dev); |
| 802 | |
| 803 | /* Special flags */ |
| 804 | if (dev->pci_device == 0x01a0) |
| 805 | dev_priv->flags |= NV_NFORCE; |
| 806 | else if (dev->pci_device == 0x01f0) |
| 807 | dev_priv->flags |= NV_NFORCE2; |
| 808 | |
| 809 | /* For kernel modesetting, init card now and bring up fbcon */ |
| 810 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
| 811 | int ret = nouveau_card_init(dev); |
| 812 | if (ret) |
| 813 | return ret; |
| 814 | } |
| 815 | |
| 816 | return 0; |
| 817 | } |
| 818 | |
| 819 | static void nouveau_close(struct drm_device *dev) |
| 820 | { |
| 821 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 822 | |
Francisco Jerez | 111b459 | 2009-12-22 18:24:09 +0100 | [diff] [blame] | 823 | /* In the case of an error dev_priv may not be allocated yet */ |
| 824 | if (dev_priv) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 825 | nouveau_card_takedown(dev); |
| 826 | } |
| 827 | |
| 828 | /* KMS: we need mmio at load time, not when the first drm client opens. */ |
| 829 | void nouveau_lastclose(struct drm_device *dev) |
| 830 | { |
| 831 | if (drm_core_check_feature(dev, DRIVER_MODESET)) |
| 832 | return; |
| 833 | |
| 834 | nouveau_close(dev); |
| 835 | } |
| 836 | |
| 837 | int nouveau_unload(struct drm_device *dev) |
| 838 | { |
| 839 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 840 | |
| 841 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 842 | nouveau_fbcon_fini(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 843 | if (dev_priv->card_type >= NV_50) |
| 844 | nv50_display_destroy(dev); |
| 845 | else |
| 846 | nv04_display_destroy(dev); |
| 847 | nouveau_close(dev); |
| 848 | } |
| 849 | |
| 850 | iounmap(dev_priv->mmio); |
| 851 | iounmap(dev_priv->ramin); |
| 852 | |
| 853 | kfree(dev_priv); |
| 854 | dev->dev_private = NULL; |
| 855 | return 0; |
| 856 | } |
| 857 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 858 | int nouveau_ioctl_getparam(struct drm_device *dev, void *data, |
| 859 | struct drm_file *file_priv) |
| 860 | { |
| 861 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 862 | struct drm_nouveau_getparam *getparam = data; |
| 863 | |
| 864 | NOUVEAU_CHECK_INITIALISED_WITH_RETURN; |
| 865 | |
| 866 | switch (getparam->param) { |
| 867 | case NOUVEAU_GETPARAM_CHIPSET_ID: |
| 868 | getparam->value = dev_priv->chipset; |
| 869 | break; |
| 870 | case NOUVEAU_GETPARAM_PCI_VENDOR: |
| 871 | getparam->value = dev->pci_vendor; |
| 872 | break; |
| 873 | case NOUVEAU_GETPARAM_PCI_DEVICE: |
| 874 | getparam->value = dev->pci_device; |
| 875 | break; |
| 876 | case NOUVEAU_GETPARAM_BUS_TYPE: |
| 877 | if (drm_device_is_agp(dev)) |
| 878 | getparam->value = NV_AGP; |
| 879 | else if (drm_device_is_pcie(dev)) |
| 880 | getparam->value = NV_PCIE; |
| 881 | else |
| 882 | getparam->value = NV_PCI; |
| 883 | break; |
| 884 | case NOUVEAU_GETPARAM_FB_PHYSICAL: |
| 885 | getparam->value = dev_priv->fb_phys; |
| 886 | break; |
| 887 | case NOUVEAU_GETPARAM_AGP_PHYSICAL: |
| 888 | getparam->value = dev_priv->gart_info.aper_base; |
| 889 | break; |
| 890 | case NOUVEAU_GETPARAM_PCI_PHYSICAL: |
| 891 | if (dev->sg) { |
| 892 | getparam->value = (unsigned long)dev->sg->virtual; |
| 893 | } else { |
| 894 | NV_ERROR(dev, "Requested PCIGART address, " |
| 895 | "while no PCIGART was created\n"); |
| 896 | return -EINVAL; |
| 897 | } |
| 898 | break; |
| 899 | case NOUVEAU_GETPARAM_FB_SIZE: |
| 900 | getparam->value = dev_priv->fb_available_size; |
| 901 | break; |
| 902 | case NOUVEAU_GETPARAM_AGP_SIZE: |
| 903 | getparam->value = dev_priv->gart_info.aper_size; |
| 904 | break; |
| 905 | case NOUVEAU_GETPARAM_VM_VRAM_BASE: |
| 906 | getparam->value = dev_priv->vm_vram_base; |
| 907 | break; |
Marcin KoĆcielnicki | 69c9700 | 2010-01-26 18:39:20 +0000 | [diff] [blame] | 908 | case NOUVEAU_GETPARAM_GRAPH_UNITS: |
| 909 | /* NV40 and NV50 versions are quite different, but register |
| 910 | * address is the same. User is supposed to know the card |
| 911 | * family anyway... */ |
| 912 | if (dev_priv->chipset >= 0x40) { |
| 913 | getparam->value = nv_rd32(dev, NV40_PMC_GRAPH_UNITS); |
| 914 | break; |
| 915 | } |
| 916 | /* FALLTHRU */ |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 917 | default: |
| 918 | NV_ERROR(dev, "unknown parameter %lld\n", getparam->param); |
| 919 | return -EINVAL; |
| 920 | } |
| 921 | |
| 922 | return 0; |
| 923 | } |
| 924 | |
| 925 | int |
| 926 | nouveau_ioctl_setparam(struct drm_device *dev, void *data, |
| 927 | struct drm_file *file_priv) |
| 928 | { |
| 929 | struct drm_nouveau_setparam *setparam = data; |
| 930 | |
| 931 | NOUVEAU_CHECK_INITIALISED_WITH_RETURN; |
| 932 | |
| 933 | switch (setparam->param) { |
| 934 | default: |
| 935 | NV_ERROR(dev, "unknown parameter %lld\n", setparam->param); |
| 936 | return -EINVAL; |
| 937 | } |
| 938 | |
| 939 | return 0; |
| 940 | } |
| 941 | |
| 942 | /* Wait until (value(reg) & mask) == val, up until timeout has hit */ |
| 943 | bool nouveau_wait_until(struct drm_device *dev, uint64_t timeout, |
| 944 | uint32_t reg, uint32_t mask, uint32_t val) |
| 945 | { |
| 946 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 947 | struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer; |
| 948 | uint64_t start = ptimer->read(dev); |
| 949 | |
| 950 | do { |
| 951 | if ((nv_rd32(dev, reg) & mask) == val) |
| 952 | return true; |
| 953 | } while (ptimer->read(dev) - start < timeout); |
| 954 | |
| 955 | return false; |
| 956 | } |
| 957 | |
| 958 | /* Waits for PGRAPH to go completely idle */ |
| 959 | bool nouveau_wait_for_idle(struct drm_device *dev) |
| 960 | { |
| 961 | if (!nv_wait(NV04_PGRAPH_STATUS, 0xffffffff, 0x00000000)) { |
| 962 | NV_ERROR(dev, "PGRAPH idle timed out with status 0x%08x\n", |
| 963 | nv_rd32(dev, NV04_PGRAPH_STATUS)); |
| 964 | return false; |
| 965 | } |
| 966 | |
| 967 | return true; |
| 968 | } |
| 969 | |