1 /* $NetBSD: autoconf.c,v 1.27 2012/10/27 17:17:57 chs Exp $ */
2
3 /*
4 * Copyright (c) 1988 University of Utah.
5 * Copyright (c) 1992, 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * the Systems Programming Group of the University of Utah Computer
10 * Science Department and Ralph Campbell.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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
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
34 * SUCH DAMAGE.
35 *
36 * from: Utah Hdr: autoconf.c 1.31 91/01/21
37 *
38 * @(#)autoconf.c 8.1 (Berkeley) 6/10/93
39 */
40
41 #include <sys/cdefs.h>
42 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.27 2012/10/27 17:17:57 chs Exp $");
43
44 #include "opt_md.h"
45
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/conf.h>
49 #include <sys/disklabel.h>
50 #include <sys/device.h>
51 #include <sys/bus.h>
52
53 #include <sh3/exception.h>
54 #include <machine/intr.h>
55
56 #include <machine/config_hook.h>
57 #include <machine/autoconf.h>
58 #include <machine/platid.h>
59 #include <machine/platid_mask.h>
60
61 #include <hpcsh/dev/hd64461/hd64461var.h>
62 #include <hpcsh/dev/hd64465/hd64465var.h>
63
64 static char booted_device_name[16];
65 #ifndef MEMORY_DISK_IS_ROOT
66 static void get_device(char *name);
67 #endif
68
69 void
cpu_configure(void)70 cpu_configure(void)
71 {
72
73 config_hook_init();
74 hd6446x_intr_init();
75 #ifdef SH3
76 if (CPU_IS_SH3) /* HD64461 (Jornada 690, HP620LX, HPW-50PA) */
77 intc_intr_establish(SH7709_INTEVT2_IRQ4, IST_LEVEL, IPL_TTY,
78 (void *)1/* fake. see intc_intr(). */, 0);
79 #endif
80 #ifdef SH4
81 if (CPU_IS_SH4) /* HD64465 (HPW-650PA) */
82 intc_intr_establish(SH_INTEVT_IRL11, IST_LEVEL, IPL_TTY,
83 (void *)1/* fake. see intc_intr(). */, 0);
84 #endif
85
86 /* Kick off autoconfiguration. */
87 splhigh();
88 if (config_rootfound("mainbus", NULL) == NULL)
89 panic("no mainbus found");
90
91 /* Configuration is finished, turn on interrupts. */
92 spl0();
93 }
94
95 void
cpu_rootconf(void)96 cpu_rootconf(void)
97 {
98
99 #ifndef MEMORY_DISK_IS_ROOT
100 get_device(booted_device_name);
101
102 printf("boot device: %s\n",
103 booted_device ? device_xname(booted_device) : "<unknown>");
104 #endif
105 rootconf();
106 }
107
108 void
makebootdev(const char * cp)109 makebootdev(const char *cp)
110 {
111
112 strncpy(booted_device_name, cp, 16);
113 }
114
115 void
device_register(device_t dev,void * aux)116 device_register(device_t dev, void *aux)
117 {
118 device_t parent;
119
120 parent = device_parent(dev);
121
122 if (device_is_a(dev, "rtc") &&
123 parent != NULL && device_is_a(parent, "shb") &&
124 platid_match(&platid, &platid_mask_MACH_HITACHI_PERSONA_HPW50PAD)) {
125 prop_number_t rtc_baseyear;
126
127 #define HPW50PAD_RTC_BASE 1996
128
129 rtc_baseyear = prop_number_create_integer(HPW50PAD_RTC_BASE);
130 KASSERT(rtc_baseyear != NULL);
131
132 if (prop_dictionary_set(device_properties(dev),
133 "sh3_rtc_baseyear", rtc_baseyear) == false)
134 printf("WARNING: unable to set sh3_rtc_baseyear "
135 "property for %s\n", device_xname(dev));
136 prop_object_release(rtc_baseyear);
137 return;
138 }
139 }
140
141 #ifndef MEMORY_DISK_IS_ROOT
142 static void
get_device(char * name)143 get_device(char *name)
144 {
145 int unit, part;
146 char devname[16], *cp;
147 device_t dv;
148
149 if (strncmp(name, "/dev/", 5) == 0)
150 name += 5;
151
152 if (devsw_name2blk(name, devname, sizeof(devname)) == -1)
153 return;
154
155 name += strlen(devname);
156 unit = part = 0;
157
158 cp = name;
159 while (*cp >= '0' && *cp <= '9')
160 unit = (unit * 10) + (*cp++ - '0');
161 if (cp == name)
162 return;
163
164 if (*cp >= 'a' && *cp <= ('a' + MAXPARTITIONS))
165 part = *cp - 'a';
166 else if (*cp != '\0' && *cp != ' ')
167 return;
168
169 if ((dv = device_find_by_driver_unit(devname, unit)) != NULL) {
170 booted_device = dv;
171 booted_partition = part;
172 }
173 }
174 #endif /* !MEMORY_DISK_IS_ROOT */
175