Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 1 | /* |
Daniele Castagna | 7a755de | 2016-12-16 17:32:30 -0500 | [diff] [blame] | 2 | * Copyright 2014 The Chromium OS Authors. All rights reserved. |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 3 | * Use of this source code is governed by a BSD-style license that can be |
| 4 | * found in the LICENSE file. |
| 5 | */ |
| 6 | |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 7 | #ifdef DRV_I915 |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 8 | |
Kristian H. Kristensen | e8778f0 | 2018-04-04 14:21:41 -0700 | [diff] [blame] | 9 | #include <assert.h> |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 10 | #include <errno.h> |
Gurchetan Singh | 82a8eed | 2017-01-03 13:01:37 -0800 | [diff] [blame] | 11 | #include <i915_drm.h> |
Kristian H. Kristensen | 9c3fb32 | 2018-04-11 15:55:13 -0700 | [diff] [blame] | 12 | #include <stdbool.h> |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame] | 13 | #include <stdio.h> |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 14 | #include <string.h> |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 15 | #include <sys/mman.h> |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 16 | #include <xf86drm.h> |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 17 | |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 18 | #include "drv_priv.h" |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 19 | #include "helpers.h" |
| 20 | #include "util.h" |
| 21 | |
Gurchetan Singh | 68af9c2 | 2017-01-18 13:48:11 -0800 | [diff] [blame] | 22 | #define I915_CACHELINE_SIZE 64 |
| 23 | #define I915_CACHELINE_MASK (I915_CACHELINE_SIZE - 1) |
| 24 | |
Gurchetan Singh | 767c538 | 2018-05-05 00:42:12 +0000 | [diff] [blame] | 25 | static const uint32_t render_target_formats[] = { DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB1555, |
Gurchetan Singh | abe44f6 | 2018-06-06 17:01:51 -0700 | [diff] [blame] | 26 | DRM_FORMAT_ARGB8888, DRM_FORMAT_BGR888, |
| 27 | DRM_FORMAT_RGB565, DRM_FORMAT_XBGR2101010, |
| 28 | DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB1555, |
| 29 | DRM_FORMAT_XRGB2101010, DRM_FORMAT_XRGB8888 }; |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 30 | |
Tomasz Figa | b92e4f8 | 2017-06-22 16:52:43 +0900 | [diff] [blame] | 31 | static const uint32_t tileable_texture_source_formats[] = { DRM_FORMAT_GR88, DRM_FORMAT_R8, |
| 32 | DRM_FORMAT_UYVY, DRM_FORMAT_YUYV }; |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 33 | |
Tomasz Figa | b92e4f8 | 2017-06-22 16:52:43 +0900 | [diff] [blame] | 34 | static const uint32_t texture_source_formats[] = { DRM_FORMAT_YVU420, DRM_FORMAT_YVU420_ANDROID, |
| 35 | DRM_FORMAT_NV12 }; |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 36 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 37 | struct i915_device { |
Gurchetan Singh | 68af9c2 | 2017-01-18 13:48:11 -0800 | [diff] [blame] | 38 | uint32_t gen; |
| 39 | int32_t has_llc; |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
Gurchetan Singh | 68af9c2 | 2017-01-18 13:48:11 -0800 | [diff] [blame] | 42 | static uint32_t i915_get_gen(int device_id) |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 43 | { |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 44 | const uint16_t gen3_ids[] = { 0x2582, 0x2592, 0x2772, 0x27A2, 0x27AE, |
| 45 | 0x29C2, 0x29B2, 0x29D2, 0xA001, 0xA011 }; |
Stéphane Marchesin | a39dfde | 2014-09-15 15:38:25 -0700 | [diff] [blame] | 46 | unsigned i; |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 47 | for (i = 0; i < ARRAY_SIZE(gen3_ids); i++) |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 48 | if (gen3_ids[i] == device_id) |
| 49 | return 3; |
| 50 | |
| 51 | return 4; |
| 52 | } |
| 53 | |
Kristian H. Kristensen | 9c3fb32 | 2018-04-11 15:55:13 -0700 | [diff] [blame] | 54 | /* |
| 55 | * We allow allocation of ARGB formats for SCANOUT if the corresponding XRGB |
| 56 | * formats supports it. It's up to the caller (chrome ozone) to ultimately not |
| 57 | * scan out ARGB if the display controller only supports XRGB, but we'll allow |
| 58 | * the allocation of the bo here. |
| 59 | */ |
| 60 | static bool format_compatible(const struct combination *combo, uint32_t format) |
| 61 | { |
| 62 | if (combo->format == format) |
| 63 | return true; |
| 64 | |
| 65 | switch (format) { |
| 66 | case DRM_FORMAT_XRGB8888: |
| 67 | return combo->format == DRM_FORMAT_ARGB8888; |
| 68 | case DRM_FORMAT_XBGR8888: |
| 69 | return combo->format == DRM_FORMAT_ABGR8888; |
| 70 | case DRM_FORMAT_RGBX8888: |
| 71 | return combo->format == DRM_FORMAT_RGBA8888; |
| 72 | case DRM_FORMAT_BGRX8888: |
| 73 | return combo->format == DRM_FORMAT_BGRA8888; |
| 74 | default: |
| 75 | return false; |
| 76 | } |
| 77 | } |
| 78 | |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 79 | static int i915_add_kms_item(struct driver *drv, const struct kms_item *item) |
| 80 | { |
| 81 | uint32_t i; |
| 82 | struct combination *combo; |
| 83 | |
| 84 | /* |
| 85 | * Older hardware can't scanout Y-tiled formats. Newer devices can, and |
| 86 | * report this functionality via format modifiers. |
| 87 | */ |
Gurchetan Singh | bc9a87d | 2017-11-03 17:17:35 -0700 | [diff] [blame] | 88 | for (i = 0; i < drv_array_size(drv->combos); i++) { |
| 89 | combo = (struct combination *)drv_array_at_idx(drv->combos, i); |
Kristian H. Kristensen | 9c3fb32 | 2018-04-11 15:55:13 -0700 | [diff] [blame] | 90 | if (!format_compatible(combo, item->format)) |
Tomasz Figa | e821cc2 | 2017-07-08 15:53:11 +0900 | [diff] [blame] | 91 | continue; |
| 92 | |
Gurchetan Singh | d118a0e | 2018-01-12 23:31:50 +0000 | [diff] [blame] | 93 | if (item->modifier == DRM_FORMAT_MOD_LINEAR && |
Tomasz Figa | e821cc2 | 2017-07-08 15:53:11 +0900 | [diff] [blame] | 94 | combo->metadata.tiling == I915_TILING_X) { |
| 95 | /* |
| 96 | * FIXME: drv_query_kms() does not report the available modifiers |
| 97 | * yet, but we know that all hardware can scanout from X-tiled |
| 98 | * buffers, so let's add this to our combinations, except for |
| 99 | * cursor, which must not be tiled. |
| 100 | */ |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 101 | combo->use_flags |= item->use_flags & ~BO_USE_CURSOR; |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 102 | } |
Tomasz Figa | e821cc2 | 2017-07-08 15:53:11 +0900 | [diff] [blame] | 103 | |
Kristian H. Kristensen | 3cb5bba | 2018-04-04 16:10:42 -0700 | [diff] [blame] | 104 | /* If we can scanout NV12, we support all tiling modes. */ |
| 105 | if (item->format == DRM_FORMAT_NV12) |
| 106 | combo->use_flags |= item->use_flags; |
| 107 | |
Tomasz Figa | e821cc2 | 2017-07-08 15:53:11 +0900 | [diff] [blame] | 108 | if (combo->metadata.modifier == item->modifier) |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 109 | combo->use_flags |= item->use_flags; |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | static int i915_add_combinations(struct driver *drv) |
| 116 | { |
| 117 | int ret; |
Gurchetan Singh | bc9a87d | 2017-11-03 17:17:35 -0700 | [diff] [blame] | 118 | uint32_t i; |
| 119 | struct drv_array *kms_items; |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 120 | struct format_metadata metadata; |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 121 | uint64_t render_use_flags, texture_use_flags; |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 122 | |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 123 | render_use_flags = BO_USE_RENDER_MASK; |
| 124 | texture_use_flags = BO_USE_TEXTURE_MASK; |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 125 | |
| 126 | metadata.tiling = I915_TILING_NONE; |
| 127 | metadata.priority = 1; |
Kristian H. Kristensen | bc8c593 | 2017-10-24 18:36:32 -0700 | [diff] [blame] | 128 | metadata.modifier = DRM_FORMAT_MOD_LINEAR; |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 129 | |
Gurchetan Singh | d300145 | 2017-11-03 17:18:36 -0700 | [diff] [blame] | 130 | drv_add_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats), |
| 131 | &metadata, render_use_flags); |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 132 | |
Gurchetan Singh | d300145 | 2017-11-03 17:18:36 -0700 | [diff] [blame] | 133 | drv_add_combinations(drv, texture_source_formats, ARRAY_SIZE(texture_source_formats), |
| 134 | &metadata, texture_use_flags); |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 135 | |
Gurchetan Singh | d300145 | 2017-11-03 17:18:36 -0700 | [diff] [blame] | 136 | drv_add_combinations(drv, tileable_texture_source_formats, |
| 137 | ARRAY_SIZE(tileable_texture_source_formats), &metadata, |
| 138 | texture_use_flags); |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 139 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 140 | drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT); |
| 141 | drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT); |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 142 | |
Tomasz Figa | d30c0a5 | 2017-07-05 17:50:18 +0900 | [diff] [blame] | 143 | /* IPU3 camera ISP supports only NV12 output. */ |
| 144 | drv_modify_combination(drv, DRM_FORMAT_NV12, &metadata, |
Tomasz Figa | fd0b016 | 2017-07-11 18:28:02 +0900 | [diff] [blame] | 145 | BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE); |
Tomasz Figa | d30c0a5 | 2017-07-05 17:50:18 +0900 | [diff] [blame] | 146 | /* |
| 147 | * R8 format is used for Android's HAL_PIXEL_FORMAT_BLOB and is used for JPEG snapshots |
| 148 | * from camera. |
| 149 | */ |
| 150 | drv_modify_combination(drv, DRM_FORMAT_R8, &metadata, |
Tomasz Figa | fd0b016 | 2017-07-11 18:28:02 +0900 | [diff] [blame] | 151 | BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE); |
Tomasz Figa | d30c0a5 | 2017-07-05 17:50:18 +0900 | [diff] [blame] | 152 | |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 153 | render_use_flags &= ~BO_USE_RENDERSCRIPT; |
| 154 | render_use_flags &= ~BO_USE_SW_WRITE_OFTEN; |
| 155 | render_use_flags &= ~BO_USE_SW_READ_OFTEN; |
| 156 | render_use_flags &= ~BO_USE_LINEAR; |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 157 | |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 158 | texture_use_flags &= ~BO_USE_RENDERSCRIPT; |
| 159 | texture_use_flags &= ~BO_USE_SW_WRITE_OFTEN; |
| 160 | texture_use_flags &= ~BO_USE_SW_READ_OFTEN; |
| 161 | texture_use_flags &= ~BO_USE_LINEAR; |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 162 | |
| 163 | metadata.tiling = I915_TILING_X; |
| 164 | metadata.priority = 2; |
Tomasz Figa | e821cc2 | 2017-07-08 15:53:11 +0900 | [diff] [blame] | 165 | metadata.modifier = I915_FORMAT_MOD_X_TILED; |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 166 | |
Gurchetan Singh | d300145 | 2017-11-03 17:18:36 -0700 | [diff] [blame] | 167 | drv_add_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats), |
| 168 | &metadata, render_use_flags); |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 169 | |
Gurchetan Singh | d300145 | 2017-11-03 17:18:36 -0700 | [diff] [blame] | 170 | drv_add_combinations(drv, tileable_texture_source_formats, |
| 171 | ARRAY_SIZE(tileable_texture_source_formats), &metadata, |
| 172 | texture_use_flags); |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 173 | |
| 174 | metadata.tiling = I915_TILING_Y; |
| 175 | metadata.priority = 3; |
Tomasz Figa | e821cc2 | 2017-07-08 15:53:11 +0900 | [diff] [blame] | 176 | metadata.modifier = I915_FORMAT_MOD_Y_TILED; |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 177 | |
Gurchetan Singh | d300145 | 2017-11-03 17:18:36 -0700 | [diff] [blame] | 178 | drv_add_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats), |
| 179 | &metadata, render_use_flags); |
Gurchetan Singh | 8ac0c9a | 2017-05-15 09:34:22 -0700 | [diff] [blame] | 180 | |
Gurchetan Singh | d300145 | 2017-11-03 17:18:36 -0700 | [diff] [blame] | 181 | drv_add_combinations(drv, tileable_texture_source_formats, |
| 182 | ARRAY_SIZE(tileable_texture_source_formats), &metadata, |
| 183 | texture_use_flags); |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 184 | |
Kristian H. Kristensen | 3cb5bba | 2018-04-04 16:10:42 -0700 | [diff] [blame] | 185 | /* Support y-tiled NV12 for libva */ |
| 186 | const uint32_t nv12_format = DRM_FORMAT_NV12; |
| 187 | drv_add_combinations(drv, &nv12_format, 1, &metadata, |
| 188 | BO_USE_TEXTURE | BO_USE_HW_VIDEO_DECODER); |
| 189 | |
Gurchetan Singh | bc9a87d | 2017-11-03 17:17:35 -0700 | [diff] [blame] | 190 | kms_items = drv_query_kms(drv); |
| 191 | if (!kms_items) |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 192 | return 0; |
| 193 | |
Gurchetan Singh | bc9a87d | 2017-11-03 17:17:35 -0700 | [diff] [blame] | 194 | for (i = 0; i < drv_array_size(kms_items); i++) { |
| 195 | ret = i915_add_kms_item(drv, (struct kms_item *)drv_array_at_idx(kms_items, i)); |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 196 | if (ret) { |
Gurchetan Singh | bc9a87d | 2017-11-03 17:17:35 -0700 | [diff] [blame] | 197 | drv_array_destroy(kms_items); |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 198 | return ret; |
| 199 | } |
| 200 | } |
| 201 | |
Gurchetan Singh | bc9a87d | 2017-11-03 17:17:35 -0700 | [diff] [blame] | 202 | drv_array_destroy(kms_items); |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 203 | return 0; |
| 204 | } |
| 205 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 206 | static int i915_align_dimensions(struct bo *bo, uint32_t tiling, uint32_t *stride, |
| 207 | uint32_t *aligned_height) |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 208 | { |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 209 | struct i915_device *i915 = bo->drv->priv; |
Kristian H. Kristensen | e8778f0 | 2018-04-04 14:21:41 -0700 | [diff] [blame] | 210 | uint32_t horizontal_alignment; |
| 211 | uint32_t vertical_alignment; |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 212 | |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 213 | switch (tiling) { |
Gurchetan Singh | d6fb577 | 2016-08-29 19:13:51 -0700 | [diff] [blame] | 214 | default: |
| 215 | case I915_TILING_NONE: |
Kristian H. Kristensen | e8778f0 | 2018-04-04 14:21:41 -0700 | [diff] [blame] | 216 | /* |
| 217 | * The Intel GPU doesn't need any alignment in linear mode, |
| 218 | * but libva requires the allocation stride to be aligned to |
| 219 | * 16 bytes and height to 4 rows. Further, we round up the |
| 220 | * horizontal alignment so that row start on a cache line (64 |
| 221 | * bytes). |
| 222 | */ |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 223 | horizontal_alignment = 64; |
Kristian H. Kristensen | e8778f0 | 2018-04-04 14:21:41 -0700 | [diff] [blame] | 224 | vertical_alignment = 4; |
Gurchetan Singh | d6fb577 | 2016-08-29 19:13:51 -0700 | [diff] [blame] | 225 | break; |
Stéphane Marchesin | 5d867a4 | 2014-11-24 17:09:49 -0800 | [diff] [blame] | 226 | |
Gurchetan Singh | d6fb577 | 2016-08-29 19:13:51 -0700 | [diff] [blame] | 227 | case I915_TILING_X: |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 228 | horizontal_alignment = 512; |
| 229 | vertical_alignment = 8; |
Gurchetan Singh | d6fb577 | 2016-08-29 19:13:51 -0700 | [diff] [blame] | 230 | break; |
| 231 | |
| 232 | case I915_TILING_Y: |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 233 | if (i915->gen == 3) { |
| 234 | horizontal_alignment = 512; |
| 235 | vertical_alignment = 8; |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 236 | } else { |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 237 | horizontal_alignment = 128; |
| 238 | vertical_alignment = 32; |
Gurchetan Singh | d6fb577 | 2016-08-29 19:13:51 -0700 | [diff] [blame] | 239 | } |
| 240 | break; |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 241 | } |
Stéphane Marchesin | 5d867a4 | 2014-11-24 17:09:49 -0800 | [diff] [blame] | 242 | |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 243 | *aligned_height = ALIGN(bo->height, vertical_alignment); |
| 244 | if (i915->gen > 3) { |
| 245 | *stride = ALIGN(*stride, horizontal_alignment); |
Stéphane Marchesin | 5d867a4 | 2014-11-24 17:09:49 -0800 | [diff] [blame] | 246 | } else { |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 247 | while (*stride > horizontal_alignment) |
| 248 | horizontal_alignment <<= 1; |
| 249 | |
| 250 | *stride = horizontal_alignment; |
Stéphane Marchesin | 5d867a4 | 2014-11-24 17:09:49 -0800 | [diff] [blame] | 251 | } |
Stéphane Marchesin | 5d867a4 | 2014-11-24 17:09:49 -0800 | [diff] [blame] | 252 | |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 253 | if (i915->gen <= 3 && *stride > 8192) |
| 254 | return -EINVAL; |
Stéphane Marchesin | 5d867a4 | 2014-11-24 17:09:49 -0800 | [diff] [blame] | 255 | |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 256 | return 0; |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Gurchetan Singh | 68af9c2 | 2017-01-18 13:48:11 -0800 | [diff] [blame] | 259 | static void i915_clflush(void *start, size_t size) |
| 260 | { |
| 261 | void *p = (void *)(((uintptr_t)start) & ~I915_CACHELINE_MASK); |
| 262 | void *end = (void *)((uintptr_t)start + size); |
| 263 | |
| 264 | __builtin_ia32_mfence(); |
| 265 | while (p < end) { |
| 266 | __builtin_ia32_clflush(p); |
| 267 | p = (void *)((uintptr_t)p + I915_CACHELINE_SIZE); |
| 268 | } |
| 269 | } |
| 270 | |
Gurchetan Singh | 3eb8d8f | 2017-01-03 13:36:13 -0800 | [diff] [blame] | 271 | static int i915_init(struct driver *drv) |
| 272 | { |
Gurchetan Singh | 3eb8d8f | 2017-01-03 13:36:13 -0800 | [diff] [blame] | 273 | int ret; |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame] | 274 | int device_id; |
| 275 | struct i915_device *i915; |
| 276 | drm_i915_getparam_t get_param; |
Gurchetan Singh | 3eb8d8f | 2017-01-03 13:36:13 -0800 | [diff] [blame] | 277 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame] | 278 | i915 = calloc(1, sizeof(*i915)); |
| 279 | if (!i915) |
| 280 | return -ENOMEM; |
Gurchetan Singh | 3eb8d8f | 2017-01-03 13:36:13 -0800 | [diff] [blame] | 281 | |
| 282 | memset(&get_param, 0, sizeof(get_param)); |
| 283 | get_param.param = I915_PARAM_CHIPSET_ID; |
| 284 | get_param.value = &device_id; |
| 285 | ret = drmIoctl(drv->fd, DRM_IOCTL_I915_GETPARAM, &get_param); |
| 286 | if (ret) { |
Alistair Strachan | 0cfaaa5 | 2018-03-19 14:03:23 -0700 | [diff] [blame] | 287 | drv_log("Failed to get I915_PARAM_CHIPSET_ID\n"); |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame] | 288 | free(i915); |
Gurchetan Singh | 82a8eed | 2017-01-03 13:01:37 -0800 | [diff] [blame] | 289 | return -EINVAL; |
Gurchetan Singh | 3eb8d8f | 2017-01-03 13:36:13 -0800 | [diff] [blame] | 290 | } |
| 291 | |
Gurchetan Singh | 68af9c2 | 2017-01-18 13:48:11 -0800 | [diff] [blame] | 292 | i915->gen = i915_get_gen(device_id); |
| 293 | |
| 294 | memset(&get_param, 0, sizeof(get_param)); |
| 295 | get_param.param = I915_PARAM_HAS_LLC; |
| 296 | get_param.value = &i915->has_llc; |
| 297 | ret = drmIoctl(drv->fd, DRM_IOCTL_I915_GETPARAM, &get_param); |
| 298 | if (ret) { |
Alistair Strachan | 0cfaaa5 | 2018-03-19 14:03:23 -0700 | [diff] [blame] | 299 | drv_log("Failed to get I915_PARAM_HAS_LLC\n"); |
Gurchetan Singh | 68af9c2 | 2017-01-18 13:48:11 -0800 | [diff] [blame] | 300 | free(i915); |
| 301 | return -EINVAL; |
| 302 | } |
| 303 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame] | 304 | drv->priv = i915; |
Gurchetan Singh | 3eb8d8f | 2017-01-03 13:36:13 -0800 | [diff] [blame] | 305 | |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 306 | return i915_add_combinations(drv); |
Gurchetan Singh | 3eb8d8f | 2017-01-03 13:36:13 -0800 | [diff] [blame] | 307 | } |
| 308 | |
Kristian H. Kristensen | e8778f0 | 2018-04-04 14:21:41 -0700 | [diff] [blame] | 309 | static int i915_bo_from_format(struct bo *bo, uint32_t width, uint32_t height, uint32_t format) |
| 310 | { |
| 311 | uint32_t offset; |
| 312 | size_t plane; |
| 313 | int ret; |
| 314 | |
| 315 | offset = 0; |
| 316 | for (plane = 0; plane < drv_num_planes_from_format(format); plane++) { |
| 317 | uint32_t stride = drv_stride_from_format(format, width, plane); |
| 318 | uint32_t plane_height = drv_height_from_format(format, height, plane); |
| 319 | |
| 320 | if (bo->tiling != I915_TILING_NONE) |
| 321 | assert(IS_ALIGNED(offset, 4096)); |
| 322 | |
| 323 | ret = i915_align_dimensions(bo, bo->tiling, &stride, &plane_height); |
| 324 | if (ret) |
| 325 | return ret; |
| 326 | |
| 327 | bo->strides[plane] = stride; |
| 328 | bo->sizes[plane] = stride * plane_height; |
| 329 | bo->offsets[plane] = offset; |
| 330 | offset += bo->sizes[plane]; |
| 331 | } |
| 332 | |
| 333 | bo->total_size = offset; |
| 334 | |
| 335 | return 0; |
| 336 | } |
| 337 | |
Kristian H. Kristensen | 6061eab | 2017-10-03 13:53:19 -0700 | [diff] [blame] | 338 | static int i915_bo_create_for_modifier(struct bo *bo, uint32_t width, uint32_t height, |
| 339 | uint32_t format, uint64_t modifier) |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 340 | { |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 341 | int ret; |
Gurchetan Singh | 82a8eed | 2017-01-03 13:01:37 -0800 | [diff] [blame] | 342 | size_t plane; |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame] | 343 | struct drm_i915_gem_create gem_create; |
| 344 | struct drm_i915_gem_set_tiling gem_set_tiling; |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 345 | |
Kristian H. Kristensen | 6061eab | 2017-10-03 13:53:19 -0700 | [diff] [blame] | 346 | switch (modifier) { |
| 347 | case DRM_FORMAT_MOD_LINEAR: |
| 348 | bo->tiling = I915_TILING_NONE; |
| 349 | break; |
| 350 | case I915_FORMAT_MOD_X_TILED: |
| 351 | bo->tiling = I915_TILING_X; |
| 352 | break; |
| 353 | case I915_FORMAT_MOD_Y_TILED: |
| 354 | bo->tiling = I915_TILING_Y; |
| 355 | break; |
| 356 | } |
Owen Lin | bbb69fd | 2017-06-05 14:33:08 +0800 | [diff] [blame] | 357 | |
Kristian H. Kristensen | 2b8f89e | 2018-02-07 16:10:06 -0800 | [diff] [blame] | 358 | bo->format_modifiers[0] = modifier; |
| 359 | |
Kristian H. Kristensen | e8778f0 | 2018-04-04 14:21:41 -0700 | [diff] [blame] | 360 | if (format == DRM_FORMAT_YVU420_ANDROID) { |
| 361 | /* |
| 362 | * We only need to be able to use this as a linear texture, |
| 363 | * which doesn't put any HW restrictions on how we lay it |
| 364 | * out. The Android format does require the stride to be a |
| 365 | * multiple of 16 and expects the Cr and Cb stride to be |
| 366 | * ALIGN(Y_stride / 2, 16), which we can make happen by |
| 367 | * aligning to 32 bytes here. |
| 368 | */ |
| 369 | uint32_t stride = ALIGN(width, 32); |
| 370 | drv_bo_from_format(bo, stride, height, format); |
| 371 | } else { |
| 372 | i915_bo_from_format(bo, width, height, format); |
| 373 | } |
Stéphane Marchesin | 5d867a4 | 2014-11-24 17:09:49 -0800 | [diff] [blame] | 374 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame] | 375 | memset(&gem_create, 0, sizeof(gem_create)); |
| 376 | gem_create.size = bo->total_size; |
Stéphane Marchesin | 5d867a4 | 2014-11-24 17:09:49 -0800 | [diff] [blame] | 377 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame] | 378 | ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_CREATE, &gem_create); |
| 379 | if (ret) { |
Alistair Strachan | 0cfaaa5 | 2018-03-19 14:03:23 -0700 | [diff] [blame] | 380 | drv_log("DRM_IOCTL_I915_GEM_CREATE failed (size=%llu)\n", gem_create.size); |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame] | 381 | return ret; |
Ilja H. Friedel | f9d2ab7 | 2015-04-09 14:08:36 -0700 | [diff] [blame] | 382 | } |
Gurchetan Singh | 83dc4fb | 2016-07-19 15:52:33 -0700 | [diff] [blame] | 383 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame] | 384 | for (plane = 0; plane < bo->num_planes; plane++) |
| 385 | bo->handles[plane].u32 = gem_create.handle; |
Daniel Nicoara | 1de26dc | 2014-09-25 18:53:19 -0400 | [diff] [blame] | 386 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame] | 387 | memset(&gem_set_tiling, 0, sizeof(gem_set_tiling)); |
| 388 | gem_set_tiling.handle = bo->handles[0].u32; |
| 389 | gem_set_tiling.tiling_mode = bo->tiling; |
| 390 | gem_set_tiling.stride = bo->strides[0]; |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 391 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame] | 392 | ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_SET_TILING, &gem_set_tiling); |
| 393 | if (ret) { |
| 394 | struct drm_gem_close gem_close; |
| 395 | memset(&gem_close, 0, sizeof(gem_close)); |
| 396 | gem_close.handle = bo->handles[0].u32; |
| 397 | drmIoctl(bo->drv->fd, DRM_IOCTL_GEM_CLOSE, &gem_close); |
Gurchetan Singh | 82a8eed | 2017-01-03 13:01:37 -0800 | [diff] [blame] | 398 | |
Alistair Strachan | 0cfaaa5 | 2018-03-19 14:03:23 -0700 | [diff] [blame] | 399 | drv_log("DRM_IOCTL_I915_GEM_SET_TILING failed with %d\n", errno); |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 400 | return -errno; |
| 401 | } |
| 402 | |
| 403 | return 0; |
| 404 | } |
| 405 | |
Kristian H. Kristensen | 6061eab | 2017-10-03 13:53:19 -0700 | [diff] [blame] | 406 | static int i915_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format, |
| 407 | uint64_t use_flags) |
| 408 | { |
| 409 | struct combination *combo; |
| 410 | |
| 411 | combo = drv_get_combination(bo->drv, format, use_flags); |
| 412 | if (!combo) |
| 413 | return -EINVAL; |
| 414 | |
| 415 | return i915_bo_create_for_modifier(bo, width, height, format, combo->metadata.modifier); |
| 416 | } |
| 417 | |
| 418 | static int i915_bo_create_with_modifiers(struct bo *bo, uint32_t width, uint32_t height, |
| 419 | uint32_t format, const uint64_t *modifiers, uint32_t count) |
| 420 | { |
| 421 | static const uint64_t modifier_order[] = { |
Gurchetan Singh | ee43c30 | 2017-11-14 18:20:27 -0800 | [diff] [blame] | 422 | I915_FORMAT_MOD_Y_TILED, |
| 423 | I915_FORMAT_MOD_X_TILED, |
| 424 | DRM_FORMAT_MOD_LINEAR, |
Kristian H. Kristensen | 6061eab | 2017-10-03 13:53:19 -0700 | [diff] [blame] | 425 | }; |
| 426 | uint64_t modifier; |
| 427 | |
| 428 | modifier = drv_pick_modifier(modifiers, count, modifier_order, ARRAY_SIZE(modifier_order)); |
| 429 | |
Kristian H. Kristensen | 6061eab | 2017-10-03 13:53:19 -0700 | [diff] [blame] | 430 | return i915_bo_create_for_modifier(bo, width, height, format, modifier); |
| 431 | } |
| 432 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame] | 433 | static void i915_close(struct driver *drv) |
Gurchetan Singh | 82a8eed | 2017-01-03 13:01:37 -0800 | [diff] [blame] | 434 | { |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame] | 435 | free(drv->priv); |
| 436 | drv->priv = NULL; |
Gurchetan Singh | 82a8eed | 2017-01-03 13:01:37 -0800 | [diff] [blame] | 437 | } |
| 438 | |
Gurchetan Singh | fcad5ad | 2017-01-05 20:39:31 -0800 | [diff] [blame] | 439 | static int i915_bo_import(struct bo *bo, struct drv_import_fd_data *data) |
| 440 | { |
| 441 | int ret; |
| 442 | struct drm_i915_gem_get_tiling gem_get_tiling; |
| 443 | |
| 444 | ret = drv_prime_bo_import(bo, data); |
| 445 | if (ret) |
| 446 | return ret; |
| 447 | |
| 448 | /* TODO(gsingh): export modifiers and get rid of backdoor tiling. */ |
| 449 | memset(&gem_get_tiling, 0, sizeof(gem_get_tiling)); |
| 450 | gem_get_tiling.handle = bo->handles[0].u32; |
| 451 | |
| 452 | ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_GET_TILING, &gem_get_tiling); |
| 453 | if (ret) { |
Joe Kniss | 9e5d12a | 2017-06-29 11:54:22 -0700 | [diff] [blame] | 454 | drv_gem_bo_destroy(bo); |
Alistair Strachan | 0cfaaa5 | 2018-03-19 14:03:23 -0700 | [diff] [blame] | 455 | drv_log("DRM_IOCTL_I915_GEM_GET_TILING failed.\n"); |
Gurchetan Singh | fcad5ad | 2017-01-05 20:39:31 -0800 | [diff] [blame] | 456 | return ret; |
| 457 | } |
| 458 | |
| 459 | bo->tiling = gem_get_tiling.tiling_mode; |
| 460 | return 0; |
| 461 | } |
| 462 | |
Gurchetan Singh | ee43c30 | 2017-11-14 18:20:27 -0800 | [diff] [blame] | 463 | static void *i915_bo_map(struct bo *bo, struct vma *vma, size_t plane, uint32_t map_flags) |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 464 | { |
| 465 | int ret; |
Gurchetan Singh | fcad5ad | 2017-01-05 20:39:31 -0800 | [diff] [blame] | 466 | void *addr; |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 467 | |
Gurchetan Singh | fcad5ad | 2017-01-05 20:39:31 -0800 | [diff] [blame] | 468 | if (bo->tiling == I915_TILING_NONE) { |
| 469 | struct drm_i915_gem_mmap gem_map; |
| 470 | memset(&gem_map, 0, sizeof(gem_map)); |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 471 | |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 472 | if ((bo->use_flags & BO_USE_SCANOUT) && !(bo->use_flags & BO_USE_RENDERSCRIPT)) |
Gurchetan Singh | 5af2023 | 2017-09-19 15:10:58 -0700 | [diff] [blame] | 473 | gem_map.flags = I915_MMAP_WC; |
| 474 | |
Gurchetan Singh | fcad5ad | 2017-01-05 20:39:31 -0800 | [diff] [blame] | 475 | gem_map.handle = bo->handles[0].u32; |
| 476 | gem_map.offset = 0; |
| 477 | gem_map.size = bo->total_size; |
| 478 | |
| 479 | ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_MMAP, &gem_map); |
| 480 | if (ret) { |
Alistair Strachan | 0cfaaa5 | 2018-03-19 14:03:23 -0700 | [diff] [blame] | 481 | drv_log("DRM_IOCTL_I915_GEM_MMAP failed\n"); |
Gurchetan Singh | fcad5ad | 2017-01-05 20:39:31 -0800 | [diff] [blame] | 482 | return MAP_FAILED; |
| 483 | } |
| 484 | |
| 485 | addr = (void *)(uintptr_t)gem_map.addr_ptr; |
Gurchetan Singh | fcad5ad | 2017-01-05 20:39:31 -0800 | [diff] [blame] | 486 | } else { |
| 487 | struct drm_i915_gem_mmap_gtt gem_map; |
| 488 | memset(&gem_map, 0, sizeof(gem_map)); |
| 489 | |
| 490 | gem_map.handle = bo->handles[0].u32; |
| 491 | |
| 492 | ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &gem_map); |
| 493 | if (ret) { |
Alistair Strachan | 0cfaaa5 | 2018-03-19 14:03:23 -0700 | [diff] [blame] | 494 | drv_log("DRM_IOCTL_I915_GEM_MMAP_GTT failed\n"); |
Gurchetan Singh | fcad5ad | 2017-01-05 20:39:31 -0800 | [diff] [blame] | 495 | return MAP_FAILED; |
| 496 | } |
| 497 | |
Gurchetan Singh | cfb8876 | 2017-09-28 17:14:50 -0700 | [diff] [blame] | 498 | addr = mmap(0, bo->total_size, drv_get_prot(map_flags), MAP_SHARED, bo->drv->fd, |
| 499 | gem_map.offset); |
Gurchetan Singh | fcad5ad | 2017-01-05 20:39:31 -0800 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | if (addr == MAP_FAILED) { |
Alistair Strachan | 0cfaaa5 | 2018-03-19 14:03:23 -0700 | [diff] [blame] | 503 | drv_log("i915 GEM mmap failed\n"); |
Gurchetan Singh | fcad5ad | 2017-01-05 20:39:31 -0800 | [diff] [blame] | 504 | return addr; |
| 505 | } |
| 506 | |
Gurchetan Singh | ee43c30 | 2017-11-14 18:20:27 -0800 | [diff] [blame] | 507 | vma->length = bo->total_size; |
Gurchetan Singh | fcad5ad | 2017-01-05 20:39:31 -0800 | [diff] [blame] | 508 | return addr; |
| 509 | } |
Gurchetan Singh | 1a31e60 | 2016-10-06 10:58:00 -0700 | [diff] [blame] | 510 | |
Gurchetan Singh | 47e629b | 2017-11-02 14:07:18 -0700 | [diff] [blame] | 511 | static int i915_bo_invalidate(struct bo *bo, struct mapping *mapping) |
Gurchetan Singh | 2d1877f | 2017-10-10 14:12:46 -0700 | [diff] [blame] | 512 | { |
| 513 | int ret; |
| 514 | struct drm_i915_gem_set_domain set_domain; |
| 515 | |
| 516 | memset(&set_domain, 0, sizeof(set_domain)); |
| 517 | set_domain.handle = bo->handles[0].u32; |
| 518 | if (bo->tiling == I915_TILING_NONE) { |
| 519 | set_domain.read_domains = I915_GEM_DOMAIN_CPU; |
Gurchetan Singh | 47e629b | 2017-11-02 14:07:18 -0700 | [diff] [blame] | 520 | if (mapping->vma->map_flags & BO_MAP_WRITE) |
Gurchetan Singh | 2d1877f | 2017-10-10 14:12:46 -0700 | [diff] [blame] | 521 | set_domain.write_domain = I915_GEM_DOMAIN_CPU; |
| 522 | } else { |
| 523 | set_domain.read_domains = I915_GEM_DOMAIN_GTT; |
Gurchetan Singh | 47e629b | 2017-11-02 14:07:18 -0700 | [diff] [blame] | 524 | if (mapping->vma->map_flags & BO_MAP_WRITE) |
Gurchetan Singh | 2d1877f | 2017-10-10 14:12:46 -0700 | [diff] [blame] | 525 | set_domain.write_domain = I915_GEM_DOMAIN_GTT; |
| 526 | } |
| 527 | |
| 528 | ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain); |
| 529 | if (ret) { |
Alistair Strachan | 0cfaaa5 | 2018-03-19 14:03:23 -0700 | [diff] [blame] | 530 | drv_log("DRM_IOCTL_I915_GEM_SET_DOMAIN with %d\n", ret); |
Gurchetan Singh | 2d1877f | 2017-10-10 14:12:46 -0700 | [diff] [blame] | 531 | return ret; |
| 532 | } |
| 533 | |
| 534 | return 0; |
| 535 | } |
| 536 | |
Gurchetan Singh | 47e629b | 2017-11-02 14:07:18 -0700 | [diff] [blame] | 537 | static int i915_bo_flush(struct bo *bo, struct mapping *mapping) |
Gurchetan Singh | fcad5ad | 2017-01-05 20:39:31 -0800 | [diff] [blame] | 538 | { |
Gurchetan Singh | 68af9c2 | 2017-01-18 13:48:11 -0800 | [diff] [blame] | 539 | struct i915_device *i915 = bo->drv->priv; |
| 540 | if (!i915->has_llc && bo->tiling == I915_TILING_NONE) |
Gurchetan Singh | 47e629b | 2017-11-02 14:07:18 -0700 | [diff] [blame] | 541 | i915_clflush(mapping->vma->addr, mapping->vma->length); |
Gurchetan Singh | fcad5ad | 2017-01-05 20:39:31 -0800 | [diff] [blame] | 542 | |
Gurchetan Singh | 8e02e05 | 2017-09-14 14:18:43 -0700 | [diff] [blame] | 543 | return 0; |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 546 | static uint32_t i915_resolve_format(uint32_t format, uint64_t use_flags) |
Gurchetan Singh | bfba8c2 | 2016-08-16 17:57:10 -0700 | [diff] [blame] | 547 | { |
| 548 | switch (format) { |
Gurchetan Singh | f3b22da | 2016-11-21 10:46:38 -0800 | [diff] [blame] | 549 | case DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED: |
Tomasz Figa | d30c0a5 | 2017-07-05 17:50:18 +0900 | [diff] [blame] | 550 | /* KBL camera subsystem requires NV12. */ |
Gurchetan Singh | a1892b2 | 2017-09-28 16:40:52 -0700 | [diff] [blame] | 551 | if (use_flags & (BO_USE_CAMERA_READ | BO_USE_CAMERA_WRITE)) |
Tomasz Figa | d30c0a5 | 2017-07-05 17:50:18 +0900 | [diff] [blame] | 552 | return DRM_FORMAT_NV12; |
Gurchetan Singh | d6fb577 | 2016-08-29 19:13:51 -0700 | [diff] [blame] | 553 | /*HACK: See b/28671744 */ |
Gurchetan Singh | f3b22da | 2016-11-21 10:46:38 -0800 | [diff] [blame] | 554 | return DRM_FORMAT_XBGR8888; |
| 555 | case DRM_FORMAT_FLEX_YCbCr_420_888: |
Tomasz Figa | b92e4f8 | 2017-06-22 16:52:43 +0900 | [diff] [blame] | 556 | /* |
| 557 | * KBL camera subsystem requires NV12. Our other use cases |
| 558 | * don't care: |
| 559 | * - Hardware video supports NV12, |
| 560 | * - USB Camera HALv3 supports NV12, |
| 561 | * - USB Camera HALv1 doesn't use this format. |
| 562 | * Moreover, NV12 is preferred for video, due to overlay |
| 563 | * support on SKL+. |
| 564 | */ |
| 565 | return DRM_FORMAT_NV12; |
Gurchetan Singh | d6fb577 | 2016-08-29 19:13:51 -0700 | [diff] [blame] | 566 | default: |
| 567 | return format; |
Gurchetan Singh | bfba8c2 | 2016-08-16 17:57:10 -0700 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | |
Gurchetan Singh | 3e9d383 | 2017-10-31 10:36:25 -0700 | [diff] [blame] | 571 | const struct backend backend_i915 = { |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 572 | .name = "i915", |
Gurchetan Singh | d7c84fd | 2016-08-16 18:18:24 -0700 | [diff] [blame] | 573 | .init = i915_init, |
| 574 | .close = i915_close, |
| 575 | .bo_create = i915_bo_create, |
Kristian H. Kristensen | 6061eab | 2017-10-03 13:53:19 -0700 | [diff] [blame] | 576 | .bo_create_with_modifiers = i915_bo_create_with_modifiers, |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame] | 577 | .bo_destroy = drv_gem_bo_destroy, |
Gurchetan Singh | fcad5ad | 2017-01-05 20:39:31 -0800 | [diff] [blame] | 578 | .bo_import = i915_bo_import, |
Gurchetan Singh | d7c84fd | 2016-08-16 18:18:24 -0700 | [diff] [blame] | 579 | .bo_map = i915_bo_map, |
Gurchetan Singh | 8e02e05 | 2017-09-14 14:18:43 -0700 | [diff] [blame] | 580 | .bo_unmap = drv_bo_munmap, |
Gurchetan Singh | 2d1877f | 2017-10-10 14:12:46 -0700 | [diff] [blame] | 581 | .bo_invalidate = i915_bo_invalidate, |
Gurchetan Singh | 8e02e05 | 2017-09-14 14:18:43 -0700 | [diff] [blame] | 582 | .bo_flush = i915_bo_flush, |
Gurchetan Singh | bfba8c2 | 2016-08-16 17:57:10 -0700 | [diff] [blame] | 583 | .resolve_format = i915_resolve_format, |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 584 | }; |
| 585 | |
| 586 | #endif |