FreeBSD kernel kern code
subr_terminal.c File Reference
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/cons.h>
#include <sys/consio.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/systm.h>
#include <sys/terminal.h>
#include <sys/tty.h>
#include <machine/stdarg.h>
Include dependency graph for subr_terminal.c:

Go to the source code of this file.

Macros

#define TERMINAL_LOCK(tm)
 
#define TERMINAL_UNLOCK(tm)
 
#define TERMINAL_LOCK_TTY(tm)
 
#define TERMINAL_UNLOCK_TTY(tm)
 
#define TERMINAL_LOCK_CONS(tm)   mtx_lock_spin(&(tm)->tm_mtx)
 
#define TERMINAL_UNLOCK_CONS(tm)   mtx_unlock_spin(&(tm)->tm_mtx)
 
#define TCHAR_CREATE(c, a)
 

Functions

 __FBSDID ("$BSDSUniX$")
 
static MALLOC_DEFINE (M_TERMINAL,"terminal","terminal device")
 
static void terminal_init (struct terminal *tm)
 
struct terminal * terminal_alloc (const struct terminal_class *tc, void *softc)
 
static void terminal_sync_ttysize (struct terminal *tm)
 
void terminal_maketty (struct terminal *tm, const char *fmt,...)
 
void terminal_set_winsize_blank (struct terminal *tm, const struct winsize *size, int blank)
 
void terminal_set_winsize (struct terminal *tm, const struct winsize *size)
 
void terminal_mute (struct terminal *tm, int yes)
 
void terminal_input_char (struct terminal *tm, term_char_t c)
 
void terminal_input_raw (struct terminal *tm, char c)
 
void terminal_input_special (struct terminal *tm, unsigned int k)
 
static int termtty_open (struct tty *tp)
 
static void termtty_close (struct tty *tp)
 
static void termtty_outwakeup (struct tty *tp)
 
static int termtty_ioctl (struct tty *tp, u_long cmd, caddr_t data, struct thread *td)
 
static int termtty_mmap (struct tty *tp, vm_ooffset_t offset, vm_paddr_t *paddr, int nprot, vm_memattr_t *memattr)
 
void termcn_cnregister (struct terminal *tm)
 
static void termcn_cngrab (struct consdev *cp)
 
static void termcn_cnungrab (struct consdev *cp)
 
static void termcn_cnprobe (struct consdev *cp)
 
static void termcn_cninit (struct consdev *cp)
 
static void termcn_cnterm (struct consdev *cp)
 
static int termcn_cngetc (struct consdev *cp)
 
static void termcn_cnputc (struct consdev *cp, int c)
 
static void termteken_bell (void *softc)
 
static void termteken_cursor (void *softc, const teken_pos_t *p)
 
static void termteken_putchar (void *softc, const teken_pos_t *p, teken_char_t c, const teken_attr_t *a)
 
static void termteken_fill (void *softc, const teken_rect_t *r, teken_char_t c, const teken_attr_t *a)
 
static void termteken_copy (void *softc, const teken_rect_t *r, const teken_pos_t *p)
 
static void termteken_param (void *softc, int cmd, unsigned int arg)
 
static void termteken_respond (void *softc, const void *buf, size_t len)
 

Variables

static tsw_open_t termtty_open
 
static tsw_close_t termtty_close
 
static tsw_outwakeup_t termtty_outwakeup
 
static tsw_ioctl_t termtty_ioctl
 
static tsw_mmap_t termtty_mmap
 
static struct ttydevsw terminal_tty_class
 
static tf_bell_t termteken_bell
 
static tf_cursor_t termteken_cursor
 
static tf_putchar_t termteken_putchar
 
static tf_fill_t termteken_fill
 
static tf_copy_t termteken_copy
 
static tf_param_t termteken_param
 
static tf_respond_t termteken_respond
 
static teken_funcs_t terminal_drawmethods
 
static const teken_attr_t kernel_message
 
static const teken_attr_t default_message
 
static cn_probe_t termcn_cnprobe
 
static cn_init_t termcn_cninit
 
static cn_term_t termcn_cnterm
 
static cn_getc_t termcn_cngetc
 
static cn_putc_t termcn_cnputc
 
static cn_grab_t termcn_cngrab
 
static cn_ungrab_t termcn_cnungrab
 
const struct consdev_ops termcn_cnops
 

Macro Definition Documentation

