Sun Jun 12 03:14:03 2011 UTC ()
- misc KNF
- use device_xname(), device_unit(), and device_class()


(tsutsui)
diff -r1.3 -r1.4 src/sys/arch/emips/emips/autoconf.c

cvs diff -r1.3 -r1.4 src/sys/arch/emips/emips/autoconf.c (expand / switch to unified diff)

--- src/sys/arch/emips/emips/autoconf.c 2011/02/22 08:20:20 1.3
+++ src/sys/arch/emips/emips/autoconf.c 2011/06/12 03:14:03 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: autoconf.c,v 1.3 2011/02/22 08:20:20 matt Exp $ */ 1/* $NetBSD: autoconf.c,v 1.4 2011/06/12 03:14:03 tsutsui Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1988 University of Utah. 4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1992, 1993 5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved. 6 * The Regents of the University of California. All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to Berkeley by 8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer 9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department and Ralph Campbell. 10 * Science Department and Ralph Campbell.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -29,172 +29,180 @@ @@ -29,172 +29,180 @@
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE. 34 * SUCH DAMAGE.
35 * 35 *
36 * from: Utah Hdr: autoconf.c 1.31 91/01/21 36 * from: Utah Hdr: autoconf.c 1.31 91/01/21
37 * 37 *
38 * @(#)autoconf.c 8.1 (Berkeley) 6/10/93 38 * @(#)autoconf.c 8.1 (Berkeley) 6/10/93
39 */ 39 */
40 40
41#include <sys/cdefs.h> 41#include <sys/cdefs.h>
42__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.3 2011/02/22 08:20:20 matt Exp $"); 42__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.4 2011/06/12 03:14:03 tsutsui Exp $");
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <sys/systm.h> 45#include <sys/systm.h>
46#include <sys/conf.h> 46#include <sys/conf.h>
47#include <sys/reboot.h> 47#include <sys/reboot.h>
48#include <sys/device.h> 48#include <sys/device.h>
49 49
50#include <machine/autoconf.h> 50#include <machine/autoconf.h>
51#include <machine/intr.h> 51#include <machine/intr.h>
52#include <machine/sysconf.h> 52#include <machine/sysconf.h>
53 53
54static int booted_bus, booted_unit; 54static int booted_bus, booted_unit;
55static const char *booted_controller; 55static const char *booted_controller;
56 56
57/* 57/*
58 * Configure all devices on system 58 * Configure all devices on system
59 */  59 */
60void 60void
61cpu_configure(void) 61cpu_configure(void)
62{ 62{
 63
63 /* Kick off autoconfiguration. */ 64 /* Kick off autoconfiguration. */
64 (void)splhigh(); 65 (void)splhigh();
65 66
66 evcnt_attach_static(&emips_clock_evcnt); 67 evcnt_attach_static(&emips_clock_evcnt);
67 evcnt_attach_static(&emips_fpu_evcnt); 68 evcnt_attach_static(&emips_fpu_evcnt);
68 evcnt_attach_static(&emips_memerr_evcnt); 69 evcnt_attach_static(&emips_memerr_evcnt);
69 70
70 if (config_rootfound("mainbus", NULL) == NULL) 71 if (config_rootfound("mainbus", NULL) == NULL)
71 panic("no mainbus found"); 72 panic("no mainbus found");
72 73
73 /* Reset any bus errors due to probing nonexistent devices. */ 74 /* Reset any bus errors due to probing nonexistent devices. */
74 (*platform.bus_reset)(); 75 (*platform.bus_reset)();
75 76
76 /* Configuration is finished, turn on interrupts. */ 77 /* Configuration is finished, turn on interrupts. */
77 spl0(); /* enable all source forcing SOFT_INTs cleared */ 78 spl0(); /* enable all source forcing SOFT_INTs cleared */
78} 79}
79 80
80/* 81/*
81 * Look at the string 'cp' and decode the boot device. 82 * Look at the string 'cp' and decode the boot device.
82 * Boot names are something like '0/ace(0,0)/netbsd' or 'tftp()/nfsnetbsd' 83 * Boot names are something like '0/ace(0,0)/netbsd' or 'tftp()/nfsnetbsd'
83 * meaning: [BusNumber/]<ControllerName>([<DiskNumber>,<PartitionNumber])/<kernelname> 84 * meaning:
 85 * [BusNumber/]<ControllerName>([<DiskNumber>,<PartitionNumber])/<kernelname>
84 */ 86 */
85void 87void
86makebootdev(char *cp) 88makebootdev(char *cp)
87{ 89{
88 int i; 90 int i;
89 static char booted_controller_name[8]; 91 static char booted_controller_name[8];
90 92
91 booted_device = NULL; 93 booted_device = NULL;
92 booted_bus = booted_unit = booted_partition = 0; 94 booted_bus = booted_unit = booted_partition = 0;
93 booted_controller = NULL; 95 booted_controller = NULL;
94 96
95 if (*cp >= '0' && *cp <= '9') { 97 if (*cp >= '0' && *cp <= '9') {
96 booted_bus = *cp++ - '0'; 98 booted_bus = *cp++ - '0';
97 if (*cp == '/') cp++; 99 if (*cp == '/')
98 } 100 cp++;
 101 }
99 102
100 if (strncmp(cp, "tftp(", 5) == 0) { 103 if (strncmp(cp, "tftp(", 5) == 0) {
101 booted_controller = "BOOTP"; 104 booted_controller = "BOOTP";
102 goto out; 105 goto out;
103 } 106 }
104 107
105 /* Stash away the controller name and use it later 108 /*
106 */ 109 * Stash away the controller name and use it later
107 for (i = 0; i < 7 && *cp && *cp != '('; i++) 110 */
108 booted_controller_name[i] = *cp++; 111 for (i = 0; i < 7 && *cp && *cp != '('; i++)
109 booted_controller_name[7] = 0; /* sanity */ 112 booted_controller_name[i] = *cp++;
110 113 booted_controller_name[7] = 0; /* sanity */
111 if (*cp == '(') cp++; 114
112 if (*cp >= '0' && *cp <= '9')  115 if (*cp == '(')
113 booted_unit = *cp++ - '0'; 116 cp++;
114 117 if (*cp >= '0' && *cp <= '9')
115 if (*cp == ',') cp++; 118 booted_unit = *cp++ - '0';
116 if (*cp >= '0' && *cp <= '9') 119
117 booted_partition = *cp - '0'; 120 if (*cp == ',')
118 booted_controller = booted_controller_name; 121 cp++;
 122 if (*cp >= '0' && *cp <= '9')
 123 booted_partition = *cp - '0';
 124 booted_controller = booted_controller_name;
119 125
120 out: 126 out:
121#if DEBUG 127#if DEBUG
122 printf("bootdev: %d/%s(%d,%d)\n",booted_bus,booted_controller,booted_unit,booted_partition); 128 printf("bootdev: %d/%s(%d,%d)\n",
 129 booted_bus, booted_controller, booted_unit, booted_partition);
123#endif 130#endif
124 return; 131 return;
125} 132}
126 133
127void 134void
128cpu_rootconf(void) 135cpu_rootconf(void)
129{ 136{
 137
130 printf("boot device: %s part%d\n", 138 printf("boot device: %s part%d\n",
131 booted_device ? booted_device->dv_xname : "<unknown>", 139 booted_device ? device_xname(booted_device) : "<unknown>",
132 booted_partition); 140 booted_partition);
133 141
134 setroot(booted_device, booted_partition); 142 setroot(booted_device, booted_partition);
135} 143}
136 144
137/* 145/*
138 * Try to determine the boot device. 146 * Try to determine the boot device.
139 */ 147 */
140void 148void
141device_register(struct device *dev, 149device_register(device_t dev, void *aux)
142 void *aux) 
143{ 150{
144 static int found, initted, netboot; 151 static int found, initted, netboot;
145 static struct device *ebusdev; 152 static device_t ebusdev;
146 struct device *parent = device_parent(dev); 153 device_t parent = device_parent(dev);
147 154
148 if (found) 155 if (found)
149 return; 156 return;
150 157
151#if 0 158#if 0
152 printf("\n[device_register(%s,%d) class %d]\n", dev->dv_xname, dev->dv_unit, dev->dv_class); 159 printf("\n[device_register(%s,%d) class %d]\n",
 160 device_xname(dev), device_unit(dev), device_class(dev));
153#endif 161#endif
154 162
155 if (!initted) { 163 if (!initted) {
156 netboot = (strcmp(booted_controller, "BOOTP") == 0); 164 netboot = (strcmp(booted_controller, "BOOTP") == 0);
157 initted = 1; 165 initted = 1;
158 } 166 }
159 167
160 /* 168 /*
161 * Remember the EBUS 169 * Remember the EBUS
162 */ 170 */
163 if (device_is_a(dev, "ebus")) { 171 if (device_is_a(dev, "ebus")) {
164 ebusdev = dev; 172 ebusdev = dev;
165 return; 173 return;
166 } 174 }
167 175
168 /* 176 /*
169 * Check if netbooting. 177 * Check if netbooting.
170 */ 178 */
171 if (netboot) { 179 if (netboot) {
172 180
173 /* Only one Ethernet interface (on ebus). */ 181 /* Only one Ethernet interface (on ebus). */
174 if ((parent == ebusdev) 182 if ((parent == ebusdev) &&
175 && device_is_a(dev, "enic")) { 183 device_is_a(dev, "enic")) {
176 booted_device = dev; 184 booted_device = dev;
177 found = 1; 185 found = 1;
178 return; 186 return;
179 } 187 }
180 188
181 /* allow any network adapter */ 189 /* allow any network adapter */
182 if (device_class(dev) == DV_IFNET && 190 if (device_class(dev) == DV_IFNET &&
183 device_is_a(parent, "ebus")) { 191 device_is_a(parent, "ebus")) {
184 booted_device = dev; 192 booted_device = dev;
185 found = 1; 193 found = 1;
186 return; 194 return;
187 } 195 }
188 196
189 /* The NIC might be found after the disk, so bail out here */ 197 /* The NIC might be found after the disk, so bail out here */
190 return; 198 return;
191 } 199 }
192 200
193 /* BUGBUG How would I get to the bus */ 201 /* BUGBUG How would I get to the bus */
194 if (device_is_a(dev,booted_controller) && (dev->dv_unit == booted_unit)) { 202 if (device_is_a(dev, booted_controller) &&
195 booted_device = dev; 203 (device_unit(dev) == booted_unit)) {
196 found = 1; 204 booted_device = dev;
197 return; 205 found = 1;
198 } 206 return;
199 207 }
200} 208}