[xserver-commit] xserver/hw/kdrive/ati Makefile.am,1.1,1.2 ati.c,1.6,1.7 ati.h,1.2,1.3 ati_stub.c,1.1,1.2

Eric Anholt xserver-commit@pdx.freedesktop.org
Sun, 30 Nov 2003 20:34:06 -0800


Committed by: anholt

Update of /cvs/xserver/xserver/hw/kdrive/ati
In directory pdx:/home/anholt/xserver/hw/kdrive/ati

Modified Files:
	Makefile.am ati.c ati.h ati_stub.c 
Log Message:
- Add fbdev mode-setting backend to Xati.  It and vesa are compiled
  in when available, with fbdev being used by default.
- Use depth 16 by default when vesa backend is used.
- Add MMIO defines for PowerPC (should be in a common location).

Many thanks for Michel Daenzer for much of this code.


Index: Makefile.am
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/ati/Makefile.am,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Makefile.am	19 Nov 2003 08:32:35 -0000	1.1
+++ Makefile.am	1 Dec 2003 04:33:33 -0000	1.2
@@ -1,6 +1,18 @@
+if KDRIVEFBDEV
+FBDEV_INCLUDES =-I$(top_srcdir)/hw/kdrive/fbdev
+FBDEV_LIBS = $(top_builddir)/hw/kdrive/fbdev/libfbdev.a
+endif
+
+if KDRIVEVESA
+VESA_INCLUDES = -I$(top_srcdir)/hw/kdrive/vesa
+VESA_LIBS = $(top_builddir)/hw/kdrive/vesa/libvesa.a
+endif
+
+
 INCLUDES = 					\
 	@KDRIVE_INCS@				\
-	-I$(top_srcdir)/hw/kdrive/vesa		\
+	$(FBDEV_INCLUDES)			\
+	$(VESA_INCLUDES)			\
 	@XSERVER_CFLAGS@
 
 bin_PROGRAMS = Xati
@@ -22,7 +34,8 @@
 
 Xati_LDADD = \
 	libati.a 				\
-	$(top_builddir)/hw/kdrive/vesa/libvesa.a \
+	$(FBDEV_LIBS)				\
+	$(VESA_LIBS)				\
 	@KDRIVE_LIBS@				\
 	@XSERVER_LIBS@                          \
 	$(TSLIB_FLAG)

