/[gxemul]/trunk/src/devices/pci_dec21030.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/src/devices/pci_dec21030.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (show annotations)
Mon Oct 8 16:18:00 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 8494 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.707 2005/04/27 16:37:33 debug Exp $
20050408	Some minor updates to the wdc. Linux now doesn't complain
		anymore if a disk is non-present.
20050409	Various minor fixes (a bintrans bug, and some other things).
		The wdc seems to work with Playstation2 emulation, but there
		is a _long_ annoying delay when disks are detected.
		Fixing a really important bintrans bug (when devices and RAM
		are mixed within 4KB pages), which was triggered with
		NetBSD/playstation2 kernels.
20050410	Adding a dummy dev_ps2_ether (just so that NetBSD doesn't
		complain as much during bootup).
		Symbols starting with '$' are now ignored.
		Renaming dev_ps2_ohci.c to dev_ohci.c, etc.
20050411	Moving the bintrans-cache-isolation check from cpu_mips.c to
		cpu_mips_coproc.c. (I thought this would give a speedup, but
		it's not noticable.)
		Better playstation2 sbus interrupt code.
		Skip ahead many ticks if the count register is read manually.
		(This increases the speed of delay-loops that simply read
		the count register.)
20050412	Updates to the playstation2 timer/interrupt code.
		Some other minor updates.
20050413	NetBSD/cobalt runs from a disk image :-) including userland;
		updating the documentation on how to install NetBSD/cobalt
		using NetBSD/pmax (!).
		Some minor bintrans updates (no real speed improvement) and
		other minor updates (playstation2 now uses the -o options).
20050414	Adding a dummy x86 (and AMD64) mode.
20050415	Adding some (32-bit and 16-bit) x86 instructions.
		Adding some initial support for non-SCSI, non-IDE floppy
		images. (The x86 mode can boot from these, more or less.)
		Moving the devices/ and include/ directories to src/devices/
		and src/include/, respectively.
20050416	Continuing on the x86 stuff. (Adding pc_bios.c and some simple
		support for software interrupts in 16-bit mode.)
20050417	Ripping out most of the x86 instruction decoding stuff, trying
		to rewrite it in a cleaner way.
		Disabling some of the least working CPU families in the
		configure script (sparc, x86, alpha, hppa), so that they are
		not enabled by default.
20050418	Trying to fix the bug which caused problems when turning on
		and off bintrans interactively, by flushing the bintrans cache
		whenever bintrans is manually (re)enabled.
20050419	Adding the 'lswi' ppc instruction.
		Minor updates to the x86 instruction decoding.
20050420	Renaming x86 register name indices from R_xx to X86_R_xx (this
		makes building on Tru64 nicer).
20050422	Adding a check for duplicate MIPS TLB entries on tlbwr/tlbwi.
20050427	Adding screenshots to guestoses.html.
		Some minor fixes and testing for the next release.

==============  RELEASE 0.3.2  ==============


