atppc_pnpbios.c revision 1.7
1/* $NetBSD: atppc_pnpbios.c,v 1.7 2008/04/16 09:39:01 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.7 2008/04/16 09:39:01 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(device_t, cfdata_t, void *); 64static void atppc_pnpbios_attach(device_t, device_t, 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_NEW(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(device_t, void **, bus_addr_t *, 81 bus_size_t); 82static void atppc_pnpbios_dma_free(device_t, void **, bus_addr_t *, 83 bus_size_t); 84 85/* 86 * atppc_pnpbios_match: autoconf(9) match routine 87 */ 88static int 89atppc_pnpbios_match(device_t parent, cfdata_t 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(device_t parent, device_t self, void *aux) 102{ 103 struct atppc_softc *sc = device_private(self); 104 struct atppc_pnpbios_softc *asc = device_private(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_dev, "unable to get DMA channel\n"); 119 return; 120 } 121 122 pnpbios_print_devres(self, aa); 123 124 /* Attach */ 125 sc->sc_dev = self; 126 sc->sc_has = 0; 127 asc->sc_ic = aa->ic; 128 sc->sc_dev_ok = ATPPC_ATTACHED; 129 130 sc->sc_ieh = pnpbios_intr_establish(aa->pbt, aa->resc, 0, IPL_TTY, 131 atppcintr, sc); 132 sc->sc_has |= ATPPC_HAS_INTR; 133 134 /* setup DMA hooks */ 135 if (atppc_isadma_setup(sc, asc->sc_ic, asc->sc_drq) == 0) { 136 sc->sc_has |= ATPPC_HAS_DMA; 137 sc->sc_dma_start = atppc_pnpbios_dma_start; 138 sc->sc_dma_finish = atppc_pnpbios_dma_finish; 139 sc->sc_dma_abort = atppc_pnpbios_dma_abort; 140 sc->sc_dma_malloc = atppc_pnpbios_dma_malloc; 141 sc->sc_dma_free = atppc_pnpbios_dma_free; 142 } 143 144 /* Run soft configuration attach */ 145 atppc_sc_attach(sc); 146} 147 148/* Start DMA operation over ISA bus */ 149static int 150atppc_pnpbios_dma_start(struct atppc_softc *lsc, void *buf, u_int nbytes, 151 uint8_t mode) 152{ 153 struct atppc_pnpbios_softc * sc = (struct atppc_pnpbios_softc *) lsc; 154 155 return atppc_isadma_start(sc->sc_ic, sc->sc_drq, buf, nbytes, mode); 156} 157 158/* Stop DMA operation over ISA bus */ 159static int 160atppc_pnpbios_dma_finish(struct atppc_softc * lsc) 161{ 162 struct atppc_pnpbios_softc * sc = (struct atppc_pnpbios_softc *) lsc; 163 164 return atppc_isadma_finish(sc->sc_ic, sc->sc_drq); 165} 166 167/* Abort DMA operation over ISA bus */ 168int 169atppc_pnpbios_dma_abort(struct atppc_softc * lsc) 170{ 171 struct atppc_pnpbios_softc * sc = (struct atppc_pnpbios_softc *) lsc; 172 173 return atppc_isadma_abort(sc->sc_ic, sc->sc_drq); 174} 175 176/* Allocate memory for DMA over ISA bus */ 177int 178atppc_pnpbios_dma_malloc(device_t dev, void ** buf, bus_addr_t * bus_addr, 179 bus_size_t size) 180{ 181 struct atppc_pnpbios_softc * sc = device_private(dev); 182 183 return atppc_isadma_malloc(sc->sc_ic, sc->sc_drq, buf, bus_addr, size); 184} 185 186/* Free memory allocated by atppc_isa_dma_malloc() */ 187void 188atppc_pnpbios_dma_free(device_t dev, void ** buf, bus_addr_t * bus_addr, 189 bus_size_t size) 190{ 191 struct atppc_pnpbios_softc * sc = device_private(dev); 192 193 return atppc_isadma_free(sc->sc_ic, sc->sc_drq, buf, bus_addr, size); 194} 195