nouveau_drv.h 16.9 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 27 28
/*
 * Copyright 2005 Stephane Marchesin.
 * 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
 * VA LINUX SYSTEMS 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.
 */

#ifndef __NOUVEAU_DRV_H__
#define __NOUVEAU_DRV_H__

#define DRIVER_AUTHOR		"Stephane Marchesin"
B
Ben Skeggs 已提交
29
#define DRIVER_EMAIL		"nouveau@lists.freedesktop.org"
30 31 32

#define DRIVER_NAME		"nouveau"
#define DRIVER_DESC		"nVidia Riva/TNT/GeForce"
B
Ben Skeggs 已提交
33
#define DRIVER_DATE		"20120316"
34

B
Ben Skeggs 已提交
35
#define DRIVER_MAJOR		1
36
#define DRIVER_MINOR		0
B
Ben Skeggs 已提交
37
#define DRIVER_PATCHLEVEL	0
38 39 40 41 42 43 44 45 46 47

#define NOUVEAU_FAMILY   0x0000FFFF
#define NOUVEAU_FLAGS    0xFFFF0000

#include "ttm/ttm_bo_api.h"
#include "ttm/ttm_bo_driver.h"
#include "ttm/ttm_placement.h"
#include "ttm/ttm_memory.h"
#include "ttm/ttm_module.h"

48
#define XXX_THIS_IS_A_HACK
49
#include <subdev/vm.h>
50
#include <subdev/fb.h>
51
#include <core/gpuobj.h>
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

enum blah {
	NV_MEM_TYPE_UNKNOWN = 0,
	NV_MEM_TYPE_STOLEN,
	NV_MEM_TYPE_SGRAM,
	NV_MEM_TYPE_SDRAM,
	NV_MEM_TYPE_DDR1,
	NV_MEM_TYPE_DDR2,
	NV_MEM_TYPE_DDR3,
	NV_MEM_TYPE_GDDR2,
	NV_MEM_TYPE_GDDR3,
	NV_MEM_TYPE_GDDR4,
	NV_MEM_TYPE_GDDR5
};

67
#include <nouveau_drm.h>
68
#include "nouveau_reg.h"
69
#include <nouveau_bios.h>
70

71 72 73
#include <subdev/bios/pll.h>
#include "nouveau_compat.h"

74
#define nouveau_gpuobj_new(d,c,s,a,f,o) \
75
	_nouveau_gpuobj_new((d), NULL, (s), (a), (f), (o))
76 77 78 79 80 81 82

#define nouveau_vm_new(d,o,l,m,v) \
	_nouveau_vm_new((d), (o), (l), (m), (v))

#define nv50_vm_flush_engine(d,e) \
	_nv50_vm_flush_engine((d), (e))

83
#include "nouveau_bo.h"
84
#include "nouveau_gem.h"
85

86 87 88 89 90 91 92
struct nouveau_page_flip_state {
	struct list_head head;
	struct drm_pending_vblank_event *event;
	int crtc, bpp, pitch, x, y;
	uint64_t offset;
};

93
struct nouveau_display_engine {
94
	void *priv;
95 96 97 98
	int (*early_init)(struct drm_device *);
	void (*late_takedown)(struct drm_device *);
	int (*create)(struct drm_device *);
	void (*destroy)(struct drm_device *);
99 100
	int (*init)(struct drm_device *);
	void (*fini)(struct drm_device *);
101

102 103
	struct drm_property *dithering_mode;
	struct drm_property *dithering_depth;
104 105 106
	struct drm_property *underscan_property;
	struct drm_property *underscan_hborder_property;
	struct drm_property *underscan_vborder_property;
107 108 109
	/* not really hue and saturation: */
	struct drm_property *vibrant_hue_property;
	struct drm_property *color_vibrance_property;
110 111
};

112
struct nouveau_pm_voltage_level {
113 114
	u32 voltage; /* microvolts */
	u8  vid;
115 116 117 118
};

struct nouveau_pm_voltage {
	bool supported;
119
	u8 version;
120 121 122 123 124 125
	u8 vid_mask;

	struct nouveau_pm_voltage_level *level;
	int nr_level;
};

126 127 128 129 130 131 132 133 134 135
/* Exclusive upper limits */
#define NV_MEM_CL_DDR2_MAX 8
#define NV_MEM_WR_DDR2_MAX 9
#define NV_MEM_CL_DDR3_MAX 17
#define NV_MEM_WR_DDR3_MAX 17
#define NV_MEM_CL_GDDR3_MAX 16
#define NV_MEM_WR_GDDR3_MAX 18
#define NV_MEM_CL_GDDR5_MAX 21
#define NV_MEM_WR_GDDR5_MAX 20

