nouveau_state.c 37.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
 * Copyright 2005 Stephane Marchesin
 * Copyright 2008 Stuart Bennett
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#include <linux/swab.h>
27
#include <linux/slab.h>
28
29
30
31
32
#include "drmP.h"
#include "drm.h"
#include "drm_sarea.h"
#include "drm_crtc_helper.h"
#include <linux/vgaarb.h>
33
#include <linux/vga_switcheroo.h>
34
35
36

#include "nouveau_drv.h"
#include "nouveau_drm.h"
37
#include "nouveau_fbcon.h"
38
#include "nouveau_ramht.h"
39
#include "nouveau_gpio.h"
40
#include "nouveau_pm.h"
41
#include "nv50_display.h"
42
#include "nouveau_fifo.h"
43
#include "nouveau_fence.h"
44
#include "nouveau_software.h"
45
46

static void nouveau_stub_takedown(struct drm_device *dev) {}
47
static int nouveau_stub_init(struct drm_device *dev) { return 0; }
48
49
50
51
52
53
54
55
56
57
58
59

static int nouveau_init_engine_ptrs(struct drm_device *dev)
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	struct nouveau_engine *engine = &dev_priv->engine;

	switch (dev_priv->chipset & 0xf0) {
	case 0x00:
		engine->instmem.init		= nv04_instmem_init;
		engine->instmem.takedown	= nv04_instmem_takedown;
		engine->instmem.suspend		= nv04_instmem_suspend;
		engine->instmem.resume		= nv04_instmem_resume;
60
61
62
63
		engine->instmem.get		= nv04_instmem_get;
		engine->instmem.put		= nv04_instmem_put;
		engine->instmem.map		= nv04_instmem_map;
		engine->instmem.unmap		= nv04_instmem_unmap;
64
		engine->instmem.flush		= nv04_instmem_flush;
65
66
67
68
69
70
71
		engine->mc.init			= nv04_mc_init;
		engine->mc.takedown		= nv04_mc_takedown;
		engine->timer.init		= nv04_timer_init;
		engine->timer.read		= nv04_timer_read;
		engine->timer.takedown		= nv04_timer_takedown;
		engine->fb.init			= nv04_fb_init;
		engine->fb.takedown		= nv04_fb_takedown;
72
73
74
75
		engine->display.early_init	= nv04_display_early_init;
		engine->display.late_takedown	= nv04_display_late_takedown;
		engine->display.create		= nv04_display_create;
		engine->display.destroy		= nv04_display_destroy;
76
77
		engine->display.init		= nv04_display_init;
		engine->display.fini		= nv04_display_fini;
78
79
80
		engine->pm.clocks_get		= nv04_pm_clocks_get;
		engine->pm.clocks_pre		= nv04_pm_clocks_pre;
		engine->pm.clocks_set		= nv04_pm_clocks_set;
81
		engine->vram.init		= nv04_fb_vram_init;
82
		engine->vram.takedown		= nouveau_stub_takedown;
83
		engine->vram.flags_valid	= nouveau_mem_flags_valid;
84
85
86
87
88
89
		break;
	case 0x10:
		engine->instmem.init		= nv04_instmem_init;
		engine->instmem.takedown	= nv04_instmem_takedown;
		engine->instmem.suspend		= nv04_instmem_suspend;
		engine->instmem.resume		= nv04_instmem_resume;
90
91
92
93
		engine->instmem.get		= nv04_instmem_get;
		engine->instmem.put		= nv04_instmem_put;
		engine->instmem.map		= nv04_instmem_map;
		engine->instmem.unmap		= nv04_instmem_unmap;
94
		engine->instmem.flush		= nv04_instmem_flush;
95
96
97
98
99
100
101
		engine->mc.init			= nv04_mc_init;
		engine->mc.takedown		= nv04_mc_takedown;
		engine->timer.init		= nv04_timer_init;
		engine->timer.read		= nv04_timer_read;
		engine->timer.takedown		= nv04_timer_takedown;
		engine->fb.init			= nv10_fb_init;
		engine->fb.takedown		= nv10_fb_takedown;
102
103
104
		engine->fb.init_tile_region	= nv10_fb_init_tile_region;
		engine->fb.set_tile_region	= nv10_fb_set_tile_region;
		engine->fb.free_tile_region	= nv10_fb_free_tile_region;
105
106
107
108
		engine->display.early_init	= nv04_display_early_init;
		engine->display.late_takedown	= nv04_display_late_takedown;
		engine->display.create		= nv04_display_create;
		engine->display.destroy		= nv04_display_destroy;
109
110
		engine->display.init		= nv04_display_init;
		engine->display.fini		= nv04_display_fini;
111
112
		engine->gpio.drive		= nv10_gpio_drive;
		engine->gpio.sense		= nv10_gpio_sense;
113
114
115
		engine->pm.clocks_get		= nv04_pm_clocks_get;
		engine->pm.clocks_pre		= nv04_pm_clocks_pre;
		engine->pm.clocks_set		= nv04_pm_clocks_set;
116
117
118
119
120
		if (dev_priv->chipset == 0x1a ||
		    dev_priv->chipset == 0x1f)
			engine->vram.init	= nv1a_fb_vram_init;
		else
			engine->vram.init	= nv10_fb_vram_init;
121
		engine->vram.takedown		= nouveau_stub_takedown;
122
		engine->vram.flags_valid	= nouveau_mem_flags_valid;
123
124
125
126
127
128
		break;
	case 0x20:
		engine->instmem.init		= nv04_instmem_init;
		engine->instmem.takedown	= nv04_instmem_takedown;
		engine->instmem.suspend		= nv04_instmem_suspend;
		engine->instmem.resume		= nv04_instmem_resume;
129
130
131
132
		engine->instmem.get		= nv04_instmem_get;
		engine->instmem.put		= nv04_instmem_put;
		engine->instmem.map		= nv04_instmem_map;
		engine->instmem.unmap		= nv04_instmem_unmap;
133
		engine->instmem.flush		= nv04_instmem_flush;
134
135
136
137
138
		engine->mc.init			= nv04_mc_init;
		engine->mc.takedown		= nv04_mc_takedown;
		engine->timer.init		= nv04_timer_init;
		engine->timer.read		= nv04_timer_read;
		engine->timer.takedown		= nv04_timer_takedown;
139
140
141
142
143
		engine->fb.init			= nv20_fb_init;
		engine->fb.takedown		= nv20_fb_takedown;
		engine->fb.init_tile_region	= nv20_fb_init_tile_region;
		engine->fb.set_tile_region	= nv20_fb_set_tile_region;
		engine->fb.free_tile_region	= nv20_fb_free_tile_region;
144
145
146
147
		engine->display.early_init	= nv04_display_early_init;
		engine->display.late_takedown	= nv04_display_late_takedown;
		engine->display.create		= nv04_display_create;
		engine->display.destroy		= nv04_display_destroy;
148
149
		engine->display.init		= nv04_display_init;
		engine->display.fini		= nv04_display_fini;
150
151
		engine->gpio.drive		= nv10_gpio_drive;
		engine->gpio.sense		= nv10_gpio_sense;
152
153
154
		engine->pm.clocks_get		= nv04_pm_clocks_get;
		engine->pm.clocks_pre		= nv04_pm_clocks_pre;
		engine->pm.clocks_set		= nv04_pm_clocks_set;
155
		engine->vram.init		= nv20_fb_vram_init;
156
		engine->vram.takedown		= nouveau_stub_takedown;
157
		engine->vram.flags_valid	= nouveau_mem_flags_valid;
158
159
160
161
162
163
		break;
	case 0x30:
		engine->instmem.init		= nv04_instmem_init;
		engine->instmem.takedown	= nv04_instmem_takedown;
		engine->instmem.suspend		= nv04_instmem_suspend;
		engine->instmem.resume		= nv04_instmem_resume;
164
165
166
167
		engine->instmem.get		= nv04_instmem_get;
		engine->instmem.put		= nv04_instmem_put;
		engine->instmem.map		= nv04_instmem_map;
		engine->instmem.unmap		= nv04_instmem_unmap;
168
		engine->instmem.flush		= nv04_instmem_flush;
169
170
171
172
173
		engine->mc.init			= nv04_mc_init;
		engine->mc.takedown		= nv04_mc_takedown;
		engine->timer.init		= nv04_timer_init;
		engine->timer.read		= nv04_timer_read;
		engine->timer.takedown		= nv04_timer_takedown;
174
175
		engine->fb.init			= nv30_fb_init;
		engine->fb.takedown		= nv30_fb_takedown;
176
177
178
		engine->fb.init_tile_region	= nv30_fb_init_tile_region;
		engine->fb.set_tile_region	= nv10_fb_set_tile_region;
		engine->fb.free_tile_region	= nv30_fb_free_tile_region;
179
180
181
182
		engine->display.early_init	= nv04_display_early_init;
		engine->display.late_takedown	= nv04_display_late_takedown;
		engine->display.create		= nv04_display_create;
		engine->display.destroy		= nv04_display_destroy;
183
184
		engine->display.init		= nv04_display_init;
		engine->display.fini		= nv04_display_fini;
185
186
		engine->gpio.drive		= nv10_gpio_drive;
		engine->gpio.sense		= nv10_gpio_sense;
187
188
189
		engine->pm.clocks_get		= nv04_pm_clocks_get;
		engine->pm.clocks_pre		= nv04_pm_clocks_pre;
		engine->pm.clocks_set		= nv04_pm_clocks_set;
190
191
		engine->pm.voltage_get		= nouveau_voltage_gpio_get;
		engine->pm.voltage_set		= nouveau_voltage_gpio_set;
192
		engine->vram.init		= nv20_fb_vram_init;
193
		engine->vram.takedown		= nouveau_stub_takedown;
194
		engine->vram.flags_valid	= nouveau_mem_flags_valid;
195
196
197
198
199
200
201
		break;
	case 0x40:
	case 0x60:
		engine->instmem.init		= nv04_instmem_init;
		engine->instmem.takedown	= nv04_instmem_takedown;
		engine->instmem.suspend		= nv04_instmem_suspend;
		engine->instmem.resume		= nv04_instmem_resume;
202
203
204
205
		engine->instmem.get		= nv04_instmem_get;
		engine->instmem.put		= nv04_instmem_put;
		engine->instmem.map		= nv04_instmem_map;
		engine->instmem.unmap		= nv04_instmem_unmap;
206
		engine->instmem.flush		= nv04_instmem_flush;
207
208
209
210
211
212
213
		engine->mc.init			= nv40_mc_init;
		engine->mc.takedown		= nv40_mc_takedown;
		engine->timer.init		= nv04_timer_init;
		engine->timer.read		= nv04_timer_read;
		engine->timer.takedown		= nv04_timer_takedown;
		engine->fb.init			= nv40_fb_init;
		engine->fb.takedown		= nv40_fb_takedown;
214
215
216
		engine->fb.init_tile_region	= nv30_fb_init_tile_region;
		engine->fb.set_tile_region	= nv40_fb_set_tile_region;
		engine->fb.free_tile_region	= nv30_fb_free_tile_region;
217
218
219
220
		engine->display.early_init	= nv04_display_early_init;
		engine->display.late_takedown	= nv04_display_late_takedown;
		engine->display.create		= nv04_display_create;
		engine->display.destroy		= nv04_display_destroy;
221
222
		engine->display.init		= nv04_display_init;
		engine->display.fini		= nv04_display_fini;
223
224
		engine->gpio.init		= nv10_gpio_init;
		engine->gpio.fini		= nv10_gpio_fini;
225
226
		engine->gpio.drive		= nv10_gpio_drive;
		engine->gpio.sense		= nv10_gpio_sense;
227
		engine->gpio.irq_enable		= nv10_gpio_irq_enable;
228
229
230
		engine->pm.clocks_get		= nv40_pm_clocks_get;
		engine->pm.clocks_pre		= nv40_pm_clocks_pre;
		engine->pm.clocks_set		= nv40_pm_clocks_set;
231
232
		engine->pm.voltage_get		= nouveau_voltage_gpio_get;
		engine->pm.voltage_set		= nouveau_voltage_gpio_set;
233
		engine->pm.temp_get		= nv40_temp_get;
234
235
		engine->pm.pwm_get		= nv40_pm_pwm_get;
		engine->pm.pwm_set		= nv40_pm_pwm_set;
236
		engine->vram.init		= nv40_fb_vram_init;
237
		engine->vram.takedown		= nouveau_stub_takedown;
238
		engine->vram.flags_valid	= nouveau_mem_flags_valid;
239
240
241
242
		break;
	case 0x50:
	case 0x80: /* gotta love NVIDIA's consistency.. */
	case 0x90:
243
	case 0xa0:
244
245
246
247
		engine->instmem.init		= nv50_instmem_init;
		engine->instmem.takedown	= nv50_instmem_takedown;
		engine->instmem.suspend		= nv50_instmem_suspend;
		engine->instmem.resume		= nv50_instmem_resume;
248
249
250
251
		engine->instmem.get		= nv50_instmem_get;
		engine->instmem.put		= nv50_instmem_put;
		engine->instmem.map		= nv50_instmem_map;
		engine->instmem.unmap		= nv50_instmem_unmap;
252
253
254
255
		if (dev_priv->chipset == 0x50)
			engine->instmem.flush	= nv50_instmem_flush;
		else
			engine->instmem.flush	= nv84_instmem_flush;
256
257
258
259
260
		engine->mc.init			= nv50_mc_init;
		engine->mc.takedown		= nv50_mc_takedown;
		engine->timer.init		= nv04_timer_init;
		engine->timer.read		= nv04_timer_read;
		engine->timer.takedown		= nv04_timer_takedown;
261
262
		engine->fb.init			= nv50_fb_init;
		engine->fb.takedown		= nv50_fb_takedown;
263
264
265
266
		engine->display.early_init	= nv50_display_early_init;
		engine->display.late_takedown	= nv50_display_late_takedown;
		engine->display.create		= nv50_display_create;
		engine->display.destroy		= nv50_display_destroy;
267
268
		engine->display.init		= nv50_display_init;
		engine->display.fini		= nv50_display_fini;
269
		engine->gpio.init		= nv50_gpio_init;
270
271
272
		engine->gpio.fini		= nv50_gpio_fini;
		engine->gpio.drive		= nv50_gpio_drive;
		engine->gpio.sense		= nv50_gpio_sense;
273
		engine->gpio.irq_enable		= nv50_gpio_irq_enable;
274
		switch (dev_priv->chipset) {
275
276
277
278
279
280
281
		case 0x84:
		case 0x86:
		case 0x92:
		case 0x94:
		case 0x96:
		case 0x98:
		case 0xa0:
282
283
		case 0xaa:
		case 0xac:
284
		case 0x50:
285
286
287
			engine->pm.clocks_get	= nv50_pm_clocks_get;
			engine->pm.clocks_pre	= nv50_pm_clocks_pre;
			engine->pm.clocks_set	= nv50_pm_clocks_set;
288
			break;
289
		default:
290
291
292
			engine->pm.clocks_get	= nva3_pm_clocks_get;
			engine->pm.clocks_pre	= nva3_pm_clocks_pre;
			engine->pm.clocks_set	= nva3_pm_clocks_set;
293
			break;
294
		}
295
296
		engine->pm.voltage_get		= nouveau_voltage_gpio_get;
		engine->pm.voltage_set		= nouveau_voltage_gpio_set;
297
298
299
300
		if (dev_priv->chipset >= 0x84)
			engine->pm.temp_get	= nv84_temp_get;
		else
			engine->pm.temp_get	= nv40_temp_get;
301
302
		engine->pm.pwm_get		= nv50_pm_pwm_get;
		engine->pm.pwm_set		= nv50_pm_pwm_set;
303
		engine->vram.init		= nv50_vram_init;
304
		engine->vram.takedown		= nv50_vram_fini;
305
306
307
		engine->vram.get		= nv50_vram_new;
		engine->vram.put		= nv50_vram_del;
		engine->vram.flags_valid	= nv50_vram_flags_valid;
308
		break;
309
	case 0xc0:
310
311
312
313
		engine->instmem.init		= nvc0_instmem_init;
		engine->instmem.takedown	= nvc0_instmem_takedown;
		engine->instmem.suspend		= nvc0_instmem_suspend;
		engine->instmem.resume		= nvc0_instmem_resume;
314
315
316
317
318
		engine->instmem.get		= nv50_instmem_get;
		engine->instmem.put		= nv50_instmem_put;
		engine->instmem.map		= nv50_instmem_map;
		engine->instmem.unmap		= nv50_instmem_unmap;
		engine->instmem.flush		= nv84_instmem_flush;
319
320
321
322
323
324
325
326
327
328
329
		engine->mc.init			= nv50_mc_init;
		engine->mc.takedown		= nv50_mc_takedown;
		engine->timer.init		= nv04_timer_init;
		engine->timer.read		= nv04_timer_read;
		engine->timer.takedown		= nv04_timer_takedown;
		engine->fb.init			= nvc0_fb_init;
		engine->fb.takedown		= nvc0_fb_takedown;
		engine->display.early_init	= nv50_display_early_init;
		engine->display.late_takedown	= nv50_display_late_takedown;
		engine->display.create		= nv50_display_create;
		engine->display.destroy		= nv50_display_destroy;
330
331
		engine->display.init		= nv50_display_init;
		engine->display.fini		= nv50_display_fini;
332
		engine->gpio.init		= nv50_gpio_init;
333
334
335
		engine->gpio.fini		= nv50_gpio_fini;
		engine->gpio.drive		= nv50_gpio_drive;
		engine->gpio.sense		= nv50_gpio_sense;
336
		engine->gpio.irq_enable		= nv50_gpio_irq_enable;
337
		engine->vram.init		= nvc0_vram_init;
338
		engine->vram.takedown		= nv50_vram_fini;
339
340
341
		engine->vram.get		= nvc0_vram_new;
		engine->vram.put		= nv50_vram_del;
		engine->vram.flags_valid	= nvc0_vram_flags_valid;
342
		engine->pm.temp_get		= nv84_temp_get;
343
		engine->pm.clocks_get		= nvc0_pm_clocks_get;
344
345
		engine->pm.clocks_pre		= nvc0_pm_clocks_pre;
		engine->pm.clocks_set		= nvc0_pm_clocks_set;
Ben Skeggs's avatar
Ben Skeggs committed
346
		engine->pm.voltage_get		= nouveau_voltage_gpio_get;
347
		engine->pm.voltage_set		= nouveau_voltage_gpio_set;
348
349
		engine->pm.pwm_get		= nv50_pm_pwm_get;
		engine->pm.pwm_set		= nv50_pm_pwm_set;
350
		break;
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
	case 0xd0:
		engine->instmem.init		= nvc0_instmem_init;
		engine->instmem.takedown	= nvc0_instmem_takedown;
		engine->instmem.suspend		= nvc0_instmem_suspend;
		engine->instmem.resume		= nvc0_instmem_resume;
		engine->instmem.get		= nv50_instmem_get;
		engine->instmem.put		= nv50_instmem_put;
		engine->instmem.map		= nv50_instmem_map;
		engine->instmem.unmap		= nv50_instmem_unmap;
		engine->instmem.flush		= nv84_instmem_flush;
		engine->mc.init			= nv50_mc_init;
		engine->mc.takedown		= nv50_mc_takedown;
		engine->timer.init		= nv04_timer_init;
		engine->timer.read		= nv04_timer_read;
		engine->timer.takedown		= nv04_timer_takedown;
		engine->fb.init			= nvc0_fb_init;
		engine->fb.takedown		= nvc0_fb_takedown;
		engine->display.early_init	= nouveau_stub_init;
		engine->display.late_takedown	= nouveau_stub_takedown;
370
371
		engine->display.create		= nvd0_display_create;
		engine->display.destroy		= nvd0_display_destroy;
372
373
		engine->display.init		= nvd0_display_init;
		engine->display.fini		= nvd0_display_fini;
374
		engine->gpio.init		= nv50_gpio_init;
375
376
377
		engine->gpio.fini		= nv50_gpio_fini;
		engine->gpio.drive		= nvd0_gpio_drive;
		engine->gpio.sense		= nvd0_gpio_sense;
378
		engine->gpio.irq_enable		= nv50_gpio_irq_enable;
379
380
381
382
383
		engine->vram.init		= nvc0_vram_init;
		engine->vram.takedown		= nv50_vram_fini;
		engine->vram.get		= nvc0_vram_new;
		engine->vram.put		= nv50_vram_del;
		engine->vram.flags_valid	= nvc0_vram_flags_valid;
384
		engine->pm.temp_get		= nv84_temp_get;
385
		engine->pm.clocks_get		= nvc0_pm_clocks_get;
386
387
		engine->pm.clocks_pre		= nvc0_pm_clocks_pre;
		engine->pm.clocks_set		= nvc0_pm_clocks_set;
388
389
		engine->pm.voltage_get		= nouveau_voltage_gpio_get;
		engine->pm.voltage_set		= nouveau_voltage_gpio_set;
390
		break;
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
	case 0xe0:
		engine->instmem.init		= nvc0_instmem_init;
		engine->instmem.takedown	= nvc0_instmem_takedown;
		engine->instmem.suspend		= nvc0_instmem_suspend;
		engine->instmem.resume		= nvc0_instmem_resume;
		engine->instmem.get		= nv50_instmem_get;
		engine->instmem.put		= nv50_instmem_put;
		engine->instmem.map		= nv50_instmem_map;
		engine->instmem.unmap		= nv50_instmem_unmap;
		engine->instmem.flush		= nv84_instmem_flush;
		engine->mc.init			= nv50_mc_init;
		engine->mc.takedown		= nv50_mc_takedown;
		engine->timer.init		= nv04_timer_init;
		engine->timer.read		= nv04_timer_read;
		engine->timer.takedown		= nv04_timer_takedown;
		engine->fb.init			= nvc0_fb_init;
		engine->fb.takedown		= nvc0_fb_takedown;
		engine->display.early_init	= nouveau_stub_init;
		engine->display.late_takedown	= nouveau_stub_takedown;
		engine->display.create		= nvd0_display_create;
		engine->display.destroy		= nvd0_display_destroy;
		engine->display.init		= nvd0_display_init;
		engine->display.fini		= nvd0_display_fini;
		engine->gpio.init		= nv50_gpio_init;
		engine->gpio.fini		= nv50_gpio_fini;
		engine->gpio.drive		= nvd0_gpio_drive;
		engine->gpio.sense		= nvd0_gpio_sense;
		engine->gpio.irq_enable		= nv50_gpio_irq_enable;
		engine->vram.init		= nvc0_vram_init;
		engine->vram.takedown		= nv50_vram_fini;
		engine->vram.get		= nvc0_vram_new;
		engine->vram.put		= nv50_vram_del;
		engine->vram.flags_valid	= nvc0_vram_flags_valid;
		break;
425
426
427
428
429
	default:
		NV_ERROR(dev, "NV%02x unsupported\n", dev_priv->chipset);
		return 1;
	}

