atppc_pnpbios.c revision 1.5
1/* $NetBSD: atppc_pnpbios.c,v 1.5 2008/04/04 22:18:05 cegger 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.5 2008/04/04 22:18:05 cegger 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
63static int	atppc_pnpbios_match(struct device *, struct cfdata *, void *);
64static void	atppc_pnpbios_attach(struct device *, struct device *, void *);
65
66struct atppc_pnpbios_softc {
67	struct atppc_softc sc_atppc;
68
69	isa_chipset_tag_t sc_ic;
70	int sc_drq;
71};
72
73CFATTACH_DECL(atppc_pnpbios, sizeof(struct atppc_pnpbios_softc),
74    atppc_pnpbios_match, atppc_pnpbios_attach, NULL, NULL);
75
76static int atppc_pnpbios_dma_start(struct atppc_softc *, void *, u_int,
77	uint8_t);
78static int atppc_pnpbios_dma_finish(struct atppc_softc *);
79static int atppc_pnpbios_dma_abort(struct atppc_softc *);
80static int atppc_pnpbios_dma_malloc(struct device *, void **, bus_addr_t *,
81	bus_size_t);
82static void atppc_pnpbios_dma_free(struct device *, void **, bus_addr_t *,
83	bus_size_t);
84
85/*
86 * atppc_pnpbios_match: autoconf(9) match routine
87 */
88static int
89atppc_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
100static void
101atppc_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		aprint_error_dev(&sc->sc_dev, "can't map i/o space\n");
113		return;
114	}
115
116	/* find our DRQ */
117	if (pnpbios_getdmachan(aa->pbt, aa->resc, 0, &asc->sc_drq)) {
118		aprint_error_dev(&sc->sc_de, "unable to get DMA channel\n");
119		return;
120	}
121
122	pnpbios_print_devres(self, aa);
123
124	/* Attach */
125	sc->sc_has = 0;
126	asc->sc_ic = aa->ic;
127	sc->sc_dev_ok = ATPPC_ATTACHED;
128
129	sc->sc_ieh = pnpbios_intr_establish(aa->pbt, aa->resc, 0, IPL_TTY,
130					    atppcintr, sc);
131	sc->sc_has |= ATPPC_HAS_INTR;
132
133	/* setup DMA hooks */
134	if (atppc_isadma_setup(sc, asc->sc_ic, asc->sc_drq) == 0) {
135		sc->sc_has |= ATPPC_HAS_DMA;
136		sc->sc_dma_start = atppc_pnpbios_dma_start;
137		sc->sc_dma_finish = atppc_pnpbios_dma_finish;
138		sc->sc_dma_abort = atppc_pnpbios_dma_abort;
139		sc->sc_dma_malloc = atppc_pnpbios_dma_malloc;
140		sc->sc_dma_free = atppc_pnpbios_dma_free;
141	}
142
143	/* Run soft configuration attach */
144	atppc_sc_attach(sc);
145}
146
147/* Start DMA operation over ISA bus */
148static int
149atppc_pnpbios_dma_start(struct atppc_softc *lsc, void *buf, u_int nbytes,
150	uint8_t mode)
151{
152	struct atppc_pnpbios_softc * sc = (struct atppc_pnpbios_softc *) lsc;
153
154	return atppc_isadma_start(sc->sc_ic, sc->sc_drq, buf, nbytes, mode);
155}
156
157/* Stop DMA operation over ISA bus */
158static int
159atppc_pnpbios_dma_finish(struct atppc_softc * lsc)
160{
161	struct atppc_pnpbios_softc * sc = (struct atppc_pnpbios_softc *) lsc;
162
163	return atppc_isadma_finish(sc->sc_ic, sc->sc_drq);
164}
165
166/* Abort DMA operation over ISA bus */
167int
168atppc_pnpbios_dma_abort(struct atppc_softc * lsc)
169{
170	struct atppc_pnpbios_softc * sc = (struct atppc_pnpbios_softc *) lsc;
171
172	return atppc_isadma_abort(sc->sc_ic, sc->sc_drq);
173}
174
175/* Allocate memory for DMA over ISA bus */
176int
177atppc_pnpbios_dma_malloc(struct device * dev, void ** buf, bus_addr_t * bus_addr,
178	bus_size_t size)
179{
180	struct atppc_pnpbios_softc * sc = (struct atppc_pnpbios_softc *) dev;
181
182	return atppc_isadma_malloc(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
183}
184
185/* Free memory allocated by atppc_isa_dma_malloc() */
186void
187atppc_pnpbios_dma_free(struct device * dev, void ** buf, bus_addr_t * bus_addr,
188	bus_size_t size)
189{
190	struct atppc_pnpbios_softc * sc = (struct atppc_pnpbios_softc *) dev;
191
192	return atppc_isadma_free(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
193}
194