Home | History | Annotate | Line # | Download | only in isapnp
      1 /* $NetBSD: atppc_isapnp.c,v 1.11 2008/04/28 20:23:52 martin 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  *
     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.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: atppc_isapnp.c,v 1.11 2008/04/28 20:23:52 martin Exp $");
     34 
     35 #include "opt_atppc.h"
     36 
     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>
     43 #include <sys/proc.h>
     44 #include <sys/termios.h>
     45 
     46 #include <sys/bus.h>
     47 
     48 #include <dev/isa/isavar.h>
     49 #include <dev/isa/isadmavar.h>
     50 
     51 #include <dev/isapnp/isapnpreg.h>
     52 #include <dev/isapnp/isapnpvar.h>
     53 #include <dev/isapnp/isapnpdevs.h>
     54 
     55 #include <dev/ic/atppcvar.h>
     56 #include <dev/isa/atppc_isadma.h>
     57 
     58 static int	atppc_isapnp_match(device_t, cfdata_t, void *);
     59 static void	atppc_isapnp_attach(device_t, device_t, void *);
     60 
     61 struct atppc_isapnp_softc {
     62 	struct atppc_softc sc_atppc;
     63 
     64 	isa_chipset_tag_t sc_ic;
     65 	int sc_drq;
     66 };
     67 
     68 CFATTACH_DECL_NEW(atppc_isapnp, sizeof(struct atppc_isapnp_softc),
     69     atppc_isapnp_match, atppc_isapnp_attach, NULL, NULL);
     70 
     71 static int atppc_isapnp_dma_start(struct atppc_softc *, void *, u_int,
     72 	u_int8_t);
     73 static int atppc_isapnp_dma_finish(struct atppc_softc *);
     74 static int atppc_isapnp_dma_abort(struct atppc_softc *);
     75 static int atppc_isapnp_dma_malloc(device_t, void **, bus_addr_t *,
     76 	bus_size_t);
     77 static void atppc_isapnp_dma_free(device_t, void **, bus_addr_t *,
     78 	bus_size_t);
     79 /*
     80  * atppc_isapnp_match: autoconf(9) match routine
     81  */
     82 static int
     83 atppc_isapnp_match(device_t parent, cfdata_t match, void *aux)
     84 {
     85 	int pri, variant;
     86 
     87 	pri = isapnp_devmatch(aux, &isapnp_atppc_devinfo, &variant);
     88 	if (pri && variant > 0)
     89 		pri = 0;
     90 	return (pri);
     91 }
     92 
     93 static void
     94 atppc_isapnp_attach(device_t parent, device_t self, void *aux)
     95 {
     96 	struct atppc_softc *sc = device_private(self);
     97 	struct atppc_isapnp_softc *asc = device_private(self);
     98 	struct isapnp_attach_args *ipa = aux;
     99 
    100 	sc->sc_dev_ok = ATPPC_NOATTACH;
    101 
    102 	printf(": AT Parallel Port\n");
    103 
    104 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    105 		aprint_error_dev(sc->sc_dev, "error in region allocation\n");
    106 		return;
    107 	}
    108 
    109 	/* Attach */
    110 	sc->sc_dev = self;
    111 	sc->sc_iot = ipa->ipa_iot;
    112 	sc->sc_ioh = ipa->ipa_io[0].h;
    113 	sc->sc_has = 0;
    114 	asc->sc_ic = ipa->ipa_ic;
    115 	asc->sc_drq = -1;	/* Initialized below */
    116 
    117 	sc->sc_dev_ok = ATPPC_ATTACHED;
    118 
    119 	sc->sc_ieh = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    120 	    ipa->ipa_irq[0].type, IPL_TTY, atppcintr, sc);
    121 	sc->sc_has |= ATPPC_HAS_INTR;
    122 
    123 	/* setup DMA hooks */
    124 	if (ipa->ipa_ndrq > 0
    125 	    && atppc_isadma_setup(sc, asc->sc_ic, ipa->ipa_drq[0].num) == 0) {
    126 		asc->sc_drq = ipa->ipa_drq[0].num;
    127 		sc->sc_has |= ATPPC_HAS_DMA;
    128 		sc->sc_dma_start = atppc_isapnp_dma_start;
    129 		sc->sc_dma_finish = atppc_isapnp_dma_finish;
    130 		sc->sc_dma_abort = atppc_isapnp_dma_abort;
    131 		sc->sc_dma_malloc = atppc_isapnp_dma_malloc;
    132 		sc->sc_dma_free = atppc_isapnp_dma_free;
    133 	}
    134 
    135 	/* Run soft configuration attach */
    136 	atppc_sc_attach(sc);
    137 }
    138 
    139 /* Start DMA operation over ISA bus */
    140 static int
    141 atppc_isapnp_dma_start(struct atppc_softc *lsc, void *buf, u_int nbytes,
    142 	u_int8_t mode)
    143 {
    144 	struct atppc_isapnp_softc * sc = (struct atppc_isapnp_softc *) lsc;
    145 
    146 	return atppc_isadma_start(sc->sc_ic, sc->sc_drq, buf, nbytes, mode);
    147 }
    148 
    149 /* Stop DMA operation over ISA bus */
    150 static int
    151 atppc_isapnp_dma_finish(struct atppc_softc * lsc)
    152 {
    153 	struct atppc_isapnp_softc * sc = (struct atppc_isapnp_softc *) lsc;
    154 
    155 	return atppc_isadma_finish(sc->sc_ic, sc->sc_drq);
    156 }
    157 
    158 /* Abort DMA operation over ISA bus */
    159 int
    160 atppc_isapnp_dma_abort(struct atppc_softc * lsc)
    161 {
    162 	struct atppc_isapnp_softc * sc = (struct atppc_isapnp_softc *) lsc;
    163 
    164 	return atppc_isadma_abort(sc->sc_ic, sc->sc_drq);
    165 }
    166 
    167 /* Allocate memory for DMA over ISA bus */
    168 int
    169 atppc_isapnp_dma_malloc(device_t dev, void ** buf, bus_addr_t * bus_addr,
    170 	bus_size_t size)
    171 {
    172 	struct atppc_isapnp_softc * sc = device_private(dev);
    173 
    174 	return atppc_isadma_malloc(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
    175 }
    176 
    177 /* Free memory allocated by atppc_isa_dma_malloc() */
    178 void
    179 atppc_isapnp_dma_free(device_t dev, void ** buf, bus_addr_t * bus_addr,
    180 	bus_size_t size)
    181 {
    182 	struct atppc_isapnp_softc * sc = device_private(dev);
    183 
    184 	return atppc_isadma_free(sc->sc_ic, sc->sc_drq, buf, bus_addr, size);
    185 }
    186