430
431
432
433
434
435
436
437
438
	/* headless mode */
	if (nouveau_modeset == 2) {
		engine->display.early_init = nouveau_stub_init;
		engine->display.late_takedown = nouveau_stub_takedown;
		engine->display.create = nouveau_stub_init;
		engine->display.init = nouveau_stub_init;
		engine->display.destroy = nouveau_stub_takedown;
	}

439
440
441
442
443
444
	return 0;
}

static unsigned int
nouveau_vga_set_decode(void *priv, bool state)
{
445
446
447
448
449
450
451
452
	struct drm_device *dev = priv;
	struct drm_nouveau_private *dev_priv = dev->dev_private;

	if (dev_priv->chipset >= 0x40)
		nv_wr32(dev, 0x88054, state);
	else
		nv_wr32(dev, 0x1854, state);

453
454
455
456
457
458
459
	if (state)
		return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
		       VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
	else
		return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
}

460
461
462
static void nouveau_switcheroo_set_state(struct pci_dev *pdev,
					 enum vga_switcheroo_state state)
{
463
	struct drm_device *dev = pci_get_drvdata(pdev);
464
465
466
	pm_message_t pmm = { .event = PM_EVENT_SUSPEND };
	if (state == VGA_SWITCHEROO_ON) {
		printk(KERN_ERR "VGA switcheroo: switched nouveau on\n");
467
		dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
468
		nouveau_pci_resume(pdev);
469
		drm_kms_helper_poll_enable(dev);
470
		dev->switch_power_state = DRM_SWITCH_POWER_ON;
471
472
	} else {
		printk(KERN_ERR "VGA switcheroo: switched nouveau off\n");
473
		dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
474
		drm_kms_helper_poll_disable(dev);
475
		nouveau_switcheroo_optimus_dsm();
476
		nouveau_pci_suspend(pdev, pmm);
477
		dev->switch_power_state = DRM_SWITCH_POWER_OFF;
478
479
480
	}
}

