All of lore.kernel.org
 help / color / mirror / Atom feed
From: Emil Velikov <emil.l.velikov@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: Chih-Wei Huang <cwhuang@linux.org.tw>,
	Mauro Rossi <issor.oruam@gmail.com>,
	emil.l.velikov@gmail.com
Subject: [PATCH libdrm] WIP: expose boot_vga via drmDevice
Date: Thu, 28 May 2020 13:35:58 +0100	[thread overview]
Message-ID: <20200528123558.3171101-1-emil.l.velikov@gmail.com> (raw)

- ifdef check around the sysfs handling - only Linux has comprehensive
sysfs
- compile and run-time test

Cc: Chih-Wei Huang <cwhuang@linux.org.tw>
Cc: Mauro Rossi <issor.oruam@gmail.com>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
---
Chih-Wei, Mauro

Here is a quick WIP which should get you going. I have _not_ tested it
so it might need some polish - please submit once you're happy with it.
---
 xf86drm.c | 53 ++++++++++++++++++++++++++++++++++++++++++-----------
 xf86drm.h |  2 ++
 2 files changed, 44 insertions(+), 11 deletions(-)

diff --git a/xf86drm.c b/xf86drm.c
index b49d42f7..13162b81 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -3948,8 +3948,9 @@ process_device(drmDevicePtr *device, const char *d_name,
 {
     struct stat sbuf;
     char node[PATH_MAX + 1];
-    int node_type, subsystem_type;
+    int node_type, subsystem_type, ret;
     unsigned int maj, min;
+    FILE *fp;
 
     node_type = drmGetNodeType(d_name);
     if (node_type < 0)
@@ -3972,20 +3973,49 @@ process_device(drmDevicePtr *device, const char *d_name,
     switch (subsystem_type) {
     case DRM_BUS_PCI:
     case DRM_BUS_VIRTIO:
-        return drmProcessPciDevice(device, node, node_type, maj, min,
-                                   fetch_deviceinfo, flags);
+        ret = drmProcessPciDevice(device, node, node_type, maj, min,
+                                  fetch_deviceinfo, flags);
     case DRM_BUS_USB:
-        return drmProcessUsbDevice(device, node, node_type, maj, min,
-                                   fetch_deviceinfo, flags);
+        ret = drmProcessUsbDevice(device, node, node_type, maj, min,
+                                  fetch_deviceinfo, flags);
     case DRM_BUS_PLATFORM:
-        return drmProcessPlatformDevice(device, node, node_type, maj, min,
-                                        fetch_deviceinfo, flags);
+        ret = drmProcessPlatformDevice(device, node, node_type, maj, min,
+                                       fetch_deviceinfo, flags);
     case DRM_BUS_HOST1X:
-        return drmProcessHost1xDevice(device, node, node_type, maj, min,
-                                      fetch_deviceinfo, flags);
+        ret = drmProcessHost1xDevice(device, node, node_type, maj, min,
+                                     fetch_deviceinfo, flags);
     default:
         return -1;
-   }
+    }
+    if (!(flags & DRM_DEVICE_GET_BOOT_VGA))
+        return ret;
+
+    snprintf(node, sizeof(node), "/sys/dev/char/%d:%d/device/boot_vga",
+             maj, min);
+
+    fp = fopen(path, "r");
+    if (!fp) {
+#ifdef BOOT_VGA_FATAL
+        free(*device);
+        *device = NULL;
+        return -errno;
+#else
+        return 0;
+#endif
+    }
+
+    ret = fscanf(fp, "%d", &(device->boot_vga));
+    fclose(fp);
+    if (ret != 1) {
+#ifdef BOOT_VGA_FATAL
+        free(*device);
+        *device = NULL;
+        return -errno;
+#else
+        return 0;
+#endif
+    }
+    return 0;
 }
 
 /* Consider devices located on the same bus as duplicate and fold the respective
@@ -4014,7 +4044,8 @@ static void drmFoldDuplicatedDevices(drmDevicePtr local_devices[], int count)
 static int
 drm_device_validate_flags(uint32_t flags)
 {
-        return (flags & ~DRM_DEVICE_GET_PCI_REVISION);
+    return (flags & ~(DRM_DEVICE_GET_PCI_REVISION |
+                      DRM_DEVICE_GET_BOOT_VGA));
 }
 
 static bool
diff --git a/xf86drm.h b/xf86drm.h
index 7b85079a..da6f7e26 100644
--- a/xf86drm.h
+++ b/xf86drm.h
@@ -885,6 +885,7 @@ typedef struct _drmDevice {
         drmPlatformDeviceInfoPtr platform;
         drmHost1xDeviceInfoPtr host1x;
     } deviceinfo;
+    int boot_vga;
 } drmDevice, *drmDevicePtr;
 
 extern int drmGetDevice(int fd, drmDevicePtr *device);
@@ -894,6 +895,7 @@ extern int drmGetDevices(drmDevicePtr devices[], int max_devices);
 extern void drmFreeDevices(drmDevicePtr devices[], int count);
 
 #define DRM_DEVICE_GET_PCI_REVISION (1 << 0)
+#define DRM_DEVICE_GET_BOOT_VGA (1 << 1)
 extern int drmGetDevice2(int fd, uint32_t flags, drmDevicePtr *device);
 extern int drmGetDevices2(uint32_t flags, drmDevicePtr devices[], int max_devices);
 
-- 
2.25.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

                 reply	other threads:[~2020-05-28 12:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200528123558.3171101-1-emil.l.velikov@gmail.com \
    --to=emil.l.velikov@gmail.com \
    --cc=cwhuang@linux.org.tw \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=issor.oruam@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.