0475-drm-vc4-Add-a-getparam-ioctl-for-getting-the-V3D-ide.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. From 03f4e4a6e625306671266db609b4f4d488b6cf6d Mon Sep 17 00:00:00 2001
  2. From: Eric Anholt <eric@anholt.net>
  3. Date: Fri, 1 Jul 2016 13:10:38 -0700
  4. Subject: [PATCH] drm/vc4: Add a getparam ioctl for getting the V3D identity
  5. regs.
  6. As I extend the driver to support different V3D revisions, userspace
  7. needs to know what version it's targeting. This is most easily
  8. detected using the V3D identity registers.
  9. v2: Make sure V3D is runtime PM on when reading the registers.
  10. v3: Switch to a 64-bit param value (suggested by Rob Clark in review)
  11. Signed-off-by: Eric Anholt <eric@anholt.net>
  12. Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch> (v2)
  13. Reviewed-by: Rob Clark <robdclark@gmail.com> (v3, over irc)
  14. (cherry picked from commit af713795c59fea36161a7debf97dbc10bf652cf7)
  15. v4: Squashed in "drm/vc4: Fix handling of a pm_runtime_get_sync() success case."
  16. ---
  17. drivers/gpu/drm/vc4/vc4_drv.c | 42 ++++++++++++++++++++++++++++++++++++++++++
  18. include/uapi/drm/vc4_drm.h | 12 ++++++++++++
  19. 2 files changed, 54 insertions(+)
  20. --- a/drivers/gpu/drm/vc4/vc4_drv.c
  21. +++ b/drivers/gpu/drm/vc4/vc4_drv.c
  22. @@ -15,6 +15,7 @@
  23. #include <linux/module.h>
  24. #include <linux/of_platform.h>
  25. #include <linux/platform_device.h>
  26. +#include <linux/pm_runtime.h>
  27. #include "drm_fb_cma_helper.h"
  28. #include "uapi/drm/vc4_drm.h"
  29. @@ -64,6 +65,46 @@ void vc4_dump_regs32(const struct debugf
  30. }
  31. }
  32. +static int vc4_get_param_ioctl(struct drm_device *dev, void *data,
  33. + struct drm_file *file_priv)
  34. +{
  35. + struct vc4_dev *vc4 = to_vc4_dev(dev);
  36. + struct drm_vc4_get_param *args = data;
  37. + int ret;
  38. +
  39. + if (args->pad != 0)
  40. + return -EINVAL;
  41. +
  42. + switch (args->param) {
  43. + case DRM_VC4_PARAM_V3D_IDENT0:
  44. + ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
  45. + if (ret < 0)
  46. + return ret;
  47. + args->value = V3D_READ(V3D_IDENT0);
  48. + pm_runtime_put(&vc4->v3d->pdev->dev);
  49. + break;
  50. + case DRM_VC4_PARAM_V3D_IDENT1:
  51. + ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
  52. + if (ret < 0)
  53. + return ret;
  54. + args->value = V3D_READ(V3D_IDENT1);
  55. + pm_runtime_put(&vc4->v3d->pdev->dev);
  56. + break;
  57. + case DRM_VC4_PARAM_V3D_IDENT2:
  58. + ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
  59. + if (ret < 0)
  60. + return ret;
  61. + args->value = V3D_READ(V3D_IDENT2);
  62. + pm_runtime_put(&vc4->v3d->pdev->dev);
  63. + break;
  64. + default:
  65. + DRM_DEBUG("Unknown parameter %d\n", args->param);
  66. + return -EINVAL;
  67. + }
  68. +
  69. + return 0;
  70. +}
  71. +
  72. static void vc4_lastclose(struct drm_device *dev)
  73. {
  74. struct vc4_dev *vc4 = to_vc4_dev(dev);
  75. @@ -95,6 +136,7 @@ static const struct drm_ioctl_desc vc4_d
  76. DRM_IOCTL_DEF_DRV(VC4_CREATE_SHADER_BO, vc4_create_shader_bo_ioctl, DRM_RENDER_ALLOW),
  77. DRM_IOCTL_DEF_DRV(VC4_GET_HANG_STATE, vc4_get_hang_state_ioctl,
  78. DRM_ROOT_ONLY),
  79. + DRM_IOCTL_DEF_DRV(VC4_GET_PARAM, vc4_get_param_ioctl, DRM_RENDER_ALLOW),
  80. };
  81. static struct drm_driver vc4_drm_driver = {
  82. --- a/include/uapi/drm/vc4_drm.h
  83. +++ b/include/uapi/drm/vc4_drm.h
  84. @@ -37,6 +37,7 @@ extern "C" {
  85. #define DRM_VC4_MMAP_BO 0x04
  86. #define DRM_VC4_CREATE_SHADER_BO 0x05
  87. #define DRM_VC4_GET_HANG_STATE 0x06
  88. +#define DRM_VC4_GET_PARAM 0x07
  89. #define DRM_IOCTL_VC4_SUBMIT_CL DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_SUBMIT_CL, struct drm_vc4_submit_cl)
  90. #define DRM_IOCTL_VC4_WAIT_SEQNO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_WAIT_SEQNO, struct drm_vc4_wait_seqno)
  91. @@ -45,6 +46,7 @@ extern "C" {
  92. #define DRM_IOCTL_VC4_MMAP_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_MMAP_BO, struct drm_vc4_mmap_bo)
  93. #define DRM_IOCTL_VC4_CREATE_SHADER_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_CREATE_SHADER_BO, struct drm_vc4_create_shader_bo)
  94. #define DRM_IOCTL_VC4_GET_HANG_STATE DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_HANG_STATE, struct drm_vc4_get_hang_state)
  95. +#define DRM_IOCTL_VC4_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_PARAM, struct drm_vc4_get_param)
  96. struct drm_vc4_submit_rcl_surface {
  97. __u32 hindex; /* Handle index, or ~0 if not present. */
  98. @@ -280,6 +282,16 @@ struct drm_vc4_get_hang_state {
  99. __u32 pad[16];
  100. };
  101. +#define DRM_VC4_PARAM_V3D_IDENT0 0
  102. +#define DRM_VC4_PARAM_V3D_IDENT1 1
  103. +#define DRM_VC4_PARAM_V3D_IDENT2 2
  104. +
  105. +struct drm_vc4_get_param {
  106. + __u32 param;
  107. + __u32 pad;
  108. + __u64 value;
  109. +};
  110. +
  111. #if defined(__cplusplus)
  112. }
  113. #endif