1/* $NetBSD: atppc_pnpbios.c,v 1.8 2008/04/28 20:23:25 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_pnpbios.c,v 1.8 2008/04/28 20:23:25 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 <i386/pnpbios/pnpbiosvar.h> 52 53#include <dev/ic/atppcvar.h> 54#include <dev/isa/atppc_isadma.h> 55 56static int atppc_pnpbios_match(device_t, cfdata_t, void *); 57static void atppc_pnpbios_attach(device_t, device_t, void *); 58 59struct atppc_pnpbios_softc { 60 struct atppc_softc sc_atppc; 61 62 isa_chipset_tag_t sc_ic; 63 int sc_drq; 64}; 65 66CFATTACH_DECL_NEW(atppc_pnpbios, sizeof(struct atppc_pnpbios_softc), 67 atppc_pnpbios_match, atppc_pnpbios_attach, NULL, NULL); 68 69static int atppc_pnpbios_dma_start(struct atppc_softc *, void *, u_int, 70 uint8_t); 71static int atppc_pnpbios_dma_finish(struct atppc_softc *); 72static int atppc_pnpbios_dma_abort(struct atppc_softc *); 73static int atppc_pnpbios_dma_malloc(device_t, void **, bus_addr_t *, 74 bus_size_t); 75static void atppc_pnpbios_dma_free(device_t, void **, bus_addr_t *, 76 bus_size_t); 77 78/* 79 * atppc_pnpbios_match: autoconf(9) match routine 80 */ 81static int 82atppc_pnpbios_match(device_t parent, cfdata_t match, void *aux) 83{ 84 struct pnpbiosdev_attach_args *aa = aux; 85 86 if (strcmp(aa->idstr, "PNP0400") == 0 87 || strcmp(aa->idstr, "PNP0401") == 0) 88 return (1); 89 90 return (0); 91} 92 93static void 94atppc_pnpbios_attach(device_t parent, device_t self, void *aux) 95{ 96 struct atppc_softc *sc = device_private(self); 97 struct atppc_pnpbios_softc *asc = device_private(self); 98 struct pnpbiosdev_attach_args *aa = aux; 99 100 sc->sc_dev_ok = ATPPC_NOATTACH; 101 102 printf(": AT Parallel Port\n"); 103 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"); 106 return; 107 } 108 109 /* find our DRQ */ 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"); 112 return; 113 } 114 115 pnpbios_print_devres(self, aa); 116 117 /* Attach */ 118 sc->sc_dev = self; 119 sc->sc_has = 0; 120 asc->sc_ic = aa->ic; 121 sc->sc_dev_ok = ATPPC_ATTACHED; 122 123 sc->sc_ieh = pnpbios_intr_establish(aa->pbt, aa->resc, 0, IPL_TTY, 124 atppcintr, sc); 125 sc->sc_has |= ATPPC_HAS_INTR; 126 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; 135 } 136 137 /* Run soft configuration attach */ 138 atppc_sc_attach(sc); 139} 140 141/* Start DMA operation over ISA bus */ 142static int 143atppc_pnpbios_dma_start(struct atppc_softc *lsc, void *buf, u_int nbytes, 144 uint8_t mode) 145{ 146 struct atppc_pnpbios_softc * sc = (struct atppc_pnpbios_softc *) lsc; 147 148 return atppc_isadma_start(sc->sc_ic, sc->sc_drq, buf, nbytes, mode); 149} 150 151/* Stop DMA operation over ISA bus */ 152static int 153atppc_pnpbios_dma_finish(struct atppc_softc * lsc) 154{ 155 struct atppc_pnpbios_softc * sc = (struct atppc_pnpbios_softc *) lsc; 156 157 return atppc_isadma_finish(sc->sc_ic, sc->sc_drq); 158} 159 160/* Abort DMA operation over ISA bus */ 161int 162atppc_pnpbios_dma_abort(struct atppc_softc * lsc) 163{ 164 struct atppc_pnpbios_softc * sc = (struct atppc_pnpbios_softc *) lsc; 165 166 return atppc_isadma_abort(sc->sc_ic, sc->sc_drq); 167} 168 169/* Allocate memory for DMA over ISA bus */ 170int 171atppc_pnpbios_dma_malloc(device_t dev, void ** buf, bus_addr_t * bus_addr, 172 bus_size_t size) 173{ 174 struct atppc_pnpbios_softc * sc = device_private(dev); 175 176 return atppc_isadma_malloc(sc->sc_ic, sc->sc_drq, buf, bus_addr, size); 177} 178 179/* Free memory allocated by atppc_isa_dma_malloc() */ 180void 181atppc_pnpbios_dma_free(device_t dev, void ** buf, bus_addr_t * bus_addr, 182 bus_size_t size) 183{ 184 struct atppc_pnpbios_softc * sc = device_private(dev); 185 186 return atppc_isadma_free(sc->sc_ic, sc->sc_drq, buf, bus_addr, size); 187} 188