Re: Device driver, PCI, and mmapping

From: Jeff Garzik (jgarzik@mandrakesoft.com)
Date: Thu Jun 15 2000 - 12:41:32 EST


Ivan Passos wrote:
> On 15 Jun 2000, David D Golombek wrote:
> > static int
> > my_mmap(struct file *filp, struct vm_area_struct *vma) {
> > unsigned long paddr = 0, offset = 0, size = 0;
> >
> > offset = vma->vm_offset;
> > if (offset & ~PAGE_MASK)
> > return(-ENXIO);
> >
> > paddr = base0 + offset;
> > size = vma->vm_end - vma->vm_start;
> > vma->vm_flags |= (VM_SHM | VM_LOCKED | VM_IO);
> >
> > if (remap_page_range(vma->vm_start, paddr, size, vma->vm_page_prot))
> > return(-EAGAIN);
> >
> > return(0);
> > }
> >
> > The ioremap of base0 works great, I can read and write the device
> > memory with no problems from kernel space. It's just the userspace
> > that's messed. Do I need to futz with the vm_page_prot somehow? I
> > couldn't find any examples of how to do so. My userspace mmap call
> > looks has PROT_READ|PROT_WRITE and MAP_SHARED passed in.
>
> In order to access PCI MMIO areas from userspace, you should open
> "/dev/mem" (or "/dev/kmem") and then call mmap. The mmap call is something
> as follows:
[...]

Look at what he is trying to accomplish... He is writing a kernel
driver which makes the MMIO areas available to userspace, so opening
/dev/mem is bypassing his own efforts. :)

In 2.3.x/2.4.x, there is io_remap_page_range which exists for exporting
PCI MMIO areas to userspace. As James Simmons mentioned,
drivers/video/fbmem.c is an example of such usage.

        Jeff

-- 
Jeff Garzik              |
Building 1024            | Free beer tomorrow.
MandrakeSoft, Inc.       |

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Jun 15 2000 - 21:00:35 EST