481
482
483
484
485
486
static void nouveau_switcheroo_reprobe(struct pci_dev *pdev)
{
	struct drm_device *dev = pci_get_drvdata(pdev);
	nouveau_fbcon_output_poll_changed(dev);
}

487
488
489
490
491
492
493
494
495
496
497
static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
{
	struct drm_device *dev = pci_get_drvdata(pdev);
	bool can_switch;

	spin_lock(&dev->count_lock);
	can_switch = (dev->open_count == 0);
	spin_unlock(&dev->count_lock);
	return can_switch;
}

498
499
500
501
502
503
504
505
506
507
508
509
510
511
static void
nouveau_card_channel_fini(struct drm_device *dev)
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;

	if (dev_priv->channel)
		nouveau_channel_put_unlocked(&dev_priv->channel);
}

static int
nouveau_card_channel_init(struct drm_device *dev)
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	struct nouveau_channel *chan;
512
	int ret;
513
514
515
516
517
518
519

	ret = nouveau_channel_alloc(dev, &chan, NULL, NvDmaFB, NvDmaTT);
	dev_priv->channel = chan;
	if (ret)
		return ret;
	mutex_unlock(&dev_priv->channel->mutex);

520
521
	nouveau_bo_move_init(chan);
	return 0;
522
523
}

