Move TTY unrelated bits out of <sys/tty.h>.
For some reason, the <sys/tty.h> header file also contains routines of the clists and console that are used inside the TTY layer. Because the clists are not only used by the TTY layer (example: various input drivers), we'd better move the entire clist programming interface into <sys/clist.h>. Also remove a declaration of nonexistent variable. The <sys/tty.h> header also contains various definitions for the console code (tty_cons.c). Also move these to <sys/cons.h>, because they are not implemented inside the TTY layer. While there, create separate malloc pools for the clist and console code. Approved by: philip (mentor)
This commit is contained in:
parent
81590c5b37
commit
8837b0dd09
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=179246
@ -42,6 +42,8 @@ __FBSDID("$FreeBSD$");
|
||||
static void clist_init(void *);
|
||||
SYSINIT(clist, SI_SUB_CLIST, SI_ORDER_FIRST, clist_init, NULL);
|
||||
|
||||
static MALLOC_DEFINE(M_CLIST, "clist", "clist queue blocks");
|
||||
|
||||
static struct cblock *cfreelist = 0;
|
||||
int cfreecount = 0;
|
||||
static int cslushcount;
|
||||
@ -133,11 +135,11 @@ cblock_alloc_cblocks(number)
|
||||
struct cblock *cbp;
|
||||
|
||||
for (i = 0; i < number; ++i) {
|
||||
cbp = malloc(sizeof *cbp, M_TTYS, M_NOWAIT);
|
||||
cbp = malloc(sizeof *cbp, M_CLIST, M_NOWAIT);
|
||||
if (cbp == NULL) {
|
||||
printf(
|
||||
"cblock_alloc_cblocks: M_NOWAIT malloc failed, trying M_WAITOK\n");
|
||||
cbp = malloc(sizeof *cbp, M_TTYS, M_WAITOK);
|
||||
cbp = malloc(sizeof *cbp, M_CLIST, M_WAITOK);
|
||||
}
|
||||
/*
|
||||
* Freed cblocks have zero quotes and garbage elsewhere.
|
||||
@ -192,7 +194,7 @@ cblock_free_cblocks(number)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < number; ++i)
|
||||
free(cblock_alloc(), M_TTYS);
|
||||
free(cblock_alloc(), M_CLIST);
|
||||
ctotcount -= number;
|
||||
}
|
||||
|
||||
|
@ -78,6 +78,7 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/cons.h>
|
||||
#include <sys/filio.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/mutex.h>
|
||||
|
@ -66,6 +66,8 @@ __FBSDID("$FreeBSD$");
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/clock.h>
|
||||
|
||||
static MALLOC_DEFINE(M_TTYCONS, "tty console", "tty console handling");
|
||||
|
||||
static d_open_t cnopen;
|
||||
static d_close_t cnclose;
|
||||
static d_read_t cnread;
|
||||
@ -673,7 +675,7 @@ constty_set(struct tty *tp)
|
||||
KASSERT(tp != NULL, ("constty_set: NULL tp"));
|
||||
if (consbuf == NULL) {
|
||||
size = consmsgbuf_size;
|
||||
consbuf = malloc(size, M_TTYS, M_WAITOK);
|
||||
consbuf = malloc(size, M_TTYCONS, M_WAITOK);
|
||||
msgbuf_init(&consmsgbuf, consbuf, size);
|
||||
callout_init(&conscallout, 0);
|
||||
}
|
||||
@ -695,7 +697,7 @@ constty_clear(void)
|
||||
callout_stop(&conscallout);
|
||||
while ((c = msgbuf_getchar(&consmsgbuf)) != -1)
|
||||
cnputc(c);
|
||||
free(consbuf, M_TTYS);
|
||||
free(consbuf, M_TTYCONS);
|
||||
consbuf = NULL;
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,8 @@ __FBSDID("$FreeBSD$");
|
||||
static void clist_init(void *);
|
||||
SYSINIT(clist, SI_SUB_CLIST, SI_ORDER_FIRST, clist_init, NULL);
|
||||
|
||||
static MALLOC_DEFINE(M_CLIST, "clist", "clist queue blocks");
|
||||
|
||||
static struct cblock *cfreelist = 0;
|
||||
int cfreecount = 0;
|
||||
static int cslushcount;
|
||||
@ -133,11 +135,11 @@ cblock_alloc_cblocks(number)
|
||||
struct cblock *cbp;
|
||||
|
||||
for (i = 0; i < number; ++i) {
|
||||
cbp = malloc(sizeof *cbp, M_TTYS, M_NOWAIT);
|
||||
cbp = malloc(sizeof *cbp, M_CLIST, M_NOWAIT);
|
||||
if (cbp == NULL) {
|
||||
printf(
|
||||
"cblock_alloc_cblocks: M_NOWAIT malloc failed, trying M_WAITOK\n");
|
||||
cbp = malloc(sizeof *cbp, M_TTYS, M_WAITOK);
|
||||
cbp = malloc(sizeof *cbp, M_CLIST, M_WAITOK);
|
||||
}
|
||||
/*
|
||||
* Freed cblocks have zero quotes and garbage elsewhere.
|
||||
@ -192,7 +194,7 @@ cblock_free_cblocks(number)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < number; ++i)
|
||||
free(cblock_alloc(), M_TTYS);
|
||||
free(cblock_alloc(), M_CLIST);
|
||||
ctotcount -= number;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,19 @@
|
||||
#ifndef _SYS_CLIST_H_
|
||||
#define _SYS_CLIST_H_
|
||||
|
||||
/*
|
||||
* Clists are character lists, which is a variable length linked list
|
||||
* of cblocks, with a count of the number of characters in the list.
|
||||
*/
|
||||
struct clist {
|
||||
int c_cc; /* Number of characters in the clist. */
|
||||
int c_cbcount; /* Number of cblocks. */
|
||||
int c_cbmax; /* Max # cblocks allowed for this clist. */
|
||||
int c_cbreserved; /* # cblocks reserved for this clist. */
|
||||
char *c_cf; /* Pointer to the first cblock. */
|
||||
char *c_cl; /* Pointer to the last cblock. */
|
||||
};
|
||||
|
||||
struct cblock {
|
||||
struct cblock *c_next; /* next cblock in queue */
|
||||
unsigned char c_quote[CBQSIZE]; /* quoted characters */
|
||||
@ -40,8 +53,18 @@ struct cblock {
|
||||
};
|
||||
|
||||
#ifdef _KERNEL
|
||||
extern struct cblock *cfree;
|
||||
extern int cfreecount;
|
||||
|
||||
int b_to_q(char *cp, int cc, struct clist *q);
|
||||
void catq(struct clist *from, struct clist *to);
|
||||
void clist_alloc_cblocks(struct clist *q, int ccmax, int ccres);
|
||||
void clist_free_cblocks(struct clist *q);
|
||||
int getc(struct clist *q);
|
||||
void ndflush(struct clist *q, int cc);
|
||||
char *nextc(struct clist *q, char *cp, int *c);
|
||||
int putc(int c, struct clist *q);
|
||||
int q_to_b(struct clist *q, char *cp, int cc);
|
||||
int unputc(struct clist *q);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -39,6 +39,8 @@
|
||||
#define _MACHINE_CONS_H_
|
||||
|
||||
struct consdev;
|
||||
struct tty;
|
||||
|
||||
typedef void cn_probe_t(struct consdev *);
|
||||
typedef void cn_init_t(struct consdev *);
|
||||
typedef void cn_term_t(struct consdev *);
|
||||
@ -80,6 +82,9 @@ struct consdev {
|
||||
|
||||
#ifdef _KERNEL
|
||||
|
||||
extern struct msgbuf consmsgbuf; /* Message buffer for constty. */
|
||||
extern struct tty *constty; /* Temporary virtual console. */
|
||||
|
||||
#define CONS_DRIVER(name, probe, init, term, getc, checkc, putc, dbctl) \
|
||||
static struct consdev name##_consdev = { \
|
||||
probe, init, term, getc, checkc, putc \
|
||||
@ -108,6 +113,8 @@ int cngetc(void);
|
||||
void cnputc(int);
|
||||
void cnputs(char *);
|
||||
int cnunavailable(void);
|
||||
void constty_set(struct tty *tp);
|
||||
void constty_clear(void);
|
||||
|
||||
#endif /* _KERNEL */
|
||||
|
||||
|
@ -46,25 +46,13 @@
|
||||
#ifndef _SYS_TTY_H_
|
||||
#define _SYS_TTY_H_
|
||||
|
||||
#include <sys/clist.h>
|
||||
#include <sys/termios.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/selinfo.h>
|
||||
#include <sys/_lock.h>
|
||||
#include <sys/_mutex.h>
|
||||
|
||||
/*
|
||||
* Clists are character lists, which is a variable length linked list
|
||||
* of cblocks, with a count of the number of characters in the list.
|
||||
*/
|
||||
struct clist {
|
||||
int c_cc; /* Number of characters in the clist. */
|
||||
int c_cbcount; /* Number of cblocks. */
|
||||
int c_cbmax; /* Max # cblocks allowed for this clist. */
|
||||
int c_cbreserved; /* # cblocks reserved for this clist. */
|
||||
char *c_cf; /* Pointer to the first cblock. */
|
||||
char *c_cl; /* Pointer to the last cblock. */
|
||||
};
|
||||
|
||||
struct tty;
|
||||
struct pps_state;
|
||||
struct cdev;
|
||||
@ -313,25 +301,12 @@ MALLOC_DECLARE(M_TTYS);
|
||||
#define ISINIT(dev) (minor(dev) & MINOR_INIT)
|
||||
#define ISLOCK(dev) (minor(dev) & MINOR_LOCK)
|
||||
|
||||
extern struct msgbuf consmsgbuf; /* Message buffer for constty. */
|
||||
extern struct tty *constty; /* Temporary virtual console. */
|
||||
extern long tk_cancc;
|
||||
extern long tk_nin;
|
||||
extern long tk_nout;
|
||||
extern long tk_rawcc;
|
||||
|
||||
int b_to_q(char *cp, int cc, struct clist *q);
|
||||
void catq(struct clist *from, struct clist *to);
|
||||
void clist_alloc_cblocks(struct clist *q, int ccmax, int ccres);
|
||||
void clist_free_cblocks(struct clist *q);
|
||||
void constty_set(struct tty *tp);
|
||||
void constty_clear(void);
|
||||
int getc(struct clist *q);
|
||||
void ndflush(struct clist *q, int cc);
|
||||
char *nextc(struct clist *q, char *cp, int *c);
|
||||
void nottystop(struct tty *tp, int rw);
|
||||
int putc(int c, struct clist *q);
|
||||
int q_to_b(struct clist *q, char *cp, int cc);
|
||||
void termioschars(struct termios *t);
|
||||
int tputchar(int c, struct tty *tp);
|
||||
int ttcompat(struct tty *tp, u_long com, caddr_t data, int flag);
|
||||
@ -367,7 +342,6 @@ int ttyref(struct tty *tp);
|
||||
int ttyrel(struct tty *tp);
|
||||
int ttysleep(struct tty *tp, void *chan, int pri, char *wmesg, int timo);
|
||||
int ttywait(struct tty *tp);
|
||||
int unputc(struct clist *q);
|
||||
|
||||
static __inline int
|
||||
tt_open(struct tty *t, struct cdev *c)
|
||||
|
Loading…
Reference in New Issue
Block a user