blob: acbc349145ce9f4403ea45822daa8319c9f0dd00 [file] [log] [blame]
Chris Wilson838d0772016-06-21 12:14:14 +01001/*
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
Marius Vladf4361522016-12-01 14:23:56 +020024#include <signal.h>
Chris Wilson838d0772016-06-21 12:14:14 +010025#include <dirent.h>
26#include <unistd.h>
27#include <fcntl.h>
28
Daniel Vetter8c1fcc62017-09-08 11:23:15 +020029#include "igt_gvt.h"
30#include "igt_sysfs.h"
31#include "igt_kmod.h"
32#include "drmtest.h"
33
Paul Kocialkowski76bce772017-07-20 17:11:52 +030034/**
35 * SECTION:igt_gvt
36 * @short_description: Graphics virtualization technology library
37 * @title: GVT
38 * @include: igt_gvt.h
39 */
40
Chris Wilson838d0772016-06-21 12:14:14 +010041static bool is_gvt_enabled(void)
42{
Chris Wilson838d0772016-06-21 12:14:14 +010043 bool enabled = false;
Marius Vladf4361522016-12-01 14:23:56 +020044 int dir, fd;
Chris Wilson838d0772016-06-21 12:14:14 +010045
Marius Vladf4361522016-12-01 14:23:56 +020046 fd = __drm_open_driver(DRIVER_INTEL);
47 dir = igt_sysfs_open_parameters(fd);
48 if (dir < 0)
Chris Wilson838d0772016-06-21 12:14:14 +010049 return false;
50
Marius Vladf4361522016-12-01 14:23:56 +020051 enabled = igt_sysfs_get_boolean(dir, "enable_gvt");
Chris Wilson838d0772016-06-21 12:14:14 +010052
Marius Vladf4361522016-12-01 14:23:56 +020053 close(dir);
54 close(fd);
55
Chris Wilson838d0772016-06-21 12:14:14 +010056 return enabled;
Chris Wilson838d0772016-06-21 12:14:14 +010057
Chris Wilson838d0772016-06-21 12:14:14 +010058}
59
60bool igt_gvt_load_module(void)
61{
62 if (is_gvt_enabled())
63 return true;
64
Marius Vladf4361522016-12-01 14:23:56 +020065 if (igt_i915_driver_unload())
66 return false;
67
68 if (igt_i915_driver_load("enable_gvt=1"))
69 return false;
Chris Wilson838d0772016-06-21 12:14:14 +010070
71 return is_gvt_enabled();
72}
73
74void igt_gvt_unload_module(void)
75{
76 if (!is_gvt_enabled())
77 return;
78
Marius Vladf4361522016-12-01 14:23:56 +020079 igt_i915_driver_unload();
80
81 igt_i915_driver_load(NULL);
Chris Wilson838d0772016-06-21 12:14:14 +010082
83 igt_assert(!is_gvt_enabled());
84}