mainbus.c revision 1.1
11.1Smatt/*	$NetBSD: mainbus.c,v 1.1 2009/08/06 00:50:26 matt Exp $	*/
21.1Smatt
31.1Smatt/*
41.1Smatt * Copyright 2002 Wasabi Systems, Inc.
51.1Smatt * All rights reserved.
61.1Smatt *
71.1Smatt * Written by Simon Burge for Wasabi Systems, Inc.
81.1Smatt *
91.1Smatt * Redistribution and use in source and binary forms, with or without
101.1Smatt * modification, are permitted provided that the following conditions
111.1Smatt * are met:
121.1Smatt * 1. Redistributions of source code must retain the above copyright
131.1Smatt *    notice, this list of conditions and the following disclaimer.
141.1Smatt * 2. Redistributions in binary form must reproduce the above copyright
151.1Smatt *    notice, this list of conditions and the following disclaimer in the
161.1Smatt *    documentation and/or other materials provided with the distribution.
171.1Smatt * 3. All advertising materials mentioning features or use of this software
181.1Smatt *    must display the following acknowledgement:
191.1Smatt *      This product includes software developed for the NetBSD Project by
201.1Smatt *      Wasabi Systems, Inc.
211.1Smatt * 4. The name of Wasabi Systems, Inc. may not be used to endorse
221.1Smatt *    or promote products derived from this software without specific prior
231.1Smatt *    written permission.
241.1Smatt *
251.1Smatt * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
261.1Smatt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
271.1Smatt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
281.1Smatt * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
291.1Smatt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
301.1Smatt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
311.1Smatt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
321.1Smatt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
331.1Smatt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
341.1Smatt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
351.1Smatt * POSSIBILITY OF SUCH DAMAGE.
361.1Smatt */
371.1Smatt
381.1Smatt#include <sys/cdefs.h>
391.1Smatt__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.1 2009/08/06 00:50:26 matt Exp $");
401.1Smatt
411.1Smatt#include "opt_pci.h"
421.1Smatt
431.1Smatt#include <sys/param.h>
441.1Smatt#include <sys/systm.h>
451.1Smatt#include <sys/device.h>
461.1Smatt#if defined(PCI_NETBSD_CONFIGURE)
471.1Smatt#include <sys/extent.h>
481.1Smatt#include <sys/malloc.h>
491.1Smatt#endif
501.1Smatt
511.1Smatt#include <dev/pci/pcivar.h>
521.1Smatt#if defined(PCI_NETBSD_CONFIGURE)
531.1Smatt#include <dev/pci/pciconf.h>
541.1Smatt#endif
551.1Smatt
561.1Smatt#include <mips/cache.h>
571.1Smatt#include <mips/cpuregs.h>
581.1Smatt
591.1Smatt#include <mips/bonito/bonitoreg.h>
601.1Smatt#include <evbmips/gdium/gdiumvar.h>
611.1Smatt
621.1Smatt#include "locators.h"
631.1Smatt#include "pci.h"
641.1Smatt
651.1Smattstatic int	mainbus_match(device_t, cfdata_t, void *);
661.1Smattstatic void	mainbus_attach(device_t, device_t, void *);
671.1Smattstatic int	mainbus_print(void *, const char *);
681.1Smatt
691.1SmattCFATTACH_DECL_NEW(mainbus, 0,
701.1Smatt    mainbus_match, mainbus_attach, NULL, NULL);
711.1Smatt
721.1Smatt/* There can be only one. */
731.1Smattint	mainbus_found;
741.1Smatt
751.1Smattconst char * const mainbusdevs[] = {
761.1Smatt	"cpu",
771.1Smatt	"bonito",
781.1Smatt#if 0
791.1Smatt	"i2c",
801.1Smatt	"gpio",
811.1Smatt#endif
821.1Smatt	NULL,
831.1Smatt};
841.1Smatt
851.1Smattstatic int
861.1Smattmainbus_match(device_t parent, cfdata_t match, void *aux)
871.1Smatt{
881.1Smatt	if (mainbus_found)
891.1Smatt		return (0);
901.1Smatt
911.1Smatt	return (1);
921.1Smatt}
931.1Smatt
941.1Smattstatic void
951.1Smattmainbus_attach(device_t parent, device_t self, void *aux)
961.1Smatt{
971.1Smatt	size_t i;
981.1Smatt
991.1Smatt	mainbus_found = 1;
1001.1Smatt	aprint_normal("\n");
1011.1Smatt
1021.1Smatt#if defined(PCI_NETBSD_CONFIGURE)
1031.1Smatt	{
1041.1Smatt		struct extent *ioext, *memext;
1051.1Smatt
1061.1Smatt		ioext = extent_create("pciio",  0x00001000, 0x00003fff,
1071.1Smatt		    M_DEVBUF, NULL, 0, EX_NOWAIT);
1081.1Smatt		memext = extent_create("pcimem", 0, BONITO_PCILO_SIZE,
1091.1Smatt		    M_DEVBUF, NULL, 0, EX_NOWAIT);
1101.1Smatt
1111.1Smatt		pci_configure_bus(&gdium_configuration.gc_pc, ioext, memext,
1121.1Smatt		    NULL, 0, mips_dcache_align);
1131.1Smatt		extent_destroy(ioext);
1141.1Smatt		extent_destroy(memext);
1151.1Smatt	}
1161.1Smatt#endif /* PCI_NETBSD_CONFIGURE */
1171.1Smatt
1181.1Smatt	for (i = 0; i < __arraycount(mainbusdevs); i++) {
1191.1Smatt		struct mainbus_attach_args maa;
1201.1Smatt		maa.maa_name = mainbusdevs[i];
1211.1Smatt		(void) config_found_ia(self, "mainbus", &maa, mainbus_print);
1221.1Smatt	}
1231.1Smatt}
1241.1Smatt
1251.1Smattstatic int
1261.1Smattmainbus_print(void *aux, const char *pnp)
1271.1Smatt{
1281.1Smatt	struct mainbus_attach_args *maa = aux;
1291.1Smatt
1301.1Smatt	if (pnp != 0)
1311.1Smatt		return QUIET;
1321.1Smatt
1331.1Smatt	if (pnp)
1341.1Smatt		aprint_normal("%s at %s", maa->maa_name, pnp);
1351.1Smatt
1361.1Smatt	return UNCONF;
1371.1Smatt}
138