[Intel-gfx] [PATCH 4/6] drm/i915: Abstract the gem calls from common code

Richard Purdie rpurdie at linux.intel.com
Wed May 13 16:03:03 CEST 2009


Add several function pointers so different gem implementations can be
used with the common intel_vdc core code and the common code doesn't
have knowledge of struct drm_i915_gem_object internals.

Signed-off-by: Richard Purdie <rpurdie at linux.intel.com>

Index: git/drivers/gpu/drm/i915/i915_gem.c
===================================================================
--- git.orig/drivers/gpu/drm/i915/i915_gem.c	2009-05-13 13:37:54.000000000 +0100
+++ git/drivers/gpu/drm/i915/i915_gem.c	2009-05-13 13:37:58.000000000 +0100
@@ -53,6 +53,8 @@
 				struct drm_i915_gem_pwrite *args,
 				struct drm_file *file_priv);
 
+struct vdc_gem_funcs i915_gem_funcs;
+
 int i915_gem_do_init(struct drm_device *dev, unsigned long start,
 		     unsigned long end)
 {
@@ -69,6 +71,8 @@
 
 	dev->gtt_total = (uint32_t) (end - start);
 
+	dev_priv->vdc.gem_funcs = &i915_gem_funcs;
+
 	return 0;
 }
 
@@ -4343,3 +4347,57 @@
 	drm_agp_chipset_flush(dev);
 	return 0;
 }
