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