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