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