Skip to contentSkip to conversation

drm driver for baytrail's vxd392

RFC PATCH In review Yao Cheng 9 participants 27 messages Oct 13, 2014 – Oct 19, 2014

Subsystems (3)
lore
Share & tools
lore

Yao Cheng

author
#0 lore raw

cover drm driver for baytrail's vxd392

drm/ipvr is a new GEM driver for baytrail's vxd392, which accelerates VP8 video decoding.
The driver name "ipvr" means the PowerVR's IP wrapped by Intel. In the future, ipvr may support other platforms such as Merrifield. Code is placed at drivers/gpu/drm/ipvr and the following two new Kconfig are added:
CONFIG_DRM_IPVR: Build option for ipvr module
CONFIG_DRM_IPVR_EC: Experimental feature of error concealment

User mode drm helper "libdrm_ipvr.so" and simple test are also included.

Yao Cheng (3):
[1/3] drm/i915: add vxd392 bridge in i915 on baytrail [2/3] drm/ipvr: ipvr drm driver for vxd392 [3/3] libdrm: user mode helper for ipvr drm driver

Signature · 1 line
1.9.1
author
#1 lore raw

RFC PATCH 1/3 drm/i915: add vxd392 bridge in i915

Setup following resources during i915_driver_load:
1. create a child platform and resource
2. allocate a new IRQ line and irq chip
3. set up IRQ mask/unmask callbacks
vxd392 driver (if installed) will bind itself to the platform device and create new drm device

---
 drivers/gpu/drm/i915/i915_dma.c   | 98 +++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_drv.h   |  6 +++
 drivers/gpu/drm/i915/i915_irq.c   | 70 ++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_reg.h   |  4 ++
 drivers/gpu/drm/i915/i915_trace.h | 15 ++++++
 5 files changed, 193 insertions(+)
drivers/gpu/drm/i915/i915_dma.c +98 -0
index 85d14e1..73c78d1 100644
@@ -85,6 +85,96 @@ intel_read_legacy_status_page(struct drm_i915_private *dev_priv, int reg)
 #define READ_BREADCRUMB(dev_priv) READ_HWSP(dev_priv, I915_BREADCRUMB_INDEX)
 #define I915_BREADCRUMB_INDEX		0x21
 
