views:

309

answers:

1

I'm trying to map a VME address space through a PCI bus into user space so I can perform regular read/writes on the memory. I have done this with another PCI device like this :-

unsigned long *mapArea(unsigned int barAddr, unsigned int mapSize, int *fd)
{
    unsigned long *mem;

    *fd = open("/dev/mem", O_RDWR);
    if ( *fd<0 ) {
       printf("Cannot open /dev/vme_mem\n");
    exit(-1);
}

unsigned long *mem = (unsigned long*) mmap ( 0, mapSize, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, *fd,  barAddr); 
if ( (mem == NULL) || (mem == (unsigned long*)-1) ) {
    printf ( "Cannot map memory, error is %s\n", strerror(errno) );
    exit(-1);
    }

    return mem;
}

volatile unsigned long *bar = (volatile unsigned long *)mapArea(barAddr, mapSize, &fd);

And then "bar" can be used normally for read/writes.

So to VME, and with a Tundra Universe II PCI-VME Bridge chip :-

Should I open "/dev/vme_m0" Where do I map my BAR from? the lspci -vv : "Region 1: Memory at 80020000"

Also the addresses within the VME BUS are offset by 0x20000000, so how does that work wrt accessing/mapping it?!

(Using Linux 2.6.18-128.el5 #1 SMP) (Need new tag "vme"!)

+1  A: 

Where does /dev/vme_m0 come from and what does it represent? It is hard to tell what opening and accessing it will do without knowing more.

You need to look at the bridge chip manual to figure out how a read/write to Region 1 will translate to a read/write on the VME bus. The bridge chip should have a set of registers that define PCI -> VME address translations. The VME address generated by accessing 0x80020000 would depend on the VME address specified in one of those registers.

sigjuice
"/dev/vme_m0" comes from "mknod vme_m0 c 221 0".
IanVaughan
The answer comes from a library supplied to wrap the kernel module!"int map = vme_mmap(DeviceHandle, mmap_offset, length, "
IanVaughan