xref: /original-bsd/usr.sbin/config/mkioconf.c (revision f0fd5f8a)
1 /*	mkioconf.c	2.5	82/10/25	*/
2 
3 #include <stdio.h>
4 #include "y.tab.h"
5 #include "config.h"
6 
7 /*
8  * build the ioconf.c file
9  */
10 char	*qu();
11 char	*intv();
12 
13 #if MACHINE_VAX
14 vax_ioconf()
15 {
16 	register struct device *dp, *mp, *np;
17 	register int uba_n, slave;
18 	FILE *fp;
19 
20 	fp = fopen(path("ioconf.c"), "w");
21 	if (fp == 0) {
22 		perror(path("ioconf.c"));
23 		exit(1);
24 	}
25 	fprintf(fp, "#include \"../h/param.h\"\n");
26 	fprintf(fp, "#include \"../h/pte.h\"\n");
27 	fprintf(fp, "#include \"../h/buf.h\"\n");
28 	fprintf(fp, "#include \"../h/map.h\"\n");
29 	fprintf(fp, "#include \"../h/vm.h\"\n");
30 	fprintf(fp, "\n");
31 	fprintf(fp, "#include \"../vaxmba/mbavar.h\"\n");
32 	fprintf(fp, "#include \"../vaxuba/ubavar.h\"\n\n");
33 	fprintf(fp, "\n");
34 	fprintf(fp, "#define C (caddr_t)\n\n");
35 	/*
36 	 * First print the mba initialization structures
37 	 */
38 	if (seen_mba) {
39 		for (dp = dtab; dp != 0; dp = dp->d_next) {
40 			mp = dp->d_conn;
41 			if (mp == 0 || mp == TO_NEXUS ||
42 			    !eq(mp->d_name, "mba"))
43 				continue;
44 			fprintf(fp, "extern struct mba_driver %sdriver;\n",
45 			    dp->d_name);
46 		}
47 		fprintf(fp, "\nstruct mba_device mbdinit[] = {\n");
48 		fprintf(fp, "\t/* Device,  Unit, Mba, Drive, Dk */\n");
49 		for (dp = dtab; dp != 0; dp = dp->d_next) {
50 			mp = dp->d_conn;
51 			if (dp->d_unit == QUES || mp == 0 ||
52 			    mp == TO_NEXUS || !eq(mp->d_name, "mba"))
53 				continue;
54 			if (dp->d_addr) {
55 				printf("can't specify csr address on mba for %s%d\n",
56 				    dp->d_name, dp->d_unit);
57 				continue;
58 			}
59 			if (dp->d_vec != 0) {
60 				printf("can't specify vector for %s%d on mba\n",
61 				    dp->d_name, dp->d_unit);
62 				continue;
63 			}
64 			if (dp->d_drive == UNKNOWN) {
65 				printf("drive not specified for %s%d\n",
66 				    dp->d_name, dp->d_unit);
67 				continue;
68 			}
69 			if (dp->d_slave != UNKNOWN) {
70 				printf("can't specify slave number for %s%d\n",
71 				    dp->d_name, dp->d_unit);
72 				continue;
73 			}
74 			fprintf(fp,
75 				"\t{ &%sdriver, %d,   %s,  %s,    %d },\n",
76 				dp->d_name, dp->d_unit, qu(mp->d_unit),
77 				qu(dp->d_drive), dp->d_dk);
78 		}
79 		fprintf(fp, "\t0\n};\n\n");
80 		/*
81 		 * Print the mbsinit structure
82 		 * Driver Controller Unit Slave
83 		 */
84 		fprintf(fp, "struct mba_slave mbsinit [] = {\n");
85 		fprintf(fp, "\t/* Driver,  Ctlr, Unit, Slave */\n");
86 		for (dp = dtab; dp != 0; dp = dp->d_next) {
87 			/*
88 			 * All slaves are connected to something which
89 			 * is connected to the massbus.
90 			 */
91 			if ((mp = dp->d_conn) == 0 || mp == TO_NEXUS)
92 				continue;
93 			np = mp->d_conn;
94 			if (np == 0 || np == TO_NEXUS ||
95 			    !eq(np->d_name, "mba"))
96 				continue;
97 			fprintf(fp,
98 			    "\t{ &%sdriver, %s,  %2d,    %s },\n",
99 			    mp->d_name, qu(mp->d_unit), dp->d_unit,
100 			    qu(dp->d_slave));
101 		}
102 		fprintf(fp, "\t0\n};\n\n");
103 	}
104 	/*
105 	 * Now generate interrupt vectors for the unibus
106 	 */
107 	for (dp = dtab; dp != 0; dp = dp->d_next) {
108 		if (dp->d_vec != 0) {
109 			struct idlst *ip;
110 			mp = dp->d_conn;
111 			if (mp == 0 || mp == TO_NEXUS ||
112 			    !eq(mp->d_name, "uba"))
113 				continue;
114 			fprintf(fp,
115 			    "extern struct uba_driver %sdriver;\n",
116 			    dp->d_name);
117 			fprintf(fp, "extern ");
118 			ip = dp->d_vec;
119 			for (;;) {
120 				fprintf(fp, "X%s%d()", ip->id, dp->d_unit);
121 				ip = ip->id_next;
122 				if (ip == 0)
123 					break;
124 				fprintf(fp, ", ");
125 			}
126 			fprintf(fp, ";\n");
127 			fprintf(fp, "int\t (*%sint%d[])() = { ", dp->d_name,
128 			    dp->d_unit, dp->d_unit);
129 			ip = dp->d_vec;
130 			for (;;) {
131 				fprintf(fp, "X%s%d", ip->id, dp->d_unit);
132 				ip = ip->id_next;
133 				if (ip == 0)
134 					break;
135 				fprintf(fp, ", ");
136 			}
137 			fprintf(fp, ", 0 } ;\n");
138 		}
139 	}
140 	fprintf(fp, "\nstruct uba_ctlr ubminit[] = {\n");
141 	fprintf(fp, "/*\t driver,\tctlr,\tubanum,\talive,\tintr,\taddr */\n");
142 	for (dp = dtab; dp != 0; dp = dp->d_next) {
143 		mp = dp->d_conn;
144 		if (dp->d_type != CONTROLLER || mp == TO_NEXUS || mp == 0 ||
145 		    !eq(mp->d_name, "uba"))
146 			continue;
147 		if (dp->d_vec == 0) {
148 			printf("must specify vector for %s%d\n",
149 			    dp->d_name, dp->d_unit);
150 			continue;
151 		}
152 		if (dp->d_addr == 0) {
153 			printf("must specify csr address for %s%d\n",
154 			    dp->d_name, dp->d_unit);
155 			continue;
156 		}
157 		if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
158 			printf("drives need their own entries; dont ");
159 			printf("specify drive or slave for %s%d\n",
160 			    dp->d_name, dp->d_unit);
161 			continue;
162 		}
163 		if (dp->d_flags) {
164 			printf("controllers (e.g. %s%d) ",
165 			    dp->d_name, dp->d_unit);
166 			printf("don't have flags, only devices do\n");
167 			continue;
168 		}
169 		fprintf(fp,
170 		    "\t{ &%sdriver,\t%d,\t%s,\t0,\t%sint%d, C 0%o },\n",
171 		    dp->d_name, dp->d_unit, qu(mp->d_unit),
172 		    dp->d_name, dp->d_unit, dp->d_addr);
173 	}
174 	fprintf(fp, "\t0\n};\n");
175 /* unibus devices */
176 	fprintf(fp, "\nstruct uba_device ubdinit[] = {\n");
177 	fprintf(fp,
178 "\t/* driver,  unit, ctlr,  ubanum, slave,   intr,    addr,    dk, flags*/\n");
179 	for (dp = dtab; dp != 0; dp = dp->d_next) {
180 		mp = dp->d_conn;
181 		if (dp->d_unit == QUES || dp->d_type != DEVICE || mp == 0 ||
182 		    mp == TO_NEXUS || mp->d_type == MASTER ||
183 		    eq(mp->d_name, "mba"))
184 			continue;
185 		np = mp->d_conn;
186 		if (np != 0 && np != TO_NEXUS && eq(np->d_name, "mba"))
187 			continue;
188 		np = 0;
189 		if (eq(mp->d_name, "uba")) {
190 			if (dp->d_vec == 0) {
191 				printf("must specify vector for device %s%d\n",
192 				    dp->d_name, dp->d_unit);
193 				continue;
194 			}
195 			if (dp->d_addr == 0) {
196 				printf("must specify csr for device %s%d\n",
197 				    dp->d_name, dp->d_unit);
198 				continue;
199 			}
200 			if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
201 				printf("drives/slaves can be specified ");
202 				printf("only for controllers, ");
203 				printf("not for device %s%d\n",
204 				    dp->d_name, dp->d_unit);
205 				continue;
206 			}
207 			uba_n = mp->d_unit;
208 			slave = QUES;
209 		} else {
210 			if ((np = mp->d_conn) == 0) {
211 				printf("%s%d isn't connected to anything ",
212 				    mp->d_name, mp->d_unit);
213 				printf(", so %s%d is unattached\n",
214 				    dp->d_name, dp->d_unit);
215 				continue;
216 			}
217 			uba_n = np->d_unit;
218 			if (dp->d_drive == UNKNOWN) {
219 				printf("must specify ``drive number'' ");
220 				printf("for %s%d\n", dp->d_name, dp->d_unit);
221 				continue;
222 			}
223 			/* NOTE THAT ON THE UNIBUS ``drive'' IS STORED IN */
224 			/* ``SLAVE'' AND WE DON'T WANT A SLAVE SPECIFIED */
225 			if (dp->d_slave != UNKNOWN) {
226 				printf("slave numbers should be given only ");
227 				printf("for massbus tapes, not for %s%d\n",
228 				    dp->d_name, dp->d_unit);
229 				continue;
230 			}
231 			if (dp->d_vec != 0) {
232 				printf("interrupt vectors should not be ");
233 				printf("given for drive %s%d\n",
234 				    dp->d_name, dp->d_unit);
235 				continue;
236 			}
237 			if (dp->d_addr != 0) {
238 				printf("csr addresses should be given only ");
239 				printf("on controllers, not on %s%d\n",
240 				    dp->d_name, dp->d_unit);
241 				continue;
242 			}
243 			slave = dp->d_drive;
244 		}
245 		fprintf(fp,
246 "\t{ &%sdriver,  %2d,   %s,  %s,    %2d,   %s, C 0%-6o,  %d,  0x%x },\n",
247 		    eq(mp->d_name, "uba") ? dp->d_name : mp->d_name, dp->d_unit,
248 		    eq(mp->d_name, "uba") ? " -1" : qu(mp->d_unit), qu(uba_n),
249 		    slave, intv(dp), dp->d_addr, dp->d_dk, dp->d_flags);
250 	}
251 	fprintf(fp, "\t0\n};\n");
252 	(void) fclose(fp);
253 }
254 #endif
255 
256 #if MACHINE_SUN
257 sun_ioconf()
258 {
259 	register struct device *dp, *mp;
260 	register int slave;
261 	FILE *fp;
262 
263 	fp = fopen(path("ioconf.c"), "w");
264 	if (fp == 0) {
265 		perror(path("ioconf.c"));
266 		exit(1);
267 	}
268 	fprintf(fp, "#include \"../h/param.h\"\n");
269 	fprintf(fp, "#include \"../h/buf.h\"\n");
270 	fprintf(fp, "#include \"../h/map.h\"\n");
271 	fprintf(fp, "#include \"../h/vm.h\"\n");
272 	fprintf(fp, "\n");
273 	fprintf(fp, "#include \"../sunmb/mbvar.h\"\n");
274 	fprintf(fp, "\n");
275 	fprintf(fp, "#define C (caddr_t)\n\n");
276 	fprintf(fp, "\n");
277 	/*
278 	 * Now generate interrupt vectors for the Multibus
279 	 */
280 	for (dp = dtab; dp != 0; dp = dp->d_next) {
281 		if (dp->d_pri != 0) {
282 			mp = dp->d_conn;
283 			if (mp == 0 || mp == TO_NEXUS ||
284 			    !eq(mp->d_name, "mb"))
285 				continue;
286 			fprintf(fp, "extern struct mb_driver %sdriver;\n",
287 			    dp->d_name);
288 		}
289 	}
290 	/*
291 	 * Now spew forth the mb_cinfo structure
292 	 */
293 	fprintf(fp, "\nstruct mb_ctlr mbcinit[] = {\n");
294 	fprintf(fp, "/*\t driver,\tctlr,\talive,\taddr,\tintpri */\n");
295 	for (dp = dtab; dp != 0; dp = dp->d_next) {
296 		mp = dp->d_conn;
297 		if (dp->d_type != CONTROLLER || mp == TO_NEXUS || mp == 0 ||
298 		    !eq(mp->d_name, "mb"))
299 			continue;
300 		if (dp->d_pri == 0) {
301 			printf("must specify priority for %s%d\n",
302 			    dp->d_name, dp->d_unit);
303 			continue;
304 		}
305 		if (dp->d_addr == 0) {
306 			printf("must specify csr address for %s%d\n",
307 			    dp->d_name, dp->d_unit);
308 			continue;
309 		}
310 		if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
311 			printf("drives need their own entries; ");
312 			printf("dont specify drive or slave for %s%d\n",
313 			    dp->d_name, dp->d_unit);
314 			continue;
315 		}
316 		if (dp->d_flags) {
317 			printf("controllers (e.g. %s%d) don't have flags, ");
318 			printf("only devices do\n",
319 			    dp->d_name, dp->d_unit);
320 			continue;
321 		}
322 		fprintf(fp, "\t{ &%sdriver,\t%d,\t0,\tC 0x%x,\t%d },\n",
323 		    dp->d_name, dp->d_unit, dp->d_addr, dp->d_pri);
324 	}
325 	fprintf(fp, "\t0\n};\n");
326 	/*
327 	 * Now we go for the mb_device stuff
328 	 */
329 	fprintf(fp, "\nstruct mb_device mbdinit[] = {\n");
330 	fprintf(fp,
331 "\t/* driver,  unit, ctlr,  slave,   addr,    pri,    dk, flags*/\n");
332 	for (dp = dtab; dp != 0; dp = dp->d_next) {
333 		mp = dp->d_conn;
334 		if (dp->d_unit == QUES || dp->d_type != DEVICE || mp == 0 ||
335 		    mp == TO_NEXUS || mp->d_type == MASTER ||
336 		    eq(mp->d_name, "mba"))
337 			continue;
338 		if (eq(mp->d_name, "mb")) {
339 			if (dp->d_pri == 0) {
340 				printf("must specify vector for device %s%d\n",
341 				    dp->d_name, dp->d_unit);
342 				continue;
343 			}
344 			if (dp->d_addr == 0) {
345 				printf("must specify csr for device %s%d\n",
346 				    dp->d_name, dp->d_unit);
347 				continue;
348 			}
349 			if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) {
350 				printf("drives/slaves can be specified only ");
351 				printf("for controllers, not for device %s%d\n",
352 				    dp->d_name, dp->d_unit);
353 				continue;
354 			}
355 			slave = QUES;
356 		} else {
357 			if (mp->d_conn == 0) {
358 				printf("%s%d isn't connected to anything, ",
359 				    mp->d_name, mp->d_unit);
360 				printf("so %s%d is unattached\n",
361 				    dp->d_name, dp->d_unit);
362 				continue;
363 			}
364 			if (dp->d_drive == UNKNOWN) {
365 				printf("must specify ``drive number'' for %s%d\n",
366 				   dp->d_name, dp->d_unit);
367 				continue;
368 			}
369 			/* NOTE THAT ON THE UNIBUS ``drive'' IS STORED IN */
370 			/* ``SLAVE'' AND WE DON'T WANT A SLAVE SPECIFIED */
371 			if (dp->d_slave != UNKNOWN) {
372 				printf("slave numbers should be given only ");
373 				printf("for massbus tapes, not for %s%d\n",
374 				    dp->d_name, dp->d_unit);
375 				continue;
376 			}
377 			if (dp->d_pri != 0) {
378 				printf("interrupt priority should not be ");
379 				printf("given for drive %s%d\n",
380 				    dp->d_name, dp->d_unit);
381 				continue;
382 			}
383 			if (dp->d_addr != 0) {
384 				printf("csr addresses should be given only");
385 				printf("on controllers, not on %s%d\n",
386 				    dp->d_name, dp->d_unit);
387 				continue;
388 			}
389 			slave = dp->d_drive;
390 		}
391 		fprintf(fp,
392 "\t{ &%sdriver,  %2d,   %s,    %2d,   C 0x%x, %d,  %d,  0x%x },\n",
393 		    eq(mp->d_name, "mb") ? dp->d_name : mp->d_name, dp->d_unit,
394 		    eq(mp->d_name, "mb") ? " -1" : qu(mp->d_unit),
395 		    slave, dp->d_addr, dp->d_pri, dp->d_dk, dp->d_flags);
396 	}
397 	fprintf(fp, "\t0\n};\n");
398 	(void) fclose(fp);
399 }
400 #endif
401 
402 char *intv(dev)
403 	register struct device *dev;
404 {
405 	static char buf[20];
406 
407 	if (dev->d_vec == 0)
408 		return ("     0");
409 	return (sprintf(buf, "%sint%d", dev->d_name, dev->d_unit));
410 }
411 
412 char *
413 qu(num)
414 {
415 
416 	if (num == QUES)
417 		return ("'?'");
418 	if (num == UNKNOWN)
419 		return (" -1");
420 	return (sprintf(errbuf, "%3d", num));
421 }
422