+static int valleyview_ved_init(struct drm_device *dev)
+{
+	int ret;
+	int irq = -1;
+	struct resource *rsc = NULL;
+	struct drm_i915_private *dev_priv = dev->dev_private;;
+
+	dev_priv->ved_platdev = platform_device_alloc("ipvr-ved", -1);
+	if (unlikely(!dev_priv->ved_platdev)) {
+		DRM_ERROR("Failed to allocate VED platform device\n");
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	rsc = kzalloc(sizeof(*rsc) * 3, GFP_KERNEL);
+	if (unlikely(!rsc)) {
+		DRM_ERROR("Failed to allocate resource for VED platform device\n");
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	/* init IRQ number and chip/callbacks */
+	irq = irq_alloc_descs(-1, 0, 1, 0);
+	if (unlikely(irq < 0)) {
+		DRM_ERROR("Failed to allocate IRQ number: %d\n", irq);
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	ret = valleyview_initialize_ved_irq(dev, irq);
+	if (unlikely(ret)) {
+		DRM_ERROR("Failed to initialize VED IRQ: %d\n", ret);
+		goto err;
+	}
+
+	dev_priv->ved_irq = irq;
+	rsc[0].start    = rsc[0].end = irq;
+	rsc[0].flags    = IORESOURCE_IRQ;
+	rsc[0].name     = "ipvr-ved-irq";
+
+	/* MMIO/REG for child's use */
+	rsc[1].start    = pci_resource_start(dev->pdev, 0);
+	rsc[1].end      = pci_resource_start(dev->pdev, 0) + 2*1024*1024; /* gen7 */
+	rsc[1].flags    = IORESOURCE_MEM;
+	rsc[1].name     = "ipvr-ved-mmio";
+
+	rsc[2].start    = VLV_VED_BASE;
+	rsc[2].end      = VLV_VED_BASE + VLV_VED_SIZE;
+	rsc[2].flags    = IORESOURCE_REG;
+	rsc[2].name     = "ipvr-ved-reg";
+
+	ret = platform_device_add_resources(dev_priv->ved_platdev, rsc, 3);
+	if (unlikely(ret)) {
+		DRM_ERROR("Failed to add resource for VED platform device: %d\n", ret);
+		goto err;
+	}
+
+	/* Runtime-PM hook */
+	dev_priv->ved_platdev->dev.parent = dev->dev;
+	ret = platform_device_add(dev_priv->ved_platdev);
+	if (unlikely(ret)) {
+		DRM_ERROR("Failed to add VED platform device: %d\n", ret);
+		goto err;
+	}
+
+	kfree(rsc);
+	DRM_INFO("Successfully initialized Valleyview-VED\n");
+	return 0;
+err:
+	if (rsc)
+		kfree(rsc);
+	if (dev_priv->ved_platdev)
+		platform_device_unregister(dev_priv->ved_platdev);
+	if (irq >= 0)
+		irq_free_desc(irq);
+	return ret;
+}
+
+static void valleyview_ved_cleanup(struct drm_device *dev)
+{
+	int irq;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+
+	irq = platform_get_irq(dev_priv->ved_platdev, 0);
+	if (irq >= 0)
+		irq_free_desc(irq);
+
+	platform_device_unregister(dev_priv->ved_platdev);
+}
+
 void i915_update_dri1_breadcrumb(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
@@ -1793,6 +1883,10 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
 
 	intel_runtime_pm_enable(dev_priv);
 
+	if (IS_VALLEYVIEW(dev)) {
+		BUG_ON(valleyview_ved_init(dev));
+	}
+
 	return 0;
 
 out_power_well:
@@ -1833,6 +1927,10 @@ int i915_driver_unload(struct drm_device *dev)
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	int ret;
 
+	if (IS_VALLEYVIEW(dev)) {
+		valleyview_ved_cleanup(dev);
+	}
+
 	ret = i915_gem_suspend(dev);
 	if (ret) {
 		DRM_ERROR("failed to idle hardware: %d\n", ret);
drivers/gpu/drm/i915/i915_drv.h +6 -0
index 821ba26..aa8a183 100644
@@ -1709,6 +1709,10 @@ struct drm_i915_private {
 
 	uint32_t bios_vgacntr;
 
+	/* used for setup sub device for valleyview */
+	struct platform_device *ved_platdev;
+	int	ved_irq;
+
 	/* Old dri1 support infrastructure, beware the dragons ya fools entering
 	 * here! */
 	struct i915_dri1_state dri1;
@@ -2921,6 +2925,8 @@ void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
 int vlv_gpu_freq(struct drm_i915_private *dev_priv, int val);
 int vlv_freq_opcode(struct drm_i915_private *dev_priv, int val);
 
+extern int valleyview_initialize_ved_irq(struct drm_device *dev, int irq);
+
 #define FORCEWAKE_RENDER	(1 << 0)
 #define FORCEWAKE_MEDIA		(1 << 1)
 #define FORCEWAKE_ALL		(FORCEWAKE_RENDER | FORCEWAKE_MEDIA)
drivers/gpu/drm/i915/i915_irq.c +70 -0

88 lines not on this page · raw message

drivers/gpu/drm/i915/i915_reg.h +4 -0
index 2ed02c3..89c8a06 100644
@@ -1281,9 +1281,13 @@ enum punit_power_well {
 #define   GFX_PSMI_GRANULARITY		(1<<10)
 #define   GFX_PPGTT_ENABLE		(1<<9)
 
+#define VLV_VED_BASE 0x170000
+#define VLV_VED_SIZE 0x010000
 #define VLV_DISPLAY_BASE 0x180000
 #define VLV_MIPI_BASE VLV_DISPLAY_BASE
 
+#define VLV_VED_BLOCK_INTERRUPT			(1 << 23)
+
 #define VLV_GU_CTL0	(VLV_DISPLAY_BASE + 0x2030)
 #define VLV_GU_CTL1	(VLV_DISPLAY_BASE + 0x2034)
 #define SCPD0		0x0209c /* 915+ only */
drivers/gpu/drm/i915/i915_trace.h +15 -0
index f5aa006..522bd1d 100644
@@ -587,6 +587,21 @@ TRACE_EVENT(intel_gpu_freq_change,
 	    TP_printk("new_freq=%u", __entry->freq)
 );
 
+TRACE_EVENT(valleyview_ved_event,
+	    TP_PROTO(u32 iir),
+	    TP_ARGS(iir),
+
+	    TP_STRUCT__entry(
+			     __field(u32, iir)
+			     ),
+
+	    TP_fast_assign(
+			   __entry->iir = iir;
+			   ),
+
+	    TP_printk("forwarded with iir 0x%08x", __entry->iir)
+);
+
 #endif /* _I915_TRACE_H_ */
 
 /* This part must be outside protection */
Signature · 1 line
1.9.1
maintainer
#2 lore raw

Re: [RFC PATCH 1/3] drm/i915: add vxd392 bridge in i915

Quoted 118 lines · Yao Cheng

Setup following resources during i915_driver_load:
1. create a child platform and resource
2. allocate a new IRQ line and irq chip
3. set up IRQ mask/unmask callbacks
vxd392 driver (if installed) will bind itself to the platform device and create new drm device

---
 drivers/gpu/drm/i915/i915_dma.c   | 98 +++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_drv.h   |  6 +++
 drivers/gpu/drm/i915/i915_irq.c   | 70 ++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_reg.h   |  4 ++
 drivers/gpu/drm/i915/i915_trace.h | 15 ++++++
 5 files changed, 193 insertions(+)
drivers/gpu/drm/i915/i915_dma.c +90 -0
index 85d14e1..73c78d1 100644
@@ -85,6 +85,96 @@ intel_read_legacy_status_page(struct drm_i915_private *dev_priv, int reg)
 #define READ_BREADCRUMB(dev_priv) READ_HWSP(dev_priv, I915_BREADCRUMB_INDEX)
 #define I915_BREADCRUMB_INDEX		0x21
 
+static int valleyview_ved_init(struct drm_device *dev)
+{
+	int ret;
+	int irq = -1;
+	struct resource *rsc = NULL;
+	struct drm_i915_private *dev_priv = dev->dev_private;;
+
+	dev_priv->ved_platdev = platform_device_alloc("ipvr-ved", -1);
+	if (unlikely(!dev_priv->ved_platdev)) {
+		DRM_ERROR("Failed to allocate VED platform device\n");
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	rsc = kzalloc(sizeof(*rsc) * 3, GFP_KERNEL);
+	if (unlikely(!rsc)) {
+		DRM_ERROR("Failed to allocate resource for VED platform device\n");
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	/* init IRQ number and chip/callbacks */
+	irq = irq_alloc_descs(-1, 0, 1, 0);
+	if (unlikely(irq < 0)) {
+		DRM_ERROR("Failed to allocate IRQ number: %d\n", irq);
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	ret = valleyview_initialize_ved_irq(dev, irq);
+	if (unlikely(ret)) {
+		DRM_ERROR("Failed to initialize VED IRQ: %d\n", ret);
+		goto err;
+	}
+
+	dev_priv->ved_irq = irq;
+	rsc[0].start    = rsc[0].end = irq;
+	rsc[0].flags    = IORESOURCE_IRQ;
+	rsc[0].name     = "ipvr-ved-irq";
+
+	/* MMIO/REG for child's use */
+	rsc[1].start    = pci_resource_start(dev->pdev, 0);
+	rsc[1].end      = pci_resource_start(dev->pdev, 0) + 2*1024*1024; /* gen7 */
+	rsc[1].flags    = IORESOURCE_MEM;
+	rsc[1].name     = "ipvr-ved-mmio";
+
+	rsc[2].start    = VLV_VED_BASE;
+	rsc[2].end      = VLV_VED_BASE + VLV_VED_SIZE;
+	rsc[2].flags    = IORESOURCE_REG;
+	rsc[2].name     = "ipvr-ved-reg";
+
+	ret = platform_device_add_resources(dev_priv->ved_platdev, rsc, 3);
+	if (unlikely(ret)) {
+		DRM_ERROR("Failed to add resource for VED platform device: %d\n", ret);
+		goto err;
+	}
+
+	/* Runtime-PM hook */
+	dev_priv->ved_platdev->dev.parent = dev->dev;
+	ret = platform_device_add(dev_priv->ved_platdev);
+	if (unlikely(ret)) {
+		DRM_ERROR("Failed to add VED platform device: %d\n", ret);
+		goto err;
+	}
+
+	kfree(rsc);
+	DRM_INFO("Successfully initialized Valleyview-VED\n");
+	return 0;
+err:
+	if (rsc)
+		kfree(rsc);
+	if (dev_priv->ved_platdev)
+		platform_device_unregister(dev_priv->ved_platdev);
+	if (irq >= 0)
+		irq_free_desc(irq);
+	return ret;
+}
+
+static void valleyview_ved_cleanup(struct drm_device *dev)
+{
+	int irq;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+
+	irq = platform_get_irq(dev_priv->ved_platdev, 0);
+	if (irq >= 0)
+		irq_free_desc(irq);
+
+	platform_device_unregister(dev_priv->ved_platdev);
+}
+
 void i915_update_dri1_breadcrumb(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;

drivers/gpu/drm/i915/i915_dma.c int i915_driver_load(struct drm_device *dev, unsigned long flags) · line 1887

Quoted 5 lines
drivers/gpu/drm/i915/i915_dma.c +2 -0
@@ -1793,6 +1883,10 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
 
 	intel_runtime_pm_enable(dev_priv);
 
+	if (IS_VALLEYVIEW(dev)) {
+		BUG_ON(valleyview_ved_init(dev));

Just a quick drive-by comment, please don't bring down the machine if this one fails.

Thanks,
Jani.

Quoted 185 lines
drivers/gpu/drm/i915/i915_dma.c +6 -0
+	}
+
 	return 0;
 
 out_power_well:
@@ -1833,6 +1927,10 @@ int i915_driver_unload(struct drm_device *dev)
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	int ret;
 
+	if (IS_VALLEYVIEW(dev)) {
+		valleyview_ved_cleanup(dev);
+	}
+
 	ret = i915_gem_suspend(dev);
 	if (ret) {
 		DRM_ERROR("failed to idle hardware: %d\n", ret);
drivers/gpu/drm/i915/i915_drv.h +6 -0
index 821ba26..aa8a183 100644
@@ -1709,6 +1709,10 @@ struct drm_i915_private {
 
 	uint32_t bios_vgacntr;
 
+	/* used for setup sub device for valleyview */
+	struct platform_device *ved_platdev;
+	int	ved_irq;
+
 	/* Old dri1 support infrastructure, beware the dragons ya fools entering
 	 * here! */
 	struct i915_dri1_state dri1;
@@ -2921,6 +2925,8 @@ void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
 int vlv_gpu_freq(struct drm_i915_private *dev_priv, int val);
 int vlv_freq_opcode(struct drm_i915_private *dev_priv, int val);
 
+extern int valleyview_initialize_ved_irq(struct drm_device *dev, int irq);
+
 #define FORCEWAKE_RENDER	(1 << 0)
 #define FORCEWAKE_MEDIA		(1 << 1)
 #define FORCEWAKE_ALL		(FORCEWAKE_RENDER | FORCEWAKE_MEDIA)
drivers/gpu/drm/i915/i915_irq.c +70 -0
index 737b239..25c8cde 100644
@@ -2142,12 +2142,75 @@ static void i9xx_hpd_irq_handler(struct drm_device *dev)
 	}
 }
 
+static void valleyview_enable_ved_irq(struct irq_data *d)
+{
+	struct drm_device *dev = d->chip_data;
+	struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
+	unsigned long irqflags;
+	u32 imr, ier;
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	ier = I915_READ(VLV_IER);
+	ier |= VLV_VED_BLOCK_INTERRUPT;
+	DRM_DEBUG_DRIVER("%s IER=>0x%08x\n", __func__, ier);
+	I915_WRITE(VLV_IER, ier);
+	POSTING_READ(VLV_IER);
+
+	imr = I915_READ(VLV_IMR);
+	imr &= ~VLV_VED_BLOCK_INTERRUPT;
+	dev_priv->irq_mask = imr;
+	DRM_DEBUG_DRIVER("%s IMR=>0x%08x\n", __func__, imr);
+	I915_WRITE(VLV_IMR, imr);
+	POSTING_READ(VLV_IMR);
+
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
+}
+
+static void valleyview_disable_ved_irq(struct irq_data *d)
+{
+	struct drm_device *dev = d->chip_data;
+	struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
+	unsigned long irqflags;
+	u32 imr, ier;
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	ier = I915_READ(VLV_IER);
+	ier &= ~VLV_VED_BLOCK_INTERRUPT;
+	DRM_DEBUG_DRIVER("%s IER=>0x%08x\n", __func__, ier);
+	I915_WRITE(VLV_IER, ier);
+	POSTING_READ(VLV_IER);
+
+	imr = I915_READ(VLV_IMR);
+	imr |= VLV_VED_BLOCK_INTERRUPT;
+	dev_priv->irq_mask = imr;
+	DRM_DEBUG_DRIVER("%s IMR=>0x%08x\n", __func__, imr);
+	I915_WRITE(VLV_IMR, imr);
+	POSTING_READ(VLV_IMR);
+
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
+}
+
+int valleyview_initialize_ved_irq(struct drm_device *dev, int irq)
+{
+	static struct irq_chip ved_irqchip = {
+		.name = "ipvr_ved_irqchip",
+		.irq_mask = valleyview_disable_ved_irq,
+		.irq_unmask = valleyview_enable_ved_irq,
+	};
+	irq_set_chip_and_handler_name(irq,
+		&ved_irqchip,
+		handle_simple_irq,
+		"ipvr_ved_irq_handler");
+	return irq_set_chip_data(irq, dev);
+}
+
 static irqreturn_t valleyview_irq_handler(int irq, void *arg)
 {
 	struct drm_device *dev = arg;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	u32 iir, gt_iir, pm_iir;
 	irqreturn_t ret = IRQ_NONE;
+	int ved_ret;
 
 	while (true) {
 		/* Find, clear, then process each source of interrupt */
@@ -2177,6 +2240,13 @@ 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 (IS_VALLEYVIEW(dev) && dev_priv->ved_irq >= 0
+				&& (iir & VLV_VED_BLOCK_INTERRUPT)) {
+			ved_ret = generic_handle_irq(dev_priv->ved_irq);
+			if (ved_ret)
+				DRM_ERROR("Error forwarding VED irq: %d\n", ved_ret);
+			trace_valleyview_ved_event(iir);
+		}
 		/* 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 2ed02c3..89c8a06 100644
@@ -1281,9 +1281,13 @@ enum punit_power_well {
 #define   GFX_PSMI_GRANULARITY		(1<<10)
 #define   GFX_PPGTT_ENABLE		(1<<9)
 
+#define VLV_VED_BASE 0x170000
+#define VLV_VED_SIZE 0x010000
 #define VLV_DISPLAY_BASE 0x180000
 #define VLV_MIPI_BASE VLV_DISPLAY_BASE
 
+#define VLV_VED_BLOCK_INTERRUPT			(1 << 23)
+
 #define VLV_GU_CTL0	(VLV_DISPLAY_BASE + 0x2030)
 #define VLV_GU_CTL1	(VLV_DISPLAY_BASE + 0x2034)
 #define SCPD0		0x0209c /* 915+ only */
drivers/gpu/drm/i915/i915_trace.h +15 -0
index f5aa006..522bd1d 100644
@@ -587,6 +587,21 @@ TRACE_EVENT(intel_gpu_freq_change,
 	    TP_printk("new_freq=%u", __entry->freq)
 );
 
+TRACE_EVENT(valleyview_ved_event,
+	    TP_PROTO(u32 iir),
+	    TP_ARGS(iir),
+
+	    TP_STRUCT__entry(
+			     __field(u32, iir)
+			     ),
+
+	    TP_fast_assign(
+			   __entry->iir = iir;
+			   ),
+
+	    TP_printk("forwarded with iir 0x%08x", __entry->iir)
+);
+
 #endif /* _I915_TRACE_H_ */
 
 /* This part must be outside protection */
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 1 line
Jani Nikula, Intel Open Source Technology Center
author
#3 lore raw

RE: [Intel-gfx] [RFC PATCH 1/3] drm/i915: add vxd392 bridge in i915

Nikula, thx for reminder, will update it.

-----Original Message-----
From: Jani Nikula [mailto:[email protected]]
Sent: Tuesday, October 14, 2014 9:27 PM
To: Cheng, Yao; [email protected]
Cc: Jiang, Fei; [email protected]; Vetter, Daniel
Subject: Re: [Intel-gfx] [RFC PATCH 1/3] drm/i915: add vxd392 bridge in i915

Quoted 110 lines · Yao Cheng

Setup following resources during i915_driver_load:
1. create a child platform and resource 2. allocate a new IRQ line and irq chip 3. set up IRQ mask/unmask callbacks
vxd392 driver (if installed) will bind itself to the platform device and create new drm device

---
 drivers/gpu/drm/i915/i915_dma.c   | 98 +++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_drv.h   |  6 +++
 drivers/gpu/drm/i915/i915_irq.c   | 70 ++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_reg.h   |  4 ++
 drivers/gpu/drm/i915/i915_trace.h | 15 ++++++
 5 files changed, 193 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_dma.c index 85d14e1..73c78d1 100644

drivers/gpu/drm/i915/i915_dma.c +87 -0
@@ -85,6 +85,96 @@ intel_read_legacy_status_page(struct 
 drm_i915_private *dev_priv, int reg)  #define READ_BREADCRUMB(dev_priv) READ_HWSP(dev_priv, I915_BREADCRUMB_INDEX)
 #define I915_BREADCRUMB_INDEX		0x21
 
+static int valleyview_ved_init(struct drm_device *dev) {
+	int ret;
+	int irq = -1;
+	struct resource *rsc = NULL;
+	struct drm_i915_private *dev_priv = dev->dev_private;;
+
+	dev_priv->ved_platdev = platform_device_alloc("ipvr-ved", -1);
+	if (unlikely(!dev_priv->ved_platdev)) {
+		DRM_ERROR("Failed to allocate VED platform device\n");
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	rsc = kzalloc(sizeof(*rsc) * 3, GFP_KERNEL);
+	if (unlikely(!rsc)) {
+		DRM_ERROR("Failed to allocate resource for VED platform device\n");
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	/* init IRQ number and chip/callbacks */
+	irq = irq_alloc_descs(-1, 0, 1, 0);
+	if (unlikely(irq < 0)) {
+		DRM_ERROR("Failed to allocate IRQ number: %d\n", irq);
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	ret = valleyview_initialize_ved_irq(dev, irq);
+	if (unlikely(ret)) {
+		DRM_ERROR("Failed to initialize VED IRQ: %d\n", ret);
+		goto err;
+	}
+
+	dev_priv->ved_irq = irq;
+	rsc[0].start    = rsc[0].end = irq;
+	rsc[0].flags    = IORESOURCE_IRQ;
+	rsc[0].name     = "ipvr-ved-irq";
+
+	/* MMIO/REG for child's use */
+	rsc[1].start    = pci_resource_start(dev->pdev, 0);
+	rsc[1].end      = pci_resource_start(dev->pdev, 0) + 2*1024*1024; /* gen7 */
+	rsc[1].flags    = IORESOURCE_MEM;
+	rsc[1].name     = "ipvr-ved-mmio";
+
+	rsc[2].start    = VLV_VED_BASE;
+	rsc[2].end      = VLV_VED_BASE + VLV_VED_SIZE;
+	rsc[2].flags    = IORESOURCE_REG;
+	rsc[2].name     = "ipvr-ved-reg";
+
+	ret = platform_device_add_resources(dev_priv->ved_platdev, rsc, 3);
+	if (unlikely(ret)) {
+		DRM_ERROR("Failed to add resource for VED platform device: %d\n", ret);
+		goto err;
+	}
+
+	/* Runtime-PM hook */
+	dev_priv->ved_platdev->dev.parent = dev->dev;
+	ret = platform_device_add(dev_priv->ved_platdev);
+	if (unlikely(ret)) {
+		DRM_ERROR("Failed to add VED platform device: %d\n", ret);
+		goto err;
+	}
+
+	kfree(rsc);
+	DRM_INFO("Successfully initialized Valleyview-VED\n");
+	return 0;
+err:
+	if (rsc)
+		kfree(rsc);
+	if (dev_priv->ved_platdev)
+		platform_device_unregister(dev_priv->ved_platdev);
+	if (irq >= 0)
+		irq_free_desc(irq);
+	return ret;
+}
+
+static void valleyview_ved_cleanup(struct drm_device *dev) {
+	int irq;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+
+	irq = platform_get_irq(dev_priv->ved_platdev, 0);
+	if (irq >= 0)
+		irq_free_desc(irq);
+
+	platform_device_unregister(dev_priv->ved_platdev);
+}

drivers/gpu/drm/i915/i915_dma.c intel_read_legacy_status_page(struct

Quoted 10 lines
drivers/gpu/drm/i915/i915_dma.c +4 -0
+
 void i915_update_dri1_breadcrumb(struct drm_device *dev)  {
 	struct drm_i915_private *dev_priv = dev->dev_private; @@ -1793,6 
+1883,10 @@ int i915_driver_load(struct drm_device *dev, unsigned long 
 flags)
 
 	intel_runtime_pm_enable(dev_priv);
 
+	if (IS_VALLEYVIEW(dev)) {
+		BUG_ON(valleyview_ved_init(dev));

Just a quick drive-by comment, please don't bring down the machine if this one fails.

Thanks,
Jani.

Quoted 176 lines
drivers/gpu/drm/i915/i915_dma.c +6 -0
+	}
+
 	return 0;
 
 out_power_well:
@@ -1833,6 +1927,10 @@ int i915_driver_unload(struct drm_device *dev)
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	int ret;
 
+	if (IS_VALLEYVIEW(dev)) {
+		valleyview_ved_cleanup(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 821ba26..aa8a183 100644

drivers/gpu/drm/i915/i915_drv.h +4 -0
@@ -1709,6 +1709,10 @@ struct drm_i915_private {
 
 	uint32_t bios_vgacntr;
 
+	/* used for setup sub device for valleyview */
+	struct platform_device *ved_platdev;
+	int	ved_irq;
+
 	/* Old dri1 support infrastructure, beware the dragons ya fools entering
 	 * here! */
 	struct i915_dri1_state dri1;
@@ -2921,6 +2925,8 @@ void vlv_flisdsi_write(struct drm_i915_private 
 *dev_priv, u32 reg, u32 val);  int vlv_gpu_freq(struct 

drm_i915_private *dev_priv, int val); int vlv_freq_opcode(struct drm_i915_private *dev_priv, int val);

drivers/gpu/drm/i915/i915_drv.h +3 -0
+extern int valleyview_initialize_ved_irq(struct drm_device *dev, int 
+irq);
+
 #define FORCEWAKE_RENDER	(1 << 0)
 #define FORCEWAKE_MEDIA		(1 << 1)
 #define FORCEWAKE_ALL		(FORCEWAKE_RENDER | FORCEWAKE_MEDIA)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_irq.c index 737b239..25c8cde 100644

drivers/gpu/drm/i915/i915_irq.c +66 -0
@@ -2142,12 +2142,75 @@ static void i9xx_hpd_irq_handler(struct drm_device *dev)
 	}
 }
 
+static void valleyview_enable_ved_irq(struct irq_data *d) {
+	struct drm_device *dev = d->chip_data;
+	struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
+	unsigned long irqflags;
+	u32 imr, ier;
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	ier = I915_READ(VLV_IER);
+	ier |= VLV_VED_BLOCK_INTERRUPT;
+	DRM_DEBUG_DRIVER("%s IER=>0x%08x\n", __func__, ier);
+	I915_WRITE(VLV_IER, ier);
+	POSTING_READ(VLV_IER);
+
+	imr = I915_READ(VLV_IMR);
+	imr &= ~VLV_VED_BLOCK_INTERRUPT;
+	dev_priv->irq_mask = imr;
+	DRM_DEBUG_DRIVER("%s IMR=>0x%08x\n", __func__, imr);
+	I915_WRITE(VLV_IMR, imr);
+	POSTING_READ(VLV_IMR);
+
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); }
+
+static void valleyview_disable_ved_irq(struct irq_data *d) {
+	struct drm_device *dev = d->chip_data;
+	struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
+	unsigned long irqflags;
+	u32 imr, ier;
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	ier = I915_READ(VLV_IER);
+	ier &= ~VLV_VED_BLOCK_INTERRUPT;
+	DRM_DEBUG_DRIVER("%s IER=>0x%08x\n", __func__, ier);
+	I915_WRITE(VLV_IER, ier);
+	POSTING_READ(VLV_IER);
+
+	imr = I915_READ(VLV_IMR);
+	imr |= VLV_VED_BLOCK_INTERRUPT;
+	dev_priv->irq_mask = imr;
+	DRM_DEBUG_DRIVER("%s IMR=>0x%08x\n", __func__, imr);
+	I915_WRITE(VLV_IMR, imr);
+	POSTING_READ(VLV_IMR);
+
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); }
+
+int valleyview_initialize_ved_irq(struct drm_device *dev, int irq) {
+	static struct irq_chip ved_irqchip = {
+		.name = "ipvr_ved_irqchip",
+		.irq_mask = valleyview_disable_ved_irq,
+		.irq_unmask = valleyview_enable_ved_irq,
+	};
+	irq_set_chip_and_handler_name(irq,
+		&ved_irqchip,
+		handle_simple_irq,
+		"ipvr_ved_irq_handler");
+	return irq_set_chip_data(irq, dev);
+}
+
 static irqreturn_t valleyview_irq_handler(int irq, void *arg)  {
 	struct drm_device *dev = arg;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	u32 iir, gt_iir, pm_iir;
 	irqreturn_t ret = IRQ_NONE;
+	int ved_ret;
 
 	while (true) {
 		/* Find, clear, then process each source of interrupt */ @@ -2177,6 
+2240,13 @@ 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 (IS_VALLEYVIEW(dev) && dev_priv->ved_irq >= 0
+				&& (iir & VLV_VED_BLOCK_INTERRUPT)) {
+			ved_ret = generic_handle_irq(dev_priv->ved_irq);
+			if (ved_ret)
+				DRM_ERROR("Error forwarding VED irq: %d\n", ved_ret);
+			trace_valleyview_ved_event(iir);
+		}
 		/* 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 2ed02c3..89c8a06 100644

drivers/gpu/drm/i915/i915_reg.h +4 -0
@@ -1281,9 +1281,13 @@ enum punit_power_well {
 #define   GFX_PSMI_GRANULARITY		(1<<10)
 #define   GFX_PPGTT_ENABLE		(1<<9)
 
+#define VLV_VED_BASE 0x170000
+#define VLV_VED_SIZE 0x010000
 #define VLV_DISPLAY_BASE 0x180000
 #define VLV_MIPI_BASE VLV_DISPLAY_BASE
 
+#define VLV_VED_BLOCK_INTERRUPT			(1 << 23)
+
 #define VLV_GU_CTL0	(VLV_DISPLAY_BASE + 0x2030)
 #define VLV_GU_CTL1	(VLV_DISPLAY_BASE + 0x2034)
 #define SCPD0		0x0209c /* 915+ only */
drivers/gpu/drm/i915/i915_trace.h +14 -1
index f5aa006..522bd1d 100644
@@ -587,6 +587,21 @@ TRACE_EVENT(intel_gpu_freq_change,
 	    TP_printk("new_freq=%u", __entry->freq)  );
 
+TRACE_EVENT(valleyview_ved_event,
+	    TP_PROTO(u32 iir),
+	    TP_ARGS(iir),
+
+	    TP_STRUCT__entry(
+			     __field(u32, iir)
+			     ),
+
+	    TP_fast_assign(
+			   __entry->iir = iir;
+			   ),
+
+	    TP_printk("forwarded with iir 0x%08x", __entry->iir) );
+
 #endif /* _I915_TRACE_H_ */
 
 /* This part must be outside protection */
--

1.9.1

Quoted 4 lines

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

--
Jani Nikula, Intel Open Source Technology Center

#4 lore raw

Re: [RFC PATCH 1/3] drm/i915: add vxd392 bridge in i915

In reply to Yao Cheng
Quoted 8 lines · Yao Cheng

Setup following resources during i915_driver_load:
1. create a child platform and resource
2. allocate a new IRQ line and irq chip
3. set up IRQ mask/unmask callbacks
vxd392 driver (if installed) will bind itself to the platform device and create new drm device

Ok, bunch of comments. First a high-level one: I think this qualifies as a new subsystem of i915, and so it would be good to extract this into a new file (i915_ved.c maybe), including adding kerneldoc for the setup function, a short DOC: overview section and pulling it all into the drm kerneldoc (probably a new subsection in the driver core section).

Aside from the lack of documentation just a few small comments below. Overall I really like how cleanly we can integrate vxd support into i915, so good work.

Cheers, Daniel

Quoted 14 lines
---
 drivers/gpu/drm/i915/i915_dma.c   | 98 +++++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_drv.h   |  6 +++
 drivers/gpu/drm/i915/i915_irq.c   | 70 ++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_reg.h   |  4 ++
 drivers/gpu/drm/i915/i915_trace.h | 15 ++++++
 5 files changed, 193 insertions(+)
drivers/gpu/drm/i915/i915_dma.c +0 -0
index 85d14e1..73c78d1 100644
@@ -85,6 +85,96 @@ intel_read_legacy_status_page(struct drm_i915_private *dev_priv, int reg)
 #define READ_BREADCRUMB(dev_priv) READ_HWSP(dev_priv, I915_BREADCRUMB_INDEX)

drivers/gpu/drm/i915/i915_dma.c intel_read_legacy_status_page(struct drm_i915_private *dev_priv, int reg) · line 95

Quoted 10 lines
drivers/gpu/drm/i915/i915_dma.c +8 -0
 #define I915_BREADCRUMB_INDEX		0x21
 
+static int valleyview_ved_init(struct drm_device *dev)
+{
+	int ret;
+	int irq = -1;
+	struct resource *rsc = NULL;
+	struct drm_i915_private *dev_priv = dev->dev_private;;
+
+	dev_priv->ved_platdev = platform_device_alloc("ipvr-ved", -1);

I think we should put vlv into the platform name, in case this driver will ever be reused on other platforms. So maybe "ipvr-ved-vxd"?

Quoted 70 lines
drivers/gpu/drm/i915/i915_dma.c +70 -0
+	if (unlikely(!dev_priv->ved_platdev)) {
+		DRM_ERROR("Failed to allocate VED platform device\n");
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	rsc = kzalloc(sizeof(*rsc) * 3, GFP_KERNEL);
+	if (unlikely(!rsc)) {
+		DRM_ERROR("Failed to allocate resource for VED platform device\n");
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	/* init IRQ number and chip/callbacks */
+	irq = irq_alloc_descs(-1, 0, 1, 0);
+	if (unlikely(irq < 0)) {
+		DRM_ERROR("Failed to allocate IRQ number: %d\n", irq);
+		ret = -ENOMEM;
+		goto err;
+	}
+
+	ret = valleyview_initialize_ved_irq(dev, irq);
+	if (unlikely(ret)) {
+		DRM_ERROR("Failed to initialize VED IRQ: %d\n", ret);
+		goto err;
+	}
+
+	dev_priv->ved_irq = irq;
+	rsc[0].start    = rsc[0].end = irq;
+	rsc[0].flags    = IORESOURCE_IRQ;
+	rsc[0].name     = "ipvr-ved-irq";
+
+	/* MMIO/REG for child's use */
+	rsc[1].start    = pci_resource_start(dev->pdev, 0);
+	rsc[1].end      = pci_resource_start(dev->pdev, 0) + 2*1024*1024; /* gen7 */
+	rsc[1].flags    = IORESOURCE_MEM;
+	rsc[1].name     = "ipvr-ved-mmio";
+
+	rsc[2].start    = VLV_VED_BASE;
+	rsc[2].end      = VLV_VED_BASE + VLV_VED_SIZE;
+	rsc[2].flags    = IORESOURCE_REG;
+	rsc[2].name     = "ipvr-ved-reg";
+
+	ret = platform_device_add_resources(dev_priv->ved_platdev, rsc, 3);
+	if (unlikely(ret)) {
+		DRM_ERROR("Failed to add resource for VED platform device: %d\n", ret);
+		goto err;
+	}
+
+	/* Runtime-PM hook */
+	dev_priv->ved_platdev->dev.parent = dev->dev;
+	ret = platform_device_add(dev_priv->ved_platdev);
+	if (unlikely(ret)) {
+		DRM_ERROR("Failed to add VED platform device: %d\n", ret);
+		goto err;
+	}
+
+	kfree(rsc);
+	DRM_INFO("Successfully initialized Valleyview-VED\n");
+	return 0;
+err:
+	if (rsc)
+		kfree(rsc);
+	if (dev_priv->ved_platdev)
+		platform_device_unregister(dev_priv->ved_platdev);
+	if (irq >= 0)
+		irq_free_desc(irq);
+	return ret;
+}
+

drivers/gpu/drm/i915/i915_dma.c intel_read_legacy_status_page(struct drm_i915_private *dev_priv, int reg) · line 175

Quoted 10 lines
drivers/gpu/drm/i915/i915_dma.c +10 -0
+static void valleyview_ved_cleanup(struct drm_device *dev)
+{
+	int irq;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+
+	irq = platform_get_irq(dev_priv->ved_platdev, 0);
+	if (irq >= 0)
+		irq_free_desc(irq);
+
+	platform_device_unregister(dev_priv->ved_platdev);

I think you should unregister the platform device _before_ you free the irq. Otherwise the driver cleanup might freak out. Aside: Does the module reload test for i915 in i-g-t still work with the vxd driver loaded on vlv? Iirc you need to manually unload the vxd driver first to avoid inherit races in the platform device support code, so if that's the case you need to supply a patch for igt, too.

drivers/gpu/drm/i915/i915_dma.c int i915_driver_load(struct drm_device *dev, unsigned long flags) · line 1888

Quoted 12 lines
drivers/gpu/drm/i915/i915_dma.c +5 -0
+}
+
 void i915_update_dri1_breadcrumb(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
@@ -1793,6 +1883,10 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
 
 	intel_runtime_pm_enable(dev_priv);
 
+	if (IS_VALLEYVIEW(dev)) {
+		BUG_ON(valleyview_ved_init(dev));
+	}

As Jani said, now BUG_ON here please. Also, I think you should just print an error here but not even fail driver load for i915 (i.e. still return 0). We try to only fail i915 load if there's a hard issue with the modeset part of the driver, if render/GT/... parts fail to init then we'll continue. The idea is that if the user at least has a working display he can grab a lot more useful information about the init failure than when i915 is completely dead.

Quoted 92 lines
drivers/gpu/drm/i915/i915_dma.c +5 -0
+
 	return 0;
 
 out_power_well:
@@ -1833,6 +1927,10 @@ int i915_driver_unload(struct drm_device *dev)
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	int ret;
 
+	if (IS_VALLEYVIEW(dev)) {
+		valleyview_ved_cleanup(dev);
+	}
+
 	ret = i915_gem_suspend(dev);
 	if (ret) {
 		DRM_ERROR("failed to idle hardware: %d\n", ret);
drivers/gpu/drm/i915/i915_drv.h +6 -0
index 821ba26..aa8a183 100644
@@ -1709,6 +1709,10 @@ struct drm_i915_private {
 
 	uint32_t bios_vgacntr;
 
+	/* used for setup sub device for valleyview */
+	struct platform_device *ved_platdev;
+	int	ved_irq;
+
 	/* Old dri1 support infrastructure, beware the dragons ya fools entering
 	 * here! */
 	struct i915_dri1_state dri1;
@@ -2921,6 +2925,8 @@ void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);
 int vlv_gpu_freq(struct drm_i915_private *dev_priv, int val);
 int vlv_freq_opcode(struct drm_i915_private *dev_priv, int val);
 
+extern int valleyview_initialize_ved_irq(struct drm_device *dev, int irq);
+
 #define FORCEWAKE_RENDER	(1 << 0)
 #define FORCEWAKE_MEDIA		(1 << 1)
 #define FORCEWAKE_ALL		(FORCEWAKE_RENDER | FORCEWAKE_MEDIA)
drivers/gpu/drm/i915/i915_irq.c +45 -0
index 737b239..25c8cde 100644
@@ -2142,12 +2142,75 @@ static void i9xx_hpd_irq_handler(struct drm_device *dev)
 	}
 }
 
+static void valleyview_enable_ved_irq(struct irq_data *d)
+{
+	struct drm_device *dev = d->chip_data;
+	struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
+	unsigned long irqflags;
+	u32 imr, ier;
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	ier = I915_READ(VLV_IER);
+	ier |= VLV_VED_BLOCK_INTERRUPT;
+	DRM_DEBUG_DRIVER("%s IER=>0x%08x\n", __func__, ier);
+	I915_WRITE(VLV_IER, ier);
+	POSTING_READ(VLV_IER);
+
+	imr = I915_READ(VLV_IMR);
+	imr &= ~VLV_VED_BLOCK_INTERRUPT;
+	dev_priv->irq_mask = imr;
+	DRM_DEBUG_DRIVER("%s IMR=>0x%08x\n", __func__, imr);
+	I915_WRITE(VLV_IMR, imr);
+	POSTING_READ(VLV_IMR);
+
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
+}
+
+static void valleyview_disable_ved_irq(struct irq_data *d)
+{
+	struct drm_device *dev = d->chip_data;
+	struct drm_i915_private *dev_priv = (struct drm_i915_private *) dev->dev_private;
+	unsigned long irqflags;
+	u32 imr, ier;
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	ier = I915_READ(VLV_IER);
+	ier &= ~VLV_VED_BLOCK_INTERRUPT;
+	DRM_DEBUG_DRIVER("%s IER=>0x%08x\n", __func__, ier);
+	I915_WRITE(VLV_IER, ier);
+	POSTING_READ(VLV_IER);
+
+	imr = I915_READ(VLV_IMR);
+	imr |= VLV_VED_BLOCK_INTERRUPT;
+	dev_priv->irq_mask = imr;
+	DRM_DEBUG_DRIVER("%s IMR=>0x%08x\n", __func__, imr);
+	I915_WRITE(VLV_IMR, imr);
+	POSTING_READ(VLV_IMR);
+

drivers/gpu/drm/i915/i915_irq.c static void i9xx_hpd_irq_handler(struct drm_device *dev) · line 2199

Quoted 10 lines
drivers/gpu/drm/i915/i915_irq.c +10 -0
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
+}
+
+int valleyview_initialize_ved_irq(struct drm_device *dev, int irq)
+{
+	static struct irq_chip ved_irqchip = {
+		.name = "ipvr_ved_irqchip",
+		.irq_mask = valleyview_disable_ved_irq,
+		.irq_unmask = valleyview_enable_ved_irq,
+	};

Please move this struct out of the function, we generally keep vtables global. Also please add a WARN_ON(!intel_irqs_enabled()) here so that we make sure that the driver load ordering is correct. Same for the unregister side, interrupts should still be working when we remove the platform device.

Quoted 18 lines
drivers/gpu/drm/i915/i915_irq.c +8 -0
+	irq_set_chip_and_handler_name(irq,
+		&ved_irqchip,
+		handle_simple_irq,
+		"ipvr_ved_irq_handler");
+	return irq_set_chip_data(irq, dev);
+}
+
 static irqreturn_t valleyview_irq_handler(int irq, void *arg)
 {
 	struct drm_device *dev = arg;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	u32 iir, gt_iir, pm_iir;
 	irqreturn_t ret = IRQ_NONE;
+	int ved_ret;
 
 	while (true) {
 		/* Find, clear, then process each source of interrupt */

drivers/gpu/drm/i915/i915_irq.c static irqreturn_t valleyview_irq_handler(int irq, void *arg) · line 2248

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +6 -0
@@ -2177,6 +2240,13 @@ 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 (IS_VALLEYVIEW(dev) && dev_priv->ved_irq >= 0
+				&& (iir & VLV_VED_BLOCK_INTERRUPT)) {
+			ved_ret = generic_handle_irq(dev_priv->ved_irq);
+			if (ved_ret)
+				DRM_ERROR("Error forwarding VED irq: %d\n", ved_ret);
+			trace_valleyview_ved_event(iir);

I don't see a value in this tracepoint here - we don't have any other tracepoints in i915 for irq events. If you want this and the irq core doesn't provide any tracpoints (haven't checked but would be really suprising), then I think the right place to add this is in the vxd driver itself.

Quoted 55 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
+		}
 		/* 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 2ed02c3..89c8a06 100644
@@ -1281,9 +1281,13 @@ enum punit_power_well {
 #define   GFX_PSMI_GRANULARITY		(1<<10)
 #define   GFX_PPGTT_ENABLE		(1<<9)
 
+#define VLV_VED_BASE 0x170000
+#define VLV_VED_SIZE 0x010000
 #define VLV_DISPLAY_BASE 0x180000
 #define VLV_MIPI_BASE VLV_DISPLAY_BASE
 
+#define VLV_VED_BLOCK_INTERRUPT			(1 << 23)
+
 #define VLV_GU_CTL0	(VLV_DISPLAY_BASE + 0x2030)
 #define VLV_GU_CTL1	(VLV_DISPLAY_BASE + 0x2034)
 #define SCPD0		0x0209c /* 915+ only */
drivers/gpu/drm/i915/i915_trace.h +15 -0
index f5aa006..522bd1d 100644
@@ -587,6 +587,21 @@ TRACE_EVENT(intel_gpu_freq_change,
 	    TP_printk("new_freq=%u", __entry->freq)
 );
 
+TRACE_EVENT(valleyview_ved_event,
+	    TP_PROTO(u32 iir),
+	    TP_ARGS(iir),
+
+	    TP_STRUCT__entry(
+			     __field(u32, iir)
+			     ),
+
+	    TP_fast_assign(
+			   __entry->iir = iir;
+			   ),
+
+	    TP_printk("forwarded with iir 0x%08x", __entry->iir)
+);
+
 #endif /* _I915_TRACE_H_ */
 
 /* This part must be outside protection */
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
author
#5 lore raw

Re: [RFC PATCH 1/3] drm/i915: add vxd392 bridge in i915

Quoted 9 lines

Ok, bunch of comments. First a high-level one: I think this qualifies as a new subsystem of i915, and so it would be good to extract this into a new file (i915_ved.c maybe), including adding kerneldoc for the setup function, a short DOC: overview section and pulling it all into the drm kerneldoc (probably a new subsection in the driver core section).

Aside from the lack of documentation just a few small comments below. Overall I really like how cleanly we can integrate vxd support into i915, so good work.

I915_ved.c sounds to be a good place for these code, thx for this suggestion!

For the kerneldoc, I'll add a subsection in the core section for your review.

Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/i915/i915_dma.c +9 -0
+
+static void valleyview_ved_cleanup(struct drm_device *dev) {
+	int irq;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+
+	irq = platform_get_irq(dev_priv->ved_platdev, 0);
+	if (irq >= 0)
+		irq_free_desc(irq);
+
Quoted 8 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	platform_device_unregister(dev_priv->ved_platdev);

I think you should unregister the platform device _before_ you free the irq. Otherwise the driver cleanup might freak out. Aside: Does the module reload test for i915 in i-g-t still work with the vxd driver loaded on vlv? Iirc you need to manually unload the vxd driver first to avoid inherit races in the platform device support code, so if that's the case you need to supply a patch for igt, too.

Sorry, what is i-g-t? I'll follow your suggestion, test i-g-t, and patch it if needed.

Quoted 10 lines
Quoted 10 lines
(quoted diff) +3 -0
+}
+
 void i915_update_dri1_breadcrumb(struct drm_device *dev)  {
 	struct drm_i915_private *dev_priv = dev->dev_private; @@ -1793,6
+1883,10 @@ int i915_driver_load(struct drm_device *dev, unsigned long

flags)

intel_runtime_pm_enable(dev_priv);

Quoted 11 lines

drivers/gpu/drm/i915/i915_dma.c int i915_driver_load(struct drm_device *dev, unsigned long flags) · line 1888

Quoted 3 lines
drivers/gpu/drm/i915/i915_dma.c +3 -0
+	if (IS_VALLEYVIEW(dev)) {
+		BUG_ON(valleyview_ved_init(dev));
+	}

As Jani said, now BUG_ON here please. Also, I think you should just print an error here but not even fail driver load for i915 (i.e. still return 0). We try to only fail i915 load if there's a hard issue with the modeset part of the driver, if render/GT/... parts fail to init then we'll continue. The idea is that if the user at least has a working display he can grab a lot more useful information about the init failure than when
i915 is completely dead.

Sorry for this BUG_ON. Will replace with useful return value and message.

Quoted 102 lines
Quoted 21 lines
drivers/gpu/drm/i915/i915_dma.c +5 -0
+
 	return 0;
 
 out_power_well:
@@ -1833,6 +1927,10 @@ int i915_driver_unload(struct drm_device *dev)
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	int ret;
 
+	if (IS_VALLEYVIEW(dev)) {
+		valleyview_ved_cleanup(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 821ba26..aa8a183 100644

drivers/gpu/drm/i915/i915_drv.h struct drm_i915_private { · line 1716

Quoted 8 lines
drivers/gpu/drm/i915/i915_drv.h +4 -0
@@ -1709,6 +1709,10 @@ struct drm_i915_private {
 
 	uint32_t bios_vgacntr;
 
+	/* used for setup sub device for valleyview */
+	struct platform_device *ved_platdev;
+	int	ved_irq;
+
 	/* Old dri1 support infrastructure, beware the dragons ya fools

entering

drivers/gpu/drm/i915/i915_drv.h void vlv_flisdsi_write(struct drm_i915_private *dev_priv, u32 reg, u32 val);

Quoted 13 lines
drivers/gpu/drm/i915/i915_drv.h +0 -0
 	 * here! */
 	struct i915_dri1_state dri1;
@@ -2921,6 +2925,8 @@ void vlv_flisdsi_write(struct drm_i915_private
 *dev_priv, u32 reg, u32 val);  int vlv_gpu_freq(struct

drm_i915_private *dev_priv, int val); int vlv_freq_opcode(struct drm_i915_private *dev_priv, int val);

drivers/gpu/drm/i915/i915_drv.h +3 -0
+extern int valleyview_initialize_ved_irq(struct drm_device *dev, int
+irq);
+
 #define FORCEWAKE_RENDER	(1 << 0)
 #define FORCEWAKE_MEDIA		(1 << 1)
 #define FORCEWAKE_ALL		(FORCEWAKE_RENDER |

FORCEWAKE_MEDIA)

drivers/gpu/drm/i915/i915_irq.c static void i9xx_hpd_irq_handler(struct

Quoted 5 lines
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_irq.c index 737b239..25c8cde 100644

drivers/gpu/drm/i915/i915_irq.c +0 -0
@@ -2142,12 +2142,75 @@ static void i9xx_hpd_irq_handler(struct

drm_device *dev)

drivers/gpu/drm/i915/i915_irq.c static void i9xx_hpd_irq_handler(struct drm_device *dev)

Quoted 6 lines
drivers/gpu/drm/i915/i915_irq.c +3 -0
 	}
 }
 
+static void valleyview_enable_ved_irq(struct irq_data *d) {
+	struct drm_device *dev = d->chip_data;
+	struct drm_i915_private *dev_priv = (struct drm_i915_private *)

dev->dev_private;

Quoted 12 lines
drivers/gpu/drm/i915/i915_irq.c +12 -0
+	unsigned long irqflags;
+	u32 imr, ier;
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	ier = I915_READ(VLV_IER);
+	ier |= VLV_VED_BLOCK_INTERRUPT;
+	DRM_DEBUG_DRIVER("%s IER=>0x%08x\n", __func__, ier);
+	I915_WRITE(VLV_IER, ier);
+	POSTING_READ(VLV_IER);
+
+	imr = I915_READ(VLV_IMR);
+	imr &= ~VLV_VED_BLOCK_INTERRUPT;

drivers/gpu/drm/i915/i915_irq.c static void i9xx_hpd_irq_handler(struct drm_device *dev)

Quoted 10 lines
drivers/gpu/drm/i915/i915_irq.c +10 -0
+	dev_priv->irq_mask = imr;
+	DRM_DEBUG_DRIVER("%s IMR=>0x%08x\n", __func__, imr);
+	I915_WRITE(VLV_IMR, imr);
+	POSTING_READ(VLV_IMR);
+
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); }
+
+static void valleyview_disable_ved_irq(struct irq_data *d) {
+	struct drm_device *dev = d->chip_data;
+	struct drm_i915_private *dev_priv = (struct drm_i915_private *)

dev->dev_private;

Quoted 22 lines
drivers/gpu/drm/i915/i915_irq.c +22 -0
+	unsigned long irqflags;
+	u32 imr, ier;
+	spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
+
+	ier = I915_READ(VLV_IER);
+	ier &= ~VLV_VED_BLOCK_INTERRUPT;
+	DRM_DEBUG_DRIVER("%s IER=>0x%08x\n", __func__, ier);
+	I915_WRITE(VLV_IER, ier);
+	POSTING_READ(VLV_IER);
+
+	imr = I915_READ(VLV_IMR);
+	imr |= VLV_VED_BLOCK_INTERRUPT;
+	dev_priv->irq_mask = imr;
+	DRM_DEBUG_DRIVER("%s IMR=>0x%08x\n", __func__, imr);
+	I915_WRITE(VLV_IMR, imr);
+	POSTING_READ(VLV_IMR);
+
+	spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); }
+
+int valleyview_initialize_ved_irq(struct drm_device *dev, int irq) {
+	static struct irq_chip ved_irqchip = {
+		.name = "ipvr_ved_irqchip",
Quoted 8 lines

drivers/gpu/drm/i915/i915_irq.c static void i9xx_hpd_irq_handler(struct drm_device *dev) · line 2199

Quoted 3 lines
drivers/gpu/drm/i915/i915_irq.c +3 -0
+		.irq_mask = valleyview_disable_ved_irq,
+		.irq_unmask = valleyview_enable_ved_irq,
+	};

Please move this struct out of the function, we generally keep vtables global. Also please add a WARN_ON(!intel_irqs_enabled()) here so that we make sure that the driver load ordering is correct. Same for the unregister side, interrupts should still be working when we remove the platform device.

Sure. Will move this to i915_ved.c as you suggested.

Quoted 28 lines
Quoted 7 lines
drivers/gpu/drm/i915/i915_irq.c +6 -0
+	irq_set_chip_and_handler_name(irq,
+		&ved_irqchip,
+		handle_simple_irq,
+		"ipvr_ved_irq_handler");
+	return irq_set_chip_data(irq, dev);
+}

drivers/gpu/drm/i915/i915_irq.c static void i9xx_hpd_irq_handler(struct drm_device *dev)

Quoted 10 lines
drivers/gpu/drm/i915/i915_irq.c +2 -0
+
 static irqreturn_t valleyview_irq_handler(int irq, void *arg)  {
 	struct drm_device *dev = arg;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	u32 iir, gt_iir, pm_iir;
 	irqreturn_t ret = IRQ_NONE;
+	int ved_ret;
 
 	while (true) {
 		/* Find, clear, then process each source of interrupt */ @@ -

2177,6

drivers/gpu/drm/i915/i915_irq.c static irqreturn_t valleyview_irq_handler(int irq, void *arg)

Quoted 9 lines
drivers/gpu/drm/i915/i915_irq.c +6 -0
+2240,13 @@ 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 (IS_VALLEYVIEW(dev) && dev_priv->ved_irq >= 0
+				&& (iir & VLV_VED_BLOCK_INTERRUPT)) {
+			ved_ret = generic_handle_irq(dev_priv->ved_irq);
+			if (ved_ret)
+				DRM_ERROR("Error forwarding VED

irq: %d\n", ved_ret);

Quoted 6 lines

drivers/gpu/drm/i915/i915_irq.c static irqreturn_t valleyview_irq_handler(int irq, void *arg) · line 2248

Quoted 1 line
drivers/gpu/drm/i915/i915_irq.c +1 -0
+			trace_valleyview_ved_event(iir);

I don't see a value in this tracepoint here - we don't have any other tracepoints in i915 for irq events. If you want this and the irq core doesn't provide any tracpoints (haven't checked but would be really suprising), then I think the right place to add this is in the vxd driver itself.

OK vxd driver has its own irq trace_points so will remove this one.

Quoted 60 lines
Quoted 51 lines
drivers/gpu/drm/i915/i915_irq.c +1 -0
+		}
 		/* 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 2ed02c3..89c8a06 100644

drivers/gpu/drm/i915/i915_reg.h +4 -0
@@ -1281,9 +1281,13 @@ enum punit_power_well {
 #define   GFX_PSMI_GRANULARITY		(1<<10)
 #define   GFX_PPGTT_ENABLE		(1<<9)
 
+#define VLV_VED_BASE 0x170000
+#define VLV_VED_SIZE 0x010000
 #define VLV_DISPLAY_BASE 0x180000
 #define VLV_MIPI_BASE VLV_DISPLAY_BASE
 
+#define VLV_VED_BLOCK_INTERRUPT			(1 << 23)
+
 #define VLV_GU_CTL0	(VLV_DISPLAY_BASE + 0x2030)
 #define VLV_GU_CTL1	(VLV_DISPLAY_BASE + 0x2034)
 #define SCPD0		0x0209c /* 915+ only */
drivers/gpu/drm/i915/i915_trace.h +14 -1
index f5aa006..522bd1d 100644
@@ -587,6 +587,21 @@ TRACE_EVENT(intel_gpu_freq_change,
 	    TP_printk("new_freq=%u", __entry->freq)  );
 
+TRACE_EVENT(valleyview_ved_event,
+	    TP_PROTO(u32 iir),
+	    TP_ARGS(iir),
+
+	    TP_STRUCT__entry(
+			     __field(u32, iir)
+			     ),
+
+	    TP_fast_assign(
+			   __entry->iir = iir;
+			   ),
+
+	    TP_printk("forwarded with iir 0x%08x", __entry->iir) );
+
 #endif /* _I915_TRACE_H_ */
 
 /* This part must be outside protection */
--

1.9.1

Quoted 4 lines

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

--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

#6 lore raw

Re: [RFC PATCH 1/3] drm/i915: add vxd392 bridge in i915

Quoted 6 lines · Yao
Quoted 6 lines

Ok, bunch of comments. First a high-level one: I think this qualifies as a new subsystem of i915, and so it would be good to extract this into a new file (i915_ved.c maybe), including adding kerneldoc for the setup function, a short DOC: overview section and pulling it all into the drm kerneldoc (probably a new subsection in the driver core section).

Quoted 7 lines
Quoted 3 lines

Aside from the lack of documentation just a few small comments below. Overall I really like how cleanly we can integrate vxd support into i915, so good work.

I915_ved.c sounds to be a good place for these code, thx for this suggestion!

For the kerneldoc, I'll add a subsection in the core section for your review.

Yeah, i915 driver core section sounds like the right place. Btw there's a small blog post from me with some tips for how to go about this:

http://blog.ffwll.ch/2014/06/documentation-for-drmi915.html

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/i915/i915_dma.c +9 -0
+
+static void valleyview_ved_cleanup(struct drm_device *dev) {
+	int irq;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+
+	irq = platform_get_irq(dev_priv->ved_platdev, 0);
+	if (irq >= 0)
+		irq_free_desc(irq);
+
Quoted 8 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	platform_device_unregister(dev_priv->ved_platdev);

I think you should unregister the platform device _before_ you free the irq. Otherwise the driver cleanup might freak out. Aside: Does the module reload test for i915 in i-g-t still work with the vxd driver loaded on vlv? Iirc you need to manually unload the vxd driver first to avoid inherit races in the platform device support code, so if that's the case you need to supply a patch for igt, too.

Quoted 1 line

Sorry, what is i-g-t? I'll follow your suggestion, test i-g-t, and patch it if needed.

i-g-t is the i915 kernel driver regression test suite. For a quick intro see:

http://blog.ffwll.ch/2013/08/recent-drmi915-testsuite-improvements.html

The igt repo is at

http://cgit.freedesktop.org/xorg/app/intel-gpu-tools/

The README file in there also has some good information.

Cheers, Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
author
#7 lore raw

RFC PATCH 2/3 drm/ipvr: drm driver for vxd392

In reply to Yao Cheng

Probes vxd392 on Baytrail platform and create
a new drm device for hardware accelerated video
decoding.

---
 drivers/gpu/drm/Kconfig            |    2 +
 drivers/gpu/drm/Makefile           |    1 +
 drivers/gpu/drm/ipvr/Kconfig       |   16 +
 drivers/gpu/drm/ipvr/Makefile      |   21 +
 drivers/gpu/drm/ipvr/ipvr_buffer.c | 1177 +++++++++++++++++++++++++++++++++
 drivers/gpu/drm/ipvr/ipvr_buffer.h |  184 ++++++
 drivers/gpu/drm/ipvr/ipvr_debug.c  |  263 ++++++++
 drivers/gpu/drm/ipvr/ipvr_debug.h  |   50 ++
 drivers/gpu/drm/ipvr/ipvr_drm.h    |  265 ++++++++
 drivers/gpu/drm/ipvr/ipvr_drv.c    |  776 ++++++++++++++++++++++
 drivers/gpu/drm/ipvr/ipvr_drv.h    |  464 +++++++++++++
 drivers/gpu/drm/ipvr/ipvr_exec.c   |  530 +++++++++++++++
 drivers/gpu/drm/ipvr/ipvr_exec.h   |   68 ++
 drivers/gpu/drm/ipvr/ipvr_fence.c  |  550 ++++++++++++++++
 drivers/gpu/drm/ipvr/ipvr_fence.h  |   68 ++
 drivers/gpu/drm/ipvr/ipvr_gem.c    |  248 +++++++
 drivers/gpu/drm/ipvr/ipvr_gem.h    |   66 ++
 drivers/gpu/drm/ipvr/ipvr_mmu.c    |  807 +++++++++++++++++++++++
 drivers/gpu/drm/ipvr/ipvr_mmu.h    |  135 ++++
 drivers/gpu/drm/ipvr/ipvr_trace.c  |   11 +
 drivers/gpu/drm/ipvr/ipvr_trace.h  |  296 +++++++++
 drivers/gpu/drm/ipvr/ved_cmd.c     | 1269 ++++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/ipvr/ved_cmd.h     |  104 +++
 drivers/gpu/drm/ipvr/ved_ec.c      |  584 +++++++++++++++++
 drivers/gpu/drm/ipvr/ved_ec.h      |  207 ++++++
 drivers/gpu/drm/ipvr/ved_fw.c      |  660 +++++++++++++++++++
 drivers/gpu/drm/ipvr/ved_fw.h      |   73 +++
 drivers/gpu/drm/ipvr/ved_init.c    |  829 +++++++++++++++++++++++
 drivers/gpu/drm/ipvr/ved_init.h    |   61 ++
 drivers/gpu/drm/ipvr/ved_msg.h     |  364 +++++++++++
 drivers/gpu/drm/ipvr/ved_pm.c      |  392 +++++++++++
 drivers/gpu/drm/ipvr/ved_pm.h      |   55 ++
 drivers/gpu/drm/ipvr/ved_reg.h     |  609 +++++++++++++++++
 33 files changed, 11205 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_buffer.c
 create mode 100644 drivers/gpu/drm/ipvr/ipvr_buffer.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_ec.c
 create mode 100644 drivers/gpu/drm/ipvr/ved_ec.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_init.c
 create mode 100644 drivers/gpu/drm/ipvr/ved_init.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
drivers/gpu/drm/Kconfig +2 -0
index e3b4b0f..ad7585d 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 9292a76..8ec4bda 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 +16 -0
new file mode 100644
index 0000000..6516590
@@ -0,0 +1,16 @@
+config DRM_IPVR
+       tristate "Baytrail VP8 video decode driver"
+       depends on DRM
+       depends on DRM_I915
+       select SHMEM
+       select TMPFS
+       default m
+       help
+         Choose this option if you want to enable hardware accelerated VP8 decoding on Baytrail platform
+
+config DRM_IPVR_EC
+       bool "[EXPERIMENTAL] error concealment for VP8"
+       depends on DRM_IPVR
+       default y
+       help
+         Choose this option if you want to enable hardware error concealment for IPVR VP8
drivers/gpu/drm/ipvr/Makefile new file +21 -0
new file mode 100644
index 0000000..e25a7d3
@@ -0,0 +1,21 @@
+
+ccflags-y := -Iinclude/drm
+
+ipvr-y := \
+        ipvr_gem.o \
+        ipvr_drv.o \
+        ipvr_buffer.o \
+        ipvr_exec.o \
+        ipvr_fence.o \
+        ipvr_mmu.o \
+        ipvr_debug.o \
+        ipvr_trace.o \
+        ved_pm.o \
+        ved_ec.o \
+        ved_cmd.o \
+        ved_fw.o \
+        ved_init.o
+
+obj-$(CONFIG_DRM_IPVR) += ipvr.o
+
+CFLAGS_ipvr_trace.o := -I$(src)
drivers/gpu/drm/ipvr/ipvr_buffer.c new file +1177 -0

1,177 lines not on this page · raw message

drivers/gpu/drm/ipvr/ipvr_buffer.h new file +184 -0

184 lines not on this page · raw message

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

263 lines not on this page · raw message

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

50 lines not on this page · raw message

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

265 lines not on this page · raw message

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

776 lines not on this page · raw message

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

233 lines not on this page · raw message

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

530 lines not on this page · raw message

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

68 lines not on this page · raw message

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

550 lines not on this page · raw message

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

68 lines not on this page · raw message

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

248 lines not on this page · raw message

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

66 lines not on this page · raw message

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

807 lines not on this page · raw message

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

135 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 +296 -0

296 lines not on this page · raw message

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

1,269 lines not on this page · raw message

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

104 lines not on this page · raw message

drivers/gpu/drm/ipvr/ved_ec.c new file +584 -0

584 lines not on this page · raw message

drivers/gpu/drm/ipvr/ved_ec.h new file +207 -0

207 lines not on this page · raw message

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

660 lines not on this page · raw message

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

73 lines not on this page · raw message

drivers/gpu/drm/ipvr/ved_init.c new file +829 -0

829 lines not on this page · raw message

drivers/gpu/drm/ipvr/ved_init.h new file +61 -0

61 lines not on this page · raw message

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

364 lines not on this page · raw message

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

392 lines not on this page · raw message

drivers/gpu/drm/ipvr/ved_pm.h new file +55 -0

55 lines not on this page · raw message

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

609 lines not on this page · raw message

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

Signature · 6 lines
1.9.1

_______________________________________________
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.

#8 lore raw

Re: [RFC PATCH 2/3] drm/ipvr: drm driver for vxd392

Hi

Quoted 5 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +5 -0
+static struct drm_ioctl_desc ipvr_gem_ioctls[] = {
+       DRM_IOCTL_DEF_DRV(IPVR_CONTEXT_CREATE,
+                       ipvr_context_create_ioctl, DRM_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_CONTEXT_DESTROY,
+                       ipvr_context_destroy_ioctl, DRM_UNLOCKED),

drivers/gpu/drm/ipvr/ipvr_drv.c line 259

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+       DRM_IOCTL_DEF_DRV(IPVR_MISC,
+                       ipvr_misc_ioctl, DRM_AUTH),
+       DRM_IOCTL_DEF_DRV(IPVR_GEM_EXECBUFFER,
+                       ipvr_gem_execbuffer, DRM_AUTH|DRM_UNLOCKED),
+       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_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_GEM_MMAP,
+                       ipvr_gem_mmap_ioctl, DRM_UNLOCKED),

Why do you need this ioctl? mmap() should work perfectly fine. I don't see why you require people to use a ipvr specific ioctl to map buffers.

Quoted 330 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +330 -0
+       DRM_IOCTL_DEF_DRV(IPVR_SYNC_CPU,
+                       ipvr_sync_cpu_ioctl, DRM_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_GEM_WAIT,
+                       ipvr_gem_wait_ioctl, DRM_AUTH|DRM_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_GEM_USERPTR,
+                       ipvr_gem_userptr_ioctl, DRM_UNLOCKED),
+};
+
+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(union drm_ipvr_gem_objects), 0,
+                                 SLAB_HWCACHE_ALIGN, NULL);
+
+       INIT_LIST_HEAD(&dev_priv->ipvr_mm.unbound_list);
+       INIT_LIST_HEAD(&dev_priv->ipvr_mm.bound_list);
+       spin_lock_init(&dev_priv->ipvr_mm.object_stat_lock);
+
+       dev_priv->ipvr_mm.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.
+        *
+        * However, leave one page at the end still bound to the scratch page.
+        * There are a number of places where hardware apparently prefetches
+        * past the end of the object, and we've seen multiple hangs with the
+        * GPU head pointer stuck in a batchbuffer bound at last page of the
+        * aperture.  One page should be enough to keep any prefetching inside
+        * of the aperture.
+        */
+       struct drm_ipvr_private *dev_priv = dev->dev_private;
+       struct ipvr_address_space *addr_space = &dev_priv->addr_space;
+
+       /* todo: add sanity check */
+       addr_space->dev = dev_priv->dev;
+       INIT_LIST_HEAD(&addr_space->active_list);
+       INIT_LIST_HEAD(&addr_space->inactive_list);
+
+       /* 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;
+}
+
+static void ipvr_do_takedown(struct drm_device *dev)
+{
+       /* todo: need check if need clean up mm here */
+       ipvr_ved_uninit(dev);
+}
+
+static int32_t ipvr_drm_unload(struct drm_device *dev)
+{
+       struct drm_ipvr_private *dev_priv = dev->dev_private;
+
+       BUG_ON(!dev->platformdev);
+       BUG_ON(atomic_read(&dev_priv->ved_power_usage));
+
+       IPVR_DEBUG_ENTRY("entered.");
+       if (dev_priv) {
+               WARN_ON(pm_runtime_get_sync(&dev->platformdev->dev) < 0);
+
+               if (dev_priv->ipvr_bo_slab)
+                       kmem_cache_destroy(dev_priv->ipvr_bo_slab);
+               ipvr_fence_driver_fini(dev_priv);
+
+               ipvr_do_takedown(dev);
+
+               WARN_ON(pm_runtime_put_sync_suspend(&dev->platformdev->dev) < 0);
+
+               if (dev_priv->validate_ctx.buffers)
+                       vfree(dev_priv->validate_ctx.buffers);
+
+               if (dev_priv->pf_pd) {
+                       ipvr_mmu_free_pagedir(dev_priv->pf_pd);
+                       dev_priv->pf_pd = NULL;
+               }
+               if (dev_priv->mmu) {
+                       ipvr_mmu_driver_takedown(dev_priv->mmu);
+                       dev_priv->mmu = NULL;
+               }
+
+               if (dev_priv->ved_reg_base) {
+                       iounmap(dev_priv->ved_reg_base - dev_priv->ved_reg_offset);
+                       dev_priv->ved_reg_base = NULL;
+                       dev_priv->ved_reg_offset = 0;
+               }
+
+               list_del(&dev_priv->default_ctx.head);
+               idr_remove(&dev_priv->ipvr_ctx_idr, dev_priv->default_ctx.ctx_id);
+               kfree(dev_priv);
+
+       }
+
+       pm_runtime_disable(&dev->platformdev->dev);
+
+       return 0;
+}
+
+static int32_t ipvr_drm_load(struct drm_device *dev, unsigned long flags)
+{
+       struct drm_ipvr_private *dev_priv;
+       int32_t ctx_id, ret = 0;
+       struct platform_device *platdev;
+       struct resource *res_mmio, *res_reg;
+       void __iomem* mmio_addr;
+
+       dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
+       if (dev_priv == NULL)
+               return -ENOMEM;
+
+       dev->dev_private = dev_priv;
+       dev_priv->dev = dev;
+
+       BUG_ON(!dev->platformdev);
+       platdev = dev->platformdev;
+
+       mutex_init(&dev_priv->cmdbuf_mutex);
+       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(platdev, 0);
+       if (dev->irq < 0) {
+               ret = -ENODEV;
+               goto out_err;
+       }
+
+       res_mmio = platform_get_resource(platdev, IORESOURCE_MEM, 0);
+       res_reg = platform_get_resource(platdev, IORESOURCE_REG, 0);
+       if (!res_mmio || !res_reg) {
+               ret = -ENXIO;
+               goto out_err;
+       }
+
+       mmio_addr = ioremap_wc(res_mmio->start,
+                                       res_mmio->end - res_mmio->start);
+       if (IS_ERR(mmio_addr)) {
+               ret = -EACCES;
+               goto out_err;
+       }
+
+       dev_priv->ved_reg_base = mmio_addr + res_reg->start;
+       dev_priv->ved_reg_offset = res_reg->start;
+       IPVR_DEBUG_VED("ved_reg_base is %p, range is 0x%llx - 0x%llx.\n",
+               dev_priv->ved_reg_base,
+               res_reg->start, res_reg->end);
+
+       platform_set_drvdata(dev->platformdev, dev);
+       pm_runtime_enable(&dev->platformdev->dev);
+
+       if (pm_runtime_get_sync(&dev->platformdev->dev) < 0) {
+               ret = -EBUSY;
+               goto out_err;
+       }
+
+       IPVR_DEBUG_INIT("MSVDX_CORE_REV_OFFSET by readl is 0x%x.\n",
+               readl(dev_priv->ved_reg_base + 0x640));
+       IPVR_DEBUG_INIT("MSVDX_CORE_REV_OFFSET by VED_REG_READ32 is 0x%x.\n",
+               VED_REG_READ32(MSVDX_CORE_REV_OFFSET));
+
+       /* mmu init */
+       dev_priv->mmu = ipvr_mmu_driver_init((void *)0,
+               drm_ipvr_trap_pagefaults,
+               0, dev_priv);
+       if (!dev_priv->mmu) {
+               ret = -EBUSY;
+               goto out_err;
+       }
+
+       dev_priv->pf_pd = ipvr_mmu_alloc_pd(dev_priv->mmu, 1, 0);
+       if (!dev_priv->pf_pd) {
+               ret = -ENOMEM;
+               goto out_err;
+       }
+
+       ipvr_mmu_set_pd_context(ipvr_mmu_get_default_pd(dev_priv->mmu), 0);
+       ipvr_mmu_set_pd_context(dev_priv->pf_pd, 1);
+
+       /*
+        * 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);
+
+       ipvr_ved_init(dev);
+
+       WARN_ON(pm_runtime_put_sync_suspend(&dev->platformdev->dev) < 0);
+
+       dev_priv->ved_private->ved_needs_reset = 1;
+       mutex_init(&dev_priv->ved_pm_mutex);
+       atomic_set(&dev_priv->ved_power_usage, 0);
+
+       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 */
+       INIT_LIST_HEAD(&dev_priv->ipvr_ctx_list);
+       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_KERNEL);
+       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 */
+       list_add(&dev_priv->default_ctx.head, &dev_priv->ipvr_ctx_list);
+       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 int32_t
+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 (unlikely(ipvr_fp == NULL))
+               return -ENOMEM;
+
+       file_priv->driver_priv = ipvr_fp;
+
+       return 0;
+}
+
+/*
+ * The close operation is split into .preclose() and .postclose() methods.
+ * Drivers must stop and cleanup all per-file operations in the .preclose()
+ * method. For instance pending vertical blanking and page flip events must be
+ * cancelled. No per-file operation is allowed on the file handle after
+ * returning from the .preclose() method.
+ */
+static void
+ipvr_drm_preclose(struct drm_device *dev, struct drm_file *file_priv)
+{
+       /* if user didn't destory ctx explicitly, remove ctx here */
+       struct drm_ipvr_private *dev_priv;
+       struct drm_ipvr_file_private *ipvr_fpriv;
+       struct ved_private *ved_priv;
+       struct ipvr_context *ipvr_ctx  = 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;
+
+       if (ipvr_fpriv->ctx_id == IPVR_CONTEXT_INVALID_ID)
+               return;
+       ipvr_ctx = (struct ipvr_context *)
+                       idr_find(&dev_priv->ipvr_ctx_idr, ipvr_fpriv->ctx_id);
+       if (!ipvr_ctx  || (ipvr_ctx->ipvr_fpriv != ipvr_fpriv)) {
+               IPVR_DEBUG_GENERAL("ctx for id %d has already destroyed\n",
+                               ipvr_fpriv->ctx_id);
+               return;
+       }
+       IPVR_DEBUG_PM("Video:remove context profile %d, entrypoint %d\n",
+               (ipvr_ctx->ctx_type >> 8) & 0xff,
+               (ipvr_ctx->ctx_type & 0xff));
+       mutex_lock(&ved_priv->ved_mutex);
+       if (ved_priv->ipvr_ctx == ipvr_ctx )
+               ved_priv->ipvr_ctx = NULL;
+       mutex_unlock(&ved_priv->ved_mutex);
+
+       spin_lock_irqsave(&dev_priv->ipvr_ctx_lock, irq_flags);
+       list_del(&ipvr_ctx->head);
+       ipvr_fpriv->ctx_id = IPVR_CONTEXT_INVALID_ID;
+       spin_unlock_irqrestore(&dev_priv->ipvr_ctx_lock, irq_flags);
+
+       idr_remove(&dev_priv->ipvr_ctx_idr, ipvr_ctx->ctx_id);
+
+       kfree(ipvr_ctx );
+}
+
+/*
+ * Finally the .postclose() method is called as the last step of the close
+ * operation, right before calling the .lastclose() method if no other open

drivers/gpu/drm/ipvr/ipvr_drv.c line 599

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+ * file handle exists for the device. Drivers that have allocated per-file
+ * private data in the .open() method should free it here.
+ */
+static void
+ipvr_drm_postclose(struct drm_device *dev, struct drm_file *file_priv)
+{
+       struct drm_ipvr_file_private *ipvr_fpriv = file_priv->driver_priv;
+       IPVR_DEBUG_ENTRY("enter\n");
+       kfree(ipvr_fpriv);
+}

postclose() is deprecated. You can safely move this into preclose().

Quoted 113 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +113 -0
+
+static irqreturn_t ipvr_irq_handler(int32_t irq, void *arg)
+{
+       struct drm_device *dev = (struct drm_device *) arg;
+       WARN_ON(ved_irq_handler(dev));
+       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
+       /* no need to define mmap. User space maps bo with DRM_IPVR_GEM_MMAP */
+};
+
+static int32_t ipvr_drm_freeze(struct drm_device *dev)
+{
+       int32_t ret;
+       int32_t power_usage;
+       struct drm_ipvr_private *dev_priv = dev->dev_private;
+
+       IPVR_DEBUG_ENTRY("enter\n");
+       power_usage = atomic_read(&dev_priv->ved_power_usage);
+       BUG_ON(power_usage < 0);
+       if (power_usage > 0) {
+               IPVR_DEBUG_PM("VED power usage is %d, skip freezing\n", power_usage);
+               return 0;
+       }
+
+       ret = ved_check_idle(dev);
+       if (ret) {
+               IPVR_DEBUG_PM("VED check idle fail: %d, skip freezing\n", ret);
+               return 0;
+       }
+
+       if (dev->irq_enabled) {
+               ret = drm_irq_uninstall(dev);
+               if (unlikely(ret)) {
+                       IPVR_ERROR("Error uninstalling IRQ handler: %d\n", ret);
+                       return -EFAULT;
+               }
+               IPVR_DEBUG_PM("Successfully uninstalled IRQ\n");
+       }
+       else
+               IPVR_DEBUG_PM("irq_enabled is %d\n", dev->irq_enabled);
+
+       if (is_ved_on(dev)) {
+               if (!ved_power_off(dev)) {
+                       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");
+       }
+
+       return 0;
+}
+
+static int32_t ipvr_drm_thaw(struct drm_device *dev)
+{
+       int ret;
+       IPVR_DEBUG_ENTRY("enter\n");
+       if (!is_ved_on(dev)) {
+               if (!ved_power_on(dev)) {
+                       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");
+       }
+
+       if (!dev->irq_enabled) {
+               ret = drm_irq_install(dev, dev->irq);
+               if (ret) {
+                       IPVR_ERROR("Error installing IRQ handler: %d\n", ret);
+                       return -EFAULT;
+               }
+               IPVR_DEBUG_PM("Successfully installed IRQ\n");
+       }
+       else
+               IPVR_DEBUG_PM("irq_enabled is %d\n", dev->irq_enabled);
+
+       return 0;
+}
+
+static int32_t 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");
+       BUG_ON(!drm_dev);
+       return ipvr_drm_freeze(drm_dev);
+}
+static int32_t 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");
+       BUG_ON(!drm_dev);
+       return ipvr_drm_thaw(drm_dev);
+}
+
+/*
+ * dump GEM API is mainly for dumb buffers suitable for scanout,
+ * it is not needed for ipvr driver.
+ * gem_vm_ops is used for mmap case, also not needed for ipvr
+ * todo: prime support can be enabled later

drivers/gpu/drm/ipvr/ipvr_drv.c line 722

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+ */
+static struct drm_driver ipvr_drm_driver = {
+       .driver_features = DRIVER_HAVE_IRQ | DRIVER_GEM,
+       .load = ipvr_drm_load,
+       .unload = ipvr_drm_unload,
+       .open = ipvr_drm_open,
+       .preclose = ipvr_drm_preclose,
+       .postclose = ipvr_drm_postclose,
+       .irq_handler = ipvr_irq_handler,
+       .set_busid = drm_platform_set_busid,

This should be NULL for new drivers.

Quoted 9 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +9 -0
+       .gem_free_object = ipvr_gem_free_object,
+#ifdef CONFIG_DEBUG_FS
+       .debugfs_init = ipvr_debugfs_init,
+       .debugfs_cleanup = ipvr_debugfs_cleanup,
+#endif
+       .ioctls = ipvr_gem_ioctls,
+       .num_ioctls = ARRAY_SIZE(ipvr_gem_ioctls),
+       .fops = &ipvr_fops,
+       .name = IPVR_DRIVER_NAME,

drivers/gpu/drm/ipvr/ipvr_drv.c line 741

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+       .desc = IPVR_DRIVER_DESC,
+       .date = IPVR_DRIVER_DATE,
+       .major = IPVR_DRIVER_MAJOR,
+       .minor = IPVR_DRIVER_MINOR,
+       .patchlevel = IPVR_DRIVER_PATCHLEVEL,
+};
+
+static int32_t ipvr_plat_probe(struct platform_device *device)
+{
+       return drm_platform_init(&ipvr_drm_driver, device);

drm_platform_init() should be used. Please use drm_dev_alloc(), drm_dev_register() directly. udl and tegra should serve as example.

drivers/gpu/drm/ipvr/ipvr_drv.c line 746

Quoted 5 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +5 -0
+}
+
+static int32_t ipvr_plat_remove(struct platform_device *device)
+{
+       drm_put_dev(platform_get_drvdata(device));

Again, please use drm_dev_unregister() + drm_dev_unref() directly.

Thanks
David

Quoted 30 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +30 -0
+       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_plat_driver = {
+       .driver = {
+               .name = "ipvr-ved",
+               .owner = THIS_MODULE,
+#ifdef CONFIG_PM
+               .pm = &ipvr_pm_ops,
+#endif
+       },
+       .probe = ipvr_plat_probe,
+       .remove = ipvr_plat_remove,
+};
+
+module_platform_driver(ipvr_plat_driver);
+MODULE_LICENSE("GPL");
author
#9 lore raw

Re: [RFC PATCH 2/3] drm/ipvr: drm driver for vxd392

Hi Herrmann

Quoted 26 lines

-----Original Message-----
From: David Herrmann [mailto:[email protected]]
Sent: Monday, October 13, 2014 10:27 PM
To: Cheng, Yao
Cc: Intel Graphics Development; Jiang, Fei; [email protected]; Vetter, Daniel
Subject: Re: [RFC PATCH 2/3] drm/ipvr: drm driver for vxd392

Hi

Quoted 5 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +5 -0
+static struct drm_ioctl_desc ipvr_gem_ioctls[] = {
+       DRM_IOCTL_DEF_DRV(IPVR_CONTEXT_CREATE,
+                       ipvr_context_create_ioctl, DRM_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_CONTEXT_DESTROY,
+                       ipvr_context_destroy_ioctl, DRM_UNLOCKED),

drivers/gpu/drm/ipvr/ipvr_drv.c line 259

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+       DRM_IOCTL_DEF_DRV(IPVR_MISC,
+                       ipvr_misc_ioctl, DRM_AUTH),
+       DRM_IOCTL_DEF_DRV(IPVR_GEM_EXECBUFFER,
+                       ipvr_gem_execbuffer, DRM_AUTH|DRM_UNLOCKED),
+       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_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_GEM_MMAP,
+                       ipvr_gem_mmap_ioctl, DRM_UNLOCKED),
Quoted 2 lines

Why do you need this ioctl? mmap() should work perfectly fine. I don't see why you require people to use a ipvr specific ioctl to map buffers.

Many thanks to your comments, in our existing libdrm helper and userspace drivers, mmap_ioctl was the interface of mapping objects. We continued using the ioctl way for compatibility. Is it mandatory to implement mmap() to replace mmap_ioctl for GEM drivers?

Quoted 348 lines
Quoted 20 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +19 -0
+       DRM_IOCTL_DEF_DRV(IPVR_SYNC_CPU,
+                       ipvr_sync_cpu_ioctl, DRM_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_GEM_WAIT,
+                       ipvr_gem_wait_ioctl, DRM_AUTH|DRM_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_GEM_USERPTR,
+                       ipvr_gem_userptr_ioctl, DRM_UNLOCKED), };
+
+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(union drm_ipvr_gem_objects), 0,
+                                 SLAB_HWCACHE_ALIGN, NULL);
+
+       INIT_LIST_HEAD(&dev_priv->ipvr_mm.unbound_list);
+       INIT_LIST_HEAD(&dev_priv->ipvr_mm.bound_list);
+       spin_lock_init(&dev_priv->ipvr_mm.object_stat_lock);
+
+       dev_priv->ipvr_mm.interruptible = true; }

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+
+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.
+        *
+        * However, leave one page at the end still bound to the scratch page.
+        * There are a number of places where hardware apparently

prefetches

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 3 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +3 -0
+        * past the end of the object, and we've seen multiple hangs with the
+        * GPU head pointer stuck in a batchbuffer bound at last page of the
+        * aperture.  One page should be enough to keep any prefetching

inside

Quoted 36 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +36 -0
+        * of the aperture.
+        */
+       struct drm_ipvr_private *dev_priv = dev->dev_private;
+       struct ipvr_address_space *addr_space = &dev_priv->addr_space;
+
+       /* todo: add sanity check */
+       addr_space->dev = dev_priv->dev;
+       INIT_LIST_HEAD(&addr_space->active_list);
+       INIT_LIST_HEAD(&addr_space->inactive_list);
+
+       /* 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;
+}
+
+static void ipvr_do_takedown(struct drm_device *dev) {
+       /* todo: need check if need clean up mm here */
+       ipvr_ved_uninit(dev);
+}
+
+static int32_t ipvr_drm_unload(struct drm_device *dev) {
+       struct drm_ipvr_private *dev_priv = dev->dev_private;
+
+       BUG_ON(!dev->platformdev);
+       BUG_ON(atomic_read(&dev_priv->ved_power_usage));
+
+       IPVR_DEBUG_ENTRY("entered.");
+       if (dev_priv) {
+               WARN_ON(pm_runtime_get_sync(&dev->platformdev->dev) <

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+ 0);
+
+               if (dev_priv->ipvr_bo_slab)
+                       kmem_cache_destroy(dev_priv->ipvr_bo_slab);
+               ipvr_fence_driver_fini(dev_priv);
+
+               ipvr_do_takedown(dev);
+
+
+ WARN_ON(pm_runtime_put_sync_suspend(&dev->platformdev->dev)

< 0);

Quoted 86 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +15 -0
+
+               if (dev_priv->validate_ctx.buffers)
+                       vfree(dev_priv->validate_ctx.buffers);
+
+               if (dev_priv->pf_pd) {
+                       ipvr_mmu_free_pagedir(dev_priv->pf_pd);
+                       dev_priv->pf_pd = NULL;
+               }
+               if (dev_priv->mmu) {
+                       ipvr_mmu_driver_takedown(dev_priv->mmu);
+                       dev_priv->mmu = NULL;
+               }
+
+               if (dev_priv->ved_reg_base) {
+                       iounmap(dev_priv->ved_reg_base - dev_priv-

ved_reg_offset);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +6 -0
+                       dev_priv->ved_reg_base = NULL;
+                       dev_priv->ved_reg_offset = 0;
+               }
+
+               list_del(&dev_priv->default_ctx.head);
+               idr_remove(&dev_priv->ipvr_ctx_idr, dev_priv-

default_ctx.ctx_id);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +63 -0
+               kfree(dev_priv);
+
+       }
+
+       pm_runtime_disable(&dev->platformdev->dev);
+
+       return 0;
+}
+
+static int32_t ipvr_drm_load(struct drm_device *dev, unsigned long
+flags) {
+       struct drm_ipvr_private *dev_priv;
+       int32_t ctx_id, ret = 0;
+       struct platform_device *platdev;
+       struct resource *res_mmio, *res_reg;
+       void __iomem* mmio_addr;
+
+       dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
+       if (dev_priv == NULL)
+               return -ENOMEM;
+
+       dev->dev_private = dev_priv;
+       dev_priv->dev = dev;
+
+       BUG_ON(!dev->platformdev);
+       platdev = dev->platformdev;
+
+       mutex_init(&dev_priv->cmdbuf_mutex);
+       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(platdev, 0);
+       if (dev->irq < 0) {
+               ret = -ENODEV;
+               goto out_err;
+       }
+
+       res_mmio = platform_get_resource(platdev, IORESOURCE_MEM, 0);
+       res_reg = platform_get_resource(platdev, IORESOURCE_REG, 0);
+       if (!res_mmio || !res_reg) {
+               ret = -ENXIO;
+               goto out_err;
+       }
+
+       mmio_addr = ioremap_wc(res_mmio->start,
+                                       res_mmio->end - res_mmio->start);
+       if (IS_ERR(mmio_addr)) {
+               ret = -EACCES;
+               goto out_err;
+       }
+
+       dev_priv->ved_reg_base = mmio_addr + res_reg->start;
+       dev_priv->ved_reg_offset = res_reg->start;
+       IPVR_DEBUG_VED("ved_reg_base is %p, range is 0x%llx - 0x%llx.\n",
+               dev_priv->ved_reg_base,
+               res_reg->start, res_reg->end);
+
+       platform_set_drvdata(dev->platformdev, dev);

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+       pm_runtime_enable(&dev->platformdev->dev);
+
+       if (pm_runtime_get_sync(&dev->platformdev->dev) < 0) {
+               ret = -EBUSY;
+               goto out_err;
+       }
+
+       IPVR_DEBUG_INIT("MSVDX_CORE_REV_OFFSET by readl is 0x%x.\n",
+               readl(dev_priv->ved_reg_base + 0x640));
+       IPVR_DEBUG_INIT("MSVDX_CORE_REV_OFFSET by

VED_REG_READ32 is 0x%x.\n",

Quoted 131 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +18 -0
+               VED_REG_READ32(MSVDX_CORE_REV_OFFSET));
+
+       /* mmu init */
+       dev_priv->mmu = ipvr_mmu_driver_init((void *)0,
+               drm_ipvr_trap_pagefaults,
+               0, dev_priv);
+       if (!dev_priv->mmu) {
+               ret = -EBUSY;
+               goto out_err;
+       }
+
+       dev_priv->pf_pd = ipvr_mmu_alloc_pd(dev_priv->mmu, 1, 0);
+       if (!dev_priv->pf_pd) {
+               ret = -ENOMEM;
+               goto out_err;
+       }
+
+       ipvr_mmu_set_pd_context(ipvr_mmu_get_default_pd(dev_priv-

mmu), 0);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +19 -0
+       ipvr_mmu_set_pd_context(dev_priv->pf_pd, 1);
+
+       /*
+        * 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);
+
+       ipvr_ved_init(dev);
+
+       WARN_ON(pm_runtime_put_sync_suspend(&dev->platformdev-

dev) <
+ 0);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +91 -0
+
+       dev_priv->ved_private->ved_needs_reset = 1;
+       mutex_init(&dev_priv->ved_pm_mutex);
+       atomic_set(&dev_priv->ved_power_usage, 0);
+
+       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 */
+       INIT_LIST_HEAD(&dev_priv->ipvr_ctx_list);
+       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_KERNEL);
+       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 */
+       list_add(&dev_priv->default_ctx.head, &dev_priv->ipvr_ctx_list);
+       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 int32_t
+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 (unlikely(ipvr_fp == NULL))
+               return -ENOMEM;
+
+       file_priv->driver_priv = ipvr_fp;
+
+       return 0;
+}
+
+/*
+ * The close operation is split into .preclose() and .postclose() methods.
+ * Drivers must stop and cleanup all per-file operations in the
+.preclose()
+ * method. For instance pending vertical blanking and page flip
+events must be
+ * cancelled. No per-file operation is allowed on the file handle
+after
+ * returning from the .preclose() method.
+ */
+static void
+ipvr_drm_preclose(struct drm_device *dev, struct drm_file *file_priv)
+{
+       /* if user didn't destory ctx explicitly, remove ctx here */
+       struct drm_ipvr_private *dev_priv;
+       struct drm_ipvr_file_private *ipvr_fpriv;
+       struct ved_private *ved_priv;
+       struct ipvr_context *ipvr_ctx  = 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;
+

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+       if (ipvr_fpriv->ctx_id == IPVR_CONTEXT_INVALID_ID)
+               return;
+       ipvr_ctx = (struct ipvr_context *)
+                       idr_find(&dev_priv->ipvr_ctx_idr, ipvr_fpriv->ctx_id);
+       if (!ipvr_ctx  || (ipvr_ctx->ipvr_fpriv != ipvr_fpriv)) {
+               IPVR_DEBUG_GENERAL("ctx for id %d has already destroyed\n",
+                               ipvr_fpriv->ctx_id);
+               return;
+       }
+       IPVR_DEBUG_PM("Video:remove context profile %d,

entrypoint %d\n",

Quoted 27 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +27 -0
+               (ipvr_ctx->ctx_type >> 8) & 0xff,
+               (ipvr_ctx->ctx_type & 0xff));
+       mutex_lock(&ved_priv->ved_mutex);
+       if (ved_priv->ipvr_ctx == ipvr_ctx )
+               ved_priv->ipvr_ctx = NULL;
+       mutex_unlock(&ved_priv->ved_mutex);
+
+       spin_lock_irqsave(&dev_priv->ipvr_ctx_lock, irq_flags);
+       list_del(&ipvr_ctx->head);
+       ipvr_fpriv->ctx_id = IPVR_CONTEXT_INVALID_ID;
+       spin_unlock_irqrestore(&dev_priv->ipvr_ctx_lock, irq_flags);
+
+       idr_remove(&dev_priv->ipvr_ctx_idr, ipvr_ctx->ctx_id);
+
+       kfree(ipvr_ctx );
+}
+
+/*
+ * Finally the .postclose() method is called as the last step of the
+close
+ * operation, right before calling the .lastclose() method if no
+other open
+ * file handle exists for the device. Drivers that have allocated
+per-file
+ * private data in the .open() method should free it here.
+ */
+static void
Quoted 8 lines

drivers/gpu/drm/ipvr/ipvr_drv.c line 599

Quoted 6 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +6 -0
+ipvr_drm_postclose(struct drm_device *dev, struct drm_file
+*file_priv) {
+       struct drm_ipvr_file_private *ipvr_fpriv = file_priv->driver_priv;
+       IPVR_DEBUG_ENTRY("enter\n");
+       kfree(ipvr_fpriv);
+}

postclose() is deprecated. You can safely move this into preclose().

Thx, will update it in next version.

Quoted 134 lines
Quoted 19 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +18 -0
+
+static irqreturn_t ipvr_irq_handler(int32_t irq, void *arg) {
+       struct drm_device *dev = (struct drm_device *) arg;
+       WARN_ON(ved_irq_handler(dev));
+       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
+       /* no need to define mmap. User space maps bo with
+DRM_IPVR_GEM_MMAP */ };
+

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+static int32_t ipvr_drm_freeze(struct drm_device *dev) {
+       int32_t ret;
+       int32_t power_usage;
+       struct drm_ipvr_private *dev_priv = dev->dev_private;
+
+       IPVR_DEBUG_ENTRY("enter\n");
+       power_usage = atomic_read(&dev_priv->ved_power_usage);
+       BUG_ON(power_usage < 0);
+       if (power_usage > 0) {
+               IPVR_DEBUG_PM("VED power usage is %d, skip freezing\n",

power_usage);

Quoted 19 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +19 -0
+               return 0;
+       }
+
+       ret = ved_check_idle(dev);
+       if (ret) {
+               IPVR_DEBUG_PM("VED check idle fail: %d, skip freezing\n", ret);
+               return 0;
+       }
+
+       if (dev->irq_enabled) {
+               ret = drm_irq_uninstall(dev);
+               if (unlikely(ret)) {
+                       IPVR_ERROR("Error uninstalling IRQ handler: %d\n", ret);
+                       return -EFAULT;
+               }
+               IPVR_DEBUG_PM("Successfully uninstalled IRQ\n");
+       }
+       else
+               IPVR_DEBUG_PM("irq_enabled is %d\n",

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+ dev->irq_enabled);
+
+       if (is_ved_on(dev)) {
+               if (!ved_power_off(dev)) {
+                       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");

Quoted 6 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +6 -0
+       }
+
+       return 0;
+}
+
+static int32_t ipvr_drm_thaw(struct drm_device *dev) {

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+       int ret;
+       IPVR_DEBUG_ENTRY("enter\n");
+       if (!is_ved_on(dev)) {
+               if (!ved_power_on(dev)) {
+                       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");

Quoted 34 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +34 -0
+       }
+
+       if (!dev->irq_enabled) {
+               ret = drm_irq_install(dev, dev->irq);
+               if (ret) {
+                       IPVR_ERROR("Error installing IRQ handler: %d\n", ret);
+                       return -EFAULT;
+               }
+               IPVR_DEBUG_PM("Successfully installed IRQ\n");
+       }
+       else
+               IPVR_DEBUG_PM("irq_enabled is %d\n",
+ dev->irq_enabled);
+
+       return 0;
+}
+
+static int32_t 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");
+       BUG_ON(!drm_dev);
+       return ipvr_drm_freeze(drm_dev); } static int32_t
+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");
+       BUG_ON(!drm_dev);
+       return ipvr_drm_thaw(drm_dev); }
+
+/*
+ * dump GEM API is mainly for dumb buffers suitable for scanout,
+ * it is not needed for ipvr driver.
+ * gem_vm_ops is used for mmap case, also not needed for ipvr

drivers/gpu/drm/ipvr/ipvr_drv.c line 722

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+ * todo: prime support can be enabled later  */ static struct
+drm_driver ipvr_drm_driver = {
+       .driver_features = DRIVER_HAVE_IRQ | DRIVER_GEM,
+       .load = ipvr_drm_load,
+       .unload = ipvr_drm_unload,
+       .open = ipvr_drm_open,
+       .preclose = ipvr_drm_preclose,
+       .postclose = ipvr_drm_postclose,
+       .irq_handler = ipvr_irq_handler,
+       .set_busid = drm_platform_set_busid,

This should be NULL for new drivers.

Quoted 11 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +11 -0
+       .gem_free_object = ipvr_gem_free_object, #ifdef
+CONFIG_DEBUG_FS
+       .debugfs_init = ipvr_debugfs_init,
+       .debugfs_cleanup = ipvr_debugfs_cleanup, #endif
+       .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,
Quoted 9 lines

drivers/gpu/drm/ipvr/ipvr_drv.c line 741

Quoted 5 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +5 -0
+       .minor = IPVR_DRIVER_MINOR,
+       .patchlevel = IPVR_DRIVER_PATCHLEVEL, };
+
+static int32_t ipvr_plat_probe(struct platform_device *device) {
+       return drm_platform_init(&ipvr_drm_driver, device);

drm_platform_init() should be used. Please use drm_dev_alloc(), drm_dev_register() directly. udl and tegra should serve as example.

Thx, will update it in next version.

Quoted 6 lines

drivers/gpu/drm/ipvr/ipvr_drv.c line 746

Quoted 4 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +4 -0
+}
+
+static int32_t ipvr_plat_remove(struct platform_device *device) {
+       drm_put_dev(platform_get_drvdata(device));

Again, please use drm_dev_unregister() + drm_dev_unref() directly.

Thx, will update it in next version.

Quoted 32 lines

Thanks
David

Quoted 28 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +28 -0
+       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_plat_driver = {
+       .driver = {
+               .name = "ipvr-ved",
+               .owner = THIS_MODULE,
+#ifdef CONFIG_PM
+               .pm = &ipvr_pm_ops,
+#endif
+       },
+       .probe = ipvr_plat_probe,
+       .remove = ipvr_plat_remove,
+};
+
+module_platform_driver(ipvr_plat_driver);
+MODULE_LICENSE("GPL");
#10 lore raw

Re: [RFC PATCH 2/3] drm/ipvr: drm driver for vxd392

Hi

Quoted 28 lines · Yao

Hi Herrmann

Quoted 26 lines

-----Original Message-----
From: David Herrmann [mailto:[email protected]]
Sent: Monday, October 13, 2014 10:27 PM
To: Cheng, Yao
Cc: Intel Graphics Development; Jiang, Fei; [email protected]; Vetter, Daniel
Subject: Re: [RFC PATCH 2/3] drm/ipvr: drm driver for vxd392

Hi

Quoted 15 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +15 -0
+static struct drm_ioctl_desc ipvr_gem_ioctls[] = {
+       DRM_IOCTL_DEF_DRV(IPVR_CONTEXT_CREATE,
+                       ipvr_context_create_ioctl, DRM_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_CONTEXT_DESTROY,
+                       ipvr_context_destroy_ioctl, DRM_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_MISC,
+                       ipvr_misc_ioctl, DRM_AUTH),
+       DRM_IOCTL_DEF_DRV(IPVR_GEM_EXECBUFFER,
+                       ipvr_gem_execbuffer, DRM_AUTH|DRM_UNLOCKED),
+       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_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_GEM_MMAP,
+                       ipvr_gem_mmap_ioctl, DRM_UNLOCKED),
Quoted 4 lines
Quoted 2 lines

Why do you need this ioctl? mmap() should work perfectly fine. I don't see why you require people to use a ipvr specific ioctl to map buffers.

Many thanks to your comments, in our existing libdrm helper and userspace drivers, mmap_ioctl was the interface of mapping objects. We continued using the ioctl way for compatibility. Is it mandatory to implement mmap() to replace mmap_ioctl for GEM drivers?

Usually we don't care for existing user-space. We want APIs to be cleanly designed when they go upstream. But I'm not the authority to decide that. All I do is recommend hooking it up with mmap() like everyone else does. If that's not what you want, you have to convince Dave (and probably Daniel). The least you can do is hook up mmap() and make it work. Whether there is a legacy ioctl to do the same, I don't care..

Thanks
David

#11 lore raw

Re: [RFC PATCH 2/3] drm/ipvr: drm driver for vxd392

In reply to Cheng, Yao
Quoted 28 lines · Yao

Hi Herrmann

Quoted 26 lines

-----Original Message-----
From: David Herrmann [mailto:[email protected]]
Sent: Monday, October 13, 2014 10:27 PM
To: Cheng, Yao
Cc: Intel Graphics Development; Jiang, Fei; [email protected]; Vetter, Daniel
Subject: Re: [RFC PATCH 2/3] drm/ipvr: drm driver for vxd392

Hi

Quoted 15 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +15 -0
+static struct drm_ioctl_desc ipvr_gem_ioctls[] = {
+       DRM_IOCTL_DEF_DRV(IPVR_CONTEXT_CREATE,
+                       ipvr_context_create_ioctl, DRM_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_CONTEXT_DESTROY,
+                       ipvr_context_destroy_ioctl, DRM_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_MISC,
+                       ipvr_misc_ioctl, DRM_AUTH),
+       DRM_IOCTL_DEF_DRV(IPVR_GEM_EXECBUFFER,
+                       ipvr_gem_execbuffer, DRM_AUTH|DRM_UNLOCKED),
+       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_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_GEM_MMAP,
+                       ipvr_gem_mmap_ioctl, DRM_UNLOCKED),
Quoted 7 lines
Quoted 2 lines

Why do you need this ioctl? mmap() should work perfectly fine. I don't see why you require people to use a ipvr specific ioctl to map buffers.

Many thanks to your comments, in our existing libdrm helper and userspace drivers, mmap_ioctl was the interface of mapping objects. We continued using the ioctl way for compatibility. Is it mandatory to implement mmap() to replace mmap_ioctl for GEM drivers?

Yeah, the new way is to have a ioctl in the drm driver to create an mmap offset (look at the gtt_mmap_offset ioctl for i915), and the use mmap on the drm fd. Doing a direct driver ioctl to forward the mmap is deprecated.

The reason for that is that a) this is the new standard way used by all drm drivers b) if you use the standard mmap system call debug tools like valgrind will understand it without any special actions.

I'll do a patch to i915 so that people stop copy-pasting that old misdesign.
-Daniel

Quoted 551 lines
Quoted 349 lines
Quoted 21 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +19 -0
+       DRM_IOCTL_DEF_DRV(IPVR_SYNC_CPU,
+                       ipvr_sync_cpu_ioctl, DRM_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_GEM_WAIT,
+                       ipvr_gem_wait_ioctl, DRM_AUTH|DRM_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_GEM_USERPTR,
+                       ipvr_gem_userptr_ioctl, DRM_UNLOCKED), };
+
+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(union drm_ipvr_gem_objects), 0,
+                                 SLAB_HWCACHE_ALIGN, NULL);
+
+       INIT_LIST_HEAD(&dev_priv->ipvr_mm.unbound_list);
+       INIT_LIST_HEAD(&dev_priv->ipvr_mm.bound_list);
+       spin_lock_init(&dev_priv->ipvr_mm.object_stat_lock);
+
+       dev_priv->ipvr_mm.interruptible = true; }

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+
+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.
+        *
+        * However, leave one page at the end still bound to the scratch page.
+        * There are a number of places where hardware apparently

prefetches

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 3 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +3 -0
+        * past the end of the object, and we've seen multiple hangs with the
+        * GPU head pointer stuck in a batchbuffer bound at last page of the
+        * aperture.  One page should be enough to keep any prefetching

inside

Quoted 36 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +36 -0
+        * of the aperture.
+        */
+       struct drm_ipvr_private *dev_priv = dev->dev_private;
+       struct ipvr_address_space *addr_space = &dev_priv->addr_space;
+
+       /* todo: add sanity check */
+       addr_space->dev = dev_priv->dev;
+       INIT_LIST_HEAD(&addr_space->active_list);
+       INIT_LIST_HEAD(&addr_space->inactive_list);
+
+       /* 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;
+}
+
+static void ipvr_do_takedown(struct drm_device *dev) {
+       /* todo: need check if need clean up mm here */
+       ipvr_ved_uninit(dev);
+}
+
+static int32_t ipvr_drm_unload(struct drm_device *dev) {
+       struct drm_ipvr_private *dev_priv = dev->dev_private;
+
+       BUG_ON(!dev->platformdev);
+       BUG_ON(atomic_read(&dev_priv->ved_power_usage));
+
+       IPVR_DEBUG_ENTRY("entered.");
+       if (dev_priv) {
+               WARN_ON(pm_runtime_get_sync(&dev->platformdev->dev) <

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+ 0);
+
+               if (dev_priv->ipvr_bo_slab)
+                       kmem_cache_destroy(dev_priv->ipvr_bo_slab);
+               ipvr_fence_driver_fini(dev_priv);
+
+               ipvr_do_takedown(dev);
+
+
+ WARN_ON(pm_runtime_put_sync_suspend(&dev->platformdev->dev)

< 0);

Quoted 86 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +15 -0
+
+               if (dev_priv->validate_ctx.buffers)
+                       vfree(dev_priv->validate_ctx.buffers);
+
+               if (dev_priv->pf_pd) {
+                       ipvr_mmu_free_pagedir(dev_priv->pf_pd);
+                       dev_priv->pf_pd = NULL;
+               }
+               if (dev_priv->mmu) {
+                       ipvr_mmu_driver_takedown(dev_priv->mmu);
+                       dev_priv->mmu = NULL;
+               }
+
+               if (dev_priv->ved_reg_base) {
+                       iounmap(dev_priv->ved_reg_base - dev_priv-

ved_reg_offset);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +6 -0
+                       dev_priv->ved_reg_base = NULL;
+                       dev_priv->ved_reg_offset = 0;
+               }
+
+               list_del(&dev_priv->default_ctx.head);
+               idr_remove(&dev_priv->ipvr_ctx_idr, dev_priv-

default_ctx.ctx_id);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +63 -0
+               kfree(dev_priv);
+
+       }
+
+       pm_runtime_disable(&dev->platformdev->dev);
+
+       return 0;
+}
+
+static int32_t ipvr_drm_load(struct drm_device *dev, unsigned long
+flags) {
+       struct drm_ipvr_private *dev_priv;
+       int32_t ctx_id, ret = 0;
+       struct platform_device *platdev;
+       struct resource *res_mmio, *res_reg;
+       void __iomem* mmio_addr;
+
+       dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
+       if (dev_priv == NULL)
+               return -ENOMEM;
+
+       dev->dev_private = dev_priv;
+       dev_priv->dev = dev;
+
+       BUG_ON(!dev->platformdev);
+       platdev = dev->platformdev;
+
+       mutex_init(&dev_priv->cmdbuf_mutex);
+       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(platdev, 0);
+       if (dev->irq < 0) {
+               ret = -ENODEV;
+               goto out_err;
+       }
+
+       res_mmio = platform_get_resource(platdev, IORESOURCE_MEM, 0);
+       res_reg = platform_get_resource(platdev, IORESOURCE_REG, 0);
+       if (!res_mmio || !res_reg) {
+               ret = -ENXIO;
+               goto out_err;
+       }
+
+       mmio_addr = ioremap_wc(res_mmio->start,
+                                       res_mmio->end - res_mmio->start);
+       if (IS_ERR(mmio_addr)) {
+               ret = -EACCES;
+               goto out_err;
+       }
+
+       dev_priv->ved_reg_base = mmio_addr + res_reg->start;
+       dev_priv->ved_reg_offset = res_reg->start;
+       IPVR_DEBUG_VED("ved_reg_base is %p, range is 0x%llx - 0x%llx.\n",
+               dev_priv->ved_reg_base,
+               res_reg->start, res_reg->end);
+
+       platform_set_drvdata(dev->platformdev, dev);

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+       pm_runtime_enable(&dev->platformdev->dev);
+
+       if (pm_runtime_get_sync(&dev->platformdev->dev) < 0) {
+               ret = -EBUSY;
+               goto out_err;
+       }
+
+       IPVR_DEBUG_INIT("MSVDX_CORE_REV_OFFSET by readl is 0x%x.\n",
+               readl(dev_priv->ved_reg_base + 0x640));
+       IPVR_DEBUG_INIT("MSVDX_CORE_REV_OFFSET by

VED_REG_READ32 is 0x%x.\n",

Quoted 131 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +18 -0
+               VED_REG_READ32(MSVDX_CORE_REV_OFFSET));
+
+       /* mmu init */
+       dev_priv->mmu = ipvr_mmu_driver_init((void *)0,
+               drm_ipvr_trap_pagefaults,
+               0, dev_priv);
+       if (!dev_priv->mmu) {
+               ret = -EBUSY;
+               goto out_err;
+       }
+
+       dev_priv->pf_pd = ipvr_mmu_alloc_pd(dev_priv->mmu, 1, 0);
+       if (!dev_priv->pf_pd) {
+               ret = -ENOMEM;
+               goto out_err;
+       }
+
+       ipvr_mmu_set_pd_context(ipvr_mmu_get_default_pd(dev_priv-

mmu), 0);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +19 -0
+       ipvr_mmu_set_pd_context(dev_priv->pf_pd, 1);
+
+       /*
+        * 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);
+
+       ipvr_ved_init(dev);
+
+       WARN_ON(pm_runtime_put_sync_suspend(&dev->platformdev-

dev) <
+ 0);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +91 -0
+
+       dev_priv->ved_private->ved_needs_reset = 1;
+       mutex_init(&dev_priv->ved_pm_mutex);
+       atomic_set(&dev_priv->ved_power_usage, 0);
+
+       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 */
+       INIT_LIST_HEAD(&dev_priv->ipvr_ctx_list);
+       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_KERNEL);
+       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 */
+       list_add(&dev_priv->default_ctx.head, &dev_priv->ipvr_ctx_list);
+       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 int32_t
+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 (unlikely(ipvr_fp == NULL))
+               return -ENOMEM;
+
+       file_priv->driver_priv = ipvr_fp;
+
+       return 0;
+}
+
+/*
+ * The close operation is split into .preclose() and .postclose() methods.
+ * Drivers must stop and cleanup all per-file operations in the
+.preclose()
+ * method. For instance pending vertical blanking and page flip
+events must be
+ * cancelled. No per-file operation is allowed on the file handle
+after
+ * returning from the .preclose() method.
+ */
+static void
+ipvr_drm_preclose(struct drm_device *dev, struct drm_file *file_priv)
+{
+       /* if user didn't destory ctx explicitly, remove ctx here */
+       struct drm_ipvr_private *dev_priv;
+       struct drm_ipvr_file_private *ipvr_fpriv;
+       struct ved_private *ved_priv;
+       struct ipvr_context *ipvr_ctx  = 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;
+

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+       if (ipvr_fpriv->ctx_id == IPVR_CONTEXT_INVALID_ID)
+               return;
+       ipvr_ctx = (struct ipvr_context *)
+                       idr_find(&dev_priv->ipvr_ctx_idr, ipvr_fpriv->ctx_id);
+       if (!ipvr_ctx  || (ipvr_ctx->ipvr_fpriv != ipvr_fpriv)) {
+               IPVR_DEBUG_GENERAL("ctx for id %d has already destroyed\n",
+                               ipvr_fpriv->ctx_id);
+               return;
+       }
+       IPVR_DEBUG_PM("Video:remove context profile %d,

entrypoint %d\n",

Quoted 27 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +27 -0
+               (ipvr_ctx->ctx_type >> 8) & 0xff,
+               (ipvr_ctx->ctx_type & 0xff));
+       mutex_lock(&ved_priv->ved_mutex);
+       if (ved_priv->ipvr_ctx == ipvr_ctx )
+               ved_priv->ipvr_ctx = NULL;
+       mutex_unlock(&ved_priv->ved_mutex);
+
+       spin_lock_irqsave(&dev_priv->ipvr_ctx_lock, irq_flags);
+       list_del(&ipvr_ctx->head);
+       ipvr_fpriv->ctx_id = IPVR_CONTEXT_INVALID_ID;
+       spin_unlock_irqrestore(&dev_priv->ipvr_ctx_lock, irq_flags);
+
+       idr_remove(&dev_priv->ipvr_ctx_idr, ipvr_ctx->ctx_id);
+
+       kfree(ipvr_ctx );
+}
+
+/*
+ * Finally the .postclose() method is called as the last step of the
+close
+ * operation, right before calling the .lastclose() method if no
+other open
+ * file handle exists for the device. Drivers that have allocated
+per-file
+ * private data in the .open() method should free it here.
+ */
+static void
Quoted 8 lines

drivers/gpu/drm/ipvr/ipvr_drv.c line 599

Quoted 6 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +6 -0
+ipvr_drm_postclose(struct drm_device *dev, struct drm_file
+*file_priv) {
+       struct drm_ipvr_file_private *ipvr_fpriv = file_priv->driver_priv;
+       IPVR_DEBUG_ENTRY("enter\n");
+       kfree(ipvr_fpriv);
+}

postclose() is deprecated. You can safely move this into preclose().

Thx, will update it in next version.

Quoted 134 lines
Quoted 19 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +18 -0
+
+static irqreturn_t ipvr_irq_handler(int32_t irq, void *arg) {
+       struct drm_device *dev = (struct drm_device *) arg;
+       WARN_ON(ved_irq_handler(dev));
+       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
+       /* no need to define mmap. User space maps bo with
+DRM_IPVR_GEM_MMAP */ };
+

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+static int32_t ipvr_drm_freeze(struct drm_device *dev) {
+       int32_t ret;
+       int32_t power_usage;
+       struct drm_ipvr_private *dev_priv = dev->dev_private;
+
+       IPVR_DEBUG_ENTRY("enter\n");
+       power_usage = atomic_read(&dev_priv->ved_power_usage);
+       BUG_ON(power_usage < 0);
+       if (power_usage > 0) {
+               IPVR_DEBUG_PM("VED power usage is %d, skip freezing\n",

power_usage);

Quoted 19 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +19 -0
+               return 0;
+       }
+
+       ret = ved_check_idle(dev);
+       if (ret) {
+               IPVR_DEBUG_PM("VED check idle fail: %d, skip freezing\n", ret);
+               return 0;
+       }
+
+       if (dev->irq_enabled) {
+               ret = drm_irq_uninstall(dev);
+               if (unlikely(ret)) {
+                       IPVR_ERROR("Error uninstalling IRQ handler: %d\n", ret);
+                       return -EFAULT;
+               }
+               IPVR_DEBUG_PM("Successfully uninstalled IRQ\n");
+       }
+       else
+               IPVR_DEBUG_PM("irq_enabled is %d\n",

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+ dev->irq_enabled);
+
+       if (is_ved_on(dev)) {
+               if (!ved_power_off(dev)) {
+                       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");

Quoted 6 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +6 -0
+       }
+
+       return 0;
+}
+
+static int32_t ipvr_drm_thaw(struct drm_device *dev) {

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+       int ret;
+       IPVR_DEBUG_ENTRY("enter\n");
+       if (!is_ved_on(dev)) {
+               if (!ved_power_on(dev)) {
+                       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");

Quoted 34 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +34 -0
+       }
+
+       if (!dev->irq_enabled) {
+               ret = drm_irq_install(dev, dev->irq);
+               if (ret) {
+                       IPVR_ERROR("Error installing IRQ handler: %d\n", ret);
+                       return -EFAULT;
+               }
+               IPVR_DEBUG_PM("Successfully installed IRQ\n");
+       }
+       else
+               IPVR_DEBUG_PM("irq_enabled is %d\n",
+ dev->irq_enabled);
+
+       return 0;
+}
+
+static int32_t 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");
+       BUG_ON(!drm_dev);
+       return ipvr_drm_freeze(drm_dev); } static int32_t
+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");
+       BUG_ON(!drm_dev);
+       return ipvr_drm_thaw(drm_dev); }
+
+/*
+ * dump GEM API is mainly for dumb buffers suitable for scanout,
+ * it is not needed for ipvr driver.
+ * gem_vm_ops is used for mmap case, also not needed for ipvr

drivers/gpu/drm/ipvr/ipvr_drv.c line 722

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+ * todo: prime support can be enabled later  */ static struct
+drm_driver ipvr_drm_driver = {
+       .driver_features = DRIVER_HAVE_IRQ | DRIVER_GEM,
+       .load = ipvr_drm_load,
+       .unload = ipvr_drm_unload,
+       .open = ipvr_drm_open,
+       .preclose = ipvr_drm_preclose,
+       .postclose = ipvr_drm_postclose,
+       .irq_handler = ipvr_irq_handler,
+       .set_busid = drm_platform_set_busid,

This should be NULL for new drivers.

Quoted 11 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +11 -0
+       .gem_free_object = ipvr_gem_free_object, #ifdef
+CONFIG_DEBUG_FS
+       .debugfs_init = ipvr_debugfs_init,
+       .debugfs_cleanup = ipvr_debugfs_cleanup, #endif
+       .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,
Quoted 9 lines

drivers/gpu/drm/ipvr/ipvr_drv.c line 741

Quoted 5 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +5 -0
+       .minor = IPVR_DRIVER_MINOR,
+       .patchlevel = IPVR_DRIVER_PATCHLEVEL, };
+
+static int32_t ipvr_plat_probe(struct platform_device *device) {
+       return drm_platform_init(&ipvr_drm_driver, device);

drm_platform_init() should be used. Please use drm_dev_alloc(), drm_dev_register() directly. udl and tegra should serve as example.

Thx, will update it in next version.

Quoted 6 lines

drivers/gpu/drm/ipvr/ipvr_drv.c line 746

Quoted 4 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +4 -0
+}
+
+static int32_t ipvr_plat_remove(struct platform_device *device) {
+       drm_put_dev(platform_get_drvdata(device));

Again, please use drm_dev_unregister() + drm_dev_unref() directly.

Thx, will update it in next version.

Quoted 24 lines

Thanks
David

Quoted 20 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +20 -0
+       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_plat_driver = {
+       .driver = {
+               .name = "ipvr-ved",
+               .owner = THIS_MODULE,
+#ifdef CONFIG_PM
+               .pm = &ipvr_pm_ops,
Quoted 8 lines

drivers/gpu/drm/ipvr/ipvr_drv.c line 776

Quoted 8 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +8 -0
+#endif
+       },
+       .probe = ipvr_plat_probe,
+       .remove = ipvr_plat_remove,
+};
+
+module_platform_driver(ipvr_plat_driver);
+MODULE_LICENSE("GPL");

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

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
author
#12 lore raw

RE: [Intel-gfx] [RFC PATCH 2/3] drm/ipvr: drm driver for vxd392

Hi Daniel/Hermann,

Quoted 51 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Thursday, October 16, 2014 6:29 PM
To: Cheng, Yao
Cc: David Herrmann; Vetter, Daniel; Intel Graphics Development; Jiang, Fei; [email protected]
Subject: Re: [Intel-gfx] [RFC PATCH 2/3] drm/ipvr: drm driver for vxd392

Quoted 30 lines · Yao

Hi Herrmann

Quoted 28 lines

-----Original Message-----
From: David Herrmann [mailto:[email protected]]
Sent: Monday, October 13, 2014 10:27 PM
To: Cheng, Yao
Cc: Intel Graphics Development; Jiang, Fei; [email protected]; Vetter, Daniel
Subject: Re: [RFC PATCH 2/3] drm/ipvr: drm driver for vxd392

Hi

Quoted 5 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +5 -0
+static struct drm_ioctl_desc ipvr_gem_ioctls[] = {
+       DRM_IOCTL_DEF_DRV(IPVR_CONTEXT_CREATE,
+                       ipvr_context_create_ioctl, DRM_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_CONTEXT_DESTROY,
+                       ipvr_context_destroy_ioctl, DRM_UNLOCKED),

drivers/gpu/drm/ipvr/ipvr_drv.c line 259

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+       DRM_IOCTL_DEF_DRV(IPVR_MISC,
+                       ipvr_misc_ioctl, DRM_AUTH),
+       DRM_IOCTL_DEF_DRV(IPVR_GEM_EXECBUFFER,
+                       ipvr_gem_execbuffer, DRM_AUTH|DRM_UNLOCKED),
+       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_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_GEM_MMAP,
+                       ipvr_gem_mmap_ioctl, DRM_UNLOCKED),

Why do you need this ioctl? mmap() should work perfectly fine. I don't see why you require people to use a ipvr specific ioctl to map

buffers.

Quoted 5 lines

Many thanks to your comments, in our existing libdrm helper and userspace drivers, mmap_ioctl was the interface of mapping objects. We continued using the ioctl way for compatibility. Is it mandatory to implement mmap() to replace mmap_ioctl for GEM drivers?

Yeah, the new way is to have a ioctl in the drm driver to create an mmap offset (look at the gtt_mmap_offset ioctl for i915), and the use mmap on the drm fd. Doing a direct driver ioctl to forward the mmap is deprecated.

Quoted 6 lines

The reason for that is that a) this is the new standard way used by all drm drivers b) if you use the standard mmap system call debug tools like valgrind will understand it without any special actions.

I'll do a patch to i915 so that people stop copy-pasting that old misdesign. -Daniel

Accepted :) I will update the patch to implement the mmap interface and remove the legacy MMAP_IOCTL.
BTW I didn't see a field to get mmap_offset in struct drm_gem_open, I guess something like a new "GET_MMAP_OFFSET_IOCTL" need be added to support mapping flinked/primed BO, is it?

Quoted 573 lines
Quoted 14 lines
Quoted 14 lines
Quoted 4 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +1 -0
+       DRM_IOCTL_DEF_DRV(IPVR_SYNC_CPU,

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+                       ipvr_sync_cpu_ioctl, DRM_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_GEM_WAIT,
+                       ipvr_gem_wait_ioctl, DRM_AUTH|DRM_UNLOCKED),
+       DRM_IOCTL_DEF_DRV(IPVR_GEM_USERPTR,
+                       ipvr_gem_userptr_ioctl, DRM_UNLOCKED), };
+
+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",

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +9 -0
+                                 sizeof(union drm_ipvr_gem_objects), 0,
+                                 SLAB_HWCACHE_ALIGN, NULL);
+
+       INIT_LIST_HEAD(&dev_priv->ipvr_mm.unbound_list);
+       INIT_LIST_HEAD(&dev_priv->ipvr_mm.bound_list);
+       spin_lock_init(&dev_priv->ipvr_mm.object_stat_lock);
+
+       dev_priv->ipvr_mm.interruptible = true; }
+
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 8 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +8 -0
+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.
+        *
+        * However, leave one page at the end still bound to the scratch

page.

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

+ * There are a number of places where hardware apparently

prefetches

Quoted 1 line

+ * past the end of the object, and we've seen multiple hangs with

the

Quoted 1 line
Quoted 1 line
Quoted 1 line

+ * GPU head pointer stuck in a batchbuffer bound at last page of

the

Quoted 112 lines
Quoted 43 lines
Quoted 2 lines

+ * aperture. One page should be enough to keep any
+ prefetching

inside

Quoted 40 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +40 -0
+        * of the aperture.
+        */
+       struct drm_ipvr_private *dev_priv = dev->dev_private;
+       struct ipvr_address_space *addr_space =
+ &dev_priv->addr_space;
+
+       /* todo: add sanity check */
+       addr_space->dev = dev_priv->dev;
+       INIT_LIST_HEAD(&addr_space->active_list);
+       INIT_LIST_HEAD(&addr_space->inactive_list);
+
+       /* 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; }
+
+static void ipvr_do_takedown(struct drm_device *dev) {
+       /* todo: need check if need clean up mm here */
+       ipvr_ved_uninit(dev);
+}
+
+static int32_t ipvr_drm_unload(struct drm_device *dev) {
+       struct drm_ipvr_private *dev_priv = dev->dev_private;
+
+       BUG_ON(!dev->platformdev);
+       BUG_ON(atomic_read(&dev_priv->ved_power_usage));
+
+       IPVR_DEBUG_ENTRY("entered.");
+       if (dev_priv) {
+
+ WARN_ON(pm_runtime_get_sync(&dev->platformdev->dev) < 0);
+
Quoted 8 lines

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 8 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +8 -0
+               if (dev_priv->ipvr_bo_slab)
+                       kmem_cache_destroy(dev_priv->ipvr_bo_slab);
+               ipvr_fence_driver_fini(dev_priv);
+
+               ipvr_do_takedown(dev);
+
+
+ WARN_ON(pm_runtime_put_sync_suspend(&dev->platformdev-

dev)

Quoted 60 lines

< 0);

Quoted 59 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +15 -0
+
+               if (dev_priv->validate_ctx.buffers)
+                       vfree(dev_priv->validate_ctx.buffers);
+
+               if (dev_priv->pf_pd) {
+                       ipvr_mmu_free_pagedir(dev_priv->pf_pd);
+                       dev_priv->pf_pd = NULL;
+               }
+               if (dev_priv->mmu) {
+                       ipvr_mmu_driver_takedown(dev_priv->mmu);
+                       dev_priv->mmu = NULL;
+               }
+
+               if (dev_priv->ved_reg_base) {
+                       iounmap(dev_priv->ved_reg_base - dev_priv-

ved_reg_offset);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +6 -0
+                       dev_priv->ved_reg_base = NULL;
+                       dev_priv->ved_reg_offset = 0;
+               }
+
+               list_del(&dev_priv->default_ctx.head);
+               idr_remove(&dev_priv->ipvr_ctx_idr, dev_priv-

default_ctx.ctx_id);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +36 -0
+               kfree(dev_priv);
+
+       }
+
+       pm_runtime_disable(&dev->platformdev->dev);
+
+       return 0;
+}
+
+static int32_t ipvr_drm_load(struct drm_device *dev, unsigned
+long
+flags) {
+       struct drm_ipvr_private *dev_priv;
+       int32_t ctx_id, ret = 0;
+       struct platform_device *platdev;
+       struct resource *res_mmio, *res_reg;
+       void __iomem* mmio_addr;
+
+       dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
+       if (dev_priv == NULL)
+               return -ENOMEM;
+
+       dev->dev_private = dev_priv;
+       dev_priv->dev = dev;
+
+       BUG_ON(!dev->platformdev);
+       platdev = dev->platformdev;
+
+       mutex_init(&dev_priv->cmdbuf_mutex);
+       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;
+       }
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 8 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +8 -0
+
+       dev->irq = platform_get_irq(platdev, 0);
+       if (dev->irq < 0) {
+               ret = -ENODEV;
+               goto out_err;
+       }
+
+       res_mmio = platform_get_resource(platdev, IORESOURCE_MEM,

0);

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +8 -0
+       res_reg = platform_get_resource(platdev, IORESOURCE_REG, 0);
+       if (!res_mmio || !res_reg) {
+               ret = -ENXIO;
+               goto out_err;
+       }
+
+       mmio_addr = ioremap_wc(res_mmio->start,
+                                       res_mmio->end - res_mmio->start);
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 8 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +8 -0
+       if (IS_ERR(mmio_addr)) {
+               ret = -EACCES;
+               goto out_err;
+       }
+
+       dev_priv->ved_reg_base = mmio_addr + res_reg->start;
+       dev_priv->ved_reg_offset = res_reg->start;
+       IPVR_DEBUG_VED("ved_reg_base is %p, range is 0x%llx -

0x%llx.\n",

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +4 -0
+               dev_priv->ved_reg_base,
+               res_reg->start, res_reg->end);
+
+       platform_set_drvdata(dev->platformdev, dev);
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 8 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +8 -0
+       pm_runtime_enable(&dev->platformdev->dev);
+
+       if (pm_runtime_get_sync(&dev->platformdev->dev) < 0) {
+               ret = -EBUSY;
+               goto out_err;
+       }
+
+       IPVR_DEBUG_INIT("MSVDX_CORE_REV_OFFSET by readl is

0x%x.\n",

Quoted 134 lines
Quoted 56 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+               readl(dev_priv->ved_reg_base + 0x640));
+       IPVR_DEBUG_INIT("MSVDX_CORE_REV_OFFSET by

VED_REG_READ32 is 0x%x.\n",

Quoted 53 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +18 -0
+               VED_REG_READ32(MSVDX_CORE_REV_OFFSET));
+
+       /* mmu init */
+       dev_priv->mmu = ipvr_mmu_driver_init((void *)0,
+               drm_ipvr_trap_pagefaults,
+               0, dev_priv);
+       if (!dev_priv->mmu) {
+               ret = -EBUSY;
+               goto out_err;
+       }
+
+       dev_priv->pf_pd = ipvr_mmu_alloc_pd(dev_priv->mmu, 1, 0);
+       if (!dev_priv->pf_pd) {
+               ret = -ENOMEM;
+               goto out_err;
+       }
+
+       ipvr_mmu_set_pd_context(ipvr_mmu_get_default_pd(dev_priv-

mmu), 0);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +19 -0
+       ipvr_mmu_set_pd_context(dev_priv->pf_pd, 1);
+
+       /*
+        * 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);
+
+       ipvr_ved_init(dev);
+
+       WARN_ON(pm_runtime_put_sync_suspend(&dev->platformdev-

dev) <
+ 0);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +13 -0
+
+       dev_priv->ved_private->ved_needs_reset = 1;
+       mutex_init(&dev_priv->ved_pm_mutex);
+       atomic_set(&dev_priv->ved_power_usage, 0);
+
+       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;
Quoted 8 lines

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 8 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +8 -0
+       }
+
+       /* ipvr context initialization */
+       INIT_LIST_HEAD(&dev_priv->ipvr_ctx_list);
+       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,

Quoted 69 lines
Quoted 69 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +69 -0
+                          IPVR_MIN_CONTEXT_ID, IPVR_MAX_CONTEXT_ID,
+                          GFP_KERNEL);
+       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 */
+       list_add(&dev_priv->default_ctx.head, &dev_priv->ipvr_ctx_list);
+       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 int32_t
+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 (unlikely(ipvr_fp == NULL))
+               return -ENOMEM;
+
+       file_priv->driver_priv = ipvr_fp;
+
+       return 0;
+}
+
+/*
+ * The close operation is split into .preclose() and .postclose() methods.
+ * Drivers must stop and cleanup all per-file operations in the
+.preclose()
+ * method. For instance pending vertical blanking and page flip
+events must be
+ * cancelled. No per-file operation is allowed on the file handle
+after
+ * returning from the .preclose() method.
+ */
+static void
+ipvr_drm_preclose(struct drm_device *dev, struct drm_file
+*file_priv) {
+       /* if user didn't destory ctx explicitly, remove ctx here */
+       struct drm_ipvr_private *dev_priv;
+       struct drm_ipvr_file_private *ipvr_fpriv;
+       struct ved_private *ved_priv;
+       struct ipvr_context *ipvr_ctx  = NULL;
+       unsigned long irq_flags;
+
+       IPVR_DEBUG_ENTRY("enter\n");
+       dev_priv = dev->dev_private;
+       ipvr_fpriv = file_priv->driver_priv;
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 8 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +8 -0
+       ved_priv = dev_priv->ved_private;
+
+       if (ipvr_fpriv->ctx_id == IPVR_CONTEXT_INVALID_ID)
+               return;
+       ipvr_ctx = (struct ipvr_context *)
+                       idr_find(&dev_priv->ipvr_ctx_idr, ipvr_fpriv->ctx_id);
+       if (!ipvr_ctx  || (ipvr_ctx->ipvr_fpriv != ipvr_fpriv)) {
+               IPVR_DEBUG_GENERAL("ctx for id %d has already

destroyed\n",

Quoted 42 lines
Quoted 33 lines

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 4 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +4 -0
+                               ipvr_fpriv->ctx_id);
+               return;
+       }
+       IPVR_DEBUG_PM("Video:remove context profile %d,

entrypoint %d\n",

Quoted 28 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +28 -0
+               (ipvr_ctx->ctx_type >> 8) & 0xff,
+               (ipvr_ctx->ctx_type & 0xff));
+       mutex_lock(&ved_priv->ved_mutex);
+       if (ved_priv->ipvr_ctx == ipvr_ctx )
+               ved_priv->ipvr_ctx = NULL;
+       mutex_unlock(&ved_priv->ved_mutex);
+
+       spin_lock_irqsave(&dev_priv->ipvr_ctx_lock, irq_flags);
+       list_del(&ipvr_ctx->head);
+       ipvr_fpriv->ctx_id = IPVR_CONTEXT_INVALID_ID;
+       spin_unlock_irqrestore(&dev_priv->ipvr_ctx_lock,
+ irq_flags);
+
+       idr_remove(&dev_priv->ipvr_ctx_idr, ipvr_ctx->ctx_id);
+
+       kfree(ipvr_ctx );
+}
+
+/*
+ * Finally the .postclose() method is called as the last step of
+the close
+ * operation, right before calling the .lastclose() method if no
+other open
+ * file handle exists for the device. Drivers that have allocated
+per-file
+ * private data in the .open() method should free it here.
+ */
+static void
Quoted 8 lines

drivers/gpu/drm/ipvr/ipvr_drv.c line 599

Quoted 6 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +6 -0
+ipvr_drm_postclose(struct drm_device *dev, struct drm_file
+*file_priv) {
+       struct drm_ipvr_file_private *ipvr_fpriv = file_priv->driver_priv;
+       IPVR_DEBUG_ENTRY("enter\n");
+       kfree(ipvr_fpriv);
+}

postclose() is deprecated. You can safely move this into preclose().

Quoted 37 lines

Thx, will update it in next version.

Quoted 35 lines
Quoted 18 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +17 -0
+
+static irqreturn_t ipvr_irq_handler(int32_t irq, void *arg) {
+       struct drm_device *dev = (struct drm_device *) arg;
+       WARN_ON(ved_irq_handler(dev));
+       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
+       /* no need to define mmap. User space maps bo with
+DRM_IPVR_GEM_MMAP */ };
+
+static int32_t ipvr_drm_freeze(struct drm_device *dev) {

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+       int32_t ret;
+       int32_t power_usage;
+       struct drm_ipvr_private *dev_priv = dev->dev_private;
+
+       IPVR_DEBUG_ENTRY("enter\n");
+       power_usage = atomic_read(&dev_priv->ved_power_usage);
+       BUG_ON(power_usage < 0);
+       if (power_usage > 0) {
+               IPVR_DEBUG_PM("VED power usage is %d, skip
+ freezing\n",

power_usage);

Quoted 6 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +6 -0
+               return 0;
+       }
+
+       ret = ved_check_idle(dev);
+       if (ret) {
+               IPVR_DEBUG_PM("VED check idle fail: %d, skip freezing\n",

ret);

Quoted 55 lines
Quoted 55 lines
Quoted 14 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +14 -0
+               return 0;
+       }
+
+       if (dev->irq_enabled) {
+               ret = drm_irq_uninstall(dev);
+               if (unlikely(ret)) {
+                       IPVR_ERROR("Error uninstalling IRQ handler: %d\n", ret);
+                       return -EFAULT;
+               }
+               IPVR_DEBUG_PM("Successfully uninstalled IRQ\n");
+       }
+       else
+               IPVR_DEBUG_PM("irq_enabled is %d\n",
+ dev->irq_enabled);

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+
+       if (is_ved_on(dev)) {
+               if (!ved_power_off(dev)) {
+                       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");

Quoted 7 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +7 -0
+       }
+
+       return 0;
+}
+
+static int32_t ipvr_drm_thaw(struct drm_device *dev) {
+       int ret;

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+       IPVR_DEBUG_ENTRY("enter\n");
+       if (!is_ved_on(dev)) {
+               if (!ved_power_on(dev)) {
+                       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");

Quoted 12 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +12 -0
+       }
+
+       if (!dev->irq_enabled) {
+               ret = drm_irq_install(dev, dev->irq);
+               if (ret) {
+                       IPVR_ERROR("Error installing IRQ handler: %d\n", ret);
+                       return -EFAULT;
+               }
+               IPVR_DEBUG_PM("Successfully installed IRQ\n");
+       }
+       else
+               IPVR_DEBUG_PM("irq_enabled is %d\n",
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 8 lines

+ dev->irq_enabled);

drivers/gpu/drm/ipvr/ipvr_drv.c new file +7 -0
+
+       return 0;
+}
+
+static int32_t ipvr_pm_suspend(struct device *dev) {
+       struct platform_device *platformdev = to_platform_device(dev);
+       struct drm_device *drm_dev =

platform_get_drvdata(platformdev);

Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/ipvr/ipvr_drv.c

Quoted 6 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +6 -0
+       IPVR_DEBUG_PM("PM suspend called\n");
+       BUG_ON(!drm_dev);
+       return ipvr_drm_freeze(drm_dev); } static int32_t
+ipvr_pm_resume(struct device *dev) {
+       struct platform_device *platformdev = to_platform_device(dev);
+       struct drm_device *drm_dev =

platform_get_drvdata(platformdev);

Quoted 76 lines
Quoted 31 lines
Quoted 8 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +8 -0
+       IPVR_DEBUG_PM("PM resume called\n");
+       BUG_ON(!drm_dev);
+       return ipvr_drm_thaw(drm_dev); }
+
+/*
+ * dump GEM API is mainly for dumb buffers suitable for scanout,
+ * it is not needed for ipvr driver.
+ * gem_vm_ops is used for mmap case, also not needed for ipvr

drivers/gpu/drm/ipvr/ipvr_drv.c line 722

Quoted 10 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +10 -0
+ * todo: prime support can be enabled later  */ static struct
+drm_driver ipvr_drm_driver = {
+       .driver_features = DRIVER_HAVE_IRQ | DRIVER_GEM,
+       .load = ipvr_drm_load,
+       .unload = ipvr_drm_unload,
+       .open = ipvr_drm_open,
+       .preclose = ipvr_drm_preclose,
+       .postclose = ipvr_drm_postclose,
+       .irq_handler = ipvr_irq_handler,
+       .set_busid = drm_platform_set_busid,

This should be NULL for new drivers.

Quoted 11 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +11 -0
+       .gem_free_object = ipvr_gem_free_object, #ifdef
+CONFIG_DEBUG_FS
+       .debugfs_init = ipvr_debugfs_init,
+       .debugfs_cleanup = ipvr_debugfs_cleanup, #endif
+       .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,
Quoted 9 lines

drivers/gpu/drm/ipvr/ipvr_drv.c line 741

Quoted 5 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +5 -0
+       .minor = IPVR_DRIVER_MINOR,
+       .patchlevel = IPVR_DRIVER_PATCHLEVEL, };
+
+static int32_t ipvr_plat_probe(struct platform_device *device) {
+       return drm_platform_init(&ipvr_drm_driver, device);

drm_platform_init() should be used. Please use drm_dev_alloc(), drm_dev_register() directly. udl and tegra should serve as example.

Thx, will update it in next version.

Quoted 6 lines

drivers/gpu/drm/ipvr/ipvr_drv.c line 746

Quoted 4 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +4 -0
+}
+
+static int32_t ipvr_plat_remove(struct platform_device *device) {
+       drm_put_dev(platform_get_drvdata(device));

Again, please use drm_dev_unregister() + drm_dev_unref() directly.

Thx, will update it in next version.

Quoted 24 lines

Thanks
David

Quoted 20 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +20 -0
+       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_plat_driver = {
+       .driver = {
+               .name = "ipvr-ved",
+               .owner = THIS_MODULE, #ifdef CONFIG_PM
+               .pm = &ipvr_pm_ops, #endif
+       },
+       .probe = ipvr_plat_probe,
Quoted 8 lines
Quoted 4 lines

drivers/gpu/drm/ipvr/ipvr_drv.c line 776

Quoted 4 lines
drivers/gpu/drm/ipvr/ipvr_drv.c new file +4 -0
+       .remove = ipvr_plat_remove, };
+
+module_platform_driver(ipvr_plat_driver);
+MODULE_LICENSE("GPL");

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

--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

#13 lore raw

Re: [Intel-gfx] [RFC PATCH 2/3] drm/ipvr: drm driver for vxd392

Hi

Quoted 2 lines · Yao

Accepted :) I will update the patch to implement the mmap interface and remove the legacy MMAP_IOCTL.
BTW I didn't see a field to get mmap_offset in struct drm_gem_open, I guess something like a new "GET_MMAP_OFFSET_IOCTL" need be added to support mapping flinked/primed BO, is it?

Yes. There is currently no generic interface to get mmap offsets for any gem bo (because some of them may not be mapped from user-space or require extra parameters).

So, either support dumb-buffers (if you don't need any advanced parameters like tiling or cache constraints), or add an MMAP_OFFSET_IOCTL like you proposed (and most drivers do so).

Thanks
David

#14 lore raw

Re: [RFC PATCH 2/3] drm/ipvr: drm driver for vxd392

Quoted 6 lines · David Herrmann

Hi

Quoted 2 lines · Yao

Accepted :) I will update the patch to implement the mmap interface and remove the legacy MMAP_IOCTL.
BTW I didn't see a field to get mmap_offset in struct drm_gem_open, I guess something like a new "GET_MMAP_OFFSET_IOCTL" need be added to support mapping flinked/primed BO, is it?

Quoted 7 lines

Yes. There is currently no generic interface to get mmap offsets for any gem bo (because some of them may not be mapped from user-space or require extra parameters).

So, either support dumb-buffers (if you don't need any advanced parameters like tiling or cache constraints), or add an MMAP_OFFSET_IOCTL like you proposed (and most drivers do so).

Dave Airlie _really_ doesn't like it if userspace abuses the dumb buffer interface for rendering. That really should only be used for sw rendering for boot splash and similar. Some armsoc drivers don't really follow that though.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#15 lore raw
In reply to Yao Cheng
Quoted 11 lines · Yao Cheng

drm/ipvr is a new GEM driver for baytrail's vxd392, which accelerates VP8 video decoding.
The driver name "ipvr" means the PowerVR's IP wrapped by Intel. In the future, ipvr may support other platforms such as Merrifield. Code is placed at drivers/gpu/drm/ipvr and the following two new Kconfig are added:
CONFIG_DRM_IPVR: Build option for ipvr module
CONFIG_DRM_IPVR_EC: Experimental feature of error concealment

User mode drm helper "libdrm_ipvr.so" and simple test are also included.

Yao Cheng (3):
[1/3] drm/i915: add vxd392 bridge in i915 on baytrail [2/3] drm/ipvr: ipvr drm driver for vxd392

If this is Intel-specific, why doesn't it live under the i915 driver?

Thierry

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

#16 lore raw
Quoted 7 lines · Thierry Reding
Quoted 6 lines · Yao Cheng

drm/ipvr is a new GEM driver for baytrail's vxd392, which accelerates VP8 video decoding.
The driver name "ipvr" means the PowerVR's IP wrapped by Intel. In the future, ipvr may support other platforms such as Merrifield. Code is placed at drivers/gpu/drm/ipvr and the following two new Kconfig are added:
CONFIG_DRM_IPVR: Build option for ipvr module
CONFIG_DRM_IPVR_EC: Experimental feature of error concealment

Quoted 7 lines
Quoted 5 lines

User mode drm helper "libdrm_ipvr.so" and simple test are also included.

Yao Cheng (3):
[1/3] drm/i915: add vxd392 bridge in i915 on baytrail [2/3] drm/ipvr: ipvr drm driver for vxd392

If this is Intel-specific, why doesn't it live under the i915 driver?

It is an entirely unrelated HW IP block, VXD392. Nothing to do with GEN aside from DRM based.

Sean

Quoted 8 lines

Thierry

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

Signature · 3 lines
Sean V. Kelley <[email protected]>
Open Source Technology Center / SSG
Intel Corp.
author
#17 lore raw

Thx Kelley/Reding for comments,
Yes, the vxd392 is a totally different IP and it also exist on Intel's non-GEN platforms such as Merrifield. If we put it inside i915 there'll be issue if we someday supports Merrifield.

-----Original Message-----
From: Sean V Kelley [mailto:[email protected]]
Sent: Tuesday, October 14, 2014 11:51 PM
To: Thierry Reding
Cc: Cheng, Yao; Vetter, Daniel; [email protected]; Jiang, Fei; DRI mailing list
Subject: Re: [Intel-gfx] [RFC PATCH 0/3] drm driver for baytrail's vxd392

Quoted 7 lines · Thierry Reding
Quoted 6 lines · Yao Cheng

drm/ipvr is a new GEM driver for baytrail's vxd392, which accelerates VP8 video decoding.
The driver name "ipvr" means the PowerVR's IP wrapped by Intel. In the future, ipvr may support other platforms such as Merrifield. Code is placed at drivers/gpu/drm/ipvr and the following two new Kconfig are added:
CONFIG_DRM_IPVR: Build option for ipvr module
CONFIG_DRM_IPVR_EC: Experimental feature of error concealment

Quoted 7 lines
Quoted 5 lines

User mode drm helper "libdrm_ipvr.so" and simple test are also included.

Yao Cheng (3):
[1/3] drm/i915: add vxd392 bridge in i915 on baytrail [2/3]
drm/ipvr: ipvr drm driver for vxd392

If this is Intel-specific, why doesn't it live under the i915 driver?

It is an entirely unrelated HW IP block, VXD392. Nothing to do with GEN aside from DRM based.

Sean

Quoted 8 lines

Thierry

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

--
Sean V. Kelley <[email protected]> Open Source Technology Center / SSG Intel Corp.

#18 lore raw
In reply to Sean V Kelley
Quoted 11 lines · Sean V Kelley
Quoted 9 lines · Thierry Reding
Quoted 8 lines · Yao Cheng

drm/ipvr is a new GEM driver for baytrail's vxd392, which accelerates VP8 video decoding.
The driver name "ipvr" means the PowerVR's IP wrapped by Intel. In the future, ipvr may support other platforms such as Merrifield. Code is placed at drivers/gpu/drm/ipvr and the following two new Kconfig are added:
CONFIG_DRM_IPVR: Build option for ipvr module
CONFIG_DRM_IPVR_EC: Experimental feature of error concealment

User mode drm helper "libdrm_ipvr.so" and simple test are also included.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Yao Cheng (3):
[1/3] drm/i915: add vxd392 bridge in i915 on baytrail [2/3] drm/ipvr: ipvr drm driver for vxd392

If this is Intel-specific, why doesn't it live under the i915 driver?

It is an entirely unrelated HW IP block, VXD392. Nothing to do with GEN aside from DRM based.

With GEN you're referring to the Intel integrated GPU? And VXD392 I take it is the IP block licensed by Imagination? Baytrail and others then wrap some additional logic around this as it is integrated into the SoC?

How much wrapping actually happens here? I worry that this is going to lead to a lot of duplication if we ever want to support another SoC that uses the VXD392 IP. Could the code be split into a VXD392 "library" and some driver that implements the Intel-specific glue?

Finally, if this IP block is a VP8 video decoding engine only, I'm not sure DRM is the best subsystem for it. Traditionally video decoding has been done primarily in V4L2. I'm not sure that's the best fit given that it was originally designed for video capturing, but they've evolved some infrastructure to deal with encoding/decoding, whereas we have nothing like that at all in DRM.

Thierry

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

#19 lore raw
Quoted 34 lines · Thierry Reding
Quoted 4 lines · Sean V Kelley
Quoted 2 lines · Thierry Reding
Quoted 1 line · Yao Cheng

drm/ipvr is a new GEM driver for baytrail's vxd392, which accelerates

VP8 video decoding.

Quoted 1 line
Quoted 1 line
Quoted 1 line

The driver name "ipvr" means the PowerVR's IP wrapped by Intel. In

the future, ipvr may support other platforms such as Merrifield.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Code is placed at drivers/gpu/drm/ipvr and the following two new

Kconfig are added:

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

CONFIG_DRM_IPVR: Build option for ipvr module
CONFIG_DRM_IPVR_EC: Experimental feature of error concealment

User mode drm helper "libdrm_ipvr.so" and simple test are also

included.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

Yao Cheng (3):
[1/3] drm/i915: add vxd392 bridge in i915 on baytrail [2/3] drm/ipvr: ipvr drm driver for vxd392

If this is Intel-specific, why doesn't it live under the i915 driver?

It is an entirely unrelated HW IP block, VXD392. Nothing to do with GEN aside from DRM based.

With GEN you're referring to the Intel integrated GPU? And VXD392 I take it is the IP block licensed by Imagination? Baytrail and others then wrap some additional logic around this as it is integrated into the SoC?

How much wrapping actually happens here? I worry that this is going to lead to a lot of duplication if we ever want to support another SoC that uses the VXD392 IP. Could the code be split into a VXD392 "library" and some driver that implements the Intel-specific glue?

Quoted 7 lines

Finally, if this IP block is a VP8 video decoding engine only, I'm not sure DRM is the best subsystem for it. Traditionally video decoding has been done primarily in V4L2. I'm not sure that's the best fit given that it was originally designed for video capturing, but they've evolved some infrastructure to deal with encoding/decoding, whereas we have nothing like that at all in DRM.

That isn't true. i915, nouveau and radeon drm drivers all support video decoding user space in some form.

Stéphane

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

#20 lore raw
Quoted 45 lines · Stéphane Marchesin
Quoted 34 lines · Thierry Reding
Quoted 4 lines · Sean V Kelley
Quoted 2 lines · Thierry Reding
Quoted 1 line · Yao Cheng

drm/ipvr is a new GEM driver for baytrail's vxd392, which accelerates

VP8 video decoding.

Quoted 1 line
Quoted 1 line
Quoted 1 line

The driver name "ipvr" means the PowerVR's IP wrapped by Intel. In

the future, ipvr may support other platforms such as Merrifield.

Quoted 1 line
Quoted 1 line
Quoted 1 line

Code is placed at drivers/gpu/drm/ipvr and the following two new

Kconfig are added:

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

CONFIG_DRM_IPVR: Build option for ipvr module
CONFIG_DRM_IPVR_EC: Experimental feature of error concealment

User mode drm helper "libdrm_ipvr.so" and simple test are also

included.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

Yao Cheng (3):
[1/3] drm/i915: add vxd392 bridge in i915 on baytrail [2/3] drm/ipvr: ipvr drm driver for vxd392

If this is Intel-specific, why doesn't it live under the i915 driver?

It is an entirely unrelated HW IP block, VXD392. Nothing to do with GEN aside from DRM based.

With GEN you're referring to the Intel integrated GPU? And VXD392 I take it is the IP block licensed by Imagination? Baytrail and others then wrap some additional logic around this as it is integrated into the SoC?

How much wrapping actually happens here? I worry that this is going to lead to a lot of duplication if we ever want to support another SoC that uses the VXD392 IP. Could the code be split into a VXD392 "library" and some driver that implements the Intel-specific glue?

Quoted 7 lines

Finally, if this IP block is a VP8 video decoding engine only, I'm not sure DRM is the best subsystem for it. Traditionally video decoding has been done primarily in V4L2. I'm not sure that's the best fit given that it was originally designed for video capturing, but they've evolved some infrastructure to deal with encoding/decoding, whereas we have nothing like that at all in DRM.

Quoted 2 lines

That isn't true. i915, nouveau and radeon drm drivers all support video decoding user space in some form.

Well yes, because they are GPUs that happen to have video decoding engines on the same board and use the same method of command-stream submission that they use for 2D or 3D work.

For standalone video decoding hardware, the only drivers that I know of are in drivers/media.

Thierry

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

#21 lore raw
In reply to Thierry Reding
Quoted 21 lines · Thierry Reding
Quoted 11 lines · Sean V Kelley
Quoted 9 lines · Thierry Reding
Quoted 8 lines · Yao Cheng

drm/ipvr is a new GEM driver for baytrail's vxd392, which accelerates VP8 video decoding.
The driver name "ipvr" means the PowerVR's IP wrapped by Intel. In the future, ipvr may support other platforms such as Merrifield. Code is placed at drivers/gpu/drm/ipvr and the following two new Kconfig are added:
CONFIG_DRM_IPVR: Build option for ipvr module
CONFIG_DRM_IPVR_EC: Experimental feature of error concealment

User mode drm helper "libdrm_ipvr.so" and simple test are also included.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Yao Cheng (3):
[1/3] drm/i915: add vxd392 bridge in i915 on baytrail [2/3] drm/ipvr: ipvr drm driver for vxd392

If this is Intel-specific, why doesn't it live under the i915 driver?

It is an entirely unrelated HW IP block, VXD392. Nothing to do with GEN aside from DRM based.

Quoted 8 lines

With GEN you're referring to the Intel integrated GPU? And VXD392 I take it is the IP block licensed by Imagination? Baytrail and others then wrap some additional logic around this as it is integrated into the SoC?

How much wrapping actually happens here? I worry that this is going to lead to a lot of duplication if we ever want to support another SoC that uses the VXD392 IP. Could the code be split into a VXD392 "library" and some driver that implements the Intel-specific glue?

Well if someone cares for it the driver ioctl interface should be portable. But without anyone else chiming in I honestly don't care. We did try to design the entire beast like that though, and it should pretty much work with few changes on gma500 (if anyone bothers).

Quoted 6 lines

Finally, if this IP block is a VP8 video decoding engine only, I'm not sure DRM is the best subsystem for it. Traditionally video decoding has been done primarily in V4L2. I'm not sure that's the best fit given that it was originally designed for video capturing, but they've evolved some infrastructure to deal with encoding/decoding, whereas we have nothing like that at all in DRM.

Shuffling massive piles of state submission code into the kernel is imo not a sane design. So imo the sane way is to put encode/decode drivers into drm, and the kernel part just has minimal validation for security (if required at all if the iommu isn't good enough). The common interface for applications would then be gstreamer (since we don't even have a cross-vendor video api with at least libva and vdpau having rather decent open drivers available).
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#22 lore raw
In reply to Thierry Reding
Quoted 6 lines · Thierry Reding

Finally, if this IP block is a VP8 video decoding engine only, I'm not sure DRM is the best subsystem for it. Traditionally video decoding has been done primarily in V4L2. I'm not sure that's the best fit given that it was originally designed for video capturing, but they've evolved some infrastructure to deal with encoding/decoding, whereas we have nothing like that at all in DRM.

v4l maybe works for some vid dec/enc hw if the hw does enough for you.. the common ioctl approach might work for some hw, but I think not really all. For the same reason we don't try to standardize the 3d/2d cmd submission ioctls across drivers..

BR,
-R

#23 lore raw

The reason why we use DRM interface is mainly we want to use GEM for video memory manager.

Thanks,
Fei
-----Original Message-----
From: Rob Clark [mailto:[email protected]]
Sent: Friday, October 17, 2014 2:43 AM
To: Thierry Reding
Cc: Kelley, Sean V; Vetter, Daniel; [email protected]; DRI mailing list; Jiang, Fei
Subject: Re: [Intel-gfx] [RFC PATCH 0/3] drm driver for baytrail's vxd392

Quoted 6 lines · Thierry Reding

Finally, if this IP block is a VP8 video decoding engine only, I'm not sure DRM is the best subsystem for it. Traditionally video decoding has been done primarily in V4L2. I'm not sure that's the best fit given that it was originally designed for video capturing, but they've evolved some infrastructure to deal with encoding/decoding, whereas we have nothing like that at all in DRM.

v4l maybe works for some vid dec/enc hw if the hw does enough for you.. the common ioctl approach might work for some hw, but I think not really all. For the same reason we don't try to standardize the 3d/2d cmd submission ioctls across drivers..

BR,
-R

#24 lore raw
In reply to Yao Cheng
Quoted 7 lines · Yao Cheng

drm/ipvr is a new GEM driver for baytrail's vxd392, which accelerates VP8 video decoding.
The driver name "ipvr" means the PowerVR's IP wrapped by Intel. In the future, ipvr may support other platforms such as Merrifield. Code is placed at drivers/gpu/drm/ipvr and the following two new Kconfig are added:
CONFIG_DRM_IPVR: Build option for ipvr module
CONFIG_DRM_IPVR_EC: Experimental feature of error concealment

User mode drm helper "libdrm_ipvr.so" and simple test are also included.

git repos/patches for the userspace side seems to be missing. -Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
author
#25 lore raw

Hi Daniel, this patch
[RFC PATCH 3/3] libdrm: user mode helper for ipvr drm driver
adds the ipvr part into libdrm.
Do you mean this patch is missing?

Quoted 27 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Thursday, October 16, 2014 7:46 PM
To: Cheng, Yao
Cc: [email protected]; Jiang, Fei; dri- [email protected]; Vetter, Daniel
Subject: Re: [Intel-gfx] [RFC PATCH 0/3] drm driver for baytrail's vxd392

Quoted 1 line · Yao Cheng

drm/ipvr is a new GEM driver for baytrail's vxd392, which accelerates VP8

video decoding.

Quoted 1 line

The driver name "ipvr" means the PowerVR's IP wrapped by Intel. In the

future, ipvr may support other platforms such as Merrifield.

Quoted 1 line

Code is placed at drivers/gpu/drm/ipvr and the following two new Kconfig

are added:

Quoted 4 lines

CONFIG_DRM_IPVR: Build option for ipvr module
CONFIG_DRM_IPVR_EC: Experimental feature of error concealment

User mode drm helper "libdrm_ipvr.so" and simple test are also included.

git repos/patches for the userspace side seems to be missing. -Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

#26 lore raw
Quoted 4 lines · Yao

Hi Daniel, this patch
[RFC PATCH 3/3] libdrm: user mode helper for ipvr drm driver
adds the ipvr part into libdrm.
Do you mean this patch is missing?

The umd (ipvr_vaapi_driver) is needed to fully exercise the APIs exposed. That code is in flight and I'll work with you to get it into the repos.

Sean

Quoted 32 lines
Quoted 20 lines

-----Original Message-----
From: Daniel Vetter [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Thursday, October 16, 2014 7:46 PM
To: Cheng, Yao
Cc: [email protected]; Jiang, Fei; dri- [email protected]; Vetter, Daniel
Subject: Re: [Intel-gfx] [RFC PATCH 0/3] drm driver for baytrail's vxd392

Quoted 1 line · Yao Cheng

drm/ipvr is a new GEM driver for baytrail's vxd392, which accelerates VP8

video decoding.

Quoted 1 line

The driver name "ipvr" means the PowerVR's IP wrapped by Intel. In the

future, ipvr may support other platforms such as Merrifield.

Quoted 1 line

Code is placed at drivers/gpu/drm/ipvr and the following two new Kconfig

are added:

Quoted 3 lines

CONFIG_DRM_IPVR: Build option for ipvr module
CONFIG_DRM_IPVR_EC: Experimental feature of error concealment

Quoted 8 lines
Quoted 1 line

User mode drm helper "libdrm_ipvr.so" and simple test are also included.

git repos/patches for the userspace side seems to be missing. -Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

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

Signature · 3 lines
Sean V. Kelley <[email protected]>
Open Source Technology Center / SSG
Intel Corp.