| 1 | /* |
| 2 | * Copyright © 2017 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | #include <stdint.h> |
| 25 | #include <unistd.h> |
| 26 | #include <fcntl.h> |
| 27 | |
| 28 | #include "intel/dev/intel_device_info.h" |
| 29 | |
| 30 | #include "util/os_file.h" |
| 31 | |
| 32 | #include "virtio/virtio-gpu/drm_hw.h" |
| 33 | |
| 34 | #include "crocus_drm_public.h" |
| 35 | #include "crocus/crocus_screen.h" |
| 36 | |
| 37 | struct pipe_screen * |
| 38 | crocus_drm_screen_create(int fd, const struct pipe_screen_config *config) |
| 39 | { |
| 40 | int newfd = os_dupfd_cloexec(fd); |
| 41 | if (newfd < 0) |
| 42 | return NULL; |
| 43 | return crocus_screen_create(newfd, config); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Check if the native-context type exposed by virtgpu is one we |
| 48 | * support, and that we support the underlying device. |
| 49 | */ |
| 50 | bool |
| 51 | crocus_drm_probe_nctx(int fd, const struct virgl_renderer_capset_drm *caps) |
| 52 | { |
| 53 | #ifdef HAVE_INTEL_VIRTIO |
| 54 | if (caps->context_type != VIRTGPU_DRM_CONTEXT_I915) |
| 55 | return false; |
| 56 | |
| 57 | if (debug_get_bool_option("INTEL_VIRTIO_DISABLE", false)) |
| 58 | return false; |
| 59 | |
| 60 | struct intel_device_info devinfo; |
| 61 | |
| 62 | if (!intel_get_device_info_from_pci_id(caps->u.intel.pci_device_id, |
| 63 | &devinfo)) |
| 64 | return false; |
| 65 | |
| 66 | if (devinfo.ver > 8) |
| 67 | return false; |
| 68 | |
| 69 | if (devinfo.ver == 8) { |
| 70 | if (devinfo.platform != INTEL_PLATFORM_CHV && |
| 71 | !getenv("CROCUS_GEN8")) |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | return true; |
| 76 | #else |
| 77 | return false; |
| 78 | #endif |
| 79 | } |