brcm2708: update linux 4.4 patches to latest version
[openwrt/staging/chunkeey.git] / target / linux / brcm2708 / patches-4.4 / 0588-drm-vc4-Verify-at-boot-that-CMA-doesn-t-cross-a-256M.patch
1 From bf4b7e8817115f839241e55add244cf60225e436 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
5 boundary.
6
7 I've seen lots of users cranking CMA up higher, so throw an error if
8 they do.
9
10 Signed-off-by: Eric Anholt <eric@anholt.net>
11 ---
12 drivers/base/dma-contiguous.c | 1 +
13 drivers/gpu/drm/vc4/vc4_v3d.c | 18 ++++++++++++++++++
14 mm/cma.c | 2 ++
15 3 files changed, 21 insertions(+)
16
17 diff --git a/drivers/base/dma-contiguous.c b/drivers/base/dma-contiguous.c
18 index e167a1e1..60f5c25 100644
19 --- a/drivers/base/dma-contiguous.c
20 +++ b/drivers/base/dma-contiguous.c
21 @@ -35,6 +35,7 @@
22 #endif
23
24 struct cma *dma_contiguous_default_area;
25 +EXPORT_SYMBOL(dma_contiguous_default_area);
26
27 /*
28 * Default global CMA area size can be defined in kernel's .config.
29 diff --git a/drivers/gpu/drm/vc4/vc4_v3d.c b/drivers/gpu/drm/vc4/vc4_v3d.c
30 index 7cc346a..1d9e5a6 100644
31 --- a/drivers/gpu/drm/vc4/vc4_v3d.c
32 +++ b/drivers/gpu/drm/vc4/vc4_v3d.c
33 @@ -16,7 +16,10 @@
34 * this program. If not, see <http://www.gnu.org/licenses/>.
35 */
36
37 +#include "linux/init.h"
38 +#include "linux/cma.h"
39 #include "linux/component.h"
40 +#include "linux/dma-contiguous.h"
41 #include "linux/pm_runtime.h"
42 #include "vc4_drv.h"
43 #include "vc4_regs.h"
44 @@ -185,8 +188,23 @@ static int vc4_v3d_bind(struct device *dev, struct device *master, void *data)
45 struct drm_device *drm = dev_get_drvdata(master);
46 struct vc4_dev *vc4 = to_vc4_dev(drm);
47 struct vc4_v3d *v3d = NULL;
48 + struct cma *cma;
49 int ret;
50
51 + cma = dev_get_cma_area(dev);
52 + if (!cma)
53 + return -EINVAL;
54 +
55 + if ((cma_get_base(cma) & 0xf0000000) !=
56 + ((cma_get_base(cma) + cma_get_size(cma) - 1) & 0xf0000000)) {
57 + DRM_ERROR("V3D requires that the CMA area (0x%08lx - 0x%08lx) "
58 + "not span a 256MB boundary, or memory corruption "
59 + "would happen.\n",
60 + (long)cma_get_base(cma),
61 + cma_get_base(cma) + cma_get_size(cma));
62 + return -EINVAL;
63 + }
64 +
65 v3d = devm_kzalloc(&pdev->dev, sizeof(*v3d), GFP_KERNEL);
66 if (!v3d)
67 return -ENOMEM;
68 diff --git a/mm/cma.c b/mm/cma.c
69 index bd0e141..efac29b 100644
70 --- a/mm/cma.c
71 +++ b/mm/cma.c
72 @@ -47,11 +47,13 @@ phys_addr_t cma_get_base(const struct cma *cma)
73 {
74 return PFN_PHYS(cma->base_pfn);
75 }
76 +EXPORT_SYMBOL(cma_get_base);
77
78 unsigned long cma_get_size(const struct cma *cma)
79 {
80 return cma->count << PAGE_SHIFT;
81 }
82 +EXPORT_SYMBOL(cma_get_size);
83
84 static unsigned long cma_bitmap_aligned_mask(const struct cma *cma,
85 int align_order)
86 --
87 2.1.4
88