Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 140323 | Differences between
and this patch

Collapse All | Expand All

(-)ivtvdrv-noX-no-autotools/xc/programs/Xserver/hw/xfree86/drivers/ivtv/Imakefile (-55 lines)
Lines 1-55 Link Here
1
XCOMM
2
XCOMM This is an Imakefile for the fbdev driver.  
3
XCOMM
4
XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/drivers/fbdev/Imakefile,v 1.10 2001/04/06 18:16:30 dawes Exp $
5
#undef DefaultCCOptions
6
#define DefaultCCOptions
7
#define IHaveModules
8
#include <Server.tmpl>
9
10
SRCS = ivtvdev.c ivtvhw.c ivtv_xv.c
11
OBJS = ivtvdev.o ivtvhw.o ivtv_xv.o
12
13
#if defined(XF86DriverSDK)
14
INCLUDES = -I. -I../../include
15
#else
16
INCLUDES = -I. -I$(XF86COMSRC) -I$(XF86OSSRC) \
17
           -I$(SERVERSRC)/mfb -I$(SERVERSRC)/mi \
18
           -I$(SERVERSRC)/fb -I$(XF86SRC)/xaa \
19
	   -I$(XF86SRC)/fbdevhw -I$(XF86SRC)/ramdac \
20
           -I$(XF86SRC)/ddc -I$(XF86SRC)/i2c \
21
           -I$(XF86SRC)/rac \
22
           -I$(SERVERSRC)/Xext -I$(XF86SRC)/xf24_32bpp\
23
           -I$(FONTINCSRC) -I$(SERVERSRC)/include -I$(XINCLUDESRC) \
24
	   -I$(SERVERSRC)/miext/shadow -I$(EXTINCSRC) -I$(SERVERSRC)/render
25
#endif
26
#ifdef XF86_VERSION_CURRENT
27
XCOMM We are using Xfree86
28
29
#if XF86_VERSION_CURRENT >= XF86_VERSION_NUMERIC(4,3,99,16,0)
30
DEFREGIONNULL = -DX_USE_REGION_NULL
31
#endif
32
33
#else
34
XCOMM We are using X.org
35
DEFREGIONNULL = -DX_USE_REGION_NULL
36
#endif
37
DEFINES = FbdevDefines  $(DEFREGIONNULL)
38
39
#if MakeHasPosixVariableSubstitutions
40
SubdirLibraryRule($(OBJS))
41
#endif
42
43
ModuleObjectRule()
44
45
ObjectModuleTarget(ivtvdev,$(OBJS))
46
47
InstallObjectModule(ivtvdev,$(MODULEDIR),drivers)
48
49
50
DependTarget()
51
52
InstallDriverSDKNonExecFile(Imakefile,$(DRIVERSDKDIR)/drivers/ivtvdev)
53
InstallDriverSDKNonExecFile(ivtvdev.c,$(DRIVERSDKDIR)/drivers/ivtvdev)
54
55
InstallDriverSDKObjectModule(ivtvdev,$(DRIVERSDKMODULEDIR),drivers)
(-)ivtvdrv-noX-no-autotools/xc/programs/Xserver/hw/xfree86/drivers/ivtv/ivtvdev.c (-605 lines)
Lines 1-605 Link Here
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/ivtv/ivtv.c,v 1.42 2002/10/10 01:35:20 dawes Exp $ */
2
3
/*
4
 * Authors:  Alan Hourihane, <alanh@fairlite.demon.co.uk>
5
 *	     Michel Dänzer, <michdaen@iiic.ethz.ch>
6
 */
7
8
#include "ivtvhw.h"
9
#include "ivtvdev.h"
10
/* all driver need this */
11
#include "xf86.h"
12
#include "xf86_OSproc.h"
13
#include "xf86_ansic.h"
14
15
#include "mipointer.h"
16
#include "mibstore.h"
17
#include "micmap.h"
18
#include "colormapst.h"
19
#include "xf86cmap.h"
20
#include "shadow.h"
21
22
/* for visuals */
23
#include "fb.h"
24
25
#include "xf86Resources.h"
26
#include "xf86RAC.h"
27
28
#ifdef XvExtension
29
#include "xf86xv.h"
30
#endif
31
enum HAUPAGE_CHIPTAGS {
32
	PVR_UNKNOWN = 0,
33
	PVR_350,
34
	PVR_LAST
35
};
36
#define PCI_CHIP_PVR350         0x0803
37
38
static SymTabRec IVTVChipsets[] = {
39
	{PVR_350, "PVR-350"},
40
	{-1, NULL}
41
};
42
43
/* This table maps a PCI device ID to a chipset family identifier. */
44
static PciChipsets IVTVPciChipsets[] = {
45
	{PVR_350, PCI_CHIP_PVR350, RES_SHARED_VGA},
46
	{-1, -1, RES_UNDEFINED}
47
};
48
49
#define DEBUG 0
50
51
#if DEBUG
52
# define TRACE_ENTER(str)       ErrorF("ivtv: " str " %d\n",pScrn->scrnIndex)
53
# define TRACE_EXIT(str)        ErrorF("ivtv: " str " done\n")
54
# define TRACE(str)             ErrorF("ivtv trace: " str "\n")
55
#else
56
# define TRACE_ENTER(str)
57
# define TRACE_EXIT(str)
58
# define TRACE(str)
59
#endif
60
61
/* -------------------------------------------------------------------- */
62
/* prototypes                                                           */
63
64
static const OptionInfoRec *IVTVDevAvailableOptions(int chipid, int busid);
65
static void IVTVDevIdentify(int flags);
66
static Bool IVTVDevProbe(DriverPtr drv, int flags);
67
static Bool IVTVDevPreInit(ScrnInfoPtr pScrn, int flags);
68
static Bool IVTVDevScreenInit(int Index, ScreenPtr pScreen, int argc,
69
			      char **argv);
70
static Bool IVTVDevCloseScreen(int scrnIndex, ScreenPtr pScreen);
71
72
/* -------------------------------------------------------------------- */
73
74
/*
75
 * This is intentionally screen-independent.  It indicates the binding
76
 * choice made in the first PreInit.
77
 */
78
static int pix24bpp = 0;
79
80
#define VERSION			4000
81
#define IVTVDEV_NAME		"IVTVDEV_TST"
82
#define IVTVDEV_DRIVER_NAME	"ivtvdev"
83
#define IVTVDEV_MAJOR_VERSION	0
84
#define IVTVDEV_MINOR_VERSION	10
85
86
DriverRec IVTVDEV = {
87
	VERSION,
88
	IVTVDEV_DRIVER_NAME,
89
#if 0
90
	"driver for linux framebuffer devices",
91
#endif
92
	IVTVDevIdentify,
93
	IVTVDevProbe,
94
	IVTVDevAvailableOptions,
95
	NULL,
96
	0
97
};
98
99
/* Supported options */
100
typedef enum {
101
	OPTION_IVTVDEV
102
} IVTVDevOpts;
103
104
static const OptionInfoRec IVTVDevOptions[] = {
105
	{OPTION_IVTVDEV, "ivtv", OPTV_STRING, {0}, FALSE},
106
	{-1, NULL, OPTV_NONE, {0}, FALSE}
107
};
108
109
/* -------------------------------------------------------------------- */
110
111
static const char *fbSymbols[] = {
112
	"fbScreenInit",
113
	"fbPictureInit",
114
	NULL
115
};
116
117
static const char *shadowSymbols[] = {
118
	"shadowAdd",
119
	"shadowAlloc",
120
	"shadowInit",
121
	"shadowSetup",
122
	"shadowUpdatePacked",
123
	"shadowUpdateRotatePacked",
124
	NULL
125
};
126
127
#ifdef XFree86LOADER
128
129
MODULESETUPPROTO(IVTVDevSetup);
130
131
static XF86ModuleVersionInfo IVTVDevVersRec = {
132
	"ivtv",
133
	MODULEVENDORSTRING,
134
	MODINFOSTRING1,
135
	MODINFOSTRING2,
136
	XF86_VERSION_CURRENT,
137
	IVTVDEV_MAJOR_VERSION, IVTVDEV_MINOR_VERSION, 6,
138
	ABI_CLASS_VIDEODRV,
139
	ABI_VIDEODRV_VERSION,
140
	NULL,
141
	{0, 0, 0, 0}
142
};
143
144
XF86ModuleData ivtvdevModuleData = { &IVTVDevVersRec, IVTVDevSetup, NULL };
145
146
pointer IVTVDevSetup(pointer module, pointer opts, int *errmaj, int *errmin)
147
{
148
	static Bool setupDone = FALSE;
149
150
	if (!setupDone) {
151
		setupDone = TRUE;
152
		xf86AddDriver(&IVTVDEV, module, 0);
153
		LoaderRefSymLists(fbSymbols, shadowSymbols, NULL);
154
		return (pointer) 1;
155
	} else {
156
		if (errmaj)
157
			*errmaj = LDR_ONCEONLY;
158
		return NULL;
159
	}
160
}
161
162
#endif				/* XFree86LOADER */
163
164
void FBshadowUpdatePacked(ScreenPtr pScreen, shadowBufPtr pBuf)
165
{
166
167
	RegionPtr damage = &pBuf->damage;
168
	int nbox = REGION_NUM_RECTS(damage);
169
	BoxPtr pbox = REGION_RECTS(damage);
170
171
	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
172
	IVTVDevPtr fPtr = IVTVDEVPTR(pScrn);
173
	int x1 = pScrn->virtualX;
174
	int x2 = 0;
175
	int y1 = pScrn->virtualY;
176
	int y2 = 0;
177
	while (nbox--) {
178
		if (pbox->x1 < x1)
179
			x1 = pbox->x1;
180
		if (pbox->x2 > x2)
181
			x2 = pbox->x2;
182
		if (pbox->y1 < y1)
183
			y1 = pbox->y1;
184
		if (pbox->y2 > y2)
185
			y2 = pbox->y2;
186
		pbox++;
187
	};
188
189
	ivtvHWSendDMA(pScrn, fPtr->shadowmem, x1, x2, y1, y2);
190
}
191
192
static Bool IVTVDevGetRec(ScrnInfoPtr pScrn)
193
{
194
	if (pScrn->driverPrivate != NULL)
195
		return TRUE;
196
197
	pScrn->driverPrivate = xnfcalloc(sizeof(IVTVDevRec), 1);
198
	return TRUE;
199
}
200
201
static void IVTVDevFreeRec(ScrnInfoPtr pScrn)
202
{
203
	if (pScrn->driverPrivate == NULL)
204
		return;
205
	xfree(pScrn->driverPrivate);
206
	pScrn->driverPrivate = NULL;
207
}
208
209
/* -------------------------------------------------------------------- */
210
211
static const OptionInfoRec *IVTVDevAvailableOptions(int chipid, int busid)
212
{
213
	return IVTVDevOptions;
214
}
215
216
static void IVTVDevIdentify(int flags)
217
{
218
	xf86PrintChipsets(IVTVDEV_NAME, "driver for framebuffer", IVTVChipsets);
219
}
220
221
static Bool IVTVDevProbe(DriverPtr drv, int flags)
222
{
223
	int i;
224
	ScrnInfoPtr pScrn;
225
	GDevPtr *devSections;
226
	int numDevSections;
227
	int bus, device, func;
228
	char *dev;
229
	Bool foundScreen = FALSE;
230
	int *usedChips;
231
	int numUsed;
232
	TRACE("probe start");
233
234
	/* For now, just bail out for PROBE_DETECT. */
235
	if (flags & PROBE_DETECT)
236
		return FALSE;
237
238
	/* sanity checks */
239
	if ((numDevSections =
240
	     xf86MatchDevice(IVTVDEV_DRIVER_NAME, &devSections)) <= 0)
241
		return FALSE;
242
243
	if (xf86GetPciVideoInfo() == NULL)
244
		return FALSE;
245
246
	numUsed = xf86MatchPciInstances(IVTVDEV_DRIVER_NAME,
247
					PCI_HAUPAGGE_VENDOR_ID,
248
					IVTVChipsets,
249
					IVTVPciChipsets,
250
					devSections,
251
					numDevSections, drv, &usedChips);
252
253
	if (numUsed <= 0)
254
		return FALSE;
255
256
	if (flags & PROBE_DETECT) {
257
		foundScreen = TRUE;
258
	} else {
259
		for (i = 0; i < numUsed; i++) {
260
			ScrnInfoPtr pScrn = xf86AllocateScreen(drv, 0);
261
			EntityInfoPtr pEnt;
262
			dev =
263
			    xf86FindOptionValue(devSections[i]->options,
264
						"fbdev");
265
			if (ivtvHWProbe(NULL, dev, NULL)) {
266
				pScrn =
267
				    xf86ConfigPciEntity(pScrn, 0, usedChips[i],
268
							IVTVPciChipsets, 0, 0,
269
							0, 0, 0);
270
271
				/* xf86DrvMsg() can't be called without setting these */
272
				pScrn->driverName = IVTVDEV_DRIVER_NAME;
273
				pScrn->name = IVTVDEV_NAME;
274
275
				if (pScrn) {
276
					foundScreen = TRUE;
277
278
					pScrn->driverVersion = VERSION;
279
					pScrn->driverName = IVTVDEV_DRIVER_NAME;
280
					pScrn->name = IVTVDEV_NAME;
281
					pScrn->Probe = IVTVDevProbe;
282
					pScrn->PreInit = IVTVDevPreInit;
283
					pScrn->ScreenInit = IVTVDevScreenInit;
284
					pScrn->SwitchMode = ivtvHWSwitchMode;
285
					pScrn->AdjustFrame = ivtvHWAdjustFrame;
286
					pScrn->EnterVT = ivtvHWEnterVT;
287
					pScrn->LeaveVT = ivtvHWLeaveVT;
288
					pScrn->ValidMode = ivtvHWValidMode;
289
290
					xf86DrvMsg(pScrn->scrnIndex, X_INFO,
291
						   "using %s\n",
292
						   dev ? dev :
293
						   "default device");
294
				}
295
			}
296
		}
297
	}
298
	xfree(devSections);
299
	TRACE("probe done");
300
	return foundScreen;
301
}
302
303
static Bool IVTVDevPreInit(ScrnInfoPtr pScrn, int flags)
304
{
305
	IVTVDevPtr fPtr;
306
	int default_depth, fbbpp;
307
	const char *mod = NULL;
308
	const char **syms = NULL;
309
310
	if (flags & PROBE_DETECT)
311
		return FALSE;
312
313
	TRACE_ENTER("PreInit");
314
315
	/* Check the number of entities, and fail if it isn't one. */
316
	if (pScrn->numEntities != 1)
317
		return FALSE;
318
319
	pScrn->monitor = pScrn->confScreen->monitor;
320
321
	IVTVDevGetRec(pScrn);
322
	fPtr = IVTVDEVPTR(pScrn);
323
324
	fPtr->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
325
326
	pScrn->racMemFlags = RAC_FB | RAC_COLORMAP | RAC_CURSOR | RAC_VIEWPORT;
327
	/* XXX Is this right?  Can probably remove RAC_FB */
328
	pScrn->racIoFlags = RAC_FB | RAC_COLORMAP | RAC_CURSOR | RAC_VIEWPORT;
329
330
	if (fPtr->pEnt->location.type == BUS_PCI &&
331
	    xf86RegisterResources(fPtr->pEnt->index, NULL, ResExclusive)) {
332
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
333
			   "xf86RegisterResources() found resource conflicts\n");
334
		return FALSE;
335
	}
336
337
	/* open device */
338
	if (!ivtvHWInit
339
	    (pScrn, NULL,
340
	     xf86FindOptionValue(fPtr->pEnt->device->options, "fbdev")))
341
		return FALSE;
342
	default_depth = ivtvHWGetDepth(pScrn, &fbbpp);
343
	if (!xf86SetDepthBpp(pScrn, default_depth, default_depth, fbbpp, 0))
344
		return FALSE;
345
	xf86PrintDepthBpp(pScrn);
346
347
	/* Get the depth24 pixmap format */
348
	if (pScrn->depth == 24 && pix24bpp == 0)
349
		pix24bpp = xf86GetBppFromDepth(pScrn, 24);
350
351
	/* color weight */
352
	if (pScrn->depth > 8) {
353
		rgb zeros = { 0, 0, 0 };
354
		if (!xf86SetWeight(pScrn, zeros, zeros))
355
			return FALSE;
356
	}
357
358
	/* visual init */
359
	if (!xf86SetDefaultVisual(pScrn, -1))
360
		return FALSE;
361
362
	/* We don't currently support DirectColor at > 8bpp */
363
	if (pScrn->depth > 8 && pScrn->defaultVisual != TrueColor) {
364
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Given default visual"
365
			   " (%s) is not supported at depth %d\n",
366
			   xf86GetVisualName(pScrn->defaultVisual),
367
			   pScrn->depth);
368
		return FALSE;
369
	}
370
371
	{
372
		Gamma zeros = { 0.0, 0.0, 0.0 };
373
374
		if (!xf86SetGamma(pScrn, zeros)) {
375
			return FALSE;
376
		}
377
	}
378
379
	pScrn->progClock = TRUE;
380
	pScrn->rgbBits = 8;
381
	pScrn->chipset = "ivtvdev";
382
	pScrn->videoRam = ivtvHWGetVidmem(pScrn);
383
384
	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Hardware: %s (vidmem: %dk)\n",
385
		   ivtvHWGetName(pScrn), pScrn->videoRam / 1024);
386
387
	/* handle options */
388
	xf86CollectOptions(pScrn, NULL);
389
	if (!(fPtr->Options = xalloc(sizeof(IVTVDevOptions))))
390
		return FALSE;
391
	memcpy(fPtr->Options, IVTVDevOptions, sizeof(IVTVDevOptions));
392
	xf86ProcessOptions(pScrn->scrnIndex, fPtr->pEnt->device->options,
393
			   fPtr->Options);
394
395
	/* select video modes */
396
397
	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
398
		   "Checking Modes against framebuffer device...\n");
399
	ivtvHWSetVideoModes(pScrn);
400
401
	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
402
		   "Checking Modes against monitor...\n");
403
	{
404
		DisplayModePtr mode, first = mode = pScrn->modes;
405
406
		if (mode != NULL)
407
			do {
408
				mode->status =
409
				    xf86CheckModeForMonitor(mode,
410
							    pScrn->monitor);
411
				mode = mode->next;
412
			} while (mode != NULL && mode != first);
413
414
		xf86PruneDriverModes(pScrn);
415
	}
416
417
	if (NULL == pScrn->modes)
418
		ivtvHWUseBuildinMode(pScrn);
419
	pScrn->currentMode = pScrn->modes;
420
421
	pScrn->displayWidth = pScrn->virtualX;	/* ShadowFB handles this correctly */
422
423
	xf86PrintModes(pScrn);
424
425
	/* Set display resolution */
426
	xf86SetDpi(pScrn, 0, 0);
427
428
	/* Load bpp-specific modules */
429
	mod = "fb";
430
	syms = fbSymbols;
431
432
	if (mod && xf86LoadSubModule(pScrn, mod) == NULL) {
433
		IVTVDevFreeRec(pScrn);
434
		return FALSE;
435
	}
436
	if (mod && syms) {
437
		xf86LoaderReqSymLists(syms, NULL);
438
	}
439
440
	/* Load shadow */
441
	xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
442
		   "Using \"Shadow Framebuffer\"\n");
443
	if (!xf86LoadSubModule(pScrn, "shadow")) {
444
		IVTVDevFreeRec(pScrn);
445
		return FALSE;
446
	}
447
	xf86LoaderReqSymLists(shadowSymbols, NULL);
448
449
	TRACE_EXIT("PreInit");
450
	return TRUE;
451
}
452
453
void IvtvInitVideo(ScreenPtr pScreen);
454
455
static Bool
456
IVTVDevScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
457
{
458
	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
459
	IVTVDevPtr fPtr = IVTVDEVPTR(pScrn);
460
	VisualPtr visual;
461
	int init_picture = 0;
462
	int ret, flags, width, height;
463
464
	TRACE_ENTER("IVTVDevScreenInit");
465
466
	ErrorF("\tbitsPerPixel=%d, depth=%d, defaultVisual=%s\n"
467
	       "\tmask: %x,%x,%x, offset: %d,%d,%d\n",
468
	       pScrn->bitsPerPixel,
469
	       pScrn->depth,
470
	       xf86GetVisualName(pScrn->defaultVisual),
471
	       pScrn->mask.red, pScrn->mask.green, pScrn->mask.blue,
472
	       pScrn->offset.red, pScrn->offset.green, pScrn->offset.blue);
473
474
	ivtvHWSave(pScrn);
475
476
	if (!ivtvHWModeInit(pScrn, pScrn->currentMode)) {
477
		xf86DrvMsg(scrnIndex, X_ERROR, "Mode init failed\n");
478
		return FALSE;
479
	}
480
	ivtvHWSaveScreen(pScreen, SCREEN_SAVER_ON);
481
	ivtvHWAdjustFrame(scrnIndex, 0, 0, 0);
482
483
	/* mi layer */
484
	miClearVisualTypes();
485
	if (pScrn->bitsPerPixel > 8) {
486
		if (!miSetVisualTypes
487
		    (pScrn->depth, TrueColorMask, pScrn->rgbBits, TrueColor)) {
488
			xf86DrvMsg(scrnIndex, X_ERROR,
489
				   "Set visual types failed\n");
490
			return FALSE;
491
		}
492
	} else {
493
		if (!miSetVisualTypes(pScrn->depth,
494
				      miGetDefaultVisualMask(pScrn->depth),
495
				      pScrn->rgbBits, pScrn->defaultVisual)) {
496
			xf86DrvMsg(scrnIndex, X_ERROR,
497
				   "Set visual types failed\n");
498
			return FALSE;
499
		}
500
	}
501
	if (!miSetPixmapDepths()) {
502
		xf86DrvMsg(scrnIndex, X_ERROR, "Set pixmap depths failed\n");
503
		return FALSE;
504
	}
505
506
	height = pScrn->virtualY;
507
	width = pScrn->virtualX;
508
509
	/* shadowfb */
510
	if ((fPtr->shadowmem = shadowAlloc(width, height,
511
					   pScrn->bitsPerPixel)) == NULL) {
512
		xf86DrvMsg(scrnIndex, X_ERROR,
513
			   "Allocation of shadow memory failed\n");
514
		return FALSE;
515
	}
516
517
	ret = fbScreenInit(pScreen, fPtr->shadowmem, width, height,
518
			   pScrn->xDpi, pScrn->yDpi, pScrn->displayWidth,
519
			   pScrn->bitsPerPixel);
520
	init_picture = 1;
521
522
	if (!ret)
523
		return FALSE;
524
525
	if (pScrn->bitsPerPixel > 8) {
526
		/* Fixup RGB ordering */
527
		visual = pScreen->visuals + pScreen->numVisuals;
528
		while (--visual >= pScreen->visuals) {
529
			if ((visual->class | DynamicClass) == DirectColor) {
530
				visual->offsetRed = pScrn->offset.red;
531
				visual->offsetGreen = pScrn->offset.green;
532
				visual->offsetBlue = pScrn->offset.blue;
533
				visual->redMask = pScrn->mask.red;
534
				visual->greenMask = pScrn->mask.green;
535
				visual->blueMask = pScrn->mask.blue;
536
			}
537
		}
538
	}
539
540
	/* must be after RGB ordering fixed */
541
	if (init_picture && !fbPictureInit(pScreen, NULL, 0))
542
		xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
543
			   "RENDER extension initialisation failed.\n");