Index: ati.c
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/ati/ati.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- ati.c	1 Dec 2003 03:15:13 -0000	1.6
+++ ati.c	1 Dec 2003 04:33:33 -0000	1.7
@@ -157,15 +157,50 @@
 {
 	ATICardInfo *atic;
 	int i;
+	Bool initialized = FALSE;
 
-	atic = xalloc(sizeof(ATICardInfo));
+	atic = xcalloc(sizeof(ATICardInfo), 1);
 	if (atic == NULL)
 		return FALSE;
 
-	ATIMapReg(card, atic);
+#ifdef KDRIVEFBDEV
+	if (!initialized && fbdevInitialize(card, &atic->backend_priv.fbdev)) {
+		atic->use_fbdev = TRUE;
+		initialized = TRUE;
+		atic->backend_funcs.cardfini = fbdevCardFini;
+		atic->backend_funcs.scrfini = fbdevScreenFini;
+		atic->backend_funcs.initScreen = fbdevInitScreen;
+		atic->backend_funcs.finishInitScreen = fbdevFinishInitScreen;
+		atic->backend_funcs.createRes = fbdevCreateResources;
+		atic->backend_funcs.preserve = fbdevPreserve;
+		atic->backend_funcs.restore = fbdevRestore;
+		atic->backend_funcs.dpms = fbdevDPMS;
+		atic->backend_funcs.enable = fbdevEnable;
+		atic->backend_funcs.disable = fbdevDisable;
+		atic->backend_funcs.getColors = fbdevGetColors;
+		atic->backend_funcs.putColors = fbdevPutColors;
+	}
+#endif
+#ifdef KDRIVEVESA
+	if (!initialized && vesaInitialize(card, &atic->backend_priv.vesa)) {
+		atic->use_vesa = TRUE;
+		initialized = TRUE;
+		atic->backend_funcs.cardfini = vesaCardFini;
+		atic->backend_funcs.scrfini = vesaScreenFini;
+		atic->backend_funcs.initScreen = vesaInitScreen;
+		atic->backend_funcs.finishInitScreen = vesaFinishInitScreen;
+		atic->backend_funcs.createRes = vesaCreateResources;
+		atic->backend_funcs.preserve = vesaPreserve;
+		atic->backend_funcs.restore = vesaRestore;
+		atic->backend_funcs.dpms = vesaDPMS;
+		atic->backend_funcs.enable = vesaEnable;
+		atic->backend_funcs.disable = vesaDisable;
+		atic->backend_funcs.getColors = vesaGetColors;
+		atic->backend_funcs.putColors = vesaPutColors;
+	}
+#endif
 
-	if (!vesaInitialize(card, &atic->vesa))
-	{
+	if (!initialized || !ATIMapReg(card, atic)) {
 		xfree(atic);
 		return FALSE;
 	}
@@ -185,39 +220,51 @@
 	ATICardInfo *atic = (ATICardInfo *)card->driver;
 
 	ATIUnmapReg(card, atic);
-	vesaCardFini(card);
+	atic->backend_funcs.cardfini(card);
 }
 
 static Bool
 ATIScreenInit(KdScreenInfo *screen)
 {
 	ATIScreenInfo *atis;
-	int screen_size, memory;
+	ATICardInfo *atic = screen->card->driver;
+	int success = FALSE;
 
-	atis = xalloc(sizeof(ATIScreenInfo));
+	atis = xcalloc(sizeof(ATIScreenInfo), 1);
 	if (atis == NULL)
 		return FALSE;
-	memset(atis, '\0', sizeof(ATIScreenInfo));
 
-	if (!vesaScreenInitialize(screen, &atis->vesa))
-	{
+	if (screen->fb[0].depth == 0)
+		screen->fb[0].depth = 16;
+
+	screen->driver = atis;
+
+#ifdef KDRIVEFBDEV
+	if (atic->use_fbdev) {
+		success = fbdevScreenInitialize(screen,
+						&atis->backend_priv.fbdev);
+		screen->memory_size = min(atic->backend_priv.fbdev.fix.smem_len,
+		    8192 * screen->fb[0].byteStride);
+		/*screen->memory_size = atic->backend_priv.fbdev.fix.smem_len;*/
+		screen->off_screen_base =
+		    atic->backend_priv.fbdev.var.yres_virtual *
+		    screen->fb[0].byteStride;
+	}
+#endif
+#ifdef KDRIVEVESA
+	if (atic->use_vesa) {
+		if (screen->fb[0].depth == 0)
+			screen->fb[0].depth = 16;
+		success = vesaScreenInitialize(screen,
+		    &atis->backend_priv.vesa);
+	}
+#endif
+	if (!success) {
+		screen->driver = NULL;
 		xfree(atis);
 		return FALSE;
 	}
-	atis->screen = atis->vesa.fb;
-
-	memory = atis->vesa.fb_size;
-	screen_size = screen->fb[0].byteStride * screen->height;
 
-	memory -= screen_size;
-	if (memory > screen->fb[0].byteStride) {
-		atis->off_screen = atis->screen + screen_size;
-		atis->off_screen_size = memory;
-	} else {
-		atis->off_screen = 0;
-		atis->off_screen_size = 0;
-	}
-	screen->driver = atis;
 	return TRUE;
 }
 
@@ -225,8 +272,9 @@
 ATIScreenFini(KdScreenInfo *screen)
 {
 	ATIScreenInfo *atis = (ATIScreenInfo *)screen->driver;
+	ATICardInfo *atic = screen->card->driver;
 
-	vesaScreenFini(screen);
+	atic->backend_funcs.scrfini(screen);
 	xfree(atis);
 	screen->driver = 0;
 }
@@ -257,25 +305,58 @@
 	}
 }
 
-void
-ATISetMMIO(KdCardInfo *card, ATICardInfo *atic)
+static Bool
+ATIInitScreen(ScreenPtr pScreen)
 {
-	if (atic->reg_base == NULL)
-		ATIMapReg(card, atic);
+	KdScreenPriv(pScreen);
+	ATICardInfo(pScreenPriv);
+
+	return atic->backend_funcs.initScreen(pScreen);
 }
 
-void
-ATIResetMMIO(KdCardInfo *card, ATICardInfo *atic)
+static Bool
+ATIFinishInitScreen(ScreenPtr pScreen)
 {
-	ATIUnmapReg(card, atic);
+	KdScreenPriv(pScreen);
+	ATICardInfo(pScreenPriv);
+
+	return atic->backend_funcs.finishInitScreen(pScreen);
 }
 
