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 | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 38 | #include "nouveau_ramht.h" |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 39 | #include "nouveau_pm.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 40 | #include "nv50_display.h" |
| 41 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 42 | static void nouveau_stub_takedown(struct drm_device *dev) {} |
Ben Skeggs | ee2e013 | 2010-07-26 09:28:25 +1000 | [diff] [blame] | 43 | static int nouveau_stub_init(struct drm_device *dev) { return 0; } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 44 | |
| 45 | static int nouveau_init_engine_ptrs(struct drm_device *dev) |
| 46 | { |
| 47 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 48 | struct nouveau_engine *engine = &dev_priv->engine; |
| 49 | |
| 50 | switch (dev_priv->chipset & 0xf0) { |
| 51 | case 0x00: |
| 52 | engine->instmem.init = nv04_instmem_init; |
| 53 | engine->instmem.takedown = nv04_instmem_takedown; |
| 54 | engine->instmem.suspend = nv04_instmem_suspend; |
| 55 | engine->instmem.resume = nv04_instmem_resume; |
| 56 | engine->instmem.populate = nv04_instmem_populate; |
| 57 | engine->instmem.clear = nv04_instmem_clear; |
| 58 | engine->instmem.bind = nv04_instmem_bind; |
| 59 | engine->instmem.unbind = nv04_instmem_unbind; |
Ben Skeggs | f56cb86 | 2010-07-08 11:29:10 +1000 | [diff] [blame] | 60 | engine->instmem.flush = nv04_instmem_flush; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 61 | engine->mc.init = nv04_mc_init; |
| 62 | engine->mc.takedown = nv04_mc_takedown; |
| 63 | engine->timer.init = nv04_timer_init; |
| 64 | engine->timer.read = nv04_timer_read; |
| 65 | engine->timer.takedown = nv04_timer_takedown; |
| 66 | engine->fb.init = nv04_fb_init; |
| 67 | engine->fb.takedown = nv04_fb_takedown; |
| 68 | engine->graph.grclass = nv04_graph_grclass; |
| 69 | engine->graph.init = nv04_graph_init; |
| 70 | engine->graph.takedown = nv04_graph_takedown; |
| 71 | engine->graph.fifo_access = nv04_graph_fifo_access; |
| 72 | engine->graph.channel = nv04_graph_channel; |
| 73 | engine->graph.create_context = nv04_graph_create_context; |
| 74 | engine->graph.destroy_context = nv04_graph_destroy_context; |
| 75 | engine->graph.load_context = nv04_graph_load_context; |
| 76 | engine->graph.unload_context = nv04_graph_unload_context; |
| 77 | engine->fifo.channels = 16; |
| 78 | engine->fifo.init = nv04_fifo_init; |
| 79 | engine->fifo.takedown = nouveau_stub_takedown; |
| 80 | engine->fifo.disable = nv04_fifo_disable; |
| 81 | engine->fifo.enable = nv04_fifo_enable; |
| 82 | engine->fifo.reassign = nv04_fifo_reassign; |
Francisco Jerez | 588d7d1 | 2009-12-13 20:07:42 +0100 | [diff] [blame] | 83 | engine->fifo.cache_pull = nv04_fifo_cache_pull; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 84 | engine->fifo.channel_id = nv04_fifo_channel_id; |
| 85 | engine->fifo.create_context = nv04_fifo_create_context; |
| 86 | engine->fifo.destroy_context = nv04_fifo_destroy_context; |
| 87 | engine->fifo.load_context = nv04_fifo_load_context; |
| 88 | engine->fifo.unload_context = nv04_fifo_unload_context; |
Francisco Jerez | c88c2e0 | 2010-07-24 17:37:33 +0200 | [diff] [blame] | 89 | engine->display.early_init = nv04_display_early_init; |
| 90 | engine->display.late_takedown = nv04_display_late_takedown; |
| 91 | engine->display.create = nv04_display_create; |
| 92 | engine->display.init = nv04_display_init; |
| 93 | engine->display.destroy = nv04_display_destroy; |
Ben Skeggs | ee2e013 | 2010-07-26 09:28:25 +1000 | [diff] [blame] | 94 | engine->gpio.init = nouveau_stub_init; |
| 95 | engine->gpio.takedown = nouveau_stub_takedown; |
| 96 | engine->gpio.get = NULL; |
| 97 | engine->gpio.set = NULL; |
| 98 | engine->gpio.irq_enable = NULL; |
Ben Skeggs | 442b626 | 2010-09-16 16:25:26 +1000 | [diff] [blame] | 99 | engine->pm.clock_get = nv04_pm_clock_get; |
| 100 | engine->pm.clock_pre = nv04_pm_clock_pre; |
| 101 | engine->pm.clock_set = nv04_pm_clock_set; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 102 | break; |
| 103 | case 0x10: |
| 104 | engine->instmem.init = nv04_instmem_init; |
| 105 | engine->instmem.takedown = nv04_instmem_takedown; |
| 106 | engine->instmem.suspend = nv04_instmem_suspend; |
| 107 | engine->instmem.resume = nv04_instmem_resume; |
| 108 | engine->instmem.populate = nv04_instmem_populate; |
| 109 | engine->instmem.clear = nv04_instmem_clear; |
| 110 | engine->instmem.bind = nv04_instmem_bind; |
| 111 | engine->instmem.unbind = nv04_instmem_unbind; |
Ben Skeggs | f56cb86 | 2010-07-08 11:29:10 +1000 | [diff] [blame] | 112 | engine->instmem.flush = nv04_instmem_flush; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 113 | engine->mc.init = nv04_mc_init; |
| 114 | engine->mc.takedown = nv04_mc_takedown; |
| 115 | engine->timer.init = nv04_timer_init; |
| 116 | engine->timer.read = nv04_timer_read; |
| 117 | engine->timer.takedown = nv04_timer_takedown; |
| 118 | engine->fb.init = nv10_fb_init; |
| 119 | engine->fb.takedown = nv10_fb_takedown; |
Francisco Jerez | cb00f7c | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 120 | engine->fb.set_region_tiling = nv10_fb_set_region_tiling; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 121 | engine->graph.grclass = nv10_graph_grclass; |
| 122 | engine->graph.init = nv10_graph_init; |
| 123 | engine->graph.takedown = nv10_graph_takedown; |
| 124 | engine->graph.channel = nv10_graph_channel; |
| 125 | engine->graph.create_context = nv10_graph_create_context; |
| 126 | engine->graph.destroy_context = nv10_graph_destroy_context; |
| 127 | engine->graph.fifo_access = nv04_graph_fifo_access; |
| 128 | engine->graph.load_context = nv10_graph_load_context; |
| 129 | engine->graph.unload_context = nv10_graph_unload_context; |
Francisco Jerez | cb00f7c | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 130 | engine->graph.set_region_tiling = nv10_graph_set_region_tiling; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 131 | engine->fifo.channels = 32; |
| 132 | engine->fifo.init = nv10_fifo_init; |
| 133 | engine->fifo.takedown = nouveau_stub_takedown; |
| 134 | engine->fifo.disable = nv04_fifo_disable; |
| 135 | engine->fifo.enable = nv04_fifo_enable; |
| 136 | engine->fifo.reassign = nv04_fifo_reassign; |
Francisco Jerez | 588d7d1 | 2009-12-13 20:07:42 +0100 | [diff] [blame] | 137 | engine->fifo.cache_pull = nv04_fifo_cache_pull; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 138 | engine->fifo.channel_id = nv10_fifo_channel_id; |
| 139 | engine->fifo.create_context = nv10_fifo_create_context; |
Francisco Jerez | 3945e47 | 2010-10-18 03:53:39 +0200 | [diff] [blame] | 140 | engine->fifo.destroy_context = nv04_fifo_destroy_context; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 141 | engine->fifo.load_context = nv10_fifo_load_context; |
| 142 | engine->fifo.unload_context = nv10_fifo_unload_context; |
Francisco Jerez | c88c2e0 | 2010-07-24 17:37:33 +0200 | [diff] [blame] | 143 | engine->display.early_init = nv04_display_early_init; |
| 144 | engine->display.late_takedown = nv04_display_late_takedown; |
| 145 | engine->display.create = nv04_display_create; |
| 146 | engine->display.init = nv04_display_init; |
| 147 | engine->display.destroy = nv04_display_destroy; |
Ben Skeggs | ee2e013 | 2010-07-26 09:28:25 +1000 | [diff] [blame] | 148 | engine->gpio.init = nouveau_stub_init; |
| 149 | engine->gpio.takedown = nouveau_stub_takedown; |
| 150 | engine->gpio.get = nv10_gpio_get; |
| 151 | engine->gpio.set = nv10_gpio_set; |
| 152 | engine->gpio.irq_enable = NULL; |
Ben Skeggs | 442b626 | 2010-09-16 16:25:26 +1000 | [diff] [blame] | 153 | engine->pm.clock_get = nv04_pm_clock_get; |
| 154 | engine->pm.clock_pre = nv04_pm_clock_pre; |
| 155 | engine->pm.clock_set = nv04_pm_clock_set; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 156 | break; |
| 157 | case 0x20: |
| 158 | engine->instmem.init = nv04_instmem_init; |
| 159 | engine->instmem.takedown = nv04_instmem_takedown; |
| 160 | engine->instmem.suspend = nv04_instmem_suspend; |
| 161 | engine->instmem.resume = nv04_instmem_resume; |
| 162 | engine->instmem.populate = nv04_instmem_populate; |
| 163 | engine->instmem.clear = nv04_instmem_clear; |
| 164 | engine->instmem.bind = nv04_instmem_bind; |
| 165 | engine->instmem.unbind = nv04_instmem_unbind; |
Ben Skeggs | f56cb86 | 2010-07-08 11:29:10 +1000 | [diff] [blame] | 166 | engine->instmem.flush = nv04_instmem_flush; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 167 | engine->mc.init = nv04_mc_init; |
| 168 | engine->mc.takedown = nv04_mc_takedown; |
| 169 | engine->timer.init = nv04_timer_init; |
| 170 | engine->timer.read = nv04_timer_read; |
| 171 | engine->timer.takedown = nv04_timer_takedown; |
| 172 | engine->fb.init = nv10_fb_init; |
| 173 | engine->fb.takedown = nv10_fb_takedown; |
Francisco Jerez | cb00f7c | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 174 | engine->fb.set_region_tiling = nv10_fb_set_region_tiling; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 175 | engine->graph.grclass = nv20_graph_grclass; |
| 176 | engine->graph.init = nv20_graph_init; |
| 177 | engine->graph.takedown = nv20_graph_takedown; |
| 178 | engine->graph.channel = nv10_graph_channel; |
| 179 | engine->graph.create_context = nv20_graph_create_context; |
| 180 | engine->graph.destroy_context = nv20_graph_destroy_context; |
| 181 | engine->graph.fifo_access = nv04_graph_fifo_access; |
| 182 | engine->graph.load_context = nv20_graph_load_context; |
| 183 | engine->graph.unload_context = nv20_graph_unload_context; |
Francisco Jerez | cb00f7c | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 184 | engine->graph.set_region_tiling = nv20_graph_set_region_tiling; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 185 | engine->fifo.channels = 32; |
| 186 | engine->fifo.init = nv10_fifo_init; |
| 187 | engine->fifo.takedown = nouveau_stub_takedown; |
| 188 | engine->fifo.disable = nv04_fifo_disable; |
| 189 | engine->fifo.enable = nv04_fifo_enable; |
| 190 | engine->fifo.reassign = nv04_fifo_reassign; |
Francisco Jerez | 588d7d1 | 2009-12-13 20:07:42 +0100 | [diff] [blame] | 191 | engine->fifo.cache_pull = nv04_fifo_cache_pull; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 192 | engine->fifo.channel_id = nv10_fifo_channel_id; |
| 193 | engine->fifo.create_context = nv10_fifo_create_context; |
Francisco Jerez | 3945e47 | 2010-10-18 03:53:39 +0200 | [diff] [blame] | 194 | engine->fifo.destroy_context = nv04_fifo_destroy_context; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 195 | engine->fifo.load_context = nv10_fifo_load_context; |
| 196 | engine->fifo.unload_context = nv10_fifo_unload_context; |
Francisco Jerez | c88c2e0 | 2010-07-24 17:37:33 +0200 | [diff] [blame] | 197 | engine->display.early_init = nv04_display_early_init; |
| 198 | engine->display.late_takedown = nv04_display_late_takedown; |
| 199 | engine->display.create = nv04_display_create; |
| 200 | engine->display.init = nv04_display_init; |
| 201 | engine->display.destroy = nv04_display_destroy; |
Ben Skeggs | ee2e013 | 2010-07-26 09:28:25 +1000 | [diff] [blame] | 202 | engine->gpio.init = nouveau_stub_init; |
| 203 | engine->gpio.takedown = nouveau_stub_takedown; |
| 204 | engine->gpio.get = nv10_gpio_get; |
| 205 | engine->gpio.set = nv10_gpio_set; |
| 206 | engine->gpio.irq_enable = NULL; |
Ben Skeggs | 442b626 | 2010-09-16 16:25:26 +1000 | [diff] [blame] | 207 | engine->pm.clock_get = nv04_pm_clock_get; |
| 208 | engine->pm.clock_pre = nv04_pm_clock_pre; |
| 209 | engine->pm.clock_set = nv04_pm_clock_set; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 210 | break; |
| 211 | case 0x30: |
| 212 | engine->instmem.init = nv04_instmem_init; |
| 213 | engine->instmem.takedown = nv04_instmem_takedown; |
| 214 | engine->instmem.suspend = nv04_instmem_suspend; |
| 215 | engine->instmem.resume = nv04_instmem_resume; |
| 216 | engine->instmem.populate = nv04_instmem_populate; |
| 217 | engine->instmem.clear = nv04_instmem_clear; |
| 218 | engine->instmem.bind = nv04_instmem_bind; |
| 219 | engine->instmem.unbind = nv04_instmem_unbind; |
Ben Skeggs | f56cb86 | 2010-07-08 11:29:10 +1000 | [diff] [blame] | 220 | engine->instmem.flush = nv04_instmem_flush; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 221 | engine->mc.init = nv04_mc_init; |
| 222 | engine->mc.takedown = nv04_mc_takedown; |
| 223 | engine->timer.init = nv04_timer_init; |
| 224 | engine->timer.read = nv04_timer_read; |
| 225 | engine->timer.takedown = nv04_timer_takedown; |
Francisco Jerez | 8bded18 | 2010-07-21 21:08:11 +0200 | [diff] [blame] | 226 | engine->fb.init = nv30_fb_init; |
| 227 | engine->fb.takedown = nv30_fb_takedown; |
Francisco Jerez | cb00f7c | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 228 | engine->fb.set_region_tiling = nv10_fb_set_region_tiling; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 229 | engine->graph.grclass = nv30_graph_grclass; |
| 230 | engine->graph.init = nv30_graph_init; |
| 231 | engine->graph.takedown = nv20_graph_takedown; |
| 232 | engine->graph.fifo_access = nv04_graph_fifo_access; |
| 233 | engine->graph.channel = nv10_graph_channel; |
| 234 | engine->graph.create_context = nv20_graph_create_context; |
| 235 | engine->graph.destroy_context = nv20_graph_destroy_context; |
| 236 | engine->graph.load_context = nv20_graph_load_context; |
| 237 | engine->graph.unload_context = nv20_graph_unload_context; |
Francisco Jerez | cb00f7c | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 238 | engine->graph.set_region_tiling = nv20_graph_set_region_tiling; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 239 | engine->fifo.channels = 32; |
| 240 | engine->fifo.init = nv10_fifo_init; |
| 241 | engine->fifo.takedown = nouveau_stub_takedown; |
| 242 | engine->fifo.disable = nv04_fifo_disable; |
| 243 | engine->fifo.enable = nv04_fifo_enable; |
| 244 | engine->fifo.reassign = nv04_fifo_reassign; |
Francisco Jerez | 588d7d1 | 2009-12-13 20:07:42 +0100 | [diff] [blame] | 245 | engine->fifo.cache_pull = nv04_fifo_cache_pull; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 246 | engine->fifo.channel_id = nv10_fifo_channel_id; |
| 247 | engine->fifo.create_context = nv10_fifo_create_context; |
Francisco Jerez | 3945e47 | 2010-10-18 03:53:39 +0200 | [diff] [blame] | 248 | engine->fifo.destroy_context = nv04_fifo_destroy_context; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 249 | engine->fifo.load_context = nv10_fifo_load_context; |
| 250 | engine->fifo.unload_context = nv10_fifo_unload_context; |
Francisco Jerez | c88c2e0 | 2010-07-24 17:37:33 +0200 | [diff] [blame] | 251 | engine->display.early_init = nv04_display_early_init; |
| 252 | engine->display.late_takedown = nv04_display_late_takedown; |
| 253 | engine->display.create = nv04_display_create; |
| 254 | engine->display.init = nv04_display_init; |
| 255 | engine->display.destroy = nv04_display_destroy; |
Ben Skeggs | ee2e013 | 2010-07-26 09:28:25 +1000 | [diff] [blame] | 256 | engine->gpio.init = nouveau_stub_init; |
| 257 | engine->gpio.takedown = nouveau_stub_takedown; |
| 258 | engine->gpio.get = nv10_gpio_get; |
| 259 | engine->gpio.set = nv10_gpio_set; |
| 260 | engine->gpio.irq_enable = NULL; |
Ben Skeggs | 442b626 | 2010-09-16 16:25:26 +1000 | [diff] [blame] | 261 | engine->pm.clock_get = nv04_pm_clock_get; |
| 262 | engine->pm.clock_pre = nv04_pm_clock_pre; |
| 263 | engine->pm.clock_set = nv04_pm_clock_set; |
| 264 | engine->pm.voltage_get = nouveau_voltage_gpio_get; |
| 265 | engine->pm.voltage_set = nouveau_voltage_gpio_set; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 266 | break; |
| 267 | case 0x40: |
| 268 | case 0x60: |
| 269 | engine->instmem.init = nv04_instmem_init; |
| 270 | engine->instmem.takedown = nv04_instmem_takedown; |
| 271 | engine->instmem.suspend = nv04_instmem_suspend; |
| 272 | engine->instmem.resume = nv04_instmem_resume; |
| 273 | engine->instmem.populate = nv04_instmem_populate; |
| 274 | engine->instmem.clear = nv04_instmem_clear; |
| 275 | engine->instmem.bind = nv04_instmem_bind; |
| 276 | engine->instmem.unbind = nv04_instmem_unbind; |
Ben Skeggs | f56cb86 | 2010-07-08 11:29:10 +1000 | [diff] [blame] | 277 | engine->instmem.flush = nv04_instmem_flush; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 278 | engine->mc.init = nv40_mc_init; |
| 279 | engine->mc.takedown = nv40_mc_takedown; |
| 280 | engine->timer.init = nv04_timer_init; |
| 281 | engine->timer.read = nv04_timer_read; |
| 282 | engine->timer.takedown = nv04_timer_takedown; |
| 283 | engine->fb.init = nv40_fb_init; |
| 284 | engine->fb.takedown = nv40_fb_takedown; |
Francisco Jerez | cb00f7c | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 285 | engine->fb.set_region_tiling = nv40_fb_set_region_tiling; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 286 | engine->graph.grclass = nv40_graph_grclass; |
| 287 | engine->graph.init = nv40_graph_init; |
| 288 | engine->graph.takedown = nv40_graph_takedown; |
| 289 | engine->graph.fifo_access = nv04_graph_fifo_access; |
| 290 | engine->graph.channel = nv40_graph_channel; |
| 291 | engine->graph.create_context = nv40_graph_create_context; |
| 292 | engine->graph.destroy_context = nv40_graph_destroy_context; |
| 293 | engine->graph.load_context = nv40_graph_load_context; |
| 294 | engine->graph.unload_context = nv40_graph_unload_context; |
Francisco Jerez | cb00f7c | 2009-12-16 12:12:27 +0100 | [diff] [blame] | 295 | engine->graph.set_region_tiling = nv40_graph_set_region_tiling; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 296 | engine->fifo.channels = 32; |
| 297 | engine->fifo.init = nv40_fifo_init; |
| 298 | engine->fifo.takedown = nouveau_stub_takedown; |
| 299 | engine->fifo.disable = nv04_fifo_disable; |
| 300 | engine->fifo.enable = nv04_fifo_enable; |
| 301 | engine->fifo.reassign = nv04_fifo_reassign; |
Francisco Jerez | 588d7d1 | 2009-12-13 20:07:42 +0100 | [diff] [blame] | 302 | engine->fifo.cache_pull = nv04_fifo_cache_pull; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 303 | engine->fifo.channel_id = nv10_fifo_channel_id; |
| 304 | engine->fifo.create_context = nv40_fifo_create_context; |
Francisco Jerez | 3945e47 | 2010-10-18 03:53:39 +0200 | [diff] [blame] | 305 | engine->fifo.destroy_context = nv04_fifo_destroy_context; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 306 | engine->fifo.load_context = nv40_fifo_load_context; |
| 307 | engine->fifo.unload_context = nv40_fifo_unload_context; |
Francisco Jerez | c88c2e0 | 2010-07-24 17:37:33 +0200 | [diff] [blame] | 308 | engine->display.early_init = nv04_display_early_init; |
| 309 | engine->display.late_takedown = nv04_display_late_takedown; |
| 310 | engine->display.create = nv04_display_create; |
| 311 | engine->display.init = nv04_display_init; |
| 312 | engine->display.destroy = nv04_display_destroy; |
Ben Skeggs | ee2e013 | 2010-07-26 09:28:25 +1000 | [diff] [blame] | 313 | engine->gpio.init = nouveau_stub_init; |
| 314 | engine->gpio.takedown = nouveau_stub_takedown; |
| 315 | engine->gpio.get = nv10_gpio_get; |
| 316 | engine->gpio.set = nv10_gpio_set; |
| 317 | engine->gpio.irq_enable = NULL; |
Ben Skeggs | 442b626 | 2010-09-16 16:25:26 +1000 | [diff] [blame] | 318 | engine->pm.clock_get = nv04_pm_clock_get; |
| 319 | engine->pm.clock_pre = nv04_pm_clock_pre; |
| 320 | engine->pm.clock_set = nv04_pm_clock_set; |
| 321 | engine->pm.voltage_get = nouveau_voltage_gpio_get; |
| 322 | engine->pm.voltage_set = nouveau_voltage_gpio_set; |
Francisco Jerez | 8155cac | 2010-09-23 20:58:38 +0200 | [diff] [blame] | 323 | engine->pm.temp_get = nv40_temp_get; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 324 | break; |
| 325 | case 0x50: |
| 326 | case 0x80: /* gotta love NVIDIA's consistency.. */ |
| 327 | case 0x90: |
| 328 | case 0xA0: |
| 329 | engine->instmem.init = nv50_instmem_init; |
| 330 | engine->instmem.takedown = nv50_instmem_takedown; |
| 331 | engine->instmem.suspend = nv50_instmem_suspend; |
| 332 | engine->instmem.resume = nv50_instmem_resume; |
| 333 | engine->instmem.populate = nv50_instmem_populate; |
| 334 | engine->instmem.clear = nv50_instmem_clear; |
| 335 | engine->instmem.bind = nv50_instmem_bind; |
| 336 | engine->instmem.unbind = nv50_instmem_unbind; |
Ben Skeggs | 734ee83 | 2010-07-15 11:02:54 +1000 | [diff] [blame] | 337 | if (dev_priv->chipset == 0x50) |
| 338 | engine->instmem.flush = nv50_instmem_flush; |
| 339 | else |
| 340 | engine->instmem.flush = nv84_instmem_flush; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 341 | engine->mc.init = nv50_mc_init; |
| 342 | engine->mc.takedown = nv50_mc_takedown; |
| 343 | engine->timer.init = nv04_timer_init; |
| 344 | engine->timer.read = nv04_timer_read; |
| 345 | engine->timer.takedown = nv04_timer_takedown; |
Marcin KoĆcielnicki | 304424e | 2010-03-01 00:18:39 +0000 | [diff] [blame] | 346 | engine->fb.init = nv50_fb_init; |
| 347 | engine->fb.takedown = nv50_fb_takedown; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 348 | engine->graph.grclass = nv50_graph_grclass; |
| 349 | engine->graph.init = nv50_graph_init; |
| 350 | engine->graph.takedown = nv50_graph_takedown; |
| 351 | engine->graph.fifo_access = nv50_graph_fifo_access; |
| 352 | engine->graph.channel = nv50_graph_channel; |
| 353 | engine->graph.create_context = nv50_graph_create_context; |
| 354 | engine->graph.destroy_context = nv50_graph_destroy_context; |
| 355 | engine->graph.load_context = nv50_graph_load_context; |
| 356 | engine->graph.unload_context = nv50_graph_unload_context; |
Ben Skeggs | 56ac747 | 2010-10-22 10:26:24 +1000 | [diff] [blame] | 357 | if (dev_priv->chipset != 0x86) |
| 358 | engine->graph.tlb_flush = nv50_graph_tlb_flush; |
| 359 | else { |
| 360 | /* from what i can see nvidia do this on every |
| 361 | * pre-NVA3 board except NVAC, but, we've only |
| 362 | * ever seen problems on NV86 |
| 363 | */ |
| 364 | engine->graph.tlb_flush = nv86_graph_tlb_flush; |
| 365 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 366 | engine->fifo.channels = 128; |
| 367 | engine->fifo.init = nv50_fifo_init; |
| 368 | engine->fifo.takedown = nv50_fifo_takedown; |
| 369 | engine->fifo.disable = nv04_fifo_disable; |
| 370 | engine->fifo.enable = nv04_fifo_enable; |
| 371 | engine->fifo.reassign = nv04_fifo_reassign; |
| 372 | engine->fifo.channel_id = nv50_fifo_channel_id; |
| 373 | engine->fifo.create_context = nv50_fifo_create_context; |
| 374 | engine->fifo.destroy_context = nv50_fifo_destroy_context; |
| 375 | engine->fifo.load_context = nv50_fifo_load_context; |
| 376 | engine->fifo.unload_context = nv50_fifo_unload_context; |
Ben Skeggs | 56ac747 | 2010-10-22 10:26:24 +1000 | [diff] [blame] | 377 | engine->fifo.tlb_flush = nv50_fifo_tlb_flush; |
Francisco Jerez | c88c2e0 | 2010-07-24 17:37:33 +0200 | [diff] [blame] | 378 | engine->display.early_init = nv50_display_early_init; |
| 379 | engine->display.late_takedown = nv50_display_late_takedown; |
| 380 | engine->display.create = nv50_display_create; |
| 381 | engine->display.init = nv50_display_init; |
| 382 | engine->display.destroy = nv50_display_destroy; |
Ben Skeggs | ee2e013 | 2010-07-26 09:28:25 +1000 | [diff] [blame] | 383 | engine->gpio.init = nv50_gpio_init; |
| 384 | engine->gpio.takedown = nouveau_stub_takedown; |
| 385 | engine->gpio.get = nv50_gpio_get; |
| 386 | engine->gpio.set = nv50_gpio_set; |
| 387 | engine->gpio.irq_enable = nv50_gpio_irq_enable; |
Ben Skeggs | fade7ad | 2010-09-27 11:18:14 +1000 | [diff] [blame] | 388 | switch (dev_priv->chipset) { |
| 389 | case 0xa3: |
| 390 | case 0xa5: |
| 391 | case 0xa8: |
| 392 | case 0xaf: |
| 393 | engine->pm.clock_get = nva3_pm_clock_get; |
| 394 | engine->pm.clock_pre = nva3_pm_clock_pre; |
| 395 | engine->pm.clock_set = nva3_pm_clock_set; |
| 396 | break; |
| 397 | default: |
| 398 | engine->pm.clock_get = nv50_pm_clock_get; |
| 399 | engine->pm.clock_pre = nv50_pm_clock_pre; |
| 400 | engine->pm.clock_set = nv50_pm_clock_set; |
| 401 | break; |
| 402 | } |
Ben Skeggs | 02c30ca | 2010-09-16 16:17:35 +1000 | [diff] [blame] | 403 | engine->pm.voltage_get = nouveau_voltage_gpio_get; |
| 404 | engine->pm.voltage_set = nouveau_voltage_gpio_set; |
Francisco Jerez | 8155cac | 2010-09-23 20:58:38 +0200 | [diff] [blame] | 405 | if (dev_priv->chipset >= 0x84) |
| 406 | engine->pm.temp_get = nv84_temp_get; |
| 407 | else |
| 408 | engine->pm.temp_get = nv40_temp_get; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 409 | break; |
Ben Skeggs | 4b223ee | 2010-08-03 10:00:56 +1000 | [diff] [blame] | 410 | case 0xC0: |
| 411 | engine->instmem.init = nvc0_instmem_init; |
| 412 | engine->instmem.takedown = nvc0_instmem_takedown; |
| 413 | engine->instmem.suspend = nvc0_instmem_suspend; |
| 414 | engine->instmem.resume = nvc0_instmem_resume; |
| 415 | engine->instmem.populate = nvc0_instmem_populate; |
| 416 | engine->instmem.clear = nvc0_instmem_clear; |
| 417 | engine->instmem.bind = nvc0_instmem_bind; |
| 418 | engine->instmem.unbind = nvc0_instmem_unbind; |
| 419 | engine->instmem.flush = nvc0_instmem_flush; |
| 420 | engine->mc.init = nv50_mc_init; |
| 421 | engine->mc.takedown = nv50_mc_takedown; |
| 422 | engine->timer.init = nv04_timer_init; |
| 423 | engine->timer.read = nv04_timer_read; |
| 424 | engine->timer.takedown = nv04_timer_takedown; |
| 425 | engine->fb.init = nvc0_fb_init; |
| 426 | engine->fb.takedown = nvc0_fb_takedown; |
| 427 | engine->graph.grclass = NULL; //nvc0_graph_grclass; |
| 428 | engine->graph.init = nvc0_graph_init; |
| 429 | engine->graph.takedown = nvc0_graph_takedown; |
| 430 | engine->graph.fifo_access = nvc0_graph_fifo_access; |
| 431 | engine->graph.channel = nvc0_graph_channel; |
| 432 | engine->graph.create_context = nvc0_graph_create_context; |
| 433 | engine->graph.destroy_context = nvc0_graph_destroy_context; |
| 434 | engine->graph.load_context = nvc0_graph_load_context; |
| 435 | engine->graph.unload_context = nvc0_graph_unload_context; |
| 436 | engine->fifo.channels = 128; |
| 437 | engine->fifo.init = nvc0_fifo_init; |
| 438 | engine->fifo.takedown = nvc0_fifo_takedown; |
| 439 | engine->fifo.disable = nvc0_fifo_disable; |
| 440 | engine->fifo.enable = nvc0_fifo_enable; |
| 441 | engine->fifo.reassign = nvc0_fifo_reassign; |
| 442 | engine->fifo.channel_id = nvc0_fifo_channel_id; |
| 443 | engine->fifo.create_context = nvc0_fifo_create_context; |
| 444 | engine->fifo.destroy_context = nvc0_fifo_destroy_context; |
| 445 | engine->fifo.load_context = nvc0_fifo_load_context; |
| 446 | engine->fifo.unload_context = nvc0_fifo_unload_context; |
| 447 | engine->display.early_init = nv50_display_early_init; |
| 448 | engine->display.late_takedown = nv50_display_late_takedown; |
| 449 | engine->display.create = nv50_display_create; |
| 450 | engine->display.init = nv50_display_init; |
| 451 | engine->display.destroy = nv50_display_destroy; |
| 452 | engine->gpio.init = nv50_gpio_init; |
| 453 | engine->gpio.takedown = nouveau_stub_takedown; |
| 454 | engine->gpio.get = nv50_gpio_get; |
| 455 | engine->gpio.set = nv50_gpio_set; |
| 456 | engine->gpio.irq_enable = nv50_gpio_irq_enable; |
| 457 | break; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 458 | default: |
| 459 | NV_ERROR(dev, "NV%02x unsupported\n", dev_priv->chipset); |
| 460 | return 1; |
| 461 | } |
| 462 | |
| 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | static unsigned int |
| 467 | nouveau_vga_set_decode(void *priv, bool state) |
| 468 | { |
Marcin KoĆcielnicki | 9967b94 | 2010-02-08 00:20:17 +0000 | [diff] [blame] | 469 | struct drm_device *dev = priv; |
| 470 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 471 | |
| 472 | if (dev_priv->chipset >= 0x40) |
| 473 | nv_wr32(dev, 0x88054, state); |
| 474 | else |
| 475 | nv_wr32(dev, 0x1854, state); |
| 476 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 477 | if (state) |
| 478 | return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM | |
| 479 | VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
| 480 | else |
| 481 | return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM; |
| 482 | } |
| 483 | |
Ben Skeggs | 0735f62 | 2009-12-16 14:28:55 +1000 | [diff] [blame] | 484 | static int |
| 485 | nouveau_card_init_channel(struct drm_device *dev) |
| 486 | { |
| 487 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 488 | struct nouveau_gpuobj *gpuobj = NULL; |
Ben Skeggs | 0735f62 | 2009-12-16 14:28:55 +1000 | [diff] [blame] | 489 | int ret; |
| 490 | |
| 491 | ret = nouveau_channel_alloc(dev, &dev_priv->channel, |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 492 | (struct drm_file *)-2, NvDmaFB, NvDmaTT); |
Ben Skeggs | 0735f62 | 2009-12-16 14:28:55 +1000 | [diff] [blame] | 493 | if (ret) |
| 494 | return ret; |
| 495 | |
Ben Skeggs | 0735f62 | 2009-12-16 14:28:55 +1000 | [diff] [blame] | 496 | 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] | 497 | 0, dev_priv->vram_size, |
Ben Skeggs | 0735f62 | 2009-12-16 14:28:55 +1000 | [diff] [blame] | 498 | NV_DMA_ACCESS_RW, NV_DMA_TARGET_VIDMEM, |
| 499 | &gpuobj); |
| 500 | if (ret) |
| 501 | goto out_err; |
| 502 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 503 | ret = nouveau_ramht_insert(dev_priv->channel, NvDmaVRAM, gpuobj); |
| 504 | nouveau_gpuobj_ref(NULL, &gpuobj); |
Ben Skeggs | 0735f62 | 2009-12-16 14:28:55 +1000 | [diff] [blame] | 505 | if (ret) |
| 506 | goto out_err; |
| 507 | |
Ben Skeggs | 0735f62 | 2009-12-16 14:28:55 +1000 | [diff] [blame] | 508 | ret = nouveau_gpuobj_gart_dma_new(dev_priv->channel, 0, |
| 509 | dev_priv->gart_info.aper_size, |
| 510 | NV_DMA_ACCESS_RW, &gpuobj, NULL); |
| 511 | if (ret) |
| 512 | goto out_err; |
| 513 | |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 514 | ret = nouveau_ramht_insert(dev_priv->channel, NvDmaGART, gpuobj); |
| 515 | nouveau_gpuobj_ref(NULL, &gpuobj); |
Ben Skeggs | 0735f62 | 2009-12-16 14:28:55 +1000 | [diff] [blame] | 516 | if (ret) |
| 517 | goto out_err; |
| 518 | |
Ben Skeggs | cff5c13 | 2010-10-06 16:16:59 +1000 | [diff] [blame] | 519 | mutex_unlock(&dev_priv->channel->mutex); |
Ben Skeggs | 0735f62 | 2009-12-16 14:28:55 +1000 | [diff] [blame] | 520 | return 0; |
Ben Skeggs | a8eaebc | 2010-09-01 15:24:31 +1000 | [diff] [blame] | 521 | |
Ben Skeggs | 0735f62 | 2009-12-16 14:28:55 +1000 | [diff] [blame] | 522 | out_err: |
Ben Skeggs | cff5c13 | 2010-10-06 16:16:59 +1000 | [diff] [blame] | 523 | nouveau_channel_put(&dev_priv->channel); |
Ben Skeggs | 0735f62 | 2009-12-16 14:28:55 +1000 | [diff] [blame] | 524 | return ret; |
| 525 | } |
| 526 | |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 527 | static void nouveau_switcheroo_set_state(struct pci_dev *pdev, |
| 528 | enum vga_switcheroo_state state) |
| 529 | { |
Dave Airlie | fbf8176 | 2010-06-01 09:09:06 +1000 | [diff] [blame] | 530 | struct drm_device *dev = pci_get_drvdata(pdev); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 531 | pm_message_t pmm = { .event = PM_EVENT_SUSPEND }; |
| 532 | if (state == VGA_SWITCHEROO_ON) { |
| 533 | printk(KERN_ERR "VGA switcheroo: switched nouveau on\n"); |
| 534 | nouveau_pci_resume(pdev); |
Dave Airlie | fbf8176 | 2010-06-01 09:09:06 +1000 | [diff] [blame] | 535 | drm_kms_helper_poll_enable(dev); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 536 | } else { |
| 537 | printk(KERN_ERR "VGA switcheroo: switched nouveau off\n"); |
Dave Airlie | fbf8176 | 2010-06-01 09:09:06 +1000 | [diff] [blame] | 538 | drm_kms_helper_poll_disable(dev); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 539 | nouveau_pci_suspend(pdev, pmm); |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev) |
| 544 | { |
| 545 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 546 | bool can_switch; |
| 547 | |
| 548 | spin_lock(&dev->count_lock); |
| 549 | can_switch = (dev->open_count == 0); |
| 550 | spin_unlock(&dev->count_lock); |
| 551 | return can_switch; |
| 552 | } |
| 553 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 554 | int |
| 555 | nouveau_card_init(struct drm_device *dev) |
| 556 | { |
| 557 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 558 | struct nouveau_engine *engine; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 559 | int ret; |
| 560 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 561 | vga_client_register(dev->pdev, dev, NULL, nouveau_vga_set_decode); |
Dave Airlie | 6a9ee8a | 2010-02-01 15:38:10 +1000 | [diff] [blame] | 562 | vga_switcheroo_register_client(dev->pdev, nouveau_switcheroo_set_state, |
| 563 | nouveau_switcheroo_can_switch); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 564 | |
| 565 | /* Initialise internal driver API hooks */ |
| 566 | ret = nouveau_init_engine_ptrs(dev); |
| 567 | if (ret) |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 568 | goto out; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 569 | engine = &dev_priv->engine; |
Ben Skeggs | cff5c13 | 2010-10-06 16:16:59 +1000 | [diff] [blame] | 570 | spin_lock_init(&dev_priv->channels.lock); |
Maarten Maathuis | ff9e527 | 2010-02-01 20:58:27 +0100 | [diff] [blame] | 571 | spin_lock_init(&dev_priv->context_switch_lock); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 572 | |
Francisco Jerez | c88c2e0 | 2010-07-24 17:37:33 +0200 | [diff] [blame] | 573 | /* Make the CRTCs and I2C buses accessible */ |
| 574 | ret = engine->display.early_init(dev); |
| 575 | if (ret) |
| 576 | goto out; |
| 577 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 578 | /* Parse BIOS tables / Run init tables if card not POSTed */ |
Ben Skeggs | cd0b072 | 2010-06-01 15:56:22 +1000 | [diff] [blame] | 579 | ret = nouveau_bios_init(dev); |
| 580 | if (ret) |
Francisco Jerez | c88c2e0 | 2010-07-24 17:37:33 +0200 | [diff] [blame] | 581 | goto out_display_early; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 582 | |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 583 | nouveau_pm_init(dev); |
| 584 | |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 585 | ret = nouveau_mem_vram_init(dev); |
Ben Skeggs | a76fb4e | 2010-03-18 09:45:20 +1000 | [diff] [blame] | 586 | if (ret) |
| 587 | goto out_bios; |
| 588 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 589 | ret = nouveau_gpuobj_init(dev); |
| 590 | if (ret) |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 591 | goto out_vram; |
| 592 | |
| 593 | ret = engine->instmem.init(dev); |
| 594 | if (ret) |
| 595 | goto out_gpuobj; |
| 596 | |
| 597 | ret = nouveau_mem_gart_init(dev); |
| 598 | if (ret) |
| 599 | goto out_instmem; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 600 | |
| 601 | /* PMC */ |
| 602 | ret = engine->mc.init(dev); |
| 603 | if (ret) |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 604 | goto out_gart; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 605 | |
Ben Skeggs | ee2e013 | 2010-07-26 09:28:25 +1000 | [diff] [blame] | 606 | /* PGPIO */ |
| 607 | ret = engine->gpio.init(dev); |
| 608 | if (ret) |
| 609 | goto out_mc; |
| 610 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 611 | /* PTIMER */ |
| 612 | ret = engine->timer.init(dev); |
| 613 | if (ret) |
Ben Skeggs | ee2e013 | 2010-07-26 09:28:25 +1000 | [diff] [blame] | 614 | goto out_gpio; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 615 | |
| 616 | /* PFB */ |
| 617 | ret = engine->fb.init(dev); |
| 618 | if (ret) |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 619 | goto out_timer; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 620 | |
Marcin KoĆcielnicki | a32ed69 | 2010-01-26 14:00:42 +0000 | [diff] [blame] | 621 | if (nouveau_noaccel) |
| 622 | engine->graph.accel_blocked = true; |
| 623 | else { |
| 624 | /* PGRAPH */ |
| 625 | ret = engine->graph.init(dev); |
| 626 | if (ret) |
| 627 | goto out_fb; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 628 | |
Marcin KoĆcielnicki | a32ed69 | 2010-01-26 14:00:42 +0000 | [diff] [blame] | 629 | /* PFIFO */ |
| 630 | ret = engine->fifo.init(dev); |
| 631 | if (ret) |
| 632 | goto out_graph; |
| 633 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 634 | |
Francisco Jerez | c88c2e0 | 2010-07-24 17:37:33 +0200 | [diff] [blame] | 635 | ret = engine->display.create(dev); |
Ben Skeggs | e88efe0 | 2010-07-09 10:56:08 +1000 | [diff] [blame] | 636 | if (ret) |
| 637 | goto out_fifo; |
| 638 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 639 | /* this call irq_preinstall, register irq handler and |
| 640 | * call irq_postinstall |
| 641 | */ |
| 642 | ret = drm_irq_install(dev); |
| 643 | if (ret) |
Ben Skeggs | e88efe0 | 2010-07-09 10:56:08 +1000 | [diff] [blame] | 644 | goto out_display; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 645 | |
| 646 | ret = drm_vblank_init(dev, 0); |
| 647 | if (ret) |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 648 | goto out_irq; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 649 | |
| 650 | /* what about PVIDEO/PCRTC/PRAMDAC etc? */ |
| 651 | |
Ben Skeggs | 0735f62 | 2009-12-16 14:28:55 +1000 | [diff] [blame] | 652 | if (!engine->graph.accel_blocked) { |
Francisco Jerez | 0c6c1c2 | 2010-09-22 00:58:54 +0200 | [diff] [blame] | 653 | ret = nouveau_fence_init(dev); |
Ben Skeggs | 0735f62 | 2009-12-16 14:28:55 +1000 | [diff] [blame] | 654 | if (ret) |
| 655 | goto out_irq; |
Francisco Jerez | 0c6c1c2 | 2010-09-22 00:58:54 +0200 | [diff] [blame] | 656 | |
| 657 | ret = nouveau_card_init_channel(dev); |
| 658 | if (ret) |
| 659 | goto out_fence; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 660 | } |
| 661 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 662 | ret = nouveau_backlight_init(dev); |
| 663 | if (ret) |
| 664 | NV_ERROR(dev, "Error %d registering backlight\n", ret); |
| 665 | |
Ben Skeggs | cd0b072 | 2010-06-01 15:56:22 +1000 | [diff] [blame] | 666 | nouveau_fbcon_init(dev); |
| 667 | drm_kms_helper_poll_init(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 668 | return 0; |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 669 | |
Francisco Jerez | 0c6c1c2 | 2010-09-22 00:58:54 +0200 | [diff] [blame] | 670 | out_fence: |
| 671 | nouveau_fence_fini(dev); |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 672 | out_irq: |
| 673 | drm_irq_uninstall(dev); |
Ben Skeggs | e88efe0 | 2010-07-09 10:56:08 +1000 | [diff] [blame] | 674 | out_display: |
Francisco Jerez | c88c2e0 | 2010-07-24 17:37:33 +0200 | [diff] [blame] | 675 | engine->display.destroy(dev); |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 676 | out_fifo: |
Marcin KoĆcielnicki | a32ed69 | 2010-01-26 14:00:42 +0000 | [diff] [blame] | 677 | if (!nouveau_noaccel) |
| 678 | engine->fifo.takedown(dev); |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 679 | out_graph: |
Marcin KoĆcielnicki | a32ed69 | 2010-01-26 14:00:42 +0000 | [diff] [blame] | 680 | if (!nouveau_noaccel) |
| 681 | engine->graph.takedown(dev); |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 682 | out_fb: |
| 683 | engine->fb.takedown(dev); |
| 684 | out_timer: |
| 685 | engine->timer.takedown(dev); |
Ben Skeggs | ee2e013 | 2010-07-26 09:28:25 +1000 | [diff] [blame] | 686 | out_gpio: |
| 687 | engine->gpio.takedown(dev); |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 688 | out_mc: |
| 689 | engine->mc.takedown(dev); |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 690 | out_gart: |
| 691 | nouveau_mem_gart_fini(dev); |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 692 | out_instmem: |
| 693 | engine->instmem.takedown(dev); |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 694 | out_gpuobj: |
| 695 | nouveau_gpuobj_takedown(dev); |
| 696 | out_vram: |
| 697 | nouveau_mem_vram_fini(dev); |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 698 | out_bios: |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 699 | nouveau_pm_fini(dev); |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 700 | nouveau_bios_takedown(dev); |
Francisco Jerez | c88c2e0 | 2010-07-24 17:37:33 +0200 | [diff] [blame] | 701 | out_display_early: |
| 702 | engine->display.late_takedown(dev); |
Marcin KoĆcielnicki | c5804be | 2009-12-14 20:58:39 +0000 | [diff] [blame] | 703 | out: |
| 704 | vga_client_register(dev->pdev, NULL, NULL, NULL); |
| 705 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | static void nouveau_card_takedown(struct drm_device *dev) |
| 709 | { |
| 710 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 711 | struct nouveau_engine *engine = &dev_priv->engine; |
| 712 | |
Ben Skeggs | b6d3d87 | 2010-06-07 15:38:27 +1000 | [diff] [blame] | 713 | nouveau_backlight_exit(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 714 | |
Francisco Jerez | 0c6c1c2 | 2010-09-22 00:58:54 +0200 | [diff] [blame] | 715 | if (!engine->graph.accel_blocked) { |
| 716 | nouveau_fence_fini(dev); |
Francisco Jerez | 36c952e | 2010-10-18 03:01:34 +0200 | [diff] [blame^] | 717 | nouveau_channel_put_unlocked(&dev_priv->channel); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 718 | } |
Ben Skeggs | b6d3d87 | 2010-06-07 15:38:27 +1000 | [diff] [blame] | 719 | |
| 720 | if (!nouveau_noaccel) { |
| 721 | engine->fifo.takedown(dev); |
| 722 | engine->graph.takedown(dev); |
| 723 | } |
| 724 | engine->fb.takedown(dev); |
| 725 | engine->timer.takedown(dev); |
Ben Skeggs | ee2e013 | 2010-07-26 09:28:25 +1000 | [diff] [blame] | 726 | engine->gpio.takedown(dev); |
Ben Skeggs | b6d3d87 | 2010-06-07 15:38:27 +1000 | [diff] [blame] | 727 | engine->mc.takedown(dev); |
Francisco Jerez | c88c2e0 | 2010-07-24 17:37:33 +0200 | [diff] [blame] | 728 | engine->display.late_takedown(dev); |
Ben Skeggs | b6d3d87 | 2010-06-07 15:38:27 +1000 | [diff] [blame] | 729 | |
| 730 | mutex_lock(&dev->struct_mutex); |
| 731 | ttm_bo_clean_mm(&dev_priv->ttm.bdev, TTM_PL_VRAM); |
| 732 | ttm_bo_clean_mm(&dev_priv->ttm.bdev, TTM_PL_TT); |
| 733 | mutex_unlock(&dev->struct_mutex); |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 734 | nouveau_mem_gart_fini(dev); |
Ben Skeggs | b6d3d87 | 2010-06-07 15:38:27 +1000 | [diff] [blame] | 735 | |
Ben Skeggs | b6d3d87 | 2010-06-07 15:38:27 +1000 | [diff] [blame] | 736 | engine->instmem.takedown(dev); |
Ben Skeggs | fbd2895 | 2010-09-01 15:24:34 +1000 | [diff] [blame] | 737 | nouveau_gpuobj_takedown(dev); |
| 738 | nouveau_mem_vram_fini(dev); |
Ben Skeggs | b6d3d87 | 2010-06-07 15:38:27 +1000 | [diff] [blame] | 739 | |
| 740 | drm_irq_uninstall(dev); |
| 741 | |
Ben Skeggs | 330c598 | 2010-09-16 15:39:49 +1000 | [diff] [blame] | 742 | nouveau_pm_fini(dev); |
Ben Skeggs | b6d3d87 | 2010-06-07 15:38:27 +1000 | [diff] [blame] | 743 | nouveau_bios_takedown(dev); |
| 744 | |
| 745 | vga_client_register(dev->pdev, NULL, NULL, NULL); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | /* here a client dies, release the stuff that was allocated for its |
| 749 | * file_priv */ |
| 750 | void nouveau_preclose(struct drm_device *dev, struct drm_file *file_priv) |
| 751 | { |
| 752 | nouveau_channel_cleanup(dev, file_priv); |
| 753 | } |
| 754 | |
| 755 | /* first module load, setup the mmio/fb mapping */ |
| 756 | /* KMS: we need mmio at load time, not when the first drm client opens. */ |
| 757 | int nouveau_firstopen(struct drm_device *dev) |
| 758 | { |
| 759 | return 0; |
| 760 | } |
| 761 | |
| 762 | /* if we have an OF card, copy vbios to RAMIN */ |
| 763 | static void nouveau_OF_copy_vbios_to_ramin(struct drm_device *dev) |
| 764 | { |
| 765 | #if defined(__powerpc__) |
| 766 | int size, i; |
| 767 | const uint32_t *bios; |
| 768 | struct device_node *dn = pci_device_to_OF_node(dev->pdev); |
| 769 | if (!dn) { |
| 770 | NV_INFO(dev, "Unable to get the OF node\n"); |
| 771 | return; |
| 772 | } |
| 773 | |
| 774 | bios = of_get_property(dn, "NVDA,BMP", &size); |
| 775 | if (bios) { |
| 776 | for (i = 0; i < size; i += 4) |
| 777 | nv_wi32(dev, i, bios[i/4]); |
| 778 | NV_INFO(dev, "OF bios successfully copied (%d bytes)\n", size); |
| 779 | } else { |
| 780 | NV_INFO(dev, "Unable to get the OF bios\n"); |
| 781 | } |
| 782 | #endif |
| 783 | } |
| 784 | |
Marcin Slusarz | 06415c5 | 2010-05-16 17:29:56 +0200 | [diff] [blame] | 785 | static struct apertures_struct *nouveau_get_apertures(struct drm_device *dev) |
| 786 | { |
| 787 | struct pci_dev *pdev = dev->pdev; |
| 788 | struct apertures_struct *aper = alloc_apertures(3); |
| 789 | if (!aper) |
| 790 | return NULL; |
| 791 | |
| 792 | aper->ranges[0].base = pci_resource_start(pdev, 1); |
| 793 | aper->ranges[0].size = pci_resource_len(pdev, 1); |
| 794 | aper->count = 1; |
| 795 | |
| 796 | if (pci_resource_len(pdev, 2)) { |
| 797 | aper->ranges[aper->count].base = pci_resource_start(pdev, 2); |
| 798 | aper->ranges[aper->count].size = pci_resource_len(pdev, 2); |
| 799 | aper->count++; |
| 800 | } |
| 801 | |
| 802 | if (pci_resource_len(pdev, 3)) { |
| 803 | aper->ranges[aper->count].base = pci_resource_start(pdev, 3); |
| 804 | aper->ranges[aper->count].size = pci_resource_len(pdev, 3); |
| 805 | aper->count++; |
| 806 | } |
| 807 | |
| 808 | return aper; |
| 809 | } |
| 810 | |
| 811 | static int nouveau_remove_conflicting_drivers(struct drm_device *dev) |
| 812 | { |
| 813 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Marcin Slusarz | 3b9676e | 2010-05-16 17:33:09 +0200 | [diff] [blame] | 814 | bool primary = false; |
Marcin Slusarz | 06415c5 | 2010-05-16 17:29:56 +0200 | [diff] [blame] | 815 | dev_priv->apertures = nouveau_get_apertures(dev); |
| 816 | if (!dev_priv->apertures) |
| 817 | return -ENOMEM; |
| 818 | |
Marcin Slusarz | 3b9676e | 2010-05-16 17:33:09 +0200 | [diff] [blame] | 819 | #ifdef CONFIG_X86 |
| 820 | primary = dev->pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW; |
| 821 | #endif |
| 822 | |
| 823 | remove_conflicting_framebuffers(dev_priv->apertures, "nouveaufb", primary); |
Marcin Slusarz | 06415c5 | 2010-05-16 17:29:56 +0200 | [diff] [blame] | 824 | return 0; |
| 825 | } |
| 826 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 827 | int nouveau_load(struct drm_device *dev, unsigned long flags) |
| 828 | { |
| 829 | struct drm_nouveau_private *dev_priv; |
| 830 | uint32_t reg0; |
| 831 | resource_size_t mmio_start_offs; |
Ben Skeggs | cd0b072 | 2010-06-01 15:56:22 +1000 | [diff] [blame] | 832 | int ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 833 | |
| 834 | dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL); |
Dan Carpenter | a0d069e | 2010-07-30 17:04:32 +0200 | [diff] [blame] | 835 | if (!dev_priv) { |
| 836 | ret = -ENOMEM; |
| 837 | goto err_out; |
| 838 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 839 | dev->dev_private = dev_priv; |
| 840 | dev_priv->dev = dev; |
| 841 | |
| 842 | dev_priv->flags = flags & NOUVEAU_FLAGS; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 843 | |
| 844 | NV_DEBUG(dev, "vendor: 0x%X device: 0x%X class: 0x%X\n", |
| 845 | dev->pci_vendor, dev->pci_device, dev->pdev->class); |
| 846 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 847 | dev_priv->wq = create_workqueue("nouveau"); |
Dan Carpenter | a0d069e | 2010-07-30 17:04:32 +0200 | [diff] [blame] | 848 | if (!dev_priv->wq) { |
| 849 | ret = -EINVAL; |
| 850 | goto err_priv; |
| 851 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 852 | |
| 853 | /* resource 0 is mmio regs */ |
| 854 | /* resource 1 is linear FB */ |
| 855 | /* resource 2 is RAMIN (mmio regs + 0x1000000) */ |
| 856 | /* resource 6 is bios */ |
| 857 | |
| 858 | /* map the mmio regs */ |
| 859 | mmio_start_offs = pci_resource_start(dev->pdev, 0); |
| 860 | dev_priv->mmio = ioremap(mmio_start_offs, 0x00800000); |
| 861 | if (!dev_priv->mmio) { |
| 862 | NV_ERROR(dev, "Unable to initialize the mmio mapping. " |
| 863 | "Please report your setup to " DRIVER_EMAIL "\n"); |
Dan Carpenter | a0d069e | 2010-07-30 17:04:32 +0200 | [diff] [blame] | 864 | ret = -EINVAL; |
| 865 | goto err_wq; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 866 | } |
| 867 | NV_DEBUG(dev, "regs mapped ok at 0x%llx\n", |
| 868 | (unsigned long long)mmio_start_offs); |
| 869 | |
| 870 | #ifdef __BIG_ENDIAN |
| 871 | /* Put the card in BE mode if it's not */ |
| 872 | if (nv_rd32(dev, NV03_PMC_BOOT_1)) |
| 873 | nv_wr32(dev, NV03_PMC_BOOT_1, 0x00000001); |
| 874 | |
| 875 | DRM_MEMORYBARRIER(); |
| 876 | #endif |
| 877 | |
| 878 | /* Time to determine the card architecture */ |
| 879 | reg0 = nv_rd32(dev, NV03_PMC_BOOT_0); |
| 880 | |
| 881 | /* We're dealing with >=NV10 */ |
| 882 | if ((reg0 & 0x0f000000) > 0) { |
| 883 | /* Bit 27-20 contain the architecture in hex */ |
| 884 | dev_priv->chipset = (reg0 & 0xff00000) >> 20; |
| 885 | /* NV04 or NV05 */ |
| 886 | } else if ((reg0 & 0xff00fff0) == 0x20004000) { |
Ben Skeggs | 1dee7a9 | 2010-01-07 13:47:57 +1000 | [diff] [blame] | 887 | if (reg0 & 0x00f00000) |
| 888 | dev_priv->chipset = 0x05; |
| 889 | else |
| 890 | dev_priv->chipset = 0x04; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 891 | } else |
| 892 | dev_priv->chipset = 0xff; |
| 893 | |
| 894 | switch (dev_priv->chipset & 0xf0) { |
| 895 | case 0x00: |
| 896 | case 0x10: |
| 897 | case 0x20: |
| 898 | case 0x30: |
| 899 | dev_priv->card_type = dev_priv->chipset & 0xf0; |
| 900 | break; |
| 901 | case 0x40: |
| 902 | case 0x60: |
| 903 | dev_priv->card_type = NV_40; |
| 904 | break; |
| 905 | case 0x50: |
| 906 | case 0x80: |
| 907 | case 0x90: |
| 908 | case 0xa0: |
| 909 | dev_priv->card_type = NV_50; |
| 910 | break; |
Ben Skeggs | 4b223ee | 2010-08-03 10:00:56 +1000 | [diff] [blame] | 911 | case 0xc0: |
| 912 | dev_priv->card_type = NV_C0; |
| 913 | break; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 914 | default: |
| 915 | NV_INFO(dev, "Unsupported chipset 0x%08x\n", reg0); |
Dan Carpenter | a0d069e | 2010-07-30 17:04:32 +0200 | [diff] [blame] | 916 | ret = -EINVAL; |
| 917 | goto err_mmio; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | NV_INFO(dev, "Detected an NV%2x generation card (0x%08x)\n", |
| 921 | dev_priv->card_type, reg0); |
| 922 | |
Ben Skeggs | cd0b072 | 2010-06-01 15:56:22 +1000 | [diff] [blame] | 923 | ret = nouveau_remove_conflicting_drivers(dev); |
| 924 | if (ret) |
Dan Carpenter | a0d069e | 2010-07-30 17:04:32 +0200 | [diff] [blame] | 925 | goto err_mmio; |
Marcin Slusarz | 06415c5 | 2010-05-16 17:29:56 +0200 | [diff] [blame] | 926 | |
Ben Skeggs | 6d69630 | 2010-06-02 10:16:24 +1000 | [diff] [blame] | 927 | /* Map PRAMIN BAR, or on older cards, the aperture withing BAR0 */ |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 928 | if (dev_priv->card_type >= NV_40) { |
| 929 | int ramin_bar = 2; |
| 930 | if (pci_resource_len(dev->pdev, ramin_bar) == 0) |
| 931 | ramin_bar = 3; |
| 932 | |
| 933 | dev_priv->ramin_size = pci_resource_len(dev->pdev, ramin_bar); |
Ben Skeggs | 6d69630 | 2010-06-02 10:16:24 +1000 | [diff] [blame] | 934 | dev_priv->ramin = |
| 935 | ioremap(pci_resource_start(dev->pdev, ramin_bar), |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 936 | dev_priv->ramin_size); |
| 937 | if (!dev_priv->ramin) { |
Ben Skeggs | 6d69630 | 2010-06-02 10:16:24 +1000 | [diff] [blame] | 938 | NV_ERROR(dev, "Failed to PRAMIN BAR"); |
Dan Carpenter | a0d069e | 2010-07-30 17:04:32 +0200 | [diff] [blame] | 939 | ret = -ENOMEM; |
| 940 | goto err_mmio; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 941 | } |
Ben Skeggs | 6d69630 | 2010-06-02 10:16:24 +1000 | [diff] [blame] | 942 | } else { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 943 | dev_priv->ramin_size = 1 * 1024 * 1024; |
| 944 | dev_priv->ramin = ioremap(mmio_start_offs + NV_RAMIN, |
Ben Skeggs | 6d69630 | 2010-06-02 10:16:24 +1000 | [diff] [blame] | 945 | dev_priv->ramin_size); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 946 | if (!dev_priv->ramin) { |
| 947 | NV_ERROR(dev, "Failed to map BAR0 PRAMIN.\n"); |
Dan Carpenter | a0d069e | 2010-07-30 17:04:32 +0200 | [diff] [blame] | 948 | ret = -ENOMEM; |
| 949 | goto err_mmio; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 950 | } |
| 951 | } |
| 952 | |
| 953 | nouveau_OF_copy_vbios_to_ramin(dev); |
| 954 | |
| 955 | /* Special flags */ |
| 956 | if (dev->pci_device == 0x01a0) |
| 957 | dev_priv->flags |= NV_NFORCE; |
| 958 | else if (dev->pci_device == 0x01f0) |
| 959 | dev_priv->flags |= NV_NFORCE2; |
| 960 | |
| 961 | /* For kernel modesetting, init card now and bring up fbcon */ |
Ben Skeggs | cd0b072 | 2010-06-01 15:56:22 +1000 | [diff] [blame] | 962 | ret = nouveau_card_init(dev); |
| 963 | if (ret) |
Dan Carpenter | a0d069e | 2010-07-30 17:04:32 +0200 | [diff] [blame] | 964 | goto err_ramin; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 965 | |
| 966 | return 0; |
Dan Carpenter | a0d069e | 2010-07-30 17:04:32 +0200 | [diff] [blame] | 967 | |
| 968 | err_ramin: |
| 969 | iounmap(dev_priv->ramin); |
| 970 | err_mmio: |
| 971 | iounmap(dev_priv->mmio); |
| 972 | err_wq: |
| 973 | destroy_workqueue(dev_priv->wq); |
| 974 | err_priv: |
| 975 | kfree(dev_priv); |
| 976 | dev->dev_private = NULL; |
| 977 | err_out: |
| 978 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 979 | } |
| 980 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 981 | void nouveau_lastclose(struct drm_device *dev) |
| 982 | { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | int nouveau_unload(struct drm_device *dev) |
| 986 | { |
| 987 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
Francisco Jerez | c88c2e0 | 2010-07-24 17:37:33 +0200 | [diff] [blame] | 988 | struct nouveau_engine *engine = &dev_priv->engine; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 989 | |
Ben Skeggs | cd0b072 | 2010-06-01 15:56:22 +1000 | [diff] [blame] | 990 | drm_kms_helper_poll_fini(dev); |
| 991 | nouveau_fbcon_fini(dev); |
Francisco Jerez | c88c2e0 | 2010-07-24 17:37:33 +0200 | [diff] [blame] | 992 | engine->display.destroy(dev); |
Ben Skeggs | cd0b072 | 2010-06-01 15:56:22 +1000 | [diff] [blame] | 993 | nouveau_card_takedown(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 994 | |
| 995 | iounmap(dev_priv->mmio); |
| 996 | iounmap(dev_priv->ramin); |
| 997 | |
| 998 | kfree(dev_priv); |
| 999 | dev->dev_private = NULL; |
| 1000 | return 0; |
| 1001 | } |
| 1002 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1003 | int nouveau_ioctl_getparam(struct drm_device *dev, void *data, |
| 1004 | struct drm_file *file_priv) |
| 1005 | { |
| 1006 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 1007 | struct drm_nouveau_getparam *getparam = data; |
| 1008 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1009 | switch (getparam->param) { |
| 1010 | case NOUVEAU_GETPARAM_CHIPSET_ID: |
| 1011 | getparam->value = dev_priv->chipset; |
| 1012 | break; |
| 1013 | case NOUVEAU_GETPARAM_PCI_VENDOR: |
| 1014 | getparam->value = dev->pci_vendor; |
| 1015 | break; |
| 1016 | case NOUVEAU_GETPARAM_PCI_DEVICE: |
| 1017 | getparam->value = dev->pci_device; |
| 1018 | break; |
| 1019 | case NOUVEAU_GETPARAM_BUS_TYPE: |
| 1020 | if (drm_device_is_agp(dev)) |
| 1021 | getparam->value = NV_AGP; |
| 1022 | else if (drm_device_is_pcie(dev)) |
| 1023 | getparam->value = NV_PCIE; |
| 1024 | else |
| 1025 | getparam->value = NV_PCI; |
| 1026 | break; |
| 1027 | case NOUVEAU_GETPARAM_FB_PHYSICAL: |
| 1028 | getparam->value = dev_priv->fb_phys; |
| 1029 | break; |
| 1030 | case NOUVEAU_GETPARAM_AGP_PHYSICAL: |
| 1031 | getparam->value = dev_priv->gart_info.aper_base; |
| 1032 | break; |
| 1033 | case NOUVEAU_GETPARAM_PCI_PHYSICAL: |
| 1034 | if (dev->sg) { |
| 1035 | getparam->value = (unsigned long)dev->sg->virtual; |
| 1036 | } else { |
| 1037 | NV_ERROR(dev, "Requested PCIGART address, " |
| 1038 | "while no PCIGART was created\n"); |
| 1039 | return -EINVAL; |
| 1040 | } |
| 1041 | break; |
| 1042 | case NOUVEAU_GETPARAM_FB_SIZE: |
| 1043 | getparam->value = dev_priv->fb_available_size; |
| 1044 | break; |
| 1045 | case NOUVEAU_GETPARAM_AGP_SIZE: |
| 1046 | getparam->value = dev_priv->gart_info.aper_size; |
| 1047 | break; |
| 1048 | case NOUVEAU_GETPARAM_VM_VRAM_BASE: |
| 1049 | getparam->value = dev_priv->vm_vram_base; |
| 1050 | break; |
Marcin KoĆcielnicki | 7fc74f1 | 2010-05-23 11:36:04 +0000 | [diff] [blame] | 1051 | case NOUVEAU_GETPARAM_PTIMER_TIME: |
| 1052 | getparam->value = dev_priv->engine.timer.read(dev); |
| 1053 | break; |
Francisco Jerez | f13b326 | 2010-10-10 06:01:08 +0200 | [diff] [blame] | 1054 | case NOUVEAU_GETPARAM_HAS_BO_USAGE: |
| 1055 | getparam->value = 1; |
| 1056 | break; |
Marcin KoĆcielnicki | 69c9700 | 2010-01-26 18:39:20 +0000 | [diff] [blame] | 1057 | case NOUVEAU_GETPARAM_GRAPH_UNITS: |
| 1058 | /* NV40 and NV50 versions are quite different, but register |
| 1059 | * address is the same. User is supposed to know the card |
| 1060 | * family anyway... */ |
| 1061 | if (dev_priv->chipset >= 0x40) { |
| 1062 | getparam->value = nv_rd32(dev, NV40_PMC_GRAPH_UNITS); |
| 1063 | break; |
| 1064 | } |
| 1065 | /* FALLTHRU */ |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1066 | default: |
Francisco Jerez | 1397b42 | 2010-10-12 03:17:43 +0200 | [diff] [blame] | 1067 | NV_DEBUG(dev, "unknown parameter %lld\n", getparam->param); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1068 | return -EINVAL; |
| 1069 | } |
| 1070 | |
| 1071 | return 0; |
| 1072 | } |
| 1073 | |
| 1074 | int |
| 1075 | nouveau_ioctl_setparam(struct drm_device *dev, void *data, |
| 1076 | struct drm_file *file_priv) |
| 1077 | { |
| 1078 | struct drm_nouveau_setparam *setparam = data; |
| 1079 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1080 | switch (setparam->param) { |
| 1081 | default: |
Francisco Jerez | 1397b42 | 2010-10-12 03:17:43 +0200 | [diff] [blame] | 1082 | NV_DEBUG(dev, "unknown parameter %lld\n", setparam->param); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1083 | return -EINVAL; |
| 1084 | } |
| 1085 | |
| 1086 | return 0; |
| 1087 | } |
| 1088 | |
| 1089 | /* Wait until (value(reg) & mask) == val, up until timeout has hit */ |
| 1090 | bool nouveau_wait_until(struct drm_device *dev, uint64_t timeout, |
| 1091 | uint32_t reg, uint32_t mask, uint32_t val) |
| 1092 | { |
| 1093 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 1094 | struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer; |
| 1095 | uint64_t start = ptimer->read(dev); |
| 1096 | |
| 1097 | do { |
| 1098 | if ((nv_rd32(dev, reg) & mask) == val) |
| 1099 | return true; |
| 1100 | } while (ptimer->read(dev) - start < timeout); |
| 1101 | |
| 1102 | return false; |
| 1103 | } |
| 1104 | |
| 1105 | /* Waits for PGRAPH to go completely idle */ |
| 1106 | bool nouveau_wait_for_idle(struct drm_device *dev) |
| 1107 | { |
Francisco Jerez | 4b5c152 | 2010-09-07 17:34:44 +0200 | [diff] [blame] | 1108 | if (!nv_wait(dev, NV04_PGRAPH_STATUS, 0xffffffff, 0x00000000)) { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1109 | NV_ERROR(dev, "PGRAPH idle timed out with status 0x%08x\n", |
| 1110 | nv_rd32(dev, NV04_PGRAPH_STATUS)); |
| 1111 | return false; |
| 1112 | } |
| 1113 | |
| 1114 | return true; |
| 1115 | } |
| 1116 | |