Re: How do I choose an arbitrary minor number for my tty device?

From: Timur Tabi
Date: Tue Nov 23 2010 - 12:17:03 EST


Alan Cox wrote:
> Your console driver provides a device method (see kernel/printk.c).
> When /dev/console is opened the kernel iterates the console list looking
> for one with ->device and then calls that method. On success it expects
> the passed int * to contain the minor number to use.

Are you talking about this:

static struct tty_driver *ehv_bc_console_device(struct console *co, int *index)
{
*index = co->index;

return ehv_bc_driver;
}

I never really understood this function, but almost everyone does the same
thing, and it seems to work for me. Looking at console_device(), it appears
that all of the xxx_console_device functions are called in order until one of
them returns non-NULL.

How is this related to add_preferred_console()? When I call this function, I
also specify the same index and the name from the struct console device:

static struct console ehv_bc_console = {
.name = "ttyEHV",
.write = ehv_bc_console_write,
.device = ehv_bc_console_device,
.flags = CON_PRINTBUFFER | CON_ENABLED,
};

add_preferred_console(ehv_bc_console.name, ehv_bc_console.index, NULL);
register_console(&ehv_bc_console);

> I suspect in your case you probably want to attach the primary byte
> channel to minor 0 in the driver (and reserve it for that), or some
> similar rule.

Yes, that's a good idea. It does simplify things a lot.

--
Timur Tabi
Linux kernel developer at Freescale

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/