mainbus.c revision 1.3 1 /* $NetBSD: mainbus.c,v 1.3 2003/03/16 07:07:19 matt 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 "mainbus.h"
34 #include "pci.h"
35 #include "opt_multiprocessor.h"
36 #include "opt_pci.h"
37
38 #include <sys/param.h>
39 #include <sys/extent.h>
40 #include <sys/device.h>
41 #include <sys/malloc.h>
42 #include <sys/systm.h>
43
44 #include <machine/bus.h>
45
46 #include <dev/pci/pcivar.h>
47 #include <dev/pci/pciconf.h>
48
49 #include <dev/marvell/gtvar.h>
50
51 #if NCPU == 0
52 #error A cpu device is now required
53 #endif
54
55 struct mainbus_attach_args {
56 const char *mba_busname;
57 int mba_unit;
58 };
59
60 int mainbus_cfprint(void *, const char *);
61 int mainbus_match(struct device *, struct cfdata *, void *);
62 void mainbus_attach(struct device *, struct device *, void *);
63
64 CFATTACH_DECL(mainbus, sizeof(struct device),
65 mainbus_match, mainbus_attach, NULL, NULL);
66
67 int
68 mainbus_cfprint(void *aux, const char *pnp)
69 {
70 struct mainbus_attach_args *mba = aux;
71
72 if (pnp)
73 aprint_normal("%s at %s", mba->mba_busname, pnp);
74 aprint_normal(" unit %d", mba->mba_unit);
75 return (UNCONF);
76 }
77
78
79 /*
80 * Probe for the mainbus; always succeeds.
81 */
82 int
83 mainbus_match(struct device *parent, struct cfdata *match, void *aux)
84 {
85 return 1;
86 }
87
88 /*
89 * Attach the mainbus.
90 */
91 void
92 mainbus_attach(struct device *parent, struct device *self, void *aux)
93 {
94 struct mainbus_attach_args mba;
95
96 printf("\n");
97
98 memset(&mba, 0, sizeof(mba));
99
100 /*
101 * Always find the CPU
102 */
103 mba.mba_busname = "cpu";
104 mba.mba_unit = 0;
105 config_found(self, &mba, mainbus_cfprint);
106
107 #ifdef MULTIPROCESSOR
108 /*
109 * Try for a second one...
110 */
111 mba.mba_busname = "cpu";
112 mba.mba_unit = 1;
113 config_found(self, &mba, mainbus_cfprint);
114 #endif
115
116 /*
117 * Now try to configure the Discovery
118 */
119 mba.mba_busname = "gt";
120 mba.mba_unit = 0;
121 config_found(self, &mba, mainbus_cfprint);
122 }
123
124 static int cpu_match(struct device *, struct cfdata *, void *);
125 static void cpu_attach(struct device *, struct device *, void *);
126
127 CFATTACH_DECL(cpu, sizeof(struct device), cpu_match, cpu_attach, NULL, NULL);
128
129 extern struct cfdriver cpu_cd;
130
131 int
132 cpu_match(struct device *parent, struct cfdata *cf, void *aux)
133 {
134 struct mainbus_attach_args *mba = aux;
135
136 if (strcmp(mba->mba_busname, cpu_cd.cd_name) != 0)
137 return 0;
138
139 if (cpu_info[0].ci_dev != NULL)
140 return 0;
141
142 return 1;
143 }
144
145 void
146 cpu_attach(struct device *parent, struct device *self, void *aux)
147 {
148 (void) cpu_attach_common(self, 0);
149 }
150