blob: 00e2a66f845917c836ae40a7e7394eeb4c8681bf [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"
Jon Ashburnd43f9b62014-10-14 19:15:22 -060032#include "dispatch.h"
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -060033
Chia-I Wu73019ad2014-08-29 12:01:13 +080034static int intel_devid_override;
Chia-I Wu1c527012014-08-23 14:57:35 +080035int intel_debug = -1;
36
37static void intel_debug_init(void)
38{
39 const char *env;
40
41 if (intel_debug >= 0)
42 return;
43
44 intel_debug = 0;
45
46 /* parse comma-separated debug options */
47 env = getenv("INTEL_DEBUG");
48 while (env) {
49 const char *p = strchr(env, ',');
50 size_t len;
51
52 if (p)
53 len = p - env;
54 else
55 len = strlen(env);
56
Courtney Goeltzenleuchterd9fc9842014-10-13 12:58:25 -060057 if (len > 0) {
58 if (strncmp(env, "batch", len) == 0) {
59 intel_debug |= INTEL_DEBUG_BATCH;
60 } else if (strncmp(env, "nohw", len) == 0) {
61 intel_debug |= INTEL_DEBUG_NOHW;
Chia-I Wu3fb47ce2014-10-28 11:19:36 +080062 } else if (strncmp(env, "nocache", len) == 0) {
63 intel_debug |= INTEL_DEBUG_NOCACHE;
Courtney Goeltzenleuchterd9fc9842014-10-13 12:58:25 -060064 } else if (strncmp(env, "0x", 2) == 0) {
65 intel_debug |= INTEL_DEBUG_NOHW;
66 intel_devid_override = strtol(env, NULL, 16);
67 }
Chia-I Wu73019ad2014-08-29 12:01:13 +080068 }
Chia-I Wu1c527012014-08-23 14:57:35 +080069
70 if (!p)
71 break;
72
73 env = p + 1;
74 }
75}
Jon Ashburn815bddd2014-10-16 15:48:50 -060076
Chia-I Wu023ef682014-09-15 11:06:50 +080077ICD_EXPORT XGL_RESULT XGLAPI xglInitAndEnumerateGpus(
78 const XGL_APPLICATION_INFO* pAppInfo,
79 const XGL_ALLOC_CALLBACKS* pAllocCb,
80 XGL_UINT maxGpus,
81 XGL_UINT* pGpuCount,
82 XGL_PHYSICAL_GPU* pGpus)
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -060083{
Chia-I Wu023ef682014-09-15 11:06:50 +080084 struct icd_drm_device *devices, *dev;
Chia-I Wu3065c9c2014-08-04 06:28:31 +080085 XGL_RESULT ret;
Chia-I Wu023ef682014-09-15 11:06:50 +080086 XGL_UINT count;
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -060087
Chia-I Wu1c527012014-08-23 14:57:35 +080088 intel_debug_init();
89
Chia-I Wu900364b2015-01-03 13:55:22 +080090 ret = icd_allocator_init(pAllocCb);
Chia-I Wu3065c9c2014-08-04 06:28:31 +080091 if (ret != XGL_SUCCESS)
92 return ret;
93
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -060094 /*
Chia-I Wu023ef682014-09-15 11:06:50 +080095 * xglInitAndEnumerateGpus() can be called multiple times. Calling it more
96 * than once forces driver reinitialization.
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -060097 */
Chia-I Wua6e33492014-08-05 13:35:08 +080098 intel_gpu_remove_all();
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -060099
Chia-I Wuc7bff532014-08-06 12:14:54 +0800100 if (!maxGpus) {
101 *pGpuCount = 0;
Chia-I Wua6e33492014-08-05 13:35:08 +0800102 return XGL_SUCCESS;
Chia-I Wuc7bff532014-08-06 12:14:54 +0800103 }
Chia-I Wua6e33492014-08-05 13:35:08 +0800104
Chia-I Wu023ef682014-09-15 11:06:50 +0800105 devices = icd_drm_enumerate(0x8086);
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -0600106
Chia-I Wu023ef682014-09-15 11:06:50 +0800107 count = 0;
108 dev = devices;
109 while (dev) {
Chia-I Wuf07865e2014-09-15 13:52:21 +0800110 const char *primary_node, *render_node;
Chia-I Wu4d09f452014-10-13 16:21:39 +0800111 int devid;
Chia-I Wua6e33492014-08-05 13:35:08 +0800112 struct intel_gpu *gpu;
113
Chia-I Wuf07865e2014-09-15 13:52:21 +0800114 primary_node = icd_drm_get_devnode(dev, ICD_DRM_MINOR_LEGACY);
Chia-I Wuf1356882014-09-18 16:39:06 +0800115 if (!primary_node)
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -0600116 continue;
Chia-I Wua6e33492014-08-05 13:35:08 +0800117
Chia-I Wuf1356882014-09-18 16:39:06 +0800118 render_node = icd_drm_get_devnode(dev, ICD_DRM_MINOR_RENDER);
119
Chia-I Wu4d09f452014-10-13 16:21:39 +0800120 devid = (intel_devid_override) ? intel_devid_override : dev->devid;
121 ret = intel_gpu_add(devid, primary_node, render_node, &gpu);
Chia-I Wua6e33492014-08-05 13:35:08 +0800122 if (ret == XGL_SUCCESS) {
123 pGpus[count++] = (XGL_PHYSICAL_GPU) gpu;
124 if (count >= maxGpus)
125 break;
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -0600126 }
Chia-I Wu023ef682014-09-15 11:06:50 +0800127
128 dev = dev->next;
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -0600129 }
Chia-I Wua6e33492014-08-05 13:35:08 +0800130
Chia-I Wu023ef682014-09-15 11:06:50 +0800131 icd_drm_release(devices);
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -0600132
Chia-I Wua6e33492014-08-05 13:35:08 +0800133 *pGpuCount = count;
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -0600134
Chia-I Wua6e33492014-08-05 13:35:08 +0800135 return (count > 0) ? XGL_SUCCESS : XGL_ERROR_UNAVAILABLE;
Courtney Goeltzenleuchtere06e72d2014-08-01 12:44:23 -0600136}
Chia-I Wub02558c2015-01-03 15:21:51 +0800137
Chia-I Wu96177272015-01-03 15:27:41 +0800138ICD_EXPORT XGL_RESULT XGLAPI xglDbgRegisterMsgCallback(
Chia-I Wub02558c2015-01-03 15:21:51 +0800139 XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback,
140 XGL_VOID* pUserData)
141{
142 return icd_logger_add_callback(pfnMsgCallback, pUserData);
143}
144
Chia-I Wu96177272015-01-03 15:27:41 +0800145ICD_EXPORT XGL_RESULT XGLAPI xglDbgUnregisterMsgCallback(
Chia-I Wub02558c2015-01-03 15:21:51 +0800146 XGL_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
147{
148 return icd_logger_remove_callback(pfnMsgCallback);
149}
150
Chia-I Wu96177272015-01-03 15:27:41 +0800151ICD_EXPORT XGL_RESULT XGLAPI xglDbgSetGlobalOption(
Chia-I Wub02558c2015-01-03 15:21:51 +0800152 XGL_DBG_GLOBAL_OPTION dbgOption,
153 XGL_SIZE dataSize,
154 const XGL_VOID* pData)
155{
156 XGL_RESULT res = XGL_SUCCESS;
157
158 if (dataSize == 0)
159 return XGL_ERROR_INVALID_VALUE;
160
161 switch (dbgOption) {
162 case XGL_DBG_OPTION_DEBUG_ECHO_ENABLE:
163 case XGL_DBG_OPTION_BREAK_ON_ERROR:
164 case XGL_DBG_OPTION_BREAK_ON_WARNING:
165 res = icd_logger_set_bool(dbgOption, *((const bool *) pData));
166 break;
167 default:
168 res = XGL_ERROR_INVALID_VALUE;
169 break;
170 }
171
172 return res;
173}