json.c 27.70 KiB
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <unistd.h>
#include <json_object.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
#include "drm_info.h"
#include "tables.h"
static const struct {
const char *name;
uint64_t cap;
} client_caps[] = {
{ "STEREO_3D", DRM_CLIENT_CAP_STEREO_3D },
{ "UNIVERSAL_PLANES", DRM_CLIENT_CAP_UNIVERSAL_PLANES },
{ "ATOMIC", DRM_CLIENT_CAP_ATOMIC },
{ "ASPECT_RATIO", DRM_CLIENT_CAP_ASPECT_RATIO },
{ "WRITEBACK_CONNECTORS", DRM_CLIENT_CAP_WRITEBACK_CONNECTORS },
{ "CURSOR_PLANE_HOTSPOT", DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT },
};
static const struct {
const char *name;
uint64_t cap;
} caps[] = {
{ "DUMB_BUFFER", DRM_CAP_DUMB_BUFFER },
{ "VBLANK_HIGH_CRTC", DRM_CAP_VBLANK_HIGH_CRTC },
{ "DUMB_PREFERRED_DEPTH", DRM_CAP_DUMB_PREFERRED_DEPTH },
{ "DUMB_PREFER_SHADOW", DRM_CAP_DUMB_PREFER_SHADOW },
{ "PRIME", DRM_CAP_PRIME },
{ "TIMESTAMP_MONOTONIC", DRM_CAP_TIMESTAMP_MONOTONIC },
{ "ASYNC_PAGE_FLIP", DRM_CAP_ASYNC_PAGE_FLIP },
{ "CURSOR_WIDTH", DRM_CAP_CURSOR_WIDTH },
{ "CURSOR_HEIGHT", DRM_CAP_CURSOR_HEIGHT },
{ "ADDFB2_MODIFIERS", DRM_CAP_ADDFB2_MODIFIERS },
{ "PAGE_FLIP_TARGET", DRM_CAP_PAGE_FLIP_TARGET },
{ "CRTC_IN_VBLANK_EVENT", DRM_CAP_CRTC_IN_VBLANK_EVENT },
{ "SYNCOBJ", DRM_CAP_SYNCOBJ },
{ "SYNCOBJ_TIMELINE", DRM_CAP_SYNCOBJ_TIMELINE },
{ "ATOMIC_ASYNC_PAGE_FLIP", DRM_CAP_ATOMIC_ASYNC_PAGE_FLIP },
};
static struct json_object *tainted_info(void)
{
#ifndef __linux__
return NULL;
#endif
FILE *f = fopen("/proc/sys/kernel/tainted", "r");
if (f == NULL) {
perror("fopen(/proc/sys/kernel/tainted)");
return NULL;
}
char str[64];
size_t n = fread(str, 1, sizeof(str) - 1, f);
if (!feof(f)) {
fclose(f);
fprintf(stderr, "fread(/proc/sys/kernel/tainted) failed");
return NULL;