xbox.c revision 1.1 1 /* $NetBSD: xbox.c,v 1.1 1998/04/18 19:00:17 pk Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Paul Kranenburg.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Sbus expansion box.
41 */
42
43 #include <sys/param.h>
44 #include <sys/malloc.h>
45 #include <sys/systm.h>
46 #include <sys/device.h>
47 #include <vm/vm.h>
48
49 #include <machine/bus.h>
50 #include <sparc/dev/sbusvar.h>
51 #include <sparc/dev/xboxvar.h>
52 #include <machine/autoconf.h>
53
54 /*
55 * Xbox registers definitions.
56 *
57 * The xbox device can operate in two mode: "opaque" and "transparent".
58 * In opaque mode, all accesses to the xbox address space are directed
59 * to the xbox itself. In transparent mode, all accesses are mapped to
60 * the SBus cards in the expansion box.
61 *
62 * To access the xbox registers in transparent mode, you must write
63 * to the "write0" register. The layout of this register appears to
64 * be as follows:
65 *
66 * bit 31-24: xbox key (identifies device when you cascade them)
67 * bit 23-12: offset of register to access
68 * bit 11-0: value to write
69 *
70 * For instance, to switch to opaque mode:
71 * (*sc->write0_reg) = (sc->sc_key << 24) | XAC_CTL1_OFFSET;
72 *
73 * (note we're not currently using any of this)
74 */
75 #define WRITE0_OFFSET 0
76
77 #define XAC_ERR_OFFSET 0x2000
78 #define XAC_CTL0_OFFSET 0x10000
79 #define XAC_CTL1_OFFSET 0x11000
80 #define XAC_ELUA_OFFSET 0x12000
81 #define XAC_ELLA_OFFSET 0x13000
82 #define XAC_ELE_OFFSET 0x14000
83
84 #define XBC_ERR_OFFSET 0x42000
85 #define XBC_CTL0_OFFSET 0x50000
86 #define XBC_CTL1_OFFSET 0x51000
87 #define XBC_ELUA_OFFSET 0x52000
88 #define XBC_ELLA_OFFSET 0x53000
89 #define XBC_ELE_OFFSET 0x54000
90
91 #define XBOX_NREG 13
92
93 struct xbox_softc {
94 struct device sc_dev; /* base device */
95 int sc_key; /* this xbox's unique key */
96 };
97
98 /* autoconfiguration driver */
99 int xbox_match __P((struct device *, struct cfdata *, void *));
100 void xbox_attach __P((struct device *, struct device *, void *));
101 int xbox_print __P(( void *, const char *));
102
103 struct cfattach xbox_ca = {
104 sizeof(struct xbox_softc), xbox_match, xbox_attach
105 };
106
107 int
108 xbox_print(args, busname)
109 void *args;
110 const char *busname;
111 {
112 struct xbox_attach_args *xa = args;
113
114 if (busname)
115 printf("%s at %s", xa->xa_name, busname);
116 return (UNCONF);
117 }
118
119 int
120 xbox_match(parent, cf, aux)
121 struct device *parent;
122 struct cfdata *cf;
123 void *aux;
124 {
125 struct sbus_attach_args *sa = aux;
126
127 return (strcmp("SUNW,xbox", sa->sa_name) == 0);
128 }
129
130 /*
131 * Attach an Xbox.
132 */
133 void
134 xbox_attach(parent, self, aux)
135 struct device *parent;
136 struct device *self;
137 void *aux;
138 {
139 struct xbox_softc *sc = (struct xbox_softc *)self;
140 struct sbus_attach_args *sa = aux;
141 struct bootpath *bp = sa->sa_bp;
142 int node = sa->sa_node;
143 struct xbox_attach_args xa;
144 char *cp;
145
146 sc->sc_key = getpropint(node, "write0-key", -1);
147
148 cp = getpropstring(node, "model");
149 printf(": model %s", cp);
150
151 cp = getpropstring(node, "child-present");
152 if (strcmp(cp, "true") != 0) {
153 printf(": no sbus devices\n");
154 return;
155 }
156
157 printf("\n");
158
159 /* Propagate bootpath */
160 if (bp != NULL && strcmp(bp->name, "xbox") == 0)
161 bp++;
162 else
163 bp = NULL;
164
165 /*
166 * Now pretend to be another Sbus.
167 */
168 bzero(&xa, sizeof xa);
169 xa.xa_name = "sbus";
170 xa.xa_node = node;
171 xa.xa_bustag = sa->sa_bustag;
172 xa.xa_dmatag = sa->sa_dmatag;
173 xa.xa_bp = bp;
174
175 (void) config_found(&sc->sc_dev, (void *)&xa, xbox_print);
176 }
177