136 137
struct nouveau_pm_memtiming {
	int id;
138 139 140 141

	u32 reg[9];
	u32 mr[4];

142 143
	u8 tCWL;

144 145
	u8 odt;
	u8 drive_strength;
146 147
};

M
Martin Peres 已提交
148
struct nouveau_pm_tbl_header {
149 150 151 152 153 154
	u8 version;
	u8 header_len;
	u8 entry_cnt;
	u8 entry_len;
};

M
Martin Peres 已提交
155
struct nouveau_pm_tbl_entry {
156
	u8 tWR;
157
	u8 tWTR;
158
	u8 tCL;
159
	u8 tRC;
160
	u8 empty_4;
161
	u8 tRFC;	/* Byte 5 */
162
	u8 empty_6;
163
	u8 tRAS;	/* Byte 7 */
164
	u8 empty_8;
165 166 167 168 169 170 171 172 173 174 175 176
	u8 tRP;		/* Byte 9 */
	u8 tRCDRD;
	u8 tRCDWR;
	u8 tRRD;
	u8 tUNK_13;
	u8 RAM_FT1;		/* 14, a bitmask of random RAM features */
	u8 empty_15;
	u8 tUNK_16;
	u8 empty_17;
	u8 tUNK_18;
	u8 tCWL;
	u8 tUNK_20, tUNK_21;
177 178
};

179 180
struct nouveau_pm_profile;
struct nouveau_pm_profile_func {
181 182 183
	void (*destroy)(struct nouveau_pm_profile *);
	void (*init)(struct nouveau_pm_profile *);
	void (*fini)(struct nouveau_pm_profile *);
184 185 186 187 188 189 190 191 192
	struct nouveau_pm_level *(*select)(struct nouveau_pm_profile *);
};

struct nouveau_pm_profile {
	const struct nouveau_pm_profile_func *func;
	struct list_head head;
	char name[8];
};

193 194
#define NOUVEAU_PM_MAX_LEVEL 8
struct nouveau_pm_level {
195
	struct nouveau_pm_profile profile;
196 197 198 199
	struct device_attribute dev_attr;
	char name[32];
	int id;

200
	struct nouveau_pm_memtiming timing;
201
	u32 memory;
202 203 204
	u16 memscript;

	u32 core;
205
	u32 shader;
206 207 208
	u32 rop;
	u32 copy;
	u32 daemon;
209
	u32 vdec;
210
	u32 dom6;
211 212 213 214
	u32 unka0;	/* nva3:nvc0 */
	u32 hub01;	/* nvc0- */
	u32 hub06;	/* nvc0- */
	u32 hub07;	/* nvc0- */
215

216 217
	u32 volt_min; /* microvolts */
	u32 volt_max;
218
	u8  fanspeed;
219 220
};

221 222 223
struct nouveau_pm_temp_sensor_constants {
	u16 offset_constant;
	s16 offset_mult;
224 225 226
	s16 offset_div;
	s16 slope_mult;
	s16 slope_div;
227 228 229 230 231 232 233 234
};

struct nouveau_pm_threshold_temp {
	s16 critical;
	s16 down_clock;
	s16 fan_boost;
};

235
struct nouveau_pm_fan {
236
	u32 percent;
237 238
	u32 min_duty;
	u32 max_duty;
239
	u32 pwm_freq;
240
	u32 pwm_divisor;
241 242
};

243 244 245 246
struct nouveau_pm_engine {
	struct nouveau_pm_voltage voltage;
	struct nouveau_pm_level perflvl[NOUVEAU_PM_MAX_LEVEL];
	int nr_perflvl;
247 248
	struct nouveau_pm_temp_sensor_constants sensor_constants;
	struct nouveau_pm_threshold_temp threshold_temp;
249
	struct nouveau_pm_fan fan;
250

251 252
	struct nouveau_pm_profile *profile_ac;
	struct nouveau_pm_profile *profile_dc;
253
	struct nouveau_pm_profile *profile;
254 255
	struct list_head profiles;

256 257 258
	struct nouveau_pm_level boot;
	struct nouveau_pm_level *cur;

259
	struct device *hwmon;
260
	struct notifier_block acpi_nb;
261

262 263
	int  (*clocks_get)(struct drm_device *, struct nouveau_pm_level *);
	void *(*clocks_pre)(struct drm_device *, struct nouveau_pm_level *);
264
	int (*clocks_set)(struct drm_device *, void *);
265

266 267
	int (*voltage_get)(struct drm_device *);
	int (*voltage_set)(struct drm_device *, int voltage);
268 269
	int (*pwm_get)(struct drm_device *, int line, u32*, u32*);
	int (*pwm_set)(struct drm_device *, int line, u32, u32);
270
	int (*temp_get)(struct drm_device *);
271 272
};

