summaryrefslogtreecommitdiff
path: root/sys/arch/mvmeppc/dev/bugio.c
blob: e986c5c4e768fd92776f9e63010f55e7361ee449 (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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
/*	$OpenBSD: bugio.c,v 1.2 2001/07/04 08:31:31 niklas Exp $	*/

/*
 * bug routines -- assumes that the necessary sections of memory
 * are preserved.
 */
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/types.h>
#include <machine/prom.h>


/* BUG - timing routine */
void
mvmeprom_delay(msec)
	int msec; /* This is r3 */
{
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));
	asm volatile ("mr 3, %0" :: "r"(msec));
	MVMEPROM_CALL(MVMEPROM_DELAY);
        ppc_set_msr(omsr);
}

/* returns 0: success, nonzero: error */
int
mvmeprom_diskrd(arg)
	struct mvmeprom_dskio *arg;
{
	int ret;
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));

	asm volatile ("mr 3, %0" :: "r"(arg));
	MVMEPROM_CALL(MVMEPROM_NETRD);
	asm volatile ("mr %0, 3" :  "=r" (ret));
        ppc_set_msr(omsr);
	return ((ret & 0x8));
}

/* returns 0: success, nonzero: error */
int
mvmeprom_diskwr(arg)
	struct mvmeprom_dskio *arg;
{
	int ret;
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));

	asm volatile ("mr 3, %0" :: "r"(arg));
	MVMEPROM_CALL(MVMEPROM_DSKWR);
	asm volatile ("mr %0, 3" :  "=r" (ret));
        ppc_set_msr(omsr);
	return ((ret & 0x8));
}

/* BUG - query board routines */
struct mvmeprom_brdid *
mvmeprom_brdid()
{
	struct mvmeprom_brdid *id;
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));

	MVMEPROM_CALL(MVMEPROM_BRD_ID);
	asm volatile ("mr %0, 3": "=r" (id):);
        ppc_set_msr(omsr);
	return (id);
}

/* returns 0 if no characters ready to read */
int
mvmeprom_getchar()
{
	int ret;
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));

	MVMEPROM_CALL(MVMEPROM_INCHR);
	asm volatile ("mr %0, 3" :  "=r" (ret));
        ppc_set_msr(omsr);
	return ret;
}

/* returns 0 if no characters ready to read */
int
mvmeprom_instat()
{
	int ret;
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));

	MVMEPROM_CALL(MVMEPROM_INSTAT);
	asm volatile ("mr %0, 3" :  "=r" (ret));
        ppc_set_msr(omsr);
	return (!(ret & 0x4));
}

/* returns 0: success, nonzero: error */
int
mvmeprom_netctrl(arg)
	struct mvmeprom_netctrl *arg;
{
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));
	asm volatile ("mr 3, %0":: "r" (arg));
	MVMEPROM_CALL(MVMEPROM_NETCTRL);
        ppc_set_msr(omsr);
	return (arg->status);
}

int 
mvmeprom_netctrl_init(clun, dlun)
u_char	clun;
u_char	dlun;
{
	struct mvmeprom_netctrl niocall;
	niocall.clun = clun;
	niocall.dlun = dlun;
	niocall.status = 0;
	niocall.cmd = 0; /* init */
	niocall.addr = 0;
	niocall.len = 0;
	niocall.flags = 0;
	mvmeprom_netctrl(&niocall);
	return(niocall.status);
}

int 
mvmeprom_netctrl_hwa(clun, dlun, addr, len)
u_char	clun;
u_char	dlun;
void 	*addr;
u_long  *len;
{
	struct mvmeprom_netctrl niocall;
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));
	niocall.clun = clun;
	niocall.dlun = dlun;
	niocall.status = 0;
	niocall.cmd = 1; /* get hw address */
	niocall.addr = addr;
	niocall.len = *len;
	niocall.flags = 0;
	mvmeprom_netctrl(&niocall);
	*len = niocall.len;
	return(niocall.status);
}

int 
mvmeprom_netctrl_tx(clun, dlun, addr, len)
u_char	clun;
u_char	dlun;
void 	*addr;
u_long  *len;
{
	struct mvmeprom_netctrl niocall;
	niocall.clun = clun;
	niocall.dlun = dlun;
	niocall.status = 0;
	niocall.cmd = 2; /* transmit */
	niocall.addr = addr;
	niocall.len = *len;
	niocall.flags = 0;
	mvmeprom_netctrl(&niocall);
	*len = niocall.len;
	return(niocall.status);
}

int 
mvmeprom_netctrl_rx(clun, dlun, addr, len)
u_char	clun;
u_char	dlun;
void 	*addr;
u_long  *len;
{
	struct mvmeprom_netctrl niocall;
	niocall.clun = clun;
	niocall.dlun = dlun;
	niocall.status = 0;
	niocall.cmd = 3; /* receive */
	niocall.addr = addr;
	niocall.len = *len;
	niocall.flags = 0;
	mvmeprom_netctrl(&niocall);
	*len = niocall.len;
	return(niocall.status);
}

