mainbus.c revision 1.3
11.3Smatt/*	$NetBSD: mainbus.c,v 1.3 2009/08/11 02:32:38 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.3Smatt__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.3 2009/08/11 02:32:38 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.2Smattstatic bool 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};
831.1Smatt
841.1Smattstatic int
851.1Smattmainbus_match(device_t parent, cfdata_t match, void *aux)
861.1Smatt{
871.1Smatt	if (mainbus_found)
881.1Smatt		return (0);
891.1Smatt
901.1Smatt	return (1);
911.1Smatt}
921.1Smatt
931.1Smattstatic void
941.1Smattmainbus_attach(device_t parent, device_t self, void *aux)
951.1Smatt{
961.1Smatt	size_t i;
971.1Smatt
981.2Smatt	mainbus_found = true;
991.1Smatt	aprint_normal("\n");
1001.1Smatt
1011.1Smatt#if defined(PCI_NETBSD_CONFIGURE)
1021.1Smatt	{
1031.1Smatt		struct extent *ioext, *memext;
1041.1Smatt
1051.1Smatt		ioext = extent_create("pciio",  0x00001000, 0x00003fff,
1061.1Smatt		    M_DEVBUF, NULL, 0, EX_NOWAIT);
1071.1Smatt		memext = extent_create("pcimem", 0, BONITO_PCILO_SIZE,
1081.1Smatt		    M_DEVBUF, NULL, 0, EX_NOWAIT);
1091.1Smatt
1101.1Smatt		pci_configure_bus(&gdium_configuration.gc_pc, ioext, memext,
1111.1Smatt		    NULL, 0, mips_dcache_align);
1121.1Smatt		extent_destroy(ioext);
1131.1Smatt		extent_destroy(memext);
1141.1Smatt	}
1151.1Smatt#endif /* PCI_NETBSD_CONFIGURE */
1161.1Smatt
1171.1Smatt	for (i = 0; i < __arraycount(mainbusdevs); i++) {
1181.1Smatt		struct mainbus_attach_args maa;
1191.1Smatt		maa.maa_name = mainbusdevs[i];
1201.3Smatt		(void) config_found(self, &maa, mainbus_print);
1211.1Smatt	}
1221.1Smatt}
1231.1Smatt
1241.1Smattstatic int
1251.1Smattmainbus_print(void *aux, const char *pnp)
1261.1Smatt{
1271.1Smatt	struct mainbus_attach_args *maa = aux;
1281.1Smatt
1291.1Smatt	if (pnp)
1301.1Smatt		aprint_normal("%s at %s", maa->maa_name, pnp);
1311.1Smatt
1321.1Smatt	return UNCONF;
1331.1Smatt}
134