autoconf.c revision 1.15 1 /* $NetBSD: autoconf.c,v 1.15 2008/01/04 22:15:58 ad Exp $ */
2
3 /*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.15 2008/01/04 22:15:58 ad Exp $");
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/conf.h>
45 #include <sys/device.h>
46 #include <sys/bus.h>
47
48 #include <sys/socket.h> /* these three just to get ETHER_ADDR_LEN(!) */
49 #include <net/if.h>
50 #include <net/if_ether.h>
51
52 #include <machine/yamon.h>
53
54 #include <mips/alchemy/include/aureg.h>
55 #include <mips/alchemy/include/auvar.h>
56 #include <mips/alchemy/include/aubusvar.h>
57
58 /*
59 * Configure all devices on system
60 */
61 void
62 cpu_configure(void)
63 {
64
65 intr_init();
66
67 /* Kick off autoconfiguration. */
68 (void)splhigh();
69 if (config_rootfound("mainbus", NULL) == NULL)
70 panic("no mainbus found");
71
72 /*
73 * Hardware interrupts will be enabled in
74 * sys/arch/mips/mips/mips3_clockintr.c:mips3_initclocks()
75 * to avoid hardclock(9) by CPU INT5 before softclockintr is
76 * initialized in initclocks().
77 */
78 }
79
80 void
81 cpu_rootconf(void)
82 {
83
84 setroot(booted_device, booted_partition);
85 }
86
87 void
88 device_register(struct device *dev, void *aux)
89 {
90 struct aubus_attach_args *aa = aux;
91
92 /*
93 * We don't ever know the boot device. But that's because the
94 * firmware only loads from the network.
95 */
96
97 /* Fetch the MAC addresses from YAMON. */
98 if (device_is_a(dev, "aumac")) {
99 prop_data_t pd;
100 const char *cp;
101 char *cp0;
102 int i;
103 uint8_t ethaddr[ETHER_ADDR_LEN];
104
105 /* Get the Ethernet address of the first on-board Ethernet. */
106 #if defined(ETHADDR)
107 cp = ETHADDR;
108 #else
109 cp = yamon_getenv("ethaddr");
110 #endif
111 if (cp != NULL) {
112 for (i = 0; i < ETHER_ADDR_LEN; i++) {
113 ethaddr[i] = strtoul(cp, &cp0, 16);
114 cp = cp0 + 1;
115 }
116 if (aa->aa_addr != MAC0_BASE &&
117 aa->aa_addr != AU1500_MAC0_BASE) {
118 /* XXX
119 * The PROM has a variable for the MAC address
120 * of the first interface. For now, just add
121 * 0x10 to the second last octet(!) for the
122 * second interface (Linux does the same).
123 */
124 ethaddr[4] += 0x10;
125 }
126 pd = prop_data_create_data(ethaddr, ETHER_ADDR_LEN);
127 KASSERT(pd != NULL);
128 if (prop_dictionary_set(device_properties(dev),
129 "mac-addr", pd) == false) {
130 printf("WARNING: unable to set mac-addr "
131 "property for %s\n", dev->dv_xname);
132 }
133 prop_object_release(pd);
134 }
135 }
136 }
137