2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 static char sccsid[] = "@(#)mkioconf.c 8.2 (Berkeley) 1/21/94";
38 static const char rcsid[] =
39 "$FreeBSD: src/usr.sbin/config/mkioconf.c,v 1.62 2000/01/29 18:14:59 peter Exp $";
48 * build the ioconf.c file
52 devstr(struct device *dp)
56 if (dp->d_unit >= 0) {
57 snprintf(buf, sizeof(buf), "%s%d", dp->d_name, dp->d_unit);
64 write_device_resources(FILE *fp, struct device *dp)
69 fprintf(fp, "struct config_resource %s_resources[] = {\n", devstr(dp));
71 if (dp->d_connunit >= 0)
72 snprintf(buf, sizeof(buf), "%s%d", dp->d_conn, dp->d_connunit);
74 snprintf(buf, sizeof(buf), "%s", dp->d_conn);
75 fprintf(fp, "\t{ \"at\",\tRES_STRING,\t{ (long)\"%s\" }},\n", buf);
78 if (dp->d_drive != -2) {
79 fprintf(fp, "\t{ \"drive\",\tRES_INT,\t{ %d }},\n", dp->d_drive);
82 if (dp->d_target != -2) {
83 fprintf(fp, "\t{ \"target\",\tRES_INT,\t{ %d }},\n", dp->d_target);
86 if (dp->d_lun != -2) {
87 fprintf(fp, "\t{ \"lun\",\tRES_INT,\t{ %d }},\n", dp->d_lun);
90 if (dp->d_bus != -2) {
91 fprintf(fp, "\t{ \"bus\",\tRES_INT,\t{ %d }},\n", dp->d_bus);
95 fprintf(fp, "\t{ \"flags\",\tRES_INT,\t{ 0x%x }},\n", dp->d_flags);
99 fprintf(fp, "\t{ \"disabled\",\tRES_INT,\t{ %d }},\n", dp->d_disabled);
103 fprintf(fp, "\t{ \"port\",\tRES_INT,\t { %s }},\n", dp->d_port);
106 if (dp->d_portn > 0) {
107 fprintf(fp, "\t{ \"port\",\tRES_INT,\t{ 0x%x }},\n", dp->d_portn);
110 if (dp->d_maddr > 0) {
111 fprintf(fp, "\t{ \"maddr\",\tRES_INT,\t{ 0x%x }},\n", dp->d_maddr);
114 if (dp->d_msize > 0) {
115 fprintf(fp, "\t{ \"msize\",\tRES_INT,\t{ 0x%x }},\n", dp->d_msize);
118 if (dp->d_drq >= 0) {
119 fprintf(fp, "\t{ \"drq\",\tRES_INT,\t{ %d }},\n", dp->d_drq);
123 fprintf(fp, "\t{ \"irq\",\tRES_INT,\t{ %d }},\n", dp->d_irq);
127 fprintf(fp, "#define %s_count %d\n", devstr(dp), count);
131 write_all_device_resources(FILE *fp)
135 for (dp = dtab; dp != 0; dp = dp->d_next) {
136 if (dp->d_type != DEVICE)
138 if (dp->d_unit == UNKNOWN)
140 write_device_resources(fp, dp);
145 write_devtab(FILE *fp)
150 write_all_device_resources(fp);
153 fprintf(fp, "struct config_device config_devtab[] = {\n");
154 for (dp = dtab; dp != 0; dp = dp->d_next) {
155 char* n = devstr(dp);
156 if (dp->d_type != DEVICE)
158 if (dp->d_unit == UNKNOWN)
160 fprintf(fp, "\t{ \"%s\",\t%d,\t%s_count,\t%s_resources },\n",
161 dp->d_name, dp->d_unit, n, n);
165 fprintf(fp, "int devtab_count = %d;\n", count);
173 fp = fopen(path("ioconf.c.new"), "w");
175 err(1, "%s", path("ioconf.c.new"));
177 fprintf(fp, " * I/O configuration.\n");
178 fprintf(fp, " * DO NOT EDIT-- this file is automatically generated.\n");
179 fprintf(fp, " */\n");
181 fprintf(fp, "#include <sys/param.h>\n");
184 fprintf(fp, " * New bus architecture devices.\n");
185 fprintf(fp, " */\n");
187 fprintf(fp, "#include <sys/queue.h>\n");
188 fprintf(fp, "#include <sys/sysctl.h>\n");
189 if (machine == MACHINE_PC98)
190 fprintf(fp, "#include <pc98/pc98/pc98.h>\n");
192 fprintf(fp, "#include <isa/isareg.h>\n");
193 fprintf(fp, "#include <sys/bus_private.h>\n");
199 moveifchanged(path("ioconf.c.new"), path("ioconf.c"));