prompatch.c revision 1.10 1 /* $NetBSD: prompatch.c,v 1.10 2005/08/14 16:05:56 macallan Exp $ */
2
3 /*
4 * Copyright (c) 2001 Valeriy E. Ushakov
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include <sys/param.h>
31 #include <lib/libsa/stand.h>
32 #include <lib/libkern/libkern.h>
33 #include <machine/promlib.h>
34
35 char *match_c5ip(void);
36 void prom_patch(void);
37
38 /*
39 * Each patch entry is processed by:
40 * printf(message); prom_interpret(patch); printf("\n");
41 */
42 struct patch_entry {
43 char *message;
44 char *patch;
45 };
46
47 /*
48 * PROM patches to apply to machine matching name/promvers.
49 */
50 struct prom_patch {
51 char *name; /* "name" of the root node */
52 int promvers; /* prom_version() */
53 char *(*submatch)(void); /* Additional matches to test */
54 struct patch_entry *patches; /* The patches themselves */
55 };
56
57 /*
58 * Patches for JavaStation 1 with OBP 2.30
59 * NB: its romvec is version 3, so this is PROM_OBP_V3.
60 */
61 static struct patch_entry patch_js1_obp[] = {
62
63 /*
64 * Can not remove a node, so just rename bogus /obio/zs so that it
65 * does not get matched.
66 */
67 { "zs: renaming out of the way",
68 "\" /obio/zs@0,0\" find-device \" fakezs\" name"
69 " \" /obio/zs@0,100000\" find-device \" fakezs\" name "
70 " device-end"
71 },
72
73 /*
74 * Give "su" (com port) "interrupts" property.
75 */
76 { "su: adding \"interrupts\"",
77 "\" /obio/su\" find-device"
78 " d# 13 \" interrupts\" integer-attribute"
79 " device-end"
80 },
81
82 /*
83 * Create a bare-bones "8042" (pckbc) node - just enough to attach it.
84 */
85 { "8042: creating node",
86 "0 0 0 0 \" /obio\" begin-package"
87 " \" 8042\" name"
88 " 300060 0 8 reg"
89 " d# 13 \" interrupts\" integer-attribute"
90 " end-package"
91 },
92
93 { NULL, NULL }
94 }; /* patch_js1_obp */
95
96
97 /*
98 * Patches for JavaStation 1 with OpenFirmware.
99 * PROM in these machines is crippled in many ways.
100 */
101 static struct patch_entry patch_js1_ofw[] = {
102
103 /*
104 * JS1/OFW has no CPU node in the device tree. Create one to save us a
105 * _lot_ of headache in cpu.c and mainbus_attach. Mostly copied from
106 * OBP2. While clock-frequency is usually at the root node, add it
107 * here for brevity as kernel checks CPU node for this property anyway.
108 */
109 { "cpu: creating node ", /* NB: space at the end is intentional */
110 "0 0 0 0 \" /\" begin-package"
111 " \" FMI,MB86904\" device-name" /* NB: will print the name */
112 " \" cpu\" device-type"
113 " 0 \" mid\" integer-property"
114
115 " 8 \" sparc-version\" integer-property"
116 " 4 \" version\" integer-property"
117 " 0 \" implementation\" integer-property"
118 " 4 \" psr-version\" integer-property"
119 " 0 \" psr-implementation\" integer-property"
120
121 " d# 100000000 \" clock-frequency\" integer-property"
122
123 " d# 4096 \" page-size\" integer-property"
124 " d# 256 \" mmu-nctx\" integer-property"
125
126 " 2 \" ncaches\" integer-property"
127
128 " d# 512 \" icache-nlines\" integer-property"
129 " d# 32 \" icache-line-size\" integer-property"
130 " 1 \" icache-associativity\" integer-property"
131
132 " d# 512 \" dcache-nlines\" integer-property"
133 " d# 16 \" dcache-line-size\" integer-property"
134 " 1 \" dcache-associativity\" integer-property"
135
136 " 0 0 \" cache-physical?\" property"
137 " 0 0 \" cache-coherence?\" property"
138
139 " end-package"
140 },
141
142 /*
143 * mk48txx_attach needs a model name, spare clockattach from guesswork.
144 */
145 { "eeprom: adding \"model\"",
146 "dev /obio/eeprom \" mk48t08\" model device-end"
147 },
148
149 /*
150 * "interrupts" property is bogusly zero, delete it and let
151 * sbus_get_intr fallback to correct "intr" property
152 */
153 { "le: deleting bogus \"interrupts\"",
154 "dev /sbus/ledma/le \" interrupts\" delete-property device-end"
155 },
156
157 /*
158 * Give "su" (com port) "interrupts" property.
159 */
160 { "su: adding \"interrupts\"",
161 "dev /obio/su d# 13 \" interrupts\" integer-property device-end"
162 },
163
164 /*
165 * Give "8042" (pckbc) "interrupts" property.
166 */
167 { "8042: adding \"interrupts\"",
168 "dev /obio/8042 d# 13 \" interrupts\" integer-property device-end"
169 },
170
171 { NULL, NULL }
172 }; /* patch_js1_ofw */
173
174 /*
175 * Patches for Cycle 5 IP
176 */
177 static struct patch_entry patch_c5ip[] = {
178
179 /*
180 * Can not remove a node, so just rename bogus /iommu/sbus/SUNW,CS4231
181 * so that it does not get matched.
182 */
183 { "SUNW,CS4231: renaming out of the way",
184 "\" /iommu/sbus/SUNW,CS4231@3,c000000\" find-device \" fakeCS4231\" name"
185 " device-end"
186 },
187
188 { NULL, NULL }
189 }; /* patch_c5ip */
190
191 static struct patch_entry patch_krups[] = {
192
193 /*
194 * check if there's a node for the audio chip, if not create it
195 */
196 { "sound device node: ",
197 "\" /pci/ebus/sound\" ' find-device catch"
198 " 0= if"
199 " device-end"
200 " \" ok\""
201 " else"
202 " 0 0 0 0 \" /pci/ebus\" begin-package"
203 " \" sound\" name"
204 " 200000 1 600 reg"
205 " end-package"
206 " \" created\""
207 " then type"
208 },
209
210 { NULL, NULL }
211 }; /* patch_krups */
212
213 static struct prom_patch prom_patch_tab[] = {
214 { "SUNW,JavaStation-1", PROM_OBP_V3, NULL, patch_js1_obp },
215 { "SUNW,JDM1", PROM_OPENFIRM, NULL, patch_js1_ofw },
216 { "SUNW,SPARCstation-5", PROM_OBP_V3, match_c5ip, patch_c5ip },
217 { "SUNW,JSIIep", PROM_OPENFIRM, NULL, patch_krups },
218 { NULL, 0, NULL }
219 };
220
221
222 /*
223 * Additional match routine for Cycle 5 IP
224 * This uses the SPARCstation 5 PROM almost unchanged, so we check the
225 * "banner-name" attribute of the root node.
226 */
227 char * match_c5ip(void)
228 {
229 if (strcmp(prom_getpropstring(prom_findroot(), "banner-name"),
230 "Cycle Computer Corporation") == 0)
231 return "Cycle 5 IP";
232
233 return NULL;
234 }
235
236 /*
237 * Check if this machine needs tweaks to its PROM. It's simpler to fix
238 * the PROM than to invent workarounds in the kernel code. We do this
239 * patching in the secondary boot to avoid wasting space in the kernel.
240 */
241 void
242 prom_patch(void)
243 {
244 char namebuf[32];
245 char *propval;
246 struct prom_patch *p;
247
248 if (prom_version() == PROM_OLDMON)
249 return; /* don't bother - no forth in this */
250
251 propval = prom_getpropstringA(prom_findroot(), "name",
252 namebuf, sizeof(namebuf));
253 if (propval == NULL)
254 return;
255
256 for (p = prom_patch_tab; p->name != NULL; ++p) {
257 if (p->promvers == prom_version()
258 && strcmp(p->name, namebuf) == 0) {
259 struct patch_entry *e;
260 const char *promstr = "???";
261 char *submatch_info = NULL;
262
263 switch (prom_version()) {
264 case PROM_OBP_V0:
265 promstr = "OBP0";
266 break;
267 case PROM_OBP_V2:
268 promstr = "OBP2";
269 break;
270 case PROM_OBP_V3:
271 promstr = "OBP3";
272 break;
273 case PROM_OPENFIRM:
274 promstr = "OFW";
275 break;
276 }
277
278
279 if (p->submatch != NULL) {
280 submatch_info = (*p->submatch)();
281 if (submatch_info == NULL)
282 continue;
283 }
284
285 if (submatch_info != NULL)
286 printf("Patching %s for %s (%s)\n",
287 promstr, p->name, submatch_info);
288 else
289 printf("Patching %s for %s\n",
290 promstr, p->name);
291 for (e = p->patches; e->message != NULL; ++e) {
292 printf("%s", e->message);
293 prom_interpret(e->patch);
294 printf("\n");
295 }
296 return;
297 }
298 }
299 }
300