1 /* $NetBSD: atppc_isapnp.c,v 1.4 2005/12/11 12:22:16 christos 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_isapnp.c,v 1.4 2005/12/11 12:22:16 christos 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 <dev/isapnp/isapnpreg.h> 59 #include <dev/isapnp/isapnpvar.h> 60 #include <dev/isapnp/isapnpdevs.h> 61 62 #include <dev/ic/atppcvar.h> 63 #include <dev/isa/atppc_isadma.h> 64 65 static int atppc_isapnp_match(struct device *, struct cfdata *, void *); 66 static void atppc_isapnp_attach(struct device *, struct device *, void *); 67 68 struct atppc_isapnp_softc { 69 struct atppc_softc sc_atppc; 70 71 isa_chipset_tag_t sc_ic; 72 int sc_drq; 73 }; 74 75 CFATTACH_DECL(atppc_isapnp, sizeof(struct atppc_isapnp_softc), 76 atppc_isapnp_match, atppc_isapnp_attach, NULL, NULL); 77 78 static int atppc_isapnp_dma_start(struct atppc_softc *, void *, u_int, 79 u_int8_t); 80 static int atppc_isapnp_dma_finish(struct atppc_softc *); 81 static int atppc_isapnp_dma_abort(struct atppc_softc *); 82 static int atppc_isapnp_dma_malloc(struct device *, caddr_t *, bus_addr_t *, 83 bus_size_t); 84 static void atppc_isapnp_dma_free(struct device *, caddr_t *, bus_addr_t *, 85 bus_size_t); 86 /* 87 * atppc_isapnp_match: autoconf(9) match routine 88 */ 89 static int 90 atppc_isapnp_match(struct device *parent, struct cfdata *match, void *aux) 91 { 92 int pri, variant; 93 94 pri = isapnp_devmatch(aux, &isapnp_atppc_devinfo, &variant); 95 if (pri && variant > 0) 96 pri = 0; 97 return (pri); 98 } 99 100 static void 101 atppc_isapnp_attach(struct device *parent, struct device *self, void *aux) 102 { 103 struct atppc_softc *sc = (struct atppc_softc *) self; 104 struct atppc_isapnp_softc *asc = (struct atppc_isapnp_softc *)self; 105 struct isapnp_attach_args *ipa = aux; 106 107 sc->sc_dev_ok = ATPPC_NOATTACH; 108 109 printf(": AT Parallel Port\n"); 110 111 if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) { 112 printf("%s: error in region allocation\n", 113 sc->sc_dev.dv_xname); 114 return; 115 } 116 117 /* Attach */ 118 sc->sc_iot = ipa->ipa_iot; 119 sc->sc_ioh = ipa->ipa_io[0].h; 120 sc->sc_has = 0; 121 asc->sc_ic = ipa->ipa_ic; 122 asc->sc_drq = -1; /* Initialized below */ 123 124 sc->sc_dev_ok = ATPPC_ATTACHED; 125 126 sc->sc_ieh = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num, 127 ipa->ipa_irq[0].type, IPL_TTY, atppcintr, sc); 128 sc->sc_has |= ATPPC_HAS_INTR; 129 130 /* setup DMA hooks */ 131 if (ipa->ipa_ndrq > 0 132 && atppc_isadma_setup(sc, asc->sc_ic, ipa->ipa_drq[0].num) == 0) { 133 asc->sc_drq = ipa->ipa_drq[0].num; 134 sc->sc_has |= ATPPC_HAS_DMA; 135 sc->sc_dma_start = atppc_isapnp_dma_start; 136 sc->sc_dma_finish = atppc_isapnp_dma_finish; 137 sc->sc_dma_abort = atppc_isapnp_dma_abort; 138 sc->sc_dma_malloc = atppc_isapnp_dma_malloc; 139 sc->sc_dma_free = atppc_isapnp_dma_free; 140 } 141 142 /* Run soft configuration attach */ 143 atppc_sc_attach(sc); 144 } 145 146 /* Start DMA operation over ISA bus */ 147 static int 148 atppc_isapnp_dma_start(struct atppc_softc *lsc, void *buf, u_int nbytes, 149 u_int8_t mode) 150 { 151 struct atppc_isapnp_softc * sc = (struct atppc_isapnp_softc *) lsc; 152 153 return atppc_isadma_start(sc->sc_ic, sc->sc_drq, buf, nbytes, mode); 154 } 155 156 /* Stop DMA operation over ISA bus */ 157 static int 158 atppc_isapnp_dma_finish(struct atppc_softc * lsc) 159 { 160 struct atppc_isapnp_softc * sc = (struct atppc_isapnp_softc *) lsc; 161 162 return atppc_isadma_finish(sc->sc_ic, sc->sc_drq); 163 } 164 165 /* Abort DMA operation over ISA bus */ 166 int 167 atppc_isapnp_dma_abort(struct atppc_softc * lsc) 168 { 169 struct atppc_isapnp_softc * sc = (struct atppc_isapnp_softc *) lsc; 170 171 return atppc_isadma_abort(sc->sc_ic, sc->sc_drq); 172 } 173 174 /* Allocate memory for DMA over ISA bus */ 175 int 176 atppc_isapnp_dma_malloc(struct device * dev, caddr_t * buf, bus_addr_t * bus_addr, 177 bus_size_t size) 178 { 179 struct atppc_isapnp_softc * sc = (struct atppc_isapnp_softc *) dev; 180 181 return atppc_isadma_malloc(sc->sc_ic, sc->sc_drq, buf, bus_addr, size); 182 } 183 184 /* Free memory allocated by atppc_isa_dma_malloc() */ 185 void 186 atppc_isapnp_dma_free(struct device * dev, caddr_t * buf, bus_addr_t * bus_addr, 187 bus_size_t size) 188 { 189 struct atppc_isapnp_softc * sc = (struct atppc_isapnp_softc *) dev; 190 191 return atppc_isadma_free(sc->sc_ic, sc->sc_drq, buf, bus_addr, size); 192 } 193