/[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 22 - (hide annotations)
Mon Oct 8 16:19:37 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 11248 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.1121 2006/02/18 21:03:08 debug Exp $
20051126	Cobalt and PReP now work with the 21143 NIC.
		Continuing on Alpha dyntrans things.
		Fixing some more left-shift-by-24 to unsigned.
20051127	Working on OpenFirmware emulation; major cleanup/redesign.
		Progress on MacPPC emulation: NetBSD detects two CPUs (when
		running with -n 2), framebuffer output (for text) works.
		Adding quick-hack Bandit PCI controller and "gc" interrupt
		controller for MacPPC.
20051128	Changing from a Bandit to a Uni-North controller for macppc.
		Continuing on OpenFirmware and MacPPC emulation in general
		(obio controller, and wdc attached to the obio seems to work).
20051129	More work on MacPPC emulation (adding a dummy ADB controller).
		Continuing the PCI bus cleanup (endianness and tag composition)
		and rewriting all PCI controllers' access functions.
20051130	Various minor PPC dyntrans optimizations.
		Manually inlining some parts of the framebuffer redraw routine.
		Slowly beginning the conversion of the old MIPS emulation into
		dyntrans (but this will take quite some time to get right).
		Generalizing quick_pc_to_pointers.
20051201	Documentation update (David Muse has made available a kernel
		which simplifies Debian/DECstation installation).
		Continuing on the ADB bus controller.
20051202	Beginning a rewrite of the Zilog serial controller (dev_zs).
20051203	Continuing on the zs rewrite (now called dev_z8530); conversion
		to devinit style.
		Reworking some of the input-only vs output-only vs input-output
		details of src/console.c, better warning messages, and adding
		a debug dump.
		Removing the concept of "device state"; it wasn't really used.
		Changing some debug output (-vv should now be used to show all
		details about devices and busses; not shown during normal
		startup anymore).
		Beginning on some SPARC instruction disassembly support.
20051204	Minor PPC updates (WALNUT skeleton stuff).
		Continuing on the MIPS dyntrans rewrite.
		More progress on the ADB controller (a keyboard is "detected"
		by NetBSD and OpenBSD).
		Downgrading OpenBSD/arc as a guest OS from "working" to
		"almost working" in the documentation.
		Progress on Algor emulation ("v3" PCI controller).
20051205	Minor updates.
20051207	Sorting devices according to address; this reduces complexity
		of device lookups from O(n) to O(log n) in memory_rw (but no
		real performance increase (yet) in experiments).
20051210	Beginning the work on native dyntrans backends (by making a
		simple skeleton; so far only for Alpha hosts).
20051211	Some very minor SPARC updates.
20051215	Fixing a bug in the MIPS mul (note: not mult) instruction,
		so it also works with non-64-bit emulation. (Thanks to Alec
		Voropay for noticing the problem.)
20051216	More work on the fake/empty/simple/skeleton/whatever backend;
		performance doesn't increase, so this isn't really worth it,
		but it was probably worth it to prepare for a real backend
		later.
20051219	More instr call statistics gathering and analysis stuff.
20051220	Another fix for MIPS 'mul'. Also converting mul and {d,}cl{o,z}
		to dyntrans.
		memory_ppc.c syntax error fix (noticed by Peter Valchev).
		Beginning to move out machines from src/machine.c into
		individual files in src/machines (in a way similar to the
		autodev system for devices).
20051222	Updating the documentation regarding NetBSD/pmax 3.0.
20051223	- " - NetBSD/cats 3.0.
20051225	- " - NetBSD/hpcmips 3.0.
20051226	Continuing on the machine registry redesign.
		Adding support for ARM rrx (33-bit rotate).
		Fixing some signed/unsigned issues (exposed by gcc -W).
20051227	Fixing the bug which prevented a NetBSD/prep 3.0 install kernel
		from starting (triggered when an mtmsr was the last instruction
		on a page). Unfortunately not enough to get the kernel to run
		as well as the 2.1 kernels did.
20051230	Some dyntrans refactoring.
20051231	Continuing on the machine registry redesign.
20060101-10	Continuing... moving more machines. Moving MD interrupt stuff
		from machine.c into a new src/machines/interrupts.c.
20060114	Adding various mvmeppc machine skeletons.
20060115	Continuing on mvme* stuff. NetBSD/mvmeppc prints boot messages
		(for MVME1600) and reaches the root device prompt, but no
		specific hardware devices are emulated yet.
20060116	Minor updates to the mvme1600 emulation mode; the Eagle PCI bus
		seems to work without much modification, and a 21143 can be
		detected, interrupts might work (but untested so far).
		Adding a fake MK48Txx (mkclock) device, for NetBSD/mvmeppc.
20060121	Adding an aux control register for ARM. (A BIG thank you to
		Olivier Houchard for tracking down this bug.)
20060122	Adding more ARM instructions (smulXY), and dev_iq80321_7seg.
20060124	Adding disassembly of more ARM instructions (mia*, mra/mar),
		and some semi-bogus XScale and i80321 registers.
20060201-02	Various minor updates. Moving the last machines out of
		machine.c.
20060204	Adding a -c command line option, for running debugger commands
		before the simulation starts, but after all files have been
		loaded.
		Minor iq80321-related updates.
20060209	Minor hacks (DEVINIT macro, etc).
		Preparing for the generalization of the 64-bit dyntrans address
		translation subsystem.
20060216	Adding ARM ldrd (double-register load).
20060217	Continuing on various ARM-related stuff.
20060218	More progress on the ATA/wdc emulation for NetBSD/iq80321.
		NetBSD/evbarm can now be installed :-)  Updating the docs, etc.
		Continuing on Algor emulation.

==============  RELEASE 0.3.8  ==============


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

  ViewVC Help
Powered by ViewVC 1.1.26