Home | History | Annotate | Line # | Download | only in xmi
xmi.c revision 1.9
      1 /*	$NetBSD: xmi.c,v 1.9 2007/10/19 12:01:24 ad Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2000 Ludd, University of Lule}, Sweden. 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  * XMI specific routines.
     35  */
     36 
     37 #include <sys/cdefs.h>
     38 __KERNEL_RCSID(0, "$NetBSD: xmi.c,v 1.9 2007/10/19 12:01:24 ad Exp $");
     39 
     40 #include <sys/param.h>
     41 #include <sys/systm.h>
     42 #include <sys/device.h>
     43 
     44 #include <uvm/uvm_extern.h>
     45 
     46 #include <sys/bus.h>
     47 #include <sys/cpu.h>
     48 
     49 #include <dev/xmi/xmireg.h>
     50 #include <dev/xmi/xmivar.h>
     51 
     52 static int xmi_print(void *, const char *);
     53 
     54 struct xmi_list xmi_list[] = {
     55 	{XMIDT_KA62, 0, "ka6200"},
     56 	{XMIDT_KA64, 1, "ka6400"},
     57 	{XMIDT_KA65, 0, "ka6500"},
     58 	{XMIDT_KA66, 0, "ka6600"},
     59 	{XMIDT_MS62, 1, "ms62"},
     60 	{XMIDT_DWMBA, 1, "dwmba"},
     61 	{0,0,0}
     62 };
     63 
     64 int
     65 xmi_print(void *aux, const char *name)
     66 {
     67 	struct xmi_attach_args *xa = aux;
     68 	struct xmi_list *xl;
     69 
     70 	for (xl = &xmi_list[0]; xl->xl_nr; xl++)
     71 		if (xl->xl_nr == bus_space_read_2(xa->xa_iot, xa->xa_ioh, 0))
     72 			break;
     73 
     74 	if (name) {
     75 		if (xl->xl_nr == 0)
     76 			aprint_normal("unknown device 0x%x",
     77 			    bus_space_read_2(xa->xa_iot, xa->xa_ioh, 0));
     78 		else
     79 			aprint_normal(xl->xl_name);
     80 		aprint_normal(" at %s", name);
     81 	}
     82 	aprint_normal(" node %d", xa->xa_nodenr);
     83 	return xl->xl_havedriver ? UNCONF : UNSUPP;
     84 }
     85 
     86 static	int lastiv = 0;
     87 
     88 void
     89 xmi_attach(struct xmi_softc *sc)
     90 {
     91 	struct xmi_attach_args xa;
     92 	int nodenr;
     93 
     94 	printf("\n");
     95 
     96 	xa.xa_iot = sc->sc_iot;
     97 	xa.xa_busnr = sc->sc_busnr;
     98 	xa.xa_dmat = sc->sc_dmat;
     99 	xa.xa_intcpu = sc->sc_intcpu;
    100 	/*
    101 	 * Interrupt numbers. All vectors from 256-512 are free, use
    102 	 * them for XMI devices and just count them up.
    103 	 * Above 512 are only interrupt vectors for unibus devices.
    104 	 *
    105 	 * The XMI nodespace is giant in size. Only map in the first
    106 	 * page here and map more (if needed) in the device itself.
    107 	 */
    108 	for (nodenr = 0; nodenr < NNODEXMI; nodenr++) {
    109 		if (bus_space_map(sc->sc_iot, sc->sc_addr + XMI_NODE(nodenr),
    110 		    PAGE_SIZE, 0, &xa.xa_ioh)) {
    111 			printf("xmi_attach: bus_space_map failed, node %d\n",
    112 			    nodenr);
    113 			return;
    114 		}
    115 		if (badaddr((void *)xa.xa_ioh, 4)) {
    116 			bus_space_unmap(sc->sc_iot, xa.xa_ioh, PAGE_SIZE);
    117 			continue;
    118 		}
    119 		xa.xa_nodenr = nodenr;
    120 		xa.xa_ivec = 256 + lastiv;
    121 		lastiv += 4;
    122 		config_found(&sc->sc_dev, &xa, xmi_print);
    123 	}
    124 }
    125