1 /* Code to support devices on the DIO (and eventually DIO-II) bus
2 * Copyright (C) 05/1998 Peter Maydell <pmaydell@chiark.greenend.org.uk>
4 * This code has basically these routines at the moment:
5 * int dio_find(u_int deviceid)
6 * Search the list of DIO devices and return the select code
7 * of the next unconfigured device found that matches the given device ID.
8 * Note that the deviceid parameter should be the encoded ID.
9 * This means that framebuffers should pass it as
10 * DIO_ENCODE_ID(DIO_ID_FBUFFER,DIO_ID2_TOPCAT)
11 * (or whatever); everybody else just uses DIO_ID_FOOBAR.
12 * void *dio_scodetoviraddr(int scode)
13 * Return the virtual address corresponding to the given select code.
14 * NB: DIO-II devices will have to be mapped in in this routine!
15 * int dio_scodetoipl(int scode)
16 * Every DIO card has a fixed interrupt priority level. This function
17 * returns it, whatever it is.
18 * const char *dio_scodetoname(int scode)
19 * Return a character string describing this board [might be "" if
20 * not CONFIG_DIO_CONSTANTS]
21 * void dio_config_board(int scode) mark board as configured in the list
22 * void dio_unconfig_board(int scode) mark board as no longer configured
24 * This file is based on the way the Amiga port handles Zorro II cards,
25 * although we aren't so complicated...
27 #include <linux/config.h>
28 #include <linux/kernel.h>
29 #include <linux/types.h>
30 #include <linux/dio.h>
31 #include <linux/slab.h> /* kmalloc() */
32 #include <linux/init.h>
33 #include <asm/hwtest.h> /* hwreg_present() */
34 #include <asm/io.h> /* readb() */
35 /* not a real config option yet! */
36 #define CONFIG_DIO_CONSTANTS
38 #ifdef CONFIG_DIO_CONSTANTS
39 /* We associate each numeric ID with an appropriate descriptive string
40 * using a constant array of these structs.
41 * FIXME: we should be able to arrange to throw away most of the strings
42 * using the initdata stuff. Then we wouldn't need to worry about
43 * carrying them around...
44 * I think we do this by copying them into newly kmalloc()ed memory and
45 * marking the names[] array as .initdata ?
54 #define DIONAME(x) { DIO_ID_##x, DIO_DESC_##x }
55 #define DIOFBNAME(x) { DIO_ENCODE_ID( DIO_ID_FBUFFER, DIO_ID2_##x), DIO_DESC2_##x }
57 static struct dioname names[] =
59 DIONAME(DCA0), DIONAME(DCA0REM), DIONAME(DCA1), DIONAME(DCA1REM),
60 DIONAME(DCM), DIONAME(DCMREM),
62 DIONAME(FHPIB), DIONAME(NHPIB), DIONAME(IHPIB),
63 DIONAME(SCSI0), DIONAME(SCSI1), DIONAME(SCSI2), DIONAME(SCSI3),
65 DIONAME(PARALLEL), DIONAME(VME), DIONAME(DCL), DIONAME(DCLREM),
66 DIONAME(MISC0), DIONAME(MISC1), DIONAME(MISC2), DIONAME(MISC3),
67 DIONAME(MISC4), DIONAME(MISC5), DIONAME(MISC6), DIONAME(MISC7),
68 DIONAME(MISC8), DIONAME(MISC9), DIONAME(MISC10), DIONAME(MISC11),
69 DIONAME(MISC12), DIONAME(MISC13),
70 DIOFBNAME(GATORBOX), DIOFBNAME(TOPCAT), DIOFBNAME(RENAISSANCE),
71 DIOFBNAME(LRCATSEYE), DIOFBNAME(HRCCATSEYE), DIOFBNAME(HRMCATSEYE),
72 DIOFBNAME(DAVINCI), DIOFBNAME(XXXCATSEYE), DIOFBNAME(HYPERION),
73 DIOFBNAME(XGENESIS), DIOFBNAME(TIGER), DIOFBNAME(YGENESIS)
79 #define NUMNAMES (sizeof(names) / sizeof(struct dioname))
81 static const char *unknowndioname
82 = "unknown DIO board -- please email <pmaydell@chiark.greenend.org.uk>!";
84 static const char *dio_getname(int id)
86 /* return pointer to a constant string describing the board with given ID */
88 for (i = 0; i < NUMNAMES; i++)
89 if (names[i].id == id)
92 return unknowndioname;
97 static char dio_no_name[] = { 0 };
98 #define dio_getname(_id) (dio_no_name)
100 #endif /* CONFIG_DIO_CONSTANTS */
102 /* We represent all the DIO boards in the system with a linked list of these structs. */
105 struct dioboard *next; /* link to next struct in list */
106 int ipl; /* IPL of this board */
107 int configured; /* has this board been configured? */
108 int scode; /* select code of this board */
109 int id; /* encoded ID */
113 static struct dioboard *blist = NULL;
115 static int __init dio_find_slow(int deviceid)
117 /* Called to find a DIO device before the full bus scan has run. Basically
118 * only used by the console driver.
119 * We don't do the primary+secondary ID encoding thing here. Maybe we should.
120 * (that would break the topcat detection, though. I need to think about
121 * the whole primary/secondary ID thing.)
126 for (scode = 0; scode < DIO_SCMAX; scode++)
130 if (DIO_SCINHOLE(scode))
133 va = dio_scodetoviraddr(scode);
134 if (!va || !hwreg_present(va + DIO_IDOFF))
135 continue; /* no board present at that select code */
137 /* We aren't very likely to want to use this to get at the IHPIB,
138 * but maybe it's returning the same ID as the card we do want...
140 if (!DIO_ISIHPIB(scode))
145 if (prid == deviceid)
151 /* Aargh: we use 0 for an error return code, but select code 0 exists!
152 * FIXME (trivial, use -1, but requires changes to all the drivers :-< )
154 int dio_find(int deviceid)
160 for (b = blist; b; b = b->next)
161 if (b->id == deviceid && b->configured == 0)
165 return dio_find_slow(deviceid);
168 /* This is the function that scans the DIO space and works out what
169 * hardware is actually present.
171 static int __init dio_init(void)
174 struct dioboard *b, *bprev = NULL;
176 printk("Scanning for DIO devices...\n");
178 for (scode = 0; scode < DIO_SCMAX; ++scode)
180 u_char prid, secid = 0; /* primary, secondary ID bytes */
183 if (DIO_SCINHOLE(scode))
186 va = dio_scodetoviraddr(scode);
187 if (!va || !hwreg_present(va + DIO_IDOFF))
188 continue; /* no board present at that select code */
190 /* Found a board, allocate it an entry in the list */
191 b = kmalloc(sizeof(struct dioboard), GFP_KERNEL);
193 /* read the ID byte(s) and encode if necessary. Note workaround
194 * for broken internal HPIB devices...
196 if (!DIO_ISIHPIB(scode))
201 if (DIO_NEEDSSECID(prid))
203 secid = DIO_SECID(va);
204 b->id = DIO_ENCODE_ID(prid, secid);
211 b->ipl = DIO_IPL(va);
212 b->name = dio_getname(b->id);
213 printk("select code %3d: ipl %d: ID %02X", scode, b->ipl, prid);
214 if (DIO_NEEDSSECID(b->id))
215 printk(":%02X", secid);
216 printk(": %s\n", b->name);
229 subsys_initcall(dio_init);
231 /* Bear in mind that this is called in the very early stages of initialisation
232 * in order to get the virtual address of the serial port for the console...
234 void *dio_scodetoviraddr(int scode)
236 if (scode > DIOII_SCBASE)
238 printk("dio_scodetoviraddr: don't support DIO-II yet!\n");
241 else if (scode > DIO_SCMAX || scode < 0)
243 else if (DIO_SCINHOLE(scode))
245 else if (DIO_ISIHPIB(scode))
246 return (void*)DIO_IHPIBADDR;
248 return (void*)(DIO_VIRADDRBASE + DIO_BASE + scode * 0x10000);
251 int dio_scodetoipl(int scode)
254 for (b = blist; b; b = b->next)
255 if (b->scode == scode)
260 printk("dio_scodetoipl: bad select code %d\n", scode);
267 const char *dio_scodetoname(int scode)
270 for (b = blist; b; b = b->next)
271 if (b->scode == scode)
276 printk("dio_scodetoname: bad select code %d\n", scode);
283 void dio_config_board(int scode)
286 for (b = blist; b; b = b->next)
287 if (b->scode == scode)
291 printk("dio_config_board: bad select code %d\n", scode);
292 else if (b->configured)
293 printk("dio_config_board: board at select code %d already configured\n", scode);
298 void dio_unconfig_board(int scode)
301 for (b = blist; b; b = b->next)
302 if (b->scode == scode)
306 printk("dio_unconfig_board: bad select code %d\n", scode);
307 else if (!b->configured)
308 printk("dio_unconfig_board: board at select code %d not configured\n",