aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamian Hobson-Garcia <dhobsong@igel.co.jp>2022-04-06 18:11:38 +0900
committerDamian Hobson-Garcia <dhobsong@igel.co.jp>2022-04-20 10:58:39 +0900
commit6a12fcc3821e913ca799ff8981d9415d0a251836 (patch)
tree073303a4717bc06b0d2b55d6f548fc3a96b00247
parent17bf719d3b141142c6fa908485dec4ca5872fa83 (diff)
Default to first modesettable DRM device
When no DRM device is specified on the command line, try all available DRM devices until an available modesettable device is found. Bug-AGL: SPEC-3815 Change-Id: I72343558fcda755a63aee549767ccc8c00c06724 Signed-off-by: Damian Hobson-Garcia <dhobsong@igel.co.jp>
-rw-r--r--README.md4
-rw-r--r--drm-lease-manager/lease-manager.c29
-rw-r--r--drm-lease-manager/main.c2
3 files changed, 30 insertions, 5 deletions
diff --git a/README.md b/README.md
index f9a7650..458cdde 100644
--- a/README.md
+++ b/README.md
@@ -65,8 +65,8 @@ Once installed, running the following command will start the DRM Lease Manager d
drm-lease-manager [<path DRM device>]
-If no DRM device is specified, `/dev/dri/card0` will be used.
-More detailed options can be displayed by specifying the `-h` flag.
+If no DRM device is specified, the first available device capabale of modesetting will
+be used. More detailed options can be displayed by specifying the `-h` flag.
### Dynamic lease transfer
diff --git a/drm-lease-manager/lease-manager.c b/drm-lease-manager/lease-manager.c
index b339037..291594c 100644
--- a/drm-lease-manager/lease-manager.c
+++ b/drm-lease-manager/lease-manager.c
@@ -515,6 +515,29 @@ err:
return NULL;
}
+static struct lm *drm_find_drm_device(const char *device)
+{
+ drmDevicePtr devices[64];
+ int ndevs;
+ struct lm *lm = NULL;
+
+ if (device)
+ return drm_device_get_resources(device);
+
+ ndevs = drmGetDevices2(0, devices, 64);
+
+ for (int i = 0; i < ndevs; i++) {
+ lm = drm_device_get_resources(
+ devices[i]->nodes[DRM_NODE_PRIMARY]);
+ if (lm)
+ break;
+ }
+
+ drmFreeDevices(devices, ndevs);
+
+ return lm;
+}
+
static int lm_create_leases(struct lm *lm, int num_leases,
const struct lease_config *configs)
{
@@ -544,10 +567,12 @@ struct lm *lm_create_with_config(const char *device, int num_leases,
struct lease_config *configs)
{
struct lease_config *default_configs = NULL;
- struct lm *lm = drm_device_get_resources(device);
+ struct lm *lm = drm_find_drm_device(device);
- if (!lm)
+ if (!lm) {
+ ERROR_LOG("No available DRM device found\n");
return NULL;
+ }
if (configs == NULL || num_leases == 0) {
num_leases = create_default_lease_configs(lm, &default_configs);
diff --git a/drm-lease-manager/main.c b/drm-lease-manager/main.c
index ff69e75..b4ad379 100644
--- a/drm-lease-manager/main.c
+++ b/drm-lease-manager/main.c
@@ -48,7 +48,7 @@ const struct option options[] = {
int main(int argc, char **argv)
{
- char *device = "/dev/dri/card0";
+ char *device = NULL;
char *config_file = "/etc/drm-lease-manager.toml";
bool debug_log = false;