544
545
	if (!shadowSetup(pScreen) || !shadowAdd(pScreen, NULL,
546
						FBshadowUpdatePacked,
547
						NULL, 0, NULL)) {
548
		xf86DrvMsg(scrnIndex, X_ERROR,
549
			   "Shadow framebuffer initialization failed.\n");
550
		return FALSE;
551
	}
552
553
	/*      IVTVDGAInit(pScreen);
554
	 */
555
556
	if (pScrn->bitsPerPixel == 24)
557
		xf86DrvMsg(scrnIndex, X_WARNING,
558
			   "Rotation might be broken in 24 bpp\n");
559
560
	xf86SetBlackWhitePixels(pScreen);
561
	miInitializeBackingStore(pScreen);
562
	xf86SetBackingStore(pScreen);
563
564
	/* software cursor */
565
	miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
566
567
	/* XXX It would be simpler to use miCreateDefColormap() in all cases. */
568
	if (!miCreateDefColormap(pScreen))
569
		return FALSE;
570
571
	flags = CMAP_PALETTED_TRUECOLOR;
572
	if (!xf86HandleColormaps
573
	    (pScreen, 256, 8, ivtvHWLoadPalette, NULL, flags))
574
		return FALSE;
575
576
	xf86DPMSInit(pScreen, ivtvHWDPMSSet, 0);
577
578
	pScreen->SaveScreen = ivtvHWSaveScreen;
579
580
	/* Wrap the current CloseScreen function */
581
	fPtr->CloseScreen = pScreen->CloseScreen;
582
	pScreen->CloseScreen = IVTVDevCloseScreen;
583
584
	{
585
            ErrorF("Init Video\n");
586
		IvtvInitVideo(pScreen);
587
	}
588
589
	TRACE_EXIT("IVTVDevScreenInit");
590
591
	return TRUE;
592
}
593
594
static Bool IVTVDevCloseScreen(int scrnIndex, ScreenPtr pScreen)
595
{
596
	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
597
	IVTVDevPtr fPtr = IVTVDEVPTR(pScrn);
598
599
	ivtvHWRestore(pScrn);
600
	xfree(fPtr->shadowmem);
601
	pScrn->vtSema = FALSE;
602
603
	pScreen->CloseScreen = fPtr->CloseScreen;
604
	return (*pScreen->CloseScreen) (scrnIndex, pScreen);
605
}
(-)ivtvdrv-noX-no-autotools/xc/programs/Xserver/hw/xfree86/drivers/ivtv/ivtvdev.h (-17 lines)
Lines 1-17 Link Here
1
/* -------------------------------------------------------------------- */
2
/* our private data, and two functions to allocate/free this            */
3
4
typedef struct {
5
	int lineLength;
6
	unsigned char *shadowmem;
7
	CloseScreenProcPtr CloseScreen;
8
	DGAModePtr pDGAMode;
9
	int nDGAMode;
10
	void (*PointerMoved) (int index, int x, int y);
11
	EntityInfoPtr pEnt;
12
	OptionInfoPtr Options;
13
} IVTVDevRec, *IVTVDevPtr;
14
15
#define IVTVDEVPTR(p) ((IVTVDevPtr)((p)->driverPrivate))
16
17
Bool IVTVDGAInit(ScreenPtr pScreen);
(-)ivtvdrv-noX-no-autotools/xc/programs/Xserver/hw/xfree86/drivers/ivtv/ivtvhw.c (-819 lines)
Lines 1-819 Link Here
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/ivtvhw/ivtvhw.c,v 1.30 2002/11/25 14:05:00 eich Exp $ */
2
3
#include "ivtvhw.h"
4
5
/* all driver need this */
6
#include "xf86.h"
7
#include "xf86_OSproc.h"
8
#include "xf86_ansic.h"
9
10
/* pci stuff */
11
#include "xf86PciInfo.h"
12
#include "xf86Pci.h"
13
14
#include "xf86cmap.h"
15
16
#include "fbpriv.h"
17
18
#include "asm/page.h"		/* #define for PAGE_* */
19
#include "globals.h"
20
#define DPMS_SERVER
21
#include "extensions/dpms.h"
22
23
#define DEBUG 0
24
25
#if DEBUG
26
# define TRACE_ENTER(str)	ErrorF("ivtvHW: " str " %d\n",pScrn->scrnIndex)
27
#else
28
# define TRACE_ENTER(str)
29
#endif
30
31
/* -------------------------------------------------------------------- */
32
33
#ifdef XFree86LOADER
34
35
static MODULESETUPPROTO(ivtvhwSetup);
36
37
static XF86ModuleVersionInfo ivtvHWVersRec = {
38
	"ivtvhw",
39
	MODULEVENDORSTRING,
40
	MODINFOSTRING1,
41
	MODINFOSTRING2,
42
	XF86_VERSION_CURRENT,
43
	0, 0, 2,
44
	ABI_CLASS_VIDEODRV,
45
	ABI_VIDEODRV_VERSION,
46
	MOD_CLASS_NONE,
47
	{0, 0, 0, 0}
48
};
49
50
XF86ModuleData ivtvhwModuleData = { &ivtvHWVersRec, ivtvhwSetup, NULL };
51
52
static pointer
53
ivtvhwSetup(pointer module, pointer opts, int *errmaj, int *errmin)
54
{
55
	const char *osname;
56
57
	/* Check that we're being loaded on a Linux system */
58
	LoaderGetOS(&osname, NULL, NULL, NULL);
59
	if (!osname || strcmp(osname, "linux") != 0) {
60
		if (errmaj)
61
			*errmaj = LDR_BADOS;
62
		if (errmin)
63
			*errmin = 0;
64
		return NULL;
65
	} else {
66
		/* OK */
67
		return (pointer) 1;
68
	}
69
}
70
71
#else				/* XFree86LOADER */
72
73
#include <fcntl.h>
74
#include <errno.h>
75
#include <sys/mman.h>
76
77
#endif				/* XFree86LOADER */
78
79
/* -------------------------------------------------------------------- */
80
/* our private data, and two functions to allocate/free this            */
81
82
int ivtvHWPrivateIndex = -1;
83
84
Bool ivtvHWGetRec(ScrnInfoPtr pScrn)
85
{
86
	ivtvHWPtr fPtr;
87
88
	if (ivtvHWPrivateIndex < 0)
89
		ivtvHWPrivateIndex = xf86AllocateScrnInfoPrivateIndex();
90
91
	if (FBDEVHWPTR(pScrn) != NULL)
92
		return TRUE;
93
94
	fPtr = FBDEVHWPTRLVAL(pScrn) = xnfcalloc(sizeof(ivtvHWRec), 1);
95
	return TRUE;
96
}
97
98
void ivtvHWFreeRec(ScrnInfoPtr pScrn)
99
{
100
	if (ivtvHWPrivateIndex < 0)
101
		return;
102
	if (FBDEVHWPTR(pScrn) == NULL)
103
		return;
104
	xfree(FBDEVHWPTR(pScrn));
105
	FBDEVHWPTRLVAL(pScrn) = NULL;
106
}
107
108
/* -------------------------------------------------------------------- */
109
/* some helpers for printing debug informations                         */
110
111
#if DEBUG
112
static void print_ivtv_mode(char *txt, struct fb_var_screeninfo *var)
113
{
114
	ErrorF("ivtv %s mode:\t%d   %d %d %d %d   %d %d %d %d   %d %d:%d:%d\n",
115
	       txt, var->pixclock,
116
	       var->xres, var->right_margin, var->hsync_len, var->left_margin,
117
	       var->yres, var->lower_margin, var->vsync_len, var->upper_margin,
118
	       var->bits_per_pixel,
119
	       var->red.length, var->green.length, var->blue.length);
120
}
121
122
static void print_xfree_mode(char *txt, DisplayModePtr mode)
123
{
124
	ErrorF("xfree %s mode:\t%d   %d %d %d %d   %d %d %d %d\n",
125
	       txt, mode->Clock,
126
	       mode->HDisplay, mode->HSyncStart, mode->HSyncEnd, mode->HTotal,
127
	       mode->VDisplay, mode->VSyncStart, mode->VSyncEnd, mode->VTotal);
128
}
129
#endif
130
131
/* -------------------------------------------------------------------- */
132
/* Convert timings between the XFree and the Frame Buffer Device        */
133
134
static void
135
xfree2ivtv_fblayout(ScrnInfoPtr pScrn, struct fb_var_screeninfo *var)
136
{
137
	var->xres_virtual = pScrn->virtualX;
138
	var->yres_virtual = pScrn->virtualY;
139
	var->bits_per_pixel = pScrn->bitsPerPixel;
140
	var->red.length = pScrn->weight.red;
141
	var->green.length = pScrn->weight.green;
142
	var->blue.length = pScrn->weight.blue;
143
}
144
145
static void
146
xfree2ivtv_timing(DisplayModePtr mode, struct fb_var_screeninfo *var)
147
{
148
	var->xres = mode->HDisplay;
149
	var->yres = mode->VDisplay;
150
	if (var->xres_virtual < var->xres)
151
		var->xres_virtual = var->xres;
152
	if (var->yres_virtual < var->yres)
153
		var->yres_virtual = var->yres;
154
	var->xoffset = var->yoffset = 0;
155
	var->pixclock = mode->Clock ? 1000000000 / mode->Clock : 0;
156
	var->right_margin = mode->HSyncStart - mode->HDisplay;
157
	var->hsync_len = mode->HSyncEnd - mode->HSyncStart;
158
	var->left_margin = mode->HTotal - mode->HSyncEnd;
159
	var->lower_margin = mode->VSyncStart - mode->VDisplay;
160
	var->vsync_len = mode->VSyncEnd - mode->VSyncStart;
161
	var->upper_margin = mode->VTotal - mode->VSyncEnd;
162
	var->sync = 0;
163
	if (mode->Flags & V_PHSYNC)
164
		var->sync |= FB_SYNC_HOR_HIGH_ACT;
165
	if (mode->Flags & V_PVSYNC)
166
		var->sync |= FB_SYNC_VERT_HIGH_ACT;
167
	if (mode->Flags & V_PCSYNC)
168
		var->sync |= FB_SYNC_COMP_HIGH_ACT;
169
#if 1				/* Badly needed for PAL/NTSC on Amiga (amifb)!! [geert] */
170
	if (mode->Flags & V_BCAST)
171
		var->sync |= FB_SYNC_BROADCAST;
172
#endif
173
	if (mode->Flags & V_INTERLACE)
174
		var->vmode = FB_VMODE_INTERLACED;
175
	else if (mode->Flags & V_DBLSCAN)
176
		var->vmode = FB_VMODE_DOUBLE;
177
	else
178
		var->vmode = FB_VMODE_NONINTERLACED;
179
}
180
181
static void
182
ivtv2xfree_timing(struct fb_var_screeninfo *var, DisplayModePtr mode)
183
{
184
	mode->Clock = var->pixclock ? 1000000000 / var->pixclock : 28000000;
185
	mode->HDisplay = var->xres;
186
	mode->HSyncStart = mode->HDisplay + var->right_margin;
187
	mode->HSyncEnd = mode->HSyncStart + var->hsync_len;
188
	mode->HTotal = mode->HSyncEnd + var->left_margin;
189
	mode->VDisplay = var->yres;
190
	mode->VSyncStart = mode->VDisplay + var->lower_margin;
191
	mode->VSyncEnd = mode->VSyncStart + var->vsync_len;
192
	mode->VTotal = mode->VSyncEnd + var->upper_margin;
193
	mode->Flags = 0;
194
	mode->Flags |= var->sync & FB_SYNC_HOR_HIGH_ACT ? V_PHSYNC : V_NHSYNC;
195
	mode->Flags |= var->sync & FB_SYNC_VERT_HIGH_ACT ? V_PVSYNC : V_NVSYNC;
196
	mode->Flags |= var->sync & FB_SYNC_COMP_HIGH_ACT ? V_PCSYNC : V_NCSYNC;
197
#if 1				/* Badly needed for PAL/NTSC on Amiga (amifb)!! [geert] */
198
	if (var->sync & FB_SYNC_BROADCAST)
199
		mode->Flags |= V_BCAST;
200
#endif
201
	if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED)
202
		mode->Flags |= V_INTERLACE;
203
	else if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE)
204
		mode->Flags |= V_DBLSCAN;
205
	mode->SynthClock = mode->Clock;
206
	mode->CrtcHDisplay = mode->HDisplay;
207
	mode->CrtcHSyncStart = mode->HSyncStart;
208
	mode->CrtcHSyncEnd = mode->HSyncEnd;
209
	mode->CrtcHTotal = mode->HTotal;
210
	mode->CrtcVDisplay = mode->VDisplay;
211
	mode->CrtcVSyncStart = mode->VSyncStart;
212
	mode->CrtcVSyncEnd = mode->VSyncEnd;
213
	mode->CrtcVTotal = mode->VTotal;
214
	mode->CrtcHAdjusted = FALSE;
215
	mode->CrtcVAdjusted = FALSE;
216
}
217
218
/* -------------------------------------------------------------------- */
219
/* open correct framebuffer device                                      */
220
221
/* try to find the framebuffer device for a given PCI device */
222
struct v4l2_capability {
223
	__u8 driver[16];	/* i.e. "bttv" */
224
	__u8 card[32];		/* i.e. "Hauppauge WinTV" */
225
	__u8 bus_info[32];	/* "PCI:" + pci_name(pci_dev) */
226
	__u32 version;		/* should use KERNEL_VERSION() */
227
	__u32 capabilities;	/* Device capabilities */
228
	__u32 reserved[4];
229
};
230
#define VIDIOC_QUERYCAP		_IOR  ('V',  0, struct v4l2_capability)
231
232
static int ivtv_open(int scrnIndex, char *dev, char **namep, ivtvHWPtr fPtr)
233
{
234
	struct fb_fix_screeninfo fix;
235
	int fd;
236
237
	/* try argument (from XF86Config) first */
238
	if (dev) {
239
		fd = open(dev, O_RDWR, 0);
240
	} else {
241
		/* second: environment variable */
242
		dev = getenv("FRAMEBUFFER");
243
		if ((NULL == dev) || ((fd = open(dev, O_RDWR, 0)) == -1)) {
244
			/* last try: default device */
245
			dev = "/dev/fb0";
246
			fd = open(dev, O_RDWR, 0);
247
		}
248
	}
249
250
	if (fd == -1) {
251
		xf86DrvMsg(scrnIndex, X_ERROR,
252
			   "open %s: %s\n", dev, strerror(errno));
253
		return -1;
254
	}
255
256
	if (namep) {
257
		if (-1 == ioctl(fd, FBIOGET_FSCREENINFO, (void *)(&fix))) {
258
			*namep = NULL;
259
			xf86DrvMsg(scrnIndex, X_ERROR,
260
				   "FBIOGET_FSCREENINFO: %s\n",
261
				   strerror(errno));
262
			return -1;
263
		} else {
264
			*namep = xnfalloc(16);
265
			strncpy(*namep, fix.id, 16);
266
		}
267
	}
268
	if (fd != -1 && fPtr) {
269
		int fbufId = 255;
270
		int yuvId;
271
                char *devid = dev+7;
272
                if (*devid == '/')
273
                    devid++;
274
		sscanf(devid, "%d", &fbufId);
275
                
276
                xf86DrvMsg(scrnIndex, X_ERROR,"Framebuffer id from dev %sis %d\n",dev, fbufId);
277
278
		for (yuvId = 48; yuvId < 64 && fPtr->yuvDevName == NULL;
279
		     yuvId++) {
280
			char yuvDev[20] = "/dev/video";
281
			char yuvDevFull[20];
282
			char yuvDevFull1[20];
283
			int yuvFd;
284
			sprintf(yuvDevFull, "%s%d", yuvDev, yuvId);
285
			yuvFd = open(yuvDevFull, O_RDONLY);
286
                        xf86DrvMsg(scrnIndex, X_ERROR,"open %s returned  %d\n",yuvDevFull, yuvFd);
287
288
			if (yuvFd == -1 && errno == ENODEV) {
289
				sprintf(yuvDevFull1, "%s%d", yuvDev,
290
					yuvId - 48);
291
				yuvFd = open(yuvDevFull1, O_RDONLY);
292
                                xf86DrvMsg(scrnIndex, X_ERROR,"2nd open %s returned  %d\n",yuvDevFull, yuvFd);
293
			}
294
295
			if (yuvFd != -1) {
296
				int yuvFbId=-1;
297
                                int ret = ioctl(yuvFd, IVTV_IOC_GET_FB, &yuvFbId);
298
                                xf86DrvMsg(scrnIndex, X_ERROR,"get_fb returned  %d fbid %d\n",ret, yuvFbId);
299
				if (ret != -1 && yuvFbId == fbufId) {
300
					struct v4l2_capability vcap;
301
					memset(&vcap, 0, sizeof(vcap));
302
					if (ioctl(yuvFd, VIDIOC_QUERYCAP, &vcap)
303
					    < 0) {
304
						ErrorF
305
						    ("Can't query driver version so not adding Xv support on %s\n",
306
						     yuvDevFull);
307
					} else {
308
						if (vcap.version >= 0x306) {
309
							fPtr->yuvDevName =
310
							    strdup(yuvDevFull);
311
						} else {
312
							ErrorF
313
							    ("Version of ivtv is too old to support Xv\n");
314
						}
315
316
					}
317
				}
318
				close(yuvFd);
319
			}
320
321
		}
322
	}
323
	return fd;
324
}
325
326
/* -------------------------------------------------------------------- */
327
328
Bool ivtvHWProbe(pciVideoPtr pPci, char *device, char **namep)
329
{
330
	int fd;
331
	Bool retVal = TRUE;
332
	struct ivtvfb_ioctl_state_info state;
333
	fd = ivtv_open(-1, device, namep, NULL);
334
335
	if (-1 == fd)
336
		return FALSE;
337
338
	if (0 != ioctl(fd, IVTVFB_IOCTL_GET_STATE, (void *)&state)) {
339
		xf86DrvMsg(0, X_ERROR,
340
			   "ivtvHWProvbe failed to do IVTVFB_IOCTL_GET_STATE for device %s\n",
341
			   device);
342
343
		retVal = FALSE;
344
	}
345
	close(fd);
346
	return retVal;
347
}
348
349
Bool ivtvHWInit(ScrnInfoPtr pScrn, pciVideoPtr pPci, char *device)
350
{
351
	ivtvHWPtr fPtr;
352
353
	TRACE_ENTER("Init");
354
	ivtvHWGetRec(pScrn);
355
	fPtr = FBDEVHWPTR(pScrn);
356
	fPtr->fd_yuv = -1;
357
	fPtr->yuvDevName = NULL;
358
	/* open device */
359
360
	fPtr->fd = ivtv_open(pScrn->scrnIndex, device, NULL, fPtr);
361
362
	if (-1 == fPtr->fd) {
363
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
364
			   "Failed to open framebuffer device, consult warnings"
365
			   " and/or errors above for possible reasons\n"
366
			   "\t(you may have to look at the server log to see"
367
			   " warnings)\n");
368
		return FALSE;
369
	}
370
371
	/* get current fb device settings */
372
	if (-1 == ioctl(fPtr->fd, FBIOGET_FSCREENINFO, (void *)(&fPtr->fix))) {
373
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
374
			   "ioctl FBIOGET_FSCREENINFO: %s\n", strerror(errno));
375
		return FALSE;
376
	}
377
	if (-1 == ioctl(fPtr->fd, FBIOGET_VSCREENINFO, (void *)(&fPtr->var))) {
378
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
379
			   "ioctl FBIOGET_VSCREENINFO: %s\n", strerror(errno));
380
		return FALSE;
381
	}
382
383
	/* we can use the current settings as "buildin mode" */
384
	ivtv2xfree_timing(&fPtr->var, &fPtr->buildin);
385
	fPtr->buildin.name = "current";
386
	fPtr->buildin.next = &fPtr->buildin;
387
	fPtr->buildin.prev = &fPtr->buildin;
388
	fPtr->buildin.type |= M_T_BUILTIN;
389
390
	return TRUE;
