1 /*
2 * Copyright © 2016 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include <signal.h>
25 #include <dirent.h>
26 #include <unistd.h>
27 #include <fcntl.h>
28
29 #include "igt_gvt.h"
30 #include "igt_sysfs.h"
31 #include "igt_kmod.h"
32 #include "drmtest.h"
33
34 /**
35 * SECTION:igt_gvt
36 * @short_description: Graphics virtualization technology library
37 * @title: GVT
38 * @include: igt_gvt.h
39 */
40
is_gvt_enabled(void)41 static bool is_gvt_enabled(void)
42 {
43 bool enabled = false;
44 int dir, fd;
45
46 fd = __drm_open_driver(DRIVER_INTEL);
47 dir = igt_sysfs_open_parameters(fd);
48 if (dir < 0)
49 return false;
50
51 enabled = igt_sysfs_get_boolean(dir, "enable_gvt");
52
53 close(dir);
54 close(fd);
55
56 return enabled;
57
58 }
59
igt_gvt_load_module(void)60 bool igt_gvt_load_module(void)
61 {
62 if (is_gvt_enabled())
63 return true;
64
65 if (igt_i915_driver_unload())
66 return false;
67
68 if (igt_i915_driver_load("enable_gvt=1"))
69 return false;
70
71 return is_gvt_enabled();
72 }
73
igt_gvt_unload_module(void)74 void igt_gvt_unload_module(void)
75 {
76 if (!is_gvt_enabled())
77 return;
78
79 igt_i915_driver_unload();
80
81 igt_i915_driver_load(NULL);
82
83 igt_assert(!is_gvt_enabled());
84 }
85