Skip to contentSkip to conversation

drm/komeda: Add SMMU support on Komeda driver

PATCH New Lowry Li (Arm Technology China) 1 participant 3 messages Jun 12, 2019

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

v3 cover drm/komeda: Add SMMU support on Komeda driver

Hi,

This serie aims at adding the support for SMMU on Komeda driver. Also updates the device-tree doc about how to enable SMMU by devicetree.

This patch series depends on:
- https://patchwork.freedesktop.org/series/58710/
- https://patchwork.freedesktop.org/series/59000/
- https://patchwork.freedesktop.org/series/59002/
- https://patchwork.freedesktop.org/series/61650/

Changes since v1:
- Rebase to the patch in which convert dp_wait_cond() was changed to return -ETIMEDOUT and update d71_disconnect_iommu() to be consistent.
- If connected IOMMU failed, set mdev->iommu as NULL.

Changes since v2:
- Correct the code flow by not returning -ETIMEDOUT if dp_wait_cond() returns zero in d71_connect_iommu().

Thanks,
Lowry

Lowry Li (Arm Technology China) (2):
drm/komeda: Adds SMMU support
dt/bindings: drm/komeda: Adds SMMU support for D71 devicetree

 .../devicetree/bindings/display/arm,komeda.txt     |  7 ++++
 .../gpu/drm/arm/display/komeda/d71/d71_component.c |  5 +++
 drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c   | 49 ++++++++++++++++++++++
 drivers/gpu/drm/arm/display/komeda/komeda_dev.c    | 18 ++++++++
 drivers/gpu/drm/arm/display/komeda/komeda_dev.h    |  7 ++++
 .../drm/arm/display/komeda/komeda_framebuffer.c    |  2 +
 .../drm/arm/display/komeda/komeda_framebuffer.h    |  2 +
 7 files changed, 90 insertions(+)
Signature · 1 line
1.9.1
#1 lore raw

PATCH v3 1/2 drm/komeda: Adds SMMU support

From: "Lowry Li (Arm Technology China)" <[email protected]>

Adds iommu_connect and disconnect for SMMU support, and configures TBU translation once SMMU has been attached to the display device.

---
 .../gpu/drm/arm/display/komeda/d71/d71_component.c |  5 +++
 drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c   | 49 ++++++++++++++++++++++
 drivers/gpu/drm/arm/display/komeda/komeda_dev.c    | 18 ++++++++
 drivers/gpu/drm/arm/display/komeda/komeda_dev.h    |  7 ++++
 .../drm/arm/display/komeda/komeda_framebuffer.c    |  2 +
 .../drm/arm/display/komeda/komeda_framebuffer.h    |  2 +
 6 files changed, 83 insertions(+)
drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +5 -0
index 4e26a80..4a48dd6 100644
@@ -215,6 +215,8 @@ static void d71_layer_update(struct komeda_component *c,
 	malidp_write32(reg, LAYER_FMT, kfb->format_caps->hw_id);
 	malidp_write32(reg, BLK_IN_SIZE, HV_SIZE(st->hsize, st->vsize));
 
+	if (kfb->is_va)
+		ctrl |= L_TBU_EN;
 	malidp_write32_mask(reg, BLK_CONTROL, ctrl_mask, ctrl);
 }
 
@@ -348,6 +350,9 @@ static void d71_wb_layer_update(struct komeda_component *c,
 			       fb->pitches[i] & 0xFFFF);
 	}
 
+	if (kfb->is_va)
+		ctrl |= LW_TBU_EN;
+
 	malidp_write32(reg, LAYER_FMT, kfb->format_caps->hw_id);
 	malidp_write32(reg, BLK_IN_SIZE, HV_SIZE(st->hsize, st->vsize));
 	malidp_write32(reg, BLK_INPUT_ID0, to_d71_input_id(&state->inputs[0]));
drivers/gpu/drm/arm/display/komeda/d71/d71_dev.c +49 -0

61 lines not on this page · raw message

drivers/gpu/drm/arm/display/komeda/komeda_dev.c +18 -0
index c92e161..e80e673 100644
@@ -253,6 +253,19 @@ struct komeda_dev *komeda_dev_create(struct device *dev)
 	dev->dma_parms = &mdev->dma_parms;
 	dma_set_max_seg_size(dev, DMA_BIT_MASK(32));
 
