Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 1 | /* |
| 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 Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 25 | * Courtney Goeltzenleuchter <courtney@lunarg.com> |
| 26 | * Chia-I Wu <olv@lunarg.com> |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 27 | */ |
| 28 | |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame] | 29 | #include "icd-enumerate-drm.h" |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 30 | #include "gpu.h" |
| 31 | #include "intel.h" |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 32 | |
Chia-I Wu | 73019ad | 2014-08-29 12:01:13 +0800 | [diff] [blame] | 33 | static int intel_devid_override; |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 34 | int intel_debug = -1; |
| 35 | |
| 36 | static 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 Goeltzenleuchter | d9fc984 | 2014-10-13 12:58:25 -0600 | [diff] [blame^] | 56 | 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 Wu | 73019ad | 2014-08-29 12:01:13 +0800 | [diff] [blame] | 65 | } |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 66 | |
| 67 | if (!p) |
| 68 | break; |
| 69 | |
| 70 | env = p + 1; |
| 71 | } |
| 72 | } |
| 73 | |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame] | 74 | ICD_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 Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 80 | { |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame] | 81 | struct icd_drm_device *devices, *dev; |
Chia-I Wu | 3065c9c | 2014-08-04 06:28:31 +0800 | [diff] [blame] | 82 | XGL_RESULT ret; |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame] | 83 | XGL_UINT count; |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 84 | |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 85 | intel_debug_init(); |
| 86 | |
Chia-I Wu | c217f80 | 2014-08-05 10:17:50 +0800 | [diff] [blame] | 87 | ret = icd_set_allocator(pAllocCb); |
Chia-I Wu | 3065c9c | 2014-08-04 06:28:31 +0800 | [diff] [blame] | 88 | if (ret != XGL_SUCCESS) |
| 89 | return ret; |
| 90 | |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 91 | /* |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame] | 92 | * xglInitAndEnumerateGpus() can be called multiple times. Calling it more |
| 93 | * than once forces driver reinitialization. |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 94 | */ |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 95 | intel_gpu_remove_all(); |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 96 | |
Chia-I Wu | c7bff53 | 2014-08-06 12:14:54 +0800 | [diff] [blame] | 97 | if (!maxGpus) { |
| 98 | *pGpuCount = 0; |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 99 | return XGL_SUCCESS; |
Chia-I Wu | c7bff53 | 2014-08-06 12:14:54 +0800 | [diff] [blame] | 100 | } |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 101 | |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame] | 102 | devices = icd_drm_enumerate(0x8086); |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 103 | |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame] | 104 | count = 0; |
| 105 | dev = devices; |
| 106 | while (dev) { |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 107 | const char *primary_node, *render_node; |
Chia-I Wu | 4d09f45 | 2014-10-13 16:21:39 +0800 | [diff] [blame] | 108 | int devid; |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 109 | struct intel_gpu *gpu; |
| 110 | |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 111 | primary_node = icd_drm_get_devnode(dev, ICD_DRM_MINOR_LEGACY); |
Chia-I Wu | f135688 | 2014-09-18 16:39:06 +0800 | [diff] [blame] | 112 | if (!primary_node) |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 113 | continue; |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 114 | |
Chia-I Wu | f135688 | 2014-09-18 16:39:06 +0800 | [diff] [blame] | 115 | render_node = icd_drm_get_devnode(dev, ICD_DRM_MINOR_RENDER); |
| 116 | |
Chia-I Wu | 4d09f45 | 2014-10-13 16:21:39 +0800 | [diff] [blame] | 117 | devid = (intel_devid_override) ? intel_devid_override : dev->devid; |
| 118 | ret = intel_gpu_add(devid, primary_node, render_node, &gpu); |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 119 | if (ret == XGL_SUCCESS) { |
| 120 | pGpus[count++] = (XGL_PHYSICAL_GPU) gpu; |
| 121 | if (count >= maxGpus) |
| 122 | break; |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 123 | } |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame] | 124 | |
| 125 | dev = dev->next; |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 126 | } |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 127 | |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame] | 128 | icd_drm_release(devices); |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 129 | |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 130 | *pGpuCount = count; |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 131 | |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 132 | return (count > 0) ? XGL_SUCCESS : XGL_ERROR_UNAVAILABLE; |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 133 | } |