drm/nouveau: port all engines to new engine module format
[linux-block.git] / drivers / gpu / drm / nouveau / nouveau_drv.h
1 /*
2  * Copyright 2005 Stephane Marchesin.
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 #ifndef __NOUVEAU_DRV_H__
26 #define __NOUVEAU_DRV_H__
27
28 #define DRIVER_AUTHOR           "Stephane Marchesin"
29 #define DRIVER_EMAIL            "nouveau@lists.freedesktop.org"
30
31 #define DRIVER_NAME             "nouveau"
32 #define DRIVER_DESC             "nVidia Riva/TNT/GeForce"
33 #define DRIVER_DATE             "20120316"
34
35 #define DRIVER_MAJOR            1
36 #define DRIVER_MINOR            0
37 #define DRIVER_PATCHLEVEL       0
38
39 #define NOUVEAU_FAMILY   0x0000FFFF
40 #define NOUVEAU_FLAGS    0xFFFF0000
41
42 #include "ttm/ttm_bo_api.h"
43 #include "ttm/ttm_bo_driver.h"
44 #include "ttm/ttm_placement.h"
45 #include "ttm/ttm_memory.h"
46 #include "ttm/ttm_module.h"
47
48 #define XXX_THIS_IS_A_HACK
49 #include <subdev/vm.h>
50 #include <subdev/fb.h>
51 #include <core/gpuobj.h>
52
53 enum blah {
54         NV_MEM_TYPE_UNKNOWN = 0,
55         NV_MEM_TYPE_STOLEN,
56         NV_MEM_TYPE_SGRAM,
57         NV_MEM_TYPE_SDRAM,
58         NV_MEM_TYPE_DDR1,
59         NV_MEM_TYPE_DDR2,
60         NV_MEM_TYPE_DDR3,
61         NV_MEM_TYPE_GDDR2,
62         NV_MEM_TYPE_GDDR3,
63         NV_MEM_TYPE_GDDR4,
64         NV_MEM_TYPE_GDDR5
65 };
66
67 #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
68
69 #include <nouveau_drm.h>
70 #include "nouveau_reg.h"
71 #include <nouveau_bios.h>
72
73 struct nouveau_grctx;
74 struct nouveau_mem;
75
76 #include <subdev/bios/pll.h>
77 #include "nouveau_compat.h"
78
79 #define nouveau_gpuobj_new(d,c,s,a,f,o) \
80         _nouveau_gpuobj_new((d), NULL, (s), (a), (f), (o))
81
82 #define nouveau_vm_new(d,o,l,m,v) \
83         _nouveau_vm_new((d), (o), (l), (m), (v))
84
85 #define nv50_vm_flush_engine(d,e) \
86         _nv50_vm_flush_engine((d), (e))
87
88 #define MAX_NUM_DCB_ENTRIES 16
89
90 #define NOUVEAU_MAX_CHANNEL_NR 4096
91
92 #include "nouveau_bo.h"
93 #include "nouveau_gem.h"
94
95 enum nouveau_flags {
96         NV_NFORCE   = 0x10000000,
97         NV_NFORCE2  = 0x20000000
98 };
99
100 struct nouveau_page_flip_state {
101         struct list_head head;
102         struct drm_pending_vblank_event *event;
103         int crtc, bpp, pitch, x, y;
104         uint64_t offset;
105 };
106
107 enum nouveau_channel_mutex_class {
108         NOUVEAU_UCHANNEL_MUTEX,
109         NOUVEAU_KCHANNEL_MUTEX
110 };
111
112 struct nouveau_display_engine {
113         void *priv;
114         int (*early_init)(struct drm_device *);
115         void (*late_takedown)(struct drm_device *);
116         int (*create)(struct drm_device *);
117         void (*destroy)(struct drm_device *);
118         int (*init)(struct drm_device *);
119         void (*fini)(struct drm_device *);
120
121         struct drm_property *dithering_mode;
122         struct drm_property *dithering_depth;
123         struct drm_property *underscan_property;
124         struct drm_property *underscan_hborder_property;
125         struct drm_property *underscan_vborder_property;
126         /* not really hue and saturation: */
127         struct drm_property *vibrant_hue_property;
128         struct drm_property *color_vibrance_property;
129 };
130
131 struct nouveau_pm_voltage_level {
132         u32 voltage; /* microvolts */
133         u8  vid;
134 };
135
136 struct nouveau_pm_voltage {
137         bool supported;
138         u8 version;
139         u8 vid_mask;
140
141         struct nouveau_pm_voltage_level *level;
142         int nr_level;
143 };
144
145 /* Exclusive upper limits */
146 #define NV_MEM_CL_DDR2_MAX 8
147 #define NV_MEM_WR_DDR2_MAX 9
148 #define NV_MEM_CL_DDR3_MAX 17
149 #define NV_MEM_WR_DDR3_MAX 17
150 #define NV_MEM_CL_GDDR3_MAX 16
151 #define NV_MEM_WR_GDDR3_MAX 18
152 #define NV_MEM_CL_GDDR5_MAX 21
153 #define NV_MEM_WR_GDDR5_MAX 20
154
155 struct nouveau_pm_memtiming {
156         int id;
157
158         u32 reg[9];
159         u32 mr[4];
160
161         u8 tCWL;
162
163         u8 odt;
164         u8 drive_strength;
165 };
166
167 struct nouveau_pm_tbl_header {
168         u8 version;
169         u8 header_len;
170         u8 entry_cnt;
171         u8 entry_len;
172 };
173
174 struct nouveau_pm_tbl_entry {
175         u8 tWR;
176         u8 tWTR;
177         u8 tCL;
178         u8 tRC;
179         u8 empty_4;
180         u8 tRFC;        /* Byte 5 */
181         u8 empty_6;
182         u8 tRAS;        /* Byte 7 */
183         u8 empty_8;
184         u8 tRP;         /* Byte 9 */
185         u8 tRCDRD;
186         u8 tRCDWR;
187         u8 tRRD;
188         u8 tUNK_13;
189         u8 RAM_FT1;             /* 14, a bitmask of random RAM features */
190         u8 empty_15;
191         u8 tUNK_16;
192         u8 empty_17;
193         u8 tUNK_18;
194         u8 tCWL;
195         u8 tUNK_20, tUNK_21;
196 };
197
198 struct nouveau_pm_profile;
199 struct nouveau_pm_profile_func {
200         void (*destroy)(struct nouveau_pm_profile *);
201         void (*init)(struct nouveau_pm_profile *);
202         void (*fini)(struct nouveau_pm_profile *);
203         struct nouveau_pm_level *(*select)(struct nouveau_pm_profile *);
204 };
205
206 struct nouveau_pm_profile {
207         const struct nouveau_pm_profile_func *func;
208         struct list_head head;
209         char name[8];
210 };
211
212 #define NOUVEAU_PM_MAX_LEVEL 8
213 struct nouveau_pm_level {
214         struct nouveau_pm_profile profile;
215         struct device_attribute dev_attr;
216         char name[32];
217         int id;
218
219         struct nouveau_pm_memtiming timing;
220         u32 memory;
221         u16 memscript;
222
223         u32 core;
224         u32 shader;
225         u32 rop;
226         u32 copy;
227         u32 daemon;
228         u32 vdec;
229         u32 dom6;
230         u32 unka0;      /* nva3:nvc0 */
231         u32 hub01;      /* nvc0- */
232         u32 hub06;      /* nvc0- */
233         u32 hub07;      /* nvc0- */
234
235         u32 volt_min; /* microvolts */
236         u32 volt_max;
237         u8  fanspeed;
238 };
239
240 struct nouveau_pm_temp_sensor_constants {
241         u16 offset_constant;
242         s16 offset_mult;
243         s16 offset_div;
244         s16 slope_mult;
245         s16 slope_div;
246 };
247
248 struct nouveau_pm_threshold_temp {
249         s16 critical;
250         s16 down_clock;
251         s16 fan_boost;
252 };
253
254 struct nouveau_pm_fan {
255         u32 percent;
256         u32 min_duty;
257         u32 max_duty;
258         u32 pwm_freq;
259         u32 pwm_divisor;
260 };
261
262 struct nouveau_pm_engine {
263         struct nouveau_pm_voltage voltage;
264         struct nouveau_pm_level perflvl[NOUVEAU_PM_MAX_LEVEL];
265         int nr_perflvl;
266         struct nouveau_pm_temp_sensor_constants sensor_constants;
267         struct nouveau_pm_threshold_temp threshold_temp;
268         struct nouveau_pm_fan fan;
269
270         struct nouveau_pm_profile *profile_ac;
271         struct nouveau_pm_profile *profile_dc;
272         struct nouveau_pm_profile *profile;
273         struct list_head profiles;
274
275         struct nouveau_pm_level boot;
276         struct nouveau_pm_level *cur;
277
278         struct device *hwmon;
279         struct notifier_block acpi_nb;
280
281         int  (*clocks_get)(struct drm_device *, struct nouveau_pm_level *);
282         void *(*clocks_pre)(struct drm_device *, struct nouveau_pm_level *);
283         int (*clocks_set)(struct drm_device *, void *);
284
285         int (*voltage_get)(struct drm_device *);
286         int (*voltage_set)(struct drm_device *, int voltage);
287         int (*pwm_get)(struct drm_device *, int line, u32*, u32*);
288         int (*pwm_set)(struct drm_device *, int line, u32, u32);
289         int (*temp_get)(struct drm_device *);
290 };
291
292 struct nouveau_engine {
293         struct nouveau_display_engine display;
294         struct nouveau_pm_engine      pm;
295 };
296
297 enum nouveau_card_type {
298         NV_04      = 0x04,
299         NV_10      = 0x10,
300         NV_20      = 0x20,
301         NV_30      = 0x30,
302         NV_40      = 0x40,
303         NV_50      = 0x50,
304         NV_C0      = 0xc0,
305         NV_D0      = 0xd0,
306         NV_E0      = 0xe0,
307 };
308
309 struct nouveau_channel;
310
311 struct drm_nouveau_private {
312         struct drm_device *dev;
313         bool noaccel;
314
315         void *newpriv;
316
317         /* the card type, takes NV_* as values */
318         enum nouveau_card_type card_type;
319         /* exact chipset, derived from NV_PMC_BOOT_0 */
320         int chipset;
321         int flags;
322         u32 crystal;
323
324         struct nouveau_bo *vga_ram;
325
326         /* interrupt handling */
327         void (*irq_handler[32])(struct drm_device *);
328         bool msi_enabled;
329
330         struct nouveau_engine engine;
331
332         /* For PFIFO and PGRAPH. */
333         spinlock_t context_switch_lock;
334
335         /* RAMIN configuration, RAMFC, RAMHT and RAMRO offsets */
336         struct nouveau_ramht  *ramht;
337
338         uint64_t fb_available_size;
339         uint64_t fb_mappable_pages;
340         int fb_mtrr;
341
342         struct nvbios vbios;
343         u8 *mxms;
344         struct list_head i2c_ports;
345
346         struct backlight_device *backlight;
347 };
348
349 static inline struct drm_nouveau_private *
350 nouveau_private(struct drm_device *dev)
351 {
352         return dev->dev_private;
353 }
354
355 /* nouveau_drv.c */
356 extern int nouveau_modeset;
357 extern int nouveau_duallink;
358 extern int nouveau_uscript_lvds;
359 extern int nouveau_uscript_tmds;
360 extern int nouveau_vram_pushbuf;
361 extern int nouveau_vram_notify;
362 extern char *nouveau_vram_type;
363 extern int nouveau_fbpercrtc;
364 extern int nouveau_tv_disable;
365 extern char *nouveau_tv_norm;
366 extern int nouveau_reg_debug;
367 extern int nouveau_ignorelid;
368 extern int nouveau_noaccel;
369 extern int nouveau_force_post;
370 extern int nouveau_override_conntype;
371 extern char *nouveau_perflvl;
372 extern int nouveau_perflvl_wr;
373 extern int nouveau_msi;
374 extern int nouveau_ctxfw;
375 extern int nouveau_mxmdcb;
376
377 extern int nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state);
378 extern int nouveau_pci_resume(struct pci_dev *pdev);
379
380 /* nouveau_state.c */
381 extern int  nouveau_load(struct drm_device *, unsigned long flags);
382 extern int  nouveau_firstopen(struct drm_device *);
383 extern void nouveau_lastclose(struct drm_device *);
384 extern int  nouveau_unload(struct drm_device *);
385 extern bool nouveau_wait_for_idle(struct drm_device *);
386 extern int  nouveau_card_init(struct drm_device *);
387
388 /* nouveau_mem.c */
389 extern int  nouveau_mem_vram_init(struct drm_device *);
390 extern void nouveau_mem_vram_fini(struct drm_device *);
391 extern int  nouveau_mem_gart_init(struct drm_device *);
392 extern void nouveau_mem_gart_fini(struct drm_device *);
393 extern void nouveau_mem_close(struct drm_device *);
394 extern bool nouveau_mem_flags_valid(struct drm_device *, u32 tile_flags);
395 extern int  nouveau_mem_timing_calc(struct drm_device *, u32 freq,
396                                     struct nouveau_pm_memtiming *);
397 extern void nouveau_mem_timing_read(struct drm_device *,
398                                     struct nouveau_pm_memtiming *);
399 extern int nouveau_mem_vbios_type(struct drm_device *);
400 extern struct nouveau_tile_reg *nv10_mem_set_tiling(
401         struct drm_device *dev, uint32_t addr, uint32_t size,
402         uint32_t pitch, uint32_t flags);
403 extern void nv10_mem_put_tile_region(struct drm_device *dev,
404                                      struct nouveau_tile_reg *tile,
405                                      struct nouveau_fence *fence);
406
407 extern int  nouveau_channel_idle(struct nouveau_channel *chan);
408
409 /* nouveau_gpuobj.c */
410 int  nouveau_gpuobj_map_vm(struct nouveau_gpuobj *gpuobj, struct nouveau_vm *vm,
411                            u32 flags, struct nouveau_vma *vma);
412 void nouveau_gpuobj_unmap(struct nouveau_vma *vma);
413
414 /* nouveau_irq.c */
415 extern int         nouveau_irq_init(struct drm_device *);
416 extern void        nouveau_irq_fini(struct drm_device *);
417 extern irqreturn_t nouveau_irq_handler(DRM_IRQ_ARGS);
418 extern void        nouveau_irq_register(struct drm_device *, int status_bit,
419                                         void (*)(struct drm_device *));
420 extern void        nouveau_irq_unregister(struct drm_device *, int status_bit);
421 extern void        nouveau_irq_preinstall(struct drm_device *);
422 extern int         nouveau_irq_postinstall(struct drm_device *);
423 extern void        nouveau_irq_uninstall(struct drm_device *);
424
425 /* nouveau_acpi.c */
426 #define ROM_BIOS_PAGE 4096
427 #if defined(CONFIG_ACPI)
428 void nouveau_register_dsm_handler(void);
429 void nouveau_unregister_dsm_handler(void);
430 void nouveau_switcheroo_optimus_dsm(void);
431 int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len);
432 bool nouveau_acpi_rom_supported(struct pci_dev *pdev);
433 int nouveau_acpi_edid(struct drm_device *, struct drm_connector *);
434 #else
435 static inline void nouveau_register_dsm_handler(void) {}
436 static inline void nouveau_unregister_dsm_handler(void) {}
437 static inline void nouveau_switcheroo_optimus_dsm(void) {}
438 static inline bool nouveau_acpi_rom_supported(struct pci_dev *pdev) { return false; }
439 static inline int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len) { return -EINVAL; }
440 static inline int nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector) { return -EINVAL; }
441 #endif
442
443 /* nouveau_backlight.c */
444 #ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT
445 extern int nouveau_backlight_init(struct drm_device *);
446 extern void nouveau_backlight_exit(struct drm_device *);
447 #else
448 static inline int nouveau_backlight_init(struct drm_device *dev)
449 {
450         return 0;
451 }
452
453 static inline void nouveau_backlight_exit(struct drm_device *dev) { }
454 #endif
455
456 /* nouveau_bios.c */
457 extern int nouveau_bios_init(struct drm_device *);
458 extern void nouveau_bios_takedown(struct drm_device *dev);
459 extern int nouveau_run_vbios_init(struct drm_device *);
460 extern struct dcb_connector_table_entry *
461 nouveau_bios_connector_entry(struct drm_device *, int index);
462 extern int nouveau_bios_run_display_table(struct drm_device *, u16 id, int clk,
463                                           struct dcb_output *, int crtc);
464 extern bool nouveau_bios_fp_mode(struct drm_device *, struct drm_display_mode *);
465 extern uint8_t *nouveau_bios_embedded_edid(struct drm_device *);
466 extern int nouveau_bios_parse_lvds_table(struct drm_device *, int pxclk,
467                                          bool *dl, bool *if_is_24bit);
468 extern int run_tmds_table(struct drm_device *, struct dcb_output *,
469                           int head, int pxclk);
470 extern int call_lvds_script(struct drm_device *, struct dcb_output *, int head,
471                             enum LVDS_script, int pxclk);
472 bool bios_encoder_match(struct dcb_output *, u32 hash);
473
474 /* nouveau_mxm.c */
475 int  nouveau_mxm_init(struct drm_device *dev);
476 void nouveau_mxm_fini(struct drm_device *dev);
477
478 /* nouveau_ttm.c */
479 int nouveau_ttm_global_init(struct drm_nouveau_private *);
480 void nouveau_ttm_global_release(struct drm_nouveau_private *);
481 int nouveau_ttm_mmap(struct file *, struct vm_area_struct *);
482
483 /* nouveau_hdmi.c */
484 void nouveau_hdmi_mode_set(struct drm_encoder *, struct drm_display_mode *);
485
486 extern long nouveau_compat_ioctl(struct file *file, unsigned int cmd,
487                                  unsigned long arg);
488
489 /* nvd0_display.c */
490 extern int nvd0_display_create(struct drm_device *);
491 extern void nvd0_display_destroy(struct drm_device *);
492 extern int nvd0_display_init(struct drm_device *);
493 extern void nvd0_display_fini(struct drm_device *);
494 struct nouveau_bo *nvd0_display_crtc_sema(struct drm_device *, int crtc);
495 void nvd0_display_flip_stop(struct drm_crtc *);
496 int nvd0_display_flip_next(struct drm_crtc *, struct drm_framebuffer *,
497                            struct nouveau_channel *, u32 swap_interval);
498
499
500 /* nouveau_display.c */
501 int nouveau_display_create(struct drm_device *dev);
502 void nouveau_display_destroy(struct drm_device *dev);
503 int nouveau_display_init(struct drm_device *dev);
504 void nouveau_display_fini(struct drm_device *dev);
505 int nouveau_vblank_enable(struct drm_device *dev, int crtc);
506 void nouveau_vblank_disable(struct drm_device *dev, int crtc);
507 int nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
508                            struct drm_pending_vblank_event *event);
509 int nouveau_finish_page_flip(struct nouveau_channel *,
510                              struct nouveau_page_flip_state *);
511 int nouveau_display_dumb_create(struct drm_file *, struct drm_device *,
512                                 struct drm_mode_create_dumb *args);
513 int nouveau_display_dumb_map_offset(struct drm_file *, struct drm_device *,
514                                     uint32_t handle, uint64_t *offset);
515 int nouveau_display_dumb_destroy(struct drm_file *, struct drm_device *,
516                                  uint32_t handle);
517
518 #ifndef ioread32_native
519 #ifdef __BIG_ENDIAN
520 #define ioread16_native ioread16be
521 #define iowrite16_native iowrite16be
522 #define ioread32_native  ioread32be
523 #define iowrite32_native iowrite32be
524 #else /* def __BIG_ENDIAN */
525 #define ioread16_native ioread16
526 #define iowrite16_native iowrite16
527 #define ioread32_native  ioread32
528 #define iowrite32_native iowrite32
529 #endif /* def __BIG_ENDIAN else */
530 #endif /* !ioread32_native */
531
532 /* register access */
533 #define nv_rd08 _nv_rd08
534 #define nv_wr08 _nv_wr08
535 #define nv_rd32 _nv_rd32
536 #define nv_wr32 _nv_wr32
537 #define nv_mask _nv_mask
538
539 #define nv_wait(dev, reg, mask, val) \
540         nouveau_wait_eq(dev, 2000000000ULL, (reg), (mask), (val))
541 #define nv_wait_ne(dev, reg, mask, val) \
542         nouveau_wait_ne(dev, 2000000000ULL, (reg), (mask), (val))
543 #define nv_wait_cb(dev, func, data) \
544         nouveau_wait_cb(dev, 2000000000ULL, (func), (data))
545
546 /*
547  * Logging
548  * Argument d is (struct drm_device *).
549  */
550 #define NV_PRINTK(level, d, fmt, arg...) \
551         printk(level "[" DRM_NAME "] " DRIVER_NAME " %s: " fmt, \
552                                         pci_name(d->pdev), ##arg)
553 #ifndef NV_DEBUG_NOTRACE
554 #define NV_DEBUG(d, fmt, arg...) do {                                          \
555         if (drm_debug & DRM_UT_DRIVER) {                                       \
556                 NV_PRINTK(KERN_DEBUG, d, "%s:%d - " fmt, __func__,             \
557                           __LINE__, ##arg);                                    \
558         }                                                                      \
559 } while (0)
560 #define NV_DEBUG_KMS(d, fmt, arg...) do {                                      \
561         if (drm_debug & DRM_UT_KMS) {                                          \
562                 NV_PRINTK(KERN_DEBUG, d, "%s:%d - " fmt, __func__,             \
563                           __LINE__, ##arg);                                    \
564         }                                                                      \
565 } while (0)
566 #else
567 #define NV_DEBUG(d, fmt, arg...) do {                                          \
568         if (drm_debug & DRM_UT_DRIVER)                                         \
569                 NV_PRINTK(KERN_DEBUG, d, fmt, ##arg);                          \
570 } while (0)
571 #define NV_DEBUG_KMS(d, fmt, arg...) do {                                      \
572         if (drm_debug & DRM_UT_KMS)                                            \
573                 NV_PRINTK(KERN_DEBUG, d, fmt, ##arg);                          \
574 } while (0)
575 #endif
576 #define NV_ERROR(d, fmt, arg...) NV_PRINTK(KERN_ERR, d, fmt, ##arg)
577 #define NV_INFO(d, fmt, arg...) NV_PRINTK(KERN_INFO, d, fmt, ##arg)
578 #define NV_TRACEWARN(d, fmt, arg...) NV_PRINTK(KERN_NOTICE, d, fmt, ##arg)
579 #define NV_TRACE(d, fmt, arg...) NV_PRINTK(KERN_INFO, d, fmt, ##arg)
580 #define NV_WARN(d, fmt, arg...) NV_PRINTK(KERN_WARNING, d, fmt, ##arg)
581 #define NV_WARNONCE(d, fmt, arg...) do {                                       \
582         static int _warned = 0;                                                \
583         if (!_warned) {                                                        \
584                 NV_WARN(d, fmt, ##arg);                                        \
585                 _warned = 1;                                                   \
586         }                                                                      \
587 } while(0)
588
589 /* nouveau_reg_debug bitmask */
590 enum {
591         NOUVEAU_REG_DEBUG_MC             = 0x1,
592         NOUVEAU_REG_DEBUG_VIDEO          = 0x2,
593         NOUVEAU_REG_DEBUG_FB             = 0x4,
594         NOUVEAU_REG_DEBUG_EXTDEV         = 0x8,
595         NOUVEAU_REG_DEBUG_CRTC           = 0x10,
596         NOUVEAU_REG_DEBUG_RAMDAC         = 0x20,
597         NOUVEAU_REG_DEBUG_VGACRTC        = 0x40,
598         NOUVEAU_REG_DEBUG_RMVIO          = 0x80,
599         NOUVEAU_REG_DEBUG_VGAATTR        = 0x100,
600         NOUVEAU_REG_DEBUG_EVO            = 0x200,
601         NOUVEAU_REG_DEBUG_AUXCH          = 0x400
602 };
603
604 #define NV_REG_DEBUG(type, dev, fmt, arg...) do { \
605         if (nouveau_reg_debug & NOUVEAU_REG_DEBUG_##type) \
606                 NV_PRINTK(KERN_DEBUG, dev, "%s: " fmt, __func__, ##arg); \
607 } while (0)
608
609 static inline bool
610 nv_two_heads(struct drm_device *dev)
611 {
612         struct drm_nouveau_private *dev_priv = dev->dev_private;
613         const int impl = dev->pci_device & 0x0ff0;
614
615         if (dev_priv->card_type >= NV_10 && impl != 0x0100 &&
616             impl != 0x0150 && impl != 0x01a0 && impl != 0x0200)
617                 return true;
618
619         return false;
620 }
621
622 static inline bool
623 nv_gf4_disp_arch(struct drm_device *dev)
624 {
625         return nv_two_heads(dev) && (dev->pci_device & 0x0ff0) != 0x0110;
626 }
627
628 static inline bool
629 nv_two_reg_pll(struct drm_device *dev)
630 {
631         struct drm_nouveau_private *dev_priv = dev->dev_private;
632         const int impl = dev->pci_device & 0x0ff0;
633
634         if (impl == 0x0310 || impl == 0x0340 || dev_priv->card_type >= NV_40)
635                 return true;
636         return false;
637 }
638
639 static inline bool
640 nv_match_device(struct drm_device *dev, unsigned device,
641                 unsigned sub_vendor, unsigned sub_device)
642 {
643         return dev->pdev->device == device &&
644                 dev->pdev->subsystem_vendor == sub_vendor &&
645                 dev->pdev->subsystem_device == sub_device;
646 }
647
648 /* returns 1 if device is one of the nv4x using the 0x4497 object class,
649  * helpful to determine a number of other hardware features
650  */
651 static inline int
652 nv44_graph_class(struct drm_device *dev)
653 {
654         struct drm_nouveau_private *dev_priv = dev->dev_private;
655
656         if ((dev_priv->chipset & 0xf0) == 0x60)
657                 return 1;
658
659         return !(0x0baf & (1 << (dev_priv->chipset & 0x0f)));
660 }
661
662 /* memory type/access flags, do not match hardware values */
663 #define NV_MEM_ACCESS_RO  1
664 #define NV_MEM_ACCESS_WO  2
665 #define NV_MEM_ACCESS_RW (NV_MEM_ACCESS_RO | NV_MEM_ACCESS_WO)
666 #define NV_MEM_ACCESS_SYS 4
667 #define NV_MEM_ACCESS_VM  8
668 #define NV_MEM_ACCESS_NOSNOOP 16
669
670 #define NV_MEM_TARGET_VRAM        0
671 #define NV_MEM_TARGET_PCI         1
672 #define NV_MEM_TARGET_PCI_NOSNOOP 2
673 #define NV_MEM_TARGET_VM          3
674 #define NV_MEM_TARGET_GART        4
675
676 #define NV_MEM_TYPE_VM 0x7f
677 #define NV_MEM_COMP_VM 0x03
678
679 /* FIFO methods */
680 #define NV01_SUBCHAN_OBJECT                                          0x00000000
681 #define NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH                          0x00000010
682 #define NV84_SUBCHAN_SEMAPHORE_ADDRESS_LOW                           0x00000014
683 #define NV84_SUBCHAN_SEMAPHORE_SEQUENCE                              0x00000018
684 #define NV84_SUBCHAN_SEMAPHORE_TRIGGER                               0x0000001c
685 #define NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL                 0x00000001
686 #define NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG                    0x00000002
687 #define NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_GEQUAL                0x00000004
688 #define NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD                         0x00001000
689 #define NV84_SUBCHAN_NOTIFY_INTR                                     0x00000020
690 #define NV84_SUBCHAN_WRCACHE_FLUSH                                   0x00000024
691 #define NV10_SUBCHAN_REF_CNT                                         0x00000050
692 #define NVSW_SUBCHAN_PAGE_FLIP                                       0x00000054
693 #define NV11_SUBCHAN_DMA_SEMAPHORE                                   0x00000060
694 #define NV11_SUBCHAN_SEMAPHORE_OFFSET                                0x00000064
695 #define NV11_SUBCHAN_SEMAPHORE_ACQUIRE                               0x00000068
696 #define NV11_SUBCHAN_SEMAPHORE_RELEASE                               0x0000006c
697 #define NV40_SUBCHAN_YIELD                                           0x00000080
698
699 /* NV_SW object class */
700 #define NV_SW                                                        0x0000506e
701 #define NV_SW_DMA_VBLSEM                                             0x0000018c
702 #define NV_SW_VBLSEM_OFFSET                                          0x00000400
703 #define NV_SW_VBLSEM_RELEASE_VALUE                                   0x00000404
704 #define NV_SW_VBLSEM_RELEASE                                         0x00000408
705 #define NV_SW_PAGE_FLIP                                              0x00000500
706
707 #endif /* __NOUVEAU_DRV_H__ */