/[gxemul]/trunk/src/devices/dev_turbochannel.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

Annotation of /trunk/src/devices/dev_turbochannel.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (hide annotations)
Mon Oct 8 16:18:00 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 11091 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 dpavlin 4 /*
2     * Copyright (C) 2003-2005 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: dev_turbochannel.c,v 1.40 2005/02/18 06:19:19 debug Exp $
29     *
30     * Generic framework for TURBOchannel devices, used in DECstation machines.
31     */
32    
33     #include <stdio.h>
34     #include <stdlib.h>
35     #include <string.h>
36    
37     #include "devices.h"
38     #include "machine.h"
39     #include "memory.h"
40     #include "misc.h"
41     #include "sfbreg.h"
42    
43    
44     struct turbochannel_data {
45     int slot_nr;
46     uint64_t baseaddr;
47     uint64_t endaddr;
48     int irq;
49    
50     int rom_skip;
51    
52     char device_name[9]; /* NUL-terminated */
53    
54     /* These should be terminated with spaces */
55     char card_firmware_version[8];
56     char card_vendor_name[8];
57     char card_module_name[8];
58     char card_firmware_type[4];
59     };
60    
61    
62     /*
63     * dev_turbochannel_access():
64     */
65     int dev_turbochannel_access(struct cpu *cpu, struct memory *mem,
66     uint64_t relative_addr, unsigned char *data, size_t len,
67     int writeflag, void *extra)
68     {
69     struct turbochannel_data *d = extra;
70     uint64_t idata = 0, odata = 0;
71    
72     idata = memory_readmax64(cpu, data, len);
73    
74     relative_addr += d->rom_skip;
75    
76     if (writeflag == MEM_READ) {
77     debug("[ turbochannel: read from slot %i addr 0x%08lx (",
78     d->slot_nr, (long)relative_addr);
79    
80     relative_addr &= 0x7fff;
81    
82     switch (relative_addr) {
83     case 0x3e0:
84     odata = 0x00000001; debug("ROM width");
85     break;
86     case 0x3e4:
87     odata = 0x00000004; debug("ROM stride");
88     break;
89     case 0x3e8:
90     /* 8KB * romsize */
91     odata = 0x00000001; debug("ROM size");
92     break;
93     case 0x3ec:
94     /* 4MB * slotsize */
95     odata = 0x00000001; debug("slot size");
96     break;
97     case 0x3f0:
98     odata = 0x55555555; debug("ROM signature byte 0");
99     break;
100     case 0x3f4:
101     odata = 0x00000000; debug("ROM signature byte 1");
102     break;
103     case 0x3f8:
104     odata = 0xaaaaaaaa; debug("ROM signature byte 2");
105     break;
106     case 0x3fc:
107     odata = 0xffffffff; debug("ROM signature byte 3");
108     break;
109     case 0x470:
110     /* 0=nothing, 1=parity */
111     odata = 0x00000000; debug("flags"); break;
112     default:
113     if (relative_addr >= 0x400 && relative_addr < 0x420)
114     odata = d->card_firmware_version[
115     (relative_addr-0x400)/4];
116     else if (relative_addr >= 0x420 &&
117     relative_addr < 0x440)
118     odata = d->card_vendor_name[
119     (relative_addr-0x420)/4];
120     else if (relative_addr >= 0x440 &&
121     relative_addr < 0x460)
122     odata = d->card_module_name[
123     (relative_addr-0x440)/4];
124     else if (relative_addr >= 0x460 &&
125     relative_addr < 0x470)
126     odata = d->card_firmware_type[
127     (relative_addr-0x460)/4];
128     else {
129     debug("?");
130     }
131     }
132    
133     /*
134     * If this slot is empty, return an error so that a DBE
135     * exception is caused. (This is the way DECstation operating
136     * systems have to detect the absence of cards in a
137     * TURBOchannel slot.)
138     *
139     * NOTE: The Sprite kernel reads from offsets 0x3e0..0x400
140     * without handling the DBE exception, and both Ultrix and
141     * NetBSD seem to detect the DBE exception using addresses
142     * around offset 0x0 or 0x3c0000. This code seems to work
143     * with all of the those OS kernels:
144     */
145     if (d->card_module_name[0] == ' ') {
146     /* Return no data for empty slot: */
147     odata = 0;
148    
149     /* Return DBE exception in some cases: */
150     if (relative_addr < 0x3e0 || relative_addr >= 0x500)
151     return 0;
152     }
153    
154     debug(") ]\n");
155     } else {
156     /* debug("[ turbochannel: write to 0x%08lx: 0x%08x ]\n",
157     (long)relative_addr, (int)idata); */
158     }
159    
160     if (writeflag == MEM_READ)
161     memory_writemax64(cpu, data, len, odata);
162    
163     return 1;
164     }
165    
166    
167     /*
168     * dev_turbochannel_init():
169     *
170     * This is a generic turbochannel card device. device_name should point
171     * to a string such as "PMAG-BA".
172     *
173     * TODO: When running for example dual-head, maybe the name of each
174     * framebuffer should include the card slot number?
175     */
176     void dev_turbochannel_init(struct machine *machine, struct memory *mem,
177     int slot_nr, uint64_t baseaddr, uint64_t endaddr,
178     char *device_name, int irq)
179     {
180     struct vfb_data *fb;
181     struct turbochannel_data *d;
182     int rom_offset = 0x3c0000;
183     int rom_length = DEV_TURBOCHANNEL_LEN;
184     int rom_skip = 0;
185     char *name2;
186    
187     if (device_name == NULL)
188     return;
189    
190     if (strlen(device_name) > 8) {
191     fprintf(stderr, "dev_turbochannel_init(): bad device_name\n");
192     exit(1);
193     }
194    
195     d = malloc(sizeof(struct turbochannel_data));
196     if (d == NULL) {
197     fprintf(stderr, "out of memory\n");
198     exit(1);
199     }
200     memset(d, 0, sizeof(struct turbochannel_data));
201     d->slot_nr = slot_nr;
202     d->baseaddr = baseaddr;
203     d->endaddr = endaddr;
204     d->irq = irq;
205    
206     strcpy(d->device_name, device_name);
207    
208     strncpy(d->card_firmware_version, "V5.3a ", 8);
209     strncpy(d->card_vendor_name, "DEC ", 8);
210     strncpy(d->card_firmware_type, "TCF0", 4);
211    
212     memset(d->card_module_name, ' ', 8);
213     strncpy(d->card_module_name, device_name, strlen(device_name));
214    
215     /*
216     * According to NetBSD/pmax:
217     *
218     * PMAD-AA: le1 at tc0 slot 2 offset 0x0: address 00:00:00:00:00:00
219     * PMAG-AA: mfb0 at tc0 slot 2 offset 0x0: 1280x1024x8
220     * PMAG-BA: cfb0 at tc0 slot 2 offset 0x0cfb0: 1024x864x8
221     * PMAG-CA: px0 at tc0 slot 2 offset 0x0: 2D, 4x1 stamp, 8 plane
222     * (PMAG-DA,EA,FA,FB are also pixelstamps)
223     * PMAG-DV: xcfb0 at tc0 slot 2 offset 0x0: 1024x768x8
224     * PMAG-JA: "truecolor" in Ultrix
225     * PMAGB-BA: sfb0 at tc0 slot 0 offset 0x0: 0x0x8
226     * PMAGB-VA: sfb0 at tc0 slot 2 offset 0x0: 0x0x8
227     * PMAZ-AA: asc0 at tc0 slot 2 offset 0x0: NCR53C94, 25MHz, SCSI ID 7
228     *
229     * PMAF-FA: fta0 at tc0 slot 0 (fddi network, "DEC", "V1.0b")
230     */
231    
232     if (strcmp(device_name, "PMAD-AA")==0) {
233     /* le in NetBSD, Lance ethernet */
234     dev_le_init(machine, mem, baseaddr, 0, 0, irq, DEV_LE_LENGTH);
235     /* One ROM at 0x1c03e0, and one at 0x3c0000. */
236     rom_skip = 0x300;
237     rom_offset = 0x1c0000;
238     rom_length = 0x201000;
239     } else if (strcmp(device_name, "PMAZ-AA")==0) {
240     /* asc in NetBSD, SCSI */
241     dev_asc_init(machine, mem, baseaddr, irq, d,
242     DEV_ASC_DEC, NULL, NULL);
243     rom_offset = 0xc0000;
244     /* There is a copy at 0x0, at least that's where Linux
245     looks for the rom signature */
246     } else if (strcmp(device_name, "PMAG-AA")==0) {
247     /* mfb in NetBSD */
248     fb = dev_fb_init(machine, mem, baseaddr + VFB_MFB_VRAM,
249     VFB_GENERIC, 1280, 1024, 2048, 1024, 8, device_name, 1);
250     /* bt455 = palette, bt431 = cursor */
251     dev_bt455_init(mem, baseaddr + VFB_MFB_BT455, fb);
252     dev_bt431_init(mem, baseaddr + VFB_MFB_BT431, fb, 8);
253     rom_offset = 0;
254     } else if (strcmp(device_name, "PMAG-BA")==0) {
255     /* cfb in NetBSD */
256     fb = dev_fb_init(machine, mem, baseaddr, VFB_GENERIC,
257     1024,864, 1024,1024,8, device_name, 1);
258     dev_bt459_init(machine, mem, baseaddr + VFB_CFB_BT459,
259     baseaddr + 0x300000, fb, 8, irq, BT459_BA);
260     /* ROM at both 0x380000 and 0x3c0000? */
261     rom_offset = 0x380000;
262     rom_length = 0x080000;
263     } else if (strcmp(device_name, "PMAGB-BA")==0) {
264     /* sfb in NetBSD */
265     /* TODO: This is not working with Ultrix yet. */
266     fb = dev_fb_init(machine, mem, baseaddr + SFB_OFFSET_VRAM,
267     VFB_GENERIC, 1280,1024, 1280,1024,8, device_name, 1);
268     dev_sfb_init(machine, mem, baseaddr + SFB_ASIC_OFFSET, fb);
269     /* TODO: the CLEAR doesn't get through, as the address
270     range is already in use by the asic */
271     dev_bt459_init(machine, mem, baseaddr + SFB_OFFSET_BT459,
272     baseaddr + SFB_CLEAR, fb, 8, irq, BT459_BBA);
273     rom_offset = 0x0; /* ? TODO */
274     } else if (strcmp(device_name, "PMAG-CA")==0) {
275     /* px in NetBSD */
276     dev_px_init(machine, mem, baseaddr, DEV_PX_TYPE_PX, irq);
277     rom_offset = 0x3c0000;
278     } else if (strcmp(device_name, "PMAG-DA")==0) {
279     /* pxg in NetBSD */
280     dev_px_init(machine, mem, baseaddr, DEV_PX_TYPE_PXG, irq);
281     rom_offset = 0x3c0000;
282     } else if (strcmp(device_name, "PMAG-EA")==0) {
283     /* pxg+ in NetBSD: TODO (not supported by the kernel
284     I've tried) */
285     fatal("TODO (see dev_turbochannel.c)\n");
286     rom_offset = 0x3c0000;
287     } else if (strcmp(device_name, "PMAG-FA")==0) {
288     /* "pxg+ Turbo" in NetBSD */
289     dev_px_init(machine, mem, baseaddr,
290     DEV_PX_TYPE_PXGPLUSTURBO, irq);
291     rom_offset = 0x3c0000;
292     } else if (strcmp(device_name, "PMAG-DV")==0) {
293     /* xcfb in NetBSD: TODO */
294     fb = dev_fb_init(machine, mem, baseaddr + 0x2000000,
295     VFB_DEC_MAXINE, 0, 0, 0, 0, 0, "PMAG-DV", 1);
296     /* TODO: not yet usable, needs a IMS332 vdac */
297     rom_offset = 0x3c0000;
298     } else if (strcmp(device_name, "PMAG-JA")==0) {
299     /* "Truecolor", mixed 8- and 24-bit */
300     dev_pmagja_init(machine, mem, baseaddr, irq);
301     rom_offset = 0; /* NOTE: 0, not 0x3c0000 */
302     } else if (strcmp(device_name, "PMAG-RO")==0) {
303     /* This works at least B/W in Ultrix, so far. */
304     fb = dev_fb_init(machine, mem, baseaddr + 0x200000,
305     VFB_GENERIC, 1280,1024, 1280,1024, 8, "PMAG-RO", 1);
306     /* TODO: bt463 at offset 0x040000, not bt459 */
307     dev_bt459_init(machine, mem, baseaddr + 0x40000, 0,
308     fb, 8, irq, 0); /* TODO: type */
309     dev_bt431_init(mem, baseaddr + 0x40010, fb, 8); /* cursor */
310     rom_offset = 0x3c0000;
311     } else if (device_name[0] == '\0') {
312     /* If this slot is empty, then occupy the entire
313     4MB slot address range: */
314     rom_offset = 0;
315     rom_length = 4*1048576;
316     } else {
317     fatal("warning: unknown TURBOchannel device name \"%s\"\n",
318     device_name);
319     }
320    
321     d->rom_skip = rom_skip;
322    
323     name2 = malloc(strlen(device_name) + 30);
324     if (name2 == NULL) {
325     fprintf(stderr, "out of memory in dev_turbochannel_init()\n");
326     exit(1);
327     }
328     if (*device_name)
329     sprintf(name2, "turbochannel [%s]", device_name);
330     else
331     sprintf(name2, "turbochannel");
332    
333     memory_device_register(mem, name2, baseaddr + rom_offset + rom_skip,
334     rom_length-rom_skip, dev_turbochannel_access, d, MEM_DEFAULT, NULL);
335     }
336    

  ViewVC Help
Powered by ViewVC 1.1.26