@@ -58,7 +58,7 @@ static inline void clear_dma_max_seg_size(struct device *dev)
5858 * mapping.
5959 */
6060static int drm_iommu_attach_device (struct drm_device * drm_dev ,
61- struct device * subdrv_dev )
61+ struct device * subdrv_dev , void * * dma_priv )
6262{
6363 struct exynos_drm_private * priv = drm_dev -> dev_private ;
6464 int ret ;
@@ -74,7 +74,14 @@ static int drm_iommu_attach_device(struct drm_device *drm_dev,
7474 return ret ;
7575
7676 if (IS_ENABLED (CONFIG_ARM_DMA_USE_IOMMU )) {
77- if (to_dma_iommu_mapping (subdrv_dev ))
77+ /*
78+ * Keep the original DMA mapping of the sub-device and
79+ * restore it on Exynos DRM detach, otherwise the DMA
80+ * framework considers it as IOMMU-less during the next
81+ * probe (in case of deferred probe or modular build)
82+ */
83+ * dma_priv = to_dma_iommu_mapping (subdrv_dev );
84+ if (* dma_priv )
7885 arm_iommu_detach_device (subdrv_dev );
7986
8087 ret = arm_iommu_attach_device (subdrv_dev , priv -> mapping );
@@ -98,19 +105,21 @@ static int drm_iommu_attach_device(struct drm_device *drm_dev,
98105 * mapping
99106 */
100107static void drm_iommu_detach_device (struct drm_device * drm_dev ,
101- struct device * subdrv_dev )
108+ struct device * subdrv_dev , void * * dma_priv )
102109{
103110 struct exynos_drm_private * priv = drm_dev -> dev_private ;
104111
105- if (IS_ENABLED (CONFIG_ARM_DMA_USE_IOMMU ))
112+ if (IS_ENABLED (CONFIG_ARM_DMA_USE_IOMMU )) {
106113 arm_iommu_detach_device (subdrv_dev );
107- else if (IS_ENABLED (CONFIG_IOMMU_DMA ))
114+ arm_iommu_attach_device (subdrv_dev , * dma_priv );
115+ } else if (IS_ENABLED (CONFIG_IOMMU_DMA ))
108116 iommu_detach_device (priv -> mapping , subdrv_dev );
109117
110118 clear_dma_max_seg_size (subdrv_dev );
111119}
112120
113- int exynos_drm_register_dma (struct drm_device * drm , struct device * dev )
121+ int exynos_drm_register_dma (struct drm_device * drm , struct device * dev ,
122+ void * * dma_priv )
114123{
115124 struct exynos_drm_private * priv = drm -> dev_private ;
116125
@@ -137,13 +146,14 @@ int exynos_drm_register_dma(struct drm_device *drm, struct device *dev)
137146 priv -> mapping = mapping ;
138147 }
139148
140- return drm_iommu_attach_device (drm , dev );
149+ return drm_iommu_attach_device (drm , dev , dma_priv );
141150}
142151
143- void exynos_drm_unregister_dma (struct drm_device * drm , struct device * dev )
152+ void exynos_drm_unregister_dma (struct drm_device * drm , struct device * dev ,
153+ void * * dma_priv )
144154{
145155 if (IS_ENABLED (CONFIG_EXYNOS_IOMMU ))
146- drm_iommu_detach_device (drm , dev );
156+ drm_iommu_detach_device (drm , dev , dma_priv );
147157}
148158
149159void exynos_drm_cleanup_dma (struct drm_device * drm )
0 commit comments