diff options
author | Eric Anholt <anholt@freebsd.org> | 2003-12-01 04:33:36 +0000 |
---|---|---|
committer | Eric Anholt <anholt@freebsd.org> | 2003-12-01 04:33:36 +0000 |
commit | 9cdd6fd9e3d6e44adf392279093f92fb6678a49c (patch) | |
tree | 47295d996d343c4cc42f37d839e415aac4aa8098 | |
parent | ec7f5539302fafd1ac7609ac423f1379f54916ab (diff) |
- 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.
-rw-r--r-- | hw/kdrive/Makefile.am | 16 | ||||
-rw-r--r-- | hw/kdrive/ati/Makefile.am | 17 | ||||
-rw-r--r-- | hw/kdrive/ati/ati.c | 191 | ||||
-rw-r--r-- | hw/kdrive/ati/ati.h | 83 | ||||
-rw-r--r-- | hw/kdrive/ati/ati_stub.c | 5 | ||||
-rw-r--r-- | hw/kdrive/fbdev/fbdev.c | 2 | ||||
-rw-r--r-- | hw/kdrive/src/kdrive.h | 5 |
7 files changed, 250 insertions, 69 deletions
diff --git a/hw/kdrive/Makefile.am b/hw/kdrive/Makefile.am index 2d51c9c9d..1ff8a0d50 100644 --- a/hw/kdrive/Makefile.am +++ b/hw/kdrive/Makefile.am @@ -1,10 +1,14 @@ if KDRIVEVESA -VESA_SUBDIRS = vesa ati mach64 mga nvidia r128 smi +VESA_SUBDIRS = vesa mach64 mga nvidia r128 smi endif -SUBDIRS = \ - src \ - linux \ - fbdev \ - $(VESA_SUBDIRS) +if KDRIVEFBDEV +FBDEV_SUBDIRS = fbdev +endif +SUBDIRS = \ + src \ + linux \ + $(FBDEV_SUBDIRS) \ + $(VESA_SUBDIRS) \ + ati diff --git a/hw/kdrive/ati/Makefile.am b/hw/kdrive/ati/Makefile.am index f07e74095..e694d018c 100644 --- a/hw/kdrive/ati/Makefile.am +++ b/hw/kdrive/ati/Makefile.am @@ -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_SOURCES = \ Xati_LDADD = \ libati.a \ - $(top_builddir)/hw/kdrive/vesa/libvesa.a \ + $(FBDEV_LIBS) \ + $(VESA_LIBS) \ @KDRIVE_LIBS@ \ @XSERVER_LIBS@ \ $(TSLIB_FLAG) diff --git a/hw/kdrive/ati/ati.c b/hw/kdrive/ati/ati.c index 7c961d3be..67137dff6 100644 --- a/hw/kdrive/ati/ati.c +++ b/hw/kdrive/ati/ati.c @@ -157,15 +157,50 @@ ATICardInit(KdCardInfo *card) { 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 @@ ATICardFini(KdCardInfo *card) 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 @@ static void 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 @@ ATIUnmapReg(KdCardInfo *card, ATICardInfo *atic) } } -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 @@ ATIEnable(ScreenPtr pScreen) 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 @@ ATIDisable(ScreenPtr pScreen) 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 @@ KdCardFuncs ATIFuncs = { ATIDrawDisable, /* disableAccel */ ATIDrawFini, /* finiAccel */ - vesaGetColors, /* getColors */ - vesaPutColors, /* putColors */ + ATIGetColors, /* getColors */ + ATIPutColors, /* putColors */ }; - diff --git a/hw/kdrive/ati/ati.h b/hw/kdrive/ati/ati.h index 6e07fac22..f713d8027 100644 --- a/hw/kdrive/ati/ati.h +++ b/hw/kdrive/ati/ati.h @@ -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 @@ struct pci_id_list { 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 @@ ATIMapReg(KdCardInfo *card, ATICardInfo *atic); void ATIUnmapReg(KdCardInfo *card, ATICardInfo *atic); -void -ATISetMMIO(KdCardInfo *card, ATICardInfo *atic); - -void -ATIResetMMIO(KdCardInfo *card, ATICardInfo *atic); - Bool ATIDrawSetup(ScreenPtr pScreen); diff --git a/hw/kdrive/ati/ati_stub.c b/hw/kdrive/ati/ati_stub.c index 9b342feff..2cb9e0092 100644 --- a/hw/kdrive/ati/ati_stub.c +++ b/hw/kdrive/ati/ati_stub.c @@ -73,7 +73,9 @@ void ddxUseMsg (void) { KdUseMsg(); +#ifdef KDRIVEVESA vesaUseMsg(); +#endif } int @@ -81,7 +83,10 @@ ddxProcessArgument(int argc, char **argv, int i) { int ret; +#ifdef KDRIVEVESA if (!(ret = vesaProcessArgument (argc, argv, i))) +#endif ret = KdProcessArgument(argc, argv, i); + return ret; } diff --git a/hw/kdrive/fbdev/fbdev.c b/hw/kdrive/fbdev/fbdev.c index c3db79f94..257b1df14 100644 --- a/hw/kdrive/fbdev/fbdev.c +++ b/hw/kdrive/fbdev/fbdev.c @@ -37,7 +37,7 @@ fbdevInitialize (KdCardInfo *card, FbdevPriv *priv) int k; unsigned long off; if ((priv->fd = open("/dev/fb0", O_RDWR)) < 0) { - perror("Error opening /dev/fb0\n"); + perror("Error opening /dev/fb0"); return FALSE; } /* quiet valgrind */ diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h index 557972351..df2ead9f4 100644 --- a/hw/kdrive/src/kdrive.h +++ b/hw/kdrive/src/kdrive.h @@ -23,6 +23,9 @@ */ /* $RCSId: xc/programs/Xserver/hw/kdrive/kdrive.h,v 1.29 2002/11/13 16:37:39 keithp Exp $ */ +#ifndef _KDRIVE_H_ +#define _KDRIVE_H_ + #include <stdio.h> #include <X11/X.h> #define NEED_EVENTS @@ -851,3 +854,5 @@ KdOffscreenFini (ScreenPtr pScreen); /* function prototypes to be implemented by the drivers */ void InitCard (char *name); + +#endif /* _KDRIVE_H_ */ |