PCI device /dev/mem questions



Hi everyone,

Just some quick questions:

I wrote a C userspace program that accesses base address 0 of a PCI
device. In my C code, I have been able to read and write to the base
address by opening "/dev/mem" and mmap-ing the memory range I want
based off of base address 0. Afterwards I can read/write to the base
address and to any offset from the base address.

Question #1) Sometimes, I have to run lspci -v in order to check the
base address 0 of the device in order to make sure that the base
address has not changed. Is there anyway to check the base address of
the device in the userspace code instead? Or do I need to write a linux
device driver that will return to me the base address zero?

Question #2) In order to run the code, I have to run as root because I
am operating on /dev/mem. What are the reasons that I need to become
root? Is there anyway to get around being root? When I tried to chmod
666 /dev/mem, it still will not run the program. Why is that?

.