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. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)mkioconf.c 8.2 (Berkeley) 1/21/94
30 * $FreeBSD: src/usr.sbin/config/mkioconf.c,v 1.62 2000/01/29 18:14:59 peter Exp $
31 * $DragonFly: src/usr.sbin/config/mkioconf.c,v 1.9 2005/01/12 00:26:03 cpressey Exp $
40 * build the ioconf.c file
44 devstr(struct device
*dp
)
48 if (dp
->d_unit
>= 0) {
49 snprintf(buf
, sizeof(buf
), "%s%d", dp
->d_name
, dp
->d_unit
);
56 write_device_resources(FILE *fp
, struct device
*dp
)
61 fprintf(fp
, "struct config_resource %s_resources[] = {\n", devstr(dp
));
63 if (dp
->d_connunit
>= 0)
64 snprintf(buf
, sizeof(buf
), "%s%d", dp
->d_conn
, dp
->d_connunit
);
66 snprintf(buf
, sizeof(buf
), "%s", dp
->d_conn
);
67 fprintf(fp
, "\t{ \"at\",\tRES_STRING,\t{ (long)\"%s\" }},\n", buf
);
70 if (dp
->d_drive
!= -2) {
71 fprintf(fp
, "\t{ \"drive\",\tRES_INT,\t{ %d }},\n", dp
->d_drive
);
74 if (dp
->d_target
!= -2) {
75 fprintf(fp
, "\t{ \"target\",\tRES_INT,\t{ %d }},\n", dp
->d_target
);
78 if (dp
->d_lun
!= -2) {
79 fprintf(fp
, "\t{ \"lun\",\tRES_INT,\t{ %d }},\n", dp
->d_lun
);
82 if (dp
->d_bus
!= -2) {
83 fprintf(fp
, "\t{ \"bus\",\tRES_INT,\t{ %d }},\n", dp
->d_bus
);
87 fprintf(fp
, "\t{ \"flags\",\tRES_INT,\t{ 0x%x }},\n", dp
->d_flags
);
91 fprintf(fp
, "\t{ \"disabled\",\tRES_INT,\t{ %d }},\n", dp
->d_disabled
);
95 fprintf(fp
, "\t{ \"port\",\tRES_INT,\t { %s }},\n", dp
->d_port
);
98 if (dp
->d_portn
> 0) {
99 fprintf(fp
, "\t{ \"port\",\tRES_INT,\t{ 0x%x }},\n", dp
->d_portn
);
102 if (dp
->d_maddr
> 0) {
103 fprintf(fp
, "\t{ \"maddr\",\tRES_INT,\t{ 0x%x }},\n", dp
->d_maddr
);
106 if (dp
->d_msize
> 0) {
107 fprintf(fp
, "\t{ \"msize\",\tRES_INT,\t{ 0x%x }},\n", dp
->d_msize
);
110 if (dp
->d_drq
>= 0) {
111 fprintf(fp
, "\t{ \"drq\",\tRES_INT,\t{ %d }},\n", dp
->d_drq
);
115 fprintf(fp
, "\t{ \"irq\",\tRES_INT,\t{ %d }},\n", dp
->d_irq
);
119 fprintf(fp
, "#define %s_count %d\n", devstr(dp
), count
);
123 write_all_device_resources(FILE *fp
)
127 for (dp
= dtab
; dp
!= NULL
; dp
= dp
->d_next
) {
128 if (dp
->d_type
!= DEVICE
)
130 if (dp
->d_unit
== UNKNOWN
)
132 write_device_resources(fp
, dp
);
137 write_devtab(FILE *fp
)
142 write_all_device_resources(fp
);
145 fprintf(fp
, "struct config_device config_devtab[] = {\n");
146 for (dp
= dtab
; dp
!= NULL
; dp
= dp
->d_next
) {
150 if (dp
->d_type
!= DEVICE
)
152 if (dp
->d_unit
== UNKNOWN
)
154 fprintf(fp
, "\t{ \"%s\",\t%d,\t%s_count,\t%s_resources },\n",
155 dp
->d_name
, dp
->d_unit
, n
, n
);
159 fprintf(fp
, "int devtab_count = %d;\n", count
);
167 fp
= fopen(path("ioconf.c.new"), "w");
169 err(1, "%s", path("ioconf.c.new"));
171 fprintf(fp
, " * I/O configuration.\n");
172 fprintf(fp
, " * DO NOT EDIT-- this file is automatically generated.\n");
173 fprintf(fp
, " */\n");
175 fprintf(fp
, "#include <sys/param.h>\n");
178 fprintf(fp
, " * New bus architecture devices.\n");
179 fprintf(fp
, " */\n");
181 fprintf(fp
, "#include <sys/queue.h>\n");
182 fprintf(fp
, "#include <sys/sysctl.h>\n");
183 fprintf(fp
, "#include <bus/isa/isareg.h>\n");
184 fprintf(fp
, "#include <sys/bus_private.h>\n");
190 moveifchanged(path("ioconf.c.new"), path("ioconf.c"));