p5bus.c revision 1.3.4.2 1 1.3.4.2 mrg /* $NetBSD: p5bus.c,v 1.3.4.2 2012/02/18 07:31:18 mrg Exp $ */
2 1.3.4.2 mrg
3 1.3.4.2 mrg /*-
4 1.3.4.2 mrg * Copyright (c) 2011, 2012 The NetBSD Foundation, Inc.
5 1.3.4.2 mrg * All rights reserved.
6 1.3.4.2 mrg *
7 1.3.4.2 mrg * This code is derived from software contributed to The NetBSD Foundation
8 1.3.4.2 mrg * by Radoslaw Kujawa.
9 1.3.4.2 mrg *
10 1.3.4.2 mrg * Redistribution and use in source and binary forms, with or without
11 1.3.4.2 mrg * modification, are permitted provided that the following conditions
12 1.3.4.2 mrg * are met:
13 1.3.4.2 mrg * 1. Redistributions of source code must retain the above copyright
14 1.3.4.2 mrg * notice, this list of conditions and the following disclaimer.
15 1.3.4.2 mrg * 2. Redistributions in binary form must reproduce the above copyright
16 1.3.4.2 mrg * notice, this list of conditions and the following disclaimer in the
17 1.3.4.2 mrg * documentation and/or other materials provided with the distribution.
18 1.3.4.2 mrg *
19 1.3.4.2 mrg * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.3.4.2 mrg * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.3.4.2 mrg * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.3.4.2 mrg * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.3.4.2 mrg * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.3.4.2 mrg * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.3.4.2 mrg * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.3.4.2 mrg * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.3.4.2 mrg * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.3.4.2 mrg * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.3.4.2 mrg * POSSIBILITY OF SUCH DAMAGE.
30 1.3.4.2 mrg */
31 1.3.4.2 mrg
32 1.3.4.2 mrg /* Driver for internal BlizzardPPC, CyberStorm Mk-III/PPC bus. */
33 1.3.4.2 mrg
34 1.3.4.2 mrg #include <sys/cdefs.h>
35 1.3.4.2 mrg
36 1.3.4.2 mrg #include <sys/systm.h>
37 1.3.4.2 mrg #include <sys/types.h>
38 1.3.4.2 mrg #include <sys/device.h>
39 1.3.4.2 mrg #include <sys/kmem.h>
40 1.3.4.2 mrg
41 1.3.4.2 mrg #include <amiga/dev/zbusvar.h>
42 1.3.4.2 mrg #include <amiga/dev/p5busvar.h>
43 1.3.4.2 mrg
44 1.3.4.2 mrg #define ZORRO_MANID_P5 8512
45 1.3.4.2 mrg #define ZORRO_PRODID_CSPPC 100
46 1.3.4.2 mrg #define ZORRO_PRODID_BPPC 110
47 1.3.4.2 mrg
48 1.3.4.2 mrg #define P5_ROM_OFF 0xF00010
49 1.3.4.2 mrg #define P5_SN_LEN 7
50 1.3.4.2 mrg
51 1.3.4.2 mrg static int p5bus_match(struct device *pdp, struct cfdata *cfp, void *auxp);
52 1.3.4.2 mrg static void p5bus_attach(device_t parent, device_t self, void *aux);
53 1.3.4.2 mrg static char* p5bus_cardsn(void);
54 1.3.4.2 mrg static int p5bus_print(void *aux, const char *str);
55 1.3.4.2 mrg static void p5bus_callback(device_t self);
56 1.3.4.2 mrg
57 1.3.4.2 mrg struct p5bus_softc {
58 1.3.4.2 mrg device_t sc_dev;
59 1.3.4.2 mrg uint8_t sc_cardtype;
60 1.3.4.2 mrg uint8_t sc_has_scsi;
61 1.3.4.2 mrg #define P5BUS_SCSI_NONE 0
62 1.3.4.2 mrg #define P5BUS_SCSI_710 1 /* NCR 53C710 */
63 1.3.4.2 mrg #define P5BUS_SCSI_770 2 /* NCR 53C770 */
64 1.3.4.2 mrg uint8_t sc_has_ppc;
65 1.3.4.2 mrg #define P5BUS_PPC_NONE 0 /* CS Mk-III only */
66 1.3.4.2 mrg #define P5BUS_PPC_OK 1 /* has working PPC CPU */
67 1.3.4.2 mrg };
68 1.3.4.2 mrg
69 1.3.4.2 mrg CFATTACH_DECL_NEW(p5bus, sizeof(struct p5bus_softc),
70 1.3.4.2 mrg p5bus_match, p5bus_attach, NULL, NULL);
71 1.3.4.2 mrg
72 1.3.4.2 mrg static int
73 1.3.4.2 mrg p5bus_match(struct device *pdp, struct cfdata *cfp, void *auxp)
74 1.3.4.2 mrg {
75 1.3.4.2 mrg struct zbus_args *zap;
76 1.3.4.2 mrg
77 1.3.4.2 mrg zap = auxp;
78 1.3.4.2 mrg
79 1.3.4.2 mrg if (zap->manid != ZORRO_MANID_P5)
80 1.3.4.2 mrg return 0;
81 1.3.4.2 mrg
82 1.3.4.2 mrg
83 1.3.4.2 mrg if ((zap->prodid != ZORRO_PRODID_BPPC) &&
84 1.3.4.2 mrg (zap->prodid != ZORRO_PRODID_CSPPC))
85 1.3.4.2 mrg return 0;
86 1.3.4.2 mrg
87 1.3.4.2 mrg return 1;
88 1.3.4.2 mrg }
89 1.3.4.2 mrg
90 1.3.4.2 mrg static void
91 1.3.4.2 mrg p5bus_attach(device_t parent, device_t self, void *aux)
92 1.3.4.2 mrg {
93 1.3.4.2 mrg struct p5bus_softc *sc;
94 1.3.4.2 mrg struct zbus_args *zap;
95 1.3.4.2 mrg struct p5bus_attach_args p5baa;
96 1.3.4.2 mrg char *sn;
97 1.3.4.2 mrg
98 1.3.4.2 mrg zap = aux;
99 1.3.4.2 mrg sc = device_private(self);
100 1.3.4.2 mrg sc->sc_dev = self;
101 1.3.4.2 mrg
102 1.3.4.2 mrg sn = p5bus_cardsn();
103 1.3.4.2 mrg
104 1.3.4.2 mrg aprint_normal(": Phase5 PowerUP on-board bus\n");
105 1.3.4.2 mrg
106 1.3.4.2 mrg /* "Detect" what devices are present and attach the right drivers. */
107 1.3.4.2 mrg
108 1.3.4.2 mrg if (zap->prodid == ZORRO_PRODID_CSPPC) {
109 1.3.4.2 mrg
110 1.3.4.2 mrg if (sn[0] == 'F') {
111 1.3.4.2 mrg aprint_normal_dev(sc->sc_dev,
112 1.3.4.2 mrg "CyberStorm Mk-III (sn %s)\n", sn);
113 1.3.4.2 mrg sc->sc_has_ppc = P5BUS_PPC_NONE;
114 1.3.4.2 mrg } else {
115 1.3.4.2 mrg aprint_normal_dev(sc->sc_dev,
116 1.3.4.2 mrg "CyberStorm PPC 604e (sn %s)\n", sn);
117 1.3.4.2 mrg sc->sc_has_ppc = P5BUS_PPC_OK;
118 1.3.4.2 mrg }
119 1.3.4.2 mrg
120 1.3.4.2 mrg sc->sc_cardtype = P5_CARDTYPE_CS;
121 1.3.4.2 mrg sc->sc_has_scsi = P5BUS_SCSI_770;
122 1.3.4.2 mrg
123 1.3.4.2 mrg } else if (zap->prodid == ZORRO_PRODID_BPPC) {
124 1.3.4.2 mrg
125 1.3.4.2 mrg if (sn[0] != 'I') { /* only "+" model has SCSI */
126 1.3.4.2 mrg aprint_normal_dev(sc->sc_dev,
127 1.3.4.2 mrg "BlizzardPPC 603e (sn %s)\n", sn);
128 1.3.4.2 mrg sc->sc_has_scsi = P5BUS_SCSI_NONE;
129 1.3.4.2 mrg } else {
130 1.3.4.2 mrg aprint_normal_dev(sc->sc_dev,
131 1.3.4.2 mrg "BlizzardPPC 603e+ (sn %s)\n", sn);
132 1.3.4.2 mrg sc->sc_has_scsi = P5BUS_SCSI_710;
133 1.3.4.2 mrg }
134 1.3.4.2 mrg
135 1.3.4.2 mrg sc->sc_cardtype = P5_CARDTYPE_BPPC;
136 1.3.4.2 mrg sc->sc_has_ppc = P5BUS_PPC_OK;
137 1.3.4.2 mrg
138 1.3.4.2 mrg }
139 1.3.4.2 mrg
140 1.3.4.2 mrg p5baa.p5baa_cardtype = sc->sc_cardtype;
141 1.3.4.2 mrg
142 1.3.4.2 mrg /* Attach the SCSI host adapters. */
143 1.3.4.2 mrg switch (sc->sc_has_scsi) {
144 1.3.4.2 mrg case P5BUS_SCSI_710:
145 1.3.4.2 mrg strcpy(p5baa.p5baa_name, "bppcsc");
146 1.3.4.2 mrg config_found_ia(sc->sc_dev, "p5bus", &p5baa, p5bus_print);
147 1.3.4.2 mrg break;
148 1.3.4.2 mrg case P5BUS_SCSI_770:
149 1.3.4.2 mrg strcpy(p5baa.p5baa_name, "cbiiisc");
150 1.3.4.2 mrg config_found_ia(sc->sc_dev, "p5bus", &p5baa, p5bus_print);
151 1.3.4.2 mrg break;
152 1.3.4.2 mrg default:
153 1.3.4.2 mrg break;
154 1.3.4.2 mrg }
155 1.3.4.2 mrg
156 1.3.4.2 mrg /*
157 1.3.4.2 mrg * We need to wait for possible p5membar attachments. Defer the rest
158 1.3.4.2 mrg * until parent (zbus) is completely configured.
159 1.3.4.2 mrg */
160 1.3.4.2 mrg config_defer(self, p5bus_callback);
161 1.3.4.2 mrg
162 1.3.4.2 mrg }
163 1.3.4.2 mrg
164 1.3.4.2 mrg /* Continue the attachment. */
165 1.3.4.2 mrg static void
166 1.3.4.2 mrg p5bus_callback(device_t self) {
167 1.3.4.2 mrg
168 1.3.4.2 mrg struct p5bus_attach_args p5baa;
169 1.3.4.2 mrg struct p5bus_softc *sc;
170 1.3.4.2 mrg
171 1.3.4.2 mrg sc = device_private(self);
172 1.3.4.2 mrg p5baa.p5baa_cardtype = sc->sc_cardtype;
173 1.3.4.2 mrg
174 1.3.4.2 mrg /* p5pb is always found, probe is inside of p5pb driver */
175 1.3.4.2 mrg strcpy(p5baa.p5baa_name, "p5pb");
176 1.3.4.2 mrg config_found_ia(sc->sc_dev, "p5bus", &p5baa, p5bus_print);
177 1.3.4.2 mrg }
178 1.3.4.2 mrg
179 1.3.4.2 mrg /* Get serial number of the card. */
180 1.3.4.2 mrg static char *
181 1.3.4.2 mrg p5bus_cardsn(void)
182 1.3.4.2 mrg {
183 1.3.4.2 mrg char *snr, *sn;
184 1.3.4.2 mrg
185 1.3.4.2 mrg sn = kmem_zalloc(P5_SN_LEN + 1, KM_SLEEP);
186 1.3.4.2 mrg snr = (char *)__UNVOLATILE(ztwomap(P5_ROM_OFF));
187 1.3.4.2 mrg
188 1.3.4.2 mrg memcpy(sn, snr, P5_SN_LEN);
189 1.3.4.2 mrg return sn;
190 1.3.4.2 mrg }
191 1.3.4.2 mrg
192 1.3.4.2 mrg static int
193 1.3.4.2 mrg p5bus_print(void *aux, const char *str)
194 1.3.4.2 mrg {
195 1.3.4.2 mrg if (str == NULL)
196 1.3.4.2 mrg return 0;
197 1.3.4.2 mrg
198 1.3.4.2 mrg printf("%s ", str);
199 1.3.4.2 mrg
200 1.3.4.2 mrg return 0;
201 1.3.4.2 mrg }
202 1.3.4.2 mrg
203