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" |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 32 | #include "dispatch.h" |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 33 | |
Chia-I Wu | 73019ad | 2014-08-29 12:01:13 +0800 | [diff] [blame] | 34 | static int intel_devid_override; |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 35 | int intel_debug = -1; |
| 36 | |
| 37 | static 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 Goeltzenleuchter | d9fc984 | 2014-10-13 12:58:25 -0600 | [diff] [blame] | 57 | 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 Wu | 3fb47ce | 2014-10-28 11:19:36 +0800 | [diff] [blame] | 62 | } else if (strncmp(env, "nocache", len) == 0) { |
| 63 | intel_debug |= INTEL_DEBUG_NOCACHE; |
Courtney Goeltzenleuchter | d9fc984 | 2014-10-13 12:58:25 -0600 | [diff] [blame] | 64 | } else if (strncmp(env, "0x", 2) == 0) { |
| 65 | intel_debug |= INTEL_DEBUG_NOHW; |
| 66 | intel_devid_override = strtol(env, NULL, 16); |
| 67 | } |
Chia-I Wu | 73019ad | 2014-08-29 12:01:13 +0800 | [diff] [blame] | 68 | } |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 69 | |
| 70 | if (!p) |
| 71 | break; |
| 72 | |
| 73 | env = p + 1; |
| 74 | } |
| 75 | } |
Jon Ashburn | 815bddd | 2014-10-16 15:48:50 -0600 | [diff] [blame^] | 76 | |
| 77 | ICD_EXPORT XGL_VOID xglSetDispatch(XGL_LAYER_DISPATCH_TABLE *dispatch, XGL_BOOL debug) |
| 78 | { |
| 79 | struct icd_dispatch_table * disp = (struct icd_dispatch_table *) dispatch; |
| 80 | intelSetDispatch(disp, debug); |
| 81 | } |
| 82 | |
Jon Ashburn | d43f9b6 | 2014-10-14 19:15:22 -0600 | [diff] [blame] | 83 | ICD_EXPORT void * xglGetProcAddr(XGL_PHYSICAL_GPU gpu, const XGL_CHAR * pName) |
| 84 | { |
| 85 | return intelGetProcAddr(gpu, pName); |
| 86 | } |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 87 | |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame] | 88 | ICD_EXPORT XGL_RESULT XGLAPI xglInitAndEnumerateGpus( |
| 89 | const XGL_APPLICATION_INFO* pAppInfo, |
| 90 | const XGL_ALLOC_CALLBACKS* pAllocCb, |
| 91 | XGL_UINT maxGpus, |
| 92 | XGL_UINT* pGpuCount, |
| 93 | XGL_PHYSICAL_GPU* pGpus) |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 94 | { |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame] | 95 | struct icd_drm_device *devices, *dev; |
Chia-I Wu | 3065c9c | 2014-08-04 06:28:31 +0800 | [diff] [blame] | 96 | XGL_RESULT ret; |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame] | 97 | XGL_UINT count; |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 98 | |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 99 | intel_debug_init(); |
| 100 | |
Chia-I Wu | c217f80 | 2014-08-05 10:17:50 +0800 | [diff] [blame] | 101 | ret = icd_set_allocator(pAllocCb); |
Chia-I Wu | 3065c9c | 2014-08-04 06:28:31 +0800 | [diff] [blame] | 102 | if (ret != XGL_SUCCESS) |
| 103 | return ret; |
| 104 | |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 105 | /* |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame] | 106 | * xglInitAndEnumerateGpus() can be called multiple times. Calling it more |
| 107 | * than once forces driver reinitialization. |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 108 | */ |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 109 | intel_gpu_remove_all(); |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 110 | |
Chia-I Wu | c7bff53 | 2014-08-06 12:14:54 +0800 | [diff] [blame] | 111 | if (!maxGpus) { |
| 112 | *pGpuCount = 0; |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 113 | return XGL_SUCCESS; |
Chia-I Wu | c7bff53 | 2014-08-06 12:14:54 +0800 | [diff] [blame] | 114 | } |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 115 | |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame] | 116 | devices = icd_drm_enumerate(0x8086); |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 117 | |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame] | 118 | count = 0; |
| 119 | dev = devices; |
| 120 | while (dev) { |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 121 | const char *primary_node, *render_node; |
Chia-I Wu | 4d09f45 | 2014-10-13 16:21:39 +0800 | [diff] [blame] | 122 | int devid; |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 123 | struct intel_gpu *gpu; |
| 124 | |
Chia-I Wu | f07865e | 2014-09-15 13:52:21 +0800 | [diff] [blame] | 125 | primary_node = icd_drm_get_devnode(dev, ICD_DRM_MINOR_LEGACY); |
Chia-I Wu | f135688 | 2014-09-18 16:39:06 +0800 | [diff] [blame] | 126 | if (!primary_node) |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 127 | continue; |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 128 | |
Chia-I Wu | f135688 | 2014-09-18 16:39:06 +0800 | [diff] [blame] | 129 | render_node = icd_drm_get_devnode(dev, ICD_DRM_MINOR_RENDER); |
| 130 | |
Chia-I Wu | 4d09f45 | 2014-10-13 16:21:39 +0800 | [diff] [blame] | 131 | devid = (intel_devid_override) ? intel_devid_override : dev->devid; |
| 132 | ret = intel_gpu_add(devid, primary_node, render_node, &gpu); |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 133 | if (ret == XGL_SUCCESS) { |
| 134 | pGpus[count++] = (XGL_PHYSICAL_GPU) gpu; |
| 135 | if (count >= maxGpus) |
| 136 | break; |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 137 | } |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame] | 138 | |
| 139 | dev = dev->next; |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 140 | } |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 141 | |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame] | 142 | icd_drm_release(devices); |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 143 | |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 144 | *pGpuCount = count; |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 145 | |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 146 | return (count > 0) ? XGL_SUCCESS : XGL_ERROR_UNAVAILABLE; |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 147 | } |