diff options
-rw-r--r-- | virtiotest.c | 29 |
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, ¶m); - if (ret != 0) { - fprintf(stderr, "ioctl DRM_VIRTGPU_GETPARAM(%" PRId64 "): %s\n", + rc = drmIoctl(fd, DRM_IOCTL_VIRTGPU_GETPARAM, ¶m); + 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) { |