prompatch.c revision 1.3 1 1.3 uwe /* $NetBSD: prompatch.c,v 1.3 2001/11/22 04:18:28 uwe Exp $ */
2 1.1 uwe
3 1.1 uwe /*
4 1.1 uwe * Copyright (c) 2001 Valeriy E. Ushakov
5 1.1 uwe * All rights reserved.
6 1.1 uwe *
7 1.1 uwe * Redistribution and use in source and binary forms, with or without
8 1.1 uwe * modification, are permitted provided that the following conditions
9 1.1 uwe * are met:
10 1.1 uwe * 1. Redistributions of source code must retain the above copyright
11 1.1 uwe * notice, this list of conditions and the following disclaimer.
12 1.1 uwe * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 uwe * notice, this list of conditions and the following disclaimer in the
14 1.1 uwe * documentation and/or other materials provided with the distribution.
15 1.1 uwe * 3. The name of the author may not be used to endorse or promote products
16 1.1 uwe * derived from this software without specific prior written permission
17 1.1 uwe *
18 1.1 uwe * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 1.1 uwe * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 1.1 uwe * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 1.1 uwe * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 1.1 uwe * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 1.1 uwe * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 1.1 uwe * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 1.1 uwe * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 1.1 uwe * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 1.1 uwe * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 1.1 uwe */
29 1.1 uwe
30 1.1 uwe #include <sys/param.h>
31 1.1 uwe #include <lib/libsa/stand.h>
32 1.1 uwe #include <machine/promlib.h>
33 1.1 uwe
34 1.1 uwe void prom_patch(void);
35 1.1 uwe
36 1.1 uwe /*
37 1.1 uwe * Each patch entry is processed by:
38 1.1 uwe * printf(message); prom_interpret(patch); printf("\n");
39 1.1 uwe */
40 1.1 uwe struct patch_entry {
41 1.1 uwe char *message;
42 1.1 uwe char *patch;
43 1.1 uwe };
44 1.1 uwe
45 1.1 uwe /*
46 1.1 uwe * PROM patches to apply to machine matching name/promvers.
47 1.1 uwe */
48 1.1 uwe struct prom_patch {
49 1.1 uwe char *name; /* "name" of the root node */
50 1.1 uwe int promvers; /* prom_version() */
51 1.1 uwe struct patch_entry *patches;
52 1.1 uwe };
53 1.1 uwe
54 1.1 uwe
55 1.3 uwe /*
56 1.3 uwe * Patches for JavaStation 1 with OBP 2.x
57 1.3 uwe */
58 1.3 uwe static struct patch_entry patch_js1_obp2[] = {
59 1.3 uwe
60 1.3 uwe /*
61 1.3 uwe * Give "su" (com port) "interrupts" property.
62 1.3 uwe */
63 1.3 uwe { "su: adding \"interrupts\"",
64 1.3 uwe "\" /obio/su\" open-dev"
65 1.3 uwe " d# 13 \" interrupts\" integer-attribute"
66 1.3 uwe " close-dev"
67 1.3 uwe },
68 1.3 uwe
69 1.3 uwe /*
70 1.3 uwe * TODO: Create "8042" (pckbc) node.
71 1.3 uwe * Delete "zs"
72 1.3 uwe */
73 1.3 uwe
74 1.3 uwe { NULL, NULL }
75 1.3 uwe };
76 1.3 uwe
77 1.1 uwe
78 1.1 uwe /*
79 1.1 uwe * Patches for JavaStation 1 with OBP 3.* (OpenFirmware).
80 1.1 uwe * PROM in these machines is crippled in many ways.
81 1.1 uwe */
82 1.3 uwe static struct patch_entry patch_js1_ofw[] = {
83 1.1 uwe
84 1.1 uwe /*
85 1.3 uwe * JS1/OFW has no cpu node in the device tree. Create one to save us a
86 1.1 uwe * _lot_ of headache in cpu.c and mainbus_attach. Mostly copied from
87 1.1 uwe * OBP2. While clock-frequency is usually at the root node, add it
88 1.1 uwe * here for brevity as kernel checks cpu node for this property anyway.
89 1.1 uwe */
90 1.1 uwe { "cpu: creating node ", /* NB: space at the end is intentional */
91 1.1 uwe "0 0 0 0 \" /\" begin-package"
92 1.1 uwe " \" FMI,MB86904\" device-name" /* NB: will print the name */
93 1.1 uwe " \" cpu\" device-type"
94 1.1 uwe " 0 \" mid\" integer-property"
95 1.1 uwe
96 1.1 uwe " 8 \" sparc-version\" integer-property"
97 1.1 uwe " 4 \" version\" integer-property"
98 1.1 uwe " 0 \" implementation\" integer-property"
99 1.1 uwe " 4 \" psr-version\" integer-property"
100 1.1 uwe " 0 \" psr-implementation\" integer-property"
101 1.1 uwe
102 1.1 uwe " d# 100000000 \" clock-frequency\" integer-property"
103 1.1 uwe
104 1.1 uwe " d# 4096 \" page-size\" integer-property"
105 1.1 uwe " d# 256 \" mmu-nctx\" integer-property"
106 1.1 uwe
107 1.1 uwe " 2 \" ncaches\" integer-property"
108 1.1 uwe
109 1.1 uwe " d# 512 \" icache-nlines\" integer-property"
110 1.1 uwe " d# 32 \" icache-line-size\" integer-property"
111 1.1 uwe " 1 \" icache-associativity\" integer-property"
112 1.1 uwe
113 1.1 uwe " d# 512 \" dcache-nlines\" integer-property"
114 1.1 uwe " d# 16 \" dcache-line-size\" integer-property"
115 1.1 uwe " 1 \" dcache-associativity\" integer-property"
116 1.1 uwe
117 1.1 uwe " 0 0 \" cache-physical?\" property"
118 1.1 uwe " 0 0 \" cache-coherence?\" property"
119 1.1 uwe
120 1.1 uwe " end-package"
121 1.1 uwe },
122 1.1 uwe
123 1.1 uwe /*
124 1.1 uwe * mk48txx_attach needs a model name, spare clockattach from guesswork.
125 1.1 uwe */
126 1.1 uwe { "eeprom: adding \"model\"",
127 1.1 uwe "dev /obio/eeprom \" mk48t08\" model device-end"
128 1.1 uwe },
129 1.1 uwe
130 1.1 uwe /*
131 1.1 uwe * "interrupts" property is bogusly zero, delete it and let
132 1.1 uwe * sbus_get_intr fallback to correct "intr" property
133 1.1 uwe */
134 1.1 uwe { "le: deleting bogus \"interrupts\"",
135 1.1 uwe "dev /sbus/ledma/le \" interrupts\" delete-property device-end"
136 1.1 uwe },
137 1.1 uwe
138 1.1 uwe /*
139 1.1 uwe * Give "su" (com port) "interrupts" property.
140 1.1 uwe */
141 1.1 uwe { "su: adding \"interrupts\"",
142 1.1 uwe "dev /obio/su d# 13 \" interrupts\" integer-property device-end"
143 1.1 uwe },
144 1.1 uwe
145 1.1 uwe /*
146 1.1 uwe * Give "8042" (pckbc) "interrupts" property.
147 1.1 uwe */
148 1.1 uwe { "8042: adding \"interrupts\"",
149 1.1 uwe "dev /obio/8042 d# 13 \" interrupts\" integer-property device-end"
150 1.1 uwe },
151 1.1 uwe
152 1.1 uwe { NULL, NULL }
153 1.3 uwe }; /* patch_js1_ofw */
154 1.1 uwe
155 1.1 uwe
156 1.1 uwe
157 1.1 uwe static struct prom_patch prom_patch_tab[] = {
158 1.3 uwe { "SUNW,JavaStation-1", PROM_OBP_V2, patch_js1_obp2 },
159 1.3 uwe { "SUNW,JDM1", PROM_OPENFIRM, patch_js1_ofw },
160 1.1 uwe { NULL, 0, NULL }
161 1.1 uwe };
162 1.1 uwe
163 1.1 uwe
164 1.1 uwe /*
165 1.1 uwe * Check if this machine needs tweaks to its PROM. It's simpler to
166 1.1 uwe * fix PROM than to invent workarounds in the kernel code. We do this
167 1.3 uwe * patching in the secondary boot to avoid wasting space in the kernel.
168 1.1 uwe */
169 1.1 uwe void
170 1.1 uwe prom_patch(void)
171 1.1 uwe {
172 1.1 uwe char namebuf[32];
173 1.1 uwe char *propval;
174 1.1 uwe struct prom_patch *p;
175 1.1 uwe
176 1.3 uwe if (prom_version() == PROM_OLDMON)
177 1.3 uwe return; /* don't bother - no forth in this */
178 1.3 uwe
179 1.2 eeh propval = PROM_getpropstringA(prom_findroot(), "name",
180 1.1 uwe namebuf, sizeof(namebuf));
181 1.1 uwe if (propval == NULL)
182 1.1 uwe return;
183 1.1 uwe
184 1.1 uwe for (p = prom_patch_tab; p->name != NULL; ++p) {
185 1.1 uwe if (p->promvers == prom_version()
186 1.1 uwe && strcmp(p->name, namebuf) == 0) {
187 1.1 uwe struct patch_entry *e;
188 1.3 uwe const char *promstr = "???";
189 1.3 uwe
190 1.3 uwe switch (prom_version()) {
191 1.3 uwe case PROM_OBP_V0:
192 1.3 uwe promstr = "OBP0";
193 1.3 uwe break;
194 1.3 uwe case PROM_OBP_V2:
195 1.3 uwe promstr = "OBP2";
196 1.3 uwe break;
197 1.3 uwe case PROM_OBP_V3:
198 1.3 uwe promstr = "OBP3";
199 1.3 uwe break;
200 1.3 uwe case PROM_OPENFIRM:
201 1.3 uwe promstr = "OFW";
202 1.3 uwe break;
203 1.3 uwe }
204 1.1 uwe
205 1.3 uwe printf("Patching %s for %s\n", promstr, p->name);
206 1.1 uwe for (e = p->patches; e->message != NULL; ++e) {
207 1.1 uwe printf("%s", e->message);
208 1.1 uwe prom_interpret(e->patch);
209 1.1 uwe printf("\n");
210 1.1 uwe }
211 1.1 uwe return;
212 1.1 uwe }
213 1.1 uwe }
214 1.1 uwe }
215