Home | History | Annotate | Line # | Download | only in ev64260
mainbus.c revision 1.2
      1  1.2  matt /*	$NetBSD: mainbus.c,v 1.2 2003/03/07 18:24:01 matt Exp $	*/
      2  1.1  matt 
      3  1.1  matt /*
      4  1.1  matt  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
      5  1.1  matt  *
      6  1.1  matt  * Redistribution and use in source and binary forms, with or without
      7  1.1  matt  * modification, are permitted provided that the following conditions
      8  1.1  matt  * are met:
      9  1.1  matt  * 1. Redistributions of source code must retain the above copyright
     10  1.1  matt  *    notice, this list of conditions and the following disclaimer.
     11  1.1  matt  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  matt  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  matt  *    documentation and/or other materials provided with the distribution.
     14  1.1  matt  * 3. All advertising materials mentioning features or use of this software
     15  1.1  matt  *    must display the following acknowledgement:
     16  1.1  matt  *      This product includes software developed by Christopher G. Demetriou
     17  1.1  matt  *	for the NetBSD Project.
     18  1.1  matt  * 4. The name of the author may not be used to endorse or promote products
     19  1.1  matt  *    derived from this software without specific prior written permission
     20  1.1  matt  *
     21  1.1  matt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.1  matt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.1  matt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.1  matt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.1  matt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.1  matt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.1  matt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.1  matt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.1  matt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.1  matt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.1  matt  */
     32  1.1  matt 
     33  1.1  matt #include "mainbus.h"
     34  1.1  matt #include "pci.h"
     35  1.2  matt #include "opt_multiprocessor.h"
     36  1.1  matt #include "opt_pci.h"
     37  1.1  matt 
     38  1.1  matt #include <sys/param.h>
     39  1.1  matt #include <sys/extent.h>
     40  1.1  matt #include <sys/device.h>
     41  1.1  matt #include <sys/malloc.h>
     42  1.1  matt #include <sys/systm.h>
     43  1.1  matt 
     44  1.1  matt #include <machine/bus.h>
     45  1.1  matt 
     46  1.1  matt #include <dev/pci/pcivar.h>
     47  1.1  matt #include <dev/pci/pciconf.h>
     48  1.1  matt 
     49  1.1  matt #include <dev/marvell/gtvar.h>
     50  1.1  matt 
     51  1.1  matt #if NCPU == 0
     52  1.1  matt #error	A cpu device is now required
     53  1.1  matt #endif
     54  1.1  matt 
     55  1.1  matt struct	mainbus_attach_args {
     56  1.1  matt 	const char *mba_busname;
     57  1.1  matt 	int mba_unit;
     58  1.1  matt };
     59  1.1  matt 
     60  1.1  matt int	mainbus_cfprint(void *, const char *);
     61  1.1  matt int	mainbus_match(struct device *, struct cfdata *, void *);
     62  1.1  matt void	mainbus_attach(struct device *, struct device *, void *);
     63  1.1  matt 
     64  1.1  matt CFATTACH_DECL(mainbus, sizeof(struct device),
     65  1.1  matt 	mainbus_match, mainbus_attach, NULL, NULL);
     66  1.1  matt 
     67  1.1  matt int
     68  1.1  matt mainbus_cfprint(void *aux, const char *pnp)
     69  1.1  matt {
     70  1.1  matt 	struct mainbus_attach_args *mba = aux;
     71  1.1  matt 
     72  1.1  matt 	if (pnp)
     73  1.1  matt 		printf("%s at %s", mba->mba_busname, pnp);
     74  1.1  matt 	return (UNCONF);
     75  1.1  matt }
     76  1.1  matt 
     77  1.1  matt 
     78  1.1  matt /*
     79  1.1  matt  * Probe for the mainbus; always succeeds.
     80  1.1  matt  */
     81  1.1  matt int
     82  1.1  matt mainbus_match(struct device *parent, struct cfdata *match, void *aux)
     83  1.1  matt {
     84  1.1  matt 	return 1;
     85  1.1  matt }
     86  1.1  matt 
     87  1.1  matt /*
     88  1.1  matt  * Attach the mainbus.
     89  1.1  matt  */
     90  1.1  matt void
     91  1.1  matt mainbus_attach(struct device *parent, struct device *self, void *aux)
     92  1.1  matt {
     93  1.1  matt 	struct mainbus_attach_args mba;
     94  1.1  matt 
     95  1.1  matt 	printf("\n");
     96  1.1  matt 
     97  1.1  matt 	memset(&mba, 0, sizeof(mba));
     98  1.1  matt 
     99  1.1  matt 	/*
    100  1.1  matt 	 * Always find the CPU
    101  1.1  matt 	 */
    102  1.1  matt 	mba.mba_busname = "cpu";
    103  1.1  matt 	mba.mba_unit = 0;
    104  1.1  matt 	config_found(self, &mba, mainbus_cfprint);
    105  1.1  matt 
    106  1.2  matt #ifdef MULTIPROCESSOR
    107  1.1  matt 	/*
    108  1.1  matt 	 * Try for a second one...
    109  1.1  matt 	 */
    110  1.1  matt 	mba.mba_busname = "cpu";
    111  1.1  matt 	mba.mba_unit = 1;
    112  1.1  matt 	config_found(self, &mba, mainbus_cfprint);
    113  1.2  matt #endif
    114  1.1  matt 
    115  1.1  matt 	/*
    116  1.1  matt 	 * Now try to configure the Discovery
    117  1.1  matt 	 */
    118  1.1  matt 	mba.mba_busname = "gt";
    119  1.1  matt 	mba.mba_unit = 1;
    120  1.1  matt 	config_found(self, &mba, mainbus_cfprint);
    121  1.1  matt }
    122  1.1  matt 
    123  1.1  matt static int	cpu_match(struct device *, struct cfdata *, void *);
    124  1.1  matt static void	cpu_attach(struct device *, struct device *, void *);
    125  1.1  matt 
    126  1.1  matt CFATTACH_DECL(cpu, sizeof(struct device), cpu_match, cpu_attach, NULL, NULL);
    127  1.1  matt 
    128  1.1  matt extern struct cfdriver cpu_cd;
    129  1.1  matt 
    130  1.1  matt int
    131  1.1  matt cpu_match(struct device *parent, struct cfdata *cf, void *aux)
    132  1.1  matt {
    133  1.1  matt 	struct mainbus_attach_args *mba = aux;
    134  1.1  matt 
    135  1.1  matt 	if (strcmp(mba->mba_busname, cpu_cd.cd_name) != 0)
    136  1.1  matt 		return 0;
    137  1.1  matt 
    138  1.1  matt 	if (cpu_info[0].ci_dev != NULL)
    139  1.1  matt 		return 0;
    140  1.1  matt 
    141  1.1  matt 	return 1;
    142  1.1  matt }
    143  1.1  matt 
    144  1.1  matt void
    145  1.1  matt cpu_attach(struct device *parent, struct device *self, void *aux)
    146  1.1  matt {
    147  1.1  matt 	(void) cpu_attach_common(self, 0);
    148  1.1  matt }
    149