add the SiS driver - no kernel driver yet
[mesa.git] / src / mesa / drivers / dri / sis / sis_debug.c
1 /**************************************************************************
2
3 Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
4 All Rights Reserved.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sub license, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial portions
16 of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
22 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **************************************************************************/
27 /* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_debug.c,v 1.5 2000/09/26 15:56:48 tsi Exp $ */
28
29 /*
30 * Authors:
31 * Sung-Ching Lin <sclin@sis.com.tw>
32 *
33 */
34
35 /*
36 * dump HW states, set environment variable SIS_DEBUG
37 * to enable these functions
38 */
39
40 #include <fcntl.h>
41 #include <assert.h>
42
43 #include "sis_context.h"
44
45 /* for SiS 300/630/540 */
46 #define MMIOLength (0x8FFF-0x8800+1)
47 #define MMIO3DOffset (0x8800)
48 #define FILE_NAME "300.dump"
49
50 char *IOBase4Debug = 0;
51
52 char *prevLockFile = NULL;
53 int prevLockLine = 0;
54
55 GLint _empty[0x10000];
56
57 void
58 dump_agp (void *addr, int dword_count)
59 {
60 if (!getenv ("SIS_DEBUG"))
61 return;
62
63 {
64 int i;
65 FILE *file = fopen ("300agp.dump", "w");
66
67 if (file)
68 {
69 for (i = 0; i < dword_count; i++)
70 {
71 fprintf (file, "%f\n", *(float *) addr);
72 ((unsigned char *) addr) += 4;
73 }
74 fclose (file);
75 }
76 }
77 }
78
79 #ifndef _SOLO
80 void
81 d2f_once (GLcontext * ctx)
82 {
83 XMesaContext xmesa = (XMesaContext) ctx->DriverCtx;
84 sisContextPtr smesa = SIS_CONTEXT(ctx);
85
86 static int serialNumber = -1;
87
88 if (serialNumber == smesa->serialNumber)
89 return;
90 else
91 serialNumber = smesa->serialNumber;
92
93 d2f();
94 }
95
96 void
97 d2f (void)
98 {
99 if (!getenv ("SIS_DEBUG"))
100 return;
101
102 /* dump 0x8800 - 0x8AFF */
103 {
104 int fh;
105 int rval;
106 void *addr = IOBase4Debug + MMIO3DOffset;
107
108 assert (IOBase4Debug);
109
110 if ((fh = open (FILE_NAME, O_WRONLY | O_CREAT, S_IREAD | S_IWRITE)) != -1)
111 {
112 rval = write (fh, addr, MMIOLength);
113 assert (rval != -1);
114 close (fh);
115 }
116 }
117 }
118
119 /* dump to HW */
120 void
121 d2h (char *file_name)
122 {
123 int fh;
124 int rval;
125 void *addr[MMIOLength];
126
127 if (!getenv ("SIS_DEBUG"))
128 return;
129
130 if ((fh = open (file_name, O_CREAT, S_IREAD | S_IWRITE)) != -1)
131 {
132 rval = read (fh, addr, MMIOLength);
133 assert (rval != -1);
134 close (fh);
135 }
136 memcpy (IOBase4Debug + MMIO3DOffset, addr, MMIOLength);
137
138 }
139
140 /* dump video memory to file */
141 void
142 dvidmem (unsigned char *addr, int size)
143 {
144 int fh;
145 int rval;
146 static char *file_name = "vidmem.dump";
147
148 if (!getenv ("SIS_DEBUG"))
149 return;
150
151 if ((fh = open (file_name, O_WRONLY | O_CREAT, S_IREAD | S_IWRITE)) != -1)
152 {
153 rval = write (fh, addr, size);
154 assert (rval != -1);
155 close (fh);
156 }
157 }
158 #endif