linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* MPC5200 mmap, ioremap
@ 2005-08-22  8:47 Kunkel, Ulrich
  2005-08-22 14:12 ` AW: " Achim Machura
  0 siblings, 1 reply; 2+ messages in thread
From: Kunkel, Ulrich @ 2005-08-22  8:47 UTC (permalink / raw)
  To: 'linuxppc-embedded@ozlabs.org'

[-- Attachment #1: Type: text/plain, Size: 2753 bytes --]

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



[-- Attachment #2: Type: text/html, Size: 13418 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* AW: MPC5200 mmap, ioremap
  2005-08-22  8:47 MPC5200 mmap, ioremap Kunkel, Ulrich
@ 2005-08-22 14:12 ` Achim Machura
  0 siblings, 0 replies; 2+ messages in thread
From: Achim Machura @ 2005-08-22 14:12 UTC (permalink / raw)
  To: 'Kunkel, Ulrich'; +Cc: Linuxppc-Embedded (E-Mail)

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-08-22 14:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-22  8:47 MPC5200 mmap, ioremap Kunkel, Ulrich
2005-08-22 14:12 ` AW: " Achim Machura

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).