1 |
dpavlin |
4 |
/* |
2 |
dpavlin |
34 |
* Copyright (C) 2003-2007 Anders Gavare. All rights reserved. |
3 |
dpavlin |
4 |
* |
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 |
42 |
* $Id: dev_turbochannel.c,v 1.50 2007/06/15 19:57:34 debug Exp $ |
29 |
dpavlin |
4 |
* |
30 |
dpavlin |
42 |
* COMMENT: TURBOchannel bus framework, used in DECstation machines |
31 |
dpavlin |
4 |
*/ |
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 |
dpavlin |
42 |
#define DEVICE_MAX_NAMELEN 9 |
45 |
dpavlin |
10 |
#define CARD_NAME_BUFLEN 9 |
46 |
|
|
#define CARD_FIRMWARE_BUFLEN 5 |
47 |
|
|
|
48 |
dpavlin |
4 |
struct turbochannel_data { |
49 |
|
|
int slot_nr; |
50 |
|
|
uint64_t baseaddr; |
51 |
|
|
uint64_t endaddr; |
52 |
|
|
|
53 |
|
|
int rom_skip; |
54 |
|
|
|
55 |
dpavlin |
42 |
char device_name[DEVICE_MAX_NAMELEN]; /* NUL-terminated */ |
56 |
dpavlin |
4 |
|
57 |
|
|
/* These should be terminated with spaces */ |
58 |
dpavlin |
10 |
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 |
dpavlin |
4 |
}; |
63 |
|
|
|
64 |
|
|
|
65 |
dpavlin |
22 |
DEVICE_ACCESS(turbochannel) |
66 |
dpavlin |
4 |
{ |
67 |
|
|
struct turbochannel_data *d = extra; |
68 |
|
|
uint64_t idata = 0, odata = 0; |
69 |
|
|
|
70 |
dpavlin |
18 |
if (writeflag == MEM_WRITE) |
71 |
|
|
idata = memory_readmax64(cpu, data, len); |
72 |
dpavlin |
4 |
|
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 |
dpavlin |
34 |
char *device_name, char *irq_path) |
178 |
dpavlin |
4 |
{ |
179 |
|
|
struct vfb_data *fb; |
180 |
|
|
struct turbochannel_data *d; |
181 |
dpavlin |
10 |
int rom_offset=0x3c0000, rom_length=DEV_TURBOCHANNEL_LEN, rom_skip=0; |
182 |
dpavlin |
4 |
char *name2; |
183 |
dpavlin |
10 |
size_t nlen; |
184 |
dpavlin |
4 |
|
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 |
dpavlin |
42 |
CHECK_ALLOCATION(d = malloc(sizeof(struct turbochannel_data))); |
194 |
dpavlin |
4 |
memset(d, 0, sizeof(struct turbochannel_data)); |
195 |
dpavlin |
42 |
|
196 |
dpavlin |
4 |
d->slot_nr = slot_nr; |
197 |
|
|
d->baseaddr = baseaddr; |
198 |
|
|
d->endaddr = endaddr; |
199 |
|
|
|
200 |
dpavlin |
42 |
strlcpy(d->device_name, device_name, DEVICE_MAX_NAMELEN); |
201 |
dpavlin |
4 |
|
202 |
dpavlin |
10 |
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 |
dpavlin |
4 |
|
206 |
|
|
memset(d->card_module_name, ' ', 8); |
207 |
dpavlin |
10 |
memcpy(d->card_module_name, device_name, strlen(device_name)); |
208 |
dpavlin |
4 |
|
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 |
dpavlin |
34 |
dev_le_init(machine, mem, baseaddr, 0, 0, |
229 |
|
|
irq_path, DEV_LE_LENGTH); |
230 |
dpavlin |
4 |
/* 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 |
dpavlin |
34 |
dev_asc_init(machine, mem, baseaddr, irq_path, d, |
237 |
dpavlin |
4 |
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 |
dpavlin |
12 |
VFB_GENERIC, 1280, 1024, 2048, 1024, 8, device_name); |
245 |
dpavlin |
4 |
/* 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 |
dpavlin |
12 |
1024,864, 1024,1024,8, device_name); |
253 |
dpavlin |
4 |
dev_bt459_init(machine, mem, baseaddr + VFB_CFB_BT459, |
254 |
dpavlin |
34 |
baseaddr + 0x300000, fb, 8, irq_path, BT459_BA); |
255 |
dpavlin |
4 |
/* 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 |
dpavlin |
12 |
VFB_GENERIC, 1280,1024, 1280,1024,8, device_name); |
263 |
dpavlin |
4 |
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 |
dpavlin |
34 |
baseaddr + SFB_CLEAR, fb, 8, irq_path, BT459_BBA); |
268 |
dpavlin |
4 |
rom_offset = 0x0; /* ? TODO */ |
269 |
|
|
} else if (strcmp(device_name, "PMAG-CA")==0) { |
270 |
|
|
/* px in NetBSD */ |
271 |
dpavlin |
34 |
dev_px_init(machine, mem, baseaddr, DEV_PX_TYPE_PX, irq_path); |
272 |
dpavlin |
4 |
rom_offset = 0x3c0000; |
273 |
|
|
} else if (strcmp(device_name, "PMAG-DA")==0) { |
274 |
|
|
/* pxg in NetBSD */ |
275 |
dpavlin |
34 |
dev_px_init(machine, mem, baseaddr, DEV_PX_TYPE_PXG, irq_path); |
276 |
dpavlin |
4 |
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 |
dpavlin |
34 |
DEV_PX_TYPE_PXGPLUSTURBO, irq_path); |
286 |
dpavlin |
4 |
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 |
dpavlin |
12 |
VFB_DEC_MAXINE, 0, 0, 0, 0, 0, "PMAG-DV"); |
291 |
dpavlin |
4 |
/* 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 |
dpavlin |
34 |
dev_pmagja_init(machine, mem, baseaddr, irq_path); |
296 |
dpavlin |
4 |
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 |
dpavlin |
12 |
VFB_GENERIC, 1280,1024, 1280,1024, 8, "PMAG-RO"); |
301 |
dpavlin |
4 |
/* TODO: bt463 at offset 0x040000, not bt459 */ |
302 |
|
|
dev_bt459_init(machine, mem, baseaddr + 0x40000, 0, |
303 |
dpavlin |
34 |
fb, 8, irq_path, 0); /* TODO: type */ |
304 |
dpavlin |
4 |
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 |
dpavlin |
10 |
nlen = strlen(device_name) + 30; |
319 |
dpavlin |
42 |
CHECK_ALLOCATION(name2 = malloc(nlen)); |
320 |
|
|
|
321 |
dpavlin |
4 |
if (*device_name) |
322 |
dpavlin |
10 |
snprintf(name2, nlen, "turbochannel [%s]", device_name); |
323 |
dpavlin |
4 |
else |
324 |
dpavlin |
10 |
snprintf(name2, nlen, "turbochannel"); |
325 |
dpavlin |
4 |
|
326 |
|
|
memory_device_register(mem, name2, baseaddr + rom_offset + rom_skip, |
327 |
dpavlin |
20 |
rom_length-rom_skip, dev_turbochannel_access, d, DM_DEFAULT, NULL); |
328 |
dpavlin |
4 |
} |
329 |
|
|
|