via_driver.h revision 44802259
1/*
2 * Copyright 2004-2005 The Unichrome Project  [unichrome.sf.net]
3 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
4 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sub license,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
26#ifndef _VIA_DRIVER_H_
27#define _VIA_DRIVER_H_ 1
28
29//#define VIA_DEBUG_COMPOSITE 1
30#define HAVE_DEBUG 1
31
32#ifdef HAVE_DEBUG
33#define DEBUG(x) x
34#else
35#define DEBUG(x)
36#endif
37
38#include "vgaHW.h"
39#include "xf86.h"
40
41#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 6
42#include "xf86Resources.h"
43#endif
44
45#include "xf86Pci.h"
46#include "xf86_OSproc.h"
47#include "compiler.h"
48#include "xf86Cursor.h"
49#include "mipointer.h"
50#include "micmap.h"
51#include "fourcc.h"
52#include "fb.h"
53
54#include "xf86Crtc.h"
55#include "xf86RandR12.h"
56#include "xf86cmap.h"
57
58#ifdef HAVE_DRI
59#define _XF86DRI_SERVER_
60#include "xf86dri.h"
61#include "sarea.h"
62#include "dri.h"
63#include "drm_fourcc.h"
64#include "GL/glxint.h"
65#include "via_dri.h"
66#include "via_drmclient.h"
67#include "via_drm.h"
68#endif
69#include "exa.h"
70#include "via_memmgr.h"
71
72#include "via_regs.h"
73#include "via_kms.h"
74#include "via_ums.h"
75#include "via_dmabuffer.h"
76#include "via_3d.h"
77#include "via_xv.h"
78#include "via_xv_overlay.h"
79#include "via_eng_regs.h"
80
81#ifdef HAVE_PCIACCESS
82#include <pciaccess.h>
83#else
84#include "xf86PciInfo.h"
85#endif
86#include <errno.h>
87
88#include "via_vt1632.h"
89
90#include "compat-api.h"
91#define VIA_AGP_UPL_SIZE    (1024*128)
92#define VIA_DMA_DL_SIZE     (1024*128)
93#define VIA_SCRATCH_SIZE    (4*1024*1024)
94
95/*
96 * Pixmap sizes below which we don't try to do hw accel.
97 */
98
99#define VIA_MIN_COMPOSITE   400
100#define VIA_MIN_UPLOAD 4000
101#define VIA_MIN_TEX_UPLOAD 200
102#define VIA_MIN_DOWNLOAD 200
103
104#define AGP_PAGE_SIZE 4096
105#define AGP_PAGES 8192
106#define AGP_SIZE (AGP_PAGE_SIZE * AGP_PAGES)
107
108#define DRIVER_NAME     "openchrome"
109#define VIA_VERSION     ((VIA_MAJOR_VERSION << 24) | (VIA_MINOR_VERSION << 16) | VIA_PATCHLEVEL)
110
111#define VIA_VQ_SIZE     (256 * 1024)
112
113#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 6
114#define VIA_RES_SHARED RES_SHARED_VGA
115#define VIA_RES_UNDEF RES_UNDEFINED
116#else
117#define VIA_RES_SHARED NULL
118#define VIA_RES_UNDEF NULL
119#endif
120
121/* Video Engines */
122#define VIDEO_ENGINE_UNK    0   /* Unknown video engine */
123#define VIDEO_ENGINE_CLE    1   /* CLE First generation video engine */
124#define VIDEO_ENGINE_CME    2   /* CME Second generation video engine */
125
126static int gVIAEntityIndex = -1;
127
128typedef struct {
129    CARD8   SR08, SR0A, SR0F;
130
131    /*   extended Sequencer registers */
132    CARD8   SR10, SR11, SR12, SR13,SR14,SR15,SR16;
133    CARD8   SR17, SR18, SR19, SR1A,SR1B,SR1C,SR1D,SR1E;
134    CARD8   SR1F, SR20, SR21, SR22,SR23,SR24,SR25,SR26;
135    CARD8   SR27, SR28, SR29, SR2A,SR2B,SR2C,SR2D,SR2E;
136    CARD8   SR2F, SR30, SR31, SR32,SR33,SR34,SR40,SR41;
137    CARD8   SR42, SR43, SR44, SR45,SR46,SR47,SR48,SR49;
138    CARD8   SR4A, SR4B, SR4C, SR4D;
139
140    /*   extended CRTC registers */
141    CARD8   CR0C, CR0D;
142    CARD8   CR13, CR30, CR31, CR32, CR33, CR34, CR35, CR36;
143    CARD8   CR37, CR38, CR39, CR3A, CR40, CR41, CR42, CR43;
144    CARD8   CR44, CR45, CR46, CR47, CR48, CR49, CR4A;
145    CARD8   CR97, CR99, CR9B, CR9F, CRA0, CRA1, CRA2;
146    CARD8   CRTCRegs[68];
147/*    CARD8   LCDRegs[0x40];*/
148
149    /* TMDS/LVDS Control */
150    CARD8   CRD2;
151} VIARegRec, *VIARegPtr;
152
153/*
154 * variables that need to be shared among different screens.
155 */
156typedef struct {
157    Bool b3DRegsInitialized;
158} ViaSharedRec, *ViaSharedPtr;
159
160enum dri_type {
161	DRI_NONE,
162	DRI_1,
163	DRI_2
164};
165
166#ifdef HAVE_DRI
167
168#define VIA_XVMC_MAX_BUFFERS 2
169#define VIA_XVMC_MAX_CONTEXTS 4
170#define VIA_XVMC_MAX_SURFACES 20
171
172typedef struct {
173    struct buffer_object *memory_ref;
174    unsigned long offsets[VIA_XVMC_MAX_BUFFERS];
175} ViaXvMCSurfacePriv;
176
177typedef struct {
178    drm_context_t drmCtx;
179} ViaXvMCContextPriv;
180
181typedef struct {
182    XID contexts[VIA_XVMC_MAX_CONTEXTS];
183    XID surfaces[VIA_XVMC_MAX_SURFACES];
184    ViaXvMCSurfacePriv *sPrivs[VIA_XVMC_MAX_SURFACES];
185    ViaXvMCContextPriv *cPrivs[VIA_XVMC_MAX_CONTEXTS];
186    int nContexts,nSurfaces;
187    drm_handle_t mmioBase,fbBase,sAreaBase;
188    unsigned sAreaSize;
189    drmAddress sAreaAddr;
190    unsigned activePorts;
191}ViaXvMC, *ViaXvMCPtr;
192
193#endif
194
195typedef struct _twodContext {
196    CARD32 mode;
197    CARD32 cmd;
198    CARD32 fgColor;
199    CARD32 bgColor;
200    CARD32 pattern0;
201    CARD32 pattern1;
202    CARD32 patternAddr;
203    CARD32 keyControl;
204    unsigned srcOffset;
205    unsigned srcPitch;
206    unsigned Bpp;
207    unsigned bytesPPShift;
208    Bool clipping;
209    Bool dashed;
210    int clipX1;
211    int clipX2;
212    int clipY1;
213    int clipY2;
214} ViaTwodContext;
215
216typedef struct _VIA {
217    VIARegRec           SavedReg;
218    int                 Bpp, Bpl;
219
220    Bool                KMS;
221    Bool                FirstInit;
222    unsigned long       videoRambytes;
223    int                 FBFreeStart;
224    int                 FBFreeEnd;
225    int                 driSize;
226    int                 maxDriSize;
227    struct buffer_object *vq_bo;
228    int                 VQStart;
229    int                 VQEnd;
230
231    /* These are physical addresses. */
232    unsigned long       FrameBufferBase;
233    unsigned long       MmioBase;
234
235    /* These are linear addresses. */
236    unsigned char*      MapBase;
237    unsigned char*      MpegMapBase;
238    unsigned char*      BltBase;
239    unsigned char*      MapBaseDense;
240    unsigned char*      FBBase;
241    CARD8               MemClk;
242
243    /* Here are all the Options */
244    Bool                VQEnable;
245    Bool                NoAccel;
246    Bool                shadowFB;
247    Rotation            rotate;
248    int                 agpMem;
249
250	CreateScreenResourcesProcPtr CreateScreenResources;
251    CloseScreenProcPtr  CloseScreen;
252#ifdef HAVE_PCIACCESS
253    struct pci_device  *PciInfo;
254#else
255    pciVideoPtr         PciInfo;
256    PCITAG PciTag;
257#endif
258    int                 Chipset;
259    int                 ChipId;
260    int                 ChipRev;
261    int                 EntityIndex;
262
263    /* Support for shadowFB and rotation */
264    unsigned char*      ShadowPtr;
265
266    /* Support for EXA acceleration */
267    ViaTwodContext      td;
268    Via3DState          v3d;
269    Via3DState          *lastToUpload;
270    ViaCommandBuffer    cb;
271    int                 accelMarker;
272    struct buffer_object *exa_sync_bo;
273    struct buffer_object *exaMem;
274    CARD32              markerOffset;
275    void               *markerBuf;
276    CARD32              curMarker;
277    CARD32              lastMarkerRead;
278    Bool                agpDMA;
279    Bool                nPOT[VIA_NUM_TEXUNITS];
280    const unsigned     *HqvCmeRegs;
281    ExaDriverPtr        exaDriverPtr;
282    ExaOffscreenArea   *exa_scratch;
283    unsigned int        exa_scratch_next;
284    Bool                useEXA;
285    void               *maskP;
286    CARD32              maskFormat;
287    Bool                componentAlpha;
288    void               *srcP;
289    CARD32              srcFormat;
290    unsigned            scratchOffset;
291    int                 exaScratchSize;
292    char *              scratchAddr;
293    Bool                noComposite;
294    struct buffer_object *scratchBuffer;
295#ifdef HAVE_DRI
296    struct buffer_object *texAGPBuffer;
297    char *              dBounce;
298#endif
299
300    /* Rotation */
301    Bool    RandRRotation;
302
303    /* BIOS Info Ptr */
304    VIABIOSInfoPtr      pBIOSInfo;
305
306    /* OLPC XO-1.5 */
307    Bool                IsOLPCXO15;
308
309    /* I2C & DDC */
310    I2CBusPtr           pI2CBus1;
311    I2CBusPtr           pI2CBus2;
312    I2CBusPtr           pI2CBus3;
313
314    /* MHS */
315    Bool                IsSecondary;
316    Bool                HasSecondary;
317    Bool                SAMM;
318
319    drmmode_rec         drmmode;
320    enum dri_type       directRenderingType;
321#ifdef HAVE_DRI
322    Bool                XvMCEnabled;
323    DRIInfoPtr          pDRIInfo;
324    int                 numVisualConfigs;
325    __GLXvisualConfig*	pVisualConfigs;
326    VIAConfigPrivPtr	pVisualConfigsPriv;
327    drm_handle_t        agpHandle;
328    drm_handle_t        registerHandle;
329    drm_handle_t        frameBufferHandle;
330    unsigned long       agpAddr;
331    drmAddress          agpMappedAddr;
332    unsigned int        agpSize;
333    Bool                IsPCI;
334    ViaXvMC             xvmc;
335    int                 drmVerMajor;
336    int                 drmVerMinor;
337    int                 drmVerPL;
338    struct buffer_object *driOffScreenMem;
339    void *              driOffScreenSave;
340#endif
341    Bool                DRIIrqEnable;
342    Bool                agpEnable;
343    Bool                dma2d;
344    Bool                dmaXV;
345
346    /* Video */
347    int                 VideoEngine;
348    swovRec             swov;
349    CARD32              VideoStatus;
350    VIAHWDiff           HWDiff;
351    unsigned long       dwV1, dwV3;
352    unsigned long       dwFrameNum;
353
354    CARD32*             VidRegBuffer; /* Temporary buffer for video overlay registers. */
355    unsigned long       VidRegCursor; /* Write cursor for VidRegBuffer. */
356
357    unsigned long       old_dwUseExtendedFIFO;
358
359    ViaSharedPtr        sharedData;
360    Bool                useDmaBlit;
361
362    void                *displayMap;
363    CARD32              displayOffset;
364
365    CARD8               I2CDevices;	/* Option */
366
367#ifdef HAVE_DEBUG
368    Bool                disableXvBWCheck;
369    Bool                DumpVGAROM;
370    Bool                PrintVGARegs;
371    Bool                PrintTVRegs;
372    Bool                I2CScan;
373#endif /* HAVE_DEBUG */
374
375    video_via_regs*     VideoRegs;
376} VIARec, *VIAPtr;
377
378#define VIAPTR(p) ((VIAPtr)((p)->driverPrivate))
379
380typedef struct
381{
382    Bool IsDRIEnabled;
383
384    Bool HasSecondary;
385    Bool BypassSecondary;
386    /*These two registers are used to make sure the CRTC2 is
387      restored before CRTC_EXT, otherwise it could lead to blank screen.*/
388    Bool IsSecondaryRestored;
389    Bool RestorePrimary;
390
391    ScrnInfoPtr pSecondaryScrn;
392    ScrnInfoPtr pPrimaryScrn;
393} VIAEntRec, *VIAEntPtr;
394
395/* In via_exa.c. */
396Bool viaInitExa(ScreenPtr pScreen);
397Bool viaAccelSetMode(int bpp, ViaTwodContext * tdc);
398void viaAccelSync(ScrnInfoPtr);
399void viaExitAccel(ScreenPtr);
400void viaFinishInitAccel(ScreenPtr);
401Bool viaOrder(CARD32 val, CARD32 * shift);
402CARD32 viaBitExpandHelper(CARD32 pixel, CARD32 bits);
403Bool viaCheckUpload(ScrnInfoPtr pScrn, Via3DState * v3d);
404void viaPixelARGB8888(unsigned format, void *pixelP, CARD32 * argb8888);
405Bool viaExpandablePixel(int format);
406void viaAccelFillPixmap(ScrnInfoPtr, unsigned long, unsigned long,
407			int, int, int, int, int, unsigned long);
408void viaAccelTextureBlit(ScrnInfoPtr, unsigned long, unsigned, unsigned,
409			 unsigned, unsigned, unsigned, unsigned,
410			 unsigned long, unsigned, unsigned,
411			 unsigned, unsigned, int);
412#ifdef VIA_DEBUG_COMPOSITE
413void viaExaCompositePictDesc(PicturePtr pict, char *string, int n);
414void viaExaPrintCompositeInfo(char *info, CARD8 op, PicturePtr pSrc, PicturePtr pMask,
415                            PicturePtr pDst);
416#endif
417
418/* In via_exa_h2.c */
419Bool viaExaPrepareSolid_H2(PixmapPtr pPixmap, int alu, Pixel planeMask,
420                        Pixel fg);
421void viaExaSolid_H2(PixmapPtr pPixmap, int x1, int y1, int x2, int y2);
422void viaExaDoneSolidCopy_H2(PixmapPtr pPixmap);
423Bool viaExaPrepareCopy_H2(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap,
424                            int xdir, int ydir, int alu, Pixel planeMask);
425void viaExaCopy_H2(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX,
426                    int dstY, int width, int height);
427Bool viaExaCheckComposite_H2(int op, PicturePtr pSrcPicture,
428                            PicturePtr pMaskPicture, PicturePtr pDstPicture);
429Bool viaExaPrepareComposite_H2(int op, PicturePtr pSrcPicture,
430                            PicturePtr pMaskPicture, PicturePtr pDstPicture,
431                            PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst);
432void viaExaComposite_H2(PixmapPtr pDst, int srcX, int srcY,
433                        int maskX, int maskY, int dstX, int dstY,
434                        int width, int height);
435int viaAccelMarkSync_H2(ScreenPtr);
436
437/* In via_exa_h6.c */
438Bool viaExaPrepareSolid_H6(PixmapPtr pPixmap, int alu, Pixel planeMask,
439                        Pixel fg);
440void viaExaSolid_H6(PixmapPtr pPixmap, int x1, int y1, int x2, int y2);
441void viaExaDoneSolidCopy_H6(PixmapPtr pPixmap);
442Bool viaExaPrepareCopy_H6(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap,
443                            int xdir, int ydir, int alu, Pixel planeMask);
444void viaExaCopy_H6(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX,
445                    int dstY, int width, int height);
446Bool viaExaCheckComposite_H6(int op, PicturePtr pSrcPicture,
447                            PicturePtr pMaskPicture, PicturePtr pDstPicture);
448Bool viaExaPrepareComposite_H6(int op, PicturePtr pSrcPicture,
449                            PicturePtr pMaskPicture, PicturePtr pDstPicture,
450                            PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst);
451void viaExaComposite_H6(PixmapPtr pDst, int srcX, int srcY,
452                        int maskX, int maskY, int dstX, int dstY,
453                        int width, int height);
454int viaAccelMarkSync_H6(ScreenPtr);
455
456/* In via_xv.c */
457void viaInitVideo(ScreenPtr pScreen);
458void viaExitVideo(ScrnInfoPtr pScrn);
459void viaSaveVideo(ScrnInfoPtr pScrn);
460void viaRestoreVideo(ScrnInfoPtr pScrn);
461void viaSetColorSpace(VIAPtr pVia, int hue, int saturation, int brightness, int contrast,
462		      Bool reset);
463
464
465/* In via_xv.c */
466void viaInitVideo(ScreenPtr pScreen);
467void viaExitVideo(ScrnInfoPtr pScrn);
468void viaSaveVideo(ScrnInfoPtr pScrn);
469void viaRestoreVideo(ScrnInfoPtr pScrn);
470void viaSetColorSpace(VIAPtr pVia, int hue, int saturation, int brightness, int contrast,
471		      Bool reset);
472void VIAVidAdjustFrame(ScrnInfoPtr pScrn, int x, int y);
473
474/* In via_memcpy.c */
475typedef void (*vidCopyFunc)(unsigned char *, const unsigned char *,
476                            int, int, int, int);
477extern vidCopyFunc viaVidCopyInit( char *copyType, ScreenPtr pScreen );
478
479/* In via_xwmc.c */
480
481#ifdef HAVE_DRI
482/* Basic init and exit functions */
483void ViaInitXVMC(ScreenPtr pScreen);
484void ViaCleanupXVMC(ScrnInfoPtr pScrn, XF86VideoAdaptorPtr *XvAdaptors, int XvAdaptorCount);
485int viaXvMCInitXv(ScrnInfoPtr pScrn, XF86VideoAdaptorPtr XvAdapt);
486
487/* Returns the size of the fake Xv Image used as XvMC command buffer to the X server*/
488unsigned long viaXvMCPutImageSize(ScrnInfoPtr pScrn);
489#endif
490
491/* via_i2c.c */
492void ViaI2CInit(ScrnInfoPtr pScrn);
493
494#ifdef HAVE_DRI
495Bool VIADRI1ScreenInit(ScreenPtr pScreen);
496void VIADRICloseScreen(ScreenPtr pScreen);
497Bool VIADRIFinishScreenInit(ScreenPtr pScreen);
498void VIADRIRingBufferCleanup(ScrnInfoPtr pScrn);
499Bool VIADRIRingBufferInit(ScrnInfoPtr pScrn);
500void viaDRIOffscreenRestore(ScrnInfoPtr pScrn);
501void viaDRIOffscreenSave(ScrnInfoPtr pScrn);
502Bool VIADRIBufferInit(ScrnInfoPtr pScrn);
503
504#endif /* HAVE_DRI */
505
506int viaOffScreenLinear(struct buffer_object *obj, ScrnInfoPtr pScrn, unsigned long size);
507void viaShowCursor(ScrnInfoPtr pScrn);
508void viaHideCursor(ScrnInfoPtr pScrn);
509Bool viaHWCursorInit(ScreenPtr pScreen);
510void ViaDisplaySetStreamOnCRT(ScrnInfoPtr pScrn, Bool primary);
511void ViaDisplaySetStreamOnDFP(ScrnInfoPtr pScrn, Bool primary);
512void ViaDisplayEnableSimultaneous(ScrnInfoPtr pScrn);
513
514#endif /* _VIA_DRIVER_H_ */
515