All of lore.kernel.org
 help / color / mirror / Atom feed
* Bus error after successful mmap of physical address
@ 2007-08-22 17:31 Alex Gonzalez
  2007-08-22 18:08 ` Ralf Baechle
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Gonzalez @ 2007-08-22 17:31 UTC (permalink / raw)
  To: linux-mips

Hi,

I am sure there is a basic reason why this is not working but I just
can't see it.

I am booting with mem=512MB and trying to access a memory region at
0xC0000000 mapped by a fixed TLB entry.

My driver does,

vma->vm_flags = vma->vm_flags | VM_IO | VM_RESERVED ;
vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot) ;

	// Map the whole physically contiguous area in one piece
	if( (ret  = io_remap_pfn_range(vma , vma->vm_start, vma->vm_pgoff ,
vma->vm_end - vma->vm_start , vma->vm_page_prot)) < 0 )
    return ret;
	return 0

And my user space app does:

// open device
	vadr = mmap( NULL , 1024*1024 ,
PROT_WRITE|PROT_READ,MAP_NORESERVE|MAP_SHARED,device,0xC0000000);
	if(vadr == MAP_FAILED)
	{
		perror("mmap failed.\n");
		exit(-1);
	}


That goes OK, but then if I try to read or write from vadr I get a "Bus error".

Isn't that the correct way to map a physical address region to user
space? I just need to make sure that this is the case before starting
to debug the issue.

Thank a lot,
Alex

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

* Re: Bus error after successful mmap of physical address
  2007-08-22 17:31 Bus error after successful mmap of physical address Alex Gonzalez
@ 2007-08-22 18:08 ` Ralf Baechle
  2007-08-23 10:22   ` Alex Gonzalez
  0 siblings, 1 reply; 3+ messages in thread
From: Ralf Baechle @ 2007-08-22 18:08 UTC (permalink / raw)
  To: Alex Gonzalez; +Cc: linux-mips

On Wed, Aug 22, 2007 at 06:31:22PM +0100, Alex Gonzalez wrote:

> I am sure there is a basic reason why this is not working but I just
> can't see it.
> 
> I am booting with mem=512MB and trying to access a memory region at
> 0xC0000000 mapped by a fixed TLB entry.

Is 0xC0000000 a physical or virtual address.  If it's a virtual address
your mapping will conflict with other mappings generated by the kernel and
you will need additional hacks to protect the address space from being
used by the kernel for other purposes.

> My driver does,
> 
> vma->vm_flags = vma->vm_flags | VM_IO | VM_RESERVED ;
> vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot) ;
>
> // open device
> 	vadr = mmap( NULL , 1024*1024 ,
> PROT_WRITE|PROT_READ,MAP_NORESERVE|MAP_SHARED,device,0xC0000000);
                                                       ^^^^^^^^^^

This is the reason why I was asking if 0xC0000000 was a physical address.
mmap needs a physical address.

> 	if(vadr == MAP_FAILED)
> 	{
> 		perror("mmap failed.\n");
> 		exit(-1);
> 	}
> 
> 
> That goes OK, but then if I try to read or write from vadr I get a "Bus error".

Assuming device is a /dev/mem descriptor that is looking ok.  However - you
will be getting an uncached mapping from mmap so the performance will suck
rocks through a straw.

Anyway, you have 64-bit hardware, use it.  On a 64-bit kernel you can just
address all your memory through XKPHYS without the need for any TLB entries.

  Ralf

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

* Re: Bus error after successful mmap of physical address
  2007-08-22 18:08 ` Ralf Baechle
@ 2007-08-23 10:22   ` Alex Gonzalez
  0 siblings, 0 replies; 3+ messages in thread
From: Alex Gonzalez @ 2007-08-23 10:22 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips

Hi Ralf,

Thanks for answer. As always very helpful.

As you point out 0xC0000000 is not the physical address. It worked
with ioremap with the fixed TLB mapping and that made me think it was
the same one here.

I forgot that when mapping it to user space I am using the virtual
memory subsystem which will deal with the TLB itself.

Uncached access is OK. The memory area is used to share data between
the two cores and the data can change so I don't want any of them to
cache it.

Regarding 64bits, for the moment I am stuck with finding a solution
with a 32bits kernel. Too many drivers and hacks to support custom
hardware would need to be ported and tested.

Thanks for helping me out of my confusion,
Alex

On 8/22/07, Ralf Baechle <ralf@linux-mips.org> wrote:
> On Wed, Aug 22, 2007 at 06:31:22PM +0100, Alex Gonzalez wrote:
>
> > I am sure there is a basic reason why this is not working but I just
> > can't see it.
> >
> > I am booting with mem=512MB and trying to access a memory region at
> > 0xC0000000 mapped by a fixed TLB entry.
>
> Is 0xC0000000 a physical or virtual address.  If it's a virtual address
> your mapping will conflict with other mappings generated by the kernel and
> you will need additional hacks to protect the address space from being
> used by the kernel for other purposes.
>
> > My driver does,
> >
> > vma->vm_flags = vma->vm_flags | VM_IO | VM_RESERVED ;
> > vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot) ;
> >
> > // open device
> >       vadr = mmap( NULL , 1024*1024 ,
> > PROT_WRITE|PROT_READ,MAP_NORESERVE|MAP_SHARED,device,0xC0000000);
>                                                        ^^^^^^^^^^
>
> This is the reason why I was asking if 0xC0000000 was a physical address.
> mmap needs a physical address.
>
> >       if(vadr == MAP_FAILED)
> >       {
> >               perror("mmap failed.\n");
> >               exit(-1);
> >       }
> >
> >
> > That goes OK, but then if I try to read or write from vadr I get a "Bus error".
>
> Assuming device is a /dev/mem descriptor that is looking ok.  However - you
> will be getting an uncached mapping from mmap so the performance will suck
> rocks through a straw.
>
> Anyway, you have 64-bit hardware, use it.  On a 64-bit kernel you can just
> address all your memory through XKPHYS without the need for any TLB entries.
>
>   Ralf
>

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

end of thread, other threads:[~2007-08-23 10:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-22 17:31 Bus error after successful mmap of physical address Alex Gonzalez
2007-08-22 18:08 ` Ralf Baechle
2007-08-23 10:22   ` Alex Gonzalez

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.