/[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 20 - (hide annotations)
Mon Oct 8 16:19:23 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 11372 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.1055 2005/11/25 22:48:36 debug Exp $
20051031	Adding disassembly support for more ARM instructions (clz,
		smul* etc), and adding a hack to support "new tiny" pages
		for StrongARM.
20051101	Minor documentation updates (NetBSD 2.0.2 -> 2.1, and OpenBSD
		3.7 -> 3.8, and lots of testing).
		Changing from 1-sector PIO mode 0 transfers to 128-sector PIO
		mode 3 (in dev_wdc).
		Various minor ARM dyntrans updates (pc-relative loads from
		within the same page as the instruction are now treated as
		constant "mov").
20051102	Re-enabling instruction combinations (they were accidentally
		disabled).
		Dyntrans TLB entries are now overwritten using a round-robin
		scheme instead of randomly. This increases performance.
		Fixing a typo in file.c (thanks to Chuan-Hua Chang for
		noticing it).
		Experimenting with adding ATAPI support to dev_wdc (to make
		emulated *BSD detect cdroms as cdroms, not harddisks).
20051104	Various minor updates.
20051105	Continuing on the ATAPI emulation. Seems to work well enough
		for a NetBSD/cats installation, but not OpenBSD/cats.
		Various other updates.
20051106	Modifying the -Y command line option to allow scaleup with
		certain graphic controllers (only dev_vga so far), not just
		scaledown.
		Some minor dyntrans cleanups.
20051107	Beginning a cleanup up the PCI subsystem (removing the
		read_register hack, etc).
20051108	Continuing the cleanup; splitting up some pci devices into a
		normal autodev device and some separate pci glue code.
20051109	Continuing on the PCI bus stuff; all old pci_*.c have been
		incorporated into normal devices and/or rewritten as glue code
		only, adding a dummy Intel 82371AB PIIX4 for Malta (not really
		tested yet).
		Minor pckbc fix so that Linux doesn't complain.
		Working on the DEC 21143 NIC (ethernet mac rom stuff mostly).
		Various other minor fixes.
20051110	Some more ARM dyntrans fine-tuning (e.g. some instruction
		combinations (cmps followed by conditional branch within the
		same page) and special cases for DPIs with regform when the
		shifter isn't used).
20051111	ARM dyntrans updates: O(n)->O(1) for just-mark-as-non-
		writable in the generic pc_to_pointers function, and some other
		minor hacks.
		Merging Cobalt and evbmips (Malta) ISA interrupt handling,
		and some minor fixes to allow Linux to accept harddisk irqs.
20051112	Minor device updates (pckbc, dec21143, lpt, ...), most
		importantly fixing the ALI M1543/M5229 so that harddisk irqs
		work with Linux/CATS.
20051113	Some more generalizations of the PCI subsystem.
		Finally took the time to add a hack for SCSI CDROM TOCs; this
		enables OpenBSD to use partition 'a' (as needed by the OpenBSD
		installer), and Windows NT's installer to get a bit further.
		Also fixing dev_wdc to allow Linux to detect ATAPI CDROMs.
		Continuing on the DEC 21143.
20051114	Minor ARM dyntrans tweaks; ARM cmps+branch optimization when
		comparing with 0, and generalizing the xchg instr. comb.
		Adding disassembly of ARM mrrc/mcrr and q{,d}{add,sub}.
20051115	Continuing on various PPC things (BATs, other address trans-
		lation things, various loads/stores, BeBox emulation, etc.).
		Beginning to work on PPC interrupt/exception support.
20051116	Factoring out some code which initializes legacy ISA devices
		from those machines that use them (bus_isa).
		Continuing on PPC interrupt/exception support.
20051117	Minor Malta fixes: RTC year offset = 80, disabling a speed hack
		which caused NetBSD to detect a too fast cpu, and adding a new
		hack to make Linux detect a faster cpu.
		Continuing on the Artesyn PM/PPC emulation mode.
		Adding an Algor emulation skeleton (P4032 and P5064);
		implementing some of the basics.
		Continuing on PPC emulation in general; usage of unimplemented
		SPRs is now easier to track, continuing on memory/exception
		related issues, etc.
20051118	More work on PPC emulation (tgpr0..3, exception handling,
		memory stuff, syscalls, etc.).
20051119	Changing the ARM dyntrans code to mostly use cpu->pc, and not
		necessarily use arm reg 15. Seems to work.
		Various PPC updates; continuing on the PReP emulation mode.
20051120	Adding a workaround/hack to dev_mc146818 to allow NetBSD/prep
		to detect the clock.
20051121	More cleanup of the PCI bus (memory and I/O bases, etc).
		Continuing on various PPC things (decrementer and timebase,
		WDCs on obio (on PReP) use irq 13, not 14/15).
20051122	Continuing on the CPC700 controller (interrupts etc) for PMPPC,
		and on PPC stuff in general.
		Finally! After some bug fixes to the virtual to physical addr
		translation, NetBSD/{prep,pmppc} 2.1 reach userland and are
		stable enough to be interacted with.
		More PCI updates; reverse-endian device access for PowerPC etc.
20051123	Generalizing the IEEE floating point subsystem (moving it out
		from src/cpus/cpu_mips_coproc.c into a new src/float_emul.c).
		Input via slave xterms was sometimes not really working; fixing
		this for ns16550, and a warning message is now displayed if
		multiple non-xterm consoles are active.
		Adding some PPC floating point support, etc.
		Various interrupt related updates (dev_wdc, _ns16550, _8259,
		and the isa32 common code in machine.c).
		NetBSD/prep can now be installed! :-) (Well, with some manual
		commands necessary before running sysinst.) Updating the
		documentation and various other things to reflect this.
20051124	Various minor documentation updates.
		Continuing the work on the DEC 21143 NIC.
20051125	LOTS of work on the 21143. Both OpenBSD and NetBSD work fine
		with it now, except that OpenBSD sometimes gives a time-out
		warning.
		Minor documentation updates.

==============  RELEASE 0.3.7  ==============


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

  ViewVC Help
Powered by ViewVC 1.1.26