Fixed bug 5422 - KMSDRM_LEGACY: Add OpenBSD support wahil1976 This patch adds support for OpenBSD to KMSDRM_LEGACY. Note that the patch won't be ported to the atomic KMSDRM backend because OpenBSD does not support atomic KMS properly yet.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
diff --git a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.c b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.c
index 9c497cd..29bc4a5 100644
--- a/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.c
+++ b/src/video/kmsdrm_legacy/SDL_kmsdrm_legacy_video.c
@@ -47,7 +47,19 @@
#include <errno.h>
#include <poll.h>
+#ifdef __OpenBSD__
+#define KMSDRM_LEGACY_DRI_PATH "/dev/"
+#define KMSDRM_LEGACY_DRI_DEVFMT "%sdrm%d"
+#define KMSDRM_LEGACY_DRI_DEVNAME "drm"
+#define KMSDRM_LEGACY_DRI_DEVNAMESIZE 3
+#define KMSDRM_LEGACY_DRI_CARDPATHFMT "/dev/drm%d"
+#else
#define KMSDRM_LEGACY_DRI_PATH "/dev/dri/"
+#define KMSDRM_LEGACY_DRI_DEVFMT "%scard%d"
+#define KMSDRM_LEGACY_DRI_DEVNAME "card"
+#define KMSDRM_LEGACY_DRI_DEVNAMESIZE 4
+#define KMSDRM_LEGACY_DRI_CARDPATHFMT "/dev/dri/card%d"
+#endif
static int
check_modestting(int devindex)
@@ -56,14 +68,14 @@ check_modestting(int devindex)
char device[512];
int drm_fd;
- SDL_snprintf(device, sizeof (device), "%scard%d", KMSDRM_LEGACY_DRI_PATH, devindex);
+ SDL_snprintf(device, sizeof (device), KMSDRM_LEGACY_DRI_DEVFMT, KMSDRM_LEGACY_DRI_PATH, devindex);
drm_fd = open(device, O_RDWR | O_CLOEXEC);
if (drm_fd >= 0) {
if (SDL_KMSDRM_LEGACY_LoadSymbols()) {
drmModeRes *resources = KMSDRM_LEGACY_drmModeGetResources(drm_fd);
if (resources) {
- SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "%scard%d connector, encoder and CRTC counts are: %d %d %d",
+ SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, KMSDRM_LEGACY_DRI_DEVFMT " connector, encoder and CRTC counts are: %d %d %d",
KMSDRM_LEGACY_DRI_PATH, devindex,
resources->count_connectors, resources->count_encoders, resources->count_crtcs);
@@ -104,7 +116,7 @@ static int get_dricount(void)
if (folder) {
while ((res = readdir(folder))) {
int len = SDL_strlen(res->d_name);
- if (len > 4 && SDL_strncmp(res->d_name, "card", 4) == 0) {
+ if (len > KMSDRM_LEGACY_DRI_DEVNAMESIZE && SDL_strncmp(res->d_name, KMSDRM_LEGACY_DRI_DEVNAME, KMSDRM_LEGACY_DRI_DEVNAMESIZE) == 0) {
devcount++;
}
}
@@ -441,8 +453,8 @@ KMSDRM_LEGACY_VideoInit(_THIS)
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "KMSDRM_LEGACY_VideoInit()");
- /* Open /dev/dri/cardNN */
- SDL_snprintf(devname, sizeof(devname), "/dev/dri/card%d", viddata->devindex);
+ /* Open /dev/dri/cardNN (/dev/drmN if on OpenBSD) */
+ SDL_snprintf(devname, sizeof(devname), KMSDRM_LEGACY_DRI_CARDPATHFMT, viddata->devindex);
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Opening device %s", devname);
viddata->drm_fd = open(devname, O_RDWR | O_CLOEXEC);