Home | History | Annotate | Line # | Download | only in isa
com_isa.c revision 1.9
      1 /*	$NetBSD: com_isa.c,v 1.9 1997/10/19 18:56:52 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1993, 1994, 1995, 1996
      5  *	Charles M. Hannum.  All rights reserved.
      6  * Copyright (c) 1991 The Regents of the University of California.
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed by the University of
     20  *	California, Berkeley and its contributors.
     21  * 4. Neither the name of the University nor the names of its contributors
     22  *    may be used to endorse or promote products derived from this software
     23  *    without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  * SUCH DAMAGE.
     36  *
     37  *	@(#)com.c	7.5 (Berkeley) 5/16/91
     38  */
     39 
     40 #include <sys/param.h>
     41 #include <sys/systm.h>
     42 #include <sys/ioctl.h>
     43 #include <sys/select.h>
     44 #include <sys/tty.h>
     45 #include <sys/proc.h>
     46 #include <sys/user.h>
     47 #include <sys/conf.h>
     48 #include <sys/file.h>
     49 #include <sys/uio.h>
     50 #include <sys/kernel.h>
     51 #include <sys/syslog.h>
     52 #include <sys/types.h>
     53 #include <sys/device.h>
     54 
     55 #include <machine/intr.h>
     56 #include <machine/bus.h>
     57 
     58 #include <dev/ic/comreg.h>
     59 #include <dev/ic/comvar.h>
     60 
     61 #include <dev/isa/isavar.h>
     62 
     63 struct com_isa_softc {
     64 	struct	com_softc sc_com;	/* real "com" softc */
     65 
     66 	/* ISA-specific goo. */
     67 	void	*sc_ih;			/* interrupt handler */
     68 };
     69 
     70 #ifdef __BROKEN_INDIRECT_CONFIG
     71 int com_isa_probe __P((struct device *, void *, void *));
     72 #else
     73 int com_isa_probe __P((struct device *, struct cfdata *, void *));
     74 #endif
     75 void com_isa_attach __P((struct device *, struct device *, void *));
     76 void com_isa_cleanup __P((void *));
     77 
     78 struct cfattach com_isa_ca = {
     79 	sizeof(struct com_isa_softc), com_isa_probe, com_isa_attach
     80 };
     81 
     82 int
     83 com_isa_probe(parent, match, aux)
     84 	struct device *parent;
     85 #ifdef __BROKEN_INDIRECT_CONFIG
     86 	void *match;
     87 #else
     88 	struct cfdata *match;
     89 #endif
     90 	void *aux;
     91 {
     92 	bus_space_tag_t iot;
     93 	bus_space_handle_t ioh;
     94 	int iobase;
     95 	int rv = 1;
     96 	struct isa_attach_args *ia = aux;
     97 
     98 	/* Disallow wildcarded i/o address. */
     99 	if (ia->ia_iobase == ISACF_PORT_DEFAULT)
    100 		return (0);
    101 
    102 	iot = ia->ia_iot;
    103 	iobase = ia->ia_iobase;
    104 
    105 	/* if it's in use as console, it's there. */
    106 	if (!com_is_console(iot, iobase, 0)) {
    107 		if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
    108 			return 0;
    109 		}
    110 		rv = comprobe1(iot, ioh, iobase);
    111 		bus_space_unmap(iot, ioh, COM_NPORTS);
    112 	}
    113 
    114 	if (rv) {
    115 		ia->ia_iosize = COM_NPORTS;
    116 		ia->ia_msize = 0;
    117 	}
    118 	return (rv);
    119 }
    120 
    121 void
    122 com_isa_attach(parent, self, aux)
    123 	struct device *parent, *self;
    124 	void *aux;
    125 {
    126 	struct com_isa_softc *isc = (void *)self;
    127 	struct com_softc *sc = &isc->sc_com;
    128 	int iobase, irq;
    129 	bus_space_tag_t iot;
    130 	struct isa_attach_args *ia = aux;
    131 
    132 	/*
    133 	 * We're living on an isa.
    134 	 */
    135 	iobase = sc->sc_iobase = ia->ia_iobase;
    136 	iot = sc->sc_iot = ia->ia_iot;
    137 	if(!com_is_console(iot, iobase, &sc->sc_ioh)
    138 		&& bus_space_map(iot, iobase, COM_NPORTS, 0, &sc->sc_ioh))
    139 			panic("comattach: io mapping failed");
    140 
    141 	sc->sc_frequency = COM_FREQ;
    142 	irq = ia->ia_irq;
    143 
    144 	com_attach_subr(sc);
    145 
    146 	if (irq != IRQUNK) {
    147 		isc->sc_ih = isa_intr_establish(ia->ia_ic, irq,
    148 		    IST_EDGE, IPL_SERIAL, comintr, sc);
    149 	}
    150 
    151 	/*
    152 	 * Shutdown hook for buggy BIOSs that don't recognize the UART
    153 	 * without a disabled FIFO.
    154 	 */
    155 	if (shutdownhook_establish(com_isa_cleanup, sc) == NULL)
    156 		panic("comisa: could not establish shutdown hook");
    157 }
    158 
    159 void
    160 com_isa_cleanup(arg)
    161 	void *arg;
    162 {
    163 	struct com_softc *sc = arg;
    164 
    165 	if (ISSET(sc->sc_hwflags, COM_HW_FIFO))
    166 		bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_fifo, 0);
    167 }
    168