Home
Welcome
Information


FPGA projects - Basic
Music box
LED displays
Pong game
R/C servos
Text LCD module
Quadrature decoder
PWM and one-bit DAC
Debouncer
Crossing clock domains
The art of counting
External contributions

Interfaces
RS-232
JTAG
I2C
EPP
SPI
PCI
PCI Express
Ethernet
HDMI
SDRAM

Advanced
Digital oscilloscope
Graphic LCD panel
Direct Digital Synthesis
CNC steppers
Spoc CPU core

Hands-on
A simple oscilloscope


FPGA introduction
What are FPGAs?
How FPGAs work
Internal RAM
FPGA pins
Clocks and global lines
Download cables
Configuration
Learn more

FPGA software
Design software
Design-entry
Simulation
Pin assignment
Synthesis and P&R

FPGA electronic
SMD technology
Crystals and oscillators

HDL info
HDL tutorials
Verilog tips
VHDL tips

Quick-start guides
ISE
Quartus-II

Site
Links
HDL tutorials
Forum


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



>>> HOME: PCI project >>>



This page was last updated on November 08 2004.