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
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 $
44 * build the ioconf.c file
48 devstr(struct device
*dp
)
52 if (dp
->d_unit
>= 0) {
53 snprintf(buf
, sizeof(buf
), "%s%d", dp
->d_name
, dp
->d_unit
);
60 write_device_resources(FILE *fp
, struct device
*dp
)
65 fprintf(fp
, "struct config_resource %s_resources[] = {\n", devstr(dp
));
67 if (dp
->d_connunit
>= 0)
68 snprintf(buf
, sizeof(buf
), "%s%d", dp
->d_conn
, dp
->d_connunit
);
70 snprintf(buf
, sizeof(buf
), "%s", dp
->d_conn
);
71 fprintf(fp
, "\t{ \"at\",\tRES_STRING,\t{ (long)\"%s\" }},\n", buf
);
74 if (dp
->d_drive
!= -2) {
75 fprintf(fp
, "\t{ \"drive\",\tRES_INT,\t{ %d }},\n", dp
->d_drive
);
78 if (dp
->d_target
!= -2) {
79 fprintf(fp
, "\t{ \"target\",\tRES_INT,\t{ %d }},\n", dp
->d_target
);
82 if (dp
->d_lun
!= -2) {
83 fprintf(fp
, "\t{ \"lun\",\tRES_INT,\t{ %d }},\n", dp
->d_lun
);
86 if (dp
->d_bus
!= -2) {
87 fprintf(fp
, "\t{ \"bus\",\tRES_INT,\t{ %d }},\n", dp
->d_bus
);
91 fprintf(fp
, "\t{ \"flags\",\tRES_INT,\t{ 0x%x }},\n", dp
->d_flags
);
95 fprintf(fp
, "\t{ \"disabled\",\tRES_INT,\t{ %d }},\n", dp
->d_disabled
);
99 fprintf(fp
, "\t{ \"port\",\tRES_INT,\t { %s }},\n", dp
->d_port
);
102 if (dp
->d_portn
> 0) {
103 fprintf(fp
, "\t{ \"port\",\tRES_INT,\t{ 0x%x }},\n", dp
->d_portn
);
106 if (dp
->d_maddr
> 0) {
107 fprintf(fp
, "\t{ \"maddr\",\tRES_INT,\t{ 0x%x }},\n", dp
->d_maddr
);
110 if (dp
->d_msize
> 0) {
111 fprintf(fp
, "\t{ \"msize\",\tRES_INT,\t{ 0x%x }},\n", dp
->d_msize
);
114 if (dp
->d_drq
>= 0) {
115 fprintf(fp
, "\t{ \"drq\",\tRES_INT,\t{ %d }},\n", dp
->d_drq
);
119 fprintf(fp
, "\t{ \"irq\",\tRES_INT,\t{ %d }},\n", dp
->d_irq
);
123 fprintf(fp
, "#define %s_count %d\n", devstr(dp
), count
);
127 write_all_device_resources(FILE *fp
)
131 for (dp
= dtab
; dp
!= NULL
; dp
= dp
->d_next
) {
132 if (dp
->d_type
!= DEVICE
)
134 if (dp
->d_unit
== UNKNOWN
)
136 write_device_resources(fp
, dp
);
141 write_devtab(FILE *fp
)
146 write_all_device_resources(fp
);
149 fprintf(fp
, "struct config_device config_devtab[] = {\n");
150 for (dp
= dtab
; dp
!= NULL
; dp
= dp
->d_next
) {
154 if (dp
->d_type
!= DEVICE
)
156 if (dp
->d_unit
== UNKNOWN
)
158 fprintf(fp
, "\t{ \"%s\",\t%d,\t%s_count,\t%s_resources },\n",
159 dp
->d_name
, dp
->d_unit
, n
, n
);
163 fprintf(fp
, "int devtab_count = %d;\n", count
);
171 fp
= fopen(path("ioconf.c.new"), "w");
173 err(1, "%s", path("ioconf.c.new"));
175 fprintf(fp
, " * I/O configuration.\n");
176 fprintf(fp
, " * DO NOT EDIT-- this file is automatically generated.\n");
177 fprintf(fp
, " */\n");
179 fprintf(fp
, "#include <sys/param.h>\n");
182 fprintf(fp
, " * New bus architecture devices.\n");
183 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");
194 moveifchanged(path("ioconf.c.new"), path("ioconf.c"));