mainbus.c revision 1.28.4.1 1 1.28.4.1 thorpej /* $NetBSD: mainbus.c,v 1.28.4.1 2021/03/22 02:00:54 thorpej Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.1 thorpej * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1 thorpej * by Jason R. Thorpe.
9 1.1 thorpej *
10 1.1 thorpej * Redistribution and use in source and binary forms, with or without
11 1.1 thorpej * modification, are permitted provided that the following conditions
12 1.1 thorpej * are met:
13 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.1 thorpej * notice, this list of conditions and the following disclaimer.
15 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.1 thorpej * documentation and/or other materials provided with the distribution.
18 1.1 thorpej *
19 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
30 1.1 thorpej */
31 1.14 lukem
32 1.14 lukem #include <sys/cdefs.h>
33 1.28.4.1 thorpej __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.28.4.1 2021/03/22 02:00:54 thorpej Exp $");
34 1.1 thorpej
35 1.1 thorpej #include "opt_algor_p4032.h"
36 1.1 thorpej #include "opt_algor_p5064.h"
37 1.1 thorpej #include "opt_algor_p6032.h"
38 1.1 thorpej
39 1.1 thorpej #include "opt_pci.h"
40 1.1 thorpej
41 1.1 thorpej #include <sys/param.h>
42 1.25 matt #include <sys/bus.h>
43 1.1 thorpej #include <sys/conf.h>
44 1.1 thorpej #include <sys/device.h>
45 1.1 thorpej #include <sys/malloc.h>
46 1.25 matt #include <sys/reboot.h>
47 1.25 matt #include <sys/systm.h>
48 1.1 thorpej
49 1.25 matt #include <algor/autoconf.h>
50 1.1 thorpej
51 1.7 thorpej #include <mips/cache.h>
52 1.7 thorpej
53 1.1 thorpej #include <dev/pci/pcivar.h>
54 1.1 thorpej #include <dev/pci/pciconf.h>
55 1.1 thorpej
56 1.4 thorpej #if defined(PCI_NETBSD_CONFIGURE) && defined(PCI_NETBSD_ENABLE_IDE)
57 1.4 thorpej #if defined(ALGOR_P5064) || defined(ALGOR_P6032)
58 1.4 thorpej #include <dev/pci/pciide_piix_reg.h>
59 1.4 thorpej #endif /* ALGOR_P5064 || ALGOR_P6032 */
60 1.4 thorpej #endif /* PCI_NETBSD_CONFIGURE && PCI_NETBSD_ENABLE_IDE */
61 1.4 thorpej
62 1.1 thorpej #include "locators.h"
63 1.1 thorpej #include "pci.h"
64 1.1 thorpej
65 1.22 matt int mainbus_match(device_t, cfdata_t, void *);
66 1.22 matt void mainbus_attach(device_t, device_t, void *);
67 1.1 thorpej
68 1.22 matt CFATTACH_DECL_NEW(mainbus, 0,
69 1.12 thorpej mainbus_match, mainbus_attach, NULL, NULL);
70 1.1 thorpej
71 1.1 thorpej int mainbus_print(void *, const char *);
72 1.22 matt int mainbus_submatch(device_t, cfdata_t,
73 1.18 drochner const int *, void *);
74 1.1 thorpej
75 1.1 thorpej /* There can be only one. */
76 1.1 thorpej int mainbus_found;
77 1.1 thorpej
78 1.2 thorpej struct mainbusdev {
79 1.2 thorpej const char *md_name;
80 1.2 thorpej bus_addr_t md_addr;
81 1.2 thorpej int md_irq;
82 1.2 thorpej };
83 1.2 thorpej
84 1.2 thorpej #if defined(ALGOR_P4032)
85 1.2 thorpej #include <algor/algor/algor_p4032reg.h>
86 1.2 thorpej #include <algor/algor/algor_p4032var.h>
87 1.2 thorpej
88 1.2 thorpej struct mainbusdev mainbusdevs[] = {
89 1.2 thorpej { "cpu", -1, -1 },
90 1.2 thorpej { "mcclock", P4032_RTC, P4032_IRQ_RTC },
91 1.2 thorpej { "com", P4032_COM1, P4032_IRQ_COM1 },
92 1.2 thorpej { "com", P4032_COM2, P4032_IRQ_COM2 },
93 1.2 thorpej { "lpt", P4032_LPT, P4032_IRQ_LPT },
94 1.2 thorpej { "pckbc", P4032_PCKBC, P4032_IRQ_PCKBC },
95 1.2 thorpej { "fdc", P4032_FDC, P4032_IRQ_FLOPPY },
96 1.2 thorpej { "vtpbc", P4032_V962PBC, -1 },
97 1.2 thorpej
98 1.2 thorpej { NULL, 0, 0 },
99 1.2 thorpej };
100 1.28 thorpej
101 1.28 thorpej /* Reserve the bottom 64K of the I/O space for ISA devices. */
102 1.28 thorpej #define PCI_IO_START 0x00010000
103 1.28 thorpej #define PCI_IO_END 0x000effff
104 1.28 thorpej #define PCI_MEM_START 0x01000000
105 1.28 thorpej #define PCI_MEM_END 0x07ffffff
106 1.28 thorpej #define PCI_CHIPSET &p4032_configuration.ac_pc
107 1.2 thorpej #endif /* ALGOR_P4032 */
108 1.2 thorpej
109 1.1 thorpej #if defined(ALGOR_P5064)
110 1.1 thorpej #include <algor/algor/algor_p5064reg.h>
111 1.1 thorpej #include <algor/algor/algor_p5064var.h>
112 1.1 thorpej
113 1.2 thorpej struct mainbusdev mainbusdevs[] = {
114 1.2 thorpej { "cpu", -1, -1 },
115 1.2 thorpej { "vtpbc", P5064_V360EPC, -1 },
116 1.1 thorpej
117 1.2 thorpej { NULL, 0, 0 },
118 1.1 thorpej };
119 1.28 thorpej
120 1.28 thorpej /*
121 1.28 thorpej * Reserve the bottom 512K of the I/O space for ISA devices.
122 1.28 thorpej * According to the PMON sources, this is a work-around for
123 1.28 thorpej * a bug in the ISA bridge.
124 1.28 thorpej */
125 1.28 thorpej #define PCI_IO_START 0x00080000
126 1.28 thorpej #define PCI_IO_END 0x00ffffff
127 1.28 thorpej #define PCI_MEM_START 0x01000000
128 1.28 thorpej #define PCI_MEM_END 0x07ffffff
129 1.28 thorpej #define PCI_IDE_DEV 2
130 1.28 thorpej #define PCI_IDE_FUNC 1
131 1.28 thorpej #define PCI_CHIPSET &p5064_configuration.ac_pc
132 1.1 thorpej #endif /* ALGOR_P5064 */
133 1.1 thorpej
134 1.3 thorpej #if defined(ALGOR_P6032)
135 1.3 thorpej #include <algor/algor/algor_p6032reg.h>
136 1.3 thorpej #include <algor/algor/algor_p6032var.h>
137 1.3 thorpej
138 1.3 thorpej struct mainbusdev mainbusdevs[] = {
139 1.3 thorpej { "cpu", -1, -1 },
140 1.3 thorpej { "bonito", BONITO_REG_BASE, -1 },
141 1.3 thorpej
142 1.3 thorpej { NULL, 0, 0 },
143 1.3 thorpej };
144 1.28 thorpej
145 1.28 thorpej /* Reserve the bottom 64K of the I/O space for ISA devices. */
146 1.28 thorpej #define PCI_IO_START 0x00010000
147 1.28 thorpej #define PCI_IO_END 0x000effff
148 1.28 thorpej #define PCI_MEM_START 0x01000000
149 1.28 thorpej #define PCI_MEM_END 0x0affffff
150 1.28 thorpej #define PCI_IDE_DEV 17
151 1.28 thorpej #define PCI_IDE_FUNC 1
152 1.28 thorpej #define PCI_CHIPSET &p6032_configuration.ac_pc
153 1.3 thorpej #endif /* ALGOR_P6032 */
154 1.3 thorpej
155 1.28 thorpej #define PCI_IO_SIZE ((PCI_IO_END - PCI_IO_START) + 1)
156 1.28 thorpej #define PCI_MEM_SIZE ((PCI_MEM_END - PCI_MEM_START) + 1)
157 1.28 thorpej
158 1.1 thorpej int
159 1.22 matt mainbus_match(device_t parent, cfdata_t cf, void *aux)
160 1.1 thorpej {
161 1.1 thorpej
162 1.1 thorpej if (mainbus_found)
163 1.1 thorpej return (0);
164 1.1 thorpej
165 1.1 thorpej return (1);
166 1.1 thorpej }
167 1.1 thorpej
168 1.1 thorpej void
169 1.22 matt mainbus_attach(device_t parent, device_t self, void *aux)
170 1.1 thorpej {
171 1.2 thorpej struct mainbus_attach_args ma;
172 1.2 thorpej struct mainbusdev *md;
173 1.2 thorpej bus_space_tag_t st;
174 1.1 thorpej
175 1.1 thorpej mainbus_found = 1;
176 1.1 thorpej
177 1.1 thorpej printf("\n");
178 1.1 thorpej
179 1.1 thorpej #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
180 1.28 thorpej struct pciconf_resources *pcires = pciconf_resource_init();
181 1.1 thorpej
182 1.28 thorpej pciconf_resource_add(pcires, PCICONF_RESOURCE_IO,
183 1.28 thorpej PCI_IO_START, PCI_IO_SIZE);
184 1.28 thorpej pciconf_resource_add(pcires, PCICONF_RESOURCE_MEM,
185 1.28 thorpej PCI_MEM_START, PCI_MEM_SIZE);
186 1.28 thorpej
187 1.28 thorpej pci_configure_bus(PCI_CHIPSET, pcires, 0,
188 1.28 thorpej mips_cache_info.mci_dcache_align);
189 1.28 thorpej pciconf_resource_fini(pcires);
190 1.4 thorpej
191 1.4 thorpej #if defined(PCI_NETBSD_ENABLE_IDE)
192 1.4 thorpej /*
193 1.4 thorpej * Perhaps PMON has not enabled the IDE controller. Easy to
194 1.4 thorpej * fix -- just set the ENABLE bits for each channel in the
195 1.4 thorpej * IDETIM register. Just clear all the bits for the channel
196 1.4 thorpej * except for the ENABLE bits -- the `pciide' driver will
197 1.4 thorpej * properly configure it later.
198 1.4 thorpej */
199 1.28 thorpej pcitag_t idetag = pci_make_tag(PCI_CHIPSET, 0, PCI_IDE_DEV,
200 1.28 thorpej PCI_IDE_FUNC);
201 1.28 thorpej pcireg_t idetim = 0;
202 1.4 thorpej if (PCI_NETBSD_ENABLE_IDE & 0x01)
203 1.4 thorpej idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 0);
204 1.4 thorpej if (PCI_NETBSD_ENABLE_IDE & 0x02)
205 1.4 thorpej idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 1);
206 1.28 thorpej pci_conf_write(PCI_CHIPSET, idetag, PIIX_IDETIM, idetim);
207 1.4 thorpej #endif
208 1.1 thorpej #endif /* NPCI > 0 && defined(PCI_NETBSD_CONFIGURE) */
209 1.1 thorpej
210 1.2 thorpej #if defined(ALGOR_P4032)
211 1.2 thorpej st = &p4032_configuration.ac_lociot;
212 1.2 thorpej #elif defined(ALGOR_P5064)
213 1.3 thorpej st = NULL;
214 1.3 thorpej #elif defined(ALGOR_P6032)
215 1.2 thorpej st = NULL;
216 1.2 thorpej #endif
217 1.2 thorpej
218 1.2 thorpej for (md = mainbusdevs; md->md_name != NULL; md++) {
219 1.2 thorpej ma.ma_name = md->md_name;
220 1.2 thorpej ma.ma_st = st;
221 1.2 thorpej ma.ma_addr = md->md_addr;
222 1.2 thorpej ma.ma_irq = md->md_irq;
223 1.28.4.1 thorpej config_found(self, &ma, mainbus_print,
224 1.28.4.1 thorpej CFARG_SUBMATCH, mainbus_submatch,
225 1.28.4.1 thorpej CFARG_IATTR, "mainbus",
226 1.28.4.1 thorpej CFARG_EOL);
227 1.2 thorpej }
228 1.1 thorpej }
229 1.1 thorpej
230 1.1 thorpej int
231 1.1 thorpej mainbus_print(void *aux, const char *pnp)
232 1.1 thorpej {
233 1.1 thorpej struct mainbus_attach_args *ma = aux;
234 1.1 thorpej
235 1.1 thorpej if (pnp)
236 1.13 thorpej aprint_normal("%s at %s", ma->ma_name, pnp);
237 1.1 thorpej if (ma->ma_addr != (bus_addr_t) -1)
238 1.24 matt aprint_normal(" addr %#" PRIxBUSADDR, ma->ma_addr);
239 1.1 thorpej
240 1.1 thorpej return (UNCONF);
241 1.1 thorpej }
242 1.1 thorpej
243 1.1 thorpej int
244 1.22 matt mainbus_submatch(device_t parent, cfdata_t cf,
245 1.18 drochner const int *ldesc, void *aux)
246 1.1 thorpej {
247 1.1 thorpej struct mainbus_attach_args *ma = aux;
248 1.1 thorpej
249 1.1 thorpej if (cf->cf_loc[MAINBUSCF_ADDR] != MAINBUSCF_ADDR_DEFAULT &&
250 1.1 thorpej cf->cf_loc[MAINBUSCF_ADDR] != ma->ma_addr)
251 1.1 thorpej return (0);
252 1.1 thorpej
253 1.9 thorpej return (config_match(parent, cf, aux));
254 1.1 thorpej }
255