* mmap problem another :)
@ 2004-12-08 16:40 Dmitriy Tochansky
2004-12-08 17:27 ` Dan Malek
0 siblings, 1 reply; 7+ messages in thread
From: Dmitriy Tochansky @ 2004-12-08 16:40 UTC (permalink / raw)
To: linux-mips
Ok. I did as you say and got that mmap func:
static int
mdrv_mmap (struct file *file, struct vm_area_struct *vma)
{
unsigned long offset = 0;
int ret;
struct inode *inode;
inode = file->f_dentry->d_inode;
struct pci_dev *curdev = NULL;
int minor = MINOR (inode->i_rdev);
printk("minor = 0x%X\n",minor);
curdev = (devs[minor]);
unsigned long start = vma->vm_start;
unsigned long size = (vma->vm_end - vma->vm_start);
offset = pci_resource_start (curdev, IOMEM0);
printk("offset = 0x%X\n",(unsigned int)offset);
ret = remap_page_range_high (start, offset, size, vma->vm_page_prot);
return ret;
}
And it works fine but... but when I try to do mmap not /dev/mboard0 but /dev/mboard1 Im again
have the "bad" result. :( Is there something specific to mmap several devices?
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: mmap problem another :)
2004-12-08 16:40 mmap problem another :) Dmitriy Tochansky
@ 2004-12-08 17:27 ` Dan Malek
2004-12-08 18:20 ` Pete Popov
2004-12-09 6:56 ` Dmitriy Tochansky
0 siblings, 2 replies; 7+ messages in thread
From: Dan Malek @ 2004-12-08 17:27 UTC (permalink / raw)
To: Dmitriy Tochansky; +Cc: linux-mips
On Dec 8, 2004, at 11:40 AM, Dmitriy Tochansky wrote:
> ret = remap_page_range_high (start, offset, size, vma->vm_page_prot);
Hmmm....this is in 2.4? Did you apply all of the 36-bit IO
patch as Pete Popov has mentioned in past e-mail messages?
Did you make sure you enabled CONFIG_64BIT_PHYS_ADDR?
I know this does work. In fact, you should just use
io_remap_page_range(). If that doesn't work, something
is wrong with the kernel configuration.
-- Dan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: mmap problem another :)
2004-12-08 17:27 ` Dan Malek
@ 2004-12-08 18:20 ` Pete Popov
2004-12-09 6:56 ` Dmitriy Tochansky
1 sibling, 0 replies; 7+ messages in thread
From: Pete Popov @ 2004-12-08 18:20 UTC (permalink / raw)
To: Dan Malek; +Cc: Dmitriy Tochansky, linux-mips
Dan Malek wrote:
>
> On Dec 8, 2004, at 11:40 AM, Dmitriy Tochansky wrote:
>
>> ret = remap_page_range_high (start, offset, size, vma->vm_page_prot);
>
>
> Hmmm....this is in 2.4? Did you apply all of the 36-bit IO
> patch as Pete Popov has mentioned in past e-mail messages?
The 36 bit patch is integrated in 2.4, and now in 2.6. The above
code looks like 2.4.
Pete
> Did you make sure you enabled CONFIG_64BIT_PHYS_ADDR?
>
> I know this does work. In fact, you should just use
> io_remap_page_range(). If that doesn't work, something
> is wrong with the kernel configuration.
>
> -- Dan
>
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: mmap problem another :)
2004-12-08 17:27 ` Dan Malek
2004-12-08 18:20 ` Pete Popov
@ 2004-12-09 6:56 ` Dmitriy Tochansky
1 sibling, 0 replies; 7+ messages in thread
From: Dmitriy Tochansky @ 2004-12-09 6:56 UTC (permalink / raw)
To: Dan Malek; +Cc: linux-mips
On Wed, 8 Dec 2004 12:27:02 -0500
Dan Malek <dan@embeddededge.com> wrote:
>
> On Dec 8, 2004, at 11:40 AM, Dmitriy Tochansky wrote:
>
> > ret = remap_page_range_high (start, offset, size,
> > vma->vm_page_prot);
>
> Hmmm....this is in 2.4? Did you apply all of the 36-bit IO
> patch as Pete Popov has mentioned in past e-mail messages?
Could you please direct me where it is exectly? In this maillist? May be on the web?
> Did you make sure you enabled CONFIG_64BIT_PHYS_ADDR?
Yes. I'm sure.
^ permalink raw reply [flat|nested] 7+ messages in thread
* mmap problem another :)
@ 2004-12-09 13:12 Dmitriy Tochansky
2004-12-09 14:36 ` Dan Malek
0 siblings, 1 reply; 7+ messages in thread
From: Dmitriy Tochansky @ 2004-12-09 13:12 UTC (permalink / raw)
To: linux-mips
Seems like I found problem.
Look ret = io_remap_page_range(start, offset, size, vma->vm_page_prot); remaps
from "offset" which I got from pci_resource_start (curdev, IOMEM0); its ok
from first board where it eq 0x40000000 but on second it 0x40002040
Then I'm reading from x = mmap (NULL, MMAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); with
shift 0x3C>>2 where I expect board register. But for second board x points to where?
0x40000000 or 0x40002040 or as I think remap_page_range or sonething realign offset to
PAGE so x points to 0x40002000 or 0x40003000 and reading with shift 0x3C have no sense.
Am I rigth?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: mmap problem another :)
2004-12-09 13:12 Dmitriy Tochansky
@ 2004-12-09 14:36 ` Dan Malek
2004-12-14 7:51 ` Dmitriy Tochansky
0 siblings, 1 reply; 7+ messages in thread
From: Dan Malek @ 2004-12-09 14:36 UTC (permalink / raw)
To: Dmitriy Tochansky; +Cc: linux-mips
On Dec 9, 2004, at 8:12 AM, Dmitriy Tochansky wrote:
> Look ret = io_remap_page_range(start, offset, size,
> vma->vm_page_prot); remaps
> from "offset" which I got from pci_resource_start (curdev, IOMEM0);
> its ok
> from first board where it eq 0x40000000 but on second it 0x40002040
Read the memory mapping docuemntation and understand the APIs.
All of the Linux mapping functions, whether mmap() from an application
or in the kernel are going to align on page boundaries.
The address of 0x40002040 is going to be aligned to a page boundary,
so you have to consider the offset into that page to the base of the
device, plus the register offset. The kernel mapping functions,
like remap_page_range, are going to force the alignment because
that is what we expect in the kernel. An mmap() with an unaligned
address will generate an error.
-- Dan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: mmap problem another :)
2004-12-09 14:36 ` Dan Malek
@ 2004-12-14 7:51 ` Dmitriy Tochansky
0 siblings, 0 replies; 7+ messages in thread
From: Dmitriy Tochansky @ 2004-12-14 7:51 UTC (permalink / raw)
To: linux-mips
On Thu, 9 Dec 2004 09:36:11 -0500
Dan Malek <dan@embeddededge.com> wrote:
> Read the memory mapping docuemntation and understand the APIs.
> All of the Linux mapping functions, whether mmap() from an application
> or in the kernel are going to align on page boundaries.
>
> The address of 0x40002040 is going to be aligned to a page boundary,
> so you have to consider the offset into that page to the base of the
> device, plus the register offset. The kernel mapping functions,
> like remap_page_range, are going to force the alignment because
> that is what we expect in the kernel. An mmap() with an unaligned
> address will generate an error.
Ok. I understand. But still havent fun. :(
Yes, Im assume that offset if pagealligned:
static int
mdrv_mmap (struct file *file, struct vm_area_struct *vma)
{
unsigned long offset = 0;
int ret;
struct inode *inode;
inode = file->f_dentry->d_inode;
struct pci_dev *curdev = NULL;
int minor = MINOR (inode->i_rdev);
printk("minor = 0x%X\n",minor);
curdev = (devs[minor]);
unsigned long start = vma->vm_start;
unsigned long size = (vma->vm_end - vma->vm_start);
offset = pci_resource_start (curdev, IOMEM0);
offset &= PAGE_MASK;
printk("start= 0x%X offset = 0x%X size=0x%X\n",start, (unsigned int)offset, (unsigned int) size);
ret = remap_page_range_high(start, offset, size, vma->vm_page_prot);
return ret;
}
This code, AFAIK will return me a pointer to begin of page where my ioaddr is. ?
Then in my testcode I compensate shift by adding it to addr:
---
#include "mdrv.h"
#include <sys/mman.h>
#include <stdio.h>
#include <fcntl.h>
#define MMAP_SIZE 0x40
int fd, fd2;
int
main ()
{
fd = open ("/dev/mboard1", O_RDWR);
unsigned long *x;
x = mmap (NULL, MMAP_SIZE, 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");
printf("x = 0x%X\n",x);
#define CONS 0
//0x2040 >> 2
x += CONS;
printf("x = 0x%X\n",x);
unsigned long m = 0xEF;
printf("m = 0x%X\n",m);
//printf ("%p\n", x[(0x3C)>>2]); //We have to get 0xE6 here
m = x[(0x40>>2)+(0x3C>>2)];
printf("m = 0x%p\n", m);
x -= CONS;
munmap (x, MMAP_SIZE);
close(fd);
return 0;
}
---
DEbug output shows that mmap - success. I get pointer and size = 0x1000(one page). Then
I try to read m from board register. BTW, if I just read apps finishing but when I try to output
to console(as in src) "m" programm hangs.
Have no idea what the ... is goin on. Some hints please.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2004-12-14 7:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-12-08 16:40 mmap problem another :) Dmitriy Tochansky
2004-12-08 17:27 ` Dan Malek
2004-12-08 18:20 ` Pete Popov
2004-12-09 6:56 ` Dmitriy Tochansky
-- strict thread matches above, loose matches on Subject: below --
2004-12-09 13:12 Dmitriy Tochansky
2004-12-09 14:36 ` Dan Malek
2004-12-14 7:51 ` 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.