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.
This commit is contained in:
Sam Lantinga 2020-12-28 11:47:53 -08:00
parent 8fc0baad98
commit 3cb0e840e6
1 changed files with 17 additions and 5 deletions

View File

@ -47,7 +47,19 @@
#include <errno.h> #include <errno.h>
#include <poll.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_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 static int
check_modestting(int devindex) check_modestting(int devindex)
@ -56,14 +68,14 @@ check_modestting(int devindex)
char device[512]; char device[512];
int drm_fd; 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); drm_fd = open(device, O_RDWR | O_CLOEXEC);
if (drm_fd >= 0) { if (drm_fd >= 0) {
if (SDL_KMSDRM_LEGACY_LoadSymbols()) { if (SDL_KMSDRM_LEGACY_LoadSymbols()) {
drmModeRes *resources = KMSDRM_LEGACY_drmModeGetResources(drm_fd); drmModeRes *resources = KMSDRM_LEGACY_drmModeGetResources(drm_fd);
if (resources) { 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, KMSDRM_LEGACY_DRI_PATH, devindex,
resources->count_connectors, resources->count_encoders, resources->count_crtcs); resources->count_connectors, resources->count_encoders, resources->count_crtcs);
@ -104,7 +116,7 @@ static int get_dricount(void)
if (folder) { if (folder) {
while ((res = readdir(folder))) { while ((res = readdir(folder))) {
int len = SDL_strlen(res->d_name); 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++; devcount++;
} }
} }
@ -441,8 +453,8 @@ KMSDRM_LEGACY_VideoInit(_THIS)
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "KMSDRM_LEGACY_VideoInit()"); SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "KMSDRM_LEGACY_VideoInit()");
/* Open /dev/dri/cardNN */ /* Open /dev/dri/cardNN (/dev/drmN if on OpenBSD) */
SDL_snprintf(devname, sizeof(devname), "/dev/dri/card%d", viddata->devindex); SDL_snprintf(devname, sizeof(devname), KMSDRM_LEGACY_DRI_CARDPATHFMT, viddata->devindex);
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Opening device %s", devname); SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Opening device %s", devname);
viddata->drm_fd = open(devname, O_RDWR | O_CLOEXEC); viddata->drm_fd = open(devname, O_RDWR | O_CLOEXEC);