fpga4fun.comwhere FPGAs are fun

PCI plug-and-play

Now that reads and writes accesses are going through, what does it take for the PCI plug-and-play to work?

Our PCI card is not yet in the list...

Configuration space

Remember that PCI cards have three "spaces" where transactions (reads and writes) take place?
  1. Memory space
  2. IO space
  3. Configuration space

The configuration space is the heart of PCI plug-and-play. The OS (Windows, Linux...) reads there first to find if PCI cards are plugged-in, and their characteristics.

For simple boards, the configuration space consists of just 64 bytes. They important fields are:

0Vendor IDManufacturer number... allocated by the PCI-SIG2 bytes
2Device IDDevice number... allocated by the manufacturers themselves2 bytes
4CommandTurn on and off accesses to the PCI board... but configuration space accesses are always on2 bytes
16BAR0 (Base address register 0)Address at which the PCI board should respond... followed by BAR1 through BAR54 bytes each

By implementing the right values and registers at these locations, the OS can "find" the PCI card.

Configuration space transactions

Each PCI slots as a signal called IDSEL. The IDSEL signal is not shared along the bus; each PCI slot has its own.
When a PCI card sees a configuration space transaction on the bus, and its own IDSEL is asserted, it knows it should respond.

parameter PCI_CBECD_CSRead = 4'b1010;   // configuration space read
parameter PCI_CBECD_CSWrite = 4'b1011;   // configuration space write

wire PCI_Targeted = PCI_TransactionStart & PCI_IDSEL & ((PCI_CBE==PCI_CBECD_CSRead) | (PCI_CBE==PCI_CBECD_CSWrite)) & (PCI_AD[1:0]==0);

After that, it can be a read or a write but it works the same way than memory or IO spaces do.

A few details: There are a few other details left out, like some bits of BAR0 are read-only...
Please refer to a PCI specification/book for the down-to-earth details.

Windows plug-and-play

Once these registers are implemented, the OS can discover the new hardware.

But the OS requires a driver before...

... it agrees to allocate the memory resource.