Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  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
/*	$NetBSD: dz_ibus.c,v 1.12 2017/05/18 16:37:06 christos Exp $	*/

/*-
 * Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Andrew Doran.
 *
 * 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.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``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 FOUNDATION OR CONTRIBUTORS
 * 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.
 */

/*
 * Copyright (c) 1998 Ludd, University of Lule}, Sweden.
 * 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. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed at Ludd, University of 
 *	Lule}, Sweden and its contributors.
 * 4. 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/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: dz_ibus.c,v 1.12 2017/05/18 16:37:06 christos Exp $");

#include "dzkbd.h"
#include "dzms.h"

#include <sys/param.h>
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/proc.h>
#include <sys/reboot.h>
#include <sys/systm.h>
#include <sys/tty.h>

#include <dev/cons.h>

#include <dev/tc/tcvar.h>		/* tc_addr_t */

#include <dev/dec/dzreg.h>
#include <dev/dec/dzvar.h>
#include <dev/dec/dzkbdvar.h>

#include <pmax/ibus/ibusvar.h>
#include <pmax/pmax/pmaxtype.h>
#include <pmax/pmax/cons.h>

#define	DZ_LINE_KBD	0
#define	DZ_LINE_MOUSE	1
#define	DZ_LINE_CONSOLE	2
#define	DZ_LINE_AUX	3

int	dz_ibus_match(device_t, cfdata_t, void *);
void	dz_ibus_attach(device_t, device_t, void *);
int	dz_ibus_intr(void *);
void	dz_ibus_cnsetup(paddr_t);
int	dz_ibus_cngetc(dev_t);
void	dz_ibus_cnputc(dev_t, int);
void	dz_ibus_cnpollc(dev_t, int);
int	dz_ibus_getmajor(void);
int	dz_ibus_print(void *, const char *);

int	dzgetc(struct dz_linestate *);
void	dzputc(struct dz_linestate *, int);

CFATTACH_DECL_NEW(dz_ibus, sizeof(struct dz_softc),
    dz_ibus_match, dz_ibus_attach, NULL, NULL);

struct consdev dz_ibus_consdev = {
	NULL, NULL, dz_ibus_cngetc, dz_ibus_cnputc,
	dz_ibus_cnpollc, NULL, NULL, NULL, NODEV, CN_NORMAL,
};

struct dzregs {
	uint16_t	csr;	/* 00 Csr: control/status */
	uint16_t	p0[3];

	uint16_t	rbuf;	/* 08 Rbuf/Lpr: receive buffer/line param  */
	uint16_t	p1[3];

	uint16_t	tcr;	/* 10 Tcr: transmit console */
	uint16_t	p2[3];

	uint16_t	tdr;	/* 18 Msr/Tdr: modem status reg/xmit data */
	uint16_t	p3[3];
} volatile *dzcn;

int	dz_ibus_iscn;
int	dz_ibus_consln = -1;

int
dz_ibus_match(device_t parent, cfdata_t cf, void *aux)
{
	struct ibus_attach_args *iba = aux;

	if (strcmp(iba->ia_name, "dc") != 0 &&
	    strcmp(iba->ia_name, "mdc") != 0 &&
	    strcmp(iba->ia_name, "dc7085") != 0)
		return (0);

	if (badaddr((void *)iba->ia_addr, 2))
		return (0);

	return (1);
}