391
}
392
393
char *ivtvHWGetName(ScrnInfoPtr pScrn)
394
{
395
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
396
	return fPtr->fix.id;
397
}
398
399
int ivtvHWGetDepth(ScrnInfoPtr pScrn, int *fbbpp)
400
{
401
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
402
403
	if (fbbpp)
404
		*fbbpp = fPtr->var.bits_per_pixel;
405
406
	if (fPtr->fix.visual == FB_VISUAL_TRUECOLOR ||
407
	    fPtr->fix.visual == FB_VISUAL_DIRECTCOLOR)
408
		return fPtr->var.red.length + fPtr->var.green.length +
409
		    fPtr->var.blue.length;
410
	else
411
		return fPtr->var.bits_per_pixel;
412
}
413
414
int ivtvHWGetLineLength(ScrnInfoPtr pScrn)
415
{
416
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
417
418
	if (fPtr->fix.line_length)
419
		return fPtr->fix.line_length;
420
	else
421
		return fPtr->var.xres_virtual * fPtr->var.bits_per_pixel / 8;
422
}
423
424
int ivtvHWGetType(ScrnInfoPtr pScrn)
425
{
426
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
427
	return fPtr->fix.type;
428
}
429
430
int ivtvHWGetVidmem(ScrnInfoPtr pScrn)
431
{
432
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
433
	return fPtr->fix.smem_len;
434
}
435
436
void ivtvHWSetVideoModes(ScrnInfoPtr pScrn)
437
{
438
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
439
	int virtX = pScrn->display->virtualX;
440
	int virtY = pScrn->display->virtualY;
441
	struct fb_var_screeninfo var;
442
	char **modename;
443
	DisplayModePtr mode, this, last = NULL;
444
445
	TRACE_ENTER("VerifyModes");
446
	if (NULL == pScrn->display->modes)
447
		return;
448
449
	for (modename = pScrn->display->modes; *modename != NULL; modename++) {
450
		for (mode = pScrn->monitor->Modes; mode != NULL;
451
		     mode = mode->next)
452
			if (0 == strcmp(mode->name, *modename))
453
				break;
454
		if (NULL == mode) {
455
			xf86DrvMsg(pScrn->scrnIndex, X_INFO,
456
				   "\tmode \"%s\" not found\n", *modename);
457
			continue;
458
		}
459
		memset(&var, 0, sizeof(var));
460
		xfree2ivtv_timing(mode, &var);
461
		var.xres_virtual = virtX;
462
		var.yres_virtual = virtY;
463
		var.bits_per_pixel = pScrn->bitsPerPixel;
464
		var.red.length = pScrn->weight.red;
465
		var.green.length = pScrn->weight.green;
466
		var.blue.length = pScrn->weight.blue;
467
468
		var.activate = FB_ACTIVATE_TEST;
469
		if (var.xres_virtual < var.xres)
470
			var.xres_virtual = var.xres;
471
		if (var.yres_virtual < var.yres)
472
			var.yres_virtual = var.yres;
473
		if (-1 == ioctl(fPtr->fd, FBIOPUT_VSCREENINFO, (void *)(&var))) {
474
			xf86DrvMsg(pScrn->scrnIndex, X_INFO,
475
				   "\tmode \"%s\" test failed\n", *modename);
476
			continue;
477
		}
478
		xf86DrvMsg(pScrn->scrnIndex, X_INFO,
479
			   "\tmode \"%s\" ok\n", *modename);
480
		if (virtX < var.xres)
481
			virtX = var.xres;
482
		if (virtY < var.yres)
483
			virtY = var.yres;
484
		if (NULL == pScrn->modes) {
485
			pScrn->modes = xnfalloc(sizeof(DisplayModeRec));
486
			this = pScrn->modes;
487
			memcpy(this, mode, sizeof(DisplayModeRec));
488
			this->next = this;
489
			this->prev = this;
490
		} else {
491
			this = xnfalloc(sizeof(DisplayModeRec));
492
			memcpy(this, mode, sizeof(DisplayModeRec));
493
			this->next = pScrn->modes;
494
			this->prev = last;
495
			last->next = this;
496
			pScrn->modes->prev = this;
497
		}
498
		last = this;
499
	}
500
	pScrn->virtualX = virtX;
501
	pScrn->virtualY = virtY;
502
}
503
504
DisplayModePtr ivtvHWGetBuildinMode(ScrnInfoPtr pScrn)
505
{
506
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
507
	return &fPtr->buildin;
508
}
509
510
void ivtvHWUseBuildinMode(ScrnInfoPtr pScrn)
511
{
512
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
513
514
	TRACE_ENTER("UseBuildinMode");
515
	pScrn->modes = &fPtr->buildin;
516
	pScrn->virtualX = pScrn->display->virtualX;
517
	pScrn->virtualY = pScrn->display->virtualY;
518
	if (pScrn->virtualX < fPtr->buildin.HDisplay)
519
		pScrn->virtualX = fPtr->buildin.HDisplay;
520
	if (pScrn->virtualY < fPtr->buildin.VDisplay)
521
		pScrn->virtualY = fPtr->buildin.VDisplay;
522
}
523
524
/* -------------------------------------------------------------------- */
525
526
void ivtvcalculateFbmem_len(ivtvHWPtr fPtr)
527
{
528
	fPtr->fboff = (unsigned long)fPtr->fix.smem_start & ~PAGE_MASK;
529
	fPtr->fbmem_len = (fPtr->fboff + fPtr->fix.smem_len + ~PAGE_MASK) &
530
	    PAGE_MASK;
531
}
532
533
int ivtvHWLinearOffset(ScrnInfoPtr pScrn)
534
{
535
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
536
537
	TRACE_ENTER("LinearOffset");
538
	return fPtr->fboff;
539
}
540
541
/* -------------------------------------------------------------------- */
542
543
Bool ivtvHWModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
544
{
545
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
546
547
	TRACE_ENTER("ModeInit");
548
	xfree2ivtv_fblayout(pScrn, &fPtr->var);
549
	xfree2ivtv_timing(mode, &fPtr->var);
550
#if DEBUG
551
	print_xfree_mode("init", mode);
552
	print_ivtv_mode("init", &fPtr->var);
553
#endif
554
	pScrn->vtSema = TRUE;
555
556
	/* set */
557
	if (0 != ioctl(fPtr->fd, FBIOPUT_VSCREENINFO, (void *)(&fPtr->var))) {
558
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
559
			   "FBIOPUT_VSCREENINFO: %s\n", strerror(errno));
560
		return FALSE;
561
	}
562
	/* read back */
563
	if (0 != ioctl(fPtr->fd, FBIOGET_FSCREENINFO, (void *)(&fPtr->fix))) {
564
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
565
			   "FBIOGET_FSCREENINFO: %s\n", strerror(errno));
566
		return FALSE;
567
	}
568
	if (0 != ioctl(fPtr->fd, FBIOGET_VSCREENINFO, (void *)(&fPtr->var))) {
569
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
570
			   "FBIOGET_VSCREENINFO: %s\n", strerror(errno));
571
		return FALSE;
572
	}
573
	return TRUE;
574
}
575
576
/* -------------------------------------------------------------------- */
577
/* video mode save/restore                                              */
578
579
/* TODO: colormap */
580
void ivtvHWSave(ScrnInfoPtr pScrn)
581
{
582
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
583
584
	TRACE_ENTER("Save");
585
	if (0 !=
586
	    ioctl(fPtr->fd, FBIOGET_VSCREENINFO, (void *)(&fPtr->saved_var)))
587
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
588
			   "FBIOGET_VSCREENINFO: %s\n", strerror(errno));
589
}
590
591
void ivtvHWRestore(ScrnInfoPtr pScrn)
592
{
593
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
594
595
	TRACE_ENTER("Restore");
596
	if (0 !=
597
	    ioctl(fPtr->fd, FBIOPUT_VSCREENINFO, (void *)(&fPtr->saved_var)))
598
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
599
			   "FBIOPUT_VSCREENINFO: %s\n", strerror(errno));
600
}
601
602
/* -------------------------------------------------------------------- */
603
/* callback for xf86HandleColormaps                                     */
604
605
void
606
ivtvHWLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
607
		  LOCO * colors, VisualPtr pVisual)
608
{
609
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
610
	struct fb_cmap cmap;
611
	unsigned short red, green, blue;
612
	int i;
613
614
	TRACE_ENTER("ModeInit");
615
	cmap.len = 1;
616
	cmap.red = &red;
617
	cmap.green = &green;
618
	cmap.blue = &blue;
619
	cmap.transp = NULL;
620
	for (i = 0; i < numColors; i++) {
621
		cmap.start = indices[i];
622
		red = (colors[indices[i]].red << 8) | colors[indices[i]].red;
623
		green = (colors[indices[i]].green << 8) |
624
		    colors[indices[i]].green;
625
		blue = (colors[indices[i]].blue << 8) | colors[indices[i]].blue;
626
		if (-1 == ioctl(fPtr->fd, FBIOPUTCMAP, (void *)&cmap))
627
			xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
628
				   "FBIOPUTCMAP: %s\n", strerror(errno));
629
	}
630
}
631
632
/* -------------------------------------------------------------------- */
633
/* these can be hooked directly into ScrnInfoRec                        */
634
635
int ivtvHWValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
636
{
637
	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
638
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
639
	struct fb_var_screeninfo var;
640
641
	TRACE_ENTER("ValidMode");
642
	memcpy(&var, &fPtr->var, sizeof(var));
643
	xfree2ivtv_timing(mode, &var);
644
	var.activate = FB_ACTIVATE_TEST;
645
	if (0 != ioctl(fPtr->fd, FBIOPUT_VSCREENINFO, (void *)(&fPtr->var))) {
646
		xf86DrvMsg(scrnIndex, X_ERROR,
647
			   "FBIOPUT_VSCREENINFO: %s\n", strerror(errno));
648
		return MODE_BAD;
649
	}
650
	return MODE_OK;
651
}
652
653
Bool ivtvHWSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
654
{
655
	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
656
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
657
658
	TRACE_ENTER("SwitchMode");
659
	xfree2ivtv_timing(mode, &fPtr->var);
660
	if (0 != ioctl(fPtr->fd, FBIOPUT_VSCREENINFO, (void *)(&fPtr->var))) {
661
		xf86DrvMsg(scrnIndex, X_ERROR,
662
			   "FBIOPUT_VSCREENINFO: %s\n", strerror(errno));
663
		return FALSE;
664
	}
665
	return TRUE;
666
}
667
668
void ivtvHWAdjustFrame(int scrnIndex, int x, int y, int flags)
669
{
670
	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
671
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
672
673
	TRACE_ENTER("AdjustFrame");
674
#ifdef JOHN
675
	fPtr->var.xoffset = x;
676
	fPtr->var.yoffset = y;
677
	if (-1 == ioctl(fPtr->fd, FBIOPAN_DISPLAY, (void *)&fPtr->var))
678
		xf86DrvMsgVerb(scrnIndex, 5, X_WARNING,
679
			       "FBIOPAN_DISPLAY: %s\n", strerror(errno));
680
#endif
681
}
682
683
Bool ivtvHWEnterVT(int scrnIndex, int flags)
684
{
685
	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
686
687
	TRACE_ENTER("EnterVT");
688
	if (!ivtvHWModeInit(pScrn, pScrn->currentMode))
689
		return FALSE;
690
	ivtvHWAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
691
	return TRUE;
692
}
693
694
void ivtvHWLeaveVT(int scrnIndex, int flags)
695
{
696
	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
697
698
	TRACE_ENTER("LeaveVT");
699
	ivtvHWRestore(pScrn);
700
}
701
702
void ivtvHWDPMSSet(ScrnInfoPtr pScrn, int mode, int flags)
703
{
704
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
705
	unsigned long fbmode;
706
707
	if (!pScrn->vtSema)
708
		return;
709
710
	switch (mode) {
711
	case DPMSModeOn:
712
		fbmode = 0;
713
		break;
714
	case DPMSModeStandby:
715
		fbmode = 2;
716
		break;
717
	case DPMSModeSuspend:
718
		fbmode = 3;
719
		break;
720
	case DPMSModeOff:
721
		fbmode = 4;
722
		break;
723
	default:
724
		return;
725
	}
726
727
#ifdef JOHN
728
	if (-1 == ioctl(fPtr->fd, FBIOBLANK, (void *)fbmode))
729
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
730
			   "FBIOBLANK: %s\n", strerror(errno));
731
#endif
732
}
733
734
Bool ivtvHWSaveScreen(ScreenPtr pScreen, int mode)
735
{
736
	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
737
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
738
	unsigned long unblank;
739
740
	if (!pScrn->vtSema)
741
		return TRUE;
742
743
	unblank = xf86IsUnblank(mode);
744
745
#ifdef JOHN
746
	if (-1 == ioctl(fPtr->fd, FBIOBLANK, (void *)(1 - unblank))) {
747
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
748
			   "FBIOBLANK: %s\n", strerror(errno));
749
		return FALSE;
750
	}
751
#endif
752
	return TRUE;
753
}
754
755
#define MAX_RETRY_DMA 10
756
char *lastScreen = NULL;
757
758
Bool ivtvHWSendDMA(ScrnInfoPtr pScrn, void *ptr, int x1, int x2, int y1, int y2)
759
{
760
	int totalScreenSize =
761
	    pScrn->virtualX * pScrn->virtualY * pScrn->bitsPerPixel / 8;
762
	int secondOffset = 0;
763
764
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
765
	struct ivtvfb_ioctl_dma_host_to_ivtv_args args;
766
	int cpt = MAX_RETRY_DMA;
767
768
	int startOffset =
769
	    (((y1) * pScrn->virtualX) + x1) * pScrn->bitsPerPixel / 8;
770
	int endOffset =
771
	    (((y2 - 1) * pScrn->virtualX) + x2) * pScrn->bitsPerPixel / 8;
772
773
	unsigned long totalData = endOffset - startOffset;
774
775
	if (totalData > 64 * 1024 * 4) {
776
		/* This is a bigger lump so send in 2 bits */
777
		totalData /= 2;
778
		totalData = (totalData + 65535) & ~65535;
779
		secondOffset = endOffset - totalData;
780
	} else
781
	{
782
		totalData = (totalData + 65535) & ~65535;
783
784
		if ((startOffset + totalData) > totalScreenSize) {
785
			startOffset -=
786
			    (startOffset + totalData) - totalScreenSize;
787
		}
788
	}
789
790
	args.source = ((char *)ptr + startOffset);
791
	args.dest_offset = startOffset;
792
	args.count = totalData;
793
794
	if (0 != ioctl(fPtr->fd, IVTVFB_IOCTL_PREP_FRAME, (void *)(&args))) {
795
		while (cpt--) {
796
			if (0 == ioctl(fPtr->fd,
797
				       IVTVFB_IOCTL_PREP_FRAME,
798
				       (void *)(&args)))
799
				break;
800
		}
801
	}
802
	if (secondOffset) {
803
		args.source = ((char *)ptr + secondOffset);
804
		args.dest_offset = secondOffset;
805
		args.count = totalData;
806
807
		if (0 != ioctl(fPtr->fd,
808
			       IVTVFB_IOCTL_PREP_FRAME, (void *)(&args))) {
809
			while (cpt--) {
810
				if (0 == ioctl(fPtr->fd,
811
					       IVTVFB_IOCTL_PREP_FRAME,
812
					       (void *)(&args)))
813
					break;
814
			}
815
		}
816
	}
817
818
	return TRUE;
819
}
(-)ivtvdrv-noX-no-autotools/xc/programs/Xserver/hw/xfree86/drivers/ivtv/ivtvhw.h (-86 lines)
Lines 1-86 Link Here
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/ivtvhw/ivtvhw.h,v 1.11 2001/10/01 13:44:12 eich Exp $ */
2
3
#ifndef _FBDEVHW_H_
4
#define _FBDEVHW_H_
5
#include "xf86str.h"
6
#include "colormapst.h"
7
#include <asm/ioctl.h>
8
#undef __STRICT_ANSI__
9
#include <inttypes.h>
10
#include <linux/ivtv.h>
11
12
#define FBDEVHW_PACKED_PIXELS		0	/* Packed Pixels        */
13
#define FBDEVHW_PLANES			1	/* Non interleaved planes */
14
#define FBDEVHW_INTERLEAVED_PLANES	2	/* Interleaved planes   */
15
#define FBDEVHW_TEXT			3	/* Text/attributes      */
16
#define FBDEVHW_VGA_PLANES		4	/* EGA/VGA planes       */
17
#include "fbpriv.h"
18
typedef struct {
19
	/* framebuffer device: filename (/dev/fb*), handle, more */
20
	char *device;
21
	int fd;
22
	char *yuvDevName;
23
	int fd_yuv;
24
	unsigned int fbmem_len;
25
	unsigned int fboff;
26
	char *mmio;
27
	unsigned int mmio_len;
28
29
	/* current hardware state */
30
	struct fb_fix_screeninfo fix;
31
	struct fb_var_screeninfo var;
32
33
	/* saved video mode */
34
	struct fb_var_screeninfo saved_var;
35
36
	/* buildin video mode */
37
	DisplayModeRec buildin;
38
39
} ivtvHWRec, *ivtvHWPtr;
40
extern int ivtvHWPrivateIndex;
41
42
#define FBDEVHWPTRLVAL(p) (p)->privates[ivtvHWPrivateIndex].ptr
43
#define FBDEVHWPTR(p) ((ivtvHWPtr)(FBDEVHWPTRLVAL(p)))
44
45
Bool IVTVDGAInit(ScreenPtr pScreen);
46
47
#define PCI_HAUPAGGE_VENDOR_ID       0x4444
48
49
Bool ivtvHWGetRec(ScrnInfoPtr pScrn);
50
void ivtvHWFreeRec(ScrnInfoPtr pScrn);
51
52
Bool ivtvHWProbe(pciVideoPtr pPci, char *device, char **namep);
53
Bool ivtvHWInit(ScrnInfoPtr pScrn, pciVideoPtr pPci, char *device);
54
55
char *ivtvHWGetName(ScrnInfoPtr pScrn);
56
int ivtvHWGetDepth(ScrnInfoPtr pScrn, int *fbbpp);
57
int ivtvHWGetLineLength(ScrnInfoPtr pScrn);
58
int ivtvHWGetType(ScrnInfoPtr pScrn);
59
int ivtvHWGetVidmem(ScrnInfoPtr pScrn);
60
61
/*void* ivtvHWMapVidmem(ScrnInfoPtr pScrn);*/
62
int ivtvHWLinearOffset(ScrnInfoPtr pScrn);
63
64
void ivtvHWSetVideoModes(ScrnInfoPtr pScrn);
65
DisplayModePtr ivtvHWGetBuildinMode(ScrnInfoPtr pScrn);
66
void ivtvHWUseBuildinMode(ScrnInfoPtr pScrn);
67
Bool ivtvHWModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode);
68
void ivtvHWSave(ScrnInfoPtr pScrn);
69
void ivtvHWRestore(ScrnInfoPtr pScrn);
70
71
void ivtvHWLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
72
		       LOCO * colors, VisualPtr pVisual);
73
74
int ivtvHWValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose,
75
		    int flags);
76
Bool ivtvHWSwitchMode(int scrnIndex, DisplayModePtr mode, int flags);
77
void ivtvHWAdjustFrame(int scrnIndex, int x, int y, int flags);
78
Bool ivtvHWEnterVT(int scrnIndex, int flags);
79
void ivtvHWLeaveVT(int scrnIndex, int flags);
80
void ivtvHWDPMSSet(ScrnInfoPtr pScrn, int mode, int flags);
81
82
Bool ivtvHWSaveScreen(ScreenPtr pScreen, int mode);
83
Bool ivtvHWSendDMA(ScrnInfoPtr pScrn, void *ptr, int x1, int x2, int y1,
84
		   int y2);
85
86
#endif
(-)ivtvdrv-noX-no-autotools/xc/programs/Xserver/hw/xfree86/drivers/ivtv/ivtv_xv.c (-785 lines)
Lines 1-785 Link Here
1
/* Based on s3virge xv code from XFree86 */
2
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/s3virge/s3v_xv.c,v 1.7 2003/02/04 02:20:50 dawes Exp $ */
3
/*
4
Copyright (C) 2000 The XFree86 Project, Inc.  All Rights Reserved.
5
6
Permission is hereby granted, free of charge, to any person obtaining a copy of
7
this software and associated documentation files (the "Software"), to deal in
8
the Software without restriction, including without limitation the rights to
9
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10
of the Software, and to permit persons to whom the Software is furnished to do
11
so, subject to the following conditions:
12
13
The above copyright notice and this permission notice shall be included in all
14
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, FIT-
18
NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
19
XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23
Except as contained in this notice, the name of the XFree86 Project shall not
24
be used in advertising or otherwise to promote the sale, use or other dealings
25
in this Software without prior written authorization from the XFree86 Project.
26
*/
27
28
/*
29
 * s3v_xv.c
30
 * X Video Extension support
31
 *
32
 * S3 ViRGE driver
33
 *
34
 * 7/2000 Kevin Brosius
35
 *
36
 * Useful references:
37
 * X Video extension support -> xc/programs/hw/xfree86/common/xf86xv.c
38
 *
39
 */
40
41
/*
42
 * I N C L U D E S
43
 */
44
#include "ivtvhw.h"
45
#include "ivtvdev.h"
46
47
#include "xf86.h"
48
#include "xf86xv.h"
49
#include "Xv.h"
50
#include "fourcc.h"
51
#include "regionstr.h"
52
typedef struct ivtv_xv_portData
53
{
54
    unsigned int colorKey;
55
    RegionRec    clip;
56
    int		 autopaintColorKey;
57
}Ivtv_Xv_PortData;
58
59
60
#define IVTV_MAX_PORTS 1
61
#define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE)
62
63
#if !defined(XvExtension) || !defined(IVTV_IOC_PREP_FRAME_YUV)
64
void IvtvInitVideo(ScreenPtr pScreen)
65
{
66
    ErrorF("XVDriver disabled at compilation time\n");
67
}
68
#else
69
70
static XF86VideoAdaptorPtr IVTVSetupImageVideoOverlay(ScreenPtr);
71
static int IVTVSetPortAttributeOverlay(ScrnInfoPtr, Atom, INT32, pointer);
72
static int IVTVGetPortAttributeOverlay(ScrnInfoPtr, Atom, INT32 *, pointer);
73
74
static void IVTVStopVideo(ScrnInfoPtr, pointer, Bool);
75
76
static void IVTVQueryBestSize(ScrnInfoPtr, Bool, short, short, short, short,
77
			      unsigned int *, unsigned int *, pointer);
78
static int IVTVPutImage(ScrnInfoPtr, short, short, short, short, short,
79
			short, short, short, int, unsigned char *, short,
80
			short, Bool, RegionPtr, pointer);
81
static int IVTVQueryImageAttributes(ScrnInfoPtr, int, unsigned short *,
82
				    unsigned short *, int *, int *);
83
84
void IvtvInitVideo(ScreenPtr pScreen)
85
{
86
	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
87
	XF86VideoAdaptorPtr *adaptors, *newAdaptors = NULL;
88
	XF86VideoAdaptorPtr newAdaptor = NULL;
89
	int num_adaptors;
90
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
91
	if (!fPtr->yuvDevName)
92
		return;
93
94
	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
95
		   "Enabling Xv support for PVR350\n");
96
	newAdaptor = IVTVSetupImageVideoOverlay(pScreen);
97
98
	num_adaptors = xf86XVListGenericAdaptors(pScrn, &adaptors);
99
100
	if (newAdaptor) {
101
		if (!num_adaptors) {
102
			num_adaptors = 1;
103
			adaptors = &newAdaptor;
104
		} else {
105
			newAdaptors =	/* need to free this someplace */
106
			    xalloc((num_adaptors +
107
				    1) * sizeof(XF86VideoAdaptorPtr *));
108
			if (newAdaptors) {
109
				memcpy(newAdaptors, adaptors, num_adaptors *
110
				       sizeof(XF86VideoAdaptorPtr));
111
				newAdaptors[num_adaptors] = newAdaptor;
112
				adaptors = newAdaptors;
113
				num_adaptors++;
114
			}
115
		}
116
	}
117
118
	if (num_adaptors)
119
		xf86XVScreenInit(pScreen, adaptors, num_adaptors);
120
121
	if (newAdaptors)
122
		xfree(newAdaptors);
123
}
124
125
/* client libraries expect an encoding */
126
static XF86VideoEncodingRec DummyEncoding[1] = {
127
	{			/* overlay limit */
128
	 0,
129
	 "XV_IMAGE",
130
	 768, 576,
131
	 {1, 1}
132
	 }
133
};
134
135
#define NUM_FORMATS_OVERLAY 4
136
#define NUM_FORMATS_TEXTURE 4
137
138
static XF86VideoFormatRec Formats[NUM_FORMATS_TEXTURE] = {
139
	/*{15, TrueColor}, */ {16, TrueColor}, {24, TrueColor}
140
	/* ,
141
	   {15, DirectColor} */ , {16, DirectColor}, {24, DirectColor}
142
};
143
144
#define NUM_IMAGES 1
145
146
static XF86ImageRec Images[NUM_IMAGES] = {
147
	XVIMAGE_YV12
148
	    /* XVIMAGE_UYVY */
149
};
150
151
#define NUM_ATTRIBUTES_OVERLAY 2
152
153
static XF86AttributeRec Attributes[NUM_ATTRIBUTES_OVERLAY] =
154
{
155
   {XvSettable | XvGettable, 0, (1 << 24) - 1, "XV_COLORKEY"},
156
   {XvSettable | XvGettable, 0, 1, "XV_AUTOPAINT_COLORKEY"},
157
158
#if 0
159
   {XvSettable | XvGettable, -128, 127, "XV_BRIGHTNESS"},
160
   {XvSettable | XvGettable, 0, 255, "XV_CONTRAST"}
161
#endif
162
};
163
static Atom  xvColorKey, xvAutopaintColorKey;
164
165
static int
166
IVTVSetPortAttributeOverlay(ScrnInfoPtr pScrn,
167
			    Atom attribute, INT32 value, pointer data)
