Commit 07ab15d6 authored by Anders Carlsson's avatar Anders Carlsson

Add mga server

parent b260825e
INCLUDES = \
-I$(top_srcdir)/fb \
-I$(top_srcdir)/hw/kdrive/src \
-I$(top_srcdir)/hw/kdrive/vesa \
-I$(top_srcdir)/include \
-I$(top_srcdir)/mi \
-I$(top_srcdir)/miext/layer \
-I$(top_srcdir)/miext/shadow \
-I$(top_srcdir)/randr \
-I$(top_srcdir)/render
bin_PROGRAMS = Xmga
noinst_LTLIBRARIES = libmga.la
libmga_la_SOURCES = \
mgadraw.c \
mga.c \
mga.h
Xmga_SOURCES = \
mgastub.c
Xmga_LDADD = \
$(top_builddir)/hw/kdrive/mga/libmga.la \
$(top_builddir)/hw/kdrive/vesa/libvesa.la \
$(top_builddir)/dix/libdix.la \
$(top_builddir)/os/libos.la \
$(top_builddir)/miext/layer/liblayer.la \
$(top_builddir)/hw/kdrive/src/libkdrive.la \
$(top_builddir)/hw/kdrive/linux/liblinux.la \
$(top_builddir)/miext/shadow/libshadow.la \
$(top_builddir)/randr/librandr.la \
$(top_builddir)/render/librender.la \
$(top_builddir)/fb/libfb.la \
$(top_builddir)/mi/libmi.la \
$(top_builddir)/Xext/libXext.la \
$(top_builddir)/randr/librandr.la \
$(top_builddir)/render/librender.la \
$(top_builddir)/xtrans/libxtrans.la \
@XFONT_LIBS@ \
$(X_LIBS) -lXau -lXdmcp \
$(top_builddir)/dix/libxpstubs.la \
-lfreetype -lm -lz
/*
* $Id$
*
* Copyright © 2003 Anders Carlsson
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of Anders Carlsson not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. Anders Carlsson makes no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* ANDERS CARLSSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL ANDERS CARLSSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Header$ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "mga.h"
Bool
mgaCardInit (KdCardInfo *card)
{
MgaCardInfo *mgac;
mgac = (MgaCardInfo *) xalloc (sizeof (MgaCardInfo));
if (!mgac)
return FALSE;
mgaMapReg (card, mgac);
if (!vesaInitialize (card, &mgac->vesa))
{
xfree (mgac);
return FALSE;
}
mgac->fifo_size = 0;
card->driver = mgac;
return TRUE;
}
Bool
mgaScreenInit (KdScreenInfo *screen)
{
MgaCardInfo *mgac = screen->card->driver;
MgaScreenInfo *mgas;
int screen_size, memory;
mgas = (MgaScreenInfo *) xalloc (sizeof (MgaScreenInfo));
if (!mgas)
return FALSE;
memset (mgas, '\0', sizeof (MgaScreenInfo));
if (!vesaScreenInitialize (screen, &mgas->vesa))
{
xfree (mgas);
return FALSE;
}
#if 0
/* if (!mgac->reg)
screen->dumb = TRUE; */
if (mgas->vesa.mapping != VESA_LINEAR)
screen->dumb = TRUE;
fprintf (stderr, "vesa mapping is %d\n", mgas->vesa.mapping);
#endif
mgas->screen = mgas->vesa.fb;
memory = mgas->vesa.fb_size;
screen_size = screen->fb[0].byteStride * screen->height;
memory -= screen_size;
if (memory > screen->fb[0].byteStride)
{
mgas->off_screen = mgas->screen + screen_size;
mgas->off_screen_size = memory;
}
else
{
mgas->off_screen = 0;
mgas->off_screen_size = 0;
}
screen->driver = mgas;
return TRUE;
}
Bool
mgaInitScreen (ScreenPtr pScreen)
{
return vesaInitScreen (pScreen);
}
Bool
mgaFinishInitScreen (ScreenPtr pScreen)
{
Bool ret;
ret = vesaFinishInitScreen (pScreen);
return ret;
}
void
mgaPreserve (KdCardInfo *card)
{
MgaCardInfo *mgac = card->driver;
vesaPreserve (card);
}
Bool
mgaMapReg (KdCardInfo *card, MgaCardInfo *mgac)
{
mgac->reg_base = (CARD8 *) KdMapDevice (MGA_REG_BASE (card),
MGA_REG_SIZE (card));
if (!mgac->reg_base)
{
return FALSE;
}
KdSetMappedMode (MGA_REG_BASE (card),
MGA_REG_SIZE (card),
KD_MAPPED_MODE_REGISTERS);
return TRUE;
}
void
mgaUnmapReg (KdCardInfo *card, MgaCardInfo *mgac)
{
if (mgac->reg_base)
{
KdResetMappedMode (MGA_REG_BASE (card),
MGA_REG_SIZE (card),
KD_MAPPED_MODE_REGISTERS);
KdUnmapDevice ((void *) mgac->reg_base, MGA_REG_SIZE (card));
mgac->reg_base = 0;
// mgac->reg = 0;
}
}
void
mgaSetMMIO (KdCardInfo *card, MgaCardInfo *mgac)
{
if (!mgac->reg_base)
mgaMapReg (card, mgac);
}
void
mgaResetMMIO (KdCardInfo *card, MgaCardInfo *mgac)
{
mgaUnmapReg (card, mgac);
}
Bool
mgaEnable (ScreenPtr pScreen)
{
KdScreenPriv (pScreen);
MgaCardInfo *mgac = pScreenPriv->card->driver;
if (!vesaEnable (pScreen))
return FALSE;
mgaSetMMIO (pScreenPriv->card, mgac);
mgaDPMS (pScreen, KD_DPMS_NORMAL);
return TRUE;
}
void
mgaDisable (ScreenPtr pScreen)
{
KdScreenPriv (pScreen);
MgaCardInfo *mgac = pScreenPriv->card->driver;
mgaResetMMIO (pScreenPriv->card, mgac);
vesaDisable (pScreen);
}
Bool
mgaDPMS (ScreenPtr pScreen, int mode)
{
/* XXX */
return TRUE;
}
void
mgaRestore (KdCardInfo *card)
{
MgaCardInfo *mgac = card->driver;
mgaResetMMIO (card, mgac);
vesaRestore (card);
}
void
mgaScreenFini (KdScreenInfo *screen)
{
MgaScreenInfo *mgas = (MgaScreenInfo *) screen->driver;
vesaScreenFini (screen);
xfree (mgas);
screen->driver = 0;
}
void
mgaCardFini (KdCardInfo *card)
{
MgaCardInfo *mgac = (MgaCardInfo *)card->driver;
mgaUnmapReg (card, mgac);
vesaCardFini (card);
}
KdCardFuncs mgaFuncs = {
mgaCardInit, /* cardinit */
mgaScreenInit, /* scrinit */
mgaInitScreen, /* initScreen */
mgaPreserve, /* preserve */
mgaEnable, /* enable */
mgaDPMS, /* dpms */
mgaDisable, /* disable */
mgaRestore, /* restore */
mgaScreenFini, /* scrfini */
mgaCardFini, /* cardfini */
0, /* initCursor */
0, /* enableCursor */
0, /* disableCursor */
0, /* finiCursor */
0, /* recolorCursor */
mgaDrawInit, /* initAccel */
mgaDrawEnable, /* enableAccel */
mgaDrawSync, /* syncAccel */
mgaDrawDisable, /* disableAccel */
mgaDrawFini, /* finiAccel */
vesaGetColors, /* getColors */
vesaPutColors, /* putColors */
mgaFinishInitScreen, /* finishInitScreen */
};
......@@ -27,10 +27,98 @@
#define _MGA_H_
#include <vesa.h>
#define MGA_REG_BASE(c) ((c)->attr.address[1])
#define MGA_REG_SIZE(c) (0x4000)
#define MGA_OUT32(mmio, a, v) (*(VOL32 *) ((mmio) + (a)) = (v))
#define MGA_IN32(mmio, a) (*(VOL32 *) ((mmio) + (a)))
#define MGA_REG_EXEC (0x0100)
#define MGA_REG_DWGCTL (0x1c00)
#define MGA_REG_PLNWT (0x1c1c)
#define MGA_REG_FCOL (0x1c24)
#define MGA_REG_MACCESS (0x1c04)
#define MGA_REG_CXBNDRY (0x1c80)
#define MGA_REG_FXBNDRY (0x1c84)
#define MGA_REG_YDSTLEN (0x1c88)
#define MGA_REG_PITCH (0x1c8c)
#define MGA_REG_YTOP (0x1c98)
#define MGA_REG_YBOT (0x1c9c)
#define MGA_REG_FIFOSTATUS (0x1e10)
#define MGA_REG_STATUS (0x1e14)
#define MGA_REG_DSTORG (0x2cb8)
#define MGA_PW8 (0)
#define MGA_PW16 (1)
#define MGA_PW24 (2)
#define MGA_PW32 (3)
/* Drawing opcodes */
#define MGA_OPCOD_TRAP (4)
#define MGA_DWGCTL_SOLID (1 << 11)
#define MGA_DWGCTL_ARZERO (1 << 12)
#define MGA_DWGCTL_SGNZERO (1 << 13)
#define MGA_DWGCTL_SHIFTZERO (1 << 14)
typedef volatile CARD8 VOL8;
typedef volatile CARD16 VOL16;
typedef volatile CARD32 VOL32;
typedef struct _mgaCardInfo {
VesaCardPrivRec vesa;
CARD8 *reg_base;
int fifo_size;
} MgaCardInfo;
#define getMgaCardInfo(kd) ((MgaCardInfo *) ((kd)->card->driver))
#define mgaCardInfo(kd) MgaCardInfo *mgac = getMgaCardInfo(kd)
typedef struct _mgaScreenInfo {
VesaScreenPrivRec vesa;
CARD8 *screen;
CARD8 *off_screen;
int off_screen_size;
int pitch;
int pw;
} MgaScreenInfo;
#define getMgaScreenInfo(kd) ((MgaScreenInfo *) ((kd)->screen->driver))
#define mgaScreenInfo(kd) MgaScreenInfo *mgas = getMgaScreenInfo(kd)
Bool
mgaMapReg (KdCardInfo *card, MgaCardInfo *mgac);
void
mgaUnmapReg (KdCardInfo *card, MgaCardInfo *mgac);
void
mgaSetMMIO (KdCardInfo *card, MgaCardInfo *mgac);
void
mgaResetMMIO (KdCardInfo *card, MgaCardInfo *mgac);
Bool
mgaDrawSetup (ScreenPtr pScreen);
Bool
mgaDrawInit (ScreenPtr pScreen);
void
mgaDrawEnable (ScreenPtr pScreen);
void
mgaDrawSync (ScreenPtr pScreen);
void
mgaDrawDisable (ScreenPtr pScreen);
void
mgaDrawFini (ScreenPtr pScreen);
extern KdCardFuncs mgaFuncs;
#endif /* _MGA_H_ */
/*
* $Id$
*
* Copyright © 2003 Anders Carlsson
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of Anders Carlsson not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. Anders Carlsson makes no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* ANDERS CARLSSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL ANDERS CARLSSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Header$ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "mga.h"
static VOL8 *mmio;
int fifo_size;
void
mgaWaitAvail (int n)
{
int i;
if (fifo_size < n) {
while ((fifo_size = MGA_IN32 (mmio, MGA_REG_FIFOSTATUS) & 0xff) < n)
;
}
fifo_size -= n;
}
void
mgaWaitIdle (void)
{
while (MGA_IN32 (mmio, MGA_REG_STATUS) & 0x10000);
}
static Bool
mgaSetup (ScreenPtr pScreen, int wait)
{
KdScreenPriv (pScreen);
mgaScreenInfo (pScreenPriv);
mgaCardInfo (pScreenPriv);
fifo_size = 0;
mmio = mgac->reg_base;
if (!mmio)
return FALSE;
mgaWaitAvail (wait + 6);
MGA_OUT32 (mmio, MGA_REG_PITCH, mgas->pitch);
MGA_OUT32 (mmio, MGA_REG_DSTORG, 0);
MGA_OUT32 (mmio, MGA_REG_MACCESS, mgas->pw);
MGA_OUT32 (mmio, MGA_REG_CXBNDRY, 0xffff0000);
MGA_OUT32 (mmio, MGA_REG_YTOP, 0x00000000);
MGA_OUT32 (mmio, MGA_REG_YBOT, 0x007fffff);
}
Bool
mgaPrepareSolid (DrawablePtr pDrawable, int alu, Pixel pm, Pixel fg)
{
int cmd;
cmd = MGA_OPCOD_TRAP | MGA_DWGCTL_SOLID | MGA_DWGCTL_ARZERO | MGA_DWGCTL_SGNZERO |
MGA_DWGCTL_SHIFTZERO;
/* XXX */
cmd |= (12 << 16);
mgaSetup (pDrawable->pScreen, 4);
MGA_OUT32 (mmio, MGA_REG_DWGCTL, cmd);
MGA_OUT32 (mmio, MGA_REG_FCOL, fg);
MGA_OUT32 (mmio, MGA_REG_PLNWT, pm);
return TRUE;
}
void
mgaSolid (int x1, int y1, int x2, int y2)
{
mgaWaitAvail (2);
MGA_OUT32 (mmio, MGA_REG_FXBNDRY, (x2 << 16) | x1 & 0xffff);
MGA_OUT32 (mmio, MGA_REG_YDSTLEN | MGA_REG_EXEC, (y1 << 16) | (y2 - y1));
}
void
mgaDoneSolid (void)
{
}
Bool
mgaPrepareCopy (DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, int dx, int dy, int alu, Pixel pm)
{
return FALSE;
}
void
mgaCopy (int srcX, int srcY, int dstX, int dstY, int w, int h)
{
}
void
mgaDoneCopy (void)
{
}
KaaScreenPrivRec mgaKaa = {
mgaPrepareSolid,
mgaSolid,
mgaDoneSolid,
mgaPrepareCopy,
mgaCopy,
mgaDoneCopy,
};
Bool
mgaDrawInit (ScreenPtr pScreen)
{
KdScreenPriv(pScreen);
if (!kaaDrawInit (pScreen, &mgaKaa))
return FALSE;
return TRUE;
}
void
mgaDrawEnable (ScreenPtr pScreen)
{
KdScreenPriv (pScreen);
mgaScreenInfo (pScreenPriv);
mgas->pitch = pScreenPriv->screen->width;
switch (pScreenPriv->screen->fb[0].depth) {
case 8:
mgas->pw = MGA_PW8;
break;
case 16:
mgas->pw = MGA_PW16;
break;
case 24:
mgas->pw = MGA_PW24;
break;
case 32:
mgas->pw = MGA_PW32;
break;
default:
FatalError ("unsupported pixel format");
}
KdMarkSync (pScreen);
}
void
mgaDrawDisable (ScreenPtr pScreen)
{
}
void
mgaDrawFini (ScreenPtr pScreen)
{
}
void
mgaDrawSync (ScreenPtr pScreen)
{
KdScreenPriv (pScreen);
mgaCardInfo (pScreenPriv);
mmio = mgac->reg_base;
mgaWaitIdle ();
}
/*
* $Id$
*
* Copyright © 2003 Anders Carlsson
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of Anders Carlsson not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. Anders Carlsson makes no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* ANDERS CARLSSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL ANDERS CARLSSON BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Header$ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "mga.h"
void
InitCard (char *name)
{
KdCardAttr attr;
if (LinuxFindPci (0x102b, 0x0525, 0, &attr))
KdCardInfoAdd (&mgaFuncs, &attr, 0);
}
void
InitOutput (ScreenInfo *pScreenInfo, int argc, char **argv)
{
KdInitOutput (pScreenInfo, argc, argv);
}
void
InitInput (int argc, char **argv)
{
KdInitInput (&LinuxMouseFuncs, &LinuxKeyboardFuncs);