+	mdev->iommu = iommu_get_domain_for_dev(mdev->dev);
+	if (!mdev->iommu)
+		DRM_INFO("continue without IOMMU support!\n");
+
+	if (mdev->iommu && mdev->funcs->connect_iommu) {
+		err = mdev->funcs->connect_iommu(mdev);
+		if (err) {
+			mdev->iommu = NULL;
+			DRM_ERROR("connect iommu failed.\n");
+			goto err_cleanup;
+		}
+	}
+
 	err = sysfs_create_group(&dev->kobj, &komeda_sysfs_attr_group);
 	if (err) {
 		DRM_ERROR("create sysfs group failed.\n");
@@ -282,6 +295,11 @@ void komeda_dev_destroy(struct komeda_dev *mdev)
 	debugfs_remove_recursive(mdev->debugfs_root);
 #endif
 
+	if (mdev->iommu && mdev->funcs->disconnect_iommu)
+		if (mdev->funcs->disconnect_iommu(mdev))
+			DRM_ERROR("disconnect iommu failed.\n");
+	mdev->iommu = NULL;
+
 	for (i = 0; i < mdev->n_pipelines; i++) {
 		komeda_pipeline_destroy(mdev, mdev->pipelines[i]);
 		mdev->pipelines[i] = NULL;
drivers/gpu/drm/arm/display/komeda/komeda_dev.h +7 -0
index 83ace71..dac1eda 100644
@@ -92,6 +92,10 @@ struct komeda_dev_funcs {
 	int (*enum_resources)(struct komeda_dev *mdev);
 	/** @cleanup: call to chip to cleanup komeda_dev->chip data */
 	void (*cleanup)(struct komeda_dev *mdev);
+	/** @connect_iommu: Optional, connect to external iommu */
+	int (*connect_iommu)(struct komeda_dev *mdev);
+	/** @disconnect_iommu: Optional, disconnect to external iommu */
+	int (*disconnect_iommu)(struct komeda_dev *mdev);
 	/**
 	 * @irq_handler:
 	 *
@@ -184,6 +188,9 @@ struct komeda_dev {
 	 */
 	void *chip_data;
 
+	/** @iommu: iommu domain */
+	struct iommu_domain *iommu;
+
 	/** @debugfs_root: root directory of komeda debugfs */
 	struct dentry *debugfs_root;
 };
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +2 -0
index d5822a3..360ab70 100644
@@ -201,6 +201,8 @@ struct drm_framebuffer *
 		goto err_cleanup;
 	}
 
+	kfb->is_va = mdev->iommu ? true : false;
+
 	return &kfb->base;
 
 err_cleanup:
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h +2 -0
index 6cbb2f6..f4046e2 100644
@@ -21,6 +21,8 @@ struct komeda_fb {
 	 * extends drm_format_info for komeda specific information
 	 */
 	const struct komeda_format_caps *format_caps;
+	/** @is_va: if smmu is enabled, it will be true */
+	bool is_va;
 	/** @aligned_w: aligned frame buffer width */
 	u32 aligned_w;
 	/** @aligned_h: aligned frame buffer height */
Signature · 1 line
1.9.1
#2 lore raw

PATCH v3 2/2 dt/bindings: drm/komeda: Adds SMMU support for D71 devicetree

In reply to Lowry Li (Arm Technology China)

From: "Lowry Li (Arm Technology China)" <[email protected]>

Updates the device-tree doc about how to enable SMMU by devicetree.

---
 Documentation/devicetree/bindings/display/arm,komeda.txt | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/display/arm,komeda.txt +7 -0
index 02b2265..b12c045 100644
@@ -11,6 +11,10 @@ Required properties:
       - "pclk": for the APB interface clock
 - #address-cells: Must be 1
 - #size-cells: Must be 0
+- iommus: configure the stream id to IOMMU, Must be configured if want to
+    enable iommu in display. for how to configure this node please reference
+        devicetree/bindings/iommu/arm,smmu-v3.txt,
+        devicetree/bindings/iommu/iommu.txt
 
 Required properties for sub-node: pipeline@nq
 Each device contains one or two pipeline sub-nodes (at least one), each
@@ -44,6 +48,9 @@ Example:
 		interrupts = <0 168 4>;
 		clocks = <&dpu_mclk>, <&dpu_aclk>;
 		clock-names = "mclk", "pclk";
+		iommus = <&smmu 0>, <&smmu 1>, <&smmu 2>, <&smmu 3>,
+			<&smmu 4>, <&smmu 5>, <&smmu 6>, <&smmu 7>,
+			<&smmu 8>, <&smmu 9>;
 
 		dp0_pipe0: pipeline@0 {
 			clocks = <&fpgaosc2>, <&dpu_aclk>;
Signature · 1 line
1.9.1