Fix typo in kernel option.
[dragonfly.git] / usr.sbin / config / mkioconf.c
blob2bd374e7987f82e48c6b0d47c4ca05df15598ff9
1 /*
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
7 * are met:
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
31 * SUCH DAMAGE.
33 * @(#)mkioconf.c 8.2 (Berkeley) 1/21/94
34 * $FreeBSD: src/usr.sbin/config/mkioconf.c,v 1.62 2000/01/29 18:14:59 peter Exp $
35 * $DragonFly: src/usr.sbin/config/mkioconf.c,v 1.9 2005/01/12 00:26:03 cpressey Exp $
38 #include <err.h>
39 #include <stdio.h>
40 #include "y.tab.h"
41 #include "config.h"
44 * build the ioconf.c file
47 static const char *
48 devstr(struct device *dp)
50 static char buf[100];
52 if (dp->d_unit >= 0) {
53 snprintf(buf, sizeof(buf), "%s%d", dp->d_name, dp->d_unit);
54 return(buf);
55 } else
56 return(dp->d_name);
59 static void
60 write_device_resources(FILE *fp, struct device *dp)
62 int count = 0;
63 char buf[80];
65 fprintf(fp, "struct config_resource %s_resources[] = {\n", devstr(dp));
66 if (dp->d_conn) {
67 if (dp->d_connunit >= 0)
68 snprintf(buf, sizeof(buf), "%s%d", dp->d_conn, dp->d_connunit);
69 else
70 snprintf(buf, sizeof(buf), "%s", dp->d_conn);
71 fprintf(fp, "\t{ \"at\",\tRES_STRING,\t{ (long)\"%s\" }},\n", buf);
72 count++;
74 if (dp->d_drive != -2) {
75 fprintf(fp, "\t{ \"drive\",\tRES_INT,\t{ %d }},\n", dp->d_drive);
76 count++;
78 if (dp->d_target != -2) {
79 fprintf(fp, "\t{ \"target\",\tRES_INT,\t{ %d }},\n", dp->d_target);
80 count++;
82 if (dp->d_lun != -2) {
83 fprintf(fp, "\t{ \"lun\",\tRES_INT,\t{ %d }},\n", dp->d_lun);
84 count++;
86 if (dp->d_bus != -2) {
87 fprintf(fp, "\t{ \"bus\",\tRES_INT,\t{ %d }},\n", dp->d_bus);
88 count++;
90 if (dp->d_flags) {
91 fprintf(fp, "\t{ \"flags\",\tRES_INT,\t{ 0x%x }},\n", dp->d_flags);
92 count++;
94 if (dp->d_disabled) {
95 fprintf(fp, "\t{ \"disabled\",\tRES_INT,\t{ %d }},\n", dp->d_disabled);
96 count++;
98 if (dp->d_port) {
99 fprintf(fp, "\t{ \"port\",\tRES_INT,\t { %s }},\n", dp->d_port);
100 count++;
102 if (dp->d_portn > 0) {
103 fprintf(fp, "\t{ \"port\",\tRES_INT,\t{ 0x%x }},\n", dp->d_portn);
104 count++;
106 if (dp->d_maddr > 0) {
107 fprintf(fp, "\t{ \"maddr\",\tRES_INT,\t{ 0x%x }},\n", dp->d_maddr);
108 count++;
110 if (dp->d_msize > 0) {
111 fprintf(fp, "\t{ \"msize\",\tRES_INT,\t{ 0x%x }},\n", dp->d_msize);
112 count++;
114 if (dp->d_drq >= 0) {
115 fprintf(fp, "\t{ \"drq\",\tRES_INT,\t{ %d }},\n", dp->d_drq);
116 count++;
118 if (dp->d_irq > 0) {
119 fprintf(fp, "\t{ \"irq\",\tRES_INT,\t{ %d }},\n", dp->d_irq);
120 count++;
122 fprintf(fp, "};\n");
123 fprintf(fp, "#define %s_count %d\n", devstr(dp), count);
126 static void
127 write_all_device_resources(FILE *fp)
129 struct device *dp;
131 for (dp = dtab; dp != NULL; dp = dp->d_next) {
132 if (dp->d_type != DEVICE)
133 continue;
134 if (dp->d_unit == UNKNOWN)
135 continue;
136 write_device_resources(fp, dp);
140 static void
141 write_devtab(FILE *fp)
143 struct device *dp;
144 int count;
146 write_all_device_resources(fp);
148 count = 0;
149 fprintf(fp, "struct config_device config_devtab[] = {\n");
150 for (dp = dtab; dp != NULL; dp = dp->d_next) {
151 const char *n;
153 n = devstr(dp);
154 if (dp->d_type != DEVICE)
155 continue;
156 if (dp->d_unit == UNKNOWN)
157 continue;
158 fprintf(fp, "\t{ \"%s\",\t%d,\t%s_count,\t%s_resources },\n",
159 dp->d_name, dp->d_unit, n, n);
160 count++;
162 fprintf(fp, "};\n");
163 fprintf(fp, "int devtab_count = %d;\n", count);
166 void
167 newbus_ioconf(void)
169 FILE *fp;
171 fp = fopen(path("ioconf.c.new"), "w");
172 if (fp == NULL)
173 err(1, "%s", path("ioconf.c.new"));
174 fprintf(fp, "/*\n");
175 fprintf(fp, " * I/O configuration.\n");
176 fprintf(fp, " * DO NOT EDIT-- this file is automatically generated.\n");
177 fprintf(fp, " */\n");
178 fprintf(fp, "\n");
179 fprintf(fp, "#include <sys/param.h>\n");
180 fprintf(fp, "\n");
181 fprintf(fp, "/*\n");
182 fprintf(fp, " * New bus architecture devices.\n");
183 fprintf(fp, " */\n");
184 fprintf(fp, "\n");
185 fprintf(fp, "#include <sys/queue.h>\n");
186 fprintf(fp, "#include <sys/sysctl.h>\n");
187 fprintf(fp, "#include <bus/isa/isareg.h>\n");
188 fprintf(fp, "#include <sys/bus_private.h>\n");
189 fprintf(fp, "\n");
191 write_devtab(fp);
193 fclose(fp);
194 moveifchanged(path("ioconf.c.new"), path("ioconf.c"));