1 /*
2 * Copyright (C) 2004 Anders Gavare. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 *
28 * $Id: pci_dec21030.c,v 1.15 2005/02/26 18:00:38 debug Exp $
29 *
30 * DEC 21030 "tga" graphics.
31 *
32 * Resolutions that seem to be possible: 640x480, 1024x768, 1280x1024.
33 * 8 bits, perhaps others? (24 bit?)
34 *
35 * NetBSD should say something like this:
36 *
37 * tga0 at pci0 dev 12 function 0: TGA2 pass 2, board type T8-02
38 * tga0: 1280 x 1024, 8bpp, Bt485 RAMDAC
39 *
40 * See netbsd/src/sys/dev/pci/tga.c for more info.
41 * tga_rop_vtov() for video-to-video copy (scrolling and fast
42 * erasing)
43 *
44 * TODO: This device is far from complete.
45 * The RAMDAC is non-existant.
46 *
47 * TODO: all fb device writes with direct writes to the framebuffer
48 * memory, and update the x1,y1,x2,y2 coordinates instead.
49 * That will give better performance.
50 */
51
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <string.h>
55
56 #include "memory.h"
57 #include "misc.h"
58 #include "devices.h"
59 #include "bus_pci.h"
60 #include "tgareg.h"
61
62 #define MAX_XSIZE 2048
63
64 #if 1
65 int dec21030_default_xsize = 640;
66 int dec21030_default_ysize = 480;
67 #else
68 int dec21030_default_xsize = 1024;
69 int dec21030_default_ysize = 768;
70 #endif
71
72
73 /* TODO: Ugly hack: this causes the framebuffer to be in memory */
74 #define FRAMEBUFFER_PADDR 0x4000000000ULL
75 #define FRAMEBUFFER_BASE 0x201000
76
77 #define PCI_VENDOR_DEC 0x1011 /* Digital Equipment */
78 #define PCI_PRODUCT_DEC_21030 0x0004 /* DECchip 21030 ("TGA") */
79
80 struct dec21030_data {
81 int graphics_mode;
82 uint32_t pixel_mask;
83 uint32_t copy_source;
84 uint32_t color;
85 struct vfb_data *vfb_data;
86 };
87
88
89 /*
90 * pci_dec21030_rr():
91 *
92 * See http://mail-index.netbsd.org/port-arc/2001/08/13/0000.html
93 * for more info.
94 */
95 uint32_t pci_dec21030_rr(int reg)
96 {
97 switch (reg) {
98 case 0x00:
99 return PCI_VENDOR_DEC + (PCI_PRODUCT_DEC_21030 << 16);
100 case 0x04:
101 return 0x02800087;
102 case 0x08:
103 return 0x03800003;
104 /* return
105 PCI_CLASS_CODE(PCI_CLASS_DISPLAY, PCI_SUBCLASS_DISPLAY_VGA, 0)
106 + 0x03; */
107 case 0x0c:
108 return 0x0000ff00;
109 case 0x10:
110 /* address (8=prefetchable) */
111 return 0x00000000 + 8;
112 case 0x30:
113 return 0x08000001;
114 case 0x3c:
115 return 0x00000100; /* interrupt pin ? */
116 default:
117 return 0;
118 }
119 }
120
121
122 /*
123 * dev_dec21030_access():
124 */
125 int dev_dec21030_access(struct cpu *cpu, struct memory *mem,
126 uint64_t relative_addr, unsigned char *data, size_t len,
127 int writeflag, void *extra)
128 {
129 struct dec21030_data *d = extra;
130 uint64_t idata, odata = 0;
131 int reg, r, i, white = 255, black = 0;
132 int newlen;
133 unsigned char buf2[MAX_XSIZE];
134
135 /* Read/write to the framebuffer: */
136 if (relative_addr >= FRAMEBUFFER_BASE) {
137 /* TODO: Perhaps this isn't graphics mode (GMOR),
138 but GOPR (operation) specific: */
139
140 switch (d->graphics_mode) {
141 case 1: /* Bitmap write: */
142 /* Copy from data into buf2: */
143 for (i=0; i<len; i++) {
144 buf2[i*8 + 0] = data[i]&1? white : black;
145 buf2[i*8 + 1] = data[i]&2? white : black;
146 buf2[i*8 + 2] = data[i]&4? white : black;
147 buf2[i*8 + 3] = data[i]&8? white : black;
148 buf2[i*8 + 4] = data[i]&16? white : black;
149 buf2[i*8 + 5] = data[i]&32? white : black;
150 buf2[i*8 + 6] = data[i]&64? white : black;
151 buf2[i*8 + 7] = data[i]&128? white : black;
152 }
153
154 newlen = 0;
155 for (i=0; i<32; i++)
156 if (d->pixel_mask & (1 << i))
157 newlen ++;
158
159 if (newlen > len * 8)
160 newlen = len * 8;
161
162 r = dev_fb_access(cpu, mem, relative_addr -
163 FRAMEBUFFER_BASE, buf2, newlen, writeflag,
164 d->vfb_data);
165 break;
166 case 0x2d: /* Block fill: */
167 /* data is nr of pixels to fill minus one */
168 newlen = memory_readmax64(cpu, data, len) + 1;
169 /* debug("YO addr=0x%08x, newlen=%i\n", relative_addr,
170 newlen); */
171 if (newlen > MAX_XSIZE)
172 newlen = MAX_XSIZE;
173 memset(buf2, d->color, newlen);
174 r = dev_fb_access(cpu, mem, relative_addr -
175 FRAMEBUFFER_BASE, buf2, newlen, MEM_WRITE,
176 d->vfb_data);
177 break;
178 default:
179 r = dev_fb_access(cpu, mem, relative_addr -
180 FRAMEBUFFER_BASE, data, len, writeflag,
181 d->vfb_data);
182 }
183 return r;
184 }
185
186 idata = memory_readmax64(cpu, data, len);
187
188 /* Read from/write to the dec21030's registers: */
189 reg = ((relative_addr - TGA_MEM_CREGS) & (TGA_CREGS_ALIAS - 1))
190 / sizeof(uint32_t);
191 switch (reg) {
192
193 /* Color? (there are 8 of these, 2 used in 8-bit mode,
194 8 in 24-bit mode) */
195 case TGA_REG_GBCR0:
196 if (writeflag == MEM_WRITE)
197 d->color = idata;
198 else
199 odata = d->color;
200 break;
201
202 /* Board revision */
203 /* case TGA_MEM_CREGS + sizeof(uint32_t) * TGA_REG_GREV: */
204 case TGA_REG_GREV:
205 /* 01,02,03,04 (rev0) and 20,21,22 (rev1) are allowed */
206 odata = 0x04;
207 break;
208
209 /* Graphics Mode: */
210 case TGA_REG_GMOR:
211 if (writeflag == MEM_WRITE)
212 d->graphics_mode = idata;
213 else
214 odata = d->graphics_mode;
215 break;
216
217 /* Pixel mask: */
218 case TGA_REG_GPXR_S: /* "one-shot" */
219 case TGA_REG_GPXR_P: /* persistant */
220 if (writeflag == MEM_WRITE)
221 d->pixel_mask = idata;
222 else
223 odata = d->pixel_mask;
224 break;
225
226 /* Horizonsal size: */
227 case TGA_REG_VHCR:
228 odata = dec21030_default_xsize / 4; /* lowest 9 bits */
229 break;
230
231 /* Vertical size: */
232 case TGA_REG_VVCR:
233 odata = dec21030_default_ysize; /* lowest 11 bits */
234 break;
235
236 /* Block copy source: */
237 case TGA_REG_GCSR:
238 d->copy_source = idata;
239 debug("[ dec21030: block copy source = 0x%08x ]\n", idata);
240 break;
241
242 /* Block copy destination: */
243 case TGA_REG_GCDR:
244 debug("[ dec21030: block copy destination = 0x%08x ]\n", idata);
245 newlen = 64;
246 /* Both source and destination are raw framebuffer addresses,
247 offset by 0x1000. */
248 dev_fb_access(cpu, mem, d->copy_source - 0x1000,
249 buf2, newlen, MEM_READ, d->vfb_data);
250 dev_fb_access(cpu, mem, idata - 0x1000,
251 buf2, newlen, MEM_WRITE, d->vfb_data);
252 break;
253
254 default:
255 if (writeflag == MEM_WRITE)
256 debug("[ dec21030: unimplemented write to address"
257 " 0x%x (=reg 0x%x), data=0x%02x ]\n",
258 (int)relative_addr, reg, (int)idata);
259 else
260 debug("[ dec21030: unimplemented read from address"
261 " 0x%x (=reg 0x%x) ]\n", (int)relative_addr, reg);
262 }
263
264 if (writeflag == MEM_READ)
265 memory_writemax64(cpu, data, len, odata);
266
267 return 1;
268 }
269
270
271 /*
272 * pci_dec21030_init():
273 */
274 void pci_dec21030_init(struct machine *machine, struct memory *mem)
275 {
276 struct dec21030_data *d;
277
278 d = malloc(sizeof(struct dec21030_data));
279 if (d == NULL) {
280 fprintf(stderr, "out of memory\n");
281 exit(1);
282 }
283 memset(d, 0, sizeof(struct dec21030_data));
284
285 /* TODO: this address is based on what NetBSD/arc uses...
286 fix this */
287 memory_device_register(mem, "dec21030", 0x100000000ULL,
288 128*1048576, dev_dec21030_access, d, MEM_DEFAULT, NULL);
289
290 /*
291 * TODO: I have no idea about how/where this framebuffer should
292 * be in relation to the pci device
293 */
294 d->vfb_data = dev_fb_init(machine, mem, FRAMEBUFFER_PADDR, VFB_GENERIC,
295 dec21030_default_xsize, dec21030_default_ysize,
296 dec21030_default_xsize, dec21030_default_ysize, 8, "TGA", 0);
297 }
298

  ViewVC Help
Powered by ViewVC 1.1.26