hc
2023-11-06 e3e12f52b214121840b44c91de5b3e5af5d3eb84
kernel/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
....@@ -63,6 +63,7 @@
6363 #else
6464 static bool is_support_iommu = true;
6565 #endif
66
+static bool iommu_reserve_map;
6667 static struct drm_driver rockchip_drm_driver;
6768
6869 struct rockchip_drm_mode_set {
....@@ -1320,6 +1321,7 @@
13201321 struct rockchip_drm_private *private = drm_dev->dev_private;
13211322 struct iommu_domain_geometry *geometry;
13221323 u64 start, end;
1324
+ int ret = 0;
13231325
13241326 if (!is_support_iommu)
13251327 return 0;
....@@ -1340,7 +1342,23 @@
13401342 iommu_set_fault_handler(private->domain, rockchip_drm_fault_handler,
13411343 drm_dev);
13421344
1343
- return 0;
1345
+ if (iommu_reserve_map) {
1346
+ /*
1347
+ * At 32 bit platform size_t maximum value is 0xffffffff, SZ_4G(0x100000000) will be
1348
+ * cliped to 0, so we split into two mapping
1349
+ */
1350
+ ret = iommu_map(private->domain, 0, 0, (size_t)SZ_2G,
1351
+ IOMMU_WRITE | IOMMU_READ | IOMMU_PRIV);
1352
+ if (ret)
1353
+ dev_err(drm_dev->dev, "failed to create 0-2G pre mapping\n");
1354
+
1355
+ ret = iommu_map(private->domain, SZ_2G, SZ_2G, (size_t)SZ_2G,
1356
+ IOMMU_WRITE | IOMMU_READ | IOMMU_PRIV);
1357
+ if (ret)
1358
+ dev_err(drm_dev->dev, "failed to create 2G-4G pre mapping\n");
1359
+ }
1360
+
1361
+ return ret;
13441362 }
13451363
13461364 static void rockchip_iommu_cleanup(struct drm_device *drm_dev)
....@@ -1350,6 +1368,10 @@
13501368 if (!is_support_iommu)
13511369 return;
13521370
1371
+ if (iommu_reserve_map) {
1372
+ iommu_unmap(private->domain, 0, (size_t)SZ_2G);
1373
+ iommu_unmap(private->domain, SZ_2G, (size_t)SZ_2G);
1374
+ }
13531375 drm_mm_takedown(&private->mm);
13541376 iommu_domain_free(private->domain);
13551377 }
....@@ -1765,16 +1787,14 @@
17651787 if (ret)
17661788 goto err_kms_helper_poll_fini;
17671789
1768
- drm_for_each_crtc(crtc, drm_dev) {
1769
- struct drm_fb_helper *helper = private->fbdev_helper;
1770
- struct rockchip_crtc_state *s = NULL;
1790
+ if (private->fbdev_helper && private->fbdev_helper->fb) {
1791
+ drm_for_each_crtc(crtc, drm_dev) {
1792
+ struct rockchip_crtc_state *s = NULL;
17711793
1772
- if (!helper)
1773
- break;
1774
-
1775
- s = to_rockchip_crtc_state(crtc->state);
1776
- if (is_support_hotplug(s->output_type))
1777
- drm_framebuffer_get(helper->fb);
1794
+ s = to_rockchip_crtc_state(crtc->state);
1795
+ if (is_support_hotplug(s->output_type))
1796
+ drm_framebuffer_get(private->fbdev_helper->fb);
1797
+ }
17781798 }
17791799
17801800 drm_dev->mode_config.allow_fb_modifiers = true;
....@@ -2303,6 +2323,7 @@
23032323 }
23042324
23052325 found = true;
2326
+ iommu_reserve_map |= of_property_read_bool(iommu, "rockchip,reserve-map");
23062327
23072328 of_node_put(iommu);
23082329 of_node_put(port);