From: Dmitriy Tochansky <toch@dfpost.ru>
To: linux-mips@linux-mips.org
Subject: mmap problem
Date: Tue, 7 Dec 2004 18:42:58 +0300 [thread overview]
Message-ID: <20041207184258.071bf401.toch@dfpost.ru> (raw)
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;
}
WARNING: multiple messages have this Message-ID (diff)
From: Dmitriy Tochansky <toch@dfpost.ru>
To: linux-mips@linux-mips.org
Subject: mmap problem
Date: Tue, 7 Dec 2004 18:42:58 +0300 [thread overview]
Message-ID: <20041207184258.071bf401.toch@dfpost.ru> (raw)
Message-ID: <20041207154258.W7z5dPvdbnCZvbChyFINpvX-9DRpZCCNp3CGarSqNTc@z> (raw)
Hi!
I try to write small driver to make access to pci device resource from
userland using mmap.
Code below didnt work. :(
next reply other threads:[~2004-12-07 15:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-07 15:42 Dmitriy Tochansky [this message]
2004-12-07 15:42 ` mmap problem 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20041207184258.071bf401.toch@dfpost.ru \
--to=toch@dfpost.ru \
--cc=linux-mips@linux-mips.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox