xref: /netbsd/sys/arch/sbmips/sbmips/zbbus.c (revision c4a72b64)
1 /* $NetBSD: zbbus.c,v 1.5 2002/10/02 15:52:31 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 
44 static int	zbbus_match(struct device *, struct cfdata *, void *);
45 static void	zbbus_attach(struct device *, struct device *, void *);
46 
47 CFATTACH_DECL(zbbus, sizeof(struct device),
48     zbbus_match, zbbus_attach, NULL, NULL);
49 
50 static int	zbbus_print(void *, const char *);
51 static int	zbbus_submatch(struct device *, struct cfdata *, void *);
52 static const char *zbbus_entity_type_name(enum zbbus_entity_type type);
53 
54 static int	zbbus_attached;
55 
56 static 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 };
63 static const int sb1250_zbbus_dev_count =
64     sizeof sb1250_zbbus_devs / sizeof sb1250_zbbus_devs[0];
65 
66 static int
67 zbbus_match(struct device *parent, struct cfdata *match, void *aux)
68 {
69 
70 	if (zbbus_attached)
71 		return (0);
72 	return 1;
73 }
74 
75 static void
76 zbbus_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 
95 int
96 zbbus_print(void *aux, const char *pnp)
97 {
98 	struct zbbus_attach_args *zap = aux;
99 
100 	if (pnp)
101 		printf("%s at %s",
102 	zbbus_entity_type_name(zap->za_locs.za_type), pnp);
103 	printf(" busid %d", zap->za_locs.za_busid);
104 	return (UNCONF);
105 }
106 
107 static int
108 zbbus_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 
119 static const char *
120 zbbus_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