+static Bool
+ATICreateResources(ScreenPtr pScreen)
+{
+	KdScreenPriv(pScreen);
+	ATICardInfo(pScreenPriv);
+
+	return atic->backend_funcs.createRes(pScreen);
+}
+
+static void
+ATIPreserve(KdCardInfo *card)
+{
+	ATICardInfo *atic = card->driver;
+
+	atic->backend_funcs.preserve(card);
+}
+
+static void
+ATIRestore(KdCardInfo *card)
+{
+	ATICardInfo *atic = card->driver;
+
+	ATIUnmapReg(card, atic);
+
+	atic->backend_funcs.restore(card);
+}
 
 static Bool
 ATIDPMS(ScreenPtr pScreen, int mode)
 {
-	/* XXX */
-	return TRUE;
+	KdScreenPriv(pScreen);
+	ATICardInfo(pScreenPriv);
+
+	return atic->backend_funcs.dpms(pScreen, mode);
 }
 
 static Bool
@@ -284,10 +365,13 @@
 	KdScreenPriv(pScreen);
 	ATICardInfo(pScreenPriv);
 
-	if (!vesaEnable(pScreen))
+	if (!atic->backend_funcs.enable(pScreen))
+		return FALSE;
+
+	if ((atic->reg_base == NULL) && !ATIMapReg(pScreenPriv->screen->card,
+	    atic))
 		return FALSE;
 
-	ATISetMMIO(pScreenPriv->card, atic);
 	ATIDPMS(pScreen, KD_DPMS_NORMAL);
 
 	return TRUE;
@@ -299,26 +383,36 @@
 	KdScreenPriv(pScreen);
 	ATICardInfo(pScreenPriv);
 
-	ATIResetMMIO(pScreenPriv->card, atic);
-	vesaDisable(pScreen);
+	ATIUnmapReg(pScreenPriv->card, atic);
+
+	atic->backend_funcs.disable(pScreen);
 }
 
 static void
-ATIRestore(KdCardInfo *card)
+ATIGetColors(ScreenPtr pScreen, int fb, int n, xColorItem *pdefs)
 {
-	ATICardInfo *atic = card->driver;
+	KdScreenPriv(pScreen);
+	ATICardInfo(pScreenPriv);
 
-	ATIResetMMIO(card, atic);
-	vesaRestore(card);
+	atic->backend_funcs.getColors(pScreen, fb, n, pdefs);
+}
+
+static void
+ATIPutColors(ScreenPtr pScreen, int fb, int n, xColorItem *pdefs)
+{
+	KdScreenPriv(pScreen);
+	ATICardInfo(pScreenPriv);
+
+	atic->backend_funcs.putColors(pScreen, fb, n, pdefs);
 }
 
 KdCardFuncs ATIFuncs = {
 	ATICardInit,		/* cardinit */
 	ATIScreenInit,		/* scrinit */
-	vesaInitScreen,		/* initScreen */
-	vesaFinishInitScreen,	/* finishInitScreen */
-	vesaCreateResources,	/* createRes */
-	vesaPreserve,		/* preserve */
+	ATIInitScreen,		/* initScreen */
+	ATIFinishInitScreen,	/* finishInitScreen */
+	ATICreateResources,	/* createRes */
+	ATIPreserve,		/* preserve */
 	ATIEnable,		/* enable */
 	ATIDPMS,		/* dpms */
 	ATIDisable,		/* disable */
@@ -338,7 +432,6 @@
 	ATIDrawDisable,		/* disableAccel */
 	ATIDrawFini,		/* finiAccel */
 
-	vesaGetColors,		/* getColors */
-	vesaPutColors,		/* putColors */
+	ATIGetColors,		/* getColors */
+	ATIPutColors,		/* putColors */
 };
-

Index: ati.h
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/ati/ati.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- ati.h	20 Nov 2003 07:49:45 -0000	1.2
+++ ati.h	1 Dec 2003 04:33:33 -0000	1.3
@@ -25,14 +25,52 @@
 
 #ifndef _ATI_H_
 #define _ATI_H_
+
+#include "config.h"
+
+#ifdef KDRIVEFBDEV
+#include <fbdev.h>
+#endif
+#ifdef KDRIVEVESA
 #include <vesa.h>
+#endif
 
 #define RADEON_REG_BASE(c)		((c)->attr.address[1])
 #define RADEON_REG_SIZE(c)		(0x10000)
 
