Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / sparc / stand / boot / prompatch.c
blob06cf20a126a31370c0237d6820c195b386cc02bf
1 /* $NetBSD: prompatch.c,v 1.6.6.4 2005/11/10 13:59:17 skrll Exp $ */
3 /*
4 * Copyright (c) 2001 Valeriy E. Ushakov
5 * All rights reserved.
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
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.
30 #include <sys/param.h>
31 #include <lib/libsa/stand.h>
32 #include <lib/libkern/libkern.h>
33 #include <machine/promlib.h>
36 void prom_patch(void);
38 static const char *match_c5ip(void);
42 * Each patch entry is processed by:
43 * printf(message); prom_interpret(patch); printf("\n");
45 struct patch_entry {
46 const char *message;
47 const char *patch;
52 * PROM patches to apply to machine matching name/promvers.
54 struct prom_patch {
55 const char *name; /* "name" of the root node */
56 int promvers; /* prom_version() */
57 const char *(*submatch)(void); /* Additional matches to test */
58 const struct patch_entry *patches; /* The patches themselves */
63 * Patches for JavaStation 1 with OBP 2.30.
64 * NB: its romvec is version 3, so this is PROM_OBP_V3.
66 static const struct patch_entry patch_js1_obp[] = {
69 * Can not remove a node, so just rename bogus /obio/zs so that it
70 * does not get matched.
72 { "zs: renaming out of the way",
73 "\" /obio/zs@0,0\" find-device \" fakezs\" name"
74 " \" /obio/zs@0,100000\" find-device \" fakezs\" name "
75 " device-end"
79 * Give "su" (com port) "interrupts" property.
81 { "su: adding \"interrupts\"",
82 "\" /obio/su\" find-device"
83 " d# 13 \" interrupts\" integer-attribute"
84 " device-end"
88 * Create a bare-bones "8042" (pckbc) node - just enough to attach it.
90 { "8042: creating node",
91 "0 0 0 0 \" /obio\" begin-package"
92 " \" 8042\" name"
93 " 300060 0 8 reg"
94 " d# 13 \" interrupts\" integer-attribute"
95 " end-package"
98 { NULL, NULL }
99 }; /* patch_js1_obp */
103 * Patches for JavaStation 1 with OpenFirmware.
104 * PROM in these machines is crippled in many ways.
106 static const struct patch_entry patch_js1_ofw[] = {
109 * JS1/OFW has no CPU node in the device tree. Create one to save us a
110 * _lot_ of headache in cpu.c and mainbus_attach. Mostly copied from
111 * OBP2. While clock-frequency is usually at the root node, add it
112 * here for brevity as kernel checks CPU node for this property anyway.
114 { "cpu: creating node ", /* NB: space at the end is intentional */
115 "0 0 0 0 \" /\" begin-package"
116 " \" FMI,MB86904\" device-name" /* NB: will print the name */
117 " \" cpu\" device-type"
118 " 0 \" mid\" integer-property"
120 " 8 \" sparc-version\" integer-property"
121 " 4 \" version\" integer-property"
122 " 0 \" implementation\" integer-property"
123 " 4 \" psr-version\" integer-property"
124 " 0 \" psr-implementation\" integer-property"
126 " d# 100000000 \" clock-frequency\" integer-property"
128 " d# 4096 \" page-size\" integer-property"
129 " d# 256 \" mmu-nctx\" integer-property"
131 " 2 \" ncaches\" integer-property"
133 " d# 512 \" icache-nlines\" integer-property"
134 " d# 32 \" icache-line-size\" integer-property"
135 " 1 \" icache-associativity\" integer-property"
137 " d# 512 \" dcache-nlines\" integer-property"
138 " d# 16 \" dcache-line-size\" integer-property"
139 " 1 \" dcache-associativity\" integer-property"
141 " 0 0 \" cache-physical?\" property"
142 " 0 0 \" cache-coherence?\" property"
144 " end-package"
148 * mk48txx_attach needs a model name, spare clockattach from guesswork.
150 { "eeprom: adding \"model\"",
151 "dev /obio/eeprom \" mk48t08\" model device-end"
155 * "interrupts" property is bogusly zero, delete it and let
156 * sbus_get_intr fallback to correct "intr" property.
158 { "le: deleting bogus \"interrupts\"",
159 "dev /sbus/ledma/le \" interrupts\" delete-property device-end"
163 * Give "su" (com port) "interrupts" property.
165 { "su: adding \"interrupts\"",
166 "dev /obio/su d# 13 \" interrupts\" integer-property device-end"
170 * Give "8042" (pckbc) "interrupts" property.
172 { "8042: adding \"interrupts\"",
173 "dev /obio/8042 d# 13 \" interrupts\" integer-property device-end"
176 { NULL, NULL }
177 }; /* patch_js1_ofw */
181 * Patches for Cycle 5 IP.
183 static const struct patch_entry patch_c5ip[] = {
186 * Can not remove a node, so just rename bogus /iommu/sbus/SUNW,CS4231
187 * so that it does not get matched.
189 { "SUNW,CS4231: renaming out of the way",
190 "\" /iommu/sbus/SUNW,CS4231@3,c000000\" find-device \" fakeCS4231\" name"
191 " device-end"
194 { NULL, NULL }
195 }; /* patch_c5ip */
199 * Patches for JavaStation NC, aka Krups.
201 static const struct patch_entry patch_krups[] = {
204 * Check if there's a node for the audio chip, if not create it.
206 { "sound device node: ",
207 "\" /pci/ebus/sound\" ' find-device catch"
208 " 0= if"
209 " device-end"
210 " \" ok\""
211 " else"
212 " 0 0 0 0 \" /pci/ebus\" begin-package"
213 " \" sound\" name"
214 " 200000 1 600 reg"
215 " end-package"
216 " \" created\""
217 " then type"
220 { NULL, NULL }
221 }; /* patch_krups */
224 static const struct prom_patch prom_patch_tab[] = {
225 { "SUNW,JavaStation-1", PROM_OBP_V3, NULL, patch_js1_obp },
226 { "SUNW,JDM1", PROM_OPENFIRM, NULL, patch_js1_ofw },
227 { "SUNW,SPARCstation-5", PROM_OBP_V3, match_c5ip, patch_c5ip },
228 { "SUNW,JSIIep", PROM_OPENFIRM, NULL, patch_krups },
229 { NULL, 0, NULL }
234 * Additional match routine for Cycle 5 IP.
235 * This uses the SPARCstation 5 PROM almost unchanged, so we check the
236 * "banner-name" attribute of the root node.
238 static const char *
239 match_c5ip(void)
241 if (strcmp(prom_getpropstring(prom_findroot(), "banner-name"),
242 "Cycle Computer Corporation") == 0)
243 return "Cycle 5 IP";
245 return NULL;
250 * Check if this machine needs tweaks to its PROM. It's simpler to fix
251 * the PROM than to invent workarounds in the kernel code. We do this
252 * patching in the secondary boot to avoid wasting space in the kernel.
254 void
255 prom_patch(void)
257 char namebuf[32];
258 char *propval;
259 const struct prom_patch *p;
261 if (prom_version() == PROM_OLDMON)
262 return; /* don't bother - no forth in this */
264 propval = prom_getpropstringA(prom_findroot(), "name",
265 namebuf, sizeof(namebuf));
266 if (propval == NULL)
267 return;
269 for (p = prom_patch_tab; p->name != NULL; ++p) {
270 if (p->promvers == prom_version()
271 && strcmp(p->name, namebuf) == 0) {
272 const struct patch_entry *e;
273 const char *promstr = "???";
274 const char *submatch_info = NULL;
276 switch (prom_version()) {
277 case PROM_OBP_V0:
278 promstr = "OBP0";
279 break;
280 case PROM_OBP_V2:
281 promstr = "OBP2";
282 break;
283 case PROM_OBP_V3:
284 promstr = "OBP3";
285 break;
286 case PROM_OPENFIRM:
287 promstr = "OFW";
288 break;
292 if (p->submatch != NULL) {
293 submatch_info = (*p->submatch)();
294 if (submatch_info == NULL)
295 continue;
298 if (submatch_info != NULL)
299 printf("Patching %s for %s (%s)\n",
300 promstr, p->name, submatch_info);
301 else
302 printf("Patching %s for %s\n",
303 promstr, p->name);
304 for (e = p->patches; e->message != NULL; ++e) {
305 printf("%s", e->message);
306 prom_interpret(e->patch);
307 printf("\n");
309 return;