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