u盘驱动 内核代码阅读 2.6.11.12版本
本文主要是对从U盘插入电脑后,驱动是咋样加载识别流程
先从device_register开始,这个函数在哪里调用的以后再分析
/**
* 往设备驱动程序模型中插入一个新的设备驱动。
* 并自动的在sysfs文件系统下为其创建一个新的目录
*/
//drivers\base\Core.c
int device_register(struct device *dev)
{
device_initialize(dev);
return device_add(dev);
}
int device_add(struct device *dev)
{
struct device *parent = NULL;
int error = -EINVAL;
dev = get_device(dev);
if (!dev || !strlen(dev->bus_id))
goto Error;
parent = get_device(dev->parent);
pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id);
/* first, register with generic layer. */
kobject_set_name(&dev->kobj, "%s", dev->bus_id);
if (parent)
dev->kobj.parent = &parent->kobj;
if ((error = kobject_add(&dev->kobj)))
goto Error;
if ((error = device_pm_add(dev)))
goto PMError;
if ((error = bus_add_device(dev)))
goto BusError;
down_write(&devices_subsys.rwsem);
if (parent)
list_add_tail(&dev->node, &parent->children);
up_write(&devices_subsys.rwsem);
/* notify platform of device entry */
if (platform_notify)
platform_notify(dev);
Done:
put_device(dev);
return error;
BusError:
device_pm_remove(dev);
PMError:
kobject_del(&dev->kobj);
Error:
if (parent)
put_device(parent);
goto Done;
}
int bus_add_device(struct device * dev)
{
struct bus_type * bus = get_bus(dev->bus);
int error = 0;
if (bus) {
down_write(&dev->bus->subsys.rwsem);
pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id);
list_add_tail(&dev->bus_list, &dev->bus->devices.list);
device_attach(dev);
up_write(&dev->bus->subsys.rwsem);
device_add_attrs(bus, dev);
sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id);
}
return error;
}
int device_attach(struct device * dev)
{
struct bus_type * bus = dev->bus;
struct list_head * entry;
int error;
if (dev->driver) {
device_bind_driver(dev);
return 1;
}
if (bus->match) {
list_for_each(entry, &bus->drivers.list) {
struct device_driver * drv = to_drv(entry);
error = driver_probe_device(drv, dev);
if (!error)
/* success, driver matched */
return 1;
if (error != -ENODEV && error != -ENXIO)
/* driver matched but the probe failed */
printk(KERN_WARNING
"%s: probe of %s failed with error %d\n",
drv->name, dev->bus_id, error);
}
}
return 0;
}
int driver_probe_device(struct device_driver * drv, struct device * dev)
{
if (drv->bus->match && !drv->bus->match(dev, drv))
return -ENODEV;
dev->driver = drv;
if (drv->probe) {
int error = drv->probe(dev);
if (error) {
dev->driver = NULL;
return error;
}
}
device_bind_driver(dev);
return 0;
}
u盘驱动 内核代码阅读 2.6.11.12版本相关推荐
- 基因驱动 CovEx 代码阅读(一)
CovEx 源代码 https://sourceforge.net/projects/cancer-pathway/ 首先重点阅读 README1.txt 一步一步执行 安装 Gurobi Optim ...
- intel IOMMU内核代码阅读笔记
内核中有若干个iommu的模块,通过IOMMU_INIT组成成一个依赖树.detect_intel_iommu最先被调用,它被用来做sanity检查并设置好 x86_init.iommu.iommu_ ...
- 将vim打造成代码阅读利器(for mac and ubuntu)
需要用到的工具: NERDTree Cscope ctags vundle homebrew(for mac) 目录: 文章目录 linux内核代码阅读神技 软件介绍 NERDTree Cscope ...
- Ubuntu14.04搭建LXR本地服务器阅读Linux内核代码
CSDN GitHub Ubuntu14.04搭建LXR本地服务器阅读Linux内核代码 AderXCoding/system/tools/lxr 本作品采用知识共享署名-非商业性使用-相同方式共享 ...
- linux 内核编号含义_如何阅读linux内核代码?
阅读代码从来就是不可行的方法,有篇文章详细讲了这个事,很多人都觉得应该多读代码, 读好的代码,比如Donald Knuth. 但事实上, 只要简单让你描述一下最近读了什么代码,绝大多数人都说不上.文章 ...
- 最小的linux内核代码,带你阅读linux内核源码:下载源码、编译内核并运行一个最小系统...
要学习linux内核,先要能够编译内核,还需要了解内核如何启动根文件系统.这样你才能在修改linux内核代码之后,完成验证的过程. 本文教你完成下列过程: 1.下载linux并编译linux内核源码 ...
- *Linux下的USB总线驱动 u盘驱动分析*
Linux下的USB总线驱动(三) u盘驱动分析 版权所有,转载请说明转自 http://my.csdn.net/weiqing1981127 https://www.xuebuyuan.com/13 ...
- [Linux] USB-Storage驱动 源码阅读笔记(一)
USB-Storage驱动 源码阅读笔记--从USB子系统开始 最近在研究U盘的驱动,遇到很多难以理解的问题,虽然之前也参考过一些很不错的书籍如:<USB那些事>,但最终还是觉得下载一份最 ...
- 代码阅读工具学习总结
代码阅读工具:Source Navigator和Source Insight 一.Source Insight实用技巧: Source Insight(下文的SI指的也是它)就是这样的一个东西: Wi ...
最新文章
- 本硕非科班,单模型获得亚军!
- 实验室蒋田仔研究员:脑网络组图谱近10年研究详解【附PPT】
- seo说_百度指数看世间沉浮_如何快速排名-互点快速排名_网站关键词排名常见问题 - 搜狗快速排名...
- C#中的接口 (转自吕振宇老师的blog)
- try...catch...finally java
- DWG TrueView 2010 下载地址
- MAC 下用GCC编译报错:“Undefined symbols for architecture x86_64: ”
- linux修改resolv自动清除,centos 6.2的/etc/resolv.conf自动清空问题
- 火狐浏览器读取ukey_火狐 83版引入HTTPS-Only模式 确保访问安全连接
- 百度关键词模拟发包php程序,仿百度的关键词匹配搜索示例
- 【编程之路(008)操作符详解】(C语言实现)
- Go语言泛型工具go2go
- 北京国家会计学院聂兴凯:用友BIP事项会计助力企业迈入智能会计时代
- linux多线程编程--学习笔迹4
- 机器人仿生控制方法研究
- 4g物联网卡赋能智能设备 加快社会智能化进程
- 女生初级健身训练计划
- linux 3.10在mini210s上移植----01. tftp安装
- 魅蓝note2android8,魅蓝Note2支持扩展储存卡吗?支持多大的储存卡?
- Compressing Wav file to MP3(代码实现:将Wav格式压缩成Mp3 )