Force add a primary plane to lease 88/29888/5 master
authorNaoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>
Sun, 5 May 2024 16:33:48 +0000 (01:33 +0900)
committerNaoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>
Thu, 6 Jun 2024 22:35:09 +0000 (07:35 +0900)
A primary plane of crtc is possible to use in every crtcs in
the configuration of rockchip drm driver.

Planes:
id crtc fb  CRTC x,y x,y gamma size possible crtcs
54 82   451 0,0      0,0 0          0x0000000f

In this case, existing drm lease manager judges to shared plane
that is not primary plane.  The alternative method,
a DRM_CLIENT_CAP_UNIVERSAL_PLANES is disable.  In this case,
the drm lease add primary plane to crtc lease automatically

This patch enable for:
* When command line option -u is set, it enable
  DRM_CLIENT_CAP_UNIVERSAL_PLANES to use existing logic.
* When command line option -u is not set, it disable
  DRM_CLIENT_CAP_UNIVERSAL_PLANES.

Bug-AGL: SPEC-5132

Change-Id: I7fca66c8907688e9b81d1ebbe8eda1d4c46f7e38
Signed-off-by: Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>
drm-lease-manager/drm-lease.h
drm-lease-manager/lease-config.c
drm-lease-manager/lease-manager.c
drm-lease-manager/lease-manager.h
drm-lease-manager/main.c

index 5670fa8..1a61075 100644 (file)
@@ -38,6 +38,8 @@ struct lease_config {
 
        int nconnectors;
        struct connector_config *connectors;
+
+       bool have_plane_setting;
 };
 
 #endif
index aaba6b6..d3214eb 100644 (file)
@@ -78,10 +78,17 @@ static bool populate_connector_config(struct lease_config *config,
 
                toml_array_t *planes =
                    toml_array_in(conn_config_data, "planes");
-               if (planes && !populate_connector_planes(conn_config, planes)) {
-                       ERROR_LOG("Invalid plane id for connector: %s\n",
-                                 conn_config->name);
-                       return false;
+               if (planes != NULL) {
+                       bool ret =
+                           populate_connector_planes(conn_config, planes);
+                       if (ret == false) {
+                               ERROR_LOG(
+                                   "Invalid plane id for connector: %s\n",
+                                   conn_config->name);
+                               return false;
+                       } else {
+                               config->have_plane_setting = true;
+                       }
                }
        }
        return true;
@@ -119,6 +126,7 @@ int parse_config(char *filename, struct lease_config **parsed_config)
                DEBUG_LOG("Memory allocation failed: %s\n", strerror(errno));
                goto err;
        }
+       config->have_plane_setting = false;
 
        for (i = 0; i < toml_array_nelem(leases); i++) {
                toml_table_t *lease = toml_table_at(leases, i);
index 51a4613..7147078 100644 (file)
@@ -504,9 +504,12 @@ err:
        return -1;
 }
 
-static struct lm *drm_device_get_resources(const char *device)
+static struct lm *drm_device_get_resources(const char *device,
+                                          bool universal_plane)
 {
        struct lm *lm = calloc(1, sizeof(struct lm));
+       uint64_t value = 0;
+
        if (!lm) {
                DEBUG_LOG("Memory allocation failed: %s\n", strerror(errno));
                return NULL;
@@ -518,9 +521,16 @@ static struct lm *drm_device_get_resources(const char *device)
                goto err;
        }
 
-       /* Enable universal planes so that ALL planes, even primary and cursor
-        * planes can be assigned from lease configurations. */
-       if (drmSetClientCap(lm->drm_fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1)) {
+       /* When -u option set at args. Enable universal planes so that ALL
+          planes, even primary and cursor planes can be assigned from lease
+          configurations. */
+       if (universal_plane == true) {
+               DEBUG_LOG("Enable universal plean mode.\n");
+               value = 1;
+       }
+
+       if (drmSetClientCap(lm->drm_fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES,
+                           value)) {
                DEBUG_LOG("drmSetClientCap failed\n");
                goto err;
        }
@@ -533,8 +543,8 @@ static struct lm *drm_device_get_resources(const char *device)
        }
 
        if (lm->drm_resource->count_connectors <= 0 ||
-               lm->drm_resource->count_crtcs <= 0 ||
-               lm->drm_resource->count_encoders <= 0) {
+           lm->drm_resource->count_crtcs <= 0 ||
+           lm->drm_resource->count_encoders <= 0) {
                DEBUG_LOG("Insufficient DRM resources on device(%s)\n", device);
                goto err;
        }
@@ -577,20 +587,20 @@ err:
        return NULL;
 }
 
