MPC5200 mmap, ioremap

2 messages, 2 authors, 2005-08-22 · open the first message on its own page

MPC5200 mmap, ioremap

From: Kunkel, Ulrich <hidden>
Date: 2005-08-22 08:47:25

Hello,

  

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 mmmap (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 completely 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???

 

Thanks for your help 

 

 

 

Ulrich Kunkel

Hottinger Baldwin Messtechnik GmbH

AW: MPC5200 mmap, ioremap

From: Achim Machura <hidden>
Date: 2005-08-22 14:19:42

Hello Ulrich,
mem =12 M
i think it means the kernel knows about 12 MB

This code below works fine at our board, but we use only a few kb in the
protected ram.
I don't Know whats happen if size is bigger as one page.

int asi_common_mmap(struct file *filp, struct vm_area_struct *vma)
{
//	unsigned long off = vma->vm_pgoff << PAGE_SHIFT;
	unsigned long physical = ASI_IOMEM_BASE;
	unsigned long vsize = vma->vm_end - vma->vm_start;
//	unsigned long psize = ASI_IOMEM_SIZE - off;

//	rt_printk("start : 0x%08lX\n", vma->vm_start);
//	rt_printk("end   : 0x%08lX\n", vma->vm_end);
//	rt_printk("offset: 0x%08lX\n", off);
//	rt_printk("phys  : 0x%08lX\n", physical);
//	rt_printk("vsize : 0x%08lX\n", vsize);
//	rt_printk("psize : 0x%08lX\n", psize);

	if (filp->f_flags & O_SYNC)
	{
//		rt_printk("I/O-Mem");
		vma->vm_flags |= VM_IO;
	}
	vma->vm_flags |= VM_RESERVED;
	//if (vsize > psize) return -EINVAL; /* spans too high */
	if(remap_page_range(vma->vm_start, physical, vsize, vma->vm_page_prot))
	{
		return -EAGAIN;
	}
	return(0);
}

Achim
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help