524
525
526
527
528
529
static const struct vga_switcheroo_client_ops nouveau_switcheroo_ops = {
	.set_gpu_state = nouveau_switcheroo_set_state,
	.reprobe = nouveau_switcheroo_reprobe,
	.can_switch = nouveau_switcheroo_can_switch,
};

530
531
532
533
534
int
nouveau_card_init(struct drm_device *dev)
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	struct nouveau_engine *engine;
535
	int ret, e = 0;
536
537

	vga_client_register(dev->pdev, dev, NULL, nouveau_vga_set_decode);
538
	vga_switcheroo_register_client(dev->pdev, &nouveau_switcheroo_ops);
539
540
541
542

	/* Initialise internal driver API hooks */
	ret = nouveau_init_engine_ptrs(dev);
	if (ret)
543
		goto out;
544
	engine = &dev_priv->engine;
545
	spin_lock_init(&dev_priv->channels.lock);
546
	spin_lock_init(&dev_priv->tile.lock);
547
	spin_lock_init(&dev_priv->context_switch_lock);
548
	spin_lock_init(&dev_priv->vm_lock);
549

550
551
552
553
554
	/* Make the CRTCs and I2C buses accessible */
	ret = engine->display.early_init(dev);
	if (ret)
		goto out;

555
	/* Parse BIOS tables / Run init tables if card not POSTed */
