Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 6: Device Drivers


Data Structures


The kernel provides several data structures to manage the system’s PCI structures. They are declared in
<pci.h>and are interlinked by a network of pointers. I give an overview of the structure elements below
before moving on to take a closer look at their definitions.

❑ The individual buses in the system are represented by instances ofpci_bus.
❑ Thepci_devstructure is provided for individual devices, cards, and function units.
❑ Each driver is described by an instance ofpci_driver.

The kernel makes two globallist_heads available to head the network of PCI data structures (both are
defined in<pci.h>).

❑ pci_root_buseslists all the PCI buses in the system. It is the starting point when the data struc-
tures are scanned ‘‘downward‘‘ to find all devices attached to the individual buses.
❑ pci_deviceslinks all PCI devices in the system without taking the bus structure into account.
This is useful when a driver wants to search for all devices it supports because the topology is of
no interest in this situation (it is, of course, possible to find the bus associated with a device using
the many links between the PCI data structures, as you will see below).

Representation of Buses


Each PCI bus is represented in memory by an instance of thepci_busdata structure, which is defined as
follows:

<pci.h>
#define PCI_BUS_NUM_RESOURCES 8

struct pci_bus {
struct list_head node; /* node in list of buses */
struct pci_bus *parent; /* parent bus this bridge is on */
struct list_head children; /* list of child buses */
struct list_head devices; /* list of devices on this bus */
struct pci_dev *self; /* bridge device as seen by parent */
struct resource *resource[PCI_BUS_NUM_RESOURCES];
/* address space routed to this bus */

struct pci_ops *ops; /* configuration access functions */
void *sysdata; /* hook for sys-specific extension */
struct proc_dir_entry *procdir; /* directory entry in /proc/bus/pci */

unsigned char number; /* bus number */
unsigned char primary; /* number of primary bridge */
unsigned char secondary; /* number of secondary bridge */
unsigned char subordinate; /* max number of subordinate buses */

char name[48];
...
};

The structure is divided into function sections as indicated by the source code formatting.
Free download pdf