xref: /netbsd/sys/arch/algor/algor/autoconf.c (revision 6550d01e)
1 /*	$NetBSD: autoconf.c,v 1.18 2010/01/22 08:56:04 martin Exp $	*/
2 
3 /*-
4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe.
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  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.18 2010/01/22 08:56:04 martin Exp $");
34 
35 #include "opt_algor_p4032.h"
36 #include "opt_algor_p5064.h"
37 #include "opt_algor_p6032.h"
38 
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/conf.h>
42 #include <sys/reboot.h>
43 #include <sys/device.h>
44 
45 #include <dev/pci/pcivar.h>
46 
47 #include <net/if.h>
48 #include <net/if_ether.h>
49 
50 #include <machine/bus.h>
51 #include <machine/autoconf.h>
52 #include <machine/intr.h>
53 
54 #ifdef ALGOR_P4032
55 #include <algor/algor/algor_p4032var.h>
56 #endif
57 
58 void
59 cpu_configure(void)
60 {
61 
62 	intr_init();
63 
64 	(void) splhigh();
65 	if (config_rootfound("mainbus", NULL) == 0)
66 		panic("no mainbus found");
67 
68 	/*
69 	 * Hardware interrupts will be enabled in
70 	 * sys/arch/mips/mips/mips3_clockintr.c:mips3_initclocks()
71 	 * to avoid hardclock(9) by CPU INT5 before softclockintr is
72 	 * initialized in initclocks().
73 	 */
74 }
75 
76 void
77 cpu_rootconf(void)
78 {
79 
80 	setroot(booted_device, booted_partition);
81 }
82 
83 #if defined(ALGOR_P4032)
84 #define	BUILTIN_ETHERNET_P(pa)						\
85 	((pa)->pa_bus == 0 && (pa)->pa_device == 5 && (pa)->pa_function == 0)
86 #elif defined(ALGOR_P5064)
87 #define	BUILTIN_ETHERNET_P(pa)						\
88 	((pa)->pa_bus == 0 && (pa)->pa_device == 0 && (pa)->pa_function == 0)
89 #elif defined(ALGOR_P6032)
90 #define	BUILTIN_ETHERNET_P(pa)						\
91 	((pa)->pa_bus == 0 && (pa)->pa_device == 16 && (pa)->pa_function == 0)
92 #else
93 #define	BUILTIN_ETHERNET_P(pa)	0
94 #endif
95 
96 void
97 device_register(struct device *dev, void *aux)
98 {
99 	struct device *pdev;
100 
101 	/*
102 	 * We don't ever know the boot device.  But that's because the
103 	 * firmware only loads from the network or the parallel port.
104 	 */
105 
106 	/*
107 	 * Fetch the MAC address for the built-in Ethernet (we grab it
108 	 * from PMON earlier in the boot process).
109 	 */
110 	if ((pdev = device_parent(dev)) != NULL && device_is_a(pdev, "pci")) {
111 		struct pci_attach_args *pa = aux;
112 
113 		if (BUILTIN_ETHERNET_P(pa)) {
114 			prop_data_t pd = prop_data_create_data_nocopy(
115 			    algor_ethaddr, ETHER_ADDR_LEN);
116 			KASSERT(pd != NULL);
117 			if (prop_dictionary_set(device_properties(dev),
118 						"mac-address", pd) == false) {
119 				printf("WARNING: unable to set mac-addr "
120 				    "property for %s\n", dev->dv_xname);
121 			}
122 			prop_object_release(pd);
123 #if defined(ALGOR_P4032)
124 			/*
125 			 * XXX This is gross, disgusting, and otherwise vile,
126 			 * XXX but V962 rev. < B2 have broken DMA FIFOs.  Give
127 			 * XXX the on-board Ethernet a different DMA window
128 			 * XXX that has pre-fetching disabled so that Ethernet
129 			 * XXX performance doesn't completely suck.
130 			 */
131 			pa->pa_dmat = &p4032_configuration.ac_pci_pf_dmat;
132 			pa->pa_dmat64 = NULL;
133 #endif /* ALGOR_P4032 */
134 		}
135 	}
136 }
137