zbbus.c revision 1.7
11.7Scgd/* $NetBSD: zbbus.c,v 1.7 2003/02/07 17:46:13 cgd 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.1Ssimonb
351.1Ssimonb#include <sys/param.h>
361.1Ssimonb#include <sys/systm.h>
371.1Ssimonb#include <sys/device.h>
381.1Ssimonb
391.1Ssimonb#include <mips/sibyte/include/zbbusvar.h>
401.1Ssimonb
411.1Ssimonb#include "locators.h"
421.1Ssimonb
431.1Ssimonbstatic int	zbbus_match(struct device *, struct cfdata *, void *);
441.1Ssimonbstatic void	zbbus_attach(struct device *, struct device *, void *);
451.1Ssimonb
461.4SthorpejCFATTACH_DECL(zbbus, sizeof(struct device),
471.5Sthorpej    zbbus_match, zbbus_attach, NULL, NULL);
481.1Ssimonb
491.1Ssimonbstatic int	zbbus_print(void *, const char *);
501.1Ssimonbstatic int	zbbus_submatch(struct device *, struct cfdata *, void *);
511.1Ssimonbstatic const char *zbbus_entity_type_name(enum zbbus_entity_type type);
521.1Ssimonb
531.1Ssimonbstatic int	zbbus_attached;
541.1Ssimonb
551.1Ssimonbstatic const struct zbbus_attach_locs sb1250_zbbus_devs[] = {
561.1Ssimonb	{	0, 	ZBBUS_ENTTYPE_CPU	},
571.1Ssimonb	{	1, 	ZBBUS_ENTTYPE_CPU	},
581.1Ssimonb	{	4, 	ZBBUS_ENTTYPE_SCD	},
591.1Ssimonb	{	2, 	ZBBUS_ENTTYPE_BRZ	},
601.1Ssimonb	{	3, 	ZBBUS_ENTTYPE_OBIO	},
611.1Ssimonb};
621.1Ssimonbstatic const int sb1250_zbbus_dev_count =
631.1Ssimonb    sizeof sb1250_zbbus_devs / sizeof sb1250_zbbus_devs[0];
641.1Ssimonb
651.1Ssimonbstatic int
661.1Ssimonbzbbus_match(struct device *parent, struct cfdata *match, void *aux)
671.1Ssimonb{
681.1Ssimonb
691.1Ssimonb	if (zbbus_attached)
701.1Ssimonb		return (0);
711.1Ssimonb	return 1;
721.1Ssimonb}
731.1Ssimonb
741.1Ssimonbstatic void
751.1Ssimonbzbbus_attach(struct device *parent, struct device *self, void *aux)
761.1Ssimonb{
771.1Ssimonb	struct zbbus_attach_args za;
781.1Ssimonb	int i;
791.1Ssimonb
801.1Ssimonb	printf("\n");
811.1Ssimonb	zbbus_attached = 1;
821.1Ssimonb
831.1Ssimonb	sb1250_icu_init();
841.1Ssimonb
851.1Ssimonb	for (i = 0; i < sb1250_zbbus_dev_count; i++) {
861.1Ssimonb		memset(&za, 0, sizeof za);
871.1Ssimonb		za.za_locs = sb1250_zbbus_devs[i];
881.1Ssimonb		config_found_sm(self, &za, zbbus_print, zbbus_submatch);
891.1Ssimonb	}
901.1Ssimonb
911.1Ssimonb	return;
921.1Ssimonb}
931.1Ssimonb
941.1Ssimonbint
951.1Ssimonbzbbus_print(void *aux, const char *pnp)
961.1Ssimonb{
971.1Ssimonb	struct zbbus_attach_args *zap = aux;
981.1Ssimonb
991.1Ssimonb	if (pnp)
1001.6Sthorpej		aprint_normal("%s at %s",
1011.6Sthorpej		    zbbus_entity_type_name(zap->za_locs.za_type), pnp);
1021.6Sthorpej	aprint_normal(" busid %d", zap->za_locs.za_busid);
1031.1Ssimonb	return (UNCONF);
1041.1Ssimonb}
1051.1Ssimonb
1061.1Ssimonbstatic int
1071.1Ssimonbzbbus_submatch(struct device *parent, struct cfdata *cf, void *aux)
1081.1Ssimonb{
1091.1Ssimonb	struct zbbus_attach_args *zap = aux;
1101.1Ssimonb
1111.1Ssimonb	if (cf->cf_loc[ZBBUSCF_BUSID] != ZBBUSCF_BUSID_DEFAULT &&
1121.1Ssimonb	    cf->cf_loc[ZBBUSCF_BUSID] != zap->za_locs.za_busid)
1131.1Ssimonb		return (0);
1141.1Ssimonb
1151.2Sthorpej	return (config_match(parent, cf, aux));
1161.1Ssimonb}
1171.1Ssimonb
1181.1Ssimonbstatic const char *
1191.1Ssimonbzbbus_entity_type_name(enum zbbus_entity_type type)
1201.1Ssimonb{
1211.1Ssimonb
1221.1Ssimonb	switch (type) {
1231.1Ssimonb	case ZBBUS_ENTTYPE_CPU:
1241.1Ssimonb		return ("cpu");
1251.1Ssimonb	case ZBBUS_ENTTYPE_SCD:
1261.1Ssimonb		return ("sbscd");
1271.1Ssimonb	case ZBBUS_ENTTYPE_BRZ:
1281.1Ssimonb		return ("sbbrz");
1291.1Ssimonb	case ZBBUS_ENTTYPE_OBIO:
1301.1Ssimonb		return ("sbobio");
1311.1Ssimonb	}
1321.1Ssimonb	panic("zbbus_entity_type_name");
1331.1Ssimonb	return ("panic");
1341.1Ssimonb}
135