Home | History | Annotate | Line # | Download | only in ev64260
mainbus.c revision 1.1
      1  1.1  matt /*	$NetBSD: mainbus.c,v 1.1 2003/03/05 22:08:27 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.1  matt #include "opt_pci.h"
     36  1.1  matt 
     37  1.1  matt #include <sys/param.h>
     38  1.1  matt #include <sys/extent.h>
     39  1.1  matt #include <sys/device.h>
     40  1.1  matt #include <sys/malloc.h>
     41  1.1  matt #include <sys/systm.h>
     42  1.1  matt 
     43  1.1  matt #include <machine/bus.h>
     44  1.1  matt 
     45  1.1  matt #include <dev/pci/pcivar.h>
     46  1.1  matt #include <dev/pci/pciconf.h>
     47  1.1  matt 
     48  1.1  matt #include <dev/marvell/gtvar.h>
     49  1.1  matt 
     50  1.1  matt #if NCPU == 0
     51  1.1  matt #error	A cpu device is now required
     52  1.1  matt #endif
     53  1.1  matt 
     54  1.1  matt struct	mainbus_attach_args {
     55  1.1  matt 	const char *mba_busname;
     56  1.1  matt 	int mba_unit;
     57  1.1  matt };
     58  1.1  matt 
     59  1.1  matt int	mainbus_cfprint(void *, const char *);
     60  1.1  matt int	mainbus_match(struct device *, struct cfdata *, void *);
     61  1.1  matt void	mainbus_attach(struct device *, struct device *, void *);
     62  1.1  matt 
     63  1.1  matt CFATTACH_DECL(mainbus, sizeof(struct device),
     64  1.1  matt 	mainbus_match, mainbus_attach, NULL, NULL);
     65  1.1  matt 
     66  1.1  matt int
     67  1.1  matt mainbus_cfprint(void *aux, const char *pnp)
     68  1.1  matt {
     69  1.1  matt 	struct mainbus_attach_args *mba = aux;
     70  1.1  matt 
     71  1.1  matt 	if (pnp)
     72  1.1  matt 		printf("%s at %s", mba->mba_busname, pnp);
     73  1.1  matt 	return (UNCONF);
     74  1.1  matt }
     75  1.1  matt 
     76  1.1  matt 
     77  1.1  matt /*
     78  1.1  matt  * Probe for the mainbus; always succeeds.
     79  1.1  matt  */
     80  1.1  matt int
     81  1.1  matt mainbus_match(struct device *parent, struct cfdata *match, void *aux)
     82  1.1  matt {
     83  1.1  matt 	return 1;
     84  1.1  matt }
     85  1.1  matt 
     86  1.1  matt /*
     87  1.1  matt  * Attach the mainbus.
     88  1.1  matt  */
     89  1.1  matt void
     90  1.1  matt mainbus_attach(struct device *parent, struct device *self, void *aux)
     91  1.1  matt {
     92  1.1  matt 	struct mainbus_attach_args mba;
     93  1.1  matt 
     94  1.1  matt 	printf("\n");
     95  1.1  matt 
     96  1.1  matt 	memset(&mba, 0, sizeof(mba));
     97  1.1  matt 
     98  1.1  matt 	/*
     99  1.1  matt 	 * Always find the CPU
    100  1.1  matt 	 */
    101  1.1  matt 	mba.mba_busname = "cpu";
    102  1.1  matt 	mba.mba_unit = 0;
    103  1.1  matt 	config_found(self, &mba, mainbus_cfprint);
    104  1.1  matt 
    105  1.1  matt 	/*
    106  1.1  matt 	 * Try for a second one...
    107  1.1  matt 	 */
    108  1.1  matt 	mba.mba_busname = "cpu";
    109  1.1  matt 	mba.mba_unit = 1;
    110  1.1  matt 	config_found(self, &mba, mainbus_cfprint);
    111  1.1  matt 
    112  1.1  matt 	/*
    113  1.1  matt 	 * Now try to configure the Discovery
    114  1.1  matt 	 */
    115  1.1  matt 	mba.mba_busname = "gt";
    116  1.1  matt 	mba.mba_unit = 1;
    117  1.1  matt 	config_found(self, &mba, mainbus_cfprint);
    118  1.1  matt }
    119  1.1  matt 
    120  1.1  matt static int	cpu_match(struct device *, struct cfdata *, void *);
    121  1.1  matt static void	cpu_attach(struct device *, struct device *, void *);
    122  1.1  matt 
    123  1.1  matt CFATTACH_DECL(cpu, sizeof(struct device), cpu_match, cpu_attach, NULL, NULL);
    124  1.1  matt 
    125  1.1  matt extern struct cfdriver cpu_cd;
    126  1.1  matt 
    127  1.1  matt int
    128  1.1  matt cpu_match(struct device *parent, struct cfdata *cf, void *aux)
    129  1.1  matt {
    130  1.1  matt 	struct mainbus_attach_args *mba = aux;
    131  1.1  matt 
    132  1.1  matt 	if (strcmp(mba->mba_busname, cpu_cd.cd_name) != 0)
    133  1.1  matt 		return 0;
    134  1.1  matt 
    135  1.1  matt 	if (cpu_info[0].ci_dev != NULL)
    136  1.1  matt 		return 0;
    137  1.1  matt 
    138  1.1  matt 	return 1;
    139  1.1  matt }
    140  1.1  matt 
    141  1.1  matt void
    142  1.1  matt cpu_attach(struct device *parent, struct device *self, void *aux)
    143  1.1  matt {
    144  1.1  matt 	(void) cpu_attach_common(self, 0);
    145  1.1  matt }
    146