0

I am studying writing a driver, with the goal of communicating to a simple PIO PCI board from user space.

First, I created a sample character driver. The simple text string in memory stuff. Created a device file to read and write to. Easy to understand.

Next, I created another driver, and I successfully registered the driver to the PCI board. I can see it is all working in the kernel messages, and the lspci -v command shows my test driver as the driver in use.

My question: How do I access the PIO PCI driver from user space?
Do I also need to create a character device, and essentially merge the two projects, so I have a "device Number" and a file to read and write to? It seems like that is would be the logical step, since the pci_driver structure doesn't have read or write functions.

Is this correct?

2

There's a good book Linux Device Drivers that is freely available at:

https://lwn.net/Kernel/LDD3/

It's a number of years old, so some thing might have changed a little, but the core of what's there should still be helpful.

In general, your driver would probably want to register a character device. That device would get a dynamically-assigned major number. You'd then create a character device file in dev with that major number. The driver will support a set of standard file operations (e.g., open(), ioctl(), read(), write()). Your userspace process would open() the character device file and use those file operation to interact with the driver. The implementation of your driver would translate those operations (and their associated content) into interactions with the physical device.

| improve this answer | |
  • Excellent. I have been using that book as my instructions. And the character device was what I thought. Thank you for the confirmation. – SpacemanScott Nov 10 '19 at 20:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.