273
struct nouveau_engine {
274
	struct nouveau_display_engine display;
275
	struct nouveau_pm_engine      pm;
276 277 278
};

enum nouveau_card_type {
279
	NV_04      = 0x04,
280 281 282 283 284
	NV_10      = 0x10,
	NV_20      = 0x20,
	NV_30      = 0x30,
	NV_40      = 0x40,
	NV_50      = 0x50,
285
	NV_C0      = 0xc0,
286
	NV_D0      = 0xd0,
287
	NV_E0      = 0xe0,
288 289 290 291 292
};

struct drm_nouveau_private {
	struct drm_device *dev;

293 294
	void *newpriv;

295 296 297 298
	/* the card type, takes NV_* as values */
	enum nouveau_card_type card_type;
	/* exact chipset, derived from NV_PMC_BOOT_0 */
	int chipset;
299
	u32 crystal;
300

B
Ben Skeggs 已提交
301
	/* interrupt handling */
302
	void (*irq_handler[32])(struct drm_device *);
B
Ben Skeggs 已提交
303
	bool msi_enabled;
304

305 306
	struct nouveau_engine engine;

307 308 309
	/* For PFIFO and PGRAPH. */
	spinlock_t context_switch_lock;

310
	struct nvbios vbios;
311
	u8 *mxms;
312 313 314 315

	struct backlight_device *backlight;
};

316 317 318 319 320 321
static inline struct drm_nouveau_private *
nouveau_private(struct drm_device *dev)
{
	return dev->dev_private;
}

322
/* nouveau_drv.c */
323
extern int nouveau_modeset;
324 325 326 327 328
extern int nouveau_duallink;
extern int nouveau_uscript_lvds;
extern int nouveau_uscript_tmds;
extern int nouveau_vram_pushbuf;
extern int nouveau_vram_notify;
329
extern char *nouveau_vram_type;
330
extern int nouveau_fbpercrtc;
331
extern int nouveau_tv_disable;
332
extern char *nouveau_tv_norm;
333
extern int nouveau_ignorelid;
334
extern int nouveau_force_post;
335
extern int nouveau_override_conntype;
336 337
extern char *nouveau_perflvl;
extern int nouveau_perflvl_wr;
B
Ben Skeggs 已提交
338
extern int nouveau_msi;
339
extern int nouveau_ctxfw;
340
extern int nouveau_mxmdcb;
341

342 343 344
extern int nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state);
extern int nouveau_pci_resume(struct pci_dev *pdev);

345 346 347 348 349 350 351 352
/* nouveau_state.c */
extern int  nouveau_load(struct drm_device *, unsigned long flags);
extern int  nouveau_firstopen(struct drm_device *);
extern void nouveau_lastclose(struct drm_device *);
extern int  nouveau_unload(struct drm_device *);
extern int  nouveau_card_init(struct drm_device *);

/* nouveau_mem.c */
353 354
extern int  nouveau_mem_timing_calc(struct drm_device *, u32 freq,
				    struct nouveau_pm_memtiming *);
355 356
extern void nouveau_mem_timing_read(struct drm_device *,
				    struct nouveau_pm_memtiming *);
357

358
/* nouveau_irq.c */
B
Ben Skeggs 已提交
359 360
extern int         nouveau_irq_init(struct drm_device *);
extern void        nouveau_irq_fini(struct drm_device *);
361
extern irqreturn_t nouveau_irq_handler(DRM_IRQ_ARGS);
362 363 364
extern void        nouveau_irq_register(struct drm_device *, int status_bit,
					void (*)(struct drm_device *));
extern void        nouveau_irq_unregister(struct drm_device *, int status_bit);
365 366 367 368 369
extern void        nouveau_irq_preinstall(struct drm_device *);
extern int         nouveau_irq_postinstall(struct drm_device *);
extern void        nouveau_irq_uninstall(struct drm_device *);

/* nouveau_acpi.c */
370
#define ROM_BIOS_PAGE 4096
371
#if defined(CONFIG_ACPI)
372 373
void nouveau_register_dsm_handler(void);
void nouveau_unregister_dsm_handler(void);
374
void nouveau_switcheroo_optimus_dsm(void);
375 376
int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len);
bool nouveau_acpi_rom_supported(struct pci_dev *pdev);
377
int nouveau_acpi_edid(struct drm_device *, struct drm_connector *);
378 379 380
#else
static inline void nouveau_register_dsm_handler(void) {}
static inline void nouveau_unregister_dsm_handler(void) {}
381
static inline void nouveau_switcheroo_optimus_dsm(void) {}
382 383
static inline bool nouveau_acpi_rom_supported(struct pci_dev *pdev) { return false; }
static inline int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len) { return -EINVAL; }
384
static inline int nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector) { return -EINVAL; }
385
#endif
386 387 388

