xref: /netbsd/sys/arch/evbppc/ev64260/autoconf.c (revision 40637d6d)
1 /*	$NetBSD: autoconf.c,v 1.17 2012/07/29 18:05:42 mlelstv 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.17 2012/07/29 18:05:42 mlelstv Exp $");
48 
49 #include <sys/param.h>
50 #include <sys/conf.h>
51 #include <sys/device_if.h>
52 #include <sys/reboot.h>
53 #include <sys/systm.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/gtpcivar.h>
63 #include <dev/marvell/gtreg.h>
64 #include <dev/marvell/marvellvar.h>
65 
66 
67 static void findroot(void);
68 
69 
70 /*
71  * Determine i/o configuration for a machine.
72  */
73 void
cpu_configure(void)74 cpu_configure(void)
75 {
76 
77 	if (config_rootfound("mainbus", NULL) == NULL)
78 		panic("configure: mainbus not configured");
79 
80 	spl0();
81 }
82 
83 void
cpu_rootconf(void)84 cpu_rootconf(void)
85 {
86 	findroot();
87 
88 	printf("boot device: %s\n",
89 	    booted_device ? device_xname(booted_device) : "<unknown>");
90 
91 	rootconf();
92 }
93 
94 dev_t	bootdev = 0;
95 
96 /*
97  * Attempt to find the device from which we were booted.
98  * If we can do so, and not instructed not to do so,
99  * change rootdev to correspond to the load device.
100  */
101 static void
findroot(void)102 findroot(void)
103 {
104 	device_t dv;
105 	const char *name;
106 
107 #if 0
108 	printf("howto %x bootdev %x ", boothowto, bootdev);
109 #endif
110 
111 	if ((bootdev & B_MAGICMASK) != (u_long)B_DEVMAGIC)
112 		return;
113 
114 
115 	name = devsw_blk2name(B_TYPE(bootdev));
116 	if (name == NULL)
117 		return;
118 
119 	if ((dv = device_find_by_driver_unit(name, B_UNIT(bootdev))) != NULL) {
120 		booted_device = dv;
121 		booted_partition = B_PARTITION(bootdev);
122 	}
123 }
124 
125 void
device_register(device_t dev,void * aux)126 device_register(device_t dev, void *aux)
127 {
128 	prop_dictionary_t dict = device_properties(dev);
129 
130 	if (device_is_a(dev, "gfe") &&
131 	    device_is_a(device_parent(dev), "gt") ) {
132 		struct marvell_attach_args *mva = aux;
133 		prop_data_t mac;
134 		char enaddr[ETHER_ADDR_LEN] =
135 		    { 0x02, 0x00, 0x04, 0x00, 0x00, 0x04 };
136 
137 		switch (mva->mva_offset) {
138 		case ETH0_BASE:	enaddr[5] |= 0; break;
139 		case ETH1_BASE: enaddr[5] |= 1; break;
140 		case ETH2_BASE: enaddr[5] |= 2; break;
141 		default:
142 			aprint_error("WARNING: unknown mac-no. for %s\n",
143 			    device_xname(dev));
144 		}
145 
146 		mac = prop_data_create_data_nocopy(enaddr, ETHER_ADDR_LEN);
147 		KASSERT(mac != NULL);
148 		if (prop_dictionary_set(dict, "mac-addr", mac) == false)
149 			aprint_error(
150 			    "WARNING: unable to set mac-addr property for %s\n",
151 			    device_xname(dev));
152 		prop_object_release(mac);
153 	}
154 	if (device_is_a(dev, "gtpci")) {
155 		extern struct gtpci_prot gtpci_prot;
156 		extern struct powerpc_bus_space
157 		    ev64260_pci0_io_bs_tag, ev64260_pci0_mem_bs_tag,
158 		    ev64260_pci1_io_bs_tag, ev64260_pci1_mem_bs_tag;
159 		extern struct genppc_pci_chipset
160 		    genppc_gtpci0_chipset, genppc_gtpci1_chipset;
161 
162 		struct marvell_attach_args *mva = aux;
163 		struct powerpc_bus_space *pci_io_bs_tag, *pci_mem_bs_tag;
164 		struct genppc_pci_chipset *genppc_gtpci_chipset;
165 		prop_data_t prot, io_bs_tag, mem_bs_tag, pc;
166 
167 		if (mva->mva_unit == 0) {
168 			pci_io_bs_tag = &ev64260_pci0_io_bs_tag;
169 			pci_mem_bs_tag = &ev64260_pci0_mem_bs_tag;
170 			genppc_gtpci_chipset = &genppc_gtpci0_chipset;
171 		} else {
172 			pci_io_bs_tag = &ev64260_pci1_io_bs_tag;
173 			pci_mem_bs_tag = &ev64260_pci1_mem_bs_tag;
174 			genppc_gtpci_chipset = &genppc_gtpci1_chipset;
175 		}
176 
177 		prot = prop_data_create_data_nocopy(
178 		    &gtpci_prot, sizeof(struct gtpci_prot));
179 		KASSERT(prot != NULL);
180 		prop_dictionary_set(dict, "prot", prot);
181 		prop_object_release(prot);
182 		io_bs_tag = prop_data_create_data_nocopy(
183 		    pci_io_bs_tag, sizeof(struct powerpc_bus_space));
184 		KASSERT(io_bs_tag != NULL);
185 		prop_dictionary_set(dict, "io-bus-tag", io_bs_tag);
186 		prop_object_release(io_bs_tag);
187 		mem_bs_tag = prop_data_create_data_nocopy(
188 		    pci_mem_bs_tag, sizeof(struct powerpc_bus_space));
189 		KASSERT(mem_bs_tag != NULL);
190 		prop_dictionary_set(dict, "mem-bus-tag", mem_bs_tag);
191 		prop_object_release(mem_bs_tag);
192 
193 		genppc_gtpci_chipset->pc_conf_v = device_private(dev);
194 		pc = prop_data_create_data_nocopy(genppc_gtpci_chipset,
195 		    sizeof(struct genppc_pci_chipset));
196 		KASSERT(pc != NULL);
197 		prop_dictionary_set(dict, "pci-chipset", pc);
198 		prop_object_release(pc);
199 
200 		prop_dictionary_set_uint64(dict, "iostart", 0x00000600);
201 		prop_dictionary_set_uint64(dict, "ioend", 0x0000ffff);
202 		prop_dictionary_set_uint64(dict, "memstart",
203 		    pci_mem_bs_tag->pbs_base);
204 		prop_dictionary_set_uint64(dict, "memend",
205 		    pci_mem_bs_tag->pbs_limit - 1);
206 		prop_dictionary_set_uint32(dict, "cache-line-size", 32);
207 	}
208 	if (device_is_a(dev, "obio") &&
209 	    device_is_a(device_parent(dev), "gt") ) {
210 		extern struct powerpc_bus_space *ev64260_obio_bs_tags[5];
211 		struct marvell_attach_args *mva = aux;
212 		struct powerpc_bus_space *bst =
213 		    ev64260_obio_bs_tags[mva->mva_unit];
214 		prop_data_t bstd;
215 
216 		bstd =
217 		    prop_data_create_data_nocopy(bst, sizeof(bus_space_tag_t));
218 		KASSERT(bstd != NULL);
219 		if (prop_dictionary_set(dict, "bus-tag", bstd) == false)
220 			aprint_error(
221 			    "WARNING: unable to set bus-tag property for %s\n",
222 			    device_xname(dev));
223 		prop_object_release(bstd);
224 	}
225 }
226