#define TCHAR_CREATE (   c,
 
)
Value:
((c) | \
(a)->ta_format << 21 | \
teken_256to8((a)->ta_fgcolor) << 26 | \
teken_256to8((a)->ta_bgcolor) << 29)

Definition at line 132 of file subr_terminal.c.

Referenced by terminal_set_winsize_blank(), termteken_fill(), and termteken_putchar().

#define TERMINAL_LOCK (   tm)
Value:
do { \
if ((tm)->tm_flags & TF_CONS) \
mtx_lock_spin(&(tm)->tm_mtx); \
else if ((tm)->tm_tty != NULL) \
tty_lock((tm)->tm_tty); \
} while (0)

Definition at line 57 of file subr_terminal.c.

Referenced by terminal_mute(), and terminal_set_winsize_blank().

#define TERMINAL_LOCK_CONS (   tm)    mtx_lock_spin(&(tm)->tm_mtx)

Definition at line 77 of file subr_terminal.c.

Referenced by termcn_cnputc().

#define TERMINAL_LOCK_TTY (   tm)
Value:
do { \
if ((tm)->tm_flags & TF_CONS) \
mtx_lock_spin(&(tm)->tm_mtx); \
} while (0)

Definition at line 69 of file subr_terminal.c.

Referenced by termtty_outwakeup().

#define TERMINAL_UNLOCK (   tm)
Value:
do { \
if ((tm)->tm_flags & TF_CONS) \
mtx_unlock_spin(&(tm)->tm_mtx); \
else if ((tm)->tm_tty != NULL) \
tty_unlock((tm)->tm_tty); \
} while (0)

Definition at line 63 of file subr_terminal.c.

Referenced by terminal_mute(), and terminal_set_winsize_blank().

#define TERMINAL_UNLOCK_CONS (   tm)    mtx_unlock_spin(&(tm)->tm_mtx)

Definition at line 78 of file subr_terminal.c.

Referenced by termcn_cnputc().

#define TERMINAL_UNLOCK_TTY (   tm)
Value:
do { \
if ((tm)->tm_flags & TF_CONS) \
mtx_unlock_spin(&(tm)->tm_mtx); \
} while (0)

Definition at line 73 of file subr_terminal.c.

Referenced by termtty_outwakeup().

Function Documentation

__FBSDID ( "$BSDSUniX$"  )
static MALLOC_DEFINE ( M_TERMINAL  ,
"terminal"  ,
"terminal device  
)
static
static int termcn_cngetc ( struct consdev *  cp)
static

Definition at line 516 of file subr_terminal.c.

static void termcn_cngrab ( struct consdev *  cp)
static

Definition at line 476 of file subr_terminal.c.

static void termcn_cninit ( struct consdev *  cp)
static

Definition at line 504 of file subr_terminal.c.

static void termcn_cnprobe ( struct consdev *  cp)
static

Definition at line 488 of file subr_terminal.c.

References terminal_init().

Here is the call graph for this function:

static void termcn_cnputc ( struct consdev *  cp,
int  c 
)
static

Definition at line 524 of file subr_terminal.c.

References kernel_message, TERMINAL_LOCK_CONS, and TERMINAL_UNLOCK_CONS.

void termcn_cnregister ( struct terminal *  tm)

Definition at line 452 of file subr_terminal.c.

References cnadd(), malloc(), sprintf(), termcn_cnops, and terminal_init().

Here is the call graph for this function:

static void termcn_cnterm ( struct consdev *  cp)
static

Definition at line 510 of file subr_terminal.c.

static void termcn_cnungrab ( struct consdev *  cp)
static

Definition at line 482 of file subr_terminal.c.

struct terminal* terminal_alloc ( const struct terminal_class *  tc,
void *  softc 
)

Definition at line 148 of file subr_terminal.c.

References malloc(), and terminal_init().

Here is the call graph for this function:

static void terminal_init ( struct terminal *  tm)
static

Definition at line 138 of file subr_terminal.c.

References default_message, mtx_init(), and terminal_drawmethods.

Referenced by termcn_cnprobe(), termcn_cnregister(), and terminal_alloc().

Here is the call graph for this function:

Here is the caller graph for this function:

void terminal_input_char ( struct terminal *  tm,
term_char_t  c 
)

Definition at line 244 of file subr_terminal.c.

