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