556
557
	ret = nouveau_bios_init(dev);
	if (ret)
558
		goto out_display_early;
559

560
561
562
563
564
565
566
567
	/* workaround an odd issue on nvc1 by disabling the device's
	 * nosnoop capability.  hopefully won't cause issues until a
	 * better fix is found - assuming there is one...
	 */
	if (dev_priv->chipset == 0xc1) {
		nv_mask(dev, 0x00088080, 0x00000800, 0x00000000);
	}

568
569
570
571
572
573
574
575
576
577
578
579
580
581
	/* PMC */
	ret = engine->mc.init(dev);
	if (ret)
		goto out_bios;

	/* PTIMER */
	ret = engine->timer.init(dev);
	if (ret)
		goto out_mc;

	/* PFB */
	ret = engine->fb.init(dev);
	if (ret)
		goto out_timer;
582

583
	ret = engine->vram.init(dev);
584
	if (ret)
585
		goto out_fb;
586

587
588
	/* PGPIO */
	ret = nouveau_gpio_create(dev);
589
	if (ret)
590
		goto out_vram;
591

592
593
594
595
	ret = nouveau_gpuobj_init(dev);
	if (ret)
		goto out_gpio;

596
597
	ret = engine->instmem.init(dev);
	if (ret)
598
		goto out_gpuobj;
599

600
	ret = nouveau_mem_vram_init(dev);
601
	if (ret)
602
		goto out_instmem;
603

604
605
606
607
	ret = nouveau_mem_gart_init(dev);
	if (ret)
		goto out_ttmvram;

