zbbus.c revision 1.4
11.4Sthorpej/* $NetBSD: zbbus.c,v 1.4 2002/10/01 21:31:35 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.1Ssimonb *    Broadcom Corporation. Neither the "Broadcom Corporation" name nor any
191.1Ssimonb *    trademark or logo of Broadcom Corporation may be used to endorse or
201.1Ssimonb *    promote products derived from this software without the prior written
211.1Ssimonb *    permission of Broadcom Corporation.
221.1Ssimonb *
231.1Ssimonb * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
241.1Ssimonb *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
251.1Ssimonb *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
261.1Ssimonb *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
271.1Ssimonb *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
281.1Ssimonb *    LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
291.1Ssimonb *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
301.1Ssimonb *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
311.1Ssimonb *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
321.1Ssimonb *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
331.1Ssimonb *    OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
341.1Ssimonb */
351.1Ssimonb
361.1Ssimonb#include <sys/param.h>
371.1Ssimonb#include <sys/systm.h>
381.1Ssimonb#include <sys/device.h>
391.1Ssimonb
401.1Ssimonb#include <mips/sibyte/include/zbbusvar.h>
411.1Ssimonb
421.1Ssimonb#include "locators.h"
431.1Ssimonb
441.1Ssimonbstatic int	zbbus_match(struct device *, struct cfdata *, void *);
451.1Ssimonbstatic void	zbbus_attach(struct device *, struct device *, void *);
461.1Ssimonb
471.4SthorpejCFATTACH_DECL(zbbus, sizeof(struct device),
481.4Sthorpej    zbbus_match, zbbus_attach, NULL, NULL)
491.1Ssimonb
501.1Ssimonbstatic int	zbbus_print(void *, const char *);
511.1Ssimonbstatic int	zbbus_submatch(struct device *, struct cfdata *, void *);
521.1Ssimonbstatic const char *zbbus_entity_type_name(enum zbbus_entity_type type);
531.1Ssimonb
541.1Ssimonbstatic int	zbbus_attached;
551.1Ssimonb
561.1Ssimonbstatic const struct zbbus_attach_locs sb1250_zbbus_devs[] = {
571.1Ssimonb	{	0, 	ZBBUS_ENTTYPE_CPU	},
581.1Ssimonb	{	1, 	ZBBUS_ENTTYPE_CPU	},
591.1Ssimonb	{	4, 	ZBBUS_ENTTYPE_SCD	},
601.1Ssimonb	{	2, 	ZBBUS_ENTTYPE_BRZ	},
611.1Ssimonb	{	3, 	ZBBUS_ENTTYPE_OBIO	},
621.1Ssimonb};
631.1Ssimonbstatic const int sb1250_zbbus_dev_count =
641.1Ssimonb    sizeof sb1250_zbbus_devs / sizeof sb1250_zbbus_devs[0];
651.1Ssimonb
661.1Ssimonbstatic int
671.1Ssimonbzbbus_match(struct device *parent, struct cfdata *match, void *aux)
681.1Ssimonb{
691.1Ssimonb
701.1Ssimonb	if (zbbus_attached)
711.1Ssimonb		return (0);
721.1Ssimonb	return 1;
731.1Ssimonb}
741.1Ssimonb
751.1Ssimonbstatic void
761.1Ssimonbzbbus_attach(struct device *parent, struct device *self, void *aux)
771.1Ssimonb{
781.1Ssimonb	struct zbbus_attach_args za;
791.1Ssimonb	int i;
801.1Ssimonb
811.1Ssimonb	printf("\n");
821.1Ssimonb	zbbus_attached = 1;
831.1Ssimonb
841.1Ssimonb	sb1250_icu_init();
851.1Ssimonb
861.1Ssimonb	for (i = 0; i < sb1250_zbbus_dev_count; i++) {
871.1Ssimonb		memset(&za, 0, sizeof za);
881.1Ssimonb		za.za_locs = sb1250_zbbus_devs[i];
891.1Ssimonb		config_found_sm(self, &za, zbbus_print, zbbus_submatch);
901.1Ssimonb	}
911.1Ssimonb
921.1Ssimonb	return;
931.1Ssimonb}
941.1Ssimonb
951.1Ssimonbint
961.1Ssimonbzbbus_print(void *aux, const char *pnp)
971.1Ssimonb{
981.1Ssimonb	struct zbbus_attach_args *zap = aux;
991.1Ssimonb
1001.1Ssimonb	if (pnp)
1011.1Ssimonb		printf("%s at %s",
1021.1Ssimonb	zbbus_entity_type_name(zap->za_locs.za_type), pnp);
1031.1Ssimonb	printf(" busid %d", zap->za_locs.za_busid);
1041.1Ssimonb	return (UNCONF);
1051.1Ssimonb}
1061.1Ssimonb
1071.1Ssimonbstatic int
1081.1Ssimonbzbbus_submatch(struct device *parent, struct cfdata *cf, void *aux)
1091.1Ssimonb{
1101.1Ssimonb	struct zbbus_attach_args *zap = aux;
1111.1Ssimonb
1121.1Ssimonb	if (cf->cf_loc[ZBBUSCF_BUSID] != ZBBUSCF_BUSID_DEFAULT &&
1131.1Ssimonb	    cf->cf_loc[ZBBUSCF_BUSID] != zap->za_locs.za_busid)
1141.1Ssimonb		return (0);
1151.1Ssimonb
1161.2Sthorpej	return (config_match(parent, cf, aux));
1171.1Ssimonb}
1181.1Ssimonb
1191.1Ssimonbstatic const char *
1201.1Ssimonbzbbus_entity_type_name(enum zbbus_entity_type type)
1211.1Ssimonb{
1221.1Ssimonb
1231.1Ssimonb	switch (type) {
1241.1Ssimonb	case ZBBUS_ENTTYPE_CPU:
1251.1Ssimonb		return ("cpu");
1261.1Ssimonb	case ZBBUS_ENTTYPE_SCD:
1271.1Ssimonb		return ("sbscd");
1281.1Ssimonb	case ZBBUS_ENTTYPE_BRZ:
1291.1Ssimonb		return ("sbbrz");
1301.1Ssimonb	case ZBBUS_ENTTYPE_OBIO:
1311.1Ssimonb		return ("sbobio");
1321.1Ssimonb	}
1331.1Ssimonb	panic("zbbus_entity_type_name");
1341.1Ssimonb	return ("panic");
1351.1Ssimonb}
136