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>
drm-lease-manager [<path DRM device>]
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
### Dynamic lease transfer
+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)
{
static int lm_create_leases(struct lm *lm, int num_leases,
const struct lease_config *configs)
{
struct lease_config *configs)
{
struct lease_config *default_configs = NULL;
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) {
+ ERROR_LOG("No available DRM device found\n");
if (configs == NULL || num_leases == 0) {
num_leases = create_default_lease_configs(lm, &default_configs);
if (configs == NULL || num_leases == 0) {
num_leases = create_default_lease_configs(lm, &default_configs);
int main(int argc, char **argv)
{
int main(int argc, char **argv)
{
- char *device = "/dev/dri/card0";
char *config_file = "/etc/drm-lease-manager.toml";
bool debug_log = false;
char *config_file = "/etc/drm-lease-manager.toml";
bool debug_log = false;