mainbus.c revision 1.1.6.1 1 1.1.6.1 joerg /* $NetBSD: mainbus.c,v 1.1.6.1 2007/11/02 13:34:37 joerg Exp $ */
2 1.1.6.1 joerg
3 1.1.6.1 joerg /*
4 1.1.6.1 joerg * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.1.6.1 joerg * All rights reserved.
6 1.1.6.1 joerg *
7 1.1.6.1 joerg * This code is derived from software contributed to The NetBSD Foundation
8 1.1.6.1 joerg * by Lennart Augustsson (lennart (at) augustsson.net) at Sandburst Corp.
9 1.1.6.1 joerg *
10 1.1.6.1 joerg * Redistribution and use in source and binary forms, with or without
11 1.1.6.1 joerg * modification, are permitted provided that the following conditions
12 1.1.6.1 joerg * are met:
13 1.1.6.1 joerg * 1. Redistributions of source code must retain the above copyright
14 1.1.6.1 joerg * notice, this list of conditions and the following disclaimer.
15 1.1.6.1 joerg * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.6.1 joerg * notice, this list of conditions and the following disclaimer in the
17 1.1.6.1 joerg * documentation and/or other materials provided with the distribution.
18 1.1.6.1 joerg * 3. All advertising materials mentioning features or use of this software
19 1.1.6.1 joerg * must display the following acknowledgement:
20 1.1.6.1 joerg * This product includes software developed by the NetBSD
21 1.1.6.1 joerg * Foundation, Inc. and its contributors.
22 1.1.6.1 joerg * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.6.1 joerg * contributors may be used to endorse or promote products derived
24 1.1.6.1 joerg * from this software without specific prior written permission.
25 1.1.6.1 joerg *
26 1.1.6.1 joerg * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.6.1 joerg * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.6.1 joerg * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.6.1 joerg * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.6.1 joerg * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.6.1 joerg * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.6.1 joerg * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.6.1 joerg * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.6.1 joerg * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.6.1 joerg * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.6.1 joerg * POSSIBILITY OF SUCH DAMAGE.
37 1.1.6.1 joerg */
38 1.1.6.1 joerg
39 1.1.6.1 joerg #include <sys/cdefs.h>
40 1.1.6.1 joerg __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.1.6.1 2007/11/02 13:34:37 joerg Exp $");
41 1.1.6.1 joerg
42 1.1.6.1 joerg #include <sys/param.h>
43 1.1.6.1 joerg #include <sys/device.h>
44 1.1.6.1 joerg #include <sys/systm.h>
45 1.1.6.1 joerg
46 1.1.6.1 joerg #include <machine/bus.h>
47 1.1.6.1 joerg #include <machine/pmppc.h>
48 1.1.6.1 joerg #include <arch/evbppc/pmppc/dev/mainbus.h>
49 1.1.6.1 joerg
50 1.1.6.1 joerg #include <dev/ic/cpc700reg.h>
51 1.1.6.1 joerg
52 1.1.6.1 joerg #include "locators.h"
53 1.1.6.1 joerg #include "mainbus.h"
54 1.1.6.1 joerg
55 1.1.6.1 joerg #if NCPU == 0
56 1.1.6.1 joerg #error A cpu device is now required
57 1.1.6.1 joerg #endif
58 1.1.6.1 joerg
59 1.1.6.1 joerg int mainbus_match(struct device *, struct cfdata *, void *);
60 1.1.6.1 joerg void mainbus_attach(struct device *, struct device *, void *);
61 1.1.6.1 joerg
62 1.1.6.1 joerg CFATTACH_DECL(mainbus, sizeof(struct device),
63 1.1.6.1 joerg mainbus_match, mainbus_attach, NULL, NULL);
64 1.1.6.1 joerg
65 1.1.6.1 joerg static int mainbus_print(void *, const char *);
66 1.1.6.1 joerg
67 1.1.6.1 joerg /*
68 1.1.6.1 joerg * Probe for the mainbus; always succeeds.
69 1.1.6.1 joerg */
70 1.1.6.1 joerg int
71 1.1.6.1 joerg mainbus_match(struct device *parent, struct cfdata *match, void *aux)
72 1.1.6.1 joerg {
73 1.1.6.1 joerg
74 1.1.6.1 joerg return 1;
75 1.1.6.1 joerg }
76 1.1.6.1 joerg
77 1.1.6.1 joerg static int
78 1.1.6.1 joerg mainbus_submatch(struct device *parent, struct cfdata *cf,
79 1.1.6.1 joerg const int *ldesc, void *aux)
80 1.1.6.1 joerg {
81 1.1.6.1 joerg struct mainbus_attach_args *maa = aux;
82 1.1.6.1 joerg
83 1.1.6.1 joerg if (cf->cf_loc[MAINBUSCF_ADDR] != maa->mb_addr)
84 1.1.6.1 joerg return (0);
85 1.1.6.1 joerg
86 1.1.6.1 joerg return (config_match(parent, cf, aux));
87 1.1.6.1 joerg }
88 1.1.6.1 joerg
89 1.1.6.1 joerg static int
90 1.1.6.1 joerg mainbus_print(void *aux, const char *pnp)
91 1.1.6.1 joerg {
92 1.1.6.1 joerg struct mainbus_attach_args *mba = aux;
93 1.1.6.1 joerg
94 1.1.6.1 joerg if (pnp)
95 1.1.6.1 joerg aprint_normal("%s at %s", mba->mb_name, pnp);
96 1.1.6.1 joerg if (mba->mb_addr != MAINBUSCF_ADDR_DEFAULT)
97 1.1.6.1 joerg aprint_normal(" addr 0x%08lx", mba->mb_addr);
98 1.1.6.1 joerg if (mba->mb_irq != MAINBUSCF_IRQ_DEFAULT)
99 1.1.6.1 joerg aprint_normal(" irq %d", mba->mb_irq);
100 1.1.6.1 joerg return (UNCONF);
101 1.1.6.1 joerg }
102 1.1.6.1 joerg
103 1.1.6.1 joerg /*
104 1.1.6.1 joerg * Attach the mainbus.
105 1.1.6.1 joerg */
106 1.1.6.1 joerg void
107 1.1.6.1 joerg mainbus_attach(struct device *parent, struct device *self, void *aux)
108 1.1.6.1 joerg {
109 1.1.6.1 joerg struct mainbus_attach_args maa;
110 1.1.6.1 joerg
111 1.1.6.1 joerg printf(": Artesyn PM/PPC\n");
112 1.1.6.1 joerg printf("%s: %sPCI bus Monarch\n", self->dv_xname,
113 1.1.6.1 joerg a_config.a_is_monarch ? "" : "not");
114 1.1.6.1 joerg printf("%s: boot from %s, %sECC, %s L2 cache\n",
115 1.1.6.1 joerg self->dv_xname,
116 1.1.6.1 joerg a_config.a_boot_device == A_BOOT_ROM ? "ROM" : "flash",
117 1.1.6.1 joerg a_config.a_has_ecc ? "" : "no ",
118 1.1.6.1 joerg a_config.a_l2_cache == A_CACHE_PARITY ? "parity" :
119 1.1.6.1 joerg a_config.a_l2_cache == A_CACHE_NO_PARITY ? "no-parity" : "no");
120 1.1.6.1 joerg
121 1.1.6.1 joerg maa.mb_bt = &pmppc_mem_tag;
122 1.1.6.1 joerg
123 1.1.6.1 joerg maa.mb_name = "cpu";
124 1.1.6.1 joerg maa.mb_addr = MAINBUSCF_ADDR_DEFAULT;
125 1.1.6.1 joerg maa.mb_irq = MAINBUSCF_IRQ_DEFAULT;
126 1.1.6.1 joerg config_found(self, &maa, mainbus_print);
127 1.1.6.1 joerg
128 1.1.6.1 joerg if (a_config.a_has_rtc) {
129 1.1.6.1 joerg maa.mb_name = "rtc";
130 1.1.6.1 joerg maa.mb_addr = PMPPC_RTC;
131 1.1.6.1 joerg maa.mb_irq = PMPPC_I_RTC_INT;
132 1.1.6.1 joerg config_found_sm_loc(self, "mainbus", NULL, &maa, mainbus_print,
133 1.1.6.1 joerg mainbus_submatch);
134 1.1.6.1 joerg }
135 1.1.6.1 joerg
136 1.1.6.1 joerg if (a_config.a_has_eth) {
137 1.1.6.1 joerg maa.mb_name = "cs";
138 1.1.6.1 joerg maa.mb_addr = PMPPC_CS_IO_BASE;
139 1.1.6.1 joerg maa.mb_irq = PMPPC_I_ETH_INT;
140 1.1.6.1 joerg config_found_sm_loc(self, "mainbus", NULL, &maa, mainbus_print,
141 1.1.6.1 joerg mainbus_submatch);
142 1.1.6.1 joerg maa.mb_bt = &pmppc_mem_tag;
143 1.1.6.1 joerg }
144 1.1.6.1 joerg if (a_config.a_flash_width != 0) {
145 1.1.6.1 joerg maa.mb_name = "flash";
146 1.1.6.1 joerg maa.mb_addr = PMPPC_FLASH_BASE;
147 1.1.6.1 joerg maa.mb_irq = MAINBUSCF_IRQ_DEFAULT;
148 1.1.6.1 joerg maa.u.mb_flash.size = a_config.a_flash_size;
149 1.1.6.1 joerg maa.u.mb_flash.width = a_config.a_flash_width;
150 1.1.6.1 joerg config_found_sm_loc(self, "mainbus", NULL, &maa, mainbus_print,
151 1.1.6.1 joerg mainbus_submatch);
152 1.1.6.1 joerg }
153 1.1.6.1 joerg
154 1.1.6.1 joerg maa.mb_name = "cpc";
155 1.1.6.1 joerg maa.mb_addr = MAINBUSCF_ADDR_DEFAULT;
156 1.1.6.1 joerg maa.mb_irq = MAINBUSCF_IRQ_DEFAULT;
157 1.1.6.1 joerg config_found(self, &maa, mainbus_print);
158 1.1.6.1 joerg }
159 1.1.6.1 joerg
160 1.1.6.1 joerg static int cpu_match(struct device *, struct cfdata *, void *);
161 1.1.6.1 joerg static void cpu_attach(struct device *, struct device *, void *);
162 1.1.6.1 joerg
163 1.1.6.1 joerg CFATTACH_DECL(cpu, sizeof(struct device),
164 1.1.6.1 joerg cpu_match, cpu_attach, NULL, NULL);
165 1.1.6.1 joerg
166 1.1.6.1 joerg extern struct cfdriver cpu_cd;
167 1.1.6.1 joerg
168 1.1.6.1 joerg int
169 1.1.6.1 joerg cpu_match(struct device *parent, struct cfdata *cf, void *aux)
170 1.1.6.1 joerg {
171 1.1.6.1 joerg struct mainbus_attach_args *maa = aux;
172 1.1.6.1 joerg
173 1.1.6.1 joerg if (strcmp(maa->mb_name, cpu_cd.cd_name) != 0)
174 1.1.6.1 joerg return 0;
175 1.1.6.1 joerg
176 1.1.6.1 joerg if (cpu_info[0].ci_dev != NULL)
177 1.1.6.1 joerg return 0;
178 1.1.6.1 joerg
179 1.1.6.1 joerg return 1;
180 1.1.6.1 joerg }
181 1.1.6.1 joerg
182 1.1.6.1 joerg void
183 1.1.6.1 joerg cpu_attach(struct device *parent, struct device *self, void *aux)
184 1.1.6.1 joerg {
185 1.1.6.1 joerg (void) cpu_attach_common(self, 0);
186 1.1.6.1 joerg }
187