Skip to contentSkip to conversation

drm driver for VED in Intel GPU

RFC PATCH In review Sean V Kelley 2 participants 10 messages Jan 8, 2015 – Jan 15, 2015

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v4 cover drm driver for VED in Intel GPU

drm/ipvr is a new GEM driver for VED (PowerVR's VPU integrated in Intel GPU), which extends video capability.
A new Kconfig added for building ipvr driver:

CONFIG_DRM_IPVR: Build option for ipvr module

The driver name "ipvr" means the PowerVR's core wrapped by Intel. The PowerVR VPUs are also integrated by non-i915 platforms such as GMA500, so we keep ipvr driver and i915 driver separated and independent to each other. To achieve this we do the minimum change in i915: i915_ved.c added for setting up the bridge between VED and i915, kerneldoc also updated.

User mode drm helper "libdrm_ipvr.so" and simple ioctl/execute test is included.

one test script "drv_module_reload" in i-g-t also updated to support ipvr loading and unloading. Due to restriction in Linux platform device model, we have to manually unload ipvr before unloading i915.

Yao Cheng (4):
[1/4] drm/i915: add i915_ved.c to setup bridge for VED [2/4] drm/ipvr: drm driver for VED
[3/4] libdrm/ipvr: user mode helper for ipvr drm driver [4/4] i-g-t: tests/drv_module_reload: add ipvr support

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#1 lore raw

RFC PATCH v4 1/4 drm/i915: add i915_ved.c to setup bridge for VED

From: Yao Cheng <[email protected]>

Setup minimum required resources during i915_driver_load:
1. Create a platform device to share MMIO/IRQ resources
2. Make the platform device child of i915 device for runtime PM.
3. Create IRQ chip to forward the VED irqs.
VED driver (a standalone drm driver) probes the VED device and creates a new dri card on install.
Currently only supports VED on valleyview.
Kerneldoc is updated for i915_ved.c.

v2:
take Daniel & Jani's comments
- extract change to new file i915_ved.c
- add kerneldoc
- change 'ipvr-ved' to 'ipvr-vlv-ved' for extensibility
- unregister platdev before irq_free_desc
- add WARN_ON(!intel_irqs_enabled) in irq init code
- remove unnecessary trace point
- remove unnecessary BUG_ON

v3:
take Ville's comments and VED PRIME support
- add HAS_VED() check
- add ved struct to make code neat
- no need to check platform in vlv_irq_handler
- i915_reg.h update
- no need to kmalloc for small amount of resource
- remove unnecessary REG resource
- follow vlv_display_irqs_install() to implement VED mask/unmask
- workaround nommu_map_sg issue by set dma_mask to support VED PRIME.

v4:
take Bob's comments
- add more detail on the use-after-free issue description
- mask VED irq before removing the child device

---
 Documentation/DocBook/drm.tmpl  |   5 +
 drivers/gpu/drm/i915/Makefile   |   3 +
 drivers/gpu/drm/i915/i915_dma.c |  11 ++
 drivers/gpu/drm/i915/i915_drv.h |  12 ++
 drivers/gpu/drm/i915/i915_irq.c |   2 +
 drivers/gpu/drm/i915/i915_reg.h |   4 +
 drivers/gpu/drm/i915/i915_ved.c | 270 ++++++++++++++++++++++++++++++++++++++++
 7 files changed, 307 insertions(+)
 create mode 100644 drivers/gpu/drm/i915/i915_ved.c
Documentation/DocBook/drm.tmpl +5 -0
index 56e2a9b..9db989c 100644
@@ -3867,6 +3867,11 @@ int num_ioctls;</synopsis>
 !Fdrivers/gpu/drm/i915/i915_irq.c intel_runtime_pm_disable_interrupts
 !Fdrivers/gpu/drm/i915/i915_irq.c intel_runtime_pm_enable_interrupts
       </sect2>
+      <sect2>
+        <title>VED video core integration</title>
+!Pdrivers/gpu/drm/i915/i915_ved.c VED video core integration
+!Idrivers/gpu/drm/i915/i915_ved.c
+      </sect2>
     </sect1>
     <sect1>
       <title>Display Hardware Handling</title>
drivers/gpu/drm/i915/Makefile +3 -0
index e4083e4..7d0bbfa 100644
@@ -84,6 +84,9 @@ i915-y += dvo_ch7017.o \
 i915-y += i915_dma.o \
 	  i915_ums.o
 
+# VED for VLV
+i915-y += i915_ved.o
+
 obj-$(CONFIG_DRM_I915)  += i915.o
 
 CFLAGS_i915_trace_points.o := -I$(src)
drivers/gpu/drm/i915/i915_dma.c +11 -0
index 887d88f..cd96618 100644
@@ -828,6 +828,13 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
 	if (IS_GEN5(dev))
 		intel_gpu_ips_init(dev_priv);
 
+	if (HAS_VED(dev)) {
+		ret = vlv_setup_ved(dev);
+		if (ret < 0) {
+			DRM_ERROR("failed to setup VED bridge: %d\n", ret);
+		}
+	}
+
 	intel_runtime_pm_enable(dev_priv);
 
 	return 0;
@@ -870,6 +877,10 @@ int i915_driver_unload(struct drm_device *dev)
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	int ret;
 
+	if (HAS_VED(dev)) {
+		vlv_teardown_ved(dev);
+	}
+
 	ret = i915_gem_suspend(dev);
 	if (ret) {
 		DRM_ERROR("failed to idle hardware: %d\n", ret);
drivers/gpu/drm/i915/i915_drv.h +12 -0
index 502a01b..aa39d47 100644
@@ -1773,6 +1773,12 @@ struct drm_i915_private {
 
 	uint32_t bios_vgacntr;
 
+	/* necessary resource sharing with ved driver. */
+	struct {
+		struct platform_device *platdev;
+		int	irq;
+	} ved;
+
 	/* Abstract the submission mechanism (legacy ringbuffer or execlists) away */
 	struct {
 		int (*do_execbuf)(struct drm_device *dev, struct drm_file *file,
@@ -2305,6 +2311,7 @@ struct drm_i915_cmd_table {
 				 IS_BROADWELL(dev) || IS_VALLEYVIEW(dev))
 #define HAS_RC6(dev)		(INTEL_INFO(dev)->gen >= 6)
 #define HAS_RC6p(dev)		(INTEL_INFO(dev)->gen == 6 || IS_IVYBRIDGE(dev))
+#define HAS_VED(dev)		(INTEL_INFO(dev)->is_valleyview && IS_GEN7(dev))
 
 #define INTEL_PCH_DEVICE_ID_MASK		0xff00
 #define INTEL_PCH_IBX_DEVICE_ID_TYPE		0x3b00
@@ -2894,6 +2901,11 @@ void i915_restore_display_reg(struct drm_device *dev);
 void i915_setup_sysfs(struct drm_device *dev_priv);
 void i915_teardown_sysfs(struct drm_device *dev_priv);
 
+/* i915_ved.c */
+int vlv_setup_ved(struct drm_device *dev);
+void vlv_teardown_ved(struct drm_device *dev);
+void vlv_ved_irq_handler(struct drm_device *dev);
+
 /* intel_i2c.c */
 extern int intel_setup_gmbus(struct drm_device *dev);
 extern void intel_teardown_gmbus(struct drm_device *dev);
drivers/gpu/drm/i915/i915_irq.c +2 -0
index 7913a72..9837a71 100644
@@ -1892,6 +1892,8 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
 			snb_gt_irq_handler(dev, dev_priv, gt_iir);
 		if (pm_iir)
 			gen6_rps_irq_handler(dev_priv, pm_iir);
+		if (iir & VLV_VED_BLOCK_INTERRUPT)
+			vlv_ved_irq_handler(dev);
 		/* Call regardless, as some status bits might not be
 		 * signalled in iir */
 		valleyview_pipestat_irq_handler(dev, iir);
drivers/gpu/drm/i915/i915_reg.h +4 -0
index 869e5ae..79d8764 100644
@@ -1301,6 +1301,9 @@ enum punit_power_well {
 #define VLV_DISPLAY_BASE 0x180000
 #define VLV_MIPI_BASE VLV_DISPLAY_BASE
 
+#define VLV_VED_BASE 0x170000
+#define VLV_VED_SIZE 0x010000
+
 #define VLV_GU_CTL0	(VLV_DISPLAY_BASE + 0x2030)
 #define VLV_GU_CTL1	(VLV_DISPLAY_BASE + 0x2034)
 #define SCPD0		0x0209c /* 915+ only */
@@ -1494,6 +1497,7 @@ enum punit_power_well {
 #define ILK_BSD_USER_INTERRUPT				(1<<5)
 
 #define I915_PM_INTERRUPT				(1<<31)
+#define VLV_VED_BLOCK_INTERRUPT			(1<<23)
 #define I915_ISP_INTERRUPT				(1<<22)
 #define I915_LPE_PIPE_B_INTERRUPT			(1<<21)
 #define I915_LPE_PIPE_A_INTERRUPT			(1<<20)
drivers/gpu/drm/i915/i915_ved.c new file +270 -0

270 lines not on this page · raw message

Signature · 6 lines
2.1.0

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

RE: [RFC PATCH V4 1/4] drm/i915: add i915_ved.c to setup bridge for VED

+ commenters of v1~v3

Thanks,
Yao

Quoted 500 lines

-----Original Message-----
From: Sean V Kelley [mailto:[email protected]]
Sent: Thursday, January 8, 2015 8:35
To: [email protected]
Cc: [email protected]; Cheng, Yao; Sean V Kelley
Subject: [RFC PATCH V4 1/4] drm/i915: add i915_ved.c to setup bridge for VED

From: Yao Cheng <[email protected]>

Setup minimum required resources during i915_driver_load:
1. Create a platform device to share MMIO/IRQ resources 2. Make the platform device child of i915 device for runtime PM.
3. Create IRQ chip to forward the VED irqs.
VED driver (a standalone drm driver) probes the VED device and creates a new dri card on install.
Currently only supports VED on valleyview.
Kerneldoc is updated for i915_ved.c.

v2:
take Daniel & Jani's comments
- extract change to new file i915_ved.c
- add kerneldoc
- change 'ipvr-ved' to 'ipvr-vlv-ved' for extensibility
- unregister platdev before irq_free_desc
- add WARN_ON(!intel_irqs_enabled) in irq init code
- remove unnecessary trace point
- remove unnecessary BUG_ON

v3:
take Ville's comments and VED PRIME support
- add HAS_VED() check
- add ved struct to make code neat
- no need to check platform in vlv_irq_handler
- i915_reg.h update
- no need to kmalloc for small amount of resource
- remove unnecessary REG resource
- follow vlv_display_irqs_install() to implement VED mask/unmask
- workaround nommu_map_sg issue by set dma_mask to support
VED PRIME.

v4:
take Bob's comments
- add more detail on the use-after-free issue description
- mask VED irq before removing the child device

---
 Documentation/DocBook/drm.tmpl  |   5 +
 drivers/gpu/drm/i915/Makefile   |   3 +
 drivers/gpu/drm/i915/i915_dma.c |  11 ++  drivers/gpu/drm/i915/i915_drv.h
|  12 ++
 drivers/gpu/drm/i915/i915_irq.c |   2 +
 drivers/gpu/drm/i915/i915_reg.h |   4 +
 drivers/gpu/drm/i915/i915_ved.c | 270
++++++++++++++++++++++++++++++++++++++++
 7 files changed, 307 insertions(+)
 create mode 100644 drivers/gpu/drm/i915/i915_ved.c
(quoted diff) +0 -0

b/Documentation/DocBook/drm.tmpl index 56e2a9b..9db989c 100644

Documentation/DocBook/drm.tmpl +0 -0
@@ -3867,6 +3867,11 @@ int

num_ioctls;</synopsis> !Fdrivers/gpu/drm/i915/i915_irq.c intel_runtime_pm_disable_interrupts
!Fdrivers/gpu/drm/i915/i915_irq.c intel_runtime_pm_enable_interrupts

       </sect2>
Documentation/DocBook/drm.tmpl +5 -0
+      <sect2>
+        <title>VED video core integration</title>
+!Pdrivers/gpu/drm/i915/i915_ved.c VED video core integration
+!Idrivers/gpu/drm/i915/i915_ved.c
+      </sect2>
     </sect1>
     <sect1>
       <title>Display Hardware Handling</title> diff --git

a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile index e4083e4..7d0bbfa 100644

drivers/gpu/drm/i915/Makefile +3 -0
@@ -84,6 +84,9 @@ i915-y += dvo_ch7017.o \  i915-y += i915_dma.o \
 	  i915_ums.o
 
+# VED for VLV
+i915-y += i915_ved.o
+
 obj-$(CONFIG_DRM_I915)  += i915.o
 
 CFLAGS_i915_trace_points.o := -I$(src)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_dma.c index 887d88f..cd96618 100644

drivers/gpu/drm/i915/i915_dma.c +7 -0
@@ -828,6 +828,13 @@ int i915_driver_load(struct drm_device *dev,
 unsigned long flags)
 	if (IS_GEN5(dev))
 		intel_gpu_ips_init(dev_priv);
 
+	if (HAS_VED(dev)) {
+		ret = vlv_setup_ved(dev);
+		if (ret < 0) {
+			DRM_ERROR("failed to setup VED bridge: %d\n", ret);
+		}
+	}
+
 	intel_runtime_pm_enable(dev_priv);
 
drivers/gpu/drm/i915/i915_dma.c +4 -0
 	return 0;
@@ -870,6 +877,10 @@ int i915_driver_unload(struct drm_device *dev)
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	int ret;
 
+	if (HAS_VED(dev)) {
+		vlv_teardown_ved(dev);
+	}
+
 	ret = i915_gem_suspend(dev);
 	if (ret) {
 		DRM_ERROR("failed to idle hardware: %d\n", ret); diff --git

a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 502a01b..aa39d47 100644

drivers/gpu/drm/i915/i915_drv.h +6 -0
@@ -1773,6 +1773,12 @@ struct drm_i915_private {
 
 	uint32_t bios_vgacntr;
 
+	/* necessary resource sharing with ved driver. */
+	struct {
+		struct platform_device *platdev;
+		int	irq;
+	} ved;
+
 	/* Abstract the submission mechanism (legacy ringbuffer or execlists)

away */

drivers/gpu/drm/i915/i915_drv.h +0 -0
 	struct {
 		int (*do_execbuf)(struct drm_device *dev, struct drm_file

*file, @@ -2305,6 +2311,7 @@ struct drm_i915_cmd_table {
IS_BROADWELL(dev) ||
IS_VALLEYVIEW(dev))
#define HAS_RC6(dev) (INTEL_INFO(dev)->gen >= 6)
#define HAS_RC6p(dev) (INTEL_INFO(dev)->gen == 6 ||
IS_IVYBRIDGE(dev))
+#define HAS_VED(dev) (INTEL_INFO(dev)->is_valleyview &&
IS_GEN7(dev))

#define INTEL_PCH_DEVICE_ID_MASK 0xff00
#define INTEL_PCH_IBX_DEVICE_ID_TYPE 0x3b00

drivers/gpu/drm/i915/i915_drv.h +4 -0
@@ -2894,6 +2901,11 @@ void i915_restore_display_reg(struct drm_device
 *dev);  void i915_setup_sysfs(struct drm_device *dev_priv);  void
 i915_teardown_sysfs(struct drm_device *dev_priv);
 
+/* i915_ved.c */
+int vlv_setup_ved(struct drm_device *dev); void vlv_teardown_ved(struct
+drm_device *dev); void vlv_ved_irq_handler(struct drm_device *dev);
+
 /* intel_i2c.c */
 extern int intel_setup_gmbus(struct drm_device *dev);  extern void

intel_teardown_gmbus(struct drm_device *dev); diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c index 7913a72..9837a71 100644

drivers/gpu/drm/i915/i915_irq.c +2 -0
@@ -1892,6 +1892,8 @@ static irqreturn_t valleyview_irq_handler(int irq,
 void *arg)
 			snb_gt_irq_handler(dev, dev_priv, gt_iir);
 		if (pm_iir)
 			gen6_rps_irq_handler(dev_priv, pm_iir);
+		if (iir & VLV_VED_BLOCK_INTERRUPT)
+			vlv_ved_irq_handler(dev);
 		/* Call regardless, as some status bits might not be
 		 * signalled in iir */

valleyview_pipestat_irq_handler(dev, iir); diff --git
a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h index 869e5ae..79d8764 100644

drivers/gpu/drm/i915/i915_reg.h +0 -0
@@ -1301,6 +1301,9 @@ enum punit_power_well {  #define

VLV_DISPLAY_BASE 0x180000 #define VLV_MIPI_BASE VLV_DISPLAY_BASE

drivers/gpu/drm/i915/i915_reg.h +4 -0
+#define VLV_VED_BASE 0x170000
+#define VLV_VED_SIZE 0x010000
+
 #define VLV_GU_CTL0	(VLV_DISPLAY_BASE + 0x2030)
 #define VLV_GU_CTL1	(VLV_DISPLAY_BASE + 0x2034)
 #define SCPD0		0x0209c /* 915+ only */
@@ -1494,6 +1497,7 @@ enum punit_power_well {
 #define ILK_BSD_USER_INTERRUPT				(1<<5)
 
 #define I915_PM_INTERRUPT				(1<<31)
+#define VLV_VED_BLOCK_INTERRUPT			(1<<23)
 #define I915_ISP_INTERRUPT				(1<<22)
 #define I915_LPE_PIPE_B_INTERRUPT			(1<<21)
 #define I915_LPE_PIPE_A_INTERRUPT			(1<<20)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_ved.c new file mode 100644 index 0000000..f8ea7be

drivers/gpu/drm/i915/i915_ved.c new file +26 -0
@@ -0,0 +1,270 @@
+/*
+ * Copyright © 2014 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person
+obtaining a
+ * copy of this software and associated documentation files (the
+"Software"),
+ * to deal in the Software without restriction, including without
+limitation
+ * the rights to use, copy, modify, merge, publish, distribute,
+sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom
+the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+next
+ * paragraph) shall be included in all copies or substantial portions
+of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO

EVENT
+SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR

drivers/gpu/drm/i915/i915_ved.c new file +4 -0
+OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR

OTHER

drivers/gpu/drm/i915/i915_ved.c new file +70 -0
+DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Yao Cheng <[email protected]>
+ *
+ */
+
+#include "i915_drv.h"
+
+/**
+ * DOC: VED video core integration
+ *
+ * Motivation:
+ * Some platforms (e.g. valleyview) integrates a VED inside GPU to
+extend the
+ * video decoding capability.
+ * The VED is driven by the standalone drm driver "ipvr" which covers
+PowerVR
+ * VPUs. Since the PowerVR VPUs are also integrated by non-i915
+platforms such
+ * as GMA500, we'd like to keep ipvr driver and i915 driver separated
+and
+ * independent to each other. To achieve this we do the minimum work in
+i915
+ * to setup a bridge between ipvr and i915:
+ * 1. Create a platform device to share MMIO/IRQ resources
+ * 2. Make the platform device child of i915 device for runtime PM.
+ * 3. Create IRQ chip to forward the VED irqs.
+ * ipvr driver probes the VED device and creates a new dri card on install.
+ *
+ * Threats:
+ * Due to the restriction in Linux platform device model, user need
+manually
+ * uninstall ipvr driver before uninstalling i915 module, otherwise we
+might
+ * run into use-after-free issues after i915 removes the platform
+device: even
+ * though ipvr driver is released, the modules is still in "installed" status.
+ *
+ * Implementation:
+ * The MMIO/REG platform resources are created according to the
+registers
+ * specification.
+ * When forwarding VED irqs, the flow control handler selection depends
+on the
+ * platform, for example on valleyview handle_simple_irq is enough.
+ *
+ */
+
+static struct platform_device* vlv_ved_platdev_create(struct drm_device
+*dev) {
+	int ret;
+	struct resource rsc[2] = { {0}, {0} };
+	struct platform_device *platdev;
+	u64 *dma_mask = NULL;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+
+	if (dev_priv->ved.irq < 0)
+		return ERR_PTR(-EINVAL);
+
+	platdev = platform_device_alloc("ipvr-ved-vlv", -1);
+	if (!platdev) {
+		ret = -ENOMEM;
+		DRM_ERROR("Failed to allocate VED platform device\n");
+		goto err;
+	}
+
+	/* to work-around check_addr in nommu_map_sg() */
+	dma_mask = kmalloc(sizeof(*platdev->dev.dma_mask),

GFP_KERNEL);

drivers/gpu/drm/i915/i915_ved.c new file +15 -0
+	if (!dma_mask) {
+		ret = -ENOMEM;
+		DRM_ERROR("Failed to allocate dma_mask\n");
+		goto err_put_dev;
+	}
+	*dma_mask = DMA_BIT_MASK(31);
+	platdev->dev.dma_mask = dma_mask;
+	platdev->dev.coherent_dma_mask = *dma_mask;
+
+	rsc[0].start    = rsc[0].end = dev_priv->ved.irq;
+	rsc[0].flags    = IORESOURCE_IRQ;
+	rsc[0].name     = "ipvr-ved-vlv-irq";
+
+	rsc[1].start    = pci_resource_start(dev->pdev, 0) + VLV_VED_BASE;
+	rsc[1].end      = pci_resource_start(dev->pdev, 0) + VLV_VED_BASE +

VLV_VED_SIZE;

drivers/gpu/drm/i915/i915_ved.c new file +6 -0
+	rsc[1].flags    = IORESOURCE_MEM;
+	rsc[1].name     = "ipvr-ved-vlv-mmio";
+
+	ret = platform_device_add_resources(platdev, rsc, 2);
+	if (ret) {
+		DRM_ERROR("Failed to add resource for VED platform

device: %d\n", ret);

drivers/gpu/drm/i915/i915_ved.c new file +30 -0
+		goto err_put_dev;
+	}
+
+	platdev->dev.parent = dev->dev; /* for VED driver's runtime-PM */
+	ret = platform_device_add(platdev);
+	if (ret) {
+		DRM_ERROR("Failed to add VED platform device: %d\n", ret);
+		goto err_put_dev;
+	}
+
+	return platdev;
+err_put_dev:
+	platform_device_put(platdev);
+err:
+	if (dma_mask)
+		kfree(dma_mask);
+	return ERR_PTR(ret);
+}
+
+static void vlv_ved_platdev_destroy(struct drm_device *dev) {
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	if (dev_priv->ved.platdev) {
+		kfree(dev_priv->ved.platdev->dev.dma_mask);
+		platform_device_unregister(dev_priv->ved.platdev);
+	}
+}
+
+static void vlv_ved_irq_unmask(struct irq_data *d) {
+	struct drm_device *dev = d->chip_data;
+	struct drm_i915_private *dev_priv = (struct drm_i915_private *)

dev->dev_private;

drivers/gpu/drm/i915/i915_ved.c new file +15 -0
+	unsigned long irqflags;
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	dev_priv->irq_mask &= ~VLV_VED_BLOCK_INTERRUPT;
+	I915_WRITE(VLV_IIR, VLV_VED_BLOCK_INTERRUPT);
+	I915_WRITE(VLV_IIR, VLV_VED_BLOCK_INTERRUPT);
+	I915_WRITE(VLV_IMR, dev_priv->irq_mask);
+	I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
+	POSTING_READ(VLV_IER);
+
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); }
+
+static void vlv_ved_irq_mask(struct irq_data *d) {
+	struct drm_device *dev = d->chip_data;
+	struct drm_i915_private *dev_priv = (struct drm_i915_private *)

dev->dev_private;

drivers/gpu/drm/i915/i915_ved.c new file +20 -0
+	unsigned long irqflags;
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	dev_priv->irq_mask |= VLV_VED_BLOCK_INTERRUPT;
+	I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
+	I915_WRITE(VLV_IMR, dev_priv->irq_mask);
+	I915_WRITE(VLV_IIR, VLV_VED_BLOCK_INTERRUPT);
+	I915_WRITE(VLV_IIR, VLV_VED_BLOCK_INTERRUPT);
+	POSTING_READ(VLV_IIR);
+
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); }
+
+static struct irq_chip vlv_ved_irqchip = {
+	.name = "ipvr_ved_irqchip",
+	.irq_mask = vlv_ved_irq_mask,
+	.irq_unmask = vlv_ved_irq_unmask,
+};
+
+static int vlv_ved_irq_init(struct drm_device *dev, int irq) {
+	struct drm_i915_private *dev_priv = (struct drm_i915_private *)

dev->dev_private;

drivers/gpu/drm/i915/i915_ved.c new file +19 -0
+	WARN_ON(!intel_irqs_enabled(dev_priv));
+	irq_set_chip_and_handler_name(irq,
+		&vlv_ved_irqchip,
+		handle_simple_irq,
+		"ipvr_ved_vlv_irq_handler");
+	return irq_set_chip_data(irq, dev);
+}
+
+/**
+ * vlv_ved_irq_handler() - forwards the VED irq
+ * @dev: the i915 drm device
+ *
+ * the VED irq is forwarded to the irq handler registered by VED driver.
+ */
+void vlv_ved_irq_handler(struct drm_device *dev) {
+	int ret;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	if (dev_priv->ved.irq < 0 && printk_ratelimit()) {
+		DRM_ERROR("invalid ved irq number: %d\n", dev_priv-
Quoted 1 line

ved.irq);

drivers/gpu/drm/i915/i915_ved.c new file +26 -0
+		return;
+	}
+	ret = generic_handle_irq(dev_priv->ved.irq);
+	if (ret && printk_ratelimit()) {
+		DRM_ERROR("error handling vlv ved irq: %d\n", ret);
+	}
+}
+
+/**
+ * vlv_setup_ved() - setup the bridge between VED driver and i915
+ * @dev: the i915 drm device
+ *
+ * set up the minimum required resources for the bridge: irq chip,
+platform
+ * resource and platform device. i915 device is set as parent of the
+new
+ * platform device.
+ *
+ * Return: 0 if successful. non-zero if allocation/initialization fails
+*/ int vlv_setup_ved(struct drm_device *dev) {
+	int ret;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+
+	dev_priv->ved.irq = irq_alloc_descs(-1, 0, 1, 0);
+	if (dev_priv->ved.irq < 0) {
+		DRM_ERROR("Failed to allocate IRQ desc: %d\n", dev_priv-
Quoted 1 line

ved.irq);

drivers/gpu/drm/i915/i915_ved.c new file +7 -0
+		ret = dev_priv->ved.irq;
+		goto err;
+	}
+
+	ret = vlv_ved_irq_init(dev, dev_priv->ved.irq);
+	if (ret) {
+		DRM_ERROR("Failed to initialize irqchip for vlv-ved: %d\n",

ret);

drivers/gpu/drm/i915/i915_ved.c new file +7 -0
+		goto err_free_irq;
+	}
+
+	dev_priv->ved.platdev = vlv_ved_platdev_create(dev);
+	if (IS_ERR(dev_priv->ved.platdev)) {
+		ret = PTR_ERR(dev_priv->ved.platdev);
+		DRM_ERROR("Failed to create platform device for vlv-

ved: %d\n", ret);

drivers/gpu/drm/i915/i915_ved.c new file +38 -1
+		goto err_free_irq;
+	}
+
+	return 0;
+err_free_irq:
+	irq_free_desc(dev_priv->ved.irq);
+err:
+	dev_priv->ved.irq = -1;
+	dev_priv->ved.platdev = NULL;
+	return ret;
+}
+
+/**
+ * vlv_teardown_ved() - destroy the bridge between VED driver and i915
+ * @dev: the i915 drm device
+ *
+ * release all the resources for VED <-> i915 bridge.
+ */
+void vlv_teardown_ved(struct drm_device *dev) {
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	unsigned long irqflags;
+
+	/**
+	 * mask VED irq before destroying
+	 */
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+	dev_priv->irq_mask |= VLV_VED_BLOCK_INTERRUPT;
+	I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
+	I915_WRITE(VLV_IMR, dev_priv->irq_mask);
+	I915_WRITE(VLV_IIR, VLV_VED_BLOCK_INTERRUPT);
+	I915_WRITE(VLV_IIR, VLV_VED_BLOCK_INTERRUPT);
+	POSTING_READ(VLV_IIR);
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
+
+	vlv_ved_platdev_destroy(dev);
+	if (dev_priv->ved.irq >= 0)
+		irq_free_desc(dev_priv->ved.irq);
+}
--
Quoted 1 line

2.1.0

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

RFC PATCH v4 2/4 drm/ipvr: drm driver for VED

In reply to Sean V Kelley

From: Yao Cheng <[email protected]>

Probes VED and creates a new drm device for hardware accelerated video decoding.
Currently support VP8 decoding on valleyview.

v2:
take David's comments
- add mmap support and remove mmap_ioctl
- remove postclose since it's deprecated
- NULL set_busid

v3:
take David, Daniel and Jesse's comments and massive refine
- use drm_dev_alloc+drm_dev_register to replace drm_platform_init
- same as above in exit side
- remove fd based explit fence
- refine ipvr_drm.h, use __u32 series and refine paddings
- add doc to describe ipvr/ved terminology
- ioctl refine: remove unused code
- use uintptr_t series for address/number conversion
- runtime pm refine: guarantee get/put paring
- add PRIME feature and remove USERPTR ioctl
- implement relocation fixup in EXEC ioctl
- call drm_gem_get_pages to replace my own implementation
- code cleanup: remove unused code

v4:
bug fixing,
- add missing unreference in ipvr_gem_fault()
- add struct_mutex lock around drm_mm_insert_node_in_range_generic()
- move ipvr_ctx_list from dev_priv to file_priv and add spinlock
- check EAGAIN for pm_runtime_get/put and add lock
- add mutex lock for do_execbuffer
- put power on fence lockup
- define all ioctls as DRM_AUTH|DRM_UNLOCKED
- correctly set ved_busy
- rename ipvr_misc_ioctl to ipvr_get_info_ioctl and remove unused code

---
 Documentation/DocBook/drm.tmpl    |   39 ++
 drivers/gpu/drm/Kconfig           |    2 +
 drivers/gpu/drm/Makefile          |    1 +
 drivers/gpu/drm/ipvr/Kconfig      |    9 +
 drivers/gpu/drm/ipvr/Makefile     |   18 +
 drivers/gpu/drm/ipvr/ipvr_bo.c    |  543 +++++++++++++++++
 drivers/gpu/drm/ipvr/ipvr_bo.h    |   80 +++
 drivers/gpu/drm/ipvr/ipvr_debug.c |  335 +++++++++++
 drivers/gpu/drm/ipvr/ipvr_debug.h |   76 +++
 drivers/gpu/drm/ipvr/ipvr_drm.h   |  259 ++++++++
 drivers/gpu/drm/ipvr/ipvr_drv.c   |  617 +++++++++++++++++++
 drivers/gpu/drm/ipvr/ipvr_drv.h   |  292 +++++++++
 drivers/gpu/drm/ipvr/ipvr_exec.c  |  613 +++++++++++++++++++
 drivers/gpu/drm/ipvr/ipvr_exec.h  |   57 ++
 drivers/gpu/drm/ipvr/ipvr_fence.c |  487 +++++++++++++++
 drivers/gpu/drm/ipvr/ipvr_fence.h |   72 +++
 drivers/gpu/drm/ipvr/ipvr_gem.c   |  297 +++++++++
 drivers/gpu/drm/ipvr/ipvr_gem.h   |   48 ++
 drivers/gpu/drm/ipvr/ipvr_mmu.c   |  752 +++++++++++++++++++++++
 drivers/gpu/drm/ipvr/ipvr_mmu.h   |  111 ++++
 drivers/gpu/drm/ipvr/ipvr_trace.c |   11 +
 drivers/gpu/drm/ipvr/ipvr_trace.h |  333 ++++++++++
 drivers/gpu/drm/ipvr/ved_cmd.c    |  882 +++++++++++++++++++++++++++
 drivers/gpu/drm/ipvr/ved_cmd.h    |   70 +++
 drivers/gpu/drm/ipvr/ved_fw.c     | 1199 +++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/ipvr/ved_fw.h     |   81 +++
 drivers/gpu/drm/ipvr/ved_msg.h    |  256 ++++++++
 drivers/gpu/drm/ipvr/ved_pm.c     |  335 +++++++++++
 drivers/gpu/drm/ipvr/ved_pm.h     |   36 ++
 drivers/gpu/drm/ipvr/ved_reg.h    |  561 +++++++++++++++++
 30 files changed, 8472 insertions(+)
 create mode 100644 drivers/gpu/drm/ipvr/Kconfig
 create mode 100644 drivers/gpu/drm/ipvr/Makefile
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_bo.c
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_bo.h
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_debug.c
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_debug.h
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_drm.h
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_drv.c
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_drv.h
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_exec.c
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_exec.h
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_fence.c
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_fence.h
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_gem.c
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_gem.h
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_mmu.c
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_mmu.h
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_trace.c
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_trace.h
 create mode 100644 drivers/gpu/drm/ipvr/ved_cmd.c
 create mode 100644 drivers/gpu/drm/ipvr/ved_cmd.h
 create mode 100644 drivers/gpu/drm/ipvr/ved_fw.c
 create mode 100644 drivers/gpu/drm/ipvr/ved_fw.h
 create mode 100644 drivers/gpu/drm/ipvr/ved_msg.h
 create mode 100644 drivers/gpu/drm/ipvr/ved_pm.c
 create mode 100644 drivers/gpu/drm/ipvr/ved_pm.h
 create mode 100644 drivers/gpu/drm/ipvr/ved_reg.h
Documentation/DocBook/drm.tmpl +39 -0
index 9db989c..e9cadf6 100644
@@ -4062,5 +4062,44 @@ int num_ioctls;</synopsis>
 
   </chapter>
 !Cdrivers/gpu/drm/i915/i915_irq.c
+  <chapter id="drmIpvr">
+    <title>drm/ipvr Intel's driver for PowerVR video core</title>
+    <para>
+      The drm/ipvr driver intends to support the PowerVR video cores
+	  integrated on Intel's platforms. The video cores can be categorized
+	  into 3 types:
+        <variablelist>
+          <varlistentry>
+            <term>VED</term>
+            <listitem>
+              <para>
+                multi-format video decoder, various video codecs are supported,
+				e.g. H.264, VP8, etc..
+              </para>
+            </listitem>
+          </varlistentry>
+          <varlistentry>
+            <term>VEC</term>
+            <listitem>
+              <para>
+                multi-format video encoder, various video codecs support like
+				VED.
+              </para>
+            </listitem>
+          </varlistentry>
+          <varlistentry>
+            <term>VSP</term>
+            <listitem>
+              <para>
+		        multi-function video processing. supports various features such
+				as color-space-conversion, sharpening, deblocking, etc..
+              </para>
+            </listitem>
+          </varlistentry>
+        </variablelist>
+	  Now ipvr only supports VED on Valleyview platform. The names "VEC"
+	  and "VSP" are reserved for possible future support.
+    </para>
+  </chapter>
 </part>
 </book>
drivers/gpu/drm/Kconfig +2 -0
index 24c2d7c..c79b813 100644
@@ -165,6 +165,8 @@ config DRM_SAVAGE
 	  Choose this option if you have a Savage3D/4/SuperSavage/Pro/Twister
 	  chipset. If M is selected the module will be called savage.
 
+source "drivers/gpu/drm/ipvr/Kconfig"
+
 source "drivers/gpu/drm/exynos/Kconfig"
 
 source "drivers/gpu/drm/vmwgfx/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index 47d8986..d364ea2 100644
@@ -41,6 +41,7 @@ obj-$(CONFIG_DRM_RADEON)+= radeon/
 obj-$(CONFIG_DRM_MGA)	+= mga/
 obj-$(CONFIG_DRM_I810)	+= i810/
 obj-$(CONFIG_DRM_I915)  += i915/
+obj-$(CONFIG_DRM_IPVR)  += ipvr/
 obj-$(CONFIG_DRM_MGAG200) += mgag200/
 obj-$(CONFIG_DRM_CIRRUS_QEMU) += cirrus/
 obj-$(CONFIG_DRM_SIS)   += sis/
drivers/gpu/drm/ipvr/Kconfig new file +9 -0
new file mode 100644
index 0000000..869bad4
@@ -0,0 +1,9 @@
+config DRM_IPVR
+       tristate "IPVR video decode driver"
+       depends on DRM
+       select SHMEM
+       select TMPFS
+       default m
+       help
+         Choose this option if you want to enable accelerated video decode with VED hardware.
+		 Currently support VP8 decoding on valleyview.
drivers/gpu/drm/ipvr/Makefile new file +18 -0
new file mode 100644
index 0000000..280647e
@@ -0,0 +1,18 @@
+ccflags-y := -Iinclude/drm
+
+ipvr-y := \
+        ipvr_drv.o \
+        ipvr_bo.o \
+        ipvr_exec.o \
+        ipvr_fence.o \
+        ipvr_gem.o \
+        ipvr_mmu.o \
+        ipvr_debug.o \
+        ipvr_trace.o \
+        ved_pm.o \
+        ved_cmd.o \
+        ved_fw.o
+
+obj-$(CONFIG_DRM_IPVR) += ipvr.o
+
+CFLAGS_ipvr_trace.o := -I$(src)
drivers/gpu/drm/ipvr/ipvr_bo.c new file +543 -0

543 lines not on this page · raw message

drivers/gpu/drm/ipvr/ipvr_bo.h new file +80 -0

80 lines not on this page · raw message

drivers/gpu/drm/ipvr/ipvr_debug.c new file +335 -0

335 lines not on this page · raw message

drivers/gpu/drm/ipvr/ipvr_debug.h new file +76 -0

76 lines not on this page · raw message

drivers/gpu/drm/ipvr/ipvr_drm.h new file +259 -0

259 lines not on this page · raw message

drivers/gpu/drm/ipvr/ipvr_drv.c new file +617 -0

617 lines not on this page · raw message

drivers/gpu/drm/ipvr/ipvr_drv.h new file +292 -0

292 lines not on this page · raw message

drivers/gpu/drm/ipvr/ipvr_exec.c new file +613 -0

613 lines not on this page · raw message

drivers/gpu/drm/ipvr/ipvr_exec.h new file +57 -0

57 lines not on this page · raw message

drivers/gpu/drm/ipvr/ipvr_fence.c new file +487 -0

42 lines not on this page · raw message

drivers/gpu/drm/ipvr/ipvr_fence.h new file +72 -0

72 lines not on this page · raw message

drivers/gpu/drm/ipvr/ipvr_gem.c new file +297 -0

297 lines not on this page · raw message

drivers/gpu/drm/ipvr/ipvr_gem.h new file +48 -0

48 lines not on this page · raw message

drivers/gpu/drm/ipvr/ipvr_mmu.c new file +752 -0

752 lines not on this page · raw message

drivers/gpu/drm/ipvr/ipvr_mmu.h new file +111 -0

111 lines not on this page · raw message

drivers/gpu/drm/ipvr/ipvr_trace.c new file +11 -0
new file mode 100644
index 0000000..91c0bda

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/ipvr/ipvr_trace.h new file +333 -0

333 lines not on this page · raw message

drivers/gpu/drm/ipvr/ved_cmd.c new file +882 -0

882 lines not on this page · raw message

drivers/gpu/drm/ipvr/ved_cmd.h new file +70 -0

70 lines not on this page · raw message

drivers/gpu/drm/ipvr/ved_fw.c new file +1199 -0

1,199 lines not on this page · raw message

drivers/gpu/drm/ipvr/ved_fw.h new file +81 -0

81 lines not on this page · raw message

drivers/gpu/drm/ipvr/ved_msg.h new file +256 -0

256 lines not on this page · raw message

drivers/gpu/drm/ipvr/ved_pm.c new file +335 -0

335 lines not on this page · raw message

drivers/gpu/drm/ipvr/ved_pm.h new file +36 -0
new file mode 100644
index 0000000..4ed1485

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/ipvr/ved_reg.h new file +561 -0

561 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 6 lines
2.1.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Part of the diff is not shown here. View the raw message.

#4 lore raw

Re: [RFC PATCH v4 2/4] drm/ipvr: drm driver for VED

+ commenters of v1~v3

Thanks,
Yao

Quoted 9,758 lines

-----Original Message-----
From: Sean V Kelley [mailto:[email protected]]
Sent: Thursday, January 8, 2015 8:35
To: [email protected]
Cc: [email protected]; Cheng, Yao; Sean V Kelley
Subject: [RFC PATCH v4 2/4] drm/ipvr: drm driver for VED

From: Yao Cheng <[email protected]>

Probes VED and creates a new drm device for hardware accelerated video decoding.
Currently support VP8 decoding on valleyview.

v2:
take David's comments
- add mmap support and remove mmap_ioctl
- remove postclose since it's deprecated
- NULL set_busid

v3:
take David, Daniel and Jesse's comments and massive refine
- use drm_dev_alloc+drm_dev_register to replace
drm_platform_init
- same as above in exit side
- remove fd based explit fence
- refine ipvr_drm.h, use __u32 series and refine paddings
- add doc to describe ipvr/ved terminology
- ioctl refine: remove unused code
- use uintptr_t series for address/number conversion
- runtime pm refine: guarantee get/put paring
- add PRIME feature and remove USERPTR ioctl
- implement relocation fixup in EXEC ioctl
- call drm_gem_get_pages to replace my own implementation
- code cleanup: remove unused code

v4:
bug fixing,
- add missing unreference in ipvr_gem_fault()
- add struct_mutex lock around
drm_mm_insert_node_in_range_generic()
- move ipvr_ctx_list from dev_priv to file_priv and add spinlock
- check EAGAIN for pm_runtime_get/put and add lock
- add mutex lock for do_execbuffer
- put power on fence lockup
- define all ioctls as DRM_AUTH|DRM_UNLOCKED
- correctly set ved_busy
- rename ipvr_misc_ioctl to ipvr_get_info_ioctl and remove unused
code

---
 Documentation/DocBook/drm.tmpl    |   39 ++
 drivers/gpu/drm/Kconfig           |    2 +
 drivers/gpu/drm/Makefile          |    1 +
 drivers/gpu/drm/ipvr/Kconfig      |    9 +
 drivers/gpu/drm/ipvr/Makefile     |   18 +
 drivers/gpu/drm/ipvr/ipvr_bo.c    |  543 +++++++++++++++++
 drivers/gpu/drm/ipvr/ipvr_bo.h    |   80 +++
 drivers/gpu/drm/ipvr/ipvr_debug.c |  335 +++++++++++
 drivers/gpu/drm/ipvr/ipvr_debug.h |   76 +++
 drivers/gpu/drm/ipvr/ipvr_drm.h   |  259 ++++++++
 drivers/gpu/drm/ipvr/ipvr_drv.c   |  617 +++++++++++++++++++
 drivers/gpu/drm/ipvr/ipvr_drv.h   |  292 +++++++++
 drivers/gpu/drm/ipvr/ipvr_exec.c  |  613 +++++++++++++++++++
 drivers/gpu/drm/ipvr/ipvr_exec.h  |   57 ++
 drivers/gpu/drm/ipvr/ipvr_fence.c |  487 +++++++++++++++
 drivers/gpu/drm/ipvr/ipvr_fence.h |   72 +++
 drivers/gpu/drm/ipvr/ipvr_gem.c   |  297 +++++++++
 drivers/gpu/drm/ipvr/ipvr_gem.h   |   48 ++
 drivers/gpu/drm/ipvr/ipvr_mmu.c   |  752 +++++++++++++++++++++++
 drivers/gpu/drm/ipvr/ipvr_mmu.h   |  111 ++++
 drivers/gpu/drm/ipvr/ipvr_trace.c |   11 +
 drivers/gpu/drm/ipvr/ipvr_trace.h |  333 ++++++++++
 drivers/gpu/drm/ipvr/ved_cmd.c    |  882
+++++++++++++++++++++++++++
 drivers/gpu/drm/ipvr/ved_cmd.h    |   70 +++
 drivers/gpu/drm/ipvr/ved_fw.c     | 1199
+++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/ipvr/ved_fw.h     |   81 +++
 drivers/gpu/drm/ipvr/ved_msg.h    |  256 ++++++++
 drivers/gpu/drm/ipvr/ved_pm.c     |  335 +++++++++++
 drivers/gpu/drm/ipvr/ved_pm.h     |   36 ++
 drivers/gpu/drm/ipvr/ved_reg.h    |  561 +++++++++++++++++
 30 files changed, 8472 insertions(+)
 create mode 100644 drivers/gpu/drm/ipvr/Kconfig
 create mode 100644 drivers/gpu/drm/ipvr/Makefile
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_bo.c
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_bo.h
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_debug.c
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_debug.h
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_drm.h
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_drv.c
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_drv.h
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_exec.c
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_exec.h
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_fence.c
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_fence.h
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_gem.c
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_gem.h
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_mmu.c
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_mmu.h
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_trace.c
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_trace.h
 create mode 100644 drivers/gpu/drm/ipvr/ved_cmd.c
 create mode 100644 drivers/gpu/drm/ipvr/ved_cmd.h
 create mode 100644 drivers/gpu/drm/ipvr/ved_fw.c
 create mode 100644 drivers/gpu/drm/ipvr/ved_fw.h
 create mode 100644 drivers/gpu/drm/ipvr/ved_msg.h
 create mode 100644 drivers/gpu/drm/ipvr/ved_pm.c
 create mode 100644 drivers/gpu/drm/ipvr/ved_pm.h
 create mode 100644 drivers/gpu/drm/ipvr/ved_reg.h
Documentation/DocBook/drm.tmpl +30 -0
index 9db989c..e9cadf6 100644
@@ -4062,5 +4062,44 @@ int num_ioctls;</synopsis>
 
   </chapter>
 !Cdrivers/gpu/drm/i915/i915_irq.c
+  <chapter id="drmIpvr">
+    <title>drm/ipvr Intel's driver for PowerVR video core</title>
+    <para>
+      The drm/ipvr driver intends to support the PowerVR video cores
+	  integrated on Intel's platforms. The video cores can be categorized
+	  into 3 types:
+        <variablelist>
+          <varlistentry>
+            <term>VED</term>
+            <listitem>
+              <para>
+                multi-format video decoder, various video codecs are supported,
+				e.g. H.264, VP8, etc..
+              </para>
+            </listitem>
+          </varlistentry>
+          <varlistentry>
+            <term>VEC</term>
+            <listitem>
+              <para>
+                multi-format video encoder, various video codecs support like
+				VED.
+              </para>
+            </listitem>
+          </varlistentry>
+          <varlistentry>
+            <term>VSP</term>
+            <listitem>
+              <para>
+		        multi-function video processing. supports various

features such

Documentation/DocBook/drm.tmpl +1 -0
+				as color-space-conversion, sharpening,

deblocking, etc..

Documentation/DocBook/drm.tmpl +5 -0
+              </para>
+            </listitem>
+          </varlistentry>
+        </variablelist>
+	  Now ipvr only supports VED on Valleyview platform. The names

"VEC"

Documentation/DocBook/drm.tmpl +3 -0
+	  and "VSP" are reserved for possible future support.
+    </para>
+  </chapter>
 </part>
 </book>
drivers/gpu/drm/Kconfig +0 -0
index 24c2d7c..c79b813 100644
@@ -165,6 +165,8 @@ config DRM_SAVAGE
 	  Choose this option if you have a

Savage3D/4/SuperSavage/Pro/Twister

drivers/gpu/drm/Kconfig +2 -0
 	  chipset. If M is selected the module will be called savage.
 
+source "drivers/gpu/drm/ipvr/Kconfig"
+
 source "drivers/gpu/drm/exynos/Kconfig"
 
 source "drivers/gpu/drm/vmwgfx/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index 47d8986..d364ea2 100644
@@ -41,6 +41,7 @@ obj-$(CONFIG_DRM_RADEON)+= radeon/
 obj-$(CONFIG_DRM_MGA)	+= mga/
 obj-$(CONFIG_DRM_I810)	+= i810/
 obj-$(CONFIG_DRM_I915)  += i915/
+obj-$(CONFIG_DRM_IPVR)  += ipvr/
 obj-$(CONFIG_DRM_MGAG200) += mgag200/
 obj-$(CONFIG_DRM_CIRRUS_QEMU) += cirrus/
 obj-$(CONFIG_DRM_SIS)   += sis/
drivers/gpu/drm/ipvr/Kconfig new file +8 -0
new file mode 100644
index 0000000..869bad4
@@ -0,0 +1,9 @@
+config DRM_IPVR
+       tristate "IPVR video decode driver"
+       depends on DRM
+       select SHMEM
+       select TMPFS
+       default m
+       help
+         Choose this option if you want to enable accelerated video decode

with VED hardware.

drivers/gpu/drm/ipvr/Kconfig new file +1 -0
+		 Currently support VP8 decoding on valleyview.
drivers/gpu/drm/ipvr/Makefile new file +18 -0
new file mode 100644
index 0000000..280647e
@@ -0,0 +1,18 @@
+ccflags-y := -Iinclude/drm
+
+ipvr-y := \
+        ipvr_drv.o \
+        ipvr_bo.o \
+        ipvr_exec.o \
+        ipvr_fence.o \
+        ipvr_gem.o \
+        ipvr_mmu.o \
+        ipvr_debug.o \
+        ipvr_trace.o \
+        ved_pm.o \
+        ved_cmd.o \
+        ved_fw.o
+
+obj-$(CONFIG_DRM_IPVR) += ipvr.o
+
+CFLAGS_ipvr_trace.o := -I$(src)
drivers/gpu/drm/ipvr/ipvr_bo.c new file +1 -0
new file mode 100644
index 0000000..5fccf7e
@@ -0,0 +1,543 @@
+/*********************************************************

*****************
+ * ipvr_bo.c: IPVR buffer creation/destory, import/export, map etc
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ipvr_bo.c new file +14 -0
+
+#include "ipvr_bo.h"
+#include "ipvr_trace.h"
+#include "ipvr_debug.h"
+#include <drmP.h>
+#include <linux/dma-buf.h>
+
+static inline bool cpu_cache_is_coherent(enum ipvr_cache_level level)
+{
+	/* on valleyview no cache snooping */
+	return (level != IPVR_CACHE_WRITEBACK);
+}
+
+static inline bool clflush_object(struct drm_ipvr_gem_object *obj, bool

force)

drivers/gpu/drm/ipvr/ipvr_bo.c new file +26 -0
+{
+	if (obj->sg_table == NULL)
+		return false;
+
+	/* no need to flush if cache is coherent */
+	if (!force && cpu_cache_is_coherent(obj->cache_level))
+		return false;
+
+	drm_clflush_sg(obj->sg_table);
+
+	return true;
+}
+
+static void
+ipvr_object_free(struct drm_ipvr_gem_object *obj)
+{
+	struct drm_ipvr_private *dev_priv = obj->base.dev->dev_private;
+	kmem_cache_free(dev_priv->ipvr_bo_slab, obj);
+}
+
+static struct drm_ipvr_gem_object *
+ipvr_object_alloc(struct drm_ipvr_private *dev_priv, size_t size)
+{
+	struct drm_ipvr_gem_object *obj;
+
+	obj = kmem_cache_alloc(dev_priv->ipvr_bo_slab, GFP_KERNEL |

__GFP_ZERO);

drivers/gpu/drm/ipvr/ipvr_bo.c new file +25 -0
+	if (obj == NULL)
+		return NULL;
+	memset(obj, 0, sizeof(*obj));
+
+	return obj;
+}
+
+static int ipvr_gem_mmu_bind_object(struct drm_ipvr_gem_object *obj)
+{
+	struct drm_ipvr_private *dev_priv = obj->base.dev->dev_private;
+	const unsigned long entry = ipvr_gem_object_mmu_offset(obj);
+
+	if (IPVR_IS_ERR(entry)) {
+		return IPVR_OFFSET_ERR(entry);
+	}
+
+	IPVR_DEBUG_GENERAL("entry is 0x%lx, size is %zu, nents is %d.\n",
+			entry, obj->base.size, obj->sg_table->nents);
+
+	return ipvr_mmu_insert_pages(dev_priv->mmu->default_pd,
+		obj->pages, entry, obj->base.size >> PAGE_SHIFT,
+		0, 0, 0);
+}
+
+static void ipvr_gem_mmu_unbind_object(struct drm_ipvr_gem_object

*obj)

drivers/gpu/drm/ipvr/ipvr_bo.c new file +16 -0
+{
+	struct drm_ipvr_private *dev_priv = obj->base.dev->dev_private;
+	const unsigned long entry = ipvr_gem_object_mmu_offset(obj);
+	IPVR_DEBUG_GENERAL("entry is 0x%lx, size is %zu.\n",
+			entry, obj->base.size);
+	ipvr_mmu_remove_pages(dev_priv->mmu->default_pd,
+		entry, obj->base.size >> PAGE_SHIFT, 0, 0);
+}
+
+static void ipvr_gem_object_pin_pages(struct drm_ipvr_gem_object *obj)
+{
+	BUG_ON(obj->sg_table == NULL);
+	obj->pages_pin_count++;
+}
+
+static void ipvr_gem_object_unpin_pages(struct drm_ipvr_gem_object

*obj)

drivers/gpu/drm/ipvr/ipvr_bo.c new file +22 -0
+{
+	BUG_ON(obj->pages_pin_count == 0);
+	obj->pages_pin_count--;
+}
+
+static int ipvr_gem_bind_to_drm_mm(struct drm_ipvr_gem_object* obj,
+			struct ipvr_address_space *vm)
+{
+	int ret = 0;
+	struct drm_mm *mm;
+	unsigned long start, end;
+	/* bind to VPU address space */
+	if (obj->tiling) {
+		mm = &vm->tiling_mm;
+		start = vm->tiling_start;
+		end = vm->tiling_start + vm->tiling_total;
+	} else {
+		mm = &vm->linear_mm;
+		start = vm->linear_start;
+		end = vm->linear_start + vm->linear_total;
+	}
+	IPVR_DEBUG_GENERAL("call

drm_mm_insert_node_in_range_generic.\n");

drivers/gpu/drm/ipvr/ipvr_bo.c new file +4 -0
+	ret = mutex_lock_interruptible(&obj->base.dev->struct_mutex);
+	if (ret)
+		return ret;
+	ret = drm_mm_insert_node_in_range_generic(mm, &obj-
Quoted 1 line

mm_node, obj->base.size,

drivers/gpu/drm/ipvr/ipvr_bo.c new file +3 -0
+						PAGE_SIZE, obj->cache_level,
+						start, end,
+

DRM_MM_SEARCH_DEFAULT,
+

	DRM_MM_CREATE_DEFAULT);
drivers/gpu/drm/ipvr/ipvr_bo.c new file +3 -0
+	if (ret) {
+		/* no shrinker implemented yet so simply return error */
+		IPVR_ERROR("failed on

drm_mm_insert_node_in_range_generic: %d\n", ret);

drivers/gpu/drm/ipvr/ipvr_bo.c new file +4 -0
+		goto out;
+	}
+
+	IPVR_DEBUG_GENERAL("drm_mm_insert_node_in_range_generic

success: "

drivers/gpu/drm/ipvr/ipvr_bo.c new file +2 -0
+		"start=0x%lx, size=%lu, color=%lu.\n",
+		obj->mm_node.start, obj->mm_node.size, obj-
Quoted 1 line

mm_node.color);

drivers/gpu/drm/ipvr/ipvr_bo.c new file +8 -0
+
+out:
+	mutex_unlock(&obj->base.dev->struct_mutex);
+
+	return ret;
+}
+
+struct drm_ipvr_gem_object* ipvr_gem_create(struct drm_ipvr_private

*dev_priv,

drivers/gpu/drm/ipvr/ipvr_bo.c new file +51 -0
+			size_t size, u32 tiling, u32 cache_level)
+{
+	struct drm_ipvr_gem_object *obj;
+	int ret = 0;
+	int npages;
+	struct address_space *mapping;
+	gfp_t mask;
+
+	BUG_ON(size & (PAGE_SIZE - 1));
+	npages = size >> PAGE_SHIFT;
+	IPVR_DEBUG_GENERAL("create bo size is %zu, tiling is %u, "
+			"cache level is %u.\n",	size, tiling, cache_level);
+
+	/* Allocate the new object */
+	obj = ipvr_object_alloc(dev_priv, size);
+	if (!obj)
+		return ERR_PTR(-ENOMEM);
+
+	/* initialization */
+	ret = drm_gem_object_init(dev_priv->dev, &obj->base, size);
+	if (ret) {
+		IPVR_ERROR("failed on drm_gem_object_init: %d\n", ret);
+		goto err_free_obj;
+	}
+	init_waitqueue_head(&obj->event_queue);
+	/* todo: need set correct mask */
+	mask = GFP_HIGHUSER | __GFP_RECLAIMABLE;
+
+	/* ipvr cannot relocate objects above 4GiB. */
+	mask &= ~__GFP_HIGHMEM;
+	mask |= __GFP_DMA32;
+
+	mapping = file_inode(obj->base.filp)->i_mapping;
+	mapping_set_gfp_mask(mapping, mask);
+
+	obj->base.write_domain = IPVR_GEM_DOMAIN_CPU;
+	obj->base.read_domains = IPVR_GEM_DOMAIN_CPU;
+	obj->drv_name = "ipvr";
+	obj->fence = NULL;
+	obj->tiling = tiling;
+	obj->cache_level = cache_level;
+
+	/* get physical pages */
+	obj->pages = drm_gem_get_pages(&obj->base);
+	if (IS_ERR(obj->pages)) {
+		ret = PTR_ERR(obj->pages);
+		IPVR_ERROR("failed on drm_gem_get_pages: %d\n", ret);
+		goto err_free_obj;
+	}
+
+	obj->sg_table = drm_prime_pages_to_sg(obj->pages, obj-
Quoted 1 line

base.size >> PAGE_SHIFT);

drivers/gpu/drm/ipvr/ipvr_bo.c new file +32 -0
+	if (IS_ERR(obj->sg_table)) {
+		ret = PTR_ERR(obj->sg_table);
+		IPVR_ERROR("failed on drm_gem_get_pages: %d\n", ret);
+		goto err_put_pages;
+	}
+
+	/* set cacheability */
+	switch (obj->cache_level) {
+	case IPVR_CACHE_UNCACHED:
+		ret = set_pages_array_uc(obj->pages, npages);
+		break;
+	case IPVR_CACHE_WRITECOMBINE:
+		ret = set_pages_array_wc(obj->pages, npages);
+		break;
+	case IPVR_CACHE_WRITEBACK:
+		ret = set_pages_array_wb(obj->pages, npages);
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+	if (ret) {
+		IPVR_DEBUG_WARN("failed to set page cache: %d.\n", ret);
+		goto err_put_sg;
+	}
+
+	ipvr_gem_object_pin_pages(obj);
+
+	/* bind to VPU address space */
+	ret = ipvr_gem_bind_to_drm_mm(obj, &dev_priv->addr_space);
+	if (ret) {
+		IPVR_ERROR("failed to call

ipvr_gem_bind_to_drm_mm: %d.\n", ret);

drivers/gpu/drm/ipvr/ipvr_bo.c new file +6 -0
+		goto err_put_sg;
+	}
+
+	ret = ipvr_gem_mmu_bind_object(obj);
+	if (ret) {
+		IPVR_ERROR("failed to call

ipvr_gem_mmu_bind_object: %d.\n", ret);

drivers/gpu/drm/ipvr/ipvr_bo.c new file +32 -0
+		goto err_remove_node;
+	}
+
+	ipvr_stat_add_object(dev_priv, obj);
+	trace_ipvr_create_object(obj, ipvr_gem_object_mmu_offset(obj));
+	return obj;
+err_remove_node:
+	drm_mm_remove_node(&obj->mm_node);
+err_put_sg:
+	sg_free_table(obj->sg_table);
+	kfree(obj->sg_table);
+err_put_pages:
+	drm_gem_put_pages(&obj->base, obj->pages, false, false);
+err_free_obj:
+	ipvr_object_free(obj);
+	return ERR_PTR(ret);
+}
+
+void *ipvr_gem_object_vmap(struct drm_ipvr_gem_object *obj)
+{
+	pgprot_t pg = PAGE_KERNEL;
+	switch (obj->cache_level) {
+	case IPVR_CACHE_WRITECOMBINE:
+		pg = pgprot_writecombine(pg);
+		break;
+	case IPVR_CACHE_UNCACHED:
+		pg = pgprot_noncached(pg);
+		break;
+	default:
+		break;
+	}
+	return vmap(obj->pages, obj->base.size >> PAGE_SHIFT, VM_MAP,

pg);

drivers/gpu/drm/ipvr/ipvr_bo.c new file +4 -0
+}
+
+/*
+ * When the last reference to a GEM object is released the GEM core calls

the
+ * drm_driver .gem_free_object() operation. That operation is mandatory for
+ * GEM-enabled drivers and must free the GEM object and all associated
+ * resources.
+ * called with struct_mutex locked.
+ */

drivers/gpu/drm/ipvr/ipvr_bo.c new file +19 -0
+void ipvr_gem_free_object(struct drm_gem_object *gem_obj)
+{
+	struct drm_device *dev = gem_obj->dev;
+	struct drm_ipvr_gem_object *obj = to_ipvr_bo(gem_obj);
+	drm_ipvr_private_t *dev_priv = dev->dev_private;
+	int ret;
+	unsigned long mmu_offset;
+	int npages = gem_obj->size >> PAGE_SHIFT;
+
+	/* fixme: consider unlocked case */
+	WARN_ON(!mutex_is_locked(&dev->struct_mutex));
+
+	mmu_offset = ipvr_gem_object_mmu_offset(obj);
+	ipvr_gem_mmu_unbind_object(obj);
+
+	if (unlikely(obj->fence)) {
+		ret = ipvr_fence_wait(obj->fence, true, false);
+		if (ret)
+			IPVR_DEBUG_WARN("Failed to wait fence

signaled: %d.\n", ret);

drivers/gpu/drm/ipvr/ipvr_bo.c new file +13 -0
+	}
+
+	drm_mm_remove_node(&obj->mm_node);
+	ipvr_gem_object_unpin_pages(obj);
+
+	if (WARN_ON(obj->pages_pin_count))
+		obj->pages_pin_count = 0;
+
+	BUG_ON(!obj->pages || !obj->sg_table);
+	/* set back to page_wb */
+	set_pages_array_wb(obj->pages, npages);
+	if (obj->base.import_attach) {
+		IPVR_DEBUG_GENERAL("free imported object (mmu_offset

0x%lx)\n", mmu_offset);

drivers/gpu/drm/ipvr/ipvr_bo.c new file +6 -0
+		drm_prime_gem_destroy(&obj->base, obj->sg_table);
+		drm_free_large(obj->pages);
+		ipvr_stat_remove_imported(dev_priv, obj);
+	}
+	else {
+		IPVR_DEBUG_GENERAL("free object (mmu_offset 0x%lx)\n",

mmu_offset);

drivers/gpu/drm/ipvr/ipvr_bo.c new file +3 -0
+		sg_free_table(obj->sg_table);
+		kfree(obj->sg_table);
+		drm_gem_put_pages(&obj->base, obj->pages, obj->dirty,

true);

drivers/gpu/drm/ipvr/ipvr_bo.c new file +12 -0
+		ipvr_stat_remove_object(dev_priv, obj);
+	}
+
+	/* mmap offset is freed by drm_gem_object_release */
+	drm_gem_object_release(&obj->base);
+
+	trace_ipvr_free_object(obj);
+
+	ipvr_object_free(obj);
+}
+
+static inline struct page *get_object_page(struct drm_ipvr_gem_object

*obj, int n)

drivers/gpu/drm/ipvr/ipvr_bo.c new file +4 -0
+{
+	struct sg_page_iter sg_iter;
+
+	for_each_sg_page(obj->sg_table->sgl, &sg_iter, obj->sg_table-
Quoted 1 line

nents, n)

drivers/gpu/drm/ipvr/ipvr_bo.c new file +14 -0
+		return sg_page_iter_page(&sg_iter);
+
+	return NULL;
+}
+
+int ipvr_gem_object_apply_reloc(struct drm_ipvr_gem_object *obj,
+				u64 offset_in_bo, u32 value)
+{
+	u64 page_offset = offset_in_page(offset_in_bo);
+	char *vaddr;
+	struct page *target_page;
+
+	/* set to cpu domain */
+	target_page = get_object_page(obj,	offset_in_bo >>

PAGE_SHIFT);

drivers/gpu/drm/ipvr/ipvr_bo.c new file +27 -0
+	if (!target_page)
+		return -EINVAL;
+
+	/**
+	 * for efficiency we'd better record the page index,
+	 * and avoid frequent map/unmap on the same page
+	 */
+	vaddr = kmap_atomic(target_page);
+	if (!vaddr)
+		return -ENOMEM;
+	*(u32 *)(vaddr + page_offset) = value;
+
+	kunmap_atomic(vaddr);
+
+	return 0;
+}
+
+int ipvr_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
+{
+	struct drm_gem_object *obj = vma->vm_private_data;
+	struct drm_device *dev = obj->dev;
+	unsigned long pfn;
+	pgoff_t pgoff;
+	int ret;
+	struct drm_ipvr_gem_object *ipvr_obj = to_ipvr_bo(obj);
+
+	/* Make sure we don't parallel update on a fault, nor move or

remove

drivers/gpu/drm/ipvr/ipvr_bo.c new file +18 -0
+	 * something from beneath our feet
+	 */
+	ret = mutex_lock_interruptible(&dev->struct_mutex);
+	if (ret)
+		goto out;
+
+	if (!ipvr_obj->sg_table) {
+		ret = -ENODATA;
+		goto out_unlock;
+	}
+
+	/* We don't use vmf->pgoff since that has the fake offset: */
+	pgoff = ((unsigned long)vmf->virtual_address -
+			vma->vm_start) >> PAGE_SHIFT;
+
+	pfn = page_to_pfn(ipvr_obj->pages[pgoff]);
+
+	IPVR_DEBUG_GENERAL("Inserting %p pfn %lx, pa %lx\n", vmf-
Quoted 1 line

virtual_address,

drivers/gpu/drm/ipvr/ipvr_bo.c new file +26 -0
+			pfn, pfn << PAGE_SHIFT);
+
+	ret = vm_insert_pfn(vma, (unsigned long)vmf->virtual_address, pfn);
+
+out_unlock:
+	mutex_unlock(&dev->struct_mutex);
+out:
+	switch (ret) {
+	case -EAGAIN:
+	case 0:
+	case -ERESTARTSYS:
+	case -EINTR:
+	case -EBUSY:
+		/*
+		 * EBUSY is ok: this just means that another thread
+		 * already did the job.
+		 */
+		return VM_FAULT_NOPAGE;
+	case -ENOMEM:
+		return VM_FAULT_OOM;
+	default:
+		return VM_FAULT_SIGBUS;
+	}
+}
+
+struct sg_table *ipvr_gem_prime_get_sg_table(struct drm_gem_object

*obj)

drivers/gpu/drm/ipvr/ipvr_bo.c new file +11 -0
+{
+	struct drm_ipvr_gem_object *ipvr_obj = to_ipvr_bo(obj);
+	struct sg_table *sgt = NULL;
+	int ret;
+
+	if (!ipvr_obj->sg_table) {
+		ret = -ENOENT;
+		goto out;
+	}
+
+	sgt = drm_prime_pages_to_sg(ipvr_obj->pages, obj->size >>

PAGE_SHIFT);

drivers/gpu/drm/ipvr/ipvr_bo.c new file +5 -0
+	if (IS_ERR(sgt)) {
+		goto out;
+	}
+
+	IPVR_DEBUG_GENERAL("exported sg_table for obj (mmu_offset

0x%lx)\n",

drivers/gpu/drm/ipvr/ipvr_bo.c new file +6 -0
+		ipvr_gem_object_mmu_offset(ipvr_obj));
+out:
+	return sgt;
+}
+
+struct drm_gem_object *ipvr_gem_prime_import_sg_table(struct

drm_device *dev,

drivers/gpu/drm/ipvr/ipvr_bo.c new file +20 -0
+		struct dma_buf_attachment *attach, struct sg_table *sg)
+{
+	struct drm_ipvr_gem_object *obj;
+	int ret = 0;
+	int i, npages;
+	unsigned long pfn;
+	struct drm_ipvr_private *dev_priv = dev->dev_private;
+
+	if (!sg || !attach || (attach->dmabuf->size & (PAGE_SIZE - 1)))
+		return ERR_PTR(-EINVAL);
+
+	IPVR_DEBUG_ENTRY("enter, size=0x%zx\n", attach->dmabuf->size);
+
+	obj = ipvr_object_alloc(dev_priv, attach->dmabuf->size);
+	if (!obj)
+		return ERR_PTR(-ENOMEM);
+
+	memset(obj, 0, sizeof(*obj));
+
+	drm_gem_private_object_init(dev, &obj->base, attach->dmabuf-
Quoted 1 line

size);

drivers/gpu/drm/ipvr/ipvr_bo.c new file +18 -0
+
+	init_waitqueue_head(&obj->event_queue);
+
+	obj->drv_name = "ipvr";
+	obj->fence = NULL;
+	obj->cache_level = IPVR_CACHE_UNCACHED;
+	obj->tiling = 0;
+
+	npages = attach->dmabuf->size >> PAGE_SHIFT;
+
+	obj->sg_table = sg;
+	obj->pages = drm_malloc_ab(npages, sizeof(struct page *));
+	if (!obj->pages) {
+		ret = -ENOMEM;
+		goto err_free_obj;
+	}
+
+	ret = drm_prime_sg_to_page_addr_arrays(sg, obj->pages, NULL,

npages);

drivers/gpu/drm/ipvr/ipvr_bo.c new file +18 -0
+	if (ret)
+		goto err_put_pages;
+
+	/* validate sg_table
+	 * should be under 4GiB
+	 */
+	for (i = 0; i < npages; ++i) {
+		pfn = page_to_pfn(obj->pages[i]);
+		if (pfn >= 0x00100000UL) {
+			IPVR_ERROR("cannot support pfn 0x%lx.\n", pfn);
+			ret = -EINVAL; /* what's the better err code? */
+			goto err_put_pages;
+		}
+	}
+
+	ret = ipvr_gem_bind_to_drm_mm(obj, &dev_priv->addr_space);
+	if (ret) {
+		IPVR_ERROR("failed to call

ipvr_gem_bind_to_drm_mm: %d.\n", ret);

drivers/gpu/drm/ipvr/ipvr_bo.c new file +8 -0
+		goto err_put_pages;
+	}
+
+	/* do we really have to set the external pages uncached?
+	 * this might causes perf issue in exporter side */
+	ret = set_pages_array_uc(obj->pages, npages);
+	if (ret)
+		IPVR_DEBUG_WARN("failed to set imported pages as

uncached: %d, ignore\n", ret);

drivers/gpu/drm/ipvr/ipvr_bo.c new file +4 -0
+
+	ret = ipvr_gem_mmu_bind_object(obj);
+	if (ret) {
+		IPVR_ERROR("failed to call

ipvr_gem_mmu_bind_object: %d.\n", ret);

drivers/gpu/drm/ipvr/ipvr_bo.c new file +3 -0
+		goto err_remove_node;
+	}
+	IPVR_DEBUG_GENERAL("imported sg_table, new bo mmu

offset=0x%lx.\n",

drivers/gpu/drm/ipvr/ipvr_bo.c new file +17 -0
+		ipvr_gem_object_mmu_offset(obj));
+	ipvr_stat_add_imported(dev_priv, obj);
+	ipvr_gem_object_pin_pages(obj);
+	return &obj->base;
+err_remove_node:
+	drm_mm_remove_node(&obj->mm_node);
+err_put_pages:
+	drm_free_large(obj->pages);
+err_free_obj:
+	ipvr_object_free(obj);
+	return ERR_PTR(ret);
+}
+
+int ipvr_gem_prime_pin(struct drm_gem_object *obj)
+{
+	struct drm_ipvr_private *dev_priv = obj->dev->dev_private;
+	IPVR_DEBUG_ENTRY("mmu offset 0x%lx\n",

ipvr_gem_object_mmu_offset(to_ipvr_bo(obj)));

drivers/gpu/drm/ipvr/ipvr_bo.c new file +8 -0
+	ipvr_stat_add_exported(dev_priv, to_ipvr_bo(obj));
+	return 0;
+}
+
+void ipvr_gem_prime_unpin(struct drm_gem_object *obj)
+{
+	struct drm_ipvr_private *dev_priv = obj->dev->dev_private;
+	IPVR_DEBUG_ENTRY("mmu offset 0x%lx\n",

ipvr_gem_object_mmu_offset(to_ipvr_bo(obj)));

drivers/gpu/drm/ipvr/ipvr_bo.c new file +2 -0
+	ipvr_stat_remove_exported(dev_priv, to_ipvr_bo(obj));
+}
drivers/gpu/drm/ipvr/ipvr_bo.h new file +1 -0
new file mode 100644
index 0000000..4981587
@@ -0,0 +1,80 @@
+/*********************************************************

*****************
+ * ipvr_bo.h: IPVR buffer creation/destory, import/export, map etc
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ipvr_bo.h new file +38 -0
+
+
+#ifndef _IPVR_BO_H_
+#define _IPVR_BO_H_
+
+#include "ipvr_drv.h"
+#include "ipvr_drm.h"
+#include "ipvr_fence.h"
+#include <drmP.h>
+#include <drm_gem.h>
+
+struct ipvr_fence;
+
+struct drm_ipvr_gem_object {
+	struct drm_gem_object base;
+
+	/* used to disinguish between i915 and ipvr */
+	char *drv_name;
+
+	/** MM related */
+	struct drm_mm_node mm_node;
+
+	bool tiling;
+
+	enum ipvr_cache_level cache_level;
+
+	bool dirty;
+
+	struct sg_table *sg_table;
+	struct page **pages;
+	int pages_pin_count;
+
+	struct ipvr_fence *fence;
+	atomic_t reserved;
+	wait_queue_head_t event_queue;
+};
+
+struct drm_ipvr_gem_object* ipvr_gem_create(struct drm_ipvr_private

*dev_priv,

drivers/gpu/drm/ipvr/ipvr_bo.h new file +7 -0
+			size_t size, u32 tiling, u32 cache_level);
+void ipvr_gem_free_object(struct drm_gem_object *obj);
+void *ipvr_gem_object_vmap(struct drm_ipvr_gem_object *obj);
+int ipvr_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
+int ipvr_gem_object_apply_reloc(struct drm_ipvr_gem_object *obj,
+			u64 offset_in_bo, u32 value);
+struct sg_table *ipvr_gem_prime_get_sg_table(struct drm_gem_object

*obj);
+struct drm_gem_object *ipvr_gem_prime_import_sg_table(struct drm_device *dev,

drivers/gpu/drm/ipvr/ipvr_bo.h new file +1 -0
+			struct dma_buf_attachment *attach, struct sg_table

*sg);

drivers/gpu/drm/ipvr/ipvr_bo.h new file +10 -0
+int ipvr_gem_prime_pin(struct drm_gem_object *obj);
+void ipvr_gem_prime_unpin(struct drm_gem_object *obj);
+
+static inline unsigned long
+ipvr_gem_object_mmu_offset(struct drm_ipvr_gem_object *obj)
+{
+	return obj->mm_node.start;
+}
+
+#endif
drivers/gpu/drm/ipvr/ipvr_debug.c new file +1 -0
new file mode 100644
index 0000000..c30a78a
@@ -0,0 +1,335 @@
+/*********************************************************

*****************
+ * ipvr_debug.c: IPVR debugfs support to assist bug triage
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ipvr_debug.c new file +20 -0
+
+#if defined(CONFIG_DEBUG_FS)
+
+#include "ipvr_debug.h"
+#include "ipvr_drv.h"
+#include "ved_reg.h"
+#include <linux/seq_file.h>
+#include <linux/debugfs.h>
+
+union ipvr_debugfs_vars debugfs_vars;
+
+static int ipvr_debug_info(struct seq_file *m, void *data)
+{
+	seq_printf(m, "ipvr platform\n");
+	return 0;
+}
+
+/* some bookkeeping */
+void
+ipvr_stat_add_object(struct drm_ipvr_private *dev_priv, struct

drm_ipvr_gem_object *obj)

drivers/gpu/drm/ipvr/ipvr_debug.c new file +9 -0
+{
+	spin_lock(&dev_priv->ipvr_stat.object_stat_lock);
+	dev_priv->ipvr_stat.allocated_count++;
+	dev_priv->ipvr_stat.allocated_memory += obj->base.size;
+	spin_unlock(&dev_priv->ipvr_stat.object_stat_lock);
+}
+
+void
+ipvr_stat_remove_object(struct drm_ipvr_private *dev_priv, struct

drm_ipvr_gem_object *obj)

drivers/gpu/drm/ipvr/ipvr_debug.c new file +9 -0
+{
+	spin_lock(&dev_priv->ipvr_stat.object_stat_lock);
+	dev_priv->ipvr_stat.allocated_count--;
+	dev_priv->ipvr_stat.allocated_memory -= obj->base.size;
+	spin_unlock(&dev_priv->ipvr_stat.object_stat_lock);
+}
+
+void
+ipvr_stat_add_imported(struct drm_ipvr_private *dev_priv, struct

drm_ipvr_gem_object *obj)

drivers/gpu/drm/ipvr/ipvr_debug.c new file +9 -0
+{
+	spin_lock(&dev_priv->ipvr_stat.object_stat_lock);
+	dev_priv->ipvr_stat.imported_count++;
+	dev_priv->ipvr_stat.imported_memory += obj->base.size;
+	spin_unlock(&dev_priv->ipvr_stat.object_stat_lock);
+}
+
+void
+ipvr_stat_remove_imported(struct drm_ipvr_private *dev_priv, struct

drm_ipvr_gem_object *obj)

drivers/gpu/drm/ipvr/ipvr_debug.c new file +9 -0
+{
+	spin_lock(&dev_priv->ipvr_stat.object_stat_lock);
+	dev_priv->ipvr_stat.imported_count--;
+	dev_priv->ipvr_stat.imported_memory -= obj->base.size;
+	spin_unlock(&dev_priv->ipvr_stat.object_stat_lock);
+}
+
+void
+ipvr_stat_add_exported(struct drm_ipvr_private *dev_priv, struct

drm_ipvr_gem_object *obj)

drivers/gpu/drm/ipvr/ipvr_debug.c new file +9 -0
+{
+	spin_lock(&dev_priv->ipvr_stat.object_stat_lock);
+	dev_priv->ipvr_stat.exported_count++;
+	dev_priv->ipvr_stat.exported_memory += obj->base.size;
+	spin_unlock(&dev_priv->ipvr_stat.object_stat_lock);
+}
+
+void
+ipvr_stat_remove_exported(struct drm_ipvr_private *dev_priv, struct

drm_ipvr_gem_object *obj)

drivers/gpu/drm/ipvr/ipvr_debug.c new file +8 -0
+{
+	spin_lock(&dev_priv->ipvr_stat.object_stat_lock);
+	dev_priv->ipvr_stat.exported_count--;
+	dev_priv->ipvr_stat.exported_memory -= obj->base.size;
+	spin_unlock(&dev_priv->ipvr_stat.object_stat_lock);
+}
+
+void ipvr_stat_add_mmu_bind(struct drm_ipvr_private *dev_priv, size_t

size)

drivers/gpu/drm/ipvr/ipvr_debug.c new file +7 -0
+{
+	spin_lock(&dev_priv->ipvr_stat.object_stat_lock);
+	dev_priv->ipvr_stat.mmu_used_size += size;
+	spin_unlock(&dev_priv->ipvr_stat.object_stat_lock);
+}
+
+void ipvr_stat_remove_mmu_bind(struct drm_ipvr_private *dev_priv,

size_t size)

drivers/gpu/drm/ipvr/ipvr_debug.c new file +101 -0
+{
+	spin_lock(&dev_priv->ipvr_stat.object_stat_lock);
+	dev_priv->ipvr_stat.mmu_used_size -= size;
+	spin_unlock(&dev_priv->ipvr_stat.object_stat_lock);
+}
+
+static int ipvr_debug_gem_object_info(struct seq_file *m, void* data)
+{
+	struct drm_info_node *node = (struct drm_info_node *) m->private;
+	struct drm_device *dev = node->minor->dev;
+	struct drm_ipvr_private *dev_priv = dev->dev_private;
+	int ret;
+
+	ret = mutex_lock_interruptible(&dev->struct_mutex);
+	if (ret)
+		return ret;
+
+	seq_printf(m, "total allocate %u objects, %zu bytes\n\n",
+		   dev_priv->ipvr_stat.allocated_count,
+		   dev_priv->ipvr_stat.allocated_memory);
+	seq_printf(m, "total imported %u objects, %zu bytes\n\n",
+		   dev_priv->ipvr_stat.imported_count,
+		   dev_priv->ipvr_stat.imported_memory);
+	seq_printf(m, "total exported %u objects, %zu bytes\n\n",
+		   dev_priv->ipvr_stat.exported_count,
+		   dev_priv->ipvr_stat.exported_memory);
+	seq_printf(m, "total used MMU size %zu bytes\n\n",
+		   dev_priv->ipvr_stat.mmu_used_size);
+
+	mutex_unlock(&dev->struct_mutex);
+
+	return 0;
+}
+
+static int ipvr_debug_gem_seqno_info(struct seq_file *m, void *data)
+{
+	struct drm_info_node *node = (struct drm_info_node *) m->private;
+	struct drm_device *dev = node->minor->dev;
+	drm_ipvr_private_t *dev_priv = dev->dev_private;
+	int ret;
+
+	ret = mutex_lock_interruptible(&dev->struct_mutex);
+	if (ret)
+		return ret;
+
+	seq_printf(m, "last signaled seq is %d, last emitted seq is %d\n",
+		atomic_read(&dev_priv->fence_drv.signaled_seq),
+		dev_priv->fence_drv.sync_seq);
+
+	mutex_unlock(&dev->struct_mutex);
+
+	return 0;
+}
+
+static ssize_t ipvr_debug_ved_reg_read(struct file *filp, char __user *ubuf,
+					size_t max, loff_t *ppos)
+{
+	struct drm_device *dev = filp->private_data;
+	drm_ipvr_private_t *dev_priv = dev->dev_private;
+	char buf[200], offset[20], operation[10], format[20], val[20];
+	int len = 0, ret, no_of_tokens;
+	unsigned long reg_offset, reg_to_write;
+
+	if (debugfs_vars.reg.reg_input == 0)
+		return len;
+
+	snprintf(format, sizeof(format), "%%%zus %%%zus %%%zus",
+			sizeof(operation), sizeof(offset), sizeof(val));
+
+	no_of_tokens = sscanf(debugfs_vars.reg.reg_vars,
+					format, operation, offset, val);
+
+	if (no_of_tokens < 3)
+		return len;
+
+	len = sizeof(debugfs_vars.reg.reg_vars);
+
+	if (strcmp(operation, IPVR_READ_TOKEN) == 0) {
+		ret = kstrtoul(offset, 16, &reg_offset);
+		if (ret)
+			return -EINVAL;
+
+		len = scnprintf(buf, sizeof(buf), "0x%x: 0x%x\n",
+			(u32)reg_offset,
+			IPVR_REG_READ32((u32)reg_offset));
+	} else if (strcmp(operation, IPVR_WRITE_TOKEN) == 0) {
+		ret = kstrtoul(offset, 16, &reg_offset);
+		if (ret)
+			return -EINVAL;
+
+		ret = kstrtoul(val, 16, &reg_to_write);
+		if (ret)
+			return -EINVAL;
+
+		IPVR_REG_WRITE32(reg_offset, reg_to_write);
+		len = scnprintf(buf, sizeof(buf),
+				"0x%x: 0x%x\n",
+				(u32)reg_offset,
+				(u32)IPVR_REG_READ32(reg_offset));
+	} else {
+		len = scnprintf(buf, sizeof(buf), "Operation Not

Supported\n");

drivers/gpu/drm/ipvr/ipvr_debug.c new file +15 -0
+	}
+
+	debugfs_vars.reg.reg_input = 0;
+
+	simple_read_from_buffer(ubuf, max, ppos, buf, len);
+
+	return len;
+}
+
+static ssize_t
+ipvr_debug_ved_reg_write(struct file *filp,const char __user *ubuf,
+			size_t cnt, loff_t *ppos)
+{
+	/* reset the string */
+	memset(debugfs_vars.reg.reg_vars, 0,

IPVR_MAX_BUFFER_STR_LEN);

drivers/gpu/drm/ipvr/ipvr_debug.c new file +18 -0
+
+	if (cnt > 0) {
+		if (cnt > sizeof(debugfs_vars.reg.reg_vars) - 1)
+			return -EINVAL;
+
+		if (copy_from_user(debugfs_vars.reg.reg_vars, ubuf, cnt))
+			return -EFAULT;
+
+		debugfs_vars.reg.reg_vars[cnt] = 0;
+
+		/* Enable Read */
+		debugfs_vars.reg.reg_input = 1;
+	}
+
+	return cnt;
+}
+
+/* As the drm_debugfs_init() routines are called before dev->dev_private

is
+ * allocated we need to hook into the minor for release. */

drivers/gpu/drm/ipvr/ipvr_debug.c new file +96 -0
+static int ipvr_add_fake_info_node(struct drm_minor *minor,
+					struct dentry *ent, const void *key)
+{
+	struct drm_info_node *node;
+
+	node = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL);
+	if (node == NULL) {
+		debugfs_remove(ent);
+		return -ENOMEM;
+	}
+
+	node->minor = minor;
+	node->dent = ent;
+	node->info_ent = (void *) key;
+
+	mutex_lock(&minor->debugfs_lock);
+	list_add(&node->list, &minor->debugfs_list);
+	mutex_unlock(&minor->debugfs_lock);
+
+	return 0;
+}
+
+static int ipvr_debugfs_create(struct dentry *root,
+			       struct drm_minor *minor,
+			       const char *name,
+			       const struct file_operations *fops)
+{
+	struct drm_device *dev = minor->dev;
+	struct dentry *ent;
+
+	ent = debugfs_create_file(name,
+				  S_IRUGO | S_IWUSR,
+				  root, dev,
+				  fops);
+	if (IS_ERR(ent))
+		return PTR_ERR(ent);
+
+	return ipvr_add_fake_info_node(minor, ent, fops);
+}
+
+static const struct file_operations ipvr_ved_reg_fops = {
+	.owner = THIS_MODULE,
+	.open = simple_open,
+	.read = ipvr_debug_ved_reg_read,
+	.write = ipvr_debug_ved_reg_write,
+	.llseek = default_llseek,
+};
+
+static struct drm_info_list ipvr_debugfs_list[] = {
+	{"ipvr_capabilities", ipvr_debug_info, 0},
+	{"ipvr_gem_objects", ipvr_debug_gem_object_info, 0},
+	{"ipvr_gem_seqno", ipvr_debug_gem_seqno_info, 0},
+
+};
+#define IPVR_DEBUGFS_ENTRIES ARRAY_SIZE(ipvr_debugfs_list)
+
+static struct ipvr_debugfs_files {
+	const char *name;
+	const struct file_operations *fops;
+} ipvr_debugfs_files[] = {
+	{"ipvr_ved_reg_api", &ipvr_ved_reg_fops},
+};
+
+int ipvr_debugfs_init(struct drm_minor *minor)
+{
+	int ret, i;
+
+	for (i = 0; i < ARRAY_SIZE(ipvr_debugfs_files); i++) {
+		ret = ipvr_debugfs_create(minor->debugfs_root, minor,
+				   ipvr_debugfs_files[i].name,
+				   ipvr_debugfs_files[i].fops);
+		if (ret)
+			return ret;
+	}
+
+	return drm_debugfs_create_files(ipvr_debugfs_list,
+				 IPVR_DEBUGFS_ENTRIES,
+				 minor->debugfs_root, minor);
+}
+
+void ipvr_debugfs_cleanup(struct drm_minor *minor)
+{
+	int i;
+
+	drm_debugfs_remove_files(ipvr_debugfs_list,
+			  IPVR_DEBUGFS_ENTRIES, minor);
+
+	for (i = 0; i < ARRAY_SIZE(ipvr_debugfs_files); i++) {
+		struct drm_info_list *info_list =
+			(struct drm_info_list *)ipvr_debugfs_files[i].fops;
+
+		drm_debugfs_remove_files(info_list, 1, minor);
+	}
+}
+
+#endif /* CONFIG_DEBUG_FS */
drivers/gpu/drm/ipvr/ipvr_debug.h new file +1 -0
new file mode 100644
index 0000000..a88382e
@@ -0,0 +1,76 @@
+/*********************************************************

*****************
+ * ipvr_debug.h: IPVR debugfs support header file
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ipvr_debug.h new file +52 -0
+
+
+#ifndef _IPVR_DEBUG_H_
+#define _IPVR_DEBUG_H_
+
+#include "ipvr_bo.h"
+#include "drmP.h"
+
+/* Operations supported */
+#define IPVR_MAX_BUFFER_STR_LEN		200
+
+#define IPVR_READ_TOKEN			"READ"
+#define IPVR_WRITE_TOKEN		"WRITE"
+
+/* DebugFS Variable declaration */
+struct ipvr_debugfs_reg_vars {
+	char reg_vars[IPVR_MAX_BUFFER_STR_LEN];
+	u32 reg_input;
+};
+
+union ipvr_debugfs_vars {
+	struct ipvr_debugfs_reg_vars reg;
+};
+
+int ipvr_debugfs_init(struct drm_minor *minor);
+void ipvr_debugfs_cleanup(struct drm_minor *minor);
+
+void ipvr_stat_add_object(struct drm_ipvr_private *dev_priv,
+			struct drm_ipvr_gem_object *obj);
+
+void ipvr_stat_remove_object(struct drm_ipvr_private *dev_priv,
+			struct drm_ipvr_gem_object *obj);
+
+void ipvr_stat_add_imported(struct drm_ipvr_private *dev_priv,
+			struct drm_ipvr_gem_object *obj);
+
+void ipvr_stat_remove_imported(struct drm_ipvr_private *dev_priv,
+			struct drm_ipvr_gem_object *obj);
+
+void ipvr_stat_add_exported(struct drm_ipvr_private *dev_priv,
+			struct drm_ipvr_gem_object *obj);
+
+void ipvr_stat_remove_exported(struct drm_ipvr_private *dev_priv,
+			struct drm_ipvr_gem_object *obj);
+
+void ipvr_stat_add_mmu_bind(struct drm_ipvr_private *dev_priv,
+			size_t size);
+
+void ipvr_stat_remove_mmu_bind(struct drm_ipvr_private *dev_priv,
+			size_t size);
+
+#endif
drivers/gpu/drm/ipvr/ipvr_drm.h new file +1 -0
new file mode 100644
index 0000000..fade9a3
@@ -0,0 +1,259 @@
+/*********************************************************

*****************
+ * ipvr_drm.h: IPVR header file exported to user space
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ipvr_drm.h new file +3 -0
+
+
+/* this file only define structs and macro which need export to user space

*/

drivers/gpu/drm/ipvr/ipvr_drm.h new file +95 -0
+#ifndef _IPVR_DRM_H_
+#define _IPVR_DRM_H_
+
+#include <drm/drm.h>
+struct drm_ipvr_context_create {
+	/* passed ctx_info, including codec, profile info */
+#define IPVR_CONTEXT_TYPE_VED   (0x1)
+	__u32 ctx_type;
+	/* returned back ctx_id */
+	__u32 ctx_id;
+	/*
+	 * following tiling strides for VED are supported:
+	 * stride 0: 512 for scheme 0, 1024 for scheme 1
+	 * stride 1: 1024 for scheme 0, 2048 for scheme 1
+	 * stride 2: 2048 for scheme 0, 4096 for scheme 1
+	 * stride 3: 4096 for scheme 0
+	 */
+	__u32 tiling_stride;
+	/*
+	 * scheme 0: tile is 256x16, while minimal tile stride is 512
+	 * scheme 1: tile is 512x8, while minimal tile stride is 1024
+	 */
+	__u32 tiling_scheme;
+};
+
+struct drm_ipvr_context_destroy {
+	__u32 ctx_id;
+	__u32 pad64;
+};
+
+/* ioctl used for querying info from driver */
+enum drm_ipvr_misc_key {
+	IPVR_DEVICE_INFO,
+};
+struct drm_ipvr_get_info {
+	__u64 key;
+	__u64 value;
+};
+
+struct drm_ipvr_gem_relocation_entry {
+	/**
+	 * Handle of the buffer being pointed to by this relocation entry.
+	 *
+	 * It's appealing to make this be an index into the mm_validate_entry
+	 * list to refer to the buffer, but this allows the driver to create
+	 * a relocation list for state buffers and not re-write it per
+	 * exec using the buffer.
+	 */
+	__u32 target_handle;
+
+	/**
+	 * Value to be added to the offset of the target buffer to make up
+	 * the relocation entry.
+	 */
+	__u32 delta;
+
+	/** Offset in the buffer the relocation entry will be written into */
+	__u64 offset;
+
+	/**
+	 * Offset value of the target buffer that the relocation entry was last
+	 * written as.
+	 *
+	 * If the buffer has the same offset as last time, we can skip syncing
+	 * and writing the relocation.  This value is written back out by
+	 * the execbuffer ioctl when the relocation is written.
+	 */
+	__u64 presumed_offset;
+
+	/**
+	 * Target memory domains read by this operation.
+	 */
+	__u32 read_domains;
+
+	/**
+	 * Target memory domains written by this operation.
+	 *
+	 * Note that only one domain may be written by the whole
+	 * execbuffer operation, so that where there are conflicts,
+	 * the application will get -EINVAL back.
+	 */
+	__u32 write_domain;
+};
+
+struct drm_ipvr_gem_exec_object {
+	/**
+	 * User's handle for a buffer to be bound into the MMU for this
+	 * operation.
+	 */
+	__u32 handle;
+
+	/** Number of relocations to be performed on this buffer */
+	__u32 relocation_count;
+	/**
+	 * Pointer to array of struct drm_i915_gem_relocation_entry

containing

drivers/gpu/drm/ipvr/ipvr_drm.h new file +121 -0
+	 * the relocations to be performed in this buffer.
+	 */
+	__u64 relocs_ptr;
+
+	/** Required alignment in graphics aperture */
+	__u64 alignment;
+
+	/**
+	 * Returned value of the updated offset of the object, for future
+	 * presumed_offset writes.
+	 */
+	__u64 offset;
+
+#define IPVR_EXEC_OBJECT_NEED_FENCE (1 << 0)
+#define IPVR_EXEC_OBJECT_SUBMIT     (1 << 1)
+	__u64 flags;
+
+	__u64 rsvd1;
+	__u64 rsvd2;
+};
+
+struct drm_ipvr_gem_execbuffer {
+	/**
+	 * List of gem_exec_object2 structs
+	 */
+	__u64 buffers_ptr;
+	__u32 buffer_count;
+
+	/** Offset in the batchbuffer to start execution from. */
+	__u32 exec_start_offset;
+	/** Bytes used in batchbuffer from batch_start_offset */
+	__u32 exec_len;
+
+	/**
+	 * ID of hardware context.
+	 */
+	__u32 ctx_id;
+
+	__u64 flags;
+	__u64 rsvd1;
+	__u64 rsvd2;
+};
+
+enum ipvr_cache_level
+{
+	IPVR_CACHE_UNCACHED,
+	IPVR_CACHE_WRITEBACK,
+	IPVR_CACHE_WRITECOMBINE,
+	IPVR_CACHE_MAX,
+};
+
+struct drm_ipvr_gem_create {
+	/*
+	 * Requested size for the object.
+	 * The (page-aligned) allocated size for the object will be returned.
+	 */
+	__u64 size;
+	__u64 rounded_size;
+	__u64 mmu_offset;
+	/*
+	 * Returned handle for the object.
+	 * Object handles are nonzero.
+	 */
+	__u32 handle;
+	__u32 tiling;
+
+	__u32 cache_level;
+	__u32 pad64;
+	/*
+	 * Handle used for user to mmap BO
+	 */
+	__u64 map_offset;
+};
+
+struct drm_ipvr_gem_busy {
+	/* Handle of the buffer to check for busy */
+	__u32 handle;
+
+	/*
+	 * Return busy status (1 if busy, 0 if idle).
+	 * The high word is used to indicate on which rings the object
+	 * currently resides:
+	 *  16:31 - busy (r or r/w) rings (16 render, 17 bsd, 18 blt, etc)
+	 */
+	__u32 busy;
+};
+
+struct drm_ipvr_gem_mmap_offset {
+	/** Handle for the object being mapped. */
+	__u32 handle;
+	__u32 pad64;
+	/**
+	 * Fake offset to use for subsequent mmap call
+	 *
+	 * This is a fixed-size type for 32/64 compatibility.
+	 */
+	__u64 offset;
+};
+
+struct drm_ipvr_gem_wait {
+	/* Handle of BO we shall wait on */
+	__u32 handle;
+	__u32 flags;
+	/** Number of nanoseconds to wait, Returns time remaining. */
+	__s64 timeout_ns;
+};
+
+/*
+ * IPVR GEM specific ioctls
+ */
+#define DRM_IPVR_CONTEXT_CREATE     0x00
+#define DRM_IPVR_CONTEXT_DESTROY    0x01
+#define DRM_IPVR_GET_INFO           0x02
+#define DRM_IPVR_GEM_EXECBUFFER     0x03
+#define DRM_IPVR_GEM_BUSY           0x04
+#define DRM_IPVR_GEM_CREATE         0x05
+#define DRM_IPVR_GEM_WAIT           0x06
+#define DRM_IPVR_GEM_MMAP_OFFSET    0x07
+
+#define DRM_IOCTL_IPVR_CONTEXT_CREATE	\
+	DRM_IOWR(DRM_COMMAND_BASE +

DRM_IPVR_CONTEXT_CREATE, struct drm_ipvr_context_create)

drivers/gpu/drm/ipvr/ipvr_drm.h new file +2 -0
+#define DRM_IOCTL_IPVR_CONTEXT_DESTROY	\
+	DRM_IOW(DRM_COMMAND_BASE +

DRM_IPVR_CONTEXT_DESTROY, struct drm_ipvr_context_destroy)

drivers/gpu/drm/ipvr/ipvr_drm.h new file +2 -0
+#define DRM_IOCTL_IPVR_GET_INFO		\
+	DRM_IOWR(DRM_COMMAND_BASE + DRM_IPVR_GET_INFO, struct

drm_ipvr_get_info)

drivers/gpu/drm/ipvr/ipvr_drm.h new file +2 -0
+#define DRM_IOCTL_IPVR_GEM_EXECBUFFER	\
+	DRM_IOWR(DRM_COMMAND_BASE +

DRM_IPVR_GEM_EXECBUFFER, struct drm_ipvr_gem_execbuffer)

drivers/gpu/drm/ipvr/ipvr_drm.h new file +2 -0
+#define DRM_IOCTL_IPVR_GEM_BUSY		\
+	DRM_IOWR(DRM_COMMAND_BASE + DRM_IPVR_GEM_BUSY,

struct drm_ipvr_gem_busy)

drivers/gpu/drm/ipvr/ipvr_drm.h new file +2 -0
+#define DRM_IOCTL_IPVR_GEM_CREATE	\
+	DRM_IOWR(DRM_COMMAND_BASE + DRM_IPVR_GEM_CREATE,

struct drm_ipvr_gem_create)

drivers/gpu/drm/ipvr/ipvr_drm.h new file +2 -0
+#define DRM_IOCTL_IPVR_GEM_WAIT		\
+	DRM_IOWR(DRM_COMMAND_BASE + DRM_IPVR_GEM_WAIT,

struct drm_ipvr_gem_wait)

drivers/gpu/drm/ipvr/ipvr_drm.h new file +2 -0
+#define DRM_IOCTL_IPVR_GEM_MMAP_OFFSET	\
+	DRM_IOWR(DRM_COMMAND_BASE +

DRM_IPVR_GEM_MMAP_OFFSET, struct drm_ipvr_gem_mmap_offset)

drivers/gpu/drm/ipvr/ipvr_drm.h new file +2 -0
+
+#endif
drivers/gpu/drm/ipvr/ipvr_drv.c new file +1 -0
new file mode 100644
index 0000000..29ffe39
@@ -0,0 +1,617 @@
+/*********************************************************

*****************
+ * ipvr_drv.c: IPVR driver common file for initialization/de-initialization
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ipvr_drv.c new file +30 -0
+
+#include "ipvr_drv.h"
+#include "ipvr_gem.h"
+#include "ipvr_mmu.h"
+#include "ipvr_exec.h"
+#include "ipvr_bo.h"
+#include "ipvr_debug.h"
+#include "ipvr_trace.h"
+#include "ved_fw.h"
+#include "ved_pm.h"
+#include "ved_reg.h"
+#include "ved_cmd.h"
+#include <linux/device.h>
+#include <linux/version.h>
+#include <uapi/drm/drm.h>
+#include <linux/pm_runtime.h>
+#include <linux/console.h>
+#include <linux/module.h>
+#include <asm/uaccess.h>
+
+int drm_ipvr_debug = 0x80;
+int drm_ipvr_freq = 320;
+
+module_param_named(debug, drm_ipvr_debug, int, 0600);
+module_param_named(freq, drm_ipvr_freq, int, 0600);
+
+MODULE_PARM_DESC(debug,
+		"control debug info output"
+		"default: 0"
+		"0x01:IPVR_D_GENERAL, 0x02:IPVR_D_INIT,

0x04:IPVR_D_IRQ, 0x08:IPVR_D_ENTRY"

drivers/gpu/drm/ipvr/ipvr_drv.c new file +1 -0
+		"0x10:IPVR_D_PM, 0x20:IPVR_D_REG, 0x40:IPVR_D_VED,

0x80:IPVR_D_WARN");

drivers/gpu/drm/ipvr/ipvr_drv.c new file +7 -0
+MODULE_PARM_DESC(freq,
+		"prefered VED frequency"
+		"default: 320 MHz");
+
+static struct drm_ioctl_desc ipvr_gem_ioctls[] = {
+	DRM_IOCTL_DEF_DRV(IPVR_CONTEXT_CREATE,
+			ipvr_context_create_ioctl,

DRM_AUTH|DRM_UNLOCKED),

drivers/gpu/drm/ipvr/ipvr_drv.c new file +2 -0
+	DRM_IOCTL_DEF_DRV(IPVR_CONTEXT_DESTROY,
+			ipvr_context_destroy_ioctl,

DRM_AUTH|DRM_UNLOCKED),

drivers/gpu/drm/ipvr/ipvr_drv.c new file +4 -0
+	DRM_IOCTL_DEF_DRV(IPVR_GET_INFO,
+			ipvr_get_info_ioctl, DRM_AUTH|DRM_UNLOCKED),
+	DRM_IOCTL_DEF_DRV(IPVR_GEM_EXECBUFFER,
+			ipvr_gem_execbuffer_ioctl,

DRM_AUTH|DRM_UNLOCKED),

drivers/gpu/drm/ipvr/ipvr_drv.c new file +4 -0
+	DRM_IOCTL_DEF_DRV(IPVR_GEM_BUSY,
+			ipvr_gem_busy_ioctl, DRM_AUTH|DRM_UNLOCKED),
+	DRM_IOCTL_DEF_DRV(IPVR_GEM_CREATE,
+			ipvr_gem_create_ioctl,

DRM_AUTH|DRM_UNLOCKED),

drivers/gpu/drm/ipvr/ipvr_drv.c new file +4 -0
+	DRM_IOCTL_DEF_DRV(IPVR_GEM_WAIT,
+			ipvr_gem_wait_ioctl, DRM_AUTH|DRM_UNLOCKED),
+	DRM_IOCTL_DEF_DRV(IPVR_GEM_MMAP_OFFSET,
+			ipvr_gem_mmap_offset_ioctl,

DRM_AUTH|DRM_UNLOCKED),

drivers/gpu/drm/ipvr/ipvr_drv.c new file +49 -0
+};
+
+static void ipvr_gem_init(struct drm_device *dev)
+{
+	struct drm_ipvr_private *dev_priv = dev->dev_private;
+
+	dev_priv->ipvr_bo_slab = kmem_cache_create("ipvr_gem_object",
+				  sizeof(struct drm_ipvr_gem_object), 0,
+				  SLAB_HWCACHE_ALIGN, NULL);
+
+	spin_lock_init(&dev_priv->ipvr_stat.object_stat_lock);
+	dev_priv->ipvr_stat.interruptible = true;
+}
+
+static void ipvr_gem_setup_mmu(struct drm_device *dev,
+				       unsigned long linear_start,
+				       unsigned long linear_end,
+				       unsigned long tiling_start,
+				       unsigned long tiling_end)
+{
+	/* Let GEM Manage all of the aperture.
+	 */
+	struct drm_ipvr_private *dev_priv = dev->dev_private;
+	struct ipvr_address_space *addr_space = &dev_priv->addr_space;
+
+	addr_space->dev = dev_priv->dev;
+
+	/* Subtract the guard page ... */
+	drm_mm_init(&addr_space->linear_mm, linear_start,
+		    linear_end - linear_start - PAGE_SIZE);
+	dev_priv->addr_space.linear_start = linear_start;
+	dev_priv->addr_space.linear_total = linear_end - linear_start;
+
+	drm_mm_init(&addr_space->tiling_mm, tiling_start,
+		    tiling_end - tiling_start - PAGE_SIZE);
+	dev_priv->addr_space.tiling_start = tiling_start;
+	dev_priv->addr_space.tiling_total = tiling_end - tiling_start;
+}
+
+int ipvr_runtime_pm_get(struct drm_ipvr_private *dev_priv)
+{
+	int ret = 0;
+	int pending;
+	unsigned long irq_flags;
+	struct platform_device *platdev = dev_priv->dev->platformdev;
+	BUG_ON(!platdev);
+	BUG_ON(atomic_read(&dev_priv->pending_events) < 0);
+	spin_lock_irqsave(&dev_priv->power_usage_lock, irq_flags);
+	if ((pending = atomic_inc_return(&dev_priv->pending_events)) == 1)

{

drivers/gpu/drm/ipvr/ipvr_drv.c new file +4 -0
+		do {
+			ret = pm_runtime_get_sync(&platdev->dev);
+			if (ret == -EAGAIN) {
+
	IPVR_DEBUG_WARN("pm_runtime_get_sync returns EAGAIN\n");
drivers/gpu/drm/ipvr/ipvr_drv.c new file +3 -0
+			}
+			else if (ret < 0) {
+				IPVR_ERROR("pm_runtime_get_sync

returns %d\n", ret);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +1 -0
+				pending = atomic_dec_return(&dev_priv-
Quoted 1 line

pending_events);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +4 -0
+			}
+		} while (ret == -EAGAIN);
+	}
+	trace_ipvr_get_power(atomic_read(&platdev-
Quoted 1 line

dev.power.usage_count),

drivers/gpu/drm/ipvr/ipvr_drv.c new file +15 -0
+		pending);
+	spin_unlock_irqrestore(&dev_priv->power_usage_lock, irq_flags);
+	return ret;
+}
+
+int ipvr_runtime_pm_put(struct drm_ipvr_private *dev_priv, bool async)
+{
+	int ret = 0;
+	int pending;
+	unsigned long irq_flags;
+	struct platform_device *platdev = dev_priv->dev->platformdev;
+	BUG_ON(!platdev);
+	BUG_ON(atomic_read(&dev_priv->pending_events) <= 0);
+	spin_lock_irqsave(&dev_priv->power_usage_lock, irq_flags);
+	if ((pending = atomic_dec_return(&dev_priv->pending_events)) ==

0) {

drivers/gpu/drm/ipvr/ipvr_drv.c new file +7 -0
+		do {
+			if (async)
+				ret = pm_runtime_put(&platdev->dev);
+			else
+				ret = pm_runtime_put_sync(&platdev->dev);
+			if (ret == -EAGAIN)
+				IPVR_DEBUG_WARN("pm_runtime_put

returns EAGAIN\n");

drivers/gpu/drm/ipvr/ipvr_drv.c new file +2 -0
+			else if (ret < 0)
+				IPVR_ERROR("pm_runtime_put

returns %d\n", ret);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +3 -0
+		} while (ret == -EAGAIN);
+	}
+	trace_ipvr_put_power(atomic_read(&platdev-
Quoted 1 line

dev.power.usage_count),

drivers/gpu/drm/ipvr/ipvr_drv.c new file +6 -0
+		pending);
+	spin_unlock_irqrestore(&dev_priv->power_usage_lock, irq_flags);
+	return ret;
+}
+
+int ipvr_runtime_pm_put_all(struct drm_ipvr_private *dev_priv, bool

async)

drivers/gpu/drm/ipvr/ipvr_drv.c new file +15 -0
+{
+	int ret = 0;
+	unsigned long irq_flags;
+	struct platform_device *platdev = dev_priv->dev->platformdev;
+	BUG_ON(!platdev);
+	spin_lock_irqsave(&dev_priv->power_usage_lock, irq_flags);
+	if (atomic_read(&dev_priv->pending_events) > 0) {
+		atomic_set(&dev_priv->pending_events, 0);
+		do {
+			if (async)
+				ret = pm_runtime_put(&platdev->dev);
+			else
+				ret = pm_runtime_put_sync(&platdev->dev);
+			if (ret == -EAGAIN)
+				IPVR_DEBUG_WARN("pm_runtime_put

returns EAGAIN\n");

drivers/gpu/drm/ipvr/ipvr_drv.c new file +2 -0
+			else if (ret < 0)
+				IPVR_ERROR("pm_runtime_put

returns %d\n", ret);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +3 -0
+		} while (ret == -EAGAIN);
+	}
+	trace_ipvr_put_power(atomic_read(&platdev-
Quoted 1 line

dev.power.usage_count),

drivers/gpu/drm/ipvr/ipvr_drv.c new file +21 -0
+		0);
+	spin_unlock_irqrestore(&dev_priv->power_usage_lock, irq_flags);
+	return ret;
+}
+
+static int ipvr_drm_unload(struct drm_device *dev)
+{
+	struct drm_ipvr_private *dev_priv = dev->dev_private;
+	IPVR_DEBUG_ENTRY("entered.");
+	BUG_ON(!dev->platformdev);
+
+	if (dev_priv) {
+		if (dev_priv->ipvr_bo_slab)
+			kmem_cache_destroy(dev_priv->ipvr_bo_slab);
+		ipvr_fence_driver_fini(dev_priv);
+
+		if (WARN_ON(ipvr_runtime_pm_get(dev_priv) < 0))
+			IPVR_DEBUG_WARN("Error getting ipvr power\n");
+		else {
+			ved_core_deinit(dev_priv);
+			if (WARN_ON(ipvr_runtime_pm_put_all(dev_priv,

false) < 0))

drivers/gpu/drm/ipvr/ipvr_drv.c new file +1 -0
+				IPVR_DEBUG_WARN("Error getting ipvr

power\n");

drivers/gpu/drm/ipvr/ipvr_drv.c new file +16 -0
+		}
+		if (dev_priv->validate_ctx.buffers)
+			vfree(dev_priv->validate_ctx.buffers);
+
+		if (dev_priv->mmu) {
+			ipvr_mmu_driver_takedown(dev_priv->mmu);
+			dev_priv->mmu = NULL;
+		}
+
+		if (dev_priv->reg_base) {
+			iounmap(dev_priv->reg_base);
+			dev_priv->reg_base = NULL;
+		}
+
+		list_del(&dev_priv->default_ctx.head);
+		idr_remove(&dev_priv->ipvr_ctx_idr, dev_priv-
Quoted 1 line

default_ctx.ctx_id);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +41 -0
+		kfree(dev_priv);
+
+	}
+	pm_runtime_disable(&dev->platformdev->dev);
+
+	return 0;
+}
+
+static int ipvr_drm_load(struct drm_device *dev, unsigned long flags)
+{
+	struct drm_ipvr_private *dev_priv;
+	u32 ctx_id;
+	int ret = 0;
+	struct resource *res_mmio;
+	void __iomem* mmio_start;
+
+	if (!dev->platformdev)
+		return -ENODEV;
+
+	dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
+	if (dev_priv == NULL)
+		return -ENOMEM;
+
+	dev->dev_private = dev_priv;
+	dev_priv->dev = dev;
+
+	INIT_LIST_HEAD(&dev_priv->validate_ctx.validate_list);
+
+	dev_priv->pci_root = pci_get_bus_and_slot(0, PCI_DEVFN(0, 0));
+	if (!dev_priv->pci_root) {
+		kfree(dev_priv);
+		return -ENODEV;
+	}
+
+	dev->irq = platform_get_irq(dev->platformdev, 0);
+	if (dev->irq < 0) {
+		kfree(dev_priv);
+		return -ENODEV;
+	}
+
+	res_mmio = platform_get_resource(dev->platformdev,

IORESOURCE_MEM, 0);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +29 -0
+	if (!res_mmio) {
+		kfree(dev_priv);
+		return -ENXIO;
+	}
+
+	mmio_start = ioremap_nocache(res_mmio->start,
+					res_mmio->end - res_mmio->start);
+	if (!mmio_start) {
+		kfree(dev_priv);
+		return -EACCES;
+	}
+
+	dev_priv->reg_base = mmio_start;
+	IPVR_DEBUG_VED("reg_base is %p - 0x%p.\n",
+		dev_priv->reg_base,
+		dev_priv->reg_base + (res_mmio->end - res_mmio->start));
+
+	atomic_set(&dev_priv->pending_events, 0);
+	spin_lock_init(&dev_priv->power_usage_lock);
+	pm_runtime_enable(&dev->platformdev->dev);
+	if (WARN_ON(ipvr_runtime_pm_get(dev_priv) < 0)) {
+		IPVR_ERROR("Error getting ipvr power\n");
+		ret = -EBUSY;
+		goto out_err;
+	}
+
+	IPVR_DEBUG_INIT("MSVDX_CORE_REV_OFFSET by readl is 0x%x.\n",
+		readl(dev_priv->reg_base + 0x640));
+	IPVR_DEBUG_INIT("MSVDX_CORE_REV_OFFSET by

VED_REG_READ32 is 0x%x.\n",

drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+		IPVR_REG_READ32(MSVDX_CORE_REV_OFFSET));
+
+	/* mmu init */
+	dev_priv->mmu = ipvr_mmu_driver_init(NULL, 0, dev_priv);
+	if (!dev_priv->mmu) {
+		ret = -EBUSY;
+		goto out_err;
+	}
+
+	ipvr_mmu_set_pd_context(ipvr_mmu_get_default_pd(dev_priv-
Quoted 1 line

mmu), 0);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +102 -0
+
+	/*
+	 * Initialize sequence numbers for the different command
+	 * submission mechanisms.
+	 */
+	dev_priv->last_seq = 1;
+
+	ipvr_gem_init(dev);
+
+	ipvr_gem_setup_mmu(dev,
+		IPVR_MEM_MMU_LINEAR_START,
+		IPVR_MEM_MMU_LINEAR_END,
+		IPVR_MEM_MMU_TILING_START,
+		IPVR_MEM_MMU_TILING_END);
+
+	ved_core_init(dev_priv);
+
+	if (WARN_ON(ipvr_runtime_pm_put(dev_priv, false) < 0))
+		IPVR_DEBUG_WARN("Error putting ipvr power\n");
+
+	dev_priv->ved_private->ved_needs_reset = 1;
+
+	ipvr_fence_driver_init(dev_priv);
+
+	dev_priv->validate_ctx.buffers =
+		vmalloc(IPVR_NUM_VALIDATE_BUFFERS *
+			sizeof(struct ipvr_validate_buffer));
+	if (!dev_priv->validate_ctx.buffers) {
+		ret = -ENOMEM;
+		goto out_err;
+	}
+
+	/* ipvr context initialization */
+	spin_lock_init(&dev_priv->ipvr_ctx_lock);
+	idr_init(&dev_priv->ipvr_ctx_idr);
+	/* default ipvr context is used for scaling, rotation case */
+	ctx_id = idr_alloc(&dev_priv->ipvr_ctx_idr, &dev_priv->default_ctx,
+			   IPVR_MIN_CONTEXT_ID, IPVR_MAX_CONTEXT_ID,
+			   GFP_NOWAIT);
+	if (ctx_id < 0) {
+		return -ENOMEM;
+		goto out_err;
+	}
+	dev_priv->default_ctx.ctx_id = ctx_id;
+	INIT_LIST_HEAD(&dev_priv->default_ctx.head);
+	dev_priv->default_ctx.ctx_type = 0;
+	dev_priv->default_ctx.ipvr_fpriv = NULL;
+
+	/* don't need protect with spinlock during module load stage */
+	dev_priv->default_ctx.tiling_scheme = 0;
+	dev_priv->default_ctx.tiling_stride = 0;
+
+	return 0;
+out_err:
+	ipvr_drm_unload(dev);
+	return ret;
+}
+
+/*
+ * The .open() method is called every time the device is opened by an
+ * application. Drivers can allocate per-file private data in this method and
+ * store them in the struct drm_file::driver_priv field. Note that the .open()
+ * method is called before .firstopen().
+ */
+static int
+ipvr_drm_open(struct drm_device *dev, struct drm_file *file_priv)
+{
+	struct drm_ipvr_file_private *ipvr_fp;
+	IPVR_DEBUG_ENTRY("enter\n");
+
+	ipvr_fp = kzalloc(sizeof(*ipvr_fp), GFP_KERNEL);
+	if (!ipvr_fp)
+		return -ENOMEM;
+
+	file_priv->driver_priv = ipvr_fp;
+	INIT_LIST_HEAD(&ipvr_fp->ctx_list);
+	return 0;
+}
+
+/*
+ * The close operation is split into .preclose() and .postclose() methods.
+ * Since .postclose() is deprecated, all resource destruction related to file
+ * handle are now done in .preclose() method.
+ */
+static void
+ipvr_drm_preclose(struct drm_device *dev, struct drm_file *file_priv)
+{
+	/* force close all contexts not explicitly closed by user */
+	struct drm_ipvr_private *dev_priv;
+	struct drm_ipvr_file_private *ipvr_fpriv;
+	struct ved_private *ved_priv;
+	struct ipvr_context *pos = NULL, *n = NULL;
+	unsigned long irq_flags;
+
+	IPVR_DEBUG_ENTRY("enter\n");
+	dev_priv = dev->dev_private;
+	ipvr_fpriv = file_priv->driver_priv;
+	ved_priv = dev_priv->ved_private;
+
+	spin_lock_irqsave(&dev_priv->ipvr_ctx_lock, irq_flags);
+	if (ved_priv && (!list_empty(&ved_priv->ved_queue)
+			|| (atomic_read(&dev_priv->pending_events) > 0)))

{

drivers/gpu/drm/ipvr/ipvr_drv.c new file +1 -0
+		IPVR_DEBUG_WARN("Closing the FD while pending cmds

exist!\n");

drivers/gpu/drm/ipvr/ipvr_drv.c new file +3 -0
+	}
+	list_for_each_entry_safe(pos, n, &ipvr_fpriv->ctx_list, head) {
+		IPVR_DEBUG_GENERAL("Video:remove context %d type

0x%x\n",

drivers/gpu/drm/ipvr/ipvr_drv.c new file +38 -0
+			pos->ctx_id, pos->ctx_type);
+		list_del(&pos->head);
+		idr_remove(&dev_priv->ipvr_ctx_idr, pos->ctx_id);
+		kfree(pos);
+	}
+
+	spin_unlock_irqrestore(&dev_priv->ipvr_ctx_lock, irq_flags);
+	kfree(ipvr_fpriv);
+}
+
+static irqreturn_t ipvr_irq_handler(int irq, void *arg)
+{
+	struct drm_device *dev = (struct drm_device *) arg;
+	struct drm_ipvr_private *dev_priv = dev->dev_private;
+	WARN_ON(ved_irq_handler(dev_priv->ved_private));
+	return IRQ_HANDLED;
+}
+
+static const struct file_operations ipvr_fops = {
+	.owner = THIS_MODULE,
+	.open = drm_open,
+	.release = drm_release,
+	.unlocked_ioctl = drm_ioctl,
+#ifdef CONFIG_COMPAT
+	.compat_ioctl = drm_ioctl,
+#endif
+	.mmap = drm_gem_mmap,
+};
+
+static int ipvr_drm_freeze(struct drm_device *dev)
+{
+	int ret;
+	struct drm_ipvr_private *dev_priv = dev->dev_private;
+	IPVR_DEBUG_ENTRY("enter\n");
+
+	ret = ved_check_idle(dev_priv->ved_private);
+	if (ret) {
+		IPVR_DEBUG_PM("VED check idle fail: %d, skip freezing\n",

ret);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+		/**
+		 * fixme: better to schedule a delayed task?
+		 */
+		return 0;
+	}
+
+	if (dev->irq_enabled) {
+		ret = drm_irq_uninstall(dev);
+		if (ret) {
+			IPVR_ERROR("Failed to uninstall drm irq

handler: %d\n", ret);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +11 -0
+		}
+	}
+
+	if (is_ved_on(dev_priv)) {
+		if (!ved_power_off(dev_priv)) {
+			IPVR_ERROR("Failed to power off VED\n");
+			return -EFAULT;
+		}
+		IPVR_DEBUG_PM("Successfully powered off\n");
+	} else {
+		IPVR_DEBUG_PM("Skiped power-off since already powered

off\n");

drivers/gpu/drm/ipvr/ipvr_drv.c new file +18 -0
+	}
+
+	return 0;
+}
+
+static int ipvr_drm_thaw(struct drm_device *dev)
+{
+	int ret;
+	struct drm_ipvr_private *dev_priv = dev->dev_private;
+	IPVR_DEBUG_ENTRY("enter\n");
+	if (!is_ved_on(dev_priv)) {
+		if (!ved_power_on(dev_priv)) {
+			IPVR_ERROR("Failed to power on VED\n");
+			return -EFAULT;
+		}
+		IPVR_DEBUG_PM("Successfully powered on\n");
+	} else {
+		IPVR_DEBUG_PM("Skiped power-on since already powered

on\n");

drivers/gpu/drm/ipvr/ipvr_drv.c new file +6 -0
+	}
+
+	if (!dev->irq_enabled) {
+		ret = drm_irq_install(dev, dev->irq);
+		if (ret) {
+			IPVR_ERROR("Failed to install drm irq handler: %d\n",

ret);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +29 -0
+		}
+	}
+
+	return 0;
+}
+
+static int ipvr_pm_suspend(struct device *dev)
+{
+	struct platform_device *platformdev = to_platform_device(dev);
+	struct drm_device *drm_dev = platform_get_drvdata(platformdev);
+	IPVR_DEBUG_PM("PM suspend called\n");
+	return drm_dev? ipvr_drm_freeze(drm_dev): 0;
+}
+static int ipvr_pm_resume(struct device *dev)
+{
+	struct platform_device *platformdev = to_platform_device(dev);
+	struct drm_device *drm_dev = platform_get_drvdata(platformdev);
+	IPVR_DEBUG_PM("PM resume called\n");
+	return drm_dev? ipvr_drm_thaw(drm_dev): 0;
+}
+
+static const struct vm_operations_struct ipvr_gem_vm_ops = {
+	.fault = ipvr_gem_fault,
+	.open = drm_gem_vm_open,
+	.close = drm_gem_vm_close,
+};
+
+static struct drm_driver ipvr_drm_driver = {
+	.driver_features = DRIVER_HAVE_IRQ | DRIVER_GEM |

DRIVER_PRIME,

drivers/gpu/drm/ipvr/ipvr_drv.c new file +46 -0
+	.load = ipvr_drm_load,
+	.unload = ipvr_drm_unload,
+	.open = ipvr_drm_open,
+	.preclose = ipvr_drm_preclose,
+	.irq_handler = ipvr_irq_handler,
+	.gem_free_object = ipvr_gem_free_object,
+	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
+	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
+	.gem_prime_export	= drm_gem_prime_export,
+	.gem_prime_import	= drm_gem_prime_import,
+	.gem_prime_get_sg_table = ipvr_gem_prime_get_sg_table,
+	.gem_prime_import_sg_table = ipvr_gem_prime_import_sg_table,
+	.gem_prime_pin		= ipvr_gem_prime_pin,
+	.gem_prime_unpin	= ipvr_gem_prime_unpin,
+#ifdef CONFIG_DEBUG_FS
+	.debugfs_init = ipvr_debugfs_init,
+	.debugfs_cleanup = ipvr_debugfs_cleanup,
+#endif
+	.gem_vm_ops = &ipvr_gem_vm_ops,
+	.ioctls = ipvr_gem_ioctls,
+	.num_ioctls = ARRAY_SIZE(ipvr_gem_ioctls),
+	.fops = &ipvr_fops,
+	.name = IPVR_DRIVER_NAME,
+	.desc = IPVR_DRIVER_DESC,
+	.date = IPVR_DRIVER_DATE,
+	.major = IPVR_DRIVER_MAJOR,
+	.minor = IPVR_DRIVER_MINOR,
+	.patchlevel = IPVR_DRIVER_PATCHLEVEL,
+};
+
+static int ipvr_plat_probe(struct platform_device *device)
+{
+	struct drm_device *drm_dev;
+	int ret;
+
+	drm_dev = drm_dev_alloc(&ipvr_drm_driver, &device->dev);
+	if (!drm_dev)
+		return -ENOMEM;
+
+	drm_dev->platformdev = device;
+	platform_set_drvdata(device, drm_dev);
+	ret = drm_dev_register(drm_dev, 0);
+	if (ret)
+		goto err_free;
+
+	DRM_INFO("Initialized IPVR on minor %d\n", drm_dev->primary-
Quoted 1 line

index);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +45 -0
+
+	return 0;
+err_free:
+	drm_dev_unref(drm_dev);
+	return ret;
+}
+
+static int ipvr_plat_remove(struct platform_device *device)
+{
+	struct drm_device *drm_dev = platform_get_drvdata(device);
+	if (drm_dev) {
+		drm_dev_unregister(drm_dev);
+		drm_dev_unref(drm_dev);
+		platform_set_drvdata(device, NULL);
+	}
+	return 0;
+}
+
+static struct dev_pm_ops ipvr_pm_ops = {
+	.suspend = ipvr_pm_suspend,
+	.resume = ipvr_pm_resume,
+	.freeze = ipvr_pm_suspend,
+	.thaw = ipvr_pm_resume,
+	.poweroff = ipvr_pm_suspend,
+	.restore = ipvr_pm_resume,
+#ifdef CONFIG_PM_RUNTIME
+	.runtime_suspend = ipvr_pm_suspend,
+	.runtime_resume = ipvr_pm_resume,
+#endif
+};
+
+static struct platform_driver ipvr_vlv_plat_driver = {
+	.driver = {
+		.name = "ipvr-ved-vlv",
+		.owner = THIS_MODULE,
+#ifdef CONFIG_PM
+		.pm = &ipvr_pm_ops,
+#endif
+	},
+	.probe = ipvr_plat_probe,
+	.remove = ipvr_plat_remove,
+};
+
+module_platform_driver(ipvr_vlv_plat_driver);
+MODULE_LICENSE("GPL");
drivers/gpu/drm/ipvr/ipvr_drv.h new file +1 -0
new file mode 100644
index 0000000..7f88380
@@ -0,0 +1,292 @@
+/*********************************************************

*****************
+ * ipvr_drv.h: IPVR driver common header file
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ipvr_drv.h new file +150 -0
+
+#ifndef _IPVR_DRV_H_
+#define _IPVR_DRV_H_
+#include "drmP.h"
+#include "ipvr_drm.h"
+#include "ipvr_mmu.h"
+#include <linux/version.h>
+#include <linux/io-mapping.h>
+#include <linux/i2c.h>
+#include <linux/i2c-algo-bit.h>
+#include <linux/backlight.h>
+#include <linux/intel-iommu.h>
+#include <linux/kref.h>
+#include <linux/pm_qos.h>
+#include <linux/mmu_notifier.h>
+
+#define IPVR_DRIVER_AUTHOR		"Intel, Inc."
+#define IPVR_DRIVER_NAME		"ipvr"
+#define IPVR_DRIVER_DESC		"PowerVR video drm driver"
+#define IPVR_DRIVER_DATE		"20141113"
+#define IPVR_DRIVER_MAJOR		0
+#define IPVR_DRIVER_MINOR		1
+#define IPVR_DRIVER_PATCHLEVEL	0
+
+/* read/write domains */
+#define IPVR_GEM_DOMAIN_CPU		0x00000001
+#define IPVR_GEM_DOMAIN_VPU		0x00000002
+
+/* context ID and type */
+#define IPVR_CONTEXT_INVALID_ID 0
+#define IPVR_MIN_CONTEXT_ID 1
+#define IPVR_MAX_CONTEXT_ID 0xff
+
+/*
+ *Debug print bits setting
+ */
+#define IPVR_D_GENERAL   (1 << 0)
+#define IPVR_D_INIT      (1 << 1)
+#define IPVR_D_IRQ       (1 << 2)
+#define IPVR_D_ENTRY     (1 << 3)
+#define IPVR_D_PM        (1 << 4)
+#define IPVR_D_REG       (1 << 5)
+#define IPVR_D_VED       (1 << 6)
+#define IPVR_D_WARN      (1 << 7)
+
+#define IPVR_DEBUG_GENERAL(_fmt, _arg...) \
+	IPVR_DEBUG(IPVR_D_GENERAL, _fmt, ##_arg)
+#define IPVR_DEBUG_INIT(_fmt, _arg...) \
+	IPVR_DEBUG(IPVR_D_INIT, _fmt, ##_arg)
+#define IPVR_DEBUG_IRQ(_fmt, _arg...) \
+	IPVR_DEBUG(IPVR_D_IRQ, _fmt, ##_arg)
+#define IPVR_DEBUG_ENTRY(_fmt, _arg...) \
+	IPVR_DEBUG(IPVR_D_ENTRY, _fmt, ##_arg)
+#define IPVR_DEBUG_PM(_fmt, _arg...) \
+	IPVR_DEBUG(IPVR_D_PM, _fmt, ##_arg)
+#define IPVR_DEBUG_REG(_fmt, _arg...) \
+	IPVR_DEBUG(IPVR_D_REG, _fmt, ##_arg)
+#define IPVR_DEBUG_VED(_fmt, _arg...) \
+	IPVR_DEBUG(IPVR_D_VED, _fmt, ##_arg)
+#define IPVR_DEBUG_WARN(_fmt, _arg...) \
+	IPVR_DEBUG(IPVR_D_WARN, _fmt, ##_arg)
+
+#define IPVR_DEBUG(_flag, _fmt, _arg...) \
+	do { \
+		if (unlikely((_flag) & drm_ipvr_debug)) \
+			printk(KERN_INFO \
+			       "[ipvr:0x%02x:%s] " _fmt , _flag, \
+			       __func__ , ##_arg); \
+	} while (0)
+
+#define IPVR_ERROR(_fmt, _arg...) \
+	do { \
+			printk(KERN_ERR \
+			       "[ipvr:ERROR:%s] " _fmt, \
+			       __func__ , ##_arg); \
+	} while (0)
+
+#define IPVR_UDELAY(usec) \
+	do { \
+		cpu_relax(); \
+	} while (0)
+
+#define IPVR_REG_WRITE32(_val, _offs) \
+	iowrite32(_val, dev_priv->reg_base + (_offs))
+#define IPVR_REG_READ32(_offs) \
+	ioread32(dev_priv->reg_base + (_offs))
+
+typedef struct ipvr_validate_buffer ipvr_validate_buffer_t;
+
+#define to_ipvr_bo(x) container_of(x, struct drm_ipvr_gem_object, base)
+
+extern int drm_ipvr_debug;
+extern int drm_ipvr_freq;
+
+struct ipvr_validate_context {
+	ipvr_validate_buffer_t *buffers;
+	int used_buffers;
+	struct list_head validate_list;
+};
+
+struct ipvr_mmu_driver;
+struct ipvr_mmu_pd;
+
+struct ipvr_gem_stat {
+	/**
+	 * Are we in a non-interruptible section of code?
+	 */
+	bool interruptible;
+
+	/* accounting, useful for userland debugging */
+	spinlock_t object_stat_lock;
+	size_t allocated_memory;
+	int allocated_count;
+	size_t imported_memory;
+	int imported_count;
+	size_t exported_memory;
+	int exported_count;
+	size_t mmu_used_size;
+};
+
+struct ipvr_address_space {
+	struct drm_mm linear_mm;
+	struct drm_mm tiling_mm;
+	struct drm_device *dev;
+	unsigned long linear_start;
+	size_t linear_total;
+	unsigned long tiling_start;
+	size_t tiling_total;
+
+	/* need it during clear_range */
+	struct {
+		dma_addr_t addr;
+		struct page *page;
+	} scratch;
+};
+
+struct ipvr_fence_driver {
+	u16	sync_seq;
+	atomic_t signaled_seq;
+	unsigned long last_activity;
+	bool initialized;
+	spinlock_t fence_lock;
+};
+
+struct ipvr_context {
+	/* used to link into ipvr_ctx_list */
+	struct list_head head;
+	u32 ctx_id;
+	/* used to double check ctx when find with idr, may be removed */
+	struct drm_ipvr_file_private *ipvr_fpriv; /* DRM device file pointer

*/

drivers/gpu/drm/ipvr/ipvr_drv.h new file +93 -0
+	u32 ctx_type;
+
+	u16 cur_seq;
+
+	/* for IMG DDK, only use tiling for 2k and 4k buffer stride */
+	/*
+	 * following tiling strides for VED are supported:
+	 * stride 0: 512 for scheme 0, 1024 for scheme 1
+	 * stride 1: 1024 for scheme 0, 2048 for scheme 1
+	 * stride 2: 2048 for scheme 0, 4096 for scheme 1
+	 * stride 3: 4096 for scheme 0
+	 */
+	u8 tiling_stride;
+	/*
+	 * scheme 0: tile is 256x16, while minimal tile stride is 512
+	 * scheme 1: tile is 512x8, while minimal tile stride is 1024
+	 */
+	u8 tiling_scheme;
+};
+
+typedef struct drm_ipvr_private {
+	struct drm_device *dev;
+	struct pci_dev *pci_root;
+
+	/* IMG video context */
+	spinlock_t ipvr_ctx_lock;
+	struct idr ipvr_ctx_idr;
+	struct ipvr_context default_ctx;
+
+	/* PM related */
+	atomic_t pending_events;
+	spinlock_t power_usage_lock;
+
+	/* exec related */
+	struct ipvr_validate_context validate_ctx;
+
+	/* IMG MMU specific */
+	struct ipvr_mmu_driver *mmu;
+	atomic_t ipvr_mmu_invaldc;
+
+	/* GEM mm related */
+	struct ipvr_gem_stat ipvr_stat;
+	struct kmem_cache *ipvr_bo_slab;
+	struct ipvr_address_space addr_space;
+
+	/* fence related */
+	u32 last_seq;
+	wait_queue_head_t fence_queue;
+	struct ipvr_fence_driver fence_drv;
+
+	/* MMIO window shared from parent device */
+	u8 __iomem* reg_base;
+
+	/*
+	 * VED specific
+	 */
+	struct ved_private *ved_private;
+}drm_ipvr_private_t;
+
+struct drm_ipvr_gem_object;
+
+/* VED private structure */
+struct ved_private {
+	struct drm_ipvr_private *dev_priv;
+
+	/* used to record seq got from irq fw-to-host msg */
+	u16 ved_cur_seq;
+
+	/*
+	 * VED Rendec Memory
+	 */
+	struct drm_ipvr_gem_object *ccb0;
+	u32 base_addr0;
+	struct drm_ipvr_gem_object *ccb1;
+	u32 base_addr1;
+	bool rendec_initialized;
+
+	/* VED firmware related */
+	struct drm_ipvr_gem_object  *fw_bo;
+	u32 fw_offset;
+	u32 mtx_mem_size;
+	bool fw_loaded_to_bo;
+	bool ved_fw_loaded;
+	void *ved_fw_ptr;
+	size_t ved_fw_size;
+
+	/*
+	 * ved command queue
+	 */
+	spinlock_t ved_lock;
+	struct mutex ved_mutex;
+	struct list_head ved_queue;
+	/* busy means cmd submitted to fw, while irq hasn't been receieved

*/

drivers/gpu/drm/ipvr/ipvr_drv.h new file +23 -0
+	bool ved_busy;
+	u32 ved_dash_access_ctrl;
+
+	/* pm related */
+	int ved_needs_reset;
+
+	int default_tiling_stride;
+	int default_tiling_scheme;
+
+	struct page *mmu_recover_page;
+};
+
+struct drm_ipvr_file_private {
+	/**
+	 * protected by dev_priv->ipvr_ctx_lock
+	 */
+	struct list_head ctx_list;
+};
+
+/* helpers for runtime pm */
+int ipvr_runtime_pm_get(struct drm_ipvr_private *dev_priv);
+int ipvr_runtime_pm_put(struct drm_ipvr_private *dev_priv, bool async);
+int ipvr_runtime_pm_put_all(struct drm_ipvr_private *dev_priv, bool

async);

drivers/gpu/drm/ipvr/ipvr_drv.h new file +2 -0
+
+#endif
drivers/gpu/drm/ipvr/ipvr_exec.c new file +1 -0
new file mode 100644
index 0000000..2e52dea
@@ -0,0 +1,613 @@
+/*********************************************************

*****************
+ * ipvr_exec.c: IPVR command buffer execution
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ipvr_exec.c new file +23 -0
+
+#include "ipvr_exec.h"
+#include "ipvr_gem.h"
+#include "ipvr_mmu.h"
+#include "ipvr_bo.h"
+#include "ipvr_fence.h"
+#include "ipvr_trace.h"
+#include "ved_fw.h"
+#include "ved_msg.h"
+#include "ved_reg.h"
+#include "ved_pm.h"
+#include "ved_cmd.h"
+#include <linux/io.h>
+#include <linux/delay.h>
+#include <linux/pm_runtime.h>
+
+static inline bool ipvr_bo_is_reserved(struct drm_ipvr_gem_object *obj)
+{
+	return atomic_read(&obj->reserved);
+}
+
+static int
+ipvr_bo_wait_unreserved(struct drm_ipvr_gem_object *obj, bool

interruptible)

drivers/gpu/drm/ipvr/ipvr_exec.c new file +28 -0
+{
+	if (interruptible) {
+		return wait_event_interruptible(obj->event_queue,
+					       !ipvr_bo_is_reserved(obj));
+	} else {
+		wait_event(obj->event_queue, !ipvr_bo_is_reserved(obj));
+		return 0;
+	}
+}
+
+/**
+ * ipvr_bo_reserve - reserve the given bo
+ *
+ * @obj:     The buffer object to reserve.
+ * @interruptible:     whether the waiting is interruptible or not.
+ * @no_wait:    flag to indicate returning immediately
+ *
+ * Returns: 0 if successful, error code otherwise
+ */
+int ipvr_bo_reserve(struct drm_ipvr_gem_object *obj,
+			bool interruptible, bool no_wait)
+{
+	int ret;
+
+	while (unlikely(atomic_xchg(&obj->reserved, 1) != 0)) {
+		if (no_wait)
+			return -EBUSY;
+		IPVR_DEBUG_GENERAL("wait bo unreserved, add to wait

queue.\n");

drivers/gpu/drm/ipvr/ipvr_exec.c new file +108 -0
+		ret = ipvr_bo_wait_unreserved(obj, interruptible);
+		if (unlikely(ret))
+			return ret;
+	}
+
+	return 0;
+}
+
+/**
+ * ipvr_bo_unreserve - unreserve the given bo
+ *
+ * @obj:     The buffer object to reserve.
+ *
+ * No return value.
+ */
+void ipvr_bo_unreserve(struct drm_ipvr_gem_object *obj)
+{
+	atomic_set(&obj->reserved, 0);
+	wake_up_all(&obj->event_queue);
+}
+
+static void ipvr_backoff_reservation(struct list_head *list)
+{
+	struct ipvr_validate_buffer *entry;
+
+	list_for_each_entry(entry, list, head) {
+		struct drm_ipvr_gem_object *obj = entry->ipvr_gem_bo;
+		if (!atomic_read(&obj->reserved))
+			continue;
+		atomic_set(&obj->reserved, 0);
+		wake_up_all(&obj->event_queue);
+	}
+}
+
+/*
+ * ipvr_reserve_buffers - Reserve buffers for validation.
+ *
+ * @list:     points to a bo list to be backoffed
+ *
+ * If a buffer in the list is marked for CPU access, we back off and
+ * wait for that buffer to become free for VPU access.
+ *
+ * If a buffer is reserved for another validation, the validator with
+ * the highest validation sequence backs off and waits for that buffer
+ * to become unreserved. This prevents deadlocks when validating multiple
+ * buffers in different orders.
+ *
+ * Returns:
+ * 0 on success, error code on failure.
+ */
+int ipvr_reserve_buffers(struct list_head *list)
+{
+	struct ipvr_validate_buffer *entry;
+	int ret;
+
+	if (list_empty(list))
+		return 0;
+
+	list_for_each_entry(entry, list, head) {
+		struct drm_ipvr_gem_object *bo = entry->ipvr_gem_bo;
+
+		ret = ipvr_bo_reserve(bo, true, true);
+		switch (ret) {
+		case 0:
+			break;
+		case -EBUSY:
+			ret = ipvr_bo_reserve(bo, true, false);
+			if (!ret)
+				break;
+			else
+				goto err;
+		default:
+			goto err;
+		}
+	}
+
+	return 0;
+err:
+	ipvr_backoff_reservation(list);
+	return ret;
+}
+
+/**
+ * ipvr_set_tile - global setting of tiling info
+ *
+ * @dev:     the ipvr drm device
+ * @tiling_scheme:     see ipvr_drm.h for details
+ * @tiling_stride:     see ipvr_drm.h for details
+ *
+ * vxd392 hardware supports only one tile region so this configuration
+ * is global.
+ */
+void ipvr_set_tile(struct drm_ipvr_private *dev_priv,
+		u8 tiling_scheme, u8 tiling_stride)
+{
+	u32 cmd;
+	u32 start = IPVR_MEM_MMU_TILING_START;
+	u32 end = IPVR_MEM_MMU_TILING_END;
+
+	/* Enable memory tiling */
+	cmd = ((start >> 20) + (((end >> 20) - 1) << 12) +
+				((0x8 | tiling_stride) << 24));
+	IPVR_DEBUG_GENERAL("VED: MMU Tiling register0 %08x.\n", cmd);
+	IPVR_DEBUG_GENERAL("Region 0x%08x-0x%08x.\n", start, end);
+	IPVR_REG_WRITE32(cmd, MSVDX_MMU_TILE_BASE0_OFFSET);
+
+	/* we need set tile format as 512x8 on Baytrail, which is shceme 1 */
+	IPVR_REG_WRITE32(tiling_scheme << 3,

MSVDX_MMU_CONTROL2_OFFSET);

drivers/gpu/drm/ipvr/ipvr_exec.c new file +52 -0
+}
+
+/**
+ * ipvr_find_ctx_with_fence - lookup the context with given fence seqno
+ *
+ * @dev_priv:     the ipvr drm device
+ * @fence:     fence seqno generated by the context
+ *
+ * Returns:
+ * context pointer if found.
+ * NULL if not found.
+ */
+struct ipvr_context*
+ipvr_find_ctx_with_fence(struct drm_ipvr_private *dev_priv, u16 fence)
+{
+	struct ipvr_context *pos;
+	int id = 0;
+
+	spin_lock(&dev_priv->ipvr_ctx_lock);
+	idr_for_each_entry(&dev_priv->ipvr_ctx_idr, pos, id) {
+		if (pos->cur_seq == fence) {
+			spin_unlock(&dev_priv->ipvr_ctx_lock);
+			return pos;
+		}
+	}
+	spin_unlock(&dev_priv->ipvr_ctx_lock);
+
+	return NULL;
+}
+
+static void ipvr_unreference_buffers(struct ipvr_validate_context *context)
+{
+	struct ipvr_validate_buffer *entry, *next;
+	struct drm_ipvr_gem_object *obj;
+	struct list_head *list = &context->validate_list;
+
+	list_for_each_entry_safe(entry, next, list, head) {
+		obj = entry->ipvr_gem_bo;
+		list_del(&entry->head);
+		drm_gem_object_unreference_unlocked(&obj->base);
+		context->used_buffers--;
+	}
+}
+
+static int ipvr_update_buffers(struct drm_file *file_priv,
+					struct ipvr_validate_context *context,
+					u64 buffer_list,
+					int count)
+{
+	struct ipvr_validate_buffer *entry;
+	struct drm_ipvr_gem_exec_object __user *val_arg
+		= (struct drm_ipvr_gem_exec_object __user

*)(uintptr_t)buffer_list;

drivers/gpu/drm/ipvr/ipvr_exec.c new file +7 -0
+
+	if (list_empty(&context->validate_list))
+		return 0;
+
+	list_for_each_entry(entry, &context->validate_list, head) {
+		if (!val_arg) {
+			IPVR_DEBUG_WARN("unexpected end of val_arg

list!!!\n");

drivers/gpu/drm/ipvr/ipvr_exec.c new file +20 -0
+			return -EINVAL;
+		}
+		if (unlikely(copy_to_user(val_arg, &entry->val_req,
+					    sizeof(entry->val_req)))) {
+			IPVR_ERROR("copy_to_user fault.\n");
+			return -EFAULT;
+		}
+		val_arg ++;
+	}
+	return 0;
+}
+
+static int ipvr_reference_buffers(struct drm_file *file_priv,
+					struct ipvr_validate_context *context,
+					u64 buffer_list,
+					int count)
+{
+	struct drm_device *dev = file_priv->minor->dev;
+	struct drm_ipvr_gem_exec_object __user *val_arg
+		= (struct drm_ipvr_gem_exec_object __user

*)(uintptr_t)buffer_list;

drivers/gpu/drm/ipvr/ipvr_exec.c new file +7 -0
+	struct ipvr_validate_buffer *item;
+	struct drm_ipvr_gem_object *obj;
+	int ret = 0;
+	int i = 0;
+
+	for (i = 0; i < count; ++i) {
+		if (unlikely(context->used_buffers >=

IPVR_NUM_VALIDATE_BUFFERS)) {

drivers/gpu/drm/ipvr/ipvr_exec.c new file +16 -0
+			IPVR_ERROR("Too many buffers on validate list.\n");
+			ret = -EINVAL;
+			goto out_err;
+		}
+		item = &context->buffers[context->used_buffers];
+		if (unlikely(copy_from_user(&item->val_req, val_arg,
+					    sizeof(item->val_req)) != 0)) {
+			IPVR_ERROR("copy_from_user fault.\n");
+			ret = -EFAULT;
+			goto out_err;
+		}
+		INIT_LIST_HEAD(&item->head);
+		obj = to_ipvr_bo(drm_gem_object_lookup(dev, file_priv,
+						item->val_req.handle));
+		if (&obj->base == NULL) {
+			IPVR_ERROR("cannot find obj for handle %u at

position %d.\n",

drivers/gpu/drm/ipvr/ipvr_exec.c new file +29 -0
+				item->val_req.handle, i);
+			ret = -ENOENT;
+			goto out_err;
+		}
+		item->ipvr_gem_bo = obj;
+
+		list_add_tail(&item->head, &context->validate_list);
+		context->used_buffers++;
+
+		val_arg++;
+	}
+
+	return 0;
+
+out_err:
+	ipvr_unreference_buffers(context);
+	return ret;
+}
+
+static int ipvr_fixup_reloc_entries(struct drm_device *dev,
+					struct drm_file *filp,
+					struct ipvr_validate_buffer *val_obj)
+{
+	int i, ret;
+	u64 mmu_offset;
+	struct drm_ipvr_gem_object *obj, *target_obj;
+	struct drm_ipvr_gem_exec_object *exec_obj = &val_obj->val_req;
+	struct drm_ipvr_gem_relocation_entry __user *reloc_entries
+		= (struct drm_ipvr_gem_relocation_entry __user

*)(uintptr_t)exec_obj->relocs_ptr;

drivers/gpu/drm/ipvr/ipvr_exec.c new file +17 -0
+	struct drm_ipvr_gem_relocation_entry local_reloc_entry;
+
+	obj = val_obj->ipvr_gem_bo;
+	if (!obj)
+		return -ENOENT;
+
+	/* todo: check write access */
+
+	/* overwrite user content and update relocation entries */
+	mmu_offset = ipvr_gem_object_mmu_offset(obj);
+	if (mmu_offset != exec_obj->offset) {
+		exec_obj->offset = mmu_offset;
+		IPVR_DEBUG_GENERAL("Fixup BO %u offset to 0x%llx\n",
+			exec_obj->handle, exec_obj->offset);
+	}
+	for (i = 0; i < exec_obj->relocation_count; ++i) {
+		if (unlikely(copy_from_user(&local_reloc_entry,

&reloc_entries[i],

drivers/gpu/drm/ipvr/ipvr_exec.c new file +6 -0
+					    sizeof(local_reloc_entry)) != 0)) {
+			IPVR_ERROR("copy_from_user fault.\n");
+			return -EFAULT;
+		}
+		target_obj = to_ipvr_bo(drm_gem_object_lookup(dev, filp,
+
	local_reloc_entry.target_handle));
drivers/gpu/drm/ipvr/ipvr_exec.c new file +2 -0
+		if (&target_obj->base == NULL) {
+			IPVR_ERROR("cannot find obj for handle %u at

position %d.\n",

drivers/gpu/drm/ipvr/ipvr_exec.c new file +6 -0
+				local_reloc_entry.target_handle, i);
+			return -ENOENT;
+		}
+		ret = ipvr_gem_object_apply_reloc(obj,
+				local_reloc_entry.offset,
+				local_reloc_entry.delta +

ipvr_gem_object_mmu_offset(target_obj));

drivers/gpu/drm/ipvr/ipvr_exec.c new file +3 -0
+		if (ret) {
+			IPVR_ERROR("Failed applying reloc: %d\n", ret);
+
	drm_gem_object_unreference_unlocked(&target_obj->base);
drivers/gpu/drm/ipvr/ipvr_exec.c new file +3 -0
+			return ret;
+		}
+		if (unlikely(copy_to_user(&reloc_entries[i],

&local_reloc_entry,

drivers/gpu/drm/ipvr/ipvr_exec.c new file +1 -0
+						sizeof(local_reloc_entry)) !=

0)) {

drivers/gpu/drm/ipvr/ipvr_exec.c new file +3 -0
+			IPVR_DEBUG_WARN("copy_to_user fault.\n");
+		}
+		IPVR_DEBUG_GENERAL("Fixup offset %llx in BO %u to

0x%lx\n",

drivers/gpu/drm/ipvr/ipvr_exec.c new file +2 -0
+			local_reloc_entry.offset, exec_obj->handle,
+			local_reloc_entry.delta +

ipvr_gem_object_mmu_offset(target_obj));

drivers/gpu/drm/ipvr/ipvr_exec.c new file +1 -0
+		drm_gem_object_unreference_unlocked(&target_obj-
Quoted 1 line

base);

drivers/gpu/drm/ipvr/ipvr_exec.c new file +13 -0
+	}
+	return 0;
+}
+
+static int ipvr_fixup_relocs(struct drm_device *dev,
+					struct drm_file *filp,
+					struct ipvr_validate_context *context)
+{
+	int ret;
+	struct ipvr_validate_buffer *entry;
+
+	if (list_empty(&context->validate_list)) {
+		IPVR_DEBUG_WARN("No relocs required in validate contex,

skip\n");

drivers/gpu/drm/ipvr/ipvr_exec.c new file +9 -0
+		return 0;
+	}
+
+	list_for_each_entry(entry, &context->validate_list, head) {
+		IPVR_DEBUG_GENERAL("Fixing up reloc for BO handle %u\n",
+			entry->val_req.handle);
+		ret = ipvr_fixup_reloc_entries(dev, filp, entry);
+		if (ret) {
+			IPVR_ERROR("Failed to fixup reloc for BO

handle %u\n",

drivers/gpu/drm/ipvr/ipvr_exec.c new file +11 -0
+				entry->val_req.handle);
+			return ret;
+		}
+	}
+	return 0;
+}
+
+static int ipvr_validate_buffer_list(struct drm_file *file_priv,
+					struct ipvr_validate_context *context,
+					bool *need_fixup_relocs,
+					struct drm_ipvr_gem_object

**cmd_buffer)

drivers/gpu/drm/ipvr/ipvr_exec.c new file +24 -0
+{
+	struct ipvr_validate_buffer *entry;
+	struct drm_ipvr_gem_object *obj;
+	struct list_head *list = &context->validate_list;
+	int ret = 0;
+	u64 real_mmu_offset;
+
+	list_for_each_entry(entry, list, head) {
+		obj = entry->ipvr_gem_bo;
+		/**
+		 * need validate bo locate in the mmu space
+		 * check if presumed offset is correct
+		 * with ved_check_presumed, if presume is not correct,
+		 * call fixup relocs with ved_fixup_relocs.
+		 * current implementation doesn't support shrink/evict,
+		 * so needn't validate mmu offset.
+		 * need be implemented in the future if shrink/evict
+		 * is supported.
+		 */
+		real_mmu_offset = ipvr_gem_object_mmu_offset(obj);
+		if (IPVR_IS_ERR(real_mmu_offset))
+			return -ENOENT;
+		if (entry->val_req.offset != real_mmu_offset) {
+			IPVR_DEBUG_GENERAL("BO %u offset doesn't

match MMU, need fixup reloc\n", entry->val_req.handle);

drivers/gpu/drm/ipvr/ipvr_exec.c new file +5 -0
+			*need_fixup_relocs = true;
+		}
+		if (entry->val_req.flags & IPVR_EXEC_OBJECT_SUBMIT) {
+			if (*cmd_buffer != NULL) {
+				IPVR_ERROR("Only one BO can be submitted

in one exec ioctl\n");

drivers/gpu/drm/ipvr/ipvr_exec.c new file +22 -0
+				return -EINVAL;
+			}
+			*cmd_buffer = obj;
+		}
+	}
+
+	return ret;
+}
+
+/**
+ * ipvr_gem_do_execbuffer - lookup the context with given fence seqno
+ *
+ * @dev:     the ipvr drm device
+ * @file_priv:      the ipvr drm file pointer
+ * @args:      input argument passed from userland
+ * @vm:      ipvr address space for all the bo to bind to
+ *
+ * Returns: 0 on success, error code on failure
+ */
+static int ipvr_gem_do_execbuffer(struct drm_device *dev,
+					struct drm_file *file_priv,
+					struct drm_ipvr_gem_execbuffer

*args,

drivers/gpu/drm/ipvr/ipvr_exec.c new file +17 -0
+					struct ipvr_address_space *vm)
+{
+	drm_ipvr_private_t *dev_priv = dev->dev_private;
+	struct ipvr_validate_context *context = &dev_priv->validate_ctx;
+	struct ved_private *ved_priv = dev_priv->ved_private;
+	struct drm_ipvr_gem_object *cmd_buffer = NULL;
+	struct ipvr_context *ipvr_ctx  = NULL;
+	int ret, ctx_id;
+	bool need_fixup_relocs = false;
+
+	/* if not pass 0, use default context instead */
+	if (args->ctx_id == 0)
+		ctx_id = dev_priv->default_ctx.ctx_id;
+	else
+		ctx_id = args->ctx_id;
+
+	IPVR_DEBUG_GENERAL("try to find ctx according ctx_id %d.\n",

ctx_id);

drivers/gpu/drm/ipvr/ipvr_exec.c new file +10 -0
+
+	/* we're already in struct_mutex lock */
+	ipvr_ctx = (struct ipvr_context *)
+			idr_find(&dev_priv->ipvr_ctx_idr, ctx_id);
+	if (!ipvr_ctx) {
+		IPVR_DEBUG_WARN("video ctx is not found.\n");
+		return -ENOENT;
+	}
+
+	IPVR_DEBUG_GENERAL("reference all buffers passed through

buffer_list.\n");

drivers/gpu/drm/ipvr/ipvr_exec.c new file +8 -0
+	ret = ipvr_reference_buffers(file_priv, context,
+				args->buffers_ptr, args->buffer_count);
+	if (unlikely(ret)) {
+		IPVR_DEBUG_WARN("reference buffer failed: %d.\n", ret);
+		return ret;
+	}
+
+	IPVR_DEBUG_GENERAL("reserve all buffers to make them not

accessed "

drivers/gpu/drm/ipvr/ipvr_exec.c new file +11 -0
+			"by other threads.\n");
+	ret = ipvr_reserve_buffers(&context->validate_list);
+	if (unlikely(ret)) {
+		IPVR_ERROR("reserve buffers failed.\n");
+		/* -EBUSY or -ERESTARTSYS */
+		goto out_unref_buf;
+	}
+
+	IPVR_DEBUG_GENERAL("validate buffer list, mainly check "
+			"the bo mmu offset.\n");
+	ret = ipvr_validate_buffer_list(file_priv, context,

&need_fixup_relocs, &cmd_buffer);

drivers/gpu/drm/ipvr/ipvr_exec.c new file +41 -0
+	if (unlikely(ret)) {
+		IPVR_ERROR("validate buffers failed: %d.\n", ret);
+		goto out_backoff_reserv;
+	}
+
+	if (unlikely(cmd_buffer == NULL)) {
+		IPVR_ERROR("No cmd BO found.\n");
+		ret = -EINVAL;
+		goto out_backoff_reserv;
+	}
+
+	if (unlikely(need_fixup_relocs)) {
+		ret = ipvr_fixup_relocs(dev, file_priv, context);
+		if (ret) {
+			IPVR_ERROR("fixup relocs failed.\n");
+			goto out_backoff_reserv;
+		}
+	}
+
+#if 0
+	bo = idr_find(&file_priv->object_idr, args->cmdbuf_handle);
+	if (!bo) {
+		IPVR_DEBUG_WARN("Invalid cmd object handle 0x%x.\n",
+			args->cmdbuf_handle);
+		ret = -EINVAL;
+		goto out_backoff_reserv;
+	}
+
+	cmd_buffer = to_ipvr_bo(bo);
+#endif
+	/**
+	 * check contex id and type
+	 */
+	/*
+	 * only VED is supported currently
+	 */
+	if (ipvr_ctx->ctx_type == IPVR_CONTEXT_TYPE_VED)
+	{
+		/* fixme: should support non-zero start_offset */
+		if (unlikely(args->exec_start_offset != 0)) {
+			IPVR_ERROR("Unsupported exec_start_offset %u\n",

args->exec_start_offset);

drivers/gpu/drm/ipvr/ipvr_exec.c new file +12 -0
+			ret = -EINVAL;
+			goto out_backoff_reserv;
+		}
+
+		ret = mutex_lock_interruptible(&ved_priv->ved_mutex);
+		if (unlikely(ret)) {
+			IPVR_ERROR("Error get VED mutex: %d\n", ret);
+			/* -EINTR */
+			goto out_backoff_reserv;
+		}
+
+		IPVR_DEBUG_GENERAL("parse cmd buffer and send to

VED.\n");

drivers/gpu/drm/ipvr/ipvr_exec.c new file +4 -0
+		ret = ved_cmdbuf_video(ved_priv, cmd_buffer,
+				args->exec_len, ipvr_ctx );
+		if (unlikely(ret)) {
+			IPVR_ERROR("ved_cmdbuf_video returns %d.\n",

ret);

drivers/gpu/drm/ipvr/ipvr_exec.c new file +15 -0
+			/* -EINVAL, -ENOMEM, -EFAULT, -EBUSY */
+			mutex_unlock(&ved_priv->ved_mutex);
+			goto out_backoff_reserv;
+		}
+
+		mutex_unlock(&ved_priv->ved_mutex);
+	}
+
+	/**
+	 * update mmu_offsets and fence fds to user
+	 */
+	ret = ipvr_update_buffers(file_priv, context,
+				args->buffers_ptr, args->buffer_count);
+	if (unlikely(ret)) {
+		IPVR_DEBUG_WARN("ipvr_update_buffers returns

error %d.\n", ret);

drivers/gpu/drm/ipvr/ipvr_exec.c new file +8 -0
+		ret = 0;
+	}
+
+out_backoff_reserv:
+	IPVR_DEBUG_GENERAL("unreserve buffer list.\n");
+	ipvr_backoff_reservation(&context->validate_list);
+out_unref_buf:
+	IPVR_DEBUG_GENERAL("unref bufs which are refered during bo

lookup.\n");

drivers/gpu/drm/ipvr/ipvr_exec.c new file +45 -0
+	ipvr_unreference_buffers(context);
+	return ret;
+}
+
+/**
+ * ipvr_gem_do_execbuffer - lookup the context with given fence seqno
+ *
+ * ioctl entry for DRM_IPVR_GEM_EXECBUFFER
+ *
+ * Returns: 0 on success, error code on failure
+ */
+int ipvr_gem_execbuffer_ioctl(struct drm_device *dev, void *data,
+				struct drm_file *file_priv)
+{
+	struct drm_ipvr_private *dev_priv = dev->dev_private;
+	struct drm_ipvr_gem_execbuffer *args = data;
+	int ret;
+	struct ipvr_validate_context *context = &dev_priv->validate_ctx;
+
+	ret = mutex_lock_interruptible(&dev->struct_mutex);
+	if (ret)
+		return ret;
+
+	if (!context || !context->buffers) {
+		ret = -EINVAL;
+		goto out;
+	}
+
+	context->used_buffers = 0;
+
+	if (args->buffer_count < 1 ||
+		args->buffer_count >
+			(UINT_MAX / sizeof(struct ipvr_validate_buffer))) {
+		IPVR_ERROR("validate %d buffers.\n", args->buffer_count);
+		ret = -EINVAL;
+		goto out;
+	}
+
+	trace_ipvr_execbuffer(args);
+	ret = ipvr_gem_do_execbuffer(dev, file_priv, args,
+				    &dev_priv->addr_space);
+out:
+	mutex_unlock(&dev->struct_mutex);
+	return ret;
+}
drivers/gpu/drm/ipvr/ipvr_exec.h new file +1 -0
new file mode 100644
index 0000000..cd174a8
@@ -0,0 +1,57 @@
+/*********************************************************

*****************
+ * ipvr_exec.h: IPVR header file for command buffer execution
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ipvr_exec.h new file +33 -0
+
+#ifndef _IPVR_EXEC_H_
+#define _IPVR_EXEC_H_
+
+#include "ipvr_drv.h"
+#include "ipvr_drm.h"
+#include "ipvr_gem.h"
+#include "ipvr_fence.h"
+
+struct drm_ipvr_private;
+
+#define IPVR_NUM_VALIDATE_BUFFERS 2048
+#define IPVR_MAX_RELOC_PAGES 1024
+
+struct ipvr_validate_buffer {
+	struct drm_ipvr_gem_exec_object val_req;
+	struct list_head head;
+	struct drm_ipvr_gem_object *ipvr_gem_bo;
+	struct ipvr_fence *old_fence;
+};
+
+int ipvr_bo_reserve(struct drm_ipvr_gem_object *obj,
+			bool interruptible, bool no_wait);
+
+void ipvr_bo_unreserve(struct drm_ipvr_gem_object *obj);
+
+struct ipvr_context*
+ipvr_find_ctx_with_fence(struct drm_ipvr_private *dev_priv, u16 fence);
+
+void ipvr_set_tile(struct drm_ipvr_private *dev_priv,
+			u8 tiling_scheme, u8 tiling_stride);
+
+#endif
drivers/gpu/drm/ipvr/ipvr_fence.c new file +1 -0
new file mode 100644
index 0000000..ef8212a
@@ -0,0 +1,487 @@
+/*********************************************************

*****************
+ * ipvr_fence.c: IPVR fence handling to track command exectuion status
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ipvr_fence.c new file +61 -0
+
+#include "ipvr_fence.h"
+#include "ipvr_exec.h"
+#include "ipvr_bo.h"
+#include "ipvr_trace.h"
+#include "ved_reg.h"
+#include "ved_fw.h"
+#include "ved_cmd.h"
+#include <linux/debugfs.h>
+#include <linux/export.h>
+#include <linux/file.h>
+#include <linux/fs.h>
+#include <linux/kernel.h>
+#include <linux/poll.h>
+#include <linux/sched.h>
+#include <linux/seq_file.h>
+#include <linux/slab.h>
+#include <linux/uaccess.h>
+#include <linux/anon_inodes.h>
+
+/**
+ * ipvr_fence_create - create and init a fence
+ *
+ * @dev_priv: drm_ipvr_private pointer
+ * @fence: ipvr fence object
+ * @fence_fd: file descriptor for exporting fence
+ *
+ * Create a fence, actually the fence is written to ipvr through msg.
+ * exporting a new file descriptor to userspace.
+ * Returns pointer on success, ERR_PTR otherwise.
+ */
+struct ipvr_fence* __must_check
+ipvr_fence_create(struct drm_ipvr_private *dev_priv)
+{
+	struct ipvr_fence *fence;
+	unsigned long irq_flags;
+	u16 old_seq;
+	struct ved_private *ved_priv;
+
+	ved_priv = dev_priv->ved_private;
+
+	fence = kzalloc(sizeof(struct ipvr_fence), GFP_KERNEL);
+	if (!fence) {
+		fence = ERR_PTR(-ENOMEM);
+		goto out;
+	}
+
+	kref_init(&fence->kref);
+	fence->dev_priv = dev_priv;
+
+	spin_lock_irqsave(&dev_priv->fence_drv.fence_lock, irq_flags);
+	/* cmds in one batch use different fence value */
+	old_seq = dev_priv->fence_drv.sync_seq;
+	dev_priv->fence_drv.sync_seq = dev_priv->last_seq++;
+	dev_priv->fence_drv.sync_seq <<= 4;
+	fence->seq = dev_priv->fence_drv.sync_seq;
+
+	spin_unlock_irqrestore(&dev_priv->fence_drv.fence_lock, irq_flags);
+
+	kref_get(&fence->kref);
+	IPVR_DEBUG_GENERAL("fence is created and its seq is %u

(0x%04x).\n",

drivers/gpu/drm/ipvr/ipvr_fence.c new file +37 -0
+		fence->seq, fence->seq);
+out:
+	return fence;
+}
+
+/**
+ * ipvr_fence_destroy - destroy a fence
+ *
+ * @kref: fence kref
+ *
+ * Frees the fence object (all asics).
+ */
+static void ipvr_fence_destroy(struct kref *kref)
+{
+	struct ipvr_fence *fence;
+
+	fence = container_of(kref, struct ipvr_fence, kref);
+	kfree(fence);
+}
+
+/**
+ * ipvr_fence_process - process a fence
+ *
+ * @dev_priv: drm_ipvr_private pointer
+ * @seq: indicate the fence seq has been signaled
+ * @err: indicate if err happened, for future use
+ *
+ * Checks the current fence value and wakes the fence queue
+ * if the sequence number has increased (all asics).
+ */
+void ipvr_fence_process(struct drm_ipvr_private *dev_priv, u16 seq, u8 err)
+{
+	int signaled_seq_int;
+	u16 signaled_seq;
+	u16 last_emitted;
+
+	signaled_seq_int = atomic_read(&dev_priv-
Quoted 1 line

fence_drv.signaled_seq);

drivers/gpu/drm/ipvr/ipvr_fence.c new file +5 -0
+	signaled_seq = (u16)signaled_seq_int;
+	last_emitted = dev_priv->fence_drv.sync_seq;
+
+	if (ipvr_seq_after(seq, last_emitted)) {
+		IPVR_DEBUG_WARN("seq error, seq is %u, signaled_seq

is %u, "

drivers/gpu/drm/ipvr/ipvr_fence.c new file +8 -0
+				"last_emitted is %u.\n",
+				seq, signaled_seq, last_emitted);
+		return;
+	}
+	if (ipvr_seq_after(seq, signaled_seq)) {
+		atomic_xchg(&dev_priv->fence_drv.signaled_seq, seq);
+		dev_priv->fence_drv.last_activity = jiffies;
+		IPVR_DEBUG_GENERAL("last emitted seq %u is updated.\n",

seq);

drivers/gpu/drm/ipvr/ipvr_fence.c new file +27 -0
+		wake_up_all(&dev_priv->fence_queue);
+	}
+}
+
+/**
+ * ipvr_fence_signaled - check if a fence sequeuce number has signaled
+ *
+ * @dev_priv: ipvr device pointer
+ * @seq: sequence number
+ *
+ * Check if the last singled fence sequnce number is >= the requested
+ * sequence number (all asics).
+ * Returns true if the fence has signaled (current fence value
+ * is >= requested value) or false if it has not (current fence
+ * value is < the requested value.
+ */
+static bool ipvr_fence_signaled(struct drm_ipvr_private *dev_priv, u16 seq)
+{
+	u16 curr_seq, signaled_seq;
+	unsigned long irq_flags;
+	spin_lock_irqsave(&dev_priv->fence_drv.fence_lock, irq_flags);
+	curr_seq = dev_priv->ved_private->ved_cur_seq;
+	signaled_seq = atomic_read(&dev_priv->fence_drv.signaled_seq);
+
+	if (ipvr_seq_after(seq, signaled_seq)) {
+		/* poll new last sequence at least once */
+		ipvr_fence_process(dev_priv, curr_seq,

IPVR_CMD_SUCCESS);

drivers/gpu/drm/ipvr/ipvr_fence.c new file +1 -0
+		signaled_seq = atomic_read(&dev_priv-
Quoted 1 line

fence_drv.signaled_seq);

drivers/gpu/drm/ipvr/ipvr_fence.c new file +2 -0
+		if (ipvr_seq_after(seq, signaled_seq)) {
+			spin_unlock_irqrestore(&dev_priv-
Quoted 1 line

fence_drv.fence_lock,

drivers/gpu/drm/ipvr/ipvr_fence.c new file +20 -0
+						irq_flags);
+			return false;
+		}
+	}
+	spin_unlock_irqrestore(&dev_priv->fence_drv.fence_lock, irq_flags);
+	return true;
+}
+
+/**
+ * ipvr_fence_lockup - ipvr lockup is detected
+ *
+ * @dev_priv: ipvr device pointer
+ * @fence: lockup detected when wait the specific fence
+ *
+ * During the calling of ipvr_fence_wait, if wait to timeout,
+ * indicate lockup happened, need flush cmd queue and reset ved
+ * If ipvr_fence_wait_empty_locked encounter lockup, fence is NULL
+ */
+static void
+ipvr_fence_lockup(struct drm_ipvr_private *dev_priv, struct ipvr_fence

*fence)

drivers/gpu/drm/ipvr/ipvr_fence.c new file +5 -0
+{
+	unsigned long irq_flags;
+	struct ved_private *ved_priv = dev_priv->ved_private;
+
+	IPVR_DEBUG_WARN("timeout detected, flush queued cmd, maybe

lockup.\n");

drivers/gpu/drm/ipvr/ipvr_fence.c new file +5 -0
+	IPVR_DEBUG_WARN("MSVDX_COMMS_FW_STATUS reg is 0x%x.\n",
+			IPVR_REG_READ32(MSVDX_COMMS_FW_STATUS));
+
+	if (fence) {
+		spin_lock_irqsave(&dev_priv->fence_drv.fence_lock,

irq_flags);

drivers/gpu/drm/ipvr/ipvr_fence.c new file +1 -0
+		ipvr_fence_process(dev_priv, fence->seq,

IPVR_CMD_LOCKUP);

drivers/gpu/drm/ipvr/ipvr_fence.c new file +1 -0
+		spin_unlock_irqrestore(&dev_priv->fence_drv.fence_lock,

irq_flags);

drivers/gpu/drm/ipvr/ipvr_fence.c new file +42 -0
+	}
+
+	/* should behave according to ctx type in the future */
+	ved_flush_cmd_queue(dev_priv->ved_private);
+	ipvr_runtime_pm_put_all(dev_priv, false);
+
+	ved_priv->ved_needs_reset = 1;
+}
+
+/**
+ * ipvr_fence_wait_seq - wait for a specific sequence number
+ *
+ * @dev_priv: ipvr device pointer
+ * @target_seq: sequence number we want to wait for
+ * @intr: use interruptable sleep
+ *
+ * Wait for the requested sequence number to be written.
+ * @intr selects whether to use interruptable (true) or non-interruptable
+ * (false) sleep when waiting for the sequence number.
+ * Returns 0 if the sequence number has passed, error for all other cases.
+ * -EDEADLK is returned when a VPU lockup has been detected.
+ */
+static int ipvr_fence_wait_seq(struct drm_ipvr_private *dev_priv,
+					u16 target_seq, bool intr)
+{
+	struct ipvr_fence_driver	*fence_drv = &dev_priv->fence_drv;
+	unsigned long timeout, last_activity;
+	u16 signaled_seq;
+	int ret;
+	unsigned long irq_flags;
+	bool signaled;
+	spin_lock_irqsave(&dev_priv->fence_drv.fence_lock, irq_flags);
+
+	while (ipvr_seq_after(target_seq,
+			(u16)atomic_read(&fence_drv->signaled_seq))) {
+		/* seems the fence_drv->last_activity is useless? */
+		timeout = IPVR_FENCE_JIFFIES_TIMEOUT;
+		signaled_seq = atomic_read(&fence_drv->signaled_seq);
+		/* save last activity valuee, used to check for VPU lockups */
+		last_activity = fence_drv->last_activity;
+
+		spin_unlock_irqrestore(&dev_priv->fence_drv.fence_lock,

irq_flags);

drivers/gpu/drm/ipvr/ipvr_fence.c new file +4 -0
+		if (intr) {
+			ret = wait_event_interruptible_timeout(
+				dev_priv->fence_queue,
+				(signaled = ipvr_fence_signaled(dev_priv,

target_seq)),

drivers/gpu/drm/ipvr/ipvr_fence.c new file +5 -0
+				timeout);
+		} else {
+			ret = wait_event_timeout(
+				dev_priv->fence_queue,
+				(signaled = ipvr_fence_signaled(dev_priv,

target_seq)),

drivers/gpu/drm/ipvr/ipvr_fence.c new file +3 -0
+				timeout);
+		}
+		spin_lock_irqsave(&dev_priv->fence_drv.fence_lock,

irq_flags);

drivers/gpu/drm/ipvr/ipvr_fence.c new file +22 -0
+
+		if (unlikely(!signaled)) {
+			/* we were interrupted for some reason and fence
+			 * isn't signaled yet, resume waiting until timeout  */
+			if (unlikely(ret < 0)) {
+				/* should return -ERESTARTSYS,
+				 * interrupted by a signal */
+				continue;
+			}
+
+			/* check if sequence value has changed since
+			 * last_activity */
+			if (signaled_seq !=
+				atomic_read(&fence_drv->signaled_seq)) {
+				continue;
+			}
+
+			if (last_activity != fence_drv->last_activity) {
+				continue;
+			}
+
+			/* lockup happen, it is better have some reg to check

*/

drivers/gpu/drm/ipvr/ipvr_fence.c new file +1 -0
+			IPVR_DEBUG_WARN("VPU lockup (waiting for 0x%0x

last "

drivers/gpu/drm/ipvr/ipvr_fence.c new file +7 -0
+					"signaled fence id 0x%x).\n",
+					target_seq, signaled_seq);
+
+			/* change last activity so nobody else
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

fence_drv.fence_lock,

drivers/gpu/drm/ipvr/ipvr_fence.c new file +28 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

singaled.\n");

drivers/gpu/drm/ipvr/ipvr_fence.c new file +22 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

fence_drv.signaled_seq),

drivers/gpu/drm/ipvr/ipvr_fence.c new file +14 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

fence_drv.signaled_seq),

drivers/gpu/drm/ipvr/ipvr_fence.c new file +51 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

seq %d.\n",

drivers/gpu/drm/ipvr/ipvr_fence.c new file +79 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

{

drivers/gpu/drm/ipvr/ipvr_fence.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

fence\n",

drivers/gpu/drm/ipvr/ipvr_fence.c new file +5 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/ipvr/ipvr_fence.h new file +1 -0
new file mode 100644
index 0000000..91c1bc6

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*****************
+ * ipvr_fence.h: IPVR header file for fence handling
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ipvr_fence.h new file +34 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

err);

drivers/gpu/drm/ipvr/ipvr_fence.h new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

drm_ipvr_private *dev_priv);

drivers/gpu/drm/ipvr/ipvr_fence.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*fence);

drivers/gpu/drm/ipvr/ipvr_fence.h new file +6 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/ipvr/ipvr_gem.c new file +1 -0
new file mode 100644
index 0000000..94c266a

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*****************
+ * ipvr_gem.c: IPVR hook file for gem ioctls
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ipvr_gem.c new file +34 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

stide %d.\n",

drivers/gpu/drm/ipvr/ipvr_gem.c new file +49 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

{

drivers/gpu/drm/ipvr/ipvr_gem.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

cmds exist!\n");

drivers/gpu/drm/ipvr/ipvr_gem.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

ctx_id);

drivers/gpu/drm/ipvr/ipvr_gem.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

args->ctx_id);

drivers/gpu/drm/ipvr/ipvr_gem.c new file +61 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

handle);

drivers/gpu/drm/ipvr/ipvr_gem.c new file +13 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

base.vma_node);

drivers/gpu/drm/ipvr/ipvr_gem.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%llx.\n",

drivers/gpu/drm/ipvr/ipvr_gem.c new file +16 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

handle));

drivers/gpu/drm/ipvr/ipvr_gem.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

status\n",

drivers/gpu/drm/ipvr/ipvr_gem.c new file +19 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

in
+ * the timeout parameter.

+ *  -ETIME: object is still busy after timeout
+ *  -ERESTARTSYS: signal interrupted the wait
+ *  -ENONENT: object doesn't exist
+ * Also possible, but rare:
+ *  -EAGAIN: VPU wedged
+ *  -ENOMEM: damn
+ *  -ENODEV: Internal IRQ fail
+ *  -E?: The add request failed

+ *
+ * The wait ioctl with a timeout of 0 reimplements the busy ioctl. With any
+ * non-zero timeout parameter the wait ioctl will wait for the given number of
+ * nanoseconds on an object becoming unbusy. Since the wait itself does so
+ * without holding struct_mutex the object may become re-busied before this
+ * function completes. A similar but shorter * race condition exists in the busy
+ * ioctl
+ */

drivers/gpu/drm/ipvr/ipvr_gem.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

handle);

drivers/gpu/drm/ipvr/ipvr_gem.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

handle));

drivers/gpu/drm/ipvr/ipvr_gem.c new file +25 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

handle);

drivers/gpu/drm/ipvr/ipvr_gem.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

handle));

drivers/gpu/drm/ipvr/ipvr_gem.c new file +12 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/ipvr/ipvr_gem.h new file +1 -0
new file mode 100644
index 0000000..525f630

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*****************
+ * ipvr_gem.h: IPVR header file for GEM ioctls
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ipvr_gem.h new file +24 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/ipvr/ipvr_mmu.c new file +1 -0
new file mode 100644
index 0000000..0f8f364

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*****************
+ * ipvr_mmu.c: IPVR MMU handling to support VED, VEC, VSP buffer access
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * Copyright (c) Imagination Technologies Limited, UK
+ * Copyright (c) 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ipvr_mmu.c new file +19 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

and
+ * no other functions that may be using the locks for other purposed may be
+ * called from within the locked region.
+ * Since the slots are per processor, this will guarantee that we are the only
+ * user.
+ */

drivers/gpu/drm/ipvr/ipvr_mmu.c new file +188 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

invalid_type);

drivers/gpu/drm/ipvr/ipvr_mmu.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

invalid_type);

drivers/gpu/drm/ipvr/ipvr_mmu.c new file +130 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

addr)

drivers/gpu/drm/ipvr/ipvr_mmu.c new file +105 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*driver)

drivers/gpu/drm/ipvr/ipvr_mmu.c new file +12 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*driver)

drivers/gpu/drm/ipvr/ipvr_mmu.c new file +86 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%lx, "

drivers/gpu/drm/ipvr/ipvr_mmu.c new file +26 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

v[ipvr_mmu_pt_index(addr)]);

drivers/gpu/drm/ipvr/ipvr_mmu.c new file +23 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

address,

drivers/gpu/drm/ipvr/ipvr_mmu.c new file +54 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

PAGE_SHIFT);

drivers/gpu/drm/ipvr/ipvr_mmu.c new file +50 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%lx\n", pfn);

drivers/gpu/drm/ipvr/ipvr_mmu.c new file +24 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

PAGE_SHIFT);

drivers/gpu/drm/ipvr/ipvr_mmu.c new file +2 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/ipvr/ipvr_mmu.h new file +1 -0
new file mode 100644
index 0000000..1f524d4

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*****************
+ * ipvr_mmu.h: IPVR header file for VED/VEC/VSP MMU handling
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * Copyright (c) Imagination Technologies Limited, UK
+ * Copyright (c) 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:

+ *    Eric Anholt <[email protected]>
+ *    Fei Jiang <[email protected]>
+ *    Yao Cheng <[email protected]>

+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ipvr_mmu.h new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

offset)

drivers/gpu/drm/ipvr/ipvr_mmu.h new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

long offset)

drivers/gpu/drm/ipvr/ipvr_mmu.h new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

long err)

drivers/gpu/drm/ipvr/ipvr_mmu.h new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MMU only */
+#define IPVR_MMU_RO_MEMORY (1 << 1) /* MMU RO
memory */
+#define IPVR_MMU_WO_MEMORY (1 << 2) /* MMU WO memory
*/

drivers/gpu/drm/ipvr/ipvr_mmu.h new file +37 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

__iomem *registers,

drivers/gpu/drm/ipvr/ipvr_mmu.h new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

hw_context);

drivers/gpu/drm/ipvr/ipvr_mmu.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*driver);

drivers/gpu/drm/ipvr/ipvr_mmu.h new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

type);

drivers/gpu/drm/ipvr/ipvr_mmu.h new file +6 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/ipvr/ipvr_trace.c new file +11 -0
new file mode 100644
index 0000000..91c0bda

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/ipvr/ipvr_trace.h new file +1 -0
new file mode 100644
index 0000000..6ea8b9a

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*****************
+ * ipvr_trace.h: IPVR header file for trace support
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ipvr_trace.h new file +37 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

mmu_offset=0x%llx",

drivers/gpu/drm/ipvr/ipvr_trace.h new file +34 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

sync_seq=%d",

drivers/gpu/drm/ipvr/ipvr_trace.h new file +22 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

sync_seq=%d",

drivers/gpu/drm/ipvr/ipvr_trace.h new file +23 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

sync_seq=%d",

drivers/gpu/drm/ipvr/ipvr_trace.h new file +120 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*completed_msg),

drivers/gpu/drm/ipvr/ipvr_trace.h new file +18 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

mb=[%u, %u]",

drivers/gpu/drm/ipvr/ipvr_trace.h new file +36 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

rsvd=0x%04x, "

drivers/gpu/drm/ipvr/ipvr_trace.h new file +19 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/ipvr/ved_cmd.c new file +1 -0
new file mode 100644
index 0000000..d9de33e

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*****************
+ * ved_cmd.c: VED command handling between host driver and VED firmware
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * Copyright (c) Imagination Technologies Limited, UK
+ * Copyright (c) 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ved_cmd.c new file +46 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&

drivers/gpu/drm/ipvr/ved_cmd.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ret);

drivers/gpu/drm/ipvr/ved_cmd.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&

drivers/gpu/drm/ipvr/ved_cmd.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(IPVR_REG_READ32(MSVDX_COMMS_TO_MTX_BUF_SIZE) >> 16) +

0x2000;

drivers/gpu/drm/ipvr/ved_cmd.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

"

drivers/gpu/drm/ipvr/ved_cmd.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

is %d.\n",

drivers/gpu/drm/ipvr/ved_cmd.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

empty

drivers/gpu/drm/ipvr/ved_cmd.c new file +16 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

IPVR_REG_READ32(MSVDX_COMMS_TO_MTX_WRT_INDEX);

drivers/gpu/drm/ipvr/ved_cmd.c new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ret);

drivers/gpu/drm/ipvr/ved_cmd.c new file +43 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

header.bits.msg_fence;

drivers/gpu/drm/ipvr/ved_cmd.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

cur_cmd_size %u.\n",

drivers/gpu/drm/ipvr/ved_cmd.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

cur_seq);

drivers/gpu/drm/ipvr/ved_cmd.c new file +11 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

cur_cmd_size);

drivers/gpu/drm/ipvr/ved_cmd.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

cur_cmd_size);

drivers/gpu/drm/ipvr/ved_cmd.c new file +27 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

cmd_seq);

drivers/gpu/drm/ipvr/ved_cmd.c new file +32 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

cmd_seq, IPVR_CMD_SKIP);

drivers/gpu/drm/ipvr/ved_cmd.c new file +35 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

msvdx_mmu_invalid;

drivers/gpu/drm/ipvr/ved_cmd.c new file +25 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

{

drivers/gpu/drm/ipvr/ved_cmd.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

size.\n");

drivers/gpu/drm/ipvr/ved_cmd.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

dev_priv->mmu);

drivers/gpu/drm/ipvr/ved_cmd.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

addr32.\n");

drivers/gpu/drm/ipvr/ved_cmd.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

dev_priv->ipvr_mmu_invaldc, 1, 0);

drivers/gpu/drm/ipvr/ved_cmd.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

FW_INVALIDATE_MMU;

drivers/gpu/drm/ipvr/ved_cmd.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

invalidate\n");

drivers/gpu/drm/ipvr/ved_cmd.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

default_ctx.ctx_id;

drivers/gpu/drm/ipvr/ved_cmd.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

mmu_ptd >> 8;

drivers/gpu/drm/ipvr/ved_cmd.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

header.bits.msg_fence,

drivers/gpu/drm/ipvr/ved_cmd.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

flag_size.bits.buffer_size,

drivers/gpu/drm/ipvr/ved_cmd.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

mmu_context.bits.context,

drivers/gpu/drm/ipvr/ved_cmd.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

mmu_context.bits.mmu_ptd,

drivers/gpu/drm/ipvr/ved_cmd.c new file +22 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

validate_ctx.validate_list,

drivers/gpu/drm/ipvr/ved_cmd.c new file +16 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

default_tiling_scheme,

drivers/gpu/drm/ipvr/ved_cmd.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ipvr_ctx);

drivers/gpu/drm/ipvr/ved_cmd.c new file +61 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

sequence);

drivers/gpu/drm/ipvr/ved_cmd.c new file +102 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*cmd_buffer,

drivers/gpu/drm/ipvr/ved_cmd.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

cmdbuf_size, ipvr_ctx, 0);

drivers/gpu/drm/ipvr/ved_cmd.c new file +37 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

IPVR_REG_READ32(MSVDX_DMAC_STREAM_STATUS_OFFSET);

drivers/gpu/drm/ipvr/ved_cmd.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%x,"

drivers/gpu/drm/ipvr/ved_cmd.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dmac_sts);

drivers/gpu/drm/ipvr/ved_cmd.c new file +13 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

IPVR_CMD_FAILED);

drivers/gpu/drm/ipvr/ved_cmd.c new file +35 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

seq=0x%04x.\n", fence);

drivers/gpu/drm/ipvr/ved_cmd.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*/

drivers/gpu/drm/ipvr/ved_cmd.c new file +30 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

IPVR_REG_READ32(MSVDX_COMMS_TO_HOST_WRT_INDEX);

drivers/gpu/drm/ipvr/ved_cmd.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

IPVR_REG_READ32(MSVDX_COMMS_TO_HOST_BUF_SIZE) &

drivers/gpu/drm/ipvr/ved_cmd.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

(IPVR_REG_READ32(MSVDX_COMMS_TO_HOST_BUF_SIZE) >> 16)

drivers/gpu/drm/ipvr/ved_cmd.c new file +30 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*)buf;

drivers/gpu/drm/ipvr/ved_cmd.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

irq pairing

drivers/gpu/drm/ipvr/ved_cmd.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

true) < 0)) {

drivers/gpu/drm/ipvr/ved_cmd.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

power\n");

drivers/gpu/drm/ipvr/ved_cmd.c new file +12 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

safely call

drivers/gpu/drm/ipvr/ved_cmd.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

true) < 0)) {

drivers/gpu/drm/ipvr/ved_cmd.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ID:0x%08x.\n",

drivers/gpu/drm/ipvr/ved_cmd.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

read.\n");

drivers/gpu/drm/ipvr/ved_cmd.c new file +14 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

IPVR_REG_READ32(MSVDX_INTERRUPT_STATUS_OFFSET);

drivers/gpu/drm/ipvr/ved_cmd.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_INTERRUPT_STATUS_MMU_FAULT_IRQ_MASK) {

drivers/gpu/drm/ipvr/ved_cmd.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

IPVR_REG_WRITE32(MSVDX_MMU_CONTROL0_MMU_PAUSE_MAS
K,

drivers/gpu/drm/ipvr/ved_cmd.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

IPVR_REG_WRITE32(MSVDX_INTERRUPT_STATUS_MMU_FAULT_IR
Q_MASK,

drivers/gpu/drm/ipvr/ved_cmd.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_INTERRUPT_STATUS_MTX_IRQ_MASK) {

drivers/gpu/drm/ipvr/ved_cmd.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

msvdx_stat);

drivers/gpu/drm/ipvr/ved_cmd.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_INTERRUPT_CLEAR_OFFSET);

drivers/gpu/drm/ipvr/ved_cmd.c new file +30 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_INTERRUPT_STATUS,

drivers/gpu/drm/ipvr/ved_cmd.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&&

drivers/gpu/drm/ipvr/ved_cmd.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_INTERRUPT_STATUS_MMU_FAULT_IRQ_MASK) &&

drivers/gpu/drm/ipvr/ved_cmd.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

core_reset.\n");

drivers/gpu/drm/ipvr/ved_cmd.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

requests */

drivers/gpu/drm/ipvr/ved_cmd.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reg is 0x%x,\n"

drivers/gpu/drm/ipvr/ved_cmd.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	IPVR_REG_READ32(MSVDX_MMU_MEM_REQ_OFFSET),
+
	IPVR_REG_READ32(MSVDX_COMMS_FW_STATUS),
+
	IPVR_REG_READ32(MSVDX_COMMS_ERROR_TRIG));
drivers/gpu/drm/ipvr/ved_cmd.c new file +14 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*/

drivers/gpu/drm/ipvr/ved_cmd.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_RESET_NEEDS_REUPLOAD_FW) {

drivers/gpu/drm/ipvr/ved_cmd.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

~MSVDX_RESET_NEEDS_REUPLOAD_FW;

drivers/gpu/drm/ipvr/ved_cmd.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

err\n");

drivers/gpu/drm/ipvr/ved_cmd.c new file +4 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/ipvr/ved_cmd.h new file +1 -0
new file mode 100644
index 0000000..f604b02

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*****************
+ * ved_cmd.h: VED header file to support command buffer handling
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * Copyright (c) Imagination Technologies Limited, UK
+ * Copyright (c) 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ved_cmd.h new file +39 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

cmd_size,

drivers/gpu/drm/ipvr/ved_cmd.h new file +5 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0
new file mode 100644
index 0000000..43682da

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*****************
+ * ved_fw.c: VED initialization and mtx-firmware upload
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * Copyright (c) Imagination Technologies Limited, UK
+ * Copyright (c) 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ved_fw.c new file +32 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MTX_IRQ, 1);

drivers/gpu/drm/ipvr/ved_fw.c new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MTX_IRQ, 0);

drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_HOST_INTERRUPT_ENABLE_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MTX_IRQ,

drivers/gpu/drm/ipvr/ved_fw.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_HOST_INTERRUPT_ENABLE_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +24 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

register %08x:"

drivers/gpu/drm/ipvr/ved_fw.c new file +13 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

IPVR_REG_READ32(MSVDX_MAN_CLK_ENABLE_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_MAN_CLK_ENABLE_CORE_MAN_CLK_ENABLE_MASK,

drivers/gpu/drm/ipvr/ved_fw.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_MAN_CLK_ENABLE_CORE_MAN_CLK_ENABLE_MASK,

drivers/gpu/drm/ipvr/ved_fw.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_MAN_CLK_ENABLE_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_MAN_CLK_ENABLE_CORE_MAN_CLK_ENABLE_MASK;

drivers/gpu/drm/ipvr/ved_fw.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_MAN_CLK_ENABLE_CORE_MAN_CLK_ENABLE_MASK,

drivers/gpu/drm/ipvr/ved_fw.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_MAN_CLK_ENABLE_CORE_MAN_CLK_ENABLE_MASK,

drivers/gpu/drm/ipvr/ved_fw.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_MAN_CLK_ENABLE_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_MAN_CLK_ENABLE_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +28 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&&

drivers/gpu/drm/ipvr/ved_fw.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_INTERRUPT_STATUS_MMU_FAULT_IRQ_MASK) &&

drivers/gpu/drm/ipvr/ved_fw.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

PAGE_SHIFT;

drivers/gpu/drm/ipvr/ved_fw.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_MMU_DIR_LIST_BASE_OFFSET + 0);

drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_MMU_DIR_LIST_BASE_OFFSET + 4);

drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_MMU_DIR_LIST_BASE_OFFSET + 8);

drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_MMU_DIR_LIST_BASE_OFFSET + 12);

drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

IPVR_REG_WRITE32(MSVDX_INTERRUPT_STATUS_MMU_FAULT_IR
Q_MASK,
+

	MSVDX_INTERRUPT_STATUS_OFFSET);
drivers/gpu/drm/ipvr/ved_fw.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_MMU_MEM_REQ_OFFSET,

drivers/gpu/drm/ipvr/ved_fw.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	IPVR_REG_READ32(MSVDX_MMU_MEM_REQ_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

RENDEC_DEC_DISABLE, 1);

drivers/gpu/drm/ipvr/ved_fw.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

int)~MSVDX_CONTROL_MSVDX_SOFT_RESET_MASK,

drivers/gpu/drm/ipvr/ved_fw.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_MMU_MEM_REQ_OFFSET,

drivers/gpu/drm/ipvr/ved_fw.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

IPVR_REG_WRITE32(MSVDX_CONTROL_MSVDX_SOFT_RESET_MAS
K,

drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_CONTROL_OFFSET, 0,
+
MSVDX_CONTROL_MSVDX_SOFT_RESET_MASK,

drivers/gpu/drm/ipvr/ved_fw.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_HOST_INTERRUPT_ENABLE_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_INTERRUPT_CLEAR_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

is %d,\n"

drivers/gpu/drm/ipvr/ved_fw.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	IPVR_REG_READ32(MSVDX_CONTROL_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	IPVR_REG_READ32(MSVDX_MMU_MEM_REQ_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +16 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

IPVR_REG_WRITE32(MSVDX_CONTROL_MSVDX_SOFT_RESET_MAS
K,

drivers/gpu/drm/ipvr/ved_fw.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

2000000, 5);

drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_HOST_INTERRUPT_ENABLE_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_INTERRUPT_CLEAR_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +11 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	int32_t ccb0_size,
+
	int32_t ccb1_size)
drivers/gpu/drm/ipvr/ved_fw.c new file +16 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0, 0);

drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

buffer: %d.\n", ret);

drivers/gpu/drm/ipvr/ved_fw.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ipvr_gem_object_mmu_offset(ved_priv->ccb0);

drivers/gpu/drm/ipvr/ved_fw.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

buffer: %d.\n", ret);

drivers/gpu/drm/ipvr/ved_fw.c new file +17 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0, 0);

drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

buffer: %d.\n", ret);

drivers/gpu/drm/ipvr/ved_fw.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ipvr_gem_object_mmu_offset(ved_priv->ccb1);

drivers/gpu/drm/ipvr/ved_fw.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

buffer: %d.\n", ret);

drivers/gpu/drm/ipvr/ved_fw.c new file +24 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

base);

drivers/gpu/drm/ipvr/ved_fw.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

base);

drivers/gpu/drm/ipvr/ved_fw.c new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_RENDEC_BASE_ADDR0_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_RENDEC_BASE_ADDR1_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +29 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

RENDEC_INITIALISE, 1);

drivers/gpu/drm/ipvr/ved_fw.c new file +13 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

1024);

drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

1024);

drivers/gpu/drm/ipvr/ved_fw.c new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MTX_DBG_IS_SLAVE, 1);

drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MTX_DBG_GPIO_IN, 0x02);

drivers/gpu/drm/ipvr/ved_fw.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

get_mtx_control_from_dash.\n");

drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

IPVR_REG_READ32(MTX_RAM_ACCESS_CONTROL_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MTX_RAM_ACCESS_CONTROL_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +17 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dma_channel));

drivers/gpu/drm/ipvr/ved_fw.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dma_channel));

drivers/gpu/drm/ipvr/ved_fw.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dma_channel));

drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%x\n",
+
IPVR_REG_READ32(DMAC_DMAC_PERIPHERAL_ADDR_OFFSET +

drivers/gpu/drm/ipvr/ved_fw.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	IPVR_REG_READ32(DMAC_DMAC_IRQ_STAT_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	IPVR_REG_READ32(MSVDX_MMU_CONTROL0_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dma_channel));

drivers/gpu/drm/ipvr/ved_fw.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

value is 0x%x\n",
+
IPVR_REG_READ32(MTX_REGISTER_READ_WRITE_REQUEST_OFFSET
));

drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%x\n",
+

	IPVR_REG_READ32(MTX_RAM_ACCESS_CONTROL_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%x\n",
+

	IPVR_REG_READ32(MTX_RAM_ACCESS_STATUS_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +15 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%x\n",
+

	IPVR_REG_READ32(MSVDX_INTERRUPT_CLEAR_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%x\n",
+

	IPVR_REG_READ32(MSVDX_INTERRUPT_STATUS_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

value is 0x%x\n",
+

	IPVR_REG_READ32(MSVDX_HOST_INTERRUPT_ENABLE_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%x\n",
+

	IPVR_REG_READ32(MSVDX_MAN_CLK_ENABLE_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%x\n",
+

	IPVR_REG_READ32(MSVDX_MMU_STATUS_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%x\n",
+

	IPVR_REG_READ32(FE_MSVDX_WDT_CONTROL_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%x\n",
+

	IPVR_REG_READ32(BE_MSVDX_WDT_CONTROL_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	IPVR_REG_READ32(VEC_SHIFTREG_CONTROL_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%x\n",
+

	IPVR_REG_READ32(MSVDX_RENDEC_CONTROL0_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%x\n",
+

	IPVR_REG_READ32(MSVDX_RENDEC_BUFFER_SIZE_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%x\n",
+

	IPVR_REG_READ32(MSVDX_RENDEC_BASE_ADDR0_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

is 0x%x\n",
+

	IPVR_REG_READ32(MSVDX_RENDEC_BASE_ADDR1_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%x\n",
+

	IPVR_REG_READ32(MSVDX_RENDEC_READ_DATA_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%x\n",
+

	IPVR_REG_READ32(MSVDX_RENDEC_CONTEXT0_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%x\n",
+

	IPVR_REG_READ32(MSVDX_RENDEC_CONTEXT1_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

value is 0x%x\n",
+

	IPVR_REG_READ32(MSVDX_CMDS_END_SLICE_PICTURE_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	IPVR_REG_READ32(MSVDX_MMU_MEM_REQ_OFFSET));
drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x%x\n",

drivers/gpu/drm/ipvr/ved_fw.c new file +24 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

4);

drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*/

drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	1);
drivers/gpu/drm/ipvr/ved_fw.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	words);
drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*/

drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

DMAC_CH0_SELECT, 0);

drivers/gpu/drm/ipvr/ved_fw.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dma_channel);

drivers/gpu/drm/ipvr/ved_fw.c new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

mmu);

drivers/gpu/drm/ipvr/ved_fw.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_MMU_DIR_LIST_BASE_OFFSET + 0);

drivers/gpu/drm/ipvr/ved_fw.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MMU_INVALDC, 1);

drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dma_channel);

drivers/gpu/drm/ipvr/ved_fw.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

upload.\n");

drivers/gpu/drm/ipvr/ved_fw.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

IPVR_DMAC_VALUE_COUNT(IPVR_DMAC_BSWAP_NO_SWAP, 0,

drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0, (size >> 2));

drivers/gpu/drm/ipvr/ved_fw.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dma_channel);

drivers/gpu/drm/ipvr/ved_fw.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

IPVR_DMAC_VALUE_PERIPH_PARAM(IPVR_DMAC_ACC_DEL_0,

drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dma_channel);

drivers/gpu/drm/ipvr/ved_fw.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

DMAC_DMAC_PERIPHERAL_ADDR_OFFSET + dma_channel);

drivers/gpu/drm/ipvr/ved_fw.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

dma_channel,
+
DMAC_DMAC_IRQ_STAT_TRANSFER_FIN_MASK,
+
DMAC_DMAC_IRQ_STAT_TRANSFER_FIN_MASK,

drivers/gpu/drm/ipvr/ved_fw.c new file +30 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

platformdev->dev);

drivers/gpu/drm/ipvr/ved_fw.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Reason %d.\n", name, rc);

drivers/gpu/drm/ipvr/ved_fw.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

(*raw)->size);

drivers/gpu/drm/ipvr/ved_fw.c new file +30 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

mtx_mem_size);

drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_MTX_DATA_LOCATION),

drivers/gpu/drm/ipvr/ved_fw.c new file +19 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

char *name)

drivers/gpu/drm/ipvr/ved_fw.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

platformdev->dev);

drivers/gpu/drm/ipvr/ved_fw.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Reason %d\n",

drivers/gpu/drm/ipvr/ved_fw.c new file +50 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MTX_REGISTER_READ_WRITE_DATA_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MTX_REGISTER_READ_WRITE_REQUEST,

drivers/gpu/drm/ipvr/ved_fw.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MTX_REGISTER_READ_WRITE_REQUEST,

drivers/gpu/drm/ipvr/ved_fw.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MTX_REGISTER_READ_WRITE_REQUEST_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MTX_REGISTER_READ_WRITE_REQUEST_MTX_DREADY_MASK,
+
MTX_REGISTER_READ_WRITE_REQUEST_MTX_DREADY_MASK,

drivers/gpu/drm/ipvr/ved_fw.c new file +24 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

4096, 0, 0);

drivers/gpu/drm/ipvr/ved_fw.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

fw_bo);

drivers/gpu/drm/ipvr/ved_fw.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

base);

drivers/gpu/drm/ipvr/ved_fw.c new file +24 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_COMMS_FIRMWARE_ID);

drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MTX_SYSC_TIMERDIV */

drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

EXT_FW_ERROR_STATE */

drivers/gpu/drm/ipvr/ved_fw.c new file +18 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

IPVR_REG_READ32(MSVDX_MTX_RAM_BANK_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ram_bank_size);

drivers/gpu/drm/ipvr/ved_fw.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

udevd\n");

drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

running?\n");

drivers/gpu/drm/ipvr/ved_fw.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

BO\n");

drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ved_get_fw_bo: %d.\n", ret);

drivers/gpu/drm/ipvr/ved_fw.c new file +17 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

data_location);

drivers/gpu/drm/ipvr/ved_fw.c new file +11 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MTX_ENABLE_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +26 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

DSIABLE_Auto_CLOCK_GATING |

drivers/gpu/drm/ipvr/ved_fw.c new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_COMMS_FIRMWARE_ID);

drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_COMMS_OFFSET_FLAGS);

drivers/gpu/drm/ipvr/ved_fw.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

IPVR_REG_READ32(MSVDX_MTX_RAM_BANK_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +29 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

as 0x1 */

drivers/gpu/drm/ipvr/ved_fw.c new file +38 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ret);

drivers/gpu/drm/ipvr/ved_fw.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

FE_MSVDX_WDT_COMPAREMATCH_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

BE_MSVDX_WDT_COMPAREMATCH_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

FE_MSVDX_WDT_COMPAREMATCH_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

BE_MSVDX_WDT_COMPAREMATCH_OFFSET);

drivers/gpu/drm/ipvr/ved_fw.c new file +35 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

failed: %d.\n", ret);

drivers/gpu/drm/ipvr/ved_fw.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ved_private.\n");

drivers/gpu/drm/ipvr/ved_fw.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

failed: %d.\n", ret);

drivers/gpu/drm/ipvr/ved_fw.c new file +36 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

fw_bo->base);

drivers/gpu/drm/ipvr/ved_fw.c new file +14 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/ipvr/ved_fw.h new file +1 -0
new file mode 100644
index 0000000..3ced466

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*****************
+ * ved_fw.h: VED firmware support header file
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * Copyright (c) Imagination Technologies Limited, UK
+ * Copyright (c) 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ved_fw.h new file +14 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	0x00000020
drivers/gpu/drm/ipvr/ved_fw.h new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	0x00000200
+#define MSVDX_DEVICE_NODE_FLAGS_DEFAULT_D0
		\
drivers/gpu/drm/ipvr/ved_fw.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

		\
drivers/gpu/drm/ipvr/ved_fw.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

		\
drivers/gpu/drm/ipvr/ved_fw.h new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

		\
drivers/gpu/drm/ipvr/ved_fw.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

		\
drivers/gpu/drm/ipvr/ved_fw.h new file +29 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/ipvr/ved_msg.h new file +1 -0
new file mode 100644
index 0000000..1a1e89d

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*****************
+ * ved_msg.h: VED message definition
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * Copyright (c) 2003 Imagination Technologies Limited, UK
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:

+ *    Fei Jiang <[email protected]>
+ *    Li Zeng <[email protected]>
+ *    Yao Cheng <[email protected]>

+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ved_msg.h new file +38 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

FWRK_MSGID_START_PSR_MTXHOST_MSG,

drivers/gpu/drm/ipvr/ved_msg.h new file +192 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/ipvr/ved_pm.c new file +1 -0
new file mode 100644
index 0000000..ee11c39

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*****************
+ * ved_pm.c: VED power management support
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ved_pm.c new file +49 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

0x13: code))
+#define GET_FREQ_CODE(freq_num) FREQ_CODE_CLAMP((((1600 *
2/freq_num + 1) >> 1) << 1) - 1)

drivers/gpu/drm/ipvr/ved_pm.c new file +15 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MTX_SOFT_RESET_OFFSET);

drivers/gpu/drm/ipvr/ved_pm.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ret);

drivers/gpu/drm/ipvr/ved_pm.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

4);

drivers/gpu/drm/ipvr/ved_pm.c new file +17 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

PCI_ROOT_MSGBUS_CTRL_EXT_REG,

drivers/gpu/drm/ipvr/ved_pm.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&data);

drivers/gpu/drm/ipvr/ved_pm.c new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

u32 data)

drivers/gpu/drm/ipvr/ved_pm.c new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

data);

drivers/gpu/drm/ipvr/ved_pm.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

PCI_ROOT_MSGBUS_CTRL_EXT_REG,

drivers/gpu/drm/ipvr/ved_pm.c new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

u32 *freq_code_rlzd)

drivers/gpu/drm/ipvr/ved_pm.c new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

reg_freq);

drivers/gpu/drm/ipvr/ved_pm.c new file +27 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

~IP_FREQ_VALID);

drivers/gpu/drm/ipvr/ved_pm.c new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

u32 freq_code, u32 *p_freq_code_rlzd)

drivers/gpu/drm/ipvr/ved_pm.c new file +15 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

&freq_code_realized);

drivers/gpu/drm/ipvr/ved_pm.c new file +54 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

VEDSSPM0, VED_APM_STS_D0);

drivers/gpu/drm/ipvr/ved_pm.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

PUNIT_PORT, VEDSSPM0);

drivers/gpu/drm/ipvr/ved_pm.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

VEDSSPM0, VED_APM_STS_D3);

drivers/gpu/drm/ipvr/ved_pm.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

PUNIT_PORT, VEDSSPM0);

drivers/gpu/drm/ipvr/ved_pm.c new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

VEDSSPM0, VED_APM_STS_D0);

drivers/gpu/drm/ipvr/ved_pm.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

PUNIT_PORT, VEDSSPM0);

drivers/gpu/drm/ipvr/ved_pm.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

VEDSSPM0, VED_APM_STS_D3);

drivers/gpu/drm/ipvr/ved_pm.c new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

PUNIT_PORT, VEDSSPM0);

drivers/gpu/drm/ipvr/ved_pm.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ved_freq_code_after;

drivers/gpu/drm/ipvr/ved_pm.c new file +15 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

=> %dMHz\n",

drivers/gpu/drm/ipvr/ved_pm.c new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

GET_FREQ_NUMBER(ved_freq_code_before),

drivers/gpu/drm/ipvr/ved_pm.c new file +17 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

powering off\n", ret);

drivers/gpu/drm/ipvr/ved_pm.c new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

ved_freq_code, drm_ipvr_freq);

drivers/gpu/drm/ipvr/ved_pm.c new file +12 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

VEDSSPM0);

drivers/gpu/drm/ipvr/ved_pm.c new file +2 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/ipvr/ved_pm.h new file +1 -0
new file mode 100644
index 0000000..4ed1485

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*****************
+ * ved_pm.h: VED power management header file
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ved_pm.h new file +13 -0

Lines of this file are not shown. View the raw message.

drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0
new file mode 100644
index 0000000..b7c69cf

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*****************
+ * ved_reg.h: VED register definition
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * Copyright (c) Imagination Technologies Limited, UK
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

drivers/gpu/drm/ipvr/ved_reg.h new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

(__group__##_##__reg__##_OFFSET)

drivers/gpu/drm/ipvr/ved_reg.h new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

		\
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

		\
+do {
	\
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

		\
+do {
	\
drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

		\
drivers/gpu/drm/ipvr/ved_reg.h new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

		\
+do {
	\
drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
+do {
	\
drivers/gpu/drm/ipvr/ved_reg.h new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

**************
+Offset address Name Identifier
+0x0000 - 0x03FF (1024B) MTX Register
REG_MSVDX_MTX
+0x0400 - 0x047F (128B) VDMC Register REG_MSVDX
_VDMC
+0x0480 - 0x04FF (128B) VDEB Register REG_MSVDX
_VDEB
+0x0500 - 0x05FF (256B) DMAC Register REG_MSVDX
_DMAC
+0x0600 - 0x06FF (256B) MSVDX Core Register REG_MSVDX
_SYS
+0x0700 - 0x07FF (256B) VEC iQ Matrix RAM
REG_MSVDX_VEC_IQRAM
+0x0800 - 0x0FFF (2048B) VEC Registers REG_MSVDX
_VEC
+0x1000 - 0x1FFF (4kB) Command Register REG_MSVDX _CMD
+0x2000 - 0x2FFF (4kB) VEC Local RAM REG_MSVDX
_VEC_RAM
+0x3000 - 0x4FFF (8kB) VEC VLC Table RAM REG_MSVDX
_VEC_VLC
+0x5000 - 0x5FFF (4kB) AXI Register REG_MSVDX _AXI
+*********************************************************
*********************/

drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

****************/

drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00000001)
drivers/gpu/drm/ipvr/ved_reg.h new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00FC)
+#define MTX_REGISTER_READ_WRITE_REQUEST_MTX_DREADY_MASK
	(0x80000000)
+#define MTX_REGISTER_READ_WRITE_REQUEST_MTX_DREADY_SHIFT
	(31)
+#define MTX_REGISTER_READ_WRITE_REQUEST_MTX_RNW_MASK
	(0x00010000)
+#define MTX_REGISTER_READ_WRITE_REQUEST_MTX_RNW_SHIFT
	(16)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00F8)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0104)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0108)
+#define MTX_RAM_ACCESS_CONTROL_MTX_MCMID_MASK
	(0x0FF00000)
+#define MTX_RAM_ACCESS_CONTROL_MTX_MCMID_SHIFT
	(20)
+#define MTX_RAM_ACCESS_CONTROL_MTX_MCM_ADDR_MASK
	(0x000FFFFC)
+#define MTX_RAM_ACCESS_CONTROL_MTX_MCM_ADDR_SHIFT
	(2)
+#define MTX_RAM_ACCESS_CONTROL_MTX_MCMAI_MASK
	(0x00000002)
+#define MTX_RAM_ACCESS_CONTROL_MTX_MCMAI_SHIFT
	(1)
+#define MTX_RAM_ACCESS_CONTROL_MTX_MCMR_MASK
	(0x00000001)
+#define MTX_RAM_ACCESS_CONTROL_MTX_MCMR_SHIFT
	(0)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x010C)
drivers/gpu/drm/ipvr/ved_reg.h new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00000001)
+#define MTX_SOFT_RESET_MTX_RESET_SHIFT
	(0)
+#define	MTX_SOFT_RESET_MTXRESET
	(0x00000001)
drivers/gpu/drm/ipvr/ved_reg.h new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x07000000)
+#define MTX_SYSC_CDMAC_BURSTSIZE_SHIFT
	(24)
+#define MTX_SYSC_CDMAC_RNW_MASK
	(0x00020000)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00010000)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0000FFFF)
drivers/gpu/drm/ipvr/ved_reg.h new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

**************************/

drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

***************/

drivers/gpu/drm/ipvr/ved_reg.h new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0500)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0504)
+#define DMAC_DMAC_COUNT_BSWAP_LSBMASK
	(0x00000001)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00000003)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00000001)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00000003)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0000FFFF)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00010000)
drivers/gpu/drm/ipvr/ved_reg.h new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0508)
+#define DMAC_DMAC_PERIPH_ACC_DEL_LSBMASK
	(0x00000007)
+#define DMAC_DMAC_PERIPH_ACC_DEL_SHIFT
	(29)
+#define DMAC_DMAC_PERIPH_INCR_LSBMASK
	(0x00000001)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00000007)
+#define DMAC_DMAC_PERIPH_BURST_SHIFT
	(24)
drivers/gpu/drm/ipvr/ved_reg.h new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00020000)
drivers/gpu/drm/ipvr/ved_reg.h new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x007FFFFF)
+#define DMAC_DMAC_PERIPHERAL_ADDR_ADDR_LSBMASK
	(0x007FFFFF)
+#define DMAC_DMAC_PERIPHERAL_ADDR_ADDR_SHIFT
	(0)
drivers/gpu/drm/ipvr/ved_reg.h new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

COUNT) \

drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

		\
drivers/gpu/drm/ipvr/ved_reg.h new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

		\
drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

<< \

drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

		\
drivers/gpu/drm/ipvr/ved_reg.h new file +18 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

cycles */

drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

cycles */

drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

cycles */

drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

cycles */

drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

cycles */

drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

cycles */

drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

cycles */

drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

cycles */

drivers/gpu/drm/ipvr/ved_reg.h new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

address. */

drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

address. */

drivers/gpu/drm/ipvr/ved_reg.h new file +13 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

**************************/

drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

***************/
+#define MSVDX_CONTROL_OFFSET

	(0x0600)
+#define MSVDX_CONTROL_MSVDX_SOFT_RESET_MASK
	(0x00000100)
+#define MSVDX_CONTROL_MSVDX_SOFT_RESET_SHIFT
	(8)
+#define MSVDX_CONTROL_DMAC_CH0_SELECT_MASK
	(0x00001000)
+#define MSVDX_CONTROL_DMAC_CH0_SELECT_SHIFT
	(12)
+#define MSVDX_CONTROL_MSVDX_SOFT_RESET_MASK
	(0x00000100)
+#define MSVDX_CONTROL_MSVDX_SOFT_RESET_SHIFT
	(8)
+#define MSVDX_CONTROL_MSVDX_FE_SOFT_RESET_MASK
	(0x00010000)
+#define MSVDX_CONTROL_MSVDX_BE_SOFT_RESET_MASK
	(0x00100000)
+#define MSVDX_CONTROL_MSVDX_VEC_MEMIF_SOFT_RESET_MASK
		(0x01000000)
+#define
MSVDX_CONTROL_MSVDX_VEC_RENDEC_DEC_SOFT_RESET_MASK
	(0x10000000)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	\
drivers/gpu/drm/ipvr/ved_reg.h new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0608)
+#define MSVDX_INTERRUPT_STATUS_MMU_FAULT_IRQ_MASK
	(0x00000F00)
+#define MSVDX_INTERRUPT_STATUS_MMU_FAULT_IRQ_SHIFT
	(8)
+#define MSVDX_INTERRUPT_STATUS_MTX_IRQ_MASK
	(0x00004000)
+#define MSVDX_INTERRUPT_STATUS_MTX_IRQ_SHIFT
	(14)
drivers/gpu/drm/ipvr/ved_reg.h new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

		(0x00000001)
+#define
MSVDX_MAN_CLK_ENABLE_VDEB_PROCESS_MAN_CLK_ENABLE_MASK
	(0x00000002)
+#define
MSVDX_MAN_CLK_ENABLE_VDEB_ACCESS_MAN_CLK_ENABLE_MASK
	(0x00000004)
+#define MSVDX_MAN_CLK_ENABLE_VDMC_MAN_CLK_ENABLE_MASK
		(0x00000008)
+#define
MSVDX_MAN_CLK_ENABLE_VEC_ENTDEC_MAN_CLK_ENABLE_MASK
	(0x00000010)
+#define
MSVDX_MAN_CLK_ENABLE_VEC_ITRANS_MAN_CLK_ENABLE_MASK
	(0x00000020)
+#define MSVDX_MAN_CLK_ENABLE_MTX_MAN_CLK_ENABLE_MASK
		(0x00000040)

+#define MSVDX_MAN_CLK_ENABLE_VDEB_PROCESS_AUTO_CLK_ENABLE_MASK (0x00020000)
+#define MSVDX_MAN_CLK_ENABLE_VDEB_ACCESS_AUTO_CLK_ENABLE_MASK

	(0x00040000)
+#define MSVDX_MAN_CLK_ENABLE_VDMC_AUTO_CLK_ENABLE_MASK
	(0x00080000)
+#define
MSVDX_MAN_CLK_ENABLE_VEC_ENTDEC_AUTO_CLK_ENABLE_MASK
	(0x00100000)
+#define
MSVDX_MAN_CLK_ENABLE_VEC_ITRANS_AUTO_CLK_ENABLE_MASK
	(0x00200000)
drivers/gpu/drm/ipvr/ved_reg.h new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

			| \

+
MSVDX_MAN_CLK_ENABLE_VDEB_PROCESS_MAN_CLK_ENABLE_M
ASK | \
+
MSVDX_MAN_CLK_ENABLE_VDEB_ACCESS_MAN_CLK_ENABLE_MA
SK | \

drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	 		| \

+
MSVDX_MAN_CLK_ENABLE_VEC_ENTDEC_MAN_CLK_ENABLE_MAS
K | \
+
MSVDX_MAN_CLK_ENABLE_VEC_ITRANS_MAN_CLK_ENABLE_MAS
K | \

drivers/gpu/drm/ipvr/ved_reg.h new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

(MSVDX_MAN_CLK_ENABLE_VDEB_PROCESS_AUTO_CLK_ENABLE_
MASK | \
+
MSVDX_MAN_CLK_ENABLE_VDEB_ACCESS_AUTO_CLK_ENABLE_M
ASK | \

drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

			| \

+
MSVDX_MAN_CLK_ENABLE_VEC_ENTDEC_AUTO_CLK_ENABLE_MA
SK | \
+
MSVDX_MAN_CLK_ENABLE_VEC_ITRANS_AUTO_CLK_ENABLE_MAS
K | \

drivers/gpu/drm/ipvr/ved_reg.h new file +1 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

		| \
drivers/gpu/drm/ipvr/ved_reg.h new file +6 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0648)
drivers/gpu/drm/ipvr/ved_reg.h new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00000002)
+#define MSVDX_MMU_CONTROL0_MMU_PAUSE_SHIFT
	(1)
+#define MSVDX_MMU_CONTROL0_MMU_INVALDC_MASK
	(0x00000008)
+#define MSVDX_MMU_CONTROL0_MMU_INVALDC_SHIFT
	(3)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0688)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x068C)
drivers/gpu/drm/ipvr/ved_reg.h new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0694)
drivers/gpu/drm/ipvr/ved_reg.h new file +9 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x000F0000)
+#define MSVDX_MTX_RAM_BANK_MTX_RAM_BANK_SIZE_SHIFT
	(16)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

MSVDX_MTX_RAM_BANK_OFFSET
+#define MSVDX_MTX_DEBUG_MTX_DBG_IS_SLAVE_MASK

	(0x00000004)
+#define MSVDX_MTX_DEBUG_MTX_DBG_IS_SLAVE_LSBMASK
	(0x00000001)
+#define MSVDX_MTX_DEBUG_MTX_DBG_IS_SLAVE_SHIFT
	(2)
+#define MSVDX_MTX_DEBUG_MTX_DBG_GPIO_IN_MASK
	(0x00000003)
+#define MSVDX_MTX_DEBUG_MTX_DBG_GPIO_IN_LSBMASK
	(0x00000003)
+#define MSVDX_MTX_DEBUG_MTX_DBG_GPIO_IN_SHIFT
	(0)
drivers/gpu/drm/ipvr/ved_reg.h new file +5 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00060000)
+#define FE_MSVDX_WDT_CONTROL_FE_WDT_CNT_CTRL_LSBMASK
	(0x00000003)
+#define FE_MSVDX_WDT_CONTROL_FE_WDT_CNT_CTRL_SHIFT
	(17)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00010000)
+#define FE_MSVDX_WDT_CONTROL_FE_WDT_ENABLE_LSBMASK
	(0x00000001)
+#define FE_MSVDX_WDT_CONTROL_FE_WDT_ENABLE_SHIFT
	(16)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00003000)
+#define FE_MSVDX_WDT_CONTROL_FE_WDT_ACTION1_LSBMASK
	(0x00000003)
+#define FE_MSVDX_WDT_CONTROL_FE_WDT_ACTION1_SHIFT
	(12)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00000100)
+#define FE_MSVDX_WDT_CONTROL_FE_WDT_ACTION0_LSBMASK
	(0x00000001)
+#define FE_MSVDX_WDT_CONTROL_FE_WDT_ACTION0_SHIFT
	(8)
+/* MSVDX_CORE, CR_FE_MSVDX_WDT_CONTROL, FE_WDT_CLEAR_SELECT
*/
+#define FE_MSVDX_WDT_CONTROL_FE_WDT_CLEAR_SELECT_MASK
		(0x00000030)
+#define FE_MSVDX_WDT_CONTROL_FE_WDT_CLEAR_SELECT_LSBMASK
	(0x00000003)
+#define FE_MSVDX_WDT_CONTROL_FE_WDT_CLEAR_SELECT_SHIFT
	(4)
+/* MSVDX_CORE, CR_FE_MSVDX_WDT_CONTROL,
FE_WDT_CLKDIV_SELECT */
+#define FE_MSVDX_WDT_CONTROL_FE_WDT_CLKDIV_SELECT_MASK
		(0x00000007)
+#define FE_MSVDX_WDT_CONTROL_FE_WDT_CLKDIV_SELECT_LSBMASK
	(0x00000007)
+#define FE_MSVDX_WDT_CONTROL_FE_WDT_CLKDIV_SELECT_SHIFT
	(0)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0668)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0000FFFF)
+#define FE_MSVDX_WDTIMER_FE_WDT_COUNTER_LSBMASK
	(0x0000FFFF)
+#define FE_MSVDX_WDTIMER_FE_WDT_COUNTER_SHIFT
	(0)
drivers/gpu/drm/ipvr/ved_reg.h new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*/
+#define FE_MSVDX_WDT_COMPAREMATCH_FE_WDT_CM1_MASK

	(0xFFFF0000)
+#define FE_MSVDX_WDT_COMPAREMATCH_FE_WDT_CM1_LSBMASK
		(0x0000FFFF)
+#define FE_MSVDX_WDT_COMPAREMATCH_FE_WDT_CM1_SHIFT
	(16)
+/* MSVDX_CORE, CR_FE_MSVDX_WDT_COMPAREMATCH, FE_WDT_CM0
*/
+#define FE_MSVDX_WDT_COMPAREMATCH_FE_WDT_CM0_MASK
	(0x0000FFFF)
+#define FE_MSVDX_WDT_COMPAREMATCH_FE_WDT_CM0_LSBMASK
		(0x0000FFFF)
+#define FE_MSVDX_WDT_COMPAREMATCH_FE_WDT_CM0_SHIFT
	(0)
drivers/gpu/drm/ipvr/ved_reg.h new file +4 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x001E0000)
+#define BE_MSVDX_WDT_CONTROL_BE_WDT_CNT_CTRL_LSBMASK
	(0x0000000F)
+#define BE_MSVDX_WDT_CONTROL_BE_WDT_CNT_CTRL_SHIFT
	(17)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00010000)
+#define BE_MSVDX_WDT_CONTROL_BE_WDT_ENABLE_LSBMASK
	(0x00000001)
+#define BE_MSVDX_WDT_CONTROL_BE_WDT_ENABLE_SHIFT
	(16)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00000100)
+#define BE_MSVDX_WDT_CONTROL_BE_WDT_ACTION0_LSBMASK
	(0x00000001)
+#define BE_MSVDX_WDT_CONTROL_BE_WDT_ACTION0_SHIFT
	(8)
+/* MSVDX_CORE, CR_BE_MSVDX_WDT_CONTROL,
BE_WDT_CLEAR_SELECT */
+#define BE_MSVDX_WDT_CONTROL_BE_WDT_CLEAR_SELECT_MASK
		(0x000000F0)
+#define BE_MSVDX_WDT_CONTROL_BE_WDT_CLEAR_SELECT_LSBMASK
	(0x0000000F)
+#define BE_MSVDX_WDT_CONTROL_BE_WDT_CLEAR_SELECT_SHIFT
	(4)
+/* MSVDX_CORE, CR_BE_MSVDX_WDT_CONTROL,
BE_WDT_CLKDIV_SELECT */
+#define BE_MSVDX_WDT_CONTROL_BE_WDT_CLKDIV_SELECT_MASK
		(0x00000007)
+#define BE_MSVDX_WDT_CONTROL_BE_WDT_CLKDIV_SELECT_LSBMASK
	(0x00000007)
+#define BE_MSVDX_WDT_CONTROL_BE_WDT_CLKDIV_SELECT_SHIFT
	(0)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0674)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0000FFFF)
+#define BE_MSVDX_WDTIMER_BE_WDT_COUNTER_LSBMASK
	(0x0000FFFF)
+#define BE_MSVDX_WDTIMER_BE_WDT_COUNTER_SHIFT
	(0)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x678)
+/* MSVDX_CORE, CR_BE_MSVDX_WDT_COMPAREMATCH, BE_WDT_CM0
*/
+#define BE_MSVDX_WDT_COMPAREMATCH_BE_WDT_CM0_MASK
	(0x0000FFFF)
+#define BE_MSVDX_WDT_COMPAREMATCH_BE_WDT_CM0_LSBMASK
		(0x0000FFFF)
+#define BE_MSVDX_WDT_COMPAREMATCH_BE_WDT_CM0_SHIFT
	(0)
drivers/gpu/drm/ipvr/ved_reg.h new file +3 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*************************/

drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

******************/

drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x00000300)
+#define VEC_SHIFTREG_CONTROL_SR_MASTER_SELECT_SHIFT
	(8)

+/************************** VEC Registers end
**************************/

drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

**************************/
+#define MSVDX_RENDEC_CONTROL0_OFFSET

	(0x0868)
+#define MSVDX_RENDEC_CONTROL0_RENDEC_INITIALISE_MASK
	(0x00000001)
+#define MSVDX_RENDEC_CONTROL0_RENDEC_INITIALISE_SHIFT
	(0)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x086C)
+#define
MSVDX_RENDEC_CONTROL1_RENDEC_DECODE_START_SIZE_MASK
	(0x000000FF)
+#define
MSVDX_RENDEC_CONTROL1_RENDEC_DECODE_START_SIZE_SHIFT	(0)
+#define MSVDX_RENDEC_CONTROL1_RENDEC_BURST_SIZE_W_MASK
		(0x000C0000)
+#define MSVDX_RENDEC_CONTROL1_RENDEC_BURST_SIZE_W_SHIFT
		(18)
+#define MSVDX_RENDEC_CONTROL1_RENDEC_BURST_SIZE_R_MASK
		(0x00030000)
+#define MSVDX_RENDEC_CONTROL1_RENDEC_BURST_SIZE_R_SHIFT
		(16)
+#define
MSVDX_RENDEC_CONTROL1_RENDEC_EXTERNAL_MEMORY_MASK
	(0x01000000)
+#define
MSVDX_RENDEC_CONTROL1_RENDEC_EXTERNAL_MEMORY_SHIFT	(24)
+#define MSVDX_RENDEC_CONTROL1_RENDEC_DEC_DISABLE_MASK
	(0x08000000)
+#define MSVDX_RENDEC_CONTROL1_RENDEC_DEC_DISABLE_SHIFT
	(27)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0870)
+#define MSVDX_RENDEC_BUFFER_SIZE_RENDEC_BUFFER_SIZE0_MASK
	(0x0000FFFF)
+#define MSVDX_RENDEC_BUFFER_SIZE_RENDEC_BUFFER_SIZE0_SHIFT
	(0)
+#define MSVDX_RENDEC_BUFFER_SIZE_RENDEC_BUFFER_SIZE1_MASK
	(0xFFFF0000)
+#define MSVDX_RENDEC_BUFFER_SIZE_RENDEC_BUFFER_SIZE1_SHIFT
	(16)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0874)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0878)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0898)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0950)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0954)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0958)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x095C)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0960)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(0x0964)

+/*************************** RENDEC registers end ****************************/

drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

********************/
+#define MSVDX_CMDS_END_SLICE_PICTURE_OFFSET

	(0x1404)

+/****************************** CMD Register end
*****************************/

drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*******************/

drivers/gpu/drm/ipvr/ved_reg.h new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*/
+#define MSVDX_FW_STATUS_HW_IDLE

	0x00000001
drivers/gpu/drm/ipvr/ved_reg.h new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature value */

drivers/gpu/drm/ipvr/ved_reg.h new file +7 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

	(MSVDX_COMMS_AREA_ADDR - 0x08)
+#define MSVDX_COMMS_ERROR_TRIG
	(MSVDX_COMMS_AREA_ADDR - 0x08)
+#define MSVDX_COMMS_FIRMWARE_ID
	(MSVDX_COMMS_AREA_ADDR - 0x0C)
+#define MSVDX_COMMS_OFFSET_FLAGS
	(MSVDX_COMMS_AREA_ADDR + 0x18)
+#define	MSVDX_COMMS_MSG_COUNTER
	(MSVDX_COMMS_AREA_ADDR - 0x04)
+#define MSVDX_COMMS_FW_STATUS
	(MSVDX_COMMS_AREA_ADDR - 0x10)
+#define	MSVDX_COMMS_SIGNATURE
	(MSVDX_COMMS_AREA_ADDR + 0x00)
+#define	MSVDX_COMMS_TO_HOST_BUF_SIZE
	(MSVDX_COMMS_AREA_ADDR + 0x04)
+#define MSVDX_COMMS_TO_HOST_RD_INDEX
	(MSVDX_COMMS_AREA_ADDR + 0x08)
+#define MSVDX_COMMS_TO_HOST_WRT_INDEX
	(MSVDX_COMMS_AREA_ADDR + 0x0C)
+#define MSVDX_COMMS_TO_MTX_BUF_SIZE
	(MSVDX_COMMS_AREA_ADDR + 0x10)
+#define MSVDX_COMMS_TO_MTX_RD_INDEX
	(MSVDX_COMMS_AREA_ADDR + 0x14)
+#define MSVDX_COMMS_TO_MTX_CB_RD_INDEX
	(MSVDX_COMMS_AREA_ADDR + 0x18)
+#define MSVDX_COMMS_TO_MTX_WRT_INDEX
	(MSVDX_COMMS_AREA_ADDR + 0x1C)
+#define MSVDX_COMMS_TO_HOST_BUF
	(MSVDX_COMMS_AREA_ADDR + 0x20)
drivers/gpu/drm/ipvr/ved_reg.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

(NUM_WORDS_HOST_BUF << 2))

drivers/gpu/drm/ipvr/ved_reg.h new file +46 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

*****************************/

drivers/gpu/drm/ipvr/ved_reg.h new file +2 -1

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 1 line

2.1.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Part of the diff is not shown here. View the raw message.

#5 lore raw

RFC PATCH v4 3/4 ipvr: user mode helper for ipvr drm driver

In reply to Sean V Kelley

From: Yao Cheng <[email protected]>

add usermode helper for the ipvr kernel driver.
test_ioctl: test kernel driver by directly ioctl

v2:
take Emil's comments
- correctly align ipvr_drm.h

v3:
take Daniel Vetter and Daniel Stone's comments, and implement PRIME
- correctly align ipvr_drm.h
- use __u32 family in ipvr_drm.h
- rip out explicit fence from libdrm_ipvr
- implemented PRIME support
- add relocation fixup implementation

v4
bug fixing and add stress test tool
- rename ipvr/test_ioctl.c to ipvr/test_ipvr.c
- implement parallel ioctl stress test in test_ipvr.c
- implement parallel libdrm stress test in test_ipvr.c
- update ipvr_drm.h to keep consistent with kernel change
- remove unused "buffer_ofs/alloc_size/ext_handle" from struct drm_ipvr_bo
- remove unused arguments for some public functions
- fix a few foolish copy-paste bugs
- fix 32bit compiling issue

---
 Makefile.am            |    6 +-
 Makefile.sources       |    1 +
 configure.ac           |   26 +-
 include/drm/ipvr_drm.h |  259 +++++++++++
 ipvr/Makefile.am       |   57 +++
 ipvr/Makefile.sources  |    5 +
 ipvr/ipvr_bufmgr.h     |  132 ++++++
 ipvr/ipvr_bufmgr_gem.c | 1188 ++++++++++++++++++++++++++++++++++++++++++++++++
 ipvr/libdrm_ipvr.pc.in |   11 +
 ipvr/test_ipvr.c       |  919 +++++++++++++++++++++++++++++++++++++
 10 files changed, 2602 insertions(+), 2 deletions(-)
 create mode 100644 include/drm/ipvr_drm.h
 create mode 100644 ipvr/Makefile.am
 create mode 100644 ipvr/Makefile.sources
 create mode 100644 ipvr/ipvr_bufmgr.h
 create mode 100644 ipvr/ipvr_bufmgr_gem.c
 create mode 100644 ipvr/libdrm_ipvr.pc.in
 create mode 100644 ipvr/test_ipvr.c
Makefile.am +5 -1
index 3cb516c..035d937 100644
@@ -33,6 +33,10 @@ if HAVE_INTEL
 INTEL_SUBDIR = intel
 endif
 
+if HAVE_IPVR
+IPVR_SUBDIR = ipvr
+endif
+
 if HAVE_NOUVEAU
 NOUVEAU_SUBDIR = nouveau
 endif
@@ -57,7 +61,7 @@ if HAVE_TEGRA
 TEGRA_SUBDIR = tegra
 endif
 
-SUBDIRS = . $(LIBKMS_SUBDIR) $(INTEL_SUBDIR) $(NOUVEAU_SUBDIR) $(RADEON_SUBDIR) $(OMAP_SUBDIR) $(EXYNOS_SUBDIR) $(FREEDRENO_SUBDIR) $(TEGRA_SUBDIR) tests man
+SUBDIRS = . $(LIBKMS_SUBDIR) $(INTEL_SUBDIR) $(IPVR_SUBDIR) $(NOUVEAU_SUBDIR) $(RADEON_SUBDIR) $(OMAP_SUBDIR) $(EXYNOS_SUBDIR) $(FREEDRENO_SUBDIR) $(TEGRA_SUBDIR) tests man
 
 libdrm_la_LTLIBRARIES = libdrm.la
 libdrm_ladir = $(libdir)
Makefile.sources +1 -0
index 566f7b5..819a0cb 100644
@@ -18,6 +18,7 @@ LIBDRM_INCLUDE_H_FILES := \
 	include/drm/drm_mode.h \
 	include/drm/drm_sarea.h \
 	include/drm/i915_drm.h \
+	include/drm/ipvr_drm.h \
 	include/drm/mach64_drm.h \
 	include/drm/mga_drm.h \
 	include/drm/nouveau_drm.h \
configure.ac +25 -1
index c88a1c5..9fea4db 100644
@@ -68,6 +68,11 @@ AC_ARG_ENABLE(intel,
 	      [Enable support for intel's KMS API (default: auto)]),
 	      [INTEL=$enableval], [INTEL=auto])
 
+AC_ARG_ENABLE(ipvr,
+	      AS_HELP_STRING([--disable-ipvr],
+	      [Enable support for valeyview's IPVR hardware decode (default: auto)]),
+	      [IPVR=$enableval], [IPVR=auto])
+
 AC_ARG_ENABLE(radeon,
 	      AS_HELP_STRING([--disable-radeon],
 	      [Enable support for radeon's KMS API (default: auto)]),
@@ -209,7 +214,7 @@ if test "x$drm_cv_atomic_primitives" = "xlibatomic-ops"; then
 	AC_DEFINE(HAVE_LIB_ATOMIC_OPS, 1, [Enable if you have libatomic-ops-dev installed])
 fi
 
-if test "x$INTEL" != "xno" -o "x$RADEON" != "xno" -o "x$NOUVEAU" != "xno"; then
+if test "x$INTEL" != "xno" -o "x$IPVR" != "xno" -o "x$RADEON" != "xno" -o "x$NOUVEAU" != "xno"; then
 	if test "x$drm_cv_atomic_primitives" = "xnone"; then
 		if test "x$INTEL" != "xauto"; then
 			if test "x$INTEL" != "xno"; then
@@ -219,6 +224,14 @@ if test "x$INTEL" != "xno" -o "x$RADEON" != "xno" -o "x$NOUVEAU" != "xno"; then
 			AC_MSG_WARN([Disabling libdrm_intel. It depends on atomic operations, which were not found for your compiler/cpu. Try compiling with -march=native, or install the libatomics-op-dev package.])
 			INTEL=no
 		fi
+		if test "x$IPVR" != "xauto"; then
+			if test "x$IPVR" != "xno"; then
+				AC_MSG_ERROR([libdrm_ipvr depends upon atomic operations, which were not found for your compiler/cpu. Try compiling with -march=native, or install the libatomics-op-dev package, or, failing both of those, disable support for IPVR by passing --disable-ipvr to ./configure])
+			fi
+		else
+			AC_MSG_WARN([Disabling libdrm_ipvr. It depends on atomic operations, which were not found for your compiler/cpu. Try compiling with -march=native, or install the libatomics-op-dev package.])
+			IPVR=no
+		fi
 		if test "x$RADEON" != "xauto"; then
 			if test "x$RADEON" != "xno"; then
 				AC_MSG_ERROR([libdrm_radeon depends upon atomic operations, which were not found for your compiler/cpu. Try compiling with -march=native, or install the libatomics-op-dev package, or, failing both of those, disable support for Radeon GPUs by passing --disable-radeon to ./configure])
@@ -242,6 +255,9 @@ if test "x$INTEL" != "xno" -o "x$RADEON" != "xno" -o "x$NOUVEAU" != "xno"; then
 				*) INTEL=no ;;
 			esac
 		fi
+		if test "x$IPVR" != "xno"; then
+			IPVR=yes
+		fi
 		if test "x$RADEON" != "xno"; then
 			RADEON=yes
 		fi
@@ -279,6 +295,11 @@ if test "x$INTEL" = xyes; then
 	AC_DEFINE(HAVE_INTEL, 1, [Have intel support])
 fi
 
+AM_CONDITIONAL(HAVE_IPVR, [test "x$IPVR" = xyes])
+if test "x$IPVR" = xyes; then
+	AC_DEFINE(HAVE_PVR, 1, [Have ipvr support])
+fi
+
 AM_CONDITIONAL(HAVE_VMWGFX, [test "x$VMWGFX" = xyes])
 if test "x$VMWGFX" = xyes; then
 	AC_DEFINE(HAVE_VMWGFX, 1, [Have vmwgfx kernel headers])
@@ -403,6 +424,8 @@ AC_CONFIG_FILES([
 	libkms/libkms.pc
 	intel/Makefile
 	intel/libdrm_intel.pc
+	ipvr/Makefile
+	ipvr/libdrm_ipvr.pc
 	radeon/Makefile
 	radeon/libdrm_radeon.pc
 	nouveau/Makefile
@@ -433,6 +456,7 @@ echo "$PACKAGE_STRING will be compiled with:"
 echo ""
 echo "  libkms         $LIBKMS"
 echo "  Intel API      $INTEL"
+echo "  Ipvr API       $IPVR"
 echo "  vmwgfx API     $VMWGFX"
 echo "  Radeon API     $RADEON"
 echo "  Nouveau API    $NOUVEAU"
include/drm/ipvr_drm.h new file +259 -0

259 lines not on this page · raw message

ipvr/Makefile.am new file +57 -0

57 lines not on this page · raw message

ipvr/Makefile.sources new file +5 -0
new file mode 100644
index 0000000..5103a02
@@ -0,0 +1,5 @@
+LIBDRM_IPVR_FILES := \
+	ipvr_bufmgr_gem.c
+
+LIBDRM_IPVR_H_FILES := \
+	ipvr_bufmgr.h
ipvr/ipvr_bufmgr.h new file +132 -0

132 lines not on this page · raw message

ipvr/ipvr_bufmgr_gem.c new file +1188 -0

1,188 lines not on this page · raw message

ipvr/libdrm_ipvr.pc.in new file +11 -0
new file mode 100644
index 0000000..34c5291
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libdrm_ipvr
+Description: Userspace interface to IPVR hardware decoder on valleyview
+Version: @PACKAGE_VERSION@
+Requires: libdrm
+Libs: -L${libdir} -ldrm_ipvr
+Cflags: -I${includedir} -I${includedir}/libdrm
ipvr/test_ipvr.c new file +919 -0

919 lines not on this page · raw message

Signature · 6 lines
2.1.0

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw

Re: [RFC PATCH v4 3/4] ipvr: user mode helper for ipvr drm driver

+ commenters of v1~v3

Thanks,
Yao

Quoted 3,077 lines

-----Original Message-----
From: Sean V Kelley [mailto:[email protected]]
Sent: Thursday, January 8, 2015 8:35
To: [email protected]
Cc: [email protected]; Cheng, Yao; Sean V Kelley
Subject: [RFC PATCH v4 3/4] ipvr: user mode helper for ipvr drm driver

From: Yao Cheng <[email protected]>

add usermode helper for the ipvr kernel driver.
test_ioctl: test kernel driver by directly ioctl

v2:
take Emil's comments
- correctly align ipvr_drm.h

v3:
take Daniel Vetter and Daniel Stone's comments, and implement PRIME
- correctly align ipvr_drm.h
- use __u32 family in ipvr_drm.h
- rip out explicit fence from libdrm_ipvr
- implemented PRIME support
- add relocation fixup implementation

v4
bug fixing and add stress test tool
- rename ipvr/test_ioctl.c to ipvr/test_ipvr.c
- implement parallel ioctl stress test in test_ipvr.c
- implement parallel libdrm stress test in test_ipvr.c
- update ipvr_drm.h to keep consistent with kernel change
- remove unused "buffer_ofs/alloc_size/ext_handle" from struct
drm_ipvr_bo
- remove unused arguments for some public functions
- fix a few foolish copy-paste bugs
- fix 32bit compiling issue

---
 Makefile.am            |    6 +-
 Makefile.sources       |    1 +
 configure.ac           |   26 +-
 include/drm/ipvr_drm.h |  259 +++++++++++
 ipvr/Makefile.am       |   57 +++
 ipvr/Makefile.sources  |    5 +
 ipvr/ipvr_bufmgr.h     |  132 ++++++
 ipvr/ipvr_bufmgr_gem.c | 1188
++++++++++++++++++++++++++++++++++++++++++++++++
 ipvr/libdrm_ipvr.pc.in |   11 +
 ipvr/test_ipvr.c       |  919 +++++++++++++++++++++++++++++++++++++
 10 files changed, 2602 insertions(+), 2 deletions(-)
 create mode 100644 include/drm/ipvr_drm.h
 create mode 100644 ipvr/Makefile.am
 create mode 100644 ipvr/Makefile.sources
 create mode 100644 ipvr/ipvr_bufmgr.h
 create mode 100644 ipvr/ipvr_bufmgr_gem.c
 create mode 100644 ipvr/libdrm_ipvr.pc.in
 create mode 100644 ipvr/test_ipvr.c
Makefile.am +4 -1
index 3cb516c..035d937 100644
@@ -33,6 +33,10 @@ if HAVE_INTEL
 INTEL_SUBDIR = intel
 endif
 
+if HAVE_IPVR
+IPVR_SUBDIR = ipvr
+endif
+
 if HAVE_NOUVEAU
 NOUVEAU_SUBDIR = nouveau
 endif
@@ -57,7 +61,7 @@ if HAVE_TEGRA
 TEGRA_SUBDIR = tegra
 endif
 
-SUBDIRS = . $(LIBKMS_SUBDIR) $(INTEL_SUBDIR) $(NOUVEAU_SUBDIR)
 $(RADEON_SUBDIR) $(OMAP_SUBDIR) $(EXYNOS_SUBDIR)

$(FREEDRENO_SUBDIR) $(TEGRA_SUBDIR) tests man +SUBDIRS = . $(LIBKMS_SUBDIR) $(INTEL_SUBDIR) $(IPVR_SUBDIR) $(NOUVEAU_SUBDIR) $(RADEON_SUBDIR) $(OMAP_SUBDIR) $(EXYNOS_SUBDIR) $(FREEDRENO_SUBDIR) $(TEGRA_SUBDIR) tests man

libdrm_la_LTLIBRARIES = libdrm.la
libdrm_ladir = $(libdir)

Makefile.sources +1 -0
index 566f7b5..819a0cb 100644
@@ -18,6 +18,7 @@ LIBDRM_INCLUDE_H_FILES := \
 	include/drm/drm_mode.h \
 	include/drm/drm_sarea.h \
 	include/drm/i915_drm.h \
+	include/drm/ipvr_drm.h \
 	include/drm/mach64_drm.h \
 	include/drm/mga_drm.h \
 	include/drm/nouveau_drm.h \
configure.ac +5 -0
index c88a1c5..9fea4db 100644
@@ -68,6 +68,11 @@ AC_ARG_ENABLE(intel,
 	      [Enable support for intel's KMS API (default: auto)]),
 	      [INTEL=$enableval], [INTEL=auto])
 
+AC_ARG_ENABLE(ipvr,
+	      AS_HELP_STRING([--disable-ipvr],
+	      [Enable support for valeyview's IPVR hardware decode (default:
 auto)]),
+	      [IPVR=$enableval], [IPVR=auto])
+
 AC_ARG_ENABLE(radeon,
 	      AS_HELP_STRING([--disable-radeon],
configure.ac +0 -0
 	      [Enable support for radeon's KMS API (default: auto)]),
@@ -209,7 +214,7 @@ if test "x$drm_cv_atomic_primitives" = "xlibatomic-

ops"; then
AC_DEFINE(HAVE_LIB_ATOMIC_OPS, 1, [Enable if you have
libatomic-ops-dev installed])
fi

-if test "x$INTEL" != "xno" -o "x$RADEON" != "xno" -o "x$NOUVEAU" != "xno"; then
+if test "x$INTEL" != "xno" -o "x$IPVR" != "xno" -o "x$RADEON" != "xno" -o "x$NOUVEAU" != "xno"; then

configure.ac +0 -0
 	if test "x$drm_cv_atomic_primitives" = "xnone"; then
 		if test "x$INTEL" != "xauto"; then
 			if test "x$INTEL" != "xno"; then
@@ -219,6 +224,14 @@ if test "x$INTEL" != "xno" -o "x$RADEON" != "xno" -o

"x$NOUVEAU" != "xno"; then
AC_MSG_WARN([Disabling libdrm_intel. It depends
on atomic operations, which were not found for your compiler/cpu. Try compiling with -march=native, or install the libatomics-op-dev package.])

configure.ac +3 -0
 			INTEL=no
 		fi
+		if test "x$IPVR" != "xauto"; then
+			if test "x$IPVR" != "xno"; then
+				AC_MSG_ERROR([libdrm_ipvr depends upon

atomic operations, which were not found for your compiler/cpu. Try compiling with -march=native, or install the libatomics-op-dev package, or, failing both of those, disable support for IPVR by passing --disable-ipvr to ./configure])

configure.ac +3 -0
+			fi
+		else
+			AC_MSG_WARN([Disabling libdrm_ipvr. It depends

on atomic operations, which were not found for your compiler/cpu. Try compiling with -march=native, or install the libatomics-op-dev package.])

configure.ac +2 -0
+			IPVR=no
+		fi
 		if test "x$RADEON" != "xauto"; then
 			if test "x$RADEON" != "xno"; then
 				AC_MSG_ERROR([libdrm_radeon depends

upon atomic operations, which were not found for your compiler/cpu. Try compiling with -march=native, or install the libatomics-op-dev package, or, failing both of those, disable support for Radeon GPUs by passing --disable- radeon to ./configure])

configure.ac +0 -0
@@ -242,6 +255,9 @@ if test "x$INTEL" != "xno" -o "x$RADEON" != "xno" -o

"x$NOUVEAU" != "xno"; then

configure.ac +11 -0
 				*) INTEL=no ;;
 			esac
 		fi
+		if test "x$IPVR" != "xno"; then
+			IPVR=yes
+		fi
 		if test "x$RADEON" != "xno"; then
 			RADEON=yes
 		fi
@@ -279,6 +295,11 @@ if test "x$INTEL" = xyes; then
 	AC_DEFINE(HAVE_INTEL, 1, [Have intel support])
 fi
 
+AM_CONDITIONAL(HAVE_IPVR, [test "x$IPVR" = xyes])
+if test "x$IPVR" = xyes; then
+	AC_DEFINE(HAVE_PVR, 1, [Have ipvr support])
+fi
+
 AM_CONDITIONAL(HAVE_VMWGFX, [test "x$VMWGFX" = xyes])
 if test "x$VMWGFX" = xyes; then
 	AC_DEFINE(HAVE_VMWGFX, 1, [Have vmwgfx kernel headers])
@@ -403,6 +424,8 @@ AC_CONFIG_FILES([
 	libkms/libkms.pc
 	intel/Makefile
 	intel/libdrm_intel.pc
+	ipvr/Makefile
+	ipvr/libdrm_ipvr.pc
 	radeon/Makefile
 	radeon/libdrm_radeon.pc
 	nouveau/Makefile
@@ -433,6 +456,7 @@ echo "$PACKAGE_STRING will be compiled with:"
 echo ""
 echo "  libkms         $LIBKMS"
 echo "  Intel API      $INTEL"
+echo "  Ipvr API       $IPVR"
 echo "  vmwgfx API     $VMWGFX"
 echo "  Radeon API     $RADEON"
 echo "  Nouveau API    $NOUVEAU"
include/drm/ipvr_drm.h new file +1 -0
new file mode 100644
index 0000000..fade9a3
@@ -0,0 +1,259 @@
+/*********************************************************

*****************
+ * ipvr_drm.h: IPVR header file exported to user space
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Fei Jiang <[email protected]>
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

include/drm/ipvr_drm.h new file +3 -0
+
+
+/* this file only define structs and macro which need export to user space

*/

include/drm/ipvr_drm.h new file +95 -0
+#ifndef _IPVR_DRM_H_
+#define _IPVR_DRM_H_
+
+#include <drm/drm.h>
+struct drm_ipvr_context_create {
+	/* passed ctx_info, including codec, profile info */
+#define IPVR_CONTEXT_TYPE_VED   (0x1)
+	__u32 ctx_type;
+	/* returned back ctx_id */
+	__u32 ctx_id;
+	/*
+	 * following tiling strides for VED are supported:
+	 * stride 0: 512 for scheme 0, 1024 for scheme 1
+	 * stride 1: 1024 for scheme 0, 2048 for scheme 1
+	 * stride 2: 2048 for scheme 0, 4096 for scheme 1
+	 * stride 3: 4096 for scheme 0
+	 */
+	__u32 tiling_stride;
+	/*
+	 * scheme 0: tile is 256x16, while minimal tile stride is 512
+	 * scheme 1: tile is 512x8, while minimal tile stride is 1024
+	 */
+	__u32 tiling_scheme;
+};
+
+struct drm_ipvr_context_destroy {
+	__u32 ctx_id;
+	__u32 pad64;
+};
+
+/* ioctl used for querying info from driver */
+enum drm_ipvr_misc_key {
+	IPVR_DEVICE_INFO,
+};
+struct drm_ipvr_get_info {
+	__u64 key;
+	__u64 value;
+};
+
+struct drm_ipvr_gem_relocation_entry {
+	/**
+	 * Handle of the buffer being pointed to by this relocation entry.
+	 *
+	 * It's appealing to make this be an index into the mm_validate_entry
+	 * list to refer to the buffer, but this allows the driver to create
+	 * a relocation list for state buffers and not re-write it per
+	 * exec using the buffer.
+	 */
+	__u32 target_handle;
+
+	/**
+	 * Value to be added to the offset of the target buffer to make up
+	 * the relocation entry.
+	 */
+	__u32 delta;
+
+	/** Offset in the buffer the relocation entry will be written into */
+	__u64 offset;
+
+	/**
+	 * Offset value of the target buffer that the relocation entry was last
+	 * written as.
+	 *
+	 * If the buffer has the same offset as last time, we can skip syncing
+	 * and writing the relocation.  This value is written back out by
+	 * the execbuffer ioctl when the relocation is written.
+	 */
+	__u64 presumed_offset;
+
+	/**
+	 * Target memory domains read by this operation.
+	 */
+	__u32 read_domains;
+
+	/**
+	 * Target memory domains written by this operation.
+	 *
+	 * Note that only one domain may be written by the whole
+	 * execbuffer operation, so that where there are conflicts,
+	 * the application will get -EINVAL back.
+	 */
+	__u32 write_domain;
+};
+
+struct drm_ipvr_gem_exec_object {
+	/**
+	 * User's handle for a buffer to be bound into the MMU for this
+	 * operation.
+	 */
+	__u32 handle;
+
+	/** Number of relocations to be performed on this buffer */
+	__u32 relocation_count;
+	/**
+	 * Pointer to array of struct drm_i915_gem_relocation_entry

containing

include/drm/ipvr_drm.h new file +121 -0
+	 * the relocations to be performed in this buffer.
+	 */
+	__u64 relocs_ptr;
+
+	/** Required alignment in graphics aperture */
+	__u64 alignment;
+
+	/**
+	 * Returned value of the updated offset of the object, for future
+	 * presumed_offset writes.
+	 */
+	__u64 offset;
+
+#define IPVR_EXEC_OBJECT_NEED_FENCE (1 << 0)
+#define IPVR_EXEC_OBJECT_SUBMIT     (1 << 1)
+	__u64 flags;
+
+	__u64 rsvd1;
+	__u64 rsvd2;
+};
+
+struct drm_ipvr_gem_execbuffer {
+	/**
+	 * List of gem_exec_object2 structs
+	 */
+	__u64 buffers_ptr;
+	__u32 buffer_count;
+
+	/** Offset in the batchbuffer to start execution from. */
+	__u32 exec_start_offset;
+	/** Bytes used in batchbuffer from batch_start_offset */
+	__u32 exec_len;
+
+	/**
+	 * ID of hardware context.
+	 */
+	__u32 ctx_id;
+
+	__u64 flags;
+	__u64 rsvd1;
+	__u64 rsvd2;
+};
+
+enum ipvr_cache_level
+{
+	IPVR_CACHE_UNCACHED,
+	IPVR_CACHE_WRITEBACK,
+	IPVR_CACHE_WRITECOMBINE,
+	IPVR_CACHE_MAX,
+};
+
+struct drm_ipvr_gem_create {
+	/*
+	 * Requested size for the object.
+	 * The (page-aligned) allocated size for the object will be returned.
+	 */
+	__u64 size;
+	__u64 rounded_size;
+	__u64 mmu_offset;
+	/*
+	 * Returned handle for the object.
+	 * Object handles are nonzero.
+	 */
+	__u32 handle;
+	__u32 tiling;
+
+	__u32 cache_level;
+	__u32 pad64;
+	/*
+	 * Handle used for user to mmap BO
+	 */
+	__u64 map_offset;
+};
+
+struct drm_ipvr_gem_busy {
+	/* Handle of the buffer to check for busy */
+	__u32 handle;
+
+	/*
+	 * Return busy status (1 if busy, 0 if idle).
+	 * The high word is used to indicate on which rings the object
+	 * currently resides:
+	 *  16:31 - busy (r or r/w) rings (16 render, 17 bsd, 18 blt, etc)
+	 */
+	__u32 busy;
+};
+
+struct drm_ipvr_gem_mmap_offset {
+	/** Handle for the object being mapped. */
+	__u32 handle;
+	__u32 pad64;
+	/**
+	 * Fake offset to use for subsequent mmap call
+	 *
+	 * This is a fixed-size type for 32/64 compatibility.
+	 */
+	__u64 offset;
+};
+
+struct drm_ipvr_gem_wait {
+	/* Handle of BO we shall wait on */
+	__u32 handle;
+	__u32 flags;
+	/** Number of nanoseconds to wait, Returns time remaining. */
+	__s64 timeout_ns;
+};
+
+/*
+ * IPVR GEM specific ioctls
+ */
+#define DRM_IPVR_CONTEXT_CREATE     0x00
+#define DRM_IPVR_CONTEXT_DESTROY    0x01
+#define DRM_IPVR_GET_INFO           0x02
+#define DRM_IPVR_GEM_EXECBUFFER     0x03
+#define DRM_IPVR_GEM_BUSY           0x04
+#define DRM_IPVR_GEM_CREATE         0x05
+#define DRM_IPVR_GEM_WAIT           0x06
+#define DRM_IPVR_GEM_MMAP_OFFSET    0x07
+
+#define DRM_IOCTL_IPVR_CONTEXT_CREATE	\
+	DRM_IOWR(DRM_COMMAND_BASE +

DRM_IPVR_CONTEXT_CREATE, struct drm_ipvr_context_create)

include/drm/ipvr_drm.h new file +2 -0
+#define DRM_IOCTL_IPVR_CONTEXT_DESTROY	\
+	DRM_IOW(DRM_COMMAND_BASE +

DRM_IPVR_CONTEXT_DESTROY, struct drm_ipvr_context_destroy)

include/drm/ipvr_drm.h new file +2 -0
+#define DRM_IOCTL_IPVR_GET_INFO		\
+	DRM_IOWR(DRM_COMMAND_BASE + DRM_IPVR_GET_INFO, struct

drm_ipvr_get_info)

include/drm/ipvr_drm.h new file +2 -0
+#define DRM_IOCTL_IPVR_GEM_EXECBUFFER	\
+	DRM_IOWR(DRM_COMMAND_BASE +

DRM_IPVR_GEM_EXECBUFFER, struct drm_ipvr_gem_execbuffer)

include/drm/ipvr_drm.h new file +2 -0
+#define DRM_IOCTL_IPVR_GEM_BUSY		\
+	DRM_IOWR(DRM_COMMAND_BASE + DRM_IPVR_GEM_BUSY,

struct drm_ipvr_gem_busy)

include/drm/ipvr_drm.h new file +2 -0
+#define DRM_IOCTL_IPVR_GEM_CREATE	\
+	DRM_IOWR(DRM_COMMAND_BASE + DRM_IPVR_GEM_CREATE,

struct drm_ipvr_gem_create)

include/drm/ipvr_drm.h new file +2 -0
+#define DRM_IOCTL_IPVR_GEM_WAIT		\
+	DRM_IOWR(DRM_COMMAND_BASE + DRM_IPVR_GEM_WAIT,

struct drm_ipvr_gem_wait)

include/drm/ipvr_drm.h new file +2 -0
+#define DRM_IOCTL_IPVR_GEM_MMAP_OFFSET	\
+	DRM_IOWR(DRM_COMMAND_BASE +

DRM_IPVR_GEM_MMAP_OFFSET, struct drm_ipvr_gem_mmap_offset)

include/drm/ipvr_drm.h new file +2 -0
+
+#endif
ipvr/Makefile.am new file +14 -0
new file mode 100644
index 0000000..d4cd32b
@@ -0,0 +1,57 @@
+# Copyright © 2014 Intel Corporation
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,

EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS

ipvr/Makefile.am new file +33 -0
+# IN THE SOFTWARE.
+#
+# Authors:
+#    Yao Cheng <[email protected]>
+
+include Makefile.sources
+
+AM_CFLAGS = \
+	$(WARN_CFLAGS) \
+	$(VISIBILITY_CFLAGS) \
+	-I$(top_srcdir) \
+	-I$(top_srcdir)/ipvr \
+	$(PTHREADSTUBS_CFLAGS) \
+	$(PCIACCESS_CFLAGS) \
+	$(VALGRIND_CFLAGS) \
+	-I$(top_srcdir)/include/drm
+
+libdrm_ipvr_la_LTLIBRARIES = libdrm_ipvr.la
+libdrm_ipvr_ladir = $(libdir)
+libdrm_ipvr_la_LDFLAGS = -version-number 0:1:0 -no-undefined
+libdrm_ipvr_la_LIBADD = ../libdrm.la \
+	@PTHREADSTUBS_LIBS@ \
+	@PCIACCESS_LIBS@ \
+	@CLOCK_LIB@
+
+libdrm_ipvr_la_SOURCES = $(LIBDRM_IPVR_FILES)
+
+ipvr_bufmgr_gem_o_CFLAGS = $(AM_CFLAGS) -c99
+
+libdrm_ipvrincludedir = ${includedir}/libdrm
+libdrm_ipvrinclude_HEADERS = $(LIBDRM_IPVR_H_FILES)
+
+# This may be interesting even outside of "make check", due to the -dump

option.

ipvr/Makefile.am new file +3 -0
+noinst_PROGRAMS = test_ipvr
+
+test_ipvr_LDADD = libdrm_ipvr.la ../libdrm.la ../intel/libdrm_intel.la -

lpthread

ipvr/Makefile.am new file +2 -0
+
+pkgconfig_DATA = libdrm_ipvr.pc
ipvr/Makefile.sources new file +5 -0
new file mode 100644
index 0000000..5103a02
@@ -0,0 +1,5 @@
+LIBDRM_IPVR_FILES := \
+	ipvr_bufmgr_gem.c
+
+LIBDRM_IPVR_H_FILES := \
+	ipvr_bufmgr.h
ipvr/ipvr_bufmgr.h new file +5 -0
new file mode 100644
index 0000000..aa72737
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2014 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the

"Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ * Yao Cheng <[email protected]>
+ *
+ */

ipvr/ipvr_bufmgr.h new file +67 -0
+#ifndef IPVR_BUFMGR_H
+#define IPVR_BUFMGR_H
+#include <stdio.h>
+#include <stdint.h>
+#include <stdio.h>
+
+typedef struct _drm_ipvr_bo drm_ipvr_bo;
+typedef struct _drm_ipvr_bufmgr drm_ipvr_bufmgr;
+typedef struct _drm_ipvr_context drm_ipvr_context;
+
+struct _drm_ipvr_bo {
+    /**
+     * Size in bytes of the buffer object.
+     *
+     * The size may be larger than the size originally requested for the
+     * allocation, such as being aligned to page size.
+     */
+    size_t size;
+
+    /** GEM handle of the BO */
+    uint32_t handle;
+
+    /**
+     * Last seen card virtual address (offset from the beginning of the
+     * aperture) for the object.  This should be used to fill relocation
+     * entries when calling drm_ipvr_gem_bo_emit_reloc()
+     */
+    uint64_t offset;
+
+    /**
+     * Virtual address for accessing the buffer data.  Only valid while
+     * mapped.
+     */
+    void *virt;
+
+    /** Buffer manager context associated with this buffer object */
+    drm_ipvr_bufmgr *bufmgr;
+};
+
+struct _drm_ipvr_bufmgr {
+    int debug;
+};
+
+struct _drm_ipvr_context
+{
+    /**
+     * context id for hardware to distinguish different clients
+     */
+    uint32_t ctx_id;
+
+    /**
+     * Commands on different context are submitted to different hardware
+     */
+    uint32_t ctx_type;
+
+    /** Buffer manager context associated with this buffer object */
+    drm_ipvr_bufmgr *bufmgr;
+};
+
+drm_ipvr_bufmgr *drm_ipvr_gem_bufmgr_init(int fd);
+
+void drm_ipvr_gem_bufmgr_destroy(drm_ipvr_bufmgr *bufmgr);
+
+int drm_ipvr_gem_bufmgr_get_device_info(drm_ipvr_bufmgr *bufmgr,
+            uint16_t *dev_id, uint16_t *caps);
+
+drm_ipvr_bo *drm_ipvr_gem_bo_alloc(drm_ipvr_bufmgr *bufmgr,

drm_ipvr_context *ctx,

ipvr/ipvr_bufmgr.h new file +20 -0
+            const char *name, size_t size,
+            uint8_t tiling, uint8_t cache_level);
+
+void drm_ipvr_gem_bo_reference(drm_ipvr_bo *bo);
+
+void drm_ipvr_gem_bo_unreference(drm_ipvr_bo *bo);
+
+int drm_ipvr_gem_bo_map(drm_ipvr_bo *bo, int write_enable);
+
+int drm_ipvr_gem_bo_unmap(drm_ipvr_bo *bo);
+
+void drm_ipvr_gem_bo_wait(drm_ipvr_bo *bo);
+
+int drm_ipvr_gem_bo_emit_reloc(drm_ipvr_bo *bo, uint64_t offset,
+            drm_ipvr_bo *target_bo, uint64_t target_offset, uint8_t skip_fence);
+
+int drm_ipvr_gem_bo_exec(drm_ipvr_bo *bo, uint64_t offset, size_t len,
+            int fence_in, int *fence_out);
+
+drm_ipvr_bo *drm_ipvr_gem_bo_create_from_name(drm_ipvr_bufmgr

*bufmgr,

ipvr/ipvr_bufmgr.h new file +7 -0
+            drm_ipvr_context *ctx, const char *name, uint32_t global_handle);
+
+int drm_ipvr_gem_bo_flink(drm_ipvr_bo *bo, uint32_t *global_handle);
+
+int drm_ipvr_gem_bo_export_to_prime(drm_ipvr_bo *bo, int *prime_fd);
+
+drm_ipvr_bo *drm_ipvr_gem_bo_create_from_prime(drm_ipvr_bufmgr

*bufmgr,
+ drm_ipvr_context *ctx, const char *name, int prime_fd, size_t
guessed_size);

ipvr/ipvr_bufmgr.h new file +4 -0
+
+int drm_ipvr_gem_bo_busy(drm_ipvr_bo *bo);
+
+void drm_ipvr_gem_bo_remove_relocs(drm_ipvr_bo *bo, uint8_t

recursive);

ipvr/ipvr_bufmgr.h new file +2 -0
+
+drm_ipvr_context *drm_ipvr_gem_context_create(drm_ipvr_bufmgr

*bufmgr,

ipvr/ipvr_bufmgr.h new file +5 -0
+            uint32_t ctx_type, uint32_t tiling_stride, uint32_t tiling_mode);
+
+void drm_ipvr_gem_context_destroy(drm_ipvr_context *ctx);
+
+#endif
ipvr/ipvr_bufmgr_gem.c new file +1 -0
new file mode 100644
index 0000000..e382550
@@ -0,0 +1,1188 @@
+/*********************************************************

*****************
+ *
+ * Copyright 2014 Intel Corporation
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ *
+
**********************************************************
****************/

ipvr/ipvr_bufmgr_gem.c new file +151 -0
+/*
+ * Authors: Yao Cheng <[email protected]>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <xf86drm.h>
+#include <xf86atomic.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <assert.h>
+#include <pthread.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <stdbool.h>
+#include <inttypes.h>
+
+#include "errno.h"
+#ifndef ETIME
+#define ETIME ETIMEDOUT
+#endif
+#include "libdrm.h"
+#include "libdrm_lists.h"
+#include "ipvr_bufmgr.h"
+#include "string.h"
+
+#include "ipvr_drm.h"
+
+static int debug_level = 3;
+
+typedef uint64_t nsecs_t;
+#define VERB(fmt, ...)    _DBGPRINT(0, fmt, ##__VA_ARGS__)
+#define DBG(fmt, ...)     _DBGPRINT(1, fmt, ##__VA_ARGS__)
+#define INFO(fmt, ...)    _DBGPRINT(2, fmt, ##__VA_ARGS__)
+#define WARN(fmt, ...)    _DBGPRINT(3, fmt, ##__VA_ARGS__)
+#define ERR(fmt, ...)     _DBGPRINT(4, fmt, ##__VA_ARGS__)
+#define _DBGPRINT(level, fmt, ...) \
+    do { \
+        if (debug_level <= level) { \
+            fprintf(stderr, fmt, ##__VA_ARGS__); \
+        } \
+    } while (false);
+
+#define IPVR_TIMEOUT_USEC 990000LL
+
+typedef struct _drm_ipvr_bo_gem drm_ipvr_bo_gem;
+
+typedef struct _drm_ipvr_reloc_target_info {
+    drm_ipvr_bo *bo;
+    uint64_t flags;
+} drm_ipvr_reloc_target;
+
+struct drm_ipvr_cache_bucket {
+    unsigned long size;
+    drmMMListHead head;
+    size_t count;
+    size_t  limit;
+};
+
+typedef struct _drm_ipvr_bufmgr_gem
+{
+    drm_ipvr_bufmgr base;
+    int fd;
+    pthread_mutex_t lock;
+    pthread_mutex_t list_lock;
+
+    struct drm_ipvr_gem_exec_object *exec_objs;
+    drm_ipvr_bo **exec_bos;
+    int exec_size;
+    int exec_count;
+    time_t time;
+    int max_relocs;
+
+    /* cache bucket of power-of-two */
+    int cache_bucket_size;
+
+    /* only cache linear BOs */
+    struct drm_ipvr_cache_bucket *cache_buckets;
+
+    /* seqno used to check BO's last operation oldness */
+    int exec_seq;
+} drm_ipvr_bufmgr_gem;
+
+typedef struct _drm_ipvr_bo_gem
+{
+    drm_ipvr_bo base;
+    const char *name;
+    /**
+     * Kenel-assigned global name for this object
+     */
+    unsigned int global_name;
+    atomic_t refcount;
+    uint32_t tiling;
+    uint32_t caching;
+    atomic_t mapcount;
+    struct drm_ipvr_gem_relocation_entry *relocs;
+    /*
+     * Handle for mmap
+     */
+    uint64_t map_offset;
+    /**
+     * Array of info structs corresponding to relocs[i].target_handle etc
+     */
+    drm_ipvr_reloc_target *reloc_target_info;
+    /** Number of entries in relocs */
+    int reloc_count;
+    /**
+     * Index of the buffer within the validation list while preparing a
+     * batchbuffer execution.
+     */
+    int validate_index;
+    /**
+     * Boolean of whether this buffer has been used as a relocation
+     * target and had its size accounted for, and thus can't have any
+     * further relocations added to it.
+     */
+    bool used_as_reloc_target;
+    /*bool                        is_vmap;*/
+    bool is_prime_imported;
+    /*void                        *user_virt;*/
+
+    /** BO cache list */
+    drmMMListHead cache_head;
+    /** Indicates the BO can be re-used or not after being recycled */
+    int reusable;
+
+    drm_ipvr_context *ctx;
+    int exec_seq;
+} drm_ipvr_bo_gem;
+
+static nsecs_t get_time_ns(void)
+{
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+    return tv.tv_sec * 1000000000LL + tv.tv_usec * 1000LL;
+}
+
+static struct drm_ipvr_cache_bucket *
+drm_ipvr_cache_bucket_for_size(drm_ipvr_bufmgr *bufmgr,
+                 size_t size, uint8_t tiling)
+{
+    int i;
+    drm_ipvr_bufmgr_gem *bufmgr_gem =

(drm_ipvr_bufmgr_gem*)bufmgr;

ipvr/ipvr_bufmgr_gem.c new file +16 -0
+
+    assert(tiling == 0);
+    for (i = 0; i < bufmgr_gem->cache_bucket_size; i++) {
+        struct drm_ipvr_cache_bucket *bucket =
+            &bufmgr_gem->cache_buckets[i];
+        if (bucket->size >= size) {
+            return bucket;
+        }
+    }
+    return NULL;
+}
+
+static int
+drm_ipvr_gem_bo_free(drm_ipvr_bo *bo)
+{
+    drm_ipvr_bufmgr_gem *bufmgr_gem = (drm_ipvr_bufmgr_gem*) bo-
Quoted 1 line

bufmgr;

ipvr/ipvr_bufmgr_gem.c new file +11 -0
+    drm_ipvr_bo_gem *bo_gem = (drm_ipvr_bo_gem *) bo;
+    struct drm_gem_close arg;
+    int ret;
+    bool fence_destroyed = false;
+
+    /* Close this object */
+    arg.handle = bo->handle;
+
+    ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_GEM_CLOSE, &arg);
+    if (ret != 0) {
+        ERR("%s: DRM_IOCTL_GEM_CLOSE \"%s\" handle 0x%x offset 0x%lx

failed: %s\n",

ipvr/ipvr_bufmgr_gem.c new file +19 -0
+            __FUNCTION__, bo_gem->name,
+            bo->handle, bo->offset, strerror(errno));
+    }
+
+    if (bo_gem->relocs)
+        free(bo_gem->relocs);
+    if (bo_gem->reloc_target_info)
+        free(bo_gem->reloc_target_info);
+
+    DBG("%s: freed buf khandle \"%s\" hnd %x, offset 0x%lx, %s\n",
+        __FUNCTION__, bo_gem->name, bo->handle, bo->offset,
+        (fence_destroyed? "fence is destroyed": "no fence to destroy"));
+
+    memset(bo_gem, 0, sizeof(*bo_gem));
+    free(bo_gem);
+    return 0;
+}
+
+drm_public int drm_ipvr_gem_bo_map(drm_ipvr_bo *bo, int

write_enable);

ipvr/ipvr_bufmgr_gem.c new file +3 -0
+drm_public int drm_ipvr_gem_bo_unmap(drm_ipvr_bo *bo);
+
+drm_public drm_ipvr_bo *drm_ipvr_gem_bo_alloc(drm_ipvr_bufmgr

*bufmgr,

ipvr/ipvr_bufmgr_gem.c new file +5 -0
+            drm_ipvr_context *ctx,
+            const char *name, size_t size,
+            uint8_t tiling, uint8_t cache_level)
+{
+    drm_ipvr_bufmgr_gem *bufmgr_gem = (drm_ipvr_bufmgr_gem*)

bufmgr;

ipvr/ipvr_bufmgr_gem.c new file +11 -0
+    drm_ipvr_bo_gem *allocated_bo_gem = NULL;
+    int ret;
+    struct drm_ipvr_gem_create arg;
+    int reusable = 1;
+    bool alloc_from_cache = false;
+    size_t alloc_size = size;
+    struct drm_ipvr_cache_bucket *bucket = NULL;
+    int bo_movings = 0;
+    int bucket_free_before, bucket_free_after;
+    nsecs_t begin_ns, end_ns;
+    nsecs_t time_wait, time_bo_moving, time_fence_destroy,

time_kernel_alloc;

ipvr/ipvr_bufmgr_gem.c new file +2 -0
+    nsecs_t now;
+    time_wait = time_bo_moving = time_fence_destroy = time_kernel_alloc

= 0;

ipvr/ipvr_bufmgr_gem.c new file +5 -0
+    bucket_free_before = bucket_free_after = 0;
+
+    begin_ns = get_time_ns();
+    if (reusable)
+        bucket = drm_ipvr_cache_bucket_for_size(&bufmgr_gem->base, size,

tiling);

ipvr/ipvr_bufmgr_gem.c new file +4 -0
+
+    if (reusable && !bucket) {
+        reusable = false;
+        WARN("%s size %zu cannot fit into any cache bucket, set as non-

reusable\n",

ipvr/ipvr_bufmgr_gem.c new file +11 -0
+            __FUNCTION__, size);
+    }
+    if (reusable && bucket) {
+        /**
+         * only expand size when it's reusable
+         */
+        alloc_size = bucket->size;
+    }
+
+    if (reusable && bucket && !DRMLISTEMPTY(&bucket->head)) {
+        VERB("%s searching cached BOs in fast mode: free_list\n",

__FUNCTION__);

ipvr/ipvr_bufmgr_gem.c new file +70 -0
+        now = get_time_ns();
+        pthread_mutex_lock(&bufmgr_gem->list_lock);
+        allocated_bo_gem = DRMLISTENTRY(drm_ipvr_bo_gem,
+                      bucket->head.next, cache_head);
+        if (bufmgr_gem->exec_seq - allocated_bo_gem->exec_seq < 5) {
+            alloc_from_cache = false;
+            allocated_bo_gem = NULL;
+        }
+        else if (!drm_ipvr_gem_bo_busy(&allocated_bo_gem->base)) {
+            alloc_from_cache = true;
+            DRMLISTDELINIT(&allocated_bo_gem->cache_head);
+            bucket->count--;
+        }
+        else {
+            drm_ipvr_gem_bo_wait(&allocated_bo_gem->base);
+            alloc_from_cache = true;
+            DRMLISTDELINIT(&allocated_bo_gem->cache_head);
+            bucket->count--;
+        }
+        pthread_mutex_unlock(&bufmgr_gem->list_lock);
+        time_wait += get_time_ns() - now;
+        VERB("%s got free BO from cache\n", __FUNCTION__);
+    }
+    else {
+        VERB("%s empty free_list, alloc_from kernel\n", __FUNCTION__);
+        alloc_from_cache = false;
+    }
+
+    if (!alloc_from_cache) {
+        allocated_bo_gem = calloc(1, sizeof(*allocated_bo_gem));
+        if (!allocated_bo_gem) {
+            ERR("%s: calloc failed: %s\n", __FUNCTION__, strerror(errno));
+            return NULL;
+        }
+
+        if (reusable)
+            arg.size = alloc_size;
+        else
+            arg.size = size;
+        arg.tiling = tiling;
+        arg.cache_level = cache_level;
+
+        now = get_time_ns();
+        ret = drmCommandWriteRead(bufmgr_gem->fd,
+                   DRM_IPVR_GEM_CREATE,
+                   &arg, sizeof(arg));
+
+        if (ret != 0) {
+            ERR("%s: IOCTL GEM_CREATE failed: %d\n",
+                __FUNCTION__, ret);
+            free(allocated_bo_gem);
+            allocated_bo_gem = NULL;
+            return NULL;
+        }
+        time_kernel_alloc = get_time_ns() - now;
+
+        allocated_bo_gem->base.bufmgr = bufmgr;
+        allocated_bo_gem->base.handle = arg.handle;
+        allocated_bo_gem->tiling = arg.tiling;
+        allocated_bo_gem->caching = arg.cache_level;
+        allocated_bo_gem->base.offset = arg.mmu_offset;
+        allocated_bo_gem->base.size = arg.rounded_size;
+        allocated_bo_gem->name = name;
+        allocated_bo_gem->base.virt = NULL;
+        allocated_bo_gem->map_offset = arg.map_offset;
+        allocated_bo_gem->is_prime_imported = false;
+        atomic_set(&allocated_bo_gem->mapcount, 0);
+
+        DBG("%s: allocated buf handle 0x%x from kernel, "
+            "offset 0x%lx, name \"%s\" size %lu, tiling %u, cache_level %u,

bufmgr %p\n",

ipvr/ipvr_bufmgr_gem.c new file +2 -0
+            __FUNCTION__,
+            allocated_bo_gem->base.handle, allocated_bo_gem->base.offset,

allocated_bo_gem->name,
+ allocated_bo_gem->base.size, allocated_bo_gem->tiling,
allocated_bo_gem->caching, bufmgr);

ipvr/ipvr_bufmgr_gem.c new file +5 -0
+    }
+    else {
+        assert(allocated_bo_gem);
+        DBG("%s: allocated buf handle 0x%x from userspace cache, "
+            "offset 0x%lx, name \"%s\" size %lu, tiling %u, cache_level %u,

bufmgr %p\n",

ipvr/ipvr_bufmgr_gem.c new file +2 -0
+            __FUNCTION__,
+            allocated_bo_gem->base.handle, allocated_bo_gem->base.offset,

allocated_bo_gem->name,
+ allocated_bo_gem->base.size, allocated_bo_gem->tiling,
allocated_bo_gem->caching, bufmgr);

ipvr/ipvr_bufmgr_gem.c new file +17 -0
+    }
+
+    allocated_bo_gem->name = name;
+    allocated_bo_gem->validate_index = -1;
+    allocated_bo_gem->ctx = ctx;
+    allocated_bo_gem->reusable = reusable;
+    allocated_bo_gem->exec_seq = -1;
+
+    atomic_set(&allocated_bo_gem->refcount, 1);
+    end_ns = get_time_ns();
+    if (bucket) {
+        bucket_free_after = bucket->count;
+    }
+    assert(atomic_read(&allocated_bo_gem->mapcount) == 0);
+
+    if (end_ns - begin_ns > 2 * 1000 * 1000) {
+        DBG("%s got from %s: \"%s\" hnd %u offset 0x%lx size %lu took %.2f

ms, "

ipvr/ipvr_bufmgr_gem.c new file +5 -0
+            "(wait %.2f, "
+            "bo_moving %.2f, kernel_alloc %.2f), "
+            "bucket (%d/%zu)=>(%d/%zu)\n",
+            __FUNCTION__, (alloc_from_cache? "CACHE": "KERNEL"),
+            allocated_bo_gem->name, allocated_bo_gem->base.handle,

allocated_bo_gem->base.offset,

ipvr/ipvr_bufmgr_gem.c new file +13 -0
+            allocated_bo_gem->base.size, (end_ns - begin_ns)/1000000.0,
+            time_wait/1000000.0,
+            bo_movings/1000000.0, time_kernel_alloc/1000000.0,
+            bucket_free_before, (bucket? bucket->limit: 0),
+            bucket_free_after, (bucket? bucket->limit: 0));
+    }
+    return &allocated_bo_gem->base;
+}
+
+drm_public void drm_ipvr_gem_bo_unreference(drm_ipvr_bo *bo);
+
+static void
+drm_ipvr_gem_bo_remove_reloc(drm_ipvr_bo *bo, int depth, uint8_t

recursive)

ipvr/ipvr_bufmgr_gem.c new file +7 -0
+{
+    int i;
+    drm_ipvr_bo_gem *bo_gem = (drm_ipvr_bo_gem*)bo;
+    drm_ipvr_bo_gem *target_bo_gem;
+    for (i = 0; i < bo_gem->reloc_count; i++) {
+        if (bo_gem->reloc_target_info[i].bo != bo) {
+            target_bo_gem = (drm_ipvr_bo_gem*)bo_gem-
Quoted 1 line

reloc_target_info[i].bo;

+ VERB("%s (depth: %d) remove \"%s\" hnd %x off 0x%lx => \"%s\"
hnd %x off 0x%lx\n",
+ __FUNCTION__, depth, bo_gem->name, bo_gem->base.handle,
bo->offset,
+ target_bo_gem->name, target_bo_gem->base.handle,
target_bo_gem->base.offset);

ipvr/ipvr_bufmgr_gem.c new file +2 -0
+            if (recursive)
+                drm_ipvr_gem_bo_remove_reloc(bo_gem-
Quoted 1 line

reloc_target_info[i].bo, depth + 1, true);

ipvr/ipvr_bufmgr_gem.c new file +21 -0
+            drm_ipvr_gem_bo_unreference(bo_gem->reloc_target_info[i].bo);
+        }
+        bo_gem->reloc_target_info[i].bo = NULL;
+        memset(&bo_gem->relocs[i], 0, sizeof(bo_gem->relocs[i]));
+    }
+    bo_gem->reloc_count = 0;
+}
+
+
+drm_public void
+drm_ipvr_gem_bo_remove_relocs(drm_ipvr_bo *bo, uint8_t recursive)
+{
+    drm_ipvr_gem_bo_remove_reloc(bo, 0, recursive);
+}
+
+drm_public void drm_ipvr_gem_bo_reference(drm_ipvr_bo *bo)
+{
+    drm_ipvr_bo_gem *bo_gem = (drm_ipvr_bo_gem *)bo;
+    atomic_inc(&bo_gem->refcount);
+    VERB("%s \"%s\" hnd 0x%x offset 0x%lx, refcount became %d\n",
+        __FUNCTION__, bo_gem->name, bo->handle, bo->offset,

atomic_read(&bo_gem->refcount));

ipvr/ipvr_bufmgr_gem.c new file +7 -0
+}
+
+static void drm_ipvr_gem_bo_finalize(drm_ipvr_bo *bo)
+{
+    struct drm_ipvr_cache_bucket *bucket;
+    drm_ipvr_bo_gem *bo_gem = (drm_ipvr_bo_gem*)bo;
+    drm_ipvr_bufmgr_gem *bufmgr_gem = (drm_ipvr_bufmgr_gem*)bo-
Quoted 1 line

bufmgr;

ipvr/ipvr_bufmgr_gem.c new file +7 -0
+    int mapcount;
+    /* add lock? */
+    /* Automatically unreference all the target buffers */
+    drm_ipvr_gem_bo_remove_relocs(bo, false);
+    mapcount = atomic_read(&bo_gem->mapcount);
+    if (mapcount != 0)
+        WARN("%s BO is finalized with mapcount %d\n", __FUNCTION__,

mapcount);

ipvr/ipvr_bufmgr_gem.c new file +6 -0
+
+    assert(atomic_read(&bo_gem->mapcount) == 0);
+
+    bo_gem->validate_index = -1;
+
+    bucket = drm_ipvr_cache_bucket_for_size(bo->bufmgr, bo->size,

bo_gem->tiling);

ipvr/ipvr_bufmgr_gem.c new file +29 -0
+
+    /* Put the buffer into our internal cache for reuse if we can. */
+    if (bo_gem->reusable && bucket != NULL) {
+        bo_gem->validate_index = -1;
+        DBG("%s adding bo \"%s\" hnd %x (offset 0x%lx) to internal cache\n",
+            __FUNCTION__, bo_gem->name, bo->handle, bo->offset);
+
+        pthread_mutex_lock(&bufmgr_gem->list_lock);
+        DRMLISTADDTAIL(&bo_gem->cache_head, &bucket->head);
+        bucket->count++;
+
+        pthread_mutex_unlock(&bufmgr_gem->list_lock);
+    } else {
+        VERB("%s freeing bo \"%s\" hnd %x (offset 0x%lx)\n",
+            __FUNCTION__, bo_gem->name, bo->handle, bo->offset);
+        drm_ipvr_gem_bo_free(bo);
+    }
+}
+
+drm_public void
+drm_ipvr_gem_bo_unreference(drm_ipvr_bo *bo)
+{
+    drm_ipvr_bo_gem * bo_gem = (drm_ipvr_bo_gem*)bo;
+    assert(atomic_read(&bo_gem->refcount) > 0);
+    if (atomic_dec_and_test(&bo_gem->refcount)) {
+        drm_ipvr_gem_bo_finalize(bo);
+    } else {
+        VERB("%s \"%s\" handle 0x%x offset 0x%lx, refcount became %d\n",
+            __FUNCTION__, bo_gem->name, bo->handle, bo->offset,

atomic_read(&bo_gem->refcount));

ipvr/ipvr_bufmgr_gem.c new file +7 -0
+    }
+}
+
+drm_public int drm_ipvr_gem_bo_map(drm_ipvr_bo *bo, int write_enable)
+{
+    int ret;
+    drm_ipvr_bufmgr_gem *bufmgr_gem = (drm_ipvr_bufmgr_gem *)bo-
Quoted 1 line

bufmgr;

ipvr/ipvr_bufmgr_gem.c new file +16 -0
+    drm_ipvr_bo_gem *bo_gem = (drm_ipvr_bo_gem*)bo;
+    struct drm_ipvr_gem_mmap_offset arg;
+    int prot = PROT_READ;
+
+    if (write_enable)
+        prot |= PROT_WRITE;
+    assert(atomic_read(&bo_gem->mapcount) >= 0);
+    /* maintain userspace mapping cache, to avoid unnecessary IOCTLs */
+    if (atomic_read(&bo_gem->mapcount) == 0 && !bo->virt) {
+        /* no need to call synccpu-grab, kernel do it automatically */
+        VERB("mmaping with handle %u\n", bo->handle);
+
+        if (!bo_gem->map_offset) {
+            memset(&arg, 0, sizeof(arg));
+            arg.handle = bo->handle;
+            ret = drmCommandWriteRead(bufmgr_gem->fd,

DRM_IPVR_GEM_MMAP_OFFSET,

ipvr/ipvr_bufmgr_gem.c new file +8 -0
+                &arg, sizeof(arg));
+            if (ret < 0) {
+                ERR("%s: failed to get mmap offset at bo \"%s\" 0x%x: %d (%s)\n",
+                    __FUNCTION__, bo_gem->name, bo->handle, ret, strerror(ret));
+                return ret;
+            }
+            if (arg.offset == 0) {
+                ERR("%s: got invalid mmap offset 0x%llx at bo \"%s\" 0x%x: %d

(%s)\n",
+ __FUNCTION__, arg.offset, bo_gem->name, bo->handle, ret,
strerror(ret));

ipvr/ipvr_bufmgr_gem.c new file +11 -0
+                return -ENOSPC;
+            }
+            bo_gem->map_offset = arg.offset;
+        }
+        bo->virt = drm_mmap(0, bo->size, prot,
+                   MAP_SHARED, bufmgr_gem->fd, bo_gem->map_offset);
+        if (bo->virt == MAP_FAILED) {
+            bo->virt = NULL;
+            ERR("%s: failed to drm_mmap bo \"%s\" with map_offset 0x%"PRIx64
+                " hnd 0x%x: %d (%s)\n",
+                __FUNCTION__, bo_gem->name, bo_gem->map_offset, bo-
Quoted 1 line

handle,

ipvr/ipvr_bufmgr_gem.c new file +5 -0
+                -errno, strerror(-errno));
+            return -errno;
+        }
+
+        VERB("%s: map for first time, \"%s\" hnd 0x%x (offset 0x%lx) (%s) -
Quoted 1 line

%p\n",

+ __FUNCTION__, bo_gem->name, bo->handle, bo->offset, bo_gem-

Quoted 1 line

name, bo->virt);

ipvr/ipvr_bufmgr_gem.c new file +3 -0
+    }
+    else {
+        VERB("%s: already mapped, \"%s\" hnd 0x%x (offset 0x%lx) (%s) -
Quoted 1 line

%p\n",

+ __FUNCTION__, bo_gem->name, bo->handle, bo->offset, bo_gem-

Quoted 1 line

name, bo->virt);

ipvr/ipvr_bufmgr_gem.c new file +18 -0
+    }
+    atomic_inc(&bo_gem->mapcount);
+    assert(bo->virt);
+    VERB("%s: map_count became %d\n",
+        __FUNCTION__, atomic_read(&bo_gem->mapcount));
+
+    return 0;
+}
+
+drm_public int
+drm_ipvr_gem_bo_unmap(drm_ipvr_bo *bo)
+{
+    drm_ipvr_bo_gem *bo_gem = (drm_ipvr_bo_gem*)bo;
+    int mapcount;
+
+    mapcount = atomic_read(&bo_gem->mapcount);
+    if (mapcount <= 0) {
+        VERB("%s: unexpected unmap() when mapcount is %d, ignore it\n",

__FUNCTION__, mapcount);

ipvr/ipvr_bufmgr_gem.c new file +8 -0
+    }
+    else if (atomic_dec_and_test(&bo_gem->mapcount)) {
+        if (bo->virt)
+            drm_munmap(bo->virt, bo->size);
+        bo->virt = NULL;
+    }
+    VERB("%s: \"%s\" hnd 0x%x offset 0x%lx map_count became %d\n",
+        __FUNCTION__, bo_gem->name, bo->handle, bo->offset,

atomic_read(&bo_gem->mapcount));

ipvr/ipvr_bufmgr_gem.c new file +7 -0
+    return 0;
+}
+
+drm_public void
+drm_ipvr_gem_bo_wait(drm_ipvr_bo *bo)
+{
+    drm_ipvr_bufmgr_gem *bufmgr_gem = (drm_ipvr_bufmgr_gem*) bo-
Quoted 1 line

bufmgr;

ipvr/ipvr_bufmgr_gem.c new file +9 -0
+    drm_ipvr_bo_gem * bo_gem = (drm_ipvr_bo_gem*)bo;
+    struct drm_ipvr_gem_wait arg;
+    int ret;
+    VERB("%s: wait \"%s\" hnd 0x%x offset 0x%lx\n",
+        __FUNCTION__, bo_gem->name, bo->handle, bo->offset);
+
+    arg.handle = bo->handle;
+    arg.flags = 0;
+    ret = drmCommandWriteRead(bufmgr_gem->fd, DRM_IPVR_GEM_WAIT,

&arg, sizeof(arg));

ipvr/ipvr_bufmgr_gem.c new file +3 -0
+    if (ret < 0) {
+        ERR("%s \"%s\" hnd %u offset 0x%lx failed, %d (%s)\n",
+            __FUNCTION__, bo_gem->name, bo->handle, bo->offset, ret,

strerror(ret));

ipvr/ipvr_bufmgr_gem.c new file +23 -0
+    }
+}
+
+static unsigned
+drm_ipvr_time_diff(struct timeval *now, struct timeval *then)
+{
+    long long val;
+
+    val = now->tv_sec - then->tv_sec;
+    val *= 1000000LL;
+    val += now->tv_usec;
+    val -= then->tv_usec;
+    if (val < 1LL)
+        val = 1LL;
+
+    return (unsigned) val;
+}
+
+static int
+drm_ipvr_setup_reloc_list(drm_ipvr_bo *bo)
+{
+    drm_ipvr_bo_gem *bo_gem = (drm_ipvr_bo_gem *) bo;
+    drm_ipvr_bufmgr_gem *bufmgr_gem = (drm_ipvr_bufmgr_gem *) bo-
Quoted 1 line

bufmgr;

ipvr/ipvr_bufmgr_gem.c new file +11 -0
+    unsigned int max_relocs = bufmgr_gem->max_relocs;
+
+    if (bo->size / 4 < max_relocs)
+        max_relocs = bo->size / 4;
+
+    bo_gem->relocs = malloc(max_relocs *
+                sizeof(struct drm_ipvr_gem_relocation_entry));
+    bo_gem->reloc_target_info = malloc(max_relocs *
+                       sizeof(drm_ipvr_reloc_target));
+    if (bo_gem->relocs == NULL || bo_gem->reloc_target_info == NULL) {
+        ERR("%s: failed to alloc relocs and reloc_target_info\n",

__FUNCTION__);

ipvr/ipvr_bufmgr_gem.c new file +15 -0
+        free (bo_gem->relocs);
+        bo_gem->relocs = NULL;
+
+        free (bo_gem->reloc_target_info);
+        bo_gem->reloc_target_info = NULL;
+
+        return 1;
+    }
+
+    return 0;
+}
+
+drm_public int
+drm_ipvr_gem_bo_emit_reloc(drm_ipvr_bo *bo, uint64_t offset,
+                drm_ipvr_bo *target_bo, uint64_t target_offset, uint8_t

skip_fence)

ipvr/ipvr_bufmgr_gem.c new file +3 -0
+{
+    int ret;
+    drm_ipvr_bufmgr_gem *bufmgr_gem = (drm_ipvr_bufmgr_gem *) bo-
Quoted 1 line

bufmgr;

ipvr/ipvr_bufmgr_gem.c new file +33 -0
+    drm_ipvr_bo_gem *bo_gem = (drm_ipvr_bo_gem *) bo;
+    drm_ipvr_bo_gem *target_bo_gem = (drm_ipvr_bo_gem *) target_bo;
+    VERB("%s::%d\n", __func__, __LINE__);
+    /* Create a new relocation list if needed */
+    if (bo_gem->relocs == NULL) {
+        ret = drm_ipvr_setup_reloc_list(bo);
+        if (ret) {
+            ERR("%s failed: relocs = %p, setup_reloc_list returns %d (%s)\n",
+                __FUNCTION__, bo_gem->relocs, ret, strerror(ret));
+            return -ENOMEM;
+        }
+    }
+
+    /* Check overflow */
+    assert(bo_gem->reloc_count < bufmgr_gem->max_relocs);
+
+    /* Check args */
+    assert(offset <= bo->size - 4);
+
+    /* Make sure that we're not adding a reloc to something whose size has
+     * already been accounted for.
+     */
+    if (target_bo_gem != bo_gem) {
+         /* todo: check it */
+    }
+    /* An object needing a fence is a tiled buffer, so it won't have
+     * relocs to other buffers.
+     */
+    bo_gem->relocs[bo_gem->reloc_count].offset = offset;
+    bo_gem->relocs[bo_gem->reloc_count].delta = target_offset;
+    bo_gem->relocs[bo_gem->reloc_count].target_handle =
+        target_bo_gem->base.handle;
+    bo_gem->relocs[bo_gem->reloc_count].presumed_offset = target_bo-
Quoted 1 line

offset;

ipvr/ipvr_bufmgr_gem.c new file +10 -0
+    bo_gem->reloc_target_info[bo_gem->reloc_count].bo = target_bo;
+
+    if (target_bo != bo)
+        drm_ipvr_gem_bo_reference(target_bo);
+    bo_gem->reloc_target_info[bo_gem->reloc_count].flags = skip_fence?
+        0: IPVR_EXEC_OBJECT_NEED_FENCE;
+
+    bo_gem->reloc_count++;
+
+    VERB("%s emitted reloc: \"%s\" hnd %x (0x%lx) => \"%s\" hnd %x (0x%lx

= 0x%lx+0x%lx)\n",

ipvr/ipvr_bufmgr_gem.c new file +7 -0
+        __FUNCTION__, bo_gem->name, bo->handle, bo->offset,
+        target_bo_gem->name, target_bo->handle,
+        target_bo->offset + target_offset, target_bo->offset, target_offset);
+    return 0;
+}
+
+drm_public drm_ipvr_bo

*drm_ipvr_gem_bo_create_from_name(drm_ipvr_bufmgr *bufmgr,

ipvr/ipvr_bufmgr_gem.c new file +3 -0
+            drm_ipvr_context *ctx, const char *name, uint32_t global_handle)
+{
+    drm_ipvr_bufmgr_gem *bufmgr_gem = (drm_ipvr_bufmgr_gem *)

bufmgr;

ipvr/ipvr_bufmgr_gem.c new file +39 -0
+    drm_ipvr_bo_gem *bo_gem;
+    int ret;
+    struct drm_gem_open open_arg;
+
+    open_arg.name = global_handle;
+    ret = drmIoctl(bufmgr_gem->fd,
+               DRM_IOCTL_GEM_OPEN,
+               &open_arg);
+    if (ret) {
+        ERR("Couldn't reference %s handle 0x%08x: %s\n",
+            name, global_handle, strerror(errno));
+        return NULL;
+    }
+    bo_gem = calloc(1, sizeof(*bo_gem));
+    if (!bo_gem)
+        return NULL;
+
+    bo_gem->base.size = open_arg.size;
+    /**
+     * we don't know the presumed offset.
+     * kernel will fix it up during execution.
+     */
+    bo_gem->base.offset = 0;
+    bo_gem->base.bufmgr = bufmgr;
+    bo_gem->base.handle = open_arg.handle;
+    bo_gem->reusable = false;
+    bo_gem->tiling = 0;
+    bo_gem->caching = 0;
+    bo_gem->name = "flinked";
+    bo_gem->base.virt = NULL;
+    bo_gem->map_offset = 0;
+    atomic_set(&bo_gem->mapcount, 0);
+    atomic_set(&bo_gem->refcount, 1);
+    bo_gem->validate_index = -1;
+    bo_gem->ctx = ctx;
+    bo_gem->exec_seq = -1;
+    bo_gem->is_prime_imported = false;
+    bo_gem->global_name = global_handle;
+    DBG("bo_create_from_handle: %d (%s)\n", global_handle, bo_gem-
Quoted 1 line

name);

ipvr/ipvr_bufmgr_gem.c new file +5 -0
+
+    return &bo_gem->base;
+}
+
+drm_public int drm_ipvr_gem_bo_flink(drm_ipvr_bo *bo, uint32_t

*global_handle)

ipvr/ipvr_bufmgr_gem.c new file +2 -0
+{
+    drm_ipvr_bufmgr_gem *bufmgr_gem = (drm_ipvr_bufmgr_gem *) bo-
Quoted 1 line

bufmgr;

ipvr/ipvr_bufmgr_gem.c new file +22 -0
+    drm_ipvr_bo_gem *bo_gem = (drm_ipvr_bo_gem *) bo;
+    int ret;
+    struct drm_gem_flink flink;
+    if (!bo_gem->global_name) {
+        flink.handle = bo_gem->base.handle;
+
+        ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_GEM_FLINK, &flink);
+        if (ret)
+            return ret;
+
+        bo_gem->global_name = flink.name;
+        bo_gem->reusable = false;
+    }
+
+    *global_handle = bo_gem->global_name;
+    return 0;
+}
+
+drm_public int
+drm_ipvr_gem_bo_export_to_prime(drm_ipvr_bo *bo, int *prime_fd)
+{
+    drm_ipvr_bufmgr_gem *bufmgr_gem = (drm_ipvr_bufmgr_gem *) bo-
Quoted 1 line

bufmgr;

ipvr/ipvr_bufmgr_gem.c new file +18 -0
+    drm_ipvr_bo_gem *bo_gem = (drm_ipvr_bo_gem *) bo;
+    int ret;
+    ret = drmPrimeHandleToFD(bufmgr_gem->fd, bo_gem->base.handle,
+                   DRM_CLOEXEC, prime_fd);
+    if (ret) {
+        ERR("%s: failed calling drmPrimeHandleToFD: %d (%s)\n",
+            __FUNCTION__, ret, strerror(ret))
+        return ret;
+    }
+
+    bo_gem->reusable = false;
+
+    return 0;
+}
+
+drm_public drm_ipvr_bo*
+drm_ipvr_gem_bo_create_from_prime(drm_ipvr_bufmgr *bufmgr,
+            drm_ipvr_context *ctx, const char *name, int prime_fd, size_t

guessed_size)

ipvr/ipvr_bufmgr_gem.c new file +2 -0
+{
+    drm_ipvr_bufmgr_gem *bufmgr_gem = (drm_ipvr_bufmgr_gem *)

bufmgr;

ipvr/ipvr_bufmgr_gem.c new file +68 -0
+    int ret;
+    uint32_t handle;
+    drm_ipvr_bo_gem *bo_gem;
+
+    ret = drmPrimeFDToHandle(bufmgr_gem->fd, prime_fd, &handle);
+    if (ret) {
+        ERR("%s: failed calling drmPrimeFDToHandle: %d (%s)\n",
+            __FUNCTION__, ret, strerror(ret))
+        return NULL;
+    }
+
+    /*
+     * See if the kernel has already returned this buffer to us. Just as
+     * for named buffers, we must not create two bo's pointing at the same
+     * kernel object
+     */
+    pthread_mutex_lock(&bufmgr_gem->lock);
+
+    bo_gem = calloc(1, sizeof(*bo_gem));
+    if (!bo_gem) {
+        pthread_mutex_unlock(&bufmgr_gem->lock);
+        return NULL;
+    }
+    /* Determine size of bo.  The fd-to-handle ioctl really should
+     * return the size, but it doesn't.  If we have kernel 3.12 or
+     * later, we can lseek on the prime fd to get the size.  Older
+     * kernels will just fail, in which case we fall back to the
+     * provided (estimated or guess size). */
+    ret = lseek(prime_fd, 0, SEEK_END);
+    if (ret != -1)
+        bo_gem->base.size = ret;
+    else
+        bo_gem->base.size = guessed_size;
+
+    bo_gem->base.bufmgr = bufmgr;
+    bo_gem->base.handle = handle;
+    bo_gem->tiling = 0;
+    bo_gem->caching = 0;
+    bo_gem->name = name;
+    bo_gem->base.virt = NULL;
+    bo_gem->map_offset = 0;
+    atomic_set(&bo_gem->mapcount, 0);
+    atomic_set(&bo_gem->refcount, 1);
+    bo_gem->validate_index = -1;
+    bo_gem->ctx = ctx;
+    bo_gem->reusable = false;
+    bo_gem->exec_seq = -1;
+    bo_gem->is_prime_imported = true;
+
+    pthread_mutex_unlock(&bufmgr_gem->lock);
+
+    return &bo_gem->base;
+}
+
+static int drm_ipvr_add_validate_buffer(drm_ipvr_bo *bo, uint64_t flags)
+{
+    drm_ipvr_bufmgr_gem *bufmgr_gem = NULL;
+    drm_ipvr_bo_gem *bo_gem = NULL;
+    int index;
+
+    if (!bo) {
+        ERR("%s, invalid bo %p\n", __FUNCTION__, bo);
+        return -EINVAL;
+    }
+    bo_gem = (drm_ipvr_bo_gem *) bo;
+    if (!(bo->bufmgr)) {
+        ERR("%s, invalid bo bufmgr %p for bo \"%s\" hnd %x (off 0x%lx)\n",
+            __FUNCTION__, bo->bufmgr, bo_gem->name, bo->handle, bo-
Quoted 1 line

offset);

ipvr/ipvr_bufmgr_gem.c new file +7 -0
+        return -EINVAL;
+    }
+
+    bufmgr_gem = (drm_ipvr_bufmgr_gem *)bo->bufmgr;
+
+    if (bo_gem->validate_index != -1) {
+        if (!(bufmgr_gem->exec_objs[bo_gem->validate_index].flags &

IPVR_EXEC_OBJECT_NEED_FENCE)

ipvr/ipvr_bufmgr_gem.c new file +2 -0
+            && (flags & IPVR_EXEC_OBJECT_NEED_FENCE)) {
+            VERB("%s: already has validate_index %d, update flags: 0x%llx-
Quoted 1 line

0x%llx\n",

ipvr/ipvr_bufmgr_gem.c new file +3 -0
+                __FUNCTION__, bo_gem->validate_index,
+                bufmgr_gem->exec_objs[bo_gem->validate_index].flags,
+                IPVR_EXEC_OBJECT_NEED_FENCE | bufmgr_gem-
Quoted 1 line

exec_objs[bo_gem->validate_index].flags);

+ bufmgr_gem->exec_objs[bo_gem->validate_index].flags |=
IPVR_EXEC_OBJECT_NEED_FENCE;

ipvr/ipvr_bufmgr_gem.c new file +34 -0
+        }
+        return 0;
+    }
+
+    /* Extend the array of validation entries as necessary. */
+    if (bufmgr_gem->exec_count == bufmgr_gem->exec_size) {
+        int new_size = bufmgr_gem->exec_size * 2;
+
+        if (new_size == 0)
+            new_size = 10;
+
+        bufmgr_gem->exec_objs =
+            realloc(bufmgr_gem->exec_objs,
+                sizeof(*bufmgr_gem->exec_objs) * new_size);
+        bufmgr_gem->exec_bos =
+            realloc(bufmgr_gem->exec_bos,
+                sizeof(*bufmgr_gem->exec_bos) * new_size);
+        bufmgr_gem->exec_size = new_size;
+    }
+
+    if (!bufmgr_gem->exec_objs || !bufmgr_gem->exec_bos) {
+        ERR("%s val_args = %p and exec_bos = %p\n",
+            __FUNCTION__, bufmgr_gem->exec_objs, bufmgr_gem->exec_bos);
+        return -ENOMEM;
+    }
+
+    index = bufmgr_gem->exec_count;
+    bo_gem->validate_index = index;
+    /* Fill in array entry */
+    if (bufmgr_gem->exec_objs && bufmgr_gem->exec_bos) {
+        bufmgr_gem->exec_objs[index].offset = bo->offset;
+        bufmgr_gem->exec_objs[index].handle = bo_gem->base.handle;
+        bufmgr_gem->exec_objs[index].flags = flags;
+        bufmgr_gem->exec_objs[index].relocs_ptr = (uintptr_t)bo_gem-
Quoted 1 line

relocs;

+ bufmgr_gem->exec_objs[index].relocation_count = bo_gem-

Quoted 1 line

reloc_count;

ipvr/ipvr_bufmgr_gem.c new file +48 -0
+        bufmgr_gem->exec_bos[index] = bo;
+
+        VERB("%s added validate buffer \"%s\" hnd %x (off 0x%lx) at [%d]\n",
+            __FUNCTION__, bo_gem->name, bo->handle, bo->offset, index);
+        bufmgr_gem->exec_count++;
+    }
+    return 0;
+}
+
+static int drm_ipvr_bo_process_reloc(drm_ipvr_bo *bo, uint64_t flags)
+{
+    drm_ipvr_bo_gem *bo_gem = (drm_ipvr_bo_gem *)bo;
+    int i;
+    int ret = 0;
+
+    /* Add the target to the validate list */
+    ret = drm_ipvr_add_validate_buffer(bo, flags);
+    if (ret != 0)
+        return ret;
+
+    if (bo_gem->relocs == NULL)
+        return 0;
+
+    for (i = 0; i < bo_gem->reloc_count; i++) {
+        drm_ipvr_bo *target_bo = bo_gem->reloc_target_info[i].bo;
+        uint64_t target_flags = bo_gem->reloc_target_info[i].flags;
+        if (target_bo == bo)
+            continue;
+
+        /* Continue walking the tree depth-first. */
+        ret = drm_ipvr_bo_process_reloc(target_bo, target_flags);
+        if (ret != 0)
+            return ret;
+    }
+
+    return ret;
+}
+
+drm_public int drm_ipvr_gem_bo_exec(drm_ipvr_bo *bo,
+            uint64_t offset, size_t len, int fence_in, int *fence_out)
+{
+    int ret;
+    int i;
+    struct timeval then, now;
+    bool have_then = false;
+    struct drm_ipvr_gem_execbuffer exec_arg;
+    drm_ipvr_bo_gem *bo_gem = (drm_ipvr_bo_gem *)bo;
+    drm_ipvr_bufmgr_gem *bufmgr_gem = (drm_ipvr_bufmgr_gem*)bo-
Quoted 1 line

bufmgr;

ipvr/ipvr_bufmgr_gem.c new file +20 -0
+
+    pthread_mutex_lock(&bufmgr_gem->lock);
+
+    ret = drm_ipvr_bo_process_reloc(bo,
+        IPVR_EXEC_OBJECT_NEED_FENCE | IPVR_EXEC_OBJECT_SUBMIT);
+    if (ret != 0) {
+        ERR("%s bo_process_reloc2 failed: %d (%s)\n",
+            __FUNCTION__, ret, strerror(ret));
+        pthread_mutex_unlock(&bufmgr_gem->lock);
+        return ret;
+    }
+
+    VERB("%s finished the reloc/validate processing. exec_count=%d\n",
+        __FUNCTION__, bufmgr_gem->exec_count);
+    exec_arg.exec_start_offset = offset;
+    exec_arg.exec_len = len;
+    exec_arg.buffers_ptr = (uintptr_t)bufmgr_gem->exec_objs;
+    exec_arg.buffer_count = bufmgr_gem->exec_count;
+    exec_arg.ctx_id = bo_gem->ctx->ctx_id;
+    VERB("%s sending EXEC IOCTL to kernel with: cmdbuf_handle %x (0x%lx),

size %zu, "

ipvr/ipvr_bufmgr_gem.c new file +25 -0
+        "buffer_list_count %u, ctx_id 0x%08x\n", __FUNCTION__, bo->handle,
+        bo->offset, len,
+        exec_arg.buffer_count, exec_arg.ctx_id);
+
+    bufmgr_gem->exec_seq ++;
+    do {
+        ret = drmCommandWriteRead(bufmgr_gem->fd,
+                   DRM_IPVR_GEM_EXECBUFFER,
+                   &exec_arg, sizeof(exec_arg));
+        if (ret == EAGAIN) {
+            if (!have_then) {
+                if (gettimeofday(&then, NULL)) {
+                    ERR("%s have no then, gettimeofday error.\n", __FUNCTION__);
+                    break;
+                }
+
+                have_then = true;
+            }
+            if (gettimeofday(&now, NULL)) {
+                ERR("%s: Gettimeofday error.\n", __FUNCTION__);
+                break;
+            }
+
+        }
+    } while ((ret == EAGAIN) && (drm_ipvr_time_diff(&now, &then) <

IPVR_TIMEOUT_USEC));

ipvr/ipvr_bufmgr_gem.c new file +26 -0
+
+    if (ret) {
+        WARN("%s: command write return is %d\n", __FUNCTION__, ret);
+        goto out;
+    }
+
+    /* update the presumed_mmu_offsets
+     * in case we support eviction in IPVR driver later */
+    for (i = 0; i < bufmgr_gem->exec_count; i++) {
+        drm_ipvr_bo *bo = bufmgr_gem->exec_bos[i];
+        drm_ipvr_bo_gem *bo_gem = (drm_ipvr_bo_gem *)bo;
+
+        /* Update the buffer offset to accelerate future exec */
+        if (bufmgr_gem->exec_objs[i].offset != bo->offset) {
+            VERB("BO \"%s\" hnd %x migrated: 0x%"PRIx64" -> 0x%llx\n",
+                bo_gem->name, bo->handle, bo->offset,
+                bufmgr_gem->exec_objs[i].offset);
+            bo->offset = bufmgr_gem->exec_objs[i].offset;
+        }
+        bo_gem->exec_seq = bufmgr_gem->exec_seq;
+    }
+
+    VERB("%s EXECBUFFER IOCTL succeeded\n", __FUNCTION__);
+out:
+    for (i = 0; i < bufmgr_gem->exec_count; i++) {
+        drm_ipvr_bo_gem *bo_gem = (drm_ipvr_bo_gem*)bufmgr_gem-
Quoted 1 line

exec_bos[i];

ipvr/ipvr_bufmgr_gem.c new file +20 -0
+
+        /* Disconnect the buffer from the validate list */
+        bo_gem->validate_index = -1;
+        bufmgr_gem->exec_bos[i] = NULL;
+    }
+
+    /* autmatically decrease all bo's refcount in the reloc tree.
+     * VA created bo will be cached if unreferencing in vaRenderPicture.
+     * execbuf/mtxmsg/surface/colocated_buffer's refcount will become 1.
+     */
+    drm_ipvr_gem_bo_remove_relocs(bo, 1);
+
+    bufmgr_gem->exec_count = 0;
+    pthread_mutex_unlock(&bufmgr_gem->lock);
+    return 0;
+}
+
+drm_public int drm_ipvr_gem_bo_busy(drm_ipvr_bo *bo)
+{
+    drm_ipvr_bufmgr_gem *bufmgr_gem = (drm_ipvr_bufmgr_gem*)bo-
Quoted 1 line

bufmgr;

ipvr/ipvr_bufmgr_gem.c new file +7 -0
+    drm_ipvr_bo_gem *bo_gem = (drm_ipvr_bo_gem *) bo;
+    struct drm_ipvr_gem_busy arg;
+    int ret;
+
+    arg.handle = bo->handle;
+
+    ret = drmCommandWriteRead(bufmgr_gem->fd, DRM_IPVR_GEM_BUSY,

&arg, sizeof(arg));

ipvr/ipvr_bufmgr_gem.c new file +2 -0
+    if (ret == -EBUSY || (ret == 0 && arg.busy)) {
+        VERB("%s returns %d: buffer \"%s\" hnd %x (offset 0x%lx) param is

busy\".\n",

ipvr/ipvr_bufmgr_gem.c new file +12 -0
+            __FUNCTION__, ret, bo_gem->name, bo->handle, bo->offset);
+        return 1;
+    }
+    else if (!ret && !arg.busy){
+        VERB("%s: buffer \"%s\" hnd %x (offset 0x%lx) param is free\".\n",
+            __FUNCTION__, bo_gem->name, bo->handle, bo->offset);
+        return 0;
+    }
+    else {
+        WARN("%s: checking buffer busy \"%s\" hnd %u (offset 0x%lx) "
+            "got unexpected result: %d (%s), busy state=%d, view it as free.\n",
+            __FUNCTION__, bo_gem->name, bo->handle, bo->offset, ret,

strerror(ret), arg.busy);

ipvr/ipvr_bufmgr_gem.c new file +6 -0
+
+        return 0;
+    }
+}
+
+drm_public void drm_ipvr_gem_bufmgr_destroy(drm_ipvr_bufmgr

*bufmgr)

ipvr/ipvr_bufmgr_gem.c new file +3 -0
+{
+    int j;
+    drm_ipvr_bufmgr_gem *bufmgr_gem =

(drm_ipvr_bufmgr_gem*)bufmgr;

ipvr/ipvr_bufmgr_gem.c new file +36 -0
+
+    if (bufmgr_gem->exec_bos)
+        free(bufmgr_gem->exec_bos);
+    if (bufmgr_gem->exec_objs)
+        free(bufmgr_gem->exec_objs);
+
+    if (bufmgr_gem->cache_buckets) {
+        for (j = 0; j < bufmgr_gem->cache_bucket_size; j++) {
+            struct drm_ipvr_cache_bucket *bucket =
+                &bufmgr_gem->cache_buckets[j];
+
+            while (!DRMLISTEMPTY(&bucket->head)) {
+                drm_ipvr_bo_gem *bo_gem;
+
+                bo_gem = DRMLISTENTRY(drm_ipvr_bo_gem,
+                              bucket->head.next, cache_head);
+
+                DRMLISTDELINIT(&bo_gem->cache_head);
+                bucket->count--;
+                assert(bo_gem->reloc_count == 0);
+                drm_ipvr_gem_bo_free(&bo_gem->base);
+            }
+        }
+
+        free(bufmgr_gem->cache_buckets);
+    }
+
+    pthread_mutex_destroy(&bufmgr_gem->lock);
+    pthread_mutex_destroy(&bufmgr_gem->list_lock);
+    free(bufmgr_gem);
+}
+
+drm_public void drm_ipvr_gem_context_destroy(drm_ipvr_context *ctx)
+{
+    int ret;
+    drm_ipvr_bufmgr_gem *bufmgr_gem = (drm_ipvr_bufmgr_gem*)ctx-
Quoted 1 line

bufmgr;

ipvr/ipvr_bufmgr_gem.c new file +4 -0
+    struct drm_ipvr_context_destroy arg;
+    arg.ctx_id = ctx->ctx_id;
+
+    ret = drmCommandWriteRead(bufmgr_gem->fd,

DRM_IPVR_CONTEXT_DESTROY, &arg, sizeof(arg));

ipvr/ipvr_bufmgr_gem.c new file +14 -0
+    if (ret != 0) {
+        ERR("%s: Error destroying context %u: %s .\n",
+            __FUNCTION__, ctx->ctx_id, strerror(ret));
+    }
+
+    free(ctx);
+}
+
+drm_public drm_ipvr_context*
+drm_ipvr_gem_context_create(drm_ipvr_bufmgr *bufmgr,
+            uint32_t ctx_type, uint32_t tiling_stride, uint32_t tiling_mode)
+{
+    int ret;
+    drm_ipvr_bufmgr_gem *bufmgr_gem =

(drm_ipvr_bufmgr_gem*)bufmgr;

ipvr/ipvr_bufmgr_gem.c new file +6 -0
+    struct drm_ipvr_context_create arg;
+    drm_ipvr_context *ctx = calloc(1, sizeof(drm_ipvr_context));
+    arg.ctx_type = ctx_type;
+    arg.tiling_stride = tiling_stride;
+    arg.tiling_scheme = tiling_mode;
+    ret = drmCommandWriteRead(bufmgr_gem->fd,

DRM_IPVR_CONTEXT_CREATE, &arg, sizeof(arg));

ipvr/ipvr_bufmgr_gem.c new file +2 -0
+    if (ret != 0) {
+        ERR("%s: Error creating context %d: %s. tiling stride=%u,

scheme=%u\n",

ipvr/ipvr_bufmgr_gem.c new file +10 -0
+            __FUNCTION__, ctx_type, strerror(ret),
+            arg.tiling_stride, arg.tiling_scheme);
+        free(ctx);
+        return NULL;
+    }
+    ctx->ctx_id = arg.ctx_id;
+    ctx->ctx_type = ctx_type;
+    ctx->bufmgr = bufmgr;
+
+    DBG("%s: successfully create drm context: id=%x, tiling stride=%u,

scheme=%u\n",

ipvr/ipvr_bufmgr_gem.c new file +5 -0
+        __FUNCTION__, ctx->ctx_id, arg.tiling_stride, arg.tiling_scheme);
+    return ctx;
+}
+
+drm_public int drm_ipvr_gem_bufmgr_get_device_info(drm_ipvr_bufmgr

*bufmgr,

ipvr/ipvr_bufmgr_gem.c new file +5 -0
+            uint16_t *dev_id, uint16_t *caps)
+{
+    struct drm_ipvr_get_info arg;
+    int ret;
+    drm_ipvr_bufmgr_gem *bufmgr_gem =

(drm_ipvr_bufmgr_gem*)bufmgr;

ipvr/ipvr_bufmgr_gem.c new file +3 -0
+    arg.key = IPVR_DEVICE_INFO;
+    arg.value = 0;
+    ret = drmCommandWriteRead(bufmgr_gem->fd, DRM_IPVR_GET_INFO,

&arg, sizeof(arg));

ipvr/ipvr_bufmgr_gem.c new file +44 -0
+    if (ret != 0) {
+        ERR("%s: Error getting device info: %s .\n",
+            __FUNCTION__, strerror(ret));
+        return ret;
+    }
+    *dev_id = (arg.value >> 16) & 0xffff;
+    *caps = arg.value & 0xffff;
+    return 0;
+}
+
+drm_public drm_ipvr_bufmgr *drm_ipvr_gem_bufmgr_init(int fd)
+{
+    drm_ipvr_bufmgr_gem * bufmgr_gem = NULL;
+    int j;
+
+    bufmgr_gem = calloc(1, sizeof(*bufmgr_gem));
+    if (bufmgr_gem == NULL) {
+        ERR("bufmgr init: calloc failed: %s\n", strerror(errno));
+        return NULL;
+    }
+
+    bufmgr_gem->fd = fd;
+
+    if (pthread_mutex_init(&bufmgr_gem->lock, NULL) != 0) {
+        ERR("bufmgr init: mutex init failed: %s\n", strerror(errno));
+        free(bufmgr_gem);
+        bufmgr_gem = NULL;
+        return NULL;
+    }
+    if (pthread_mutex_init(&bufmgr_gem->list_lock, NULL) != 0) {
+        ERR("bufmgr init: mutex init failed: %s\n", strerror(errno));
+        free(bufmgr_gem);
+        bufmgr_gem = NULL;
+        return NULL;
+    }
+
+    /* Hard code one.
+     */
+    bufmgr_gem->max_relocs = 32;
+
+    bufmgr_gem->exec_seq = -1;
+
+    /* init cache buckets */
+    /* 4KB, 8KB, 16KB, 32KB, 64KB, 128KB, 256KB, 512KB, 1MB, 2MB, 4MB,

8MB, 16MB, 32MB */

ipvr/ipvr_bufmgr_gem.c new file +17 -0
+    bufmgr_gem->cache_bucket_size = 14;
+    bufmgr_gem->cache_buckets = calloc(bufmgr_gem->cache_bucket_size,
+        sizeof(struct drm_ipvr_cache_bucket));
+    if (!bufmgr_gem->cache_buckets) {
+        ERR("%s failed to allocate cache buckets\n", __FUNCTION__);
+        return NULL;
+    }
+
+    for (j = 0; j < bufmgr_gem->cache_bucket_size; ++j) {
+        DRMINITLISTHEAD(&bufmgr_gem->cache_buckets[j].head);
+        bufmgr_gem->cache_buckets[j].size = 0x1000 << j;
+        bufmgr_gem->cache_buckets[j].limit = 2 << ((14 - j)/2);
+        bufmgr_gem->cache_buckets[j].count = 0;
+    }
+
+    DBG("%s created bufmgr %p with cache_bucket_size %u\n",
+        __FUNCTION__, &bufmgr_gem->base, bufmgr_gem-
Quoted 1 line

cache_bucket_size);

ipvr/ipvr_bufmgr_gem.c new file +3 -0
+
+    return &bufmgr_gem->base;
+}
ipvr/libdrm_ipvr.pc.in new file +11 -0
new file mode 100644
index 0000000..34c5291
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libdrm_ipvr
+Description: Userspace interface to IPVR hardware decoder on valleyview
+Version: @PACKAGE_VERSION@
+Requires: libdrm
+Libs: -L${libdir} -ldrm_ipvr
+Cflags: -I${includedir} -I${includedir}/libdrm
ipvr/test_ipvr.c new file +1 -0
new file mode 100644
index 0000000..acbee94
@@ -0,0 +1,919 @@
+/*********************************************************

*****************
+ * test_ioctl.c: it is gem ioctl unit test
+ *
+ * Copyright (c) 2014 Intel Corporation, Hillsboro, OR, USA
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authors:
+ * Yao Cheng <[email protected]>
+ *
+
**********************************************************
****************/

ipvr/test_ipvr.c new file +64 -0
+
+/*
+ * This is a program to do stress test on ipvr driver and libdrm_ipvr,
+ * It creates multiple threads executing decode commands in parallel.
+ * Usage: test_ipvr -l <loop count> -t <thread count>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <xf86drm.h>
+#include <xf86atomic.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <assert.h>
+#include <pthread.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <stdbool.h>
+#include <inttypes.h>
+#include <stdint.h>
+
+#include "errno.h"
+#ifndef ETIME
+#define ETIME ETIMEDOUT
+#endif
+#include "libdrm.h"
+#include "libdrm_lists.h"
+#include "ipvr_bufmgr.h"
+#include "string.h"
+
+#include "ipvr_drm.h"
+#include "../intel/intel_bufmgr.h"
+
+static inline void random_wait(void) {
+    usleep(rand()%5000);
+}
+
+static void random_mem_init(void *mem, size_t size)
+{
+    uint32_t i;
+    uint32_t *dword = (uint32_t*)mem;
+    for (i = 0; i < size/sizeof(uint32_t); ++i) {
+        *(dword++) = (uint32_t)rand();
+    }
+}
+
+#define exit_with_err(ret, fmt, ...) \
+    do { \
+        fprintf(stderr, fmt, ##__VA_ARGS__); \
+        exit(ret); \
+    } while (0);
+
+#define check_condition(cond) \
+    do { \
+        if (!(cond)) \
+            exit_with_err(-1, "failed at %s::%d: \"%s\"\n", __FILE__, __LINE__,

#cond); \

ipvr/test_ipvr.c new file +13 -0
+    } while (0);
+
+#define check_equal(a, b) \
+    do { \
+        if (a != b) \
+            exit_with_err(-1, "failed at %s::%d: %"PRIx64" == %"PRIx64"\n", \
+                __FILE__, __LINE__, (uint64_t)a, (uint64_t)b); \
+    } while (0);
+
+#define check_fd(fd) \
+    do { \
+        if (fd < 0) \
+            exit_with_err(ret, "failed at %s::%d: fd = %d\n", __FILE__, __LINE__,

fd); \

ipvr/test_ipvr.c new file +11 -1
+    } while (0);
+
+#define check_ret(ret) \
+    do { \
+        if (ret) \
+            exit_with_err(ret, "failed at %s::%d: %d (%s)\n", __FILE__, __LINE__,
-ret, strerror(-ret)); \
+    } while (0);
+#define check_addr(addr) \
+    do { \
+        if (!addr) \
+            exit_with_err(-1, "failed at %s::%d: NULL address\n", __FILE__,

__LINE__); \

ipvr/test_ipvr.c new file +4 -0
+    } while (0);
+
+static unsigned char video_slice_data[] = {
+

0x00,0x00,0x01,0x65,0x88,0x84,0x00,0x57,0x87,0xc6,0xb2,0xd9,0xe6,0x75,0x be,0x70,
+ 0x28,0x14,0xc0,0xfb,0x61,0xa2,0x42,0xd8,0xca,0x67,0xa2,0xd0,0x3e,0x14,0x6 1,0x6d,
+ 0x80,0xc0,0x2b,0x11,0x9d,0x92,0x47,0x73,0x04,0x87,0xe3,0xb0,0x8b,0x82,0x c9,0xf0,
+ 0x8f,0xaf,0x35,0x28,0x6b,0x11,0xdf,0x9c,0xe9,0xa2,0xc5,0xb0,0x8e,0xed,0xd a,0x0e,

ipvr/test_ipvr.c new file +5 -0
+    0x3c,0x1c,0xb4,0xc0,0x00,0x00,0x00,0x00
+};
+
+static unsigned char video_cmd_data[] = {
+

0x00,0x00,0x00,0x90,0x08,0x00,0x0a,0x00,0x00,0x50,0x51,0x00,0x00,0x00,0x0 0,0x00,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 0,0x00,
+ 0x19,0x00,0x10,0x80,0x10,0x04,0x00,0xe0,0x00,0x60,0x59,0x00,0xec,0x08,0x1 6,0x10,
+ 0x00,0x60,0x02,0x00,0xa0,0x38,0x07,0x00,0xf4,0x28,0x08,0x00,0x2d,0x31,0x0 a,0x00,
+ 0x59,0x59,0x0b,0x00,0x7b,0x51,0x0c,0x00,0x96,0x11,0x0d,0x00,0xad,0xb1,0x 0d,0x00,
+ 0xbe,0x21,0x0e,0x00,0xc8,0x59,0x0e,0x00,0xcd,0x79,0x0e,0x00,0xd3,0xb1,0x 0e,0x00,
+ 0xd8,0xd1,0x0e,0x00,0xdd,0x09,0x0f,0x00,0xe7,0x71,0x0f,0x00,0xf6,0x01,0x0 0,0x00,
+ 0xdd,0xa4,0x56,0x12,0x92,0x92,0x48,0x01,0x50,0x80,0x24,0x11,0x02,0x00,0x 00,0x00,
+ 0x02,0x2a,0x00,0x00,0x2a,0x28,0x08,0x01,0x01,0x00,0x00,0xb0,0x40,0x00,0x0 0,0x00,
+ 0x45,0x00,0x00,0x00,0x45,0x00,0x00,0xa0,0x00,0xf0,0x5e,0x00,0x0c,0x08,0x0 1,0x10,
+ 0x11,0x00,0x00,0x00,0x00,0x0a,0x05,0x10,0x00,0x37,0x00,0x00,0x05,0x02,0x1 e,0x1e,
+ 0x08,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x70,0x00,0x00,0x18,0x0a,0x0 1,0x10,
+ 0x00,0x00,0x00,0x00,0x10,0x08,0x01,0x50,0x11,0x00,0x00,0x00,0xd8,0x0a,0x0 7,0x50,
+ 0x00,0x37,0x00,0x00,0x05,0x02,0x1e,0x1e,0x08,0x00,0x00,0x00,0x00,0x00,0x 08,0x00,
+ 0x00,0x70,0x00,0x00,0x00,0x70,0x5f,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x3 8,0x50,
+ 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1 0,0x10,
+ 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1 0,0x10,
+ 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1 0,0x10,
+ 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1 0,0x10,
+ 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1 0,0x10,
+ 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1 0,0x10,
+ 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1 0,0x10,
+ 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1 0,0x10,
+ 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1 0,0x10,
+ 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1 0,0x10,
+ 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1 0,0x10,
+ 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1 0,0x10,
+ 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1 0,0x10,
+ 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1 0,0x10,
+ 0x00,0x10,0x0a,0x50,0x0f,0xf0,0x00,0x00,0x0f,0xf0,0x00,0x00,0x00,0x10,0x21 ,0x04,
+ 0x00,0xf0,0x50,0x00,0x00,0x30,0x51,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x5 1,0x00,
+ 0x04,0x80,0x04,0x00,0x00,0x00,0x00,0x00,0x55,0x00,0x00,0x00,0x00,0x14,0x0 1,0x50,
+ 0x08,0x00,0x0a,0x00,0x3c,0x10,0x02,0x50,0x00,0x00,0x00,0x00,0x00,0x02,0x0 0,0x00,

ipvr/test_ipvr.c new file +5 -0
+    0x00,0x00,0x00,0x60
+};
+
+static unsigned char video_msg_data[] = {
+

0x14,0x81,0x80,0x01,0x11,0x49,0x85,0x00,0x00,0xd0,0x5b,0x00,0x95,0x70,0x ee,0x31,

ipvr/test_ipvr.c new file +52 -0
+    0x00,0x10,0x21,0x04
+};
+
+static int reference_cache_size = 512 * 1024;
+#define CLIP_WIDTH  16
+#define CLIP_HEIGHT 16
+
+static int pre_opened_fd;
+static drm_ipvr_bufmgr *pre_opened_bufmgr;
+
+#define RAND_MEM_SIZE (16 * 4096)
+static uint8_t rand_ipvr_mem[RAND_MEM_SIZE];
+static uint8_t rand_i915_mem[RAND_MEM_SIZE];
+static void* basic_ioctl_test(void* arg)
+{
+    struct drm_ipvr_gem_create create_arg;
+    struct drm_gem_close close_arg;
+    struct drm_gem_flink flink_arg;
+    struct drm_gem_open open_arg;
+    struct drm_ipvr_gem_mmap_offset map_offset_arg;
+    int fd, i915_fd, export_fd, i915_export_fd;
+    dri_bufmgr *i915_bufmgr;
+    dri_bo *i915_bo;
+    uint32_t global_name;
+    uint32_t *vaddr;
+    uint32_t import_handle;
+    int ret = 0;
+    int use_pre_opened = 1;
+    size_t create_size = 16 * 4096;
+    size_t i915_create_size = 2 * 4096;
+
+    if(rand() % 3)
+        use_pre_opened = 0;
+    if (use_pre_opened)
+        fd = pre_opened_fd;
+    else
+        fd = open("/dev/dri/card1", O_RDWR);
+
+    check_fd(fd);
+    i915_fd = open("/dev/dri/card0", O_RDWR);
+    check_fd(i915_fd);
+    i915_bufmgr = drm_intel_bufmgr_gem_init(i915_fd, 4096);
+    check_addr(i915_bufmgr);
+
+    /* create bo */
+    {
+        random_wait();
+        memset(&create_arg, 0, sizeof(create_arg));
+        create_arg.size = create_size;
+        create_arg.cache_level = 0;
+        create_arg.tiling = 0;
+        ret = drmCommandWriteRead(fd, DRM_IPVR_GEM_CREATE,

&create_arg, sizeof(create_arg));

ipvr/test_ipvr.c new file +9 -0
+        check_ret(ret);
+    }
+
+    /* mmap bo*/
+    {
+        random_wait();
+        if (!create_arg.map_offset) {
+            map_offset_arg.handle = create_arg.handle;
+            ret = drmCommandWriteRead(fd, DRM_IPVR_GEM_MMAP_OFFSET,

&map_offset_arg, sizeof(map_offset_arg));

ipvr/test_ipvr.c new file +4 -0
+            check_ret(ret);
+        }
+        random_wait();
+        vaddr = drm_mmap(NULL, create_arg.rounded_size, PROT_READ |

PROT_WRITE,

ipvr/test_ipvr.c new file +27 -0
+                   MAP_SHARED, fd, create_arg.map_offset);
+        check_addr (vaddr);
+        memcpy(vaddr, rand_ipvr_mem, create_size);
+        random_wait();
+        drm_munmap(vaddr, create_arg.rounded_size);
+    }
+
+    /* flink and open */
+    {
+        random_wait();
+        flink_arg.handle = create_arg.handle;
+        flink_arg.name = 0;
+        ret = drmIoctl(fd, DRM_IOCTL_GEM_FLINK, &flink_arg);
+        check_ret(ret);
+        global_name = flink_arg.name;
+
+        /* open from flink name */
+        open_arg.name = global_name;
+        random_wait();
+        ret = drmIoctl(fd, DRM_IOCTL_GEM_OPEN, &open_arg);
+        check_ret(ret);
+        check_equal (open_arg.size, create_arg.rounded_size)
+
+        /* mmap and verify the bo content */
+        map_offset_arg.handle = open_arg.handle;
+        random_wait();
+        ret = drmCommandWriteRead(fd, DRM_IPVR_GEM_MMAP_OFFSET,

&map_offset_arg, sizeof(map_offset_arg));

ipvr/test_ipvr.c new file +21 -0
+        check_ret(ret);
+        /* mmap bo ioctl*/
+        random_wait();
+        vaddr = drm_mmap(NULL, open_arg.size, PROT_READ,
+                   MAP_SHARED, fd, map_offset_arg.offset);
+        check_addr(vaddr);
+        check_ret(memcmp(vaddr, rand_ipvr_mem, create_size));
+        random_wait();
+        drm_munmap(vaddr, create_arg.rounded_size);
+
+        /* close opened bo ioctl*/
+        random_wait();
+        close_arg.handle = open_arg.handle;
+        ret = drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, &close_arg);
+        check_ret(ret);
+    }
+
+    /* test prime import */
+    {
+        random_wait();
+        i915_bo = dri_bo_alloc(i915_bufmgr, "to-be-exported",

i915_create_size, 0x1000);

ipvr/test_ipvr.c new file +18 -0
+        check_addr(i915_bo);
+        ret = dri_bo_map(i915_bo, 1);
+        check_ret(ret);
+        check_addr(i915_bo->virtual);
+        vaddr = i915_bo->virtual;
+        memcpy(i915_bo->virtual, rand_i915_mem, i915_create_size);
+        ret = dri_bo_unmap(i915_bo);
+        check_ret(ret);
+        random_wait();
+        ret = drm_intel_bo_gem_export_to_prime(i915_bo, &i915_export_fd);
+        check_ret(ret);
+        check_fd(i915_export_fd);
+        random_wait();
+        ret = drmPrimeFDToHandle(fd, i915_export_fd, &import_handle);
+        check_ret(ret);
+        map_offset_arg.handle = import_handle;
+        random_wait();
+        ret = drmCommandWriteRead(fd, DRM_IPVR_GEM_MMAP_OFFSET,

&map_offset_arg, sizeof(map_offset_arg));

ipvr/test_ipvr.c new file +25 -0
+        check_ret(ret);
+        random_wait();
+        vaddr = drm_mmap(NULL, i915_create_size, PROT_READ,
+                   MAP_SHARED, fd, map_offset_arg.offset);
+        check_addr(vaddr);
+        check_ret(memcmp(vaddr, rand_i915_mem, i915_create_size));
+        random_wait();
+        ret = drm_munmap(vaddr, i915_create_size);
+        check_ret(ret);
+        random_wait();
+        close_arg.handle = import_handle;
+        ret = drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, &close_arg);
+        check_ret(ret);
+        close(i915_export_fd);
+        dri_bo_unreference(i915_bo);
+    }
+
+    /* test prime export */
+    {
+        random_wait();
+        ret = drmPrimeHandleToFD(fd, create_arg.handle, 0, &export_fd);
+        check_ret(ret);
+        check_fd(export_fd);
+        random_wait();
+        i915_bo = drm_intel_bo_gem_create_from_prime(i915_bufmgr,

export_fd, create_arg.rounded_size);

ipvr/test_ipvr.c new file +55 -0
+        check_addr(i915_bo);
+        check_equal(i915_bo->size, create_size);
+        ret = drm_intel_gem_bo_map_gtt(i915_bo);
+        check_ret(ret);
+        check_addr(i915_bo->virtual);
+        //check_ret(memcmp(i915_bo->virtual, rand_ipvr_mem, create_size));
+        ret = dri_bo_unmap(i915_bo);
+        check_ret(ret);
+        random_wait();
+        dri_bo_unreference(i915_bo);
+        random_wait();
+        close(export_fd);
+    }
+
+    /* close bo ioctl*/
+    random_wait();
+    close_arg.handle = create_arg.handle;
+    ret = drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, &close_arg);
+    check_ret(ret);
+
+    dri_bufmgr_destroy(i915_bufmgr);
+    close(i915_fd);
+    if (!use_pre_opened)
+        close(fd);
+
+    return NULL;
+}
+
+static void* decode_ioctl_test(void* args)
+{
+    struct drm_ipvr_context_create ctx_create_arg;
+    struct drm_ipvr_context_destroy ctx_destroy_arg;
+    struct drm_ipvr_gem_create create_arg;
+    struct drm_ipvr_gem_execbuffer exec_arg;
+    struct drm_ipvr_gem_wait wait_arg;
+    struct drm_ipvr_gem_busy busy_arg;
+    struct drm_gem_close close_arg;
+    struct drm_ipvr_gem_relocation_entry reloc_entries[6];
+    struct drm_ipvr_gem_exec_object exec_objs[7];
+    struct drm_ipvr_gem_exec_object *arg;
+    int fd, i915_fd, i915_export_fd;
+    dri_bufmgr *i915_bufmgr;
+    dri_bo *i915_bo;
+    uint32_t import_handle;
+    uint32_t *vaddr;
+    int i, ret = 0, ctx_type;
+    int use_pre_opened = 1;
+    if(rand() % 3)
+        use_pre_opened = 0;
+    if (use_pre_opened)
+        fd = pre_opened_fd;
+    else
+        fd = open("/dev/dri/card1", O_RDWR);
+
+    memset(exec_objs, 0, sizeof(7 * sizeof(struct

drm_ipvr_gem_exec_object)));
+ memset(reloc_entries, 0, sizeof(6 * sizeof(struct
drm_ipvr_gem_relocation_entry)));

ipvr/test_ipvr.c new file +13 -0
+    check_fd(fd);
+    i915_fd = open("/dev/dri/card0", O_RDWR);
+    check_fd(i915_fd);
+    i915_bufmgr = drm_intel_bufmgr_gem_init(i915_fd, 4096);
+    check_addr(i915_bufmgr);
+
+    random_wait();
+    memset(&ctx_create_arg, 0, sizeof(ctx_create_arg));
+    ctx_type = IPVR_CONTEXT_TYPE_VED;
+    ctx_create_arg.ctx_type = ctx_type;
+    ctx_create_arg.tiling_scheme = 0;
+    ctx_create_arg.tiling_stride = 0;
+    ret = drmCommandWriteRead(fd, DRM_IPVR_CONTEXT_CREATE,

&ctx_create_arg, sizeof(ctx_create_arg));

ipvr/test_ipvr.c new file +7 -0
+    check_ret(ret);
+
+    /* create preload bo */
+    random_wait();
+    memset(&create_arg, 0, sizeof(create_arg));
+    create_arg.size = 1 << 12;
+    ret = drmCommandWriteRead(fd, DRM_IPVR_GEM_CREATE,

&create_arg, sizeof(create_arg));

ipvr/test_ipvr.c new file +18 -0
+    check_ret(ret);
+    arg = &exec_objs[0];
+    arg->handle = create_arg.handle;
+    arg->offset = create_arg.mmu_offset;
+    arg->flags = IPVR_EXEC_OBJECT_NEED_FENCE;
+    arg->relocation_count = 0;
+    arg->relocs_ptr = (uintptr_t)NULL;
+    reloc_entries[0].delta = 0;
+    reloc_entries[0].offset = 8;
+    reloc_entries[0].presumed_offset = create_arg.mmu_offset;
+    reloc_entries[0].target_handle = create_arg.handle;
+    /* preload bo end */
+
+    /* create colocated bo */
+    random_wait();
+    memset(&create_arg, 0, sizeof(create_arg));
+    create_arg.size = 5 << 12;
+    ret = drmCommandWriteRead(fd, DRM_IPVR_GEM_CREATE,

&create_arg, sizeof(create_arg));

ipvr/test_ipvr.c new file +18 -0
+    check_ret(ret);
+    arg = &exec_objs[1];
+    arg->handle = create_arg.handle;
+    arg->offset = create_arg.mmu_offset;
+    arg->flags = IPVR_EXEC_OBJECT_NEED_FENCE;
+    arg->relocation_count = 0;
+    arg->relocs_ptr = (uintptr_t)NULL;
+    reloc_entries[1].delta = 0;
+    reloc_entries[1].offset = 57 * 4;
+    reloc_entries[1].presumed_offset = create_arg.mmu_offset;
+    reloc_entries[1].target_handle = create_arg.handle;
+    /* colocated bo end */
+
+    /* create reference cache bo */
+    random_wait();
+    memset(&create_arg, 0, sizeof(create_arg));
+    create_arg.size = reference_cache_size;
+    ret = drmCommandWriteRead(fd, DRM_IPVR_GEM_CREATE,

&create_arg, sizeof(create_arg));

ipvr/test_ipvr.c new file +16 -0
+    check_ret(ret);
+    arg = &exec_objs[2];
+    arg->flags = 0;
+    arg->handle = create_arg.handle;
+    arg->offset = create_arg.mmu_offset;
+    arg->relocation_count = 0;
+    arg->relocs_ptr = (uintptr_t)NULL;
+    reloc_entries[2].delta = 0;
+    reloc_entries[2].offset = 123 * 4;
+    reloc_entries[2].presumed_offset = create_arg.mmu_offset;
+    reloc_entries[2].target_handle = create_arg.handle;
+    /* reference cache bo end */
+
+    /* create surface bo */
+    random_wait();
+    i915_bo = dri_bo_alloc(i915_bufmgr, "to-be-exported", 512 * 32 * 3 / 2,

0x1000);

ipvr/test_ipvr.c new file +25 -0
+    check_addr(i915_bo);
+    ret = drm_intel_bo_gem_export_to_prime(i915_bo, &i915_export_fd);
+    check_ret(ret);
+    check_fd(i915_export_fd);
+    random_wait();
+    ret = drmPrimeFDToHandle(fd, i915_export_fd, &import_handle);
+    check_ret(ret);
+    arg = &exec_objs[3];
+    arg->handle = import_handle;
+    arg->offset = 0; /* we don't know the mmu offset */
+    arg->flags = IPVR_EXEC_OBJECT_NEED_FENCE;
+    arg->relocation_count = 0;
+    arg->relocs_ptr = (uintptr_t)NULL;
+    reloc_entries[3].delta = 0;
+    reloc_entries[3].offset = 120 * 4;
+    reloc_entries[3].presumed_offset = 0; // let kernel fix it
+    reloc_entries[3].target_handle = import_handle;
+    /* create surface bo */
+
+    /* create slice data bo */
+    random_wait();
+    memset(&create_arg, 0, sizeof(create_arg));
+    create_arg.size = 4096;
+    create_arg.cache_level = IPVR_CACHE_WRITECOMBINE;
+    ret = drmCommandWriteRead(fd, DRM_IPVR_GEM_CREATE,

&create_arg, sizeof(create_arg));

ipvr/test_ipvr.c new file +2 -0
+    check_ret(ret);
+    vaddr = drm_mmap(NULL, create_arg.rounded_size, PROT_READ |

PROT_WRITE,

ipvr/test_ipvr.c new file +22 -0
+               MAP_SHARED, fd, create_arg.map_offset);
+    check_addr (vaddr);
+    memcpy((void *)vaddr, video_slice_data, sizeof(video_slice_data));
+    random_wait();
+    drm_munmap(vaddr, create_arg.rounded_size);
+    arg = &exec_objs[4];
+    arg->flags = 0;
+    arg->handle = create_arg.handle;
+    arg->offset = create_arg.mmu_offset;
+    arg->relocation_count = 0;
+    arg->relocs_ptr = (uintptr_t)NULL;
+    reloc_entries[4].delta = 0;
+    reloc_entries[4].offset = 38 * 4;
+    reloc_entries[4].presumed_offset = create_arg.mmu_offset;
+    reloc_entries[4].target_handle = create_arg.handle;
+    /* slice data end */
+
+    /* create cmd bo */
+    random_wait();
+    memset(&create_arg, 0, sizeof(create_arg));
+    create_arg.size = 4096;
+    ret = drmCommandWriteRead(fd, DRM_IPVR_GEM_CREATE,

&create_arg, sizeof(create_arg));

ipvr/test_ipvr.c new file +2 -0
+    check_ret(ret);
+    vaddr = drm_mmap(NULL, create_arg.rounded_size, PROT_READ |

PROT_WRITE,

ipvr/test_ipvr.c new file +27 -0
+               MAP_SHARED, fd, create_arg.map_offset);
+    check_addr (vaddr);
+    memcpy((void *)vaddr, video_cmd_data, sizeof(video_cmd_data));
+    vaddr[2] = exec_objs[0].offset;
+    vaddr[38] = exec_objs[4].offset;
+    vaddr[57] = exec_objs[1].offset;
+    vaddr[120] = exec_objs[3].offset;
+    vaddr[123] = exec_objs[2].offset;
+    random_wait();
+    drm_munmap(vaddr, create_arg.rounded_size);
+    arg = &exec_objs[5];
+    arg->flags = IPVR_EXEC_OBJECT_NEED_FENCE;
+    arg->handle = create_arg.handle;
+    arg->offset = create_arg.mmu_offset;
+    arg->relocation_count = 5;
+    arg->relocs_ptr = (uintptr_t)&reloc_entries[0];
+    reloc_entries[5].delta = 0;
+    reloc_entries[5].offset = 8;
+    reloc_entries[5].presumed_offset = create_arg.mmu_offset;
+    reloc_entries[5].target_handle = create_arg.handle;
+    /* cmd buf end */
+
+    /* create msg bo */
+    random_wait();
+    memset(&create_arg, 0, sizeof(create_arg));
+    create_arg.size = 4096;
+    ret = drmCommandWriteRead(fd, DRM_IPVR_GEM_CREATE,

&create_arg, sizeof(create_arg));

ipvr/test_ipvr.c new file +2 -0
+    check_ret(ret);
+    vaddr = drm_mmap(NULL, create_arg.rounded_size, PROT_READ |

PROT_WRITE,

ipvr/test_ipvr.c new file +8 -0
+               MAP_SHARED, fd, create_arg.map_offset);
+    check_addr (vaddr);
+    memcpy((void *)vaddr, video_msg_data, sizeof(video_msg_data));
+    vaddr[2] = exec_objs[5].offset;
+    random_wait();
+    drm_munmap(vaddr, create_arg.rounded_size);
+    arg = &exec_objs[6];
+    arg->flags = IPVR_EXEC_OBJECT_NEED_FENCE |

IPVR_EXEC_OBJECT_SUBMIT;

ipvr/test_ipvr.c new file +16 -0
+    arg->handle = create_arg.handle;
+    arg->offset = create_arg.mmu_offset;
+    arg->relocation_count = 1;
+    arg->relocs_ptr = (uintptr_t)&reloc_entries[5];
+    /* msg bo end */
+
+    /* run execbuffer ioctl */
+    random_wait();
+    memset(&exec_arg, 0, sizeof(exec_arg));
+    exec_arg.buffer_count = 7;
+    exec_arg.buffers_ptr = (uintptr_t)exec_objs;
+    exec_arg.exec_start_offset = 0;
+    exec_arg.exec_len = 20;
+    exec_arg.ctx_id = ctx_create_arg.ctx_id;
+    random_wait();
+    ret = drmCommandWriteRead(fd, DRM_IPVR_GEM_EXECBUFFER,

&exec_arg, sizeof(exec_arg));

ipvr/test_ipvr.c new file +7 -0
+    check_ret(ret);
+
+    /*check busy ioctl*/
+    random_wait();
+    memset(&busy_arg, 0, sizeof(busy_arg));
+    busy_arg.handle = create_arg.handle;
+    ret = drmCommandWriteRead(fd, DRM_IPVR_GEM_BUSY, &busy_arg,

sizeof(busy_arg));

ipvr/test_ipvr.c new file +7 -0
+    check_condition ((ret == 0) || (ret == -EBUSY));
+
+    /*wait for finish*/
+    random_wait();
+    memset(&wait_arg, 0, sizeof(wait_arg));
+    wait_arg.handle = create_arg.handle;
+    ret = drmCommandWriteRead(fd, DRM_IPVR_GEM_WAIT, &wait_arg,

sizeof(wait_arg));

ipvr/test_ipvr.c new file +23 -0
+    /* the random command causes PANIC */
+    check_condition((ret == 0) || (ret == -EDEADLK));
+
+    /* close val bo and cmd bo */
+    random_wait();
+    memset(&close_arg, 0, sizeof(close_arg));
+    for (i = 0; i < 7; i++) {
+        close_arg.handle = exec_objs[i].handle;
+        ret = drmIoctl(fd, DRM_IOCTL_GEM_CLOSE, &close_arg);
+        check_ret (ret);
+    }
+
+    /* clean up i915 */
+    close(i915_export_fd);
+    dri_bo_unreference(i915_bo);
+    dri_bufmgr_destroy(i915_bufmgr);
+    close(i915_fd);
+
+    /* destroy the ctx_context */
+    random_wait();
+    memset(&ctx_destroy_arg, 0, sizeof(ctx_destroy_arg));
+    ctx_destroy_arg.ctx_id = ctx_create_arg.ctx_id;
+    ret = drmCommandWriteRead(fd, DRM_IPVR_CONTEXT_DESTROY,

&ctx_destroy_arg, sizeof(ctx_destroy_arg));

ipvr/test_ipvr.c new file +44 -0
+    check_ret(ret);
+    if (!use_pre_opened)
+        close(fd);
+    return NULL;
+}
+
+static void* basic_libdrm_test(void *args)
+{
+    int fd, i915_fd, export_fd, i915_export_fd;
+    drm_ipvr_bo *created_bo, *flinked_bo, *imported_bo;
+    dri_bo *i915_created_bo, *i915_imported_bo;
+    drm_ipvr_bufmgr *bufmgr;
+    dri_bufmgr *i915_bufmgr;
+    int ret= 0;
+    uint32_t flink_name;
+    int use_pre_opened_fd = 1;
+    int use_pre_opened_bufmgr = 1;
+    size_t create_size = 16 * 4096;
+    size_t i915_create_size = 2 * 4096;
+
+    if(rand() % 3)
+        use_pre_opened_fd = 0;
+    if(rand() % 3)
+        use_pre_opened_bufmgr = 0;
+
+    if (use_pre_opened_fd)
+        fd = pre_opened_fd;
+    else
+        fd = open("/dev/dri/card1", O_RDWR);
+    check_fd(fd);
+
+    if (use_pre_opened_bufmgr)
+        bufmgr = pre_opened_bufmgr;
+    else
+        bufmgr = drm_ipvr_gem_bufmgr_init(fd);
+    check_addr(bufmgr);
+
+    i915_fd = open("/dev/dri/card0", O_RDWR);
+    check_fd(i915_fd);
+    i915_bufmgr = drm_intel_bufmgr_gem_init(i915_fd, 4096);
+    check_addr(i915_bufmgr);
+
+    {
+        created_bo = drm_ipvr_gem_bo_alloc(bufmgr, NULL, "created",

create_size, 0, 0);

ipvr/test_ipvr.c new file +14 -0
+        check_addr(created_bo);
+        check_condition(created_bo->size >= create_size);
+        ret = drm_ipvr_gem_bo_map(created_bo, 1);
+        check_ret(ret);
+        check_addr(created_bo->virt);
+        memcpy(created_bo->virt, rand_ipvr_mem, create_size);
+        ret = drm_ipvr_gem_bo_unmap(created_bo);
+        check_ret(ret);
+    }
+
+    {
+        ret = drm_ipvr_gem_bo_flink(created_bo, &flink_name);
+        check_ret(ret);
+        flinked_bo = drm_ipvr_gem_bo_create_from_name(bufmgr, NULL,

"flinked", flink_name);

ipvr/test_ipvr.c new file +6 -0
+        check_addr(flinked_bo);
+        check_equal(flinked_bo->size, created_bo->size);
+        ret = drm_ipvr_gem_bo_map(flinked_bo, 0);
+        check_ret(ret);
+        check_addr(flinked_bo->virt);
+        check_ret(memcmp(flinked_bo->virt, rand_ipvr_mem, flinked_bo-
Quoted 1 line

size));

ipvr/test_ipvr.c new file +7 -0
+        ret = drm_ipvr_gem_bo_unmap(flinked_bo);
+        check_ret(ret);
+        drm_ipvr_gem_bo_unreference(flinked_bo);
+    }
+
+    {
+        i915_created_bo = dri_bo_alloc(i915_bufmgr, "i915_bo",

i915_create_size, 0x1000);

ipvr/test_ipvr.c new file +9 -0
+        check_addr(i915_created_bo);
+        ret = dri_bo_map(i915_created_bo, 1);
+        check_ret(ret);
+        check_addr(i915_created_bo->virtual);
+        memcpy(i915_created_bo->virtual, rand_i915_mem, i915_create_size);
+        ret = dri_bo_unmap(i915_created_bo);
+        check_ret(ret);
+        random_wait();
+        ret = drm_intel_bo_gem_export_to_prime(i915_created_bo,

&i915_export_fd);

ipvr/test_ipvr.c new file +3 -0
+        check_ret(ret);
+        check_fd(i915_export_fd);
+        imported_bo = drm_ipvr_gem_bo_create_from_prime(bufmgr, NULL,

"imported", i915_export_fd, i915_create_size);

ipvr/test_ipvr.c new file +6 -0
+        check_addr(imported_bo);
+        check_equal(i915_created_bo->size, imported_bo->size);
+        ret = drm_ipvr_gem_bo_map(imported_bo, 0);
+        check_ret(ret);
+        check_addr(imported_bo->virt);
+        check_ret(memcmp(imported_bo->virt, rand_i915_mem,

i915_create_size));

ipvr/test_ipvr.c new file +12 -0
+        ret = drm_ipvr_gem_bo_unmap(imported_bo);
+        check_ret(ret);
+        drm_ipvr_gem_bo_unreference(imported_bo);
+        close(i915_export_fd);
+        dri_bo_unreference(i915_created_bo);
+    }
+
+    {
+        ret = drm_ipvr_gem_bo_export_to_prime(created_bo, &export_fd);
+        check_ret(ret);
+        check_fd(export_fd);
+        i915_imported_bo =

drm_intel_bo_gem_create_from_prime(i915_bufmgr, export_fd, created_bo->size);

ipvr/test_ipvr.c new file +6 -0
+        check_addr(i915_imported_bo);
+        check_equal(i915_imported_bo->size, created_bo->size);
+        ret = drm_intel_gem_bo_map_gtt(i915_imported_bo);
+        check_ret(ret);
+        check_addr(i915_imported_bo->virtual);
+        //check_ret(memcmp(i915_imported_bo->virtual, rand_ipvr_mem,

create_size));

ipvr/test_ipvr.c new file +24 -0
+        ret = dri_bo_unmap(i915_imported_bo);
+        check_ret(ret);
+        dri_bo_unreference(i915_imported_bo);
+        close(export_fd);
+    }
+
+    drm_ipvr_gem_bo_unreference(created_bo);
+
+    dri_bufmgr_destroy(i915_bufmgr);
+    close(i915_fd);
+    if (!use_pre_opened_bufmgr)
+        drm_ipvr_gem_bufmgr_destroy(bufmgr);
+    if (!use_pre_opened_fd)
+        close(fd);
+
+    return NULL;
+}
+
+static void* decode_libdrm_test(void *args)
+{
+    int fd, i915_fd, i915_export_fd;
+    dri_bufmgr *i915_bufmgr;
+    drm_ipvr_bufmgr *bufmgr;
+    drm_ipvr_bo *pre_bo, *col_bo, *slc_bo, *surf_bo, *ref_bo, *cmd_bo,

*msg_bo;

ipvr/test_ipvr.c new file +31 -0
+    dri_bo *i915_bo;
+    drm_ipvr_context *ctx;
+    int ret = 0;
+    int use_pre_opened_fd = 1;
+    int use_pre_opened_bufmgr = 1;
+
+    if(rand() % 3)
+        use_pre_opened_fd = 0;
+    if(rand() % 3)
+        use_pre_opened_bufmgr = 0;
+
+    if (use_pre_opened_fd)
+        fd = pre_opened_fd;
+    else
+        fd = open("/dev/dri/card1", O_RDWR);
+    check_fd(fd);
+
+    if (use_pre_opened_bufmgr)
+        bufmgr = pre_opened_bufmgr;
+    else
+        bufmgr = drm_ipvr_gem_bufmgr_init(fd);
+    check_addr(bufmgr);
+
+    i915_fd = open("/dev/dri/card0", O_RDWR);
+    check_fd(i915_fd);
+    i915_bufmgr = drm_intel_bufmgr_gem_init(i915_fd, 4096);
+    check_addr(i915_bufmgr);
+
+    /* create a ctx_context, which is needed for exec ioctl */
+    random_wait();
+    ctx = drm_ipvr_gem_context_create(bufmgr, IPVR_CONTEXT_TYPE_VED,

0, 0);

ipvr/test_ipvr.c new file +9 -0
+    check_addr(ctx);
+
+    /* preload */
+    random_wait();
+    pre_bo = drm_ipvr_gem_bo_alloc(bufmgr, NULL, "preload", 4096, 0, 0);
+    check_addr(pre_bo);
+    /* colocated */
+    random_wait();
+    col_bo = drm_ipvr_gem_bo_alloc(bufmgr, NULL, "colocated", 5 << 12, 0,

0);

ipvr/test_ipvr.c new file +4 -0
+    check_addr(col_bo);
+    /* reference */
+    random_wait();
+    ref_bo = drm_ipvr_gem_bo_alloc(bufmgr, NULL, "reference",

reference_cache_size, 0, 0);

ipvr/test_ipvr.c new file +10 -0
+    check_addr(ref_bo);
+    /* surface */
+    random_wait();
+    i915_bo = dri_bo_alloc(i915_bufmgr, "surface", 512 * 32 * 3 / 2, 0x1000);
+    check_addr(i915_bo);
+    ret = drm_intel_bo_gem_export_to_prime(i915_bo, &i915_export_fd);
+    check_ret(ret);
+    check_fd(i915_export_fd);
+    random_wait();
+    surf_bo = drm_ipvr_gem_bo_create_from_prime(bufmgr, ctx,

"imported", i915_export_fd, 512 * 32 * 3 / 2);

ipvr/test_ipvr.c new file +4 -0
+    check_addr(surf_bo);
+    /* slice */
+    random_wait();
+    slc_bo = drm_ipvr_gem_bo_alloc(bufmgr, NULL, "slice",

sizeof(video_slice_data), 0, 0);

ipvr/test_ipvr.c new file +4 -0
+    check_addr(slc_bo);
+    /* cmd bo */
+    random_wait();
+    cmd_bo = drm_ipvr_gem_bo_alloc(bufmgr, NULL, "cmd",

sizeof(video_cmd_data), 0, 0);

ipvr/test_ipvr.c new file +4 -0
+    check_addr(cmd_bo);
+    /* cmd bo */
+    random_wait();
+    msg_bo = drm_ipvr_gem_bo_alloc(bufmgr, ctx, "msg",

sizeof(video_msg_data), 0, 0);

ipvr/test_ipvr.c new file +40 -0
+    check_addr(msg_bo);
+
+    /* setup relocs */
+    ret = drm_ipvr_gem_bo_emit_reloc(msg_bo, 8, cmd_bo, 0, 0);
+    check_ret(ret);
+    ret = drm_ipvr_gem_bo_emit_reloc(cmd_bo, 8, pre_bo, 0, 0);
+    check_ret(ret);
+    ret = drm_ipvr_gem_bo_emit_reloc(cmd_bo, 57 * 4, col_bo, 0, 0);
+    check_ret(ret);
+    ret = drm_ipvr_gem_bo_emit_reloc(cmd_bo, 123 * 4, ref_bo, 0, 1);
+    check_ret(ret);
+    ret = drm_ipvr_gem_bo_emit_reloc(cmd_bo, 120 * 4, surf_bo, 0, 0);
+    check_ret(ret);
+    ret = drm_ipvr_gem_bo_emit_reloc(cmd_bo, 38 * 4, slc_bo, 0, 0);
+    check_ret(ret);
+
+    /* set data */
+    random_wait();
+    ret = drm_ipvr_gem_bo_map(slc_bo, 1);
+    check_ret(ret);
+    check_addr(slc_bo->virt);
+    memcpy(slc_bo->virt, video_slice_data, sizeof(video_slice_data));
+    ret = drm_ipvr_gem_bo_unmap(slc_bo);
+    check_ret(ret);
+    ret = drm_ipvr_gem_bo_map(cmd_bo, 1);
+    check_ret(ret);
+    check_addr(cmd_bo->virt);
+    memcpy(cmd_bo->virt, video_cmd_data, sizeof(video_cmd_data));
+    ret = drm_ipvr_gem_bo_unmap(cmd_bo);
+    check_ret(ret);
+    ret = drm_ipvr_gem_bo_map(msg_bo, 1);
+    check_ret(ret);
+    check_addr(msg_bo->virt);
+    memcpy(msg_bo->virt, video_msg_data, sizeof(video_msg_data));
+    ret = drm_ipvr_gem_bo_unmap(msg_bo);
+    check_ret(ret);
+
+    /* execute */
+    random_wait();
+    ret = drm_ipvr_gem_bo_exec(msg_bo, 0, sizeof(video_msg_data), -1,

NULL);

ipvr/test_ipvr.c new file +72 -0
+    check_ret(ret);
+
+    /*check busy ioctl*/
+    random_wait();
+    drm_ipvr_gem_bo_busy(col_bo);
+
+    /*wait for finish*/
+    random_wait();
+    drm_ipvr_gem_bo_wait(surf_bo);
+
+    /* destroy all bos */
+    drm_ipvr_gem_bo_unreference(msg_bo);
+    drm_ipvr_gem_bo_unreference(cmd_bo);
+    drm_ipvr_gem_bo_unreference(surf_bo);
+    drm_ipvr_gem_bo_unreference(slc_bo);
+    drm_ipvr_gem_bo_unreference(pre_bo);
+    drm_ipvr_gem_bo_unreference(col_bo);
+    drm_ipvr_gem_bo_unreference(ref_bo);
+
+    /* clean up i915 */
+    close(i915_export_fd);
+    dri_bo_unreference(i915_bo);
+    dri_bufmgr_destroy(i915_bufmgr);
+    close(i915_fd);
+
+    /* destroy the ctx_context */
+    random_wait();
+    drm_ipvr_gem_context_destroy(ctx);
+    check_ret(ret);
+
+    /* house-cleaning */
+    if (!use_pre_opened_bufmgr)
+        drm_ipvr_gem_bufmgr_destroy(bufmgr);
+    if (!use_pre_opened_fd)
+        close(fd);
+    return NULL;
+}
+
+int main(int argc, char **argv)
+{
+    int err, opt;
+    int loop_count = 1;
+    int thread_count = 1;
+    int i;
+    int ret = 0;
+    pthread_t *threads;
+    pre_opened_fd = open("/dev/dri/card1", O_RDWR);
+    check_fd(pre_opened_fd);
+    pre_opened_bufmgr = drm_ipvr_gem_bufmgr_init(pre_opened_fd);
+    check_addr(pre_opened_bufmgr);
+
+    while ((opt = getopt(argc, argv, "l:t:")) != -1) {
+       switch (opt) {
+       case 'l':
+           loop_count = atoi(optarg);
+           break;
+       case 't':
+           thread_count = atoi(optarg);
+           break;
+       default: /* '?' */
+           fprintf(stderr, "Usage: %s [-t nsecs] [-n] name\n",
+                   argv[0]);
+           exit(-1);
+       }
+    }
+
+    random_mem_init(rand_ipvr_mem, sizeof(rand_ipvr_mem));
+    random_mem_init(rand_i915_mem, sizeof(rand_i915_mem));
+
+    threads = (pthread_t*)calloc(4 * thread_count, sizeof(pthread_t));
+    check_addr(threads);
+    fprintf(stderr, "Starting stress test with %d loops and %d threads for each

loop\n\n",

ipvr/test_ipvr.c new file +7 -0
+        loop_count, thread_count);
+    /* test bo create, mmap, close */
+    while (loop_count--) {
+        for (i = 0; i < thread_count; ++i) {
+            err = pthread_create(&threads[i], NULL, basic_ioctl_test, NULL);
+            check_ret(err);
+            err = pthread_create(&threads[thread_count * 1 + i], NULL,

decode_ioctl_test, NULL);

ipvr/test_ipvr.c new file +2 -0
+            check_ret(err);
+            err = pthread_create(&threads[thread_count * 2 + i], NULL,

basic_libdrm_test, NULL);

ipvr/test_ipvr.c new file +2 -0
+            check_ret(err);
+            err = pthread_create(&threads[thread_count * 3 + i], NULL,

decode_libdrm_test, NULL);

ipvr/test_ipvr.c new file +14 -1
+            check_ret(err);
+        }
+        for (i = 0; i < thread_count * 4; ++i) {
+            err = pthread_join(threads[i], NULL);
+            check_ret(err);
+        }
+        fprintf(stderr, ".");
+    }
+    free(threads);
+    drm_ipvr_gem_bufmgr_destroy(pre_opened_bufmgr);
+    close(pre_opened_fd);
+    fprintf(stderr, "\n\nAll tests finished successfully!\n");
+    return 0;
+}
--
Quoted 1 line

2.1.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#7 lore raw

RFC PATCH v4 4/4 tests/drv_module_reload: add ipvr support

In reply to Sean V Kelley

From: Yao Cheng <[email protected]>

on vlv, if ipvr is installed, it need be manually unloaded before i915, otherwise user might run into use-after-free issue.

v2:
added this patch per Daniel's comment

v3:
no change

---
 tests/drv_module_reload | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
tests/drv_module_reload +16 -0
index 5cbff89..82c67bd 100755
@@ -24,6 +24,14 @@ rmmod snd_hda_intel &> /dev/null
 
 #ignore errors in ips - gen5 only
 rmmod intel_ips &> /dev/null
+
+# vlv only for now:
+# due to platform device model limitation, need unload ipvr manually
+if lsmod | grep ipvr &> /dev/null ; then
+	echo Need manually unload ipvr.ko.
+	rmmod ipvr
+fi
+
 rmmod i915
 #ignore errors in intel-gtt, often built-in
 rmmod intel-gtt &> /dev/null
@@ -31,6 +39,11 @@ rmmod intel-gtt &> /dev/null
 rmmod drm_kms_helper &> /dev/null
 rmmod drm &> /dev/null
 
+if lsmod | grep ipvr &> /dev/null ; then
+	echo WARNING: ipvr.ko still loaded!
+	exit 1
+fi
+
 if lsmod | grep i915 &> /dev/null ; then
 	echo WARNING: i915.ko still loaded!
 	exit 1
@@ -41,6 +54,9 @@ fi
 modprobe i915
 echo 1 > /sys/class/vtconsole/vtcon1/bind
 
+# for vlv, load VED driver
+modprobe ipvr
+
 modprobe snd_hda_intel
 
 # try to run something
Signature · 6 lines
2.1.0

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#8 lore raw

RE: [RFC PATCH v4 4/4] tests/drv_module_reload: add ipvr support

+ commenters on v1~v3

When locking issue resolved, this patch can be removed.

Thanks,
Yao

Quoted 64 lines

-----Original Message-----
From: Sean V Kelley [mailto:[email protected]]
Sent: Thursday, January 8, 2015 8:35
To: [email protected]
Cc: [email protected]; Cheng, Yao; Sean V Kelley
Subject: [RFC PATCH v4 4/4] tests/drv_module_reload: add ipvr support

From: Yao Cheng <[email protected]>

on vlv, if ipvr is installed, it need be manually unloaded before i915, otherwise user might run into use-after-free issue.

v2:
added this patch per Daniel's comment

v3:
no change

---
 tests/drv_module_reload | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
tests/drv_module_reload index renamed from tests/drv_module_reload +0 -0

5cbff89..82c67bd 100755

tests/drv_module_reload +8 -0
@@ -24,6 +24,14 @@ rmmod snd_hda_intel &> /dev/null
 
 #ignore errors in ips - gen5 only
 rmmod intel_ips &> /dev/null
+
+# vlv only for now:
+# due to platform device model limitation, need unload ipvr manually if
+lsmod | grep ipvr &> /dev/null ; then
+	echo Need manually unload ipvr.ko.
+	rmmod ipvr
+fi
+
 rmmod i915
 #ignore errors in intel-gtt, often built-in  rmmod intel-gtt &> /dev/null @@ -

31,6 +39,11 @@ rmmod intel-gtt &> /dev/null rmmod drm_kms_helper &> /dev/null rmmod drm &> /dev/null

tests/drv_module_reload +8 -1
+if lsmod | grep ipvr &> /dev/null ; then
+	echo WARNING: ipvr.ko still loaded!
+	exit 1
+fi
+
 if lsmod | grep i915 &> /dev/null ; then
 	echo WARNING: i915.ko still loaded!
 	exit 1
@@ -41,6 +54,9 @@ fi
 modprobe i915
 echo 1 > /sys/class/vtconsole/vtcon1/bind
 
+# for vlv, load VED driver
+modprobe ipvr
+
 modprobe snd_hda_intel
 
 # try to run something
--
Quoted 1 line

2.1.0

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#9 lore raw
In reply to Sean V Kelley

+ commenters of v1~v3

Thanks,
Yao

Quoted 33 lines

-----Original Message-----
From: dri-devel [mailto:[email protected]] On Behalf Of Sean V Kelley
Sent: Thursday, January 8, 2015 8:35
To: [email protected]
Cc: [email protected]
Subject: [RFC PATCH v4 0/4] drm driver for VED in Intel GPU

drm/ipvr is a new GEM driver for VED (PowerVR's VPU integrated in Intel GPU), which extends video capability.
A new Kconfig added for building ipvr driver:

CONFIG_DRM_IPVR: Build option for ipvr module

The driver name "ipvr" means the PowerVR's core wrapped by Intel. The PowerVR VPUs are also integrated by non-i915 platforms such as GMA500, so we keep ipvr driver and i915 driver separated and independent to each other. To achieve this we do the minimum change in i915: i915_ved.c added for setting up the bridge between VED and i915, kerneldoc also updated.

User mode drm helper "libdrm_ipvr.so" and simple ioctl/execute test is included.

one test script "drv_module_reload" in i-g-t also updated to support ipvr loading and unloading. Due to restriction in Linux platform device model, we have to manually unload ipvr before unloading i915.

Yao Cheng (4):
[1/4] drm/i915: add i915_ved.c to setup bridge for VED [2/4] drm/ipvr: drm driver for VED [3/4] libdrm/ipvr: user mode helper for ipvr drm driver [4/4] i-
g-t: tests/drv_module_reload: add ipvr support

Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx