/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26