-static struct lm *drm_find_drm_device(const char *device)
+static struct lm *drm_find_drm_device(const char *device, bool universal_plane)
 {
        drmDevicePtr devices[64];
        int ndevs;
        struct lm *lm = NULL;
 
        if (device)
-               return drm_device_get_resources(device);
+               return drm_device_get_resources(device, universal_plane);
 
        ndevs = drmGetDevices2(0, devices, 64);
 
        for (int i = 0; i < ndevs; i++) {
                lm = drm_device_get_resources(
-                   devices[i]->nodes[DRM_NODE_PRIMARY]);
+                   devices[i]->nodes[DRM_NODE_PRIMARY], universal_plane);
                if (lm)
                        break;
        }
@@ -626,10 +636,11 @@ static int lm_create_leases(struct lm *lm, int num_leases,
 }
 
 struct lm *lm_create_with_config(const char *device, int num_leases,
-                                struct lease_config *configs)
+                                struct lease_config *configs,
+                                bool universal_plane)
 {
        struct lease_config *default_configs = NULL;
-       struct lm *lm = drm_find_drm_device(device);
+       struct lm *lm = drm_find_drm_device(device, universal_plane);
 
        if (!lm) {
                ERROR_LOG("No available DRM device found\n");
@@ -658,7 +669,7 @@ struct lm *lm_create_with_config(const char *device, int num_leases,
 
 struct lm *lm_create(const char *device)
 {
-       return lm_create_with_config(device, 0, NULL);
+       return lm_create_with_config(device, 0, NULL, false);
 }
 
 void lm_destroy(struct lm *lm)
index d13ca43..9891adc 100644 (file)
@@ -21,7 +21,8 @@ struct lm;
 
 struct lm *lm_create(const char *path);
 struct lm *lm_create_with_config(const char *path, int leases,
-                                struct lease_config *configs);
+                                struct lease_config *configs,
+                                bool universal_plane);
 
 void lm_destroy(struct lm *lm);
 
index 5ac3600..d5e8788 100644 (file)
 
 static void usage(const char *progname)
 {
-       printf("Usage: %s [OPTIONS] [<DRM device>]\n\n"
-              "Options:\n"
-              "-h, --help \tPrint this help\n"
-              "-c, --config \t path to configuration file (default "
-              "/etc/drm-lease-manager.toml)\n"
-              "-v, --verbose \tEnable verbose debug messages\n"
-              "-t, --lease-transfer \tAllow lease transfter to new clients\n"
-              "-k, --keep-on-crash \tDon't close lease on client crash\n",
-              progname);
+       printf(
+           "Usage: %s [OPTIONS] [<DRM device>]\n\n"
+           "Options:\n"
+           "-h, --help \tPrint this help\n"
+           "-c, --config \t path to configuration file (default "
+           "/etc/drm-lease-manager.toml)\n"
+           "-v, --verbose \tEnable verbose debug messages\n"
+           "-t, --lease-transfer \tAllow lease transfter to new clients\n"
+           "-k, --keep-on-crash \tDon't close lease on client crash\n",
+           "-u, --enable-universal-plane \tEnable universal plane support\n",
+           progname);
 }
 
-const char *opts = "vtkhc:";
+const char *opts = "vtkhcu:";
 const struct option options[] = {
     {"help", no_argument, NULL, 'h'},
     {"verbose", no_argument, NULL, 'v'},
     {"lease-transfer", no_argument, NULL, 't'},
     {"keep-on-crash", no_argument, NULL, 'k'},
     {"config", required_argument, NULL, 'c'},
+    {"enable-universal-plane", required_argument, NULL, 'u'},
     {NULL, 0, NULL, 0},
 };
 
@@ -59,6 +62,7 @@ int main(int argc, char **argv)
        bool debug_log = false;
        bool can_transfer_leases = false;
        bool keep_on_crash = false;
+       bool universal_plane = false;
 
        int c;
        while ((c = getopt_long(argc, argv, opts, options, NULL)) != -1) {
@@ -76,6 +80,9 @@ int main(int argc, char **argv)
                case 'c':
                        config_file = optarg;
                        break;
+               case 'u':
+                       universal_plane = true;
+                       break;
                case 'h':
                        ret = EXIT_SUCCESS;
                        /* fall through */
@@ -93,8 +100,8 @@ int main(int argc, char **argv)
        struct lease_config *lease_configs = NULL;
        int num_configs = parse_config(config_file, &lease_configs);
 
-       struct lm *lm =
-           lm_create_with_config(device, num_configs, lease_configs);
+       struct lm *lm = lm_create_with_config(device, num_configs,
+                                             lease_configs, universal_plane);
 
        if (!lm) {
                ERROR_LOG("DRM Lease initialization failed\n");