Browse Source

Plan 9 from Bell Labs 2004-04-08

David du Colombier 16 years ago
parent
commit
97c8d36173
5 changed files with 985 additions and 351 deletions
  1. 3 2
      dist/replica/plan9.db
  2. 3 0
      dist/replica/plan9.log
  3. 179 0
      sys/src/9/pc/nv_dma.h
  4. 257 89
      sys/src/9/pc/vganvidia.c
  5. 543 260
      sys/src/cmd/aux/vga/nvidia.c

+ 3 - 2
dist/replica/plan9.db

@@ -5371,6 +5371,7 @@ sys/src/9/pc/mmu.c - 664 sys sys 1049509456 10014
 sys/src/9/pc/mouse.c - 664 sys sys 1065717607 6625
 sys/src/9/pc/mp.c - 664 sys sys 1048644112 16928
 sys/src/9/pc/mp.h - 664 sys sys 1015014520 6575
+sys/src/9/pc/nv_dma.h - 664 sys sys 1081384508 12943
 sys/src/9/pc/pc - 664 sys sys 1079575705 1367
 sys/src/9/pc/pcauth - 664 sys sys 1073851852 657
 sys/src/9/pc/pccd - 664 sys sys 1055090302 1302
@@ -5417,7 +5418,7 @@ sys/src/9/pc/vgamach64xx.c - 664 sys sys 1071245447 29146
 sys/src/9/pc/vgamga2164w.c - 664 sys sys 1015014527 5654
 sys/src/9/pc/vgamga4xx.c - 664 sys sys 1015014527 11122
 sys/src/9/pc/vganeomagic.c - 664 sys sys 1071245447 10719
-sys/src/9/pc/vganvidia.c - 664 sys sys 1060269772 6545
+sys/src/9/pc/vganvidia.c - 664 sys sys 1081358011 12205
 sys/src/9/pc/vgargb524.c - 664 sys sys 1015014527 4235
 sys/src/9/pc/vgas3.c - 664 sys sys 1068129423 12143
 sys/src/9/pc/vgasavage.c - 664 sys sys 1064679984 16251
@@ -7144,7 +7145,7 @@ sys/src/cmd/aux/vga/mga4xx.c - 664 sys sys 1014925010 35895
 sys/src/cmd/aux/vga/mkfile - 664 sys sys 1048636613 905
 sys/src/cmd/aux/vga/neomagic.c - 664 sys sys 1014925010 8801
 sys/src/cmd/aux/vga/notes.txt - 664 sys sys 1028334647 14376
-sys/src/cmd/aux/vga/nvidia.c - 664 sys sys 1060012272 12142
+sys/src/cmd/aux/vga/nvidia.c - 664 sys sys 1081358076 23145
 sys/src/cmd/aux/vga/palette.c - 664 sys sys 1014925010 2201
 sys/src/cmd/aux/vga/pci.c - 664 sys sys 1014925011 8659
 sys/src/cmd/aux/vga/pci.h - 664 sys sys 1014925011 3290

+ 3 - 0
dist/replica/plan9.log

@@ -14807,3 +14807,6 @@
 1081204245 0 a rc/bin/patch/applied - 775 sys sys 1081204295 110
 1081204245 1 c rc/bin/patch/list - 775 sys sys 1081204287 644
 1081204245 2 a rc/bin/patch/move - 775 sys sys 1081204288 547
+1081359072 0 c sys/src/9/pc/vganvidia.c - 664 sys sys 1081358011 12205
+1081359072 1 c sys/src/cmd/aux/vga/nvidia.c - 664 sys sys 1081358076 23145
+1081386076 0 a sys/src/9/pc/nv_dma.h - 664 sys sys 1081384508 12943

+ 179 - 0
sys/src/9/pc/nv_dma.h

