autoconf.c revision 1.13 1 /* $NetBSD: autoconf.c,v 1.13 2010/04/28 13:51:55 kiyohara Exp $ */
2
3 /*-
4 * Copyright (c) 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * William Jolitz.
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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)autoconf.c 7.1 (Berkeley) 5/9/91
35 */
36
37 /*
38 * Setup the system to run on the current machine.
39 *
40 * Configure() is called at boot time and initializes the vba
41 * device tables and the memory controller monitoring. Available
42 * devices are determined (from possibilities mentioned in ioconf.c),
43 * and the drivers are initialized.
44 */
45
46 #include <sys/cdefs.h>
47 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.13 2010/04/28 13:51:55 kiyohara Exp $");
48
49 #include <sys/param.h>
50 #include <sys/conf.h>
51 #include <sys/reboot.h>
52 #include <sys/systm.h>
53 #include <sys/types.h>
54
55 #include <net/if.h>
56 #include <net/if_ether.h>
57
58 #include <dev/pci/pcivar.h>
59
60 #include <machine/pci_machdep.h>
61
62 #include <dev/marvell/gtreg.h>
63 #include <dev/marvell/marvellvar.h>
64
65
66 static void findroot(void);
67
68
69 /*
70 * Determine i/o configuration for a machine.
71 */
72 void
73 cpu_configure(void)
74 {
75
76 if (config_rootfound("mainbus", NULL) == NULL)
77 panic("configure: mainbus not configured");
78
79 aprint_normal("biomask %jx netmask %jx ttymask %jx\n",
80 imask[IPL_BIO] & 0x3fffffffffffffff,
81 imask[IPL_NET] & 0x3fffffffffffffff,
82 imask[IPL_TTY] & 0x3fffffffffffffff);
83
84 spl0();
85 }
86
87 void
88 cpu_rootconf(void)
89 {
90 findroot();
91
92 printf("boot device: %s\n",
93 booted_device ? booted_device->dv_xname : "<unknown>");
94
95 setroot(booted_device, booted_partition);
96 }
97
98 dev_t bootdev = 0;
99
100 /*
101 * Attempt to find the device from which we were booted.
102 * If we can do so, and not instructed not to do so,
103 * change rootdev to correspond to the load device.
104 */
105 static void
106 findroot(void)
107 {
108 device_t dv;
109 const char *name;
110
111 #if 0
112 printf("howto %x bootdev %x ", boothowto, bootdev);
113 #endif
114
115 if ((bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC)
116 return;
117
118
119 name = devsw_blk2name(B_TYPE(bootdev));
120 if (name == NULL)
121 return;
122
123 if ((dv = device_find_by_driver_unit(name, B_UNIT(bootdev))) != NULL) {
124 booted_device = dv;
125 booted_partition = B_PARTITION(bootdev);
126 }
127 }
128
129 void
130 device_register(struct device *dev, void *aux)
131 {
132 prop_dictionary_t dict = device_properties(dev);
133
134 if (device_is_a(dev, "gfe") &&
135 device_is_a(device_parent(dev), "gt") ) {
136 struct marvell_attach_args *mva = aux;
137 prop_data_t mac;
138 char enaddr[ETHER_ADDR_LEN] =
139 { 0x02, 0x00, 0x04, 0x00, 0x00, 0x04 };
140
141 switch (mva->mva_offset) {
142 case ETH0_BASE: enaddr[5] |= 0; break;
143 case ETH1_BASE: enaddr[5] |= 1; break;
144 case ETH2_BASE: enaddr[5] |= 2; break;
145 default:
146 aprint_error("WARNING: unknown mac-no. for %s\n",
147 dev->dv_xname);
148 }
149
150 mac = prop_data_create_data_nocopy(enaddr, ETHER_ADDR_LEN);
151 KASSERT(mac != NULL);
152 if (prop_dictionary_set(dict, "mac-addr", mac) == false)
153 aprint_error(
154 "WARNING: unable to set mac-addr property for %s\n",
155 dev->dv_xname);
156 prop_object_release(mac);
157 }
158 if (device_is_a(dev, "gtpci")) {
159 extern struct powerpc_bus_space
160 ev64260_pci0_io_bs_tag, ev64260_pci0_mem_bs_tag,
161 ev64260_pci1_io_bs_tag, ev64260_pci1_mem_bs_tag;
162 extern struct genppc_pci_chipset
163 genppc_gtpci0_chipset, genppc_gtpci1_chipset;
164
165 struct marvell_attach_args *mva = aux;
166 struct powerpc_bus_space *pci_io_bs_tag, *pci_mem_bs_tag;
167 struct genppc_pci_chipset *genppc_gtpci_chipset;
168 prop_data_t io_bs_tag, mem_bs_tag, pc;
169
170 if (mva->mva_unit == 0) {
171 pci_io_bs_tag = &ev64260_pci0_io_bs_tag;
172 pci_mem_bs_tag = &ev64260_pci0_mem_bs_tag;
173 genppc_gtpci_chipset = &genppc_gtpci0_chipset;
174 } else {
175 pci_io_bs_tag = &ev64260_pci1_io_bs_tag;
176 pci_mem_bs_tag = &ev64260_pci1_mem_bs_tag;
177 genppc_gtpci_chipset = &genppc_gtpci1_chipset;
178 }
179
180 io_bs_tag = prop_data_create_data_nocopy(
181 pci_io_bs_tag, sizeof(struct powerpc_bus_space));
182 KASSERT(io_bs_tag != NULL);
183 prop_dictionary_set(dict, "io-bus-tag", io_bs_tag);
184 prop_object_release(io_bs_tag);
185 mem_bs_tag = prop_data_create_data_nocopy(
186 pci_mem_bs_tag, sizeof(struct powerpc_bus_space));
187 KASSERT(mem_bs_tag != NULL);
188 prop_dictionary_set(dict, "mem-bus-tag", mem_bs_tag);
189 prop_object_release(mem_bs_tag);
190
191 genppc_gtpci_chipset->pc_conf_v = device_private(dev);
192 pc = prop_data_create_data_nocopy(genppc_gtpci_chipset,
193 sizeof(struct genppc_pci_chipset));
194 KASSERT(pc != NULL);
195 prop_dictionary_set(dict, "pci-chipset", pc);
196 prop_object_release(pc);
197
198 prop_dictionary_set_uint64(dict, "iostart", 0x00000600);
199 prop_dictionary_set_uint64(dict, "ioend", 0x0000ffff);
200 prop_dictionary_set_uint64(dict, "memstart",
201 pci_mem_bs_tag->pbs_base);
202 prop_dictionary_set_uint64(dict, "memend",
203 pci_mem_bs_tag->pbs_limit - 1);
204 prop_dictionary_set_uint32(dict, "cache-line-size", 32);
205 }
206 if (device_is_a(dev, "obio") &&
207 device_is_a(device_parent(dev), "gt") ) {
208 extern struct powerpc_bus_space *ev64260_obio_bs_tags[5];
209 struct marvell_attach_args *mva = aux;
210 struct powerpc_bus_space *bst =
211 ev64260_obio_bs_tags[mva->mva_unit];
212 prop_data_t bstd;
213
214 bstd =
215 prop_data_create_data_nocopy(bst, sizeof(bus_space_tag_t));
216 KASSERT(bstd != NULL);
217 if (prop_dictionary_set(dict, "bus-tag", bstd) == false)
218 aprint_error(
219 "WARNING: unable to set bus-tag property for %s\n",
220 dev->dv_xname);
221 prop_object_release(bstd);
222 }
223 }
224