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