int 
mvmeprom_netctrl_flush_rx(clun, dlun)
u_char	clun;
u_char	dlun;
{
	struct mvmeprom_netctrl niocall;
	niocall.clun = clun;
	niocall.dlun = dlun;
	niocall.status = 0;
	niocall.cmd = 4; /* reset */
	niocall.addr = 0;
	niocall.len = 0;
	niocall.flags = 0;
	mvmeprom_netctrl(&niocall);
	return(niocall.status);
}

int 
mvmeprom_netctrl_reset(clun, dlun)
u_char	clun;
u_char	dlun;
{
	struct mvmeprom_netctrl niocall;
	niocall.clun = clun;
	niocall.dlun = dlun;
	niocall.status = 0;
	niocall.cmd = 5; /* reset */
	niocall.addr = 0;
	niocall.len = 0;
	niocall.flags = 0;
	mvmeprom_netctrl(&niocall);
	return(niocall.status);
}

/* returns 0: success, nonzero: error */
int
mvmeprom_netfopen(arg)
	struct mvmeprom_netfopen *arg;
{
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));
	asm volatile ("mr 3, %0": : "r" (arg));
	MVMEPROM_CALL(MVMEPROM_NETFOPEN);
        ppc_set_msr(omsr);
	return (arg->status);
}

/* returns 0: success, nonzero: error */
int
mvmeprom_netfread(arg)
	struct mvmeprom_netfread *arg;
{
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));
	asm volatile ("mr 3, %0": : "r" (arg));
	MVMEPROM_CALL(MVMEPROM_NETFREAD);
        ppc_set_msr(omsr);
	return (arg->status);
}

/* returns 0: success, nonzero: error */
int
mvmeprom_netrd(arg)
	struct mvmeprom_netio *arg;
{
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));
	asm volatile ("mr 3, %0": : "r" (arg));
	MVMEPROM_CALL(MVMEPROM_NETRD);
        ppc_set_msr(omsr);
	return (arg->status);
}

/* returns 0: success, nonzero: error */
int
mvmeprom_netwr(arg)
	struct mvmeprom_netio *arg;
{
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));
	asm volatile ("mr 3, %0": : "r" (arg));
	MVMEPROM_CALL(MVMEPROM_NETWR);
        ppc_set_msr(omsr);
	return (arg->status);
}

void
mvmeprom_outln(start, end)
	char *start, *end;
{
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));
	asm volatile ("mr 3, %0": : "r" (start));
	asm volatile ("mr 4, %0": : "r" (end));
	MVMEPROM_CALL(MVMEPROM_OUTLN);
        ppc_set_msr(omsr);
}

void
mvmeprom_outstr(start, end)
	char *start, *end;
{
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));
	asm volatile ("mr 3, %0": : "r" (start));
	asm volatile ("mr 4, %0": : "r" (end));
	MVMEPROM_CALL(MVMEPROM_OUTSTR);
        ppc_set_msr(omsr);
}

void
mvmeprom_outchar(c)
	int c;
{
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));
	asm  volatile ("mr 3, %0" :: "r" (c));
	MVMEPROM_CALL(MVMEPROM_OUTCHR);
        ppc_set_msr(omsr);
}

/* BUG - return to bug routine */
void
mvmeprom_return()
{
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));
	MVMEPROM_CALL(MVMEPROM_RETURN);
        ppc_set_msr(omsr);
	/*NOTREACHED*/
}


void
mvmeprom_rtc_rd(ptime)
	struct mvmeprom_time *ptime;
{
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));
	asm volatile ("mr 3, %0": : "r" (ptime));
	MVMEPROM_CALL(MVMEPROM_RTC_RD);
        ppc_set_msr(omsr);
}

int 
bugenvsz(void)
{
	register int ret;
	char tmp[1];
	void *ptr = tmp;
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));
	
	asm volatile ("mr 3, %0": : "r" (ptr));
	asm volatile ("li 5, 0x1");
	asm volatile ("li 5, 0x0"); /* get size */
	MVMEPROM_CALL(MVMEPROM_ENVIRON);
	asm volatile ("mr %0, 3" :  "=r" (ret));
        ppc_set_msr(omsr);
	
	return(ret);
}

struct bugenviron bugenviron; 
int bugenv_init = 0;
char bugenv_buf[1024];

#ifdef BUG_DEBUG
void bug_printenv(void);

