drm/nouveau: remove nouveau_gpuobj_ref completely, replace with sanity
[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            "dri-devel@lists.sourceforge.net"
30
31 #define DRIVER_NAME             "nouveau"
32 #define DRIVER_DESC             "nVidia Riva/TNT/GeForce"
33 #define DRIVER_DATE             "20090420"
34
35 #define DRIVER_MAJOR            0
36 #define DRIVER_MINOR            0
37 #define DRIVER_PATCHLEVEL       16
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 struct nouveau_fpriv {
49         struct ttm_object_file *tfile;
50 };
51
52 #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
53
54 #include "nouveau_drm.h"
55 #include "nouveau_reg.h"
56 #include "nouveau_bios.h"
57 struct nouveau_grctx;
58
59 #define MAX_NUM_DCB_ENTRIES 16
60
61 #define NOUVEAU_MAX_CHANNEL_NR 128
62 #define NOUVEAU_MAX_TILE_NR 15
63
64 #define NV50_VM_MAX_VRAM (2*1024*1024*1024ULL)
65 #define NV50_VM_BLOCK    (512*1024*1024ULL)
66 #define NV50_VM_VRAM_NR  (NV50_VM_MAX_VRAM / NV50_VM_BLOCK)
67
68 struct nouveau_tile_reg {
69         struct nouveau_fence *fence;
70         uint32_t addr;
71         uint32_t size;
72         bool used;
73 };
74
75 struct nouveau_bo {
76         struct ttm_buffer_object bo;
77         struct ttm_placement placement;
78         u32 placements[3];
79         u32 busy_placements[3];
80         struct ttm_bo_kmap_obj kmap;
81         struct list_head head;
82
83         /* protected by ttm_bo_reserve() */
84         struct drm_file *reserved_by;
85         struct list_head entry;
86         int pbbo_index;
87         bool validate_mapped;
88
89         struct nouveau_channel *channel;
90
91         bool mappable;
92         bool no_vm;
93
94         uint32_t tile_mode;
95         uint32_t tile_flags;
96         struct nouveau_tile_reg *tile;
97
98         struct drm_gem_object *gem;
99         struct drm_file *cpu_filp;
100         int pin_refcnt;
101 };
102
103 static inline struct nouveau_bo *
104 nouveau_bo(struct ttm_buffer_object *bo)
105 {
106         return container_of(bo, struct nouveau_bo, bo);
107 }
108
109 static inline struct nouveau_bo *
110 nouveau_gem_object(struct drm_gem_object *gem)
111 {
112         return gem ? gem->driver_private : NULL;
113 }
114
115 /* TODO: submit equivalent to TTM generic API upstream? */
116 static inline void __iomem *
117 nvbo_kmap_obj_iovirtual(struct nouveau_bo *nvbo)
118 {
119         bool is_iomem;
120         void __iomem *ioptr = (void __force __iomem *)ttm_kmap_obj_virtual(
121                                                 &nvbo->kmap, &is_iomem);
122         WARN_ON_ONCE(ioptr && !is_iomem);
123         return ioptr;
124 }
125
126 enum nouveau_flags {
127         NV_NFORCE   = 0x10000000,
128         NV_NFORCE2  = 0x20000000
129 };
130
131 #define NVOBJ_ENGINE_SW         0
132 #define NVOBJ_ENGINE_GR         1
133 #define NVOBJ_ENGINE_DISPLAY    2
134 #define NVOBJ_ENGINE_INT        0xdeadbeef
135
136 #define NVOBJ_FLAG_ZERO_ALLOC           (1 << 1)
137 #define NVOBJ_FLAG_ZERO_FREE            (1 << 2)
138 #define NVOBJ_FLAG_FAKE                 (1 << 3)
139 struct nouveau_gpuobj {
140         struct drm_device *dev;
141         struct list_head list;
142
143         struct drm_mm_node *im_pramin;
144         struct nouveau_bo *im_backing;
145         uint32_t im_backing_start;
146         uint32_t *im_backing_suspend;
147         int im_bound;
148
149         uint32_t flags;
150         int refcount;
151
152         u32 pinst;
153         u32 cinst;
154         u64 vinst;
155
156         uint32_t engine;
157         uint32_t class;
158
159         void (*dtor)(struct drm_device *, struct nouveau_gpuobj *);
160         void *priv;
161 };
162
163 struct nouveau_channel {
164         struct drm_device *dev;
165         int id;
166
167         /* owner of this fifo */
168         struct drm_file *file_priv;
169         /* mapping of the fifo itself */
170         struct drm_local_map *map;
171
172         /* mapping of the regs controling the fifo */
173         void __iomem *user;
174         uint32_t user_get;
175         uint32_t user_put;
176
177         /* Fencing */
178         struct {
179                 /* lock protects the pending list only */
180                 spinlock_t lock;
181                 struct list_head pending;
182                 uint32_t sequence;
183                 uint32_t sequence_ack;
184                 atomic_t last_sequence_irq;
185         } fence;
186
187         /* DMA push buffer */
188         struct nouveau_gpuobj *pushbuf;
189         struct nouveau_bo     *pushbuf_bo;
190         uint32_t               pushbuf_base;
191
192         /* Notifier memory */
193         struct nouveau_bo *notifier_bo;
194         struct drm_mm notifier_heap;
195
196         /* PFIFO context */
197         struct nouveau_gpuobj *ramfc;
198         struct nouveau_gpuobj *cache;
199
200         /* PGRAPH context */
201         /* XXX may be merge 2 pointers as private data ??? */
202         struct nouveau_gpuobj *ramin_grctx;
203         void *pgraph_ctx;
204
205         /* NV50 VM */
206         struct nouveau_gpuobj *vm_pd;
207         struct nouveau_gpuobj *vm_gart_pt;
208         struct nouveau_gpuobj *vm_vram_pt[NV50_VM_VRAM_NR];
209
210         /* Objects */
211         struct nouveau_gpuobj *ramin; /* Private instmem */
212         struct drm_mm          ramin_heap; /* Private PRAMIN heap */
213         struct nouveau_ramht  *ramht; /* Hash table */
214
215         /* GPU object info for stuff used in-kernel (mm_enabled) */
216         uint32_t m2mf_ntfy;
217         uint32_t vram_handle;
218         uint32_t gart_handle;
219         bool accel_done;
220
221         /* Push buffer state (only for drm's channel on !mm_enabled) */
222         struct {
223                 int max;
224                 int free;
225                 int cur;
226                 int put;
227                 /* access via pushbuf_bo */
228
229                 int ib_base;
230                 int ib_max;
231                 int ib_free;
232                 int ib_put;
233         } dma;
234
235         uint32_t sw_subchannel[8];
236
237         struct {
238                 struct nouveau_gpuobj *vblsem;
239                 uint32_t vblsem_offset;
240                 uint32_t vblsem_rval;
241                 struct list_head vbl_wait;
242         } nvsw;
243
244         struct {
245                 bool active;
246                 char name[32];
247                 struct drm_info_list info;
248         } debugfs;
249 };
250
251 struct nouveau_instmem_engine {
252         void    *priv;
253
254         int     (*init)(struct drm_device *dev);
255         void    (*takedown)(struct drm_device *dev);
256         int     (*suspend)(struct drm_device *dev);
257         void    (*resume)(struct drm_device *dev);
258
259         int     (*populate)(struct drm_device *, struct nouveau_gpuobj *,
260                             uint32_t *size);
261         void    (*clear)(struct drm_device *, struct nouveau_gpuobj *);
262         int     (*bind)(struct drm_device *, struct nouveau_gpuobj *);
263         int     (*unbind)(struct drm_device *, struct nouveau_gpuobj *);
264         void    (*flush)(struct drm_device *);
265 };
266
267 struct nouveau_mc_engine {
268         int  (*init)(struct drm_device *dev);
269         void (*takedown)(struct drm_device *dev);
270 };
271
272 struct nouveau_timer_engine {
273         int      (*init)(struct drm_device *dev);
274         void     (*takedown)(struct drm_device *dev);
275         uint64_t (*read)(struct drm_device *dev);
276 };
277
278 struct nouveau_fb_engine {
279         int num_tiles;
280
281         int  (*init)(struct drm_device *dev);
282         void (*takedown)(struct drm_device *dev);
283
284         void (*set_region_tiling)(struct drm_device *dev, int i, uint32_t addr,
285                                  uint32_t size, uint32_t pitch);
286 };
287
288 struct nouveau_fifo_engine {
289         int  channels;
290
291         struct nouveau_gpuobj *playlist[2];
292         int cur_playlist;
293
294         int  (*init)(struct drm_device *);
295         void (*takedown)(struct drm_device *);
296
297         void (*disable)(struct drm_device *);
298         void (*enable)(struct drm_device *);
299         bool (*reassign)(struct drm_device *, bool enable);
300         bool (*cache_flush)(struct drm_device *dev);
301         bool (*cache_pull)(struct drm_device *dev, bool enable);
302
303         int  (*channel_id)(struct drm_device *);
304
305         int  (*create_context)(struct nouveau_channel *);
306         void (*destroy_context)(struct nouveau_channel *);
307         int  (*load_context)(struct nouveau_channel *);
308         int  (*unload_context)(struct drm_device *);
309 };
310
311 struct nouveau_pgraph_object_method {
312         int id;
313         int (*exec)(struct nouveau_channel *chan, int grclass, int mthd,
314                       uint32_t data);
315 };
316
317 struct nouveau_pgraph_object_class {
318         int id;
319         bool software;
320         struct nouveau_pgraph_object_method *methods;
321 };
322
323 struct nouveau_pgraph_engine {
324         struct nouveau_pgraph_object_class *grclass;
325         bool accel_blocked;
326         int grctx_size;
327
328         /* NV2x/NV3x context table (0x400780) */
329         struct nouveau_gpuobj *ctx_table;
330
331         int  (*init)(struct drm_device *);
332         void (*takedown)(struct drm_device *);
333
334         void (*fifo_access)(struct drm_device *, bool);
335
336         struct nouveau_channel *(*channel)(struct drm_device *);
337         int  (*create_context)(struct nouveau_channel *);
338         void (*destroy_context)(struct nouveau_channel *);
339         int  (*load_context)(struct nouveau_channel *);
340         int  (*unload_context)(struct drm_device *);
341
342         void (*set_region_tiling)(struct drm_device *dev, int i, uint32_t addr,
343                                   uint32_t size, uint32_t pitch);
344 };
345
346 struct nouveau_display_engine {
347         int (*early_init)(struct drm_device *);
348         void (*late_takedown)(struct drm_device *);
349         int (*create)(struct drm_device *);
350         int (*init)(struct drm_device *);
351         void (*destroy)(struct drm_device *);
352 };
353
354 struct nouveau_gpio_engine {
355         int  (*init)(struct drm_device *);
356         void (*takedown)(struct drm_device *);
357
358         int  (*get)(struct drm_device *, enum dcb_gpio_tag);
359         int  (*set)(struct drm_device *, enum dcb_gpio_tag, int state);
360
361         void (*irq_enable)(struct drm_device *, enum dcb_gpio_tag, bool on);
362 };
363
364 struct nouveau_engine {
365         struct nouveau_instmem_engine instmem;
366         struct nouveau_mc_engine      mc;
367         struct nouveau_timer_engine   timer;
368         struct nouveau_fb_engine      fb;
369         struct nouveau_pgraph_engine  graph;
370         struct nouveau_fifo_engine    fifo;
371         struct nouveau_display_engine display;
372         struct nouveau_gpio_engine    gpio;
373 };
374
375 struct nouveau_pll_vals {
376         union {
377                 struct {
378 #ifdef __BIG_ENDIAN
379                         uint8_t N1, M1, N2, M2;
380 #else
381                         uint8_t M1, N1, M2, N2;
382 #endif
383                 };
384                 struct {
385                         uint16_t NM1, NM2;
386                 } __attribute__((packed));
387         };
388         int log2P;
389
390         int refclk;
391 };
392
393 enum nv04_fp_display_regs {
394         FP_DISPLAY_END,
395         FP_TOTAL,
396         FP_CRTC,
397         FP_SYNC_START,
398         FP_SYNC_END,
399         FP_VALID_START,
400         FP_VALID_END
401 };
402
403 struct nv04_crtc_reg {
404         unsigned char MiscOutReg;     /* */
405         uint8_t CRTC[0xa0];
406         uint8_t CR58[0x10];
407         uint8_t Sequencer[5];
408         uint8_t Graphics[9];
409         uint8_t Attribute[21];
410         unsigned char DAC[768];       /* Internal Colorlookuptable */
411
412         /* PCRTC regs */
413         uint32_t fb_start;
414         uint32_t crtc_cfg;
415         uint32_t cursor_cfg;
416         uint32_t gpio_ext;
417         uint32_t crtc_830;
418         uint32_t crtc_834;
419         uint32_t crtc_850;
420         uint32_t crtc_eng_ctrl;
421
422         /* PRAMDAC regs */
423         uint32_t nv10_cursync;
424         struct nouveau_pll_vals pllvals;
425         uint32_t ramdac_gen_ctrl;
426         uint32_t ramdac_630;
427         uint32_t ramdac_634;
428         uint32_t tv_setup;
429         uint32_t tv_vtotal;
430         uint32_t tv_vskew;
431         uint32_t tv_vsync_delay;
432         uint32_t tv_htotal;
433         uint32_t tv_hskew;
434         uint32_t tv_hsync_delay;
435         uint32_t tv_hsync_delay2;
436         uint32_t fp_horiz_regs[7];
437         uint32_t fp_vert_regs[7];
438         uint32_t dither;
439         uint32_t fp_control;
440         uint32_t dither_regs[6];
441         uint32_t fp_debug_0;
442         uint32_t fp_debug_1;
443         uint32_t fp_debug_2;
444         uint32_t fp_margin_color;
445         uint32_t ramdac_8c0;
446         uint32_t ramdac_a20;
447         uint32_t ramdac_a24;
448         uint32_t ramdac_a34;
449         uint32_t ctv_regs[38];
450 };
451
452 struct nv04_output_reg {
453         uint32_t output;
454         int head;
455 };
456
457 struct nv04_mode_state {
458         uint32_t bpp;
459         uint32_t width;
460         uint32_t height;
461         uint32_t interlace;
462         uint32_t repaint0;
463         uint32_t repaint1;
464         uint32_t screen;
465         uint32_t scale;
466         uint32_t dither;
467         uint32_t extra;
468         uint32_t fifo;
469         uint32_t pixel;
470         uint32_t horiz;
471         int arbitration0;
472         int arbitration1;
473         uint32_t pll;
474         uint32_t pllB;
475         uint32_t vpll;
476         uint32_t vpll2;
477         uint32_t vpllB;
478         uint32_t vpll2B;
479         uint32_t pllsel;
480         uint32_t sel_clk;
481         uint32_t general;
482         uint32_t crtcOwner;
483         uint32_t head;
484         uint32_t head2;
485         uint32_t cursorConfig;
486         uint32_t cursor0;
487         uint32_t cursor1;
488         uint32_t cursor2;
489         uint32_t timingH;
490         uint32_t timingV;
491         uint32_t displayV;
492         uint32_t crtcSync;
493
494         struct nv04_crtc_reg crtc_reg[2];
495 };
496
497 enum nouveau_card_type {
498         NV_04      = 0x00,
499         NV_10      = 0x10,
500         NV_20      = 0x20,
501         NV_30      = 0x30,
502         NV_40      = 0x40,
503         NV_50      = 0x50,
504         NV_C0      = 0xc0,
505 };
506
507 struct drm_nouveau_private {
508         struct drm_device *dev;
509
510         /* the card type, takes NV_* as values */
511         enum nouveau_card_type card_type;
512         /* exact chipset, derived from NV_PMC_BOOT_0 */
513         int chipset;
514         int flags;
515
516         void __iomem *mmio;
517         void __iomem *ramin;
518         uint32_t ramin_size;
519
520         struct nouveau_bo *vga_ram;
521
522         struct workqueue_struct *wq;
523         struct work_struct irq_work;
524         struct work_struct hpd_work;
525
526         struct list_head vbl_waiting;
527
528         struct {
529                 struct drm_global_reference mem_global_ref;
530                 struct ttm_bo_global_ref bo_global_ref;
531                 struct ttm_bo_device bdev;
532                 atomic_t validate_sequence;
533         } ttm;
534
535         int fifo_alloc_count;
536         struct nouveau_channel *fifos[NOUVEAU_MAX_CHANNEL_NR];
537
538         struct nouveau_engine engine;
539         struct nouveau_channel *channel;
540
541         /* For PFIFO and PGRAPH. */
542         spinlock_t context_switch_lock;
543
544         /* RAMIN configuration, RAMFC, RAMHT and RAMRO offsets */
545         struct nouveau_ramht *ramht;
546         uint32_t ramin_rsvd_vram;
547         uint32_t ramht_offset;
548         uint32_t ramht_size;
549         uint32_t ramht_bits;
550         uint32_t ramfc_offset;
551         uint32_t ramfc_size;
552         uint32_t ramro_offset;
553         uint32_t ramro_size;
554
555         struct {
556                 enum {
557                         NOUVEAU_GART_NONE = 0,
558                         NOUVEAU_GART_AGP,
559                         NOUVEAU_GART_SGDMA
560                 } type;
561                 uint64_t aper_base;
562                 uint64_t aper_size;
563                 uint64_t aper_free;
564
565                 struct nouveau_gpuobj *sg_ctxdma;
566                 struct page *sg_dummy_page;
567                 dma_addr_t sg_dummy_bus;
568         } gart_info;
569
570         /* nv10-nv40 tiling regions */
571         struct {
572                 struct nouveau_tile_reg reg[NOUVEAU_MAX_TILE_NR];
573                 spinlock_t lock;
574         } tile;
575
576         /* VRAM/fb configuration */
577         uint64_t vram_size;
578         uint64_t vram_sys_base;
579
580         uint64_t fb_phys;
581         uint64_t fb_available_size;
582         uint64_t fb_mappable_pages;
583         uint64_t fb_aper_free;
584         int fb_mtrr;
585
586         /* G8x/G9x virtual address space */
587         uint64_t vm_gart_base;
588         uint64_t vm_gart_size;
589         uint64_t vm_vram_base;
590         uint64_t vm_vram_size;
591         uint64_t vm_end;
592         struct nouveau_gpuobj *vm_vram_pt[NV50_VM_VRAM_NR];
593         int vm_vram_pt_nr;
594
595         struct drm_mm ramin_heap;
596
597         struct list_head gpuobj_list;
598
599         struct nvbios vbios;
600
601         struct nv04_mode_state mode_reg;
602         struct nv04_mode_state saved_reg;
603         uint32_t saved_vga_font[4][16384];
604         uint32_t crtc_owner;
605         uint32_t dac_users[4];
606
607         struct nouveau_suspend_resume {
608                 uint32_t *ramin_copy;
609         } susres;
610
611         struct backlight_device *backlight;
612
613         struct nouveau_channel *evo;
614         struct {
615                 struct dcb_entry *dcb;
616                 u16 script;
617                 u32 pclk;
618         } evo_irq;
619
620         struct {
621                 struct dentry *channel_root;
622         } debugfs;
623
624         struct nouveau_fbdev *nfbdev;
625         struct apertures_struct *apertures;
626 };
627
628 static inline struct drm_nouveau_private *
629 nouveau_bdev(struct ttm_bo_device *bd)
630 {
631         return container_of(bd, struct drm_nouveau_private, ttm.bdev);
632 }
633
634 static inline int
635 nouveau_bo_ref(struct nouveau_bo *ref, struct nouveau_bo **pnvbo)
636 {
637         struct nouveau_bo *prev;
638
639         if (!pnvbo)
640                 return -EINVAL;
641         prev = *pnvbo;
642
643         *pnvbo = ref ? nouveau_bo(ttm_bo_reference(&ref->bo)) : NULL;
644         if (prev) {
645                 struct ttm_buffer_object *bo = &prev->bo;
646
647                 ttm_bo_unref(&bo);
648         }
649
650         return 0;
651 }
652
653 #define NOUVEAU_GET_USER_CHANNEL_WITH_RETURN(id, cl, ch) do {    \
654         struct drm_nouveau_private *nv = dev->dev_private;       \
655         if (!nouveau_channel_owner(dev, (cl), (id))) {           \
656                 NV_ERROR(dev, "pid %d doesn't own channel %d\n", \
657                          DRM_CURRENTPID, (id));                  \
658                 return -EPERM;                                   \
659         }                                                        \
660         (ch) = nv->fifos[(id)];                                  \
661 } while (0)
662
663 /* nouveau_drv.c */
664 extern int nouveau_noagp;
665 extern int nouveau_duallink;
666 extern int nouveau_uscript_lvds;
667 extern int nouveau_uscript_tmds;
668 extern int nouveau_vram_pushbuf;
669 extern int nouveau_vram_notify;
670 extern int nouveau_fbpercrtc;
671 extern int nouveau_tv_disable;
672 extern char *nouveau_tv_norm;
673 extern int nouveau_reg_debug;
674 extern char *nouveau_vbios;
675 extern int nouveau_ignorelid;
676 extern int nouveau_nofbaccel;
677 extern int nouveau_noaccel;
678 extern int nouveau_override_conntype;
679
680 extern int nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state);
681 extern int nouveau_pci_resume(struct pci_dev *pdev);
682
683 /* nouveau_state.c */
684 extern void nouveau_preclose(struct drm_device *dev, struct drm_file *);
685 extern int  nouveau_load(struct drm_device *, unsigned long flags);
686 extern int  nouveau_firstopen(struct drm_device *);
687 extern void nouveau_lastclose(struct drm_device *);
688 extern int  nouveau_unload(struct drm_device *);
689 extern int  nouveau_ioctl_getparam(struct drm_device *, void *data,
690                                    struct drm_file *);
691 extern int  nouveau_ioctl_setparam(struct drm_device *, void *data,
692                                    struct drm_file *);
693 extern bool nouveau_wait_until(struct drm_device *, uint64_t timeout,
694                                uint32_t reg, uint32_t mask, uint32_t val);
695 extern bool nouveau_wait_for_idle(struct drm_device *);
696 extern int  nouveau_card_init(struct drm_device *);
697
698 /* nouveau_mem.c */
699 extern int  nouveau_mem_detect(struct drm_device *dev);
700 extern int  nouveau_mem_init(struct drm_device *);
701 extern int  nouveau_mem_init_agp(struct drm_device *);
702 extern int  nouveau_mem_reset_agp(struct drm_device *);
703 extern void nouveau_mem_close(struct drm_device *);
704 extern struct nouveau_tile_reg *nv10_mem_set_tiling(struct drm_device *dev,
705                                                     uint32_t addr,
706                                                     uint32_t size,
707                                                     uint32_t pitch);
708 extern void nv10_mem_expire_tiling(struct drm_device *dev,
709                                    struct nouveau_tile_reg *tile,
710                                    struct nouveau_fence *fence);
711 extern int  nv50_mem_vm_bind_linear(struct drm_device *, uint64_t virt,
712                                     uint32_t size, uint32_t flags,
713                                     uint64_t phys);
714 extern void nv50_mem_vm_unbind(struct drm_device *, uint64_t virt,
715                                uint32_t size);
716
717 /* nouveau_notifier.c */
718 extern int  nouveau_notifier_init_channel(struct nouveau_channel *);
719 extern void nouveau_notifier_takedown_channel(struct nouveau_channel *);
720 extern int  nouveau_notifier_alloc(struct nouveau_channel *, uint32_t handle,
721                                    int cout, uint32_t *offset);
722 extern int  nouveau_notifier_offset(struct nouveau_gpuobj *, uint32_t *);
723 extern int  nouveau_ioctl_notifier_alloc(struct drm_device *, void *data,
724                                          struct drm_file *);
725 extern int  nouveau_ioctl_notifier_free(struct drm_device *, void *data,
726                                         struct drm_file *);
727
728 /* nouveau_channel.c */
729 extern struct drm_ioctl_desc nouveau_ioctls[];
730 extern int nouveau_max_ioctl;
731 extern void nouveau_channel_cleanup(struct drm_device *, struct drm_file *);
732 extern int  nouveau_channel_owner(struct drm_device *, struct drm_file *,
733                                   int channel);
734 extern int  nouveau_channel_alloc(struct drm_device *dev,
735                                   struct nouveau_channel **chan,
736                                   struct drm_file *file_priv,
737                                   uint32_t fb_ctxdma, uint32_t tt_ctxdma);
738 extern void nouveau_channel_free(struct nouveau_channel *);
739
740 /* nouveau_object.c */
741 extern int  nouveau_gpuobj_early_init(struct drm_device *);
742 extern int  nouveau_gpuobj_init(struct drm_device *);
743 extern void nouveau_gpuobj_takedown(struct drm_device *);
744 extern void nouveau_gpuobj_late_takedown(struct drm_device *);
745 extern int  nouveau_gpuobj_suspend(struct drm_device *dev);
746 extern void nouveau_gpuobj_suspend_cleanup(struct drm_device *dev);
747 extern void nouveau_gpuobj_resume(struct drm_device *dev);
748 extern int nouveau_gpuobj_channel_init(struct nouveau_channel *,
749                                        uint32_t vram_h, uint32_t tt_h);
750 extern void nouveau_gpuobj_channel_takedown(struct nouveau_channel *);
751 extern int nouveau_gpuobj_new(struct drm_device *, struct nouveau_channel *,
752                               uint32_t size, int align, uint32_t flags,
753                               struct nouveau_gpuobj **);
754 extern void nouveau_gpuobj_ref(struct nouveau_gpuobj *,
755                                struct nouveau_gpuobj **);
756 extern int nouveau_gpuobj_new_fake(struct drm_device *,
757                                    uint32_t p_offset, uint32_t b_offset,
758                                    uint32_t size, uint32_t flags,
759                                    struct nouveau_gpuobj **);
760 extern int nouveau_gpuobj_dma_new(struct nouveau_channel *, int class,
761                                   uint64_t offset, uint64_t size, int access,
762                                   int target, struct nouveau_gpuobj **);
763 extern int nouveau_gpuobj_gart_dma_new(struct nouveau_channel *,
764                                        uint64_t offset, uint64_t size,
765                                        int access, struct nouveau_gpuobj **,
766                                        uint32_t *o_ret);
767 extern int nouveau_gpuobj_gr_new(struct nouveau_channel *, int class,
768                                  struct nouveau_gpuobj **);
769 extern int nouveau_gpuobj_sw_new(struct nouveau_channel *, int class,
770                                  struct nouveau_gpuobj **);
771 extern int nouveau_ioctl_grobj_alloc(struct drm_device *, void *data,
772                                      struct drm_file *);
773 extern int nouveau_ioctl_gpuobj_free(struct drm_device *, void *data,
774                                      struct drm_file *);
775
776 /* nouveau_irq.c */
777 extern irqreturn_t nouveau_irq_handler(DRM_IRQ_ARGS);
778 extern void        nouveau_irq_preinstall(struct drm_device *);
779 extern int         nouveau_irq_postinstall(struct drm_device *);
780 extern void        nouveau_irq_uninstall(struct drm_device *);
781
782 /* nouveau_sgdma.c */
783 extern int nouveau_sgdma_init(struct drm_device *);
784 extern void nouveau_sgdma_takedown(struct drm_device *);
785 extern int nouveau_sgdma_get_page(struct drm_device *, uint32_t offset,
786                                   uint32_t *page);
787 extern struct ttm_backend *nouveau_sgdma_init_ttm(struct drm_device *);
788
789 /* nouveau_debugfs.c */
790 #if defined(CONFIG_DRM_NOUVEAU_DEBUG)
791 extern int  nouveau_debugfs_init(struct drm_minor *);
792 extern void nouveau_debugfs_takedown(struct drm_minor *);
793 extern int  nouveau_debugfs_channel_init(struct nouveau_channel *);
794 extern void nouveau_debugfs_channel_fini(struct nouveau_channel *);
795 #else
796 static inline int
797 nouveau_debugfs_init(struct drm_minor *minor)
798 {
799         return 0;
800 }
801
802 static inline void nouveau_debugfs_takedown(struct drm_minor *minor)
803 {
804 }
805
806 static inline int
807 nouveau_debugfs_channel_init(struct nouveau_channel *chan)
808 {
809         return 0;
810 }
811
812 static inline void
813 nouveau_debugfs_channel_fini(struct nouveau_channel *chan)
814 {
815 }
816 #endif
817
818 /* nouveau_dma.c */
819 extern void nouveau_dma_pre_init(struct nouveau_channel *);
820 extern int  nouveau_dma_init(struct nouveau_channel *);
821 extern int  nouveau_dma_wait(struct nouveau_channel *, int slots, int size);
822
823 /* nouveau_acpi.c */
824 #define ROM_BIOS_PAGE 4096
825 #if defined(CONFIG_ACPI)
826 void nouveau_register_dsm_handler(void);
827 void nouveau_unregister_dsm_handler(void);
828 int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len);
829 bool nouveau_acpi_rom_supported(struct pci_dev *pdev);
830 int nouveau_acpi_edid(struct drm_device *, struct drm_connector *);
831 #else
832 static inline void nouveau_register_dsm_handler(void) {}
833 static inline void nouveau_unregister_dsm_handler(void) {}
834 static inline bool nouveau_acpi_rom_supported(struct pci_dev *pdev) { return false; }
835 static inline int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len) { return -EINVAL; }
836 static inline int nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector) { return -EINVAL; }
837 #endif
838
839 /* nouveau_backlight.c */
840 #ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT
841 extern int nouveau_backlight_init(struct drm_device *);
842 extern void nouveau_backlight_exit(struct drm_device *);
843 #else
844 static inline int nouveau_backlight_init(struct drm_device *dev)
845 {
846         return 0;
847 }
848
849 static inline void nouveau_backlight_exit(struct drm_device *dev) { }
850 #endif
851
852 /* nouveau_bios.c */
853 extern int nouveau_bios_init(struct drm_device *);
854 extern void nouveau_bios_takedown(struct drm_device *dev);
855 extern int nouveau_run_vbios_init(struct drm_device *);
856 extern void nouveau_bios_run_init_table(struct drm_device *, uint16_t table,
857                                         struct dcb_entry *);
858 extern struct dcb_gpio_entry *nouveau_bios_gpio_entry(struct drm_device *,
859                                                       enum dcb_gpio_tag);
860 extern struct dcb_connector_table_entry *
861 nouveau_bios_connector_entry(struct drm_device *, int index);
862 extern int get_pll_limits(struct drm_device *, uint32_t limit_match,
863                           struct pll_lims *);
864 extern int nouveau_bios_run_display_table(struct drm_device *,
865                                           struct dcb_entry *,
866                                           uint32_t script, int pxclk);
867 extern void *nouveau_bios_dp_table(struct drm_device *, struct dcb_entry *,
868                                    int *length);
869 extern bool nouveau_bios_fp_mode(struct drm_device *, struct drm_display_mode *);
870 extern uint8_t *nouveau_bios_embedded_edid(struct drm_device *);
871 extern int nouveau_bios_parse_lvds_table(struct drm_device *, int pxclk,
872                                          bool *dl, bool *if_is_24bit);
873 extern int run_tmds_table(struct drm_device *, struct dcb_entry *,
874                           int head, int pxclk);
875 extern int call_lvds_script(struct drm_device *, struct dcb_entry *, int head,
876                             enum LVDS_script, int pxclk);
877
878 /* nouveau_ttm.c */
879 int nouveau_ttm_global_init(struct drm_nouveau_private *);
880 void nouveau_ttm_global_release(struct drm_nouveau_private *);
881 int nouveau_ttm_mmap(struct file *, struct vm_area_struct *);
882
883 /* nouveau_dp.c */
884 int nouveau_dp_auxch(struct nouveau_i2c_chan *auxch, int cmd, int addr,
885                      uint8_t *data, int data_nr);
886 bool nouveau_dp_detect(struct drm_encoder *);
887 bool nouveau_dp_link_train(struct drm_encoder *);
888
889 /* nv04_fb.c */
890 extern int  nv04_fb_init(struct drm_device *);
891 extern void nv04_fb_takedown(struct drm_device *);
892
893 /* nv10_fb.c */
894 extern int  nv10_fb_init(struct drm_device *);
895 extern void nv10_fb_takedown(struct drm_device *);
896 extern void nv10_fb_set_region_tiling(struct drm_device *, int, uint32_t,
897                                       uint32_t, uint32_t);
898
899 /* nv30_fb.c */
900 extern int  nv30_fb_init(struct drm_device *);
901 extern void nv30_fb_takedown(struct drm_device *);
902
903 /* nv40_fb.c */
904 extern int  nv40_fb_init(struct drm_device *);
905 extern void nv40_fb_takedown(struct drm_device *);
906 extern void nv40_fb_set_region_tiling(struct drm_device *, int, uint32_t,
907                                       uint32_t, uint32_t);
908
909 /* nv50_fb.c */
910 extern int  nv50_fb_init(struct drm_device *);
911 extern void nv50_fb_takedown(struct drm_device *);
912
913 /* nvc0_fb.c */
914 extern int  nvc0_fb_init(struct drm_device *);
915 extern void nvc0_fb_takedown(struct drm_device *);
916
917 /* nv04_fifo.c */
918 extern int  nv04_fifo_init(struct drm_device *);
919 extern void nv04_fifo_disable(struct drm_device *);
920 extern void nv04_fifo_enable(struct drm_device *);
921 extern bool nv04_fifo_reassign(struct drm_device *, bool);
922 extern bool nv04_fifo_cache_flush(struct drm_device *);
923 extern bool nv04_fifo_cache_pull(struct drm_device *, bool);
924 extern int  nv04_fifo_channel_id(struct drm_device *);
925 extern int  nv04_fifo_create_context(struct nouveau_channel *);
926 extern void nv04_fifo_destroy_context(struct nouveau_channel *);
927 extern int  nv04_fifo_load_context(struct nouveau_channel *);
928 extern int  nv04_fifo_unload_context(struct drm_device *);
929
930 /* nv10_fifo.c */
931 extern int  nv10_fifo_init(struct drm_device *);
932 extern int  nv10_fifo_channel_id(struct drm_device *);
933 extern int  nv10_fifo_create_context(struct nouveau_channel *);
934 extern void nv10_fifo_destroy_context(struct nouveau_channel *);
935 extern int  nv10_fifo_load_context(struct nouveau_channel *);
936 extern int  nv10_fifo_unload_context(struct drm_device *);
937
938 /* nv40_fifo.c */
939 extern int  nv40_fifo_init(struct drm_device *);
940 extern int  nv40_fifo_create_context(struct nouveau_channel *);
941 extern void nv40_fifo_destroy_context(struct nouveau_channel *);
942 extern int  nv40_fifo_load_context(struct nouveau_channel *);
943 extern int  nv40_fifo_unload_context(struct drm_device *);
944
945 /* nv50_fifo.c */
946 extern int  nv50_fifo_init(struct drm_device *);
947 extern void nv50_fifo_takedown(struct drm_device *);
948 extern int  nv50_fifo_channel_id(struct drm_device *);
949 extern int  nv50_fifo_create_context(struct nouveau_channel *);
950 extern void nv50_fifo_destroy_context(struct nouveau_channel *);
951 extern int  nv50_fifo_load_context(struct nouveau_channel *);
952 extern int  nv50_fifo_unload_context(struct drm_device *);
953
954 /* nvc0_fifo.c */
955 extern int  nvc0_fifo_init(struct drm_device *);
956 extern void nvc0_fifo_takedown(struct drm_device *);
957 extern void nvc0_fifo_disable(struct drm_device *);
958 extern void nvc0_fifo_enable(struct drm_device *);
959 extern bool nvc0_fifo_reassign(struct drm_device *, bool);
960 extern bool nvc0_fifo_cache_flush(struct drm_device *);
961 extern bool nvc0_fifo_cache_pull(struct drm_device *, bool);
962 extern int  nvc0_fifo_channel_id(struct drm_device *);
963 extern int  nvc0_fifo_create_context(struct nouveau_channel *);
964 extern void nvc0_fifo_destroy_context(struct nouveau_channel *);
965 extern int  nvc0_fifo_load_context(struct nouveau_channel *);
966 extern int  nvc0_fifo_unload_context(struct drm_device *);
967
968 /* nv04_graph.c */
969 extern struct nouveau_pgraph_object_class nv04_graph_grclass[];
970 extern int  nv04_graph_init(struct drm_device *);
971 extern void nv04_graph_takedown(struct drm_device *);
972 extern void nv04_graph_fifo_access(struct drm_device *, bool);
973 extern struct nouveau_channel *nv04_graph_channel(struct drm_device *);
974 extern int  nv04_graph_create_context(struct nouveau_channel *);
975 extern void nv04_graph_destroy_context(struct nouveau_channel *);
976 extern int  nv04_graph_load_context(struct nouveau_channel *);
977 extern int  nv04_graph_unload_context(struct drm_device *);
978 extern void nv04_graph_context_switch(struct drm_device *);
979
980 /* nv10_graph.c */
981 extern struct nouveau_pgraph_object_class nv10_graph_grclass[];
982 extern int  nv10_graph_init(struct drm_device *);
983 extern void nv10_graph_takedown(struct drm_device *);
984 extern struct nouveau_channel *nv10_graph_channel(struct drm_device *);
985 extern int  nv10_graph_create_context(struct nouveau_channel *);
986 extern void nv10_graph_destroy_context(struct nouveau_channel *);
987 extern int  nv10_graph_load_context(struct nouveau_channel *);
988 extern int  nv10_graph_unload_context(struct drm_device *);
989 extern void nv10_graph_context_switch(struct drm_device *);
990 extern void nv10_graph_set_region_tiling(struct drm_device *, int, uint32_t,
991                                          uint32_t, uint32_t);
992
993 /* nv20_graph.c */
994 extern struct nouveau_pgraph_object_class nv20_graph_grclass[];
995 extern struct nouveau_pgraph_object_class nv30_graph_grclass[];
996 extern int  nv20_graph_create_context(struct nouveau_channel *);
997 extern void nv20_graph_destroy_context(struct nouveau_channel *);
998 extern int  nv20_graph_load_context(struct nouveau_channel *);
999 extern int  nv20_graph_unload_context(struct drm_device *);
1000 extern int  nv20_graph_init(struct drm_device *);
1001 extern void nv20_graph_takedown(struct drm_device *);
1002 extern int  nv30_graph_init(struct drm_device *);
1003 extern void nv20_graph_set_region_tiling(struct drm_device *, int, uint32_t,
1004                                          uint32_t, uint32_t);
1005
1006 /* nv40_graph.c */
1007 extern struct nouveau_pgraph_object_class nv40_graph_grclass[];
1008 extern int  nv40_graph_init(struct drm_device *);
1009 extern void nv40_graph_takedown(struct drm_device *);
1010 extern struct nouveau_channel *nv40_graph_channel(struct drm_device *);
1011 extern int  nv40_graph_create_context(struct nouveau_channel *);
1012 extern void nv40_graph_destroy_context(struct nouveau_channel *);
1013 extern int  nv40_graph_load_context(struct nouveau_channel *);
1014 extern int  nv40_graph_unload_context(struct drm_device *);
1015 extern void nv40_grctx_init(struct nouveau_grctx *);
1016 extern void nv40_graph_set_region_tiling(struct drm_device *, int, uint32_t,
1017                                          uint32_t, uint32_t);
1018
1019 /* nv50_graph.c */
1020 extern struct nouveau_pgraph_object_class nv50_graph_grclass[];
1021 extern int  nv50_graph_init(struct drm_device *);
1022 extern void nv50_graph_takedown(struct drm_device *);
1023 extern void nv50_graph_fifo_access(struct drm_device *, bool);
1024 extern struct nouveau_channel *nv50_graph_channel(struct drm_device *);
1025 extern int  nv50_graph_create_context(struct nouveau_channel *);
1026 extern void nv50_graph_destroy_context(struct nouveau_channel *);
1027 extern int  nv50_graph_load_context(struct nouveau_channel *);
1028 extern int  nv50_graph_unload_context(struct drm_device *);
1029 extern void nv50_graph_context_switch(struct drm_device *);
1030 extern int  nv50_grctx_init(struct nouveau_grctx *);
1031
1032 /* nvc0_graph.c */
1033 extern int  nvc0_graph_init(struct drm_device *);
1034 extern void nvc0_graph_takedown(struct drm_device *);
1035 extern void nvc0_graph_fifo_access(struct drm_device *, bool);
1036 extern struct nouveau_channel *nvc0_graph_channel(struct drm_device *);
1037 extern int  nvc0_graph_create_context(struct nouveau_channel *);
1038 extern void nvc0_graph_destroy_context(struct nouveau_channel *);
1039 extern int  nvc0_graph_load_context(struct nouveau_channel *);
1040 extern int  nvc0_graph_unload_context(struct drm_device *);
1041
1042 /* nv04_instmem.c */
1043 extern int  nv04_instmem_init(struct drm_device *);
1044 extern void nv04_instmem_takedown(struct drm_device *);
1045 extern int  nv04_instmem_suspend(struct drm_device *);
1046 extern void nv04_instmem_resume(struct drm_device *);
1047 extern int  nv04_instmem_populate(struct drm_device *, struct nouveau_gpuobj *,
1048                                   uint32_t *size);
1049 extern void nv04_instmem_clear(struct drm_device *, struct nouveau_gpuobj *);
1050 extern int  nv04_instmem_bind(struct drm_device *, struct nouveau_gpuobj *);
1051 extern int  nv04_instmem_unbind(struct drm_device *, struct nouveau_gpuobj *);
1052 extern void nv04_instmem_flush(struct drm_device *);
1053
1054 /* nv50_instmem.c */
1055 extern int  nv50_instmem_init(struct drm_device *);
1056 extern void nv50_instmem_takedown(struct drm_device *);
1057 extern int  nv50_instmem_suspend(struct drm_device *);
1058 extern void nv50_instmem_resume(struct drm_device *);
1059 extern int  nv50_instmem_populate(struct drm_device *, struct nouveau_gpuobj *,
1060                                   uint32_t *size);
1061 extern void nv50_instmem_clear(struct drm_device *, struct nouveau_gpuobj *);
1062 extern int  nv50_instmem_bind(struct drm_device *, struct nouveau_gpuobj *);
1063 extern int  nv50_instmem_unbind(struct drm_device *, struct nouveau_gpuobj *);
1064 extern void nv50_instmem_flush(struct drm_device *);
1065 extern void nv84_instmem_flush(struct drm_device *);
1066 extern void nv50_vm_flush(struct drm_device *, int engine);
1067
1068 /* nvc0_instmem.c */
1069 extern int  nvc0_instmem_init(struct drm_device *);
1070 extern void nvc0_instmem_takedown(struct drm_device *);
1071 extern int  nvc0_instmem_suspend(struct drm_device *);
1072 extern void nvc0_instmem_resume(struct drm_device *);
1073 extern int  nvc0_instmem_populate(struct drm_device *, struct nouveau_gpuobj *,
1074                                   uint32_t *size);
1075 extern void nvc0_instmem_clear(struct drm_device *, struct nouveau_gpuobj *);
1076 extern int  nvc0_instmem_bind(struct drm_device *, struct nouveau_gpuobj *);
1077 extern int  nvc0_instmem_unbind(struct drm_device *, struct nouveau_gpuobj *);
1078 extern void nvc0_instmem_flush(struct drm_device *);
1079
1080 /* nv04_mc.c */
1081 extern int  nv04_mc_init(struct drm_device *);
1082 extern void nv04_mc_takedown(struct drm_device *);
1083
1084 /* nv40_mc.c */
1085 extern int  nv40_mc_init(struct drm_device *);
1086 extern void nv40_mc_takedown(struct drm_device *);
1087
1088 /* nv50_mc.c */
1089 extern int  nv50_mc_init(struct drm_device *);
1090 extern void nv50_mc_takedown(struct drm_device *);
1091
1092 /* nv04_timer.c */
1093 extern int  nv04_timer_init(struct drm_device *);
1094 extern uint64_t nv04_timer_read(struct drm_device *);
1095 extern void nv04_timer_takedown(struct drm_device *);
1096
1097 extern long nouveau_compat_ioctl(struct file *file, unsigned int cmd,
1098                                  unsigned long arg);
1099
1100 /* nv04_dac.c */
1101 extern int nv04_dac_create(struct drm_connector *, struct dcb_entry *);
1102 extern uint32_t nv17_dac_sample_load(struct drm_encoder *encoder);
1103 extern int nv04_dac_output_offset(struct drm_encoder *encoder);
1104 extern void nv04_dac_update_dacclk(struct drm_encoder *encoder, bool enable);
1105 extern bool nv04_dac_in_use(struct drm_encoder *encoder);
1106
1107 /* nv04_dfp.c */
1108 extern int nv04_dfp_create(struct drm_connector *, struct dcb_entry *);
1109 extern int nv04_dfp_get_bound_head(struct drm_device *dev, struct dcb_entry *dcbent);
1110 extern void nv04_dfp_bind_head(struct drm_device *dev, struct dcb_entry *dcbent,
1111                                int head, bool dl);
1112 extern void nv04_dfp_disable(struct drm_device *dev, int head);
1113 extern void nv04_dfp_update_fp_control(struct drm_encoder *encoder, int mode);
1114
1115 /* nv04_tv.c */
1116 extern int nv04_tv_identify(struct drm_device *dev, int i2c_index);
1117 extern int nv04_tv_create(struct drm_connector *, struct dcb_entry *);
1118
1119 /* nv17_tv.c */
1120 extern int nv17_tv_create(struct drm_connector *, struct dcb_entry *);
1121
1122 /* nv04_display.c */
1123 extern int nv04_display_early_init(struct drm_device *);
1124 extern void nv04_display_late_takedown(struct drm_device *);
1125 extern int nv04_display_create(struct drm_device *);
1126 extern int nv04_display_init(struct drm_device *);
1127 extern void nv04_display_destroy(struct drm_device *);
1128
1129 /* nv04_crtc.c */
1130 extern int nv04_crtc_create(struct drm_device *, int index);
1131
1132 /* nouveau_bo.c */
1133 extern struct ttm_bo_driver nouveau_bo_driver;
1134 extern int nouveau_bo_new(struct drm_device *, struct nouveau_channel *,
1135                           int size, int align, uint32_t flags,
1136                           uint32_t tile_mode, uint32_t tile_flags,
1137                           bool no_vm, bool mappable, struct nouveau_bo **);
1138 extern int nouveau_bo_pin(struct nouveau_bo *, uint32_t flags);
1139 extern int nouveau_bo_unpin(struct nouveau_bo *);
1140 extern int nouveau_bo_map(struct nouveau_bo *);
1141 extern void nouveau_bo_unmap(struct nouveau_bo *);
1142 extern void nouveau_bo_placement_set(struct nouveau_bo *, uint32_t type,
1143                                      uint32_t busy);
1144 extern u16 nouveau_bo_rd16(struct nouveau_bo *nvbo, unsigned index);
1145 extern void nouveau_bo_wr16(struct nouveau_bo *nvbo, unsigned index, u16 val);
1146 extern u32 nouveau_bo_rd32(struct nouveau_bo *nvbo, unsigned index);
1147 extern void nouveau_bo_wr32(struct nouveau_bo *nvbo, unsigned index, u32 val);
1148 extern int nouveau_bo_sync_gpu(struct nouveau_bo *, struct nouveau_channel *);
1149
1150 /* nouveau_fence.c */
1151 struct nouveau_fence;
1152 extern int nouveau_fence_init(struct nouveau_channel *);
1153 extern void nouveau_fence_fini(struct nouveau_channel *);
1154 extern void nouveau_fence_update(struct nouveau_channel *);
1155 extern int nouveau_fence_new(struct nouveau_channel *, struct nouveau_fence **,
1156                              bool emit);
1157 extern int nouveau_fence_emit(struct nouveau_fence *);
1158 struct nouveau_channel *nouveau_fence_channel(struct nouveau_fence *);
1159 extern bool nouveau_fence_signalled(void *obj, void *arg);
1160 extern int nouveau_fence_wait(void *obj, void *arg, bool lazy, bool intr);
1161 extern int nouveau_fence_flush(void *obj, void *arg);
1162 extern void nouveau_fence_unref(void **obj);
1163 extern void *nouveau_fence_ref(void *obj);
1164
1165 /* nouveau_gem.c */
1166 extern int nouveau_gem_new(struct drm_device *, struct nouveau_channel *,
1167                            int size, int align, uint32_t flags,
1168                            uint32_t tile_mode, uint32_t tile_flags,
1169                            bool no_vm, bool mappable, struct nouveau_bo **);
1170 extern int nouveau_gem_object_new(struct drm_gem_object *);
1171 extern void nouveau_gem_object_del(struct drm_gem_object *);
1172 extern int nouveau_gem_ioctl_new(struct drm_device *, void *,
1173                                  struct drm_file *);
1174 extern int nouveau_gem_ioctl_pushbuf(struct drm_device *, void *,
1175                                      struct drm_file *);
1176 extern int nouveau_gem_ioctl_cpu_prep(struct drm_device *, void *,
1177                                       struct drm_file *);
1178 extern int nouveau_gem_ioctl_cpu_fini(struct drm_device *, void *,
1179                                       struct drm_file *);
1180 extern int nouveau_gem_ioctl_info(struct drm_device *, void *,
1181                                   struct drm_file *);
1182
1183 /* nv10_gpio.c */
1184 int nv10_gpio_get(struct drm_device *dev, enum dcb_gpio_tag tag);
1185 int nv10_gpio_set(struct drm_device *dev, enum dcb_gpio_tag tag, int state);
1186
1187 /* nv50_gpio.c */
1188 int nv50_gpio_init(struct drm_device *dev);
1189 int nv50_gpio_get(struct drm_device *dev, enum dcb_gpio_tag tag);
1190 int nv50_gpio_set(struct drm_device *dev, enum dcb_gpio_tag tag, int state);
1191 void nv50_gpio_irq_enable(struct drm_device *, enum dcb_gpio_tag, bool on);
1192
1193 /* nv50_calc. */
1194 int nv50_calc_pll(struct drm_device *, struct pll_lims *, int clk,
1195                   int *N1, int *M1, int *N2, int *M2, int *P);
1196 int nv50_calc_pll2(struct drm_device *, struct pll_lims *,
1197                    int clk, int *N, int *fN, int *M, int *P);
1198
1199 #ifndef ioread32_native
1200 #ifdef __BIG_ENDIAN
1201 #define ioread16_native ioread16be
1202 #define iowrite16_native iowrite16be
1203 #define ioread32_native  ioread32be
1204 #define iowrite32_native iowrite32be
1205 #else /* def __BIG_ENDIAN */
1206 #define ioread16_native ioread16
1207 #define iowrite16_native iowrite16
1208 #define ioread32_native  ioread32
1209 #define iowrite32_native iowrite32
1210 #endif /* def __BIG_ENDIAN else */
1211 #endif /* !ioread32_native */
1212
1213 /* channel control reg access */
1214 static inline u32 nvchan_rd32(struct nouveau_channel *chan, unsigned reg)
1215 {
1216         return ioread32_native(chan->user + reg);
1217 }
1218
1219 static inline void nvchan_wr32(struct nouveau_channel *chan,
1220                                                         unsigned reg, u32 val)
1221 {
1222         iowrite32_native(val, chan->user + reg);
1223 }
1224
1225 /* register access */
1226 static inline u32 nv_rd32(struct drm_device *dev, unsigned reg)
1227 {
1228         struct drm_nouveau_private *dev_priv = dev->dev_private;
1229         return ioread32_native(dev_priv->mmio + reg);
1230 }
1231
1232 static inline void nv_wr32(struct drm_device *dev, unsigned reg, u32 val)
1233 {
1234         struct drm_nouveau_private *dev_priv = dev->dev_private;
1235         iowrite32_native(val, dev_priv->mmio + reg);
1236 }
1237
1238 static inline u32 nv_mask(struct drm_device *dev, u32 reg, u32 mask, u32 val)
1239 {
1240         u32 tmp = nv_rd32(dev, reg);
1241         nv_wr32(dev, reg, (tmp & ~mask) | val);
1242         return tmp;
1243 }
1244
1245 static inline u8 nv_rd08(struct drm_device *dev, unsigned reg)
1246 {
1247         struct drm_nouveau_private *dev_priv = dev->dev_private;
1248         return ioread8(dev_priv->mmio + reg);
1249 }
1250
1251 static inline void nv_wr08(struct drm_device *dev, unsigned reg, u8 val)
1252 {
1253         struct drm_nouveau_private *dev_priv = dev->dev_private;
1254         iowrite8(val, dev_priv->mmio + reg);
1255 }
1256
1257 #define nv_wait(reg, mask, val) \
1258         nouveau_wait_until(dev, 2000000000ULL, (reg), (mask), (val))
1259
1260 /* PRAMIN access */
1261 static inline u32 nv_ri32(struct drm_device *dev, unsigned offset)
1262 {
1263         struct drm_nouveau_private *dev_priv = dev->dev_private;
1264         return ioread32_native(dev_priv->ramin + offset);
1265 }
1266
1267 static inline void nv_wi32(struct drm_device *dev, unsigned offset, u32 val)
1268 {
1269         struct drm_nouveau_private *dev_priv = dev->dev_private;
1270         iowrite32_native(val, dev_priv->ramin + offset);
1271 }
1272
1273 /* object access */
1274 extern u32 nv_ro32(struct nouveau_gpuobj *, u32 offset);
1275 extern void nv_wo32(struct nouveau_gpuobj *, u32 offset, u32 val);
1276
1277 /*
1278  * Logging
1279  * Argument d is (struct drm_device *).
1280  */
1281 #define NV_PRINTK(level, d, fmt, arg...) \
1282         printk(level "[" DRM_NAME "] " DRIVER_NAME " %s: " fmt, \
1283                                         pci_name(d->pdev), ##arg)
1284 #ifndef NV_DEBUG_NOTRACE
1285 #define NV_DEBUG(d, fmt, arg...) do {                                          \
1286         if (drm_debug & DRM_UT_DRIVER) {                                       \
1287                 NV_PRINTK(KERN_DEBUG, d, "%s:%d - " fmt, __func__,             \
1288                           __LINE__, ##arg);                                    \
1289         }                                                                      \
1290 } while (0)
1291 #define NV_DEBUG_KMS(d, fmt, arg...) do {                                      \
1292         if (drm_debug & DRM_UT_KMS) {                                          \
1293                 NV_PRINTK(KERN_DEBUG, d, "%s:%d - " fmt, __func__,             \
1294                           __LINE__, ##arg);                                    \
1295         }                                                                      \
1296 } while (0)
1297 #else
1298 #define NV_DEBUG(d, fmt, arg...) do {                                          \
1299         if (drm_debug & DRM_UT_DRIVER)                                         \
1300                 NV_PRINTK(KERN_DEBUG, d, fmt, ##arg);                          \
1301 } while (0)
1302 #define NV_DEBUG_KMS(d, fmt, arg...) do {                                      \
1303         if (drm_debug & DRM_UT_KMS)                                            \
1304                 NV_PRINTK(KERN_DEBUG, d, fmt, ##arg);                          \
1305 } while (0)
1306 #endif
1307 #define NV_ERROR(d, fmt, arg...) NV_PRINTK(KERN_ERR, d, fmt, ##arg)
1308 #define NV_INFO(d, fmt, arg...) NV_PRINTK(KERN_INFO, d, fmt, ##arg)
1309 #define NV_TRACEWARN(d, fmt, arg...) NV_PRINTK(KERN_NOTICE, d, fmt, ##arg)
1310 #define NV_TRACE(d, fmt, arg...) NV_PRINTK(KERN_INFO, d, fmt, ##arg)
1311 #define NV_WARN(d, fmt, arg...) NV_PRINTK(KERN_WARNING, d, fmt, ##arg)
1312
1313 /* nouveau_reg_debug bitmask */
1314 enum {
1315         NOUVEAU_REG_DEBUG_MC             = 0x1,
1316         NOUVEAU_REG_DEBUG_VIDEO          = 0x2,
1317         NOUVEAU_REG_DEBUG_FB             = 0x4,
1318         NOUVEAU_REG_DEBUG_EXTDEV         = 0x8,
1319         NOUVEAU_REG_DEBUG_CRTC           = 0x10,
1320         NOUVEAU_REG_DEBUG_RAMDAC         = 0x20,
1321         NOUVEAU_REG_DEBUG_VGACRTC        = 0x40,
1322         NOUVEAU_REG_DEBUG_RMVIO          = 0x80,
1323         NOUVEAU_REG_DEBUG_VGAATTR        = 0x100,
1324         NOUVEAU_REG_DEBUG_EVO            = 0x200,
1325 };
1326
1327 #define NV_REG_DEBUG(type, dev, fmt, arg...) do { \
1328         if (nouveau_reg_debug & NOUVEAU_REG_DEBUG_##type) \
1329                 NV_PRINTK(KERN_DEBUG, dev, "%s: " fmt, __func__, ##arg); \
1330 } while (0)
1331
1332 static inline bool
1333 nv_two_heads(struct drm_device *dev)
1334 {
1335         struct drm_nouveau_private *dev_priv = dev->dev_private;
1336         const int impl = dev->pci_device & 0x0ff0;
1337
1338         if (dev_priv->card_type >= NV_10 && impl != 0x0100 &&
1339             impl != 0x0150 && impl != 0x01a0 && impl != 0x0200)
1340                 return true;
1341
1342         return false;
1343 }
1344
1345 static inline bool
1346 nv_gf4_disp_arch(struct drm_device *dev)
1347 {
1348         return nv_two_heads(dev) && (dev->pci_device & 0x0ff0) != 0x0110;
1349 }
1350
1351 static inline bool
1352 nv_two_reg_pll(struct drm_device *dev)
1353 {
1354         struct drm_nouveau_private *dev_priv = dev->dev_private;
1355         const int impl = dev->pci_device & 0x0ff0;
1356
1357         if (impl == 0x0310 || impl == 0x0340 || dev_priv->card_type >= NV_40)
1358                 return true;
1359         return false;
1360 }
1361
1362 static inline bool
1363 nv_match_device(struct drm_device *dev, unsigned device,
1364                 unsigned sub_vendor, unsigned sub_device)
1365 {
1366         return dev->pdev->device == device &&
1367                 dev->pdev->subsystem_vendor == sub_vendor &&
1368                 dev->pdev->subsystem_device == sub_device;
1369 }
1370
1371 #define NV_SW                                                        0x0000506e
1372 #define NV_SW_DMA_SEMAPHORE                                          0x00000060
1373 #define NV_SW_SEMAPHORE_OFFSET                                       0x00000064
1374 #define NV_SW_SEMAPHORE_ACQUIRE                                      0x00000068
1375 #define NV_SW_SEMAPHORE_RELEASE                                      0x0000006c
1376 #define NV_SW_DMA_VBLSEM                                             0x0000018c
1377 #define NV_SW_VBLSEM_OFFSET                                          0x00000400
1378 #define NV_SW_VBLSEM_RELEASE_VALUE                                   0x00000404
1379 #define NV_SW_VBLSEM_RELEASE                                         0x00000408
1380
1381 #endif /* __NOUVEAU_DRV_H__ */