blob: 6cd0fa0d70997411ee44cd66771e6d7f00b6fb97 [file] [log] [blame]
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -06001/*
2 * XGL 3-D graphics library
3 *
4 * Copyright (C) 2014 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
Chia-I Wu44e42362014-09-02 08:32:09 +080025 * Courtney Goeltzenleuchter <courtney@lunarg.com>
26 * Chia-I Wu <olv@lunarg.com>
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -060027 */
28
Chia-I Wu023ef682014-09-15 11:06:50 +080029#include "icd-enumerate-drm.h"
Chia-I Wua6e33492014-08-05 13:35:08 +080030#include "gpu.h"
31#include "intel.h"
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -060032
Chia-I Wu73019ad2014-08-29 12:01:13 +080033static int intel_devid_override;
Chia-I Wu1c527012014-08-23 14:57:35 +080034int intel_debug = -1;
35
36static void intel_debug_init(void)
37{
38 const char *env;
39
40 if (intel_debug >= 0)
41 return;
42
43 intel_debug = 0;
44
45 /* parse comma-separated debug options */
46 env = getenv("INTEL_DEBUG");
47 while (env) {
48 const char *p = strchr(env, ',');
49 size_t len;
50
51 if (p)
52 len = p - env;
53 else
54 len = strlen(env);
55
Courtney Goeltzenleuchterd9fc9842014-10-13 12:58:25 -060056 if (len > 0) {
57 if (strncmp(env, "batch", len) == 0) {
58 intel_debug |= INTEL_DEBUG_BATCH;
59 } else if (strncmp(env, "nohw", len) == 0) {
60 intel_debug |= INTEL_DEBUG_NOHW;
61 } else if (strncmp(env, "0x", 2) == 0) {
62 intel_debug |= INTEL_DEBUG_NOHW;
63 intel_devid_override = strtol(env, NULL, 16);
64 }
Chia-I Wu73019ad2014-08-29 12:01:13 +080065 }
Chia-I Wu1c527012014-08-23 14:57:35 +080066
67 if (!p)
68 break;
69
70 env = p + 1;
71 }
72}
73
Chia-I Wu023ef682014-09-15 11:06:50 +080074ICD_EXPORT XGL_RESULT XGLAPI xglInitAndEnumerateGpus(
75 const XGL_APPLICATION_INFO* pAppInfo,
76 const XGL_ALLOC_CALLBACKS* pAllocCb,
77 XGL_UINT maxGpus,
78 XGL_UINT* pGpuCount,
79 XGL_PHYSICAL_GPU* pGpus)
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -060080{
Chia-I Wu023ef682014-09-15 11:06:50 +080081 struct icd_drm_device *devices, *dev;
Chia-I Wu3065c9c2014-08-04 06:28:31 +080082 XGL_RESULT ret;
Chia-I Wu023ef682014-09-15 11:06:50 +080083 XGL_UINT count;
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -060084
Chia-I Wu1c527012014-08-23 14:57:35 +080085 intel_debug_init();
86
Chia-I Wuc217f802014-08-05 10:17:50 +080087 ret = icd_set_allocator(pAllocCb);
Chia-I Wu3065c9c2014-08-04 06:28:31 +080088 if (ret != XGL_SUCCESS)
89 return ret;
90
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -060091 /*
Chia-I Wu023ef682014-09-15 11:06:50 +080092 * xglInitAndEnumerateGpus() can be called multiple times. Calling it more
93 * than once forces driver reinitialization.
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -060094 */
Chia-I Wua6e33492014-08-05 13:35:08 +080095 intel_gpu_remove_all();
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -060096
Chia-I Wuc7bff532014-08-06 12:14:54 +080097 if (!maxGpus) {
98 *pGpuCount = 0;
Chia-I Wua6e33492014-08-05 13:35:08 +080099 return XGL_SUCCESS;
Chia-I Wuc7bff532014-08-06 12:14:54 +0800100 }
Chia-I Wua6e33492014-08-05 13:35:08 +0800101
Chia-I Wu023ef682014-09-15 11:06:50 +0800102 devices = icd_drm_enumerate(0x8086);
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -0600103
Chia-I Wu023ef682014-09-15 11:06:50 +0800104 count = 0;
105 dev = devices;
106 while (dev) {
Chia-I Wuf07865e2014-09-15 13:52:21 +0800107 const char *primary_node, *render_node;
Chia-I Wu4d09f452014-10-13 16:21:39 +0800108 int devid;
Chia-I Wua6e33492014-08-05 13:35:08 +0800109 struct intel_gpu *gpu;
110
Chia-I Wuf07865e2014-09-15 13:52:21 +0800111 primary_node = icd_drm_get_devnode(dev, ICD_DRM_MINOR_LEGACY);
Chia-I Wuf1356882014-09-18 16:39:06 +0800112 if (!primary_node)
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -0600113 continue;
Chia-I Wua6e33492014-08-05 13:35:08 +0800114
Chia-I Wuf1356882014-09-18 16:39:06 +0800115 render_node = icd_drm_get_devnode(dev, ICD_DRM_MINOR_RENDER);
116
Chia-I Wu4d09f452014-10-13 16:21:39 +0800117 devid = (intel_devid_override) ? intel_devid_override : dev->devid;
118 ret = intel_gpu_add(devid, primary_node, render_node, &gpu);
Chia-I Wua6e33492014-08-05 13:35:08 +0800119 if (ret == XGL_SUCCESS) {
120 pGpus[count++] = (XGL_PHYSICAL_GPU) gpu;
121 if (count >= maxGpus)
122 break;
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -0600123 }
Chia-I Wu023ef682014-09-15 11:06:50 +0800124
125 dev = dev->next;
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -0600126 }
Chia-I Wua6e33492014-08-05 13:35:08 +0800127
Chia-I Wu023ef682014-09-15 11:06:50 +0800128 icd_drm_release(devices);
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -0600129
Chia-I Wua6e33492014-08-05 13:35:08 +0800130 *pGpuCount = count;
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -0600131
Chia-I Wua6e33492014-08-05 13:35:08 +0800132 return (count > 0) ? XGL_SUCCESS : XGL_ERROR_UNAVAILABLE;
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -0600133}