References ttydisc_rint(), ttydisc_rint_done(), and ttydisc_rint_simple().

Here is the call graph for this function:

void terminal_input_raw ( struct terminal *  tm,
char  c 
)

Definition at line 297 of file subr_terminal.c.

References ttydisc_rint(), and ttydisc_rint_done().

Here is the call graph for this function:

void terminal_input_special ( struct terminal *  tm,
unsigned int  k 
)

Definition at line 312 of file subr_terminal.c.

References ttydisc_rint_done(), and ttydisc_rint_simple().

Here is the call graph for this function:

void terminal_maketty ( struct terminal *  tm,
const char *  fmt,
  ... 
)

Definition at line 176 of file subr_terminal.c.

References name, terminal_sync_ttysize(), terminal_tty_class, tty_alloc(), tty_makedev(), and vsnrprintf().

Here is the call graph for this function:

void terminal_mute ( struct terminal *  tm,
int  yes 
)

Definition at line 232 of file subr_terminal.c.

References TERMINAL_LOCK, and TERMINAL_UNLOCK.

void terminal_set_winsize ( struct terminal *  tm,
const struct winsize *  size 
)

Definition at line 219 of file subr_terminal.c.

References terminal_set_winsize_blank().

Here is the call graph for this function:

void terminal_set_winsize_blank ( struct terminal *  tm,
const struct winsize *  size,
int  blank 
)

Definition at line 193 of file subr_terminal.c.

References default_message, TCHAR_CREATE, TERMINAL_LOCK, terminal_sync_ttysize(), and TERMINAL_UNLOCK.

Referenced by terminal_set_winsize().

Here is the call graph for this function:

Here is the caller graph for this function:

static void terminal_sync_ttysize ( struct terminal *  tm)
static

Definition at line 162 of file subr_terminal.c.

References tty_set_winsize().

Referenced by terminal_maketty(), and terminal_set_winsize_blank().

Here is the call graph for this function:

Here is the caller graph for this function:

static void termteken_bell ( void *  softc)
static

Definition at line 547 of file subr_terminal.c.

static void termteken_copy ( void *  softc,
const teken_rect_t *  r,
const teken_pos_t *  p 
)
static

Definition at line 581 of file subr_terminal.c.

static void termteken_cursor ( void *  softc,
const teken_pos_t *  p 
)
static

Definition at line 555 of file subr_terminal.c.

static void termteken_fill ( void *  softc,
const teken_rect_t *  r,
teken_char_t  c,
const teken_attr_t *  a 
)
static

Definition at line 572 of file subr_terminal.c.

References TCHAR_CREATE.

static void termteken_param ( void *  softc,
int  cmd,
unsigned int  arg 
)
static

Definition at line 589 of file subr_terminal.c.

static void termteken_putchar ( void *  softc,
const teken_pos_t *  p,
teken_char_t  c,
const teken_attr_t *  a 
)
static

Definition at line 563 of file subr_terminal.c.

References TCHAR_CREATE.

static void termteken_respond ( void *  softc,
const void *  buf,
size_t  len 
)
static

Definition at line 597 of file subr_terminal.c.

References ttydisc_rint_done(), and ttydisc_rint_simple().

Here is the call graph for this function:

static void termtty_close ( struct tty *  tp)
static

Definition at line 345 of file subr_terminal.c.

static int termtty_ioctl ( struct tty *  tp,
u_long  cmd,
caddr_t  data,
struct thread *  td 
)
static

Definition at line 376 of file subr_terminal.c.

static int termtty_mmap ( struct tty *  tp,
vm_ooffset_t  offset,
vm_paddr_t *  paddr,
int  nprot,
vm_memattr_t *  memattr 
)
static

Definition at line 421 of file subr_terminal.c.

static int termtty_open ( struct tty *  tp)
static

Definition at line 336 of file subr_terminal.c.

static void termtty_outwakeup ( struct tty *  tp)
static

Definition at line 353 of file subr_terminal.c.

References TERMINAL_LOCK_TTY, TERMINAL_UNLOCK_TTY, and ttydisc_getc().

Here is the call graph for this function:

Variable Documentation

const teken_attr_t default_message
static
Initial value:
= {
.ta_fgcolor = TC_WHITE,
.ta_bgcolor = TC_BLACK,
}

Definition at line 127 of file subr_terminal.c.

Referenced by terminal_init(), and terminal_set_winsize_blank().

