I am trying to execute the following code in linaro on zed board. My problem is that I am trying to access the Physical locations by mapping them to virtual locations and the problem is I am trying to access consecutive memory locations 0x1ff00000 0x1ff00004 0x1ff00008 0x1ff00012. mmap is allocating a valid address to 0x1ff00000 and for rest all it is returning a virtual address of 0xffffffff.
Here is my source code
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <sys/mman.h>
#definetttDMA_BASEADDRtt0x40400000
#definetttS2MM_DMACRtt0xC
#definetttS2MM_DMASRtt0xD
#definetttS2MM_DAttt0x12
#definetttS2MM_LENGTHtt0x16
#definetttCOUNTER_BASEADDRt0x43C00000
#definetttDEST_ADDRtt0x1FF00000
#definetttPAGE_SIZEtt0x1000
#define SECOND_BYTE 0x1FF00004
#define THIRD_BYTE 0x1FF00008
#define FOURTH_BYTE 0x1FF00012
int main (void) {
int fd=0;
if ( (fd = open("/dev/mem", O_RDWR)) < 1)tttt
{
perror("
Error opening device file
");
return -1;
}
fprintf(stdout, "
Opened device file successfully
");
unsigned int *dma_base_address;
unsigned int *counter_base_address;
dma_base_address=(unsigned int*)DMA_BASEADDR;
counter_base_address=(unsigned int*)COUNTER_BASEADDR;
printf("Original DMA Base:0x%08x
",dma_base_address);
printf("Original Counter Base:0x%08x
",counter_base_address);
unsigned int *virtual_dma_base_address;
unsigned int *virtual_counter_base_address;
virtual_dma_base_address=(unsigned int*)mmap(NULL, 65 , PROT_READ|PROT_WRITE, MAP_SHARED, fd, DMA_BASEADDR);
if (virtual_dma_base_address == NULL)
perror("
Unable fetch virt. addr. for AXI DMA
");
printf("Memory mapped DMA Base Address: %08x
",virtual_dma_base_address);
virtual_counter_base_address=(unsigned int*)mmap(NULL, 16 , PROT_READ|PROT_WRITE, MAP_SHARED, fd, COUNTER_BASEADDR);
if (virtual_counter_base_address == NULL)
perror("
Unable fetch virt. addr. for AXI Counter
");
printf("Memory mapped counter Base Address: %08x
",virtual_counter_base_address);
unsigned int *virtual_address_firstchunk;
unsigned int *virtual_address_secondchunk;
unsigned int *virtual_address_thirdchunk;
unsigned int *virtual_address_fourthchunk;
virtual_address_firstchunk=(unsigned int*)mmap(NULL, 4 , PROT_READ|PROT_WRITE, MAP_SHARED, fd, DEST_ADDR);
virtual_address_secondchunk=(unsigned int*)mmap(NULL, 4 , PROT_READ|PROT_WRITE, MAP_SHARED, fd, SECOND_BYTE);
virtual_address_thirdchunk=(unsigned int*)mmap(NULL, 4 , PROT_READ|PROT_WRITE, MAP_SHARED, fd, THIRD_BYTE);
virtual_address_fourthchunk=(unsigned int*)mmap(NULL, 4 , PROT_READ|PROT_WRITE, MAP_SHARED, fd, FOURTH_BYTE);
printf("First read addr virtual addr: 0x%08x
",virtual_address_firstchunk);
printf("Second read addr virtual addr: 0x%08x
",virtual_address_secondchunk);
printf("Third read addr virtual addr: 0x%08x
",virtual_address_thirdchunk);
printf("Fourth read addr virtual addr: 0x%08x
",virtual_address_fourthchunk);
}
Executing the code gives the following output
Opened device file successfully
Original DMA Base:0x40400000
Original Counter Base:0x43c00000
Memory mapped DMA Base Address: b6f9d000
Memory mapped counter Base Address: b6f9c000
First read addr virtual addr: 0xb6f84000
Second read addr virtual addr: 0xffffffff
Third read addr virtual addr: 0xffffffff
Fourth read addr virtual addr: 0xffffffff
Please could someone help me why this occurs