+#ifdef __powerpc__
+
+static __inline__ void
+MMIO_OUT32(__volatile__ void *base, const unsigned long offset,
+	   const unsigned int val)
+{
+	__asm__ __volatile__(
+			"stwbrx %1,%2,%3\n\t"
+			"eieio"
+			: "=m" (*((volatile unsigned char *)base+offset))
+			: "r" (val), "b" (base), "r" (offset));
+}
+
+static __inline__ CARD32
+MMIO_IN32(__volatile__ void *base, const unsigned long offset)
+{
+	register unsigned int val;
+	__asm__ __volatile__(
+			"lwbrx %0,%1,%2\n\t"
+			"eieio"
+			: "=r" (val)
+			: "b" (base), "r" (offset),
+			"m" (*((volatile unsigned char *)base+offset)));
+	return val;
+}
+
+#else
+
 #define MMIO_OUT32(mmio, a, v)		(*(VOL32 *)((mmio) + (a)) = (v))
 #define MMIO_IN32(mmio, a)		(*(VOL32 *)((mmio) + (a)))
 
+#endif
+
 typedef volatile CARD8	VOL8;
 typedef volatile CARD16	VOL16;
 typedef volatile CARD32	VOL32;
@@ -43,20 +81,49 @@
 	char *name;
 };
 
+struct backend_funcs {
+	void    (*cardfini)(KdCardInfo *);
+	void    (*scrfini)(KdScreenInfo *);
+	Bool    (*initScreen)(ScreenPtr);
+	Bool    (*finishInitScreen)(ScreenPtr pScreen);
+	Bool	(*createRes)(ScreenPtr);
+	void    (*preserve)(KdCardInfo *);
+	void    (*restore)(KdCardInfo *);
+	Bool    (*dpms)(ScreenPtr, int);
+	Bool    (*enable)(ScreenPtr);
+	void    (*disable)(ScreenPtr);
+	void    (*getColors)(ScreenPtr, int, int, xColorItem *);
+	void    (*putColors)(ScreenPtr, int, int, xColorItem *);
+};
+
 typedef struct _ATICardInfo {
-	VesaCardPrivRec vesa;
+	union {
+#ifdef KDRIVEFBDEV
+		FbdevPriv fbdev;
+#endif
+#ifdef KDRIVEVESA
+		VesaCardPrivRec vesa;
+#endif
+	} backend_priv;
+	struct backend_funcs backend_funcs;
+
 	CARD8 *reg_base;
 	Bool is_radeon;
+	Bool use_fbdev, use_vesa;
 } ATICardInfo;
 
 #define getATICardInfo(kd)	((ATICardInfo *) ((kd)->card->driver))
 #define ATICardInfo(kd)		ATICardInfo *atic = getATICardInfo(kd)
 
 typedef struct _ATIScreenInfo {
-	VesaScreenPrivRec vesa;
-	CARD8 *screen;
-	CARD8 *off_screen;
-	int off_screen_size;
+	union {
+#ifdef KDRIVEFBDEV
+		FbdevScrPriv fbdev;
+#endif
+#ifdef KDRIVEVESA
+		VesaScreenPrivRec vesa;
+#endif
+	} backend_priv;
 
 	int datatype;
 	int dp_gui_master_cntl;
@@ -71,12 +138,6 @@
 void
 ATIUnmapReg(KdCardInfo *card, ATICardInfo *atic);
 
-void
-ATISetMMIO(KdCardInfo *card, ATICardInfo *atic);
-
-void
-ATIResetMMIO(KdCardInfo *card, ATICardInfo *atic);
-
 Bool
 ATIDrawSetup(ScreenPtr pScreen);
 

Index: ati_stub.c
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/ati/ati_stub.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ati_stub.c	19 Nov 2003 08:32:35 -0000	1.1
+++ ati_stub.c	1 Dec 2003 04:33:33 -0000	1.2
@@ -73,7 +73,9 @@
 ddxUseMsg (void)
 {
 	KdUseMsg();
+#ifdef KDRIVEVESA
 	vesaUseMsg();
+#endif
 }
 
 int
@@ -81,7 +83,10 @@
 {
 	int	ret;
     
+#ifdef KDRIVEVESA
 	if (!(ret = vesaProcessArgument (argc, argv, i)))
+#endif
 		ret = KdProcessArgument(argc, argv, i);
+
 	return ret;
 }