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