Don't ioremap the framebuffer area. The ioremapped area wasn't used by
authorEric Anholt <anholt@freebsd.org>
Tue, 16 Dec 2003 08:57:08 +0000 (08:57 +0000)
committerEric Anholt <anholt@freebsd.org>
Tue, 16 Dec 2003 08:57:08 +0000 (08:57 +0000)
    anything, and took up valuable KVA. While I'm in the area, clean up BSD
    MTRR stuff some more.
Suggested by: jonsmirl

22 files changed:
bsd-core/drmP.h
bsd-core/drm_bufs.c
bsd-core/drm_drv.c
bsd-core/drm_sysctl.c
bsd/drmP.h
bsd/drm_bufs.h
bsd/drm_drv.h
bsd/drm_sysctl.h
linux-core/drm_bufs.c
linux/drm_bufs.h
shared-core/mga_dma.c
shared-core/mga_drv.h
shared-core/r128_cce.c
shared-core/r128_drv.h
shared-core/radeon_cp.c
shared-core/radeon_drv.h
shared/mga_dma.c
shared/mga_drv.h
shared/r128_cce.c
shared/r128_drv.h
shared/radeon_cp.c
shared/radeon_drv.h

index 82a226a..d7e73f0 100644 (file)
@@ -267,7 +267,7 @@ typedef struct drm_agp_head {
        int                enabled;
        int                acquired;
        unsigned long      base;
-       int                agp_mtrr;
+       int                mtrr;
        int                cant_use_aperture;
        unsigned long      page_mask;
 } drm_agp_head_t;
