txcsbus.c revision 1.22.52.2 1 1.22.52.2 thorpej /* $NetBSD: txcsbus.c,v 1.22.52.2 2021/03/20 20:49:43 thorpej Exp $ */
2 1.1 uch
3 1.5 uch /*-
4 1.5 uch * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 1.1 uch * All rights reserved.
6 1.1 uch *
7 1.5 uch * This code is derived from software contributed to The NetBSD Foundation
8 1.5 uch * by UCHIYAMA Yasushi.
9 1.5 uch *
10 1.1 uch * Redistribution and use in source and binary forms, with or without
11 1.1 uch * modification, are permitted provided that the following conditions
12 1.1 uch * are met:
13 1.1 uch * 1. Redistributions of source code must retain the above copyright
14 1.1 uch * notice, this list of conditions and the following disclaimer.
15 1.5 uch * 2. Redistributions in binary form must reproduce the above copyright
16 1.5 uch * notice, this list of conditions and the following disclaimer in the
17 1.5 uch * documentation and/or other materials provided with the distribution.
18 1.1 uch *
19 1.5 uch * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.5 uch * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.5 uch * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.5 uch * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.5 uch * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.5 uch * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.5 uch * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.5 uch * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.5 uch * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.5 uch * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.5 uch * POSSIBILITY OF SUCH DAMAGE.
30 1.1 uch */
31 1.15 lukem
32 1.15 lukem #include <sys/cdefs.h>
33 1.22.52.2 thorpej __KERNEL_RCSID(0, "$NetBSD: txcsbus.c,v 1.22.52.2 2021/03/20 20:49:43 thorpej Exp $");
34 1.1 uch
35 1.1 uch #include <sys/param.h>
36 1.1 uch #include <sys/systm.h>
37 1.1 uch #include <sys/device.h>
38 1.1 uch
39 1.6 takemura #include <machine/intr.h>
40 1.1 uch #include <machine/bus.h>
41 1.6 takemura #include <machine/bus_space_hpcmips.h>
42 1.1 uch
43 1.1 uch #include <machine/platid.h>
44 1.1 uch #include <machine/platid_mask.h>
45 1.1 uch
46 1.1 uch #include <hpcmips/tx/tx39var.h>
47 1.1 uch #include <hpcmips/tx/txcsbusvar.h>
48 1.1 uch #include <hpcmips/tx/tx39biuvar.h>
49 1.1 uch #include <hpcmips/tx/tx39biureg.h>
50 1.1 uch
51 1.1 uch #include "locators.h"
52 1.1 uch
53 1.3 uch /* TX39 CS mapping. (nonconfigurationable) */
54 1.3 uch const struct csmap {
55 1.16 he const char *cs_name;
56 1.3 uch paddr_t cs_addr;
57 1.3 uch psize_t cs_size;
58 1.3 uch } __csmap[] = {
59 1.3 uch [TX39_CS0] = {"CS0(ROM)" , TX39_SYSADDR_CS0 ,
60 1.3 uch TX39_SYSADDR_CS_SIZE},
61 1.3 uch [TX39_CS1] = {"CS1" , TX39_SYSADDR_CS1 ,
62 1.3 uch TX39_SYSADDR_CS_SIZE},
63 1.3 uch [TX39_CS2] = {"CS2" , TX39_SYSADDR_CS2 ,
64 1.3 uch TX39_SYSADDR_CS_SIZE},
65 1.3 uch [TX39_CS3] = {"CS3" , TX39_SYSADDR_CS3 ,
66 1.3 uch TX39_SYSADDR_CS_SIZE},
67 1.3 uch [TX39_MCS0] = {"MCS0" , TX39_SYSADDR_MCS0 ,
68 1.3 uch TX39_SYSADDR_MCS_SIZE},
69 1.3 uch [TX39_MCS1] = {"MCS1" , TX39_SYSADDR_MCS1 ,
70 1.3 uch TX39_SYSADDR_MCS_SIZE},
71 1.3 uch #ifdef TX391X
72 1.3 uch [TX39_MCS2] = {"MCS2" , TX39_SYSADDR_MCS2 ,
73 1.3 uch TX39_SYSADDR_MCS_SIZE},
74 1.3 uch [TX39_MCS3] = {"MCS3" , TX39_SYSADDR_MCS3 ,
75 1.3 uch TX39_SYSADDR_MCS_SIZE},
76 1.3 uch #endif /* TX391X */
77 1.3 uch [TX39_CARD1] = {"CARD1(io/attr)", TX39_SYSADDR_CARD1 ,
78 1.3 uch TX39_SYSADDR_CARD_SIZE},
79 1.3 uch [TX39_CARD2] = {"CARD2(io/attr)", TX39_SYSADDR_CARD2 ,
80 1.3 uch TX39_SYSADDR_CARD_SIZE},
81 1.3 uch [TX39_CARD1MEM] = {"CARD1(mem)" , TX39_SYSADDR_CARD1MEM ,
82 1.3 uch TX39_SYSADDR_CARD_SIZE},
83 1.3 uch [TX39_CARD2MEM] = {"CARD2(mem)" , TX39_SYSADDR_CARD2MEM ,
84 1.3 uch TX39_SYSADDR_CARD_SIZE},
85 1.18 nakayama [TX39_KUCS0] = {"KUCS0" , TX39_SYSADDR_KUSEG_CS0,
86 1.18 nakayama TX39_SYSADDR_KUCS_SIZE},
87 1.18 nakayama [TX39_KUCS1] = {"KUCS1" , TX39_SYSADDR_KUSEG_CS1,
88 1.18 nakayama TX39_SYSADDR_KUCS_SIZE},
89 1.18 nakayama [TX39_KUCS2] = {"KUCS2" , TX39_SYSADDR_KUSEG_CS2,
90 1.18 nakayama TX39_SYSADDR_KUCS_SIZE},
91 1.18 nakayama [TX39_KUCS3] = {"KUCS3" , TX39_SYSADDR_KUSEG_CS3,
92 1.18 nakayama TX39_SYSADDR_KUCS_SIZE},
93 1.3 uch };
94 1.3 uch
95 1.22 chs int txcsbus_match(device_t, cfdata_t, void *);
96 1.22 chs void txcsbus_attach(device_t, device_t, void *);
97 1.5 uch int txcsbus_print(void *, const char *);
98 1.22 chs int txcsbus_search(device_t, cfdata_t, const int *, void *);
99 1.1 uch
100 1.1 uch struct txcsbus_softc {
101 1.1 uch tx_chipset_tag_t sc_tc;
102 1.1 uch /* chip select space tag */
103 1.7 uch struct bus_space_tag_hpcmips *sc_cst[TX39_MAXCS];
104 1.18 nakayama int sc_pri;
105 1.1 uch };
106 1.1 uch
107 1.22 chs CFATTACH_DECL_NEW(txcsbus, sizeof(struct txcsbus_softc),
108 1.13 thorpej txcsbus_match, txcsbus_attach, NULL, NULL);
109 1.1 uch
110 1.5 uch static bus_space_tag_t __txcsbus_alloc_cstag(struct txcsbus_softc *,
111 1.5 uch struct cs_handle *);
112 1.1 uch
113 1.1 uch int
114 1.22 chs txcsbus_match(device_t parent, cfdata_t cf, void *aux)
115 1.1 uch {
116 1.1 uch struct csbus_attach_args *cba = aux;
117 1.1 uch platid_mask_t mask;
118 1.1 uch
119 1.9 thorpej if (strcmp(cba->cba_busname, cf->cf_name))
120 1.5 uch return (0);
121 1.1 uch
122 1.5 uch if (cf->cf_loc[TXCSBUSIFCF_PLATFORM] == TXCSBUSIFCF_PLATFORM_DEFAULT)
123 1.5 uch return (1);
124 1.1 uch
125 1.1 uch mask = PLATID_DEREF(cf->cf_loc[TXCSBUSIFCF_PLATFORM]);
126 1.5 uch if (platid_match(&platid, &mask))
127 1.5 uch return (2);
128 1.1 uch
129 1.5 uch return (0);
130 1.1 uch }
131 1.1 uch
132 1.1 uch void
133 1.22 chs txcsbus_attach(device_t parent, device_t self, void *aux)
134 1.1 uch {
135 1.1 uch struct csbus_attach_args *cba = aux;
136 1.22 chs struct txcsbus_softc *sc = device_private(self);
137 1.1 uch
138 1.1 uch sc->sc_tc = cba->cba_tc;
139 1.1 uch printf("\n");
140 1.1 uch
141 1.1 uch /*
142 1.1 uch * Attach external chip.
143 1.1 uch */
144 1.18 nakayama /* higher priority devices attach first */
145 1.18 nakayama sc->sc_pri = 2;
146 1.22.52.2 thorpej config_search(self, NULL,
147 1.22.52.1 thorpej CFARG_SUBMATCH, txcsbus_search,
148 1.22.52.1 thorpej CFARG_IATTR, "txcsbus",
149 1.22.52.1 thorpej CFARG_EOL);
150 1.22.52.1 thorpej
151 1.18 nakayama /* then, normal priority devices */
152 1.18 nakayama sc->sc_pri = 1;
153 1.22.52.2 thorpej config_search(self, NULL,
154 1.22.52.1 thorpej CFARG_SUBMATCH, txcsbus_search,
155 1.22.52.1 thorpej CFARG_IATTR, "txcsbus",
156 1.22.52.1 thorpej CFARG_EOL);
157 1.1 uch }
158 1.1 uch
159 1.1 uch int
160 1.5 uch txcsbus_print(void *aux, const char *pnp)
161 1.1 uch {
162 1.3 uch #define PRINTIRQ(i) i, (i) / 32, (i) % 32
163 1.3 uch struct cs_attach_args *ca = aux;
164 1.3 uch
165 1.3 uch if (ca->ca_csreg.cs != TXCSBUSCF_REGCS_DEFAULT) {
166 1.14 thorpej aprint_normal(" regcs %s %dbit %#x+%#x",
167 1.5 uch __csmap[ca->ca_csreg.cs].cs_name,
168 1.5 uch ca->ca_csreg.cswidth,
169 1.5 uch ca->ca_csreg.csbase,
170 1.5 uch ca->ca_csreg.cssize);
171 1.3 uch }
172 1.3 uch
173 1.3 uch if (ca->ca_csio.cs != TXCSBUSCF_IOCS_DEFAULT) {
174 1.14 thorpej aprint_normal(" iocs %s %dbit %#x+%#x",
175 1.5 uch __csmap[ca->ca_csio.cs].cs_name,
176 1.5 uch ca->ca_csio.cswidth,
177 1.5 uch ca->ca_csio.csbase,
178 1.5 uch ca->ca_csio.cssize);
179 1.3 uch }
180 1.3 uch
181 1.3 uch if (ca->ca_csmem.cs != TXCSBUSCF_MEMCS_DEFAULT) {
182 1.14 thorpej aprint_normal(" memcs %s %dbit %#x+%#x",
183 1.5 uch __csmap[ca->ca_csmem.cs].cs_name,
184 1.5 uch ca->ca_csmem.cswidth,
185 1.5 uch ca->ca_csmem.csbase,
186 1.5 uch ca->ca_csmem.cssize);
187 1.3 uch }
188 1.3 uch
189 1.3 uch if (ca->ca_irq1 != TXCSBUSCF_IRQ1_DEFAULT) {
190 1.14 thorpej aprint_normal(" irq1 %d(%d:%d)", PRINTIRQ(ca->ca_irq1));
191 1.3 uch }
192 1.3 uch
193 1.3 uch if (ca->ca_irq2 != TXCSBUSCF_IRQ2_DEFAULT) {
194 1.14 thorpej aprint_normal(" irq2 %d(%d:%d)", PRINTIRQ(ca->ca_irq2));
195 1.3 uch }
196 1.3 uch
197 1.3 uch if (ca->ca_irq3 != TXCSBUSCF_IRQ3_DEFAULT) {
198 1.14 thorpej aprint_normal(" irq3 %d(%d:%d)", PRINTIRQ(ca->ca_irq3));
199 1.3 uch }
200 1.3 uch
201 1.5 uch return (UNCONF);
202 1.1 uch }
203 1.1 uch
204 1.1 uch int
205 1.22 chs txcsbus_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
206 1.1 uch {
207 1.22 chs struct txcsbus_softc *sc = device_private(parent);
208 1.1 uch struct cs_attach_args ca;
209 1.1 uch
210 1.1 uch ca.ca_tc = sc->sc_tc;
211 1.1 uch
212 1.1 uch ca.ca_csreg.cs = cf->cf_loc[TXCSBUSCF_REGCS];
213 1.1 uch ca.ca_csreg.csbase = cf->cf_loc[TXCSBUSCF_REGCSBASE];
214 1.1 uch ca.ca_csreg.cssize = cf->cf_loc[TXCSBUSCF_REGCSSIZE];
215 1.1 uch ca.ca_csreg.cswidth = cf->cf_loc[TXCSBUSCF_REGCSWIDTH];
216 1.2 uch
217 1.1 uch if (ca.ca_csreg.cs != TXCSBUSCF_REGCS_DEFAULT) {
218 1.2 uch ca.ca_csreg.cstag = __txcsbus_alloc_cstag(sc, &ca.ca_csreg);
219 1.1 uch }
220 1.1 uch
221 1.1 uch ca.ca_csio.cs = cf->cf_loc[TXCSBUSCF_IOCS];
222 1.1 uch ca.ca_csio.csbase = cf->cf_loc[TXCSBUSCF_IOCSBASE];
223 1.1 uch ca.ca_csio.cssize = cf->cf_loc[TXCSBUSCF_IOCSSIZE];
224 1.1 uch ca.ca_csio.cswidth = cf->cf_loc[TXCSBUSCF_IOCSWIDTH];
225 1.2 uch
226 1.1 uch if (ca.ca_csio.cs != TXCSBUSCF_IOCS_DEFAULT) {
227 1.2 uch ca.ca_csio.cstag = __txcsbus_alloc_cstag(sc, &ca.ca_csio);
228 1.1 uch }
229 1.2 uch
230 1.1 uch ca.ca_csmem.cs = cf->cf_loc[TXCSBUSCF_MEMCS];
231 1.1 uch ca.ca_csmem.csbase = cf->cf_loc[TXCSBUSCF_MEMCSBASE];
232 1.1 uch ca.ca_csmem.cssize = cf->cf_loc[TXCSBUSCF_MEMCSSIZE];
233 1.1 uch ca.ca_csmem.cswidth = cf->cf_loc[TXCSBUSCF_MEMCSWIDTH];
234 1.2 uch
235 1.1 uch if (ca.ca_csmem.cs != TXCSBUSCF_MEMCS_DEFAULT) {
236 1.2 uch ca.ca_csmem.cstag = __txcsbus_alloc_cstag(sc, &ca.ca_csmem);
237 1.1 uch }
238 1.1 uch
239 1.1 uch ca.ca_irq1 = cf->cf_loc[TXCSBUSCF_IRQ1];
240 1.1 uch ca.ca_irq2 = cf->cf_loc[TXCSBUSCF_IRQ2];
241 1.1 uch ca.ca_irq3 = cf->cf_loc[TXCSBUSCF_IRQ3];
242 1.1 uch
243 1.18 nakayama if (config_match(parent, cf, &ca) == sc->sc_pri) {
244 1.1 uch config_attach(parent, cf, &ca, txcsbus_print);
245 1.1 uch }
246 1.1 uch
247 1.5 uch return (0);
248 1.1 uch }
249 1.1 uch
250 1.1 uch bus_space_tag_t
251 1.5 uch __txcsbus_alloc_cstag(struct txcsbus_softc *sc, struct cs_handle *csh)
252 1.1 uch {
253 1.1 uch
254 1.1 uch tx_chipset_tag_t tc = sc->sc_tc;
255 1.1 uch int cs = csh->cs;
256 1.1 uch int width = csh->cswidth;
257 1.7 uch struct bus_space_tag_hpcmips *iot;
258 1.1 uch txreg_t reg;
259 1.1 uch
260 1.18 nakayama if (!TX39_ISCS(cs) && !TX39_ISMCS(cs) && !TX39_ISCARD(cs) &&
261 1.18 nakayama !TX39_ISKUCS(cs)) {
262 1.11 provos panic("txcsbus_alloc_tag: bogus chip select %d", cs);
263 1.1 uch }
264 1.1 uch
265 1.1 uch /* Already setuped chip select */
266 1.1 uch if (sc->sc_cst[cs]) {
267 1.7 uch return (&sc->sc_cst[cs]->bst);
268 1.1 uch }
269 1.1 uch
270 1.1 uch iot = hpcmips_alloc_bus_space_tag();
271 1.7 uch hpcmips_init_bus_space(iot, hpcmips_system_bus_space_hpcmips(),
272 1.7 uch __csmap[cs].cs_name, __csmap[cs].cs_addr, __csmap[cs].cs_size);
273 1.1 uch sc->sc_cst[cs] = iot;
274 1.1 uch
275 1.1 uch /* CS bus-width (configurationable) */
276 1.1 uch switch (width) {
277 1.1 uch default:
278 1.11 provos panic("txcsbus_alloc_tag: bogus bus width %d", width);
279 1.2 uch
280 1.1 uch case 32:
281 1.1 uch if (TX39_ISCS(cs)) {
282 1.1 uch reg = tx_conf_read(tc, TX39_MEMCONFIG0_REG);
283 1.1 uch reg |= (1 << cs);
284 1.1 uch tx_conf_write(tc, TX39_MEMCONFIG0_REG, reg);
285 1.2 uch } else if(TX39_ISMCS(cs)) {
286 1.1 uch #ifdef TX391X
287 1.1 uch panic("txcsbus_alloc_tag: MCS is 16bit only");
288 1.2 uch #endif /* TX391X */
289 1.2 uch #ifdef TX392X
290 1.1 uch reg = tx_conf_read(tc, TX39_MEMCONFIG1_REG);
291 1.2 uch reg |= ((cs == TX39_MCS0) ?
292 1.5 uch TX39_MEMCONFIG1_MCS0_32 :
293 1.5 uch TX39_MEMCONFIG1_MCS1_32);
294 1.1 uch tx_conf_write(tc, TX39_MEMCONFIG1_REG, reg);
295 1.2 uch #endif /* TX392X */
296 1.1 uch }
297 1.1 uch break;
298 1.2 uch
299 1.1 uch case 16:
300 1.1 uch if (TX39_ISCS(cs)) {
301 1.1 uch reg = tx_conf_read(tc, TX39_MEMCONFIG0_REG);
302 1.1 uch reg &= ~(1 << cs);
303 1.1 uch tx_conf_write(tc, TX39_MEMCONFIG0_REG, reg);
304 1.2 uch } else if(TX39_ISMCS(cs)) {
305 1.2 uch /* TX391X always 16bit port */
306 1.1 uch #ifdef TX392X
307 1.1 uch reg = tx_conf_read(tc, TX39_MEMCONFIG1_REG);
308 1.2 uch reg &= ~((cs == TX39_MCS0) ?
309 1.5 uch TX39_MEMCONFIG1_MCS0_32 :
310 1.5 uch TX39_MEMCONFIG1_MCS1_32);
311 1.1 uch tx_conf_write(tc, TX39_MEMCONFIG1_REG, reg);
312 1.2 uch #endif /* TX392X */
313 1.18 nakayama } else if (TX39_ISCARD(cs)) {
314 1.2 uch /* CARD io/attr or mem */
315 1.2 uch reg = tx_conf_read(tc, TX39_MEMCONFIG3_REG);
316 1.2 uch
317 1.2 uch /* enable I/O access */
318 1.2 uch reg |= (cs == TX39_CARD1) ?
319 1.5 uch TX39_MEMCONFIG3_CARD1IOEN :
320 1.5 uch TX39_MEMCONFIG3_CARD2IOEN;
321 1.2 uch /* disable 8bit access */
322 1.2 uch #ifdef TX392X
323 1.2 uch reg &= ~((cs == TX39_CARD1) ?
324 1.5 uch TX39_MEMCONFIG3_CARD1_8SEL :
325 1.5 uch TX39_MEMCONFIG3_CARD2_8SEL);
326 1.2 uch #endif /* TX392X */
327 1.2 uch #ifdef TX391X
328 1.2 uch reg &= ~TX39_MEMCONFIG3_PORT8SEL;
329 1.2 uch #endif /* TX391X */
330 1.2 uch tx_conf_write(tc, TX39_MEMCONFIG3_REG, reg);
331 1.1 uch }
332 1.1 uch break;
333 1.2 uch
334 1.2 uch case 8:
335 1.2 uch if (TX39_ISCARD(cs)) {
336 1.2 uch reg = tx_conf_read(tc, TX39_MEMCONFIG3_REG);
337 1.2 uch
338 1.2 uch /* enable I/O access */
339 1.2 uch reg |= (cs == TX39_CARD1) ?
340 1.5 uch TX39_MEMCONFIG3_CARD1IOEN :
341 1.5 uch TX39_MEMCONFIG3_CARD2IOEN;
342 1.2 uch /* disable 8bit access */
343 1.2 uch #ifdef TX392X
344 1.2 uch reg |= (cs == TX39_CARD1) ?
345 1.5 uch TX39_MEMCONFIG3_CARD1_8SEL :
346 1.5 uch TX39_MEMCONFIG3_CARD2_8SEL;
347 1.2 uch #endif /* TX392X */
348 1.2 uch #ifdef TX391X
349 1.2 uch reg |= TX39_MEMCONFIG3_PORT8SEL;
350 1.2 uch #endif /* TX391X */
351 1.2 uch tx_conf_write(tc, TX39_MEMCONFIG3_REG, reg);
352 1.2 uch
353 1.2 uch } else {
354 1.2 uch panic("__txcsbus_alloc_cstag: CS%d 8bit mode is"
355 1.5 uch "not allowed", cs);
356 1.2 uch }
357 1.1 uch }
358 1.1 uch
359 1.7 uch return (&iot->bst);
360 1.1 uch }
361