/* nouveau_backlight.c */
#ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT
389 390
extern int nouveau_backlight_init(struct drm_device *);
extern void nouveau_backlight_exit(struct drm_device *);
391
#else
392
static inline int nouveau_backlight_init(struct drm_device *dev)
393 394 395 396
{
	return 0;
}

397
static inline void nouveau_backlight_exit(struct drm_device *dev) { }
398 399 400 401 402 403 404 405
#endif

/* nouveau_bios.c */
extern int nouveau_bios_init(struct drm_device *);
extern void nouveau_bios_takedown(struct drm_device *dev);
extern int nouveau_run_vbios_init(struct drm_device *);
extern struct dcb_connector_table_entry *
nouveau_bios_connector_entry(struct drm_device *, int index);
406
extern int nouveau_bios_run_display_table(struct drm_device *, u16 id, int clk,
407
					  struct dcb_output *, int crtc);
408 409 410 411
extern bool nouveau_bios_fp_mode(struct drm_device *, struct drm_display_mode *);
extern uint8_t *nouveau_bios_embedded_edid(struct drm_device *);
extern int nouveau_bios_parse_lvds_table(struct drm_device *, int pxclk,
					 bool *dl, bool *if_is_24bit);
412
extern int run_tmds_table(struct drm_device *, struct dcb_output *,
413
			  int head, int pxclk);
414
extern int call_lvds_script(struct drm_device *, struct dcb_output *, int head,
415
			    enum LVDS_script, int pxclk);
416
bool bios_encoder_match(struct dcb_output *, u32 hash);
417 418 419 420 421 422

/* nouveau_ttm.c */
int nouveau_ttm_global_init(struct drm_nouveau_private *);
void nouveau_ttm_global_release(struct drm_nouveau_private *);
int nouveau_ttm_mmap(struct file *, struct vm_area_struct *);

423 424 425
/* nouveau_hdmi.c */
void nouveau_hdmi_mode_set(struct drm_encoder *, struct drm_display_mode *);

426
extern long nouveau_compat_ioctl(struct file *file, unsigned int cmd,
427
			         unsigned long arg);
428

429 430 431
/* nvd0_display.c */
extern int nvd0_display_create(struct drm_device *);
extern void nvd0_display_destroy(struct drm_device *);
432 433
extern int nvd0_display_init(struct drm_device *);
extern void nvd0_display_fini(struct drm_device *);
434 435 436 437
struct nouveau_bo *nvd0_display_crtc_sema(struct drm_device *, int crtc);
void nvd0_display_flip_stop(struct drm_crtc *);
int nvd0_display_flip_next(struct drm_crtc *, struct drm_framebuffer *,
			   struct nouveau_channel *, u32 swap_interval);
438

D
Dave Airlie 已提交
439

440
/* nouveau_display.c */
441 442
int nouveau_display_create(struct drm_device *dev);
void nouveau_display_destroy(struct drm_device *dev);
443 444
int nouveau_display_init(struct drm_device *dev);
void nouveau_display_fini(struct drm_device *dev);
445 446
int nouveau_vblank_enable(struct drm_device *dev, int crtc);
void nouveau_vblank_disable(struct drm_device *dev, int crtc);
447 448 449 450
int nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
			   struct drm_pending_vblank_event *event);
int nouveau_finish_page_flip(struct nouveau_channel *,
			     struct nouveau_page_flip_state *);
B
Ben Skeggs 已提交
451 452 453 454 455 456
int nouveau_display_dumb_create(struct drm_file *, struct drm_device *,
				struct drm_mode_create_dumb *args);
int nouveau_display_dumb_map_offset(struct drm_file *, struct drm_device *,
				    uint32_t handle, uint64_t *offset);
int nouveau_display_dumb_destroy(struct drm_file *, struct drm_device *,
				 uint32_t handle);
457

458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
#ifndef ioread32_native
#ifdef __BIG_ENDIAN
#define ioread16_native ioread16be
#define iowrite16_native iowrite16be
#define ioread32_native  ioread32be
#define iowrite32_native iowrite32be
#else /* def __BIG_ENDIAN */
#define ioread16_native ioread16
#define iowrite16_native iowrite16
#define ioread32_native  ioread32
#define iowrite32_native iowrite32
#endif /* def __BIG_ENDIAN else */
#endif /* !ioread32_native */

