[Intel-gfx] [RFC 2/2]libdrm: tell kernel which gem_bo is clean

Shaohua Li shaohua.li at intel.com
Thu Jun 11 08:45:32 CEST 2009


libdrm tells kernel which gem_bo is clean. When kernel tries to
truncate object's pages, it might unmap object's mapping. To avoid
the confusion, we unmap bo_gem first.

Index: drm/libdrm/intel/intel_bufmgr_gem.c
===================================================================
--- drm.orig/libdrm/intel/intel_bufmgr_gem.c
+++ drm/libdrm/intel/intel_bufmgr_gem.c
@@ -594,6 +594,23 @@ drm_intel_gem_bo_unreference_locked(drm_
 
 	    DRMLISTADDTAIL(&bo_gem->head, &bucket->head);
 	    bucket->num_entries++;
+{
+	struct drm_i915_gem_obj_clean clean;
+
+	/* with below ioctl, kernel might unmap the object where we don't know,
+	 * so let's unmap first */
+	if (bo_gem->mem_virtual) {
+		munmap (bo_gem->mem_virtual, bo_gem->bo.size);
+		bo_gem->mem_virtual = NULL;
+	}
+	if (bo_gem->gtt_virtual) {
+		munmap (bo_gem->gtt_virtual, bo_gem->bo.size);
+		bo_gem->gtt_virtual = NULL;
+	}
+
+	clean.handle=  bo_gem->gem_handle;
+	ioctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_OBJ_CLEAN, &clean);
+}
 	} else {
 	    drm_intel_gem_bo_free(bo);
 	}
Index: drm/shared-core/i915_drm.h
===================================================================
--- drm.orig/shared-core/i915_drm.h
+++ drm/shared-core/i915_drm.h
@@ -206,6 +206,7 @@ typedef struct drm_i915_sarea {
 #define DRM_I915_GEM_GET_APERTURE 0x23
 #define DRM_I915_GEM_MMAP_GTT	0x24
 #define DRM_I915_GET_PIPE_FROM_CRTC_ID	0x25
+#define DRM_I915_GEM_OBJ_CLEAN	0x26
 
 #define DRM_IOCTL_I915_INIT		DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
 #define DRM_IOCTL_I915_FLUSH		DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -244,6 +245,7 @@ typedef struct drm_i915_sarea {
 #define DRM_IOCTL_I915_GEM_GET_TILING	DRM_IOWR (DRM_COMMAND_BASE + DRM_I915_GEM_GET_TILING, struct drm_i915_gem_get_tiling)
 #define DRM_IOCTL_I915_GEM_GET_APERTURE	DRM_IOR  (DRM_COMMAND_BASE + DRM_I915_GEM_GET_APERTURE, struct drm_i915_gem_get_aperture)
 #define DRM_IOCTL_I915_GET_PIPE_FROM_CRTC_ID DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GET_PIPE_FROM_CRTC_ID, struct drm_i915_get_pipe_from_crtc_id)
+#define DRM_IOCTL_I915_GEM_OBJ_CLEAN DRM_IOW(DRM_COMMAND_BASE+DRM_I915_GEM_OBJ_CLEAN, struct drm_i915_gem_obj_clean)
 
 /* Asynchronous page flipping:
  */
@@ -779,4 +781,7 @@ struct drm_i915_get_pipe_from_crtc_id {
 	uint32_t pipe;
 };
 
+struct drm_i915_gem_obj_clean {
+	uint32_t handle;
+};
 #endif				/* _I915_DRM_H_ */



More information about the Intel-gfx mailing list