+
+uint32_t i915_gem_get_offset(struct drm_gem_object *obj)
+{
+	struct drm_i915_gem_object *obj_priv = obj->driver_private;
+
+	return obj_priv->gtt_offset;
+}
+
+uint32_t i915_gem_get_physaddr(struct drm_gem_object *obj)
+{
+	struct drm_i915_gem_object *obj_priv = obj->driver_private;
+
+	return obj_priv->phys_obj->handle->busaddr;
+}
+
+int i915_tiling_alignment(struct drm_gem_object *obj)
+{
+	struct drm_i915_gem_object *obj_priv = obj->driver_private;
+
+	switch (obj_priv->tiling_mode) {
+	case I915_TILING_NONE:
+		return 64 * 1024;
+	case I915_TILING_X:
+		/* pin() will align the object as required by fence */
+		return 0;
+	case I915_TILING_Y:
+		/* FIXME: Is this true? */
+		DRM_ERROR("Y tiled not allowed for scan out buffers\n");
+		return -EINVAL;
+	default:
+		BUG();
+		return -EINVAL;
+	}
+}
+
+int i915_is_tiled(struct drm_gem_object *obj)
+{
+	struct drm_i915_gem_object *obj_priv = obj->driver_private;
+
+	return (obj_priv->tiling_mode != I915_TILING_NONE);
+}
+
+struct vdc_gem_funcs i915_gem_funcs = {
+	.obj_set_to_gtt_domain = i915_gem_object_set_to_gtt_domain,
+	.obj_pin = i915_gem_object_pin,
+	.obj_unpin = i915_gem_object_unpin,
+	.attach_phys_object = i915_gem_attach_phys_object,
+	.detach_phys_object = i915_gem_detach_phys_object,
+	.get_offset = i915_gem_get_offset,
+	.get_physaddr = i915_gem_get_physaddr,
+	.tiling_align = i915_tiling_alignment,
+	.is_tiled = i915_is_tiled,
+};
+
Index: git/drivers/gpu/drm/i915/intel_fb.c
===================================================================
--- git.orig/drivers/gpu/drm/i915/intel_fb.c	2009-05-13 13:37:55.000000000 +0100
+++ git/drivers/gpu/drm/i915/intel_fb.c	2009-05-13 13:37:58.000000000 +0100
@@ -432,6 +432,7 @@
 			  uint32_t surface_height,
 			  struct intel_framebuffer **intel_fb_p)
 {
+	struct intel_vdc_private *vdc = dev->dev_private;
 	struct fb_info *info;
 	struct intelfb_par *par;
 	struct drm_framebuffer *fb;
@@ -461,14 +462,14 @@
 
 	mutex_lock(&dev->struct_mutex);
 
-	ret = i915_gem_object_pin(fbo, PAGE_SIZE);
+	ret = vdc->gem_funcs->obj_pin(fbo, PAGE_SIZE);
 	if (ret) {
 		DRM_ERROR("failed to pin fb: %d\n", ret);
 		goto out_unref;
 	}
 
 	/* Flush everything out, we'll be doing GTT only from now on */
-	i915_gem_object_set_to_gtt_domain(fbo, 1);
+	vdc->gem_funcs->obj_set_to_gtt_domain(fbo, 1);
 
 	ret = intel_framebuffer_create(dev, &mode_cmd, &fb, fbo);
 	if (ret) {
@@ -609,7 +610,7 @@
 	return 0;
 
 out_unpin:
-	i915_gem_object_unpin(fbo);
+	vdc->gem_funcs->obj_unpin(fbo);
 out_unref:
 	drm_gem_object_unreference(fbo);
 	mutex_unlock(&dev->struct_mutex);
Index: git/drivers/gpu/drm/i915/intel_display.c
===================================================================
--- git.orig/drivers/gpu/drm/i915/intel_display.c	2009-05-13 13:37:57.000000000 +0100
+++ git/drivers/gpu/drm/i915/intel_display.c	2009-05-13 13:37:58.000000000 +0100
@@ -652,7 +652,6 @@
 	struct drm_i915_master_private *master_priv;
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 	struct intel_framebuffer *intel_fb;
-	struct drm_i915_gem_object *obj_priv;
 	struct drm_gem_object *obj;
 	int pipe = intel_crtc->pipe;
 	unsigned long Start, Offset;
@@ -681,34 +680,21 @@
 
 	intel_fb = to_intel_framebuffer(crtc->fb);
 	obj = intel_fb->obj;
-	obj_priv = obj->driver_private;
 
-	switch (obj_priv->tiling_mode) {
-	case I915_TILING_NONE:
-		alignment = 64 * 1024;
-		break;
-	case I915_TILING_X:
-		/* pin() will align the object as required by fence */
-		alignment = 0;
-		break;
-	case I915_TILING_Y:
-		/* FIXME: Is this true? */
-		DRM_ERROR("Y tiled not allowed for scan out buffers\n");
-		return -EINVAL;
-	default:
-		BUG();
-	}
+	alignment = vdc->gem_funcs->tiling_align(obj);
+	if (alignment < 0)
+		return alignment;
 
 	mutex_lock(&dev->struct_mutex);
-	ret = i915_gem_object_pin(intel_fb->obj, alignment);
+	ret = vdc->gem_funcs->obj_pin(intel_fb->obj, alignment);
 	if (ret != 0) {
 		mutex_unlock(&dev->struct_mutex);
 		return ret;
 	}
 
-	ret = i915_gem_object_set_to_gtt_domain(intel_fb->obj, 1);
+	ret = vdc->gem_funcs->obj_set_to_gtt_domain(intel_fb->obj, 1);
 	if (ret != 0) {
-		i915_gem_object_unpin(intel_fb->obj);
+		vdc->gem_funcs->obj_unpin(intel_fb->obj);
 		mutex_unlock(&dev->struct_mutex);
 		return ret;
 	}
@@ -732,12 +718,12 @@
 		break;
 	default:
 		DRM_ERROR("Unknown color depth\n");
-		i915_gem_object_unpin(intel_fb->obj);
+		vdc->gem_funcs->obj_unpin(intel_fb->obj);
 		mutex_unlock(&dev->struct_mutex);
 		return -EINVAL;
 	}
 	if (IS_I965G(dev) || IS_MRST(dev)) {
-		if (obj_priv->tiling_mode != I915_TILING_NONE)
+		if (vdc->gem_funcs->is_tiled(obj))
 			dspcntr |= DISPPLANE_TILED;
 		else
 			dspcntr &= ~DISPPLANE_TILED;
@@ -745,7 +731,7 @@
 
 	I915_WRITE(dspcntr_reg, dspcntr);
 
-	Start = obj_priv->gtt_offset;
+	Start = vdc->gem_funcs->get_offset(obj);
 	Offset = y * crtc->fb->pitch + x * (crtc->fb->bits_per_pixel / 8);
 
 	DRM_DEBUG("Writing base %08lX %08lX %d %d\n", Start, Offset, x, y);
@@ -765,7 +751,7 @@
 
 	if (old_fb) {
 		intel_fb = to_intel_framebuffer(old_fb);
-		i915_gem_object_unpin(intel_fb->obj);
+		vdc->gem_funcs->obj_unpin(intel_fb->obj);
 	}
 	mutex_unlock(&dev->struct_mutex);
 
@@ -1360,7 +1346,6 @@
 	struct intel_vdc_private *vdc = dev->dev_private;
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 	struct drm_gem_object *bo;
-	struct drm_i915_gem_object *obj_priv;
 	int pipe = intel_crtc->pipe;
 	uint32_t control = (pipe == 0) ? CURACNTR : CURBCNTR;
 	uint32_t base = (pipe == 0) ? CURABASE : CURBBASE;
@@ -1390,8 +1375,6 @@
 	if (!bo)
 		return -ENOENT;
 
-	obj_priv = bo->driver_private;
-
 	if (bo->size < width * height * 4) {
 		DRM_ERROR("buffer is to small\n");
 		ret = -ENOMEM;
@@ -1401,19 +1384,19 @@
 	/* we only need to pin inside GTT if cursor is non-phy */
 	mutex_lock(&dev->struct_mutex);
 	if (!vdc->cursor_needs_physical) {
-		ret = i915_gem_object_pin(bo, PAGE_SIZE);
+		ret = vdc->gem_funcs->obj_pin(bo, PAGE_SIZE);
 		if (ret) {
 			DRM_ERROR("failed to pin cursor bo\n");
 			goto fail_locked;
 		}
-		addr = obj_priv->gtt_offset;
+		addr = vdc->gem_funcs->get_offset(bo);
 	} else {
-		ret = i915_gem_attach_phys_object(dev, bo, (pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1);
+		ret = vdc->gem_funcs->attach_phys_object(dev, bo, (pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1);
 		if (ret) {
 			DRM_ERROR("failed to attach phys object\n");
 			goto fail_locked;
 		}
-		addr = obj_priv->phys_obj->handle->busaddr;
+		addr = vdc->gem_funcs->get_physaddr(bo);
 	}
 
 	temp = 0;
@@ -1428,9 +1411,9 @@
 	if (intel_crtc->cursor_bo) {
 		if (vdc->cursor_needs_physical) {
 			if (intel_crtc->cursor_bo != bo)
-				i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
+				vdc->gem_funcs->detach_phys_object(dev, intel_crtc->cursor_bo);
 		} else
-			i915_gem_object_unpin(intel_crtc->cursor_bo);
+			vdc->gem_funcs->obj_unpin(intel_crtc->cursor_bo);
 		drm_gem_object_unreference(intel_crtc->cursor_bo);
 	}
 	mutex_unlock(&dev->struct_mutex);
Index: git/drivers/gpu/drm/i915/intel_vdc.h
===================================================================
--- git.orig/drivers/gpu/drm/i915/intel_vdc.h	2009-05-13 13:37:54.000000000 +0100
+++ git/drivers/gpu/drm/i915/intel_vdc.h	2009-05-13 13:38:48.000000000 +0100
@@ -28,11 +28,25 @@
 #ifndef _INTEL_VDC_H_
 #define _INTEL_VDC_H_
 
+struct vdc_gem_funcs {
+	int (*obj_set_to_gtt_domain) (struct drm_gem_object *obj, int write);
+	int (*obj_pin) (struct drm_gem_object *obj, uint32_t alignment);
+	void (*obj_unpin) (struct drm_gem_object *obj);
+	int (*attach_phys_object) (struct drm_device *dev, struct drm_gem_object *obj, int id);
+	void (*detach_phys_object) (struct drm_device *dev, struct drm_gem_object *obj);
+	uint32_t (*get_offset) (struct drm_gem_object *obj);
+	uint32_t (*get_physaddr) (struct drm_gem_object *obj);
+	int (*tiling_align)(struct drm_gem_object *obj);
+	int (*is_tiled)(struct drm_gem_object *obj);
+};
+
 struct intel_vdc_private {
 	void __iomem *regs;
 
 	bool cursor_needs_physical;
 
+	struct vdc_gem_funcs *gem_funcs;
+
 	/* LVDS info */
 	int backlight_duty_cycle;  /* restore backlight to this value */
 	bool panel_wants_dither;




More information about the Intel-gfx mailing list