Avoid duplicating ttselect() so that we don't have to change cyselect()

when ttselect() is improved.  This requires using an array of tty structs
and not using ttymalloc().

Fix an off by 1 error.  Some caclulations seem to be off by a factor
of NCY.  NCY defaults to 16, which gives 256 tty structs occupying
0xd000 bytes.  The minor number encoding only allows 16 ttys.

Update the types of timeout functions to 2.0.
This commit is contained in:
Bruce Evans 1995-02-15 18:41:41 +00:00
parent 73bac2c219
commit ae5e131ac8
3 changed files with 54 additions and 90 deletions

View File

@ -27,7 +27,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: cy.c,v 1.7 1994/05/24 07:31:12 mycroft Exp $ * $Id: cy.c,v 1.1 1995/02/09 09:47:27 jkh Exp $
*/ */
/* /*
@ -244,7 +244,11 @@ struct cy {
int cydefaultrate = TTYDEF_SPEED; int cydefaultrate = TTYDEF_SPEED;
cy_addr cyclom_base; /* base address of the card */ cy_addr cyclom_base; /* base address of the card */
static struct cy *info[NCY*PORTS_PER_CYCLOM]; static struct cy *info[NCY*PORTS_PER_CYCLOM];
#ifdef __FreeBSD__ /* XXX actually only temporarily for 2.1-Development */
struct tty cy_tty[NCY*PORTS_PER_CYCLOM];
#else
struct tty *cy_tty[NCY*PORTS_PER_CYCLOM]; struct tty *cy_tty[NCY*PORTS_PER_CYCLOM];
#endif
static volatile u_char timeout_scheduled = 0; /* true if a timeout has been scheduled */ static volatile u_char timeout_scheduled = 0; /* true if a timeout has been scheduled */
#ifdef CyDebug #ifdef CyDebug
@ -354,13 +358,17 @@ cyopen(dev_t dev, int flag, int mode, struct proc *p)
int error = 0; int error = 0;
u_char carrier; u_char carrier;
if (unit >= PORTS_PER_CYCLOM) if (unit >= /* NCY * ? */ PORTS_PER_CYCLOM)
return (ENXIO); return (ENXIO);
infop = info[unit]; infop = info[unit];
base = infop->base_addr; base = infop->base_addr;
#ifdef __FreeBSD__
infop->tty = &cy_tty[unit];
#else
if (!cy_tty[unit]) if (!cy_tty[unit])
infop->tty = cy_tty[unit] = ttymalloc(); infop->tty = cy_tty[unit] = ttymalloc();
#endif
tp = infop->tty; tp = infop->tty;
tp->t_oproc = cystart; tp->t_oproc = cystart;
@ -421,7 +429,7 @@ cyopen(dev_t dev, int flag, int mode, struct proc *p)
void void
cyclose_wakeup(caddr_t arg) cyclose_wakeup(void *arg)
{ {
wakeup(arg); wakeup(arg);
} /* end of cyclose_wakeup() */ } /* end of cyclose_wakeup() */
@ -664,7 +672,7 @@ service_upper_mdm(int unit)
/* upper level character processing routine */ /* upper level character processing routine */
void void
cytimeout(caddr_t ptr) cytimeout(void *ptr)
{ {
int unit; int unit;
@ -1496,31 +1504,7 @@ cystop(struct tty *tp, int flag)
int int
cyselect(dev_t dev, int rw, struct proc *p) cyselect(dev_t dev, int rw, struct proc *p)
{ {
struct tty *tp = info[UNIT(dev)]->tty; return (ttselect(UNIT(dev), rw, p));
int s = spltty();
int nread;
switch (rw) {
case FREAD:
nread = ttnread(tp);
if (nread > 0 ||
((tp->t_cflag&CLOCAL) == 0 && (tp->t_state&TS_CARR_ON) == 0))
goto win;
selrecord(p, &tp->t_rsel);
break;
case FWRITE:
if (tp->t_outq.c_cc <= tp->t_lowat)
goto win;
selrecord(p, &tp->t_wsel);
break;
}
splx(s);
return (0);
win:
splx(s);
return (1);
} /* end of cyselect() */ } /* end of cyselect() */
@ -1617,11 +1601,15 @@ cyparam_dummy(struct tty *tp, struct termios *t)
void void
cyset(int unit, int active) cyset(int unit, int active)
{ {
if (unit < 0 || unit > PORTS_PER_CYCLOM) { if (unit < 0 || unit >= /* NCY *? */ PORTS_PER_CYCLOM) {
printf("bad unit number %d\n", unit); printf("bad unit number %d\n", unit);
return; return;
} }
#ifdef __FreeBSD__
cy_tty[unit].t_param = active ? cyparam : cyparam_dummy;
#else
cy_tty[unit]->t_param = active ? cyparam : cyparam_dummy; cy_tty[unit]->t_param = active ? cyparam : cyparam_dummy;
#endif
} }

View File

@ -27,7 +27,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: cy.c,v 1.7 1994/05/24 07:31:12 mycroft Exp $ * $Id: cy.c,v 1.1 1995/02/09 09:47:27 jkh Exp $
*/ */
/* /*
@ -244,7 +244,11 @@ struct cy {
int cydefaultrate = TTYDEF_SPEED; int cydefaultrate = TTYDEF_SPEED;
cy_addr cyclom_base; /* base address of the card */ cy_addr cyclom_base; /* base address of the card */
static struct cy *info[NCY*PORTS_PER_CYCLOM]; static struct cy *info[NCY*PORTS_PER_CYCLOM];
#ifdef __FreeBSD__ /* XXX actually only temporarily for 2.1-Development */
struct tty cy_tty[NCY*PORTS_PER_CYCLOM];
#else
struct tty *cy_tty[NCY*PORTS_PER_CYCLOM]; struct tty *cy_tty[NCY*PORTS_PER_CYCLOM];
#endif
static volatile u_char timeout_scheduled = 0; /* true if a timeout has been scheduled */ static volatile u_char timeout_scheduled = 0; /* true if a timeout has been scheduled */
#ifdef CyDebug #ifdef CyDebug
@ -354,13 +358,17 @@ cyopen(dev_t dev, int flag, int mode, struct proc *p)
int error = 0; int error = 0;
u_char carrier; u_char carrier;
if (unit >= PORTS_PER_CYCLOM) if (unit >= /* NCY * ? */ PORTS_PER_CYCLOM)
return (ENXIO); return (ENXIO);
infop = info[unit]; infop = info[unit];
base = infop->base_addr; base = infop->base_addr;
#ifdef __FreeBSD__
infop->tty = &cy_tty[unit];
#else
if (!cy_tty[unit]) if (!cy_tty[unit])
infop->tty = cy_tty[unit] = ttymalloc(); infop->tty = cy_tty[unit] = ttymalloc();
#endif
tp = infop->tty; tp = infop->tty;
tp->t_oproc = cystart; tp->t_oproc = cystart;
@ -421,7 +429,7 @@ cyopen(dev_t dev, int flag, int mode, struct proc *p)
void void
cyclose_wakeup(caddr_t arg) cyclose_wakeup(void *arg)
{ {
wakeup(arg); wakeup(arg);
} /* end of cyclose_wakeup() */ } /* end of cyclose_wakeup() */
@ -664,7 +672,7 @@ service_upper_mdm(int unit)
/* upper level character processing routine */ /* upper level character processing routine */
void void
cytimeout(caddr_t ptr) cytimeout(void *ptr)
{ {
int unit; int unit;
@ -1496,31 +1504,7 @@ cystop(struct tty *tp, int flag)
int int
cyselect(dev_t dev, int rw, struct proc *p) cyselect(dev_t dev, int rw, struct proc *p)
{ {
struct tty *tp = info[UNIT(dev)]->tty; return (ttselect(UNIT(dev), rw, p));
int s = spltty();
int nread;
switch (rw) {
case FREAD:
nread = ttnread(tp);
if (nread > 0 ||
((tp->t_cflag&CLOCAL) == 0 && (tp->t_state&TS_CARR_ON) == 0))
goto win;
selrecord(p, &tp->t_rsel);
break;
case FWRITE:
if (tp->t_outq.c_cc <= tp->t_lowat)
goto win;
selrecord(p, &tp->t_wsel);
break;
}
splx(s);
return (0);
win:
splx(s);
return (1);
} /* end of cyselect() */ } /* end of cyselect() */
@ -1617,11 +1601,15 @@ cyparam_dummy(struct tty *tp, struct termios *t)
void void
cyset(int unit, int active) cyset(int unit, int active)
{ {
if (unit < 0 || unit > PORTS_PER_CYCLOM) { if (unit < 0 || unit >= /* NCY *? */ PORTS_PER_CYCLOM) {
printf("bad unit number %d\n", unit); printf("bad unit number %d\n", unit);
return; return;
} }
#ifdef __FreeBSD__
cy_tty[unit].t_param = active ? cyparam : cyparam_dummy;
#else
cy_tty[unit]->t_param = active ? cyparam : cyparam_dummy; cy_tty[unit]->t_param = active ? cyparam : cyparam_dummy;
#endif
} }

View File

@ -27,7 +27,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: cy.c,v 1.7 1994/05/24 07:31:12 mycroft Exp $ * $Id: cy.c,v 1.1 1995/02/09 09:47:27 jkh Exp $
*/ */
/* /*
@ -244,7 +244,11 @@ struct cy {
int cydefaultrate = TTYDEF_SPEED; int cydefaultrate = TTYDEF_SPEED;
cy_addr cyclom_base; /* base address of the card */ cy_addr cyclom_base; /* base address of the card */
static struct cy *info[NCY*PORTS_PER_CYCLOM]; static struct cy *info[NCY*PORTS_PER_CYCLOM];
#ifdef __FreeBSD__ /* XXX actually only temporarily for 2.1-Development */
struct tty cy_tty[NCY*PORTS_PER_CYCLOM];
#else
struct tty *cy_tty[NCY*PORTS_PER_CYCLOM]; struct tty *cy_tty[NCY*PORTS_PER_CYCLOM];
#endif
static volatile u_char timeout_scheduled = 0; /* true if a timeout has been scheduled */ static volatile u_char timeout_scheduled = 0; /* true if a timeout has been scheduled */
#ifdef CyDebug #ifdef CyDebug
@ -354,13 +358,17 @@ cyopen(dev_t dev, int flag, int mode, struct proc *p)
int error = 0; int error = 0;
u_char carrier; u_char carrier;
if (unit >= PORTS_PER_CYCLOM) if (unit >= /* NCY * ? */ PORTS_PER_CYCLOM)
return (ENXIO); return (ENXIO);
infop = info[unit]; infop = info[unit];
base = infop->base_addr; base = infop->base_addr;
#ifdef __FreeBSD__
infop->tty = &cy_tty[unit];
#else
if (!cy_tty[unit]) if (!cy_tty[unit])
infop->tty = cy_tty[unit] = ttymalloc(); infop->tty = cy_tty[unit] = ttymalloc();
#endif
tp = infop->tty; tp = infop->tty;
tp->t_oproc = cystart; tp->t_oproc = cystart;
@ -421,7 +429,7 @@ cyopen(dev_t dev, int flag, int mode, struct proc *p)
void void
cyclose_wakeup(caddr_t arg) cyclose_wakeup(void *arg)
{ {
wakeup(arg); wakeup(arg);
} /* end of cyclose_wakeup() */ } /* end of cyclose_wakeup() */
@ -664,7 +672,7 @@ service_upper_mdm(int unit)
/* upper level character processing routine */ /* upper level character processing routine */
void void
cytimeout(caddr_t ptr) cytimeout(void *ptr)
{ {
int unit; int unit;
@ -1496,31 +1504,7 @@ cystop(struct tty *tp, int flag)
int int
cyselect(dev_t dev, int rw, struct proc *p) cyselect(dev_t dev, int rw, struct proc *p)
{ {
struct tty *tp = info[UNIT(dev)]->tty; return (ttselect(UNIT(dev), rw, p));
int s = spltty();
int nread;
switch (rw) {
case FREAD:
nread = ttnread(tp);
if (nread > 0 ||
((tp->t_cflag&CLOCAL) == 0 && (tp->t_state&TS_CARR_ON) == 0))
goto win;
selrecord(p, &tp->t_rsel);
break;
case FWRITE:
if (tp->t_outq.c_cc <= tp->t_lowat)
goto win;
selrecord(p, &tp->t_wsel);
break;
}
splx(s);
return (0);
win:
splx(s);
return (1);
} /* end of cyselect() */ } /* end of cyselect() */
@ -1617,11 +1601,15 @@ cyparam_dummy(struct tty *tp, struct termios *t)
void void
cyset(int unit, int active) cyset(int unit, int active)
{ {
if (unit < 0 || unit > PORTS_PER_CYCLOM) { if (unit < 0 || unit >= /* NCY *? */ PORTS_PER_CYCLOM) {
printf("bad unit number %d\n", unit); printf("bad unit number %d\n", unit);
return; return;
} }
#ifdef __FreeBSD__
cy_tty[unit].t_param = active ? cyparam : cyparam_dummy;
#else
cy_tty[unit]->t_param = active ? cyparam : cyparam_dummy; cy_tty[unit]->t_param = active ? cyparam : cyparam_dummy;
#endif
} }