Home | History | Annotate | Line # | Download | only in boot
prompatch.c revision 1.3
      1 /*	$NetBSD: prompatch.c,v 1.3 2001/11/22 04:18:28 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.x
     57  */
     58 static struct patch_entry patch_js1_obp2[] = {
     59 
     60 /*
     61  * Give "su" (com port) "interrupts" property.
     62  */
     63 { "su: adding \"interrupts\"",
     64 	"\" /obio/su\" open-dev"
     65 	" d# 13 \" interrupts\" integer-attribute"
     66 	" close-dev"
     67 },
     68 
     69 /*
     70  * TODO: Create "8042" (pckbc) node.
     71  *       Delete "zs"
     72  */
     73 
     74 { NULL, NULL }
     75 };
     76 
     77 
     78 /*
     79  * Patches for JavaStation 1 with OBP 3.* (OpenFirmware).
     80  * PROM in these machines is crippled in many ways.
     81  */
     82 static struct patch_entry patch_js1_ofw[] = {
     83 
     84 /*
     85  * JS1/OFW has no cpu node in the device tree.  Create one to save us a
     86  * _lot_ of headache in cpu.c and mainbus_attach.  Mostly copied from
     87  * OBP2.  While clock-frequency is usually at the root node, add it
     88  * here for brevity as kernel checks cpu node for this property anyway.
     89  */
     90 { "cpu: creating node ", /* NB: space at the end is intentional */
     91 	"0 0 0 0 \" /\" begin-package"
     92 	" \" FMI,MB86904\" device-name" /* NB: will print the name */
     93 	" \" cpu\" device-type"
     94 	" 0 \" mid\" integer-property"
     95 
     96 	" 8 \" sparc-version\" integer-property"
     97 	" 4 \" version\" integer-property"
     98 	" 0 \" implementation\" integer-property"
     99 	" 4 \" psr-version\" integer-property"
    100  	" 0 \" psr-implementation\" integer-property"
    101 
    102 	" d# 100000000 \" clock-frequency\" integer-property"
    103 
    104 	" d# 4096 \" page-size\" integer-property"
    105 	" d# 256 \" mmu-nctx\" integer-property"
    106 
    107 	" 2 \" ncaches\" integer-property"
    108 
    109 	" d# 512 \" icache-nlines\" integer-property"
    110 	" d# 32 \" icache-line-size\" integer-property"
    111 	" 1 \" icache-associativity\" integer-property"
    112 
    113 	" d# 512 \" dcache-nlines\" integer-property"
    114 	" d# 16 \" dcache-line-size\" integer-property"
    115 	" 1 \" dcache-associativity\" integer-property"
    116 
    117 	" 0 0 \" cache-physical?\" property"
    118 	" 0 0 \" cache-coherence?\" property"
    119 
    120 	" end-package"
    121 },
    122 
    123 /*
    124  * mk48txx_attach needs a model name, spare clockattach from guesswork.
    125  */
    126 { "eeprom: adding \"model\"",
    127 	"dev /obio/eeprom \" mk48t08\" model device-end"
    128 },
    129 
    130 /*
    131  * "interrupts" property is bogusly zero, delete it and let
    132  * sbus_get_intr fallback to correct "intr" property
    133  */
    134 { "le: deleting bogus \"interrupts\"",
    135 	"dev /sbus/ledma/le \" interrupts\" delete-property device-end"
    136 },
    137 
    138 /*
    139  * Give "su" (com port) "interrupts" property.
    140  */
    141 { "su: adding \"interrupts\"",
    142 	"dev /obio/su d# 13 \" interrupts\" integer-property device-end"
    143 },
    144 
    145 /*
    146  * Give "8042" (pckbc) "interrupts" property.
    147  */
    148 { "8042: adding \"interrupts\"",
    149 	"dev /obio/8042 d# 13 \" interrupts\" integer-property device-end"
    150 },
    151 
    152 { NULL, NULL }
    153 }; /* patch_js1_ofw */
    154 
    155 
    156 
    157 static struct prom_patch prom_patch_tab[] = {
    158 	{ "SUNW,JavaStation-1", PROM_OBP_V2,	patch_js1_obp2	},
    159 	{ "SUNW,JDM1",		PROM_OPENFIRM,	patch_js1_ofw	},
    160 	{ NULL, 0, NULL }
    161 };
    162 
    163 
    164 /*
    165  * Check if this machine needs tweaks to its PROM.  It's simpler to
    166  * fix PROM than to invent workarounds in the kernel code.  We do this
    167  * patching in the secondary boot to avoid wasting space in the kernel.
    168  */
    169 void
    170 prom_patch(void)
    171 {
    172 	char namebuf[32];
    173 	char *propval;
    174 	struct prom_patch *p;
    175 
    176 	if (prom_version() == PROM_OLDMON)
    177 		return;		/* don't bother - no forth in this */
    178 
    179 	propval = PROM_getpropstringA(prom_findroot(), "name",
    180 				 namebuf, sizeof(namebuf));
    181 	if (propval == NULL)
    182 		return;
    183 
    184 	for (p = prom_patch_tab; p->name != NULL; ++p) {
    185 		if (p->promvers == prom_version()
    186 		    && strcmp(p->name, namebuf) == 0) {
    187 			struct patch_entry *e;
    188 			const char *promstr = "???";
    189 
    190 			switch (prom_version()) {
    191 			case PROM_OBP_V0:
    192 				promstr = "OBP0";
    193 				break;
    194 			case PROM_OBP_V2:
    195 				promstr = "OBP2";
    196 				break;
    197 			case PROM_OBP_V3:
    198 				promstr = "OBP3";
    199 				break;
    200 			case PROM_OPENFIRM:
    201 				promstr = "OFW";
    202 				break;
    203 			}
    204 
    205 			printf("Patching %s for %s\n", promstr, p->name);
    206 			for (e = p->patches; e->message != NULL; ++e) {
    207 				printf("%s", e->message);
    208 				prom_interpret(e->patch);
    209 				printf("\n");
    210 			}
    211 			return;
    212 		}
    213 	}
    214 }
    215