/* register access */
473 474 475 476 477
#define nv_rd08 _nv_rd08
#define nv_wr08 _nv_wr08
#define nv_rd32 _nv_rd32
#define nv_wr32 _nv_wr32
#define nv_mask _nv_mask
478

479
#define nv_wait(dev, reg, mask, val) \
480 481 482
	nouveau_wait_eq(dev, 2000000000ULL, (reg), (mask), (val))
#define nv_wait_ne(dev, reg, mask, val) \
	nouveau_wait_ne(dev, 2000000000ULL, (reg), (mask), (val))
483 484
#define nv_wait_cb(dev, func, data) \
	nouveau_wait_cb(dev, 2000000000ULL, (func), (data))
485 486 487 488 489 490 491 492 493 494

/*
 * Logging
 * Argument d is (struct drm_device *).
 */
#define NV_PRINTK(level, d, fmt, arg...) \
	printk(level "[" DRM_NAME "] " DRIVER_NAME " %s: " fmt, \
					pci_name(d->pdev), ##arg)
#ifndef NV_DEBUG_NOTRACE
#define NV_DEBUG(d, fmt, arg...) do {                                          \
495 496 497 498 499 500 501
	if (drm_debug & DRM_UT_DRIVER) {                                       \
		NV_PRINTK(KERN_DEBUG, d, "%s:%d - " fmt, __func__,             \
			  __LINE__, ##arg);                                    \
	}                                                                      \
} while (0)
#define NV_DEBUG_KMS(d, fmt, arg...) do {                                      \
	if (drm_debug & DRM_UT_KMS) {                                          \
502 503 504 505 506 507
		NV_PRINTK(KERN_DEBUG, d, "%s:%d - " fmt, __func__,             \
			  __LINE__, ##arg);                                    \
	}                                                                      \
} while (0)
#else
#define NV_DEBUG(d, fmt, arg...) do {                                          \
508 509 510 511 512
	if (drm_debug & DRM_UT_DRIVER)                                         \
		NV_PRINTK(KERN_DEBUG, d, fmt, ##arg);                          \
} while (0)
#define NV_DEBUG_KMS(d, fmt, arg...) do {                                      \
	if (drm_debug & DRM_UT_KMS)                                            \
513 514 515 516 517 518 519 520
		NV_PRINTK(KERN_DEBUG, d, fmt, ##arg);                          \
} while (0)
#endif
#define NV_ERROR(d, fmt, arg...) NV_PRINTK(KERN_ERR, d, fmt, ##arg)
#define NV_INFO(d, fmt, arg...) NV_PRINTK(KERN_INFO, d, fmt, ##arg)
#define NV_TRACEWARN(d, fmt, arg...) NV_PRINTK(KERN_NOTICE, d, fmt, ##arg)
#define NV_TRACE(d, fmt, arg...) NV_PRINTK(KERN_INFO, d, fmt, ##arg)
#define NV_WARN(d, fmt, arg...) NV_PRINTK(KERN_WARNING, d, fmt, ##arg)
521 522 523 524 525 526 527
#define NV_WARNONCE(d, fmt, arg...) do {                                       \
	static int _warned = 0;                                                \
	if (!_warned) {                                                        \
		NV_WARN(d, fmt, ##arg);                                        \
		_warned = 1;                                                   \
	}                                                                      \
} while(0)
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558

static inline bool
nv_two_heads(struct drm_device *dev)
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	const int impl = dev->pci_device & 0x0ff0;

	if (dev_priv->card_type >= NV_10 && impl != 0x0100 &&
	    impl != 0x0150 && impl != 0x01a0 && impl != 0x0200)
		return true;

	return false;
}

static inline bool
nv_gf4_disp_arch(struct drm_device *dev)
{
	return nv_two_heads(dev) && (dev->pci_device & 0x0ff0) != 0x0110;
}

static inline bool
nv_two_reg_pll(struct drm_device *dev)
{
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	const int impl = dev->pci_device & 0x0ff0;

	if (impl == 0x0310 || impl == 0x0340 || dev_priv->card_type >= NV_40)
		return true;
	return false;
}

559 560 561 562 563 564 565 566 567
static inline bool
nv_match_device(struct drm_device *dev, unsigned device,
		unsigned sub_vendor, unsigned sub_device)
{
	return dev->pdev->device == device &&
		dev->pdev->subsystem_vendor == sub_vendor &&
		dev->pdev->subsystem_device == sub_device;
}

568
#endif /* __NOUVEAU_DRV_H__ */