How to access physical memory directly?
Hello
I am working on a board which has two processors; an ARM9, and a TI's DaVinci processor. ARM9 has Linux running on it and DaVinci is running without operating system. There is a shared memory space between them and I want to use a small portion of this shared memory as communication channel between the two processors. In order to do so I have to access the physical memory directly from Linux so that I can write to it from Linux (ARM9) and then read it from DaVinci. Can I do it using mmap()? or will I have to write a driver for it? How can I make sure that this small portion of memory is not allocated to some other process by the kernel on ARM9? |
Quote:
#define MAP_SIZE 4096 #define MAP_MASK (MAP_SIZE-1) off_t target=0xFFFFF43C; //the physical address which u should know. and use mmap() similar to below. map_base=mmap(0,MAP_SIZE,PROT_READ|PROT_WRITE,MAP_SHARED,fd1,target & ~ MAP_MASK); if(map_base == (void *) -1) { perror("map_base"); exit(-1); } the above i have used for ARM 9 based AT91SAM9261 or best is u can convert this to kernel space by using a mofule. tat way ur performance will be better. warm regards, Ravi Kulkarni. |
Cannot write to the mapped memory location
Quote:
Thanks a lot Ravi for the reply. I tried mmap, the way you told me, on my desktop computer first but I could not write to the mapped memory. mmap() returns a valid pointer and I can read the data at that pointer. It always shows FF. When I write at it by assigning a new value, the data at that location doesn't change and it remains FF. What could be wrong? the code that I ran is /////////////////////////////////////////// #include <stdio.h> #include <sys/mman.h> #include <fcntl.h> #define MAP_SIZE 4096 #define MAP_MASK (MAP_SIZE-1) off_t target = 0xD000F000; int main(void) { int fd1; char *map_base; if((fd1=open("/dev/mem",O_RDWR))==0) { perror("Error openning file /dev/mem"); return -1; } map_base = (char *)mmap(0,MAP_SIZE,PROT_READ|PROT_WRITE,MAP_SHARED,fd1,target&~MAP_MASK); if(map_base == (void *)-1) { perror("Error mapping"); return -2; } printf("Value at map_base before writing is %2X\n",map_base[0]); map_base[0] = 1; //***This should alter the value at this memory location*** printf("Value at map_base after writing is %2X\n",map_base[0]); //***This should print 1 but it prints FF*** return 0; } //////////////////////////////////// Regards, Atif Shabir . |
If u tried this on your desktop make sure u check ur PAGE size correctly ? and also check whether this physical address is valid! what i gave example for ARM based board and what u are trying is on x86 unless ur desktop is other ARCH . check arch dependency first.
warm regards, Ravi Kulkarni. |
All times are GMT -5. The time now is 10:05 AM. |