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