autoconf.c revision 1.1 1 /* $NetBSD: autoconf.c,v 1.1 2015/04/29 08:32:01 hikaru Exp $ */
2
3 /*
4 * Copyright 2002 Wasabi Systems, Inc.
5 * All rights reserved.
6 *
7 * Written by Simon Burge for Wasabi Systems, Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
23 * written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.1 2015/04/29 08:32:01 hikaru Exp $");
40
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/buf.h>
44 #include <sys/conf.h>
45 #include <sys/device.h>
46
47 #include <net/if_ether.h>
48
49 #include <machine/cpu.h>
50
51 #include <evbmips/cavium/octeon_uboot.h>
52
53 static void findroot(void);
54
55 void
56 cpu_configure(void)
57 {
58
59 intr_init();
60
61 /* Kick off autoconfiguration. */
62 (void)splhigh();
63 if (config_rootfound("mainbus", NULL) == NULL)
64 panic("no mainbus found");
65
66 /* XXX need this? */
67 (void)spl0();
68 }
69
70 void
71 cpu_rootconf(void)
72 {
73 findroot();
74
75 printf("boot device: %s\n",
76 booted_device ? booted_device->dv_xname : "<unknown>");
77
78 rootconf();
79 }
80
81 extern char bootstring[];
82 extern int netboot;
83
84 static void
85 findroot(void)
86 {
87 device_t dv;
88 deviter_t di;
89
90 if (booted_device)
91 return;
92
93 if ((booted_device == NULL) && netboot == 0) {
94 for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST); dv != NULL;
95 dv = deviter_next(&di)) {
96 if (device_class(dv) == DV_DISK &&
97 device_is_a(dv, "wd"))
98 booted_device = dv;
99 }
100 deviter_release(&di);
101 }
102
103 /*
104 * XXX Match up MBR boot specification with BSD disklabel for root?
105 */
106 booted_partition = 0;
107
108 return;
109 }
110
111 static void
112 prop_set_cnmac(device_t dev)
113 {
114 prop_dictionary_t dict = device_properties(dev);
115 prop_data_t pd;
116 prop_number_t pn;
117 uint8_t enaddr[ETHER_ADDR_LEN];
118 uint32_t mac_lo;
119 int unit = device_unit(dev);
120
121 /* ethernet mac address */
122 memcpy(enaddr, octeon_btinfo.obt_mac_addr_base,
123 sizeof(enaddr));
124 mac_lo = enaddr[3] << 16;
125 mac_lo += enaddr[4] << 8;
126 mac_lo += enaddr[5];
127 KASSERT(unit < octeon_btinfo.obt_mac_addr_count);
128 mac_lo += unit;
129 enaddr[3] = (mac_lo >> 16) & 0xff;
130 enaddr[4] = (mac_lo >> 8) & 0xff;
131 enaddr[5] = mac_lo & 0xff;
132 pd = prop_data_create_data(enaddr, ETHER_ADDR_LEN);
133 KASSERT(pd != NULL);
134 prop_dictionary_set_and_rel(dict, "mac-address", pd);
135
136 /* ethernet phy adddress */
137 switch (octeon_btinfo.obt_board_type) {
138 case BOARD_TYPE_UBIQUITI_E100:
139 pn = prop_number_create_integer(0x07 - unit);
140 break;
141 default:
142 pn = prop_number_create_integer(-1);
143 break;
144 }
145 KASSERT(pn != NULL);
146 prop_dictionary_set_and_rel(dict, "phy-addr", pn);
147 }
148
149 static void
150 prop_set_octeon_gmx(device_t dev)
151 {
152 prop_dictionary_t dict = device_properties(dev);
153 prop_number_t tx, rx;
154
155 /* ethernet rgmii phy dependent timing parameter. */
156 switch (octeon_btinfo.obt_board_type) {
157 case BOARD_TYPE_UBIQUITI_E100:
158 tx = prop_number_create_integer(16);
159 rx = prop_number_create_integer(0);
160 break;
161 default:
162 tx = prop_number_create_integer(0);
163 rx = prop_number_create_integer(0);
164 break;
165 }
166 KASSERT(tx != NULL);
167 KASSERT(rx != NULL);
168 prop_dictionary_set_and_rel(dict, "rgmii-tx", tx);
169 prop_dictionary_set_and_rel(dict, "rgmii-rx", rx);
170 }
171
172 void
173 device_register(device_t dev, void *aux)
174 {
175 if ((booted_device == NULL) && (netboot == 1))
176 if (device_class(dev) == DV_IFNET)
177 booted_device = dev;
178
179 if (device_is_a(dev, "cnmac")) {
180 prop_set_cnmac(dev);
181 } else if (device_is_a(dev, "octeon_gmx")) {
182 prop_set_octeon_gmx(dev);
183 }
184 }
185