168
{
169
	IVTVDevPtr devPtr = IVTVDEVPTR(pScrn);
170
        Ivtv_Xv_PortData *pPriv = (Ivtv_Xv_PortData *)data;
171
#ifdef JOHN
172
	if (attribute == xvBrightness) {
173
		if ((value < -128) || (value > 127))
174
			return BadValue;
175
		pPriv->brightness = value;
176
		OUTREG(MGAREG_BESLUMACTL, ((pPriv->brightness & 0xff) << 16) |
177
		       (pPriv->contrast & 0xff));
178
	} else if (attribute == xvContrast) {
179
		if ((value < 0) || (value > 255))
180
			return BadValue;
181
		pPriv->contrast = value;
182
		OUTREG(MGAREG_BESLUMACTL, ((pPriv->brightness & 0xff) << 16) |
183
		       (pPriv->contrast & 0xff));
184
	} else 
185
#endif
186
            if (attribute == xvColorKey) {
187
		pPriv->colorKey = value;
188
#ifdef JOHN
189
		outMGAdac(0x55, (pPriv->colorKey & pScrn->mask.red) >>
190
			  pScrn->offset.red);
191
		outMGAdac(0x56, (pPriv->colorKey & pScrn->mask.green) >>
192
			  pScrn->offset.green);
193
		outMGAdac(0x57, (pPriv->colorKey & pScrn->mask.blue) >>
194
			  pScrn->offset.blue);
195
#endif
196
		REGION_EMPTY(pScrn->pScreen, &pPriv->clip);
197
	}else if (attribute == xvAutopaintColorKey) {
198
		pPriv->autopaintColorKey = value;
199
        } else
200
        {
201
            ErrorF("IvtvSetPortAttributeOverlay bad attribute\n");
202
203
		return BadMatch;
204
        }
205
206
	return Success;
207
}
208
209
static int
210
IVTVGetPortAttributeOverlay(ScrnInfoPtr pScrn,
211
			    Atom attribute, INT32 * value, pointer data)
212
{
213
	IVTVDevPtr devPtr = IVTVDEVPTR(pScrn);
214
        Ivtv_Xv_PortData *pPriv = (Ivtv_Xv_PortData *)data;
215
216
#ifdef JOHN
217
	if (attribute == xvBrightness) {
218
		*value = pPriv->brightness;
219
	} else if (attribute == xvContrast) {
220
		*value = pPriv->contrast;
221
	} else
222
#endif
223
            if (attribute == xvColorKey) {
224
		*value = pPriv->colorKey;
225
	} else if (attribute == xvAutopaintColorKey) {
226
		*value = pPriv->autopaintColorKey;
227
	} else
228
        {
229
            ErrorF("IvtvGetPortAttributeOverlay bad attribute\n");
230
		return BadMatch;
231
        }
232
233
	return Success;
234
}
235
236
static void
237
IVTVQueryBestSize(ScrnInfoPtr pScrn,
238
		  Bool motion,
239
		  short vid_w, short vid_h,
240
		  short drw_w, short drw_h,
241
		  unsigned int *p_w, unsigned int *p_h, pointer data)
242
{
243
    ErrorF("Query best vid_w %d vid_h %d drw_w %d drw_h %d\n",
244
           vid_w, vid_h, drw_w, drw_h);
245
	*p_w = drw_w;
246
	*p_h = drw_h;
247
}
248
249
static XF86VideoAdaptorPtr IVTVAllocAdaptor(ScreenPtr pScreen)
250
{
251
	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
252
	XF86VideoAdaptorPtr adapt;
253
	DevUnion *pPriv;
254
	IVTVDevPtr devPtr = IVTVDEVPTR(pScrn);
255
	int i;
256
257
	if (!(adapt = xf86XVAllocateVideoAdaptorRec(pScrn)))
258
		return NULL;
259
260
	if (!(pPriv = xcalloc(1, sizeof(DevUnion) * IVTV_MAX_PORTS))) {
261
		xfree(adapt);
262
		return NULL;
263
	}
264
265
	adapt->pPortPrivates = pPriv;
266
267
	for (i = 0; i < IVTV_MAX_PORTS; i++)
268
        {
269
            Ivtv_Xv_PortData *portData =  (Ivtv_Xv_PortData *)xcalloc(1,sizeof(Ivtv_Xv_PortData));
270
            portData->colorKey = 101;
271
            portData->autopaintColorKey = 0;
272
#ifdef X_USE_REGION_NULL
273
            REGION_NULL(pScreen, &portData->clip);
274
#else
275
            REGION_INIT(pScreen, &portData->clip, NullBox, 0); 
276
#endif
277
            adapt->pPortPrivates[i].ptr =portData;
278
        }
279
            
280
281
#if 0
282
	xvBrightness = MAKE_ATOM("XV_BRIGHTNESS");
283
	xvContrast = MAKE_ATOM("XV_CONTRAST");
284
#endif
285
	xvColorKey 		= MAKE_ATOM("XV_COLORKEY");
286
        xvAutopaintColorKey 	= MAKE_ATOM("XV_AUTOPAINT_COLORKEY");
287
288
	return adapt;
289
}
290
291
static XF86VideoAdaptorPtr IVTVSetupImageVideoOverlay(ScreenPtr pScreen)
292
{
293
	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
294
#ifdef JOHN
295
	IVTVPtr ps3v = IVTVPTR(pScrn);
296
#endif
297
	XF86VideoAdaptorPtr adapt;
298
	adapt = IVTVAllocAdaptor(pScreen);
299
300
	adapt->type = XvWindowMask | XvInputMask | XvImageMask;
301
	adapt->flags = VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT;
302
	adapt->name = "PVR350";
303
	adapt->nEncodings = 1;
304
	adapt->pEncodings = &DummyEncoding[0];
305
	adapt->nFormats = NUM_FORMATS_OVERLAY;
306
	adapt->pFormats = Formats;
307
	adapt->nPorts = 1;
308
	adapt->pAttributes = Attributes /*Attributes */ ;
309
	adapt->nImages = 1;
310
	adapt->nAttributes = NUM_ATTRIBUTES_OVERLAY;
311
	adapt->pImages = Images;
312
	adapt->PutVideo = NULL;
313
	adapt->PutStill = NULL;
314
	adapt->GetVideo = NULL;
315
	adapt->GetStill = NULL;
316
	adapt->StopVideo = IVTVStopVideo;
317
	/* Empty Attrib functions - required anyway */
318
	adapt->SetPortAttribute = IVTVSetPortAttributeOverlay;
319
	adapt->GetPortAttribute = IVTVGetPortAttributeOverlay;
320
	adapt->QueryBestSize = IVTVQueryBestSize;
321
	adapt->PutImage = IVTVPutImage;
322
	adapt->QueryImageAttributes = IVTVQueryImageAttributes;
323
324
	return adapt;
325
}
326
327
static Bool RegionsEqual(RegionPtr A, RegionPtr B)
328
{
329
	int *dataA, *dataB;
330
	int num;
331
332
	num = REGION_NUM_RECTS(A);
333
	if (num != REGION_NUM_RECTS(B))
334
		return FALSE;
335
336
	if ((A->extents.x1 != B->extents.x1) ||
337
	    (A->extents.x2 != B->extents.x2) ||
338
	    (A->extents.y1 != B->extents.y1) ||
339
	    (A->extents.y2 != B->extents.y2))
340
		return FALSE;
341
342
	dataA = (int *)REGION_RECTS(A);
343
	dataB = (int *)REGION_RECTS(B);
344
345
	while (num--) {
346
		if ((dataA[0] != dataB[0]) || (dataA[1] != dataB[1]))
347
			return FALSE;
348
		dataA += 2;
349
		dataB += 2;
350
	}
351
352
	return TRUE;
353
}
354
355
#ifdef JOHN
356
/* Not using this at the moment */
357
/* IVTVClipVideo - copied from MGAClipVideo -  
358
359
   Takes the dst box in standard X BoxRec form (top and left
360
   edges inclusive, bottom and right exclusive).  The new dst
361
   box is returned.  The source boundaries are given (x1, y1 
362
   inclusive, x2, y2 exclusive) and returned are the new source 
363
   boundaries in 16.16 fixed point. 
364
*/
365
366
#define DummyScreen screenInfo.screens[0]
367
368
static Bool
369
IVTVClipVideo(BoxPtr dst,
370
	      INT32 * x1,
371
	      INT32 * x2,
372
	      INT32 * y1, INT32 * y2, RegionPtr reg, INT32 width, INT32 height)
