Home | History | Annotate | Line # | Download | only in bi
      1 /*	$NetBSD: bi.c,v 1.27 2021/08/07 16:19:09 thorpej Exp $ */
      2 /*
      3  * Copyright (c) 1996 Ludd, University of Lule}, Sweden.
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *      This product includes software developed at Ludd, University of
     17  *      Lule}, Sweden and its contributors.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 
     34 
     35 /*
     36  * VAXBI specific routines.
     37  */
     38 /*
     39  * TODO
     40  *   handle BIbus errors more gracefully.
     41  */
     42 
     43 #include <sys/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: bi.c,v 1.27 2021/08/07 16:19:09 thorpej Exp $");
     45 
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 
     49 #include <sys/bus.h>
     50 #include <sys/cpu.h>
     51 #include <sys/device.h>
     52 
     53 #include <dev/bi/bireg.h>
     54 #include <dev/bi/bivar.h>
     55 
     56 static int bi_print(void *, const char *);
     57 
     58 static const struct bi_list bi_list[] = {
     59 	{BIDT_MS820, DT_HAVDRV, "ms820"},
     60 	{BIDT_DRB32, DT_UNSUPP, "drb32"},
     61 	{BIDT_DWBUA, DT_HAVDRV|DT_ADAPT, "dwbua"},
     62 	{BIDT_KLESI, DT_HAVDRV|DT_ADAPT, "klesi"},
     63 	{BIDT_KA820, DT_HAVDRV, "ka820"},
     64 	{BIDT_DB88,  DT_HAVDRV|DT_QUIET, "db88"},
     65 	{BIDT_CIBCA, DT_UNSUPP, "cibca"},
     66 	{BIDT_DMB32, DT_UNSUPP, "dmb32"},
     67 	{BIDT_CIBCI, DT_UNSUPP, "cibci"},
     68 	{BIDT_KA800, DT_UNSUPP, "ka800"},
     69 	{BIDT_KDB50, DT_HAVDRV|DT_VEC, "kdb50"},
     70 	{BIDT_DWMBA, DT_HAVDRV|DT_QUIET, "dwmba"},
     71 	{BIDT_KFBTA, DT_UNSUPP, "kfbta"},
     72 	{BIDT_DEBNK, DT_HAVDRV|DT_VEC, "debnk"},
     73 	{BIDT_DEBNA, DT_HAVDRV|DT_VEC, "debna"},
     74 	{0,0,0}
     75 };
     76 
     77 int
     78 bi_print(void *aux, const char *name)
     79 {
     80 	struct bi_attach_args *ba = aux;
     81 	const struct bi_list *bl;
     82 	u_int16_t nr;
     83 
     84 	nr = bus_space_read_2(ba->ba_iot, ba->ba_ioh, 0);
     85 	for (bl = &bi_list[0]; bl->bl_nr; bl++)
     86 		if (bl->bl_nr == nr)
     87 			break;
     88 
     89 	if (name) {
     90 		if (bl->bl_nr == 0)
     91 			aprint_normal("unknown device 0x%x", nr);
     92 		else
     93 			aprint_normal(bl->bl_name);
     94 		aprint_normal(" at %s", name);
     95 	}
     96 	aprint_normal(" node %d", ba->ba_nodenr);
     97 	if (bl->bl_havedriver & DT_VEC)
     98 		aprint_normal(" vec %o", ba->ba_ivec & 511);
     99 #ifdef DEBUG
    100 	if (bus_space_read_4(ba->ba_iot, ba->ba_ioh, BIREG_SADR) &&
    101 	    bus_space_read_4(ba->ba_iot, ba->ba_ioh, BIREG_EADR))
    102 		aprint_debug(" [sadr %x eadr %x]",
    103 		    bus_space_read_4(ba->ba_iot, ba->ba_ioh, BIREG_SADR),
    104 		    bus_space_read_4(ba->ba_iot, ba->ba_ioh, BIREG_EADR));
    105 #endif
    106 	if (bl->bl_havedriver & DT_QUIET)
    107 		aprint_normal("\n");
    108 	return bl->bl_havedriver & DT_QUIET ? QUIET :
    109 	    bl->bl_havedriver & DT_HAVDRV ? UNCONF : UNSUPP;
    110 }
    111 
    112 void
    113 bi_attach(struct bi_softc *sc)
    114 {
    115 	struct bi_attach_args ba;
    116 	int nodenr;
    117 
    118 	aprint_normal("\n");
    119 
    120 	ba.ba_iot = sc->sc_iot;
    121 	ba.ba_busnr = sc->sc_busnr;
    122 	ba.ba_dmat = sc->sc_dmat;
    123 	ba.ba_intcpu = sc->sc_intcpu;
    124 	ba.ba_icookie = sc;
    125 	/*
    126 	 * Interrupt numbers. Assign them as described in
    127 	 * VAX 8800 system maintenance manual; this means like nexus
    128 	 * adapters have them assigned.
    129 	 * XXX - must address Unibus adapters.
    130 	 */
    131 	for (nodenr = 0; nodenr < NNODEBI; nodenr++) {
    132 		if (bus_space_map(sc->sc_iot, sc->sc_addr + BI_NODE(nodenr),
    133 		    BI_NODESIZE, 0, &ba.ba_ioh)) {
    134 			aprint_error_dev(sc->sc_dev,
    135 			    "bus_space_map failed, node %d\n", nodenr);
    136 			return;
    137 		}
    138 		if (badaddr((void *)ba.ba_ioh, 4) ||
    139 		    (bus_space_read_2(ba.ba_iot, ba.ba_ioh, 0) == 0)) {
    140 			bus_space_unmap(ba.ba_iot, ba.ba_ioh, BI_NODESIZE);
    141 			continue;
    142 		}
    143 		ba.ba_nodenr = nodenr;
    144 		ba.ba_ivec = sc->sc_lastiv + 64 + 4 * nodenr; /* all on spl5 */
    145 		config_found(sc->sc_dev, &ba, bi_print, CFARGS_NONE);
    146 	}
    147 }
    148