Re: how is a device detected
How the kernel scan the pci devices: In /arch/x86/pci/legacy.c, *pci_legacy_init()* invoke - *pcibios_scan_root(0) *to scan pci devices from the root bus, if the bus is already scanned then just return; else the - *pci_scan_bus_parented() *will be invoked, in this function the **-* pci_create_bus()* will create pci_bus for the corresponding bus and add it to the *pci_root_buses*. - *pci_scan_child_bus() *is* *invoked to enumerate all the devices of that bus. for each device number(each bus host up to 32 devices, see *Page 303, LDD3*) invoke - *pci_scan_slot() *to scan its 8 function number, here the - *pci_scan_single_device()* be invoked, that means for each device the - *pci_scan_device() *will be invoked, if the device exist, the - *pci_device_add() *will add the device to the devices list of the bus it belongs to. Oh, A lot of code to read, I think you will be interest in the *pci_scan_device()* function, this function gets *configuration registers* of the pci device(*Page 308, LDD3*) eh, I must go to class now... On Tue, Nov 30, 2010 at 4:56 AM, Bond wrote: > On Tue, Nov 23, 2010 at 3:07 AM, Yuchen Liao wrote: > > AFAIK, in the device_add() function (in driver/base/core.c), kernel will > > invoke "device_create_file()" function to create the "uevent" file; > > (The kobj is also added in this device_add() function by invoke > > kobject_add() function) > > In user space, the udevd is listening the NETLINK_KOBJECT_EVENT to get > the > > "uevent" event. Then it will find a match udev rule under the > > /etc/udev/rules.d/. It will make changes according to the rule(Like > create > > the device file under /dev). > > Every device when it is register, it will create a uevent file(by this > way, > > can trigger a hotplug event), can write a "add" or "remove" command to > add > > or remove a device. > > When starting computer, kernel will register a lot of devices, but the > > udev(in user space) is not start. After it start, it will scan the sysfs, > to > > get all the uevent file, and write "add" into it. In this way, the event > > been triggered. > > > > I'm not so sure that I'm right. Please correct me if there is anything > > wrong. Thank you~ > Hi thanks your explanation was very good. > I have been doing some research on this aspect and replying you after > so many days it is helpful. > What I came across was some thing known as pci-core for PCI devices > and USB core for USB devices. > So that is one thing I surely want to understand. > My objective by this exercise is to be able to write a kernel which is > working on bare metal.(I just want a small set of code which can work) > So I want to understand it more.If some one has more thoughts here > then share it please. > -- from Yuchen Liao via Gmail yyloves.me
Re: how is a device detected
On Tue, Nov 23, 2010 at 3:07 AM, Yuchen Liao wrote: > AFAIK, in the device_add() function (in driver/base/core.c), kernel will > invoke "device_create_file()" function to create the "uevent" file; > (The kobj is also added in this device_add() function by invoke > kobject_add() function) > In user space, the udevd is listening the NETLINK_KOBJECT_EVENT to get the > "uevent" event. Then it will find a match udev rule under the > /etc/udev/rules.d/. It will make changes according to the rule(Like create > the device file under /dev). > Every device when it is register, it will create a uevent file(by this way, > can trigger a hotplug event), can write a "add" or "remove" command to add > or remove a device. > When starting computer, kernel will register a lot of devices, but the > udev(in user space) is not start. After it start, it will scan the sysfs, to > get all the uevent file, and write "add" into it. In this way, the event > been triggered. > > I'm not so sure that I'm right. Please correct me if there is anything > wrong. Thank you~ Hi thanks your explanation was very good. I have been doing some research on this aspect and replying you after so many days it is helpful. What I came across was some thing known as pci-core for PCI devices and USB core for USB devices. So that is one thing I surely want to understand. My objective by this exercise is to be able to write a kernel which is working on bare metal.(I just want a small set of code which can work) So I want to understand it more.If some one has more thoughts here then share it please. -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: how is a device detected
AFAIK, in the device_add() function (in driver/base/core.c), kernel will invoke "device_create_file()" function to create the "*uevent*" file; (The kobj is also added in this device_add() function by invoke kobject_add() function) In user space, the *udevd* is listening the NETLINK_KOBJECT_EVENT to get the "uevent" event. Then it will find a match udev rule under the /etc/udev/rules.d/. It will make changes according to the rule(Like create the device file under /dev). Every device when it is register, it will create a uevent file(by this way, can trigger a hotplug event), can write a "add" or "remove" command to add or remove a device. When starting computer, kernel will register a lot of devices, but the udev(in user space) is not start. After it start, it will scan the sysfs, to get all the uevent file, and write "add" into it. In this way, the event been triggered. I'm not so sure that I'm right. Please correct me if there is anything wrong. Thank you~ On Mon, Nov 22, 2010 at 3:22 AM, Mulyadi Santosa wrote: > On Mon, Nov 22, 2010 at 13:37, Bond wrote: > > Hi, in some of the books I am reading I find > > a text which mentions MODULE_DEVICE_TABLE () macro makes a user > > defined structure available in the module image so that the module > > can be loaded on demand if the card is hotplugged. > > I am not clear with how is this detection happening inside the kernel. > > How does the kernel detects the presence of a particular device?( I am > > not referring to the probe function defined in many drivers) > > AFAIK, when a device is hotplugged, it raised an interrupt...and > assuming a handler sits there (from device driver), then it is > captured and registered in a subsystem...that is kobject..I > think..which is related to sysfs. > > Greg KH and others might know better > > > -- > regards, > > Mulyadi Santosa > Freelance Linux trainer and consultant > > blog: the-hydra.blogspot.com > training: mulyaditraining.blogspot.com > > -- > To unsubscribe from this list: send an email with > "unsubscribe kernelnewbies" to ecar...@nl.linux.org > Please read the FAQ at http://kernelnewbies.org/FAQ > > -- from Yuchen Liao via Gmail yyloves.me
Re: how is a device detected
On Mon, Nov 22, 2010 at 13:37, Bond wrote: > Hi, in some of the books I am reading I find > a text which mentions MODULE_DEVICE_TABLE () macro makes a user > defined structure available in the module image so that the module > can be loaded on demand if the card is hotplugged. > I am not clear with how is this detection happening inside the kernel. > How does the kernel detects the presence of a particular device?( I am > not referring to the probe function defined in many drivers) AFAIK, when a device is hotplugged, it raised an interrupt...and assuming a handler sits there (from device driver), then it is captured and registered in a subsystem...that is kobject..I think..which is related to sysfs. Greg KH and others might know better -- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