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