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 | |
Chia-I Wu | 73019ad | 2014-08-29 12:01:13 +0800 | [diff] [blame] | 56 | if (strncmp(env, "batch", len) == 0) { |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 57 | intel_debug |= INTEL_DEBUG_BATCH; |
Chia-I Wu | 73019ad | 2014-08-29 12:01:13 +0800 | [diff] [blame] | 58 | } else if (strncmp(env, "nohw", len) == 0) { |
Chia-I Wu | 93ada31 | 2014-08-23 15:02:25 +0800 | [diff] [blame] | 59 | intel_debug |= INTEL_DEBUG_NOHW; |
Chia-I Wu | 73019ad | 2014-08-29 12:01:13 +0800 | [diff] [blame] | 60 | } else if (strncmp(env, "0x", 2) == 0) { |
| 61 | intel_debug |= INTEL_DEBUG_NOHW; |
| 62 | intel_devid_override = strtol(env, NULL, 16); |
| 63 | } |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 64 | |
| 65 | if (!p) |
| 66 | break; |
| 67 | |
| 68 | env = p + 1; |
| 69 | } |
| 70 | } |
| 71 | |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame^] | 72 | ICD_EXPORT XGL_RESULT XGLAPI xglInitAndEnumerateGpus( |
| 73 | const XGL_APPLICATION_INFO* pAppInfo, |
| 74 | const XGL_ALLOC_CALLBACKS* pAllocCb, |
| 75 | XGL_UINT maxGpus, |
| 76 | XGL_UINT* pGpuCount, |
| 77 | XGL_PHYSICAL_GPU* pGpus) |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 78 | { |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame^] | 79 | struct icd_drm_device *devices, *dev; |
Chia-I Wu | 3065c9c | 2014-08-04 06:28:31 +0800 | [diff] [blame] | 80 | XGL_RESULT ret; |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame^] | 81 | XGL_UINT count; |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 82 | |
Chia-I Wu | 1c52701 | 2014-08-23 14:57:35 +0800 | [diff] [blame] | 83 | intel_debug_init(); |
| 84 | |
Chia-I Wu | c217f80 | 2014-08-05 10:17:50 +0800 | [diff] [blame] | 85 | ret = icd_set_allocator(pAllocCb); |
Chia-I Wu | 3065c9c | 2014-08-04 06:28:31 +0800 | [diff] [blame] | 86 | if (ret != XGL_SUCCESS) |
| 87 | return ret; |
| 88 | |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 89 | /* |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame^] | 90 | * xglInitAndEnumerateGpus() can be called multiple times. Calling it more |
| 91 | * than once forces driver reinitialization. |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 92 | */ |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 93 | intel_gpu_remove_all(); |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 94 | |
Chia-I Wu | c7bff53 | 2014-08-06 12:14:54 +0800 | [diff] [blame] | 95 | if (!maxGpus) { |
| 96 | *pGpuCount = 0; |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 97 | return XGL_SUCCESS; |
Chia-I Wu | c7bff53 | 2014-08-06 12:14:54 +0800 | [diff] [blame] | 98 | } |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 99 | |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame^] | 100 | devices = icd_drm_enumerate(0x8086); |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 101 | |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame^] | 102 | count = 0; |
| 103 | dev = devices; |
| 104 | while (dev) { |
| 105 | const char *devnode; |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 106 | struct intel_gpu *gpu; |
| 107 | |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame^] | 108 | devnode = icd_drm_get_devnode(dev, ICD_DRM_MINOR_RENDER); |
| 109 | if (!devnode) |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 110 | continue; |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 111 | |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame^] | 112 | ret = intel_gpu_add(dev->devid, devnode, &gpu); |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 113 | if (ret == XGL_SUCCESS) { |
| 114 | pGpus[count++] = (XGL_PHYSICAL_GPU) gpu; |
| 115 | if (count >= maxGpus) |
| 116 | break; |
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 | |
| 119 | dev = dev->next; |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 120 | } |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 121 | |
Chia-I Wu | 023ef68 | 2014-09-15 11:06:50 +0800 | [diff] [blame^] | 122 | icd_drm_release(devices); |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 123 | |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 124 | *pGpuCount = count; |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 125 | |
Chia-I Wu | a6e3349 | 2014-08-05 13:35:08 +0800 | [diff] [blame] | 126 | return (count > 0) ? XGL_SUCCESS : XGL_ERROR_UNAVAILABLE; |
Courtney Goeltzenleuchter | e06e72d | 2014-08-01 12:44:23 -0600 | [diff] [blame] | 127 | } |