The attached patch fixes a problem with the mmio area on mach64.

On some really old cards the mmio area is aligned on 2048 byte boundary 
and on new cards it's on a 4096 byte boundary. Fbdev's mmap() however 
returns a PAGE_SIZE aligned area. So with some cards the registers are 
found at offset PAGE_SIZE - 2048 and on other's they are at PAGE_SIZE - 
4096.

Can anyone see any potential problems with the patch?

-- 
Ville Syrj�l�
[EMAIL PROTECTED]
http://www.sci.fi/~syrjala/
Index: fbdev.c
===================================================================
RCS file: /cvs/directfb/DirectFB/systems/fbdev/fbdev.c,v
retrieving revision 1.7
diff -u -r1.7 fbdev.c
--- fbdev.c     9 Aug 2004 18:34:22 -0000       1.7
+++ fbdev.c     13 Aug 2004 05:01:48 -0000
@@ -314,6 +314,7 @@
 {
      DFBResult   ret;
      CoreScreen *screen;
+     long        page_size;
 
      D_ASSERT( dfb_fbdev == NULL );
 
@@ -326,6 +327,9 @@
 
      dfb_fbdev->core = core;
 
+     page_size = sysconf( _SC_PAGESIZE );
+     dfb_fbdev->shared->page_mask = page_size < 0 ? 0 : page_size - 1;
+
      ret = dfb_fbdev_open();
      if (ret) {
           SHFREE( dfb_fbdev->shared );
@@ -612,7 +616,8 @@
           return NULL;
      }
 
-     return(volatile void*) addr;
+     return(volatile void*) ((__u8*) addr + (dfb_fbdev->shared->fix.mmio_start &
+                                             dfb_fbdev->shared->page_mask));
 }
 
 static void
@@ -622,7 +627,8 @@
      if (length <= 0)
           length = dfb_fbdev->shared->fix.mmio_len;
 
-     if (munmap( (void*) addr, length ) < 0)
+     if (munmap( (void*) ((__u8*) addr - (dfb_fbdev->shared->fix.mmio_start &
+                                          dfb_fbdev->shared->page_mask)), length ) < 
0)
           D_PERROR( "DirectFB/FBDev: Could not unmap MMIO region "
                      "at %p (length %d)!\n", addr, length );
 }
Index: fbdev.h
===================================================================
RCS file: /cvs/directfb/DirectFB/systems/fbdev/fbdev.h,v
retrieving revision 1.1
diff -u -r1.1 fbdev.h
--- fbdev.h     29 Apr 2004 19:08:44 -0000      1.1
+++ fbdev.h     13 Aug 2004 05:01:48 -0000
@@ -63,6 +63,8 @@
      struct fb_cmap           temp_cmap;     /* scratch */
 
      FusionCall               fbdev_ioctl;   /* ioctl rpc */
+
+     unsigned long            page_mask;     /* PAGE_SIZE - 1 */
 } FBDevShared;
 
 typedef struct {

Reply via email to