xref: /netbsd-src/sys/arch/mipsco/mipsco/autoconf.c (revision 50e68e123bf74d17378f7bcc0bb6ac0616d03635)
1 /*	$NetBSD: autoconf.c,v 1.28 2017/06/22 16:46:53 flxd 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 /*
42  * Setup the system to run on the current machine.
43  *
44  * Configure() is called at boot time.  Available
45  * devices are determined (from possibilities mentioned in ioconf.c),
46  * and the drivers are initialized.
47  */
48 
49 #define __INTR_PRIVATE
50 #include <sys/cdefs.h>
51 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.28 2017/06/22 16:46:53 flxd Exp $");
52 
53 #include <sys/param.h>
54 #include <sys/systm.h>
55 #include <sys/buf.h>
56 #include <sys/conf.h>
57 #include <sys/reboot.h>
58 #include <sys/device.h>
59 
60 #include <dev/scsipi/scsi_all.h>
61 #include <dev/scsipi/scsipi_all.h>
62 #include <dev/scsipi/scsiconf.h>
63 
64 #include <machine/cpu.h>
65 #include <machine/mainboard.h>
66 #include <machine/autoconf.h>
67 
68 /*
69  * The following several variables are related to
70  * the configuration process, and are used in initializing
71  * the machine.
72  */
73 int	cpuspeed = 25;	/* approx # instr per usec. */
74 
75 extern int initcpu(void);		/*XXX*/
76 
77 void	findroot(device_t *, int *);
78 
79 struct mipsco_intrhand intrtab[MAX_INTR_COOKIES];
80 
81 /*
82  * Determine mass storage and memory configuration for a machine.
83  * Print CPU type, and then iterate over an array of devices
84  * found on the baseboard or in TURBOchannel option slots.
85  * Once devices are configured, enable interrupts, and probe
86  * for attached scsi devices.
87  */
88 void
cpu_configure(void)89 cpu_configure(void)
90 {
91 
92 	/*
93 	 * Kick off autoconfiguration
94 	 */
95 	(void) splhigh();
96 	if (config_rootfound("mainbus", NULL) == NULL)
97 		panic("no mainbus found");
98 	initcpu();
99 }
100 
101 void
cpu_rootconf(void)102 cpu_rootconf(void)
103 {
104 	findroot(&booted_device, &booted_partition);
105 
106 	printf("boot device: %s\n",
107 	       booted_device ? device_xname(booted_device) : "<unknown>");
108 	rootconf();
109 }
110 
111 dev_t	bootdev = 0;
112 char	boot_class;
113 int	boot_id, boot_lun, boot_part;
114 
115 /*
116  * Attempt to find the device from which we were booted.
117  */
118 void
findroot(device_t * devpp,int * partp)119 findroot(device_t *devpp, int *partp)
120 {
121 	device_t dv;
122 	deviter_t di;
123 
124 	for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
125 	     dv != NULL;
126 	     dv = deviter_next(&di)) {
127 		if (device_class(dv) == boot_class &&
128 		    /* XXX device_unit() abuse */
129 		    device_unit(dv) == boot_id)
130 		    	break;
131 	}
132 	deviter_release(&di);
133 	if (dv != NULL) {
134 		*devpp = dv;
135 		*partp = boot_part;
136 		return;
137 	}
138 
139 	/*
140 	 * Default to "not found".
141 	 */
142 	*devpp = NULL;
143 	*partp = 0;
144 	return;
145 }
146 
147 void
makebootdev(char * cp)148 makebootdev(char *cp)
149 {
150 	boot_class = -1;
151 	boot_id = boot_lun = boot_part = 0;
152 
153 	if (strlen(cp) < 6)
154 		return;
155 	if (strncmp(cp, "dk", 2) == 0 && cp[4] == '(') { /* Disk */
156 		cp += 5;
157 		if (*cp >= '0' && *cp <= '9')
158 			boot_lun = *cp++ - '0';
159 		if (*cp == ',')
160 			cp += 1;
161 		if (*cp >= '0' && *cp <= '9')
162 			boot_id = *cp++ - '0';
163 		if (*cp == ',')
164 			cp += 1;
165 		if (*cp >= '0' && *cp <= '7')
166 			boot_part = *cp - '0';
167 		boot_class = DV_DISK;
168 		return;
169 	}
170 }
171