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