All of lore.kernel.org
 help / color / mirror / Atom feed
* mmap problem
@ 2004-12-07 15:42 ` Dmitriy Tochansky
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitriy Tochansky @ 2004-12-07 15:42 UTC (permalink / raw)
  To: linux-mips

Hi!
I try to write small driver to make access to pci device resource from 
userland using mmap.
Code below didnt work. :(
From I module in debug I make some testes - I can read from device registers
but after mmap from userspace I reading just part of memory. :(
Some cache?

CPU - au1500

.....

static unsigned long *offset;

static int mdrv_mmap(struct file * file, struct vm_area_struct *vma)                                   
{                                                                                                      
                                                                                                       
 int ret;                                                                                              
 struct inode *inode;                                                                                  
 inode = file->f_dentry->d_inode;                                                                      
 
 ret = -EINVAL;                                                                                        
 unsigned long start = vma->vm_start;                                                                  
 unsigned long size = (vma->vm_end-vma->vm_start);                                                     
 
 offset = ioremap(0x40000000,0x40);
 
 printk("0x%p\n",__pa(offset));


  printk("lb 0x%X\n",offset[ 0x3C>>2 ] );

  vma->vm_flags |= VM_LOCKED;

  printk("+++++0x%X 0x%X\n",start,size);

  vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
                                   
  ret = remap_page_range( start, 0x40000000, size, vma->vm_page_prot ); //0x40000000 is first iomem range of pci device

  return ret;                                                               
}

struct file_operations mdrv_fops = {
  .open = mdrv_open,
  .release = mdrv_close,
  .read = mdrv_read,
  .write = mdrv_write,
  .mmap = mdrv_mmap
};

....


Here is userland 
#include "mdrv.h"
#include <sys/mman.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <linux/kernel.h>
#include <string.h>

int fd,fd2;

int
main ()
{

  fd = open("/dev/mboard0",O_RDWR);
  
  unsigned long *x;
  x = mmap(NULL,64,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);

  printf("mmap return: 0x%X",x);

  if(x == MAP_FAILED)
  {
   printf(" it is very bad! :(\n");
   perror("mmap:");
   return -1;
  }
 
  printf(" its ok!\n");

  int i;
  for(i=0;i<16;i++)
  {
  printf(" %d = 0x%X\n",i,x[i]);
  }
  munmap(x,64);
  
  return 0;
}

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

* mmap problem
@ 2004-12-07 15:42 ` Dmitriy Tochansky
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitriy Tochansky @ 2004-12-07 15:42 UTC (permalink / raw)
  To: linux-mips

