1 From b280acf3c32746106c81419390f5b1869d644f66 Mon Sep 17 00:00:00 2001
2 From: Eric Anholt <eric@anholt.net>
3 Date: Mon, 12 Oct 2015 08:58:08 -0700
4 Subject: [PATCH] drm/vc4: Verify at boot that CMA doesn't cross a 256MB
7 I've seen lots of users cranking CMA up higher, so throw an error if
10 Signed-off-by: Eric Anholt <eric@anholt.net>
12 drivers/base/dma-contiguous.c | 1 +
13 drivers/gpu/drm/vc4/vc4_v3d.c | 18 ++++++++++++++++++
15 3 files changed, 21 insertions(+)
17 --- a/drivers/base/dma-contiguous.c
18 +++ b/drivers/base/dma-contiguous.c
22 struct cma *dma_contiguous_default_area;
23 +EXPORT_SYMBOL(dma_contiguous_default_area);
26 * Default global CMA area size can be defined in kernel's .config.
27 --- a/drivers/gpu/drm/vc4/vc4_v3d.c
28 +++ b/drivers/gpu/drm/vc4/vc4_v3d.c
30 * this program. If not, see <http://www.gnu.org/licenses/>.
33 +#include "linux/init.h"
34 +#include "linux/cma.h"
35 #include "linux/component.h"
36 +#include "linux/dma-contiguous.h"
37 #include "linux/pm_runtime.h"
40 @@ -185,8 +188,23 @@ static int vc4_v3d_bind(struct device *d
41 struct drm_device *drm = dev_get_drvdata(master);
42 struct vc4_dev *vc4 = to_vc4_dev(drm);
43 struct vc4_v3d *v3d = NULL;
47 + cma = dev_get_cma_area(dev);
51 + if ((cma_get_base(cma) & 0xf0000000) !=
52 + ((cma_get_base(cma) + cma_get_size(cma) - 1) & 0xf0000000)) {
53 + DRM_ERROR("V3D requires that the CMA area (0x%08lx - 0x%08lx) "
54 + "not span a 256MB boundary, or memory corruption "
56 + (long)cma_get_base(cma),
57 + cma_get_base(cma) + cma_get_size(cma));
61 v3d = devm_kzalloc(&pdev->dev, sizeof(*v3d), GFP_KERNEL);
66 @@ -47,11 +47,13 @@ phys_addr_t cma_get_base(const struct cm
68 return PFN_PHYS(cma->base_pfn);
70 +EXPORT_SYMBOL(cma_get_base);
72 unsigned long cma_get_size(const struct cma *cma)
74 return cma->count << PAGE_SHIFT;
76 +EXPORT_SYMBOL(cma_get_size);
78 static unsigned long cma_bitmap_aligned_mask(const struct cma *cma,