mainbus.c revision 1.7
11.7Sthorpej/*	$NetBSD: mainbus.c,v 1.7 2023/12/20 14:12:25 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.7Sthorpej__KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.7 2023/12/20 14:12:25 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
471.1Sbouyer#include <dev/pci/pcivar.h>
481.1Sbouyer#if defined(PCI_NETBSD_CONFIGURE)
491.1Sbouyer#include <dev/pci/pciconf.h>
501.1Sbouyer#endif
511.1Sbouyer
521.1Sbouyer#include <mips/cache.h>
531.1Sbouyer#include <mips/cpuregs.h>
541.1Sbouyer
551.1Sbouyer#include <mips/bonito/bonitoreg.h>
561.1Sbouyer
571.1Sbouyer#include <evbmips/loongson/autoconf.h>
581.2Sskrll#if defined(PCI_NETBSD_CONFIGURE)
591.2Sskrll#include <evbmips/loongson/loongson_bus_defs.h>
601.2Sskrll#endif
611.1Sbouyer
621.1Sbouyer#include "locators.h"
631.1Sbouyer#include "pci.h"
641.1Sbouyer
651.1Sbouyerstatic int	mainbus_match(device_t, cfdata_t, void *);
661.1Sbouyerstatic void	mainbus_attach(device_t, device_t, void *);
671.1Sbouyerstatic int	mainbus_print(void *, const char *);
681.1Sbouyer
691.1SbouyerCFATTACH_DECL_NEW(mainbus, 0,
701.1Sbouyer    mainbus_match, mainbus_attach, NULL, NULL);
711.1Sbouyer
721.1Sbouyer/* There can be only one. */
731.1Sbouyerstatic bool mainbus_found;
741.1Sbouyer
751.1Sbouyerconst char * const mainbusdevs[] = {
761.1Sbouyer	"cpu",
771.1Sbouyer	"bonito",
781.1Sbouyer#if 0
791.1Sbouyer	"i2c",
801.1Sbouyer	"gpio",
811.1Sbouyer#endif
821.1Sbouyer};
831.1Sbouyer
841.4Sthorpej#define	PCI_IO_START	0x00001000
851.4Sthorpej#define	PCI_IO_END	0x00003fff
861.4Sthorpej#define	PCI_IO_SIZE	((PCI_IO_END - PCI_IO_START) + 1)
871.4Sthorpej
881.4Sthorpej#define	PCI_MEM_START	0
891.4Sthorpej#define	PCI_MEM_SIZE	BONITO_PCILO_SIZE
901.4Sthorpej
911.1Sbouyerstatic int
921.1Sbouyermainbus_match(device_t parent, cfdata_t match, void *aux)
931.1Sbouyer{
941.1Sbouyer	if (mainbus_found)
951.1Sbouyer		return (0);
961.1Sbouyer
971.1Sbouyer	return (1);
981.1Sbouyer}
991.1Sbouyer
1001.1Sbouyerstatic void
1011.1Sbouyermainbus_attach(device_t parent, device_t self, void *aux)
1021.1Sbouyer{
1031.1Sbouyer	size_t i;
1041.1Sbouyer
1051.1Sbouyer	mainbus_found = true;
1061.1Sbouyer	aprint_normal("\n");
1071.1Sbouyer
1081.1Sbouyer#if defined(PCI_NETBSD_CONFIGURE)
1091.2Sskrll	struct mips_cache_info * const mci = &mips_cache_info;
1101.4Sthorpej	struct pciconf_resources *pcires = pciconf_resource_init();
1111.4Sthorpej
1121.4Sthorpej	pciconf_resource_add(pcires, PCICONF_RESOURCE_IO,
1131.4Sthorpej	    PCI_IO_START, PCI_IO_SIZE);
1141.4Sthorpej	pciconf_resource_add(pcires, PCICONF_RESOURCE_MEM,
1151.4Sthorpej	    PCI_MEM_START, PCI_MEM_SIZE);
1161.2Sskrll
1171.4Sthorpej	pci_configure_bus(&bonito_pc, pcires, 0, mci->mci_dcache_align);
1181.4Sthorpej	pciconf_resource_fini(pcires);
1191.1Sbouyer#endif /* PCI_NETBSD_CONFIGURE */
1201.1Sbouyer
1211.1Sbouyer	for (i = 0; i < __arraycount(mainbusdevs); i++) {
1221.1Sbouyer		struct mainbus_attach_args maa;
1231.1Sbouyer		maa.maa_name = mainbusdevs[i];
1241.6Sthorpej		(void) config_found(self, &maa, mainbus_print, CFARGS_NONE);
1251.1Sbouyer	}
1261.1Sbouyer}
1271.1Sbouyer
1281.1Sbouyerstatic int
1291.1Sbouyermainbus_print(void *aux, const char *pnp)
1301.1Sbouyer{
1311.1Sbouyer	struct mainbus_attach_args *maa = aux;
1321.1Sbouyer
1331.1Sbouyer	if (pnp)
1341.1Sbouyer		aprint_normal("%s at %s", maa->maa_name, pnp);
1351.1Sbouyer
1361.1Sbouyer	return UNCONF;
1371.1Sbouyer}
138