@@ -0,0 +1,179 @@
+
+ /***************************************************************************\
+|*                                                                           *|
+|*       Copyright 2003 NVIDIA, Corporation.  All rights reserved.           *|
+|*                                                                           *|
+|*     NOTICE TO USER:   The source code  is copyrighted under  U.S. and     *|
+|*     international laws.  Users and possessors of this source code are     *|
+|*     hereby granted a nonexclusive,  royalty-free copyright license to     *|
+|*     use this code in individual and commercial software.                  *|
+|*                                                                           *|
+|*     Any use of this source code must include,  in the user documenta-     *|
+|*     tion and  internal comments to the code,  notices to the end user     *|
+|*     as follows:                                                           *|
+|*                                                                           *|
+|*       Copyright 2003 NVIDIA, Corporation.  All rights reserved.           *|
+|*                                                                           *|
+|*     NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY     *|
+|*     OF  THIS SOURCE  CODE  FOR ANY PURPOSE.  IT IS  PROVIDED  "AS IS"     *|
+|*     WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND.  NVIDIA, CORPOR-     *|
+|*     ATION DISCLAIMS ALL WARRANTIES  WITH REGARD  TO THIS SOURCE CODE,     *|
+|*     INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE-     *|
+|*     MENT,  AND FITNESS  FOR A PARTICULAR PURPOSE.   IN NO EVENT SHALL     *|
+|*     NVIDIA, CORPORATION  BE LIABLE FOR ANY SPECIAL,  INDIRECT,  INCI-     *|
+|*     DENTAL, OR CONSEQUENTIAL DAMAGES,  OR ANY DAMAGES  WHATSOEVER RE-     *|
+|*     SULTING 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 SOURCE CODE.     *|
+|*                                                                           *|
+|*     U.S. Government  End  Users.   This source code  is a "commercial     *|
+|*     item,"  as that  term is  defined at  48 C.F.R. 2.101 (OCT 1995),     *|
+|*     consisting  of "commercial  computer  software"  and  "commercial     *|
+|*     computer  software  documentation,"  as such  terms  are  used in     *|
+|*     48 C.F.R. 12.212 (SEPT 1995)  and is provided to the U.S. Govern-     *|
+|*     ment only as  a commercial end item.   Consistent with  48 C.F.R.     *|
+|*     12.212 and  48 C.F.R. 227.7202-1 through  227.7202-4 (JUNE 1995),     *|
+|*     all U.S. Government End Users  acquire the source code  with only     *|
+|*     those rights set forth herein.                                        *|
+|*                                                                           *|
+ \***************************************************************************/
+
+/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nv/nv_dma.h,v 1.2 2003/07/31 21:41:26 mvojkovi Exp $ */
+
+#define SURFACE_FORMAT                                              0x00000300
+#define SURFACE_FORMAT_DEPTH8                                       0x00000001
+#define SURFACE_FORMAT_DEPTH15                                      0x00000002
+#define SURFACE_FORMAT_DEPTH16                                      0x00000004
+#define SURFACE_FORMAT_DEPTH24                                      0x00000006
+#define SURFACE_PITCH                                               0x00000304
+#define SURFACE_PITCH_SRC                                           15:0
+#define SURFACE_PITCH_DST                                           31:16
+#define SURFACE_OFFSET_SRC                                          0x00000308
+#define SURFACE_OFFSET_DST                                          0x0000030C
+
+#define ROP_SET                                                     0x00002300
+
+#define PATTERN_FORMAT                                              0x00004300
+#define PATTERN_FORMAT_DEPTH8                                       0x00000003
+#define PATTERN_FORMAT_DEPTH16                                      0x00000001
+#define PATTERN_FORMAT_DEPTH24                                      0x00000003
+#define PATTERN_COLOR_0                                             0x00004310
+#define PATTERN_COLOR_1                                             0x00004314
+#define PATTERN_PATTERN_0                                           0x00004318
+#define PATTERN_PATTERN_1                                           0x0000431C
+
+#define CLIP_POINT                                                  0x00006300
+#define CLIP_POINT_X                                                15:0
+#define CLIP_POINT_Y                                                31:16
+#define CLIP_SIZE                                                   0x00006304
+#define CLIP_SIZE_WIDTH                                             15:0
+#define CLIP_SIZE_HEIGHT                                            31:16
+
+#define LINE_FORMAT                                                 0x00008300
+#define LINE_FORMAT_DEPTH8                                          0x00000003
+#define LINE_FORMAT_DEPTH16                                         0x00000001
+#define LINE_FORMAT_DEPTH24                                         0x00000003
+#define LINE_COLOR                                                  0x00008304
+#define LINE_MAX_LINES                                              16
+#define LINE_LINES(i)                                               0x00008400\
+                                                                    +(i)*8
+#define LINE_LINES_POINT0_X                                         15:0
+#define LINE_LINES_POINT0_Y                                         31:16 
+#define LINE_LINES_POINT1_X                                         47:32
+#define LINE_LINES_POINT1_Y                                         63:48
+
+#define BLIT_POINT_SRC                                              0x0000A300
+#define BLIT_POINT_SRC_X                                            15:0
+#define BLIT_POINT_SRC_Y                                            31:16
+#define BLIT_POINT_DST                                              0x0000A304
+#define BLIT_POINT_DST_X                                            15:0
+#define BLIT_POINT_DST_Y                                            31:16
+#define BLIT_SIZE                                                   0x0000A308
+#define BLIT_SIZE_WIDTH                                             15:0
+#define BLIT_SIZE_HEIGHT                                            31:16
+
+#define RECT_FORMAT                                                 0x0000C300
+#define RECT_FORMAT_DEPTH8                                          0x00000003
+#define RECT_FORMAT_DEPTH16                                         0x00000001
+#define RECT_FORMAT_DEPTH24                                         0x00000003
+#define RECT_SOLID_COLOR                                            0x0000C3FC
+#define RECT_SOLID_RECTS_MAX_RECTS                                  32
+#define RECT_SOLID_RECTS(i)                                         0x0000C400\
+                                                                    +(i)*8
+#define RECT_SOLID_RECTS_Y                                          15:0
+#define RECT_SOLID_RECTS_X                                          31:16
+#define RECT_SOLID_RECTS_HEIGHT                                     47:32
+#define RECT_SOLID_RECTS_WIDTH                                      63:48
+
+#define RECT_EXPAND_ONE_COLOR_CLIP                                  0x0000C7EC
+#define RECT_EXPAND_ONE_COLOR_CLIP_POINT0_X                         15:0
+#define RECT_EXPAND_ONE_COLOR_CLIP_POINT0_Y                         31:16
+#define RECT_EXPAND_ONE_COLOR_CLIP_POINT1_X                         47:32
+#define RECT_EXPAND_ONE_COLOR_CLIP_POINT1_Y                         63:48
+#define RECT_EXPAND_ONE_COLOR_COLOR                                 0x0000C7F4
+#define RECT_EXPAND_ONE_COLOR_SIZE                                  0x0000C7F8
+#define RECT_EXPAND_ONE_COLOR_SIZE_WIDTH                            15:0
+#define RECT_EXPAND_ONE_COLOR_SIZE_HEIGHT                           31:16
+#define RECT_EXPAND_ONE_COLOR_POINT                                 0x0000C7FC
+#define RECT_EXPAND_ONE_COLOR_POINT_X                               15:0
+#define RECT_EXPAND_ONE_COLOR_POINT_Y                               31:16
+#define RECT_EXPAND_ONE_COLOR_DATA_MAX_DWORDS                       128
+#define RECT_EXPAND_ONE_COLOR_DATA(i)                               0x0000C800\
+                                                                    +(i)*4
+
+#define RECT_EXPAND_TWO_COLOR_CLIP                                  0x0000CBE4
+#define RECT_EXPAND_TWO_COLOR_CLIP_POINT0_X                         15:0
+#define RECT_EXPAND_TWO_COLOR_CLIP_POINT0_Y                         31:16
+#define RECT_EXPAND_TWO_COLOR_CLIP_POINT1_X                         47:32
+#define RECT_EXPAND_TWO_COLOR_CLIP_POINT1_Y                         63:48
+#define RECT_EXPAND_TWO_COLOR_COLOR_0                               0x0000CBEC
+#define RECT_EXPAND_TWO_COLOR_COLOR_1                               0x0000CBF0
+#define RECT_EXPAND_TWO_COLOR_SIZE_IN                               0x0000CBF4
+#define RECT_EXPAND_TWO_COLOR_SIZE_IN_WIDTH                         15:0
+#define RECT_EXPAND_TWO_COLOR_SIZE_IN_HEIGHT                        31:16
+#define RECT_EXPAND_TWO_COLOR_SIZE_OUT                              0x0000CBF8
+#define RECT_EXPAND_TWO_COLOR_SIZE_OUT_WIDTH                        15:0
+#define RECT_EXPAND_TWO_COLOR_SIZE_OUT_HEIGHT                       31:16
+#define RECT_EXPAND_TWO_COLOR_POINT                                 0x0000CBFC
+#define RECT_EXPAND_TWO_COLOR_POINT_X                               15:0
+#define RECT_EXPAND_TWO_COLOR_POINT_Y                               31:16
+#define RECT_EXPAND_TWO_COLOR_DATA_MAX_DWORDS                       128
+#define RECT_EXPAND_TWO_COLOR_DATA(i)                               0x0000CC00\
+                                                                    +(i)*4
+
+#define STRETCH_BLIT_FORMAT                                         0x0000E300
+#define STRETCH_BLIT_FORMAT_DEPTH8                                  0x00000004
+#define STRETCH_BLIT_FORMAT_DEPTH16                                 0x00000007
+#define STRETCH_BLIT_FORMAT_DEPTH24                                 0x00000004
+#define STRETCH_BLIT_FORMAT_X8R8G8B8                                0x00000004
+#define STRETCH_BLIT_FORMAT_YUYV                                    0x00000005
+#define STRETCH_BLIT_FORMAT_UYVY                                    0x00000006
+#define STRETCH_BLIT_CLIP_POINT                                     0x0000E308
+#define STRETCH_BLIT_CLIP_POINT_X                                   15:0 
+#define STRETCH_BLIT_CLIP_POINT_Y                                   31:16
+#define STRETCH_BLIT_CLIP_SIZE                                      0x0000E30C
+#define STRETCH_BLIT_CLIP_SIZE_WIDTH                                15:0
+#define STRETCH_BLIT_CLIP_SIZE_HEIGHT                               31:16
+#define STRETCH_BLIT_DST_POINT                                      0x0000E310
+#define STRETCH_BLIT_DST_POINT_X                                    15:0
+#define STRETCH_BLIT_DST_POINT_Y                                    31:16
+#define STRETCH_BLIT_DST_SIZE                                       0x0000E314
+#define STRETCH_BLIT_DST_SIZE_WIDTH                                 15:0
+#define STRETCH_BLIT_DST_SIZE_HEIGHT                                31:16
+#define STRETCH_BLIT_DU_DX                                          0x0000E318
+#define STRETCH_BLIT_DV_DY                                          0x0000E31C
+#define STRETCH_BLIT_SRC_SIZE                                       0x0000E400
+#define STRETCH_BLIT_SRC_SIZE_WIDTH                                 15:0
+#define STRETCH_BLIT_SRC_SIZE_HEIGHT                                31:16
+#define STRETCH_BLIT_SRC_FORMAT                                     0x0000E404
+#define STRETCH_BLIT_SRC_FORMAT_PITCH                               15:0
+#define STRETCH_BLIT_SRC_FORMAT_ORIGIN                              23:16
+#define STRETCH_BLIT_SRC_FORMAT_ORIGIN_CENTER                       0x00000001
+#define STRETCH_BLIT_SRC_FORMAT_ORIGIN_CORNER                       0x00000002
+#define STRETCH_BLIT_SRC_FORMAT_FILTER                              31:24
+#define STRETCH_BLIT_SRC_FORMAT_FILTER_POINT_SAMPLE                 0x00000000
+#define STRETCH_BLIT_SRC_FORMAT_FILTER_BILINEAR                     0x00000001
+#define STRETCH_BLIT_SRC_OFFSET                                     0x0000E408
+#define STRETCH_BLIT_SRC_POINT                                      0x0000E40C
+#define STRETCH_BLIT_SRC_POINT_U                                    15:0
+#define STRETCH_BLIT_SRC_POINT_V                                    31:16

