mainbus.c revision 1.4
11.4Sthorpej/*	$NetBSD: mainbus.c,v 1.4 2020/07/07 03:38:47 thorpej Exp $	*/
21.1Sbouyer
31.1Sbouyer/*
41.1Sbouyer * Copyright 2002 Wasabi Systems, Inc.
51.1Sbouyer * All rights reserved.
61.1Sbouyer *
71.1Sbouyer * Written by Simon Burge for Wasabi Systems, Inc.
81.1Sbouyer *
91.1Sbouyer * Redistribution and use in source and binary forms, with or without
101.1Sbouyer * modification, are permitted provided that the following conditions
111.1Sbouyer * are met:
121.1Sbouyer * 1. Redistributions of source code must retain the above copyright
131.1Sbouyer *    notice, this list of conditions and the following disclaimer.
141.1Sbouyer * 2. Redistributions in binary form must reproduce the above copyright
151.1Sbouyer *    notice, this list of conditions and the following disclaimer in the
161.1Sbouyer *    documentation and/or other materials provided with the distribution.
171.1Sbouyer * 3. All advertising materials mentioning features or use of this software
181.1Sbouyer *    must display the following acknowledgement:
191.1Sbouyer *      This product includes software developed for the NetBSD Project by
201.1Sbouyer *      Wasabi Systems, Inc.
211.1Sbouyer * 4. The name of Wasabi Systems, Inc. may not be used to endorse
221.1Sbouyer *    or promote products derived from this software without specific prior
231.1Sbouyer *    written permission.
241.1Sbouyer *
251.1Sbouyer * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
261.1Sbouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
271.1Sbouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
281.1Sbouyer * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
291.1Sbouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
301.1Sbouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
311.1Sbouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
321.1Sbouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
331.1Sbouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
341.1Sbouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
351.1Sbouyer * POSSIBILITY OF SUCH DAMAGE.
361.1Sbouyer */
371.1Sbouyer
381.1Sbouyer#include <sys/cdefs.h>
391.4Sthorpej__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.4 2020/07/07 03:38:47 thorpej Exp $");
401.1Sbouyer
411.1Sbouyer#include "opt_pci.h"
421.1Sbouyer
431.1Sbouyer#include <sys/param.h>
441.1Sbouyer#include <sys/systm.h>
451.1Sbouyer#include <sys/device.h>
461.1Sbouyer#if defined(PCI_NETBSD_CONFIGURE)
471.1Sbouyer#include <sys/malloc.h>
481.1Sbouyer#endif
491.1Sbouyer
501.1Sbouyer#include <dev/pci/pcivar.h>
511.1Sbouyer#if defined(PCI_NETBSD_CONFIGURE)
521.1Sbouyer#include <dev/pci/pciconf.h>
531.1Sbouyer#endif
541.1Sbouyer
551.1Sbouyer#include <mips/cache.h>
561.1Sbouyer#include <mips/cpuregs.h>
571.1Sbouyer
581.1Sbouyer#include <mips/bonito/bonitoreg.h>
591.1Sbouyer
601.1Sbouyer#include <evbmips/loongson/autoconf.h>
611.2Sskrll#if defined(PCI_NETBSD_CONFIGURE)
621.2Sskrll#include <evbmips/loongson/loongson_bus_defs.h>
631.2Sskrll#endif
641.1Sbouyer
651.1Sbouyer#include "locators.h"
661.1Sbouyer#include "pci.h"
671.1Sbouyer
681.1Sbouyerstatic int	mainbus_match(device_t, cfdata_t, void *);
691.1Sbouyerstatic void	mainbus_attach(device_t, device_t, void *);
701.1Sbouyerstatic int	mainbus_print(void *, const char *);
711.1Sbouyer
721.1SbouyerCFATTACH_DECL_NEW(mainbus, 0,
731.1Sbouyer    mainbus_match, mainbus_attach, NULL, NULL);
741.1Sbouyer
751.1Sbouyer/* There can be only one. */
761.1Sbouyerstatic bool mainbus_found;
771.1Sbouyer
781.1Sbouyerconst char * const mainbusdevs[] = {
791.1Sbouyer	"cpu",
801.1Sbouyer	"bonito",
811.1Sbouyer#if 0
821.1Sbouyer	"i2c",
831.1Sbouyer	"gpio",
841.1Sbouyer#endif
851.1Sbouyer};
861.1Sbouyer
871.4Sthorpej#define	PCI_IO_START	0x00001000
881.4Sthorpej#define	PCI_IO_END	0x00003fff
891.4Sthorpej#define	PCI_IO_SIZE	((PCI_IO_END - PCI_IO_START) + 1)
901.4Sthorpej
911.4Sthorpej#define	PCI_MEM_START	0
921.4Sthorpej#define	PCI_MEM_SIZE	BONITO_PCILO_SIZE
931.4Sthorpej
941.1Sbouyerstatic int
951.1Sbouyermainbus_match(device_t parent, cfdata_t match, void *aux)
961.1Sbouyer{
971.1Sbouyer	if (mainbus_found)
981.1Sbouyer		return (0);
991.1Sbouyer
1001.1Sbouyer	return (1);
1011.1Sbouyer}
1021.1Sbouyer
1031.1Sbouyerstatic void
1041.1Sbouyermainbus_attach(device_t parent, device_t self, void *aux)
1051.1Sbouyer{
1061.1Sbouyer	size_t i;
1071.1Sbouyer
1081.1Sbouyer	mainbus_found = true;
1091.1Sbouyer	aprint_normal("\n");
1101.1Sbouyer
1111.1Sbouyer#if defined(PCI_NETBSD_CONFIGURE)
1121.2Sskrll	struct mips_cache_info * const mci = &mips_cache_info;
1131.4Sthorpej	struct pciconf_resources *pcires = pciconf_resource_init();
1141.4Sthorpej
1151.4Sthorpej	pciconf_resource_add(pcires, PCICONF_RESOURCE_IO,
1161.4Sthorpej	    PCI_IO_START, PCI_IO_SIZE);
1171.4Sthorpej	pciconf_resource_add(pcires, PCICONF_RESOURCE_MEM,
1181.4Sthorpej	    PCI_MEM_START, PCI_MEM_SIZE);
1191.2Sskrll
1201.4Sthorpej	pci_configure_bus(&bonito_pc, pcires, 0, mci->mci_dcache_align);
1211.4Sthorpej	pciconf_resource_fini(pcires);
1221.1Sbouyer#endif /* PCI_NETBSD_CONFIGURE */
1231.1Sbouyer
1241.1Sbouyer	for (i = 0; i < __arraycount(mainbusdevs); i++) {
1251.1Sbouyer		struct mainbus_attach_args maa;
1261.1Sbouyer		maa.maa_name = mainbusdevs[i];
1271.1Sbouyer		(void) config_found(self, &maa, mainbus_print);
1281.1Sbouyer	}
1291.1Sbouyer}
1301.1Sbouyer
1311.1Sbouyerstatic int
1321.1Sbouyermainbus_print(void *aux, const char *pnp)
1331.1Sbouyer{
1341.1Sbouyer	struct mainbus_attach_args *maa = aux;
1351.1Sbouyer
1361.1Sbouyer	if (pnp)
1371.1Sbouyer		aprint_normal("%s at %s", maa->maa_name, pnp);
1381.1Sbouyer
1391.1Sbouyer	return UNCONF;
1401.1Sbouyer}
141