Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm currently learning about device developement for linux, I have glaced at some books such as LLD3, .. but I still can't understand what happen when we plug a device into computer, That's my imagination: When we plugs a device into a port, in a magic way, Linux kernel will know what device type and call to appropriate module's probe function to determine if it is exactly device which module need, and the next is magic .... Can anyone correction this?

share|improve this question
    
what kind of device connecting to what kind of computer ? usb device to a x86 computer (a.k.a. PC) or some other combination ? –  MelBurslan Dec 12 '12 at 17:02
    
is it different depend on device type (usb flash, keyboard)? so we choose the usb flash for example :D –  Bình Nguyên Dec 12 '12 at 17:06
    
then, when you plug this device in, your PC (assumed here as you didn't specify), your X86 processor gets an interrupt, telling it a new hardware has been connected to a certain USB port. Then it is up to the kernel/device developer to decide how to handle this interrupt. –  MelBurslan Dec 12 '12 at 17:14

1 Answer 1

up vote 0 down vote accepted

It's not really magic, it's hardware. Information about peripheral events comes to the CPU thru the front side bus, which is the gateway to other hardware; programmatically (in kernel code) these are dealt with via the concept of the interrupt request (IRQ).

Have a look at these in order:

http://en.wikipedia.org/wiki/Northbridge_%28computing%29

http://en.wikipedia.org/wiki/Front_side_bus.

Now consider that the kernel is what determines what goes on in the CPU. Next:

http://en.wikipedia.org/wiki/Interrupts

http://en.wikipedia.org/wiki/IRQ

To get more specific WRT the linux kernel code, it uses handlers which fire on receipt of an interrupt request. The basic parts of this are done with architecture specific asm code, a lot of which you will find in (eg) src/arch/x86/kernel. I don't code in asm (the .S files), so it's greek to me, unfortunately, but the idea here (should be in that wikipedia stuff) is that on receipt of an IRQ, the kernel pre-empts whatever user space code is running in order to process the IRQ (possibly passing something on to whatever user space process).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.