karsa 发表于 2010-04-27 00:49

linux 总线 和 总线设备本身

本帖最后由 karsa 于 2010-04-27 00:57 编辑

最近在看LDD3,发现了两个问题,就是:
1.在注册总线时,总线本身的device也是要注册的,我的问题是:怎么就知道我注册的设备他就代表这条总线呢?就是device和bus_type怎么联系上。(注意,是总线本身的设备,而不是挂在总线上的设备和驱动)(比如LDD3上的lddbus这个例子)
2.还有一个问题,就是我在看SDIO驱动的时候,发现注册了bus_register(&sdio_bus_type);但是死活找不到sdio总线本身设备的注册,他肯定是被注册了,但是是在哪里,什么时候注册的,我还搞不清楚。
可能是我不够认真,但是我找了几遍都找不到答案,希望牛人能帮我解答下,非常感谢

karsa 发表于 2010-04-27 19:05

回复 1# karsa


   大侠们,帮帮忙啊,up

jieao111 发表于 2010-04-27 20:59

This pci_bus_type variable is registered with the driver core when the PCI subsystem is loaded in the kernel with a call to bus_register

karsa 发表于 2010-04-28 00:11

This pci_bus_type variable is registered with the driver core when the PCI subsystem is loaded in th ...
jieao111 发表于 2010-04-27 20:59 http://linux.chinaunix.net/bbs/images/common/back.gif

还是不明白,你说的是:当pci子系统被装载到内核中的时候,pci_bus_type将通过bus_register函数向driver core中注册。
但是PCI bus本身也是个设备,这个设备什么时候被注册的呢?
不知道是你说清楚了我不明白,还是你没说清楚,我接触linux的时间也不长,是个菜鸟,能详细点解释吗,谢谢

jieao111 发表于 2010-05-05 12:15

We have seen how the lddbus code registers its bus type. However, an actual bus is a device and must be registered separately. For simplicity, the lddbus module supports only a single virtual bus, so the driver sets up its device at compile time:

static void ldd_bus_release(struct device *dev)

{

    printk(KERN_DEBUG "lddbus release\n");

}

   

struct device ldd_bus = {

    .bus_id   = "ldd0",

    .release= ldd_bus_release

};


This is a top-level bus, so the parent and bus fields are left NULL. We have a simple, no-op release method, and, as the first (and only) bus, its name is ldd0. This bus device is registered with:

ret = device_register(&ldd_bus);

if (ret)

    printk(KERN_NOTICE "Unable to register ldd0\n");


Once that call is complete, the new bus can be seen under /sys/devices in sysfs. Any devices added to this bus then shows up under /sys/devices/ldd0/.

jieao111 发表于 2010-05-05 12:19

这个一个bus是一个device(即这个bus结构体内也有device这个成员),而这个bus的结构体内有bus_type这个成员,所以注册的时候就联系一起了。
页: [1]
查看完整版本: linux 总线 和 总线设备本身