On 12/04/13 08:48, De Roo, Steven wrote:
> Dear Martyn and Manohar,
Hi Steven,
> Can somebody give me a small example on how to use the "vme_user" module ?
> I have some legacy code running on an old machine that reads/writes
> some data on the VME-bus using lseek/read/write,
> using an undocumented & 'unsourced' driver... Is something similar
> possible with the "vme_user" module ?
>
Assuming the VME support has has been built as modules, you will need to have
the vme core, a suitable bridge driver and the vme_user module.
To load the core call "modprobe vme" or equivalent. There are bridge drivers
for the Tundra/IDT tsi148 ("Tempe") and Tundra/IDT ca91cx42 ("Universe II")
PCI to VME bridges. These are called vme_tsi148 and vme_ca91cx42 respectively.
You will need to load the bridge driver for the chip on your board. Just out
of interest, which board and chip are you using?
The vme_user module requires the VME bus to which it is to be bound to be
specified at module load. For most people (who only have 1 VME bridge on their
board) this will be bus 0. You can load vme_user and bind it to the first bus
with the following command:
modprobe vme_user bus=0
If you have built the VME core, bridge driver and vme_user into you kernel,
appending "vme_user.bus=0" to your boot args should be sufficient to bind to
the first VME bus.
Once bound and assuming you have udev support in user space, the driver will
provide access to 4 master and 4 slave windows via device files in
"/dev/bus/vme/". These VME windows can be configured by opening the relevant
device file and making an ioctl call with the VME_SET_MASTER or VME_SET_SLAVE
command (for master and slave windows respectively), likewise the settings can
be retrieved using the VME_GET_MASTER or VME_GET_SLAVE ioctl commands.
Once a window is configured, reading and writing the device file will either
read/write across the VME bus for master windows or read/write into the slave
window buffer for slave windows.
Here's a simple test application to test the vme_user driver (you will need to
copy the vme_user.h header into the same directory as the file containing this
code, from drivers/staging/vme/devices/vme_user.h in the kernel source, to get
this to build):
----------
/* Simple VME User module test.
*
* This test opens the first VME master window, configures it as follows:
* - A24 Address space
* - Address: 0x30000
* - Size: 0x10000
* - Access Mode: User/Data
* - Mode: 16-bit transfers
*
* It then attempts to read and print out the first 512 bytes of data found
* at this address.
*/
#define _XOPEN_SOURCE 500
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "vme_user.h"
int main(int argc, char *argv[])
{
int fd;
int i;
int retval;
unsigned char data[512];
struct vme_master master;
printf("Simple VME User Module Test\n");
fd = open("/dev/bus/vme/m0", O_RDONLY);
if (fd == -1) {
perror("ERROR: Opening window device file");
return 1;
}
master.enable = 1;
master.vme_addr = 0x30000;
master.size = 0x10000;
master.aspace = 2; // VME_A24
master.cycle = 0x2000 | 0x8000; // user/data access
master.dwidth = 2; // 16 bit word access
retval = ioctl(fd, VME_SET_MASTER, &master);
if (retval != 0) {
printf("retval=%d\n", retval);
perror("ERROR: Failed to configure window");
return 1;
}
/*
* Reading first 512 bytes
*/
for (i=0; i<512; i++) {
data[i] = 0;
}
retval = pread(fd, data, 512, 0);
if (retval < 512) {
printf("WARNING: Only read %d bytes", retval);
}
for(i=0; i<retval; i++) {
if (i % 8 == 0) {
printf("\n""%4.4x: ", i);
}
printf("%2.2x ", data[i]);
}
printf("\n");
close(fd);
return 0;
}
----------
Hope that helps,
Martyn
--
Martyn Welch (Lead Software Engineer) | Registered in England and Wales
GE Intelligent Platforms | (3828642) at 100 Barbirolli Square
T +44(0)1327322748 | Manchester, M2 3AB
E [email protected] | VAT:GB 927559189
_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel