autoconf.c revision 1.1.2.6 1 1.1.2.6 matt /* $NetBSD: autoconf.c,v 1.1.2.6 2012/01/04 16:17:52 matt Exp $ */
2 1.1.2.1 cliff
3 1.1.2.1 cliff /*
4 1.1.2.1 cliff * Copyright 2002 Wasabi Systems, Inc.
5 1.1.2.1 cliff * All rights reserved.
6 1.1.2.1 cliff *
7 1.1.2.1 cliff * Written by Simon Burge for Wasabi Systems, Inc.
8 1.1.2.1 cliff *
9 1.1.2.1 cliff * Redistribution and use in source and binary forms, with or without
10 1.1.2.1 cliff * modification, are permitted provided that the following conditions
11 1.1.2.1 cliff * are met:
12 1.1.2.1 cliff * 1. Redistributions of source code must retain the above copyright
13 1.1.2.1 cliff * notice, this list of conditions and the following disclaimer.
14 1.1.2.1 cliff * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.2.1 cliff * notice, this list of conditions and the following disclaimer in the
16 1.1.2.1 cliff * documentation and/or other materials provided with the distribution.
17 1.1.2.1 cliff * 3. All advertising materials mentioning features or use of this software
18 1.1.2.1 cliff * must display the following acknowledgement:
19 1.1.2.1 cliff * This product includes software developed for the NetBSD Project by
20 1.1.2.1 cliff * Wasabi Systems, Inc.
21 1.1.2.1 cliff * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1.2.1 cliff * or promote products derived from this software without specific prior
23 1.1.2.1 cliff * written permission.
24 1.1.2.1 cliff *
25 1.1.2.1 cliff * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1.2.1 cliff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1.2.1 cliff * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1.2.1 cliff * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1.2.1 cliff * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1.2.1 cliff * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1.2.1 cliff * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1.2.1 cliff * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1.2.1 cliff * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1.2.1 cliff * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1.2.1 cliff * POSSIBILITY OF SUCH DAMAGE.
36 1.1.2.1 cliff */
37 1.1.2.1 cliff
38 1.1.2.1 cliff #include <sys/cdefs.h>
39 1.1.2.6 matt __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.1.2.6 2012/01/04 16:17:52 matt Exp $");
40 1.1.2.5 matt
41 1.1.2.5 matt #define _MIPS_BUS_DMA_PRIVATE
42 1.1.2.1 cliff
43 1.1.2.1 cliff #include <sys/param.h>
44 1.1.2.1 cliff #include <sys/systm.h>
45 1.1.2.5 matt #include <sys/bus.h>
46 1.1.2.1 cliff #include <sys/conf.h>
47 1.1.2.1 cliff #include <sys/cpu.h>
48 1.1.2.5 matt #include <sys/device.h>
49 1.1.2.5 matt
50 1.1.2.5 matt #include <mips/rmi/rmixlvar.h>
51 1.1.2.1 cliff
52 1.1.2.1 cliff static void findroot(void);
53 1.1.2.5 matt static void rmixl_bus_dma_init(void);
54 1.1.2.1 cliff
55 1.1.2.1 cliff void
56 1.1.2.1 cliff cpu_configure()
57 1.1.2.1 cliff {
58 1.1.2.5 matt rmixl_bus_dma_init();
59 1.1.2.1 cliff
60 1.1.2.6 matt rmixl_fmn_init();
61 1.1.2.6 matt
62 1.1.2.1 cliff intr_init();
63 1.1.2.1 cliff
64 1.1.2.1 cliff /* Kick off autoconfiguration. */
65 1.1.2.1 cliff (void)splhigh();
66 1.1.2.1 cliff if (config_rootfound("mainbus", NULL) == NULL)
67 1.1.2.1 cliff panic("no mainbus found");
68 1.1.2.1 cliff
69 1.1.2.1 cliff /*
70 1.1.2.1 cliff * Hardware interrupts will be enabled in
71 1.1.2.1 cliff * sys/arch/mips/mips/mips3_clockintr.c:mips3_initclocks()
72 1.1.2.1 cliff * to avoid hardclock(9) by CPU INT5 before softclockintr is
73 1.1.2.1 cliff * initialized in initclocks().
74 1.1.2.1 cliff */
75 1.1.2.1 cliff }
76 1.1.2.1 cliff
77 1.1.2.1 cliff void
78 1.1.2.1 cliff cpu_rootconf()
79 1.1.2.1 cliff {
80 1.1.2.1 cliff findroot();
81 1.1.2.1 cliff
82 1.1.2.1 cliff printf("boot device: %s\n",
83 1.1.2.1 cliff booted_device ? booted_device->dv_xname : "<unknown>");
84 1.1.2.1 cliff
85 1.1.2.1 cliff setroot(booted_device, booted_partition);
86 1.1.2.1 cliff }
87 1.1.2.1 cliff
88 1.1.2.1 cliff extern char bootstring[];
89 1.1.2.1 cliff extern int netboot;
90 1.1.2.1 cliff
91 1.1.2.1 cliff static void
92 1.1.2.1 cliff findroot(void)
93 1.1.2.1 cliff {
94 1.1.2.1 cliff if (booted_device)
95 1.1.2.1 cliff return;
96 1.1.2.1 cliff
97 1.1.2.4 matt if ((booted_device == NULL) && netboot == 0) {
98 1.1.2.4 matt device_t dv;
99 1.1.2.4 matt deviter_t di;
100 1.1.2.4 matt
101 1.1.2.5 matt for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
102 1.1.2.5 matt dv != NULL;
103 1.1.2.5 matt dv = deviter_next(&di)) {
104 1.1.2.4 matt if (device_class(dv) == DV_DISK
105 1.1.2.4 matt && (device_is_a(dv, "wd")
106 1.1.2.4 matt || device_is_a(dv, "sd")
107 1.1.2.4 matt || device_is_a(dv, "ld")))
108 1.1.2.4 matt booted_device = dv;
109 1.1.2.4 matt }
110 1.1.2.4 matt deviter_release(&di);
111 1.1.2.4 matt }
112 1.1.2.1 cliff
113 1.1.2.1 cliff /*
114 1.1.2.1 cliff * XXX Match up MBR boot specification with BSD disklabel for root?
115 1.1.2.1 cliff */
116 1.1.2.1 cliff booted_partition = 0;
117 1.1.2.1 cliff }
118 1.1.2.1 cliff
119 1.1.2.5 matt static void
120 1.1.2.5 matt addprop_integer(device_t dev, const char *name, uint32_t val)
121 1.1.2.5 matt {
122 1.1.2.5 matt prop_number_t pn;
123 1.1.2.5 matt pn = prop_number_create_integer(val);
124 1.1.2.5 matt KASSERT(pn != NULL);
125 1.1.2.5 matt if (prop_dictionary_set(device_properties(dev), name, pn) == false) {
126 1.1.2.5 matt printf("WARNING: unable to set %s property for %s",
127 1.1.2.5 matt name, device_xname(dev));
128 1.1.2.5 matt }
129 1.1.2.5 matt prop_object_release(pn);
130 1.1.2.5 matt }
131 1.1.2.5 matt
132 1.1.2.1 cliff void
133 1.1.2.4 matt device_register(device_t dev, void *aux)
134 1.1.2.1 cliff {
135 1.1.2.4 matt
136 1.1.2.5 matt if (booted_device == NULL
137 1.1.2.5 matt && netboot == 1
138 1.1.2.5 matt && device_class(dev) == DV_IFNET)
139 1.1.2.5 matt booted_device = dev;
140 1.1.2.5 matt
141 1.1.2.5 matt if (device_is_a(dev, "com")) {
142 1.1.2.5 matt device_t parent = device_parent(dev);
143 1.1.2.5 matt if (device_is_a(parent, "mainbus")) {
144 1.1.2.5 matt addprop_integer(dev, "frequency", 133333333);
145 1.1.2.5 matt } if (device_is_a(parent, "pci")) {
146 1.1.2.5 matt struct pci_attach_args * const pa = aux;
147 1.1.2.5 matt int bus;
148 1.1.2.5 matt pci_decompose_tag(pa->pa_pc, pa->pa_tag, &bus,
149 1.1.2.5 matt NULL, NULL);
150 1.1.2.5 matt if (bus == 0) {
151 1.1.2.5 matt addprop_integer(dev, "frequency", 133333333);
152 1.1.2.5 matt }
153 1.1.2.5 matt } else if (device_is_a(parent, "obio")) {
154 1.1.2.5 matt addprop_integer(dev, "frequency", 66666666);
155 1.1.2.5 matt }
156 1.1.2.5 matt }
157 1.1.2.5 matt }
158 1.1.2.5 matt
159 1.1.2.5 matt static void
160 1.1.2.5 matt rmixl_bus_dma_init(void)
161 1.1.2.5 matt {
162 1.1.2.5 matt struct rmixl_config * const rcp = &rmixl_configuration;
163 1.1.2.5 matt int error;
164 1.1.2.5 matt
165 1.1.2.5 matt /* 64bit dmatag was staticly initialized */
166 1.1.2.5 matt
167 1.1.2.5 matt /* dma space for addr < 4GB */
168 1.1.2.5 matt if (rcp->rc_dmat32 == NULL) {
169 1.1.2.5 matt error = bus_dmatag_subregion(rcp->rc_dmat64,
170 1.1.2.5 matt 0, (bus_addr_t)1 << 32, &rcp->rc_dmat32, 0);
171 1.1.2.5 matt if (error)
172 1.1.2.5 matt panic("%s: failed to create 32bit dma tag: %d",
173 1.1.2.5 matt __func__, error);
174 1.1.2.5 matt }
175 1.1.2.5 matt
176 1.1.2.5 matt /* dma space for addr < 512MB (KSEG0/1) */
177 1.1.2.5 matt if (rcp->rc_dmat29 == NULL) {
178 1.1.2.5 matt error = bus_dmatag_subregion(rcp->rc_dmat32,
179 1.1.2.5 matt 0, (bus_addr_t)1 << 29, &rcp->rc_dmat29, 0);
180 1.1.2.5 matt if (error)
181 1.1.2.5 matt panic("%s: failed to create 29bit dma tag: %d",
182 1.1.2.5 matt __func__, error);
183 1.1.2.5 matt }
184 1.1.2.1 cliff }
185