Home | History | Annotate | Line # | Download | only in mainbus
mainbus.c revision 1.21.42.1
      1  1.21.42.1  thorpej /* $NetBSD: mainbus.c,v 1.21.42.1 2021/03/20 19:33:31 thorpej Exp $ */
      2        1.1  reinoud 
      3        1.1  reinoud /*
      4        1.1  reinoud  * Copyright (c) 1994,1995 Mark Brinicombe.
      5        1.1  reinoud  * Copyright (c) 1994 Brini.
      6        1.1  reinoud  * All rights reserved.
      7        1.1  reinoud  *
      8        1.1  reinoud  * Redistribution and use in source and binary forms, with or without
      9        1.1  reinoud  * modification, are permitted provided that the following conditions
     10        1.1  reinoud  * are met:
     11        1.1  reinoud  * 1. Redistributions of source code must retain the above copyright
     12        1.1  reinoud  *    notice, this list of conditions and the following disclaimer.
     13        1.1  reinoud  * 2. Redistributions in binary form must reproduce the above copyright
     14        1.1  reinoud  *    notice, this list of conditions and the following disclaimer in the
     15        1.1  reinoud  *    documentation and/or other materials provided with the distribution.
     16        1.1  reinoud  * 3. All advertising materials mentioning features or use of this software
     17        1.1  reinoud  *    must display the following acknowledgement:
     18        1.1  reinoud  *	This product includes software developed by Brini.
     19        1.1  reinoud  * 4. The name of the company nor the name of the author may be used to
     20        1.1  reinoud  *    endorse or promote products derived from this software without specific
     21        1.1  reinoud  *    prior written permission.
     22        1.1  reinoud  *
     23        1.1  reinoud  * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
     24        1.1  reinoud  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     25        1.1  reinoud  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26        1.1  reinoud  * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     27        1.1  reinoud  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     28        1.1  reinoud  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     29        1.1  reinoud  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30        1.1  reinoud  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31        1.1  reinoud  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32        1.1  reinoud  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33        1.1  reinoud  * SUCH DAMAGE.
     34        1.1  reinoud  *
     35        1.1  reinoud  * RiscBSD kernel project
     36        1.1  reinoud  *
     37        1.1  reinoud  * mainbus.c
     38        1.1  reinoud  *
     39        1.1  reinoud  * mainbus configuration
     40        1.1  reinoud  *
     41        1.1  reinoud  * Created      : 15/12/94
     42        1.1  reinoud  */
     43        1.9    lukem 
     44        1.9    lukem #include <sys/cdefs.h>
     45  1.21.42.1  thorpej __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.21.42.1 2021/03/20 19:33:31 thorpej Exp $");
     46        1.1  reinoud 
     47        1.1  reinoud #include <sys/param.h>
     48        1.1  reinoud #include <sys/systm.h>
     49        1.1  reinoud #include <sys/kernel.h>
     50        1.1  reinoud #include <sys/conf.h>
     51        1.1  reinoud #include <sys/malloc.h>
     52        1.1  reinoud #include <sys/device.h>
     53        1.1  reinoud 
     54        1.2     matt #if defined(arm32)		/* XXX */
     55        1.3  nathanw #include <machine/io.h>
     56        1.2     matt #endif
     57       1.18   dyoung #include <sys/bus.h>
     58        1.1  reinoud #include <arm/mainbus/mainbus.h>
     59        1.1  reinoud #include "locators.h"
     60        1.1  reinoud 
     61        1.1  reinoud /*
     62        1.1  reinoud  * mainbus is a root device so we a bus space tag to pass to children
     63        1.1  reinoud  *
     64        1.1  reinoud  * The tag is provided by mainbus_io.c and mainbus_io_asm.S
     65        1.1  reinoud  */
     66        1.1  reinoud 
     67        1.1  reinoud extern struct bus_space mainbus_bs_tag;
     68        1.1  reinoud 
     69        1.1  reinoud /* Prototypes for functions provided */
     70        1.1  reinoud 
     71       1.17     matt static int  mainbusmatch(device_t, cfdata_t, void *);
     72       1.17     matt static void mainbusattach(device_t, device_t, void *);
     73       1.15      dsl static int  mainbusprint(void *aux, const char *mainbus);
     74       1.17     matt static int  mainbussearch(device_t, cfdata_t,
     75       1.15      dsl 				const int *, void *);
     76        1.1  reinoud 
     77        1.1  reinoud /* attach and device structures for the device */
     78        1.1  reinoud 
     79       1.17     matt CFATTACH_DECL_NEW(mainbus, 0,
     80        1.6  thorpej     mainbusmatch, mainbusattach, NULL, NULL);
     81        1.1  reinoud 
     82        1.1  reinoud /*
     83       1.17     matt  * int mainbusmatch(device_t parent, cfdata_t cf, void *aux)
     84        1.1  reinoud  *
     85        1.1  reinoud  * Always match for unit 0
     86        1.1  reinoud  */
     87        1.1  reinoud 
     88        1.1  reinoud static int
     89       1.17     matt mainbusmatch(device_t parent, cfdata_t cf, void *aux)
     90        1.1  reinoud {
     91        1.1  reinoud 	return (1);
     92        1.1  reinoud }
     93        1.1  reinoud 
     94        1.1  reinoud /*
     95        1.1  reinoud  * int mainbusprint(void *aux, const char *mainbus)
     96        1.1  reinoud  *
     97        1.1  reinoud  * print routine used during config of children
     98        1.1  reinoud  */
     99        1.1  reinoud 
    100        1.1  reinoud static int
    101       1.16      dsl mainbusprint(void *aux, const char *mainbus)
    102        1.1  reinoud {
    103        1.1  reinoud 	struct mainbus_attach_args *mb = aux;
    104        1.1  reinoud 
    105        1.1  reinoud 	if (mb->mb_iobase != MAINBUSCF_BASE_DEFAULT)
    106        1.7  thorpej 		aprint_normal(" base 0x%x", mb->mb_iobase);
    107        1.1  reinoud 	if (mb->mb_iosize > 1)
    108        1.7  thorpej 		aprint_normal("-0x%x", mb->mb_iobase + mb->mb_iosize - 1);
    109        1.1  reinoud 	if (mb->mb_irq != -1)
    110        1.7  thorpej 		aprint_normal(" irq %d", mb->mb_irq);
    111        1.1  reinoud 	if (mb->mb_drq != -1)
    112        1.7  thorpej 		aprint_normal(" drq 0x%08x", mb->mb_drq);
    113       1.20     matt 	if (mb->mb_core != MAINBUSCF_CORE_DEFAULT)
    114       1.20     matt 		aprint_normal(" core %d", mb->mb_core);
    115        1.1  reinoud 
    116        1.1  reinoud /* XXXX print flags */
    117        1.1  reinoud 	return (QUIET);
    118        1.1  reinoud }
    119        1.1  reinoud 
    120        1.1  reinoud /*
    121       1.17     matt  * int mainbussearch(device_t parent, device_t self, void *aux)
    122        1.1  reinoud  *
    123        1.1  reinoud  * search routine used during the config of children
    124        1.1  reinoud  */
    125        1.1  reinoud 
    126        1.1  reinoud static int
    127       1.17     matt mainbussearch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    128        1.1  reinoud {
    129        1.1  reinoud 	struct mainbus_attach_args mb;
    130        1.1  reinoud 	int tryagain;
    131        1.1  reinoud 
    132        1.1  reinoud 	do {
    133        1.1  reinoud 		if (cf->cf_loc[MAINBUSCF_BASE] == MAINBUSCF_BASE_DEFAULT) {
    134        1.1  reinoud 			mb.mb_iobase = MAINBUSCF_BASE_DEFAULT;
    135        1.1  reinoud 			mb.mb_iosize = 0;
    136        1.1  reinoud 			mb.mb_drq = MAINBUSCF_DACK_DEFAULT;
    137        1.1  reinoud 			mb.mb_irq = MAINBUSCF_IRQ_DEFAULT;
    138        1.1  reinoud 		} else {
    139        1.2     matt 			mb.mb_iobase = cf->cf_loc[MAINBUSCF_BASE];
    140       1.10    chris #if defined(arm32) && !defined(EB7500ATX)
    141        1.2     matt 			mb.mb_iobase += IO_CONF_BASE;
    142        1.2     matt #endif
    143       1.14     matt 			mb.mb_iosize = cf->cf_loc[MAINBUSCF_SIZE];
    144        1.1  reinoud 			mb.mb_drq = cf->cf_loc[MAINBUSCF_DACK];
    145        1.1  reinoud 			mb.mb_irq = cf->cf_loc[MAINBUSCF_IRQ];
    146        1.1  reinoud 		}
    147       1.20     matt 		mb.mb_core = cf->cf_loc[MAINBUSCF_CORE];
    148       1.19     matt 		mb.mb_intrbase = cf->cf_loc[MAINBUSCF_INTRBASE];
    149        1.1  reinoud 		mb.mb_iot = &mainbus_bs_tag;
    150        1.1  reinoud 
    151        1.1  reinoud 		tryagain = 0;
    152        1.4  thorpej 		if (config_match(parent, cf, &mb) > 0) {
    153        1.1  reinoud 			config_attach(parent, cf, &mb, mainbusprint);
    154       1.21     matt #ifdef MULTIPROCESSOR
    155       1.21     matt 			tryagain = (cf->cf_fstate == FSTATE_STAR);
    156       1.21     matt #endif
    157        1.1  reinoud 		}
    158        1.1  reinoud 	} while (tryagain);
    159        1.1  reinoud 
    160        1.1  reinoud 	return (0);
    161        1.1  reinoud }
    162        1.1  reinoud 
    163        1.1  reinoud /*
    164       1.17     matt  * void mainbusattach(device_t parent, device_t self, void *aux)
    165        1.1  reinoud  *
    166        1.1  reinoud  * probe and attach all children
    167        1.1  reinoud  */
    168        1.1  reinoud 
    169        1.1  reinoud static void
    170       1.17     matt mainbusattach(device_t parent, device_t self, void *aux)
    171        1.1  reinoud {
    172        1.8  thorpej 	aprint_naive("\n");
    173        1.8  thorpej 	aprint_normal("\n");
    174        1.1  reinoud 
    175  1.21.42.1  thorpej 	config_search(self, NULL,
    176  1.21.42.1  thorpej 	    CFARG_SUBMATCH, mainbussearch,
    177  1.21.42.1  thorpej 	    CFARG_IATTR, "mainbus",
    178  1.21.42.1  thorpej 	    CFARG_EOL);
    179        1.1  reinoud }
    180        1.1  reinoud 
    181        1.1  reinoud /* End of mainbus.c */
    182