+static void
+vc4_screen_query_dmabuf_modifiers(struct pipe_screen *pscreen,
+ enum pipe_format format, int max,
+ uint64_t *modifiers,
+ unsigned int *external_only,
+ int *count)
+{
+ int m, i;
+ uint64_t available_modifiers[] = {
+ DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED,
+ DRM_FORMAT_MOD_LINEAR,
+ };
+ struct vc4_screen *screen = vc4_screen(pscreen);
+ int num_modifiers = screen->has_tiling_ioctl ? 2 : 1;
+
+ if (!modifiers) {
+ *count = num_modifiers;
+ return;
+ }
+
+ *count = MIN2(max, num_modifiers);
+ m = screen->has_tiling_ioctl ? 0 : 1;
+ /* We support both modifiers (tiled and linear) for all sampler
+ * formats, but if we don't have the DRM_VC4_GET_TILING ioctl
+ * we shouldn't advertise the tiled formats.
+ */
+ for (i = 0; i < *count; i++) {
+ modifiers[i] = available_modifiers[m++];
+ if (external_only)
+ external_only[i] = false;
+ }
+}
+
+#define PTR_TO_UINT(x) ((unsigned)((intptr_t)(x)))
+
+static unsigned handle_hash(void *key)
+{
+ return PTR_TO_UINT(key);
+}
+
+static int handle_compare(void *key1, void *key2)
+{
+ return PTR_TO_UINT(key1) != PTR_TO_UINT(key2);
+}
+
+static bool
+vc4_has_feature(struct vc4_screen *screen, uint32_t feature)
+{
+ struct drm_vc4_get_param p = {
+ .param = feature,
+ };
+ int ret = vc4_ioctl(screen->fd, DRM_IOCTL_VC4_GET_PARAM, &p);
+
+ if (ret != 0)
+ return false;
+
+ return p.value;
+}
+
+static bool
+vc4_get_chip_info(struct vc4_screen *screen)
+{
+ struct drm_vc4_get_param ident0 = {
+ .param = DRM_VC4_PARAM_V3D_IDENT0,
+ };
+ struct drm_vc4_get_param ident1 = {
+ .param = DRM_VC4_PARAM_V3D_IDENT1,
+ };
+ int ret;
+
+ ret = vc4_ioctl(screen->fd, DRM_IOCTL_VC4_GET_PARAM, &ident0);
+ if (ret != 0) {
+ if (errno == EINVAL) {
+ /* Backwards compatibility with 2835 kernels which
+ * only do V3D 2.1.
+ */
+ screen->v3d_ver = 21;
+ return true;
+ } else {
+ fprintf(stderr, "Couldn't get V3D IDENT0: %s\n",
+ strerror(errno));
+ return false;
+ }
+ }
+ ret = vc4_ioctl(screen->fd, DRM_IOCTL_VC4_GET_PARAM, &ident1);
+ if (ret != 0) {
+ fprintf(stderr, "Couldn't get V3D IDENT1: %s\n",
+ strerror(errno));
+ return false;
+ }
+
+ uint32_t major = (ident0.value >> 24) & 0xff;
+ uint32_t minor = (ident1.value >> 0) & 0xf;
+ screen->v3d_ver = major * 10 + minor;
+
+ if (screen->v3d_ver != 21 && screen->v3d_ver != 26) {
+ fprintf(stderr,
+ "V3D %d.%d not supported by this version of Mesa.\n",
+ screen->v3d_ver / 10,
+ screen->v3d_ver % 10);
+ return false;
+ }
+
+ return true;
+}
+