608
	if (!dev_priv->noaccel) {
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
		switch (dev_priv->card_type) {
		case NV_04:
			nv04_fifo_create(dev);
			break;
		case NV_10:
		case NV_20:
		case NV_30:
			if (dev_priv->chipset < 0x17)
				nv10_fifo_create(dev);
			else
				nv17_fifo_create(dev);
			break;
		case NV_40:
			nv40_fifo_create(dev);
			break;
		case NV_50:
			if (dev_priv->chipset == 0x50)
				nv50_fifo_create(dev);
			else
				nv84_fifo_create(dev);
			break;
		case NV_C0:
		case NV_D0:
			nvc0_fifo_create(dev);
			break;
		case NV_E0:
			nve0_fifo_create(dev);
			break;
		default:
			break;
		}

641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
		switch (dev_priv->card_type) {
		case NV_04:
			nv04_fence_create(dev);
			break;
		case NV_10:
		case NV_20:
		case NV_30:
		case NV_40:
		case NV_50:
			if (dev_priv->chipset < 0x84)
				nv10_fence_create(dev);
			else
				nv84_fence_create(dev);
			break;
		case NV_C0:
		case NV_D0:
		case NV_E0:
			nvc0_fence_create(dev);
			break;
		default:
			break;
		}

664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
		switch (dev_priv->card_type) {
		case NV_04:
		case NV_10:
		case NV_20:
		case NV_30:
		case NV_40:
			nv04_software_create(dev);
			break;
		case NV_50:
			nv50_software_create(dev);
			break;
		case NV_C0:
		case NV_D0:
		case NV_E0:
			nvc0_software_create(dev);
			break;
		default:
			break;
		}

684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
		switch (dev_priv->card_type) {
		case NV_04:
			nv04_graph_create(dev);
			break;
		case NV_10:
			nv10_graph_create(dev);
			break;
		case NV_20:
		case NV_30:
			nv20_graph_create(dev);
			break;
		case NV_40:
			nv40_graph_create(dev);
			break;
		case NV_50:
			nv50_graph_create(dev);
			break;
		case NV_C0:
702
		case NV_D0:
703
704
			nvc0_graph_create(dev);
			break;
705
706
707
		case NV_E0:
			nve0_graph_create(dev);
			break;
708
709
710
		default:
			break;
		}
711

712
		switch (dev_priv->chipset) {
713
714
715
716
717
718
719
		case 0x84:
		case 0x86:
		case 0x92:
		case 0x94:
		case 0x96:
		case 0xa0:
			nv84_crypt_create(dev);
720
			break;
721
722
723
724
725
		case 0x98:
		case 0xaa:
		case 0xac:
			nv98_crypt_create(dev);
			break;
726
727
		}

728
729
730
731
732
733
734
735
736
737
738
		switch (dev_priv->card_type) {
		case NV_50:
			switch (dev_priv->chipset) {
			case 0xa3:
			case 0xa5:
			case 0xa8:
				nva3_copy_create(dev);
				break;
			}
			break;
		case NV_C0:
739
740
			if (!(nv_rd32(dev, 0x022500) & 0x00000200))
				nvc0_copy_create(dev, 1);
741
		case NV_D0:
742
743
			if (!(nv_rd32(dev, 0x022500) & 0x00000100))
				nvc0_copy_create(dev, 0);
744
745
746
747
748
			break;
		default:
			break;
		}

749
750
751
752
753
754
755
756
757
758
759
760
761
		if (dev_priv->chipset >= 0xa3 || dev_priv->chipset == 0x98) {
			nv84_bsp_create(dev);
			nv84_vp_create(dev);
			nv98_ppp_create(dev);
		} else
		if (dev_priv->chipset >= 0x84) {
			nv50_mpeg_create(dev);
			nv84_bsp_create(dev);
			nv84_vp_create(dev);
		} else
		if (dev_priv->chipset >= 0x50) {
			nv50_mpeg_create(dev);
		} else
762
763
764
		if (dev_priv->card_type == NV_40 ||
		    dev_priv->chipset == 0x31 ||
		    dev_priv->chipset == 0x34 ||
765
		    dev_priv->chipset == 0x36) {
766
			nv31_mpeg_create(dev);
767
		}
768

769
770
771
772
773
774
775
		for (e = 0; e < NVOBJ_ENGINE_NR; e++) {
			if (dev_priv->eng[e]) {
				ret = dev_priv->eng[e]->init(dev, e);
				if (ret)
					goto out_engine;
			}
		}
776
	}
777

778
779
	ret = nouveau_irq_init(dev);
	if (ret)
780
		goto out_engine;
781

782
	ret = nouveau_display_create(dev);
783
	if (ret)
784
		goto out_irq;
785

786
	nouveau_backlight_init(dev);
787
	nouveau_pm_init(dev);
788

789
	if (dev_priv->eng[NVOBJ_ENGINE_GR]) {
790
		ret = nouveau_card_channel_init(dev);
791
		if (ret)
792
			goto out_pm;
793
794
795
	}

	if (dev->mode_config.num_crtc) {
796
		ret = nouveau_display_init(dev);
797
798
799
800
		if (ret)
			goto out_chan;

		nouveau_fbcon_init(dev);
801
802
803
	}

	return 0;
804

805
out_chan:
806
	nouveau_card_channel_fini(dev);
807
808
out_pm:
	nouveau_pm_fini(dev);
809
	nouveau_backlight_exit(dev);
810
	nouveau_display_destroy(dev);
811
out_irq:
Ben Skeggs's avatar
Ben Skeggs committed
812
	nouveau_irq_fini(dev);
813
out_engine:
814
	if (!dev_priv->noaccel) {
815
		for (e = e - 1; e >= 0; e--) {
816
817
			if (!dev_priv->eng[e])
				continue;
818
			dev_priv->eng[e]->fini(dev, e, false);
819
			dev_priv->eng[e]->destroy(dev,e );
820
821
		}
	}
822
	nouveau_mem_gart_fini(dev);
823
824
out_ttmvram:
	nouveau_mem_vram_fini(dev);
825
826
out_instmem:
	engine->instmem.takedown(dev);
827
828
out_gpuobj:
	nouveau_gpuobj_takedown(dev);
829
830
out_gpio:
	nouveau_gpio_destroy(dev);
831
out_vram:
832
	engine->vram.takedown(dev);
833
834
835
836
837
838
out_fb:
	engine->fb.takedown(dev);
out_timer:
	engine->timer.takedown(dev);
out_mc:
	engine->mc.takedown(dev);
839
840
out_bios:
	nouveau_bios_takedown(dev);
841
842
out_display_early:
	engine->display.late_takedown(dev);
843
out:
844
	vga_switcheroo_unregister_client(dev->pdev);
845
846
	vga_client_register(dev->pdev, NULL, NULL, NULL);
	return ret;
847
848
849
850
851
852
}

static void nouveau_card_takedown(struct drm_device *dev)
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	struct nouveau_engine *engine = &dev_priv->engine;
853
	int e;
854

855
856
	if (dev->mode_config.num_crtc) {
		nouveau_fbcon_fini(dev);
857
		nouveau_display_fini(dev);
858
	}
859

860
	nouveau_card_channel_fini(dev);
861
	nouveau_pm_fini(dev);
862
	nouveau_backlight_exit(dev);
863
	nouveau_display_destroy(dev);
864

