• 【linux驱动分析】misc设备驱动


        misc设备驱动。又称混杂设备驱动。

    misc设备驱动共享一个设备驱动号MISC_MAJOR。它在includelinuxmajor.h中定义:

            #define MISC_MAJOR 10
    miscdevice的结构体例如以下,它在includelinuxmiscdevice.h中定义:
    struct  miscdevice {
     int  minor;
     const  char  *name;
     const  struct file_operations  *fops;
     struct  list_head  list;
     struct  device  *parent;
     struct  device  *this_device;
     const  char  *nodename;
     mode_t  mode;
    };
    misc设备驱动的注冊和注销时用这两个函数,他们也定义在includelinuxmiscdevice.h中:
    extern int misc_register(struct miscdevice * misc);
    extern int misc_deregister(struct miscdevice *misc);

    样例:
    再分配此设备号时,能够设为MISC_DYNAMIC_MINOR。这样会自己主动分配此设备号,如:
    static struct miscdevice misc = {
     .minor = MISC_DYNAMIC_MINOR,
     .name = DEVICE_NAME,
     .fops = &dev_fops,
    };
    以下的是file_operations结构体:
    static struct file_operations dev_fops = {
     .owner = THIS_MODULE,
     .unlocked_ioctl = sbc2440_leds_ioctl,
    };
    注冊和注销函数:
    static int __init dev_init(void)
    {
     int ret;
     …………

     ret = misc_register(&misc);
     printk (DEVICE_NAME" initialized ");
     return ret;
    }

    static void __exit dev_exit(void)
    {
     misc_deregister(&misc);
    }
  • 相关阅读:
    计算机网络学习笔记——计算机网络概述
    基础续一
    Python基础一
    linux lvm的操作手册_pvcreate_vgcreate_lvcreate_相关
    Oracle Linux 挂载存储
    MegaCLI SAS RAID Management Tool
    DELL RACADM 批量升级戴尔IDRAC固件
    LSI MegaCli 命令使用4
    LSI MegaCli 命令使用2
    LSI MegaCl i命令使用1
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/6925769.html
Copyright © 2020-2023  润新知