/[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 22 - (show annotations)
Mon Oct 8 16:19:37 2007 UTC (16 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 7070 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 /*
2 * Copyright (C) 2005-2006 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.16 2006/02/09 20:02:59 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 struct pcic_data *d = malloc(sizeof(struct pcic_data));
216
217 if (d == NULL) {
218 fprintf(stderr, "out of memory\n");
219 exit(1);
220 }
221 memset(d, 0, sizeof(struct pcic_data));
222 d->irq_nr = devinit->irq_nr;
223
224 memory_device_register(devinit->machine->memory, devinit->name,
225 devinit->addr, DEV_PCIC_LENGTH,
226 dev_pcic_access, (void *)d, DM_DEFAULT, NULL);
227
228 /* TODO: this shouldn't be hardcoded for hpcmips here! */
229 memory_device_register(devinit->machine->memory, "pcic_cis",
230 0x10070000, 0x1000, dev_pcic_cis_access, (void *)d,
231 DM_DEFAULT, NULL);
232
233 /* TODO: find out a good way to specify the address, and the IRQ! */
234 /* IRQ 8 + 32 + 9 */
235 device_add(devinit->machine, "wdc addr=0x14000180 irq=49");
236
237 /* TODO: Linux/MobilePro looks at 0x14000170 and 0x1f0... */
238 /* Yuck. Now there are two. How should this be solved nicely? */
239 device_add(devinit->machine, "wdc addr=0x140001f0 irq=49");
240
241 return 1;
242 }
243

  ViewVC Help
Powered by ViewVC 1.1.26