373
{
374
	INT32 vscale, hscale, delta;
375
	BoxPtr extents = REGION_EXTENTS(DummyScreen, reg);
376
	int diff;
377
378
	hscale = ((*x2 - *x1) << 16) / (dst->x2 - dst->x1);
379
	vscale = ((*y2 - *y1) << 16) / (dst->y2 - dst->y1);
380
381
	*x1 <<= 16;
382
	*x2 <<= 16;
383
	*y1 <<= 16;
384
	*y2 <<= 16;
385
386
	diff = extents->x1 - dst->x1;
387
	if (diff > 0) {
388
		dst->x1 = extents->x1;
389
		*x1 += diff * hscale;
390
	}
391
	diff = dst->x2 - extents->x2;
392
	if (diff > 0) {
393
		dst->x2 = extents->x2;
394
		*x2 -= diff * hscale;
395
	}
396
	diff = extents->y1 - dst->y1;
397
	if (diff > 0) {
398
		dst->y1 = extents->y1;
399
		*y1 += diff * vscale;
400
	}
401
	diff = dst->y2 - extents->y2;
402
	if (diff > 0) {
403
		dst->y2 = extents->y2;
404
		*y2 -= diff * vscale;
405
	}
406
407
	if (*x1 < 0) {
408
		diff = (-*x1 + hscale - 1) / hscale;
409
		dst->x1 += diff;
410
		*x1 += diff * hscale;
411
	}
412
	delta = *x2 - (width << 16);
413
	if (delta > 0) {
414
		diff = (delta + hscale - 1) / hscale;
415
		dst->x2 -= diff;
416
		*x2 -= diff * hscale;
417
	}
418
	if (*x1 >= *x2)
419
		return FALSE;
420
421
	if (*y1 < 0) {
422
		diff = (-*y1 + vscale - 1) / vscale;
423
		dst->y1 += diff;
424
		*y1 += diff * vscale;
425
	}
426
	delta = *y2 - (height << 16);
427
	if (delta > 0) {
428
		diff = (delta + vscale - 1) / vscale;
429
		dst->y2 -= diff;
430
		*y2 -= diff * vscale;
431
	}
432
	if (*y1 >= *y2)
433
		return FALSE;
434
435
	if ((dst->x1 != extents->x1) || (dst->x2 != extents->x2) ||
436
	    (dst->y1 != extents->y1) || (dst->y2 != extents->y2)) {
437
		RegionRec clipReg;
438
		REGION_INIT(DummyScreen, &clipReg, dst, 1);
439
		REGION_INTERSECT(DummyScreen, reg, reg, &clipReg);
440
		REGION_UNINIT(DummyScreen, &clipReg);
441
	}
442
	return TRUE;
443
}
444
#endif
445
446
static void IVTVStopVideo(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
447
{
448
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
449
        Ivtv_Xv_PortData *pPriv = (Ivtv_Xv_PortData *)data;
450
451
	REGION_EMPTY(pScrn->pScreen, &pPriv->clip);
452
453
	if (shutdown) {
454
		if (fPtr->fd_yuv != -1) {
455
                        IVTVDevPtr devPtr = IVTVDEVPTR(pScrn);
456
			struct ivtvfb_ioctl_state_info state;
457
			close(fPtr->fd_yuv);
458
			fPtr->fd_yuv = -1;
459
                        struct ivtvfb_ioctl_colorkey colorKey;
460
                        colorKey.state = 0;
461
                        colorKey.colorKey = pPriv->colorKey;
462
                        if (ioctl(fPtr->fd,IVTVFB_IOCTL_SET_COLORKEY, &colorKey) < 0) {
463
                            ErrorF
464
                                ("IVTVFB_IOCTL_SET_COLORKEY failed (error: %s)\n",
465
                                 strerror(errno));
466
                        }
467
		}
468
	}
469
470
}
471
472
static void de_macro_y(unsigned char *src, unsigned char *dst,
473
		       int w, int h, int src_x, int src_y, int height, int width)
474
{
475
	unsigned int x, y, i;
476
	unsigned char *dst_2;
477
	unsigned int h_tail, w_tail;
478
	unsigned int h_size, w_size;
479
	unsigned int h_lead, w_lead;
480
481
	// Always round the origin, but compensate by increasing the size
482
	if (src_x & 15) {
483
		w += src_x & 15;
484
		src_x &= ~15;
485
	}
486
487
	if (src_y & 15) {
488
		h += src_y & 15;
489
		src_y &= ~15;
490
	}
491
492
	// The right / bottom edge might not be a multiple of 16
493
	h_tail = h & 15;
494
	w_tail = w & 15;
495
496
	// One block is 16 pixels high
497
	h_size = 16;
498
499
	// descramble Y plane
500
	for (y = 0; y < h; y += 16) {
501
502
		// Clip if we've reached the bottom & the size isn't a multiple of 16
503
		if (y + 16 > h) h_size = h_tail;
504
505
		for (x = 0; x < w; x += 16) {
506
			if (x + 16 > w)
507
				w_size = w_tail;
508
			else
509
				w_size = 16;
510
511
			dst_2 = dst + (720 * y) + (720 * src_y) + (256 * (src_x>>4)) + (x * 16);
512
513
			for (i = 0; i < h_size; i++) {
514
				memcpy(dst_2, src + src_x + x + (y + i) * width + (src_y * width), w_size);
515
				dst_2 += 16;
516
			}
517
		}
518
	}
519
}
520
521
static void de_macro_uv(unsigned char *srcu, unsigned char *srcv,
522
			unsigned char *dst, int w, int h, int src_x, int src_y,
523
		       int height, int width)
524
{
525
	unsigned int x, y, i, f;
526
	unsigned char *dst_2;
527
	unsigned int h_tail, w_tail;
528
	unsigned int h_size, w_size;
529
	unsigned int h_lead, w_lead;
530
531
	// The uv plane is half the size of the y plane, so 'correct' all dimensions.
532
	w /= 2;
533
	h /= 2;
534
	src_x /= 2;
535
	src_y /= 2;
536
	height /= 2;
537
	width /= 2;
538
539
	// Always round the origin, but compensate by increasing the size
540
	if (src_x & 7) {
541
		w += src_x & 7;
542
		src_x &= ~7;
543
	}
544
545
	if (src_y & 15) {
546
		h += src_y & 15;
547
		src_y &= ~15;
548
	}
549
550
	// The right / bottom edge may not be a multiple of 16
551
	h_tail = h & 15;
552
	w_tail = w & 7;
553
554
	h_size = 16;
555
556
	// descramble U/V plane
557
	for (y = 0; y < h; y += 16) {
558
		if ( y + 16 > h ) h_size = h_tail;
559
		for (x = 0; x < w; x += 8) {
560
			dst_2 = dst + (720 * y) + (720 * src_y) + (256 * (src_x>>3)) + (x * 32);
561
			if (x + 8 <= w) {
562
				for (i = 0; i < h_size; i++) {
563
					int idx = src_x + x + ((y + i) * width) + (src_y * width);
564
					dst_2[0] = srcu[idx + 0];
565
					dst_2[1] = srcv[idx + 0];
566
					dst_2[2] = srcu[idx + 1];
567
					dst_2[3] = srcv[idx + 1];
568
					dst_2[4] = srcu[idx + 2];
569
					dst_2[5] = srcv[idx + 2];
570
					dst_2[6] = srcu[idx + 3];
571
					dst_2[7] = srcv[idx + 3];
572
					dst_2[8] = srcu[idx + 4];
573
					dst_2[9] = srcv[idx + 4];
574
					dst_2[10] = srcu[idx + 5];
575
					dst_2[11] = srcv[idx + 5];
576
					dst_2[12] = srcu[idx + 6];
577
					dst_2[13] = srcv[idx + 6];
578
					dst_2[14] = srcu[idx + 7];
579
					dst_2[15] = srcv[idx + 7];
580
					dst_2 += 16;
581
				}
582
			}
583
			else {
584
				for (i = 0; i < h_size; i ++) {
585
					int idx = src_x + x + ((y + i) * width) + (src_y * width);
586
					for (f = 0; f < w_tail; f++) {
587
						dst_2[0] = srcu[idx + f];
588
						dst_2[1] = srcv[idx + f];
589
						dst_2 += 2;
590
					}
591
/*
592
					// Used for testing edge cutoff. Sets colour to Green
593
					for (f = w_tail;f < 8;f ++) {
594
						dst_2[0] = 0;
595
						dst_2[1] = 0;
596
						dst_2 += 2;
597
					}
598
*/
599
					dst_2 += 16 - (w_tail << 1);
600
				}
601
			}
602
		}
603
	}
604
}
605
606
static char outbuf[622080];
607
608
static int
609
IVTVPutImage(ScrnInfoPtr pScrn,
610
	     short src_x, short src_y,
611
	     short drw_x, short drw_y,
612
	     short src_w, short src_h,
613
	     short drw_w, short drw_h,
614
	     int id, unsigned char *buf,
615
	     short width, short height,
616
	     Bool sync, RegionPtr clipBoxes, pointer data)
617
{
618
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
619
        Ivtv_Xv_PortData *pPriv = (Ivtv_Xv_PortData *)data;
620
621
	struct ivtvyuv_ioctl_dma_host_to_ivtv_args args;
622
#ifdef JOHN
623
        ErrorF("src_w %d src_h %d drw_w %d drw_h %d width %d height %d\n",
624
               src_w, src_h, drw_w, drw_h, width, height);
625
        ErrorF("src_x %d src_y %d drw_x %d drw_y %d width %d height %d\n",
626
               src_x, src_y, drw_x, drw_y, width, height);
627
#endif
628
629
	// FIXME - Is this the correct place for this ?
630
631
	// Source coordinates must be even
632
	// For origin, round down
633
	src_x &= ~1;
634
	src_y &= ~1;
635
636
	// For size, round up
637
	src_w += src_w & 1;
638
	src_h += src_h & 1;
639
640
#ifdef JOHN
641
	INT32 x1, x2, y1, y2;
642
	unsigned char *dst_start;
643
	int top, left, npixels, nlines;
644
645
	BoxRec dstBox;
646
	CARD32 tmp;
647
	static int once = 1;
648
	static int once2 = 1;
649
650
	/* Clip */
651
	x1 = src_x;
652
	x2 = src_x + src_w;
653
	y1 = src_y;
654
	y2 = src_y + src_h;
655
656
	dstBox.x1 = drw_x;
657
	dstBox.x2 = drw_x + drw_w;
658
	dstBox.y1 = drw_y;
659
	dstBox.y2 = drw_y + drw_h;
660
661
#ifdef JOHN
662
	if (!IVTVClipVideo
663
	    (&dstBox, &x1, &x2, &y1, &y2, clipBoxes, width, height))
664
		return Success;
665
#endif
666
667
	dstBox.x1 -= pScrn->frameX0;
668
	dstBox.x2 -= pScrn->frameX0;
669
	dstBox.y1 -= pScrn->frameY0;
670
	dstBox.y2 -= pScrn->frameY0;
671
672
	pitch = pScrn->bitsPerPixel * pScrn->displayWidth >> 3;
673
674
	dstPitch = ((width << 1) + 15) & ~15;
675
	new_h = ((dstPitch * height) + pitch - 1) / pitch;
676
#endif
677
678
	switch (id) {
679
680
	case FOURCC_YV12:
681
		{
682
			de_macro_y(buf, outbuf, src_w, src_h, src_x, src_y, height, width);
683
			de_macro_uv(buf + (width * height) + width * height/ 4,
684
				    buf + (width * height), outbuf + 720 * 576,
685
				    src_w,  src_h, src_x, src_y, height, width);
686
687
			args.y_source = outbuf;
688
			args.uv_source = outbuf + (720 * 576);
689
			args.src_x = src_x;
690
                        args.src_y = src_y;
691
                        args.dst_x = drw_x;
692
                        args.dst_y = drw_y;
693
			args.src_w = src_w;
694
                        args.dst_w = drw_w;
695
                        args.srcBuf_width = width;
696
			args.src_h = src_h;
697
                        args.dst_h = drw_h;
698
                        args.srcBuf_height = height;
699
			args.yuv_type = IVTV_YUV_TYPE_HME12;
700
		}
701
		break;
702
	default:
703
		return BadMatch;
704
	}
705
	if (fPtr->fd_yuv == -1) {
706
		if ((fPtr->fd_yuv = open(fPtr->yuvDevName, O_RDWR)) == -1) {
707
			if (errno == ENODEV)
708
				ErrorF
709
				    ("Failed to open \"%s\". Need to initialize the mpeg decoder before the YUV output can be used\n",
710
				     fPtr->yuvDevName);
711
			else
712
				ErrorF("Failed to open \"%s\" Error %s\n",
713
				       fPtr->yuvDevName, strerror(errno));
714
			return BadAccess;
715
		}
716
                struct ivtvfb_ioctl_colorkey colorKey;
717
                colorKey.state = 1;
718
                colorKey.colorKey = pPriv->colorKey;
719
                if (ioctl(fPtr->fd,IVTVFB_IOCTL_SET_COLORKEY, &colorKey) < 0) {
720
                    ErrorF
721
                        ("IVTVFB_IOCTL_SET_COLORKEY failed (error: %s)\n",
722
                         strerror(errno));
723
                }
724
	}
725
	int ret = ioctl(fPtr->fd_yuv, IVTV_IOC_PREP_FRAME_YUV, &args);
726
	if (ret == -1) {
727
		ErrorF
728
		    ("Ioctl IVTV_IOC_PREP_FRAME_YUV returned failed Error %s\n",
729
		     strerror(errno));
730
		return BadImplementation;
731
	}
732
                                                                          
733
        if(pPriv->autopaintColorKey && 
734
           !RegionsEqual( &pPriv->clip, clipBoxes))
735
        {
736
            /* we always paint V4L's color key */
737
            REGION_COPY(pScrn->pScreen, &pPriv->clip, clipBoxes);
738
            xf86XVFillKeyHelper(pScrn->pScreen, pPriv->colorKey, clipBoxes);
739
        }
740
	return Success;
741
}
742
743
static int
744
IVTVQueryImageAttributes(ScrnInfoPtr pScrn,
745
			 int id,
746
			 unsigned short *w, unsigned short *h,
747
			 int *pitches, int *offsets)
748
{
749
	int size = 0, tmp;
750
751
	if (*w > 768)
752
		*w = 768;
753
	if (*h > pScrn->virtualY)
754
		*h = pScrn->virtualY;
755
756
	*w = (*w + 1) & ~1;
757
	if (offsets)
758
		offsets[0] = 0;
759
760
	switch (id) {
761
	case FOURCC_YV12:
762
		*h = (*h + 1) & ~1;
763
		size = (*w + 3) & ~3;
764
		if (pitches)
765
			pitches[0] = size;
766
		size *= *h;
767
		if (offsets)
768
			offsets[1] = size;
769
		tmp = ((*w >> 1) + 3) & ~3;
770
		if (pitches)
771
			pitches[1] = pitches[2] = tmp;
772
		tmp *= (*h >> 1);
773
		size += tmp;
774
		if (offsets)
775
			offsets[2] = size;
776
		size += tmp;
777
		break;
778
	default:
779
		break;
780
	}
781
782
	return size;
783
}
784
785
#endif				/* !XvExtension */
(-)ivtvdrv-noX-no-autotools/xc/programs/Xserver/hw/xfree86/drivers/ivtv/Makefile (-6 lines)
Lines 1-6 Link Here
1
2
3
all:
4
	echo "Run xmkmf /PATH_TO_X_SOURCE/"
5
6
(-)ivtvdrv-noX-no-autotools/xc/programs/Xserver/hw/xfree86/drivers/ivtv/src/ivtvdev.c (+635 lines)
Line 0 Link Here
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/ivtv/ivtv.c,v 1.42 2002/10/10 01:35:20 dawes Exp $ */
2
3
/*
4
 * Authors:  Alan Hourihane, <alanh@fairlite.demon.co.uk>
5
 *	     Michel Dänzer, <michdaen@iiic.ethz.ch>
6
 */
7
8
#include "string.h"
9
#include "config.h"
10
#include "ivtvhw.h"
11
#include "ivtvdev.h"
12
/* all driver need this */
13
#include "xf86.h"
14
#include "xf86_OSproc.h"
15
16
#include "mipointer.h"
17
#include "mibstore.h"
18
#include "micmap.h"
19
#include "colormapst.h"
20
#include "xf86cmap.h"
21
#include "shadow.h"
22
#include "shadowfb.h"
23
24
/* for visuals */
25
#include "fb.h"
26
27
#include "xf86Resources.h"
28
#include "xf86RAC.h"
29
30
#ifdef XvExtension
31
#include "xf86xv.h"
32
#endif
33
enum HAUPAGE_CHIPTAGS {
34
	PVR_UNKNOWN = 0,
35
	PVR_350,
36
	PVR_LAST
37
};
38
#define PCI_CHIP_PVR350         0x0803
39
40
static SymTabRec IVTVChipsets[] = {
41
	{PVR_350, "PVR-350"},
42
	{-1, NULL}
43
};
44
45
/* This table maps a PCI device ID to a chipset family identifier. */
46
static PciChipsets IVTVPciChipsets[] = {
47
	{PVR_350, PCI_CHIP_PVR350, RES_SHARED_VGA},
48
	{-1, -1, RES_UNDEFINED}
49
};
50
51
#define DEBUG 0
52
53
#if DEBUG
54
# define TRACE_ENTER(str)       ErrorF("ivtv: " str " %d\n",pScrn->scrnIndex)
55
# define TRACE_EXIT(str)        ErrorF("ivtv: " str " done\n")
56
# define TRACE(str)             ErrorF("ivtv trace: " str "\n")
57
#else
58
# define TRACE_ENTER(str)
59
# define TRACE_EXIT(str)
60
# define TRACE(str)
61
#endif
62
63
/* -------------------------------------------------------------------- */
64
/* prototypes                                                           */
65
66
static const OptionInfoRec *IVTVDevAvailableOptions(int chipid, int busid);
67
static void IVTVDevIdentify(int flags);
68
static Bool IVTVDevProbe(DriverPtr drv, int flags);
69
static Bool IVTVDevPreInit(ScrnInfoPtr pScrn, int flags);
70
static Bool IVTVDevScreenInit(int Index, ScreenPtr pScreen, int argc,
71
			      char **argv);
72
static Bool IVTVDevCloseScreen(int scrnIndex, ScreenPtr pScreen);
73
74
/* -------------------------------------------------------------------- */
75
76
/*
77
 * This is intentionally screen-independent.  It indicates the binding
78
 * choice made in the first PreInit.
79
 */
80
static int pix24bpp = 0;
81
82
#define IVTVDEV_VERSION			4000
83
#define IVTVDEV_NAME		"IVTVDEV_TST"
84
#define IVTVDEV_DRIVER_NAME	"ivtvdev"
85
#define IVTVDEV_MAJOR_VERSION	0
86
#define IVTVDEV_MINOR_VERSION	10
87
88
DriverRec IVTVDEV = {
89
	IVTVDEV_VERSION,
90
	IVTVDEV_DRIVER_NAME,
91
#if 0
92
	"driver for linux framebuffer devices",
93
#endif
94
	IVTVDevIdentify,
95
	IVTVDevProbe,
96
	IVTVDevAvailableOptions,
97
	NULL,
98
	0
99
};
100
101
/* Supported options */
102
typedef enum {
103
	OPTION_IVTVDEV
104
} IVTVDevOpts;
105
106
static const OptionInfoRec IVTVDevOptions[] = {
107
	{OPTION_IVTVDEV, "ivtv", OPTV_STRING, {0}, FALSE},
108
	{-1, NULL, OPTV_NONE, {0}, FALSE}
109
};
110
111
/* -------------------------------------------------------------------- */
112
113
const char *IVTVDevshadowFBSymbols[] = {
114
    "ShadowFBInit",
115
    NULL
116
};
117
118
static const char *fbSymbols[] = {
119
	"fbScreenInit",
120
	"fbPictureInit",
121
	NULL
122
};
123
124
static const char *shadowSymbols[] = {
125
	"shadowAdd",
126
	"shadowInit",
127
	"shadowSetup",
128
	NULL
129
};
130
131
#ifdef XFree86LOADER
132
133
MODULESETUPPROTO(IVTVDevSetup);
134
135
static XF86ModuleVersionInfo IVTVDevVersRec = {
136
	"ivtv",
137
	MODULEVENDORSTRING,
138
	MODINFOSTRING1,
139
	MODINFOSTRING2,
140
	XORG_VERSION_CURRENT,
141
	IVTVDEV_MAJOR_VERSION, IVTVDEV_MINOR_VERSION, 6,
142
	ABI_CLASS_VIDEODRV,
143
	ABI_VIDEODRV_VERSION,
144
	MOD_CLASS_VIDEODRV,
145
	{0, 0, 0, 0}
146
};
147
148
XF86ModuleData ivtvdevModuleData = { &IVTVDevVersRec, IVTVDevSetup, NULL };
149
150
pointer IVTVDevSetup(pointer module, pointer opts, int *errmaj, int *errmin)
151
{
152
	static Bool setupDone = FALSE;
153
154
	if (!setupDone) {
155
		setupDone = TRUE;
156
		xf86AddDriver(&IVTVDEV, module, 0);
157
		LoaderRefSymLists(fbSymbols, shadowSymbols,
158
				  IVTVDevshadowFBSymbols, NULL);
159
		return (pointer) 1;
160
	} else {
161
		if (errmaj)
162
			*errmaj = LDR_ONCEONLY;
163
		return NULL;
164
	}
165
}
166
167
#endif				/* XFree86LOADER */
168
169
void FBshadowUpdatePacked(ScreenPtr pScreen, shadowBufPtr pBuf)
170
{
171
172
	RegionPtr damage = &pBuf->damage;
173
	int nbox = REGION_NUM_RECTS(damage);
174
	BoxPtr pbox = REGION_RECTS(damage);
175
176
	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
177
	IVTVDevPtr fPtr = IVTVDEVPTR(pScrn);
178
	int x1 = pScrn->virtualX;
179
	int x2 = 0;
180
	int y1 = pScrn->virtualY;
181
	int y2 = 0;
182
	while (nbox--) {
183
		if (pbox->x1 < x1)
184
			x1 = pbox->x1;
185
		if (pbox->x2 > x2)
186
			x2 = pbox->x2;
187
		if (pbox->y1 < y1)
188
			y1 = pbox->y1;
189
		if (pbox->y2 > y2)
190
			y2 = pbox->y2;
191
		pbox++;
192
	};
193
194
	ivtvHWSendDMA(pScrn, fPtr->shadowmem, x1, x2, y1, y2);
195
}
196
197
void
198
IVTVDevRefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
199
{
200
	IVTVDevPtr fPtr = IVTVDEVPTR(pScrn);
201
	int x1 = pScrn->virtualX;
202
	int x2 = 0;
203
	int y1 = pScrn->virtualY;
204
	int y2 = 0;
205
	while (num--) {
206
		if (pbox->x1 < x1)
207
			x1 = pbox->x1;
208
		if (pbox->x2 > x2)
209
			x2 = pbox->x2;
210
		if (pbox->y1 < y1)
211
			y1 = pbox->y1;
212
		if (pbox->y2 > y2)
213
			y2 = pbox->y2;
214
		pbox++;
215
	};
216
217
	ivtvHWSendDMA(pScrn, fPtr->shadowmem, x1, x2, y1, y2);
218
}
219
220
static Bool IVTVDevGetRec(ScrnInfoPtr pScrn)
221
{
222
	if (pScrn->driverPrivate != NULL)
223
		return TRUE;
224
225
	pScrn->driverPrivate = xnfcalloc(sizeof(IVTVDevRec), 1);
226
	return TRUE;
227
}
228
229
static void IVTVDevFreeRec(ScrnInfoPtr pScrn)
230
{
231
	if (pScrn->driverPrivate == NULL)
232
		return;
233
	xfree(pScrn->driverPrivate);
234
	pScrn->driverPrivate = NULL;
235
}
236
237
/* -------------------------------------------------------------------- */
238
239
static const OptionInfoRec *IVTVDevAvailableOptions(int chipid, int busid)
240
{
241
	return IVTVDevOptions;
242
}
243
244
static void IVTVDevIdentify(int flags)
245
{
246
	xf86PrintChipsets(IVTVDEV_NAME, "driver for framebuffer", IVTVChipsets);
247
}
248
249
static Bool IVTVDevProbe(DriverPtr drv, int flags)
250
{
251
	int i;
252
	GDevPtr *devSections;
253
	int numDevSections;
254
	char *dev;
255
	Bool foundScreen = FALSE;
256
	int *usedChips;
257
	int numUsed;
258
	TRACE("probe start");
259
260
	/* For now, just bail out for PROBE_DETECT. */
261
	if (flags & PROBE_DETECT)
262
		return FALSE;
263
264
	/* sanity checks */
265
	if ((numDevSections =
266
	     xf86MatchDevice(IVTVDEV_DRIVER_NAME, &devSections)) <= 0)
267
		return FALSE;
268
269
	if (xf86GetPciVideoInfo() == NULL)
270
		return FALSE;
271
272
	numUsed = xf86MatchPciInstances(IVTVDEV_DRIVER_NAME,
273
					PCI_HAUPAGGE_VENDOR_ID,
274
					IVTVChipsets,
275
					IVTVPciChipsets,
276
					devSections,
277
					numDevSections, drv, &usedChips);
278
279
	if (numUsed <= 0)
280
		return FALSE;
281
282
	if (flags & PROBE_DETECT) {
283
		foundScreen = TRUE;
284
	} else {
285
		for (i = 0; i < numUsed; i++) {
286
			ScrnInfoPtr pScrn = xf86AllocateScreen(drv, 0);
287
			dev =
288
			    xf86FindOptionValue(devSections[i]->options,
289
						"fbdev");
290
			if (ivtvHWProbe(NULL, dev, NULL)) {
291
				pScrn =
292
				    xf86ConfigPciEntity(pScrn, 0, usedChips[i],
293
							IVTVPciChipsets, 0, 0,
294
							0, 0, 0);
295
296
				/* xf86DrvMsg() can't be called without setting these */
297
				pScrn->driverName = IVTVDEV_DRIVER_NAME;
298
				pScrn->name = IVTVDEV_NAME;
299
300
				if (pScrn) {
301
					foundScreen = TRUE;
302
303
					pScrn->driverVersion = IVTVDEV_VERSION;
304
					pScrn->driverName = IVTVDEV_DRIVER_NAME;
305
					pScrn->name = IVTVDEV_NAME;
306
					pScrn->Probe = IVTVDevProbe;
307
					pScrn->PreInit = IVTVDevPreInit;
308
					pScrn->ScreenInit = IVTVDevScreenInit;
309
					pScrn->SwitchMode = ivtvHWSwitchMode;
310
					pScrn->AdjustFrame = ivtvHWAdjustFrame;
311
					pScrn->EnterVT = ivtvHWEnterVT;
312
					pScrn->LeaveVT = ivtvHWLeaveVT;
313
					pScrn->ValidMode = ivtvHWValidMode;
314
315
					xf86DrvMsg(pScrn->scrnIndex, X_INFO,
316
						   "using %s\n",
317
						   dev ? dev :
318
						   "default device");
319
				}
320
			}
321
		}
322
	}
323
	xfree(devSections);
324
	TRACE("probe done");
325
	return foundScreen;
326
}
327
328
static Bool IVTVDevPreInit(ScrnInfoPtr pScrn, int flags)
329
{
330
	IVTVDevPtr fPtr;
331
	int default_depth, fbbpp;
332
	const char *mod = NULL;
333
	const char **syms = NULL;
334
335
	if (flags & PROBE_DETECT)
336
		return FALSE;
337
338
	TRACE_ENTER("PreInit");
339
340
	/* Check the number of entities, and fail if it isn't one. */
341
	if (pScrn->numEntities != 1)
342
		return FALSE;
343
344
	pScrn->monitor = pScrn->confScreen->monitor;
345
346
	IVTVDevGetRec(pScrn);
347
	fPtr = IVTVDEVPTR(pScrn);
348
349
	fPtr->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
350
351
	pScrn->racMemFlags = RAC_FB | RAC_COLORMAP | RAC_CURSOR | RAC_VIEWPORT;
352
	/* XXX Is this right?  Can probably remove RAC_FB */
353
	pScrn->racIoFlags = RAC_FB | RAC_COLORMAP | RAC_CURSOR | RAC_VIEWPORT;
354
355
	if (fPtr->pEnt->location.type == BUS_PCI &&
356
	    xf86RegisterResources(fPtr->pEnt->index, NULL, ResExclusive)) {
357
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
358
			   "xf86RegisterResources() found resource conflicts\n");
359
		return FALSE;
360
	}
361
362
	/* open device */
363
	if (!ivtvHWInit
364
	    (pScrn, NULL,
365
	     xf86FindOptionValue(fPtr->pEnt->device->options, "fbdev")))
366
		return FALSE;
367
	default_depth = ivtvHWGetDepth(pScrn, &fbbpp);
368
	if (!xf86SetDepthBpp(pScrn, default_depth, default_depth, fbbpp, 0))
369
		return FALSE;
370
	xf86PrintDepthBpp(pScrn);
371
372
	/* Get the depth24 pixmap format */
373
	if (pScrn->depth == 24 && pix24bpp == 0)
374
		pix24bpp = xf86GetBppFromDepth(pScrn, 24);
375
376
	/* color weight */
377
	if (pScrn->depth > 8) {
378
		rgb zeros = { 0, 0, 0 };
379
		if (!xf86SetWeight(pScrn, zeros, zeros))
380
			return FALSE;
381
	}
382
383
	/* visual init */
384
	if (!xf86SetDefaultVisual(pScrn, -1))
385
		return FALSE;
386
387
	/* We don't currently support DirectColor at > 8bpp */
388
	if (pScrn->depth > 8 && pScrn->defaultVisual != TrueColor) {
389
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Given default visual"
390
			   " (%s) is not supported at depth %d\n",
391
			   xf86GetVisualName(pScrn->defaultVisual),
392
			   pScrn->depth);
393
		return FALSE;
394
	}
395
396
	{
397
		Gamma zeros = { 0.0, 0.0, 0.0 };
398
399
		if (!xf86SetGamma(pScrn, zeros)) {
400
			return FALSE;
401
		}
402
	}
403
404
	pScrn->progClock = TRUE;
405
	pScrn->rgbBits = 8;
406
	pScrn->chipset = "ivtvdev";
407
	pScrn->videoRam = ivtvHWGetVidmem(pScrn);
408
409
	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Hardware: %s (vidmem: %dk)\n",
410
		   ivtvHWGetName(pScrn), pScrn->videoRam / 1024);
411
412
	/* handle options */
413
	xf86CollectOptions(pScrn, NULL);
414
	if (!(fPtr->Options = xalloc(sizeof(IVTVDevOptions))))
415
		return FALSE;
416
	memcpy(fPtr->Options, IVTVDevOptions, sizeof(IVTVDevOptions));
417
	xf86ProcessOptions(pScrn->scrnIndex, fPtr->pEnt->device->options,
418
			   fPtr->Options);
419
420
	/* select video modes */
421
422
	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
423
		   "Checking Modes against framebuffer device...\n");
424
	ivtvHWSetVideoModes(pScrn);
425
426
	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
427
		   "Checking Modes against monitor...\n");
428
	{
429
		DisplayModePtr mode, first = mode = pScrn->modes;
430
431
		if (mode != NULL)
432
			do {
433
				mode->status =
434
				    xf86CheckModeForMonitor(mode,
435
							    pScrn->monitor);
436
				mode = mode->next;
437
			} while (mode != NULL && mode != first);
438
439
		xf86PruneDriverModes(pScrn);
440
	}
441
442
	if (NULL == pScrn->modes)
443
		ivtvHWUseBuildinMode(pScrn);
444
	pScrn->currentMode = pScrn->modes;
445
446
	pScrn->displayWidth = pScrn->virtualX;	/* ShadowFB handles this correctly */
447
448
	xf86PrintModes(pScrn);
449
450
	/* Set display resolution */
451
	xf86SetDpi(pScrn, 0, 0);
452
453
	/* Load bpp-specific modules */
454
	mod = "fb";
455
	syms = fbSymbols;
456
457
	if (mod && xf86LoadSubModule(pScrn, mod) == NULL) {
458
		IVTVDevFreeRec(pScrn);
459
		return FALSE;
460
	}
461
	if (mod && syms) {
462
		xf86LoaderReqSymLists(syms, NULL);
463
	}
464
465
	xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "loading shadowfb");
466
	if (!xf86LoadSubModule(pScrn, "shadowfb")) {
467
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
468
			   "Couldn't load shadowfb module:\n");
469
		return FALSE;
470
	}
471
	xf86LoaderReqSymLists(IVTVDevshadowFBSymbols, NULL);
472
473
	/* Load shadow */
474
	xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Using \"Shadow Framebuffer\"\n");
475
	if (!xf86LoadSubModule(pScrn, "shadow")) {
476
		IVTVDevFreeRec(pScrn);
477
		return FALSE;
478
	}
479
	xf86LoaderReqSymLists(shadowSymbols, NULL);
480
481
	TRACE_EXIT("PreInit");
482
	return TRUE;
483
}
484
485
void IvtvInitVideo(ScreenPtr pScreen);
486
487
static Bool
488
IVTVDevScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
489
{
490
	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
491
	IVTVDevPtr fPtr = IVTVDEVPTR(pScrn);
492
	VisualPtr visual;
493
	int ret, flags, width, height;
494
495
	TRACE_ENTER("IVTVDevScreenInit");
496
497
	ErrorF("\tbitsPerPixel=%d, depth=%d, defaultVisual=%s\n"
498
	       "\tmask: %x,%x,%x, offset: %d,%d,%d\n",
499
	       pScrn->bitsPerPixel,
500
	       pScrn->depth,
501
	       xf86GetVisualName(pScrn->defaultVisual),
502
	       pScrn->mask.red, pScrn->mask.green, pScrn->mask.blue,
503
	       pScrn->offset.red, pScrn->offset.green, pScrn->offset.blue);
504
505
	ivtvHWSave(pScrn);
506
507
	if (!ivtvHWModeInit(pScrn, pScrn->currentMode)) {
508
		xf86DrvMsg(scrnIndex, X_ERROR, "Mode init failed\n");
509
		return FALSE;
510
	}
511
	ivtvHWSaveScreen(pScreen, SCREEN_SAVER_ON);
512
	ivtvHWAdjustFrame(scrnIndex, 0, 0, 0);
513
514
	/* mi layer */
515
	miClearVisualTypes();
516
	if (pScrn->bitsPerPixel > 8) {
517
		if (!miSetVisualTypes
518
		    (pScrn->depth, TrueColorMask, pScrn->rgbBits, TrueColor)) {
519
			xf86DrvMsg(scrnIndex, X_ERROR,
520
				   "Set visual types failed\n");
521
			return FALSE;
522
		}
523
	} else {
524
		if (!miSetVisualTypes(pScrn->depth,
525
				      miGetDefaultVisualMask(pScrn->depth),
526
				      pScrn->rgbBits, pScrn->defaultVisual)) {
527
			xf86DrvMsg(scrnIndex, X_ERROR,
528
				   "Set visual types failed\n");
529
			return FALSE;
530
		}
531
	}
532
	if (!miSetPixmapDepths()) {
533
		xf86DrvMsg(scrnIndex, X_ERROR, "Set pixmap depths failed\n");
534
		return FALSE;
535
	}
536
537
	height = pScrn->virtualY;
538
	width = pScrn->virtualX;
539
540
	/* shadowfb */
541
	if ((fPtr->shadowmem = shadowAlloc(width, height,
542
					   pScrn->bitsPerPixel)) == NULL) {
543
		xf86DrvMsg(scrnIndex, X_ERROR,
544
			   "Allocation of shadow memory failed\n");
545
		return FALSE;
546
	}
547
548
	ret = fbScreenInit(pScreen, fPtr->shadowmem, width, height,
549
			   pScrn->xDpi, pScrn->yDpi, pScrn->displayWidth,
550
			   pScrn->bitsPerPixel);
551
552
	if (!ret)
553
		return FALSE;
554
555
	if (pScrn->bitsPerPixel > 8) {
556
		/* Fixup RGB ordering */
557
		visual = pScreen->visuals + pScreen->numVisuals;
558
		while (--visual >= pScreen->visuals) {
559
			if ((visual->class | DynamicClass) == DirectColor) {
560
				visual->offsetRed = pScrn->offset.red;
561
				visual->offsetGreen = pScrn->offset.green;
562
				visual->offsetBlue = pScrn->offset.blue;
563
				visual->redMask = pScrn->mask.red;
564
				visual->greenMask = pScrn->mask.green;
565
				visual->blueMask = pScrn->mask.blue;
566
			}
567
		}
568
	}
569
570
	/* must be after RGB ordering fixed */
571
	if (!fbPictureInit(pScreen, NULL, 0))
572
		xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
573
			   "RENDER extension initialisation failed.\n");
574
575
	if (!shadowInit(pScreen, FBshadowUpdatePacked, NULL)) {
576
		xf86DrvMsg(scrnIndex, X_ERROR,
577
			   "Shadow framebuffer initialization failed.\n");
578
		return FALSE;
579
	}
580
581
	/*      IVTVDGAInit(pScreen);
582
	 */
583
584
	if (pScrn->bitsPerPixel == 24)
585
		xf86DrvMsg(scrnIndex, X_WARNING,
586
			   "Rotation might be broken in 24 bpp\n");
587
588
	xf86SetBlackWhitePixels(pScreen);
589
	miInitializeBackingStore(pScreen);
590
	xf86SetBackingStore(pScreen);
591
592
	/* software cursor */
593
	miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
594
595
	ShadowFBInit(pScreen, IVTVDevRefreshArea);
596
597
	/* XXX It would be simpler to use miCreateDefColormap() in all cases. */
598
	if (!miCreateDefColormap(pScreen))
599
		return FALSE;
600
601
	flags = CMAP_PALETTED_TRUECOLOR;
602
	if (!xf86HandleColormaps
603
	    (pScreen, 256, 8, ivtvHWLoadPalette, NULL, flags))