void
dz_ibus_attach(device_t parent, device_t self, void *aux)
{
	struct ibus_attach_args *iba = aux;
	struct dz_softc *sc = device_private(self);
	volatile struct dzregs *dz;
#if NDZMS > 0 || NDZKBD > 0
	struct dzkm_attach_args daa;
#endif
	int i;


	DELAY(100000);

	sc->sc_dev = self;

	/* 
	 * XXX - This is evil and ugly, but... due to the nature of how
	 * bus_space_* works on pmax it will do for the time being.
	 */
	sc->sc_iot = normal_memt;
	sc->sc_ioh = (bus_space_handle_t)MIPS_PHYS_TO_KSEG1(iba->ia_addr);

	sc->sc_dr.dr_csr = 0;
	sc->sc_dr.dr_rbuf = 8;
	sc->sc_dr.dr_dtr = 17;
	sc->sc_dr.dr_break = 25;
	sc->sc_dr.dr_tbuf = 24;
	sc->sc_dr.dr_tcr = 16;
	sc->sc_dr.dr_dcd = 25;
	sc->sc_dr.dr_ring = 24;

	sc->sc_dr.dr_firstreg = 0;
	sc->sc_dr.dr_winsize = sizeof(struct dzregs);

	sc->sc_type = DZ_DZV;

	dz = (volatile struct dzregs *)sc->sc_ioh;
	i = dz->tcr;
	dz->csr = DZ_CSR_MSE | DZ_CSR_TXIE;
	dz->tcr = 0;
	wbflush();
	DELAY(1000);
	dz->tcr = 1;
	wbflush();
	DELAY(100000);
	dz->tcr = i;
	wbflush();

	sc->sc_dsr = 0x0f; /* XXX check if VS has modem ctrl bits */

	aprint_normal(": DC-7085, 4 lines");
	ibus_intr_establish(parent, (void *)iba->ia_cookie, IPL_TTY,
	    dz_ibus_intr, sc);
	dzattach(sc, NULL, dz_ibus_consln);
	DELAY(10000);

	if (systype == DS_PMAX || systype == DS_3MAX) {
#if NDZKBD > 0
		if (!dz_ibus_iscn)
			dz->rbuf = DZ_LPR_RX_ENABLE | (DZ_LPR_B4800 << 8) |
			    DZ_LPR_8_BIT_CHAR | DZ_LINE_KBD;
		daa.daa_line = DZ_LINE_KBD;
		daa.daa_flags = (dz_ibus_iscn ? 0 : DZKBD_CONSOLE);
		config_found(self, &daa, dz_ibus_print);
#endif
#if NDZMS > 0
		dz->rbuf = DZ_LPR_RX_ENABLE | (DZ_LPR_B4800 << 8) |
		    DZ_LPR_8_BIT_CHAR | DZ_LPR_PARENB | DZ_LPR_OPAR |
		    DZ_LINE_MOUSE;
		daa.daa_line = DZ_LINE_MOUSE;
		daa.daa_flags = 0;
		config_found(self, &daa, dz_ibus_print);
#endif
	}
}

int
dz_ibus_getmajor(void)
{
	extern const struct cdevsw dz_cdevsw;
	static int cache = -1;

	if (cache != -1)
		return (cache);

	return (cache = cdevsw_lookup_major(&dz_cdevsw));
}

int
dz_ibus_intr(void *cookie)
{
	struct dz_softc *sc;
	volatile struct dzregs *dzr;
	unsigned csr;

	sc = cookie;
	dzr = (volatile struct dzregs *)sc->sc_ioh;

	while (((csr = dzr->csr) & (DZ_CSR_RX_DONE | DZ_CSR_TX_READY)) != 0) {
		if ((csr & DZ_CSR_RX_DONE) != 0)
			dzrint(sc);
		if ((csr & DZ_CSR_TX_READY) != 0)
			dzxint(sc);
	}

	return (0);
}

void
dz_ibus_cnsetup(paddr_t addr)
{

	dzcn = (void *)MIPS_PHYS_TO_KSEG1(addr);
}

void
dz_ibus_cnattach(int line)
{

	switch (line) {
	case 0:
		line = DZ_LINE_KBD;
		break;
	case 4:
		line = DZ_LINE_CONSOLE;
		break;
	default:
		line = DZ_LINE_AUX;
		break;
	}

	dz_ibus_iscn = 1;
	dz_ibus_consln = line;

	/* Disable scanning until init is done. */
	dzcn->csr = 0;
	wbflush();
	DELAY(1000);

	/* Turn on transmitter for the console. */
	dzcn->tcr = (1 << line);
	wbflush();
	DELAY(1000);

	/* Turn scanning back on. */
	dzcn->csr = 0x20;
	wbflush();
	DELAY(1000);

	/*
	 * Point the console at the DZ-11.
	 */
	cn_tab = &dz_ibus_consdev;
	cn_tab->cn_pri = CN_REMOTE;
	cn_tab->cn_dev = makedev(dz_ibus_getmajor(), line);
}

