1*c7fb772bSthorpej /* $NetBSD: isa_machdep.c,v 1.43 2021/08/07 16:18:46 thorpej Exp $ */
23adf93ecSleo
33adf93ecSleo /*
43adf93ecSleo * Copyright (c) 1997 Leo Weppelman. All rights reserved.
53adf93ecSleo * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
66d3d8a13Smycroft * Copyright (c) 1994 Charles M. Hannum. All rights reserved.
73adf93ecSleo *
83adf93ecSleo * Redistribution and use in source and binary forms, with or without
93adf93ecSleo * modification, are permitted provided that the following conditions
103adf93ecSleo * are met:
113adf93ecSleo * 1. Redistributions of source code must retain the above copyright
123adf93ecSleo * notice, this list of conditions and the following disclaimer.
133adf93ecSleo * 2. Redistributions in binary form must reproduce the above copyright
143adf93ecSleo * notice, this list of conditions and the following disclaimer in the
153adf93ecSleo * documentation and/or other materials provided with the distribution.
163adf93ecSleo * 3. All advertising materials mentioning features or use of this software
173adf93ecSleo * must display the following acknowledgement:
186d3d8a13Smycroft * This product includes software developed by Charles M. Hannum.
193adf93ecSleo * 4. The name of the author may not be used to endorse or promote products
203adf93ecSleo * derived from this software without specific prior written permission.
213adf93ecSleo *
223adf93ecSleo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
233adf93ecSleo * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
243adf93ecSleo * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
253adf93ecSleo * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
263adf93ecSleo * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
273adf93ecSleo * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
283adf93ecSleo * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
293adf93ecSleo * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
303adf93ecSleo * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
313adf93ecSleo * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
323adf93ecSleo */
333adf93ecSleo
34e803bea7Slukem #include <sys/cdefs.h>
35*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.43 2021/08/07 16:18:46 thorpej Exp $");
36e803bea7Slukem
373adf93ecSleo #include <sys/types.h>
383adf93ecSleo #include <sys/param.h>
393adf93ecSleo #include <sys/systm.h>
403adf93ecSleo #include <sys/device.h>
413adf93ecSleo
42b44e732fSleo #define _ATARI_BUS_DMA_PRIVATE
43ed9977b1Sdyoung #include <sys/bus.h>
443adf93ecSleo #include <dev/isa/isavar.h>
453adf93ecSleo #include <dev/isa/isareg.h>
463adf93ecSleo
47b38e8527Sleo #include "pckbc.h"
48b38e8527Sleo #if (NPCKBC > 0)
49b38e8527Sleo #include <dev/ic/pckbcvar.h>
50b38e8527Sleo #include <dev/ic/i8042reg.h>
51b38e8527Sleo #endif /* NPCKBC > 0 */
52b38e8527Sleo
533adf93ecSleo #include <machine/iomap.h>
543adf93ecSleo #include <machine/mfp.h>
553adf93ecSleo #include <atari/atari/device.h>
563adf93ecSleo
57b44e732fSleo #include "isadma.h"
58b44e732fSleo
59b44e732fSleo #if NISADMA == 0
60b44e732fSleo
61b44e732fSleo /*
62b44e732fSleo * Entry points for ISA DMA while no DMA capable devices are attached.
63b44e732fSleo * This must be a serious error. Cause a panic...
64b44e732fSleo */
65b44e732fSleo struct atari_bus_dma_tag isa_bus_dma_tag = {
66b44e732fSleo 0
67b44e732fSleo };
68b44e732fSleo #endif /* NISADMA == 0 */
69b44e732fSleo
70c1b2bf5aStsutsui static int atariisabusprint(void *, const char *);
71c1b2bf5aStsutsui static int isabusmatch(device_t, cfdata_t, void *);
72c1b2bf5aStsutsui static void isabusattach(device_t, device_t, void *);
733adf93ecSleo
74a3dbb61fSthorpej struct isabus_softc {
75c1b2bf5aStsutsui device_t sc_dev;
76a3dbb61fSthorpej struct atari_isa_chipset sc_chipset;
77a3dbb61fSthorpej };
78a3dbb61fSthorpej
79c1b2bf5aStsutsui CFATTACH_DECL_NEW(isab, sizeof(struct isabus_softc),
80c5e91d44Sthorpej isabusmatch, isabusattach, NULL, NULL);
813adf93ecSleo
82b38e8527Sleo /*
83b38e8527Sleo * We need some static storage to attach a console keyboard on the Milan
84b38e8527Sleo * during early console init.
85b38e8527Sleo */
86b38e8527Sleo static struct atari_bus_space bs_storage[2]; /* 1 iot, 1 memt */
87b38e8527Sleo
883adf93ecSleo int
isabusmatch(device_t parent,cfdata_t cf,void * aux)89c1b2bf5aStsutsui isabusmatch(device_t parent, cfdata_t cf, void *aux)
903adf93ecSleo {
91b9a7cb08Sleo static int nmatched = 0;
92b9a7cb08Sleo
93c1b2bf5aStsutsui if (strcmp((char *)aux, "isab"))
94eb9963a8Stsutsui return 0; /* Wrong number... */
95b9a7cb08Sleo
963adf93ecSleo if (atari_realconfig == 0)
97eb9963a8Stsutsui return 1;
98b9a7cb08Sleo
99b9a7cb08Sleo if (machineid & (ATARI_HADES|ATARI_MILAN)) {
100b9a7cb08Sleo /*
101b9a7cb08Sleo * The Hades and Milan have only one pci bus
102b9a7cb08Sleo */
103b9a7cb08Sleo if (nmatched)
104eb9963a8Stsutsui return 0;
105b9a7cb08Sleo nmatched++;
106eb9963a8Stsutsui return 1;
107b9a7cb08Sleo }
108eb9963a8Stsutsui return 0;
1093adf93ecSleo }
1103adf93ecSleo
1113adf93ecSleo void
isabusattach(device_t parent,device_t self,void * aux)112c1b2bf5aStsutsui isabusattach(device_t parent, device_t self, void *aux)
1133adf93ecSleo {
114ecd4d63aStsutsui struct isabus_softc *sc;
1153adf93ecSleo struct isabus_attach_args iba;
116b44e732fSleo extern struct atari_bus_dma_tag isa_bus_dma_tag;
117164b0454Sleo extern void isa_bus_init(void);
1183adf93ecSleo
119b44e732fSleo iba.iba_dmat = &isa_bus_dma_tag;
120b38e8527Sleo iba.iba_iot = leb_alloc_bus_space_tag(&bs_storage[0]);
121b38e8527Sleo iba.iba_memt = leb_alloc_bus_space_tag(&bs_storage[1]);
122bc9ebf17Sleo if ((iba.iba_iot == NULL) || (iba.iba_memt == NULL)) {
123bc9ebf17Sleo printf("leb_alloc_bus_space_tag failed!\n");
124bc9ebf17Sleo return;
125bc9ebf17Sleo }
126bc9ebf17Sleo iba.iba_iot->base = ISA_IOSTART;
127bc9ebf17Sleo iba.iba_memt->base = ISA_MEMSTART;
1283adf93ecSleo
129164b0454Sleo if (machineid & ATARI_HADES)
1303adf93ecSleo MFP->mf_aer |= (IO_ISA1|IO_ISA2); /* ISA interrupts: LOW->HIGH */
131164b0454Sleo isa_bus_init();
132c1b2bf5aStsutsui if (self == NULL) { /* Early init */
133b38e8527Sleo #if (NPCKBC > 0)
1344be6ce2eSjdc pckbc_cnattach(iba.iba_iot, IO_KBD, KBCMDP, PCKBC_KBD_SLOT, 0);
135b38e8527Sleo #endif
136b38e8527Sleo return;
137b38e8527Sleo }
1383adf93ecSleo
139ecd4d63aStsutsui sc = device_private(self);
140ecd4d63aStsutsui sc->sc_dev = self;
141ecd4d63aStsutsui iba.iba_ic = &sc->sc_chipset;
142ecd4d63aStsutsui
1433adf93ecSleo printf("\n");
144*c7fb772bSthorpej config_found(self, &iba, atariisabusprint, CFARGS_NONE);
1453adf93ecSleo }
1463adf93ecSleo
1473adf93ecSleo int
atariisabusprint(void * aux,const char * name)148c1b2bf5aStsutsui atariisabusprint(void *aux, const char *name)
1493adf93ecSleo {
150eb9963a8Stsutsui
1513adf93ecSleo if (name == NULL)
152eb9963a8Stsutsui return UNCONF;
153eb9963a8Stsutsui return QUIET;
1543adf93ecSleo }
1553adf93ecSleo
1563adf93ecSleo void
isa_attach_hook(device_t parent,device_t self,struct isabus_attach_args * iba)157c1b2bf5aStsutsui isa_attach_hook(device_t parent, device_t self, struct isabus_attach_args *iba)
1583adf93ecSleo {
1593adf93ecSleo }
1603adf93ecSleo
16147b66b70Sdyoung void
isa_detach_hook(isa_chipset_tag_t ic,device_t self)1625401d283Smrg isa_detach_hook(isa_chipset_tag_t ic, device_t self)
16347b66b70Sdyoung {
16447b66b70Sdyoung }
16547b66b70Sdyoung
166cffb5808Scgd const struct evcnt *
isa_intr_evcnt(isa_chipset_tag_t ic,int irq)167cffb5808Scgd isa_intr_evcnt(isa_chipset_tag_t ic, int irq)
168cffb5808Scgd {
169cffb5808Scgd
170cffb5808Scgd /* XXX for now, no evcnt parent reported */
171cffb5808Scgd return NULL;
172cffb5808Scgd }
173