xref: /netbsd-src/sys/arch/evbppc/ev64260/mainbus.c (revision 27527e67bbdf8d9ec84fd58803048ed6d181ece2)
1 /*	$NetBSD: mainbus.c,v 1.5 2005/12/11 12:17:12 christos Exp $	*/
2 
3 /*
4  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *      This product includes software developed by Christopher G. Demetriou
17  *	for the NetBSD Project.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.5 2005/12/11 12:17:12 christos Exp $");
35 
36 #include "mainbus.h"
37 #include "pci.h"
38 #include "opt_multiprocessor.h"
39 #include "opt_pci.h"
40 
41 #include <sys/param.h>
42 #include <sys/extent.h>
43 #include <sys/device.h>
44 #include <sys/malloc.h>
45 #include <sys/systm.h>
46 
47 #include <machine/bus.h>
48 
49 #include <dev/pci/pcivar.h>
50 #include <dev/pci/pciconf.h>
51 
52 #include <dev/marvell/gtvar.h>
53 
54 #if NCPU == 0
55 #error	A cpu device is now required
56 #endif
57 
58 struct	mainbus_attach_args {
59 	const char *mba_busname;
60 	int mba_unit;
61 };
62 
63 int	mainbus_cfprint(void *, const char *);
64 int	mainbus_match(struct device *, struct cfdata *, void *);
65 void	mainbus_attach(struct device *, struct device *, void *);
66 
67 CFATTACH_DECL(mainbus, sizeof(struct device),
68 	mainbus_match, mainbus_attach, NULL, NULL);
69 
70 int
71 mainbus_cfprint(void *aux, const char *pnp)
72 {
73 	struct mainbus_attach_args *mba = aux;
74 
75 	if (pnp)
76 		aprint_normal("%s at %s", mba->mba_busname, pnp);
77 	aprint_normal(" unit %d", mba->mba_unit);
78 	return (UNCONF);
79 }
80 
81 
82 /*
83  * Probe for the mainbus; always succeeds.
84  */
85 int
86 mainbus_match(struct device *parent, struct cfdata *match, void *aux)
87 {
88 	return 1;
89 }
90 
91 /*
92  * Attach the mainbus.
93  */
94 void
95 mainbus_attach(struct device *parent, struct device *self, void *aux)
96 {
97 	struct mainbus_attach_args mba;
98 
99 	printf("\n");
100 
101 	memset(&mba, 0, sizeof(mba));
102 
103 	/*
104 	 * Always find the CPU
105 	 */
106 	mba.mba_busname = "cpu";
107 	mba.mba_unit = 0;
108 	config_found(self, &mba, mainbus_cfprint);
109 
110 #ifdef MULTIPROCESSOR
111 	/*
112 	 * Try for a second one...
113 	 */
114 	mba.mba_busname = "cpu";
115 	mba.mba_unit = 1;
116 	config_found(self, &mba, mainbus_cfprint);
117 #endif
118 
119 	/*
120 	 * Now try to configure the Discovery
121 	 */
122 	mba.mba_busname = "gt";
123 	mba.mba_unit = 0;
124 	config_found(self, &mba, mainbus_cfprint);
125 }
126 
127 static int	cpu_match(struct device *, struct cfdata *, void *);
128 static void	cpu_attach(struct device *, struct device *, void *);
129 
130 CFATTACH_DECL(cpu, sizeof(struct device), cpu_match, cpu_attach, NULL, NULL);
131 
132 extern struct cfdriver cpu_cd;
133 
134 int
135 cpu_match(struct device *parent, struct cfdata *cf, void *aux)
136 {
137 	struct mainbus_attach_args *mba = aux;
138 
139 	if (strcmp(mba->mba_busname, cpu_cd.cd_name) != 0)
140 		return 0;
141 
142 	if (cpu_info[0].ci_dev != NULL)
143 		return 0;
144 
145 	return 1;
146 }
147 
148 void
149 cpu_attach(struct device *parent, struct device *self, void *aux)
150 {
151 	(void) cpu_attach_common(self, 0);
152 }
153