This section, as usual, summarizes the symbols introduced in the chapter.
#include <linux/config.h>
,
CONFIG_PCI
This macro should be used to conditionally compile PCI-related code. When a PCI module is loaded to a non-PCI kernel, insmod complains about several symbols being unresolved.
#include <linux/pci.h>
This header includes symbolic names for the PCI registers and several vendor and device ID values.
int pci_present(void);
This function returns a boolean value that tells whether the computer we’re running on has PCI capabilities or not.
struct pci_dev;
,
struct pci_bus;
,
struct pci_driver;
,
struct pci_device_id;
These structures represent the objects involved in PCI management. The
concept of pci_driver
is new as of Linux 2.4, and
struct pci_device_id
is central to it.
struct pci_dev *pci_find_device(unsigned int vendor, unsigned int device, struct pci_dev *from);
,
struct pci_dev *pci_find_class(unsigned int class, struct pci_dev *from);
These functions are used to look up the device list looking for
devices with a specific signature or belonging to a specific
class. The return value is NULL
if none is
found. from
is used to continue a search; it must
be NULL
the first time you call either function, and
it must point to the device just found if you are searching for more
devices.
int pci_read_config_byte(struct pci_dev *dev, int where, u8 *val);
,
int pci_read_config_word(struct pci_dev *dev, int where, u16 *val);
,
int pci_read_config_dword(struct pci_dev *dev, int where, u32 *val);
,
int pci_write_config_byte (struct pci_dev *dev, int where, u8 *val);
,
int pci_write_config_word (struct pci_dev *dev, int where, u16 *val);
,
int pci_write_config_dword (struct pci_dev *dev, int where, u32 *val);
These functions are used to read or write a PCI configuration register. Although the Linux kernel takes care of byte ordering, the programmer must be careful about byte ordering when assembling multibyte values from individual bytes. The PCI bus is little-endian.
int pci_register_driver(struct pci_driver *drv);
,
int pci_module_init(struct pci_driver *drv);
,
void pci_unregister_driver(struct pci_driver *drv);
These functions support the concept of a PCI driver. Whereas compiled-in
code uses pci_register_driver (which returns the
number of devices that are managed by this driver), modularized code
should call pci_module_init instead (which
returns 0 if one or more devices are there and
-ENODEV
if no suitable device is plugged into the
system).
#include <linux/usb.h>
,
#include <linux/input.h>
The former header is where everything related to USB resides and must be included by USB device drivers. The latter defines the core of the input subsystem. Neither of them is available in Linux 2.0.
struct usb_driver;
,
int usb_register(struct usb_driver *d);
,
void usb_deregister(struct usb_driver *d);
usb_driver
is the main building block of USB device
drivers. It must be registered and unregistered at module load and
unload time.