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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 34 - (show annotations)
Mon Oct 8 16:21:17 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 7223 byte(s)
++ trunk/HISTORY	(local)
$Id: HISTORY,v 1.1480 2007/02/19 01:34:42 debug Exp $
20061029	Changing usleep(1) calls in the debugger to usleep(10000)
20061107	Adding a new disk image option (-d o...) which sets the ISO9660
		filesystem base offset; also making some other hacks to allow
		NetBSD/dreamcast and homebrew demos/games to boot directly
		from a filesystem image.
		Moving Dreamcast-specific stuff in the documentation to its
		own page (dreamcast.html).
		Adding a border to the Dreamcast PVR framebuffer.
20061108	Adding a -T command line option (again?), for halting the
		emulator on unimplemented memory accesses.
20061109	Continuing on various SH4 and Dreamcast related things.
		The emulator should now halt on more unimplemented device
		accesses, instead of just printing a warning, forcing me to
		actually implement missing stuff :)
20061111	Continuing on SH4 and Dreamcast stuff.
		Adding a bogus Landisk (SH4) machine mode.
20061112	Implementing some parts of the Dreamcast GDROM device. With
		some ugly hacks, NetBSD can (barely) mount an ISO image.
20061113	NetBSD/dreamcast now starts booting from the Live CD image,
		but crashes randomly quite early on in the boot process.
20061122	Beginning on a skeleton interrupt.h and interrupt.c for the
		new interrupt subsystem.
20061124	Continuing on the new interrupt system; taking the first steps
		to attempt to connect CPUs (SuperH and MIPS) and devices
		(dev_cons and SH4 timer interrupts) to it. Many things will
		probably break from now on.
20061125	Converting dev_ns16550, dev_8253 to the new interrupt system.
		Attempting to begin to convert the ISA bus.
20061130	Incorporating a patch from Brian Foley for the configure
		script, which checks for X11 libs in /usr/X11R6/lib64 (which
		is used on some Linux systems).
20061227	Adding a note in the man page about booting from Dreamcast
		CDROM images (i.e. that no external kernel is needed).
20061229	Continuing on the interrupt system rewrite: beginning to
		convert more devices, adding abort() calls for legacy interrupt
		system calls so that everything now _has_ to be rewritten!
		Almost all machine modes are now completely broken.
20061230	More progress on removing old interrupt code, mostly related
		to the ISA bus + devices, the LCA bus (on AlphaBook1), and
		the Footbridge bus (for CATS). And some minor PCI stuff.
		Connecting the ARM cpu to the new interrupt system.
		The CATS, NetWinder, and QEMU_MIPS machine modes now work with
		the new interrupt system :)
20061231	Connecting PowerPC CPUs to the new interrupt system.
		Making PReP machines (IBM 6050) work again.
		Beginning to convert the GT PCI controller (for e.g. Malta
		and Cobalt emulation). Some things work, but not everything.
		Updating Copyright notices for 2007.
20070101	Converting dev_kn02 from legacy style to devinit; the 3max
		machine mode now works with the new interrupt system :-]
20070105	Beginning to convert the SGI O2 machine to the new interrupt
		system; finally converting O2 (IP32) devices to devinit, etc.
20070106	Continuing on the interrupt system redesign/rewrite; KN01
		(PMAX), KN230, and Dreamcast ASIC interrupts should work again,
		moving out stuff from machine.h and devices.h into the
		corresponding devices, beginning the rewrite of i80321
		interrupts, etc.
20070107	Beginning on the rewrite of Eagle interrupt stuff (PReP, etc).
20070117	Beginning the rewrite of Algor (V3) interrupts (finally
		changing dev_v3 into devinit style).
20070118	Removing the "bus" registry concept from machine.h, because
		it was practically meaningless.
		Continuing on the rewrite of Algor V3 ISA interrupts.
20070121	More work on Algor interrupts; they are now working again,
		well enough to run NetBSD/algor. :-)
20070122	Converting VR41xx (HPCmips) interrupts. NetBSD/hpcmips
		can be installed using the new interrupt system :-)
20070123	Making the testmips mode work with the new interrupt system.
20070127	Beginning to convert DEC5800 devices to devinit, and to the
		new interrupt system.
		Converting Playstation 2 devices to devinit, and converting
		the interrupt system. Also fixing a severe bug: the interrupt
		mask register on Playstation 2 is bitwise _toggled_ on writes.
