/[gxemul]/upstream/0.4.6/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.6/src/devices/dev_turbochannel.c

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26