1*7663c1deSthorpej /* $NetBSD: jensenio.c,v 1.23 2023/12/04 00:32:10 thorpej Exp $ */
2a66c3e66Sthorpej
3a66c3e66Sthorpej /*-
4a66c3e66Sthorpej * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
5a66c3e66Sthorpej * All rights reserved.
6a66c3e66Sthorpej *
7a66c3e66Sthorpej * This code is derived from software contributed to The NetBSD Foundation
8a66c3e66Sthorpej * by Jason R. Thorpe.
9a66c3e66Sthorpej *
10a66c3e66Sthorpej * Redistribution and use in source and binary forms, with or without
11a66c3e66Sthorpej * modification, are permitted provided that the following conditions
12a66c3e66Sthorpej * are met:
13a66c3e66Sthorpej * 1. Redistributions of source code must retain the above copyright
14a66c3e66Sthorpej * notice, this list of conditions and the following disclaimer.
15a66c3e66Sthorpej * 2. Redistributions in binary form must reproduce the above copyright
16a66c3e66Sthorpej * notice, this list of conditions and the following disclaimer in the
17a66c3e66Sthorpej * documentation and/or other materials provided with the distribution.
18a66c3e66Sthorpej *
19a66c3e66Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20a66c3e66Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21a66c3e66Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22a66c3e66Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23a66c3e66Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24a66c3e66Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25a66c3e66Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26a66c3e66Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27a66c3e66Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28a66c3e66Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29a66c3e66Sthorpej * POSSIBILITY OF SUCH DAMAGE.
30a66c3e66Sthorpej */
31a66c3e66Sthorpej
32a66c3e66Sthorpej /*
33a66c3e66Sthorpej * Driver for the Jensen I/O bus.
34a66c3e66Sthorpej *
35a66c3e66Sthorpej * The Jensen I/O `bus' is comprised of two things:
36a66c3e66Sthorpej *
37a66c3e66Sthorpej * - VLSI VL82C106 junk I/O chip
38a66c3e66Sthorpej * - Intel EISA bus interface
39a66c3e66Sthorpej *
40a66c3e66Sthorpej * Access to the 82C106 is different than to the rest of EISA space, even
41a66c3e66Sthorpej * though it is a single address space.
42a66c3e66Sthorpej */
43a66c3e66Sthorpej
44a66c3e66Sthorpej #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
45a66c3e66Sthorpej
46*7663c1deSthorpej __KERNEL_RCSID(0, "$NetBSD: jensenio.c,v 1.23 2023/12/04 00:32:10 thorpej Exp $");
47a66c3e66Sthorpej
48a66c3e66Sthorpej #include <sys/param.h>
49a66c3e66Sthorpej #include <sys/systm.h>
50a66c3e66Sthorpej #include <sys/device.h>
51a66c3e66Sthorpej
52a66c3e66Sthorpej #include <machine/autoconf.h>
53a66c3e66Sthorpej
54a66c3e66Sthorpej #include <dev/eisa/eisavar.h>
55a66c3e66Sthorpej
56a66c3e66Sthorpej #include <dev/isa/isareg.h>
57a66c3e66Sthorpej #include <dev/isa/isavar.h>
58a66c3e66Sthorpej
59a66c3e66Sthorpej #include <alpha/jensenio/jensenioreg.h>
60a66c3e66Sthorpej #include <alpha/jensenio/jenseniovar.h>
61a66c3e66Sthorpej
6261ac7027Sdrochner #include "locators.h"
6361ac7027Sdrochner
64b0226574Sthorpej #include "eisa.h"
65b0226574Sthorpej
66a66c3e66Sthorpej /*
67a66c3e66Sthorpej * The devices built-in to the VLSI VL82C106 junk I/O chip.
68a66c3e66Sthorpej */
699cd21b65Sjoerg static const struct jensenio_dev {
70a66c3e66Sthorpej const char *jd_name; /* device name */
71a66c3e66Sthorpej bus_addr_t jd_ioaddr; /* I/O space address */
72a66c3e66Sthorpej int jd_irq[2]; /* Jensen IRQs */
73a66c3e66Sthorpej } jensenio_devs[] = {
740fb6b9a8Sthorpej { "pckbc", IO_KBD, { 0x980, 0x990 } },
750fb6b9a8Sthorpej { "com", IO_COM1, { 0x900, -1 } },
760fb6b9a8Sthorpej { "com", IO_COM2, { 0x920, -1 } },
77a66c3e66Sthorpej { "lpt", IO_LPT3, { 1, -1 } },
78a66c3e66Sthorpej { "mcclock", 0x170, { -1, -1 } },
79a66c3e66Sthorpej { NULL, 0, { -1, -1 } },
80a66c3e66Sthorpej };
81a66c3e66Sthorpej
829cd21b65Sjoerg static int jensenio_match(device_t, cfdata_t, void *);
839cd21b65Sjoerg static void jensenio_attach(device_t, device_t, void *);
84a66c3e66Sthorpej
859cd21b65Sjoerg CFATTACH_DECL_NEW(jensenio, 0, jensenio_match, jensenio_attach, NULL, NULL);
86a66c3e66Sthorpej
879cd21b65Sjoerg static int jensenio_print(void *, const char *);
88a66c3e66Sthorpej
899cd21b65Sjoerg static int jensenio_attached;
90a66c3e66Sthorpej
91a66c3e66Sthorpej struct jensenio_config jensenio_configuration;
92a66c3e66Sthorpej
939cd21b65Sjoerg static void jensenio_eisa_attach_hook(device_t, device_t,
94a66c3e66Sthorpej struct eisabus_attach_args *);
959cd21b65Sjoerg static int jensenio_eisa_maxslots(void *);
96a66c3e66Sthorpej
979cd21b65Sjoerg static void jensenio_isa_attach_hook(device_t, device_t,
98a66c3e66Sthorpej struct isabus_attach_args *);
99a66c3e66Sthorpej
10072047fbcSdyoung static void jensenio_isa_detach_hook(isa_chipset_tag_t, device_t);
101e178a961Sdyoung
102a66c3e66Sthorpej /*
103a66c3e66Sthorpej * Set up the Jensen's function pointers.
104a66c3e66Sthorpej */
105a66c3e66Sthorpej void
jensenio_init(struct jensenio_config * jcp)106*7663c1deSthorpej jensenio_init(struct jensenio_config *jcp)
107a66c3e66Sthorpej {
108a66c3e66Sthorpej
109a66c3e66Sthorpej /*
110a66c3e66Sthorpej * Initialize the Host Address Extension register to 0
111a66c3e66Sthorpej * (the firmware should have already done this). We will
112a66c3e66Sthorpej * disallow mapping of any device who's address would
113a66c3e66Sthorpej * require a non-0 HAE. This should be safe as the final
114a66c3e66Sthorpej * draft of the Jensen system specification states that
115a66c3e66Sthorpej * applications should follow this little rule.
116a66c3e66Sthorpej *
117a66c3e66Sthorpej * There's a good reason for this; actually using HAE would
118a66c3e66Sthorpej * require a mutex around *every* EISA cycle! Gross!
119a66c3e66Sthorpej */
120a66c3e66Sthorpej REGVAL(JENSEN_HAE) = 0;
121a66c3e66Sthorpej alpha_mb();
122a66c3e66Sthorpej
123a66c3e66Sthorpej if (jcp->jc_initted == 0) {
124a66c3e66Sthorpej /* don't do these twice since they set up extents */
125a66c3e66Sthorpej jensenio_bus_io_init(&jcp->jc_eisa_iot, jcp);
126a66c3e66Sthorpej jensenio_bus_intio_init(&jcp->jc_internal_iot, jcp);
127a66c3e66Sthorpej jensenio_bus_mem_init(&jcp->jc_eisa_memt, jcp);
128a66c3e66Sthorpej }
129a66c3e66Sthorpej }
130a66c3e66Sthorpej
1319cd21b65Sjoerg static int
jensenio_match(device_t parent,cfdata_t cf,void * aux)1329cd21b65Sjoerg jensenio_match(device_t parent, cfdata_t cf, void *aux)
133a66c3e66Sthorpej {
134a66c3e66Sthorpej struct mainbus_attach_args *ma = aux;
135a66c3e66Sthorpej
136d1ad2ac4Sthorpej if (strcmp(ma->ma_name, cf->cf_name) != 0)
137a66c3e66Sthorpej return (0);
138a66c3e66Sthorpej
139a66c3e66Sthorpej /* There can be only one. */
140a66c3e66Sthorpej if (jensenio_attached)
141a66c3e66Sthorpej return (0);
142a66c3e66Sthorpej
143a66c3e66Sthorpej return (1);
144a66c3e66Sthorpej }
145a66c3e66Sthorpej
1469cd21b65Sjoerg static void
jensenio_attach(device_t parent,device_t self,void * aux)1479cd21b65Sjoerg jensenio_attach(device_t parent, device_t self, void *aux)
148a66c3e66Sthorpej {
149a66c3e66Sthorpej struct jensenio_attach_args ja;
150a66c3e66Sthorpej struct jensenio_config *jcp = &jensenio_configuration;
151a66c3e66Sthorpej int i;
152fa3cb84dSdrochner int locs[JENSENIOCF_NLOCS];
153a66c3e66Sthorpej
154a66c3e66Sthorpej printf("\n");
155a66c3e66Sthorpej
156a66c3e66Sthorpej jensenio_attached = 1;
157a66c3e66Sthorpej
158a66c3e66Sthorpej /*
159a66c3e66Sthorpej * Done once at console init time, but we might need to do
160a66c3e66Sthorpej * additional work this time.
161a66c3e66Sthorpej */
162*7663c1deSthorpej jensenio_init(jcp);
163a66c3e66Sthorpej
164a66c3e66Sthorpej /*
165a66c3e66Sthorpej * Initialize DMA.
166a66c3e66Sthorpej */
167a66c3e66Sthorpej jensenio_dma_init(jcp);
168a66c3e66Sthorpej
169a66c3e66Sthorpej /*
170a66c3e66Sthorpej * Initialize interrupts.
171a66c3e66Sthorpej */
172a66c3e66Sthorpej jensenio_intr_init(jcp);
173a66c3e66Sthorpej
174a66c3e66Sthorpej /*
175a66c3e66Sthorpej * First attach all of the built-in devices.
176a66c3e66Sthorpej */
177a66c3e66Sthorpej for (i = 0; jensenio_devs[i].jd_name != NULL; i++) {
178a66c3e66Sthorpej ja.ja_name = jensenio_devs[i].jd_name;
179a66c3e66Sthorpej ja.ja_ioaddr = jensenio_devs[i].jd_ioaddr;
180a66c3e66Sthorpej ja.ja_irq[0] = jensenio_devs[i].jd_irq[0];
181a66c3e66Sthorpej ja.ja_irq[1] = jensenio_devs[i].jd_irq[1];
182a66c3e66Sthorpej
183a66c3e66Sthorpej ja.ja_iot = &jcp->jc_internal_iot;
184a66c3e66Sthorpej ja.ja_ec = &jcp->jc_ec;
185a66c3e66Sthorpej
186fa3cb84dSdrochner locs[JENSENIOCF_PORT] = jensenio_devs[i].jd_ioaddr;
1872685996bSthorpej config_found(self, &ja, jensenio_print,
188c7fb772bSthorpej CFARGS(.submatch = config_stdsubmatch,
189c7fb772bSthorpej .iattr = "jensenio",
190c7fb772bSthorpej .locators = locs));
191a66c3e66Sthorpej }
192a66c3e66Sthorpej
193a66c3e66Sthorpej /*
194a66c3e66Sthorpej * Attach the EISA bus.
195a66c3e66Sthorpej */
196a66c3e66Sthorpej jcp->jc_ec.ec_attach_hook = jensenio_eisa_attach_hook;
197a66c3e66Sthorpej jcp->jc_ec.ec_maxslots = jensenio_eisa_maxslots;
198a66c3e66Sthorpej
199a66c3e66Sthorpej ja.ja_eisa.eba_iot = &jcp->jc_eisa_iot;
200a66c3e66Sthorpej ja.ja_eisa.eba_memt = &jcp->jc_eisa_memt;
201a66c3e66Sthorpej ja.ja_eisa.eba_dmat = &jcp->jc_dmat_eisa;
202a66c3e66Sthorpej ja.ja_eisa.eba_ec = &jcp->jc_ec;
2032685996bSthorpej config_found(self, &ja.ja_eisa, eisabusprint,
204c7fb772bSthorpej CFARGS(.iattr = "eisabus"));
205a66c3e66Sthorpej
206a66c3e66Sthorpej /*
207a66c3e66Sthorpej * Attach the ISA bus.
208a66c3e66Sthorpej */
209a66c3e66Sthorpej jcp->jc_ic.ic_attach_hook = jensenio_isa_attach_hook;
210e178a961Sdyoung jcp->jc_ic.ic_detach_hook = jensenio_isa_detach_hook;
211a66c3e66Sthorpej
212a66c3e66Sthorpej ja.ja_isa.iba_iot = &jcp->jc_eisa_iot;
213a66c3e66Sthorpej ja.ja_isa.iba_memt = &jcp->jc_eisa_memt;
214a66c3e66Sthorpej ja.ja_isa.iba_dmat = &jcp->jc_dmat_isa;
215a66c3e66Sthorpej ja.ja_isa.iba_ic = &jcp->jc_ic;
2162685996bSthorpej config_found(self, &ja.ja_isa, isabusprint,
217c7fb772bSthorpej CFARGS(.iattr = "eisabus"));
218a66c3e66Sthorpej }
219a66c3e66Sthorpej
2209cd21b65Sjoerg static int
jensenio_print(void * aux,const char * pnp)221a66c3e66Sthorpej jensenio_print(void *aux, const char *pnp)
222a66c3e66Sthorpej {
223a66c3e66Sthorpej struct jensenio_attach_args *ja = aux;
224a66c3e66Sthorpej
225a66c3e66Sthorpej if (pnp != NULL)
2267ca7bdb3Sthorpej aprint_normal("%s at %s", ja->ja_name, pnp);
227a66c3e66Sthorpej
2287ca7bdb3Sthorpej aprint_normal(" port 0x%lx", ja->ja_ioaddr);
229a66c3e66Sthorpej
230a66c3e66Sthorpej return (UNCONF);
231a66c3e66Sthorpej }
232a66c3e66Sthorpej
2339cd21b65Sjoerg static void
jensenio_eisa_attach_hook(device_t parent,device_t self,struct eisabus_attach_args * eba)2349cd21b65Sjoerg jensenio_eisa_attach_hook(device_t parent, device_t self,
235a66c3e66Sthorpej struct eisabus_attach_args *eba)
236a66c3e66Sthorpej {
237a66c3e66Sthorpej
238b0226574Sthorpej #if NEISA > 0
239b0226574Sthorpej /*
240b0226574Sthorpej * Jensen's EISA config info is sparse, and is mapped at a
241b0226574Sthorpej * different location that on other EISA systems.
242b0226574Sthorpej */
243b0226574Sthorpej eisa_config_stride = 0x200;
244b0226574Sthorpej eisa_config_addr = JENSEN_FEPROM1;
245d99606f7Stsutsui eisa_init(eba->eba_ec);
246b0226574Sthorpej #endif
247a66c3e66Sthorpej }
248a66c3e66Sthorpej
2499cd21b65Sjoerg static int
jensenio_eisa_maxslots(void * v)250a66c3e66Sthorpej jensenio_eisa_maxslots(void *v)
251a66c3e66Sthorpej {
252a66c3e66Sthorpej
253d99606f7Stsutsui return (8); /* jensen seems to have only 8 valid slots */
254a66c3e66Sthorpej }
255a66c3e66Sthorpej
2569cd21b65Sjoerg static void
jensenio_isa_attach_hook(device_t parent,device_t self,struct isabus_attach_args * iba)2579cd21b65Sjoerg jensenio_isa_attach_hook(device_t parent, device_t self,
258a66c3e66Sthorpej struct isabus_attach_args *iba)
259a66c3e66Sthorpej {
260a66c3e66Sthorpej
261a66c3e66Sthorpej /* Nothing to do. */
262a66c3e66Sthorpej }
263e178a961Sdyoung
264e178a961Sdyoung static void
jensenio_isa_detach_hook(isa_chipset_tag_t ic,device_t self)26572047fbcSdyoung jensenio_isa_detach_hook(isa_chipset_tag_t ic, device_t self)
266e178a961Sdyoung {
267e178a961Sdyoung
268e178a961Sdyoung /* Nothing to do. */
269e178a961Sdyoung }
270