diff options
author | dawes <dawes> | 2000-11-30 17:31:29 +0000 |
---|---|---|
committer | dawes <dawes> | 2000-11-30 17:31:29 +0000 |
commit | d129f7fd02961869422c111dd8c3cf824bc54243 (patch) | |
tree | a8616855bbbfea89de0a0584e6d0daade1711bd2 /xc/programs/Xserver/hw/xfree86 | |
parent | c6fd424b4371a3348ec8a34475cfacad1c8fddb9 (diff) |
Initial revision
Diffstat (limited to 'xc/programs/Xserver/hw/xfree86')
-rw-r--r-- | xc/programs/Xserver/hw/xfree86/drivers/ark/Imakefile | 49 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/xfree86/drivers/ark/ark.h | 71 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/xfree86/drivers/ark/ark_accel.c | 227 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/xfree86/drivers/ark/ark_driver.c | 1170 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/xfree86/drivers/ark/ark_reg.h | 88 |
5 files changed, 1605 insertions, 0 deletions
diff --git a/xc/programs/Xserver/hw/xfree86/drivers/ark/Imakefile b/xc/programs/Xserver/hw/xfree86/drivers/ark/Imakefile new file mode 100644 index 000000000..ba5216709 --- /dev/null +++ b/xc/programs/Xserver/hw/xfree86/drivers/ark/Imakefile @@ -0,0 +1,49 @@ +XCOMM $XFree86: xc/programs/Xserver/hw/xfree86/drivers/ark/Imakefile,v 1.5 2000/11/15 23:13:08 dawes Exp $ +/* + * + * Copyright 2000 Ani Joshi <ajoshi@unixbox.com> + * + */ + +#define IHaveModules +#include <Server.tmpl> + +SRCS = ark_driver.c ark_accel.c + +OBJS = ark_driver.o ark_accel.o + +#if defined(XF86DriverSDK) +INCLUDES = -I. -I../../include +#else +INCLUDES = -I. -I$(XF86COMSRC) -I$(XF86OSSRC) \ + -I$(SERVERSRC)/mfb -I$(SERVERSRC)/mi \ + -I$(SERVERSRC)/cfb -I$(XF86SRC)/xaa \ + -I$(XF86SRC)/xf1bpp -I$(XF86SRC)/xf4bpp \ + -I$(XF86SRC)/xf24_32bpp -I$(SERVERSRC)/Xext \ + -I$(XF86SRC)/vgahw -I$(XF86SRC)/ramdac \ + -I$(XF86SRC)/rac -I$(XF86SRC)/int10 \ + -I$(XF86SRC)/fbdevhw -I$(XF86SRC)/ddc \ + -I$(XF86SRC)/i2c \ + -I$(SERVERSRC)/include -I$(XINCLUDESRC) -I$(FONTINCSRC) \ + -I$(EXTINCSRC) -I$(SERVERSRC)/render +#endif + +#if MakeHasPosixVariableSubstitutions +SubdirLibraryRule($(OBJS)) +#endif + +NormalAsmObjectRule() + +ModuleObjectRule() +ObjectModuleTarget(ark, $(OBJS)) + +InstallObjectModule(ark,$(MODULEDIR),drivers) + +DependTarget() + +InstallDriverSDKNonExecFile(Imakefile,$(DRIVERSDKDIR)/drivers/ark) +InstallDriverSDKNonExecFile(ark.h,$(DRIVERSDKDIR)/drivers/ark) +InstallDriverSDKNonExecFile(ark_reg.h,$(DRIVERSDKDIR)/drivers/ark) +InstallDriverSDKNonExecFile(ark_driver.c,$(DRIVERSDKDIR)/drivers/ark) +InstallDriverSDKNonExecFile(ark_accel.c,$(DRIVERSDKDIR)/drivers/ark) + diff --git a/xc/programs/Xserver/hw/xfree86/drivers/ark/ark.h b/xc/programs/Xserver/hw/xfree86/drivers/ark/ark.h new file mode 100644 index 000000000..6a95f8039 --- /dev/null +++ b/xc/programs/Xserver/hw/xfree86/drivers/ark/ark.h @@ -0,0 +1,71 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/ark/ark.h,v 1.1 2000/11/14 17:28:12 dawes Exp $ */ +/* + * ark + */ + +#ifndef _ARK_H +#define _ARK_H + +#include "xf86.h" +#include "xf86Pci.h" +#include "xf86PciInfo.h" +#include "xaa.h" +#include "xf86_ansic.h" +#include "vgaHW.h" + +typedef struct _ARKRegRec { + unsigned char sr10, sr11, sr12, sr13, sr14, + sr15, sr16, sr17, sr18, sr20, + sr21, sr22, sr23, sr24, sr25, + sr26, sr27, sr28, sr29, sr2a, + sr2b; + unsigned char sr1c, sr1d; + unsigned char cr40, cr41, cr42, cr44, cr46; + unsigned char dac_command; + unsigned char stg_17xx[3]; + unsigned char gendac[6]; +} ARKRegRec, *ARKRegPtr; + + +typedef struct _ARKRec { + pciVideoPtr PciInfo; + PCITAG PciTag; + EntityInfoPtr pEnt; + CARD32 IOAddress; + CARD32 FBAddress; + unsigned char * FBBase; + unsigned char * MMIOBase; + unsigned long videoRam; + OptionInfoPtr Options; + unsigned int Flags; + Bool NoAccel; + CARD32 Bus; + XAAInfoRecPtr pXAA; + int Chipset, ChipRev; + int clock_mult; + int dac_width; + int multiplex_threshold; + int ramdac; + ARKRegRec SavedRegs; /* original mode */ + ARKRegRec ModeRegs; /* current mode */ + Bool (*CloseScreen)(int, ScreenPtr); +} ARKRec, *ARKPtr; + + +#define ARKPTR(p) ((ARKPtr)((p)->driverPrivate)) + + +#define DRIVER_NAME "ark" +#define DRIVER_VERSION "0.5.0" +#define VERSION_MAJOR 0 +#define VERSION_MINOR 5 +#define PATCHLEVEL 0 +#define ARK_VERSION ((VERSION_MAJOR << 24) | \ + (VERSION_MINOR << 16) | \ + PATCHLEVEL) + +#define ZOOMDAC 0x404 +#define ATT490 0x101 + + +#endif /* _ARK_H */ diff --git a/xc/programs/Xserver/hw/xfree86/drivers/ark/ark_accel.c b/xc/programs/Xserver/hw/xfree86/drivers/ark/ark_accel.c new file mode 100644 index 000000000..c2cefce63 --- /dev/null +++ b/xc/programs/Xserver/hw/xfree86/drivers/ark/ark_accel.c @@ -0,0 +1,227 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/ark/ark_accel.c,v 1.4 2000/11/15 23:13:09 dawes Exp $ */ +/* + * Copyright 2000 Ani Joshi <ajoshi@unixbox.com> + * + * XFree86 4.x driver for ARK Logic chipset + * + * 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 Ani Joshi not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. Ani Joshi makes no representations + * about the suitability of this software for any purpose. It is provided + * "as-is" without express or implied warranty. + * + * ANI JOSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL ANI JOSHI 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. + * + * + * Based on the 3.3.x driver by: + * Harm Hanemaayer <H.Hanemaayer@inter.nl.net> + * + */ + + +#include "Xarch.h" +#include "xf86.h" +#include "xf86_ansic.h" +#include "xf86_OSproc.h" +#include "xaa.h" +#include "xf86PciInfo.h" +#include "compiler.h" + +#include "ark.h" +#include "ark_reg.h" + + +int curx, cury, cmd_flags; + + +static void ARKSync(ScrnInfoPtr pScrn) +{ + for (;;) { + if (!(inb(0x3cb) & 0x40)) + break; + } +} + + +static void ARKSetupForSolidFill(ScrnInfoPtr pScrn, int color, + int rop, unsigned int planemask) +{ + ARKPtr pARK = ARKPTR(pScrn); + + OUTREG16(FG_COLOR, color); + /* ARK color mix matches X raster-ops */ + OUTREG16(COLOR_MIX_SEL, (rop | (rop << 8))); + switch (pScrn->bitsPerPixel) { + case 8: + if ((planemask & 0xff) == 0xff) + cmd_flags = DISABLE_PLANEMASK; + else { + OUTREG16(WRITE_PLANEMASK, planemask); + cmd_flags = 0; + } + break; + case 16: + if ((planemask & 0xffff) == 0xffff) + cmd_flags = DISABLE_PLANEMASK; + else { + OUTREG16(WRITE_PLANEMASK, planemask); + cmd_flags = 0; + } + break; + case 32: + OUTREG16(FG_COLOR_HI, color >> 16); + if ((planemask & 0xffffff) == 0xffffff) + cmd_flags = DISABLE_PLANEMASK; + else { + OUTREG16(WRITE_PLANEMASK, planemask); + cmd_flags = 0; + } + break; + } + + curx = cury = -1; +} + + +static void ARKSubsequentSolidFillRect(ScrnInfoPtr pScrn, int x, + int y, int w, int h) +{ + ARKPtr pARK = ARKPTR(pScrn); + int dst_addr; + + OUTREG(WIDTH, ((h - 1) << 16) | (w - 1)); + if (x != curx || y != cury) { + dst_addr = y * pScrn->displayWidth + x; + OUTREG(DST_ADDR, dst_addr); + curx = x; + cury = y; + } + OUTREG16(COMMAND, SELECT_BG_COLOR | SELECT_FG_COLOR | + STENCIL_ONES | DISABLE_CLIPPING | BITBLT | + cmd_flags); + cury += h; +} + + + +static void ARKSetupForScreenToScreenCopy(ScrnInfoPtr pScrn, int xdir, + int ydir, int rop, unsigned int planemask, + int trans_color) +{ + ARKPtr pARK = ARKPTR(pScrn); + + cmd_flags = 0; + if (trans_color != -1) { + if (pScrn->bitsPerPixel <= 16) + OUTREG16(TRANS_COLOR, trans_color); + else { + OUTREG16(TRANS_COLOR, trans_color & 0xffff); + OUTREG16(TRANS_COLOR_HI, trans_color >> 16); + } + cmd_flags = STENCIL_GENERATED; + OUTREG16(COLOR_MIX_SEL, rop | 0x0500); + } else { + OUTREG16(COLOR_MIX_SEL, rop | (rop << 8)); + } + + if (ydir < 0) + cmd_flags |= UP; + if (xdir < 0) + cmd_flags |= LEFT; + + /* yes, quite ugly */ + if ((pScrn->bitsPerPixel == 8 && (planemask & 0xff) == 0xff) || + (pScrn->bitsPerPixel == 16 && (planemask & 0xffff) == 0xffff) || + (pScrn->bitsPerPixel == 32 && (planemask & 0xffffff) == 0xffffff)) + cmd_flags |= DISABLE_PLANEMASK; + else + OUTREG16(WRITE_PLANEMASK, planemask); + +} + + + +static void ARKSubsequentScreenToScreenCopy(ScrnInfoPtr pScrn, + int x1, int y1, + int x2, int y2, + int w, int h) +{ + ARKPtr pARK = ARKPTR(pScrn); + int src_addr, dst_addr; + + if (cmd_flags & UP) { + src_addr = (y1 + h - 1) * pScrn->displayWidth; + dst_addr = (y2 + h - 1) * pScrn->displayWidth; + } else { + src_addr = y1 * pScrn->displayWidth; + dst_addr = y2 * pScrn->displayWidth; + } + if (cmd_flags & LEFT) { + src_addr += x1 + w - 1; + dst_addr += x2 + w - 1; + } else { + src_addr += x1; + dst_addr += x2; + } + + OUTREG(SRC_ADDR, src_addr); + OUTREG(DST_ADDR, dst_addr); + OUTREG(WIDTH, ((h - 1) << 16) | (w - 1)); + OUTREG16(COMMAND, BG_BITMAP | FG_BITMAP | DISABLE_CLIPPING | + BITBLT | cmd_flags); +} + + + +Bool ARKAccelInit(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + ARKPtr pARK = ARKPTR(pScrn); + vgaHWPtr hwp = VGAHWPTR(pScrn); + XAAInfoRecPtr pXAA; + + if (!(pXAA = XAACreateInfoRec())) + return FALSE; + + pXAA->Flags = LINEAR_FRAMEBUFFER; + + pXAA->Sync = ARKSync; + pXAA->SetupForSolidFill = ARKSetupForSolidFill; + pXAA->SubsequentSolidFillRect = ARKSubsequentSolidFillRect; + pXAA->ScreenToScreenCopyFlags = 0; + pXAA->SetupForScreenToScreenCopy = ARKSetupForScreenToScreenCopy; + pXAA->SubsequentScreenToScreenCopy = ARKSubsequentScreenToScreenCopy; + + OUTREG16(COLOR_MIX_SEL, 0x0303); + if (pARK->Chipset == PCI_CHIP_1000PV) { + OUTREG16(WRITE_PLANEMASK, 0xffff); + OUTREG16(TRANS_COLOR_MSK, 0xffff); + } else { + OUTREG16(TRANS_COLOR, 0xffff); + OUTREG16(TRANS_COLOR, 0xffffffff >> 16); + } + if (pARK->Chipset == PCI_CHIP_1000PV && pScrn->bitsPerPixel == 32) { + OUTREG16(STENCIL_PITCH, pScrn->displayWidth * 2); + OUTREG16(SRC_PITCH, pScrn->displayWidth * 2); + OUTREG16(DST_PITCH, pScrn->displayWidth * 2); + } else { + OUTREG16(STENCIL_PITCH, pScrn->displayWidth); + OUTREG16(SRC_PITCH, pScrn->displayWidth); + OUTREG16(DST_PITCH, pScrn->displayWidth); + } + + OUTREG16(BITMAP_CONFIG, LINEAR_STENCIL_ADDR | LINEAR_SRC_ADDR | + LINEAR_DST_ADDR); + + return XAAInit(pScreen, pXAA); +} diff --git a/xc/programs/Xserver/hw/xfree86/drivers/ark/ark_driver.c b/xc/programs/Xserver/hw/xfree86/drivers/ark/ark_driver.c new file mode 100644 index 000000000..b7e765b5c --- /dev/null +++ b/xc/programs/Xserver/hw/xfree86/drivers/ark/ark_driver.c @@ -0,0 +1,1170 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/ark/ark_driver.c,v 1.8 2000/11/15 23:13:09 dawes Exp $ */ +/* + * Copyright 2000 Ani Joshi <ajoshi@unixbox.com> + * + * XFree86 4.x driver for ARK Logic chipset + * + * 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 Ani Joshi not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. Ani Joshi makes no representations + * about the suitability of this software for any purpose. It is provided + * "as-is" without express or implied warranty. + * + * ANI JOSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL ANI JOSHI 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. + * + * + * Based on the 3.3.x driver by: + * Harm Hanemaayer <H.Hanemaayer@inter.nl.net> + * + */ + + +#include "xf86.h" +#include "xf86_OSproc.h" +#include "xf86_ansic.h" +#include "xf86Pci.h" +#include "xf86PciInfo.h" +#include "xf86Version.h" +#include "xf86Resources.h" +#include "xf86fbman.h" +#include "xf86cmap.h" +#include "compiler.h" +#include "xaa.h" +#include "mipointer.h" +#include "micmap.h" +#include "mibstore.h" + +#include "ark.h" + + +/* + * prototypes + */ +static OptionInfoPtr ARKAvailableOptions(int chipid, int busid); +static void ARKIdentify(int flags); +static Bool ARKProbe(DriverPtr drv, int flags); +static Bool ARKPreInit(ScrnInfoPtr pScrn, int flags); +static Bool ARKEnterVT(int scrnIndex, int flags); +static void ARKLeaveVT(int scrnIndex, int flags); +static void ARKSave(ScrnInfoPtr pScrn); +static Bool ARKScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, + char **argv); +static Bool ARKMapMem(ScrnInfoPtr pScrn); +static void ARKUnmapMem(ScrnInfoPtr pScrn); +static Bool ARKModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode); +static void ARKAdjustFrame(int scrnIndex, int x, int y, int flags); +Bool ARKSwitchMode(int scrnIndex, DisplayModePtr mode, int flags); +Bool ARKCloseScreen(int scrnIndex, ScreenPtr pScreen); +Bool ARKSaveScreen(ScreenPtr pScreen, int mode); +static void ARKFreeScreen(int scrnIndex, int flags); +static void ARKLoadPalette(ScrnInfoPtr pScrn, int numColors, + int *indicies, LOCO *colors, + VisualPtr pVisual); +static void ARKWriteMode(ScrnInfoPtr pScrn, vgaRegPtr pVga, ARKRegPtr new); + +/* helpers */ +static unsigned char get_daccomm(); +static unsigned char set_daccom(unsigned char comm); + + +DriverRec ARK = +{ + ARK_VERSION, + DRIVER_NAME, + ARKIdentify, + ARKProbe, + ARKAvailableOptions, + NULL, + 0 +}; + +/* supported chipsets */ +static SymTabRec ARKChipsets[] = { + { PCI_CHIP_1000PV, "ark1000pv" }, + { PCI_CHIP_2000PV, "ark2000pv" }, + { PCI_CHIP_2000MT, "ark2000mt" }, + { -1, NULL } +}; + +static PciChipsets ARKPciChipsets[] = { + { PCI_CHIP_1000PV, PCI_CHIP_1000PV, RES_SHARED_VGA }, + { PCI_CHIP_2000PV, PCI_CHIP_2000PV, RES_SHARED_VGA }, + { PCI_CHIP_2000MT, PCI_CHIP_2000MT, RES_SHARED_VGA }, + { -1, -1, RES_UNDEFINED } +}; + +typedef enum { + OPTION_NOACCEL +} ARKOpts; + +static OptionInfoRec ARKOptions[] = { + { OPTION_NOACCEL, "noaccel", OPTV_BOOLEAN, {0}, FALSE } +}; + +static const char *fbSymbols[] = { + "fbScreenInit", + NULL +}; + +static const char *vgaHWSymbols[] = { + "vgaHWGetHWRec", + "vgaHWFreeHWRec", + "vgaHWGetIOBase", + "vgaHWSave", + "vgaHWProtect", + "vgaHWRestore", + "vgaHWMapMem", + "vgaHWUnmapMem", + "vgaHWSaveScreen", + "vgaHWLock", + NULL +}; + +static const char *xaaSymbols[] = { + "XAACreateInfoRec", + "XAADestroyInfoRec", + "XAAInit", + "XAAScreenIndex", + NULL +}; + +#ifdef XFree86LOADER + +MODULESETUPPROTO(ARKSetup); + +static XF86ModuleVersionInfo ARKVersRec = { + "ark", + MODULEVENDORSTRING, + MODINFOSTRING1, + MODINFOSTRING2, + XF86_VERSION_CURRENT, + VERSION_MAJOR, VERSION_MINOR, PATCHLEVEL, + ABI_CLASS_VIDEODRV, + ABI_VIDEODRV_VERSION, + MOD_CLASS_VIDEODRV, + {0, 0, 0, 0} +}; + +XF86ModuleData arkModuleData = { &ARKVersRec, ARKSetup, NULL }; + +pointer ARKSetup(pointer module, pointer opts, int *errmaj, int *errmin) +{ + static Bool setupDone = FALSE; + + if (!setupDone) { + setupDone = TRUE; + xf86AddDriver(&ARK, module, 0); + LoaderRefSymLists(fbSymbols, vgaHWSymbols, xaaSymbols, NULL); + return (pointer) 1; + } else { + if (errmaj) + *errmaj = LDR_ONCEONLY; + return NULL; + } +} + +#endif /* XFree86LOADER */ + + +static Bool ARKGetRec(ScrnInfoPtr pScrn) +{ + if (pScrn->driverPrivate) + return TRUE; + + pScrn->driverPrivate = xnfcalloc(sizeof(ARKRec), 1); + + return TRUE; +} + +static void ARKFreeRec(ScrnInfoPtr pScrn) +{ + if (!pScrn->driverPrivate) + return; + + xfree(pScrn->driverPrivate); + pScrn->driverPrivate = NULL; +} + +static OptionInfoPtr ARKAvailableOptions(int chipid, int busid) +{ + return ARKOptions; +} + +static void ARKIdentify(int flags) +{ + xf86PrintChipsets("ark", "driver (version " DRIVER_VERSION " for ARK Logic chipset", + ARKChipsets); +} + +static Bool ARKProbe(DriverPtr drv, int flags) +{ + int i; + GDevPtr *devSections = NULL; + int *usedChips; + int numDevSections; + int numUsed; + Bool foundScreen = FALSE; + + /* sanity check */ + if ((numDevSections = xf86MatchDevice("ark", &devSections)) <= 0) + return FALSE; + + /* do ISA later */ + numUsed = xf86MatchPciInstances("ark", PCI_VENDOR_ARK, + ARKChipsets, ARKPciChipsets, + devSections, numDevSections, drv, + &usedChips); + + if (devSections) + xfree(devSections); + + if (numUsed <= 0) + return FALSE; + + if (flags & PROBE_DETECT) + foundScreen = TRUE; + else for (i=0; i<numUsed; i++) { + ScrnInfoPtr pScrn = xf86AllocateScreen(drv, 0); + + pScrn->driverVersion = VERSION_MAJOR; + pScrn->driverName = DRIVER_NAME; + pScrn->name = "ark"; + pScrn->Probe = ARKProbe; + pScrn->PreInit = ARKPreInit; + pScrn->ScreenInit = ARKScreenInit; + pScrn->SwitchMode = ARKSwitchMode; + pScrn->AdjustFrame = ARKAdjustFrame; + pScrn->EnterVT = ARKEnterVT; + pScrn->LeaveVT = ARKLeaveVT; + pScrn->FreeScreen = ARKFreeScreen; + foundScreen = TRUE; + xf86ConfigActivePciEntity(pScrn, usedChips[i], ARKPciChipsets, + NULL, NULL, NULL, NULL, NULL); + } + + xfree(usedChips); + + return foundScreen; +} + + +static Bool ARKPreInit(ScrnInfoPtr pScrn, int flags) +{ + EntityInfoPtr pEnt; + ARKPtr pARK; + vgaHWPtr hwp; + MessageType from = X_DEFAULT; + int i; + ClockRangePtr clockRanges; + char *mod = NULL; + const char *reqSym = NULL; + rgb zeros = {0, 0, 0}; + Gamma gzeros = {0.0, 0.0, 0.0}; + unsigned char tmp; + + if (flags & PROBE_DETECT) + return FALSE; + + if (!xf86LoadSubModule(pScrn, "vgahw")) + return FALSE; + + xf86LoaderReqSymLists(vgaHWSymbols, NULL); + + if (!vgaHWGetHWRec(pScrn)) + return FALSE; + + hwp = VGAHWPTR(pScrn); + vgaHWGetIOBase(hwp); + + pScrn->monitor = pScrn->confScreen->monitor; + + if (!xf86SetDepthBpp(pScrn, 8, 8, 8, Support24bppFb | Support32bppFb)) + return FALSE; + else { + switch (pScrn->depth) { + case 8: + case 16: + case 24: + case 32: + /* OK */ + break; + default: + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Given depth (%d) is not supported by this driver\n", + pScrn->depth); + return FALSE; + } + } + + xf86PrintDepthBpp(pScrn); + + if (pScrn->depth > 8) { + if (!xf86SetWeight(pScrn, zeros, zeros)) + return FALSE; + } + + if (pScrn->depth == 8) + pScrn->rgbBits = 8; + + if (!xf86SetDefaultVisual(pScrn, -1)) + return FALSE; + + pScrn->progClock = TRUE; + + if (!ARKGetRec(pScrn)) + return FALSE; + + pARK = ARKPTR(pScrn); + + xf86CollectOptions(pScrn, NULL); + xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ARKOptions); + + if (xf86ReturnOptValBool(ARKOptions, OPTION_NOACCEL, FALSE)) { + pARK->NoAccel = TRUE; + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Option: NoAccel - acceleration disabled\n"); + } else + pARK->NoAccel = FALSE; + + if (pScrn->numEntities > 1) { + ARKFreeRec(pScrn); + return FALSE; + } + + pEnt = xf86GetEntityInfo(pScrn->entityList[0]); + if (pEnt->resources) { + xfree(pEnt); + ARKFreeRec(pScrn); + return FALSE; + } + + pARK->PciInfo = xf86GetPciInfoForEntity(pEnt->index); + xf86RegisterResources(pEnt->index, NULL, ResNone); + xf86SetOperatingState(RES_SHARED_VGA, pEnt->index, ResUnusedOpr); + xf86SetOperatingState(resVgaMemShared, pEnt->index, ResDisableOpr); + + if (pEnt->device->chipset && *pEnt->device->chipset) { + pScrn->chipset = pEnt->device->chipset; + pARK->Chipset = xf86StringToToken(ARKChipsets, pScrn->chipset); + } else if (pEnt->device->chipID >= 0) { + pARK->Chipset = pEnt->device->chipID; + pScrn->chipset = (char *)xf86TokenToString(ARKChipsets, + pARK->Chipset); + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipID override: 0x%04X\n", + pARK->Chipset); + } else { + pARK->Chipset = pARK->PciInfo->chipType; + pScrn->chipset = (char *)xf86TokenToString(ARKChipsets, + pARK->Chipset); + } + + if (pEnt->device->chipRev >= 0) { + pARK->ChipRev = pEnt->device->chipRev; + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "ChipRev override: %d\n", + pARK->ChipRev); + } else + pARK->ChipRev = pARK->PciInfo->chipRev; + + xfree(pEnt); + + xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Chipset: \"%s\"\n", pScrn->chipset); + + pARK->PciTag = pciTag(pARK->PciInfo->bus, pARK->PciInfo->device, + pARK->PciInfo->func); + + /* unlock CRTC[0-7] */ + outb(hwp->IOBase + 4, 0x11); + tmp = inb(hwp->IOBase + 5); + outb(hwp->IOBase + 5, tmp & 0x7f); + modinx(0x3c4, 0x1d, 0x01, 0x01); + + /* use membase's later on ??? */ + pARK->FBAddress = (rdinx(0x3c4, 0x13) << 16) + + (rdinx(0x3c4, 0x14) << 24); + + xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "Framebuffer @ 0x%x\n", + pARK->FBAddress); + + if (!xf86SetGamma(pScrn, gzeros)) + return FALSE; + + if (!pScrn->videoRam) { + unsigned char sr10; + + sr10 = rdinx(0x3c4, 0x10); + if (pARK->Chipset == PCI_CHIP_1000PV) { + if ((sr10 & 0x40) == 0) + pScrn->videoRam = 1024; + else + pScrn->videoRam = 2048; + } + if (pARK->Chipset == PCI_CHIP_2000PV || + pARK->Chipset == PCI_CHIP_2000MT) { + if ((sr10 & 0xc0) == 0) + pScrn->videoRam = 1024; + else if ((sr10 & 0xc0) == 0x40) + pScrn->videoRam = 2048; + else + pScrn->videoRam = 4096; + } + + xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "Detected %d bytes video ram\n", + pScrn->videoRam); + + /* try to detect the RAMDAC */ + { + int man_id, dev_id; + + inb(0x3c6); /* skip command register */ + man_id = inb(0x3c6); /* manufacturer id */ + dev_id = inb(0x3c6); /* device id */ + if (man_id == 0x84 && dev_id == 0x98) { + pARK->ramdac = ZOOMDAC; + pARK->dac_width = 16; + pARK->multiplex_threshold = 40000; + xf86DrvMsg(pScrn->scrnIndex, X_PROBED, + "Detected ZOOMDAC\n"); + } + } + + /* hack for this Bali32 */ + pARK->ramdac = ATT490; + pARK->dac_width = 8; + + pARK->clock_mult = 1; + if (pARK->dac_width == 16) { + if (pScrn->bitsPerPixel == 32) + pARK->clock_mult = 2; + } + + pScrn->numClocks = 1; + pScrn->clock[0] = 80000; /* safe */ + + clockRanges = xnfcalloc(sizeof(ClockRange), 1); + clockRanges->next = NULL; + clockRanges->minClock = 20000; + clockRanges->maxClock = 80000; + clockRanges->clockIndex = -1; + clockRanges->interlaceAllowed = FALSE; /* ? */ + clockRanges->doubleScanAllowed = FALSE; /* ? */ + + i = xf86ValidateModes(pScrn, pScrn->monitor->Modes, + pScrn->display->modes, clockRanges, + NULL, 256, 2048, pScrn->bitsPerPixel, + 128, 2048, pScrn->virtualX, + pScrn->display->virtualY, pARK->videoRam * 1024, + LOOKUP_BEST_REFRESH); + if (i == -1) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "no valid modes left\n"); + ARKFreeRec(pScrn); + return FALSE; + } + + xf86PruneDriverModes(pScrn); + + if (i == 0 || pScrn->modes == NULL) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "no valid modes found\n"); + ARKFreeRec(pScrn); + return FALSE; + } + + xf86SetCrtcForModes(pScrn, 0); + pScrn->currentMode = pScrn->modes; + xf86PrintModes(pScrn); + xf86SetDpi(pScrn, 0, 0); + + xf86LoadSubModule(pScrn, "fb"); + xf86LoaderReqSymbols("fbScreenInit", NULL); + + if (!pARK->NoAccel) { + xf86LoadSubModule(pScrn, "xaa"); + xf86LoaderReqSymLists(xaaSymbols, NULL); + } + + return TRUE; +} +} + +static Bool ARKScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, + char **argv) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + ARKPtr pARK = ARKPTR(pScrn); + BoxRec MemBox; + int i; + + pScrn->fbOffset = 0; + + if (!ARKMapMem(pScrn)) { + ARKFreeRec(pScrn); + return FALSE; + } + + ARKSave(pScrn); + +/* vgaHWBlankScreen(pScrn, TRUE); */ + + if (!ARKModeInit(pScrn, pScrn->currentMode)) + return FALSE; + + ARKSaveScreen(pScreen, SCREEN_SAVER_ON); + + pScrn->AdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); + + miClearVisualTypes(); + if (pScrn->bitsPerPixel > 8) { + if (!miSetVisualTypes(pScrn->depth, TrueColorMask, + pScrn->rgbBits, pScrn->defaultVisual)) + return FALSE; + } else { + if (!miSetVisualTypes(pScrn->depth, miGetDefaultVisualMask(pScrn->depth), + pScrn->rgbBits, pScrn->defaultVisual)) + return FALSE; + } + + if (!fbScreenInit(pScreen, pARK->FBBase, pScrn->virtualX, + pScrn->virtualY, pScrn->xDpi, pScrn->yDpi, + pScrn->displayWidth, pScrn->bitsPerPixel)) + return FALSE; + + xf86SetBlackWhitePixels(pScreen); + + if (pScrn->bitsPerPixel > 8) { + VisualPtr pVis; + + pVis = pScreen->visuals + pScreen->numVisuals; + while (--pVis >= pScreen->visuals) { + if ((pVis->class | DynamicClass) == DirectColor) { + pVis->offsetRed = pScrn->offset.red; + pVis->offsetGreen = pScrn->offset.green; + pVis->offsetBlue = pScrn->offset.blue; + pVis->redMask = pScrn->mask.red; + pVis->greenMask = pScrn->mask.green; + pVis->blueMask = pScrn->mask.blue; + } + } + } + + + miInitializeBackingStore(pScreen); + xf86SetBackingStore(pScreen); + + if (!pARK->NoAccel) { + if (ARKAccelInit(pScreen)) { + xf86DrvMsg(scrnIndex, X_INFO, "Acceleration enabled\n"); + } else { + xf86DrvMsg(scrnIndex, X_ERROR, "Acceleration initialization failed\n"); + xf86DrvMsg(scrnIndex, X_INFO, "Acceleration disabled\n"); + } + } else { + xf86DrvMsg(scrnIndex, X_INFO, "Acceleration disabled\n"); + } + + miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); + + if (!miCreateDefColormap(pScreen)) + return FALSE; + + if (!xf86HandleColormaps(pScreen, 256, 8, ARKLoadPalette, NULL, + CMAP_RELOAD_ON_MODE_SWITCH)) + return FALSE; + +/* vgaHWBlankScreen(pScrn, TRUE); */ + + pScreen->SaveScreen = ARKSaveScreen; + pARK->CloseScreen = pScreen->CloseScreen; + pScreen->CloseScreen = ARKCloseScreen; + + return TRUE; +} + + + +static void ARKSave(ScrnInfoPtr pScrn) +{ + ARKPtr pARK = ARKPTR(pScrn); + ARKRegPtr save = &pARK->SavedRegs; + vgaHWPtr hwp = VGAHWPTR(pScrn); + int vgaIOBase = hwp->IOBase; + + vgaHWUnlock(hwp); + vgaHWSave(pScrn, &hwp->SavedReg, VGA_SR_ALL); + vgaHWLock(hwp); + + /* set read and write aperture index to 0 */ + wrinx(0x3c4, 0x15, 0x00); + wrinx(0x3c4, 0x16, 0x00); + outb(0x3c8, 0); /* reset DAC register access mode */ + + save->sr10 = rdinx(0x3c4, 0x10); + save->sr11 = rdinx(0x3c4, 0x11); + save->sr12 = rdinx(0x3c4, 0x12); + save->sr13 = rdinx(0x3c4, 0x13); + save->sr14 = rdinx(0x3c4, 0x14); + save->sr15 = rdinx(0x3c4, 0x15); + save->sr16 = rdinx(0x3c4, 0x16); + save->sr17 = rdinx(0x3c4, 0x17); + save->sr18 = rdinx(0x3c4, 0x18); + +#if 0 + save->sr1d = rdinx(0x3c4, 0x1d); + save->sr1c = rdinx(0x3c4, 0x1c); + + save->sr20 = rdinx(0x3c4, 0x20); + save->sr21 = rdinx(0x3c4, 0x21); + save->sr22 = rdinx(0x3c4, 0x22); + save->sr23 = rdinx(0x3c4, 0x23); + save->sr24 = rdinx(0x3c4, 0x24); + save->sr25 = rdinx(0x3c4, 0x25); + save->sr26 = rdinx(0x3c4, 0x26); + save->sr27 = rdinx(0x3c4, 0x27); + save->sr29 = rdinx(0x3c4, 0x29); + save->sr2a = rdinx(0x3c4, 0x2a); + if ((pARK->Chipset == PCI_CHIP_2000PV) || + (pARK->Chipset == PCI_CHIP_2000MT)) { + save->sr28 = rdinx(0x3c4, 0x28); + save->sr2b = rdinx(0x3c4, 0x2b); + } +#endif + + save->cr40 = rdinx(vgaIOBase + 4, 0x40); + save->cr41 = rdinx(vgaIOBase + 4, 0x41); + save->cr42 = rdinx(vgaIOBase + 4, 0x42); + save->cr44 = rdinx(vgaIOBase + 4, 0x44); + + if ((pARK->Chipset == PCI_CHIP_2000PV) || + (pARK->Chipset == PCI_CHIP_2000MT)) + save->cr46 = rdinx(vgaIOBase + 4, 0x46); + + /* save RAMDAC regs here, based on type */ + save->dac_command = get_daccomm(); +} + + + +static Bool ARKModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode) +{ + ARKPtr pARK = ARKPTR(pScrn); + ARKRegPtr new = &pARK->ModeRegs; + int multiplexing, dac16, modepitch; + vgaHWPtr hwp = VGAHWPTR(pScrn); + vgaRegPtr pVga = &hwp->ModeReg; + int vgaIOBase = hwp->IOBase; + unsigned char tmp; + int offset; + + multiplexing = 0; + + if ((pScrn->bitsPerPixel == 8) && (pARK->dac_width == 16) && + (mode->Clock > pARK->multiplex_threshold)) + multiplexing = 1; + + if (pARK->clock_mult == 2) { + if (!mode->CrtcHAdjusted) { + mode->CrtcHDisplay <<= 1; + mode->CrtcHSyncStart <<= 1; + mode->CrtcHSyncEnd <<= 1; + mode->CrtcHTotal <<= 1; + mode->CrtcHSkew <<= 1; + mode->CrtcHAdjusted = TRUE; + } + } + + if (multiplexing) { + if (!mode->CrtcHAdjusted) { + mode->CrtcHDisplay >>= 1; + mode->CrtcHSyncStart >>= 1; + mode->CrtcHSyncEnd >>= 1; + mode->CrtcHTotal >>= 1; + mode->CrtcHSkew >>= 1; + mode->CrtcHAdjusted = TRUE; + } + } + + if (!vgaHWInit(pScrn, mode)) + return FALSE; + + if ((pARK->Chipset == PCI_CHIP_2000PV) || + (pARK->Chipset == PCI_CHIP_2000MT)) { + new->cr46 = rdinx(vgaIOBase + 4, 0x46) & ~0x04; + dac16 = 0; + if (pScrn->bitsPerPixel > 8) + dac16 = 1; + if (dac16) + new->cr46 |= 0x04; + } + + offset = (pScrn->displayWidth * (pScrn->bitsPerPixel / 8)) >> 3; + pVga->CRTC[0x13] = offset; + pVga->Attribute[0x11] = 0x00; + new->cr41 = (offset & 0x100) >> 5; + + pVga->MiscOutReg |= 0x0c; + + new->sr11 = rdinx(0x3c4, 0x11) & ~0x0f; + switch (pScrn->bitsPerPixel) { + case 8: + new->sr11 |= 0x06; + break; + case 16: + new->sr11 |= 0x0a; + break; + case 24: + new->sr11 |= 0x06; + break; + case 32: + if ((pARK->Chipset == PCI_CHIP_2000PV) || + (pARK->Chipset == PCI_CHIP_2000MT)) + new->sr11 |= 0x0e; + else + new->sr11 |= 0x0a; + break; + default: + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Unsupported screen depth %d\n", + pScrn->bitsPerPixel); + return FALSE; + } + + switch (pScrn->displayWidth) { + case 640: + modepitch = 0; + break; + case 800: + modepitch = 1; + break; + case 1024: + modepitch = 2; + break; + case 1280: + modepitch = 4; + break; + case 1600: + modepitch = 5; + break; + case 2048: + modepitch = 6; + break; + default: + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Unsupported screen width %d\n", + pScrn->displayWidth); + return FALSE; + } + + new->sr17 &= ~0xc7; + new->sr17 |= modepitch; + + new->sr10 = rdinx(0x3c4, 0x10) & ~0x1f; + new->sr10 |= 0x1f; + + new->sr13 = pARK->FBAddress >> 16; + new->sr14 = pARK->FBAddress >> 24; + + new->sr12 = rdinx(0x3c4, 0x12) & ~0x03; + switch (pScrn->videoRam) { + case 1024: + new->sr12 |= 0x01; + break; + case 2048: + new->sr12 |= 0x02; + break; + case 4096: + new->sr12 |= 0x03; + break; + default: + new->sr12 |= 0x01; + break; + } + + new->sr15 = new->sr16 = 0; + + tmp = 0; + if ((mode->CrtcVTotal - 2) & 0x400) + tmp |= 0x80; + if ((mode->CrtcVDisplay - 1) & 0x400) + tmp |= 0x40; + if (mode->CrtcVSyncStart & 0x400) + tmp |= 0x10; + new->cr40 = tmp; + + tmp = new->cr41; /* initialized earlier */ + if ((mode->CrtcHTotal / 8 - 5) & 0x100) + tmp |= 0x80; + if ((mode->CrtcHDisplay / 8 - 1) & 0x100) + tmp |= 0x40; + if ((mode->CrtcHSyncStart / 8 - 1) & 0x100) + tmp |= 0x20; + if ((mode->CrtcHSyncStart / 8) & 0x100) + tmp |= 0x10; + new->cr41 |= tmp; + + new->cr44 = rdinx(vgaIOBase + 4, 0x44) & ~0x34; + new->cr44 &= ~0x01; + new->cr42 = 0; + + /* check interlace here later */ + + /* set display FIFO threshold */ + { + int threshold; + unsigned char tmp; + int bandwidthused, percentused; + + /* mostly guesses here as I would need to know more about + * and from the ramdac... + */ + bandwidthused = (mode->Clock / pARK->clock_mult) * + (pScrn->bitsPerPixel / 8); + /* 120000 is another guess */ + percentused = (bandwidthused * 100) / 120000; + tmp = rdinx(0x3c4, 0x18); + if (pARK->Chipset == PCI_CHIP_1000PV) { + threshold = 4; + tmp |= 0x08; /* enable full FIFO (8 deep) */ + tmp &= ~0x07; + tmp |= threshold; + } + if ((pARK->Chipset == PCI_CHIP_2000PV) || + (pARK->Chipset == PCI_CHIP_2000MT)) { + threshold = 12; + if (percentused >= 45) + threshold = 8; + if (percentused >= 70) + threshold = 4; + tmp &= 0x40; + tmp |= 0x10; + tmp |= (threshold & 0x0e) >> 1; + if (threshold & 0x01) + tmp |= 0x80; + if (threshold & 0x10) + tmp |= 0x20; + } + new->sr18 = tmp; + } + + /* setup the RAMDAC regs */ + if (pARK->ramdac == ZOOMDAC) { + new->dac_command = 0x04; + if ((pScrn->bitsPerPixel == 8) && multiplexing) + new->dac_command = 0x24; + if ((pScrn->bitsPerPixel == 16) && (pARK->dac_width == 16)) + /* assuming green weight is not 5 */ + new->dac_command = 0x34; + if ((pScrn->bitsPerPixel == 16) && (pARK->dac_width == 8)) + new->dac_command = 0x64; + if ((pScrn->bitsPerPixel == 24) && (pARK->dac_width == 16)) + new->dac_command = 0xb4; /* packed */ + if ((pScrn->bitsPerPixel == 32) && (pARK->dac_width == 16)) + new->dac_command = 0x54; + } else if (pARK->ramdac == ATT490) { + new->dac_command = 0x00; + if (pScrn->bitsPerPixel == 16) + /* assuming green weight is 6 */ + new->dac_command = 0xc0; + if (pScrn->bitsPerPixel == 24) + new->dac_command = 0xe0; + } + + /* hrmm... */ + new->dac_command |= 0x02; + +#if 0 + /* hw cursor regs */ + new->sr20 = rdinx(0x3c4, 0x20); + new->sr21 = rdinx(0x3c4, 0x21); + new->sr22 = rdinx(0x3c4, 0x22); + new->sr23 = rdinx(0x3c4, 0x23); + new->sr24 = rdinx(0x3c4, 0x24); + new->sr25 = rdinx(0x3c4, 0x25); + new->sr26 = rdinx(0x3c4, 0x26); + new->sr27 = rdinx(0x3c4, 0x27); + new->sr29 = rdinx(0x3c4, 0x29); + new->sr2a = rdinx(0x3c4, 0x2a); + if ((pARK->Chipset == PCI_CHIP_2000PV) || + (pARK->Chipset == PCI_CHIP_2000MT)) { + new->sr28 = rdinx(0x3c4, 0x28); + new->sr2b = rdinx(0x3c4, 0x3b); + } +#endif + + + ARKWriteMode(pScrn, pVga, new); + + return TRUE; +} + + +static void ARKAdjustFrame(int scrnIndex, int x, int y, int flags) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + ARKPtr pARK = ARKPTR(pScrn); + vgaHWPtr hwp = VGAHWPTR(pScrn); + int vgaIOBase = hwp->IOBase; + int base; + + base = ((y * pScrn->displayWidth + x) * + (pScrn->bitsPerPixel / 8)); + + if (((pARK->Chipset == PCI_CHIP_2000PV) || + (pARK->Chipset == PCI_CHIP_2000MT)) && + (pScrn->videoRam >= 2048)) + base >>= 3; + else + base >>= 2; + if (pScrn->bitsPerPixel == 24) + base -= base % 3; + + outw(vgaIOBase + 4, (base & 0x00ff00) | 0x0c); + outw(vgaIOBase + 4, ((base & 0x00ff) << 8) | 0x0d); + + modinx(vgaIOBase + 4, 0x40, 0x07, (base & 0x070000) >> 16); +} + + + +static void ARKWriteMode(ScrnInfoPtr pScrn, vgaRegPtr pVga, ARKRegPtr new) +{ + ARKPtr pARK = ARKPTR(pScrn); + vgaHWPtr hwp = VGAHWPTR(pScrn); + int vgaIOBase = hwp->IOBase; + + vgaHWProtect(pScrn, TRUE); + + /* set read and write aperture index to 0 */ + wrinx(0x3c4, 0x15, 0x00); + wrinx(0x3c4, 0x16, 0x00); + + /* write the extended registers first so that textmode font + * restoration can suceed + */ + wrinx(0x3c4, 0x10, new->sr10); + modinx(0x3c4, 0x11, 0x3f, new->sr11); + wrinx(0x3c4, 0x12, new->sr12); + wrinx(0x3c4, 0x13, new->sr13); + wrinx(0x3c4, 0x14, new->sr14); + wrinx(0x3c4, 0x15, new->sr15); + wrinx(0x3c4, 0x16, new->sr16); + wrinx(0x3c4, 0x17, new->sr17); + +#if 0 + wrinx(0x3c4, 0x1c, new->sr1c); + wrinx(0x3c4, 0x1d, new->sr1d); + + /* hw cursor regs */ + wrinx(0x3c4, 0x20, new->sr20); + wrinx(0x3c4, 0x21, new->sr21); + wrinx(0x3c4, 0x22, new->sr22); + wrinx(0x3c4, 0x23, new->sr23); + wrinx(0x3c4, 0x24, new->sr24); + wrinx(0x3c4, 0x25, new->sr25); + wrinx(0x3c4, 0x26, new->sr26); + wrinx(0x3c4, 0x27, new->sr27); + wrinx(0x3c4, 0x29, new->sr29); + wrinx(0x3c4, 0x2a, new->sr2a); +#endif + + if ((pARK->Chipset == PCI_CHIP_2000PV) || + (pARK->Chipset == PCI_CHIP_2000MT)) { + wrinx(0x3c4, 0x28, new->sr28); + wrinx(0x3c4, 0x2B, new->sr2b); + } + + wrinx(vgaIOBase + 4, 0x40, new->cr40); + wrinx(vgaIOBase + 4, 0x41, new->cr41); + wrinx(vgaIOBase + 4, 0x42, new->cr42); + wrinx(vgaIOBase + 4, 0x44, new->cr44); + + if ((pARK->Chipset == PCI_CHIP_2000PV) || + (pARK->Chipset == PCI_CHIP_2000MT)) + wrinx(vgaIOBase + 4, 0x46, new->cr46); + + /* RAMDAC regs */ + if (pARK->ramdac == ZOOMDAC) { + set_daccom(new->dac_command); + } + + if (xf86IsPrimaryPci(pARK->PciInfo)) + vgaHWRestore(pScrn, pVga, VGA_SR_ALL); + else + vgaHWRestore(pScrn, pVga, VGA_SR_MODE); + + inb(0x3c8); + outb(0x3c6, 0xff); + + vgaHWProtect(pScrn, FALSE); + +} + + +static Bool ARKEnterVT(int scrnIndex, int flags) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + + if (!ARKModeInit(pScrn, pScrn->currentMode)) + return FALSE; + + ARKAdjustFrame(scrnIndex, pScrn->frameX0, pScrn->frameY0, 0); + + return TRUE; +} + + + +static void ARKLeaveVT(int scrnIndex, int flags) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + ARKPtr pARK = ARKPTR(pScrn); + ARKRegPtr old = &pARK->SavedRegs; + vgaHWPtr hwp = VGAHWPTR(pScrn); + + ARKWriteMode(pScrn, &hwp->ModeReg, old); + + vgaHWUnlock(hwp); + vgaHWRestore(pScrn, &hwp->SavedReg, VGA_SR_MODE | VGA_SR_FONTS); + vgaHWLock(hwp); + + return; +} + + +static Bool ARKMapMem(ScrnInfoPtr pScrn) +{ + ARKPtr pARK = ARKPTR(pScrn); + vgaHWPtr hwp = VGAHWPTR(pScrn); + + /* extended to cover MMIO space at 0xB8000 */ + hwp->MapSize = 0x20000; + + pARK->MMIOBase = xf86MapVidMem(pScrn->scrnIndex, VIDMEM_MMIO, + 0xb8000, 0x8000); + + pARK->FBBase = xf86MapPciMem(pScrn->scrnIndex, VIDMEM_FRAMEBUFFER, + pARK->PciTag, pARK->FBAddress, + pScrn->videoRam * 1024); + if (!pARK->FBBase) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Cound not map framebuffer\n"); + return FALSE; + } + + return TRUE; +} + + +static void ARKUnmapMem(ScrnInfoPtr pScrn) +{ + ARKPtr pARK = ARKPTR(pScrn); + + vgaHWUnmapMem(pScrn); + + xf86UnMapVidMem(pScrn->scrnIndex, (pointer)pARK->FBBase, + pScrn->videoRam * 1024); + + return; +} + + +Bool ARKCloseScreen(int scrnIndex, ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + ARKPtr pARK = ARKPTR(pScrn); + vgaHWPtr hwp = VGAHWPTR(pScrn); + + if (pScrn->vtSema) { + vgaHWUnlock(hwp); + ARKWriteMode(pScrn, &hwp->SavedReg, &pARK->SavedRegs); + vgaHWLock(hwp); + ARKUnmapMem(pScrn); + } + + pScrn->vtSema = FALSE; + pScreen->CloseScreen = pARK->CloseScreen; + + return (*pScreen->CloseScreen)(scrnIndex, pScreen); +} + + +Bool ARKSaveScreen(ScreenPtr pScreen, int mode) +{ + return vgaHWSaveScreen(pScreen, mode); +} + + +Bool ARKSwitchMode(int scrnIndex, DisplayModePtr mode, int flags) +{ + return ARKModeInit(xf86Screens[scrnIndex], mode); +} + + +static void ARKLoadPalette(ScrnInfoPtr pScrn, int numColors, + int *indicies, LOCO *colors, + VisualPtr pVisual) +{ + int i, index; + + for (i=0; i<numColors; i++) { + index = indicies[i]; + outb(0x3c8, index); + outb(0x3c9, colors[index].red); + outb(0x3c9, colors[index].green); + outb(0x3c9, colors[index].blue); + } +} + + +static void ARKFreeScreen(int scrnIndex, int flags) +{ + ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + + vgaHWFreeHWRec(pScrn); + + ARKFreeRec(pScrn); +} + + +static unsigned char get_daccomm() +{ + unsigned char tmp; + + outb(0x3c8, 0); + inb(0x3c6); + inb(0x3c6); + inb(0x3c6); + inb(0x3c6); + tmp = inb(0x3c6); + outb(0x3c8, 0); + + return tmp; +} + + +static unsigned char set_daccom(unsigned char comm) +{ +#if 0 + outb(0x3c8, 0); +#else + inb(0x3c8); +#endif + inb(0x3c6); + inb(0x3c6); + inb(0x3c6); + inb(0x3c6); + outb(0x3c6, comm); +#if 0 + outb(0x3c8, 0); +#else + inb(0x3c8); +#endif + + return inb(0x3c6); +} diff --git a/xc/programs/Xserver/hw/xfree86/drivers/ark/ark_reg.h b/xc/programs/Xserver/hw/xfree86/drivers/ark/ark_reg.h new file mode 100644 index 000000000..43bb7838f --- /dev/null +++ b/xc/programs/Xserver/hw/xfree86/drivers/ark/ark_reg.h @@ -0,0 +1,88 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/ark/ark_reg.h,v 1.1 2000/11/14 17:28:13 dawes Exp $ */ + +#ifndef _ARK_REG_H +#define _ARK_REG_H + +/* and let there be no 'u' in color */ +#define BG_COLOR 0x00 +#define FG_COLOR 0x02 +#define BG_COLOR_HI 0x04 +#define FG_COLOR_HI 0x06 +#define TRANS_COLOR 0x08 +#define TRANS_COLOR_MSK 0x0a +#define TRANS_COLOR_HI 0x0c +#define TRANS_COLOR_MSK_HI 0x0e +#define COLOR_MIX_SEL 0x18 +#define WRITE_PLANEMASK 0x1a +#define ERROR_TERM 0x50 +#define AXIAL_ERROR_INC 0x54 +#define STENCIL_PITCH 0x60 +#define SRC_PITCH 0x62 +#define DST_PITCH 0x64 +#define STENCIL_ADDR 0x68 +#define STENCIL_X 0x68 +#define STENCIL_Y 0x6a +#define SRC_ADDR 0x6c +#define SRC_X 0x6c +#define SRC_Y 0x6e +#define DST_ADDR 0x70 +#define DST_X 0x70 +#define DST_Y 0x72 +#define WIDTH 0x74 +#define HEIGHT 0x76 +#define BITMAP_CONFIG 0x7c +#define COMMAND 0x7e + + +/* constants for COMMAND register */ + +#define DRAWSTEP 0x0000 +#define LINEDRAW 0x1000 +#define BITBLT 0x2000 +#define TEXTBITBLT 0x3000 +#define USE_PLANEMASK 0x0000 +#define DISABLE_PLANEMASK 0x0800 +#define PATTERN_8X8 0x0400 +#define SELECT_BG_COLOR 0x0000 +#define BG_BITMAP 0x0200 +#define SELECT_FG_COLOR 0x0000 +#define FG_BITMAP 0x0100 +#define STENCIL_ONES 0x0000 +#define STENCIL_GENERATED 0x0040 +#define STENCIL_BITMAP 0x0080 +#define LINE_DRAWALL 0x0000 +#define LINE_SKIP_FIRST 0x0010 +#define LINE_SKIP_LAST 0x0020 +#define ENABLE_CLIPPING 0x0000 +#define DISABLE_CLIPPING 0x0008 +#undef DOWN +#define DOWN 0x0000 +#undef UP +#define UP 0x0002 +#define RIGHT 0x0000 +#define LEFT 0x0004 +#define DX_GREATER_THAN_DY 0x0000 +#define DY_GREATER_THAN_DX 0x0001 + + +/* constants for bitmap config register */ + +#define SWAP_NIBLES 0x2000 +#define SWAP_BITS 0x1000 +#define SYSTEM_STENCIL 0x0200 +#define LINEAR_STENCIL_ADDR 0x0100 +#define SYSTEM_SRC 0x0020 +#define LINEAR_SRC_ADDR 0x0010 +#define SYSTEM_DST 0x0002 +#define LINEAR_DST_ADDR 0x0001 + + +/* IO macros */ + +#define OUTREG16(offset, value) \ + *(unsigned short *)(pARK->MMIOBase + offset) = value +#define OUTREG(offset, value) \ + *(unsigned int *)(pARK->MMIOBase + offset) = value + + +#endif /* _ARK_REG_H */ |