xref: /illumos-gate/usr/src/test/bhyve-tests/tests/vmm/check_iommu.c (revision 77c0a660417a046bfab6c8ef58d00c181c0264b3)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2022 Oxide Computer Company
14  */
15 
16 #include <stdio.h>
17 #include <unistd.h>
18 #include <stdlib.h>
19 #include <fcntl.h>
20 #include <libgen.h>
21 
22 #include <sys/vmm.h>
23 #include <sys/vmm_dev.h>
24 
25 int
26 main(int argc, char *argv[])
27 {
28 	const char *suite_name = basename(argv[0]);
29 
30 	int ctl_fd = open(VMM_CTL_DEV, O_EXCL | O_RDWR);
31 	if (ctl_fd < 0) {
32 		perror("could not open vmmctl device");
33 		return (EXIT_FAILURE);
34 	}
35 
36 	int res = ioctl(ctl_fd, VMM_CHECK_IOMMU, 0);
37 	if (res < 0) {
38 		perror("VMM_CHECK_IOMMU ioctl failed");
39 		return (EXIT_FAILURE);
40 	}
41 
42 	(void) close(ctl_fd);
43 	(void) printf("%s\tPASS\n", suite_name);
44 	return (0);
45 }
46