在procttydriver添加rial⽂件,来统计系统的串⼝设备的统计
信息
1、⽬前系统有4类串⼝设备 omap spi usb 4g,美⼀类都有⾃⼰的信息。需要统⼀到⼀个⽂件⾥
2、在D:\z_linux_picohood_project\board-support_xj\board-support\linux-4.4.x-mainline\linux-4.4.x-mainline\drivers\tty\rial\rial_core.c 添加⾃⼰的lsh_rial_uart_proc_fops
/*add by lsh*/
const struct file_operations lsh_rial_uart_proc_fops = {
.owner = THIS_MODULE,
.open = uart_proc_open,
.read = q_read,
.llek = q_lek,
.relea = single_relea,
};
EXPORT_SYMBOL_GPL(lsh_rial_uart_proc_fops);
3、在D:\z_linux_picohood_project\board-support_xj\board-support\linux-4.4.x-mainline\linux-4.4.x-mainline\fs\proc\proc_tty.c安全生产管理人员
添加proc_create_data("rial", 0, proc_tty_driver, &lsh_rial_uart_proc_fops, NULL);
void __init proc_tty_init(void)
{
if (!proc_mkdir("tty", NULL))
return;
proc_mkdir("tty/ldisc", NULL); /* Prerved: it's urspace visible */
/*
* /proc/tty/driver/rial reveals the exact character counts for
* rial links which is just too easy to abu for inferring
* password lengths and inter-keystroke timings during password
* entry.
*/
proc_tty_driver = proc_mkdir_mode("tty/driver", S_IRUSR|S_IXUSR, NULL);
proc_create("tty/ldiscs", 0, NULL, &tty_ldiscs_proc_fops);
proc_create("tty/drivers", 0, NULL, &proc_tty_drivers_operations);
/*add by lsh*/
//proc_create("tty/driver/rial", 0, NULL, &lsh_rial_uart_proc_fops);
proc_create_data("rial", 0, proc_tty_driver, &lsh_rial_uart_proc_fops, NULL);
}
4、添加⼀个函数通过⽂件名找到对应的struct tty_driver函数
/*add by lsh*/
struct tty_driver * return_my_rial_proc_tty_driver(const char *name)
院感知识培训
{
struct tty_driver *ttydrv;
struct proc_dir_entry * file_dir;
file_dir = pde_subdir_find(proc_tty_driver,name,strlen(name));
ttydrv = file_dir->data;
return ttydrv;
}
5、添加对应驱动的串⼝统计的数据打印到指定⽂件
/
*add by lsh*/
static void rial_uart_line_info(struct q_file *m, struct uart_driver *drv, int i, int disp_nr)
{
struct uart_state *state = drv->state + i;
struct tty_port *port = &state->port;
enum uart_pm_state pm_state;
struct uart_port *uport = state->uart_port;
char stat_buf[32];
unsigned int status;
int mmio;
if (!uport)
return;
mmio = uport->iotype >= UPIO_MEM;
q_printf(m, "%d: uart:%s %s%08llX irq:%d",
disp_nr, mmio ? "OMAPSERI" : "MAX14830",
mmio ? "mmio:0x" : "port:0x",
mmio ? (unsigned long long)uport->mapba
: (unsigned long long)uport->ioba,
uport->irq);
if (uport->type == PORT_UNKNOWN) {
q_putc(m, '\n');
return;
}
if (capable(CAP_SYS_ADMIN)) {
mutex_lock(&port->mutex);
pm_state = state->pm_state;
if (pm_state != UART_PM_STATE_ON)
uart_change_pm(state, UART_PM_STATE_ON);
spin_lock_irq(&uport->lock);
status = uport->ops->get_mctrl(uport);
spin_unlock_irq(&uport->lock);
if (pm_state != UART_PM_STATE_ON)
uart_change_pm(state, pm_state);
mutex_unlock(&port->mutex);
q_printf(m, " tx:%d rx:%d",
uport-&, uport-&);
if (uport->icount.frame)
q_printf(m, " fe:%d",
uport->icount.frame);
if (uport->icount.parity)
q_printf(m, " pe:%d",
uport->icount.parity);
if (uport->icount.brk)
q_printf(m, " brk:%d",
uport->icount.brk);
if (uport->icount.overrun)
q_printf(m, " oe:%d",
uport->icount.overrun);
#define INFOBIT(bit, str) \
if (uport->mctrl & (bit)) \
strncat(stat_buf, (str), sizeof(stat_buf) - \
strlen(stat_buf) - 2)
#define STATBIT(bit, str) \
if (status & (bit)) \
strncat(stat_buf, (str), sizeof(stat_buf) - \
strlen(stat_buf) - 2)
stat_buf[0] = '\0';
stat_buf[1] = '\0';
INFOBIT(TIOCM_RTS, "|RTS");
STATBIT(TIOCM_CTS, "|CTS");
INFOBIT(TIOCM_DTR, "|DTR");
STATBIT(TIOCM_DSR, "|DSR");
STATBIT(TIOCM_CAR, "|CD");
STATBIT(TIOCM_RNG, "|RI");
if (stat_buf[0])
stat_buf[0] = ' ';
q_puts(m, stat_buf);
}
q_putc(m, '\n');
手机三包是哪三包
#undef STATBIT
#undef INFOBIT
}
6、usb转串⼝的数据⽐较不⼀致,需要单独加显⽰函数
/* add by lsh*/
static int usb_rial_proc_show(struct q_file *m,struct tty_driver *ttydrv,int i,int disp_nr) {
struct tty_struct *tty;
struct usb_rial *rial;
struct usb_rial_port *port;
char stat_buf[40];
unsigned int status;
port = usb_rial_port_get_by_minor(i);
if (port == NULL)
return 0;
rial = port->rial;
/*******************************************************************************/
/*add by lsh */
q_printf(m, "%d: uart:%s %s%08X irq:%d",
disp_nr,module_name(rial->type->driver.owner),
"port:0x",
(unsigned int)port,
183);
q_printf(m, " tx:%d rx:%d",
port-&, port-&);
if (port->icount.frame)
q_printf(m, " fe:%d",
port->icount.frame);
if (port->icount.parity)
绿仙子
q_printf(m, " pe:%d",
port->icount.parity);
if (port->icount.brk)
q_printf(m, " brk:%d",
port->icount.brk);
if (port->icount.overrun)
参加葬礼注意事项q_printf(m, " oe:%d",
port->icount.overrun);
q_printf(m, " DSR|",
port->icount.overrun);
q_printf(m, "CD",
port->icount.overrun);
/*
tty = tty_port_tty_get(&port->port);
status = rial->type->tiocmget(tty); //kernel null pointer
#define STATBIT(bit, str) \
增高方法if (status & (bit)) \
strncat(stat_buf, (str), sizeof(stat_buf) - \
strlen(stat_buf) - 2)
stat_buf[0] = '\0';
stat_buf[1] = '\0';
STATBIT(TIOCM_RTS, "|RTS");
STATBIT(TIOCM_CTS, "|CTS");
STATBIT(TIOCM_DTR, "|DTR");
STATBIT(TIOCM_DSR, "|DSR");
STATBIT(TIOCM_CAR, "|CD");
STATBIT(TIOCM_RNG, "|RI");
if (stat_buf[0])
stat_buf[0] = ' ';
q_puts(m, stat_buf);
*/
q_putc(m, '\n');
/*******************************************************************************/
usb_rial_put(rial);
因数和倍数的概念mutex_unlock(&rial->disc_mutex);
#undef STATBIT
}
7、usb需要通过此设备号,获取当前的串⼝号,需要将改函数导出usb_rial_port_get_by_minor
D:\z_linux_picohood_project\board-support_xj\board-support\linux-4.4.x-mainline\linux-4.4.x-mainline\drivers\usb\rial\usb-rial.c struct usb_rial_port *usb_rial_port_get_by_minor(unsigned minor)
{
struct usb_rial *rial;
struct usb_rial_port *port;
mutex_lock(&table_lock);
port = idr_find(&rial_minors, minor);少林十三棍僧
if (!port)
goto exit;
rial = port->rial;
mutex_lock(&rial->disc_mutex);
if (rial->disconnected) {
mutex_unlock(&rial->disc_mutex);
port = NULL;
} el {
kref_get(&rial->kref);
}
exit:
mutex_unlock(&table_lock);
return port;
}
/*add by lsh*/
EXPORT_SYMBOL_GPL(usb_rial_port_get_by_minor);
8、usb串⼝要配置⼀个⽂件名,才会在、/proc/tty/driver/ 下⽣成 usbriver⽂件,其他的⽂件都是在对应驱动注册时。加⼊了配置
D:\z_linux_picohood_project\board-support_xj\board-support\linux-4.4.x-mainline\linux-4.4.x-mainline\drivers\usb\rial\usb-rial.c
static int __init usb_rial_init(void)
{
int result;
usb_rial_tty_driver = alloc_tty_driver(USB_SERIAL_TTY_MINORS);
if (!usb_rial_tty_driver)
return -ENOMEM;
/* Initialize our global data */
result = bus_register(&usb_rial_bus_type);
if (result) {
pr_err("%s - registering bus driver failed\n", __func__);
goto exit_bus;
}
usb_rial_tty_driver->driver_name = "usbrial";
usb_rial_tty_driver->name = "ttyUSB";
usb_rial_tty_driver->major = USB_SERIAL_TTY_MAJOR;
usb_rial_tty_driver->minor_start = 0;
usb_rial_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
usb_rial_tty_driver->subtype = SERIAL_TYPE_NORMAL;
usb_rial_tty_driver->flags = TTY_DRIVER_REAL_RAW |
TTY_DRIVER_DYNAMIC_DEV;
usb_rial_tty_driver->init_termios = tty_std_termios;
usb_rial_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD
| HUPCL | CLOCAL;
usb_rial_tty_driver->init_termios.c_ispeed = 9600;
usb_rial_tty_driver->init_termios.c_ospeed = 9600;
tty_t_operations(usb_rial_tty_driver, &rial_ops);
result = tty_register_driver(usb_rial_tty_driver);
if (result) {
pr_err("%s - tty_register_driver failed\n", __func__);
goto exit_reg_driver;
}
/* register the USB driver */
result = usb_register(&usb_rial_driver);
if (result < 0) {
pr_err("%s - usb_register failed\n", __func__);
goto exit_tty;
}
/* register the generic driver, if we should */
result = usb_rial_generic_register();
if (result < 0) {
pr_err("%s - registering generic driver failed\n", __func__); goto exit_generic;
}
return result;
exit_generic:
usb_deregister(&usb_rial_driver);
exit_tty:
tty_unregister_driver(usb_rial_tty_driver);
exit_reg_driver:
bus_unregister(&usb_rial_bus_type);
exit_bus:
pr_err("%s - returning with error %d\n", __func__, result); put_tty_driver(usb_rial_tty_driver);
return result;
}