xref: /netbsd-src/sys/arch/alpha/sableio/fdc_sableio.c (revision b7b2b8a3d89bfee25ca9324638c59a92666e2e4e)
1*b7b2b8a3Sthorpej /* $NetBSD: fdc_sableio.c,v 1.17 2021/05/07 16:58:34 thorpej Exp $ */
2f363b73fSthorpej 
3f363b73fSthorpej /*-
4f363b73fSthorpej  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
5f363b73fSthorpej  * All rights reserved.
6f363b73fSthorpej  *
7f363b73fSthorpej  * This code is derived from software contributed to The NetBSD Foundation
8f363b73fSthorpej  * by Jason R. Thorpe.
9f363b73fSthorpej  *
10f363b73fSthorpej  * Redistribution and use in source and binary forms, with or without
11f363b73fSthorpej  * modification, are permitted provided that the following conditions
12f363b73fSthorpej  * are met:
13f363b73fSthorpej  * 1. Redistributions of source code must retain the above copyright
14f363b73fSthorpej  *    notice, this list of conditions and the following disclaimer.
15f363b73fSthorpej  * 2. Redistributions in binary form must reproduce the above copyright
16f363b73fSthorpej  *    notice, this list of conditions and the following disclaimer in the
17f363b73fSthorpej  *    documentation and/or other materials provided with the distribution.
18f363b73fSthorpej  *
19f363b73fSthorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20f363b73fSthorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21f363b73fSthorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22f363b73fSthorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23f363b73fSthorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24f363b73fSthorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25f363b73fSthorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26f363b73fSthorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27f363b73fSthorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28f363b73fSthorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29f363b73fSthorpej  * POSSIBILITY OF SUCH DAMAGE.
30f363b73fSthorpej  */
31f363b73fSthorpej 
32f363b73fSthorpej #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
33f363b73fSthorpej 
34*b7b2b8a3Sthorpej __KERNEL_RCSID(0, "$NetBSD: fdc_sableio.c,v 1.17 2021/05/07 16:58:34 thorpej Exp $");
35f363b73fSthorpej 
36f363b73fSthorpej #include <sys/param.h>
37f363b73fSthorpej #include <sys/systm.h>
38f363b73fSthorpej #include <sys/callout.h>
39f363b73fSthorpej #include <sys/device.h>
40f363b73fSthorpej #include <sys/buf.h>
41f363b73fSthorpej 
42cf10107dSdyoung #include <sys/bus.h>
43f363b73fSthorpej #include <machine/intr.h>
44f363b73fSthorpej 
45f363b73fSthorpej #include <dev/isa/isavar.h>
46f363b73fSthorpej #include <dev/isa/isadmavar.h>
47f363b73fSthorpej 
48f363b73fSthorpej #include <dev/isa/fdreg.h>
49f363b73fSthorpej #include <dev/isa/fdcvar.h>
50f363b73fSthorpej 
51f363b73fSthorpej #include <dev/pci/pcivar.h>
52f363b73fSthorpej 
53f363b73fSthorpej #include <alpha/sableio/sableiovar.h>
54f363b73fSthorpej 
55*b7b2b8a3Sthorpej static int	fdc_sableio_match(device_t, cfdata_t, void *);
56*b7b2b8a3Sthorpej static void	fdc_sableio_attach(device_t, device_t, void *);
57f363b73fSthorpej 
58f363b73fSthorpej struct fdc_sableio_softc {
59f363b73fSthorpej 	struct	fdc_softc sc_fdc;	/* real "fdc" softc */
60f363b73fSthorpej 
61f363b73fSthorpej 	bus_space_handle_t sc_baseioh;	/* base I/O handle */
62f363b73fSthorpej };
63f363b73fSthorpej 
64bb192d4cScube CFATTACH_DECL_NEW(fdc_sableio, sizeof(struct fdc_sableio_softc),
65b96bc0d7Sthorpej     fdc_sableio_match, fdc_sableio_attach, NULL, NULL);
66f363b73fSthorpej 
67*b7b2b8a3Sthorpej static int
fdc_sableio_match(device_t parent,cfdata_t match,void * aux)68bb192d4cScube fdc_sableio_match(device_t parent, cfdata_t match, void *aux)
69f363b73fSthorpej {
70f363b73fSthorpej 	struct sableio_attach_args *sa = aux;
71f363b73fSthorpej 
72f363b73fSthorpej 	/* Always present. */
73d1ad2ac4Sthorpej 	if (strcmp(sa->sa_name, match->cf_name) == 0)
74f363b73fSthorpej 		return (1);
75f363b73fSthorpej 
76f363b73fSthorpej 	return (0);
77f363b73fSthorpej }
78f363b73fSthorpej 
79*b7b2b8a3Sthorpej static void
fdc_sableio_attach(device_t parent,device_t self,void * aux)80bb192d4cScube fdc_sableio_attach(device_t parent, device_t self, void *aux)
81f363b73fSthorpej {
82bb192d4cScube 	struct fdc_sableio_softc *sfdc = device_private(self);
83bb192d4cScube 	struct fdc_softc *fdc = &sfdc->sc_fdc;
84f363b73fSthorpej 	struct sableio_attach_args *sa = aux;
85f363b73fSthorpej 	const char *intrstr;
86e58a356cSchristos 	char buf[PCI_INTRSTR_LEN];
871099504eSthorpej 	pci_intr_handle_t ih;
88f363b73fSthorpej 
89bb192d4cScube 	aprint_normal("\n");
90f363b73fSthorpej 
91bb192d4cScube 	fdc->sc_dev = self;
92f363b73fSthorpej 	fdc->sc_iot = sa->sa_iot;
93f363b73fSthorpej 	fdc->sc_ic = sa->sa_ic;
94f363b73fSthorpej 	fdc->sc_drq = sa->sa_drq;
95f363b73fSthorpej 
96f363b73fSthorpej 	if (bus_space_map(fdc->sc_iot, sa->sa_ioaddr, 6 /* FDC_NPORT */, 0,
97f363b73fSthorpej 	    &sfdc->sc_baseioh)) {
98bb192d4cScube 		aprint_error_dev(self, "unable to map I/O space\n");
99f363b73fSthorpej 		return;
100f363b73fSthorpej 	}
101f363b73fSthorpej 
102f363b73fSthorpej 	if (bus_space_subregion(fdc->sc_iot, sfdc->sc_baseioh, 2, 4,
103f363b73fSthorpej 	    &fdc->sc_ioh)) {
104bb192d4cScube 		aprint_error_dev(self, "unable to subregion I/O space\n");
105f363b73fSthorpej 		return;
106f363b73fSthorpej 	}
107f363b73fSthorpej 
108f363b73fSthorpej 	if (bus_space_map(fdc->sc_iot, sa->sa_ioaddr + fdctl + 2, 1, 0,
109f363b73fSthorpej 	    &fdc->sc_fdctlioh)) {
110bb192d4cScube 		aprint_error_dev(self, "unable to map CTL I/O space\n");
111f363b73fSthorpej 		return;
112f363b73fSthorpej 	}
113f363b73fSthorpej 
1141099504eSthorpej 	alpha_pci_intr_handle_init(&ih, sa->sa_sableirq[0], 0);
1151099504eSthorpej 
1161099504eSthorpej 	intrstr = pci_intr_string(sa->sa_pc, ih, buf, sizeof(buf));
1171099504eSthorpej 	fdc->sc_ih = pci_intr_establish(sa->sa_pc, ih, IPL_BIO,
1181099504eSthorpej 	    fdcintr, fdc);
119f363b73fSthorpej 	if (fdc->sc_ih == NULL) {
120bb192d4cScube 		aprint_error_dev(self, "unable to establish interrupt");
121f363b73fSthorpej 		if (intrstr != NULL)
12274341862Snjoly 			aprint_error(" at %s", intrstr);
12374341862Snjoly 		aprint_error("\n");
124f363b73fSthorpej 		return;
125f363b73fSthorpej 	}
126bb192d4cScube 	aprint_normal_dev(self, "interrupting at %s\n", intrstr);
127f363b73fSthorpej 
128864b9626Smycroft 	fdcattach(fdc);
129f363b73fSthorpej }
130