@@ -287,7 +287,7 @@ typedef struct drm_local_map {
        drm_map_flags_t flags;   /* Flags                                   */
        void            *handle; /* User-space: "Handle" to pass to mmap    */
                                 /* Kernel-space: kernel-virtual address    */
-       int             mtrr;    /* MTRR slot used                          */
+       int             mtrr;    /* Boolean: MTRR used */
                                 /* Private data                            */
        bus_space_tag_t iot;
        bus_space_handle_t ioh;
index 15d4a3b..4bcd012 100644 (file)
@@ -87,7 +87,7 @@ int DRM(addmap)( DRM_IOCTL_ARGS )
        map->size = request.size;
        map->type = request.type;
        map->flags = request.flags;
-       map->mtrr   = -1;
+       map->mtrr = 0;
        map->handle = 0;
        
        /* Only allow shared memory to be removable since we only keep enough
@@ -104,28 +104,23 @@ int DRM(addmap)( DRM_IOCTL_ARGS )
                DRM(free)( map, sizeof(*map), DRM_MEM_MAPS );
                return DRM_ERR(EINVAL);
        }
+       if (map->offset + map->size < map->offset) {
+               DRM(free)(map, sizeof(*map), DRM_MEM_MAPS);
+               return DRM_ERR(EINVAL);
+       }
 
        switch ( map->type ) {
        case _DRM_REGISTERS:
+               DRM_IOREMAP(map, dev);
+               if (!(map->flags & _DRM_WRITE_COMBINING))
+                       break;
+               /* FALLTHROUGH */
        case _DRM_FRAME_BUFFER:
-               if ( map->offset + map->size < map->offset ) {
-                       DRM(free)( map, sizeof(*map), DRM_MEM_MAPS );
-                       return DRM_ERR(EINVAL);
-               }
 #if __REALLY_HAVE_MTRR
-               if ( map->type == _DRM_FRAME_BUFFER ||
-                    (map->flags & _DRM_WRITE_COMBINING) ) {
-                       int mtrr;
-                            
-                       mtrr = DRM(mtrr_add)(map->offset, map->size,
-                            DRM_MTRR_WC);
-                       if (mtrr == 0)
-                               map->mtrr = 1;
-               }
-#endif /* __REALLY_HAVE_MTRR */
-               DRM_IOREMAP(map, dev);
+               if (DRM(mtrr_add)(map->offset, map->size, DRM_MTRR_WC) == 0)
+                       map->mtrr = 1;
+#endif
                break;
-
        case _DRM_SHM:
                map->handle = (void *)DRM(alloc)(map->size, DRM_MEM_SAREA);
                DRM_DEBUG( "%lu %d %p\n",
@@ -152,7 +147,7 @@ int DRM(addmap)( DRM_IOCTL_ARGS )
 #if __REALLY_HAVE_AGP
        case _DRM_AGP:
                map->offset += dev->agp->base;
-               map->mtrr   = dev->agp->agp_mtrr; /* for getmap */
+               map->mtrr   = dev->agp->mtrr; /* for getmap */
                break;
 #endif
        case _DRM_SCATTER_GATHER:
@@ -231,12 +226,12 @@ int DRM(rmmap)( DRM_IOCTL_ARGS )
        case _DRM_REGISTERS:
        case _DRM_FRAME_BUFFER:
 #if __REALLY_HAVE_MTRR
-               if (map->mtrr >= 0) {
-                       int __unused mtrr;
+               if (map->mtrr) {
+                       int __unused retcode;
                        
-                       mtrr = DRM(mtrr_del)(map->offset, map->size,
+                       retcode = DRM(mtrr_del)(map->offset, map->size,
                            DRM_MTRR_WC);
-                       DRM_DEBUG("mtrr_del = %d\n", mtrr);
+                       DRM_DEBUG("mtrr_del = %d\n", retcode);
                }
 #endif
                DRM(ioremapfree)(map);
index bf1e2ac..7184e3d 100644 (file)
@@ -565,17 +565,18 @@ static int DRM(takedown)( drm_device_t *dev )
                        map = list->map;
                        switch ( map->type ) {
                        case _DRM_REGISTERS:
+                               DRM(ioremapfree)(map);
+                               /* FALLTHROUGH */
                        case _DRM_FRAME_BUFFER:
 #if __REALLY_HAVE_MTRR
-                               if ( map->mtrr >= 0 ) {
-                                       int __unused mtrr;
+                               if (map->mtrr) {
+                                       int __unused retcode;
 
-                                       mtrr = DRM(mtrr_del)(map->offset,
+                                       retcode = DRM(mtrr_del)(map->offset,
                                            map->size, DRM_MTRR_WC);
-                                       DRM_DEBUG("mtrr_del=%d\n", mtrr);
+                                       DRM_DEBUG("mtrr_del = %d", retcode);
                                }
 #endif
-                               DRM(ioremapfree)( map );
                                break;
                        case _DRM_SHM:
                                DRM(free)(map->handle,
@@ -679,12 +680,9 @@ static int DRM(init)( device_t nbdev )
 #endif /* __MUST_HAVE_AGP */
 #if __REALLY_HAVE_MTRR
        if (dev->agp) {
-               int retcode;
-               
-               retcode = DRM(mtrr_add)(dev->agp->info.ai_aperture_base,
-                   dev->agp->info.ai_aperture_size, DRM_MTRR_WC);
-               if (retcode == 0)
-                       dev->agp->agp_mtrr=1;
+               if (DRM(mtrr_add)(dev->agp->info.ai_aperture_base,
+                   dev->agp->info.ai_aperture_size, DRM_MTRR_WC) == 0)
+                       dev->agp->mtrr = 1;
        }
 #endif /* __REALLY_HAVE_MTRR */
 #endif /* __REALLY_HAVE_AGP */
@@ -742,12 +740,12 @@ static void DRM(cleanup)(drm_device_t *dev)
 #endif
 
 #if __REALLY_HAVE_AGP && __REALLY_HAVE_MTRR
-       if ( dev->agp && dev->agp->agp_mtrr >= 0) {
-               int __unused mtrr;
+       if (dev->agp && dev->agp->mtrr) {
+               int __unused retcode;
 
-               mtrr = DRM(mtrr_del)(dev->agp->info.ai_aperture_base,
+               retcode = DRM(mtrr_del)(dev->agp->info.ai_aperture_base,
                    dev->agp->info.ai_aperture_size, DRM_MTRR_WC);
-               DRM_DEBUG("mtrr_del=%d\n", mtrr);
+               DRM_DEBUG("mtrr_del = %d", retcode);
        }
 #endif
 
index 4bb603f..0897c35 100644 (file)
@@ -192,7 +192,7 @@ static int DRM(vm_info)DRM_SYSCTL_HANDLER_ARGS
                else
                        type = types[map->type];
 
-               if (map->mtrr <= 0)
+               if (!map->mtrr)
                        yesno = "no";
                else
                        yesno = "yes";
index 82a226a..d7e73f0 100644 (file)
@@ -267,7 +267,7 @@ typedef struct drm_agp_head {
        int                enabled;
        int                acquired;
        unsigned long      base;
-       int                agp_mtrr;
+       int                mtrr;
        int                cant_use_aperture;
        unsigned long      page_mask;
 } drm_agp_head_t;
@@ -287,7 +287,7 @@ typedef struct drm_local_map {
        drm_map_flags_t flags;   /* Flags                                   */
        void            *handle; /* User-space: "Handle" to pass to mmap    */
                                 /* Kernel-space: kernel-virtual address    */
-       int             mtrr;    /* MTRR slot used                          */
+       int             mtrr;    /* Boolean: MTRR used */
                                 /* Private data                            */
        bus_space_tag_t iot;
        bus_space_handle_t ioh;
index 15d4a3b..4bcd012 100644 (file)
@@ -87,7 +87,7 @@ int DRM(addmap)( DRM_IOCTL_ARGS )
        map->size = request.size;
        map->type = request.type;
        map->flags = request.flags;
-       map->mtrr   = -1;
+       map->mtrr = 0;
        map->handle = 0;
        
        /* Only allow shared memory to be removable since we only keep enough
@@ -104,28 +104,23 @@ int DRM(addmap)( DRM_IOCTL_ARGS )
                DRM(free)( map, sizeof(*map), DRM_MEM_MAPS );
                return DRM_ERR(EINVAL);
        }
+       if (map->offset + map->size < map->offset) {
+               DRM(free)(map, sizeof(*map), DRM_MEM_MAPS);
+               return DRM_ERR(EINVAL);
+       }
 
        switch ( map->type ) {
        case _DRM_REGISTERS:
+               DRM_IOREMAP(map, dev);
+               if (!(map->flags & _DRM_WRITE_COMBINING))
+                       break;
+               /* FALLTHROUGH */
        case _DRM_FRAME_BUFFER:
-               if ( map->offset + map->size < map->offset ) {
-                       DRM(free)( map, sizeof(*map), DRM_MEM_MAPS );
-                       return DRM_ERR(EINVAL);
-               }
 #if __REALLY_HAVE_MTRR
-               if ( map->type == _DRM_FRAME_BUFFER ||
-                    (map->flags & _DRM_WRITE_COMBINING) ) {
-                       int mtrr;
-                            
-                       mtrr = DRM(mtrr_add)(map->offset, map->size,
-                            DRM_MTRR_WC);
-                       if (mtrr == 0)
-                               map->mtrr = 1;
-               }
-#endif /* __REALLY_HAVE_MTRR */
-               DRM_IOREMAP(map, dev);
+               if (DRM(mtrr_add)(map->offset, map->size, DRM_MTRR_WC) == 0)
+                       map->mtrr = 1;
+#endif
                break;
-
        case _DRM_SHM:
                map->handle = (void *)DRM(alloc)(map->size, DRM_MEM_SAREA);
                DRM_DEBUG( "%lu %d %p\n",
@@ -152,7 +147,7 @@ int DRM(addmap)( DRM_IOCTL_ARGS )
 #if __REALLY_HAVE_AGP
        case _DRM_AGP:
                map->offset += dev->agp->base;
-               map->mtrr   = dev->agp->agp_mtrr; /* for getmap */
+               map->mtrr   = dev->agp->mtrr; /* for getmap */
                break;
 #endif
        case _DRM_SCATTER_GATHER:
@@ -231,12 +226,12 @@ int DRM(rmmap)( DRM_IOCTL_ARGS )
        case _DRM_REGISTERS:
        case _DRM_FRAME_BUFFER:
 #if __REALLY_HAVE_MTRR
-               if (map->mtrr >= 0) {
-                       int __unused mtrr;
+               if (map->mtrr) {
+                       int __unused retcode;
                        
-                       mtrr = DRM(mtrr_del)(map->offset, map->size,
+                       retcode = DRM(mtrr_del)(map->offset, map->size,
                            DRM_MTRR_WC);
-                       DRM_DEBUG("mtrr_del = %d\n", mtrr);
+                       DRM_DEBUG("mtrr_del = %d\n", retcode);
                }
 #endif
                DRM(ioremapfree)(map);
index bf1e2ac..7184e3d 100644 (file)
@@ -565,17 +565,18 @@ static int DRM(takedown)( drm_device_t *dev )
                        map = list->map;
                        switch ( map->type ) {
                        case _DRM_REGISTERS:
+                               DRM(ioremapfree)(map);
+                               /* FALLTHROUGH */
                        case _DRM_FRAME_BUFFER:
 #if __REALLY_HAVE_MTRR
-                               if ( map->mtrr >= 0 ) {
-                                       int __unused mtrr;
+                               if (map->mtrr) {
+                                       int __unused retcode;
 
-                                       mtrr = DRM(mtrr_del)(map->offset,
+                                       retcode = DRM(mtrr_del)(map->offset,
                                            map->size, DRM_MTRR_WC);
-                                       DRM_DEBUG("mtrr_del=%d\n", mtrr);
+                                       DRM_DEBUG("mtrr_del = %d", retcode);
                                }
 #endif
-                               DRM(ioremapfree)( map );
                                break;
                        case _DRM_SHM:
                                DRM(free)(map->handle,
@@ -679,12 +680,9 @@ static int DRM(init)( device_t nbdev )
 #endif /* __MUST_HAVE_AGP */
 #if __REALLY_HAVE_MTRR
        if (dev->agp) {
-               int retcode;
-               
-               retcode = DRM(mtrr_add)(dev->agp->info.ai_aperture_base,
-                   dev->agp->info.ai_aperture_size, DRM_MTRR_WC);
-               if (retcode == 0)
-                       dev->agp->agp_mtrr=1;
+               if (DRM(mtrr_add)(dev->agp->info.ai_aperture_base,
+                   dev->agp->info.ai_aperture_size, DRM_MTRR_WC) == 0)
+                       dev->agp->mtrr = 1;
        }
 #endif /* __REALLY_HAVE_MTRR */
 #endif /* __REALLY_HAVE_AGP */
@@ -742,12 +740,12 @@ static void DRM(cleanup)(drm_device_t *dev)
 #endif
 
 #if __REALLY_HAVE_AGP && __REALLY_HAVE_MTRR
-       if ( dev->agp && dev->agp->agp_mtrr >= 0) {
-               int __unused mtrr;
+       if (dev->agp && dev->agp->mtrr) {
+               int __unused retcode;
 
-               mtrr = DRM(mtrr_del)(dev->agp->info.ai_aperture_base,
+               retcode = DRM(mtrr_del)(dev->agp->info.ai_aperture_base,
                    dev->agp->info.ai_aperture_size, DRM_MTRR_WC);
-               DRM_DEBUG("mtrr_del=%d\n", mtrr);
+               DRM_DEBUG("mtrr_del = %d", retcode);
        }
 #endif
 
index 4bb603f..0897c35 100644 (file)
@@ -192,7 +192,7 @@ static int DRM(vm_info)DRM_SYSCTL_HANDLER_ARGS
                else
                        type = types[map->type];
 
-               if (map->mtrr <= 0)
+               if (!map->mtrr)
                        yesno = "no";
                else
                        yesno = "yes";
index e30e6de..577a1c9 100644 (file)
@@ -148,7 +148,9 @@ int DRM(addmap)( struct inode *inode, struct file *filp,
                                              MTRR_TYPE_WRCOMB, 1 );
                }
 #endif
-               map->handle = DRM(ioremap)( map->offset, map->size, dev );
+               if (map->type == _DRM_REGISTERS)
+                       map->handle = DRM(ioremap)( map->offset, map->size,
+                                                   dev );
                break;
 
        case _DRM_SHM:
index e30e6de..577a1c9 100644 (file)
@@ -148,7 +148,9 @@ int DRM(addmap)( struct inode *inode, struct file *filp,
                                              MTRR_TYPE_WRCOMB, 1 );
                }
 #endif
-               map->handle = DRM(ioremap)( map->offset, map->size, dev );
+               if (map->type == _DRM_REGISTERS)
+                       map->handle = DRM(ioremap)( map->offset, map->size,
+                                                   dev );
                break;
 
        case _DRM_SHM:
index 19bc9e3..5e5c407 100644 (file)
@@ -500,14 +500,6 @@ static int mga_do_init_dma( drm_device_t *dev, drm_mga_init_t *init )
                return DRM_ERR(EINVAL);
        }
 
-       DRM_FIND_MAP( dev_priv->fb, init->fb_offset );
-       if(!dev_priv->fb) {
-               DRM_ERROR( "failed to find framebuffer!\n" );
-               /* Assign dev_private so we can do cleanup. */
-               dev->dev_private = (void *)dev_priv;
-               mga_do_cleanup_dma( dev );
-               return DRM_ERR(EINVAL);
-       }
        DRM_FIND_MAP( dev_priv->mmio, init->mmio_offset );
        if(!dev_priv->mmio) {
                DRM_ERROR( "failed to find mmio region!\n" );
index 9396ae9..6584716 100644 (file)
@@ -91,7 +91,6 @@ typedef struct drm_mga_private {
        unsigned int texture_size;
 
        drm_local_map_t *sarea;
-       drm_local_map_t *fb;
        drm_local_map_t *mmio;
        drm_local_map_t *status;
        drm_local_map_t *warp;
index abf05c1..bf4b4d9 100644 (file)
@@ -467,13 +467,6 @@ static int r128_do_init_cce( drm_device_t *dev, drm_r128_init_t *init )
                return DRM_ERR(EINVAL);
        }
 
-       DRM_FIND_MAP( dev_priv->fb, init->fb_offset );
-       if(!dev_priv->fb) {
-               DRM_ERROR("could not find framebuffer!\n");
-               dev->dev_private = (void *)dev_priv;
-               r128_do_cleanup_cce( dev );
-               return DRM_ERR(EINVAL);
-       }
        DRM_FIND_MAP( dev_priv->mmio, init->mmio_offset );
        if(!dev_priv->mmio) {
                DRM_ERROR("could not find mmio region!\n");
index 10569f4..9df32e5 100644 (file)
@@ -97,7 +97,6 @@ typedef struct drm_r128_private {
        u32 span_pitch_offset_c;
 
        drm_local_map_t *sarea;
-       drm_local_map_t *fb;
        drm_local_map_t *mmio;
        drm_local_map_t *cce_ring;
        drm_local_map_t *ring_rptr;
index 4cacef5..e145c78 100644 (file)
@@ -1118,13 +1118,6 @@ static int radeon_do_init_cp( drm_device_t *dev, drm_radeon_init_t *init )
                return DRM_ERR(EINVAL);
        }
 
-       DRM_FIND_MAP( dev_priv->fb, init->fb_offset );
-       if(!dev_priv->fb) {
-               DRM_ERROR("could not find framebuffer!\n");
-               dev->dev_private = (void *)dev_priv;
-               radeon_do_cleanup_cp(dev);
-               return DRM_ERR(EINVAL);
-       }
        DRM_FIND_MAP( dev_priv->mmio, init->mmio_offset );
        if(!dev_priv->mmio) {
                DRM_ERROR("could not find mmio region!\n");
index 1569caa..afa516e 100644 (file)
@@ -135,7 +135,6 @@ typedef struct drm_radeon_private {
        unsigned long gart_textures_offset;
 
        drm_local_map_t *sarea;
-       drm_local_map_t *fb;
        drm_local_map_t *mmio;
        drm_local_map_t *cp_ring;
        drm_local_map_t *ring_rptr;
index 19bc9e3..5e5c407 100644 (file)
@@ -500,14 +500,6 @@ static int mga_do_init_dma( drm_device_t *dev, drm_mga_init_t *init )
                return DRM_ERR(EINVAL);
        }
 
-       DRM_FIND_MAP( dev_priv->fb, init->fb_offset );
-       if(!dev_priv->fb) {
-               DRM_ERROR( "failed to find framebuffer!\n" );
-               /* Assign dev_private so we can do cleanup. */
-               dev->dev_private = (void *)dev_priv;
-               mga_do_cleanup_dma( dev );
-               return DRM_ERR(EINVAL);
-       }
        DRM_FIND_MAP( dev_priv->mmio, init->mmio_offset );
        if(!dev_priv->mmio) {
                DRM_ERROR( "failed to find mmio region!\n" );
index 9396ae9..6584716 100644 (file)
@@ -91,7 +91,6 @@ typedef struct drm_mga_private {
        unsigned int texture_size;
 
        drm_local_map_t *sarea;
-       drm_local_map_t *fb;
        drm_local_map_t *mmio;
        drm_local_map_t *status;
        drm_local_map_t *warp;
index abf05c1..bf4b4d9 100644 (file)
@@ -467,13 +467,6 @@ static int r128_do_init_cce( drm_device_t *dev, drm_r128_init_t *init )
                return DRM_ERR(EINVAL);
        }
 
-       DRM_FIND_MAP( dev_priv->fb, init->fb_offset );
-       if(!dev_priv->fb) {
-               DRM_ERROR("could not find framebuffer!\n");
-               dev->dev_private = (void *)dev_priv;
-               r128_do_cleanup_cce( dev );
-               return DRM_ERR(EINVAL);
-       }
        DRM_FIND_MAP( dev_priv->mmio, init->mmio_offset );
        if(!dev_priv->mmio) {
                DRM_ERROR("could not find mmio region!\n");
index 10569f4..9df32e5 100644 (file)
@@ -97,7 +97,6 @@ typedef struct drm_r128_private {
        u32 span_pitch_offset_c;
 
        drm_local_map_t *sarea;
-       drm_local_map_t *fb;
        drm_local_map_t *mmio;
        drm_local_map_t *cce_ring;
        drm_local_map_t *ring_rptr;
index 4cacef5..e145c78 100644 (file)
@@ -1118,13 +1118,6 @@ static int radeon_do_init_cp( drm_device_t *dev, drm_radeon_init_t *init )
                return DRM_ERR(EINVAL);
        }
 
-       DRM_FIND_MAP( dev_priv->fb, init->fb_offset );
-       if(!dev_priv->fb) {
-               DRM_ERROR("could not find framebuffer!\n");
-               dev->dev_private = (void *)dev_priv;
-               radeon_do_cleanup_cp(dev);
-               return DRM_ERR(EINVAL);
-       }
        DRM_FIND_MAP( dev_priv->mmio, init->mmio_offset );
        if(!dev_priv->mmio) {
                DRM_ERROR("could not find mmio region!\n");
index 1569caa..afa516e 100644 (file)
@@ -135,7 +135,6 @@ typedef struct drm_radeon_private {
        unsigned long gart_textures_offset;
 
        drm_local_map_t *sarea;
-       drm_local_map_t *fb;
        drm_local_map_t *mmio;
        drm_local_map_t *cp_ring;
        drm_local_map_t *ring_rptr;