LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-19-2005, 09:22 AM   #1
mspies
LQ Newbie
 
Registered: Aug 2005
Posts: 1

Rep: Reputation: 0
ioremap and remap_page_range


I am using a Motorola PPC Hardware (MPC5200) with linux kernel 2.4.25 and 32 MB RAM.

I would like to map a large contiguous kernel memory buffer (6 MB) into user space with mmap and remap_page_range. For this action I reserved memory at the end of the phyiscal memory at boot time. (Kernel boot option mem =12 M) Now, the kernel only knows about 20 MB of memory. The high_memory border is at 0x1400000 (physical address).
I have to do a ioremap() on the high_memory (0x1400000) to map the high physical memory into a virtual kernel memory.

ioremap_ptr = ioremap_nocache (__pa(high_memory), 6*1024*1024); //6 MB

ioremap_ptr is a virtual kernel address.

Now I do a mem_map_reserve () on every page in this memory block.

On the ioremap ptr I do a memset to check the data in user space later.

memset(ioremap_ptr, 0xAB, 6*1024*1024);

With bdi2000 I looked to the memory values at 0x1400000 and everything is ok, I see 0xABABABAB.

If I do a virt_to_phys() on ioremap_ptr, I get a really strange address. I expected to get the physical address 0x1400000.

Example:

__pa(high_memory): 0x1400000
ioremap_ptr: 0xc22a4000
virt_to_phys(ioremap_ptr): 0x22a4000
virt_to_bus(ioremap_ptr): 0x22a4000


Now I want to map the buffer into to user space with mmap and remap_page_range.


static int mmap (struct file *file, struct vm_area_struct *vma)
{
unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
int error;
unsigned long start = (unsigned long)vma->vm_start;
unsigned long size = (unsigned long)(vma->vm_end - vma->vm_start);



if (offset != 0)
{
printk ("rt_iso1394_mmap: invalid offset: must be 0\n");
return -ENXIO;
}


if(size == PAGE_ALIGN(6*1024*1024)
{
start,virt_to_phys(shared_buffer_ptr), size, protect);
error = remap_page_range (vma->vm_start, 0x1400000 , size, PAGE_SHARED);

if (error)
{
printk ("rt_iso1394_mmap: remap_page_range failed\n");
return -EAGAIN;
}
}

else
{

printk ("rt_iso1394_mmap: invalid mmap size, size is: %d\n", (int) size);
return -EAGAIN;
}


return 0;
}


The function returned with no errors.

If I call mmap () in user space, the function returnes a virtual user address. But if do a read on this memory, I don’t see the data I have written in the kernel data block in kernel space. I only get zeros. It seems that remap_page_range maps a copletely different data block.

Are the any ideas to solve the problem? What I am doing wrong? What is missing? Where ist the Problem with the addresses???
 
Old 08-20-2005, 10:41 PM   #2
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 53
i don't know anything about those motorola processors
i know even less about device drivers but since sometimes fresh eyes can help even dumb ones

it looks like you allocated a DMA buffer using kmalloc
and it says in asm-ppc64/io.h about virt_to_phys()
This function does not give bus mappings for DMA transfers.

seems like you get a phyical address and then
phys_to_bus()
then ioremap()
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ioremap() and readl() not compiling CyberEE Linux - Software 0 01-19-2004 10:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration