summaryrefslogtreecommitdiff
path: root/sys/arch/sparc/stand/boot/prompatch.c
blob: 6d547369b42e5c8ca7bb9481da471db9016443cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*	$NetBSD: prompatch.c,v 1.12 2005/12/11 12:19:08 christos Exp $ */

/*
 * Copyright (c) 2001 Valeriy E. Ushakov
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/param.h>
#include <lib/libsa/stand.h>
#include <lib/libkern/libkern.h>
#include <machine/promlib.h>


void prom_patch(void);

static const char *match_c5ip(void);


/*
 * Each patch entry is processed by:
 * printf(message);  prom_interpret(patch);  printf("\n");
 */
struct patch_entry {
	const char *message;
	const char *patch;
};


/*
 * PROM patches to apply to machine matching name/promvers.
 */
struct prom_patch {
	const char *name;		/* "name" of the root node */
	int promvers;			/* prom_version() */
	const char *(*submatch)(void);	/* Additional matches to test */
	const struct patch_entry *patches;	/* The patches themselves */
};


/*
 * Patches for JavaStation 1 with OBP 2.30.
 * NB: its romvec is version 3, so this is PROM_OBP_V3.
 */
static const struct patch_entry patch_js1_obp[] = {

/*
 * Can not remove a node, so just rename bogus /obio/zs so that it
 * does not get matched.
 */
{ "zs: renaming out of the way",
	"\" /obio/zs@0,0\" find-device \" fakezs\" name"
	" \" /obio/zs@0,100000\" find-device \" fakezs\" name "
	" device-end"
},

/*
 * Give "su" (com port) "interrupts" property.
 */
{ "su: adding \"interrupts\"",
	"\" /obio/su\" find-device"
	" d# 13 \" interrupts\" integer-attribute"
	" device-end"
},

/*
 * Create a bare-bones "8042" (pckbc) node - just enough to attach it.
 */
{ "8042: creating node",
	"0 0 0 0 \" /obio\" begin-package"
	" \" 8042\" name"
	" 300060 0 8 reg"
	" d# 13 \" interrupts\" integer-attribute"
	" end-package"
},

{ NULL, NULL }
}; /* patch_js1_obp */


/*
 * Patches for JavaStation 1 with OpenFirmware.
 * PROM in these machines is crippled in many ways.
 */
static const struct patch_entry patch_js1_ofw[] = {

/*
 * JS1/OFW has no CPU node in the device tree.  Create one to save us a
 * _lot_ of headache in cpu.c and mainbus_attach.  Mostly copied from
 * OBP2.  While clock-frequency is usually at the root node, add it
 * here for brevity as kernel checks CPU node for this property anyway.
 */
{ "cpu: creating node ", /* NB: space at the end is intentional */
	"0 0 0 0 \" /\" begin-package"
	" \" FMI,MB86904\" device-name" /* NB: will print the name */
	" \" cpu\" device-type"
	" 0 \" mid\" integer-property"

	" 8 \" sparc-version\" integer-property"
	" 4 \" version\" integer-property"
	" 0 \" implementation\" integer-property"
	" 4 \" psr-version\" integer-property"
 	" 0 \" psr-implementation\" integer-property"

	" d# 100000000 \" clock-frequency\" integer-property"

	" d# 4096 \" page-size\" integer-property"
	" d# 256 \" mmu-nctx\" integer-property"

	" 2 \" ncaches\" integer-property"

	" d# 512 \" icache-nlines\" integer-property"
	" d# 32 \" icache-line-size\" integer-property"
	" 1 \" icache-associativity\" integer-property"

	" d# 512 \" dcache-nlines\" integer-property"
	" d# 16 \" dcache-line-size\" integer-property"
	" 1 \" dcache-associativity\" integer-property"

	" 0 0 \" cache-physical?\" property"
	" 0 0 \" cache-coherence?\" property"

	" end-package"
},

/*
 * mk48txx_attach needs a model name, spare clockattach from guesswork.
 */
{ "eeprom: adding \"model\"",
	"dev /obio/eeprom \" mk48t08\" model device-end"
},

/* 
 * "interrupts" property is bogusly zero, delete it and let
 * sbus_get_intr fallback to correct "intr" property.
 */
{ "le: deleting bogus \"interrupts\"",
	"dev /sbus/ledma/le \" interrupts\" delete-property device-end"
},

/*
 * Give "su" (com port) "interrupts" property.
 */
{ "su: adding \"interrupts\"",
	"dev /obio/su d# 13 \" interrupts\" integer-property device-end"
},
    
/*
 * Give "8042" (pckbc) "interrupts" property.
 */
{ "8042: adding \"interrupts\"",
	"dev /obio/8042 d# 13 \" interrupts\" integer-property device-end"
},
    
{ NULL, NULL }
}; /* patch_js1_ofw */


/*
 * Patches for Cycle 5 IP.
 */
static const struct patch_entry patch_c5ip[] = {

/*
 * Can not remove a node, so just rename bogus /iommu/sbus/SUNW,CS4231
 * so that it does not get matched.
 */
{ "SUNW,CS4231: renaming out of the way",
	"\" /iommu/sbus/SUNW,CS4231@3,c000000\" find-device \" fakeCS4231\" name"
	" device-end"
},
    
{ NULL, NULL }
}; /* patch_c5ip */


/*
 * Patches for JavaStation NC, aka Krups.
 */
static const struct patch_entry patch_krups[] = {

/*
 * Check if there's a node for the audio chip, if not create it.
 */
{ "sound device node: ",
	"\" /pci/ebus/sound\" ' find-device catch"
	" 0= if"
		" device-end"
		" \" ok\""
	" else"
		" 0 0 0 0 \" /pci/ebus\" begin-package"
			" \" sound\" name" 
			" 200000 1 600 reg"
		" end-package"
		" \" created\""
	" then type"
},

{ NULL, NULL }
}; /* patch_krups */


static const struct prom_patch prom_patch_tab[] = {
	{ "SUNW,JavaStation-1",  PROM_OBP_V3,   NULL,	    patch_js1_obp },
	{ "SUNW,JDM1",		 PROM_OPENFIRM, NULL,	    patch_js1_ofw },
	{ "SUNW,SPARCstation-5", PROM_OBP_V3,   match_c5ip, patch_c5ip	  },
	{ "SUNW,JSIIep",	 PROM_OPENFIRM,	NULL,	    patch_krups   },
	{ NULL, 0, NULL }
};


/*
 * Additional match routine for Cycle 5 IP.
 * This uses the SPARCstation 5 PROM almost unchanged, so we check the
 * "banner-name" attribute of the root node.
 */
static const char *
match_c5ip(void)
{
	if (strcmp(prom_getpropstring(prom_findroot(), "banner-name"),
	    "Cycle Computer Corporation") == 0)
		 return "Cycle 5 IP";

	return NULL;
}


/*
 * Check if this machine needs tweaks to its PROM.  It's simpler to fix
 * the PROM than to invent workarounds in the kernel code.  We do this
 * patching in the secondary boot to avoid wasting space in the kernel.
 */
void
prom_patch(void)
{
	char namebuf[32];
	char *propval;
	const struct prom_patch *p;

	if (prom_version() == PROM_OLDMON)
		return;		/* don't bother - no forth in this */

	propval = prom_getpropstringA(prom_findroot(), "name",
				 namebuf, sizeof(namebuf));
	if (propval == NULL)
		return;

	for (p = prom_patch_tab; p->name != NULL; ++p) {
		if (p->promvers == prom_version()
		    && strcmp(p->name, namebuf) == 0) {
			const struct patch_entry *e;
			const char *promstr = "???";
			const char *submatch_info = NULL;

			switch (prom_version()) {
			case PROM_OBP_V0:
				promstr = "OBP0";
				break;
			case PROM_OBP_V2:
				promstr = "OBP2";
				break;
			case PROM_OBP_V3:
				promstr = "OBP3";
				break;
			case PROM_OPENFIRM:
				promstr = "OFW";
				break;
			}


			if (p->submatch != NULL) {
				submatch_info = (*p->submatch)();
				if (submatch_info == NULL)
					continue;
			}

			if (submatch_info != NULL)
				printf("Patching %s for %s (%s)\n",
				    promstr, p->name, submatch_info);
			else
				printf("Patching %s for %s\n",
				    promstr, p->name);
			for (e = p->patches; e->message != NULL; ++e) {
				printf("%s", e->message);
				prom_interpret(e->patch);
				printf("\n");
			}
			return;
		}
	}
}