prompatch.c revision 1.1 1 /* $NetBSD: prompatch.c,v 1.1 2001/06/21 03:13:05 uwe 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 /*
57 * Patches for JavaStation 1 with OBP 3.* (OpenFirmware).
58 * PROM in these machines is crippled in many ways.
59 */
60 static struct patch_entry patch_js1_of[] = {
61
62 /*
63 * JS1/OF has no cpu node in the device tree. Create one to save us a
64 * _lot_ of headache in cpu.c and mainbus_attach. Mostly copied from
65 * OBP2. While clock-frequency is usually at the root node, add it
66 * here for brevity as kernel checks cpu node for this property anyway.
67 */
68 { "cpu: creating node ", /* NB: space at the end is intentional */
69 "0 0 0 0 \" /\" begin-package"
70 " \" FMI,MB86904\" device-name" /* NB: will print the name */
71 " \" cpu\" device-type"
72 " 0 \" mid\" integer-property"
73
74 " 8 \" sparc-version\" integer-property"
75 " 4 \" version\" integer-property"
76 " 0 \" implementation\" integer-property"
77 " 4 \" psr-version\" integer-property"
78 " 0 \" psr-implementation\" integer-property"
79
80 " d# 100000000 \" clock-frequency\" integer-property"
81
82 " d# 4096 \" page-size\" integer-property"
83 " d# 256 \" mmu-nctx\" integer-property"
84
85 " 2 \" ncaches\" integer-property"
86
87 " d# 512 \" icache-nlines\" integer-property"
88 " d# 32 \" icache-line-size\" integer-property"
89 " 1 \" icache-associativity\" integer-property"
90
91 " d# 512 \" dcache-nlines\" integer-property"
92 " d# 16 \" dcache-line-size\" integer-property"
93 " 1 \" dcache-associativity\" integer-property"
94
95 " 0 0 \" cache-physical?\" property"
96 " 0 0 \" cache-coherence?\" property"
97
98 " end-package"
99 },
100
101 /*
102 * mk48txx_attach needs a model name, spare clockattach from guesswork.
103 */
104 { "eeprom: adding \"model\"",
105 "dev /obio/eeprom \" mk48t08\" model device-end"
106 },
107
108 /*
109 * "interrupts" property is bogusly zero, delete it and let
110 * sbus_get_intr fallback to correct "intr" property
111 */
112 { "le: deleting bogus \"interrupts\"",
113 "dev /sbus/ledma/le \" interrupts\" delete-property device-end"
114 },
115
116 /*
117 * Give "su" (com port) "interrupts" property.
118 */
119 { "su: adding \"interrupts\"",
120 "dev /obio/su d# 13 \" interrupts\" integer-property device-end"
121 },
122
123 /*
124 * Give "8042" (pckbc) "interrupts" property.
125 */
126 { "8042: adding \"interrupts\"",
127 "dev /obio/8042 d# 13 \" interrupts\" integer-property device-end"
128 },
129
130 { NULL, NULL }
131 }; /* patch_js1_of */
132
133
134
135 static struct prom_patch prom_patch_tab[] = {
136 { "SUNW,JDM1", PROM_OPENFIRM, patch_js1_of },
137 { NULL, 0, NULL }
138 };
139
140
141 /*
142 * Check if this machine needs tweaks to its PROM. It's simpler to
143 * fix PROM than to invent workarounds in the kernel code. We do this
144 * patching in the secondary boot to avoid wasting space in the
145 * kernel.
146 */
147 void
148 prom_patch(void)
149 {
150 char namebuf[32];
151 char *propval;
152 struct prom_patch *p;
153
154 propval = getpropstringA(prom_findroot(), "name",
155 namebuf, sizeof(namebuf));
156 if (propval == NULL)
157 return;
158
159 for (p = prom_patch_tab; p->name != NULL; ++p) {
160 if (p->promvers == prom_version()
161 && strcmp(p->name, namebuf) == 0) {
162 struct patch_entry *e;
163
164 printf("Patching PROM v%d for %s\n",
165 p->promvers, p->name);
166 for (e = p->patches; e->message != NULL; ++e) {
167 printf("%s", e->message);
168 prom_interpret(e->patch);
169 printf("\n");
170 }
171 return;
172 }
173 }
174 }
175