1 /* $NetBSD: xbox.c,v 1.26 2022/09/25 18:03:04 thorpej 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 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * Sbus expansion box.
34 */
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: xbox.c,v 1.26 2022/09/25 18:03:04 thorpej Exp $");
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
42
43 #include <sys/bus.h>
44 #include <dev/sbus/sbusvar.h>
45 #include <dev/sbus/xboxvar.h>
46 #include <machine/autoconf.h>
47
48 /*
49 * Xbox registers definitions.
50 *
51 * The xbox device can operate in two mode: "opaque" and "transparent".
52 * In opaque mode, all accesses to the xbox address space are directed
53 * to the xbox itself. In transparent mode, all accesses are mapped to
54 * the SBus cards in the expansion box.
55 *
56 * To access the xbox registers in transparent mode, you must write
57 * to the "write0" register. The layout of this register appears to
58 * be as follows:
59 *
60 * bit 31-24: xbox key (identifies device when you cascade them)
61 * bit 23-12: offset of register to access
62 * bit 11-0: value to write
63 *
64 * For instance, to switch to opaque mode:
65 * (*sc->write0_reg) = (sc->sc_key << 24) | XAC_CTL1_OFFSET;
66 *
67 * (note we're not currently using any of this)
68 */
69 #define WRITE0_OFFSET 0
70
71 #define XAC_ERR_OFFSET 0x2000
72 #define XAC_CTL0_OFFSET 0x10000
73 #define XAC_CTL1_OFFSET 0x11000
74 #define XAC_ELUA_OFFSET 0x12000
75 #define XAC_ELLA_OFFSET 0x13000
76 #define XAC_ELE_OFFSET 0x14000
77
78 #define XBC_ERR_OFFSET 0x42000
79 #define XBC_CTL0_OFFSET 0x50000
80 #define XBC_CTL1_OFFSET 0x51000
81 #define XBC_ELUA_OFFSET 0x52000
82 #define XBC_ELLA_OFFSET 0x53000
83 #define XBC_ELE_OFFSET 0x54000
84
85 #define XBOX_NREG 13
86
87 struct xbox_softc {
88 int sc_key; /* this xbox's unique key */
89 };
90
91 /* autoconfiguration driver */
92 int xbox_match(device_t, cfdata_t, void *);
93 void xbox_attach(device_t, device_t, void *);
94 int xbox_print(void *, const char *);
95
96 CFATTACH_DECL_NEW(xbox, sizeof(struct xbox_softc),
97 xbox_match, xbox_attach, NULL, NULL);
98
99 int
xbox_print(void * args,const char * busname)100 xbox_print(void *args, const char *busname)
101 {
102 struct xbox_attach_args *xa = args;
103
104 if (busname)
105 aprint_normal("%s at %s", xa->xa_name, busname);
106 return (UNCONF);
107 }
108
109 int
xbox_match(device_t parent,cfdata_t cf,void * aux)110 xbox_match(device_t parent, cfdata_t cf, void *aux)
111 {
112 struct sbus_attach_args *sa = aux;
113
114 return (strcmp("SUNW,xbox", sa->sa_name) == 0);
115 }
116
117 /*
118 * Attach an Xbox.
119 */
120 void
xbox_attach(device_t parent,device_t self,void * aux)121 xbox_attach(device_t parent, device_t self, void *aux)
122 {
123 struct xbox_softc *sc = device_private(self);
124 struct sbus_attach_args *sa = aux;
125 int node = sa->sa_node;
126 struct xbox_attach_args xa;
127 char *cp;
128
129 sc->sc_key = prom_getpropint(node, "write0-key", -1);
130
131 cp = prom_getpropstring(node, "model");
132 printf(": model %s", cp);
133
134 cp = prom_getpropstring(node, "child-present");
135 if (strcmp(cp, "true") != 0) {
136 printf(": no sbus devices\n");
137 return;
138 }
139
140 printf("\n");
141
142 /*
143 * Now pretend to be another Sbus.
144 */
145 memset(&xa, 0, sizeof xa);
146 xa.xa_name = "sbus";
147 xa.xa_node = node;
148 xa.xa_bustag = sa->sa_bustag;
149 xa.xa_dmatag = sa->sa_dmatag;
150
151 (void) config_found(self, (void *)&xa, xbox_print,
152 CFARGS(.devhandle = device_handle(self)));
153 }
154