xref: /netbsd-src/sys/arch/cobalt/cobalt/autoconf.c (revision cbab9cadce21ae72fac13910001079fff214cc29)
1 /*	$NetBSD: autoconf.c,v 1.31 2012/10/27 17:17:43 chs Exp $	*/
2 
3 /*
4  * Copyright (c) 2000 Soren S. Jorvang.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions, and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.31 2012/10/27 17:17:43 chs Exp $");
30 
31 #include <sys/param.h>
32 #include <sys/buf.h>
33 #include <sys/cpu.h>
34 #include <sys/conf.h>
35 #include <sys/device.h>
36 #include <sys/intr.h>
37 #include <sys/systm.h>
38 
39 #include <dev/pci/pcivar.h>
40 #include <dev/ata/atavar.h>
41 
42 extern char	bootstring[];
43 extern int	netboot;
44 extern int	bootunit;
45 extern int	bootpart;
46 
47 void
cpu_configure(void)48 cpu_configure(void)
49 {
50 
51 	(void)splhigh();
52 
53 	intr_init();
54 
55 	if (config_rootfound("mainbus", NULL) == NULL)
56 		panic("no mainbus found");
57 
58 	/*
59 	 * Hardware interrupts will be enabled in
60 	 * sys/arch/mips/mips/mips3_clockintr.c:mips3_initclocks()
61 	 * to avoid hardclock(9) by CPU INT5 before softclockintr is
62 	 * initialized in initclocks().
63 	 */
64 }
65 
66 void
cpu_rootconf(void)67 cpu_rootconf(void)
68 {
69 
70 	printf("boot device: %s\n",
71 	    booted_device ? device_xname(booted_device) : "<unknown>");
72 
73 	rootconf();
74 }
75 
76 void
device_register(device_t dev,void * aux)77 device_register(device_t dev, void *aux)
78 {
79 
80 	if (booted_device != NULL)
81 		return;
82 
83 	if (netboot == 1) {
84 		/* check tlp0 on netboot */
85 		if (device_class(dev) == DV_IFNET &&
86 		    device_is_a(dev, "tlp")) {
87 			struct pci_attach_args *pa = aux;
88 
89 			if (pa->pa_bus == 0 &&
90 			    pa->pa_device == 7 &&
91 			    pa->pa_function == 0)
92 				booted_device = dev;
93 		}
94 	} else {
95 		/* check wd channel and drive */
96 		if (device_class(dev) == DV_DISK &&
97 		    device_is_a(dev, "wd")) {
98 			struct ata_device *adev = aux;
99 			int unit;
100 
101 			unit = adev->adev_channel * 2 +
102 			    adev->adev_drv_data->drive;
103 			if (unit == bootunit) {
104 				booted_device = dev;
105 			}
106 		}
107 		/*
108 		 * XXX Match up MBR boot specification with BSD disklabel
109 		 *     for root?
110 		 */
111 		booted_partition = 0;
112 	}
113 }
114