604
		return FALSE;
605
606
	xf86DPMSInit(pScreen, ivtvHWDPMSSet, 0);
607
608
	pScreen->SaveScreen = ivtvHWSaveScreen;
609
610
	/* Wrap the current CloseScreen function */
611
	fPtr->CloseScreen = pScreen->CloseScreen;
612
	pScreen->CloseScreen = IVTVDevCloseScreen;
613
614
	{
615
            ErrorF("Init Video\n");
616
		IvtvInitVideo(pScreen);
617
	}
618
619
	TRACE_EXIT("IVTVDevScreenInit");
620
621
	return TRUE;
622
}
623
624
static Bool IVTVDevCloseScreen(int scrnIndex, ScreenPtr pScreen)
625
{
626
	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
627
	IVTVDevPtr fPtr = IVTVDEVPTR(pScrn);
628
629
	ivtvHWRestore(pScrn);
630
	xfree(fPtr->shadowmem);
631
	pScrn->vtSema = FALSE;
632
633
	pScreen->CloseScreen = fPtr->CloseScreen;
634
	return (*pScreen->CloseScreen) (scrnIndex, pScreen);
635
}
(-)ivtvdrv-noX-no-autotools/xc/programs/Xserver/hw/xfree86/drivers/ivtv/src/ivtvdev.h (+17 lines)
Line 0 Link Here
1
/* -------------------------------------------------------------------- */
2
/* our private data, and two functions to allocate/free this            */
3
4
typedef struct {
5
	int lineLength;
6
	unsigned char *shadowmem;
7
	CloseScreenProcPtr CloseScreen;
8
	DGAModePtr pDGAMode;
9
	int nDGAMode;
10
	void (*PointerMoved) (int index, int x, int y);
11
	EntityInfoPtr pEnt;
12
	OptionInfoPtr Options;
13
} IVTVDevRec, *IVTVDevPtr;
14
15
#define IVTVDEVPTR(p) ((IVTVDevPtr)((p)->driverPrivate))
16
17
Bool IVTVDGAInit(ScreenPtr pScreen);
(-)ivtvdrv-noX-no-autotools/xc/programs/Xserver/hw/xfree86/drivers/ivtv/src/ivtvhw.c (+834 lines)
Line 0 Link Here
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/ivtvhw/ivtvhw.c,v 1.30 2002/11/25 14:05:00 eich Exp $ */
2
3
#include "errno.h"
4
#include "fcntl.h"
5
#include "stdio.h"
6
#include "stdlib.h"
7
#include "string.h"
8
#include "unistd.h"
9
10
#include "sys/ioctl.h"
11
12
#include "config.h"
13
14
#include "ivtvhw.h"
15
16
/* all driver need this */
17
#include "xf86.h"
18
#include "xf86_OSproc.h"
19
20
/* pci stuff */
21
#include "xf86PciInfo.h"
22
#include "xf86Pci.h"
23
24
#include "xf86cmap.h"
25
26
#include "linux/fb.h"
27
#include "asm/page.h"		/* #define for PAGE_* */
28
#include "globals.h"
29
#define DPMS_SERVER
30
#include "extensions/dpms.h"
31
32
#define DEBUG 0
33
34
#if DEBUG
35
# define TRACE_ENTER(str)	ErrorF("ivtvHW: " str " %d\n",pScrn->scrnIndex)
36
#else
37
# define TRACE_ENTER(str)
38
#endif
39
40
/* -------------------------------------------------------------------- */
41
42
#ifdef XFree86LOADER
43
44
static MODULESETUPPROTO(ivtvhwSetup);
45
46
static XF86ModuleVersionInfo ivtvHWVersRec = {
47
	"ivtvhw",
48
	MODULEVENDORSTRING,
49
	MODINFOSTRING1,
50
	MODINFOSTRING2,
51
	XF86_VERSION_CURRENT,
52
	0, 0, 2,
53
	ABI_CLASS_VIDEODRV,
54
	ABI_VIDEODRV_VERSION,
55
	MOD_CLASS_VIDEODRV,
56
	{0, 0, 0, 0}
57
};
58
59
XF86ModuleData ivtvhwModuleData = { &ivtvHWVersRec, ivtvhwSetup, NULL };
60
61
static pointer
62
ivtvhwSetup(pointer module, pointer opts, int *errmaj, int *errmin)
63
{
64
	const char *osname;
65
66
	/* Check that we're being loaded on a Linux system */
67
	LoaderGetOS(&osname, NULL, NULL, NULL);
68
	if (!osname || strcmp(osname, "linux") != 0) {
69
		if (errmaj)
70
			*errmaj = LDR_BADOS;
71
		if (errmin)
72
			*errmin = 0;
73
		return NULL;
74
	} else {
75
		/* OK */
76
		return (pointer) 1;
77
	}
78
}
79
80
#else				/* XFree86LOADER */
81
82
#include <fcntl.h>
83
#include <errno.h>
84
#include <sys/mman.h>
85
86
#endif				/* XFree86LOADER */
87
88
/* -------------------------------------------------------------------- */
89
/* our private data, and two functions to allocate/free this            */
90
91
int ivtvHWPrivateIndex = -1;
92
93
Bool ivtvHWGetRec(ScrnInfoPtr pScrn)
94
{
95
	ivtvHWPtr fPtr;
96
97
	if (ivtvHWPrivateIndex < 0)
98
		ivtvHWPrivateIndex = xf86AllocateScrnInfoPrivateIndex();
99
100
	if (FBDEVHWPTR(pScrn) != NULL)
101
		return TRUE;
102
103
	fPtr = FBDEVHWPTRLVAL(pScrn) = xnfcalloc(sizeof(ivtvHWRec), 1);
104
	return TRUE;
105
}
106
107
void ivtvHWFreeRec(ScrnInfoPtr pScrn)
108
{
109
	if (ivtvHWPrivateIndex < 0)
110
		return;
111
	if (FBDEVHWPTR(pScrn) == NULL)
112
		return;
113
	xfree(FBDEVHWPTR(pScrn));
114
	FBDEVHWPTRLVAL(pScrn) = NULL;
115
}
116
117
/* -------------------------------------------------------------------- */
118
/* some helpers for printing debug informations                         */
119
120
#if DEBUG
121
static void print_ivtv_mode(char *txt, struct fb_var_screeninfo *var)
122
{
123
	ErrorF("ivtv %s mode:\t%d   %d %d %d %d   %d %d %d %d   %d %d:%d:%d\n",
124
	       txt, var->pixclock,
125
	       var->xres, var->right_margin, var->hsync_len, var->left_margin,
126
	       var->yres, var->lower_margin, var->vsync_len, var->upper_margin,
127
	       var->bits_per_pixel,
128
	       var->red.length, var->green.length, var->blue.length);
129
}
130
131
static void print_xfree_mode(char *txt, DisplayModePtr mode)
132
{
133
	ErrorF("xfree %s mode:\t%d   %d %d %d %d   %d %d %d %d\n",
134
	       txt, mode->Clock,
135
	       mode->HDisplay, mode->HSyncStart, mode->HSyncEnd, mode->HTotal,
136
	       mode->VDisplay, mode->VSyncStart, mode->VSyncEnd, mode->VTotal);
137
}
138
#endif
139
140
/* -------------------------------------------------------------------- */
141
/* Convert timings between the XFree and the Frame Buffer Device        */
142
143
static void
144
xfree2ivtv_fblayout(ScrnInfoPtr pScrn, struct fb_var_screeninfo *var)
145
{
146
	var->xres_virtual = pScrn->virtualX;
147
	var->yres_virtual = pScrn->virtualY;
148
	var->bits_per_pixel = pScrn->bitsPerPixel;
149
	var->red.length = pScrn->weight.red;
150
	var->green.length = pScrn->weight.green;
151
	var->blue.length = pScrn->weight.blue;
152
}
153
154
static void
155
xfree2ivtv_timing(DisplayModePtr mode, struct fb_var_screeninfo *var)
156
{
157
	var->xres = mode->HDisplay;
158
	var->yres = mode->VDisplay;
159
	if (var->xres_virtual < var->xres)
160
		var->xres_virtual = var->xres;
161
	if (var->yres_virtual < var->yres)
162
		var->yres_virtual = var->yres;
163
	var->xoffset = var->yoffset = 0;
164
	var->pixclock = mode->Clock ? 1000000000 / mode->Clock : 0;
165
	var->right_margin = mode->HSyncStart - mode->HDisplay;
166
	var->hsync_len = mode->HSyncEnd - mode->HSyncStart;
167
	var->left_margin = mode->HTotal - mode->HSyncEnd;
168
	var->lower_margin = mode->VSyncStart - mode->VDisplay;
169
	var->vsync_len = mode->VSyncEnd - mode->VSyncStart;
170
	var->upper_margin = mode->VTotal - mode->VSyncEnd;
171
	var->sync = 0;
172
	if (mode->Flags & V_PHSYNC)
173
		var->sync |= FB_SYNC_HOR_HIGH_ACT;
174
	if (mode->Flags & V_PVSYNC)
175
		var->sync |= FB_SYNC_VERT_HIGH_ACT;
176
	if (mode->Flags & V_PCSYNC)
177
		var->sync |= FB_SYNC_COMP_HIGH_ACT;
178
#if 1				/* Badly needed for PAL/NTSC on Amiga (amifb)!! [geert] */
179
	if (mode->Flags & V_BCAST)
180
		var->sync |= FB_SYNC_BROADCAST;
181
#endif
182
	if (mode->Flags & V_INTERLACE)
183
		var->vmode = FB_VMODE_INTERLACED;
184
	else if (mode->Flags & V_DBLSCAN)
185
		var->vmode = FB_VMODE_DOUBLE;
186
	else
187
		var->vmode = FB_VMODE_NONINTERLACED;
188
}
189
190
static void
191
ivtv2xfree_timing(struct fb_var_screeninfo *var, DisplayModePtr mode)
192
{
193
	mode->Clock = var->pixclock ? 1000000000 / var->pixclock : 28000000;
194
	mode->HDisplay = var->xres;
195
	mode->HSyncStart = mode->HDisplay + var->right_margin;
196
	mode->HSyncEnd = mode->HSyncStart + var->hsync_len;
197
	mode->HTotal = mode->HSyncEnd + var->left_margin;
198
	mode->VDisplay = var->yres;
199
	mode->VSyncStart = mode->VDisplay + var->lower_margin;
200
	mode->VSyncEnd = mode->VSyncStart + var->vsync_len;
201
	mode->VTotal = mode->VSyncEnd + var->upper_margin;
202
	mode->Flags = 0;
203
	mode->Flags |= var->sync & FB_SYNC_HOR_HIGH_ACT ? V_PHSYNC : V_NHSYNC;
204
	mode->Flags |= var->sync & FB_SYNC_VERT_HIGH_ACT ? V_PVSYNC : V_NVSYNC;
205
	mode->Flags |= var->sync & FB_SYNC_COMP_HIGH_ACT ? V_PCSYNC : V_NCSYNC;
206
#if 1				/* Badly needed for PAL/NTSC on Amiga (amifb)!! [geert] */
207
	if (var->sync & FB_SYNC_BROADCAST)
208
		mode->Flags |= V_BCAST;
209
#endif
210
	if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED)
211
		mode->Flags |= V_INTERLACE;
212
	else if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE)
213
		mode->Flags |= V_DBLSCAN;
214
	mode->SynthClock = mode->Clock;
215
	mode->CrtcHDisplay = mode->HDisplay;
216
	mode->CrtcHSyncStart = mode->HSyncStart;
217
	mode->CrtcHSyncEnd = mode->HSyncEnd;
218
	mode->CrtcHTotal = mode->HTotal;
219
	mode->CrtcVDisplay = mode->VDisplay;
220
	mode->CrtcVSyncStart = mode->VSyncStart;
221
	mode->CrtcVSyncEnd = mode->VSyncEnd;
222
	mode->CrtcVTotal = mode->VTotal;
223
	mode->CrtcHAdjusted = FALSE;
224
	mode->CrtcVAdjusted = FALSE;
225
}
226
227
/* -------------------------------------------------------------------- */
228
/* open correct framebuffer device                                      */
229
230
/* try to find the framebuffer device for a given PCI device */
231
struct v4l2_capability {
232
	__u8 driver[16];	/* i.e. "bttv" */
233
	__u8 card[32];		/* i.e. "Hauppauge WinTV" */
234
	__u8 bus_info[32];	/* "PCI:" + pci_name(pci_dev) */
235
	__u32 version;		/* should use KERNEL_VERSION() */
236
	__u32 capabilities;	/* Device capabilities */
237
	__u32 reserved[4];
238
};
239
#define VIDIOC_QUERYCAP		_IOR  ('V',  0, struct v4l2_capability)
240
241
static int ivtv_open(int scrnIndex, char *dev, char **namep, ivtvHWPtr fPtr)
242
{
243
	struct fb_fix_screeninfo fix;
244
	int fd;
245
246
	/* try argument (from XF86Config) first */
247
	if (dev) {
248
		fd = open(dev, O_RDWR, 0);
249
	} else {
250
		/* second: environment variable */
251
		dev = getenv("FRAMEBUFFER");
252
		if ((NULL == dev) || ((fd = open(dev, O_RDWR, 0)) == -1)) {
253
			/* last try: default device */
254
			dev = "/dev/fb0";
255
			fd = open(dev, O_RDWR, 0);
256
		}
257
	}
258
259
	if (fd == -1) {
260
		xf86DrvMsg(scrnIndex, X_ERROR,
261
			   "open %s: %s\n", dev, strerror(errno));
262
		return -1;
263
	}
264
265
	if (namep) {
266
		if (-1 == ioctl(fd, FBIOGET_FSCREENINFO, (void *)(&fix))) {
267
			*namep = NULL;
268
			xf86DrvMsg(scrnIndex, X_ERROR,
269
				   "FBIOGET_FSCREENINFO: %s\n",
270
				   strerror(errno));
271
			return -1;
272
		} else {
273
			*namep = xnfalloc(16);
274
			strncpy(*namep, fix.id, 16);
275
		}
276
	}
277
	if (fd != -1 && fPtr) {
278
		int fbufId = 255;
279
		int yuvId;
280
                char *devid = dev+7;
281
                if (*devid == '/')
282
                    devid++;
283
		sscanf(devid, "%d", &fbufId);
284
                
285
                xf86DrvMsg(scrnIndex, X_ERROR,"Framebuffer id from dev %sis %d\n",dev, fbufId);
286
287
		for (yuvId = 48; yuvId < 64 && fPtr->yuvDevName == NULL;
288
		     yuvId++) {
289
			char yuvDev[20] = "/dev/video";
290
			char yuvDevFull[20];
291
			char yuvDevFull1[20];
292
			int yuvFd;
293
			sprintf(yuvDevFull, "%s%d", yuvDev, yuvId);
294
			yuvFd = open(yuvDevFull, O_RDONLY);
295
                        xf86DrvMsg(scrnIndex, X_ERROR,"open %s returned  %d\n",yuvDevFull, yuvFd);
296
297
			if (yuvFd == -1 && errno == ENODEV) {
298
				sprintf(yuvDevFull1, "%s%d", yuvDev,
299
					yuvId - 48);
300
				yuvFd = open(yuvDevFull1, O_RDONLY);
301
                                xf86DrvMsg(scrnIndex, X_ERROR,"2nd open %s returned  %d\n",yuvDevFull, yuvFd);
302
			}
303
304
			if (yuvFd != -1) {
305
				int yuvFbId=-1;
306
                                int ret = ioctl(yuvFd, IVTV_IOC_GET_FB, &yuvFbId);
307
                                xf86DrvMsg(scrnIndex, X_ERROR,"get_fb returned  %d fbid %d\n",ret, yuvFbId);
308
				if (ret != -1 && yuvFbId == fbufId) {
309
					struct v4l2_capability vcap;
310
					memset(&vcap, 0, sizeof(vcap));
311
					if (ioctl(yuvFd, VIDIOC_QUERYCAP, &vcap)
312
					    < 0) {
313
						ErrorF
314
						    ("Can't query driver version so not adding Xv support on %s\n",
315
						     yuvDevFull);
316
					} else {
317
						if (vcap.version >= 0x306) {
318
							fPtr->yuvDevName =
319
							    strdup(yuvDevFull);
320
						} else {
321
							ErrorF
322
							    ("Version of ivtv is too old to support Xv\n");
323
						}
324
325
					}
326
				}
327
				close(yuvFd);
328
			}
329
330
		}
331
	}
332
	return fd;
333
}
334
335
/* -------------------------------------------------------------------- */
336
337
Bool ivtvHWProbe(pciVideoPtr pPci, char *device, char **namep)
338
{
339
	int fd;
340
	Bool retVal = TRUE;
341
	struct ivtvfb_ioctl_state_info state;
342
	fd = ivtv_open(-1, device, namep, NULL);
343
344
	if (-1 == fd)
345
		return FALSE;
346
347
	if (0 != ioctl(fd, IVTVFB_IOCTL_GET_STATE, (void *)&state)) {
348
		xf86DrvMsg(0, X_ERROR,
349
			   "ivtvHWProvbe failed to do IVTVFB_IOCTL_GET_STATE for device %s\n",
350
			   device);
351
352
		retVal = FALSE;
353
	}
354
	close(fd);
355
	return retVal;
356
}
357
358
Bool ivtvHWInit(ScrnInfoPtr pScrn, pciVideoPtr pPci, char *device)
359
{
360
	ivtvHWPtr fPtr;
361
362
	TRACE_ENTER("Init");
363
	ivtvHWGetRec(pScrn);
364
	fPtr = FBDEVHWPTR(pScrn);
365
	fPtr->fd_yuv = -1;
366
	fPtr->yuvDevName = NULL;
367
	/* open device */
368
369
	fPtr->fd = ivtv_open(pScrn->scrnIndex, device, NULL, fPtr);
370
371
	if (-1 == fPtr->fd) {
372
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
373
			   "Failed to open framebuffer device, consult warnings"
374
			   " and/or errors above for possible reasons\n"
375
			   "\t(you may have to look at the server log to see"
376
			   " warnings)\n");
377
		return FALSE;
378
	}
379
380
	/* get current fb device settings */
381
	if (-1 == ioctl(fPtr->fd, FBIOGET_FSCREENINFO, (void *)(&fPtr->fix))) {
382
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
383
			   "ioctl FBIOGET_FSCREENINFO: %s\n", strerror(errno));
384
		return FALSE;
385
	}
386
	if (-1 == ioctl(fPtr->fd, FBIOGET_VSCREENINFO, (void *)(&fPtr->var))) {
387
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
388
			   "ioctl FBIOGET_VSCREENINFO: %s\n", strerror(errno));
389
		return FALSE;
390
	}
391
392
	/* we can use the current settings as "buildin mode" */
393
	ivtv2xfree_timing(&fPtr->var, &fPtr->buildin);
394
	fPtr->buildin.name = "current";
395
	fPtr->buildin.next = &fPtr->buildin;
396
	fPtr->buildin.prev = &fPtr->buildin;
397
	fPtr->buildin.type |= M_T_BUILTIN;
398
399
	return TRUE;
400
}
401
402
char *ivtvHWGetName(ScrnInfoPtr pScrn)
403
{
404
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
405
	return fPtr->fix.id;
406
}
407
408
int ivtvHWGetDepth(ScrnInfoPtr pScrn, int *fbbpp)
409
{
410
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
411
412
	if (fbbpp)
413
		*fbbpp = fPtr->var.bits_per_pixel;
414
415
	if (fPtr->fix.visual == FB_VISUAL_TRUECOLOR ||
416
	    fPtr->fix.visual == FB_VISUAL_DIRECTCOLOR)
417
		return fPtr->var.red.length + fPtr->var.green.length +
418
		    fPtr->var.blue.length;
419
	else
420
		return fPtr->var.bits_per_pixel;
421
}
422
423
int ivtvHWGetLineLength(ScrnInfoPtr pScrn)
424
{
425
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
426
427
	if (fPtr->fix.line_length)
428
		return fPtr->fix.line_length;
429
	else
430
		return fPtr->var.xres_virtual * fPtr->var.bits_per_pixel / 8;
431
}
432
433
int ivtvHWGetType(ScrnInfoPtr pScrn)
434
{
435
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
436
	return fPtr->fix.type;
437
}
438
439
int ivtvHWGetVidmem(ScrnInfoPtr pScrn)
440
{
441
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
442
	return fPtr->fix.smem_len;
443
}
444
445
void ivtvHWSetVideoModes(ScrnInfoPtr pScrn)
446
{
447
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
448
	int virtX = pScrn->display->virtualX;
449
	int virtY = pScrn->display->virtualY;
450
	struct fb_var_screeninfo var;
451
	char **modename;
452
	DisplayModePtr mode, this, last = NULL;
453
454
	TRACE_ENTER("VerifyModes");
455
	if (NULL == pScrn->display->modes)
456
		return;
457
458
	for (modename = pScrn->display->modes; *modename != NULL; modename++) {
459
		for (mode = pScrn->monitor->Modes; mode != NULL;
460
		     mode = mode->next)
461
			if (0 == strcmp(mode->name, *modename))
462
				break;
463
		if (NULL == mode) {
464
			xf86DrvMsg(pScrn->scrnIndex, X_INFO,
465
				   "\tmode \"%s\" not found\n", *modename);
466
			continue;
467
		}
468
		memset(&var, 0, sizeof(var));
469
		xfree2ivtv_timing(mode, &var);
470
		var.xres_virtual = virtX;
471
		var.yres_virtual = virtY;
472
		var.bits_per_pixel = pScrn->bitsPerPixel;
473
		var.red.length = pScrn->weight.red;
474
		var.green.length = pScrn->weight.green;
475
		var.blue.length = pScrn->weight.blue;
476
477
		var.activate = FB_ACTIVATE_TEST;
478
		if (var.xres_virtual < var.xres)
479
			var.xres_virtual = var.xres;
480
		if (var.yres_virtual < var.yres)
481
			var.yres_virtual = var.yres;
482
		if (-1 == ioctl(fPtr->fd, FBIOPUT_VSCREENINFO, (void *)(&var))) {
483
			xf86DrvMsg(pScrn->scrnIndex, X_INFO,
484
				   "\tmode \"%s\" test failed\n", *modename);
485
			continue;
486
		}
487
		xf86DrvMsg(pScrn->scrnIndex, X_INFO,
488
			   "\tmode \"%s\" ok\n", *modename);
489
		if (virtX < var.xres)
490
			virtX = var.xres;
491
		if (virtY < var.yres)
492
			virtY = var.yres;
493
		if (NULL == pScrn->modes) {
494
			pScrn->modes = xnfalloc(sizeof(DisplayModeRec));
495
			this = pScrn->modes;
496
			memcpy(this, mode, sizeof(DisplayModeRec));
497
			this->next = this;
498
			this->prev = this;
499
		} else {
500
			this = xnfalloc(sizeof(DisplayModeRec));
501
			memcpy(this, mode, sizeof(DisplayModeRec));
502
			this->next = pScrn->modes;
503
			this->prev = last;
504
			last->next = this;
505
			pScrn->modes->prev = this;
506
		}
507
		last = this;
508
	}
509
	pScrn->virtualX = virtX;
510
	pScrn->virtualY = virtY;
511
}
512
513
DisplayModePtr ivtvHWGetBuildinMode(ScrnInfoPtr pScrn)
514
{
515
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
516
	return &fPtr->buildin;
517
}
518
519
void ivtvHWUseBuildinMode(ScrnInfoPtr pScrn)
520
{
521
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
522
523
	TRACE_ENTER("UseBuildinMode");
524
	pScrn->modes = &fPtr->buildin;
525
	pScrn->virtualX = pScrn->display->virtualX;
526
	pScrn->virtualY = pScrn->display->virtualY;
527
	if (pScrn->virtualX < fPtr->buildin.HDisplay)
528
		pScrn->virtualX = fPtr->buildin.HDisplay;
529
	if (pScrn->virtualY < fPtr->buildin.VDisplay)
530
		pScrn->virtualY = fPtr->buildin.VDisplay;
531
}
532
533
/* -------------------------------------------------------------------- */
534
535
void ivtvcalculateFbmem_len(ivtvHWPtr fPtr)
536
{
537
	fPtr->fboff = (unsigned long)fPtr->fix.smem_start & ~PAGE_MASK;
538
	fPtr->fbmem_len = (fPtr->fboff + fPtr->fix.smem_len + ~PAGE_MASK) &
539
	    PAGE_MASK;
540
}
541
542
int ivtvHWLinearOffset(ScrnInfoPtr pScrn)
543
{
544
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
545
546
	TRACE_ENTER("LinearOffset");
547
	return fPtr->fboff;
548
}
549
550
/* -------------------------------------------------------------------- */
551
552
Bool ivtvHWModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
553
{
554
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
555
556
	TRACE_ENTER("ModeInit");
557
	xfree2ivtv_fblayout(pScrn, &fPtr->var);
558
	xfree2ivtv_timing(mode, &fPtr->var);
559
#if DEBUG
560
	print_xfree_mode("init", mode);
561
	print_ivtv_mode("init", &fPtr->var);
562
#endif
563
	pScrn->vtSema = TRUE;
564
565
	/* set */
566
	if (0 != ioctl(fPtr->fd, FBIOPUT_VSCREENINFO, (void *)(&fPtr->var))) {
567
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
568
			   "FBIOPUT_VSCREENINFO: %s\n", strerror(errno));
569
		return FALSE;
570
	}
