Experimental Physics and
| |||||||||||||||||
|
To find the pci address in linux, use 'lspci' as root The PCI address is function of the hardware location (pci slot) in the computer. So if you fiddle with the hardware that address will change. The kernel driver should take care of handling the PCI addresses and provide a method to memory map (mmap) the hardware address into user space. When this is done the hardware I/O or memory space can be accessed directly from user space. . insmod xxx.ko should be called once during system boot (this might not be correct, maybe just only once then don't have to be called anymore)??? Many drivers allocate device numbers dynamically and the major number assigned can be found from /proc/devices. A device node in /dev has to be created for each major/minor combination the device is using. After this the application can open the device /dev/xxx and perform file operations e.g. mmap. As an example the Linux kernel driver for the MRF cPCI-EVG is loaded following: /sbin/modprobe pci_mrfevg || exit 1 majors=$(awk "\$2==\"mrfevg\" {print \$1}" /proc/devices) echo "Found" $(echo $majors | wc -w) "Event Generators." echo "Creating device nodes..." device=1 for major in $majors; do dev=$(echo $device | awk '{ printf "%c", 96+ $1}') device=$((++device)) rm -f /dev/eg$dev[0-3] echo "Creating nodes /dev/eg"$dev"[0-3] for major" $major mknod '/dev/eg'$dev'0' c $major 0 mknod '/dev/eg'$dev'1' c $major 1 mknod '/dev/eg'$dev'2' c $major 2 mknod '/dev/eg'$dev'3' c $major 3 # Allow write access to members of group mrf chgrp mrf '/dev/eg'$dev[0-3] chmod g+w '/dev/eg'$dev'3' done In this driver minor number 3 provides a direct memory map to a PCI address space of the hardware. Below is an excerpt from the API sources for the EVG to show how the user space access to the EVG registers is gained. The function is called with "/dev/ega3" as the device name and it return a pointer to a user space address (*pEg) which the kernel directly maps to hardware. int EvgOpen(struct MrfEgRegs **pEg, char *device_name) { int fd; /* Open Event Generator device for read/write */ fd = open(device_name, O_RDWR); #ifdef DEBUG DEBUG_PRINTF("EvgOpen: open(\"%s\", O_RDWR) returned %d\n", device_name, fd); #endif if (fd != -1) { /* Memory map Event Generator registers */ *pEg = (struct MrfEgRegs *) mmap(0, EVG_MEM_WINDOW, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); #ifdef DEBUG DEBUG_PRINTF("EvgOpen: mmap returned %08x, errno %d\n", (int) *pEg, errno); #endif if (*pEg == MAP_FAILED) { close(fd); return -1; } } return fd; } The sources for MRF CompactPCI EVG/EVR drivers are available from me. Please let me know if you want a copy. Regards, Jukka
| ||||||||||||||||
ANJ, 10 Nov 2011 |
·
Home
·
News
·
About
·
Base
·
Modules
·
Extensions
·
Distributions
·
Download
·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing · |