Commit b923d897 authored by Keith Packard's avatar Keith Packard

Initial revision

parent 544ee9bb
XCOMM $XFree86: xc/programs/Xserver/hw/kdrive/smi/Imakefile,v 1.2 2001/06/16 05:48:48 keithp Exp $
KDRIVE=..
#include "../Kdrive.tmpl"
#if BuildXvExt
XVSRCS=smivideo.c
XVOBJS=smivideo.o
#endif
SRCS = smi.c smidraw.c smistub.c $(XVSRCS)
OBJS = smi.o smidraw.o smistub.o $(XVOBJS)
DEFINES = XvExtensionDefines -DVESA /* -DUSE_PCI*/
INCLUDES = -I. $(KDINCS) -I$(KDRIVE)/vesa
NormalLibraryObjectRule()
NormalLibraryTarget(smi,$(OBJS))
DependTarget()
/*
* Copyright 2001 Keith Packard
*
* 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 Keith Packard not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. Keith Packard makes no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL KEITH PACKARD 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.
*/
/* $XFree86: xc/programs/Xserver/hw/kdrive/smi/smi.c,v 1.11 2002/10/18 06:31:17 keithp Exp $ */
#include "smi.h"
#include <sys/io.h>
#define DEBUG
#ifdef DEBUG
#define DBGOUT(fmt,a...) fprintf (stderr, fmt, ##a)
#else
#define DBGOUT(fmt,a...)
#endif
#define ENTER() DBGOUT("Enter %s\n", __FUNCTION__)
#define LEAVE() DBGOUT("Leave %s\n", __FUNCTION__)
Bool
smiCardInit (KdCardInfo *card)
{
SmiCardInfo *smic;
ENTER ();
smic = (SmiCardInfo *) xalloc (sizeof (SmiCardInfo));
if (!smic)
return FALSE;
(void) smiMapReg (card, smic);
if (!vesaInitialize (card, &smic->vesa))
{
xfree (smic);
return FALSE;
}
card->driver = smic;
LEAVE();
return TRUE;
}
Bool
smiScreenInit (KdScreenInfo *screen)
{
SmiCardInfo *smic = screen->card->driver;
SmiScreenInfo *smis;
int screen_size, memory;
ENTER();
smis = (SmiScreenInfo *) xalloc (sizeof (SmiScreenInfo));
if (!smis)
return FALSE;
memset (smis, '\0', sizeof (SmiScreenInfo));
if (!vesaScreenInitialize (screen, &smis->vesa))
{
xfree (smis);
return FALSE;
}
if (!smic->reg_base)
screen->dumb = TRUE;
if (smis->vesa.mapping != VESA_LINEAR)
screen->dumb = TRUE;
smis->screen = smis->vesa.fb;
memory = smis->vesa.fb_size;
screen_size = screen->fb[0].byteStride * screen->height;
screen->softCursor = TRUE;
memory -= screen_size;
if (memory > screen->fb[0].byteStride)
{
smis->off_screen = smis->screen + screen_size;
smis->off_screen_size = memory;
}
else
{
smis->off_screen = 0;
smis->off_screen_size = 0;
}
screen->driver = smis;
LEAVE();
return TRUE;
}
Bool
smiInitScreen (ScreenPtr pScreen)
{
Bool ret;
ENTER ();
#if 0
#ifdef XV
KdScreenPriv(pScreen);
SmiCardInfo *smic = pScreenPriv->screen->card->driver;
if (smic->media_reg && smic->reg)
smiInitVideo(pScreen);
#endif
#endif
ret = vesaInitScreen (pScreen);
LEAVE();
}
#ifdef RANDR
smiRandRSetConfig (ScreenPtr pScreen,
Rotation randr,
int rate,
RRScreenSizePtr pSize)
{
Bool ret;
KdScreenPriv(pScreen);
ENTER ();
KdCheckSync (pScreen);
ret = vesaRandRSetConfig (pScreen, randr, rate, pSize);
LEAVE();
return ret;
}
Bool
smiRandRInit (ScreenPtr pScreen)
{
rrScrPriv(pScreen);
ENTER ();
pScrPriv->rrSetConfig = smiRandRSetConfig;
LEAVE ();
return TRUE;
}
#endif
Bool
smiFinishInitScreen (ScreenPtr pScreen)
{
ENTER ();
if (!vesaFinishInitScreen (pScreen))
return FALSE;
#ifdef RANDR
if (!smiRandRInit (pScreen))
return FALSE;
#endif
LEAVE ();
return TRUE;
}
void
smiPreserve (KdCardInfo *card)
{
SmiCardInfo *smic = card->driver;
ENTER ();
vesaPreserve(card);
LEAVE();
}
Bool
smiMapReg (KdCardInfo *card, SmiCardInfo *smic)
{
ENTER ();
smic->io_base = 0; /* only handles one SMI card at standard VGA address */
smic->reg_base = (CARD8 *) KdMapDevice (SMI_REG_BASE(card),
SMI_REG_SIZE(card));
if (!smic->reg_base)
{
smic->dpr = 0;
return FALSE;
}
KdSetMappedMode (SMI_REG_BASE(card),
SMI_REG_SIZE(card),
KD_MAPPED_MODE_REGISTERS);
smic->dpr = (DPR *) (smic->reg_base + SMI_DPR_OFF(card));
LEAVE ();
return TRUE;
}
void
smiUnmapReg (KdCardInfo *card, SmiCardInfo *smic)
{
ENTER ();
if (smic->reg_base)
{
KdResetMappedMode (SMI_REG_BASE(card),
SMI_REG_SIZE(card),
KD_MAPPED_MODE_REGISTERS);
KdUnmapDevice ((void *) smic->reg_base, SMI_REG_SIZE(card));
smic->reg_base = 0;
smic->dpr = 0;
}
LEAVE ();
}
void
smiOutb (CARD16 port, CARD8 val)
{
asm volatile ("outb %b0,%w1" : : "a" (val), "d" (port));
}
CARD8
smiInb (CARD16 port)
{
CARD8 v;
asm volatile ("inb %w1,%b0" : "=a" (v) : "d" (port));
return v;
}
CARD8
smiGetIndex (SmiCardInfo *smic, CARD16 addr, CARD16 data, CARD8 id)
{
smiOutb (smic->io_base + addr, id);
return smiInb (smic->io_base + data);
}
void
smiSetIndex (SmiCardInfo *smic, CARD16 addr, CARD16 data, CARD8 id, CARD8 val)
{
smiOutb (smic->io_base + addr, id);
smiOutb (smic->io_base + data, val);
}
void
smiSetMMIO (KdCardInfo *card, SmiCardInfo *smic)
{
ENTER ();
if (!smic->reg_base)
smiMapReg (card, smic);
LEAVE();
}
void
smiResetMMIO (KdCardInfo *card, SmiCardInfo *smic)
{
smiUnmapReg (card, smic);
}
Bool
smiEnable (ScreenPtr pScreen)
{
KdScreenPriv(pScreen);
SmiCardInfo *smic = pScreenPriv->card->driver;
ENTER ();
if (!vesaEnable (pScreen))
return FALSE;
smiSetMMIO (pScreenPriv->card, smic);
smiDPMS (pScreen, KD_DPMS_NORMAL);
#if 0
#ifdef XV
KdXVEnable (pScreen);
#endif
#endif
LEAVE ();
return TRUE;
}
void
smiDisable (ScreenPtr pScreen)
{
KdScreenPriv(pScreen);
SmiCardInfo *smic = pScreenPriv->card->driver;
ENTER ();
#ifdef XV
KdXVDisable (pScreen);
#endif
smiResetMMIO (pScreenPriv->card, smic);
vesaDisable (pScreen);
LEAVE ();
}
Bool
smiDPMS (ScreenPtr pScreen, int mode)
{
Bool ret;
ENTER ();
ret = vesaDPMS (pScreen, mode);
LEAVE ();
return ret;
}
void
smiRestore (KdCardInfo *card)
{
SmiCardInfo *smic = card->driver;
ENTER ();
vesaRestore (card);
LEAVE();
}
void
smiScreenFini (KdScreenInfo *screen)
{
SmiScreenInfo *smis = (SmiScreenInfo *) screen->driver;
ENTER ();
vesaScreenFini (screen);
xfree (smis);
screen->driver = 0;
LEAVE ();
}
void
smiCardFini (KdCardInfo *card)
{
SmiCardInfo *smic = card->driver;
ENTER ();
smiUnmapReg (card, smic);
vesaCardFini (card);
LEAVE ();
}
#define smiCursorInit 0 /* initCursor */
#define smiCursorEnable 0 /* enableCursor */
#define smiCursorDisable 0 /* disableCursor */
#define smiCursorFini 0 /* finiCursor */
#define smiRecolorCursor 0 /* recolorCursor */
KdCardFuncs smiFuncs = {
smiCardInit, /* cardinit */
smiScreenInit, /* scrinit */
smiInitScreen, /* initScreen */
smiPreserve, /* preserve */
smiEnable, /* enable */
smiDPMS, /* dpms */
smiDisable, /* disable */
smiRestore, /* restore */
smiScreenFini, /* scrfini */
smiCardFini, /* cardfini */
smiCursorInit, /* initCursor */
smiCursorEnable, /* enableCursor */
smiCursorDisable, /* disableCursor */
smiCursorFini, /* finiCursor */
smiRecolorCursor, /* recolorCursor */
smiDrawInit, /* initAccel */
smiDrawEnable, /* enableAccel */
smiDrawSync, /* syncAccel */
smiDrawDisable, /* disableAccel */
smiDrawFini, /* finiAccel */
vesaGetColors, /* getColors */
vesaPutColors, /* putColors */
smiFinishInitScreen, /* finishInitScreen */
};
/*
* Id: smi.h,v 1.2 1999/11/02 08:17:24 keithp Exp $
*
* Copyright 2001 Keith Packard
*
* 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 Keith Packard not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. Keith Packard makes no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL KEITH PACKARD 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.
*/
/* $XFree86: xc/programs/Xserver/hw/kdrive/smi/smi.h,v 1.6 2001/07/24 19:06:03 keithp Exp $ */
#ifndef _SMI_H_
#define _SMI_H_
#include <vesa.h>
#include "kxv.h"
/*
* offset from ioport beginning
*/
#define SMI_IO_BASE(c) ((c)->attr.io)
#define SMI_REG_BASE(c) ((c)->attr.address[0])
#define SMI_REG_SIZE(c) (4096)
#define SMI_DPR_OFF(c) (0x00000)
typedef volatile CARD8 VOL8;
typedef volatile CARD16 VOL16;
typedef volatile CARD32 VOL32;
/* DPR reg */
typedef struct _DPR {
VOL32 src_xy; /* 0x00 */
VOL32 dst_xy; /* 0x04 */
VOL32 dst_wh; /* 0x08 */
VOL32 accel_cmd; /* 0x0c */
VOL32 src_stride; /* 0x10 */
VOL32 fg; /* 0x14 */
VOL32 bg; /* 0x18 */
VOL32 data_format; /* 0x1c */
VOL32 transparent; /* 0x20 */
VOL32 mask1; /* 0x24 ? */
VOL32 mask2; /* 0x28 ? */
VOL32 scissors_ul; /* 0x2c */
VOL32 scissors_lr; /* 0x30 */
VOL32 mask3; /* 0x34 */
VOL32 mask4; /* 0x38 */
VOL32 dst_stride; /* 0x3c */
VOL32 unknown_40; /* 0x40 */
VOL32 unknown_44; /* 0x44 */
} DPR;
#define SMI_XY(x,y) (((y) & 0x7fff) | (((x) & 0x7fff) << 16))
/* 2D Engine commands */
#define SMI_TRANSPARENT_SRC 0x00000100
#define SMI_TRANSPARENT_DEST 0x00000300
#define SMI_OPAQUE_PXL 0x00000000
#define SMI_TRANSPARENT_PXL 0x00000400
#define SMI_MONO_PACK_8 0x00001000
#define SMI_MONO_PACK_16 0x00002000
#define SMI_MONO_PACK_32 0x00003000
#define SMI_ROP2_SRC 0x00008000
#define SMI_ROP2_PAT 0x0000C000
#define SMI_ROP3 0x00000000
#define SMI_BITBLT 0x00000000
#define SMI_RECT_FILL 0x00010000
#define SMI_TRAPEZOID_FILL 0x00030000
#define SMI_SHORT_STROKE 0x00060000
#define SMI_BRESENHAM_LINE 0x00070000
#define SMI_HOSTBLT_WRITE 0x00080000
#define SMI_HOSTBLT_READ 0x00090000
#define SMI_ROTATE_BLT 0x000B0000
#define SMI_SRC_COLOR 0x00000000
#define SMI_SRC_MONOCHROME 0x00400000
#define SMI_GRAPHICS_STRETCH 0x00800000
#define SMI_ROTATE_CW 0x01000000
#define SMI_ROTATE_CCW 0x02000000
#define SMI_MAJOR_X 0x00000000
#define SMI_MAJOR_Y 0x04000000
#define SMI_LEFT_TO_RIGHT 0x00000000
#define SMI_RIGHT_TO_LEFT 0x08000000
#define SMI_COLOR_PATTERN 0x40000000
#define SMI_MONO_PATTERN 0x00000000
#define SMI_QUICK_START 0x10000000
#define SMI_START_ENGINE 0x80000000
#define VGA_SEQ_INDEX 0x3C4
#define VGA_SEQ_DATA 0x3C5
typedef struct _smiCardInfo {
VesaCardPrivRec vesa;
CARD16 io_base;
CARD8 *reg_base;
DPR *dpr;
int avail;
} SmiCardInfo;
#define getSmiCardInfo(kd) ((SmiCardInfo *) ((kd)->card->driver))
#define smiCardInfo(kd) SmiCardInfo *smic = getSmiCardInfo(kd)
typedef struct _smiScreenInfo {
VesaScreenPrivRec vesa;
CARD8 *screen;
CARD8 *off_screen;
int off_screen_size;
CARD32 stride;
CARD32 data_format;
CARD8 dpr_vpr_enable;
} SmiScreenInfo;
#define getSmiScreenInfo(kd) ((SmiScreenInfo *) ((kd)->screen->driver))
#define smiScreenInfo(kd) SmiScreenInfo *smis = getSmiScreenInfo(kd)
void
smiPreserve (KdCardInfo *card);
Bool
smiMapReg (KdCardInfo *card, SmiCardInfo *smic);
void
smiUnmapReg (KdCardInfo *card, SmiCardInfo *smic);
void
smiSetMMIO (KdCardInfo *card, SmiCardInfo *smic);
void
smiResetMMIO (KdCardInfo *card, SmiCardInfo *smic);
Bool
smiEnable (ScreenPtr pScreen);
void
smiDisable (ScreenPtr pScreen);
void
smiWaitAvail(SmiCardInfo *smic, int n);
void
smiWaitIdle (SmiCardInfo *smic);
Bool
smiDrawSetup (ScreenPtr pScreen);
Bool
smiDrawInit (ScreenPtr pScreen);
void
smiDrawReinit (ScreenPtr pScreen);
void
smiDrawEnable (ScreenPtr pScreen);
void
smiDrawSync (ScreenPtr pScreen);
void
smiDrawDisable (ScreenPtr pScreen);
void
smiDrawFini (ScreenPtr pScreen);
CARD8
smiReadIndex (SmiCardInfo *smic, CARD16 port, CARD8 index);
void
smiWriteIndex (SmiCardInfo *smic, CARD16 port, CARD8 index, CARD8 value);
extern KdCardFuncs smiFuncs;
#endif /* _SMI_H_ */
/*
* Id: smidraw.c,v 1.1 1999/11/02 03:54:47 keithp Exp $
*
* Copyright 1999 Keith Packard
*
* 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 Keith Packard not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. Keith Packard makes no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL KEITH PACKARD 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.
*/
/* $XFree86: xc/programs/Xserver/hw/kdrive/smi/smidraw.c,v 1.7 2001/07/24 19:06:03 keithp Exp $ */
#include "smi.h"
#include "smidraw.h"
#include "Xmd.h"
#include "gcstruct.h"
#include "scrnintstr.h"
#include "pixmapstr.h"
#include "regionstr.h"
#include "mistruct.h"
#include "fontstruct.h"
#include "dixfontstr.h"
#include "fb.h"
#include "migc.h"
#include "miline.h"
#include "picturestr.h"
CARD8 smiBltRop[16] = {
/* GXclear */ 0x00, /* 0 */
/* GXand */ 0x88, /* src AND dst */
/* GXandReverse */ 0x44, /* src AND NOT dst */
/* GXcopy */ 0xcc, /* src */
/* GXandInverted*/ 0x22, /* NOT src AND dst */
/* GXnoop */ 0xaa, /* dst */
/* GXxor */ 0x66, /* src XOR dst */
/* GXor */ 0xee, /* src OR dst */
/* GXnor */ 0x11, /* NOT src AND NOT dst */
/* GXequiv */ 0x99, /* NOT src XOR dst */
/* GXinvert */ 0x55, /* NOT dst */
/* GXorReverse */ 0xdd, /* src OR NOT dst */
/* GXcopyInverted*/ 0x33, /* NOT src */