xref: /netbsd-src/sys/arch/i386/pnpbios/atppc_pnpbios.c (revision 4b896b232495b7a9b8b94a1cf1e21873296d53b8)
1 /* $NetBSD: atppc_pnpbios.c,v 1.1 2004/01/28 09:09:14 jdolecek Exp $ */
2 
3 /*-
4  * Copyright (c) 2004 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jaromir Dolecek.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: atppc_pnpbios.c,v 1.1 2004/01/28 09:09:14 jdolecek Exp $");
41 
42 #include "opt_atppc.h"
43 
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/errno.h>
47 #include <sys/ioctl.h>
48 #include <sys/syslog.h>
49 #include <sys/device.h>
50 #include <sys/proc.h>
51 #include <sys/termios.h>
52 
53 #include <machine/bus.h>
54 
55 #include <dev/isa/isavar.h>
56 #include <dev/isa/isadmavar.h>
57 
58 #include <i386/pnpbios/pnpbiosvar.h>
59 
60 #include <dev/ic/atppcvar.h>
61 #include <dev/isa/atppc_isadma.h>
62 
63 static int	atppc_pnpbios_match(struct device *, struct cfdata *, void *);
64 static void	atppc_pnpbios_attach(struct device *, struct device *, void *);
65 
66 struct atppc_pnpbios_softc {
67 	struct atppc_softc sc_atppc;
68 
69 	isa_chipset_tag_t sc_ic;
70 	int sc_drq;
71 };
72 
73 CFATTACH_DECL(atppc_pnpbios, sizeof(struct atppc_pnpbios_softc),
74     atppc_pnpbios_match, atppc_pnpbios_attach, NULL, NULL);
75 
76 static int atppc_pnpbios_dma_start(struct atppc_softc *, void *, u_int,
77 	u_int8_t);
78 static int atppc_pnpbios_dma_finish(struct atppc_softc *);
79 static int atppc_pnpbios_dma_abort(struct atppc_softc *);
80 static int atppc_pnpbios_dma_malloc(struct device *, caddr_t *, bus_addr_t *,
81 	bus_size_t);
82 static void atppc_pnpbios_dma_free(struct device *, caddr_t *, bus_addr_t *,
83 	bus_size_t);
84 
85 /*
86  * atppc_pnpbios_match: autoconf(9) match routine
87  */
88 static int
89 atppc_pnpbios_match(struct device *parent, struct cfdata *match, void *aux)
90 {
91 	struct pnpbiosdev_attach_args *aa = aux;
92 
93 	if (strcmp(aa->idstr, "PNP0400") == 0
94 	    || strcmp(aa->idstr, "PNP0401") == 0)
95 		return (1);
96 
97 	return (0);
98 }
99 
100 static void
101 atppc_pnpbios_attach(struct device *parent, struct device *self, void *aux)
102 {
103 	struct atppc_softc *sc = (struct atppc_softc *) self;
104 	struct atppc_pnpbios_softc *asc = (struct atppc_pnpbios_softc *)self;
105 	struct pnpbiosdev_attach_args *aa = aux;
106 
107 	sc->sc_dev_ok = ATPPC_NOATTACH;
108 
109 	printf(": AT Parallel Port\n");
110 
111 	if (pnpbios_io_map(aa->pbt, aa->resc, 0, &sc->sc_iot, &sc->sc_ioh)) {
112 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
113 		return;
114 	}
115 
116 	/* find our DRQ */
117 	if (pnpbios_getdmachan(aa->pbt, aa->resc, 0, &asc->sc_drq)) {
118 		printf("%s: unable to get DMA channel\n",
119 		    sc->sc_dev.dv_xname);
120 		return;
121 	}
122 
123 	pnpbios_print_devres(self, aa);
124 
125 	/* Attach */
126 	sc->sc_has = 0;
127 	asc->sc_ic = aa->ic;
128 	sc->sc_dev_ok = ATPPC_ATTACHED;
129 
130 	sc->sc_ieh = pnpbios_intr_establish(aa->pbt, aa->resc, 0, IPL_TTY,
131 					    atppcintr, sc);
132 	sc->sc_has |= ATPPC_HAS_INTR;
133 
134 	/* setup DMA hooks */
135 	if (atppc_isadma_setup(sc, asc->sc_ic, asc->sc_drq) == 0) {
136 		sc->sc_has |= ATPPC_HAS_DMA;
137 		sc->sc_dma_start = atppc_pnpbios_dma_start;
138 		sc->sc_dma_finish = atppc_pnpbios_dma_finish;
139 		sc->sc_dma_abort = atppc_pnpbios_dma_abort;
140 		sc->sc_dma_malloc = atppc_pnpbios_dma_malloc;
141 		sc->sc_dma_free = atppc_pnpbios_dma_free;
142 	}
143 
144 	/* Run soft configuration attach */
145 	atppc_sc_attach(sc);
146 }
147 
148 /* Start DMA operation over ISA bus */
149 static int
150 atppc_pnpbios_dma_start(struct atppc_softc *lsc, void *buf, u_int nbytes,
151 	u_int8_t mode)
152 {
153 	struct atppc_pnpbios_softc * sc = (struct atppc_pnpbios_softc *) lsc;
154 
155 	return atppc_isadma_start(sc->sc_ic, sc->sc_drq, buf, nbytes, mode);
156 }
157 
158 /* Stop DMA operation over ISA bus */
159 static int
160 atppc_pnpbios_dma_finish(struct atppc_softc * lsc)
161 {
162 	struct atppc_pnpbios_softc * sc = (struct atppc_pnpbios_softc *) lsc;
163 
164 	return atppc_isadma_finish(sc->sc_ic, sc->sc_drq);
165 }
166 
167 /* Abort DMA operation over ISA bus */
168 int
169 atppc_pnpbios_dma_abort(struct atppc_softc * lsc)
170 {
171 	struct atppc_pnpbios_softc * sc = (struct atppc_pnpbios_softc *) lsc;
172 
173 	return atppc_isadma_abort(sc->sc_ic, sc->sc_drq);
174 }
175 
176 /* Allocate memory for DMA over ISA bus */
177 int
178 atppc_pnpbios_dma_malloc(struct device * dev, caddr_t * buf, bus_addr_t * bus_addr,
179 	bus_size_t size)
180 {
181 	struct atppc_pnpbios_softc * sc = (struct atppc_pnpbios_softc *) dev;
182 
183 	return atppc_isadma_malloc(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
184 }
185 
186 /* Free memory allocated by atppc_isa_dma_malloc() */
187 void
188 atppc_pnpbios_dma_free(struct device * dev, caddr_t * buf, bus_addr_t * bus_addr,
189 	bus_size_t size)
190 {
191 	struct atppc_pnpbios_softc * sc = (struct atppc_pnpbios_softc *) dev;
192 
193 	return atppc_isadma_free(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
194 }
195