randr12: rename mon -> edid
[nouveau] / src / nv_type.h
1 #ifndef __NV_STRUCT_H__
2 #define __NV_STRUCT_H__
3
4 #include "colormapst.h"
5 #include "vgaHW.h"
6 #include "xf86Cursor.h"
7 #include "xf86int10.h"
8 #include "exa.h"
9 #ifdef XF86DRI
10 #define _XF86DRI_SERVER_
11 #include "xf86drm.h"
12 #include "dri.h"
13 #include <stdbool.h>
14 #include <stdint.h>
15 #include "nouveau_drm.h"
16 #include "xf86Crtc.h"
17 #else
18 #error "This driver requires a DRI-enabled X server"
19 #endif
20
21 #include "nv_pcicompat.h"
22
23 #include "nouveau_local.h" /* needed for NOUVEAU_EXA_PIXMAPS */
24
25 #include "nouveau_crtc.h"
26 #include "nouveau_connector.h"
27 #include "nouveau_output.h"
28
29 #include "drmmode_display.h"
30
31 #define NV_ARCH_03  0x03
32 #define NV_ARCH_04  0x04
33 #define NV_ARCH_10  0x10
34 #define NV_ARCH_20  0x20
35 #define NV_ARCH_30  0x30
36 #define NV_ARCH_40  0x40
37 #define NV_ARCH_50  0x50
38
39 #define CHIPSET_NV03     0x0010
40 #define CHIPSET_NV04     0x0020
41 #define CHIPSET_NV10     0x0100
42 #define CHIPSET_NV11     0x0110
43 #define CHIPSET_NV15     0x0150
44 #define CHIPSET_NV17     0x0170
45 #define CHIPSET_NV18     0x0180
46 #define CHIPSET_NFORCE   0x01A0
47 #define CHIPSET_NFORCE2  0x01F0
48 #define CHIPSET_NV20     0x0200
49 #define CHIPSET_NV25     0x0250
50 #define CHIPSET_NV28     0x0280
51 #define CHIPSET_NV30     0x0300
52 #define CHIPSET_NV31     0x0310
53 #define CHIPSET_NV34     0x0320
54 #define CHIPSET_NV35     0x0330
55 #define CHIPSET_NV36     0x0340
56 #define CHIPSET_NV40     0x0040
57 #define CHIPSET_NV41     0x00C0
58 #define CHIPSET_NV43     0x0140
59 #define CHIPSET_NV44     0x0160
60 #define CHIPSET_NV44A    0x0220
61 #define CHIPSET_NV45     0x0210
62 #define CHIPSET_NV50     0x0190
63 #define CHIPSET_NV84     0x0400
64 #define CHIPSET_MISC_BRIDGED  0x00F0
65 #define CHIPSET_G70      0x0090
66 #define CHIPSET_G71      0x0290
67 #define CHIPSET_G72      0x01D0
68 #define CHIPSET_G73      0x0390
69 // integrated GeForces (6100, 6150)
70 #define CHIPSET_C51      0x0240
71 // variant of C51, seems based on a G70 design
72 #define CHIPSET_C512     0x03D0
73 #define CHIPSET_G73_BRIDGED 0x02E0
74
75
76 #define BITMASK(t,b) (((unsigned)(1U << (((t)-(b)+1)))-1)  << (b))
77 #define MASKEXPAND(mask) BITMASK(1?mask,0?mask)
78 #define SetBF(mask,value) ((value) << (0?mask))
79 #define GetBF(var,mask) (((unsigned)((var) & MASKEXPAND(mask))) >> (0?mask) )
80 #define SetBitField(value,from,to) SetBF(to, GetBF(value,from))
81 #define SetBit(n) (1<<(n))
82 #define Set8Bits(value) ((value)&0xff)
83
84 #define MAX_NUM_DCB_ENTRIES 16
85
86 #define LOC_ON_CHIP 0
87
88 struct dcb_entry {
89         int index;
90         uint8_t type;
91         uint8_t i2c_index;
92         uint8_t heads;
93         uint8_t bus;
94         uint8_t location;
95         uint8_t or;
96         bool duallink_possible;
97         union {
98                 struct {
99                         bool use_straps_for_mode;
100                         bool use_power_scripts;
101                 } lvdsconf;
102         };
103 };
104
105 typedef enum
106 {/* matches DCB types */
107         OUTPUT_NONE = 4,
108         OUTPUT_ANALOG = 0,
109         OUTPUT_TMDS = 2,
110         OUTPUT_LVDS = 3,
111         OUTPUT_TV = 1,
112         OUTPUT_ANY = 5,
113 } NVOutputType;
114
115 /* NV50 */
116 typedef enum Head {
117         HEAD0 = 0,
118         HEAD1
119 } Head;
120
121 /* NV50 */
122 typedef enum ORNum {
123         DAC0 = 0,
124         DAC1 = 1,
125         DAC2 = 2,
126         SOR0 = 0,
127         SOR1 = 1
128 } ORNum;
129
130 enum scaling_modes {
131         SCALE_PANEL,
132         SCALE_FULLSCREEN,
133         SCALE_ASPECT,
134         SCALE_NOSCALE,
135         SCALE_INVALID
136 };
137
138 typedef struct _nv_crtc_reg 
139 {
140         unsigned char MiscOutReg;     /* */
141         uint8_t CRTC[0xff];
142         uint8_t CR58[0x10];
143         uint8_t Sequencer[5];
144         uint8_t Graphics[9];
145         uint8_t Attribute[21];
146         unsigned char DAC[768];       /* Internal Colorlookuptable */
147         uint32_t cursorConfig;
148         uint32_t crtcOwner;
149         uint32_t gpio;
150         uint32_t gpio_ext;
151         uint32_t unk830;
152         uint32_t unk834;
153         uint32_t unk850;
154         uint32_t head;
155         uint32_t config;
156         uint32_t fb_start;
157
158         /* These are former output regs, but are believed to be crtc related */
159         uint32_t general;
160         uint32_t unk_630;
161         uint32_t debug_0;
162         uint32_t debug_1;
163         uint32_t debug_2;
164         uint32_t unk_a20;
165         uint32_t unk_a24;
166         uint32_t unk_a34;
167         uint32_t dither_regs[6];
168         uint32_t fp_horiz_regs[7];
169         uint32_t fp_vert_regs[7];
170         uint32_t nv10_cursync;
171         uint32_t fp_control;
172         uint32_t dither;
173         uint32_t vpll_a;
174         uint32_t vpll_b;
175 } NVCrtcRegRec, *NVCrtcRegPtr;
176
177 typedef struct _nv_output_reg
178 {
179         uint32_t output;
180         int head;
181 } NVOutputRegRec, *NVOutputRegPtr;
182
183 typedef struct _riva_hw_state
184 {
185         uint32_t bpp;
186         uint32_t width;
187         uint32_t height;
188         uint32_t interlace;
189         uint32_t repaint0;
190         uint32_t repaint1;
191         uint32_t screen;
192         uint32_t scale;
193         uint32_t dither;
194         uint32_t extra;
195         uint32_t fifo;
196         uint32_t pixel;
197         uint32_t horiz;
198         uint32_t arbitration0;
199         uint32_t arbitration1;
200         uint32_t pll;
201         uint32_t pllB;
202         uint32_t vpll;
203         uint32_t vpll2;
204         uint32_t vpllB;
205         uint32_t vpll2B;
206         uint32_t pllsel;
207         uint32_t sel_clk;
208         uint32_t reg580;
209         uint32_t general;
210         uint32_t crtcOwner;
211         uint32_t head;
212         uint32_t head2;
213         uint32_t cursorConfig;
214         uint32_t cursor0;
215         uint32_t cursor1;
216         uint32_t cursor2;
217         uint32_t timingH;
218         uint32_t timingV;
219         uint32_t displayV;
220         uint32_t crtcSync;
221
222         NVCrtcRegRec crtc_reg[2];
223 } RIVA_HW_STATE, *NVRegPtr;
224
225 struct nouveau_crtc {
226         int head;
227         uint8_t last_dpms;
228 #if NOUVEAU_EXA_PIXMAPS
229         struct nouveau_bo *shadow;
230 #else
231         ExaOffscreenArea *shadow;
232 #endif /* NOUVEAU_EXA_PIXMAPS */
233         int fp_users;
234 };
235
236 typedef enum {
237         OUTPUT_A = (1 << 0),
238         OUTPUT_B = (1 << 1),
239         OUTPUT_C = (1 << 2)
240 } ValidOutputResource;
241
242 struct nouveau_encoder {
243         uint8_t last_dpms;
244         struct dcb_entry *dcb;
245         DisplayModePtr native_mode;
246         uint8_t scaling_mode;
247         bool dithering;
248         NVOutputRegRec restore;
249 };
250
251 struct nouveau_connector {
252         xf86MonPtr edid;
253         I2CBusPtr pDDCBus;
254         uint16_t possible_encoders;
255         struct nouveau_encoder *nv_encoder;
256 };
257
258 #define to_nouveau_connector(x) ((struct nouveau_connector *)(x)->driver_private)
259 #define to_nouveau_crtc(x) ((struct nouveau_crtc *)(x)->driver_private)
260 #define to_nouveau_encoder(x) ((struct nouveau_connector *)(x)->driver_private)->nv_encoder
261
262 /* changing these requires matching changes to reg tables in nv_get_clock */
263 #define MAX_PLL_TYPES   4
264 enum pll_types {
265         NVPLL,
266         MPLL,
267         VPLL1,
268         VPLL2
269 };
270
271 struct pll_lims {
272         struct {
273                 int minfreq;
274                 int maxfreq;
275                 int min_inputfreq;
276                 int 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 max_log2p_bias;
286         uint8_t log2p_bias;
287         int refclk;
288 };
289
290 typedef struct {
291         uint8_t *data;
292         unsigned int length;
293         bool execute;
294
295         uint8_t major_version, chip_version;
296         uint8_t feature_byte;
297
298         uint32_t fmaxvco, fminvco;
299
300         uint32_t dactestval;
301
302         uint16_t init_script_tbls_ptr;
303         uint16_t extra_init_script_tbl_ptr;
304         uint16_t macro_index_tbl_ptr;
305         uint16_t macro_tbl_ptr;
306         uint16_t condition_tbl_ptr;
307         uint16_t io_condition_tbl_ptr;
308         uint16_t io_flag_condition_tbl_ptr;
309         uint16_t init_function_tbl_ptr;
310
311         uint16_t pll_limit_tbl_ptr;
312         uint16_t ram_restrict_tbl_ptr;
313
314         uint8_t digital_min_front_porch;
315
316         struct {
317                 DisplayModePtr native_mode;
318                 uint8_t *edid;
319                 uint16_t lvdsmanufacturerpointer;
320                 uint16_t fpxlatemanufacturertableptr;
321                 uint16_t xlated_entry;
322                 bool power_off_for_reset;
323                 bool reset_after_pclk_change;
324                 bool dual_link;
325                 bool link_c_increment;
326                 bool if_is_24bit;
327                 bool BITbit1;
328                 int duallink_transition_clk;
329                 /* lower nibble stores PEXTDEV_BOOT_0 strap
330                  * upper nibble stores xlated display strap */
331                 uint8_t strapping;
332         } fp;
333
334         struct {
335                 uint16_t output0_script_ptr;
336                 uint16_t output1_script_ptr;
337         } tmds;
338
339         struct {
340                 uint16_t mem_init_tbl_ptr;
341                 uint16_t sdr_seq_tbl_ptr;
342                 uint16_t ddr_seq_tbl_ptr;
343
344                 struct {
345                         uint8_t crt, tv, panel;
346                 } i2c_indices;
347         } legacy;
348 } bios_t;
349
350 enum LVDS_script {
351         /* Order *does* matter here */
352         LVDS_INIT = 1,
353         LVDS_RESET,
354         LVDS_BACKLIGHT_ON,
355         LVDS_BACKLIGHT_OFF,
356         LVDS_PANEL_ON,
357         LVDS_PANEL_OFF
358 };
359
360 typedef struct _NVRec *NVPtr;
361 typedef struct _NVRec {
362     RIVA_HW_STATE       SavedReg;
363     RIVA_HW_STATE       ModeReg;
364     uint32_t saved_vga_font[4][16384];
365     uint32_t              Architecture;
366     EntityInfoPtr       pEnt;
367 #ifndef XSERVER_LIBPCIACCESS
368         pciVideoPtr     PciInfo;
369         PCITAG          PciTag;
370 #else
371         struct pci_device *PciInfo;
372 #endif /* XSERVER_LIBPCIACCESS */
373     int                 Chipset;
374     int                 NVArch;
375     Bool                Primary;
376     CARD32              IOAddress;
377
378     /* VRAM physical address */
379     unsigned long       VRAMPhysical;
380     /* Size of VRAM BAR */
381     unsigned long       VRAMPhysicalSize;
382     /* Accesible VRAM size (by the GPU) */
383     unsigned long       VRAMSize;
384     /* Accessible AGP size */
385     unsigned long       AGPSize;
386
387     /* Various pinned memory regions */
388     struct nouveau_bo * FB;
389     //struct nouveau_bo * FB_old; /* for KMS */
390     struct nouveau_bo * shadow[2]; /* for easy acces by exa */
391     struct nouveau_bo * Cursor;
392     struct nouveau_bo * Cursor2;
393     struct nouveau_bo * CLUT0;  /* NV50 only */
394     struct nouveau_bo * CLUT1;  /* NV50 only */
395     struct nouveau_bo * GART;
396
397     bios_t              VBIOS;
398     Bool                NoAccel;
399     Bool                HWCursor;
400     Bool                FpScale;
401     Bool                ShadowFB;
402     unsigned char *     ShadowPtr;
403     int                 ShadowPitch;
404     CARD32              MinVClockFreqKHz;
405     CARD32              MaxVClockFreqKHz;
406     CARD32              CrystalFreqKHz;
407     CARD32              RamAmountKBytes;
408
409     volatile CARD32 *REGS;
410     volatile CARD32 *FB_BAR;
411     volatile CARD32 *PGRAPH;
412     volatile CARD32 *PRAMIN;
413     volatile CARD32 *CURSOR;
414     volatile CARD8 *PCIO0;
415     volatile CARD8 *PCIO1;
416     volatile CARD8 *PVIO0;
417     volatile CARD8 *PVIO1;
418     volatile CARD8 *PDIO0;
419     volatile CARD8 *PDIO1;
420
421     unsigned int SaveGeneration;
422     uint8_t cur_head;
423     ExaDriverPtr        EXADriverPtr;
424     xf86CursorInfoPtr   CursorInfoRec;
425     ScreenBlockHandlerProcPtr BlockHandler;
426     CloseScreenProcPtr  CloseScreen;
427     /* Cursor */
428     CARD32              curFg, curBg;
429     CARD32              curImage[256];
430     /* I2C / DDC */
431     xf86Int10InfoPtr    pInt10;
432     unsigned            Int10Mode;
433     I2CBusPtr           I2C;
434   void          (*VideoTimerCallback)(ScrnInfoPtr, Time);
435     XF86VideoAdaptorPtr overlayAdaptor;
436     XF86VideoAdaptorPtr blitAdaptor;
437     XF86VideoAdaptorPtr textureAdaptor[2];
438     int                 videoKey;
439     int                 FlatPanel;
440     Bool                FPDither;
441     int                 Mobile;
442     Bool                Television;
443         int         vtOWNER;
444         Bool            crtc_active[2];
445     OptionInfoPtr       Options;
446     Bool                alphaCursor;
447     unsigned char       DDCBase;
448     Bool                twoHeads;
449     Bool                twoStagePLL;
450     Bool                fpScaler;
451     int                 fpWidth;
452     int                 fpHeight;
453     CARD32              fpSyncs;
454     Bool                usePanelTweak;
455     int                 PanelTweak;
456     Bool                LVDS;
457
458     Bool                LockedUp;
459
460     CARD32              currentRop;
461
462     Bool                WaitVSyncPossible;
463     Bool                BlendingPossible;
464     DRIInfoPtr          pDRIInfo;
465     drmVersionPtr       pLibDRMVersion;
466     drmVersionPtr       pKernelDRMVersion;
467
468         Bool randr12_enable;
469         Bool kms_enable;
470
471         I2CBusPtr           pI2CBus[MAX_NUM_DCB_ENTRIES];
472         struct nouveau_encoder *encoders;
473
474 #ifdef XF86DRM_MODE
475         void *drmmode; /* for KMS */
476 #endif
477
478         struct {
479                 int entries;
480                 struct dcb_entry entry[MAX_NUM_DCB_ENTRIES];
481                 unsigned char i2c_read[MAX_NUM_DCB_ENTRIES];
482                 unsigned char i2c_write[MAX_NUM_DCB_ENTRIES];
483         } dcb_table;
484
485         nouveauCrtcPtr crtc[2];
486         nouveauOutputPtr output; /* this a linked list. */
487         /* Assume a connector can exist for each i2c bus. */
488         nouveauConnectorPtr connector[MAX_NUM_DCB_ENTRIES];
489
490         struct {
491                 ORNum dac;
492                 ORNum sor;
493         } i2cMap[4];
494         struct {
495                 Bool  present;
496                 ORNum or;
497         } lvds;
498
499         /* DRM interface */
500         struct nouveau_device *dev;
501
502         /* GPU context */
503         struct nouveau_channel *chan;
504         struct nouveau_notifier *notify0;
505         struct nouveau_grobj *NvNull;
506         struct nouveau_grobj *NvContextSurfaces;
507         struct nouveau_grobj *NvContextBeta1;
508         struct nouveau_grobj *NvContextBeta4;
509         struct nouveau_grobj *NvImagePattern;
510         struct nouveau_grobj *NvRop;
511         struct nouveau_grobj *NvRectangle;
512         struct nouveau_grobj *NvImageBlit;
513         struct nouveau_grobj *NvScaledImage;
514         struct nouveau_grobj *NvClipRectangle;
515         struct nouveau_grobj *NvMemFormat;
516         struct nouveau_grobj *NvImageFromCpu;
517         struct nouveau_grobj *Nv2D;
518         struct nouveau_grobj *Nv3D;
519         struct nouveau_bo *tesla_scratch;
520 } NVRec;
521
522 #define NVPTR(p) ((NVPtr)((p)->driverPrivate))
523
524 #define NVShowHideCursor(pScrn, show) do {                                                      \
525         NVPtr pNv = NVPTR(pScrn);                                                                               \
526         nv_crtc_show_hide_cursor(pScrn, pNv->cur_head, show);                           \
527 } while(0)
528
529 #define NVLockUnlock(pScrn, lock) NVLockVgaCrtc(NVPTR(pScrn), NVPTR(pScrn)->cur_head, lock)
530
531 #define nvReadCurVGA(pNv, reg) NVReadVgaCrtc(pNv, pNv->cur_head, reg)
532 #define nvWriteCurVGA(pNv, reg, val) NVWriteVgaCrtc(pNv, pNv->cur_head, reg, val)
533
534 #define nvReadCurRAMDAC(pNv, reg) NVReadRAMDAC(pNv, pNv->cur_head, reg)
535 #define nvWriteCurRAMDAC(pNv, reg, val) NVWriteRAMDAC(pNv, pNv->cur_head, reg, val)
536
537 #define nvReadCurCRTC(pNv, reg) NVReadCRTC(pNv, pNv->cur_head, reg)
538 #define nvWriteCurCRTC(pNv, reg, val) NVWriteCRTC(pNv, pNv->cur_head, reg, val)
539
540 #define nvReadFB(pNv, reg) DDXMMIOW("nvReadFB: reg %08x val %08x\n", reg, (uint32_t)MMIO_IN32(pNv->REGS, reg))
541 #define nvWriteFB(pNv, reg, val) MMIO_OUT32(pNv->REGS, reg, DDXMMIOW("nvWriteFB: reg %08x val %08x\n", reg, val))
542
543 #define nvReadGRAPH(pNv, reg) DDXMMIOW("nvReadGRAPH: reg %08x val %08x\n", reg, (uint32_t)MMIO_IN32(pNv->REGS, reg))
544 #define nvWriteGRAPH(pNv, reg, val) MMIO_OUT32(pNv->REGS, reg, DDXMMIOW("nvWriteGRAPH: reg %08x val %08x\n", reg, val))
545
546 #define nvReadMC(pNv, reg) DDXMMIOW("nvReadMC: reg %08x val %08x\n", reg, (uint32_t)MMIO_IN32(pNv->REGS, reg))
547 #define nvWriteMC(pNv, reg, val) MMIO_OUT32(pNv->REGS, reg, DDXMMIOW("nvWriteMC: reg %08x val %08x\n", reg, val))
548
549 #define nvReadME(pNv, reg) DDXMMIOW("nvReadME: reg %08x val %08x\n", reg, (uint32_t)MMIO_IN32(pNv->REGS, reg))
550 #define nvWriteME(pNv, reg, val) MMIO_OUT32(pNv->REGS, reg, DDXMMIOW("nvWriteME: reg %08x val %08x\n", reg, val))
551
552 #define nvReadEXTDEV(pNv, reg) DDXMMIOW("nvReadEXTDEV: reg %08x val %08x\n", reg, (uint32_t)MMIO_IN32(pNv->REGS, reg))
553 #define nvWriteEXTDEV(pNv, reg, val) MMIO_OUT32(pNv->REGS, reg, DDXMMIOW("nvWriteEXTDEV: reg %08x val %08x\n", reg, val))
554
555 #define nvReadTIMER(pNv, reg) DDXMMIOW("nvReadTIMER: reg %08x val %08x\n", reg, (uint32_t)MMIO_IN32(pNv->REGS, reg))
556 #define nvWriteTIMER(pNv, reg, val) MMIO_OUT32(pNv->REGS, reg, DDXMMIOW("nvWriteTIMER: reg %08x val %08x\n", reg, val))
557
558 #define nvReadVIDEO(pNv, reg) DDXMMIOW("nvReadVIDEO: reg %08x val %08x\n", reg, (uint32_t)MMIO_IN32(pNv->REGS, reg))
559 #define nvWriteVIDEO(pNv, reg, val) MMIO_OUT32(pNv->REGS, reg, DDXMMIOW("nvWriteVIDEO: reg %08x val %08x\n", reg, val))
560
561 typedef struct _NVPortPrivRec {
562         short           brightness;
563         short           contrast;
564         short           saturation;
565         short           hue;
566         RegionRec       clip;
567         CARD32          colorKey;
568         Bool            autopaintColorKey;
569         Bool            doubleBuffer;
570         CARD32          videoStatus;
571         int             currentBuffer;
572         Time            videoTime;
573         int             overlayCRTC;
574         Bool            grabbedByV4L;
575         Bool            iturbt_709;
576         Bool            blitter;
577         Bool            texture;
578         Bool            bicubic; /* only for texture adapter */
579         Bool            SyncToVBlank;
580         struct nouveau_bo *video_mem;
581         int             pitch;
582         int             offset;
583         struct nouveau_bo *TT_mem_chunk[2];
584         int             currentHostBuffer;
585         struct nouveau_notifier *DMANotifier[2];
586 } NVPortPrivRec, *NVPortPrivPtr;
587
588 #define GET_OVERLAY_PRIVATE(pNv) \
589             (NVPortPrivPtr)((pNv)->overlayAdaptor->pPortPrivates[0].ptr)
590
591 #define GET_BLIT_PRIVATE(pNv) \
592             (NVPortPrivPtr)((pNv)->blitAdaptor->pPortPrivates[0].ptr)
593
594 #define OFF_TIMER       0x01
595 #define FREE_TIMER      0x02
596 #define CLIENT_VIDEO_ON 0x04
597 #define OFF_DELAY       500  /* milliseconds */
598 #define FREE_DELAY      5000
599
600 #define TIMER_MASK      (OFF_TIMER | FREE_TIMER)
601
602 #endif /* __NV_STRUCT_H__ */