Subject: troubles mmaping PCI device on Au1550

From: Clem Taylor <[email-masked]>
Date: Sun, 10 Apr 2005 18:16:17 -0400

I'm working on a Au1550 driver for a PCI based co-processor. The
processor exports a 4Mbyte BAR that I want to mmap() into user space.
From inside the driver I can read and write to the BAR using an
address from ioremap_nocache(). I can read location with known values
and get back the expected data and with JTAG on the co-processor I saw
that data written from the 1550 really makes it into the PCI device.
From userspace with the llseek/read interface I can read the data well
known data and the data written by the driver.

However, I'm not having any luck getting mmap() to work. I must just
be mapping the wrong address... I tried a bunch of different
combinations of addresses, but so far I haven't had any luck getting
the mmap() to work.

The mmap() handler calls remap_pfn_range with a physical address
returned from pci_resource_start().

My driver code has something like:
remap_pfn_range ( vma, vma->vm_start,
     ( pci_resource_start ( pdev, BAR ) >> PAGE_SHIFT ) + vma->pgoff,
     vma->vm_end - vma->vm_start, vma->vm_page_prot );

vma->pgoff is zero, so this should map starting at the beginning of
the BAR. From user space, the data at the mmap()ed address isn't what
I was expecting.

For a sanity check, I tried using /dev/mem to mmap the PCI address as
returned by lspci. This seems to return similar, but not identical
data as my device driver. But it isn't what I was expecting.

I tried a similar test using /dev/mem and the address the linear
framebuffer on my desktop machine (as returned by lspci). The mapped
data matches the pixels on the first line (as reported by xmag).

Has anyone tried something like this on the Alchemy processors with a
recent kernel?

                          Many thanks,
                          Clem Taylor

---

From: Dan Malek <[email-masked]>
Date: Tue, 12 Apr 2005 11:22:24 -0400

>      vma->vm_end - vma->vm_start, vma->vm_page_prot );

The Au15xx uses 36-bit addressing for the PCI (among other) physical
addresses.  The mmap() in your driver is the right thing, but you need
to use io_remap_page_range() where the 2nd parameter is a phys_t.
Your offset should be a phys_t type, and pci_resource_start() also
returns a phys_t.

> framebuffer on my desktop machine (as returned by lspci).

You can't use /dev/mem for this on Au15xx because it doesn't have
provisions for more than 32-bit addresses.  Be careful with lspci,
as it only returns the 32-bit BAR, not the 36-bit Au15xx address nor
the 32-bit ioremapped address.

Thanks.

	-- Dan

---

From: Clem Taylor <[email-masked]>
Date: Tue, 12 Apr 2005 16:56:56 -0400

> Your offset should be a phys_t type, and pci_resource_start() also

Yeah, this was exactly my problem. Last night I managed to find the
comment about this in au1000.h. Now I can happily mmap() the PCI
devices memory. Thanks!

                                --Clem