11.4Sthorpej/* $NetBSD: zbbus.c,v 1.4 2021/08/07 16:18:52 thorpej Exp $ */
21.1Smrg
31.1Smrg/*
41.1Smrg * Copyright 2000, 2001
51.1Smrg * Broadcom Corporation. All rights reserved.
61.1Smrg *
71.1Smrg * This software is furnished under license and may be used and copied only
81.1Smrg * in accordance with the following terms and conditions.  Subject to these
91.1Smrg * conditions, you may download, copy, install, use, modify and distribute
101.1Smrg * modified or unmodified copies of this software in source and/or binary
111.1Smrg * form. No title or ownership is transferred hereby.
121.1Smrg *
131.1Smrg * 1) Any source code used, modified or distributed must reproduce and
141.1Smrg *    retain this copyright notice and list of conditions as they appear in
151.1Smrg *    the source file.
161.1Smrg *
171.1Smrg * 2) No right is granted to use any trade name, trademark, or logo of
181.1Smrg *    Broadcom Corporation.  The "Broadcom Corporation" name may not be
191.1Smrg *    used to endorse or promote products derived from this software
201.1Smrg *    without the prior written permission of Broadcom Corporation.
211.1Smrg *
221.1Smrg * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
231.1Smrg *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
241.1Smrg *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
251.1Smrg *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
261.1Smrg *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
271.1Smrg *    LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
281.1Smrg *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
291.1Smrg *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
301.1Smrg *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
311.1Smrg *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
321.1Smrg *    OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
331.1Smrg */
341.1Smrg
351.1Smrg#include <sys/cdefs.h>
361.4Sthorpej__KERNEL_RCSID(0, "$NetBSD: zbbus.c,v 1.4 2021/08/07 16:18:52 thorpej Exp $");
371.1Smrg
381.1Smrg#include <sys/param.h>
391.1Smrg#include <sys/systm.h>
401.1Smrg#include <sys/device.h>
411.1Smrg
421.1Smrg#include <mips/sibyte/include/zbbusvar.h>
431.1Smrg
441.2Smrg#include <evbmips/sbmips/systemsw.h>
451.2Smrg
461.1Smrg#include "locators.h"
471.1Smrg
481.1Smrgstatic int	zbbus_match(device_t, cfdata_t, void *);
491.1Smrgstatic void	zbbus_attach(device_t, device_t, void *);
501.1Smrg
511.1SmrgCFATTACH_DECL_NEW(zbbus, 0,
521.1Smrg    zbbus_match, zbbus_attach, NULL, NULL);
531.1Smrg
541.1Smrgstatic int	zbbus_print(void *, const char *);
551.1Smrgstatic int	zbbus_submatch(device_t, cfdata_t, const int *, void *);
561.1Smrgstatic const char *zbbus_entity_type_name(enum zbbus_entity_type type);
571.1Smrg
581.1Smrgstatic int	zbbus_attached;
591.1Smrg
601.1Smrgstatic const struct zbbus_attach_locs sb1250_zbbus_devs[] = {
611.1Smrg	{	0, 	ZBBUS_ENTTYPE_CPU	},
621.1Smrg	{	1, 	ZBBUS_ENTTYPE_CPU	},
631.1Smrg	{	4, 	ZBBUS_ENTTYPE_SCD	},
641.1Smrg	{	2, 	ZBBUS_ENTTYPE_BRZ	},
651.1Smrg	{	3, 	ZBBUS_ENTTYPE_OBIO	},
661.1Smrg};
671.1Smrgstatic const int sb1250_zbbus_dev_count =
681.1Smrg    sizeof sb1250_zbbus_devs / sizeof sb1250_zbbus_devs[0];
691.1Smrg
701.1Smrgstatic int
711.1Smrgzbbus_match(device_t parent, cfdata_t match, void *aux)
721.1Smrg{
731.1Smrg
741.1Smrg	if (zbbus_attached)
751.1Smrg		return (0);
761.1Smrg	return 1;
771.1Smrg}
781.1Smrg
791.1Smrgstatic void
801.1Smrgzbbus_attach(device_t parent, device_t self, void *aux)
811.1Smrg{
821.1Smrg	struct zbbus_attach_args za;
831.1Smrg	int i;
841.1Smrg
851.1Smrg	printf("\n");
861.1Smrg	zbbus_attached = 1;
871.1Smrg
881.1Smrg	sb1250_icu_init();
891.1Smrg
901.1Smrg	for (i = 0; i < sb1250_zbbus_dev_count; i++) {
911.1Smrg		memset(&za, 0, sizeof za);
921.1Smrg		za.za_locs = sb1250_zbbus_devs[i];
931.3Sthorpej		config_found(self, &za, zbbus_print,
941.4Sthorpej		    CFARGS(.submatch = zbbus_submatch));
951.1Smrg	}
961.1Smrg
971.1Smrg	return;
981.1Smrg}
991.1Smrg
1001.1Smrgint
1011.1Smrgzbbus_print(void *aux, const char *pnp)
1021.1Smrg{
1031.1Smrg	struct zbbus_attach_args *zap = aux;
1041.1Smrg
1051.1Smrg	if (pnp)
1061.1Smrg		aprint_normal("%s at %s",
1071.1Smrg		    zbbus_entity_type_name(zap->za_locs.za_type), pnp);
1081.1Smrg	aprint_normal(" busid %d", zap->za_locs.za_busid);
1091.1Smrg	return (UNCONF);
1101.1Smrg}
1111.1Smrg
1121.1Smrgstatic int
1131.1Smrgzbbus_submatch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
1141.1Smrg{
1151.1Smrg	struct zbbus_attach_args *zap = aux;
1161.1Smrg
1171.1Smrg	if (cf->cf_loc[ZBBUSCF_BUSID] != ZBBUSCF_BUSID_DEFAULT &&
1181.1Smrg	    cf->cf_loc[ZBBUSCF_BUSID] != zap->za_locs.za_busid)
1191.1Smrg		return (0);
1201.1Smrg
1211.1Smrg	return (config_match(parent, cf, aux));
1221.1Smrg}
1231.1Smrg
1241.1Smrgstatic const char *
1251.1Smrgzbbus_entity_type_name(enum zbbus_entity_type type)
1261.1Smrg{
1271.1Smrg
1281.1Smrg	switch (type) {
1291.1Smrg	case ZBBUS_ENTTYPE_CPU:
1301.1Smrg		return ("cpu");
1311.1Smrg	case ZBBUS_ENTTYPE_SCD:
1321.1Smrg		return ("sbscd");
1331.1Smrg	case ZBBUS_ENTTYPE_BRZ:
1341.1Smrg		return ("sbbrz");
1351.1Smrg	case ZBBUS_ENTTYPE_OBIO:
1361.1Smrg		return ("sbobio");
1371.1Smrg	}
1381.1Smrg	panic("zbbus_entity_type_name");
1391.1Smrg	return ("panic");
1401.1Smrg}
141