1 /*
2 * Copyright © 2015 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 <stdlib.h>
25
26 #include "util/macros.h"
27
28 #include "intel_engine.h"
29 #include "i915/intel_engine.h"
30 #include "xe/intel_engine.h"
31
32 struct intel_query_engine_info *
intel_engine_get_info(int fd,enum intel_kmd_type type)33 intel_engine_get_info(int fd, enum intel_kmd_type type)
34 {
35 switch (type) {
36 case INTEL_KMD_TYPE_I915:
37 return i915_engine_get_info(fd);
38 case INTEL_KMD_TYPE_XE:
39 return xe_engine_get_info(fd);
40 default:
41 unreachable("Missing");
42 return NULL;
43 }
44 }
45
46 int
intel_engines_count(const struct intel_query_engine_info * info,enum intel_engine_class engine_class)47 intel_engines_count(const struct intel_query_engine_info *info,
48 enum intel_engine_class engine_class)
49 {
50 int count = 0;
51
52 for (int i = 0; i < info->num_engines; i++) {
53 if (info->engines[i].engine_class == engine_class)
54 count++;
55 }
56
57 return count;
58 }
59
60 const char *
intel_engines_class_to_string(enum intel_engine_class engine_class)61 intel_engines_class_to_string(enum intel_engine_class engine_class)
62 {
63 switch (engine_class) {
64 case INTEL_ENGINE_CLASS_RENDER:
65 return "render";
66 case INTEL_ENGINE_CLASS_COPY:
67 return "copy";
68 case INTEL_ENGINE_CLASS_VIDEO:
69 return "video";
70 case INTEL_ENGINE_CLASS_VIDEO_ENHANCE:
71 return "video-enh";
72 case INTEL_ENGINE_CLASS_COMPUTE:
73 return "compute";
74 default:
75 return "unknown";
76 }
77 }
78
79 static bool
is_guc_semaphore_functional(int fd,const struct intel_device_info * info)80 is_guc_semaphore_functional(int fd, const struct intel_device_info *info)
81 {
82 switch (info->kmd_type) {
83 case INTEL_KMD_TYPE_I915:
84 return i915_engines_is_guc_semaphore_functional(fd, info);
85 case INTEL_KMD_TYPE_XE:
86 return xe_engines_is_guc_semaphore_functional(fd, info);
87 default:
88 unreachable("Missing");
89 return false;
90 }
91 }
92
93 int
intel_engines_supported_count(int fd,const struct intel_device_info * info,const struct intel_query_engine_info * engine_info,enum intel_engine_class engine_class)94 intel_engines_supported_count(int fd, const struct intel_device_info *info,
95 const struct intel_query_engine_info *engine_info,
96 enum intel_engine_class engine_class)
97 {
98 bool supported;
99
100 switch (engine_class) {
101 case INTEL_ENGINE_CLASS_COMPUTE:
102 supported = is_guc_semaphore_functional(fd, info);
103 break;
104 default:
105 /* There is no restrictions or parameters for other engines */
106 supported = true;
107 }
108
109 return supported ? intel_engines_count(engine_info, engine_class) : 0;
110 }
111