1 /* $NetBSD: prompatch.c,v 1.6 2002/12/16 13:01:01 jdc 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 char *match_c5ip(void); 35 void prom_patch(void); 36 37 /* 38 * Each patch entry is processed by: 39 * printf(message); prom_interpret(patch); printf("\n"); 40 */ 41 struct patch_entry { 42 char *message; 43 char *patch; 44 }; 45 46 /* 47 * PROM patches to apply to machine matching name/promvers. 48 */ 49 struct prom_patch { 50 char *name; /* "name" of the root node */ 51 int promvers; /* prom_version() */ 52 char *(*submatch)(void); /* Additional matches to test */ 53 struct patch_entry *patches; /* The patches themselves */ 54 }; 55 56 /* 57 * Patches for JavaStation 1 with OBP 2.30 58 * NB: its romvec is version 3, so this is PROM_OBP_V3. 59 */ 60 static struct patch_entry patch_js1_obp[] = { 61 62 /* 63 * Can not remove a node, so just rename bogus /obio/zs so that it 64 * does not get matched. 65 */ 66 { "zs: renaming out of the way", 67 "\" /obio/zs@0,0\" find-device \" fakezs\" name" 68 " \" /obio/zs@0,100000\" find-device \" fakezs\" name " 69 " device-end" 70 }, 71 72 /* 73 * Give "su" (com port) "interrupts" property. 74 */ 75 { "su: adding \"interrupts\"", 76 "\" /obio/su\" find-device" 77 " d# 13 \" interrupts\" integer-attribute" 78 " device-end" 79 }, 80 81 /* 82 * Create a bare-bones "8042" (pckbc) node - just enough to attach it. 83 */ 84 { "8042: creating node", 85 "0 0 0 0 \" /obio\" begin-package" 86 " \" 8042\" name" 87 " 300060 0 8 reg" 88 " d# 13 \" interrupts\" integer-attribute" 89 " end-package" 90 }, 91 92 { NULL, NULL } 93 }; /* patch_js1_obp */ 94 95 96 /* 97 * Patches for JavaStation 1 with OpenFirmware. 98 * PROM in these machines is crippled in many ways. 99 */ 100 static struct patch_entry patch_js1_ofw[] = { 101 102 /* 103 * JS1/OFW has no cpu node in the device tree. Create one to save us a 104 * _lot_ of headache in cpu.c and mainbus_attach. Mostly copied from 105 * OBP2. While clock-frequency is usually at the root node, add it 106 * here for brevity as kernel checks cpu node for this property anyway. 107 */ 108 { "cpu: creating node ", /* NB: space at the end is intentional */ 109 "0 0 0 0 \" /\" begin-package" 110 " \" FMI,MB86904\" device-name" /* NB: will print the name */ 111 " \" cpu\" device-type" 112 " 0 \" mid\" integer-property" 113 114 " 8 \" sparc-version\" integer-property" 115 " 4 \" version\" integer-property" 116 " 0 \" implementation\" integer-property" 117 " 4 \" psr-version\" integer-property" 118 " 0 \" psr-implementation\" integer-property" 119 120 " d# 100000000 \" clock-frequency\" integer-property" 121 122 " d# 4096 \" page-size\" integer-property" 123 " d# 256 \" mmu-nctx\" integer-property" 124 125 " 2 \" ncaches\" integer-property" 126 127 " d# 512 \" icache-nlines\" integer-property" 128 " d# 32 \" icache-line-size\" integer-property" 129 " 1 \" icache-associativity\" integer-property" 130 131 " d# 512 \" dcache-nlines\" integer-property" 132 " d# 16 \" dcache-line-size\" integer-property" 133 " 1 \" dcache-associativity\" integer-property" 134 135 " 0 0 \" cache-physical?\" property" 136 " 0 0 \" cache-coherence?\" property" 137 138 " end-package" 139 }, 140 141 /* 142 * mk48txx_attach needs a model name, spare clockattach from guesswork. 143 */ 144 { "eeprom: adding \"model\"", 145 "dev /obio/eeprom \" mk48t08\" model device-end" 146 }, 147 148 /* 149 * "interrupts" property is bogusly zero, delete it and let 150 * sbus_get_intr fallback to correct "intr" property 151 */ 152 { "le: deleting bogus \"interrupts\"", 153 "dev /sbus/ledma/le \" interrupts\" delete-property device-end" 154 }, 155 156 /* 157 * Give "su" (com port) "interrupts" property. 158 */ 159 { "su: adding \"interrupts\"", 160 "dev /obio/su d# 13 \" interrupts\" integer-property device-end" 161 }, 162 163 /* 164 * Give "8042" (pckbc) "interrupts" property. 165 */ 166 { "8042: adding \"interrupts\"", 167 "dev /obio/8042 d# 13 \" interrupts\" integer-property device-end" 168 }, 169 170 { NULL, NULL } 171 }; /* patch_js1_ofw */ 172 173 /* 174 * Patches for Cycle 5 IP 175 */ 176 static struct patch_entry patch_c5ip[] = { 177 178 /* 179 * Can not remove a node, so just rename bogus /iommu/sbus/SUNW,CS4231 180 * so that it does not get matched. 181 */ 182 { "SUNW,CS4231: renaming out of the way", 183 "\" /iommu/sbus/SUNW,CS4231@3,c000000\" find-device \" fakeCS4231\" name" 184 " device-end" 185 }, 186 187 { NULL, NULL } 188 }; /* patch_c5ip */ 189 190 static struct prom_patch prom_patch_tab[] = { 191 { "SUNW,JavaStation-1", PROM_OBP_V3, NULL, patch_js1_obp }, 192 { "SUNW,JDM1", PROM_OPENFIRM, NULL, patch_js1_ofw }, 193 { "SUNW,SPARCstation-5", PROM_OBP_V3, match_c5ip, patch_c5ip }, 194 { NULL, 0, NULL } 195 }; 196 197 198 /* 199 * Additional match routine for Cycle 5 IP 200 * This uses the SPARCstation 5 PROM almost unchanged, so we check the 201 * "banner-name" attribute of the root node. 202 */ 203 char * match_c5ip(void) 204 { 205 if (strcmp(PROM_getpropstring(prom_findroot(), "banner-name"), 206 "Cycle Computer Corporation") == 0) 207 return "Cycle 5 IP"; 208 209 return NULL; 210 } 211 212 /* 213 * Check if this machine needs tweaks to its PROM. It's simpler to fix 214 * the PROM than to invent workarounds in the kernel code. We do this 215 * patching in the secondary boot to avoid wasting space in the kernel. 216 */ 217 void 218 prom_patch(void) 219 { 220 char namebuf[32]; 221 char *propval; 222 struct prom_patch *p; 223 224 if (prom_version() == PROM_OLDMON) 225 return; /* don't bother - no forth in this */ 226 227 propval = PROM_getpropstringA(prom_findroot(), "name", 228 namebuf, sizeof(namebuf)); 229 if (propval == NULL) 230 return; 231 232 for (p = prom_patch_tab; p->name != NULL; ++p) { 233 if (p->promvers == prom_version() 234 && strcmp(p->name, namebuf) == 0) { 235 struct patch_entry *e; 236 const char *promstr = "???"; 237 char *submatch_info = NULL; 238 239 switch (prom_version()) { 240 case PROM_OBP_V0: 241 promstr = "OBP0"; 242 break; 243 case PROM_OBP_V2: 244 promstr = "OBP2"; 245 break; 246 case PROM_OBP_V3: 247 promstr = "OBP3"; 248 break; 249 case PROM_OPENFIRM: 250 promstr = "OFW"; 251 break; 252 } 253 254 255 if (p->submatch != NULL) { 256 submatch_info = (*p->submatch)(); 257 if (submatch_info == NULL) 258 continue; 259 } 260 261 if (submatch_info != NULL) 262 printf("Patching %s for %s (%s)\n", 263 promstr, p->name, submatch_info); 264 else 265 printf("Patching %s for %s\n", 266 promstr, p->name); 267 for (e = p->patches; e->message != NULL; ++e) { 268 printf("%s", e->message); 269 prom_interpret(e->patch); 270 printf("\n"); 271 } 272 return; 273 } 274 } 275 } 276