+ 257 - 89
sys/src/9/pc/vganvidia.c

@@ -1,3 +1,45 @@
+
+/* Portions of this file derived from work with the following copyright */
+
+ /***************************************************************************\
+|*                                                                           *|
+|*       Copyright 2003 NVIDIA, Corporation.  All rights reserved.           *|
+|*                                                                           *|
+|*     NOTICE TO USER:   The source code  is copyrighted under  U.S. and     *|
+|*     international laws.  Users and possessors of this source code are     *|
+|*     hereby granted a nonexclusive,  royalty-free copyright license to     *|
+|*     use this code in individual and commercial software.                  *|
+|*                                                                           *|
+|*     Any use of this source code must include,  in the user documenta-     *|
+|*     tion and  internal comments to the code,  notices to the end user     *|
+|*     as follows:                                                           *|
+|*                                                                           *|
+|*       Copyright 2003 NVIDIA, Corporation.  All rights reserved.           *|
+|*                                                                           *|
+|*     NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY     *|
+|*     OF  THIS SOURCE  CODE  FOR ANY PURPOSE.  IT IS  PROVIDED  "AS IS"     *|
+|*     WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND.  NVIDIA, CORPOR-     *|
+|*     ATION DISCLAIMS ALL WARRANTIES  WITH REGARD  TO THIS SOURCE CODE,     *|
+|*     INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE-     *|
+|*     MENT,  AND FITNESS  FOR A PARTICULAR PURPOSE.   IN NO EVENT SHALL     *|
+|*     NVIDIA, CORPORATION  BE LIABLE FOR ANY SPECIAL,  INDIRECT,  INCI-     *|
+|*     DENTAL, OR CONSEQUENTIAL DAMAGES,  OR ANY DAMAGES  WHATSOEVER RE-     *|
+|*     SULTING 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 SOURCE CODE.     *|
+|*                                                                           *|
+|*     U.S. Government  End  Users.   This source code  is a "commercial     *|
+|*     item,"  as that  term is  defined at  48 C.F.R. 2.101 (OCT 1995),     *|
+|*     consisting  of "commercial  computer  software"  and  "commercial     *|
+|*     computer  software  documentation,"  as such  terms  are  used in     *|
+|*     48 C.F.R. 12.212 (SEPT 1995)  and is provided to the U.S. Govern-     *|
+|*     ment only as  a commercial end item.   Consistent with  48 C.F.R.     *|
+|*     12.212 and  48 C.F.R. 227.7202-1 through  227.7202-4 (JUNE 1995),     *|
+|*     all U.S. Government End Users  acquire the source code  with only     *|
+|*     those rights set forth herein.                                        *|
+|*                                                                           *|
+ \***************************************************************************/
+
 #include "u.h"
 #include "../port/lib.h"
 #include "mem.h"
