02-10-2020 02:37 AM
Hi,
I'm rewriting the xdma driver code for multiple board.
I know that a single device driver can probe multiple devices and detect it but how to differentiate each device?
I want to write a different function for each board with a specific ID identifying each board.
How can I give each board a specific ID? And how can I use it in a driver code?
Thanks in advance.
Best regards,
02-10-2020 10:04 PM
02-10-2020 10:04 PM
02-11-2020 01:31 PM
There are a few options to consider. At least as far as Linux kernel modules are concerned, when the module is loaded, it registers a new PCIe device driver. Registering a device driver involves providing a list of entry points (probe, remove, etc.) along with a set of PCIe device IDs that the driver should be attached to. The Linux kernel will use that information when scanning devices to figure out which driver to attach.
In the probe method, the driver can look at identifying information on the device - vendor and product IDs, subsystem vendor and product IDs, device registers, etc. and decide what to do with the device. So you could set the same vendor and product IDs and differentiate with subsystem IDs. Or you could set different product IDs, set the driver ID list to match all of them, and then check the actual ID in the kernel module. Or you could implement read-only informational registers that the driver can read via MMIO. Setting the vendor and product IDs can be done either in the wizard, or by driving ports on the IP core which may need to be exposed by changing a setting in the wizard. Adding informational registers is done outside the PCIe IP core by implementing BARs. If you're using the XDMA core, then setting vendor/product IDs is probably going to be the simplest method. On the other hand, informational registers can expose the values of verilog parameters without having to regenerate the IP core, which can be very useful.