20070128	Removing the dummy NetGear machine mode and the 8250 device
		(which was only used by the NetGear machine).
		Beginning to convert the MacPPC GC (Grand Central) interrupt
		controller to the new interrupt system.
		Converting Jazz interrupts (PICA61 etc.) to the new interrupt
		system. NetBSD/arc can be installed again :-)
		Fixing the JAZZ timer (hardcoding it at 100 Hz, works with
		NetBSD and it is better than a completely dummy timer as it
		was before).
		Converting dev_mp to the new interrupt system, although I
		haven't had time to actually test it yet.
		Completely removing src/machines/interrupts.c, cpu_interrupt
		and cpu_interrupt_ack in src/cpu.c, and
		src/include/machine_interrupts.h! Adding fatal error messages
		+ abort() in the few places that are left to fix.
		Converting dev_z8530 to the new interrupt system.
		FINALLY removing the md_int struct completely from the
		machine struct.
		SH4 fixes (adding a PADDR invalidation in the ITLB replacement
		code in memory_sh.c); the NetBSD/dreamcast LiveCD now runs
		all the way to the login prompt, and can be interacted with :-)
		Converting the CPC700 controller (PCI and interrupt controller
		for PM/PPC) to the new interrupt system.
20070129	Fixing MACE ISA interrupts (SGI IP32 emulation). Both NetBSD/
		sgimips' and OpenBSD/sgi's ramdisk kernels can now be
		interacted with again.
20070130	Moving out the MIPS multi_lw and _sw instruction combinations
		so that they are auto-generated at compile time instead.
20070131	Adding detection of amd64/x86_64 hosts in the configure script,
		for doing initial experiments (again :-) with native code
		generation.
		Adding a -k command line option to set the size of the dyntrans
		cache, and a -B command line option to disable native code
		generation, even if GXemul was compiled with support for
		native code generation for the specific host CPU architecture.
20070201	Experimenting with a skeleton for native code generation.
		Changing the default behaviour, so that native code generation
		is now disabled by default, and has to be enabled by using
		-b on the command line.
20070202	Continuing the native code generation experiments.
		Making PCI interrupts work for Footbridge again.
20070203	More native code generation experiments.
		Removing most of the native code generation experimental code,
		it does not make sense to include any quick hacks like this.
		Minor cleanup/removal of some more legacy MIPS interrupt code.
20070204	Making i80321 interrupts work again (for NetBSD/evbarm etc.),
		and fixing the timer at 100 Hz.
20070206	Experimenting with removing the wdc interrupt slowness hack.
20070207	Lowering the number of dyntrans TLB entries for MIPS from
		192 to 128, resulting in a minor speed improvement.
		Minor optimization to the code invalidation routine in
		cpu_dyntrans.c.
20070208	Increasing (experimentally) the nr of dyntrans instructions per
		loop from 60 to 120.
20070210	Commenting out (experimentally) the dyntrans_device_danger
		detection in memory_rw.c.
		Changing the testmips and baremips machines to use a revision 2
		MIPS64 CPU by default, instead of revision 1.
		Removing the dummy i960, IA64, x86, AVR32, and HP PA-RISC
		files, the PC bios emulation, and the Olivetti M700 (ARC) and
		db64360 emulation modes.
20070211	Adding an "mp" demo to the demos directory, which tests the
		SMP functionality of the testmips machine.
		Fixing PReP interrupts some more. NetBSD/prep now boots again.
20070216	Adding a "nop workaround" for booting Mach/PMAX to the
		documentation; thanks to Artur Bujdoso for the values.
		Converting more of the MacPPC interrupt stuff to the new
		system.
		Beginning to convert BeBox interrupts to the new system.
		PPC603e should NOT have the PPC_NO_DEC flag! Removing it.
		Correcting BeBox clock speed (it was set to 100 in the NetBSD
		bootinfo block, but should be 33000000/4), allowing NetBSD
		to start without using the (incorrect) PPC_NO_DEC hack.
20070217	Implementing (slow) AltiVec vector loads and stores, allowing
		NetBSD/macppc to finally boot using the GENERIC kernel :-)
		Updating the documentation with install instructions for
		NetBSD/macppc.
20070218-19	Regression testing for the release.

==============  RELEASE 0.4.4  ==============


