__add_preferred_console的作用是添加console到console_cmdline 数组

来源:互联网 发布:win10查看图片软件 编辑:程序博客网 时间:2024/06/01 09:52
在printk.c 中有定义一个数组static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
 在程序中调用__add_preferred_console 会将kernel commandline 或者 通过acpi的scpr 表传递过来的console参数添加到console_cmdline 中
static int __add_preferred_console(char *name, int idx, char *options,
                   char *brl_options)
{
    struct console_cmdline *c;
    int i;

    /*
     *    See if this tty is not yet registered, and
     *    if we have a slot free.
     */
    for (i = 0, c = console_cmdline;
         i < MAX_CMDLINECONSOLES && c->name[0];
         i++, c++) {
        if (strcmp(c->name, name) == 0 && c->index == idx) {
            if (!brl_options)
                selected_console = i;
            return 0;
        }
    }
    if (i == MAX_CMDLINECONSOLES)
        return -E2BIG;
    if (!brl_options)
        selected_console = i;
    strlcpy(c->name, name, sizeof(c->name));
    c->options = options;
    braille_set_options(c, brl_options);

    c->index = idx;
    return 0;
}
这样当个个console driver 调用register_console的时候,就会通过下面的code 来匹配注册的console 和 保存在console_cmdline 中的console是否匹配
    for (i = 0, c = console_cmdline;
         i < MAX_CMDLINECONSOLES && c->name[0];
         i++, c++) {
        if (!newcon->match ||
            newcon->match(newcon, c->name, c->index, c->options) != 0) {
            /* default matching */
            BUILD_BUG_ON(sizeof(c->name) != sizeof(newcon->name));
            if (strcmp(c->name, newcon->name) != 0)
                continue;
            if (newcon->index >= 0 &&
                newcon->index != c->index)
                continue;
            if (newcon->index < 0)
                newcon->index = c->index;

            if (_braille_register_console(newcon, c))
                return;

            if (newcon->setup &&
                newcon->setup(newcon, c->options) != 0)
                break;
        }

        newcon->flags |= CON_ENABLED;
        if (i == selected_console) {
            newcon->flags |= CON_CONSDEV;
            preferred_console = selected_console;
        }
        break;
    }
从这段code中console driver 要么提供match函数,要么提供setup函数,或者两者都提供。在__add_preferred_console 中会设置selected_console 来选择用哪个console driver,这样的话,如果在调用register_console的时候发现当前调用的console driver 和selected_console 相等,就或上CON_CONSDEV,并让preferred_console = selected_console

0 0