PCI software driver for Linux
Fedora is an impressive Linux release.
Microsoft should be worried...
Writing a Plug-and-Play PCI driver for Linux
It's actually easier than on Windows.
1. Create the init_module and cleanup_module
These functions are called when the driver is loaded or unloaded.
int init_module(void)
{
return pci_module_init(&pci_driver_DevicePCI);
}
void cleanup_module(void)
{
pci_unregister_driver(&pci_driver_DevicePCI);
}
The "pci_driver_DevicePCI" structure is shown next...
2. Create tables describing the PCI board
#define VENDOR_ID 0x1000
#define DEVICE_ID 0x0000
struct pci_device_id pci_device_id_DevicePCI[] =
{
{VENDOR_ID, DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
{} // end of list
};
struct pci_driver pci_driver_DevicePCI =
{
name: "MyPCIDevice",
id_table: pci_device_id_DevicePCI,
probe: device_probe,
remove: device_remove
};
device_probe and device_remove are 2 callback functions, created next...
3. Create the "probe" and "remove" callbacks
int device_probe(struct pci_dev *dev, const struct pci_device_id *id)
{
int ret;
ret = pci_enable_device(dev);
if (ret < 0) return ret;
ret = pci_request_regions(dev, "MyPCIDevice");
if (ret < 0)
{
pci_disable_device(dev);
return ret;
}
return 0;
}
void device_remove(struct pci_dev *dev)
{
pci_release_regions(dev);
pci_disable_device(dev);
}
That should be enough to allocate the memory resource...
Thanks to Ian Johnston's help, I got the current
files (for Fedora Core 2 - kernel 2.6) to compile.
Build them using "make" followed by "insmod DevicePCI.ko" to load the driver, and "rmmod DevicePCI.ko" to unload it.
Your turn to experiment!
Link
This page was last updated on November 07 2004.