const teken_attr_t kernel_message
static
Initial value:
= {
.ta_fgcolor = TC_WHITE,
.ta_bgcolor = TC_BLACK,
.ta_format = TF_BOLD,
}

Definition at line 121 of file subr_terminal.c.

Referenced by termcn_cnputc().

cn_getc_t termcn_cngetc
static

Definition at line 436 of file subr_terminal.c.

cn_grab_t termcn_cngrab
static

Definition at line 438 of file subr_terminal.c.

cn_init_t termcn_cninit
static

Definition at line 434 of file subr_terminal.c.

const struct consdev_ops termcn_cnops
Initial value:
= {
.cn_probe = termcn_cnprobe,
.cn_init = termcn_cninit,
.cn_term = termcn_cnterm,
.cn_getc = termcn_cngetc,
.cn_putc = termcn_cnputc,
.cn_grab = termcn_cngrab,
.cn_ungrab = termcn_cnungrab,
}
static cn_grab_t termcn_cngrab
static cn_init_t termcn_cninit
static cn_term_t termcn_cnterm
static cn_putc_t termcn_cnputc
static cn_getc_t termcn_cngetc
static cn_probe_t termcn_cnprobe
static cn_ungrab_t termcn_cnungrab

Definition at line 441 of file subr_terminal.c.

Referenced by termcn_cnregister().

cn_probe_t termcn_cnprobe
static

Definition at line 433 of file subr_terminal.c.

cn_putc_t termcn_cnputc
static

Definition at line 437 of file subr_terminal.c.

cn_term_t termcn_cnterm
static

Definition at line 435 of file subr_terminal.c.

cn_ungrab_t termcn_cnungrab
static

Definition at line 439 of file subr_terminal.c.

teken_funcs_t terminal_drawmethods
static
Initial value:
= {
.tf_bell = termteken_bell,
.tf_cursor = termteken_cursor,
.tf_putchar = termteken_putchar,
.tf_fill = termteken_fill,
.tf_copy = termteken_copy,
.tf_param = termteken_param,
.tf_respond = termteken_respond,
}
static tf_putchar_t termteken_putchar
static tf_respond_t termteken_respond
static tf_cursor_t termteken_cursor
static tf_copy_t termteken_copy
static tf_bell_t termteken_bell
static tf_param_t termteken_param
static tf_fill_t termteken_fill

Definition at line 110 of file subr_terminal.c.

Referenced by terminal_init().

struct ttydevsw terminal_tty_class
static
Initial value:
= {
.tsw_open = termtty_open,
.tsw_close = termtty_close,
.tsw_outwakeup = termtty_outwakeup,
.tsw_ioctl = termtty_ioctl,
.tsw_mmap = termtty_mmap,
}
static tsw_mmap_t termtty_mmap
Definition: subr_terminal.c:88
static tsw_ioctl_t termtty_ioctl
Definition: subr_terminal.c:87
static tsw_close_t termtty_close
Definition: subr_terminal.c:85
static tsw_open_t termtty_open
Definition: subr_terminal.c:84
static tsw_outwakeup_t termtty_outwakeup
Definition: subr_terminal.c:86

Definition at line 90 of file subr_terminal.c.

Referenced by terminal_maketty().

tf_bell_t termteken_bell
static

Definition at line 102 of file subr_terminal.c.

tf_copy_t termteken_copy
static

Definition at line 106 of file subr_terminal.c.

tf_cursor_t termteken_cursor
static

Definition at line 103 of file subr_terminal.c.

tf_fill_t termteken_fill
static

Definition at line 105 of file subr_terminal.c.

tf_param_t termteken_param
static

Definition at line 107 of file subr_terminal.c.

tf_putchar_t termteken_putchar
static

Definition at line 104 of file subr_terminal.c.

tf_respond_t termteken_respond
static

Definition at line 108 of file subr_terminal.c.

tsw_close_t termtty_close
static

Definition at line 85 of file subr_terminal.c.

tsw_ioctl_t termtty_ioctl
static

Definition at line 87 of file subr_terminal.c.

tsw_mmap_t termtty_mmap
static

Definition at line 88 of file subr_terminal.c.

tsw_open_t termtty_open
static

Definition at line 84 of file subr_terminal.c.

tsw_outwakeup_t termtty_outwakeup
static

Definition at line 86 of file subr_terminal.c.