void
bug_printenv(void)
{
	printf("Startup Mode: %c\n", bugenviron.s.s_mode);
	printf("Startup Menu: %c\n", bugenviron.s.s_menu);
	printf("Remote Start: %c\n", bugenviron.s.s_remotestart);
	printf("Probe Devs: %c\n", bugenviron.s.s_probe);
	printf("Negate Sysfail: %c\n", bugenviron.s.s_negsysfail);
	printf("Reset SCSI Bus: %c\n", bugenviron.s.s_resetscsi);
	printf("Ignore CFNA Block: %c\n", bugenviron.s.s_nocfblk);
	printf("SCSI sync method: %c\n", bugenviron.s.s_scsisync);

	printf("Auto Boot Enable: %c\n", bugenviron.b.b_enable);
	printf("Auto Boot on power-up Only: %c\n", bugenviron.b.b_poweruponly);
	printf("Auto Boot CLUN: %02x\n", bugenviron.b.b_clun);
	printf("Auto Boot DLUN: %02x\n", bugenviron.b.b_dlun);
	printf("Auto Boot Delay: %02x\n", bugenviron.b.b_delay);
	printf("Auto Boot String: %s\n", bugenviron.b.b_string);

	printf("ROM Boot Enable: %c\n", bugenviron.r.r_enable);
	printf("ROM Boot on power-up Only: %c\n", bugenviron.r.r_poweruponly);
	printf("ROM Boot Scan VME bus: %c\n", bugenviron.r.r_bootvme);
	printf("ROM Boot Delay: %02x\n", bugenviron.r.r_delay);
	printf("ROM Boot Start: %08x\n", bugenviron.r.r_start);
	printf("ROM Boot End: %08x\n", bugenviron.r.r_end);

	printf("Net Boot Enable: %c\n", bugenviron.n.n_enable);
	printf("Net Boot on power-up Only: %c\n", bugenviron.n.n_poweruponly);
	printf("Net Boot CLUN: %02x\n", bugenviron.n.n_clun);
	printf("Net Boot DLUN: %02x\n", bugenviron.n.n_dlun);
	printf("Net Boot Delay: %02x\n", bugenviron.n.n_delay);
	printf("Net Boot CFG param pointer: %08x\n", bugenviron.n.n_param);

	printf("Memory Size Enable: %c\n", bugenviron.m.m_sizeenable);
	printf("Memory Start: %08x\n", bugenviron.m.m_start);
	printf("Memory End: %08x\n", bugenviron.m.m_end);

	Debugger();
}
#else
#define	bug_printenv()	
#endif 

struct bugenviron *
mvmeprom_envrd(void)
{
	register int ret;
	char *ptr, *dptr, *ptr_end;
	int env_size = 0;
	int pkt_typ, pkt_len;
	unsigned long omsr = ppc_get_msr();
        ppc_set_msr(((omsr | PSL_IP) &~ PSL_EE));

	env_size = bugenvsz();
        bzero(&bugenviron, sizeof(struct bugenviron)); 
        bzero(&bugenv_buf[0], 1024); 
	ptr = bugenv_buf;
	
	if (ptr != NULL) {

		asm volatile ("mr 3, %0": : "r" (ptr));
		asm volatile ("mr 4, %0": : "r" (env_size));
		asm volatile ("li 5, 0x2");
		MVMEPROM_CALL(MVMEPROM_ENVIRON);
		asm volatile ("mr %0, 3" :  "=r" (ret));

		if (ret) { /* scram if we have an error */
			ppc_set_msr(omsr);
			return NULL;
		}
		ptr_end = ptr + env_size;
		while (ptr <= ptr_end) {
	                pkt_typ = *ptr++;
			pkt_len = *ptr++;
			dptr = ptr;
			switch (pkt_typ) {
			case BUG_ENV_END:
				bugenv_init = 1; /* we have read the env */
				bug_printenv();				
				ppc_set_msr(omsr);
				return(&bugenviron);
				break;
			case BUG_STARTUP_PARAM:
				/* All chars.  We can use bcopy. */
				bcopy(dptr, &bugenviron.s.s_mode, pkt_len);
				break;
			case BUG_AUTOBOOT_INFO:
				/* All chars.  We can use bcopy. */
				bcopy(dptr, &bugenviron.b.b_enable, pkt_len);
				break;
			case BUG_ROMBOOT_INFO:
				/* This data stream has integer info that 
				 * may not be word aligned.  We can't use 
				 * bcopy for the whole struct in this 
				 * instance. */
				bcopy(dptr, &bugenviron.r.r_enable, 4);
				dptr+=4;
				bcopy(dptr, &bugenviron.r.r_start, 4);
				dptr+=4;
				bcopy(dptr, &bugenviron.r.r_end, 4);
				break;
			case BUG_NETBOOT_INFO:
				/* This data stream has integer info that 
				 * may not be word aligned.  We can't use 
				 * bcopy for the whole struct in this 
				 * instance. */
				bcopy(dptr, &bugenviron.n.n_enable, 5);
				dptr+=5;
				bcopy(dptr, &bugenviron.n.n_param, 4);
				break;
			case BUG_MEMORY_INFO:
                                bugenviron.m.m_sizeenable = *dptr++;
				bcopy(dptr, &bugenviron.m.m_start, 4);
				dptr+=4;
				bcopy(dptr, &bugenviron.m.m_end, 4);
				break;
			}
			ptr += pkt_len;
		}
	}
        ppc_set_msr(omsr);
	return NULL;
}