1 /*
2 * Copyright (C) 2005-2007 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_pcic.c,v 1.18 2007/01/21 21:02:57 debug Exp $
29 *
30 * Intel 82365SL PC Card Interface Controller (called "pcic" by NetBSD).
31 *
32 * TODO: Lots of stuff. This is just a quick hack. Don't rely on it.
33 */
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38
39 #include "cpu.h"
40 #include "device.h"
41 #include "emul.h"
42 #include "machine.h"
43 #include "memory.h"
44 #include "misc.h"
45
46 #include "i82365reg.h"
47 #include "pcmciareg.h"
48
49
50 /* #define debug fatal */
51
52 #define DEV_PCIC_LENGTH 2
53
54 struct pcic_data {
55 int irq_nr;
56 int regnr;
57 };
58
59
60 /*
61 * dev_pcic_cis_access():
62 */
63 DEVICE_ACCESS(pcic_cis)
64 {
65 /* struct pcic_data *d = (struct pcic_data *) extra; */
66 uint64_t idata = 0, odata = 0;
67
68 idata = memory_readmax64(cpu, data, len);
69
70 {
71 #if 0
72 /* SMC, PCM Ethernet Adapter, CIS V1.05 (manufacturer 0x108,
73 product 0x105) */
74 unsigned char x[] = {
75 PCMCIA_CISTPL_DEVICE, 3, PCMCIA_DTYPE_FUNCSPEC, 0xff,0xff,
76 PCMCIA_CISTPL_FUNCID, 2, 0x06, 0x00,
77 PCMCIA_CISTPL_MANFID, 4, 0x08, 0x01, 0x05, 0x01,
78 PCMCIA_CISTPL_VERS_1, 0x26,
79 0x04, 0x01, 0x53, 0x4d, 0x43, 0x00, 0x50, 0x43, 0x4d, 0x20,
80 0x45, 0x74, 0x68, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x41,
81 0x64, 0x61, 0x70, 0x74, 0x65, 0x72, 0x00, 0x43, 0x49, 0x53,
82 0x20, 0x56, 0x31, 0x2e, 0x30, 0x35, 0x00, 0xff,
83 PCMCIA_CISTPL_CONFIG, 0x0a,
84 0x02, 0x01, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0xff,
85 PCMCIA_CISTPL_CFTABLE_ENTRY, 0x0b,
86 0xc1, 0x01, 0x70, 0x50, 0xbc, 0x8e, 0x48, 0x40, 0x00,0x02,0xff,
87 /* unhandled CISTPL 22 */
88 0x22, 0x02, 0x01, 0x02,
89 /* unhandled CISTPL 22 */
90 0x22, 0x05, 0x02, 0x80, 0x96, 0x98, 0x00,
91 /* unhandled CISTPL 22 */
92 0x22, 0x02, 0x03, 0x01,
93 /* unhandled CISTPL 22 */
94 0x22, 0x08, 0x04, 0x06, 0x00, 0x00, 0xc0, 0x2f, 0x48, 0xd2,
95 /* unhandled CISTPL 22 */
96 0x22, 0x02, 0x05, 0x01,
97
98 PCMCIA_CISTPL_END, 0
99 };
100 #endif
101
102 /* From http://www.mail-archive.com/freebsd-current@freebsd.
103 org/msg32550.html */
104 unsigned char x[] = {
105 PCMCIA_CISTPL_DEVICE, 3, 0xdc, 0x00, 0xff,
106 PCMCIA_CISTPL_VERS_1, 0x1a,
107 0x04,0x01,0x20,0x00,0x4e,0x69,0x6e,0x6a,0x61,0x41,0x54,0x41,
108 0x2d,0x00,0x56,0x31,0x2e,0x30,0x00,0x41,0x50,0x30,0x30,0x20,
109 0x00,0xff,
110 PCMCIA_CISTPL_CONFIG, 5,
111 0x01,0x23,0x00,0x02,0x03,
112 PCMCIA_CISTPL_CFTABLE_ENTRY, 0x15,
113 0xe1,0x01,0x3d,0x11,0x55,0x1e,0xfc,0x23,0xf0,0x61,0x80,0x01,
114 0x07,0x86,0x03,0x01,0x30,0x68,0xd0,0x10,0x00,
115 #if 0
116 PCMCIA_CISTPL_CFTABLE_ENTRY, 0xf,
117 0x22,0x38,0xf0,0x61,0x90,0x01,0x07,0x96,0x03,0x01,0x30,0x68,
118 0xd0,0x10,0x00,
119 PCMCIA_CISTPL_CFTABLE_ENTRY, 0xf,
120 0x23,0x38,0xf0,0x61,0xa0,0x01,0x07,0xa6,0x03,0x01,0x30,0x68,
121 0xd0,0x10,0x00,
122 #endif
123 PCMCIA_CISTPL_NO_LINK, 0,
124
125 PCMCIA_CISTPL_END, 0
126 };
127
128 relative_addr /= 2;
129 if (relative_addr < sizeof(x))
130 odata = x[relative_addr];
131
132 debug("[ dev_pcic_cis_access: blah blah: addr=0x%x ]\n",
133 (int)relative_addr);
134 }
135
136 if (writeflag == MEM_READ)
137 memory_writemax64(cpu, data, len, odata);
138
139 return 1;
140 }
141
142
143 /*
144 * dev_pcic_access():
145 */
146 DEVICE_ACCESS(pcic)
147 {
148 struct pcic_data *d = (struct pcic_data *) extra;
149 uint64_t idata = 0, odata = 0;
150 int controller_nr, socket_nr;
151
152 if (writeflag == MEM_WRITE)
153 idata = memory_readmax64(cpu, data, len);
154
155 controller_nr = d->regnr & 0x80? 1 : 0;
156 socket_nr = d->regnr & 0x40? 1 : 0;
157
158 switch (relative_addr) {
159 case 0: /* Register select: */
160 if (writeflag == MEM_WRITE)
161 d->regnr = idata;
162 else
163 odata = d->regnr;
164 break;
165 case 1: /* Register access: */
166 switch (d->regnr & 0x3f) {
167 case PCIC_IDENT:
168 /* This causes sockets A and B to be present on
169 controller 0, and only socket A on controller 1. */
170 if (controller_nr == 1 && socket_nr == 1)
171 odata = 0;
172 else
173 odata = PCIC_IDENT_IFTYPE_MEM_AND_IO
174 | PCIC_IDENT_REV_I82365SLR1;
175 break;
176 #if 1
177 case PCIC_INTR:
178 odata = PCIC_INTR_IRQ3;
179 break;
180 #endif
181 case PCIC_CSC:
182 odata = PCIC_CSC_GPI;
183 break;
184 case PCIC_IF_STATUS:
185 odata = PCIC_IF_STATUS_READY
186 | PCIC_IF_STATUS_POWERACTIVE;
187 if (controller_nr == 0 && socket_nr == 0)
188 odata |= PCIC_IF_STATUS_CARDDETECT_PRESENT;
189 break;
190 default:
191 if (writeflag == MEM_WRITE) {
192 debug("[ pcic: unimplemented write to "
193 "controller %i socket %c, regnr %i: "
194 "data=0x%02x ]\n", controller_nr,
195 socket_nr? 'B' : 'A',
196 d->regnr & 0x3f, (int)idata);
197 } else {
198 debug("[ pcic: unimplemented read from "
199 "controller %i socket %c, regnr %i ]\n",
200 controller_nr, socket_nr? 'B' : 'A',
201 d->regnr & 0x3f);
202 }
203 }
204 }
205
206 if (writeflag == MEM_READ)
207 memory_writemax64(cpu, data, len, odata);
208
209 return 1;
210 }
211
212
213 DEVINIT(pcic)
214 {
215 char tmpstr[200];
216 struct pcic_data *d = malloc(sizeof(struct pcic_data));
217
218 if (d == NULL) {
219 fprintf(stderr, "out of memory\n");
220 exit(1);
221 }
222 memset(d, 0, sizeof(struct pcic_data));
223 d->irq_nr = devinit->irq_nr;
224
225 memory_device_register(devinit->machine->memory, devinit->name,
226 devinit->addr, DEV_PCIC_LENGTH,
227 dev_pcic_access, (void *)d, DM_DEFAULT, NULL);
228
229 /* TODO: this shouldn't be hardcoded for hpcmips here! */
230 memory_device_register(devinit->machine->memory, "pcic_cis",
231 0x10070000, 0x1000, dev_pcic_cis_access, (void *)d,
232 DM_DEFAULT, NULL);
233
234 /* TODO: find out a good way to specify the address, and the IRQ! */
235 snprintf(tmpstr, sizeof(tmpstr), "wdc addr=0x14000180 irq=%s.giu.9",
236 devinit->interrupt_path);
237 device_add(devinit->machine, tmpstr);
238
239 /* TODO: Linux/MobilePro looks at 0x14000170 and 0x1f0... */
240 /* Yuck. Now there are two. How should this be solved nicely? */
241 snprintf(tmpstr, sizeof(tmpstr), "wdc addr=0x140001f0 irq=%s.giu.9",
242 devinit->interrupt_path);
243 device_add(devinit->machine, tmpstr);
244
245 return 1;
246 }
247

  ViewVC Help
Powered by ViewVC 1.1.26