0
votes

I am modifying an existing Linux device driver and library API. My modification is to allow multiple devices (it is currently hard-coded for one device). One concept I don't understand is the mapping between the character device and the PCIe device itself.

When initializing the driver in the probe method, I create a character device (or multiple). The library API makes a IOCTL call using the file descriptor from this character device. However in the driver itself, it is maintaining a global variable for the device that contains the PCI information. So my next step is to maintain state information for all the PCI device.

What I don't understand is what the link is between the character devices I created and the PCIe state information in the driver. From my understanding the character device is created, and when I open it, or IOCTL into it, those commands are mapped through the driver. I am not sure how to link that character device that I am receiving through to the device structure that I want to control though.

1

1 Answers

2
votes

You can use the minor device number to do so.

When being probed, you can register char devices with the same major number and different minor number and map your own struct with the minor number. When the IOCTL is called, you can get the minor number from cdev->dev so that you can find your own struct.