aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2018-10-15 14:50:55 +0200
committerGerd Hoffmann <kraxel@redhat.com>2018-10-15 14:50:55 +0200
commit33272774098eff1b5f3b091e988efc3693291829 (patch)
tree9defc0103fd3cf9bfc800168e5f232e7546e35be
parent8729c86f595b963992109f86e0389a1613aeb649 (diff)
downloaddrminfo-33272774098eff1b5f3b091e988efc3693291829.tar.gz
sanity check, fix getparam
-rw-r--r--virtiotest.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/virtiotest.c b/virtiotest.c
index ecbe283..b9ac3a8 100644
--- a/virtiotest.c
+++ b/virtiotest.c
@@ -40,11 +40,11 @@ static uint64_t virtio_get_cap(uint64_t cap)
.param = cap,
.value = 0,
};
- int ret;
+ int rc;
- ret = ioctl(fd, DRM_VIRTGPU_GETPARAM, &param);
- if (ret != 0) {
- fprintf(stderr, "ioctl DRM_VIRTGPU_GETPARAM(%" PRId64 "): %s\n",
+ rc = drmIoctl(fd, DRM_IOCTL_VIRTGPU_GETPARAM, &param);
+ if (rc != 0) {
+ fprintf(stderr, "ioctl DRM_IOCTL_VIRTGPU_GETPARAM(%" PRId64 "): %s\n",
cap, strerror(errno));
exit(1);
}
@@ -63,6 +63,25 @@ static void virtio_print_caps(void)
}
}
+static void virtio_check(int cardno)
+{
+ char syspath[128];
+ char symlink[128];
+ int len;
+
+ snprintf(syspath, sizeof(syspath), "/sys/class/drm/card%d", cardno);
+ len = readlink(syspath, symlink, sizeof(symlink));
+ if (len < 0) {
+ fprintf(stderr, "readlink %s: %s\n", syspath, strerror(errno));
+ exit(1);
+ }
+ symlink[len] = 0;
+ if (strstr(symlink, "/virtio") == NULL) {
+ fprintf(stderr, "card%d: not a virtio-gpu device\n", cardno);
+ exit(1);
+ }
+}
+
/* ------------------------------------------------------------------ */
static void usage(FILE *fp)
@@ -106,6 +125,8 @@ int main(int argc, char **argv)
}
}
+ virtio_check(card);
+
drm_init_dev(card, output, modename, false);
if (printinfo) {