Chris Wilson | 838d077 | 2016-06-21 12:14:14 +0100 | [diff] [blame] | 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 "igt.h" |
| 25 | #include "igt_gvt.h" |
Marius Vlad | 0268d73 | 2016-12-01 21:45:47 +0000 | [diff] [blame] | 26 | #include "igt_sysfs.h" |
Marius Vlad | f436152 | 2016-12-01 14:23:56 +0200 | [diff] [blame] | 27 | #include "igt_kmod.h" |
Chris Wilson | 838d077 | 2016-06-21 12:14:14 +0100 | [diff] [blame] | 28 | |
Marius Vlad | f436152 | 2016-12-01 14:23:56 +0200 | [diff] [blame] | 29 | #include <signal.h> |
Chris Wilson | 838d077 | 2016-06-21 12:14:14 +0100 | [diff] [blame] | 30 | #include <dirent.h> |
| 31 | #include <unistd.h> |
| 32 | #include <fcntl.h> |
| 33 | |
Paul Kocialkowski | 76bce77 | 2017-07-20 17:11:52 +0300 | [diff] [blame^] | 34 | /** |
| 35 | * SECTION:igt_gvt |
| 36 | * @short_description: Graphics virtualization technology library |
| 37 | * @title: GVT |
| 38 | * @include: igt_gvt.h |
| 39 | */ |
| 40 | |
Chris Wilson | 838d077 | 2016-06-21 12:14:14 +0100 | [diff] [blame] | 41 | static bool is_gvt_enabled(void) |
| 42 | { |
Chris Wilson | 838d077 | 2016-06-21 12:14:14 +0100 | [diff] [blame] | 43 | bool enabled = false; |
Marius Vlad | f436152 | 2016-12-01 14:23:56 +0200 | [diff] [blame] | 44 | int dir, fd; |
Chris Wilson | 838d077 | 2016-06-21 12:14:14 +0100 | [diff] [blame] | 45 | |
Marius Vlad | f436152 | 2016-12-01 14:23:56 +0200 | [diff] [blame] | 46 | fd = __drm_open_driver(DRIVER_INTEL); |
| 47 | dir = igt_sysfs_open_parameters(fd); |
| 48 | if (dir < 0) |
Chris Wilson | 838d077 | 2016-06-21 12:14:14 +0100 | [diff] [blame] | 49 | return false; |
| 50 | |
Marius Vlad | f436152 | 2016-12-01 14:23:56 +0200 | [diff] [blame] | 51 | enabled = igt_sysfs_get_boolean(dir, "enable_gvt"); |
Chris Wilson | 838d077 | 2016-06-21 12:14:14 +0100 | [diff] [blame] | 52 | |
Marius Vlad | f436152 | 2016-12-01 14:23:56 +0200 | [diff] [blame] | 53 | close(dir); |
| 54 | close(fd); |
| 55 | |
Chris Wilson | 838d077 | 2016-06-21 12:14:14 +0100 | [diff] [blame] | 56 | return enabled; |
Chris Wilson | 838d077 | 2016-06-21 12:14:14 +0100 | [diff] [blame] | 57 | |
Chris Wilson | 838d077 | 2016-06-21 12:14:14 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | bool igt_gvt_load_module(void) |
| 61 | { |
| 62 | if (is_gvt_enabled()) |
| 63 | return true; |
| 64 | |
Marius Vlad | f436152 | 2016-12-01 14:23:56 +0200 | [diff] [blame] | 65 | if (igt_i915_driver_unload()) |
| 66 | return false; |
| 67 | |
| 68 | if (igt_i915_driver_load("enable_gvt=1")) |
| 69 | return false; |
Chris Wilson | 838d077 | 2016-06-21 12:14:14 +0100 | [diff] [blame] | 70 | |
| 71 | return is_gvt_enabled(); |
| 72 | } |
| 73 | |
| 74 | void igt_gvt_unload_module(void) |
| 75 | { |
| 76 | if (!is_gvt_enabled()) |
| 77 | return; |
| 78 | |
Marius Vlad | f436152 | 2016-12-01 14:23:56 +0200 | [diff] [blame] | 79 | igt_i915_driver_unload(); |
| 80 | |
| 81 | igt_i915_driver_load(NULL); |
Chris Wilson | 838d077 | 2016-06-21 12:14:14 +0100 | [diff] [blame] | 82 | |
| 83 | igt_assert(!is_gvt_enabled()); |
| 84 | } |