xbox.c revision 1.6 1 /* $NetBSD: xbox.c,v 1.6 2001/11/13 06:58:18 lukem 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/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: xbox.c,v 1.6 2001/11/13 06:58:18 lukem Exp $");
45
46 #include <sys/param.h>
47 #include <sys/malloc.h>
48 #include <sys/systm.h>
49 #include <sys/device.h>
50
51 #include <machine/bus.h>
52 #include <dev/sbus/sbusvar.h>
53 #include <dev/sbus/xboxvar.h>
54 #include <machine/autoconf.h>
55
56 /*
57 * Xbox registers definitions.
58 *
59 * The xbox device can operate in two mode: "opaque" and "transparent".
60 * In opaque mode, all accesses to the xbox address space are directed
61 * to the xbox itself. In transparent mode, all accesses are mapped to
62 * the SBus cards in the expansion box.
63 *
64 * To access the xbox registers in transparent mode, you must write
65 * to the "write0" register. The layout of this register appears to
66 * be as follows:
67 *
68 * bit 31-24: xbox key (identifies device when you cascade them)
69 * bit 23-12: offset of register to access
70 * bit 11-0: value to write
71 *
72 * For instance, to switch to opaque mode:
73 * (*sc->write0_reg) = (sc->sc_key << 24) | XAC_CTL1_OFFSET;
74 *
75 * (note we're not currently using any of this)
76 */
77 #define WRITE0_OFFSET 0
78
79 #define XAC_ERR_OFFSET 0x2000
80 #define XAC_CTL0_OFFSET 0x10000
81 #define XAC_CTL1_OFFSET 0x11000
82 #define XAC_ELUA_OFFSET 0x12000
83 #define XAC_ELLA_OFFSET 0x13000
84 #define XAC_ELE_OFFSET 0x14000
85
86 #define XBC_ERR_OFFSET 0x42000
87 #define XBC_CTL0_OFFSET 0x50000
88 #define XBC_CTL1_OFFSET 0x51000
89 #define XBC_ELUA_OFFSET 0x52000
90 #define XBC_ELLA_OFFSET 0x53000
91 #define XBC_ELE_OFFSET 0x54000
92
93 #define XBOX_NREG 13
94
95 struct xbox_softc {
96 struct device sc_dev; /* base device */
97 int sc_key; /* this xbox's unique key */
98 };
99
100 /* autoconfiguration driver */
101 int xbox_match __P((struct device *, struct cfdata *, void *));
102 void xbox_attach __P((struct device *, struct device *, void *));
103 int xbox_print __P(( void *, const char *));
104
105 struct cfattach xbox_ca = {
106 sizeof(struct xbox_softc), xbox_match, xbox_attach
107 };
108
109 int
110 xbox_print(args, busname)
111 void *args;
112 const char *busname;
113 {
114 struct xbox_attach_args *xa = args;
115
116 if (busname)
117 printf("%s at %s", xa->xa_name, busname);
118 return (UNCONF);
119 }
120
121 int
122 xbox_match(parent, cf, aux)
123 struct device *parent;
124 struct cfdata *cf;
125 void *aux;
126 {
127 struct sbus_attach_args *sa = aux;
128
129 return (strcmp("SUNW,xbox", sa->sa_name) == 0);
130 }
131
132 /*
133 * Attach an Xbox.
134 */
135 void
136 xbox_attach(parent, self, aux)
137 struct device *parent;
138 struct device *self;
139 void *aux;
140 {
141 struct xbox_softc *sc = (struct xbox_softc *)self;
142 struct sbus_attach_args *sa = aux;
143 int node = sa->sa_node;
144 struct xbox_attach_args xa;
145 char *cp;
146
147 sc->sc_key = PROM_getpropint(node, "write0-key", -1);
148
149 cp = PROM_getpropstring(node, "model");
150 printf(": model %s", cp);
151
152 cp = PROM_getpropstring(node, "child-present");
153 if (strcmp(cp, "true") != 0) {
154 printf(": no sbus devices\n");
155 return;
156 }
157
158 printf("\n");
159
160 /*
161 * Now pretend to be another Sbus.
162 */
163 bzero(&xa, sizeof xa);
164 xa.xa_name = "sbus";
165 xa.xa_node = node;
166 xa.xa_bustag = sa->sa_bustag;
167 xa.xa_dmatag = sa->sa_dmatag;
168
169 (void) config_found(&sc->sc_dev, (void *)&xa, xbox_print);
170 }
171