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