/[gxemul]/upstream/0.4.5.1/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

Contents of /upstream/0.4.5.1/src/devices/dev_turbochannel.c

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26