Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - shared memory issue: (5 Items)
   
shared memory issue  
There is a shared memory object (NVRAM, ~24Mbytes) on my target board. I tried to map a block of NVRAM memory as my DMA 
buffer as below, 

fd = shm_open(shm_buff_name, O_RDWR, 0);
vaddr = mmap(NULL, 0x20000, PROT_READ | PROT_WRITE | PROT_NOCACHE,  MAP_SHARED, fd,  shm_buff_off);
mem_offset64(vaddr, NOFD, 0x20000, &paddr, NULL);

The 'shm_buff_off' is the offset inside the NVRAM, where I want to allocate memory from.

When ‘shm_buff_off’ was changed, for example, from 0x100000 to 0x200000, the ‘vaddr’ was changed accordingly. 
However, the ‘paddr’ was always same. What is possible reason?

Thanks,

 

Re: shared memory issue  
> There is a shared memory object (NVRAM, ~24Mbytes) on my target board. I tried
>  to map a block of NVRAM memory as my DMA buffer as below, 
> 
> fd = shm_open(shm_buff_name, O_RDWR, 0);
> vaddr = mmap(NULL, 0x20000, PROT_READ | PROT_WRITE | PROT_NOCACHE,  MAP_SHARED
> , fd,  shm_buff_off);
> mem_offset64(vaddr, NOFD, 0x20000, &paddr, NULL);
> 
> The 'shm_buff_off' is the offset inside the NVRAM, where I want to allocate 
> memory from.
> 
> When ‘shm_buff_off’ was changed, for example, from 0x100000 to 0x200000, the
>  ‘vaddr’ was changed accordingly. However, the ‘paddr’ was always same. 
> What is possible reason?
> 

Is it possible you got them reversed, because it's more likely vaddr wouldn't have changed, it's a virtual address.

> Thanks,
> 
>  
> 


Re: shared memory issue  
I tested it again. I found that both of vaddr and paddr are same for different offset. Below is my test code,

vaddr = mmap(NULL, 0x20000, PROT_READ|PROT_WRITE|PROT_NOCACHE, MAP_SHARED, fd, shm_buff_off);
if (vaddr != MAP_FAILED) {
    int config_len;
    if (mem_offset64(vaddr, NOFD, 0x20000, &paddr, &config_len) != -1) {
        printf("Memory available 0x%x, vaddr 0x%x, paddr 0x%x ",  config_len, (uint32_t)vaddr, paddr);
    }
}

Moreover, the 'config_len' is always 0x1000. I am not sure if it is correct. However, the allocated DMA buffer works 
fine. 
Re: shared memory issue  
On Wed, Feb 13, 2008 at 02:45:16PM -0500, Jianwei Gao wrote:
> I tested it again. I found that both of vaddr and paddr are same for
different offset. Below is my test code,

What version of the OS are you using? There's PR 28536 if you're using
6.3.0 or earlier - if you were using shm_ctl(...,SHM_CTL_PHYS,...), the
mmap()
didn't add the offset parm to the base address of the object properly.
The bug got fixed in 6.3.2.

-- 
Brian Stecher (bstecher@qnx.com)        QNX Software Systems
phone: +1 (613) 591-0931 (voice)        175 Terence Matthews Cr.
       +1 (613) 591-3579 (fax)          Kanata, Ontario, Canada K2M 1W8
Re: shared memory issue  
Thanks a lot. The OS version is 6.3.0.