865
	if (!dev_priv->noaccel) {
866
867
		for (e = NVOBJ_ENGINE_NR - 1; e >= 0; e--) {
			if (dev_priv->eng[e]) {
868
				dev_priv->eng[e]->fini(dev, e, false);
869
870
871
				dev_priv->eng[e]->destroy(dev,e );
			}
		}
872
	}
873

874
875
876
877
878
	if (dev_priv->vga_ram) {
		nouveau_bo_unpin(dev_priv->vga_ram);
		nouveau_bo_ref(NULL, &dev_priv->vga_ram);
	}

879
880
881
882
	mutex_lock(&dev->struct_mutex);
	ttm_bo_clean_mm(&dev_priv->ttm.bdev, TTM_PL_VRAM);
	ttm_bo_clean_mm(&dev_priv->ttm.bdev, TTM_PL_TT);
	mutex_unlock(&dev->struct_mutex);
883
	nouveau_mem_gart_fini(dev);
884
	nouveau_mem_vram_fini(dev);
885

886
	engine->instmem.takedown(dev);
887
	nouveau_gpuobj_takedown(dev);
888

889
890
891
892
893
894
	nouveau_gpio_destroy(dev);
	engine->vram.takedown(dev);
	engine->fb.takedown(dev);
	engine->timer.takedown(dev);
	engine->mc.takedown(dev);

895
	nouveau_bios_takedown(dev);
896
897
898
	engine->display.late_takedown(dev);

	nouveau_irq_fini(dev);
899

900
	vga_switcheroo_unregister_client(dev->pdev);
901
	vga_client_register(dev->pdev, NULL, NULL, NULL);
902
903
}

904
905
906
int
nouveau_open(struct drm_device *dev, struct drm_file *file_priv)
{
907
	struct drm_nouveau_private *dev_priv = dev->dev_private;
908
	struct nouveau_fpriv *fpriv;
909
	int ret;
910
911
912
913
914
915

	fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL);
	if (unlikely(!fpriv))
		return -ENOMEM;

	spin_lock_init(&fpriv->lock);
916
917
	INIT_LIST_HEAD(&fpriv->channels);

918
919
920
921
922
923
924
925
926
	if (dev_priv->card_type == NV_50) {
		ret = nouveau_vm_new(dev, 0, (1ULL << 40), 0x0020000000ULL,
				     &fpriv->vm);
		if (ret) {
			kfree(fpriv);
			return ret;
		}
	} else
	if (dev_priv->card_type >= NV_C0) {
927
928
929
930
931
932
		ret = nouveau_vm_new(dev, 0, (1ULL << 40), 0x0008000000ULL,
				     &fpriv->vm);
		if (ret) {
			kfree(fpriv);
			return ret;
		}
933
	}
934

935
936
937
938
	file_priv->driver_priv = fpriv;
	return 0;
}

939
940
941
942
943
944
945
/* here a client dies, release the stuff that was allocated for its
 * file_priv */
void nouveau_preclose(struct drm_device *dev, struct drm_file *file_priv)
{
	nouveau_channel_cleanup(dev, file_priv);
}

946
947
948
949
void
nouveau_postclose(struct drm_device *dev, struct drm_file *file_priv)
{
	struct nouveau_fpriv *fpriv = nouveau_fpriv(file_priv);
950
	nouveau_vm_ref(NULL, &fpriv->vm, NULL);
951
952
953
	kfree(fpriv);
}

954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
/* first module load, setup the mmio/fb mapping */
/* KMS: we need mmio at load time, not when the first drm client opens. */
int nouveau_firstopen(struct drm_device *dev)
{
	return 0;
}

/* if we have an OF card, copy vbios to RAMIN */
static void nouveau_OF_copy_vbios_to_ramin(struct drm_device *dev)
{
#if defined(__powerpc__)
	int size, i;
	const uint32_t *bios;
	struct device_node *dn = pci_device_to_OF_node(dev->pdev);
	if (!dn) {
		NV_INFO(dev, "Unable to get the OF node\n");
		return;
	}

	bios = of_get_property(dn, "NVDA,BMP", &size);
	if (bios) {
		for (i = 0; i < size; i += 4)
			nv_wi32(dev, i, bios[i/4]);
		NV_INFO(dev, "OF bios successfully copied (%d bytes)\n", size);
	} else {
		NV_INFO(dev, "Unable to get the OF bios\n");
	}
#endif
}

984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
static struct apertures_struct *nouveau_get_apertures(struct drm_device *dev)
{
	struct pci_dev *pdev = dev->pdev;
	struct apertures_struct *aper = alloc_apertures(3);
	if (!aper)
		return NULL;

	aper->ranges[0].base = pci_resource_start(pdev, 1);
	aper->ranges[0].size = pci_resource_len(pdev, 1);
	aper->count = 1;

	if (pci_resource_len(pdev, 2)) {
		aper->ranges[aper->count].base = pci_resource_start(pdev, 2);
		aper->ranges[aper->count].size = pci_resource_len(pdev, 2);
		aper->count++;
	}

	if (pci_resource_len(pdev, 3)) {
		aper->ranges[aper->count].base = pci_resource_start(pdev, 3);
		aper->ranges[aper->count].size = pci_resource_len(pdev, 3);
		aper->count++;
	}

	return aper;
}

static int nouveau_remove_conflicting_drivers(struct drm_device *dev)
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;
1013
	bool primary = false;
1014
1015
1016
1017
	dev_priv->apertures = nouveau_get_apertures(dev);
	if (!dev_priv->apertures)
		return -ENOMEM;

1018
1019
1020
#ifdef CONFIG_X86
	primary = dev->pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
#endif
1021

1022
	remove_conflicting_framebuffers(dev_priv->apertures, "nouveaufb", primary);
1023
1024
1025
	return 0;
}

