Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 6: Device Drivers


struct pci_bus *bus; /* bus this device is on */
struct pci_bus *subordinate; /* bus this device bridges to */

void *sysdata; /* hook for sys-specific extension */
struct proc_dir_entry *procent; /* device entry in /proc/bus/pci */

unsigned int devfn; /* encoded device & function index */
unsigned short vendor;
unsigned short device;
unsigned short subsystem_vendor;
unsigned short subsystem_device;
unsigned int class; /* 3 bytes: (base,sub,prog-if) */
u8 revision; /* PCI revision, low byte of class word */
u8 hdr_type; /* PCI header type (‘multi’ flag masked out) */
u8 pcie_type; /* PCI-E device/port type */
u8 rom_base_reg; /* which config register controls the ROM */
u8 pin; /* which interrupt pin this device uses */

struct pci_driver driver; / which driver has allocated this
device /
...
struct device dev; /
Generic device interface */


/* device is compatible with these IDs */
unsigned short vendor_compatible[DEVICE_COUNT_COMPATIBLE];
unsigned short device_compatible[DEVICE_COUNT_COMPATIBLE];

int cfg_size; /* Size of configuration space */

/*



  • Instead of touching interrupt line and base address registers

  • directly, use the values stored here. They might be different!
    /
    unsigned int irq;
    struct resource resource[DEVICE_COUNT_RESOURCE]; /
    I/O and memory
    regions + expansion ROMs */
    ...
    };


The first elements of the structure are dedicated to implementing links by means of lists or trees.
global_listandbus_listare two list heads to place the device on the global device list (headed by
pci_devices) or on the bus-specific device list (headed bypci_bus->devices).

Thebuselement is used for backward linking between device and bus. It contains a pointer to the
pci_businstance to which the device is assigned. A second link to a bus is held insubordinate,which
only has a valid value if the device represented is a PCI-to-PCI bridge that interconnects two PCI buses
(otherwise it contains a null pointer). If this is the case,subordinateis used to point to the data structure
of the ‘‘subordinate‘‘ PCI bus.

The next two elements are less interesting —sysdatais used to store driver-specific data, andprocentry
to manage theprocentry for the device. Neither does the nextblock hold any surprises. All elements
betweendevfnandrom_base_regsimply store PCI configuration space data already mentioned above.
They are filled with data read from the hardware when the system is initialized. It is then no longer
Free download pdf