parser=argparse.ArgumentParser(description='Spec7 tool to access the memory mapped area',epilog='A number with prefix "0x" is interpreted as hex value')
parser.add_argument('--device','-d',default='/dev/xdma0_user',help='device path name, default is /dev/xdma0_user')
parser.add_argument('--device','-d',default='/dev/spec7_bar0',help='device path name, default is /dev/spec7')
parser.add_argument('--address','-a',default='0',help='address to access (0x prefix for hex)')
parser.add_argument('--is-pipe','-p',dest='is_pipe',action="store_true",help='register is a pipe')
parser.add_argument('--count','-n',dest='count',help='number of reads/writes')
The PCI address is here "0000:01:00.0" which gives the following sysfs entries:
- /sys/bus/pci/devices/0000:01:00.0/deadbe
Writing either '0' or '1' will write this values into the SYSCON register of the LM32.
- /sys/bus/pci/devices/0000:01:00.0/lm32_mem
Gives file based access to the LM32 memory.
BAR interfaces
--------------
The module creates to file entries in /dev:
/dev/spec7_bar0
/dev/spec7_bar4
These character devices supports access to the memory regions of each bar in a stream-like fashion through systems calls read() and write(). The region boundaries are protected by returning EOF when reading and EFAULT (invalid address) when writing beyond.
Both cp(3) and dd(3) can be used to transfer files to and from the bar memory regions.
The system call ioctl() can be used to query the size of the bar regions:
ioctl(fd, 0xdc01, 0)
returns the size in bytes.
Both devices implements also the mmap(2) system call, which enables the mapping of the BAR regions to user-space memory.
PERMISSIONS
------------
The default permissions for the device files are granted for root only. To customize this, an udev rules file must be created in /usr/lib/udev/rules.d.
This example gives users who are member of group “spec7” read-write access and others only read access:
file 60-spec7.rules contents:
KERNEL=="spec7_*", MODE="0664", GROUP="spec7"
To reload the udev config:
# udevadm control --reload
To add the group “spec7”
# addgroup spec7
To add a groups membership to an existing user the following command is given:
# usermod -a -G spec7 username
Nb. reload the driver to effectuate the new configuration.