]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
drm/vc4: Verify at boot that CMA doesn't cross a 256MB boundary.
authorEric Anholt <eric@anholt.net>
Mon, 12 Oct 2015 15:58:08 +0000 (08:58 -0700)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Tue, 19 Sep 2017 10:07:55 +0000 (12:07 +0200)
I've seen lots of users cranking CMA up higher, so throw an error if
they do.

Signed-off-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
drivers/base/dma-contiguous.c
drivers/gpu/drm/vc4/vc4_v3d.c
mm/cma.c

index e167a1e1bccb062efef2595fcd5299301a97df80..60f5c2591ccdb0202461458eab4035cfba731b8b 100644 (file)
@@ -35,6 +35,7 @@
 #endif
 
 struct cma *dma_contiguous_default_area;
+EXPORT_SYMBOL(dma_contiguous_default_area);
 
 /*
  * Default global CMA area size can be defined in kernel's .config.
index 7cc346ad9b0baed63701d1fae8f0306aa7713129..1d9e5a6edd22c29ce8b2990c9c35627aa1af2bd8 100644 (file)
  * this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "linux/init.h"
+#include "linux/cma.h"
 #include "linux/component.h"
+#include "linux/dma-contiguous.h"
 #include "linux/pm_runtime.h"
 #include "vc4_drv.h"
 #include "vc4_regs.h"
@@ -185,8 +188,23 @@ static int vc4_v3d_bind(struct device *dev, struct device *master, void *data)
        struct drm_device *drm = dev_get_drvdata(master);
        struct vc4_dev *vc4 = to_vc4_dev(drm);
        struct vc4_v3d *v3d = NULL;
+       struct cma *cma;
        int ret;
 
+       cma = dev_get_cma_area(dev);
+       if (!cma)
+               return -EINVAL;
+
+       if ((cma_get_base(cma) & 0xf0000000) !=
+           ((cma_get_base(cma) + cma_get_size(cma) - 1) & 0xf0000000)) {
+               DRM_ERROR("V3D requires that the CMA area (0x%08lx - 0x%08lx) "
+                         "not span a 256MB boundary, or memory corruption "
+                         "would happen.\n",
+                         (long)cma_get_base(cma),
+                         cma_get_base(cma) + cma_get_size(cma));
+               return -EINVAL;
+       }
+
        v3d = devm_kzalloc(&pdev->dev, sizeof(*v3d), GFP_KERNEL);
        if (!v3d)
                return -ENOMEM;
index c960459eda7e640ea55be1d4ed80c6a9125a8877..b50245282a18bc790da0f901944c2e670ffac2d2 100644 (file)
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -47,11 +47,13 @@ phys_addr_t cma_get_base(const struct cma *cma)
 {
        return PFN_PHYS(cma->base_pfn);
 }
+EXPORT_SYMBOL(cma_get_base);
 
 unsigned long cma_get_size(const struct cma *cma)
 {
        return cma->count << PAGE_SHIFT;
 }
+EXPORT_SYMBOL(cma_get_size);
 
 static unsigned long cma_bitmap_aligned_mask(const struct cma *cma,
                                             int align_order)