randr12: Fix SEL_CLK assignment again (for non-mobile cards) + fix crosswiring.
[nouveau] / src / nv_type.h
1 /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nv/nv_type.h,v 1.51 2005/04/16 23:57:26 mvojkovi Exp $ */
2
3 #ifndef __NV_STRUCT_H__
4 #define __NV_STRUCT_H__
5
6 #include "colormapst.h"
7 #include "vgaHW.h"
8 #include "xf86Cursor.h"
9 #include "xf86int10.h"
10 #include "exa.h"
11 #ifdef XF86DRI
12 #define _XF86DRI_SERVER_
13 #include "xf86drm.h"
14 #include "dri.h"
15 #include <stdint.h>
16 #include "nouveau_drm.h"
17 #include "xf86Crtc.h"
18 #else
19 #error "This driver requires a DRI-enabled X server"
20 #endif
21
22 #include "nv50_type.h"
23 #include "nv_pcicompat.h"
24
25 #define NV_ARCH_03  0x03
26 #define NV_ARCH_04  0x04
27 #define NV_ARCH_10  0x10
28 #define NV_ARCH_20  0x20
29 #define NV_ARCH_30  0x30
30 #define NV_ARCH_40  0x40
31 #define NV_ARCH_50  0x50
32
33 #define CHIPSET_NV03     0x0010
34 #define CHIPSET_NV04     0x0020
35 #define CHIPSET_NV10     0x0100
36 #define CHIPSET_NV11     0x0110
37 #define CHIPSET_NV15     0x0150
38 #define CHIPSET_NV17     0x0170
39 #define CHIPSET_NV18     0x0180
40 #define CHIPSET_NFORCE   0x01A0
41 #define CHIPSET_NFORCE2  0x01F0
42 #define CHIPSET_NV20     0x0200
43 #define CHIPSET_NV25     0x0250
44 #define CHIPSET_NV28     0x0280
45 #define CHIPSET_NV30     0x0300
46 #define CHIPSET_NV31     0x0310
47 #define CHIPSET_NV34     0x0320
48 #define CHIPSET_NV35     0x0330
49 #define CHIPSET_NV36     0x0340
50 #define CHIPSET_NV40     0x0040
51 #define CHIPSET_NV41     0x00C0
52 #define CHIPSET_NV43     0x0140
53 #define CHIPSET_NV44     0x0160
54 #define CHIPSET_NV44A    0x0220
55 #define CHIPSET_NV45     0x0210
56 #define CHIPSET_NV50     0x0190
57 #define CHIPSET_NV84     0x0400
58 #define CHIPSET_MISC_BRIDGED  0x00F0
59 #define CHIPSET_G70      0x0090
60 #define CHIPSET_G71      0x0290
61 #define CHIPSET_G72      0x01D0
62 #define CHIPSET_G73      0x0390
63 // integrated GeForces (6100, 6150)
64 #define CHIPSET_C51      0x0240
65 // variant of C51, seems based on a G70 design
66 #define CHIPSET_C512     0x03D0
67 #define CHIPSET_G73_BRIDGED 0x02E0
68
69
70 #define BITMASK(t,b) (((unsigned)(1U << (((t)-(b)+1)))-1)  << (b))
71 #define MASKEXPAND(mask) BITMASK(1?mask,0?mask)
72 #define SetBF(mask,value) ((value) << (0?mask))
73 #define GetBF(var,mask) (((unsigned)((var) & MASKEXPAND(mask))) >> (0?mask) )
74 #define SetBitField(value,from,to) SetBF(to, GetBF(value,from))
75 #define SetBit(n) (1<<(n))
76 #define Set8Bits(value) ((value)&0xff)
77
78 #define MAX_NUM_DCB_ENTRIES 16
79
80 typedef enum /* matches DCB types */
81 {
82     OUTPUT_NONE = 4,
83     OUTPUT_ANALOG = 0,
84     OUTPUT_TMDS = 2,
85     OUTPUT_LVDS = 3,
86     OUTPUT_TV = 1,
87 } NVOutputType;
88
89 typedef struct {
90     int bitsPerPixel;
91     int depth;
92     int displayWidth;
93     rgb weight;
94     DisplayModePtr mode;
95 } NVFBLayout;
96
97 typedef struct _nv_crtc_reg 
98 {
99         unsigned char MiscOutReg;     /* */
100         CARD8 CRTC[90];
101         CARD8 CR58[0x10];
102         CARD8 Sequencer[5];
103         CARD8 Graphics[9];
104         CARD8 Attribute[21];
105         unsigned char DAC[768];       /* Internal Colorlookuptable */
106         CARD32 cursorConfig;
107         CARD32 crtcOwner;
108         CARD32 gpio;
109         CARD32 unk830;
110         CARD32 unk834;
111         CARD32 unk850;
112         CARD32 unk81c;
113         CARD32 head;
114         uint32_t config;
115
116         /* These are former output regs, but are believed to be crtc related */
117         CARD32 general;
118         CARD32 debug_0;
119         CARD32 debug_1;
120         CARD32 debug_2;
121         CARD32 unk_a20;
122         CARD32 unk_a24;
123         CARD32 unk_a34;
124         CARD32 fp_horiz_regs[7];
125         CARD32 fp_vert_regs[7];
126         CARD32 fp_hvalid_start;
127         CARD32 fp_hvalid_end;
128         CARD32 fp_vvalid_start;
129         CARD32 fp_vvalid_end;
130         CARD32 bpp;
131         CARD32 nv10_cursync;
132         CARD32 fp_control;
133         CARD32 crtcSync;
134         CARD32 dither;
135 } NVCrtcRegRec, *NVCrtcRegPtr;
136
137 typedef struct _nv_output_reg
138 {
139         CARD32 test_control;
140         CARD32 unk_670;
141         CARD32 unk_900;
142
143         CARD32 output;
144         CARD8 TMDS[0xFF];
145         CARD8 TMDS2[0xFF];
146 } NVOutputRegRec, *NVOutputRegPtr;
147
148 typedef struct _riva_hw_state
149 {
150     CARD32 bpp;
151     CARD32 width;
152     CARD32 height;
153     CARD32 interlace;
154     CARD32 repaint0;
155     CARD32 repaint1;
156     CARD32 screen;
157     CARD32 scale;
158     CARD32 dither;
159     CARD32 extra;
160     CARD32 fifo;
161     CARD32 pixel;
162     CARD32 horiz;
163     CARD32 arbitration0;
164     CARD32 arbitration1;
165     CARD32 pll;
166     CARD32 pllB;
167     CARD32 vpll;
168     CARD32 vpll2;
169     CARD32 vpllB;
170     CARD32 vpll2B;
171     CARD32 pllsel;
172         CARD32 sel_clk;
173         Bool crosswired;
174         Bool db1_ratio[2];
175         /* These vpll values are only for nv4x hardware */
176         uint32_t vpll1_a;
177         uint32_t vpll1_b;
178         uint32_t vpll2_a;
179         uint32_t vpll2_b;
180         uint32_t reg580;
181         uint32_t reg594;
182     CARD32 general;
183     CARD32 crtcOwner;
184     CARD32 head;
185     CARD32 head2;
186     CARD32 config;
187     CARD32 cursorConfig;
188     CARD32 cursor0;
189     CARD32 cursor1;
190     CARD32 cursor2;
191     CARD32 timingH;
192     CARD32 timingV;
193     CARD32 displayV;
194     CARD32 crtcSync;
195
196     NVCrtcRegRec crtc_reg[2];
197     NVOutputRegRec dac_reg[2];
198 } RIVA_HW_STATE, *NVRegPtr;
199
200 typedef struct _nv50_crtc_reg
201 {
202         
203 } NV50CrtcRegRec, *NV50CrtcRegPtr;
204
205 typedef struct _nv50_hw_state
206 {
207         NV50CrtcRegRec crtc_reg[2];
208 } NV50_HW_STATE, *NV50RegPtr;
209
210 typedef enum {
211         OUTPUT_0 = (1 << 0),
212         OUTPUT_1 = (1 << 1)
213 } ValidRamdac;
214
215 typedef struct _NVOutputPrivateRec {
216         uint8_t valid_ramdac;
217         uint8_t preferred_output;
218         uint8_t bus;
219         I2CBusPtr pDDCBus;
220         NVOutputType type;
221         int dcb_entry;
222         CARD32 fpSyncs;
223         CARD32 fpWidth;
224         CARD32 fpHeight;
225         DisplayModePtr native_mode;
226         Bool fpdither;
227         uint8_t scaling_mode;
228 } NVOutputPrivateRec, *NVOutputPrivatePtr;
229
230 typedef struct _MiscStartupInfo {
231         CARD8 crtc_0_reg_52;
232         CARD32 ramdac_0_reg_580;
233         CARD32 ramdac_0_pllsel;
234         CARD32 reg_c040;
235         CARD32 sel_clk;
236 } MiscStartupInfo;
237
238 typedef enum {
239         OUTPUT_0_SLAVED = (1 << 0),
240         OUTPUT_1_SLAVED = (1 << 1),
241         OUTPUT_0_LVDS = (1 << 2),
242         OUTPUT_1_LVDS = (1 << 3),
243         OUTPUT_0_CROSSWIRED_TMDS = (1 << 4),
244         OUTPUT_1_CROSSWIRED_TMDS = (1 << 5)
245 } OutputInfo;
246
247 struct dcb_entry {
248         uint8_t type;
249         uint8_t i2c_index;
250         uint8_t heads;
251         uint8_t bus;
252         uint8_t location;
253         uint8_t or;
254         Bool duallink_possible;
255         union {
256                 struct {
257                         Bool use_straps_for_mode;
258                         Bool use_power_scripts;
259                 } lvdsconf;
260         };
261 };
262
263 typedef struct {
264         uint8_t *data;
265         unsigned int length;
266         Bool execute;
267
268         uint8_t major_version;
269
270         uint16_t init_script_tbls_ptr;
271         uint16_t macro_index_tbl_ptr;
272         uint16_t macro_tbl_ptr;
273         uint16_t condition_tbl_ptr;
274         uint16_t io_condition_tbl_ptr;
275         uint16_t io_flag_condition_tbl_ptr;
276         uint16_t init_function_tbl_ptr;
277
278         uint16_t ram_restrict_tbl_ptr;
279
280         struct {
281                 DisplayModePtr native_mode;
282                 uint16_t script_table;
283                 Bool power_off_for_reset;
284                 Bool reset_after_pclk_change;
285                 Bool dual_link;
286                 Bool if_is_24bit;
287                 uint16_t off_on_delay;
288         } fp;
289
290         struct {
291                 uint16_t output0_script_ptr;
292                 uint16_t output1_script_ptr;
293         } tmds;
294 } bios_t;
295
296 enum LVDS_script {
297         /* Order *does* matter here */
298         LVDS_INIT = 1,
299         LVDS_RESET,
300         LVDS_BACKLIGHT_ON,
301         LVDS_BACKLIGHT_OFF,
302         LVDS_PANEL_ON,
303         LVDS_PANEL_OFF
304 };
305
306 #define NVOutputPrivate(o) ((NVOutputPrivatePtr (o)->driver_private)
307
308 typedef struct _NVRec *NVPtr;
309 typedef struct _NVRec {
310     RIVA_HW_STATE       SavedReg;
311     RIVA_HW_STATE       ModeReg;
312     RIVA_HW_STATE       *CurrentState;
313         NV50_HW_STATE   NV50SavedReg;
314         NV50_HW_STATE   NV50ModeReg;
315     CARD32              Architecture;
316     EntityInfoPtr       pEnt;
317 #ifndef XSERVER_LIBPCIACCESS
318         pciVideoPtr     PciInfo;
319         PCITAG          PciTag;
320 #else
321         struct pci_device *PciInfo;
322 #endif /* XSERVER_LIBPCIACCESS */
323     int                 Chipset;
324     int                 NVArch;
325     Bool                Primary;
326     CARD32              IOAddress;
327     Bool cursorOn;
328
329     /* VRAM physical address */
330     unsigned long       VRAMPhysical;
331     /* Size of VRAM BAR */
332     unsigned long       VRAMPhysicalSize;
333     /* Accesible VRAM size (by the GPU) */
334     unsigned long       VRAMSize;
335     /* Accessible AGP size */
336     unsigned long       AGPSize;
337
338     /* Various pinned memory regions */
339     struct nouveau_bo * FB;
340     struct nouveau_bo * Cursor;
341     struct nouveau_bo * CLUT;   /* NV50 only */
342     struct nouveau_bo * GART;
343
344     bios_t              VBIOS;
345     Bool                NoAccel;
346     Bool                HWCursor;
347     Bool                FpScale;
348     Bool                ShadowFB;
349     unsigned char *     ShadowPtr;
350     int                 ShadowPitch;
351     CARD32              MinVClockFreqKHz;
352     CARD32              MaxVClockFreqKHz;
353     CARD32              CrystalFreqKHz;
354     CARD32              RamAmountKBytes;
355
356     volatile CARD32 *REGS;
357     volatile CARD32 *PCRTC0;
358     volatile CARD32 *PCRTC1;
359
360         volatile CARD32 *NV50_PCRTC;
361
362     volatile CARD32 *PRAMDAC0;
363     volatile CARD32 *PRAMDAC1;
364     volatile CARD32 *PFB;
365     volatile CARD32 *PFIFO;
366     volatile CARD32 *PGRAPH;
367     volatile CARD32 *PEXTDEV;
368     volatile CARD32 *PTIMER;
369     volatile CARD32 *PVIDEO;
370     volatile CARD32 *PMC;
371     volatile CARD32 *PRAMIN;
372     volatile CARD32 *CURSOR;
373     volatile CARD8 *PCIO0;
374     volatile CARD8 *PCIO1;
375     volatile CARD8 *PVIO0;
376     volatile CARD8 *PVIO1;
377     volatile CARD8 *PDIO0;
378     volatile CARD8 *PDIO1;
379     volatile CARD8 *PROM;
380
381
382     volatile CARD32 *RAMHT;
383     CARD32 pramin_free;
384
385     unsigned int SaveGeneration;
386     uint8_t cur_head;
387     ExaDriverPtr        EXADriverPtr;
388     xf86CursorInfoPtr   CursorInfoRec;
389     void                (*PointerMoved)(int index, int x, int y);
390     ScreenBlockHandlerProcPtr BlockHandler;
391     CloseScreenProcPtr  CloseScreen;
392     int                 Rotate;
393     NVFBLayout          CurrentLayout;
394     /* Cursor */
395     CARD32              curFg, curBg;
396     CARD32              curImage[256];
397     /* I2C / DDC */
398     int ddc2;
399     xf86Int10InfoPtr    pInt10;
400     I2CBusPtr           I2C;
401   void          (*VideoTimerCallback)(ScrnInfoPtr, Time);
402     XF86VideoAdaptorPtr overlayAdaptor;
403     XF86VideoAdaptorPtr blitAdaptor;
404     int                 videoKey;
405     int                 FlatPanel;
406     Bool                FPDither;
407     int                 Mobile;
408     Bool                Television;
409         int         vtOWNER;
410         Bool            crtc_active[2];
411         Bool            ramdac_active[2];
412     OptionInfoPtr       Options;
413     Bool                alphaCursor;
414     unsigned char       DDCBase;
415     Bool                twoHeads;
416     Bool                twoStagePLL;
417     Bool                fpScaler;
418     int                 fpWidth;
419     int                 fpHeight;
420     CARD32              fpSyncs;
421     Bool                usePanelTweak;
422     int                 PanelTweak;
423     Bool                LVDS;
424
425     Bool                LockedUp;
426
427     CARD32              currentRop;
428
429     Bool                WaitVSyncPossible;
430     Bool                BlendingPossible;
431     Bool                RandRRotation;
432     DRIInfoPtr          pDRIInfo;
433     drmVersionPtr       pLibDRMVersion;
434     drmVersionPtr       pKernelDRMVersion;
435
436     Bool randr12_enable;
437     CreateScreenResourcesProcPtr    CreateScreenResources;
438
439     I2CBusPtr           pI2CBus[MAX_NUM_DCB_ENTRIES];
440
441         int vga_count;
442         int dvi_d_count;
443         int dvi_a_count;
444         int lvds_count;
445
446         struct {
447                 int entries;
448                 struct dcb_entry entry[MAX_NUM_DCB_ENTRIES];
449                 unsigned char i2c_read[MAX_NUM_DCB_ENTRIES];
450                 unsigned char i2c_write[MAX_NUM_DCB_ENTRIES];
451         } dcb_table;
452
453         uint32_t output_info;
454         MiscStartupInfo misc_info;
455
456         struct {
457                 ORNum dac;
458                 ORNum sor;
459         } i2cMap[4];
460         struct {
461                 Bool  present;
462                 ORNum or;
463         } lvds;
464
465         /* DRM interface */
466         struct nouveau_device *dev;
467
468         /* GPU context */
469         struct nouveau_channel *chan;
470         struct nouveau_notifier *notify0;
471         struct nouveau_grobj *NvNull;
472         struct nouveau_grobj *NvContextSurfaces;
473         struct nouveau_grobj *NvContextBeta1;
474         struct nouveau_grobj *NvContextBeta4;
475         struct nouveau_grobj *NvImagePattern;
476         struct nouveau_grobj *NvRop;
477         struct nouveau_grobj *NvRectangle;
478         struct nouveau_grobj *NvImageBlit;
479         struct nouveau_grobj *NvScaledImage;
480         struct nouveau_grobj *NvClipRectangle;
481         struct nouveau_grobj *NvMemFormat;
482         struct nouveau_grobj *NvImageFromCpu;
483         struct nouveau_grobj *Nv2D;
484         struct nouveau_grobj *Nv3D;
485
486 } NVRec;
487
488 typedef struct _NVCrtcPrivateRec {
489         int crtc;
490         int head;
491         Bool paletteEnabled;
492         Bool deactivate;
493 } NVCrtcPrivateRec, *NVCrtcPrivatePtr;
494
495 typedef struct _NV50CrtcPrivRec {
496         int head;
497         int pclk; /* Target pixel clock in kHz */
498         Bool cursorVisible;
499         Bool skipModeFixup;
500         Bool dither;
501 } NV50CrtcPrivRec, *NV50CrtcPrivPtr;
502
503 #define NVCrtcPrivate(c) ((NVCrtcPrivatePtr)(c)->driver_private)
504
505 #define NVPTR(p) ((NVPtr)((p)->driverPrivate))
506
507 #define nvReadRAMDAC0(pNv, reg) nvReadRAMDAC(pNv, 0, reg)
508 #define nvWriteRAMDAC0(pNv, reg, val) nvWriteRAMDAC(pNv, 0, reg, val)
509
510 #define nvReadCurRAMDAC(pNv, reg) nvReadRAMDAC(pNv, pNv->cur_head, reg)
511 #define nvWriteCurRAMDAC(pNv, reg, val) nvWriteRAMDAC(pNv, pNv->cur_head, reg, val)
512
513 #define nvReadCRTC0(pNv, reg) nvReadCRTC(pNv, 0, reg)
514 #define nvWriteCRTC0(pNv, reg, val) nvWriteCRTC(pNv, 0, reg, val)
515
516 #define nvReadCurCRTC(pNv, reg) nvReadCRTC(pNv, pNv->cur_head, reg)
517 #define nvWriteCurCRTC(pNv, reg, val) nvWriteCRTC(pNv, pNv->cur_head, reg, val)
518
519 #define nvReadFB(pNv, fb_reg) MMIO_IN32(pNv->PFB, fb_reg)
520 #define nvWriteFB(pNv, fb_reg, val) MMIO_OUT32(pNv->PFB, fb_reg, val)
521
522 #define nvReadGRAPH(pNv, reg) MMIO_IN32(pNv->PGRAPH, reg)
523 #define nvWriteGRAPH(pNv, reg, val) MMIO_OUT32(pNv->PGRAPH, reg, val)
524
525 #define nvReadMC(pNv, reg) MMIO_IN32(pNv->PMC, reg)
526 #define nvWriteMC(pNv, reg, val) MMIO_OUT32(pNv->PMC, reg, val)
527
528 #define nvReadEXTDEV(pNv, reg) MMIO_IN32(pNv->PEXTDEV, reg)
529 #define nvWriteEXTDEV(pNv, reg, val) MMIO_OUT32(pNv->PEXTDEV, reg, val)
530
531 #define nvReadTIMER(pNv, reg) MMIO_IN32(pNv->PTIMER, reg)
532 #define nvWriteTIMER(pNv, reg, val) MMIO_OUT32(pNv->PTIMER, reg, val)
533
534 #define nvReadVIDEO(pNv, reg) MMIO_IN32(pNv->PVIDEO, reg)
535 #define nvWriteVIDEO(pNv, reg, val) MMIO_OUT32(pNv->PVIDEO, reg, val)
536
537 #endif /* __NV_STRUCT_H__ */