1/*****************************************************************************
2 * VIA Unichrome XvMC extension client lib.
3 *
4 * Copyright (c) 2004 The Unichrome Project. 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, sublicense,
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 shall be included in
14 * all copies or substantial portions of the 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 THE
19 * AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25/*
26 * Authors: Thomas Hellstr�m 2004 - 2005.
27 */
28
29#ifndef VIA_LOWLEVEL_H
30#define VIA_LOWLEVEL_H
31
32/*
33 * The below define is cache size sensitive. Increasing the AGP buffer size
34 * will enable the library to do deeper pipelining, but will degrade the
35 * performance in the drm dma command verifier.
36 */
37
38#define LL_AGP_CMDBUF_SIZE (4096*2)
39#define LL_PCI_CMDBUF_SIZE (4096)
40
41#define LL_MODE_DECODER_SLICE 0x01
42#define LL_MODE_DECODER_IDLE 0x02
43#define LL_MODE_VIDEO   0x04
44#define LL_MODE_2D      0x08
45#define LL_MODE_3D      0x10
46
47/*
48 * Errors
49 */
50
51#define LL_DECODER_TIMEDOUT 0x00000001
52#define LL_IDCT_FIFO_ERROR  0x00000002
53#define LL_SLICE_FIFO_ERROR 0x00000004
54#define LL_SLICE_FAULT      0x00000008
55#define LL_DMA_TIMEDOUT     0x00000010
56#define LL_VIDEO_TIMEDOUT   0x00000020
57#define LL_ACCEL_TIMEDOUT   0x00000040
58#define LL_PCI_COMMAND_ERR  0x00000080
59#define LL_AGP_COMMAND_ERR  0x00000100
60
61#define VIA_SLICEBUSYMASK        0x00000200
62#define VIA_BUSYMASK             0x00000207
63#define VIA_SLICEIDLEVAL         0x00000200
64#define VIA_IDLEVAL              0x00000204
65
66#include "via_drm.h"
67#include "viaXvMCPriv.h"
68
69#define setRegion(xx,yy,ww,hh,region) \
70    do {			  \
71	(region).x = (xx);	  \
72	(region).y = (yy);	  \
73	(region).w = (ww);	  \
74	(region).h = (hh);	  \
75    } while(0)
76
77#define regionEqual(r1, r2)				\
78    ((r1).x == (r2).x &&				\
79     (r1).y == (r2).y &&				\
80     (r1).w == (r2).w &&				\
81     (r1).h == (r2).h)
82
83extern void
84    *initXvMCLowLevel(int fd, drm_context_t * ctx,
85    drmLockPtr hwLock, drmAddress mmioAddress,
86    drmAddress fbAddress, unsigned fbStride, unsigned fbDepth,
87    unsigned width, unsigned height, int useAgp, unsigned chipId);
88
89extern void setLowLevelLocking(void *xlp, int perFormLocking);
90extern void closeXvMCLowLevel(void *xlp);
91extern void flushPCIXvMCLowLevel(void *xlp);
92extern CARD32 viaDMATimeStampLowLevel(void *xlp);
93extern void setAGPSyncLowLevel(void *xlp, int val, CARD32 timeStamp);
94
95/*
96 * These two functions also return and clear the current error status.
97 */
98
99extern unsigned flushXvMCLowLevel(void *xlp);
100extern unsigned syncXvMCLowLevel(void *xlp, unsigned int mode,
101    unsigned int doSleep, CARD32 timeStamp);
102
103extern void hwlUnlock(void *xlp, int videoLock);
104extern void hwlLock(void *xlp, int videoLock);
105
106extern void viaVideoSetSWFLipLocked(void *xlp, unsigned yOffs, unsigned uOffs,
107    unsigned vOffs, unsigned yStride, unsigned uvStride);
108
109extern void viaMpegReset(void *xlp);
110extern void viaMpegWriteSlice(void *xlp, CARD8 * slice,
111    int nBytes, CARD32 sCode);
112extern void viaMpegSetSurfaceStride(void *xlp, ViaXvMCContext * ctx);
113extern void viaMpegSetFB(void *xlp, unsigned i, unsigned yOffs,
114    unsigned uOffs, unsigned vOffs);
115extern void viaMpegBeginPicture(void *xlp, ViaXvMCContext * ctx,
116    unsigned width, unsigned height, const XvMCMpegControl * control);
117
118/*
119 * Low-level Video functions in viaLowLevel.c
120 */
121
122extern void viaBlit(void *xlp, unsigned bpp, unsigned srcBase,
123    unsigned srcPitch, unsigned dstBase, unsigned dstPitch,
124    unsigned w, unsigned h, int xdir, int ydir,
125    unsigned blitMode, unsigned color);
126
127extern void viaVideoSWFlipLocked(void *xlp, unsigned flags,
128    int progressiveSequence);
129
130extern void viaVideoSubPictureLocked(void *xlp,
131    ViaXvMCSubPicture * pViaSubPic);
132extern void viaVideoSubPictureOffLocked(void *xlp);
133
134#define PCI_CHIP_VT3204         0x3108 /* K8M800 */
135#define PCI_CHIP_VT3259         0x3118 /* PM800/PM880/CN400 */
136#define PCI_CHIP_CLE3122        0x3122 /* CLE266 */
137#define PCI_CHIP_VT3205         0x7205 /* KM400 */
138#define PCI_CHIP_VT3327         0x3343 /* P4M890 */
139#define PCI_CHIP_VT3364         0x3371 /* P4M900 */
140
141#endif
142