Home | History | Annotate | Line # | Download | only in isa
com_isa.c revision 1.17
      1 /*	$NetBSD: com_isa.c,v 1.17 2002/01/07 21:47:04 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Charles M. Hannum.
      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 /*-
     40  * Copyright (c) 1991 The Regents of the University of California.
     41  * All rights reserved.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice, this list of conditions and the following disclaimer.
     48  * 2. Redistributions in binary form must reproduce the above copyright
     49  *    notice, this list of conditions and the following disclaimer in the
     50  *    documentation and/or other materials provided with the distribution.
     51  * 3. All advertising materials mentioning features or use of this software
     52  *    must display the following acknowledgement:
     53  *	This product includes software developed by the University of
     54  *	California, Berkeley and its contributors.
     55  * 4. Neither the name of the University nor the names of its contributors
     56  *    may be used to endorse or promote products derived from this software
     57  *    without specific prior written permission.
     58  *
     59  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  * SUCH DAMAGE.
     70  *
     71  *	@(#)com.c	7.5 (Berkeley) 5/16/91
     72  */
     73 
     74 #include <sys/cdefs.h>
     75 __KERNEL_RCSID(0, "$NetBSD: com_isa.c,v 1.17 2002/01/07 21:47:04 thorpej Exp $");
     76 
     77 #include <sys/param.h>
     78 #include <sys/systm.h>
     79 #include <sys/ioctl.h>
     80 #include <sys/select.h>
     81 #include <sys/tty.h>
     82 #include <sys/proc.h>
     83 #include <sys/user.h>
     84 #include <sys/file.h>
     85 #include <sys/uio.h>
     86 #include <sys/kernel.h>
     87 #include <sys/syslog.h>
     88 #include <sys/device.h>
     89 
     90 #include <machine/intr.h>
     91 #include <machine/bus.h>
     92 
     93 #include <dev/ic/comreg.h>
     94 #include <dev/ic/comvar.h>
     95 
     96 #include <dev/isa/isavar.h>
     97 
     98 struct com_isa_softc {
     99 	struct	com_softc sc_com;	/* real "com" softc */
    100 
    101 	/* ISA-specific goo. */
    102 	void	*sc_ih;			/* interrupt handler */
    103 };
    104 
    105 int com_isa_probe __P((struct device *, struct cfdata *, void *));
    106 void com_isa_attach __P((struct device *, struct device *, void *));
    107 void com_isa_cleanup __P((void *));
    108 
    109 struct cfattach com_isa_ca = {
    110 	sizeof(struct com_isa_softc), com_isa_probe, com_isa_attach
    111 };
    112 
    113 int
    114 com_isa_probe(parent, match, aux)
    115 	struct device *parent;
    116 	struct cfdata *match;
    117 	void *aux;
    118 {
    119 	bus_space_tag_t iot;
    120 	bus_space_handle_t ioh;
    121 	int iobase;
    122 	int rv = 1;
    123 	struct isa_attach_args *ia = aux;
    124 
    125 	if (ia->ia_nio < 1)
    126 		return (0);
    127 	if (ia->ia_nirq < 1)
    128 		return (0);
    129 
    130 	if (ISA_DIRECT_CONFIG(ia))
    131 		return (0);
    132 
    133 	/* Disallow wildcarded i/o address. */
    134 	if (ia->ia_io[0].ir_addr == ISACF_PORT_DEFAULT)
    135 		return (0);
    136 
    137 	/* Don't allow wildcarded IRQ. */
    138 	if (ia->ia_irq[0].ir_irq == ISACF_IRQ_DEFAULT)
    139 		return (0);
    140 
    141 	iot = ia->ia_iot;
    142 	iobase = ia->ia_io[0].ir_addr;
    143 
    144 	/* if it's in use as console, it's there. */
    145 	if (!com_is_console(iot, iobase, 0)) {
    146 		if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
    147 			return 0;
    148 		}
    149 		rv = comprobe1(iot, ioh);
    150 		bus_space_unmap(iot, ioh, COM_NPORTS);
    151 	}
    152 
    153 	if (rv) {
    154 		ia->ia_nio = 1;
    155 		ia->ia_io[0].ir_size = COM_NPORTS;
    156 
    157 		ia->ia_nirq = 1;
    158 
    159 		ia->ia_niomem = 0;
    160 		ia->ia_ndrq = 0;
    161 	}
    162 	return (rv);
    163 }
    164 
    165 void
    166 com_isa_attach(parent, self, aux)
    167 	struct device *parent, *self;
    168 	void *aux;
    169 {
    170 	struct com_isa_softc *isc = (void *)self;
    171 	struct com_softc *sc = &isc->sc_com;
    172 	int iobase, irq;
    173 	bus_space_tag_t iot;
    174 	struct isa_attach_args *ia = aux;
    175 
    176 	/*
    177 	 * We're living on an isa.
    178 	 */
    179 	iobase = sc->sc_iobase = ia->ia_io[0].ir_addr;
    180 	iot = sc->sc_iot = ia->ia_iot;
    181 	if (!com_is_console(iot, iobase, &sc->sc_ioh) &&
    182 	    bus_space_map(iot, iobase, COM_NPORTS, 0, &sc->sc_ioh)) {
    183 		printf(": can't map i/o space\n");
    184 		return;
    185 	}
    186 
    187 	sc->sc_frequency = COM_FREQ;
    188 	irq = ia->ia_irq[0].ir_irq;
    189 
    190 	com_attach_subr(sc);
    191 
    192 	isc->sc_ih = isa_intr_establish(ia->ia_ic, irq, IST_EDGE, IPL_SERIAL,
    193 	    comintr, sc);
    194 
    195 	/*
    196 	 * Shutdown hook for buggy BIOSs that don't recognize the UART
    197 	 * without a disabled FIFO.
    198 	 */
    199 	if (shutdownhook_establish(com_isa_cleanup, sc) == NULL)
    200 		panic("com_isa_attach: could not establish shutdown hook");
    201 }
    202 
    203 void
    204 com_isa_cleanup(arg)
    205 	void *arg;
    206 {
    207 	struct com_softc *sc = arg;
    208 
    209 	if (ISSET(sc->sc_hwflags, COM_HW_FIFO))
    210 		bus_space_write_1(sc->sc_iot, sc->sc_ioh, com_fifo, 0);
    211 }
    212