1 /* $NetBSD: autoconf.c,v 1.10 2012/10/27 17:18:03 chs Exp $ */
2
3 /*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.10 2012/10/27 17:18:03 chs Exp $");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/device.h>
35 #include <sys/conf.h>
36 #if defined(SH7750R)
37 #include <sys/callout.h>
38 #include <sys/kernel.h>
39 #include <machine/mmeye.h>
40 #endif
41 #include <machine/bootinfo.h>
42
43 static void findroot(void);
44
45 static int bootunit;
46
47 void
cpu_configure(void)48 cpu_configure(void)
49 {
50 /* Start configuration */
51 splhigh();
52
53 findroot();
54
55 if (config_rootfound("mainbus", NULL) == NULL)
56 panic("no mainbus found");
57
58 /* Configuration is finished, turn on interrupts. */
59 spl0();
60
61 #if defined(MMEYE_EPC_WDT)
62 callout_init(&epc_wdtc, 0);
63 callout_setfunc(&epc_wdtc, epc_watchdog_timer_reset, NULL);
64 epc_watchdog_timer_reset(NULL);
65 #endif
66 }
67
68 void
cpu_rootconf(void)69 cpu_rootconf(void)
70 {
71
72 printf("boot device: %s\n",
73 booted_device ? device_xname(booted_device) : "<unknown>");
74
75 rootconf();
76 }
77
78 void
device_register(device_t dev,void * aux)79 device_register(device_t dev, void *aux)
80 {
81
82 if (booted_device != NULL)
83 return;
84
85 /* check wd drive */
86 if (device_class(dev) == DV_DISK &&
87 device_is_a(dev, "wd")) {
88 device_t bdev, cdev;
89
90 bdev = device_parent(dev);
91 if (!device_is_a(bdev, "atabus"))
92 return;
93 cdev = device_parent(bdev);
94 if (!device_is_a(cdev, "wdc"))
95 return;
96
97 if (device_unit(dev) == bootunit)
98 booted_device = dev;
99 }
100 }
101
102 /*
103 * Attempt to find the device from which we were booted.
104 * If we can do so, and not instructed not to do so,
105 * change rootdev to correspond to the load device.
106 */
107 static void
findroot(void)108 findroot(void)
109 {
110 struct btinfo_bootdev *bi;
111 int x, p;
112
113 bi = (struct btinfo_bootdev *)lookup_bootinfo(BTINFO_BOOTDEV);
114 if (bi == NULL)
115 return;
116 x = strlen(bi->bootdev) - 2;
117 p = strlen(bi->bootdev) - 1;
118 if (!isdigit(bi->bootdev[x]) ||
119 !isalpha(bi->bootdev[p]))
120 return; /* bad format */
121
122 bootunit = bi->bootdev[x] - '0';
123 booted_partition = bi->bootdev[p] - 'a';
124 }
125