1995-04-10 10:14:57 +04:00
|
|
|
/* $NetBSD: prom.c,v 1.15 1995/04/10 06:14:57 mycroft Exp $ */
|
1994-11-22 00:26:40 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1993 Adam Glass
|
|
|
|
* 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 by Adam Glass.
|
|
|
|
* 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 Adam Glass ``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 Adam Glass 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.
|
|
|
|
*/
|
1994-10-26 12:07:55 +03:00
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
#include "prom.h"
|
|
|
|
|
1994-02-23 11:28:11 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <machine/autoconf.h>
|
|
|
|
#include <machine/mon.h>
|
|
|
|
|
1994-05-05 06:59:37 +04:00
|
|
|
#include <dev/cons.h>
|
1994-02-23 11:28:11 +03:00
|
|
|
#include "../sun3/interreg.h"
|
1993-06-27 04:51:23 +04:00
|
|
|
|
1994-02-23 11:28:11 +03:00
|
|
|
/*
|
|
|
|
* cleanup:
|
|
|
|
* get autoconfiguration right, right style
|
|
|
|
* not a true serial driver but a tty driver, i.e no carrier
|
|
|
|
* make sure start is non-blocking
|
|
|
|
* add read support via timeouts
|
|
|
|
*/
|
1993-06-27 04:51:23 +04:00
|
|
|
|
1993-08-16 03:01:58 +04:00
|
|
|
void promattach __P((struct device *, struct device *, void *));
|
|
|
|
|
1993-06-27 04:51:23 +04:00
|
|
|
struct prom_softc {
|
1995-04-10 10:14:57 +04:00
|
|
|
struct device sc_dev;
|
|
|
|
int sc_flags;
|
|
|
|
int sc_nopen;
|
1993-08-16 03:01:58 +04:00
|
|
|
};
|
1995-04-10 10:14:57 +04:00
|
|
|
struct tty *prom_tty[NPROM];
|
1993-08-16 03:01:58 +04:00
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
struct cfdriver promcd = {
|
|
|
|
NULL, "prom", always_match, promattach, DV_TTY, sizeof(struct prom_softc)
|
|
|
|
};
|
1993-06-27 04:51:23 +04:00
|
|
|
|
1994-02-23 11:28:11 +03:00
|
|
|
#define UNIT_TO_PROM_SC(unit) promcd.cd_devs[unit]
|
1994-03-06 07:38:55 +03:00
|
|
|
#ifndef PROM_RECEIVE_FREQ
|
|
|
|
#define PROM_RECEIVE_FREQ 10
|
|
|
|
#endif
|
1994-02-23 11:28:11 +03:00
|
|
|
|
|
|
|
int promopen __P((dev_t, int, int, struct proc *));
|
|
|
|
int promclose __P((dev_t, int, int, struct proc *));
|
|
|
|
int promread __P((dev_t, struct uio *, int));
|
|
|
|
int promwrite __P((dev_t, struct uio *, int));
|
|
|
|
int promioctl __P((dev_t, int, caddr_t, int, struct proc *));
|
|
|
|
int promstop __P((struct tty *, int));
|
|
|
|
|
|
|
|
static int promparam __P((struct tty *, struct termios *));
|
|
|
|
static void promstart __P((struct tty *));
|
1995-04-10 10:14:57 +04:00
|
|
|
static void promreceive __P((void *));
|
1993-08-16 03:01:58 +04:00
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
void
|
|
|
|
promattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1993-08-16 03:01:58 +04:00
|
|
|
{
|
1995-04-10 10:14:57 +04:00
|
|
|
|
|
|
|
printf("\n");
|
1993-08-16 03:01:58 +04:00
|
|
|
}
|
1993-06-27 04:51:23 +04:00
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
int
|
|
|
|
promopen(dev, flag, mode, p)
|
1993-06-27 04:51:23 +04:00
|
|
|
dev_t dev;
|
|
|
|
int flag, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1995-04-10 10:14:57 +04:00
|
|
|
struct tty *tp;
|
|
|
|
struct prom_softc *sc;
|
|
|
|
int unit, result;
|
|
|
|
|
|
|
|
unit = minor(dev);
|
|
|
|
if (unit >= promcd.cd_ndevs)
|
|
|
|
return ENXIO;
|
|
|
|
sc = UNIT_TO_PROM_SC(unit);
|
|
|
|
if (sc == NULL)
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
if (prom_tty[unit] == NULL)
|
|
|
|
tp = prom_tty[unit] = ttymalloc();
|
|
|
|
else
|
|
|
|
tp = prom_tty[unit];
|
|
|
|
|
|
|
|
tp->t_oproc = promstart;
|
|
|
|
tp->t_param = promparam;
|
|
|
|
tp->t_dev = dev;
|
|
|
|
if ((tp->t_state & TS_ISOPEN) == 0) {
|
|
|
|
tp->t_state |= TS_WOPEN;
|
|
|
|
ttychars(tp);
|
|
|
|
if (tp->t_ispeed == 0) {
|
|
|
|
tp->t_iflag = TTYDEF_IFLAG;
|
|
|
|
tp->t_oflag = TTYDEF_OFLAG;
|
|
|
|
tp->t_cflag = TTYDEF_CFLAG;
|
|
|
|
tp->t_lflag = TTYDEF_LFLAG;
|
|
|
|
tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
|
|
|
|
}
|
|
|
|
promparam(tp, &tp->t_termios);
|
|
|
|
ttsetwater(tp);
|
|
|
|
} else if (tp->t_state & TS_XCLUDE && p->p_ucred->cr_uid != 0) {
|
|
|
|
return EBUSY;
|
1993-06-27 04:51:23 +04:00
|
|
|
}
|
1995-04-10 10:14:57 +04:00
|
|
|
|
|
|
|
tp->t_state |= TS_CARR_ON;
|
|
|
|
result = (*linesw[tp->t_line].l_open)(dev, tp);
|
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
timeout(promreceive, tp, hz/PROM_RECEIVE_FREQ);
|
|
|
|
return 0;
|
1993-06-27 04:51:23 +04:00
|
|
|
}
|
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
int
|
1993-06-27 04:51:23 +04:00
|
|
|
promclose(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag, mode;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
1995-04-10 10:14:57 +04:00
|
|
|
struct tty *tp;
|
|
|
|
int unit;
|
|
|
|
struct prom_softc *sc;
|
1993-06-27 04:51:23 +04:00
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
unit = minor(dev);
|
|
|
|
sc = UNIT_TO_PROM_SC(unit);
|
|
|
|
tp = prom_tty[unit];
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
(*linesw[tp->t_line].l_close)(tp, flag);
|
|
|
|
return ttyclose(tp);
|
1993-06-27 04:51:23 +04:00
|
|
|
}
|
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
int
|
1993-06-27 04:51:23 +04:00
|
|
|
promread(dev, uio, flag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1995-04-10 10:14:57 +04:00
|
|
|
int flag;
|
1993-06-27 04:51:23 +04:00
|
|
|
{
|
1995-04-10 10:14:57 +04:00
|
|
|
register struct tty *tp;
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
tp = prom_tty[minor(dev)];
|
|
|
|
return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
|
1993-06-27 04:51:23 +04:00
|
|
|
}
|
1995-04-10 10:14:57 +04:00
|
|
|
|
|
|
|
int
|
1993-06-27 04:51:23 +04:00
|
|
|
promwrite(dev, uio, flag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1995-04-10 10:14:57 +04:00
|
|
|
int flag;
|
1993-06-27 04:51:23 +04:00
|
|
|
{
|
1995-04-10 10:14:57 +04:00
|
|
|
register struct tty *tp;
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
tp = prom_tty[minor(dev)];
|
|
|
|
return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
|
1993-06-27 04:51:23 +04:00
|
|
|
}
|
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
int
|
|
|
|
promioctl(dev, cmd, data, flag, p)
|
1993-11-23 08:28:35 +03:00
|
|
|
dev_t dev;
|
1995-04-10 10:14:57 +04:00
|
|
|
u_long cmd;
|
1993-11-23 08:28:35 +03:00
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
1995-04-10 10:14:57 +04:00
|
|
|
struct proc *p;
|
1993-11-23 08:28:35 +03:00
|
|
|
{
|
1995-04-10 10:14:57 +04:00
|
|
|
register struct tty *tp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
tp = prom_tty[minor(dev)];
|
|
|
|
|
|
|
|
error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
|
|
|
|
if (error >= 0)
|
|
|
|
return error;
|
|
|
|
error = ttioctl(tp, cmd, data, flag, p);
|
|
|
|
if (error >= 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
return ENOTTY;
|
1993-11-23 08:28:35 +03:00
|
|
|
}
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
void
|
|
|
|
promstart(tp)
|
|
|
|
struct tty *tp;
|
1993-06-27 04:51:23 +04:00
|
|
|
{
|
1995-04-10 10:14:57 +04:00
|
|
|
int s, c, count;
|
|
|
|
u_char outbuf[50];
|
|
|
|
u_char *bufp;
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
if (tp->t_state & (TS_BUSY|TS_TTSTOP|TS_TIMEOUT))
|
|
|
|
goto out;
|
|
|
|
tp->t_state |= TS_BUSY;
|
|
|
|
if (tp->t_outq.c_cc <= tp->t_lowat) {
|
|
|
|
if (tp->t_state & TS_ASLEEP) {
|
|
|
|
tp->t_state &=~ TS_ASLEEP;
|
|
|
|
wakeup((caddr_t)&tp->t_outq);
|
|
|
|
}
|
|
|
|
selwakeup(&tp->t_wsel);
|
|
|
|
}
|
|
|
|
count = q_to_b(&tp->t_outq, outbuf, 49);
|
|
|
|
if (count) {
|
|
|
|
outbuf[count] = '\0';
|
|
|
|
(void) splhigh();
|
|
|
|
mon_printf("%s", outbuf);
|
|
|
|
(void) spltty();
|
1993-06-27 04:51:23 +04:00
|
|
|
}
|
1995-04-10 10:14:57 +04:00
|
|
|
tp->t_state &= ~TS_BUSY;
|
|
|
|
out:
|
|
|
|
splx(s);
|
1993-06-27 04:51:23 +04:00
|
|
|
}
|
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
void
|
|
|
|
promstop(tp, flag)
|
|
|
|
struct tty *tp;
|
|
|
|
int flag;
|
1993-06-27 04:51:23 +04:00
|
|
|
{
|
1995-04-10 10:14:57 +04:00
|
|
|
|
1994-02-23 11:28:11 +03:00
|
|
|
}
|
1995-04-10 10:14:57 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
promparam(tp, t)
|
|
|
|
struct tty *tp;
|
|
|
|
struct termios *t;
|
1994-02-23 11:28:11 +03:00
|
|
|
{
|
1995-04-10 10:14:57 +04:00
|
|
|
struct prom_softc *sc;
|
|
|
|
|
|
|
|
if (t->c_ispeed == 0 || (t->c_ispeed != t->c_ospeed))
|
|
|
|
return EINVAL;
|
|
|
|
tp->t_ispeed = t->c_ispeed;
|
|
|
|
tp->t_ospeed = t->c_ospeed;
|
|
|
|
tp->t_cflag = t->c_cflag;
|
|
|
|
return 0;
|
1993-06-27 04:51:23 +04:00
|
|
|
}
|
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
static void
|
|
|
|
promreceive(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
struct tty *tp = arg;
|
|
|
|
int c, s;
|
|
|
|
extern unsigned int orig_nmi_vector;
|
|
|
|
extern int nmi_intr();
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
if (tp->t_state & TS_ISOPEN) {
|
|
|
|
if ((tp->t_state & TS_BUSY) == 0) {
|
|
|
|
set_clk_mode(0, IREG_CLOCK_ENAB_7|IREG_CLOCK_ENAB_5, 0);
|
|
|
|
isr_add_custom(7, orig_nmi_vector);
|
|
|
|
set_clk_mode(IREG_CLOCK_ENAB_7, 0, 1);
|
|
|
|
c = mon_may_getchar();
|
|
|
|
set_clk_mode(0, IREG_CLOCK_ENAB_7|IREG_CLOCK_ENAB_5, 0);
|
|
|
|
isr_add_custom(7, nmi_intr);
|
|
|
|
set_clk_mode(IREG_CLOCK_ENAB_5, 0, 1);
|
|
|
|
if (c != -1)
|
|
|
|
(*linesw[tp->t_line].l_rint)(c, tp);
|
|
|
|
}
|
|
|
|
timeout(promreceive, tp, hz/PROM_RECEIVE_FREQ);
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
}
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
void
|
1993-08-16 03:01:58 +04:00
|
|
|
promcnprobe(cp)
|
1995-04-10 10:14:57 +04:00
|
|
|
struct consdev *cp;
|
1993-08-16 03:01:58 +04:00
|
|
|
{
|
1995-04-10 10:14:57 +04:00
|
|
|
int prommajor;
|
1993-08-16 03:01:58 +04:00
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
/* locate the major number */
|
|
|
|
for (prommajor = 0; prommajor < nchrdev; prommajor++)
|
|
|
|
if (cdevsw[prommajor].d_open == promopen)
|
|
|
|
break;
|
1993-06-27 04:51:23 +04:00
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
cp->cn_dev = makedev(prommajor, 0);
|
|
|
|
cp->cn_pri = CN_INTERNAL; /* will always exist but you don't
|
|
|
|
* want to use it unless you have to
|
|
|
|
*/
|
1993-08-16 03:01:58 +04:00
|
|
|
}
|
1993-06-27 04:51:23 +04:00
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
void
|
1993-06-27 04:51:23 +04:00
|
|
|
promcninit(cp)
|
1995-04-10 10:14:57 +04:00
|
|
|
struct consdev *cp;
|
1993-06-27 04:51:23 +04:00
|
|
|
{
|
1995-04-10 10:14:57 +04:00
|
|
|
|
|
|
|
mon_printf("console on prom0\n");
|
1993-06-27 04:51:23 +04:00
|
|
|
}
|
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
int
|
1993-06-27 04:51:23 +04:00
|
|
|
promcngetc(dev)
|
1995-04-10 10:14:57 +04:00
|
|
|
dev_t dev;
|
1993-06-27 04:51:23 +04:00
|
|
|
{
|
1995-04-10 10:14:57 +04:00
|
|
|
|
|
|
|
mon_printf("not sure how to do promcngetc() yet\n");
|
1993-06-27 04:51:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Console kernel output character routine.
|
|
|
|
*/
|
1995-04-10 10:14:57 +04:00
|
|
|
void
|
1993-08-08 16:17:37 +04:00
|
|
|
promcnputc(dev, c)
|
1995-04-10 10:14:57 +04:00
|
|
|
dev_t dev;
|
|
|
|
int c;
|
1993-06-27 04:51:23 +04:00
|
|
|
{
|
1995-04-10 10:14:57 +04:00
|
|
|
int s;
|
1994-02-23 11:28:11 +03:00
|
|
|
|
1995-04-10 10:14:57 +04:00
|
|
|
s = splhigh();
|
|
|
|
if (minor(dev) != 0)
|
|
|
|
mon_printf("non unit 0 prom console???\n");
|
|
|
|
mon_putchar(c);
|
|
|
|
splx(s);
|
1993-06-27 04:51:23 +04:00
|
|
|
}
|