1fa225cbcSrjs/***************************************************************************
2fa225cbcSrjs
3fa225cbcSrjsCopyright 2001 Intel Corporation.  All Rights Reserved.
4fa225cbcSrjs
5fa225cbcSrjsPermission is hereby granted, free of charge, to any person obtaining a
6fa225cbcSrjscopy of this software and associated documentation files (the
7fa225cbcSrjs"Software"), to deal in the Software without restriction, including
8fa225cbcSrjswithout limitation the rights to use, copy, modify, merge, publish,
9fa225cbcSrjsdistribute, sub license, and/or sell copies of the Software, and to
10fa225cbcSrjspermit persons to whom the Software is furnished to do so, subject to
11fa225cbcSrjsthe following conditions:
12fa225cbcSrjs
13fa225cbcSrjsThe above copyright notice and this permission notice (including the
14fa225cbcSrjsnext paragraph) shall be included in all copies or substantial portions
15fa225cbcSrjsof the Software.
16fa225cbcSrjs
17fa225cbcSrjsTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18fa225cbcSrjsOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19fa225cbcSrjsMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20fa225cbcSrjsIN NO EVENT SHALL INTEL, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
21fa225cbcSrjsDAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22fa225cbcSrjsOTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
23fa225cbcSrjsTHE USE OR OTHER DEALINGS IN THE SOFTWARE.
24fa225cbcSrjs
25fa225cbcSrjs**************************************************************************/
26fa225cbcSrjs
27fa225cbcSrjs/***************************************************************************
28fa225cbcSrjs * libI810XvMC.h: MC Driver i810 includes
29fa225cbcSrjs *
30fa225cbcSrjs * Authors:
31fa225cbcSrjs *      Matt Sottek <matthew.j.sottek@intel.com>
32fa225cbcSrjs *
33fa225cbcSrjs *
34fa225cbcSrjs ***************************************************************************/
35fa225cbcSrjs
36fa225cbcSrjs
37fa225cbcSrjs#ifndef I810XVMC_H
38fa225cbcSrjs#define I810XVMC_H
39fa225cbcSrjs
40fa225cbcSrjs/* #define XVMC_DEBUG(x) do {x; }while(0); */
41fa225cbcSrjs#define XVMC_DEBUG(x)
42fa225cbcSrjs
43fa225cbcSrjs#include <stdint.h>
44fa225cbcSrjs#include "xf86drm.h"
45fa225cbcSrjs#include "i810_common.h"
46fa225cbcSrjs#include <X11/Xlibint.h>
47fa225cbcSrjs
48fa225cbcSrjs
49fa225cbcSrjs/***************************************************************************
50fa225cbcSrjs// i810OverlayRec: Structure that is used to reference the overlay
51fa225cbcSrjs//  register memory. A i810OverlayRecPtr is set to the address of the
52fa225cbcSrjs//  allocated overlay registers.
53fa225cbcSrjs***************************************************************************/
54fa225cbcSrjstypedef struct _i810OverlayRec {
55fa225cbcSrjs  unsigned int OBUF_0Y;
56fa225cbcSrjs  unsigned int OBUF_1Y;
57fa225cbcSrjs  unsigned int OBUF_0U;
58fa225cbcSrjs  unsigned int OBUF_0V;
59fa225cbcSrjs  unsigned int OBUF_1U;
60fa225cbcSrjs  unsigned int OBUF_1V;
61fa225cbcSrjs  unsigned int OV0STRIDE;
62fa225cbcSrjs  unsigned int YRGB_VPH;
63fa225cbcSrjs  unsigned int UV_VPH;
64fa225cbcSrjs  unsigned int HORZ_PH;
65fa225cbcSrjs  unsigned int INIT_PH;
66fa225cbcSrjs  unsigned int DWINPOS;
67fa225cbcSrjs  unsigned int DWINSZ;
68fa225cbcSrjs  unsigned int SWID;
69fa225cbcSrjs  unsigned int SWIDQW;
70fa225cbcSrjs  unsigned int SHEIGHT;
71fa225cbcSrjs  unsigned int YRGBSCALE;
72fa225cbcSrjs  unsigned int UVSCALE;
73fa225cbcSrjs  unsigned int OV0CLRC0;
74fa225cbcSrjs  unsigned int OV0CLRC1;
75fa225cbcSrjs  unsigned int DCLRKV;
76fa225cbcSrjs  unsigned int DCLRKM;
77fa225cbcSrjs  unsigned int SCLRKVH;
78fa225cbcSrjs  unsigned int SCLRKVL;
79fa225cbcSrjs  unsigned int SCLRKM;
80fa225cbcSrjs  unsigned int OV0CONF;
81fa225cbcSrjs  unsigned int OV0CMD;
82fa225cbcSrjs} i810OverlayRec, *i810OverlayRecPtr;
83fa225cbcSrjs
84fa225cbcSrjs
85fa225cbcSrjs/***************************************************************************
86fa225cbcSrjs// i810XvMCDrmMap: Holds the data about the DRM maps
87fa225cbcSrjs***************************************************************************/
88fa225cbcSrjstypedef struct _i810XvMCDrmMap {
89fa225cbcSrjs  drm_handle_t offset;
90fa225cbcSrjs  drmAddress address;
91fa225cbcSrjs  unsigned int size;
92fa225cbcSrjs} i810XvMCDrmMap, *i810XvMCDrmMapPtr;
93fa225cbcSrjs
94fa225cbcSrjs/***************************************************************************
95fa225cbcSrjs// i810XvMCContext: Private Context data referenced via the privData
96fa225cbcSrjs//  pointer in the XvMCContext structure.
97fa225cbcSrjs***************************************************************************/
98fa225cbcSrjstypedef struct _i810XvMCContext {
99fa225cbcSrjs  int fd;   /* File descriptor for /dev/dri */
100fa225cbcSrjs  i810XvMCDrmMap overlay;
101fa225cbcSrjs  i810XvMCDrmMap surfaces;
102fa225cbcSrjs  drmBufMapPtr dmabufs;  /* Data structure to hold available dma buffers */
103fa225cbcSrjs  drm_context_t drmcontext;
104fa225cbcSrjs  unsigned int last_render;
105fa225cbcSrjs  unsigned int last_flip;
106fa225cbcSrjs  unsigned short ref;
107fa225cbcSrjs  unsigned short current;
108fa225cbcSrjs  int lock;   /* Lightweight lock to avoid locking twice */
109fa225cbcSrjs  char busIdString[10]; /* PCI:0:1:0 or PCI:0:2:0 */
110fa225cbcSrjs  i810OverlayRecPtr oregs;
111fa225cbcSrjs  unsigned int dual_prime; /* Flag to identify when dual prime is in use. */
112fa225cbcSrjs  unsigned int fb_base;
113fa225cbcSrjs  Atom xv_colorkey;
114fa225cbcSrjs  Atom xv_brightness;
115fa225cbcSrjs  Atom xv_contrast;
116fa225cbcSrjs  Atom xv_saturation;
117fa225cbcSrjs  int brightness;
118fa225cbcSrjs  int saturation;
119fa225cbcSrjs  int contrast;
120fa225cbcSrjs  int colorkey;
121fa225cbcSrjs} i810XvMCContext;
122fa225cbcSrjs
123fa225cbcSrjs/***************************************************************************
124fa225cbcSrjs// i810XvMCSurface: Private data structure for each XvMCSurface. This
125fa225cbcSrjs//  structure is referenced by the privData pointer in the XvMCSurface
126fa225cbcSrjs//  structure.
127fa225cbcSrjs***************************************************************************/
128fa225cbcSrjstypedef struct _i810XvMCSurface {
129fa225cbcSrjs  unsigned int pitch;
130fa225cbcSrjs  unsigned int dbi1y;  /* Destination buffer info command word 1 for Y */
131fa225cbcSrjs  unsigned int dbi1u; /* Destination buffer info command word 1 for U */
132fa225cbcSrjs  unsigned int dbi1v; /* Destination buffer info command word 1 for V */
133fa225cbcSrjs  unsigned int dbv1;  /* Destination buffer variables command word 1 */
134fa225cbcSrjs  unsigned int mi1y;   /* Map Info command word 1 (Minus bit 28) for Y */
135fa225cbcSrjs  unsigned int mi1u;   /* Map Info command word 1 (Minus bit 28) for U */
136fa225cbcSrjs  unsigned int mi1v;   /* Map Info command word 1 (Minus bit 28) for V */
137fa225cbcSrjs  unsigned int mi2y;   /* Map info command word 2 for y */
138fa225cbcSrjs  unsigned int mi2u;   /* Map info command word 2 for y */
139fa225cbcSrjs  unsigned int mi2v;   /* Map info command word 2 for y */
140fa225cbcSrjs  unsigned int mi3y;   /* Map info command word 3 */
141fa225cbcSrjs  unsigned int mi3u;   /* Map info command word 3 */
142fa225cbcSrjs  unsigned int mi3v;   /* Map info command word 3 */
143fa225cbcSrjs  unsigned int last_render;
144fa225cbcSrjs  unsigned int last_flip;
145fa225cbcSrjs  unsigned int second_field; /* Flags a surface that is only half done */
146fa225cbcSrjs  drmAddress data;
147fa225cbcSrjs  drm_handle_t offset;
148fa225cbcSrjs  unsigned int offsets[3];
149fa225cbcSrjs  i810XvMCContext *privContext;
150fa225cbcSrjs} i810XvMCSurface;
151fa225cbcSrjs
152fa225cbcSrjs/***************************************************************************
153fa225cbcSrjs// i810XvMCSubpicture: Private data structure for each XvMCSubpicture. This
154fa225cbcSrjs//  structure is referenced by the privData pointer in the XvMCSubpicture
155fa225cbcSrjs//  structure.
156fa225cbcSrjs***************************************************************************/
157fa225cbcSrjstypedef struct _i810XvMCSubpicture {
158fa225cbcSrjs  unsigned int pitch;
159fa225cbcSrjs  unsigned int dbi1;  /* Destination buffer info command word 1 */
160fa225cbcSrjs  unsigned int dbv1;  /* Destination buffer variables command word */
161fa225cbcSrjs  unsigned int mi1;   /* Map Info command word 1 (Minus bit 28) */
162fa225cbcSrjs  unsigned int mi2;   /* Map info command word 2 */
163fa225cbcSrjs  unsigned int mi3;   /* Map info command word 3 */
164fa225cbcSrjs  unsigned int last_render;
165fa225cbcSrjs  unsigned int last_flip;
166fa225cbcSrjs  drmAddress data;
167fa225cbcSrjs  drm_handle_t offset;
168fa225cbcSrjs  unsigned int offsets[1];
169fa225cbcSrjs  unsigned char palette[3][16];
170fa225cbcSrjs  i810XvMCContext *privContext;
171fa225cbcSrjs} i810XvMCSubpicture;
172fa225cbcSrjs
173fa225cbcSrjstypedef struct _Box {
174fa225cbcSrjs  int x1,y1,x2,y2;
175fa225cbcSrjs} Box, *BoxPtr;
176fa225cbcSrjs
177fa225cbcSrjs/***************************************************************************
178fa225cbcSrjs// drm_i810_overlay_t: Structure returned by overlay info ioctl.
179fa225cbcSrjs// NOTE: If you change this structure you will have to change the equiv.
180fa225cbcSrjs//  structure in the kernel.
181fa225cbcSrjs***************************************************************************/
182fa225cbcSrjstypedef struct _drm_i810_overlay_t {
183fa225cbcSrjs  unsigned int offset;
184fa225cbcSrjs  unsigned int physical;
185fa225cbcSrjs} drm_i810_overlay_t;
186fa225cbcSrjs
187fa225cbcSrjs/***************************************************************************
188fa225cbcSrjs// drm_i810_dma_t: Structure used by dma allocation ioctl.
189fa225cbcSrjs// NOTE: If you change this structure you will have to change the equiv.
190fa225cbcSrjs//  structure in the kernel.
191fa225cbcSrjs***************************************************************************/
192fa225cbcSrjstypedef struct _drm_i810_dma {
193fa225cbcSrjs  void *virtual;
194fa225cbcSrjs  int request_idx;
195fa225cbcSrjs  int request_size;
196fa225cbcSrjs  int granted;
197fa225cbcSrjs} drm_i810_dma_t;
198fa225cbcSrjs
199fa225cbcSrjs/***************************************************************************
200fa225cbcSrjs// drm_i810_mc_t: Structure used by mc dispatch ioctl.
201fa225cbcSrjs// NOTE: If you change this structure you will have to change the equiv.
202fa225cbcSrjs//  structure in the kernel.
203fa225cbcSrjs***************************************************************************/
204fa225cbcSrjstypedef struct _drm_i810_mc {
205fa225cbcSrjs  int idx;		/* buffer index */
206fa225cbcSrjs  int used;		/* nr bytes in use */
207fa225cbcSrjs  int num_blocks;         /* number of GFXBlocks */
208fa225cbcSrjs  int *length;	        /* List of lengths for GFXBlocks */
209fa225cbcSrjs  unsigned int last_render; /* Last render request */
210fa225cbcSrjs} drm_i810_mc_t;
211fa225cbcSrjs
212fa225cbcSrjs/* Subpicture fourcc */
213fa225cbcSrjs#define FOURCC_IA44 0x34344149
214fa225cbcSrjs
215fa225cbcSrjs/* Static Parameters */
216fa225cbcSrjs#define I810_XVMC_MAXWIDTH  720
217fa225cbcSrjs#define I810_XVMC_MAXHEIGHT  576
218fa225cbcSrjs#define I810_DEFAULT16_COLORKEY 31
219fa225cbcSrjs#define I810_DMA_BUF_NR 256
220fa225cbcSrjs
221fa225cbcSrjs/* COMMANDS */
222fa225cbcSrjs#define CMD_FLUSH        ((4<<23) | 0x1)
223fa225cbcSrjs#define BOOLEAN_ENA_1    ((3<<29) | (3<<24) | (3<<2))
224fa225cbcSrjs#define BOOLEAN_ENA_2    ((3<<29) | (4<<24) | (3<<16) | (1<<3) | (1<<2))
225fa225cbcSrjs#define DEST_BUFFER_INFO (0x15<<23)
226fa225cbcSrjs#define DEST_BUFFER_VAR  ((0x3<<29) | (0x1d<<24) | (0x85<<16))
227fa225cbcSrjs#define DRAWING_RECT_INFO ((3<<29) | (0x1d<<24) | (0x80<<16) | 3)
228fa225cbcSrjs#define GFXBLOCK         ((0x3<<29) | (0x1e<<24))
229fa225cbcSrjs#define CMD_MAP_INFO     ((0x3<<29) | (0x1d<<24) | 0x2)
230fa225cbcSrjs#define MAP_PALETTE_LOAD ((3<<29) | (0x1d<<24) | (0x82<<16) | 0xff)
231fa225cbcSrjs#define VERTEX_FORMAT    ((3<<29) | (0x5<<24))
232fa225cbcSrjs#define SRC_DEST_BLEND_MONO ((3<<29) | (8<<24))
233fa225cbcSrjs
234fa225cbcSrjs/* Bit Patterns */
235fa225cbcSrjs
236fa225cbcSrjs/*
237fa225cbcSrjs * OV0CMD - Overlay Command Register
238fa225cbcSrjs */
239fa225cbcSrjs#define VERTICAL_CHROMINANCE_FILTER     0x70000000
240fa225cbcSrjs#define VC_SCALING_OFF          0x00000000
241fa225cbcSrjs#define VC_LINE_REPLICATION     0x10000000
242fa225cbcSrjs#define VC_UP_INTERPOLATION     0x20000000
243fa225cbcSrjs#define VC_PIXEL_DROPPING       0x50000000
244fa225cbcSrjs#define VC_DOWN_INTERPOLATION   0x60000000
245fa225cbcSrjs#define VERTICAL_LUMINANCE_FILTER       0x0E000000
246fa225cbcSrjs#define VL_SCALING_OFF          0x00000000
247fa225cbcSrjs#define VL_LINE_REPLICATION     0x02000000
248fa225cbcSrjs#define VL_UP_INTERPOLATION     0x04000000
249fa225cbcSrjs#define VL_PIXEL_DROPPING       0x0A000000
250fa225cbcSrjs#define VL_DOWN_INTERPOLATION   0x0C000000
251fa225cbcSrjs#define HORIZONTAL_CHROMINANCE_FILTER   0x01C00000
252fa225cbcSrjs#define HC_SCALING_OFF          0x00000000
253fa225cbcSrjs#define HC_LINE_REPLICATION     0x00400000
254fa225cbcSrjs#define HC_UP_INTERPOLATION     0x00800000
255fa225cbcSrjs#define HC_PIXEL_DROPPING       0x01400000
256fa225cbcSrjs#define HC_DOWN_INTERPOLATION   0x01800000
257fa225cbcSrjs#define HORIZONTAL_LUMINANCE_FILTER     0x00380000
258fa225cbcSrjs#define HL_SCALING_OFF          0x00000000
259fa225cbcSrjs#define HL_LINE_REPLICATION     0x00080000
260fa225cbcSrjs#define HL_UP_INTERPOLATION     0x00100000
261fa225cbcSrjs#define HL_PIXEL_DROPPING       0x00280000
262fa225cbcSrjs#define HL_DOWN_INTERPOLATION   0x00300000
263fa225cbcSrjs
264fa225cbcSrjs#define Y_ADJUST                0x00010000
265fa225cbcSrjs#define OV_BYTE_ORDER           0x0000C000
266fa225cbcSrjs#define UV_SWAP                 0x00004000
267fa225cbcSrjs#define Y_SWAP                  0x00008000
268fa225cbcSrjs#define Y_AND_UV_SWAP           0x0000C000
269fa225cbcSrjs#define SOURCE_FORMAT           0x00003C00
270fa225cbcSrjs#define RGB_555                 0x00000800
271fa225cbcSrjs#define RGB_565                 0x00000C00
272fa225cbcSrjs#define YUV_422                 0x00002000
273fa225cbcSrjs#define YUV_411                 0x00002400
274fa225cbcSrjs#define YUV_420                 0x00003000
275fa225cbcSrjs#define YUV_410                 0x00003800
276fa225cbcSrjs#define VERTICAL_PHASE_BOTH     0x00000020
277fa225cbcSrjs#define FLIP_TYPE_FIELD         0x00000020
278fa225cbcSrjs#define FLIP_TYPE_FRAME         0x00000000
279fa225cbcSrjs#define BUFFER_AND_FIELD        0x00000006
280fa225cbcSrjs#define BUFFER0_FIELD0          0x00000000
281fa225cbcSrjs#define BUFFER0_FIELD1          0x00000002
282fa225cbcSrjs#define BUFFER1_FIELD0          0x00000004
283fa225cbcSrjs#define BUFFER1_FIELD1          0x00000006
284fa225cbcSrjs#define OVERLAY_ENABLE          0x00000001
285fa225cbcSrjs
286fa225cbcSrjs/*
287fa225cbcSrjs * DOV0STA - Display/Overlay 0 Status Register
288fa225cbcSrjs */
289fa225cbcSrjs#define DOV0STA         0x30008
290fa225cbcSrjs#define OV0ADD         0x30000
291fa225cbcSrjs#define MINUV_SCALE     0x1
292fa225cbcSrjs
293fa225cbcSrjs#define RGB16ToColorKey(c) \
294fa225cbcSrjs        (((c & 0xF800) << 8) | ((c & 0x07E0) << 5) | ((c & 0x001F) << 3))
295fa225cbcSrjs
296fa225cbcSrjs/* Locking Macros lightweight lock used to prevent relocking */
297fa225cbcSrjs#define I810_LOCK(c,f)                     \
298fa225cbcSrjs  if(!c->lock) {                           \
299fa225cbcSrjs    drmGetLock(c->fd, c->drmcontext, f);   \
300fa225cbcSrjs  }                                        \
301fa225cbcSrjs  c->lock++;
302fa225cbcSrjs
303fa225cbcSrjs#define I810_UNLOCK(c)                     \
304fa225cbcSrjs  c->lock--;                               \
305fa225cbcSrjs  if(!c->lock) {                           \
306fa225cbcSrjs    drmUnlock(c->fd, c->drmcontext);       \
307fa225cbcSrjs  }
308fa225cbcSrjs
309fa225cbcSrjs/*
310fa225cbcSrjs  Block until the passed in value (n) is the active
311fa225cbcSrjs  buffer on the overlay.
312fa225cbcSrjs*/
313fa225cbcSrjs#define BLOCK_OVERLAY(c,n)                        \
314fa225cbcSrjs  do {                                            \
315fa225cbcSrjs   int temp,i=0;                                  \
316fa225cbcSrjs   while(i < 100000) {                            \
317fa225cbcSrjs     temp = GET_FSTATUS(c);                       \
318fa225cbcSrjs     if(((temp & (1<<20))>>20) == n) {            \
319fa225cbcSrjs       break;                                     \
320fa225cbcSrjs     }                                            \
321fa225cbcSrjs     usleep(10);                                  \
322fa225cbcSrjs   }                                              \
323fa225cbcSrjs   if(i == 100000) {                              \
324fa225cbcSrjs     printf("Overlay Lockup.\n");                 \
325fa225cbcSrjs     return BadAlloc;                             \
326fa225cbcSrjs   }                                              \
327fa225cbcSrjs }while(0);
328fa225cbcSrjs
329fa225cbcSrjs#define OVERLAY_INFO(c,i) drmCommandRead(c->fd, DRM_I810_OV0INFO, &i, sizeof(i))
330fa225cbcSrjs#define OVERLAY_FLIP(c) drmCommandNone(c->fd, DRM_I810_OV0FLIP)
331fa225cbcSrjs#define GET_FSTATUS(c) drmCommandNone(c->fd, DRM_I810_FSTATUS)
332fa225cbcSrjs#define I810_MC(c,mc) drmCommandWrite(c->fd, DRM_I810_MC, &mc, sizeof(mc))
333fa225cbcSrjs#define GET_RSTATUS(c) drmCommandNone(c->fd, DRM_I810_RSTATUS)
334fa225cbcSrjs#define GET_BUFFER(c,dma) drmCommandWriteRead(c->fd, DRM_I810_GETBUF, &dma, sizeof(drmI810DMA))
335fa225cbcSrjs#define FLUSH(c) drmCommandNone(c->fd, DRM_I810_FLUSH)
336fa225cbcSrjs
337fa225cbcSrjs/*
338fa225cbcSrjs  Definitions for temporary wire protocol hooks to be replaced
339fa225cbcSrjs  when a HW independent libXvMC is created.
340fa225cbcSrjs*/
341fa225cbcSrjsextern Status _xvmc_create_context(Display *dpy, XvMCContext *context,
342fa225cbcSrjs				   int *priv_count, uint **priv_data);
343fa225cbcSrjs
344fa225cbcSrjsextern Status _xvmc_destroy_context(Display *dpy, XvMCContext *context);
345fa225cbcSrjs
346fa225cbcSrjsextern Status _xvmc_create_surface(Display *dpy, XvMCContext *context,
347fa225cbcSrjs				   XvMCSurface *surface, int *priv_count,
348fa225cbcSrjs				   uint **priv_data);
349fa225cbcSrjs
350fa225cbcSrjsextern Status _xvmc_destroy_surface(Display *dpy, XvMCSurface *surface);
351fa225cbcSrjs
352fa225cbcSrjsextern Status  _xvmc_create_subpicture(Display *dpy, XvMCContext *context,
353fa225cbcSrjs				       XvMCSubpicture *subpicture,
354fa225cbcSrjs				       int *priv_count, uint **priv_data);
355fa225cbcSrjs
356fa225cbcSrjsextern Status   _xvmc_destroy_subpicture(Display *dpy,
357fa225cbcSrjs					 XvMCSubpicture *subpicture);
358fa225cbcSrjs
359fa225cbcSrjs/*
360fa225cbcSrjs  Prototypes
361fa225cbcSrjs*/
362fa225cbcSrjsdrmBufPtr i810_get_free_buffer(i810XvMCContext *pI810XvMC);
363fa225cbcSrjsvoid i810_free_privContext(i810XvMCContext *pI810XvMC);
364fa225cbcSrjsvoid dp(unsigned int *address, unsigned int i);
365fa225cbcSrjs
366fa225cbcSrjs#endif
367