1 /* $NetBSD: prompatch.c,v 1.5 2002/01/11 01:44:32 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 * Patches for JavaStation 1 with OBP 2.30 57 * NB: its romvec is version 3, so this is PROM_OBP_V3. 58 */ 59 static struct patch_entry patch_js1_obp[] = { 60 61 /* 62 * Can not remove a node, so just rename bogus /obio/zs so that it 63 * does not get matched. 64 */ 65 { "zs: renaming out of the way", 66 "\" /obio/zs@0,0\" find-device \" fakezs\" name" 67 " \" /obio/zs@0,100000\" find-device \" fakezs\" name " 68 " device-end" 69 }, 70 71 /* 72 * Give "su" (com port) "interrupts" property. 73 */ 74 { "su: adding \"interrupts\"", 75 "\" /obio/su\" find-device" 76 " d# 13 \" interrupts\" integer-attribute" 77 " device-end" 78 }, 79 80 /* 81 * Create a bare-bones "8042" (pckbc) node - just enough to attach it. 82 */ 83 { "8042: creating node", 84 "0 0 0 0 \" /obio\" begin-package" 85 " \" 8042\" name" 86 " 300060 0 8 reg" 87 " d# 13 \" interrupts\" integer-attribute" 88 " end-package" 89 }, 90 91 { NULL, NULL } 92 }; /* patch_js1_obp */ 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_V3, patch_js1_obp }, 176 { "SUNW,JDM1", PROM_OPENFIRM, patch_js1_ofw }, 177 { NULL, 0, NULL } 178 }; 179 180 181 /* 182 * Check if this machine needs tweaks to its PROM. It's simpler to 183 * fix PROM than to invent workarounds in the kernel code. We do this 184 * patching in the secondary boot to avoid wasting space in the kernel. 185 */ 186 void 187 prom_patch(void) 188 { 189 char namebuf[32]; 190 char *propval; 191 struct prom_patch *p; 192 193 if (prom_version() == PROM_OLDMON) 194 return; /* don't bother - no forth in this */ 195 196 propval = PROM_getpropstringA(prom_findroot(), "name", 197 namebuf, sizeof(namebuf)); 198 if (propval == NULL) 199 return; 200 201 for (p = prom_patch_tab; p->name != NULL; ++p) { 202 if (p->promvers == prom_version() 203 && strcmp(p->name, namebuf) == 0) { 204 struct patch_entry *e; 205 const char *promstr = "???"; 206 207 switch (prom_version()) { 208 case PROM_OBP_V0: 209 promstr = "OBP0"; 210 break; 211 case PROM_OBP_V2: 212 promstr = "OBP2"; 213 break; 214 case PROM_OBP_V3: 215 promstr = "OBP3"; 216 break; 217 case PROM_OPENFIRM: 218 promstr = "OFW"; 219 break; 220 } 221 222 printf("Patching %s for %s\n", promstr, p->name); 223 for (e = p->patches; e->message != NULL; ++e) { 224 printf("%s", e->message); 225 prom_interpret(e->patch); 226 printf("\n"); 227 } 228 return; 229 } 230 } 231 } 232