diff --git a/hw/kdrive/Makefile.am b/hw/kdrive/Makefile.am index eb185616d..2d51c9c9d 100644 --- a/hw/kdrive/Makefile.am +++ b/hw/kdrive/Makefile.am @@ -1,5 +1,5 @@ if KDRIVEVESA -VESA_SUBDIRS = vesa mach64 mga nvidia r128 smi +VESA_SUBDIRS = vesa ati mach64 mga nvidia r128 smi endif SUBDIRS = \ diff --git a/hw/kdrive/ati/Makefile.am b/hw/kdrive/ati/Makefile.am new file mode 100644 index 000000000..f07e74095 --- /dev/null +++ b/hw/kdrive/ati/Makefile.am @@ -0,0 +1,29 @@ +INCLUDES = \ + @KDRIVE_INCS@ \ + -I$(top_srcdir)/hw/kdrive/vesa \ + @XSERVER_CFLAGS@ + +bin_PROGRAMS = Xati + +if TSLIB +TSLIB_FLAG = -lts +endif + +noinst_LIBRARIES = libati.a + +libati_a_SOURCES = \ + ati_draw.c \ + ati.c \ + ati.h \ + ati_reg.h + +Xati_SOURCES = \ + ati_stub.c + +Xati_LDADD = \ + libati.a \ + $(top_builddir)/hw/kdrive/vesa/libvesa.a \ + @KDRIVE_LIBS@ \ + @XSERVER_LIBS@ \ + $(TSLIB_FLAG) + diff --git a/hw/kdrive/ati/ati.c b/hw/kdrive/ati/ati.c new file mode 100644 index 000000000..17e9e5871 --- /dev/null +++ b/hw/kdrive/ati/ati.c @@ -0,0 +1,285 @@ +/* + * $Id$ + * + * Copyright © 2003 Eric Anholt + * + * 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 Eric Anholt not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Eric Anholt makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * ERIC ANHOLT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL ERIC ANHOLT 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 +#endif +#include "ati.h" + +struct pci_id_list radeon_id_list[] = { + {0x1002, 0x4136, "ATI Radeon RS100"}, + {0x1002, 0x4137, "ATI Radeon RS200"}, + {0x1002, 0x4237, "ATI Radeon RS250"}, + {0x1002, 0x4144, "ATI Radeon R300 AD"}, + {0x1002, 0x4145, "ATI Radeon R300 AE"}, + {0x1002, 0x4146, "ATI Radeon R300 AF"}, + {0x1002, 0x4147, "ATI Radeon R300 AG"}, + {0x1002, 0x4148, "ATI Radeon R350 AH"}, + {0x1002, 0x4149, "ATI Radeon R350 AI"}, + {0x1002, 0x414a, "ATI Radeon R350 AJ"}, + {0x1002, 0x414b, "ATI Radeon R350 AK"}, + {0x1002, 0x4150, "ATI Radeon RV350 AP"}, + {0x1002, 0x4151, "ATI Radeon RV350 AQ"}, + {0x1002, 0x4152, "ATI Radeon RV350 AR"}, + {0x1002, 0x4153, "ATI Radeon RV350 AS"}, + {0x1002, 0x4154, "ATI Radeon RV350 AT"}, + {0x1002, 0x4156, "ATI Radeon RV350 AV"}, + {0x1002, 0x4242, "ATI Radeon R200 BB"}, + {0x1002, 0x4243, "ATI Radeon R200 BC"}, + {0x1002, 0x4336, "ATI Radeon RS100"}, + {0x1002, 0x4337, "ATI Radeon RS200"}, + {0x1002, 0x4437, "ATI Radeon RS250"}, + {0x1002, 0x4c57, "ATI Radeon RV200 LW"}, + {0x1002, 0x4c58, "ATI Radeon RV200 LX"}, + {0x1002, 0x4c59, "ATI Radeon Mobility M6 LY"}, + {0x1002, 0x4c5a, "ATI Radeon Mobility LZ"}, + {0x1002, 0x4e44, "ATI Radeon R300 ND"}, + {0x1002, 0x4e45, "ATI Radeon R300 NE"}, + {0x1002, 0x4e46, "ATI Radeon R300 NF"}, + {0x1002, 0x4e47, "ATI Radeon R300 NG"}, + {0x1002, 0x4e48, "ATI Radeon R350 NH"}, + {0x1002, 0x4e49, "ATI Radeon R350 NI"}, + {0x1002, 0x4e4a, "ATI Radeon R350 NJ"}, + {0x1002, 0x4e4b, "ATI Radeon R350 NK"}, + {0x1002, 0x4e50, "ATI Radeon Mobility RV350 NP"}, + {0x1002, 0x4e51, "ATI Radeon Mobility RV350 NQ"}, + {0x1002, 0x4e52, "ATI Radeon Mobility RV350 NR"}, + {0x1002, 0x4e53, "ATI Radeon Mobility RV350 NS"}, + {0x1002, 0x4e54, "ATI Radeon Mobility RV350 NT"}, + {0x1002, 0x4e56, "ATI Radeon Mobility RV350 NV"}, + {0x1002, 0x5144, "ATI Radeon QD"}, + {0x1002, 0x5148, "ATI Radeon R200 QH"}, + {0x1002, 0x514c, "ATI Radeon R200 QL"}, + {0x1002, 0x514d, "ATI Radeon R200 QM"}, + {0x1002, 0x5157, "ATI Radeon RV200 QW"}, + {0x1002, 0x5158, "ATI Radeon RV200 QX"}, + {0x1002, 0x5159, "ATI Radeon RV100 QY"}, + {0x1002, 0x515a, "ATI Radeon RV100 QZ"}, + {0x1002, 0x5834, "ATI Radeon RS300"}, + {0x1002, 0x5835, "ATI Radeon Mobility RS300"}, + {0x1002, 0x5c60, "ATI Radeon RV280"}, + {0x1002, 0x5c61, "ATI Mobility Radeon RV280"}, + {0x1002, 0x5c62, "ATI Radeon RV280"}, + {0x1002, 0x5c63, "ATI Mobility Radeon RV280"}, + {0x1002, 0x5c64, "ATI Radeon RV280"}, + {0, 0, NULL} +}; + +struct pci_id_list r128_id_list[] = { + {0x1002, 0x4c46, "ATI Rage 128"}, + {0x1002, 0x5046, "ATI Rage 128"}, + {0, 0, NULL} +}; + +static Bool +ATICardInit(KdCardInfo *card) +{ + ATICardInfo *atic; + int i; + + atic = xalloc(sizeof(ATICardInfo)); + if (atic == NULL) + return FALSE; + + ATIMapReg(card, atic); + + if (!vesaInitialize(card, &atic->vesa)) + { + xfree(atic); + return FALSE; + } + + card->driver = atic; + + for (i = 0; radeon_id_list[i].name != NULL; i++) { + if (radeon_id_list[i].device == card->attr.deviceID) + atic->is_radeon = TRUE; + } + return TRUE; +} + +static void +ATICardFini(KdCardInfo *card) +{ + ATICardInfo *atic = (ATICardInfo *)card->driver; + + ATIUnmapReg(card, atic); + vesaCardFini(card); +} + +static Bool +ATIScreenInit(KdScreenInfo *screen) +{ + ATIScreenInfo *atis; + int screen_size, memory; + + atis = xalloc(sizeof(ATIScreenInfo)); + if (atis == NULL) + return FALSE; + memset(atis, '\0', sizeof(ATIScreenInfo)); + + if (!vesaScreenInitialize(screen, &atis->vesa)) + { + 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; +} + +static void +ATIScreenFini(KdScreenInfo *screen) +{ + ATIScreenInfo *atis = (ATIScreenInfo *)screen->driver; + + vesaScreenFini(screen); + xfree(atis); + screen->driver = 0; +} + +Bool +ATIMapReg(KdCardInfo *card, ATICardInfo *atic) +{ + atic->reg_base = (CARD8 *)KdMapDevice(RADEON_REG_BASE(card), + RADEON_REG_SIZE(card)); + + if (atic->reg_base == NULL) + return FALSE; + + KdSetMappedMode(RADEON_REG_BASE(card), RADEON_REG_SIZE(card), + KD_MAPPED_MODE_REGISTERS); + + return TRUE; +} + +void +ATIUnmapReg(KdCardInfo *card, ATICardInfo *atic) +{ + if (atic->reg_base) { + KdResetMappedMode(RADEON_REG_BASE(card), RADEON_REG_SIZE(card), + KD_MAPPED_MODE_REGISTERS); + KdUnmapDevice((void *)atic->reg_base, RADEON_REG_SIZE(card)); + atic->reg_base = 0; + } +} + +void +ATISetMMIO(KdCardInfo *card, ATICardInfo *atic) +{ + if (atic->reg_base == NULL) + ATIMapReg(card, atic); +} + +void +ATIResetMMIO(KdCardInfo *card, ATICardInfo *atic) +{ + ATIUnmapReg(card, atic); +} + + +static Bool +ATIDPMS(ScreenPtr pScreen, int mode) +{ + /* XXX */ + return TRUE; +} + +static Bool +ATIEnable(ScreenPtr pScreen) +{ + KdScreenPriv(pScreen); + ATICardInfo(pScreenPriv); + + if (!vesaEnable(pScreen)) + return FALSE; + + ATISetMMIO(pScreenPriv->card, atic); + ATIDPMS(pScreen, KD_DPMS_NORMAL); + + return TRUE; +} + +static void +ATIDisable(ScreenPtr pScreen) +{ + KdScreenPriv(pScreen); + ATICardInfo(pScreenPriv); + + ATIResetMMIO(pScreenPriv->card, atic); + vesaDisable(pScreen); +} + +static void +ATIRestore(KdCardInfo *card) +{ + ATICardInfo *atic = card->driver; + + ATIResetMMIO(card, atic); + vesaRestore(card); +} + +KdCardFuncs ATIFuncs = { + ATICardInit, /* cardinit */ + ATIScreenInit, /* scrinit */ + vesaInitScreen, /* initScreen */ + vesaFinishInitScreen, /* finishInitScreen */ + vesaCreateResources, /* createRes */ + vesaPreserve, /* preserve */ + ATIEnable, /* enable */ + ATIDPMS, /* dpms */ + ATIDisable, /* disable */ + ATIRestore, /* restore */ + ATIScreenFini, /* scrfini */ + ATICardFini, /* cardfini */ + + 0, /* initCursor */ + 0, /* enableCursor */ + 0, /* disableCursor */ + 0, /* finiCursor */ + 0, /* recolorCursor */ + + ATIDrawInit, /* initAccel */ + ATIDrawEnable, /* enableAccel */ + ATIDrawSync, /* syncAccel */ + ATIDrawDisable, /* disableAccel */ + ATIDrawFini, /* finiAccel */ + + vesaGetColors, /* getColors */ + vesaPutColors, /* putColors */ +}; + diff --git a/hw/kdrive/ati/ati.h b/hw/kdrive/ati/ati.h new file mode 100644 index 000000000..80ee26442 --- /dev/null +++ b/hw/kdrive/ati/ati.h @@ -0,0 +1,101 @@ +/* + * $Id$ + * + * Copyright © 2003 Eric Anholt + * + * 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 Eric Anholt not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Eric Anholt makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * ERIC ANHOLT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL ERIC ANHOLT 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$ */ + +#ifndef _ATI_H_ +#define _ATI_H_ +#include + +#define RADEON_REG_BASE(c) ((c)->attr.address[1]) +#define RADEON_REG_SIZE(c) (0x10000) + +#define MMIO_OUT32(mmio, a, v) (*(VOL32 *)((mmio) + (a)) = (v)) +#define MMIO_IN32(mmio, a) (*(VOL32 *)((mmio) + (a))) + +typedef volatile CARD8 VOL8; +typedef volatile CARD16 VOL16; +typedef volatile CARD32 VOL32; + +struct pci_id_list { + CARD16 vendor; + CARD16 device; + char *name; +}; + +typedef struct _ATICardInfo { + VesaCardPrivRec vesa; + CARD8 *reg_base; + Bool is_radeon; +} 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; + + int pitch; + int datatype; + int dp_gui_master_cntl; +} ATIScreenInfo; + +#define getATIScreenInfo(kd) ((ATIScreenInfo *) ((kd)->screen->driver)) +#define ATIScreenInfo(kd) ATIScreenInfo *atis = getATIScreenInfo(kd) + +Bool +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); + +Bool +ATIDrawInit(ScreenPtr pScreen); + +void +ATIDrawEnable(ScreenPtr pScreen); + +void +ATIDrawSync(ScreenPtr pScreen); + +void +ATIDrawDisable(ScreenPtr pScreen); + +void +ATIDrawFini(ScreenPtr pScreen); + +extern KdCardFuncs ATIFuncs; + +#endif /* _ATI_H_ */ diff --git a/hw/kdrive/ati/ati_draw.c b/hw/kdrive/ati/ati_draw.c new file mode 100644 index 000000000..c08390ea5 --- /dev/null +++ b/hw/kdrive/ati/ati_draw.c @@ -0,0 +1,337 @@ +/* + * $Id$ + * + * Copyright © 2003 Eric Anholt + * + * 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 Eric Anholt not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Eric Anholt makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * ERIC ANHOLT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL ERIC ANHOLT 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$ */ +#include + +#ifdef HAVE_CONFIG_H +#include +#endif +#include "ati.h" +#include "ati_reg.h" + +CARD8 ATISolidRop[16] = { + /* GXclear */ 0x00, /* 0 */ + /* GXand */ 0xa0, /* src AND dst */ + /* GXandReverse */ 0x50, /* src AND NOT dst */ + /* GXcopy */ 0xf0, /* src */ + /* GXandInverted*/ 0x0a, /* NOT src AND dst */ + /* GXnoop */ 0xaa, /* dst */ + /* GXxor */ 0x5a, /* src XOR dst */ + /* GXor */ 0xfa, /* src OR dst */ + /* GXnor */ 0x05, /* NOT src AND NOT dst */ + /* GXequiv */ 0xa5, /* NOT src XOR dst */ + /* GXinvert */ 0x55, /* NOT dst */ + /* GXorReverse */ 0xf5, /* src OR NOT dst */ + /* GXcopyInverted*/ 0x0f, /* NOT src */ + /* GXorInverted */ 0xaf, /* NOT src OR dst */ + /* GXnand */ 0x5f, /* NOT src OR NOT dst */ + /* GXset */ 0xff, /* 1 */ +}; + +CARD8 ATIBltRop[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 */ + /* GXorInverted */ 0xbb, /* NOT src OR dst */ + /* GXnand */ 0x77, /* NOT src OR NOT dst */ + /* GXset */ 0xff, /* 1 */ +}; + +int copydx, copydy; +int is_radeon; +int fifo_size; +char *mmio; +CARD32 bltCmd; + +static void +ATIWaitAvail(int n) +{ + if (fifo_size >= n) { + fifo_size -= n; + return; + } + if (is_radeon) { + fifo_size = MMIO_IN32(mmio, RADEON_REG_RBBM_STATUS) & + RADEON_RBBM_FIFOCNT_MASK; + while (fifo_size < n) { + usleep(1); + fifo_size = MMIO_IN32(mmio, RADEON_REG_RBBM_STATUS) & + RADEON_RBBM_FIFOCNT_MASK; + } + } else { + fifo_size = MMIO_IN32(mmio, R128_REG_GUI_STAT) & 0xfff; + while (fifo_size < n) { + fifo_size = MMIO_IN32(mmio, R128_REG_GUI_STAT) & 0xfff; + usleep(1); + } + } + fifo_size -= n; +} + +static void +RadeonWaitIdle(void) +{ + CARD32 temp; + /* Wait for the engine to go idle */ + ATIWaitAvail(64); + + while ((MMIO_IN32(mmio, RADEON_REG_RBBM_STATUS) & + RADEON_RBBM_ACTIVE) != 0) + usleep(1); + + /* Flush pixel cache */ + temp = MMIO_IN32(mmio, RADEON_REG_RB2D_DSTCACHE_CTLSTAT); + temp |= RADEON_RB2D_DC_FLUSH_ALL; + MMIO_OUT32(mmio, RADEON_REG_RB2D_DSTCACHE_CTLSTAT, temp); + + while ((MMIO_IN32(mmio, RADEON_REG_RB2D_DSTCACHE_CTLSTAT) & + RADEON_RB2D_DC_BUSY) != 0) + usleep(1); +} + +static void +R128WaitIdle(void) +{ + CARD32 temp; + int tries; + + ATIWaitAvail(64); + + tries = 1000000; + while (tries--) { + if ((MMIO_IN32(mmio, R128_REG_GUI_STAT) & R128_GUI_ACTIVE) == 0) + break; + } + + temp = MMIO_IN32(mmio, R128_REG_PC_NGUI_CTLSTAT); + MMIO_OUT32(mmio, R128_REG_PC_NGUI_CTLSTAT, temp | 0xff); + + tries = 1000000; + while (tries--) { + if ((MMIO_IN32(mmio, R128_REG_PC_NGUI_CTLSTAT) & R128_PC_BUSY) != + R128_PC_BUSY) + break; + } +} + +static void +ATIWaitIdle(void) +{ + if (is_radeon) + RadeonWaitIdle(); + else + R128WaitIdle(); +} + +static void +ATISetup(ScreenPtr pScreen) +{ + KdScreenPriv(pScreen); + ATICardInfo(pScreenPriv); + ATIScreenInfo(pScreenPriv); + + mmio = atic->reg_base; + + ATIWaitAvail(5); + if (is_radeon) { + MMIO_OUT32(mmio, RADEON_REG_DEFAULT_OFFSET, atis->pitch << 16); + } else { + MMIO_OUT32(mmio, RADEON_REG_DEFAULT_OFFSET, 0); + MMIO_OUT32(mmio, RADEON_REG_DEFAULT_PITCH, + pScreenPriv->screen->width >> 3); + } + MMIO_OUT32(mmio, RADEON_REG_DEFAULT_SC_BOTTOM_RIGHT, + (RADEON_DEFAULT_SC_RIGHT_MAX | RADEON_DEFAULT_SC_BOTTOM_MAX)); + MMIO_OUT32(mmio, RADEON_REG_SC_TOP_LEFT, 0); + MMIO_OUT32(mmio, RADEON_REG_SC_BOTTOM_RIGHT, + RADEON_DEFAULT_SC_RIGHT_MAX | RADEON_DEFAULT_SC_BOTTOM_MAX); +} + +static Bool +ATIPrepareSolid(PixmapPtr pPixmap, int alu, Pixel pm, Pixel fg) +{ + KdScreenPriv(pPixmap->drawable.pScreen); + ATIScreenInfo(pScreenPriv); + + ATISetup(pPixmap->drawable.pScreen); + + ATIWaitAvail(4); + MMIO_OUT32(mmio, RADEON_REG_DP_GUI_MASTER_CNTL, + atis->dp_gui_master_cntl | RADEON_GMC_BRUSH_SOLID_COLOR | + RADEON_GMC_SRC_DATATYPE_COLOR | (ATISolidRop[alu] << 16)); + MMIO_OUT32(mmio, RADEON_REG_DP_BRUSH_FRGD_CLR, fg); + MMIO_OUT32(mmio, RADEON_REG_DP_WRITE_MASK, pm); + MMIO_OUT32(mmio, RADEON_REG_DP_CNTL, RADEON_DST_X_LEFT_TO_RIGHT | + RADEON_DST_Y_TOP_TO_BOTTOM); + + return TRUE; +} + +static void +ATISolid(int x1, int y1, int x2, int y2) +{ + ATIWaitAvail(2); + MMIO_OUT32(mmio, RADEON_REG_DST_Y_X, (y1 << 16) | x1); + MMIO_OUT32(mmio, RADEON_REG_DST_WIDTH_HEIGHT, ((x2 - x1) << 16) | + (y2 - y1)); +} + +static void +ATIDoneSolid(void) +{ +} + +static Bool +ATIPrepareCopy(PixmapPtr pSrc, PixmapPtr pDst, int dx, int dy, int alu, Pixel pm) +{ + KdScreenPriv(pDst->drawable.pScreen); + ATIScreenInfo(pScreenPriv); + + copydx = dx; + copydy = dy; + + ATIWaitAvail(3); + MMIO_OUT32(mmio, RADEON_REG_DP_GUI_MASTER_CNTL, + atis->dp_gui_master_cntl | RADEON_GMC_BRUSH_SOLID_COLOR | + RADEON_GMC_SRC_DATATYPE_COLOR | (ATIBltRop[alu] << 16) | + RADEON_DP_SRC_SOURCE_MEMORY); + MMIO_OUT32(mmio, RADEON_REG_DP_WRITE_MASK, pm); + MMIO_OUT32(mmio, RADEON_REG_DP_CNTL, + (dx >= 0 ? RADEON_DST_X_LEFT_TO_RIGHT : 0) | + (dy >= 0 ? RADEON_DST_Y_TOP_TO_BOTTOM : 0)); + + return TRUE; +} + +static void +ATICopy(int srcX, int srcY, int dstX, int dstY, int w, int h) +{ + if (copydx < 0) { + srcX += w - 1; + dstX += w - 1; + } + + if (copydy < 0) { + srcY += h - 1; + dstY += h - 1; + } + + ATIWaitAvail(3); + MMIO_OUT32(mmio, RADEON_REG_SRC_Y_X, (srcY << 16) | srcX); + MMIO_OUT32(mmio, RADEON_REG_DST_Y_X, (dstY << 16) | dstX); + MMIO_OUT32(mmio, RADEON_REG_DST_HEIGHT_WIDTH, (h << 16) | w); +} + +static void +ATIDoneCopy(void) +{ +} + +KaaScreenInfoRec ATIKaa = { + ATIPrepareSolid, + ATISolid, + ATIDoneSolid, + + ATIPrepareCopy, + ATICopy, + ATIDoneCopy, +}; + +Bool +ATIDrawInit(ScreenPtr pScreen) +{ + if (!kaaDrawInit(pScreen, &ATIKaa)) + return FALSE; + + return TRUE; +} + +void +ATIDrawEnable(ScreenPtr pScreen) +{ + KdScreenPriv(pScreen); + ATIScreenInfo(pScreenPriv); + ATICardInfo(pScreenPriv); + + is_radeon = atic->is_radeon; + atis->pitch = pScreenPriv->screen->width * + pScreenPriv->screen->fb[0].bitsPerPixel/8; + + /*ErrorF("depth=%d pitch=%d radeon=%d\n", + pScreenPriv->screen->fb[0].depth, atis->pitch, is_radeon);*/ + switch (pScreenPriv->screen->fb[0].depth) + { + case 8: + atis->datatype = 2; + break; + case 15: + atis->datatype = 3; + break; + case 16: + atis->datatype = 4; + break; + case 24: + atis->datatype = 5; + break; + case 32: + atis->datatype = 6; + break; + default: + ErrorF("Bad depth %d\n", pScreenPriv->screen->fb[0].depth); + } + atis->dp_gui_master_cntl = (atis->datatype << 8) | + RADEON_GMC_CLR_CMP_CNTL_DIS | RADEON_GMC_AUX_CLIP_DIS; + KdMarkSync(pScreen); +} + +void +ATIDrawDisable(ScreenPtr pScreen) +{ +} + +void +ATIDrawFini(ScreenPtr pScreen) +{ +} + +void +ATIDrawSync(ScreenPtr pScreen) +{ + KdScreenPriv(pScreen); + ATICardInfo(pScreenPriv); + + mmio = atic->reg_base; + + ATIWaitIdle(); +} diff --git a/hw/kdrive/ati/ati_reg.h b/hw/kdrive/ati/ati_reg.h new file mode 100644 index 000000000..6a8d3e309 --- /dev/null +++ b/hw/kdrive/ati/ati_reg.h @@ -0,0 +1,63 @@ +/* + * $Id$ + * + * Copyright © 2003 Eric Anholt + * + * 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 Eric Anholt not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Eric Anholt makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * ERIC ANHOLT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL ERIC ANHOLT 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$ */ + +/* The Radeon register definitions are almost all the same for r128 */ +#define RADEON_REG_RBBM_STATUS 0x0e40 +# define RADEON_RBBM_FIFOCNT_MASK 0x007f +# define RADEON_RBBM_ACTIVE (1 << 31) +#define RADEON_REG_SRC_Y_X 0x1434 +#define RADEON_REG_DST_Y_X 0x1438 +#define RADEON_REG_DST_HEIGHT_WIDTH 0x143c +#define RADEON_REG_DP_GUI_MASTER_CNTL 0x146c +#define RADEON_REG_DP_BRUSH_FRGD_CLR 0x147c +# define RADEON_GMC_BRUSH_SOLID_COLOR (13 << 4) +# define RADEON_GMC_BRUSH_NONE (15 << 4) +# define RADEON_GMC_SRC_DATATYPE_COLOR (3 << 12) +# define RADEON_DP_SRC_SOURCE_MEMORY (2 << 24) +# define RADEON_GMC_CLR_CMP_CNTL_DIS (1 << 28) +# define RADEON_GMC_AUX_CLIP_DIS (1 << 29) +#define RADEON_REG_DP_CNTL 0x16c0 +# define RADEON_DST_X_LEFT_TO_RIGHT (1 << 0) +# define RADEON_DST_Y_TOP_TO_BOTTOM (1 << 1) +#define RADEON_REG_DST_WIDTH_HEIGHT 0x1598 +#define RADEON_REG_AUX_SC_CNTL 0x1660 +#define RADEON_REG_DP_WRITE_MASK 0x16cc +#define RADEON_REG_DEFAULT_OFFSET 0x16e0 +#define RADEON_REG_DEFAULT_PITCH 0x16e4 +#define RADEON_REG_DEFAULT_SC_BOTTOM_RIGHT 0x16e8 +# define RADEON_DEFAULT_SC_RIGHT_MAX (0x1fff << 0) +# define RADEON_DEFAULT_SC_BOTTOM_MAX (0x1fff << 16) +#define RADEON_REG_SC_TOP_LEFT 0x16ec +#define RADEON_REG_SC_BOTTOM_RIGHT 0x16f0 +#define RADEON_REG_RB2D_DSTCACHE_CTLSTAT 0x342c +# define RADEON_RB2D_DC_FLUSH (3 << 0) +# define RADEON_RB2D_DC_FREE (3 << 2) +# define RADEON_RB2D_DC_FLUSH_ALL 0xf +# define RADEON_RB2D_DC_BUSY (1 << 31) + +#define R128_REG_PC_NGUI_CTLSTAT 0x0184 +# define R128_PC_BUSY (1 << 31) +#define R128_REG_GUI_STAT 0x1740 +# define R128_GUI_ACTIVE (1 << 31) diff --git a/hw/kdrive/ati/ati_stub.c b/hw/kdrive/ati/ati_stub.c new file mode 100644 index 000000000..9b342feff --- /dev/null +++ b/hw/kdrive/ati/ati_stub.c @@ -0,0 +1,87 @@ +/* + * $Id$ + * + * Copyright © 2003 Eric Anholt + * + * 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 Eric Anholt not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Eric Anholt makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * ERIC ANHOLT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL ERIC ANHOLT 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 +#endif +#include "ati.h" +#include "klinux.h" + +extern struct pci_id_list radeon_id_list[]; +extern struct pci_id_list r128_id_list[]; + +void +InitCard(char *name) +{ + KdCardAttr attr; + int i, j; + + for (i = 0; radeon_id_list[i].name != NULL; i++) { + CARD16 vendor = radeon_id_list[i].vendor; + CARD16 device = radeon_id_list[i].device; + + j = 0; + while (LinuxFindPci(vendor, device, j++, &attr)) + KdCardInfoAdd(&ATIFuncs, &attr, 0); + } + + for (i = 0; r128_id_list[i].name != NULL; i++) { + CARD16 vendor = r128_id_list[i].vendor; + CARD16 device = r128_id_list[i].device; + + j = 0; + while (LinuxFindPci(vendor, device, j++, &attr)) + KdCardInfoAdd(&ATIFuncs, &attr, 0); + } +} + +void +InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) +{ + KdInitOutput(pScreenInfo, argc, argv); +} + +void +InitInput(int argc, char **argv) +{ + KdInitInput(&LinuxMouseFuncs, &LinuxKeyboardFuncs); +} + +void +ddxUseMsg (void) +{ + KdUseMsg(); + vesaUseMsg(); +} + +int +ddxProcessArgument(int argc, char **argv, int i) +{ + int ret; + + if (!(ret = vesaProcessArgument (argc, argv, i))) + ret = KdProcessArgument(argc, argv, i); + return ret; +} diff --git a/hw/kdrive/linux/linux.c b/hw/kdrive/linux/linux.c index 555102925..dadcee11f 100644 --- a/hw/kdrive/linux/linux.c +++ b/hw/kdrive/linux/linux.c @@ -138,6 +138,8 @@ LinuxFindPci (CARD16 vendor, CARD16 device, CARD32 count, KdCardAttr *attr) Bool ret = FALSE; int i; + attr->vendorID = vendor; + attr->deviceID = device; ven_dev = (((CARD32) vendor) << 16) | ((CARD32) device); f = fopen ("/proc/bus/pci/devices", "r"); if (!f) @@ -159,7 +161,7 @@ LinuxFindPci (CARD16 vendor, CARD16 device, CARD32 count, KdCardAttr *attr) continue; if (count--) continue; - (void) strtoul (l, &end, 16); + (void) strtoul (l, &end, 16); /* IRQ */ if (end == l) continue; l = end; @@ -186,7 +188,10 @@ LinuxFindPci (CARD16 vendor, CARD16 device, CARD32 count, KdCardAttr *attr) n--; } attr->naddr = n; - attr->bus = bus; + attr->domain = 0; /* XXX */ + attr->bus = (bus >> 8) & 0xff; + attr->slot = (bus >> 3) & 0x1f; + attr->func = bus & 0x07; ret = TRUE; break; } diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h index 77b675912..557972351 100644 --- a/hw/kdrive/src/kdrive.h +++ b/hw/kdrive/src/kdrive.h @@ -68,7 +68,14 @@ typedef struct _KdCardAttr { CARD32 io; CARD32 address[KD_MAX_CARD_ADDRESS]; int naddr; - int bus; + + /* PCI bus info */ + CARD16 vendorID; + CARD16 deviceID; + CARD8 domain; + CARD8 bus; + CARD8 slot; + CARD8 func; } KdCardAttr; typedef struct _KdCardInfo {