int
dz_ibus_cngetc(dev_t dev)
{
	int c, line, s;
	uint16_t rbuf;

	c = 0;
	line = minor(dev);
	s = spltty();

	do {
		while ((dzcn->csr & DZ_CSR_RX_DONE) == 0)
			DELAY(10);
		DELAY(10);
		rbuf = dzcn->rbuf;
		if (((rbuf >> 8) & 3) != line)
			continue;
		c = rbuf & 0x7f;
	} while (c == 17 || c == 19);		/* ignore XON/XOFF */

	splx(s);
	if (c == 13)
		c = 10;
	return (c);
}

void
dz_ibus_cnputc(dev_t dev, int ch)
{
	int timeout, s;
	uint16_t tcr;

	s = spltty();

	/* Don't hang the machine! */
	timeout = 1 << 15;

	/* Remember which lines to scan */
	tcr = dzcn->tcr;
	dzcn->tcr = (1 << minor(dev));
	wbflush();
	DELAY(10);

	/* Wait until ready */
	while ((dzcn->csr & 0x8000) == 0)
		if (--timeout < 0)
			break;
	DELAY(10);

	/* Put the character */
	dzcn->tdr = ch;
	timeout = 1 << 15;
	wbflush();
	DELAY(10);

	/* Wait until ready */
	while ((dzcn->csr & 0x8000) == 0)
		if (--timeout < 0)
			break;

	DELAY(10);
	dzcn->tcr = tcr;
	wbflush();
	DELAY(10);
	splx(s);
}

void    
dz_ibus_cnpollc(dev_t dev, int pollflag)
{

}

#if NDZKBD > 0 || NDZMS > 0
int
dz_ibus_print(void *aux, const char *pnp)
{
	struct dzkm_attach_args *daa;

	daa = aux;
	if (pnp != NULL)
		aprint_normal("lkkbd/vsms at %s", pnp);
	aprint_normal(" line %d", daa->daa_line);
	return (UNCONF);
}

int
dzgetc(struct dz_linestate *ls)
{
	volatile struct dzregs *dzr;
	int line, s;
	uint16_t rbuf;

	if (ls == NULL) {
		/*
		 * dzkbd is the only thing that should put us here.
		 */
		line = DZ_LINE_KBD;
		dzr = dzcn;
	} else {
		line = ls->dz_line;
		dzr = (volatile struct dzregs *)ls->dz_sc->sc_ioh;
	}

	s = spltty();
	for (;;) {
		while ((dzr->csr & DZ_CSR_RX_DONE) == 0)
			DELAY(10);
		DELAY(10);
		rbuf = dzr->rbuf;
		DELAY(10);
		if (((rbuf >> 8) & 3) == line)
			return (rbuf & 0xff);
	}
	splx(s);
}

void
dzputc(struct dz_linestate *ls, int ch)
{
	volatile struct dzregs *dzr;
	int line;
	uint16_t tcr;
	int s;

	/*
	 * If the dz has already been attached, the MI driver will do the
	 * transmitting:
	 */
	if (ls != NULL && ls->dz_sc != NULL) {
		line = ls->dz_line;
		dzr = (volatile struct dzregs *)ls->dz_sc->sc_ioh;
		s = spltty();
		putc(ch, &ls->dz_tty->t_outq);
		tcr = dzr->tcr;
		if ((tcr & (1 << line)) == 0) {
			dzr->tcr = tcr | (1 << line);
			wbflush();
			DELAY(10);
		}
		dzxint(ls->dz_sc);
		splx(s);
		return;
	}

	/* Use dzcnputc to do the transmitting. */
	dz_ibus_cnputc(makedev(dz_ibus_getmajor(), DZ_LINE_KBD), ch);
}
#endif /* NDZKBD > 0 || NDZMS > 0 */