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