Module Name: xsrc Committed By: macallan Date: Mon Oct 21 13:40:53 UTC 2024
Modified Files: xsrc/external/mit/xf86-video-ngle/dist/src: ngle.h ngle_driver.c Added Files: xsrc/external/mit/xf86-video-ngle/dist/src: ngle_accel.c Log Message: add acceleration, Visualize EG only for now To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 xsrc/external/mit/xf86-video-ngle/dist/src/ngle.h \ xsrc/external/mit/xf86-video-ngle/dist/src/ngle_driver.c cvs rdiff -u -r0 -r1.1 \ xsrc/external/mit/xf86-video-ngle/dist/src/ngle_accel.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: xsrc/external/mit/xf86-video-ngle/dist/src/ngle.h diff -u xsrc/external/mit/xf86-video-ngle/dist/src/ngle.h:1.1 xsrc/external/mit/xf86-video-ngle/dist/src/ngle.h:1.2 --- xsrc/external/mit/xf86-video-ngle/dist/src/ngle.h:1.1 Wed Oct 16 11:00:36 2024 +++ xsrc/external/mit/xf86-video-ngle/dist/src/ngle.h Mon Oct 21 13:40:53 2024 @@ -34,12 +34,13 @@ #include <sys/time.h> #include <dev/wscons/wsconsio.h> -#include "xorgVersion.h" - +#include "xorg-server.h" #include "xf86.h" #include "xf86_OSproc.h" +#include "compiler.h" +#include "xorgVersion.h" #include "xf86Cursor.h" - +#include "exa.h" #include "compat-api.h" #ifndef NGLE_H @@ -56,15 +57,21 @@ typedef struct { CloseScreenProcPtr CloseScreen; CreateScreenResourcesProcPtr CreateScreenResources; EntityInfoPtr pEnt; - struct wsdisplay_cursor cursor; int maskoffset; xf86CursorInfoPtr CursorInfoRec; OptionInfoPtr Options; + ExaDriverPtr pExa; + uint32_t gid, buf, fbacc; + int offset, hwmode; +#define HW_FB 0 +#define HW_FILL 1 +#define HW_BLIT 2 } NGLERec, *NGLEPtr; #define NGLEPTR(p) ((NGLEPtr)((p)->driverPrivate)) Bool NGLESetupCursor(ScreenPtr); +Bool NGLEInitAccel(ScreenPtr); #endif Index: xsrc/external/mit/xf86-video-ngle/dist/src/ngle_driver.c diff -u xsrc/external/mit/xf86-video-ngle/dist/src/ngle_driver.c:1.1 xsrc/external/mit/xf86-video-ngle/dist/src/ngle_driver.c:1.2 --- xsrc/external/mit/xf86-video-ngle/dist/src/ngle_driver.c:1.1 Wed Oct 16 11:00:36 2024 +++ xsrc/external/mit/xf86-video-ngle/dist/src/ngle_driver.c Mon Oct 21 13:40:53 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: ngle_driver.c,v 1.1 2024/10/16 11:00:36 macallan Exp $ */ +/* $NetBSD: ngle_driver.c,v 1.2 2024/10/21 13:40:53 macallan Exp $ */ /* * Copyright (c) 2024 Michael Lorenz * All rights reserved. @@ -330,7 +330,7 @@ static Bool NGLEPreInit(ScrnInfoPtr pScrn, int flags) { NGLEPtr fPtr; - int default_depth, bitsperpixel, wstype; + int default_depth, bitsperpixel, gid; const char *dev; char *mod = NULL; const char *reqSym = NULL; @@ -362,13 +362,26 @@ NGLEPreInit(ScrnInfoPtr pScrn, int flags strerror(errno)); return FALSE; } - if (ioctl(fPtr->fd, WSDISPLAYIO_GTYPE, &wstype) == -1) { - xf86DrvMsg(pScrn->scrnIndex, X_ERROR, - "ioctl WSDISPLAY_GTYPE: %s\n", - strerror(errno)); + + if (ioctl(fPtr->fd, GCID, &gid) == -1) return FALSE; + + fPtr->gid = gid; + fPtr->fbacc = 0; + + switch (gid) { + case STI_DD_EG: + fPtr->buf = BINapp1I; + fPtr->fbacc = BA(IndexedDcd, Otc04, Ots08, AddrByte, 0, fPtr->buf, 0); + break; + case STI_DD_HCRX: + /* XXX BINovly if in 8 bit */ + fPtr->buf = BINapp0F8; + fPtr->fbacc = BA(IndexedDcd, Otc04, Ots08, AddrLong, 0, fPtr->buf, 0); + break; } - + xf86Msg(X_ERROR, "gid %08x fb access %08x\n", fPtr->gid, fPtr->fbacc); + /* Handle depth */ default_depth = fPtr->fbi.fbi_bitsperpixel <= 24 ? fPtr->fbi.fbi_bitsperpixel : 24; bitsperpixel = fPtr->fbi.fbi_bitsperpixel == 15 ? 16 : fPtr->fbi.fbi_bitsperpixel; @@ -504,7 +517,7 @@ NGLEScreenInit(SCREEN_INIT_ARGS_DECL) strerror(errno)); return FALSE; } - fPtr->regs = ngle_mmap(0x40000, 0x80000000, fPtr->fd, 0); + fPtr->regs = ngle_mmap(0x400000, 0x80000000, fPtr->fd, 0); if (fPtr->regs == NULL) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, @@ -567,8 +580,8 @@ NGLEScreenInit(SCREEN_INIT_ARGS_DECL) xf86SetBackingStore(pScreen); if (fPtr) { - /* init accel here */ - //xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Using acceleration\n"); + NGLEInitAccel(pScreen); + xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Using acceleration\n"); } /* software cursor */ Added files: Index: xsrc/external/mit/xf86-video-ngle/dist/src/ngle_accel.c diff -u /dev/null xsrc/external/mit/xf86-video-ngle/dist/src/ngle_accel.c:1.1 --- /dev/null Mon Oct 21 13:40:53 2024 +++ xsrc/external/mit/xf86-video-ngle/dist/src/ngle_accel.c Mon Oct 21 13:40:53 2024 @@ -0,0 +1,301 @@ +/* + * NGLE - hardware acceleration. + * + * Copyright (C) 2024 Michael Lorenz + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * MICHAEL LORENZ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* $NetBSD: ngle_accel.c,v 1.1 2024/10/21 13:40:53 macallan Exp $ */ + +#include <sys/types.h> +#include <dev/ic/stireg.h> + + +#include "ngle.h" + +//#define DEBUG + +#ifdef DEBUG +#define ENTER xf86Msg(X_ERROR, "%s\n", __func__) +#define LEAVE xf86Msg(X_ERROR, "%s done\n", __func__) +#define DBGMSG xf86Msg +#else +#define ENTER +#define DBGMSG if (0) xf86Msg +#define LEAVE +#endif + +static inline void +NGLEWrite4(NGLEPtr fPtr, int offset, uint32_t val) +{ + volatile uint32_t *ptr = (uint32_t *)((uint8_t *)fPtr->regs + offset); + *ptr = val; +} + +static inline void +NGLEWrite1(NGLEPtr fPtr, int offset, uint8_t val) +{ + volatile uint8_t *ptr = (uint8_t *)fPtr->regs + offset; + *ptr = val; +} + +static inline uint32_t +NGLERead4(NGLEPtr fPtr, int offset) +{ + volatile uint32_t *ptr = (uint32_t *)((uint8_t *)fPtr->regs + offset); + return *ptr; +} + +static inline uint8_t +NGLERead1(NGLEPtr fPtr, int offset) +{ + volatile uint8_t *ptr = (uint8_t *)fPtr->regs + offset; + return *ptr; +} + +static void +NGLEWaitMarker(ScreenPtr pScreen, int Marker) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + NGLEPtr fPtr = NGLEPTR(pScrn); + uint8_t stat; + + ENTER; + do { + stat = NGLERead1(fPtr, NGLE_REG_15b0); + if (stat == 0) + stat = NGLERead1(fPtr, NGLE_REG_15b0); + } while (stat != 0); + LEAVE; +} + +static void +NGLEWaitFifo(NGLEPtr fPtr, int slots) +{ + uint32_t reg; + + ENTER; + do { + reg = NGLERead4(fPtr, NGLE_REG_34); + } while (reg < slots); + LEAVE; +} + +static Bool +NGLEPrepareCopy +( + PixmapPtr pSrcPixmap, + PixmapPtr pDstPixmap, + int xdir, + int ydir, + int alu, + Pixel planemask +) +{ + ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; + NGLEPtr fPtr = NGLEPTR(pScrn); + int srcpitch = exaGetPixmapPitch(pSrcPixmap); + int srcoff = exaGetPixmapOffset(pSrcPixmap); + + ENTER; + + DBGMSG(X_ERROR, "%s %d %d\n", __func__, srcoff, srcpitch); + fPtr->offset = srcoff / srcpitch; + NGLEWaitMarker(pDstPixmap->drawable.pScreen, 0); + /* XXX HCRX needs ifferent values here */ + NGLEWrite4(fPtr, NGLE_REG_10, + BA(IndexedDcd, Otc04, Ots08, AddrLong, 0, BINapp0I, 0)); + NGLEWrite4(fPtr, NGLE_REG_14, ((alu << 8) & 0xf00) | 0x23000000); + NGLEWrite4(fPtr, NGLE_REG_13, planemask); + + fPtr->hwmode = HW_BLIT; + + LEAVE; + return TRUE; +} + +static void +NGLECopy +( + PixmapPtr pDstPixmap, + int xs, + int ys, + int xd, + int yd, + int wi, + int he +) +{ + ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum]; + NGLEPtr fPtr = NGLEPTR(pScrn); + int dstpitch = exaGetPixmapPitch(pDstPixmap); + int dstoff = exaGetPixmapOffset(pDstPixmap); + + ENTER; + NGLEWaitFifo(fPtr, 3); + NGLEWrite4(fPtr, NGLE_REG_24, (xs << 16) | (ys + fPtr->offset)); + NGLEWrite4(fPtr, NGLE_REG_7, (wi << 16) | he); + NGLEWrite4(fPtr, NGLE_REG_25, (xd << 16) | (yd + (dstoff / dstpitch))); + + exaMarkSync(pDstPixmap->drawable.pScreen); + LEAVE; +} + +static void +NGLEDoneCopy(PixmapPtr pDstPixmap) +{ + ENTER; + LEAVE; +} + +static Bool +NGLEPrepareSolid( + PixmapPtr pPixmap, + int alu, + Pixel planemask, + Pixel fg) +{ + ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; + NGLEPtr fPtr = NGLEPTR(pScrn); + + ENTER; + NGLEWaitFifo(fPtr, 4); + /* plane mask */ + NGLEWrite4(fPtr, NGLE_REG_13, planemask); + /* bitmap op */ + NGLEWrite4(fPtr, NGLE_REG_14, + IBOvals(alu, 0, BitmapExtent08, 0, DataDynamic, MaskOtc, 1, 0)); + + /* XXX HCRX needs ifferent values here */ + /* dst bitmap access */ + NGLEWrite4(fPtr, NGLE_REG_11, + BA(IndexedDcd, Otc32, OtsIndirect, AddrLong, 0, BINapp0I, 0)); + NGLEWrite4(fPtr, NGLE_REG_35, fg); + fPtr->hwmode = HW_FILL; + + LEAVE; + return TRUE; +} + +static void +NGLESolid( + PixmapPtr pPixmap, + int x1, + int y1, + int x2, + int y2) +{ + ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; + NGLEPtr fPtr = NGLEPTR(pScrn); + int w = x2 - x1, h = y2 - y1; + int pitch = exaGetPixmapPitch(pPixmap); + int offset = exaGetPixmapOffset(pPixmap); + uint32_t mask; + int wi, rest; + + ENTER; + + y1 += offset >> 11; + + rest = w & 0x1f; + wi = w & 0xffffe0; + if (wi > 0) { + NGLEWaitFifo(fPtr, 3); + /* transfer data */ + NGLEWrite4(fPtr, NGLE_REG_8, 0xffffffff); + /* dst XY */ + NGLEWrite4(fPtr, NGLE_REG_6, (x1 << 16) | y1); + /* len XY start */ + NGLEWrite4(fPtr, NGLE_REG_9, (wi << 16) | h); + } + if (rest > 0) { + mask = 0xffffffff << (32 - w); + /* transfer data */ + NGLEWrite4(fPtr, NGLE_REG_8, mask); + /* dst XY */ + NGLEWrite4(fPtr, NGLE_REG_6, ((x1 + wi) << 16) | y1); + /* len XY start */ + NGLEWrite4(fPtr, NGLE_REG_9, (rest << 16) | h); + } + exaMarkSync(pPixmap->drawable.pScreen); + LEAVE; +} + +Bool +NGLEPrepareAccess(PixmapPtr pPixmap, int index) +{ + ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum]; + NGLEPtr fPtr = NGLEPTR(pScrn); + + if (fPtr->hwmode == HW_FB) return TRUE; + + NGLEWaitMarker(pPixmap->drawable.pScreen, 0); + NGLEWrite4(fPtr, NGLE_REG_10, fPtr->fbacc); + NGLEWrite4(fPtr, NGLE_REG_14, 0x83000300); + NGLEWrite4(fPtr, NGLE_REG_13, 0xff); + NGLEWaitMarker(pPixmap->drawable.pScreen, 0); + NGLEWrite1(fPtr, NGLE_REG_16b1, 1); + fPtr->hwmode = HW_FB; + return TRUE; +} + +Bool +NGLEInitAccel(ScreenPtr pScreen) +{ + ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; + NGLEPtr fPtr = NGLEPTR(pScrn); + ExaDriverPtr pExa; + int lines, bpp = pScrn->bitsPerPixel >> 3; + + pExa = exaDriverAlloc(); + if (!pExa) + return FALSE; + + fPtr->pExa = pExa; + + pExa->exa_major = EXA_VERSION_MAJOR; + pExa->exa_minor = EXA_VERSION_MINOR; + + pExa->memoryBase = fPtr->fbmem; + lines = fPtr->fbmem_len / fPtr->fbi.fbi_stride; + DBGMSG(X_ERROR, "lines %d\n", lines); + pExa->memorySize = fPtr->fbmem_len; + pExa->offScreenBase = fPtr->fbi.fbi_stride * fPtr->fbi.fbi_height; + pExa->pixmapOffsetAlign = fPtr->fbi.fbi_stride; + pExa->pixmapPitchAlign = fPtr->fbi.fbi_stride; + + pExa->flags = EXA_OFFSCREEN_PIXMAPS | EXA_MIXED_PIXMAPS; + + pExa->maxX = 2048; + pExa->maxY = 2048; + + fPtr->hwmode = -1; + + pExa->WaitMarker = NGLEWaitMarker; + pExa->PrepareSolid = NGLEPrepareSolid; + pExa->Solid = NGLESolid; + pExa->DoneSolid = NGLEDoneCopy; + pExa->PrepareCopy = NGLEPrepareCopy; + pExa->Copy = NGLECopy; + pExa->DoneCopy = NGLEDoneCopy; + pExa->PrepareAccess = NGLEPrepareAccess; + NGLEWaitMarker(pScreen, 0); + + return exaDriverInit(pScreen, pExa); +}