Hi!
I try to write small driver to make access to pci device resource from 
userland using mmap.
Code below didnt work. :(

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

* Re: mmap problem
  2004-12-07 15:42 ` Dmitriy Tochansky
  (?)
@ 2004-12-07 15:57 ` Dan Malek
  2004-12-08  7:40   ` Dmitriy Tochansky
  -1 siblings, 1 reply; 6+ messages in thread
From: Dan Malek @ 2004-12-07 15:57 UTC (permalink / raw)
  To: Dmitriy Tochansky; +Cc: linux-mips


On Dec 7, 2004, at 10:42 AM, Dmitriy Tochansky wrote:

>   ret = remap_page_range( start, 0x40000000, size, vma->vm_page_prot 
> ); //

Use io_remap_page_range, it has the same parameters, and is
designed to work with > 32-bit physical addresses.

Also, you should really use pci_resource_* functions to get
information about the pci address, size, etc.  Don't hardcode this,
even for testing.


	-- Dan

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

* Re: mmap problem
@ 2004-12-08  7:28 Alexey Shinkin
  2004-12-08  7:35 ` Dmitriy Tochansky
  0 siblings, 1 reply; 6+ messages in thread
From: Alexey Shinkin @ 2004-12-08  7:28 UTC (permalink / raw)
  To: toch; +Cc: linux-mips

Hi !

On Au1550 code like yours works

I use ioremap_nocache(PhysAddr,length)  to get access from kernel level.

For access from  userland I don't set any vm_flags in drivers' mmap() ,
  vma->vm_flags is set by kernel to  0x40FB (VM_IO is set and VM_LOCKED 
isn't).

And , as Dan said , pci_resource_* functions used for getting valid PCI 
memory address

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

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

* Re: mmap problem
  2004-12-08  7:28 Alexey Shinkin
@ 2004-12-08  7:35 ` Dmitriy Tochansky
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitriy Tochansky @ 2004-12-08  7:35 UTC (permalink / raw)
  To: linux-mips

On Wed, 08 Dec 2004 13:28:30 +0600
"Alexey Shinkin" <alexshinkin@hotmail.com> wrote:

> Hi !
> 
> On Au1550 code like yours works
> 
> I use ioremap_nocache(PhysAddr,length)  to get access from kernel
> level.
  Yes, it works. Even just ioremap()
 
> For access from  userland I don't set any vm_flags in drivers' mmap()
> ,
>   vma->vm_flags is set by kernel to  0x40FB (VM_IO is set and
>   VM_LOCKED isn't).
  I tryed it - same result. :(

> 
> And , as Dan said , pci_resource_* functions used for getting valid
> PCI memory address
  Done! :)

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

* Re: mmap problem
  2004-12-07 15:57 ` Dan Malek
@ 2004-12-08  7:40   ` Dmitriy Tochansky
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitriy Tochansky @ 2004-12-08  7:40 UTC (permalink / raw)
  To: Dan Malek; +Cc: linux-mips

On Tue, 7 Dec 2004 10:57:20 -0500
Dan Malek <dan@embeddededge.com> wrote:

> >   ret = remap_page_range( start, 0x40000000, size, vma->vm_page_prot
> >   
> > ); //
> 
> Use io_remap_page_range, it has the same parameters, and is
> designed to work with > 32-bit physical addresses.
  Well, I test it. On module load - unresolved symbol remap_page_range_high. I looking for some ifdefs
where this function blocked, but seems like everithing is ok. :(

> 
> Also, you should really use pci_resource_* functions to get
> information about the pci address, size, etc.  Don't hardcode this,
> even for testing.

There is a new variant. If I by hand make io_remap_page_range visible - system hangs. :(
  

#define MAX_DEV 4

struct pci_dev *devs[MAX_DEV];
struct pci_dev *dev = NULL;

...

static unsigned long *offset;

static int mdrv_mmap(struct file * file, struct vm_area_struct *vma)                                   
{                                                                                                      
                                                                                                       
 int ret;                                                                                              
 struct inode *inode;                                                                                  
 inode = file->f_dentry->d_inode;                                                                      
 
 ret = -EINVAL;                                                                                        
 unsigned long start = vma->vm_start;                                                                  
 unsigned long size = (vma->vm_end-vma->vm_start);                                                     
 
 struct pci_dev *curdev = NULL;
 
 int minor = MINOR(inode->i_rdev);
 
 printk("minor = %d\n",minor);
 
 curdev = (devs[minor]);
 
 offset = (unsigned long *)pci_resource_start(curdev,0);
 
 printk("offset = 0x%X\n", offset );

 ret = io_remap_page_range( start, offset, size, vma->vm_page_prot );

 return ret;                                                               
}

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

end of thread, other threads:[~2004-12-08  7:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-12-07 15:42 mmap problem Dmitriy Tochansky
2004-12-07 15:42 ` Dmitriy Tochansky
2004-12-07 15:57 ` Dan Malek
2004-12-08  7:40   ` Dmitriy Tochansky
  -- strict thread matches above, loose matches on Subject: below --
2004-12-08  7:28 Alexey Shinkin
2004-12-08  7:35 ` Dmitriy Tochansky

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.