uclinux-2008r1-rc8(bf561)内核的console(1):数据结构

 
内核中与console相关的结构体可以分为通用定义与不同体系结构的定义两部分,通用定义与具体的硬件无关,它只是定义了一类硬件的通用参数与接口,不同的体系结构下还需要加上一些特有的东西。
这个结构体的定义位于include/linux/serial_core.h,它定义了UART要实现的操作:
/*
 * This structure describes all the operations that can be
 * done on the physical hardware.
 */
struct uart_ops {
     unsigned int (*tx_empty)(struct uart_port *);
     void     (*set_mctrl)(struct uart_port *, unsigned int mctrl);
     unsigned int (*get_mctrl)(struct uart_port *);
     void     (*stop_tx)(struct uart_port *);
     void     (*start_tx)(struct uart_port *);
     void     (*send_xchar)(struct uart_port *, char ch);
     void     (*stop_rx)(struct uart_port *);
     void     (*enable_ms)(struct uart_port *);
     void     (*break_ctl)(struct uart_port *, int ctl);
     int      (*startup)(struct uart_port *);
     void     (*shutdown)(struct uart_port *);
     void     (*set_termios)(struct uart_port *, struct ktermios *new,
                          struct ktermios *old);
     void     (*pm)(struct uart_port *, unsigned int state,
                    unsigned int oldstate);
     int      (*set_wake)(struct uart_port *, unsigned int state);
 
     /*
      * Return a string describing the type of the port
      */
     const char *(*type)(struct uart_port *);
 
     /*
      * Release IO and memory resources used by the port.
      * This includes iounmap if necessary.
      */
     void     (*release_port)(struct uart_port *);
 
     /*
      * Request IO and memory resources used by the port.
      * This includes iomapping the port if necessary.
      */
     int      (*request_port)(struct uart_port *);
     void     (*config_port)(struct uart_port *, int);
     int      (*verify_port)(struct uart_port *, struct serial_struct *);
     int      (*ioctl)(struct uart_port *, unsigned int, unsigned long);
};
 
这个结构体的定义位于include/linux/serial_core.h,从它的位置可以看出,这是一个与具体硬件无关的结构体,它提供了对UART的描述信息,对于某个具体的UART,可能只使用其中的某些字段。
struct uart_port {
     spinlock_t         lock;              /* port lock */
     unsigned int       iobase;            /* in/out[bwl] */
     unsigned char __iomem *membase;     /* read/write[bwl] */
     unsigned int       irq;          /* irq number */
     unsigned int       uartclk;      /* base uart clock */
     unsigned int       fifosize;     /* tx fifo size */
     unsigned char      x_char;            /* xon/xoff char */
     unsigned char      regshift;     /* reg offset shift */
     unsigned char      iotype;            /* io access style */
     unsigned char      unused1;
 
     unsigned int       read_status_mask; /* driver specific */
     unsigned int       ignore_status_mask;    /* driver specific */
     struct uart_info   *info;             /* pointer to parent info */
     struct uart_icount icount;            /* statistics */
 
     struct console         *cons;             /* struct console, if any */
 
     upf_t              flags;
 
     unsigned int       mctrl;             /* current modem ctrl settings */
     unsigned int       timeout;      /* character-based timeout */
     unsigned int       type;              /* port type */
     const struct uart_ops *ops;
     unsigned int       custom_divisor;
     unsigned int       line;              /* port index */
     unsigned long      mapbase;      /* for ioremap */
     struct device      *dev;              /* parent device */
     unsigned char      hub6;              /* this should be in the 8250 driver */
     unsigned char      unused[3];
     void          *private_data;         /* generic platform data pointer */
};
在内核中,没有为uart_port定义独立的变量,它将从属于某个具体的serial_port,对于bf561,它将从属于bfin_serial_port这一结构体。
实际上内核只使用了以下几个成员:
l         uartclk 这个值将设置为BF561的系统时钟频率,在我的系统中,它将为99M。
l         ops 定义对UART的操作函数,指向bfin_serial_pops这一变量。
l         line 串口序号,只有一个串口,恒为0。
l         iotype 取UPIO_MEM,即直接寄存器访问方式。
l         membase 指向UART_THR(0xFFC0 0400),即UART的发送寄存器。
l         mapbase 与membase相同。
l         irq 内核中中断描述数组(irq_desc)的序号,指UART接收中断( IRQ_UART_RX)。
l         flags 配置为UPF_BOOT_AUTOCONF。
 
 
这个结构体的定义在include/asm/mach/bfin-serial-5xx.h中:
struct bfin_serial_port {
        struct uart_port        port;
        unsigned int            old_status;
     unsigned int lsr;
};
此结构体在uart_port的基础上,扩充了两个成员。
在内核中,有这样的定义:
struct bfin_serial_port bfin_serial_ports[NR_PORTS];
在这里,NR_PORTS的值为1,对UART的所有操作都将通过这一变量来完成。
这个结构体的定义在include/linux/console.h中,它定义了一个console驱动需要提供的信息及其必须实现的一些操作:
/*
 * The interface for a console, or any other device that wants to capture
 * console messages (printer driver?)
 *
 * If a console driver is marked CON_BOOT then it will be auto-unregistered
 * when the first real console is registered. This is for early-printk drivers.
 */
 
struct console {
     char name[16];
     void (*write)(struct console *, const char *, unsigned);
     int (*read)(struct console *, char *, unsigned);
     struct tty_driver *(*device)(struct console *, int *);
     void (*unblank)(void);
     int (*setup)(struct console *, char *);
     short    flags;
     short    index;
     int cflag;
     void *data;
     struct   console *next;
};
在内核中,对此结构体初始化为:
static struct console bfin_serial_console = {
     .name         = BFIN_SERIAL_NAME,   // ttyBF
     .write        = bfin_serial_console_write,
     .device       = uart_console_device,
     .setup        = bfin_serial_console_setup,
     .flags        = CON_PRINTBUFFER,
     .index        = -1,
     .data         = &bfin_serial_reg,
};
而console中的cflag则保存了串口配置,如 CREAD | HUPCL | CLOCAL | B57600 | CS8 ,使用它即可知道当前的串口配置。
flags的值在初始化完成后则变成了 CON_PRINTBUFFER | CON_ENABLED | CON_CONSDEV。
index的值在初始化完成后变成0,因为只使用serial console。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌云阁主

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值