zbbus.c revision 1.6
1/* $NetBSD: zbbus.c,v 1.6 2003/01/01 02:06:04 thorpej Exp $ */
2
3/*
4 * Copyright 2000, 2001
5 * Broadcom Corporation. All rights reserved.
6 *
7 * This software is furnished under license and may be used and copied only
8 * in accordance with the following terms and conditions.  Subject to these
9 * conditions, you may download, copy, install, use, modify and distribute
10 * modified or unmodified copies of this software in source and/or binary
11 * form. No title or ownership is transferred hereby.
12 *
13 * 1) Any source code used, modified or distributed must reproduce and
14 *    retain this copyright notice and list of conditions as they appear in
15 *    the source file.
16 *
17 * 2) No right is granted to use any trade name, trademark, or logo of
18 *    Broadcom Corporation. Neither the "Broadcom Corporation" name nor any
19 *    trademark or logo of Broadcom Corporation may be used to endorse or
20 *    promote products derived from this software without the prior written
21 *    permission of Broadcom Corporation.
22 *
23 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
24 *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
25 *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
26 *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
27 *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
28 *    LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31 *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33 *    OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/device.h>
39
40#include <mips/sibyte/include/zbbusvar.h>
41
42#include "locators.h"
43
44static int	zbbus_match(struct device *, struct cfdata *, void *);
45static void	zbbus_attach(struct device *, struct device *, void *);
46
47CFATTACH_DECL(zbbus, sizeof(struct device),
48    zbbus_match, zbbus_attach, NULL, NULL);
49
50static int	zbbus_print(void *, const char *);
51static int	zbbus_submatch(struct device *, struct cfdata *, void *);
52static const char *zbbus_entity_type_name(enum zbbus_entity_type type);
53
54static int	zbbus_attached;
55
56static const struct zbbus_attach_locs sb1250_zbbus_devs[] = {
57	{	0, 	ZBBUS_ENTTYPE_CPU	},
58	{	1, 	ZBBUS_ENTTYPE_CPU	},
59	{	4, 	ZBBUS_ENTTYPE_SCD	},
60	{	2, 	ZBBUS_ENTTYPE_BRZ	},
61	{	3, 	ZBBUS_ENTTYPE_OBIO	},
62};
63static const int sb1250_zbbus_dev_count =
64    sizeof sb1250_zbbus_devs / sizeof sb1250_zbbus_devs[0];
65
66static int
67zbbus_match(struct device *parent, struct cfdata *match, void *aux)
68{
69
70	if (zbbus_attached)
71		return (0);
72	return 1;
73}
74
75static void
76zbbus_attach(struct device *parent, struct device *self, void *aux)
77{
78	struct zbbus_attach_args za;
79	int i;
80
81	printf("\n");
82	zbbus_attached = 1;
83
84	sb1250_icu_init();
85
86	for (i = 0; i < sb1250_zbbus_dev_count; i++) {
87		memset(&za, 0, sizeof za);
88		za.za_locs = sb1250_zbbus_devs[i];
89		config_found_sm(self, &za, zbbus_print, zbbus_submatch);
90	}
91
92	return;
93}
94
95int
96zbbus_print(void *aux, const char *pnp)
97{
98	struct zbbus_attach_args *zap = aux;
99
100	if (pnp)
101		aprint_normal("%s at %s",
102		    zbbus_entity_type_name(zap->za_locs.za_type), pnp);
103	aprint_normal(" busid %d", zap->za_locs.za_busid);
104	return (UNCONF);
105}
106
107static int
108zbbus_submatch(struct device *parent, struct cfdata *cf, void *aux)
109{
110	struct zbbus_attach_args *zap = aux;
111
112	if (cf->cf_loc[ZBBUSCF_BUSID] != ZBBUSCF_BUSID_DEFAULT &&
113	    cf->cf_loc[ZBBUSCF_BUSID] != zap->za_locs.za_busid)
114		return (0);
115
116	return (config_match(parent, cf, aux));
117}
118
119static const char *
120zbbus_entity_type_name(enum zbbus_entity_type type)
121{
122
123	switch (type) {
124	case ZBBUS_ENTTYPE_CPU:
125		return ("cpu");
126	case ZBBUS_ENTTYPE_SCD:
127		return ("sbscd");
128	case ZBBUS_ENTTYPE_BRZ:
129		return ("sbbrz");
130	case ZBBUS_ENTTYPE_OBIO:
131		return ("sbobio");
132	}
133	panic("zbbus_entity_type_name");
134	return ("panic");
135}
136