Home | History | Annotate | Line # | Download | only in dev
zs_any.c revision 1.1
      1 /*	$NetBSD: zs_any.c,v 1.1 2001/04/06 15:14:39 fredette Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Gordon W. Ross and Matthew Fredette.
      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  * Zilog Z8530 Dual UART driver (machine-dependent part)
     41  *
     42  * Runs two serial lines per chip using slave drivers.
     43  * Plain tty/async lines use the zs_async slave.
     44  * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
     45  */
     46 
     47 #include <sys/param.h>
     48 #include <sys/systm.h>
     49 #include <sys/conf.h>
     50 #include <sys/device.h>
     51 #include <sys/file.h>
     52 #include <sys/ioctl.h>
     53 #include <sys/kernel.h>
     54 #include <sys/proc.h>
     55 #include <sys/tty.h>
     56 #include <sys/time.h>
     57 #include <sys/syslog.h>
     58 
     59 #include <machine/autoconf.h>
     60 #include <machine/bus.h>
     61 #include <machine/z8530var.h>
     62 
     63 #ifdef	KGDB
     64 #include <uvm/uvm_extern.h>
     65 
     66 #include <machine/idprom.h>
     67 #include <machine/pmap.h>
     68 #include <dev/sun/cons.h>
     69 #endif
     70 
     71 #include <sun2/sun2/machdep.h>
     72 #include <dev/ic/z8530reg.h>
     73 
     74 /****************************************************************
     75  * Autoconfig
     76  ****************************************************************/
     77 
     78 /* Definition of the driver for autoconfig. */
     79 static int	zs_any_match __P((struct device *, struct cfdata *, void *));
     80 static void	zs_any_attach __P((struct device *, struct device *, void *));
     81 
     82 struct cfattach zs_obio_ca = {
     83 	sizeof(struct zsc_softc), zs_any_match, zs_any_attach
     84 };
     85 
     86 struct cfattach zs_obmem_ca = {
     87 	sizeof(struct zsc_softc), zs_any_match, zs_any_attach
     88 };
     89 
     90 struct cfattach zs_mbmem_ca = {
     91 	sizeof(struct zsc_softc), zs_any_match, zs_any_attach
     92 };
     93 
     94 /*
     95  * Is the zs chip present?
     96  */
     97 static int
     98 zs_any_match(parent, cf, aux)
     99 	struct device *parent;
    100 	struct cfdata *cf;
    101 	void *aux;
    102 {
    103 	struct confargs *ca = aux;
    104 
    105 	/* Make sure there is something there... */
    106 	if (!bus_space_probe(ca->ca_bustag, 0, ca->ca_paddr,
    107 				1,	/* probe size */
    108 				0,	/* offset */
    109 				0,	/* flags */
    110 				NULL, NULL))
    111 		return (0);
    112 
    113 	/* Default interrupt priority (always splbio==2) */
    114 	if (ca->ca_intpri == -1)
    115 		ca->ca_intpri = ZSHARD_PRI;
    116 
    117 	return (1);
    118 }
    119 
    120 /*
    121  * Attach a found zs.
    122  */
    123 static void
    124 zs_any_attach(parent, self, aux)
    125 	struct device *parent;
    126 	struct device *self;
    127 	void *aux;
    128 {
    129 	struct zsc_softc *zsc = (void *) self;
    130 	struct confargs *ca = aux;
    131 	bus_space_handle_t bh;
    132 
    133         zsc->zsc_bustag = ca->ca_bustag;
    134         zsc->zsc_dmatag = ca->ca_dmatag;
    135         zsc->zsc_promunit = self->dv_unit;
    136         zsc->zsc_node = 0;
    137 
    138 	/* Map in the device. */
    139 	if (bus_space_map(ca->ca_bustag, ca->ca_paddr, sizeof(struct zsdevice),
    140 			  BUS_SPACE_MAP_LINEAR, &bh))
    141 		panic("zs_any_attach: can't map");
    142 
    143 	/* This is where we break the bus_space(9) abstraction: */
    144 	zs_attach(zsc, (void *)bh, ca->ca_intpri);
    145 }
    146 
    147 #ifdef	KGDB
    148 /*
    149  * Find a zs mapped by the PROM.  Currently this only works to find
    150  * zs0 on obio.
    151  */
    152 void *
    153 zs_find_prom(unit)
    154     int unit;
    155 {
    156 	bus_addr_t zs0_phys;
    157 	bus_space_handle_t bh;
    158 
    159 	if (unit != 0)
    160 		return (NULL);
    161 
    162 	/*
    163 	 * The physical address of zs0 is model-dependent.
    164 	 */
    165 	zs0_phys = (cpu_machine_id == SUN2_MACH_120 ?
    166 	    	    0x002000 : 0x7f2000);
    167 
    168 	if (sun2_find_prom_map(zs0_phys, PMAP_OBIO, sizeof(struct zsdevice), &bh))
    169 		return (NULL);
    170 
    171 	return ((void*) bh);
    172 }
    173 #endif	/* KGDB */
    174