1026
1027
1028
int nouveau_load(struct drm_device *dev, unsigned long flags)
{
	struct drm_nouveau_private *dev_priv;
1029
	unsigned long long offset, length;
1030
	uint32_t reg0 = ~0, strap;
1031
	int ret;
1032
1033

	dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
1034
1035
1036
1037
	if (!dev_priv) {
		ret = -ENOMEM;
		goto err_out;
	}
1038
1039
1040
	dev->dev_private = dev_priv;
	dev_priv->dev = dev;

1041
1042
	pci_set_master(dev->pdev);

1043
1044
1045
1046
1047
	dev_priv->flags = flags & NOUVEAU_FLAGS;

	NV_DEBUG(dev, "vendor: 0x%X device: 0x%X class: 0x%X\n",
		 dev->pci_vendor, dev->pci_device, dev->pdev->class);

1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
	/* first up, map the start of mmio and determine the chipset */
	dev_priv->mmio = ioremap(pci_resource_start(dev->pdev, 0), PAGE_SIZE);
	if (dev_priv->mmio) {
#ifdef __BIG_ENDIAN
		/* put the card into big-endian mode if it's not */
		if (nv_rd32(dev, NV03_PMC_BOOT_1) != 0x01000001)
			nv_wr32(dev, NV03_PMC_BOOT_1, 0x01000001);
		DRM_MEMORYBARRIER();
#endif

		/* determine chipset and derive architecture from it */
		reg0 = nv_rd32(dev, NV03_PMC_BOOT_0);
		if ((reg0 & 0x0f000000) > 0) {
			dev_priv->chipset = (reg0 & 0xff00000) >> 20;
			switch (dev_priv->chipset & 0xf0) {
			case 0x10:
			case 0x20:
			case 0x30:
				dev_priv->card_type = dev_priv->chipset & 0xf0;
				break;
			case 0x40:
			case 0x60:
				dev_priv->card_type = NV_40;
				break;
			case 0x50:
			case 0x80:
			case 0x90:
			case 0xa0:
				dev_priv->card_type = NV_50;
				break;
			case 0xc0:
				dev_priv->card_type = NV_C0;
				break;
			case 0xd0:
				dev_priv->card_type = NV_D0;
				break;
1084
1085
1086
			case 0xe0:
				dev_priv->card_type = NV_E0;
				break;
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
			default:
				break;
			}
		} else
		if ((reg0 & 0xff00fff0) == 0x20004000) {
			if (reg0 & 0x00f00000)
				dev_priv->chipset = 0x05;
			else
				dev_priv->chipset = 0x04;
			dev_priv->card_type = NV_04;
		}

		iounmap(dev_priv->mmio);
	}

	if (!dev_priv->card_type) {
		NV_ERROR(dev, "unsupported chipset 0x%08x\n", reg0);
		ret = -EINVAL;
		goto err_priv;
	}

1108
	NV_INFO(dev, "Detected an NV%02x generation card (0x%08x)\n",
1109
		     dev_priv->card_type, reg0);
1110

1111
1112
1113
1114
1115
1116
1117
	/* map the mmio regs, limiting the amount to preserve vmap space */
	offset = pci_resource_start(dev->pdev, 0);
	length = pci_resource_len(dev->pdev, 0);
	if (dev_priv->card_type < NV_E0)
		length = min(length, (unsigned long long)0x00800000);

	dev_priv->mmio = ioremap(offset, length);
1118
1119
1120
	if (!dev_priv->mmio) {
		NV_ERROR(dev, "Unable to initialize the mmio mapping. "
			 "Please report your setup to " DRIVER_EMAIL "\n");
1121
		ret = -EINVAL;
1122
		goto err_priv;
1123
	}
1124
	NV_DEBUG(dev, "regs mapped ok at 0x%llx\n", offset);
1125

1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
	/* determine frequency of timing crystal */
	strap = nv_rd32(dev, 0x101000);
	if ( dev_priv->chipset < 0x17 ||
	    (dev_priv->chipset >= 0x20 && dev_priv->chipset <= 0x25))
		strap &= 0x00000040;
	else
		strap &= 0x00400040;

	switch (strap) {
	case 0x00000000: dev_priv->crystal = 13500; break;
	case 0x00000040: dev_priv->crystal = 14318; break;
	case 0x00400000: dev_priv->crystal = 27000; break;
	case 0x00400040: dev_priv->crystal = 25000; break;
	}

	NV_DEBUG(dev, "crystal freq: %dKHz\n", dev_priv->crystal);

1143
1144
1145
1146
1147
1148
1149
	/* Determine whether we'll attempt acceleration or not, some
	 * cards are disabled by default here due to them being known
	 * non-functional, or never been tested due to lack of hw.
	 */
	dev_priv->noaccel = !!nouveau_noaccel;
	if (nouveau_noaccel == -1) {
		switch (dev_priv->chipset) {
1150
		case 0xd9: /* known broken */
1151
1152
		case 0xe4: /* needs binary driver firmware */
		case 0xe7: /* needs binary driver firmware */
1153
1154
			NV_INFO(dev, "acceleration disabled by default, pass "
				     "noaccel=0 to force enable\n");
1155
1156
1157
1158
1159
1160
1161
1162
			dev_priv->noaccel = true;
			break;
		default:
			dev_priv->noaccel = false;
			break;
		}
	}

1163
1164
	ret = nouveau_remove_conflicting_drivers(dev);
	if (ret)
1165
		goto err_mmio;
1166

Lucas De Marchi's avatar
Lucas De Marchi committed
1167
	/* Map PRAMIN BAR, or on older cards, the aperture within BAR0 */
1168
1169
1170
1171
1172
1173
	if (dev_priv->card_type >= NV_40) {
		int ramin_bar = 2;
		if (pci_resource_len(dev->pdev, ramin_bar) == 0)
			ramin_bar = 3;

		dev_priv->ramin_size = pci_resource_len(dev->pdev, ramin_bar);
1174
1175
		dev_priv->ramin =
			ioremap(pci_resource_start(dev->pdev, ramin_bar),
1176
1177
				dev_priv->ramin_size);
		if (!dev_priv->ramin) {
1178
			NV_ERROR(dev, "Failed to map PRAMIN BAR\n");
1179
1180
			ret = -ENOMEM;
			goto err_mmio;
1181
		}
1182
	} else {
1183
		dev_priv->ramin_size = 1 * 1024 * 1024;
1184
		dev_priv->ramin = ioremap(offset + NV_RAMIN,
1185
					  dev_priv->ramin_size);
Ben Skeggs's avatar