1 /* $NetBSD: autoconf.c,v 1.28 2025/10/13 15:40:14 thorpej 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.28 2025/10/13 15:40:14 thorpej 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 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 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 109 makebootdev(const char *cp) 110 { 111 112 strncpy(booted_device_name, cp, 16); 113 } 114 115 #define HPW50PAD_RTC_BASE 1996 116 117 void 118 device_register(device_t dev, void *aux) 119 { 120 device_t parent; 121 122 parent = device_parent(dev); 123 124 if (device_is_a(dev, "rtc") && 125 parent != NULL && device_is_a(parent, "shb") && 126 platid_match(&platid, &platid_mask_MACH_HITACHI_PERSONA_HPW50PAD)) { 127 if (! device_setprop_uint(dev, "start-year", 128 HPW50PAD_RTC_BASE)) { 129 printf("WARNING: unable to set start-year " 130 "property for %s\n", device_xname(dev)); 131 } 132 return; 133 } 134 } 135 136 #ifndef MEMORY_DISK_IS_ROOT 137 static void 138 get_device(char *name) 139 { 140 int unit, part; 141 char devname[16], *cp; 142 device_t dv; 143 144 if (strncmp(name, "/dev/", 5) == 0) 145 name += 5; 146 147 if (devsw_name2blk(name, devname, sizeof(devname)) == -1) 148 return; 149 150 name += strlen(devname); 151 unit = part = 0; 152 153 cp = name; 154 while (*cp >= '0' && *cp <= '9') 155 unit = (unit * 10) + (*cp++ - '0'); 156 if (cp == name) 157 return; 158 159 if (*cp >= 'a' && *cp <= ('a' + MAXPARTITIONS)) 160 part = *cp - 'a'; 161 else if (*cp != '\0' && *cp != ' ') 162 return; 163 164 if ((dv = device_find_by_driver_unit(devname, unit)) != NULL) { 165 booted_device = dv; 166 booted_partition = part; 167 } 168 } 169 #endif /* !MEMORY_DISK_IS_ROOT */ 170