prompatch.c revision 1.2.4.2 1 /* $NetBSD: prompatch.c,v 1.2.4.2 2002/01/08 00:27:54 nathanw 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 <machine/promlib.h>
33
34 void prom_patch(void);
35
36 /*
37 * Each patch entry is processed by:
38 * printf(message); prom_interpret(patch); printf("\n");
39 */
40 struct patch_entry {
41 char *message;
42 char *patch;
43 };
44
45 /*
46 * PROM patches to apply to machine matching name/promvers.
47 */
48 struct prom_patch {
49 char *name; /* "name" of the root node */
50 int promvers; /* prom_version() */
51 struct patch_entry *patches;
52 };
53
54
55 /*
56 * Patches for JavaStation 1 with OBP 2.x
57 */
58 static struct patch_entry patch_js1_obp2[] = {
59
60 /*
61 * Give "su" (com port) "interrupts" property.
62 */
63 { "su: adding \"interrupts\"",
64 "\" /obio/su\" open-dev"
65 " d# 13 \" interrupts\" integer-attribute"
66 " close-dev"
67 },
68
69 /*
70 * TODO: Create "8042" (pckbc) node.
71 * Delete "zs"
72 */
73
74 { NULL, NULL }
75 };
76
77
78 /*
79 * Patches for JavaStation 1 with OBP 3.x
80 */
81 static struct patch_entry patch_js1_obp3[] = {
82
83 /*
84 * Give "su" (com port) "interrupts" property.
85 */
86 { "su: adding \"interrupts\"",
87 "\" /obio/su\" select-dev"
88 " d# 13 \" interrupts\" integer-attribute"
89 " device-end"
90 },
91
92 { NULL, NULL }
93 };
94
95 /*
96 * Patches for JavaStation 1 with OpenFirmware.
97 * PROM in these machines is crippled in many ways.
98 */
99 static struct patch_entry patch_js1_ofw[] = {
100
101 /*
102 * JS1/OFW has no cpu node in the device tree. Create one to save us a
103 * _lot_ of headache in cpu.c and mainbus_attach. Mostly copied from
104 * OBP2. While clock-frequency is usually at the root node, add it
105 * here for brevity as kernel checks cpu node for this property anyway.
106 */
107 { "cpu: creating node ", /* NB: space at the end is intentional */
108 "0 0 0 0 \" /\" begin-package"
109 " \" FMI,MB86904\" device-name" /* NB: will print the name */
110 " \" cpu\" device-type"
111 " 0 \" mid\" integer-property"
112
113 " 8 \" sparc-version\" integer-property"
114 " 4 \" version\" integer-property"
115 " 0 \" implementation\" integer-property"
116 " 4 \" psr-version\" integer-property"
117 " 0 \" psr-implementation\" integer-property"
118
119 " d# 100000000 \" clock-frequency\" integer-property"
120
121 " d# 4096 \" page-size\" integer-property"
122 " d# 256 \" mmu-nctx\" integer-property"
123
124 " 2 \" ncaches\" integer-property"
125
126 " d# 512 \" icache-nlines\" integer-property"
127 " d# 32 \" icache-line-size\" integer-property"
128 " 1 \" icache-associativity\" integer-property"
129
130 " d# 512 \" dcache-nlines\" integer-property"
131 " d# 16 \" dcache-line-size\" integer-property"
132 " 1 \" dcache-associativity\" integer-property"
133
134 " 0 0 \" cache-physical?\" property"
135 " 0 0 \" cache-coherence?\" property"
136
137 " end-package"
138 },
139
140 /*
141 * mk48txx_attach needs a model name, spare clockattach from guesswork.
142 */
143 { "eeprom: adding \"model\"",
144 "dev /obio/eeprom \" mk48t08\" model device-end"
145 },
146
147 /*
148 * "interrupts" property is bogusly zero, delete it and let
149 * sbus_get_intr fallback to correct "intr" property
150 */
151 { "le: deleting bogus \"interrupts\"",
152 "dev /sbus/ledma/le \" interrupts\" delete-property device-end"
153 },
154
155 /*
156 * Give "su" (com port) "interrupts" property.
157 */
158 { "su: adding \"interrupts\"",
159 "dev /obio/su d# 13 \" interrupts\" integer-property device-end"
160 },
161
162 /*
163 * Give "8042" (pckbc) "interrupts" property.
164 */
165 { "8042: adding \"interrupts\"",
166 "dev /obio/8042 d# 13 \" interrupts\" integer-property device-end"
167 },
168
169 { NULL, NULL }
170 }; /* patch_js1_ofw */
171
172
173
174 static struct prom_patch prom_patch_tab[] = {
175 { "SUNW,JavaStation-1", PROM_OBP_V2, patch_js1_obp2 },
176 { "SUNW,JavaStation-1", PROM_OBP_V3, patch_js1_obp3 },
177 { "SUNW,JDM1", PROM_OPENFIRM, patch_js1_ofw },
178 { NULL, 0, NULL }
179 };
180
181
182 /*
183 * Check if this machine needs tweaks to its PROM. It's simpler to
184 * fix PROM than to invent workarounds in the kernel code. We do this
185 * patching in the secondary boot to avoid wasting space in the kernel.
186 */
187 void
188 prom_patch(void)
189 {
190 char namebuf[32];
191 char *propval;
192 struct prom_patch *p;
193
194 if (prom_version() == PROM_OLDMON)
195 return; /* don't bother - no forth in this */
196
197 propval = PROM_getpropstringA(prom_findroot(), "name",
198 namebuf, sizeof(namebuf));
199 if (propval == NULL)
200 return;
201
202 for (p = prom_patch_tab; p->name != NULL; ++p) {
203 if (p->promvers == prom_version()
204 && strcmp(p->name, namebuf) == 0) {
205 struct patch_entry *e;
206 const char *promstr = "???";
207
208 switch (prom_version()) {
209 case PROM_OBP_V0:
210 promstr = "OBP0";
211 break;
212 case PROM_OBP_V2:
213 promstr = "OBP2";
214 break;
215 case PROM_OBP_V3:
216 promstr = "OBP3";
217 break;
218 case PROM_OPENFIRM:
219 promstr = "OFW";
220 break;
221 }
222
223 printf("Patching %s for %s\n", promstr, p->name);
224 for (e = p->patches; e->message != NULL; ++e) {
225 printf("%s", e->message);
226 prom_interpret(e->patch);
227 printf("\n");
228 }
229 return;
230 }
231 }
232 }
233