@@ -11,19 +53,31 @@
 #include <memdraw.h>
 #include <cursor.h>
 #include "screen.h"
+#include "nv_dma.h"
 
 enum {
 	Pramin = 0x00710000,
 	Pramdac = 0x00680000,
 	Fifo = 0x00800000,
-	Pgraph = 0x00400000
+	Pgraph = 0x00400000,
+	Pfb = 0x00100000
 };
 
 enum {
 	hwCurPos = Pramdac + 0x0300,
-	hwCurImage = Pramin + (0x00010000 - 0x0800),
 };
 
+#define SKIPS 8
+
+struct {
+	ulong	*dmabase;
+	int		dmacurrent;
+	int		dmaput;
+	int		dmafree;
+	int		dmamax;
+} nv;
+
+
 /* Nvidia is good about backwards compatibility -- any did >= 0x20 is fine */
 static Pcidev*
 nvidiapci(void)
@@ -81,8 +135,8 @@ static void
 nvidiaenable(VGAscr* scr)
 {
 	Pcidev *p;
-	ulong aperture;
-	int align, size;
+	ulong aperture, *q;
+	int align, size, tmp;
 
 	/*
 	 * Only once, can't be disabled for now.
@@ -109,6 +163,27 @@ nvidiaenable(VGAscr* scr)
 		scr->apsize = size;
 		addvgaseg("nvidiascreen", aperture, size);
 	}
+
+	/* find video memory size */
+	if (scr->id & 0x0F00) {
+		q = KADDR(scr->io + Pfb +  0x020C);
+		tmp = (*q >> 20) & 0xFF;
+		if (tmp == 0)
+			tmp = 16;
+		scr->storage =  tmp*1024*1024;
+	} else {
+		q = KADDR(scr->io + Pfb);
+		tmp = *q;
+		if (tmp & 0x0100) {
+			scr->storage = ((tmp >> 12) & 0x0F) * 1024 + 1024 * 2;
+		} else {
+			tmp &= 0x03;
+			if (tmp)
+				scr->storage = (1024*1024*2) << tmp;
+			else
+				scr->storage = 1024*1024*32;
+		}
+	}
 }
 
 static void
