Re: Plug and play

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

I still don't understand few things and would be very glad if any one can help me.

Lets look at the PCI example as stated in LDD book.

So, when system starts up it is said in the book that BIOS reads the configuration space and allocates the memory and I/O regions, writes back to configuration space, which can be used by the driver to access the device.

Now I don't understand, how firmware knows which devices are present and how to access their configuration space ?

Book also says there is 4 bytes of configuration space which holds the unique function ID in each device so that driver can identify its device (geographical addressing) but later it says that there are three registers (device ID, vendor ID and class) which driver can use to identify the device. Isn't its contradictory? Where is this unique function ID ? Can any one make the idea of geographical addressing clear ?

Then it talks of id tables which drivers uses to tell what devices it can handle, which I understand is for hot plugging because then system has the list and if later by some means system able to figure out that there is new device attached to it, it can refer to this table to find the appropriate driver.

Then it talks of registering the driver.. which when I looked in to the code goes like this

pci_register_driver -> device_register -> bus_add_driver -> driver_attach (match this driver against every device on that bus) -> driver_probe_device -> pci_device_probe -> ultimately calls driver probe.. and if everything goes well driver will get configure to device.

So what I understood is, if you add new driver and if (somehow, I dont understand how) system has list of devices attach to that bus, we can match the driver and the device. Does it mean that while system boots up it calls all  functions with label "__init" (implying every driver registers itself) ?

Then book talks about the kernel functions to access the configuration space.

Now, after reading this, I still dont understand how the system maintains the list of devices it has on a particular bus ?

Similar to driver register function there is device register function which takes device as an argument, which when I looked goes like this

device_register -> device_add -> bus_add_device -> device_attach

Now, what is the use of this and who calls this ? how is this linked to PCI ?

Can any one please please make the things clear ?

Thank you very much
Regards



On 6/29/07, Greg KH <greg@xxxxxxxxx> wrote:
On Fri, Jun 29, 2007 at 05:48:01PM -0700, Kamal gupta wrote:
>  hi
>  I am looking in to the kernel code.. I can understand from the code how. if
>  a new driver is added to the system will get configured to the devices.. but
>  I dont understand how the linux do PnP when new device is attached. From
>  some where device_register must be called with the device structure but what
>  I dont understand is who calls this (I can see for some of the devices it is
>  called when machine is started) but not for all devices like for USB
>  devices. Can somebody please guide me ?

Sure, what specific type of device are you wanting to look at here?
PCI?  USB?  PCMCIA?  ExpressCard?  Something else?  They all do this
differently in their bus specific code and then call the driver core to
register the new device which kicks off the binding of a driver to the
device.

I think a good example of this can be found in the book, Linux Device
Drivers, third edition, free online, that shows the chain of calls from
the PCI core, into the driver core, out of the driver core into the PCI
core, into a driver, and then back into the driver core.

If, after reading that you still have specific questions, please let us
know.

hope this helps,

greg k-h



--
Kamal Kant Gupta

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux