0588-drm-vc4-Verify-at-boot-that-CMA-doesn-t-cross-a-256M.patch 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. I've seen lots of users cranking CMA up higher, so throw an error if
  7. they do.
  8. Signed-off-by: Eric Anholt <eric@anholt.net>
  9. ---
  10. drivers/base/dma-contiguous.c | 1 +
  11. drivers/gpu/drm/vc4/vc4_v3d.c | 18 ++++++++++++++++++
  12. mm/cma.c | 2 ++
  13. 3 files changed, 21 insertions(+)
  14. --- a/drivers/base/dma-contiguous.c
  15. +++ b/drivers/base/dma-contiguous.c
  16. @@ -35,6 +35,7 @@
  17. #endif
  18. struct cma *dma_contiguous_default_area;
  19. +EXPORT_SYMBOL(dma_contiguous_default_area);
  20. /*
  21. * Default global CMA area size can be defined in kernel's .config.
  22. --- a/drivers/gpu/drm/vc4/vc4_v3d.c
  23. +++ b/drivers/gpu/drm/vc4/vc4_v3d.c
  24. @@ -16,7 +16,10 @@
  25. * this program. If not, see <http://www.gnu.org/licenses/>.
  26. */
  27. +#include "linux/init.h"
  28. +#include "linux/cma.h"
  29. #include "linux/component.h"
  30. +#include "linux/dma-contiguous.h"
  31. #include "linux/pm_runtime.h"
  32. #include "vc4_drv.h"
  33. #include "vc4_regs.h"
  34. @@ -185,8 +188,23 @@ static int vc4_v3d_bind(struct device *d
  35. struct drm_device *drm = dev_get_drvdata(master);
  36. struct vc4_dev *vc4 = to_vc4_dev(drm);
  37. struct vc4_v3d *v3d = NULL;
  38. + struct cma *cma;
  39. int ret;
  40. + cma = dev_get_cma_area(dev);
  41. + if (!cma)
  42. + return -EINVAL;
  43. +
  44. + if ((cma_get_base(cma) & 0xf0000000) !=
  45. + ((cma_get_base(cma) + cma_get_size(cma) - 1) & 0xf0000000)) {
  46. + DRM_ERROR("V3D requires that the CMA area (0x%08lx - 0x%08lx) "
  47. + "not span a 256MB boundary, or memory corruption "
  48. + "would happen.\n",
  49. + (long)cma_get_base(cma),
  50. + cma_get_base(cma) + cma_get_size(cma));
  51. + return -EINVAL;
  52. + }
  53. +
  54. v3d = devm_kzalloc(&pdev->dev, sizeof(*v3d), GFP_KERNEL);
  55. if (!v3d)
  56. return -ENOMEM;
  57. --- a/mm/cma.c
  58. +++ b/mm/cma.c
  59. @@ -47,11 +47,13 @@ phys_addr_t cma_get_base(const struct cm
  60. {
  61. return PFN_PHYS(cma->base_pfn);
  62. }
  63. +EXPORT_SYMBOL(cma_get_base);
  64. unsigned long cma_get_size(const struct cma *cma)
  65. {
  66. return cma->count << PAGE_SHIFT;
  67. }
  68. +EXPORT_SYMBOL(cma_get_size);
  69. static unsigned long cma_bitmap_aligned_mask(const struct cma *cma,
  70. unsigned int align_order)