As I extend the driver to support different V3D revisions, userspace needs to know what version it's targeting. This is most easily detected using the V3D identity registers. v2: Make sure V3D is runtime PM on when reading the registers. v3: Switch to a 64-bit param value (suggested by Rob Clark in review)
Unified · Split
| @@ -14,6 +14,7 @@ · 13 unmodified lines | |||
| 14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
| 15 | #include <linux/of_platform.h> | 15 | #include <linux/of_platform.h> |
| 16 | #include <linux/platform_device.h> | 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/pm_runtime.h> | ||
| 17 | #include "drm_fb_cma_helper.h" | 18 | #include "drm_fb_cma_helper.h" |
| 18 | 19 | ||
| 19 | #include "uapi/drm/vc4_drm.h" | 20 | #include "uapi/drm/vc4_drm.h" |
| @@ -43,6 +44,46 @@ void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index) · 23 unmodified lines | |||
| 43 | return map; | 44 | return map; |
| 44 | } | 45 | } |
| 45 | 46 | ||
| 47 | static int vc4_get_param_ioctl(struct drm_device *dev, void *data, | ||
| 48 | struct drm_file *file_priv) | ||
| 49 | { | ||
| 50 | struct vc4_dev *vc4 = to_vc4_dev(dev); | ||
| 51 | struct drm_vc4_get_param *args = data; | ||
| 52 | int ret; | ||
| 53 | |||
| 54 | if (args->pad != 0) | ||
| 55 | return -EINVAL; | ||
| 56 | |||
| 57 | switch (args->param) { | ||
| 58 | case DRM_VC4_PARAM_V3D_IDENT0: | ||
| 59 | ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev); | ||
| 60 | if (ret) | ||
| 61 | return ret; | ||
| 62 | args->value = V3D_READ(V3D_IDENT0); | ||
| 63 | pm_runtime_put(&vc4->v3d->pdev->dev); | ||
| 64 | break; | ||
| 65 | case DRM_VC4_PARAM_V3D_IDENT1: | ||
| 66 | ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev); | ||
| 67 | if (ret) | ||
| 68 | return ret; | ||
| 69 | args->value = V3D_READ(V3D_IDENT1); | ||
| 70 | pm_runtime_put(&vc4->v3d->pdev->dev); | ||
| 71 | break; | ||
| 72 | case DRM_VC4_PARAM_V3D_IDENT2: | ||
| 73 | ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev); | ||
| 74 | if (ret) | ||
| 75 | return ret; | ||
| 76 | args->value = V3D_READ(V3D_IDENT2); | ||
| 77 | pm_runtime_put(&vc4->v3d->pdev->dev); | ||
| 78 | break; | ||
| 79 | default: | ||
| 80 | DRM_DEBUG("Unknown parameter %d\n", args->param); | ||
| 81 | return -EINVAL; | ||
| 82 | } | ||
| 83 | |||
| 84 | return 0; | ||
| 85 | } | ||
| 86 | |||
| 46 | static void vc4_lastclose(struct drm_device *dev) | 87 | static void vc4_lastclose(struct drm_device *dev) |
| 47 | { | 88 | { |
| 48 | struct vc4_dev *vc4 = to_vc4_dev(dev); | 89 | struct vc4_dev *vc4 = to_vc4_dev(dev); |
| @@ -74,6 +115,7 @@ static const struct drm_ioctl_desc vc4_drm_ioctls[] = { · 25 unmodified lines | |||
| 74 | DRM_IOCTL_DEF_DRV(VC4_CREATE_SHADER_BO, vc4_create_shader_bo_ioctl, DRM_RENDER_ALLOW), | 115 | DRM_IOCTL_DEF_DRV(VC4_CREATE_SHADER_BO, vc4_create_shader_bo_ioctl, DRM_RENDER_ALLOW), |
| 75 | DRM_IOCTL_DEF_DRV(VC4_GET_HANG_STATE, vc4_get_hang_state_ioctl, | 116 | DRM_IOCTL_DEF_DRV(VC4_GET_HANG_STATE, vc4_get_hang_state_ioctl, |
| 76 | DRM_ROOT_ONLY), | 117 | DRM_ROOT_ONLY), |
| 118 | DRM_IOCTL_DEF_DRV(VC4_GET_PARAM, vc4_get_param_ioctl, DRM_RENDER_ALLOW), | ||
| 77 | }; | 119 | }; |
| 78 | 120 | ||
| 79 | static struct drm_driver vc4_drm_driver = { | 121 | static struct drm_driver vc4_drm_driver = { |
| @@ -37,6 +37,7 @@ extern "C" { · 36 unmodified lines | |||
| 37 | #define DRM_VC4_MMAP_BO 0x04 | 37 | #define DRM_VC4_MMAP_BO 0x04 |
| 38 | #define DRM_VC4_CREATE_SHADER_BO 0x05 | 38 | #define DRM_VC4_CREATE_SHADER_BO 0x05 |
| 39 | #define DRM_VC4_GET_HANG_STATE 0x06 | 39 | #define DRM_VC4_GET_HANG_STATE 0x06 |
| 40 | #define DRM_VC4_GET_PARAM 0x07 | ||
| 40 | 41 | ||
| 41 | #define DRM_IOCTL_VC4_SUBMIT_CL DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_SUBMIT_CL, struct drm_vc4_submit_cl) | 42 | #define DRM_IOCTL_VC4_SUBMIT_CL DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_SUBMIT_CL, struct drm_vc4_submit_cl) |
| 42 | #define DRM_IOCTL_VC4_WAIT_SEQNO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_WAIT_SEQNO, struct drm_vc4_wait_seqno) | 43 | #define DRM_IOCTL_VC4_WAIT_SEQNO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_WAIT_SEQNO, struct drm_vc4_wait_seqno) |
| @@ -45,6 +46,7 @@ extern "C" { · 2 unmodified lines | |||
| 45 | #define DRM_IOCTL_VC4_MMAP_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_MMAP_BO, struct drm_vc4_mmap_bo) | 46 | #define DRM_IOCTL_VC4_MMAP_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_MMAP_BO, struct drm_vc4_mmap_bo) |
| 46 | #define DRM_IOCTL_VC4_CREATE_SHADER_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_CREATE_SHADER_BO, struct drm_vc4_create_shader_bo) | 47 | #define DRM_IOCTL_VC4_CREATE_SHADER_BO DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_CREATE_SHADER_BO, struct drm_vc4_create_shader_bo) |
| 47 | #define DRM_IOCTL_VC4_GET_HANG_STATE DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_HANG_STATE, struct drm_vc4_get_hang_state) | 48 | #define DRM_IOCTL_VC4_GET_HANG_STATE DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_HANG_STATE, struct drm_vc4_get_hang_state) |
| 49 | #define DRM_IOCTL_VC4_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_VC4_GET_PARAM, struct drm_vc4_get_param) | ||
| 48 | 50 | ||
| 49 | struct drm_vc4_submit_rcl_surface { | 51 | struct drm_vc4_submit_rcl_surface { |
| 50 | __u32 hindex; /* Handle index, or ~0 if not present. */ | 52 | __u32 hindex; /* Handle index, or ~0 if not present. */ |
| @@ -280,6 +282,16 @@ struct drm_vc4_get_hang_state { · 229 unmodified lines | |||
| 280 | __u32 pad[16]; | 282 | __u32 pad[16]; |
| 281 | }; | 283 | }; |
| 282 | 284 | ||
| 285 | #define DRM_VC4_PARAM_V3D_IDENT0 0 | ||
| 286 | #define DRM_VC4_PARAM_V3D_IDENT1 1 | ||
| 287 | #define DRM_VC4_PARAM_V3D_IDENT2 2 | ||
| 288 | |||
| 289 | struct drm_vc4_get_param { | ||
| 290 | __u32 param; | ||
| 291 | __u32 pad; | ||
| 292 | __u64 value; | ||
| 293 | }; | ||
| 294 | |||
| 283 | #if defined(__cplusplus) | 295 | #if defined(__cplusplus) |
| 284 | } | 296 | } |
| 285 | #endif | 297 | #endif |