[openib-general] mstflint - test1

Michael S. Tsirkin mst at mellanox.co.il
Wed Jan 12 02:51:56 PST 2005


OK.
Tom, here's a simple test.
After this we will know for sure whether mmap works, or not.
I hard-coded the physical memory offset to
1ff00100000 (this seems to be what you have), you can find out the real offset
for the first resource from lspci -vv or from cat /proc/iomem.

You have to be root to run.




==================================
#define BAR0 0x1ff00100000ull
#define _XOPEN_SOURCE 500
#define _FILE_OFFSET_BITS 64
#include <sys/mman.h>
#include <fcntl.h>

#include <unistd.h>

#include <stdio.h>


int main()
{
	int fd;
	void *ptr;
	unsigned value;
	unsigned long long offset = BAR0;
	fd = open("/dev/mem",O_RDWR | O_SYNC);
	if (fd<0) {
		perror("open");
		return 1;
	}

	ptr = mmap(NULL, 0x100000, PROT_READ | PROT_WRITE,
			MAP_SHARED, fd, offset);

	if ( (! ptr) || (ptr == MAP_FAILED) ) {
		perror("map");
		return 1;
	}

	value= *( (unsigned*)(ptr + 0x000f0014) );
	
	printf("value at 0x000f0014 is %#8.8x\n", value);

	return 0;
err:
	return 1;
}




More information about the general mailing list