Home | History | Annotate | Line # | Download | only in boot
prompatch.c revision 1.2.4.4
      1  1.2.4.4  nathanw /*	$NetBSD: prompatch.c,v 1.2.4.4 2002/02/28 04:12:09 nathanw Exp $ */
      2  1.2.4.2  nathanw 
      3  1.2.4.2  nathanw /*
      4  1.2.4.2  nathanw  * Copyright (c) 2001 Valeriy E. Ushakov
      5  1.2.4.2  nathanw  * All rights reserved.
      6  1.2.4.2  nathanw  *
      7  1.2.4.2  nathanw  * Redistribution and use in source and binary forms, with or without
      8  1.2.4.2  nathanw  * modification, are permitted provided that the following conditions
      9  1.2.4.2  nathanw  * are met:
     10  1.2.4.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     11  1.2.4.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     12  1.2.4.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.2.4.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     14  1.2.4.2  nathanw  *    documentation and/or other materials provided with the distribution.
     15  1.2.4.2  nathanw  * 3. The name of the author may not be used to endorse or promote products
     16  1.2.4.2  nathanw  *    derived from this software without specific prior written permission
     17  1.2.4.2  nathanw  *
     18  1.2.4.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.2.4.2  nathanw  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.2.4.2  nathanw  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.2.4.2  nathanw  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.2.4.2  nathanw  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  1.2.4.2  nathanw  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  1.2.4.2  nathanw  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  1.2.4.2  nathanw  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  1.2.4.2  nathanw  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  1.2.4.2  nathanw  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  1.2.4.2  nathanw  */
     29  1.2.4.2  nathanw 
     30  1.2.4.2  nathanw #include <sys/param.h>
     31  1.2.4.2  nathanw #include <lib/libsa/stand.h>
     32  1.2.4.2  nathanw #include <machine/promlib.h>
     33  1.2.4.2  nathanw 
     34  1.2.4.2  nathanw void prom_patch(void);
     35  1.2.4.2  nathanw 
     36  1.2.4.2  nathanw /*
     37  1.2.4.2  nathanw  * Each patch entry is processed by:
     38  1.2.4.2  nathanw  * printf(message);  prom_interpret(patch);  printf("\n");
     39  1.2.4.2  nathanw  */
     40  1.2.4.2  nathanw struct patch_entry {
     41  1.2.4.2  nathanw 	char *message;
     42  1.2.4.2  nathanw 	char *patch;
     43  1.2.4.2  nathanw };
     44  1.2.4.2  nathanw 
     45  1.2.4.2  nathanw /*
     46  1.2.4.2  nathanw  * PROM patches to apply to machine matching name/promvers.
     47  1.2.4.2  nathanw  */
     48  1.2.4.2  nathanw struct prom_patch {
     49  1.2.4.2  nathanw 	char *name;		/* "name" of the root node */
     50  1.2.4.2  nathanw 	int promvers;		/* prom_version() */
     51  1.2.4.2  nathanw 	struct patch_entry *patches;
     52  1.2.4.2  nathanw };
     53  1.2.4.2  nathanw 
     54  1.2.4.2  nathanw 
     55  1.2.4.2  nathanw /*
     56  1.2.4.3  nathanw  * Patches for JavaStation 1 with OBP 2.30
     57  1.2.4.3  nathanw  * NB: its romvec is version 3, so this is PROM_OBP_V3.
     58  1.2.4.2  nathanw  */
     59  1.2.4.3  nathanw static struct patch_entry patch_js1_obp[] = {
     60  1.2.4.2  nathanw 
     61  1.2.4.2  nathanw /*
     62  1.2.4.3  nathanw  * Can not remove a node, so just rename bogus /obio/zs so that it
     63  1.2.4.3  nathanw  * does not get matched.
     64  1.2.4.2  nathanw  */
     65  1.2.4.3  nathanw { "zs: renaming out of the way",
     66  1.2.4.3  nathanw 	"\" /obio/zs@0,0\" find-device \" fakezs\" name"
     67  1.2.4.3  nathanw 	" \" /obio/zs@0,100000\" find-device \" fakezs\" name "
     68  1.2.4.3  nathanw 	" device-end"
     69  1.2.4.2  nathanw },
     70  1.2.4.2  nathanw 
     71  1.2.4.2  nathanw /*
     72  1.2.4.2  nathanw  * Give "su" (com port) "interrupts" property.
     73  1.2.4.2  nathanw  */
     74  1.2.4.2  nathanw { "su: adding \"interrupts\"",
     75  1.2.4.3  nathanw 	"\" /obio/su\" find-device"
     76  1.2.4.2  nathanw 	" d# 13 \" interrupts\" integer-attribute"
     77  1.2.4.2  nathanw 	" device-end"
     78  1.2.4.2  nathanw },
     79  1.2.4.2  nathanw 
     80  1.2.4.3  nathanw /*
     81  1.2.4.3  nathanw  * Create a bare-bones "8042" (pckbc) node - just enough to attach it.
     82  1.2.4.3  nathanw  */
     83  1.2.4.3  nathanw { "8042: creating node",
     84  1.2.4.3  nathanw 	"0 0 0 0 \" /obio\" begin-package"
     85  1.2.4.3  nathanw 	" \" 8042\" name"
     86  1.2.4.3  nathanw 	" 300060 0 8 reg"
     87  1.2.4.3  nathanw 	" d# 13 \" interrupts\" integer-attribute"
     88  1.2.4.3  nathanw 	" end-package"
     89  1.2.4.3  nathanw },
     90  1.2.4.3  nathanw 
     91  1.2.4.2  nathanw { NULL, NULL }
     92  1.2.4.3  nathanw }; /* patch_js1_obp */
     93  1.2.4.3  nathanw 
     94  1.2.4.2  nathanw 
     95  1.2.4.2  nathanw /*
     96  1.2.4.2  nathanw  * Patches for JavaStation 1 with OpenFirmware.
     97  1.2.4.2  nathanw  * PROM in these machines is crippled in many ways.
     98  1.2.4.2  nathanw  */
     99  1.2.4.2  nathanw static struct patch_entry patch_js1_ofw[] = {
    100  1.2.4.2  nathanw 
    101  1.2.4.2  nathanw /*
    102  1.2.4.2  nathanw  * JS1/OFW has no cpu node in the device tree.  Create one to save us a
    103  1.2.4.2  nathanw  * _lot_ of headache in cpu.c and mainbus_attach.  Mostly copied from
    104  1.2.4.2  nathanw  * OBP2.  While clock-frequency is usually at the root node, add it
    105  1.2.4.2  nathanw  * here for brevity as kernel checks cpu node for this property anyway.
    106  1.2.4.2  nathanw  */
    107  1.2.4.2  nathanw { "cpu: creating node ", /* NB: space at the end is intentional */
    108  1.2.4.2  nathanw 	"0 0 0 0 \" /\" begin-package"
    109  1.2.4.2  nathanw 	" \" FMI,MB86904\" device-name" /* NB: will print the name */
    110  1.2.4.2  nathanw 	" \" cpu\" device-type"
    111  1.2.4.2  nathanw 	" 0 \" mid\" integer-property"
    112  1.2.4.2  nathanw 
    113  1.2.4.2  nathanw 	" 8 \" sparc-version\" integer-property"
    114  1.2.4.2  nathanw 	" 4 \" version\" integer-property"
    115  1.2.4.2  nathanw 	" 0 \" implementation\" integer-property"
    116  1.2.4.2  nathanw 	" 4 \" psr-version\" integer-property"
    117  1.2.4.2  nathanw  	" 0 \" psr-implementation\" integer-property"
    118  1.2.4.2  nathanw 
    119  1.2.4.2  nathanw 	" d# 100000000 \" clock-frequency\" integer-property"
    120  1.2.4.2  nathanw 
    121  1.2.4.2  nathanw 	" d# 4096 \" page-size\" integer-property"
    122  1.2.4.2  nathanw 	" d# 256 \" mmu-nctx\" integer-property"
    123  1.2.4.2  nathanw 
    124  1.2.4.2  nathanw 	" 2 \" ncaches\" integer-property"
    125  1.2.4.2  nathanw 
    126  1.2.4.2  nathanw 	" d# 512 \" icache-nlines\" integer-property"
    127  1.2.4.2  nathanw 	" d# 32 \" icache-line-size\" integer-property"
    128  1.2.4.2  nathanw 	" 1 \" icache-associativity\" integer-property"
    129  1.2.4.2  nathanw 
    130  1.2.4.2  nathanw 	" d# 512 \" dcache-nlines\" integer-property"
    131  1.2.4.2  nathanw 	" d# 16 \" dcache-line-size\" integer-property"
    132  1.2.4.2  nathanw 	" 1 \" dcache-associativity\" integer-property"
    133  1.2.4.2  nathanw 
    134  1.2.4.2  nathanw 	" 0 0 \" cache-physical?\" property"
    135  1.2.4.2  nathanw 	" 0 0 \" cache-coherence?\" property"
    136  1.2.4.2  nathanw 
    137  1.2.4.2  nathanw 	" end-package"
    138  1.2.4.2  nathanw },
    139  1.2.4.2  nathanw 
    140  1.2.4.2  nathanw /*
    141  1.2.4.2  nathanw  * mk48txx_attach needs a model name, spare clockattach from guesswork.
    142  1.2.4.2  nathanw  */
    143  1.2.4.2  nathanw { "eeprom: adding \"model\"",
    144  1.2.4.2  nathanw 	"dev /obio/eeprom \" mk48t08\" model device-end"
    145  1.2.4.2  nathanw },
    146  1.2.4.2  nathanw 
    147  1.2.4.2  nathanw /*
    148  1.2.4.2  nathanw  * "interrupts" property is bogusly zero, delete it and let
    149  1.2.4.2  nathanw  * sbus_get_intr fallback to correct "intr" property
    150  1.2.4.2  nathanw  */
    151  1.2.4.2  nathanw { "le: deleting bogus \"interrupts\"",
    152  1.2.4.2  nathanw 	"dev /sbus/ledma/le \" interrupts\" delete-property device-end"
    153  1.2.4.2  nathanw },
    154  1.2.4.2  nathanw 
    155  1.2.4.2  nathanw /*
    156  1.2.4.2  nathanw  * Give "su" (com port) "interrupts" property.
    157  1.2.4.2  nathanw  */
    158  1.2.4.2  nathanw { "su: adding \"interrupts\"",
    159  1.2.4.2  nathanw 	"dev /obio/su d# 13 \" interrupts\" integer-property device-end"
    160  1.2.4.2  nathanw },
    161  1.2.4.2  nathanw 
    162  1.2.4.2  nathanw /*
    163  1.2.4.2  nathanw  * Give "8042" (pckbc) "interrupts" property.
    164  1.2.4.2  nathanw  */
    165  1.2.4.2  nathanw { "8042: adding \"interrupts\"",
    166  1.2.4.2  nathanw 	"dev /obio/8042 d# 13 \" interrupts\" integer-property device-end"
    167  1.2.4.2  nathanw },
    168  1.2.4.2  nathanw 
    169  1.2.4.2  nathanw { NULL, NULL }
    170  1.2.4.2  nathanw }; /* patch_js1_ofw */
    171  1.2.4.2  nathanw 
    172  1.2.4.2  nathanw 
    173  1.2.4.2  nathanw 
    174  1.2.4.2  nathanw static struct prom_patch prom_patch_tab[] = {
    175  1.2.4.3  nathanw 	{ "SUNW,JavaStation-1", PROM_OBP_V3,	patch_js1_obp	},
    176  1.2.4.2  nathanw 	{ "SUNW,JDM1",		PROM_OPENFIRM,	patch_js1_ofw	},
    177  1.2.4.2  nathanw 	{ NULL, 0, NULL }
    178  1.2.4.2  nathanw };
    179  1.2.4.2  nathanw 
    180  1.2.4.2  nathanw 
    181  1.2.4.2  nathanw /*
    182  1.2.4.2  nathanw  * Check if this machine needs tweaks to its PROM.  It's simpler to
    183  1.2.4.2  nathanw  * fix PROM than to invent workarounds in the kernel code.  We do this
    184  1.2.4.2  nathanw  * patching in the secondary boot to avoid wasting space in the kernel.
    185  1.2.4.2  nathanw  */
    186  1.2.4.2  nathanw void
    187  1.2.4.2  nathanw prom_patch(void)
    188  1.2.4.2  nathanw {
    189  1.2.4.2  nathanw 	char namebuf[32];
    190  1.2.4.2  nathanw 	char *propval;
    191  1.2.4.2  nathanw 	struct prom_patch *p;
    192  1.2.4.2  nathanw 
    193  1.2.4.2  nathanw 	if (prom_version() == PROM_OLDMON)
    194  1.2.4.2  nathanw 		return;		/* don't bother - no forth in this */
    195  1.2.4.2  nathanw 
    196  1.2.4.2  nathanw 	propval = PROM_getpropstringA(prom_findroot(), "name",
    197  1.2.4.2  nathanw 				 namebuf, sizeof(namebuf));
    198  1.2.4.2  nathanw 	if (propval == NULL)
    199  1.2.4.2  nathanw 		return;
    200  1.2.4.2  nathanw 
    201  1.2.4.2  nathanw 	for (p = prom_patch_tab; p->name != NULL; ++p) {
    202  1.2.4.2  nathanw 		if (p->promvers == prom_version()
    203  1.2.4.2  nathanw 		    && strcmp(p->name, namebuf) == 0) {
    204  1.2.4.2  nathanw 			struct patch_entry *e;
    205  1.2.4.2  nathanw 			const char *promstr = "???";
    206  1.2.4.2  nathanw 
    207  1.2.4.2  nathanw 			switch (prom_version()) {
    208  1.2.4.2  nathanw 			case PROM_OBP_V0:
    209  1.2.4.2  nathanw 				promstr = "OBP0";
    210  1.2.4.2  nathanw 				break;
    211  1.2.4.2  nathanw 			case PROM_OBP_V2:
    212  1.2.4.2  nathanw 				promstr = "OBP2";
    213  1.2.4.2  nathanw 				break;
    214  1.2.4.2  nathanw 			case PROM_OBP_V3:
    215  1.2.4.2  nathanw 				promstr = "OBP3";
    216  1.2.4.2  nathanw 				break;
    217  1.2.4.2  nathanw 			case PROM_OPENFIRM:
    218  1.2.4.2  nathanw 				promstr = "OFW";
    219  1.2.4.2  nathanw 				break;
    220  1.2.4.2  nathanw 			}
    221  1.2.4.2  nathanw 
    222  1.2.4.2  nathanw 			printf("Patching %s for %s\n", promstr, p->name);
    223  1.2.4.2  nathanw 			for (e = p->patches; e->message != NULL; ++e) {
    224  1.2.4.2  nathanw 				printf("%s", e->message);
    225  1.2.4.2  nathanw 				prom_interpret(e->patch);
    226  1.2.4.2  nathanw 				printf("\n");
    227  1.2.4.2  nathanw 			}
    228  1.2.4.2  nathanw 			return;
    229  1.2.4.2  nathanw 		}
    230  1.2.4.2  nathanw 	}
    231  1.2.4.2  nathanw }
    232