571
	/* read back */
572
	if (0 != ioctl(fPtr->fd, FBIOGET_FSCREENINFO, (void *)(&fPtr->fix))) {
573
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
574
			   "FBIOGET_FSCREENINFO: %s\n", strerror(errno));
575
		return FALSE;
576
	}
577
	if (0 != ioctl(fPtr->fd, FBIOGET_VSCREENINFO, (void *)(&fPtr->var))) {
578
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
579
			   "FBIOGET_VSCREENINFO: %s\n", strerror(errno));
580
		return FALSE;
581
	}
582
	return TRUE;
583
}
584
585
/* -------------------------------------------------------------------- */
586
/* video mode save/restore                                              */
587
588
/* TODO: colormap */
589
void ivtvHWSave(ScrnInfoPtr pScrn)
590
{
591
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
592
593
	TRACE_ENTER("Save");
594
	if (0 !=
595
	    ioctl(fPtr->fd, FBIOGET_VSCREENINFO, (void *)(&fPtr->saved_var)))
596
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
597
			   "FBIOGET_VSCREENINFO: %s\n", strerror(errno));
598
}
599
600
void ivtvHWRestore(ScrnInfoPtr pScrn)
601
{
602
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
603
604
	TRACE_ENTER("Restore");
605
	if (0 !=
606
	    ioctl(fPtr->fd, FBIOPUT_VSCREENINFO, (void *)(&fPtr->saved_var)))
607
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
608
			   "FBIOPUT_VSCREENINFO: %s\n", strerror(errno));
609
}
610
611
/* -------------------------------------------------------------------- */
612
/* callback for xf86HandleColormaps                                     */
613
614
void
615
ivtvHWLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
616
		  LOCO * colors, VisualPtr pVisual)
617
{
618
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
619
	struct fb_cmap cmap;
620
	unsigned short red, green, blue;
621
	int i;
622
623
	TRACE_ENTER("ModeInit");
624
	cmap.len = 1;
625
	cmap.red = &red;
626
	cmap.green = &green;
627
	cmap.blue = &blue;
628
	cmap.transp = NULL;
629
	for (i = 0; i < numColors; i++) {
630
		cmap.start = indices[i];
631
		red = (colors[indices[i]].red << 8) | colors[indices[i]].red;
632
		green = (colors[indices[i]].green << 8) |
633
		    colors[indices[i]].green;
634
		blue = (colors[indices[i]].blue << 8) | colors[indices[i]].blue;
635
		if (-1 == ioctl(fPtr->fd, FBIOPUTCMAP, (void *)&cmap))
636
			xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
637
				   "FBIOPUTCMAP: %s\n", strerror(errno));
638
	}
639
}
640
641
/* -------------------------------------------------------------------- */
642
/* these can be hooked directly into ScrnInfoRec                        */
643
644
int ivtvHWValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
645
{
646
	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
647
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
648
	struct fb_var_screeninfo var;
649
650
	TRACE_ENTER("ValidMode");
651
	memcpy(&var, &fPtr->var, sizeof(var));
652
	xfree2ivtv_timing(mode, &var);
653
	var.activate = FB_ACTIVATE_TEST;
654
	if (0 != ioctl(fPtr->fd, FBIOPUT_VSCREENINFO, (void *)(&fPtr->var))) {
655
		xf86DrvMsg(scrnIndex, X_ERROR,
656
			   "FBIOPUT_VSCREENINFO: %s\n", strerror(errno));
657
		return MODE_BAD;
658
	}
659
	return MODE_OK;
660
}
661
662
Bool ivtvHWSwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
663
{
664
	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
665
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
666
667
	TRACE_ENTER("SwitchMode");
668
	xfree2ivtv_timing(mode, &fPtr->var);
669
	if (0 != ioctl(fPtr->fd, FBIOPUT_VSCREENINFO, (void *)(&fPtr->var))) {
670
		xf86DrvMsg(scrnIndex, X_ERROR,
671
			   "FBIOPUT_VSCREENINFO: %s\n", strerror(errno));
672
		return FALSE;
673
	}
674
	return TRUE;
675
}
676
677
void ivtvHWAdjustFrame(int scrnIndex, int x, int y, int flags)
678
{
679
#if defined(JOHN) || DEBUG
680
	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
681
#endif
682
#ifdef JOHN
683
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
684
#endif
685
686
	TRACE_ENTER("AdjustFrame");
687
#ifdef JOHN
688
	fPtr->var.xoffset = x;
689
	fPtr->var.yoffset = y;
690
	if (-1 == ioctl(fPtr->fd, FBIOPAN_DISPLAY, (void *)&fPtr->var))
691
		xf86DrvMsgVerb(scrnIndex, 5, X_WARNING,
692
			       "FBIOPAN_DISPLAY: %s\n", strerror(errno));
693
#endif
694
}
695
696
Bool ivtvHWEnterVT(int scrnIndex, int flags)
697
{
698
	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
699
700
	TRACE_ENTER("EnterVT");
701
	if (!ivtvHWModeInit(pScrn, pScrn->currentMode))
702
		return FALSE;
703
	ivtvHWAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
704
	return TRUE;
705
}
706
707
void ivtvHWLeaveVT(int scrnIndex, int flags)
708
{
709
	ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
710
711
	TRACE_ENTER("LeaveVT");
712
	ivtvHWRestore(pScrn);
713
}
714
715
void ivtvHWDPMSSet(ScrnInfoPtr pScrn, int mode, int flags)
716
{
717
#ifdef JOHN
718
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
719
#endif
720
	unsigned long fbmode;
721
722
	if (!pScrn->vtSema)
723
		return;
724
725
	switch (mode) {
726
	case DPMSModeOn:
727
		fbmode = 0;
728
		break;
729
	case DPMSModeStandby:
730
		fbmode = 2;
731
		break;
732
	case DPMSModeSuspend:
733
		fbmode = 3;
734
		break;
735
	case DPMSModeOff:
736
		fbmode = 4;
737
		break;
738
	default:
739
		return;
740
	}
741
742
#ifdef JOHN
743
	if (-1 == ioctl(fPtr->fd, FBIOBLANK, (void *)fbmode))
744
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
745
			   "FBIOBLANK: %s\n", strerror(errno));
746
#endif
747
}
748
749
Bool ivtvHWSaveScreen(ScreenPtr pScreen, int mode)
750
{
751
#ifdef JOHN
752
	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
753
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
754
	int unblank;
755
756
	if (!pScrn->vtSema)
757
		return TRUE;
758
759
	unblank = xf86IsUnblank(mode);
760
761
	if (-1 == ioctl(fPtr->fd, FBIOBLANK, (void *)(1 - unblank))) {
762
		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
763
			   "FBIOBLANK: %s\n", strerror(errno));
764
		return FALSE;
765
	}
766
#endif
767
	return TRUE;
768
}
769
770
#define MAX_RETRY_DMA 10
771
char *lastScreen = NULL;
772
773
Bool ivtvHWSendDMA(ScrnInfoPtr pScrn, void *ptr, int x1, int x2, int y1, int y2)
774
{
775
	int totalScreenSize =
776
	    pScrn->virtualX * pScrn->virtualY * pScrn->bitsPerPixel / 8;
777
	int secondOffset = 0;
778
779
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
780
	struct ivtvfb_ioctl_dma_host_to_ivtv_args args;
781
	int cpt = MAX_RETRY_DMA;
782
783
	int startOffset =
784
	    (((y1) * pScrn->virtualX) + x1) * pScrn->bitsPerPixel / 8;
785
	int endOffset =
786
	    (((y2 - 1) * pScrn->virtualX) + x2) * pScrn->bitsPerPixel / 8;
787
788
	unsigned long totalData = endOffset - startOffset;
789
790
	if (totalData > 64 * 1024 * 4) {
791
		/* This is a bigger lump so send in 2 bits */
792
		totalData /= 2;
793
		totalData = (totalData + 65535) & ~65535;
794
		secondOffset = endOffset - totalData;
795
	} else
796
	{
797
		totalData = (totalData + 65535) & ~65535;
798
799
		if ((startOffset + totalData) > totalScreenSize) {
800
			startOffset -=
801
			    (startOffset + totalData) - totalScreenSize;
802
		}
803
	}
804
805
	args.source = ((char *)ptr + startOffset);
806
	args.dest_offset = startOffset;
807
	args.count = totalData;
808
809
	if (0 != ioctl(fPtr->fd, IVTVFB_IOCTL_PREP_FRAME, (void *)(&args))) {
810
		while (cpt--) {
811
			if (0 == ioctl(fPtr->fd,
812
				       IVTVFB_IOCTL_PREP_FRAME,
813
				       (void *)(&args)))
814
				break;
815
		}
816
	}
817
	if (secondOffset) {
818
		args.source = ((char *)ptr + secondOffset);
819
		args.dest_offset = secondOffset;
820
		args.count = totalData;
821
822
		if (0 != ioctl(fPtr->fd,
823
			       IVTVFB_IOCTL_PREP_FRAME, (void *)(&args))) {
824
			while (cpt--) {
825
				if (0 == ioctl(fPtr->fd,
826
					       IVTVFB_IOCTL_PREP_FRAME,
827
					       (void *)(&args)))
828
					break;
829
			}
830
		}
831
	}
832
833
	return TRUE;
834
}
(-)ivtvdrv-noX-no-autotools/xc/programs/Xserver/hw/xfree86/drivers/ivtv/src/ivtvhw.h (+86 lines)
Line 0 Link Here
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/ivtvhw/ivtvhw.h,v 1.11 2001/10/01 13:44:12 eich Exp $ */
2
3
#ifndef _FBDEVHW_H_
4
#define _FBDEVHW_H_
5
#include "xf86str.h"
6
#include "colormapst.h"
7
#include <asm/ioctl.h>
8
#undef __STRICT_ANSI__
9
#include <inttypes.h>
10
#include <linux/ivtv.h>
11
12
#define FBDEVHW_PACKED_PIXELS		0	/* Packed Pixels        */
13
#define FBDEVHW_PLANES			1	/* Non interleaved planes */
14
#define FBDEVHW_INTERLEAVED_PLANES	2	/* Interleaved planes   */
15
#define FBDEVHW_TEXT			3	/* Text/attributes      */
16
#define FBDEVHW_VGA_PLANES		4	/* EGA/VGA planes       */
17
#include "linux/fb.h"
18
typedef struct {
19
	/* framebuffer device: filename (/dev/fb*), handle, more */
20
	char *device;
21
	int fd;
22
	char *yuvDevName;
23
	int fd_yuv;
24
	unsigned int fbmem_len;
25
	unsigned int fboff;
26
	char *mmio;
27
	unsigned int mmio_len;
28
29
	/* current hardware state */
30
	struct fb_fix_screeninfo fix;
31
	struct fb_var_screeninfo var;
32
33
	/* saved video mode */
34
	struct fb_var_screeninfo saved_var;
35
36
	/* buildin video mode */
37
	DisplayModeRec buildin;
38
39
} ivtvHWRec, *ivtvHWPtr;
40
extern int ivtvHWPrivateIndex;
41
42
#define FBDEVHWPTRLVAL(p) (p)->privates[ivtvHWPrivateIndex].ptr
43
#define FBDEVHWPTR(p) ((ivtvHWPtr)(FBDEVHWPTRLVAL(p)))
44
45
Bool IVTVDGAInit(ScreenPtr pScreen);
46
47
#define PCI_HAUPAGGE_VENDOR_ID       0x4444
48
49
Bool ivtvHWGetRec(ScrnInfoPtr pScrn);
50
void ivtvHWFreeRec(ScrnInfoPtr pScrn);
51
52
Bool ivtvHWProbe(pciVideoPtr pPci, char *device, char **namep);
53
Bool ivtvHWInit(ScrnInfoPtr pScrn, pciVideoPtr pPci, char *device);
54
55
char *ivtvHWGetName(ScrnInfoPtr pScrn);
56
int ivtvHWGetDepth(ScrnInfoPtr pScrn, int *fbbpp);
57
int ivtvHWGetLineLength(ScrnInfoPtr pScrn);
58
int ivtvHWGetType(ScrnInfoPtr pScrn);
59
int ivtvHWGetVidmem(ScrnInfoPtr pScrn);
60
61
/*void* ivtvHWMapVidmem(ScrnInfoPtr pScrn);*/
62
int ivtvHWLinearOffset(ScrnInfoPtr pScrn);
63
64
void ivtvHWSetVideoModes(ScrnInfoPtr pScrn);
65
DisplayModePtr ivtvHWGetBuildinMode(ScrnInfoPtr pScrn);
66
void ivtvHWUseBuildinMode(ScrnInfoPtr pScrn);
67
Bool ivtvHWModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode);
68
void ivtvHWSave(ScrnInfoPtr pScrn);
69
void ivtvHWRestore(ScrnInfoPtr pScrn);
70
71
void ivtvHWLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
72
		       LOCO * colors, VisualPtr pVisual);
73
74
int ivtvHWValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose,
75
		    int flags);
76
Bool ivtvHWSwitchMode(int scrnIndex, DisplayModePtr mode, int flags);
77
void ivtvHWAdjustFrame(int scrnIndex, int x, int y, int flags);
78
Bool ivtvHWEnterVT(int scrnIndex, int flags);
79
void ivtvHWLeaveVT(int scrnIndex, int flags);
80
void ivtvHWDPMSSet(ScrnInfoPtr pScrn, int mode, int flags);
81
82
Bool ivtvHWSaveScreen(ScreenPtr pScreen, int mode);
83
Bool ivtvHWSendDMA(ScrnInfoPtr pScrn, void *ptr, int x1, int x2, int y1,
84
		   int y2);
85
86
#endif
(-)ivtvdrv-noX-no-autotools/xc/programs/Xserver/hw/xfree86/drivers/ivtv/src/ivtv_xv.c (+791 lines)
Line 0 Link Here
1
/* Based on s3virge xv code from XFree86 */
2
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/s3virge/s3v_xv.c,v 1.7 2003/02/04 02:20:50 dawes Exp $ */
3
/*
4
Copyright (C) 2000 The XFree86 Project, Inc.  All Rights Reserved.
5
6
Permission is hereby granted, free of charge, to any person obtaining a copy of
7
this software and associated documentation files (the "Software"), to deal in
8
the Software without restriction, including without limitation the rights to
9
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10
of the Software, and to permit persons to whom the Software is furnished to do
11
so, subject to the following conditions:
12
13
The above copyright notice and this permission notice shall be included in all
14
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, FIT-
18
NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
19
XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23
Except as contained in this notice, the name of the XFree86 Project shall not
24
be used in advertising or otherwise to promote the sale, use or other dealings
25
in this Software without prior written authorization from the XFree86 Project.
26
*/
27
28
/*
29
 * s3v_xv.c
30
 * X Video Extension support
31
 *
32
 * S3 ViRGE driver
33
 *
34
 * 7/2000 Kevin Brosius
35
 *
36
 * Useful references:
37
 * X Video extension support -> xc/programs/hw/xfree86/common/xf86xv.c
38
 *
39
 */
40
41
/*
42
 * I N C L U D E S
43
 */
44
#include "errno.h"
45
#include "fcntl.h"
46
#include "string.h"
47
#include "unistd.h"
48
49
#include "sys/ioctl.h"
50
51
#include "config.h"
52
#include "ivtvhw.h"
53
#include "ivtvdev.h"
54
55
#include "xf86.h"
56
#include "xf86xv.h"
57
#include "X11/extensions/Xv.h"
58
#include "fourcc.h"
59
#include "regionstr.h"
60
typedef struct ivtv_xv_portData
61
{
62
    unsigned int colorKey;
63
    RegionRec    clip;
64
    int		 autopaintColorKey;
65
}Ivtv_Xv_PortData;
66
67
68
#define IVTV_MAX_PORTS 1
69
#define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE)
70
71
#if !defined(XvExtension) || !defined(IVTV_IOC_PREP_FRAME_YUV)
72
void IvtvInitVideo(ScreenPtr pScreen)
73
{
74
    ErrorF("XVDriver disabled at compilation time\n");
75
}
76
#else
77
78
static XF86VideoAdaptorPtr IVTVSetupImageVideoOverlay(ScreenPtr);
79
static int IVTVSetPortAttributeOverlay(ScrnInfoPtr, Atom, INT32, pointer);
80
static int IVTVGetPortAttributeOverlay(ScrnInfoPtr, Atom, INT32 *, pointer);
81
82
static void IVTVStopVideo(ScrnInfoPtr, pointer, Bool);
83
84
static void IVTVQueryBestSize(ScrnInfoPtr, Bool, short, short, short, short,
85
			      unsigned int *, unsigned int *, pointer);
86
static int IVTVPutImage(ScrnInfoPtr, short, short, short, short, short,
87
			short, short, short, int, unsigned char *, short,
88
			short, Bool, RegionPtr, pointer, DrawablePtr);
89
static int IVTVQueryImageAttributes(ScrnInfoPtr, int, unsigned short *,
90
				    unsigned short *, int *, int *);
91
92
void IvtvInitVideo(ScreenPtr pScreen)
93
{
94
	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
95
	XF86VideoAdaptorPtr *adaptors, *newAdaptors = NULL;
96
	XF86VideoAdaptorPtr newAdaptor = NULL;
97
	int num_adaptors;
98
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
99
100
	ErrorF("Here I am with fPtr %p\n", fPtr);
101
	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
102
		   "and YUV dev name %p\n", fPtr->yuvDevName);
103
104
	if (!fPtr->yuvDevName)
105
		return;
106
107
	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
108
		   "Enabling Xv support for PVR350\n");
109
	newAdaptor = IVTVSetupImageVideoOverlay(pScreen);
110
111
	num_adaptors = xf86XVListGenericAdaptors(pScrn, &adaptors);
112
113
	if (newAdaptor) {
114
		if (!num_adaptors) {
115
			num_adaptors = 1;
116
			adaptors = &newAdaptor;
117
		} else {
118
			newAdaptors =	/* need to free this someplace */
119
			    xalloc((num_adaptors +
120
				    1) * sizeof(XF86VideoAdaptorPtr *));
121
			if (newAdaptors) {
122
				memcpy(newAdaptors, adaptors, num_adaptors *
123
				       sizeof(XF86VideoAdaptorPtr));
124
				newAdaptors[num_adaptors] = newAdaptor;
125
				adaptors = newAdaptors;
126
				num_adaptors++;
127
			}
128
		}
129
	}
130
131
	if (num_adaptors)
132
		xf86XVScreenInit(pScreen, adaptors, num_adaptors);
133
134
	if (newAdaptors)
135
		xfree(newAdaptors);
136
}
137
138
/* client libraries expect an encoding */
139
static XF86VideoEncodingRec DummyEncoding[1] = {
140
	{			/* overlay limit */
141
	 0,
142
	 "XV_IMAGE",
143
	 768, 576,
144
	 {1, 1}
145
	 }
146
};
147
148
#define NUM_FORMATS_OVERLAY 4
149
#define NUM_FORMATS_TEXTURE 4
150
151
static XF86VideoFormatRec Formats[NUM_FORMATS_TEXTURE] = {
152
	/*{15, TrueColor}, */ {16, TrueColor}, {24, TrueColor}
153
	/* ,
154
	   {15, DirectColor} */ , {16, DirectColor}, {24, DirectColor}
155
};
156
157
#define NUM_IMAGES 1
158
159
static XF86ImageRec Images[NUM_IMAGES] = {
160
	XVIMAGE_YV12
161
	    /* XVIMAGE_UYVY */
162
};
163
164
#define NUM_ATTRIBUTES_OVERLAY 2
165
166
static XF86AttributeRec Attributes[NUM_ATTRIBUTES_OVERLAY] =
167
{
168
   {XvSettable | XvGettable, 0, (1 << 24) - 1, "XV_COLORKEY"},
169
   {XvSettable | XvGettable, 0, 1, "XV_AUTOPAINT_COLORKEY"},
170
171
#if 0
172
   {XvSettable | XvGettable, -128, 127, "XV_BRIGHTNESS"},
173
   {XvSettable | XvGettable, 0, 255, "XV_CONTRAST"}
174
#endif
175
};
176
static Atom  xvColorKey, xvAutopaintColorKey;
177
178
static int
179
IVTVSetPortAttributeOverlay(ScrnInfoPtr pScrn,
180
			    Atom attribute, INT32 value, pointer data)
