Magic Smoke
   


Once the magic smoke comes out, it won't work any more.

John Kasunich
jmkasunich@fastmail.fm
GPG Key

Postings:

Index (titles only):

If you are into RSS, you can Subscribe to a syndicated feed.


Links


Friends


I Support

Individual Rights

Electronic Frontier Foundation


Powered by



       

Tue, 17 Apr 2007

A simple user space library for accessing PCI bus hardware.

No posts lately. I've been busy learning VHDL and having fun with the Mesa 5i20. I have the core of a hardware step generator working (and have for several weeks actually). Now I'm working on the utilities needed to configure the very flexible stuff that the 5i20 can do.

I've been working on the utility that loads an FPGA configuration into the part. The original Mesa version isn't bad, but it had minor bug or two (and a bad one that would only show up if you have more than one 5i20 installed). I also need to add some new functionality - loading data into a block of RAM on the FPGA, to tell the HAL driver how you want to use the hardware. In my typical fashion, instead of grafting my new functionality into the existing code, I rewrote the whole thing.

One of the benefits of the rewrite is that I pulled out and genericized the code that searches the PCI bus for a card, and enables direct access from user space to the memory and I/O locations on that card. The result is a handy (I think) little library that might be of use to others, so I'm posting it here. It's called 'upci' for 'User space PCI'.

Like libpci (part of pciutils), upci can let you read the configuration data for a device, or find a particular device. But the programming interface for upci is a lot simpler. And it is actually documented! Comments in upci.h cover the entire API. On the other hand, if you just want to see that data from the command line, lspci (also part of pciutils) is a far better tool.

The real difference between libpci and upci is that upci has a very simple API for "opening" and accessing the real memory and I/O on a card, not just the PCI configuration registers. If you are using a card like the Mesa 5i20, you might want a simple user space program to be able to write to some registers that are part of your FPGA configuration. If you are just doing some experimenting with FPGAs, you don't need (or want) a full blown PCI driver, just simple access. Thats what upci gives you.

Disclaimer: as with anything that can access arbitrary hardware, you can crash your system if you go poking in the wrong places. The library tries to be safe - you have to be root (or setuid root) to use the upci "open" command, and it won't let you accidentally write outside the specific region on the specific card that you opened. But by its very nature it can't be foolproof. If you open a region on your disk controller and start writing to registers, don't blame me for the lost data!

Update: May 14

I committed upci to the EMC CVS server a week or two ago. The version originally posted here is out of date, for the most current version follow these links:

upci.c
upci.h

(posted: 17 Apr 2007 23:45) (permalink)