ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
but I could not understand this type of structure definition.
How does one point the following entry
{0x10ec, 0x8139, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 },
1) What is first field 0x10ec mapped to is it vendor ?
2) What is second field 0x8139 mapped to is it device id ?
3) Does PCI_ANY_ID both represent subvendor,subdevice
4) What are these two 0,0 are they class,mask
5) What is RTL8139 is it driver_data
6) I am also not clear with the way the macro was defined.
In the definition of following macro
#define DEFINE_PCI_DEVICE_TABLE(_table) const struct pci_device_id _table[] __devinitconst
_table is it an array of structure of type pci_device_id ?
The pci.txt file in the documentation describes the fields in the structure (the table is an array of these pci_device_id structures as you surmised). Not all of the fields have to be provided (hence the PCI_ANY_ID and the zeroes).
Code:
The ID table is an array of struct pci_device_id entries ending with an
all-zero entry; use of the macro DEFINE_PCI_DEVICE_TABLE is the preferred
method of declaring the table. Each entry consists of:
vendor,device Vendor and device ID to match (or PCI_ANY_ID)
subvendor, Subsystem vendor and device ID to match (or PCI_ANY_ID)
subdevice,
class Device class, subclass, and "interface" to match.
See Appendix D of the PCI Local Bus Spec or
include/linux/pci_ids.h for a full list of classes.
Most drivers do not need to specify class/class_mask
as vendor/device is normally sufficient.
class_mask limit which sub-fields of the class field are compared.
See drivers/scsi/sym53c8xx_2/ for example of usage.
driver_data Data private to the driver.
Most drivers don't need to use driver_data field.
Best practice is to use driver_data as an index
into a static list of equivalent device types,
instead of using it as a pointer.
The __devinitconst is just a modifier to force the table to be located in a read-only init data section.
and why does one need to have a definition of PCI_ID_TABLE
from where a new developer would get these values 0x126c, 0x1211
I have no idea when to put 0x126c or 0x1211.
How do you decide this?
But I am not able to understand how all the elements are in braces.
It is not just the definition of the table (which is done by the macro), but the initialization of the values in the table. Each list of values enclosed by braces is initializing one structure in the array of structures. After expanding the macro it looks like this (leaving out some of the detail):
Code:
struct pci_device_id rtl8139_pci_tbl[] =
{
{values for the first device structure...},
{values for the second device structure...},
...
};
Note that the pci_device_id structure itself was already predefined in another header, and is being used here to define the type of the array entries.
Quote:
from where a new developer would get these values 0x126c, 0x1211
These values are specific to a particular piece of hardware. The vendor id is assigned by the PCI SIG, and if you are working with existing hardware, there is an ad-hoc database of ids. For example, 0x1113 is the Accton vendor ID, and 0x1211 is the Accton device ID for the EN5030 ethernet controller.
The list of entries in the table will cover all the different devices for which the driver is relevant. Since different manufacturers use the same chipset, it is often possible to use the same driver for more than one PCI card. However, the cards will have different vendor and device ids, so each one will have a separate entry in the table. The table can then be used by the kernel to check for a matching driver.
Last edited by neonsignal; 11-02-2010 at 07:53 AM.
The table can then be used by the kernel to check for a matching driver.
Ok and how will the presence of a device with vendorid,deviceid combination detected by kernel?
As far as I understand once the probe function(Not too sure) detects or kernel detects then the driver would be looked up
and control would be handed over to driver.
If this is correct then how does probe works? Or how a particular device's presence on PCI bus detected.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.