]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/alpha/alpha/autoconf.c
This commit was generated by cvs2svn to compensate for changes in r49182,
[FreeBSD/FreeBSD.git] / sys / alpha / alpha / autoconf.c
1 /*-
2  * Copyright (c) 1998 Doug Rabson
3  * All rights reserved.
4  *
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  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  *      $Id: autoconf.c,v 1.29 1999/07/17 20:47:40 phk Exp $
27  */
28
29 #include "opt_bootp.h"
30 #include "opt_ffs.h"
31 #include "opt_cd9660.h"
32 #include "opt_nfsroot.h"
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/conf.h>
37 #include <sys/disklabel.h>
38 #include <sys/diskslice.h> /* for BASE_SLICE, MAX_SLICES */
39 #include <sys/reboot.h>
40 #include <sys/kernel.h>
41 #include <sys/mount.h>
42 #include <sys/sysctl.h>
43 #include <sys/bus.h>
44 #include <sys/devicestat.h>
45
46 #include <machine/cons.h>
47 #include <machine/ipl.h>
48 #include <machine/md_var.h>
49 #include <machine/cpuconf.h>
50 #include <machine/rpb.h>
51 #include <machine/bootinfo.h>
52
53 #include <cam/cam.h>
54 #include <cam/cam_ccb.h>
55 #include <cam/cam_sim.h>
56 #include <cam/cam_periph.h>
57 #include <cam/cam_xpt_sim.h>
58 #include <cam/cam_debug.h>
59
60 static void     configure __P((void *));
61 SYSINIT(configure, SI_SUB_CONFIGURE, SI_ORDER_THIRD, configure, NULL)
62
63 static void     configure_finish __P((void));
64 static void     configure_start __P((void));
65
66 device_t        isa_bus_device = 0;
67 struct cam_sim *boot_sim = 0;
68 extern int nfs_diskless_valid;
69
70 dev_t   rootdev = NODEV;
71 dev_t   dumpdev = NODEV;
72
73 static void
74 configure_start()
75 {
76 }
77
78 static void
79 configure_finish()
80 {
81 }
82
83 static int
84 atoi(const char *s)
85 {
86     int n = 0;
87     while (*s >= '0' && *s <= '9')
88         n = n * 10 + (*s++ - '0');
89     return n;
90 }
91
92 static const char *
93 bootdev_field(int which)
94 {
95         char *p = bootinfo.booted_dev;
96         char *q;
97         static char field[128];
98
99         /* Skip characters to find the right field */
100         for (; which; which--) {
101                 while (*p != ' ' && *p != '\0')
102                         p++;
103                 if (*p)
104                         p++;
105         }
106
107         /* Copy out the field and return it */
108         q = field;
109         while (*p != ' ' && *p != '\0')
110                 *q++ = *p++;
111         *q = '\0';
112
113         return field;
114 }
115
116 static const char *
117 bootdev_protocol(void)
118 {
119         return bootdev_field(0);
120 }
121
122 static int
123 bootdev_slot(void)
124 {
125         return atoi(bootdev_field(2));
126 }
127
128 static int
129 bootdev_unit(void)
130 {
131         return atoi(bootdev_field(5));
132 }
133
134 #if 0
135
136 static int
137 bootdev_bus(void)
138 {
139         return atoi(bootdev_field(1));
140 }
141
142 static int
143 bootdev_channel(void)
144 {
145         return atoi(bootdev_field(3));
146 }
147
148 static const char *
149 bootdev_remote_address(void)
150 {
151         return bootdev_field(4);
152 }
153
154 static int
155 bootdev_boot_dev_type(void)
156 {
157         return atoi(bootdev_field(6));
158 }
159
160 static const char *
161 bootdev_ctrl_dev_type(void)
162 {
163         return bootdev_field(7);
164 }
165
166 #endif
167
168 void
169 alpha_register_pci_scsi(int bus, int slot, struct cam_sim *sim)
170 {
171         if (!strcmp(bootdev_protocol(), "SCSI")) {
172                 int boot_slot = bootdev_slot();
173                 if (((bus == boot_slot / 1000 )
174                      || (bus == 1 && (boot_slot < 1000)))
175                     && slot == boot_slot % 1000)
176                         boot_sim = sim;
177         }
178 }
179
180 /*
181  * Determine i/o configuration for a machine.
182  */
183 static void
184 configure(void *dummy)
185 {
186         configure_start();
187
188         device_add_child(root_bus, platform.iobus, 0, 0);
189
190         root_bus_configure();
191
192         if((hwrpb->rpb_type != ST_DEC_3000_300) &&
193            (hwrpb->rpb_type != ST_DEC_3000_500)){
194                 /*
195                  * Probe ISA devices after everything.
196                  */
197                 if (isa_bus_device)
198                         bus_generic_attach(isa_bus_device);
199         } 
200         configure_finish();
201
202         cninit_finish();
203
204         /*
205          * Now we're ready to handle (pending) interrupts.
206          * XXX this is slightly misplaced.
207          */
208         spl0();
209
210         cold = 0;
211 }
212
213 void
214 cpu_rootconf()
215 {
216 #ifdef BOOTP_NFSROOT
217         if (!strcmp(bootdev_protocol(), "BOOTP")
218             && !mountrootfsname && !nfs_diskless_valid) {
219                 if (bootverbose)
220                         printf("Considering BOOTP NFS root f/s.\n");
221                 mountrootfsname = "nfs";
222         }
223 #endif /* BOOTP_NFSROOT */
224 #if defined(NFS) || defined(NFS_ROOT)
225         if (!mountrootfsname && nfs_diskless_valid) {
226                 if (bootverbose)
227                         printf("Considering NFS root f/s.\n");
228                 mountrootfsname = "nfs";
229         }
230 #endif /* NFS */
231
232
233 #if defined(FFS) || defined(FFS_ROOT)
234         if (!mountrootfsname) {
235                 static char rootname[] = "da0a";
236
237                 if (bootverbose)
238                         printf("Considering UFS root f/s.\n");
239                 mountrootfsname = "ufs";
240
241                 if (boot_sim) {
242                         struct cam_path *path;
243                         struct cam_periph *periph;
244             
245                         xpt_create_path(&path, NULL,
246                                         cam_sim_path(boot_sim),
247                                         bootdev_unit() / 100, 0);
248                         periph = cam_periph_find(path, "da");
249
250                         if (periph)
251                             rootdev = makebdev
252                                 (4, dkmakeminor(periph->unit_number,
253                                                 COMPATIBILITY_SLICE, 0));
254
255                         xpt_free_path(path);
256                 }
257
258                 rootdevs[0] = rootdev;
259                 rootname[2] += dkunit(rootdev);
260                 rootdevnames[0] = rootname;
261         }
262 #endif
263 }