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