1 /* $NetBSD: prompatch.c,v 1.9 2004/03/18 12:26:51 hannken 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 prom_patch prom_patch_tab[] = { 192 { "SUNW,JavaStation-1", PROM_OBP_V3, NULL, patch_js1_obp }, 193 { "SUNW,JDM1", PROM_OPENFIRM, NULL, patch_js1_ofw }, 194 { "SUNW,SPARCstation-5", PROM_OBP_V3, match_c5ip, patch_c5ip }, 195 { NULL, 0, NULL } 196 }; 197 198 199 /* 200 * Additional match routine for Cycle 5 IP 201 * This uses the SPARCstation 5 PROM almost unchanged, so we check the 202 * "banner-name" attribute of the root node. 203 */ 204 char * match_c5ip(void) 205 { 206 if (strcmp(prom_getpropstring(prom_findroot(), "banner-name"), 207 "Cycle Computer Corporation") == 0) 208 return "Cycle 5 IP"; 209 210 return NULL; 211 } 212 213 /* 214 * Check if this machine needs tweaks to its PROM. It's simpler to fix 215 * the PROM than to invent workarounds in the kernel code. We do this 216 * patching in the secondary boot to avoid wasting space in the kernel. 217 */ 218 void 219 prom_patch(void) 220 { 221 char namebuf[32]; 222 char *propval; 223 struct prom_patch *p; 224 225 if (prom_version() == PROM_OLDMON) 226 return; /* don't bother - no forth in this */ 227 228 propval = prom_getpropstringA(prom_findroot(), "name", 229 namebuf, sizeof(namebuf)); 230 if (propval == NULL) 231 return; 232 233 for (p = prom_patch_tab; p->name != NULL; ++p) { 234 if (p->promvers == prom_version() 235 && strcmp(p->name, namebuf) == 0) { 236 struct patch_entry *e; 237 const char *promstr = "???"; 238 char *submatch_info = NULL; 239 240 switch (prom_version()) { 241 case PROM_OBP_V0: 242 promstr = "OBP0"; 243 break; 244 case PROM_OBP_V2: 245 promstr = "OBP2"; 246 break; 247 case PROM_OBP_V3: 248 promstr = "OBP3"; 249 break; 250 case PROM_OPENFIRM: 251 promstr = "OFW"; 252 break; 253 } 254 255 256 if (p->submatch != NULL) { 257 submatch_info = (*p->submatch)(); 258 if (submatch_info == NULL) 259 continue; 260 } 261 262 if (submatch_info != NULL) 263 printf("Patching %s for %s (%s)\n", 264 promstr, p->name, submatch_info); 265 else 266 printf("Patching %s for %s\n", 267 promstr, p->name); 268 for (e = p->patches; e->message != NULL; ++e) { 269 printf("%s", e->message); 270 prom_interpret(e->patch); 271 printf("\n"); 272 } 273 return; 274 } 275 } 276 } 277