OSDN Git Service

minigbm: mediatek: Implement bo_create_with_modifiers
authorFritz Koenig <frkoenig@google.com>
Tue, 19 Mar 2019 20:25:45 +0000 (13:25 -0700)
committerchrome-bot <chrome-bot@chromium.org>
Tue, 2 Apr 2019 18:09:54 +0000 (11:09 -0700)
Mediatek MT8183 only supports DRM_FORMAT_MOD_LINEAR.

BUG=b:123042223, b:129645475
TEST=null_platform_test -m DRM_FORMAT_MOD_LINEAR

Change-Id: I1938e52a9b221f25b62ddd27916a2222be8c0a46
Reviewed-on: https://chromium-review.googlesource.com/1529226
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Fritz Koenig <frkoenig@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
helpers.c
helpers.h
mediatek.c
rockchip.c

index d2dab50..b18cd6a 100644 (file)
--- a/helpers.c
+++ b/helpers.c
@@ -6,7 +6,6 @@
 
 #include <assert.h>
 #include <errno.h>
-#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -670,3 +669,16 @@ uint64_t drv_pick_modifier(const uint64_t *modifiers, uint32_t count,
 
        return DRM_FORMAT_MOD_LINEAR;
 }
+
+/*
+ * Search a list of modifiers to see if a given modifier is present
+ */
+bool drv_has_modifier(const uint64_t *list, uint32_t count, uint64_t modifier)
+{
+       uint32_t i;
+       for (i = 0; i < count; i++)
+               if (list[i] == modifier)
+                       return true;
+
+       return false;
+}
index 4f68c3b..c09d2c2 100644 (file)
--- a/helpers.h
+++ b/helpers.h
@@ -7,6 +7,8 @@
 #ifndef HELPERS_H
 #define HELPERS_H
 
+#include <stdbool.h>
+
 #include "drv.h"
 #include "helpers_array.h"
 
@@ -35,4 +37,5 @@ struct drv_array *drv_query_kms(struct driver *drv);
 int drv_modify_linear_combinations(struct driver *drv);
 uint64_t drv_pick_modifier(const uint64_t *modifiers, uint32_t count,
                           const uint64_t *modifier_order, uint32_t order_count);
+bool drv_has_modifier(const uint64_t *list, uint32_t count, uint64_t modifier);
 #endif
index 5edb629..6706fdf 100644 (file)
@@ -60,14 +60,21 @@ static int mediatek_init(struct driver *drv)
        return drv_modify_linear_combinations(drv);
 }
 
-static int mediatek_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
-                             uint64_t use_flags)
+static int mediatek_bo_create_with_modifiers(struct bo *bo, uint32_t width, uint32_t height,
+                                            uint32_t format, const uint64_t *modifiers,
+                                            uint32_t count)
 {
        int ret;
        size_t plane;
        uint32_t stride;
        struct drm_mtk_gem_create gem_create;
 
+       if (!drv_has_modifier(modifiers, count, DRM_FORMAT_MOD_LINEAR)) {
+               errno = EINVAL;
+               drv_log("no usable modifier found\n");
+               return -EINVAL;
+       }
+
        /*
         * Since the ARM L1 cache line size is 64 bytes, align to that as a
         * performance optimization.
@@ -91,6 +98,14 @@ static int mediatek_bo_create(struct bo *bo, uint32_t width, uint32_t height, ui
        return 0;
 }
 
+static int mediatek_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format,
+                             uint64_t use_flags)
+{
+       uint64_t modifiers[] = { DRM_FORMAT_MOD_LINEAR };
+       return mediatek_bo_create_with_modifiers(bo, width, height, format, modifiers,
+                                                ARRAY_SIZE(modifiers));
+}
+
 static void *mediatek_bo_map(struct bo *bo, struct vma *vma, size_t plane, uint32_t map_flags)
 {
        int ret, prime_fd;
@@ -200,6 +215,7 @@ const struct backend backend_mediatek = {
        .name = "mediatek",
        .init = mediatek_init,
        .bo_create = mediatek_bo_create,
+       .bo_create_with_modifiers = mediatek_bo_create_with_modifiers,
        .bo_destroy = drv_gem_bo_destroy,
        .bo_import = drv_prime_bo_import,
        .bo_map = mediatek_bo_map,
index e0cc118..a33ede6 100644 (file)
@@ -8,7 +8,6 @@
 
 #include <errno.h>
 #include <rockchip_drm.h>
-#include <stdbool.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/mman.h>
@@ -151,16 +150,6 @@ static int rockchip_init(struct driver *drv)
        return 0;
 }
 
-static bool has_modifier(const uint64_t *list, uint32_t count, uint64_t modifier)
-{
-       uint32_t i;
-       for (i = 0; i < count; i++)
-               if (list[i] == modifier)
-                       return true;
-
-       return false;
-}
-
 static int rockchip_bo_create_with_modifiers(struct bo *bo, uint32_t width, uint32_t height,
                                             uint32_t format, const uint64_t *modifiers,
                                             uint32_t count)
@@ -179,12 +168,12 @@ static int rockchip_bo_create_with_modifiers(struct bo *bo, uint32_t width, uint
                drv_bo_from_format(bo, aligned_width, height, format);
                bo->total_size = bo->strides[0] * aligned_height + w_mbs * h_mbs * 128;
        } else if (width <= 2560 &&
-                  has_modifier(modifiers, count, DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC)) {
+                  drv_has_modifier(modifiers, count, DRM_FORMAT_MOD_CHROMEOS_ROCKCHIP_AFBC)) {
                /* If the caller has decided they can use AFBC, always
                 * pick that */
                afbc_bo_from_format(bo, width, height, format);
        } else {
-               if (!has_modifier(modifiers, count, DRM_FORMAT_MOD_LINEAR)) {
+               if (!drv_has_modifier(modifiers, count, DRM_FORMAT_MOD_LINEAR)) {
                        errno = EINVAL;
                        drv_log("no usable modifier found\n");
                        return -1;