181
{
182
        Ivtv_Xv_PortData *pPriv = (Ivtv_Xv_PortData *)data;
183
#ifdef JOHN
184
	if (attribute == xvBrightness) {
185
		if ((value < -128) || (value > 127))
186
			return BadValue;
187
		pPriv->brightness = value;
188
		OUTREG(MGAREG_BESLUMACTL, ((pPriv->brightness & 0xff) << 16) |
189
		       (pPriv->contrast & 0xff));
190
	} else if (attribute == xvContrast) {
191
		if ((value < 0) || (value > 255))
192
			return BadValue;
193
		pPriv->contrast = value;
194
		OUTREG(MGAREG_BESLUMACTL, ((pPriv->brightness & 0xff) << 16) |
195
		       (pPriv->contrast & 0xff));
196
	} else 
197
#endif
198
            if (attribute == xvColorKey) {
199
		pPriv->colorKey = value;
200
#ifdef JOHN
201
		outMGAdac(0x55, (pPriv->colorKey & pScrn->mask.red) >>
202
			  pScrn->offset.red);
203
		outMGAdac(0x56, (pPriv->colorKey & pScrn->mask.green) >>
204
			  pScrn->offset.green);
205
		outMGAdac(0x57, (pPriv->colorKey & pScrn->mask.blue) >>
206
			  pScrn->offset.blue);
207
#endif
208
		REGION_EMPTY(pScrn->pScreen, &pPriv->clip);
209
	}else if (attribute == xvAutopaintColorKey) {
210
		pPriv->autopaintColorKey = value;
211
        } else
212
        {
213
            ErrorF("IvtvSetPortAttributeOverlay bad attribute\n");
214
215
		return BadMatch;
216
        }
217
218
	return Success;
219
}
220
221
static int
222
IVTVGetPortAttributeOverlay(ScrnInfoPtr pScrn,
223
			    Atom attribute, INT32 * value, pointer data)
224
{
225
        Ivtv_Xv_PortData *pPriv = (Ivtv_Xv_PortData *)data;
226
227
#ifdef JOHN
228
	if (attribute == xvBrightness) {
229
		*value = pPriv->brightness;
230
	} else if (attribute == xvContrast) {
231
		*value = pPriv->contrast;
232
	} else
233
#endif
234
            if (attribute == xvColorKey) {
235
		*value = pPriv->colorKey;
236
	} else if (attribute == xvAutopaintColorKey) {
237
		*value = pPriv->autopaintColorKey;
238
	} else
239
        {
240
            ErrorF("IvtvGetPortAttributeOverlay bad attribute\n");
241
		return BadMatch;
242
        }
243
244
	return Success;
245
}
246
247
static void
248
IVTVQueryBestSize(ScrnInfoPtr pScrn,
249
		  Bool motion,
250
		  short vid_w, short vid_h,
251
		  short drw_w, short drw_h,
252
		  unsigned int *p_w, unsigned int *p_h, pointer data)
253
{
254
    ErrorF("Query best vid_w %d vid_h %d drw_w %d drw_h %d\n",
255
           vid_w, vid_h, drw_w, drw_h);
256
	*p_w = drw_w;
257
	*p_h = drw_h;
258
}
259
260
static XF86VideoAdaptorPtr IVTVAllocAdaptor(ScreenPtr pScreen)
261
{
262
	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
263
	XF86VideoAdaptorPtr adapt;
264
	DevUnion *pPriv;
265
	int i;
266
267
	if (!(adapt = xf86XVAllocateVideoAdaptorRec(pScrn)))
268
		return NULL;
269
270
	if (!(pPriv = xcalloc(1, sizeof(DevUnion) * IVTV_MAX_PORTS))) {
271
		xfree(adapt);
272
		return NULL;
273
	}
274
275
	adapt->pPortPrivates = pPriv;
276
277
	for (i = 0; i < IVTV_MAX_PORTS; i++)
278
        {
279
            Ivtv_Xv_PortData *portData =  (Ivtv_Xv_PortData *)xcalloc(1,sizeof(Ivtv_Xv_PortData));
280
            portData->colorKey = 101;
281
            portData->autopaintColorKey = 0;
282
#ifdef X_USE_REGION_NULL
283
            REGION_NULL(pScreen, &portData->clip);
284
#else
285
            REGION_INIT(pScreen, &portData->clip, NullBox, 0); 
286
#endif
287
            adapt->pPortPrivates[i].ptr =portData;
288
        }
289
            
290
291
#if 0
292
	xvBrightness = MAKE_ATOM("XV_BRIGHTNESS");
293
	xvContrast = MAKE_ATOM("XV_CONTRAST");
294
#endif
295
	xvColorKey 		= MAKE_ATOM("XV_COLORKEY");
296
        xvAutopaintColorKey 	= MAKE_ATOM("XV_AUTOPAINT_COLORKEY");
297
298
	return adapt;
299
}
300
301
static XF86VideoAdaptorPtr IVTVSetupImageVideoOverlay(ScreenPtr pScreen)
302
{
303
#ifdef JOHN
304
	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
305
#endif
306
	XF86VideoAdaptorPtr adapt;
307
	adapt = IVTVAllocAdaptor(pScreen);
308
309
	adapt->type = XvWindowMask | XvInputMask | XvImageMask;
310
	adapt->flags = VIDEO_OVERLAID_IMAGES | VIDEO_CLIP_TO_VIEWPORT;
311
	adapt->name = "PVR350";
312
	adapt->nEncodings = 1;
313
	adapt->pEncodings = &DummyEncoding[0];
314
	adapt->nFormats = NUM_FORMATS_OVERLAY;
315
	adapt->pFormats = Formats;
316
	adapt->nPorts = 1;
317
	adapt->pAttributes = Attributes /*Attributes */ ;
318
	adapt->nImages = 1;
319
	adapt->nAttributes = NUM_ATTRIBUTES_OVERLAY;
320
	adapt->pImages = Images;
321
	adapt->PutVideo = NULL;
322
	adapt->PutStill = NULL;
323
	adapt->GetVideo = NULL;
324
	adapt->GetStill = NULL;
325
	adapt->StopVideo = IVTVStopVideo;
326
	/* Empty Attrib functions - required anyway */
327
	adapt->SetPortAttribute = IVTVSetPortAttributeOverlay;
328
	adapt->GetPortAttribute = IVTVGetPortAttributeOverlay;
329
	adapt->QueryBestSize = IVTVQueryBestSize;
330
	adapt->PutImage = IVTVPutImage;
331
	adapt->QueryImageAttributes = IVTVQueryImageAttributes;
332
333
	return adapt;
334
}
335
336
static Bool RegionsEqual(RegionPtr A, RegionPtr B)
337
{
338
	int *dataA, *dataB;
339
	int num;
340
341
	num = REGION_NUM_RECTS(A);
342
	if (num != REGION_NUM_RECTS(B))
343
		return FALSE;
344
345
	if ((A->extents.x1 != B->extents.x1) ||
346
	    (A->extents.x2 != B->extents.x2) ||
347
	    (A->extents.y1 != B->extents.y1) ||
348
	    (A->extents.y2 != B->extents.y2))
349
		return FALSE;
350
351
	dataA = (int *)REGION_RECTS(A);
352
	dataB = (int *)REGION_RECTS(B);
353
354
	while (num--) {
355
		if ((dataA[0] != dataB[0]) || (dataA[1] != dataB[1]))
356
			return FALSE;
357
		dataA += 2;
358
		dataB += 2;
359
	}
360
361
	return TRUE;
362
}
363
364
#ifdef JOHN
365
/* Not using this at the moment */
366
/* IVTVClipVideo - copied from MGAClipVideo -  
367
368
   Takes the dst box in standard X BoxRec form (top and left
369
   edges inclusive, bottom and right exclusive).  The new dst
370
   box is returned.  The source boundaries are given (x1, y1 
371
   inclusive, x2, y2 exclusive) and returned are the new source 
372
   boundaries in 16.16 fixed point. 
373
*/
374
375
#define DummyScreen screenInfo.screens[0]
376
377
static Bool
378
IVTVClipVideo(BoxPtr dst,
379
	      INT32 * x1,
380
	      INT32 * x2,
381
	      INT32 * y1, INT32 * y2, RegionPtr reg, INT32 width, INT32 height)
382
{
383
	INT32 vscale, hscale, delta;
384
	BoxPtr extents = REGION_EXTENTS(DummyScreen, reg);
385
	int diff;
386
387
	hscale = ((*x2 - *x1) << 16) / (dst->x2 - dst->x1);
388
	vscale = ((*y2 - *y1) << 16) / (dst->y2 - dst->y1);
389
390
	*x1 <<= 16;
391
	*x2 <<= 16;
392
	*y1 <<= 16;
393
	*y2 <<= 16;
394
395
	diff = extents->x1 - dst->x1;
396
	if (diff > 0) {
397
		dst->x1 = extents->x1;
398
		*x1 += diff * hscale;
399
	}
400
	diff = dst->x2 - extents->x2;
401
	if (diff > 0) {
402
		dst->x2 = extents->x2;
403
		*x2 -= diff * hscale;
404
	}
405
	diff = extents->y1 - dst->y1;
406
	if (diff > 0) {
407
		dst->y1 = extents->y1;
408
		*y1 += diff * vscale;
409
	}
410
	diff = dst->y2 - extents->y2;
411
	if (diff > 0) {
412
		dst->y2 = extents->y2;
413
		*y2 -= diff * vscale;
414
	}
415
416
	if (*x1 < 0) {
417
		diff = (-*x1 + hscale - 1) / hscale;
418
		dst->x1 += diff;
419
		*x1 += diff * hscale;
420
	}
421
	delta = *x2 - (width << 16);
422
	if (delta > 0) {
423
		diff = (delta + hscale - 1) / hscale;
424
		dst->x2 -= diff;
425
		*x2 -= diff * hscale;
426
	}
427
	if (*x1 >= *x2)
428
		return FALSE;
429
430
	if (*y1 < 0) {
431
		diff = (-*y1 + vscale - 1) / vscale;
432
		dst->y1 += diff;
433
		*y1 += diff * vscale;
434
	}
435
	delta = *y2 - (height << 16);
436
	if (delta > 0) {
437
		diff = (delta + vscale - 1) / vscale;
438
		dst->y2 -= diff;
439
		*y2 -= diff * vscale;
440
	}
441
	if (*y1 >= *y2)
442
		return FALSE;
443
444
	if ((dst->x1 != extents->x1) || (dst->x2 != extents->x2) ||
445
	    (dst->y1 != extents->y1) || (dst->y2 != extents->y2)) {
446
		RegionRec clipReg;
447
		REGION_INIT(DummyScreen, &clipReg, dst, 1);
448
		REGION_INTERSECT(DummyScreen, reg, reg, &clipReg);
449
		REGION_UNINIT(DummyScreen, &clipReg);
450
	}
451
	return TRUE;
452
}
453
#endif
454
455
static void IVTVStopVideo(ScrnInfoPtr pScrn, pointer data, Bool shutdown)
456
{
457
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
458
        Ivtv_Xv_PortData *pPriv = (Ivtv_Xv_PortData *)data;
459
460
	REGION_EMPTY(pScrn->pScreen, &pPriv->clip);
461
462
	if (shutdown) {
463
		if (fPtr->fd_yuv != -1) {
464
			close(fPtr->fd_yuv);
465
			fPtr->fd_yuv = -1;
466
                        struct ivtvfb_ioctl_colorkey colorKey;
467
                        colorKey.state = 0;
468
                        colorKey.colorKey = pPriv->colorKey;
469
                        if (ioctl(fPtr->fd,IVTVFB_IOCTL_SET_COLORKEY, &colorKey) < 0) {
470
                            ErrorF
471
                                ("IVTVFB_IOCTL_SET_COLORKEY failed (error: %s)\n",
472
                                 strerror(errno));
473
                        }
474
		}
475
	}
476
477
}
478
479
static void de_macro_y(unsigned char *src, unsigned char *dst,
480
		       int w, int h, int src_x, int src_y, int height, int width)
481
{
482
	unsigned int x, y, i;
483
	unsigned char *dst_2;
484
	unsigned int h_tail, w_tail;
485
	unsigned int h_size, w_size;
486
487
	// Always round the origin, but compensate by increasing the size
488
	if (src_x & 15) {
489
		w += src_x & 15;
490
		src_x &= ~15;
491
	}
492
493
	if (src_y & 15) {
494
		h += src_y & 15;
495
		src_y &= ~15;
496
	}
497
498
	// The right / bottom edge might not be a multiple of 16
499
	h_tail = h & 15;
500
	w_tail = w & 15;
501
502
	// One block is 16 pixels high
503
	h_size = 16;
504
505
	// descramble Y plane
506
	for (y = 0; y < h; y += 16) {
507
508
		// Clip if we've reached the bottom & the size isn't a multiple of 16
509
		if (y + 16 > h) h_size = h_tail;
510
511
		for (x = 0; x < w; x += 16) {
512
			if (x + 16 > w)
513
				w_size = w_tail;
514
			else
515
				w_size = 16;
516
517
			dst_2 = dst + (720 * y) + (720 * src_y) + (256 * (src_x>>4)) + (x * 16);
518
519
			for (i = 0; i < h_size; i++) {
520
				memcpy(dst_2, src + src_x + x + (y + i) * width + (src_y * width), w_size);
521
				dst_2 += 16;
522
			}
523
		}
524
	}
525
}
526
527
static void de_macro_uv(unsigned char *srcu, unsigned char *srcv,
528
			unsigned char *dst, int w, int h, int src_x, int src_y,
529
		       int height, int width)
530
{
531
	unsigned int x, y, i, f;
532
	unsigned char *dst_2;
533
	unsigned int h_tail, w_tail;
534
	unsigned int h_size;
535
536
	// The uv plane is half the size of the y plane, so 'correct' all dimensions.
537
	w /= 2;
538
	h /= 2;
539
	src_x /= 2;
540
	src_y /= 2;
541
	height /= 2;
542
	width /= 2;
543
544
	// Always round the origin, but compensate by increasing the size
545
	if (src_x & 7) {
546
		w += src_x & 7;
547
		src_x &= ~7;
548
	}
549
550
	if (src_y & 15) {
551
		h += src_y & 15;
552
		src_y &= ~15;
553
	}
554
555
	// The right / bottom edge may not be a multiple of 16
556
	h_tail = h & 15;
557
	w_tail = w & 7;
558
559
	h_size = 16;
560
561
	// descramble U/V plane
562
	for (y = 0; y < h; y += 16) {
563
		if ( y + 16 > h ) h_size = h_tail;
564
		for (x = 0; x < w; x += 8) {
565
			dst_2 = dst + (720 * y) + (720 * src_y) + (256 * (src_x>>3)) + (x * 32);
566
			if (x + 8 <= w) {
567
				for (i = 0; i < h_size; i++) {
568
					int idx = src_x + x + ((y + i) * width) + (src_y * width);
569
					dst_2[0] = srcu[idx + 0];
570
					dst_2[1] = srcv[idx + 0];
571
					dst_2[2] = srcu[idx + 1];
572
					dst_2[3] = srcv[idx + 1];
573
					dst_2[4] = srcu[idx + 2];
574
					dst_2[5] = srcv[idx + 2];
575
					dst_2[6] = srcu[idx + 3];
576
					dst_2[7] = srcv[idx + 3];
577
					dst_2[8] = srcu[idx + 4];
578
					dst_2[9] = srcv[idx + 4];
579
					dst_2[10] = srcu[idx + 5];
580
					dst_2[11] = srcv[idx + 5];
581
					dst_2[12] = srcu[idx + 6];
582
					dst_2[13] = srcv[idx + 6];
583
					dst_2[14] = srcu[idx + 7];
584
					dst_2[15] = srcv[idx + 7];
585
					dst_2 += 16;
586
				}
587
			}
588
			else {
589
				for (i = 0; i < h_size; i ++) {
590
					int idx = src_x + x + ((y + i) * width) + (src_y * width);
591
					for (f = 0; f < w_tail; f++) {
592
						dst_2[0] = srcu[idx + f];
593
						dst_2[1] = srcv[idx + f];
594
						dst_2 += 2;
595
					}
596
/*
597
					// Used for testing edge cutoff. Sets colour to Green
598
					for (f = w_tail;f < 8;f ++) {
599
						dst_2[0] = 0;
600
						dst_2[1] = 0;
601
						dst_2 += 2;
602
					}
603
*/
604
					dst_2 += 16 - (w_tail << 1);
605
				}
606
			}
607
		}
608
	}
609
}
610
611
static unsigned char outbuf[622080];
612
613
static int
614
IVTVPutImage(ScrnInfoPtr pScrn,
615
	     short src_x, short src_y,
616
	     short drw_x, short drw_y,
617
	     short src_w, short src_h,
618
	     short drw_w, short drw_h,
619
	     int id, unsigned char *buf,
620
	     short width, short height,
621
	     Bool sync, RegionPtr clipBoxes, pointer data, DrawablePtr pDraw)
622
{
623
	ivtvHWPtr fPtr = FBDEVHWPTR(pScrn);
624
        Ivtv_Xv_PortData *pPriv = (Ivtv_Xv_PortData *)data;
625
626
	struct ivtvyuv_ioctl_dma_host_to_ivtv_args args;
627
#ifdef JOHN
628
        ErrorF("src_w %d src_h %d drw_w %d drw_h %d width %d height %d\n",
629
               src_w, src_h, drw_w, drw_h, width, height);
630
        ErrorF("src_x %d src_y %d drw_x %d drw_y %d width %d height %d\n",
631
               src_x, src_y, drw_x, drw_y, width, height);
632
#endif
633
634
	// FIXME - Is this the correct place for this ?
635
636
	// Source coordinates must be even
637
	// For origin, round down
638
	src_x &= ~1;
639
	src_y &= ~1;
640
641
	// For size, round up
642
	src_w += src_w & 1;
643
	src_h += src_h & 1;
644
645
#ifdef JOHN
646
	INT32 x1, x2, y1, y2;
647
	unsigned char *dst_start;
648
	int top, left, npixels, nlines;
649
	int pitch, dstPitch;
650
	int new_h;
651
652
	BoxRec dstBox;
653
	CARD32 tmp;
654
	static int once = 1;
655
	static int once2 = 1;
656
657
	/* Clip */
658
	x1 = src_x;
659
	x2 = src_x + src_w;
660
	y1 = src_y;
661
	y2 = src_y + src_h;
662
663
	dstBox.x1 = drw_x;
664
	dstBox.x2 = drw_x + drw_w;
665
	dstBox.y1 = drw_y;
666
	dstBox.y2 = drw_y + drw_h;
667
668
#ifdef JOHN
669
	if (!IVTVClipVideo
670
	    (&dstBox, &x1, &x2, &y1, &y2, clipBoxes, width, height))
671
		return Success;
672
#endif
673
674
	dstBox.x1 -= pScrn->frameX0;
675
	dstBox.x2 -= pScrn->frameX0;
676
	dstBox.y1 -= pScrn->frameY0;
677
	dstBox.y2 -= pScrn->frameY0;
678
679
	pitch = pScrn->bitsPerPixel * pScrn->displayWidth >> 3;
680
681
	dstPitch = ((width << 1) + 15) & ~15;
682
	new_h = ((dstPitch * height) + pitch - 1) / pitch;
683
#endif
684
685
	switch (id) {
686
687
	case FOURCC_YV12:
688
		{
689
			de_macro_y(buf, outbuf, src_w, src_h, src_x, src_y, height, width);
690
			de_macro_uv(buf + (width * height) + width * height/ 4,
691
				    buf + (width * height), outbuf + 720 * 576,
692
				    src_w,  src_h, src_x, src_y, height, width);
693
694
			args.y_source = outbuf;
695
			args.uv_source = outbuf + (720 * 576);
696
			args.src_x = src_x;
697
                        args.src_y = src_y;
698
                        args.dst_x = drw_x;
699
                        args.dst_y = drw_y;
700
			args.src_w = src_w;
701
                        args.dst_w = drw_w;
702
                        args.srcBuf_width = width;
703
			args.src_h = src_h;
704
                        args.dst_h = drw_h;
705
                        args.srcBuf_height = height;
706
		}
707
		break;
708
	default:
709
		return BadMatch;
710
	}
711
	if (fPtr->fd_yuv == -1) {
712
		if ((fPtr->fd_yuv = open(fPtr->yuvDevName, O_RDWR)) == -1) {
713
			if (errno == ENODEV)
714
				ErrorF
715
				    ("Failed to open \"%s\". Need to initialize the mpeg decoder before the YUV output can be used\n",
716
				     fPtr->yuvDevName);
717
			else
718
				ErrorF("Failed to open \"%s\" Error %s\n",
719
				       fPtr->yuvDevName, strerror(errno));
720
			return BadAccess;
721
		}
722
                struct ivtvfb_ioctl_colorkey colorKey;
723
                colorKey.state = 1;
724
                colorKey.colorKey = pPriv->colorKey;
725
                if (ioctl(fPtr->fd,IVTVFB_IOCTL_SET_COLORKEY, &colorKey) < 0) {
726
                    ErrorF
727
                        ("IVTVFB_IOCTL_SET_COLORKEY failed (error: %s)\n",
728
                         strerror(errno));
729
                }
730
	}
731
	int ret = ioctl(fPtr->fd_yuv, IVTV_IOC_PREP_FRAME_YUV, &args);
732
	if (ret == -1) {
733
		ErrorF
734
		    ("Ioctl IVTV_IOC_PREP_FRAME_YUV returned failed Error %s\n",
735
		     strerror(errno));
736
		return BadImplementation;
737
	}
738
                                                                          
739
        if(pPriv->autopaintColorKey && 
740
           !RegionsEqual( &pPriv->clip, clipBoxes))
741
        {
742
            /* we always paint V4L's color key */
743
            REGION_COPY(pScrn->pScreen, &pPriv->clip, clipBoxes);
744
            xf86XVFillKeyHelper(pScrn->pScreen, pPriv->colorKey, clipBoxes);
745
        }
746
	return Success;
747
}
748
749
static int
750
IVTVQueryImageAttributes(ScrnInfoPtr pScrn,
751
			 int id,
752
			 unsigned short *w, unsigned short *h,
753
			 int *pitches, int *offsets)
754
{
755
	int size = 0, tmp;
756
757
	if (*w > 768)
758
		*w = 768;
759
	if (*h > pScrn->virtualY)
760
		*h = pScrn->virtualY;
761
762
	*w = (*w + 1) & ~1;
763
	if (offsets)
764
		offsets[0] = 0;
765
766
	switch (id) {
767
	case FOURCC_YV12:
768
		*h = (*h + 1) & ~1;
769
		size = (*w + 3) & ~3;
770
		if (pitches)
771
			pitches[0] = size;
772
		size *= *h;
773
		if (offsets)
774
			offsets[1] = size;
775
		tmp = ((*w >> 1) + 3) & ~3;
776
		if (pitches)
777
			pitches[1] = pitches[2] = tmp;
778
		tmp *= (*h >> 1);
779
		size += tmp;
780
		if (offsets)
781
			offsets[2] = size;
782
		size += tmp;
783
		break;
784
	default:
785
		break;
786
	}
787
788
	return size;
789
}
790
791
#endif				/* !XvExtension */
(-)ivtvdrv-noX-no-autotools/xc/programs/Xserver/hw/xfree86/drivers/ivtv/TODO (-11 lines)
Lines 1-11 Link Here
1
 DONE write to 82c registers from driver
2
 DONE open /dev/video0 if 48 returns ENODEV and check id.
3
 DONE Try to fail sensibly in PutImage
4
 DONE define better structure for ioctl
5
 DONE Buffer allocation for stream in driver
6
 DONE Compiler warnings
7
 DONE Apply to latest ivtv source
8
 DONE Make ivtv_xv cope with NTSC (don't hard code 576)
9
 DONE vsync wakeup for dma_to_device_vsync
10
make ioctl fail if bad type
11
do ioctl with bad type and make sure it fails appropriatly to detect correct driver.

Return to bug 140323