Subject: mmap on 440gx

From: Ed Goforth <[email-masked]>
Date: Thu, 16 Jun 2005 17:33:44 -0400

I've been struggling with implementing mmap on a 440gx-based custom
board.  I have been able to use ioremap(), but we really need a mmap()
for our software.  The kernel is 2.4.18 (TimeSys 4.0).

I'm trying to access one of our FPGA's located at 0x50000000.  Offsets
0x00000000 thru
0x000FFFFF are control and status registers.  Offsets 0x01000000 thru
0x017FFFFF are the QDR SRAM on the FPGA.

Using ioremap_nocache(0x50000000, bytes_to_map) works (so long as
bytes_to_map isn't too large).  I can then use in_be32() and
out_be32() to read/write the registers and the SRAM.  However, trying
to implement mmap() causes the board to lock up hard.  I have tried
iterations both where the driver first does an ioremap(), and where it
doesn't do the ioremap().  Some bits:

In driver module:
static struct file_operations test_mmap_fops =3D {
  read : test_mmap_read,
  mmap : test_mmap_mmap,
  open : test_mmap_open,
  release : test_mmap_release,
};

static int test_mmap_mmap (struct file *filp, struct vm_area_struct *vma) {
  vma->vm_flags |=3D (VM_SHM | VM_LOCKED | VM_IO | VM_RESERVED);

  if (remap_page_range(vma->vm_start, 0x50000000, 4096, vma->vm_page_prot))
    return(-EAGAIN);

  return(0);

} /* test_mmap_mmap() */

When the test code calls mmap():
  unsigned long *mmap_region;
  unsigned long data;
  mmap_region =3D mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
it seems to work.  However, dereferencing mmap_region, either thru
  data =3D *mmap_region;
or
  data =3D mmap_region[0];
causes the board to lock hard.

I would appreciate any suggestions or hints.

Thanks,
Ed