[置顶] 我对linux理解之tty二

时间:2022-10-11 23:37:01
我们在mxc_uart.c中还发现console的初始化:
static int __init mxcuart_console_init(void)
{
    register_console(&mxc_console);
    return 0;
}
转而看register_console(&mxc_console):
void register_console(struct console *console)
{
......

    /*
     *    Put this console in the list - keep the
     *    preferred driver at the head of the list.
     */
    acquire_console_sem();
    if ((console->flags & CON_CONSDEV) || console_drivers == NULL) {
        console->next = console_drivers;
        console_drivers = console; //设定console_drivers为该console,后面printk信息生成的buffer就会送到该console里面打印出来
        if (console->next)
            console->next->flags &= ~CON_CONSDEV;
    } else {
        console->next = console_drivers->next;
        console_drivers->next = console;
    }
    if (console->flags & CON_PRINTBUFFER) {
        /*
         * release_console_sem() will print out the buffered messages
         * for us.
         */
        spin_lock_irqsave(&logbuf_lock, flags);
        con_start = log_start; //printk buffer的起始地方
        spin_unlock_irqrestore(&logbuf_lock, flags);
    }
    release_console_sem();
}

这里我们就看注释的两个地方,可以知道,这个register_console的作用主要是将改port注册到printk,以备后面printk的信息buffer输出到改port上.

http://www.qrsdev.com/forum.php?mod=viewthread&tid=397&extra=page%3D1