Joseph Smith wrote:
For the Paraflasher project I would like to setup a function to automatically detect the presence of the PC's parallel ports and their base addresses.
..
I was thinking of using /proc/ioports to do this
I'm afraid you can't win this one.
If the kernel knows about the ports (ie. if they are listed in /proc/ioports) then it's because there is already a driver in the kernel which is responsible for driving the hardware - and your /userspace program should not interfere.
If there is no driver loaded, there will be no entry in /proc/ioports so you won't know which ports to use.
There are two ways to do this while still playing nicely;
1. Interface with the kernel parport driver. This may not work, I'm not sure if parport offers a userspace API, and if it does I don't know if it offers functionality suitable for bitbanging the port.
2. Make the user specify an IO port (you can give suggestions, 0x3bc 0x378 and 0x278 are the common ones) and check that this port is NOT listed in /proc/ioports.
but I am not really sure how to do this in C.
If you know another language better then just use that. :) It doesn't matter for flashrom, I want potential future plugin stuff to use IPC so that hardware drivers can be written in any language.
In C, I would suggest fopen("/proc/ioports","r"), while(fgets()), then using strstr() to find lines with "parport" and finally sscanf() to convert the string into an uint16_t variable.
Don't forget error checking and corner cases, make sure that you have actually read a full line before letting the loop start over.
//Peter