1 /* $NetBSD: atppc_pnpbios.c,v 1.7 2008/04/16 09:39:01 cegger Exp $ */
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: atppc_pnpbios.c,v 1.7 2008/04/16 09:39:01 cegger Exp $");
35 #include "opt_atppc.h"
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/errno.h>
40 #include <sys/ioctl.h>
41 #include <sys/syslog.h>
42 #include <sys/device.h>
44 #include <sys/termios.h>
46 #include <machine/bus.h>
48 #include <dev/isa/isavar.h>
49 #include <dev/isa/isadmavar.h>
51 #include <i386/pnpbios/pnpbiosvar.h>
53 #include <dev/ic/atppcvar.h>
54 #include <dev/isa/atppc_isadma.h>
56 static int atppc_pnpbios_match(device_t
, cfdata_t
, void *);
57 static void atppc_pnpbios_attach(device_t
, device_t
, void *);
59 struct atppc_pnpbios_softc
{
60 struct atppc_softc sc_atppc
;
62 isa_chipset_tag_t sc_ic
;
66 CFATTACH_DECL_NEW(atppc_pnpbios
, sizeof(struct atppc_pnpbios_softc
),
67 atppc_pnpbios_match
, atppc_pnpbios_attach
, NULL
, NULL
);
69 static int atppc_pnpbios_dma_start(struct atppc_softc
*, void *, u_int
,
71 static int atppc_pnpbios_dma_finish(struct atppc_softc
*);
72 static int atppc_pnpbios_dma_abort(struct atppc_softc
*);
73 static int atppc_pnpbios_dma_malloc(device_t
, void **, bus_addr_t
*,
75 static void atppc_pnpbios_dma_free(device_t
, void **, bus_addr_t
*,
79 * atppc_pnpbios_match: autoconf(9) match routine
82 atppc_pnpbios_match(device_t parent
, cfdata_t match
, void *aux
)
84 struct pnpbiosdev_attach_args
*aa
= aux
;
86 if (strcmp(aa
->idstr
, "PNP0400") == 0
87 || strcmp(aa
->idstr
, "PNP0401") == 0)
94 atppc_pnpbios_attach(device_t parent
, device_t self
, void *aux
)
96 struct atppc_softc
*sc
= device_private(self
);
97 struct atppc_pnpbios_softc
*asc
= device_private(self
);
98 struct pnpbiosdev_attach_args
*aa
= aux
;
100 sc
->sc_dev_ok
= ATPPC_NOATTACH
;
102 printf(": AT Parallel Port\n");
104 if (pnpbios_io_map(aa
->pbt
, aa
->resc
, 0, &sc
->sc_iot
, &sc
->sc_ioh
)) {
105 aprint_error_dev(sc
->sc_dev
, "can't map i/o space\n");
110 if (pnpbios_getdmachan(aa
->pbt
, aa
->resc
, 0, &asc
->sc_drq
)) {
111 aprint_error_dev(sc
->sc_dev
, "unable to get DMA channel\n");
115 pnpbios_print_devres(self
, aa
);
121 sc
->sc_dev_ok
= ATPPC_ATTACHED
;
123 sc
->sc_ieh
= pnpbios_intr_establish(aa
->pbt
, aa
->resc
, 0, IPL_TTY
,
125 sc
->sc_has
|= ATPPC_HAS_INTR
;
127 /* setup DMA hooks */
128 if (atppc_isadma_setup(sc
, asc
->sc_ic
, asc
->sc_drq
) == 0) {
129 sc
->sc_has
|= ATPPC_HAS_DMA
;
130 sc
->sc_dma_start
= atppc_pnpbios_dma_start
;
131 sc
->sc_dma_finish
= atppc_pnpbios_dma_finish
;
132 sc
->sc_dma_abort
= atppc_pnpbios_dma_abort
;
133 sc
->sc_dma_malloc
= atppc_pnpbios_dma_malloc
;
134 sc
->sc_dma_free
= atppc_pnpbios_dma_free
;
137 /* Run soft configuration attach */
141 /* Start DMA operation over ISA bus */
143 atppc_pnpbios_dma_start(struct atppc_softc
*lsc
, void *buf
, u_int nbytes
,
146 struct atppc_pnpbios_softc
* sc
= (struct atppc_pnpbios_softc
*) lsc
;
148 return atppc_isadma_start(sc
->sc_ic
, sc
->sc_drq
, buf
, nbytes
, mode
);
151 /* Stop DMA operation over ISA bus */
153 atppc_pnpbios_dma_finish(struct atppc_softc
* lsc
)
155 struct atppc_pnpbios_softc
* sc
= (struct atppc_pnpbios_softc
*) lsc
;
157 return atppc_isadma_finish(sc
->sc_ic
, sc
->sc_drq
);
160 /* Abort DMA operation over ISA bus */
162 atppc_pnpbios_dma_abort(struct atppc_softc
* lsc
)
164 struct atppc_pnpbios_softc
* sc
= (struct atppc_pnpbios_softc
*) lsc
;
166 return atppc_isadma_abort(sc
->sc_ic
, sc
->sc_drq
);
169 /* Allocate memory for DMA over ISA bus */
171 atppc_pnpbios_dma_malloc(device_t dev
, void ** buf
, bus_addr_t
* bus_addr
,
174 struct atppc_pnpbios_softc
* sc
= device_private(dev
);
176 return atppc_isadma_malloc(sc
->sc_ic
, sc
->sc_drq
, buf
, bus_addr
, size
);
179 /* Free memory allocated by atppc_isa_dma_malloc() */
181 atppc_pnpbios_dma_free(device_t dev
, void ** buf
, bus_addr_t
* bus_addr
,
184 struct atppc_pnpbios_softc
* sc
= device_private(dev
);
186 return atppc_isadma_free(sc
->sc_ic
, sc
->sc_drq
, buf
, bus_addr
, size
);