@@ -120,6 +195,7 @@ nvidiacurdisable(VGAscr* scr)
 	vgaxo(Crtx, 0x31, vgaxi(Crtx, 0x31) & ~0x01);
 }
 
+
 static void
 nvidiacurload(VGAscr* scr, Cursor* curs)
 {
@@ -133,20 +209,14 @@ nvidiacurload(VGAscr* scr, Cursor* curs)
 
 	vgaxo(Crtx, 0x31, vgaxi(Crtx, 0x31) & ~0x01);
 
-	p = KADDR(scr->io + hwCurImage);
+	if (scr->id & 0x0F00)
+		p = KADDR(scr->aperture + scr->storage - 96*1024);
+	else
+		p = KADDR(scr->io + Pramin + 0x1E00 * 4);
 
 	for(i=0; i<16; i++) {
-		switch(scr->id){
-		default:
-			c = (curs->clr[2 * i] << 8) | curs->clr[2 * i+1];
-			s = (curs->set[2 * i] << 8) | curs->set[2 * i+1];
-			break;
-		case 0x171:		/* for Geforece4 MX bug, K.Okamoto */
-		case 0x181:
-			c = (curs->clr[2 * i+1] << 8) | curs->clr[2 * i];
-			s = (curs->set[2 * i+1] << 8) | curs->set[2 * i];
-			break;
-		}
+		c = (curs->clr[2 * i] << 8) | curs->clr[2 * i+1];
+		s = (curs->set[2 * i] << 8) | curs->set[2 * i+1];
 		tmp = 0;
 		for (j=0; j<16; j++){
 			if(s&0x8000)
@@ -203,34 +273,82 @@ nvidiacurenable(VGAscr* scr)
 	vgaxo(Crtx, 0x31, vgaxi(Crtx, 0x31) | 0x01);
 }
 
-enum {
-	RopFifo 		= 0x00000000, 
-	ClipFifo 		= 0x00002000,
-	PattFifo 		= 0x00004000,
-	BltFifo 		= 0x00008000,
-	BitmapFifo 	= 0x0000A000,
-};
+void
+writeput(VGAscr *scr, int data)
+{
+	uchar	*p, scratch;
+	ulong	*fifo;
 
-enum {
-	RopRop3 = RopFifo + 0x300,
+	outb(0x3D0,0);
+	p=KADDR(scr->aperture);
+	scratch = *p;
+	fifo = KADDR(scr->io + Fifo);
+	fifo[0x10] = (data << 2);
+	USED(scratch);
+}
 
-	ClipTopLeft = ClipFifo + 0x300,
-	ClipWidthHeight = ClipFifo + 0x304,
+ulong
+readget(VGAscr *scr)
+{
+	ulong	*fifo;
 
-	PattShape = PattFifo + 0x0308,
-	PattColor0 = PattFifo + 0x0310,
-	PattColor1 = PattFifo + 0x0314,
-	PattMonochrome0 = PattFifo + 0x0318,
-	PattMonochrome1 = PattFifo + 0x031C,
+	fifo = KADDR(scr->io + Fifo);
+	return (fifo[0x0011] >> 2);
+}
 
-	BltTopLeftSrc = BltFifo + 0x0300,
-	BltTopLeftDst = BltFifo + 0x0304,
-	BltWidthHeight = BltFifo + 0x0308,
+void
+nvdmakickoff(VGAscr *scr)
+{
+	if(nv.dmacurrent != nv.dmaput) {
+		nv.dmaput = nv.dmacurrent;
+		writeput(scr, nv.dmaput);
+	}
+}
+
+static void
+nvdmanext(ulong data)
+{
+	nv.dmabase[nv.dmacurrent++] = data;
+}
+
+void 
+nvdmawait(VGAscr *scr, int size)
+{
+	int dmaget;
+
+	size++;
+
+	while(nv.dmafree < size) {
+		dmaget = readget(scr);
+
+		if(nv.dmaput >= dmaget) {
+			nv.dmafree = nv.dmamax - nv.dmacurrent;
+			if(nv.dmafree < size) {
+				nvdmanext(0x20000000);
+				if(dmaget <= SKIPS) {
+					if (nv.dmaput <= SKIPS) /* corner case - will be idle */
+						writeput(scr, SKIPS + 1);
+					do { dmaget = readget(scr); }
+					while(dmaget <= SKIPS);
+				}
+				writeput(scr, SKIPS);
+				nv.dmacurrent = nv.dmaput = SKIPS;
+				nv.dmafree = dmaget - (SKIPS + 1);
+			}
+		} else 
+			nv.dmafree = dmaget - nv.dmacurrent - 1;
+	}
+}
 
-	BitmapColor1A = BitmapFifo + 0x03FC,
-	BitmapURect0TopLeft = BitmapFifo + 0x0400,
-	BitmapURect0WidthHeight = BitmapFifo + 0x0404,
-};
+
+static void
+nvdmastart(VGAscr *scr, ulong tag, int size)
+{
+	if (nv.dmafree <= size)
+		nvdmawait(scr, size);
+	nvdmanext((size << 18) | tag);
+	nv.dmafree -= (size + 1);
+}
 
 static void
 waitforidle(VGAscr *scr)
@@ -240,6 +358,12 @@ waitforidle(VGAscr *scr)
 
 	pgraph = KADDR(scr->io + Pgraph);
 
+	x = 0;
+	while((readget(scr) != nv.dmaput) && x++ < 1000000)
+		;
+	if(x >= 1000000)
+		iprint("idle stat %lud put %d scr %p pc %luX\n", readget(scr), nv.dmaput, scr, getcallerpc(&scr));
+
 	x = 0;
 	while(pgraph[0x00000700/4] & 0x01 && x++ < 1000000)
 		;
@@ -249,36 +373,104 @@ waitforidle(VGAscr *scr)
 }
 
 static void
-waitforfifo(VGAscr *scr, int fifo, int entries)
+nvresetgraphics(VGAscr *scr)
 {
-	ushort* fifofree;
-	int x;
+	ulong	surfaceFormat, patternFormat, rectFormat, lineFormat;
+	int		pitch, i;
+
+	pitch = scr->gscreen->width*BY2WD;
+
+	nv.dmabase = KADDR(scr->aperture + scr->storage - 128*1024);
+
+	for(i=0; i<SKIPS; i++)
+		nv.dmabase[i] = 0x00000000;
+
+	nv.dmabase[0x0 + SKIPS] = 0x00040000;
+	nv.dmabase[0x1 + SKIPS] = 0x80000010;
+	nv.dmabase[0x2 + SKIPS] = 0x00042000;
+	nv.dmabase[0x3 + SKIPS] = 0x80000011;
+	nv.dmabase[0x4 + SKIPS] = 0x00044000;
+	nv.dmabase[0x5 + SKIPS] = 0x80000012;
+	nv.dmabase[0x6 + SKIPS] = 0x00046000;
+	nv.dmabase[0x7 + SKIPS] = 0x80000013;
+	nv.dmabase[0x8 + SKIPS] = 0x00048000;
+	nv.dmabase[0x9 + SKIPS] = 0x80000014;
+	nv.dmabase[0xA + SKIPS] = 0x0004A000;
+	nv.dmabase[0xB + SKIPS] = 0x80000015;
+	nv.dmabase[0xC + SKIPS] = 0x0004C000;
+	nv.dmabase[0xD + SKIPS] = 0x80000016;
+	nv.dmabase[0xE + SKIPS] = 0x0004E000;
+	nv.dmabase[0xF + SKIPS] = 0x80000017;
+
+	nv.dmaput = 0;
+	nv.dmacurrent = 16 + SKIPS;
+	nv.dmamax = 8191;
+	nv.dmafree = nv.dmamax - nv.dmacurrent;
+
+	switch(scr->gscreen->depth) {
+	case 32:
+	case 24:
+		surfaceFormat = SURFACE_FORMAT_DEPTH24;
+		patternFormat = PATTERN_FORMAT_DEPTH24;
+		rectFormat    = RECT_FORMAT_DEPTH24;
+		lineFormat    = LINE_FORMAT_DEPTH24;
+		break;
+	case 16:
+	case 15:
+		surfaceFormat = SURFACE_FORMAT_DEPTH16;
+		patternFormat = PATTERN_FORMAT_DEPTH16;
+		rectFormat    = RECT_FORMAT_DEPTH16;
+		lineFormat    = LINE_FORMAT_DEPTH16;
+		break;
+	default:
+		surfaceFormat = SURFACE_FORMAT_DEPTH8;
+		patternFormat = PATTERN_FORMAT_DEPTH8;
+		rectFormat    = RECT_FORMAT_DEPTH8;
+		lineFormat    = LINE_FORMAT_DEPTH8;
+		break;
+	}
 
-	x = 0;
-	fifofree = KADDR(scr->io + Fifo + fifo + 0x10);
+	nvdmastart(scr, SURFACE_FORMAT, 4);
+	nvdmanext(surfaceFormat);
+	nvdmanext(pitch | (pitch << 16));
+	nvdmanext(0);
+	nvdmanext(0);
 
-	while(((*fifofree >> 2) < entries) && x++ < 1000000)
-		;
+	nvdmastart(scr, PATTERN_FORMAT, 1);
+	nvdmanext(patternFormat);
 
-	if(x >= 1000000)
-		iprint("fifo stat %d scrio %.8lux scr %p pc %luX\n", *fifofree, scr->io, scr, getcallerpc(&scr));
+	nvdmastart(scr, RECT_FORMAT, 1);
+	nvdmanext(rectFormat);
+
+	nvdmastart(scr, LINE_FORMAT, 1);
+	nvdmanext(lineFormat);
+
+	nvdmastart(scr, PATTERN_COLOR_0, 4);
+	nvdmanext(~0);
+	nvdmanext(~0);
+	nvdmanext(~0);
+	nvdmanext(~0);
+
+	nvdmastart(scr, ROP_SET, 1);
+	nvdmanext(0xCC);
+ 
+	nvdmakickoff(scr);
+	waitforidle(scr);
 }
 
+
 static int
 nvidiahwfill(VGAscr *scr, Rectangle r, ulong sval)
 {
-	ulong*	fifo;
+	nvdmastart(scr, RECT_SOLID_COLOR, 1);
+	nvdmanext(sval);
 
-	fifo = KADDR(scr->io + Fifo);
+	nvdmastart(scr, RECT_SOLID_RECTS(0), 2);
+	nvdmanext((r.min.x << 16) | r.min.y);
+	nvdmanext((Dx(r) << 16) | Dy(r));
 
-	waitforfifo(scr, BitmapFifo, 1);
-
-	fifo[BitmapColor1A/4] = sval;
-
-	waitforfifo(scr, BitmapFifo, 2);
-
-	fifo[BitmapURect0TopLeft/4] = (r.min.x << 16) | r.min.y;
-	fifo[BitmapURect0WidthHeight/4] = (Dx(r) << 16) | Dy(r);
+	//if ( (Dy(r) * Dx(r)) >= 512)
+		nvdmakickoff(scr);
 
 	waitforidle(scr);
 
@@ -288,15 +480,13 @@ nvidiahwfill(VGAscr *scr, Rectangle r, ulong sval)
 static int
 nvidiahwscroll(VGAscr *scr, Rectangle r, Rectangle sr)
 {
-	ulong*	fifo;
-
-	fifo = KADDR(scr->io + Fifo);
+	nvdmastart(scr, BLIT_POINT_SRC, 3);
+	nvdmanext((sr.min.y << 16) | sr.min.x);
+	nvdmanext((r.min.y << 16) | r.min.x);
+	nvdmanext((Dy(r) << 16) | Dx(r));
 
-	waitforfifo(scr, BltFifo, 3);
-
-	fifo[BltTopLeftSrc/4] = (sr.min.y << 16) | sr.min.x;
-	fifo[BltTopLeftDst/4] = (r.min.y << 16) | r.min.x;
-	fifo[BltWidthHeight/4] = (Dy(r) << 16) | Dx(r);
+	//if ( (Dy(r) * Dx(r)) >= 512)
+		nvdmakickoff(scr);
 
 	waitforidle(scr);
 
@@ -324,29 +514,7 @@ nvidiablank(VGAscr*, int blank)
 static void
 nvidiadrawinit(VGAscr *scr)
 {
-	ulong*	fifo;
-
-	fifo = KADDR(scr->io + Fifo);
-
-	waitforfifo(scr, ClipFifo, 2);
-
-	fifo[ClipTopLeft/4] = 0x0;
-	fifo[ClipWidthHeight/4] = 0x80008000;
-
-	waitforfifo(scr, PattFifo, 5);
-
-	fifo[PattShape/4] = 0;
-	fifo[PattColor0/4] = 0xffffffff;
-	fifo[PattColor1/4] = 0xffffffff;
-	fifo[PattMonochrome0/4] = 0xffffffff;
-	fifo[PattMonochrome1/4] = 0xffffffff;
-
-	waitforfifo(scr, RopFifo, 1);
-
-	fifo[RopRop3/4] = 0xCC;
-
-	waitforidle(scr);
-
+	nvresetgraphics(scr);
 	scr->blank = nvidiablank;
 	hwblank = 1;
 	scr->fill = nvidiahwfill;

File diff suppressed because it is too large
+ 543 - 260
sys/src/cmd/aux/vga/nvidia.c


Some files were not shown because too many files changed in this diff