Home | History | Annotate | Line # | Download | only in vax
      1 /*	$NetBSD: cmi.c,v 1.16 2021/08/07 16:19:07 thorpej Exp $ */
      2 /*
      3  * Copyright (c) 1999 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  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  */
     26 
     27 #include <sys/cdefs.h>
     28 __KERNEL_RCSID(0, "$NetBSD: cmi.c,v 1.16 2021/08/07 16:19:07 thorpej Exp $");
     29 
     30 #include <sys/param.h>
     31 #include <sys/systm.h>
     32 #include <sys/bus.h>
     33 #include <sys/cpu.h>
     34 #include <sys/device.h>
     35 
     36 #include <machine/nexus.h>
     37 #include <machine/sid.h>
     38 #include <machine/ka750.h>
     39 #include <machine/mainbus.h>
     40 
     41 static	int cmi_print(void *, const char *);
     42 static	int cmi_match(device_t, cfdata_t, void *);
     43 static	void cmi_attach(device_t, device_t, void*);
     44 
     45 CFATTACH_DECL_NEW(cmi, 0,
     46     cmi_match, cmi_attach, NULL, NULL);
     47 
     48 int
     49 cmi_print(void *aux, const char *name)
     50 {
     51 	struct sbi_attach_args * const sa = aux;
     52 
     53 	if (name)
     54 		aprint_normal("unknown device 0x%x at %s", sa->sa_type, name);
     55 
     56 	aprint_normal(" tr%d", sa->sa_nexnum);
     57 	return (UNCONF);
     58 }
     59 
     60 
     61 int
     62 cmi_match(device_t parent, cfdata_t cf, void *aux)
     63 {
     64 	struct mainbus_attach_args * const ma = aux;
     65 
     66 	return !strcmp("cmi", ma->ma_type);
     67 }
     68 
     69 void
     70 cmi_attach(device_t parent, device_t self, void *aux)
     71 {
     72 	struct sbi_attach_args sa;
     73 
     74         sa.sa_base = NEX750;
     75 
     76 	aprint_normal("\n");
     77 	/*
     78 	 * Probe for memory, can be in the first 4 slots.
     79 	 */
     80 #define NEXPAGES (sizeof(struct nexus) / VAX_NBPG)
     81 	for (sa.sa_nexnum = 0; sa.sa_nexnum < 4; sa.sa_nexnum++) {
     82 		sa.sa_ioh = vax_map_physmem(NEX750 +
     83 		    sizeof(struct nexus) * sa.sa_nexnum, NEXPAGES);
     84 		if (badaddr((void *)sa.sa_ioh, 4)) {
     85 			vax_unmap_physmem((vaddr_t)sa.sa_ioh, NEXPAGES);
     86 		} else {
     87 			sa.sa_type = NEX_MEM16;
     88 			config_found(self, (void*)&sa, cmi_print, CFARGS_NONE);
     89 		}
     90 	}
     91 
     92 	/*
     93 	 * Probe for mba's, can be in slot 4 - 7.
     94 	 */
     95 	for (sa.sa_nexnum = 4; sa.sa_nexnum < 7; sa.sa_nexnum++) {
     96 		sa.sa_ioh = vax_map_physmem(NEX750 +
     97 		    sizeof(struct nexus) * sa.sa_nexnum, NEXPAGES);
     98 		if (badaddr((void *)sa.sa_ioh, 4)) {
     99 			vax_unmap_physmem((vaddr_t)sa.sa_ioh, NEXPAGES);
    100 		} else {
    101 			sa.sa_type = NEX_MBA;
    102 			config_found(self, (void*)&sa, cmi_print, CFARGS_NONE);
    103 		}
    104 	}
    105 
    106 	/*
    107 	 * There are always one generic UBA, and maybe an optional.
    108 	 */
    109 	sa.sa_nexnum = 8;
    110 	sa.sa_ioh = vax_map_physmem(NEX750 +
    111 	    sizeof(struct nexus) * sa.sa_nexnum, NEXPAGES);
    112 	sa.sa_type = NEX_UBA0;
    113 	config_found(self, (void*)&sa, cmi_print, CFARGS_NONE);
    114 
    115 	sa.sa_nexnum = 9;
    116 	sa.sa_ioh = vax_map_physmem(NEX750 +
    117 	    sizeof(struct nexus) * sa.sa_nexnum, NEXPAGES);
    118 	sa.sa_type = NEX_UBA1;
    119 	if (badaddr((void *)sa.sa_ioh, 4))
    120 		vax_unmap_physmem((vaddr_t)sa.sa_ioh, NEXPAGES);
    121 	else
    122 		config_found(self, (void*)&sa, cmi_print, CFARGS_NONE);
    123 }
    124