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 | |
| 9 | #include <errno.h> |
Gurchetan Singh | 82a8eed | 2017-01-03 13:01:37 -0800 | [diff] [blame] | 10 | #include <i915_drm.h> |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 11 | #include <stdio.h> |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 12 | #include <string.h> |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 13 | #include <sys/mman.h> |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 14 | #include <xf86drm.h> |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 15 | |
Gurchetan Singh | 46faf6b | 2016-08-05 14:40:07 -0700 | [diff] [blame] | 16 | #include "drv_priv.h" |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 17 | #include "helpers.h" |
| 18 | #include "util.h" |
| 19 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 20 | static const uint32_t tileable_formats[] = { DRM_FORMAT_ARGB1555, DRM_FORMAT_ABGR8888, |
| 21 | DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB565, |
| 22 | DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB1555, |
| 23 | DRM_FORMAT_XRGB8888, DRM_FORMAT_UYVY, |
| 24 | DRM_FORMAT_YUYV }; |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 25 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 26 | static const uint32_t linear_only_formats[] = { DRM_FORMAT_GR88, DRM_FORMAT_R8, DRM_FORMAT_YVU420, |
| 27 | DRM_FORMAT_YVU420_ANDROID }; |
Gurchetan Singh | 179687e | 2016-10-28 10:07:35 -0700 | [diff] [blame] | 28 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 29 | struct i915_device { |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 30 | int gen; |
| 31 | }; |
| 32 | |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 33 | static int get_gen(int device_id) |
| 34 | { |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 35 | const uint16_t gen3_ids[] = { 0x2582, 0x2592, 0x2772, 0x27A2, 0x27AE, |
| 36 | 0x29C2, 0x29B2, 0x29D2, 0xA001, 0xA011 }; |
Stéphane Marchesin | a39dfde | 2014-09-15 15:38:25 -0700 | [diff] [blame] | 37 | unsigned i; |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 38 | for (i = 0; i < ARRAY_SIZE(gen3_ids); i++) |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 39 | if (gen3_ids[i] == device_id) |
| 40 | return 3; |
| 41 | |
| 42 | return 4; |
| 43 | } |
| 44 | |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 45 | static int i915_add_kms_item(struct driver *drv, const struct kms_item *item) |
| 46 | { |
| 47 | uint32_t i; |
| 48 | struct combination *combo; |
| 49 | |
| 50 | /* |
| 51 | * Older hardware can't scanout Y-tiled formats. Newer devices can, and |
| 52 | * report this functionality via format modifiers. |
| 53 | */ |
| 54 | for (i = 0; i < drv->backend->combos.size; i++) { |
| 55 | combo = &drv->backend->combos.data[i]; |
| 56 | if (combo->format == item->format) { |
| 57 | if ((combo->metadata.tiling == I915_TILING_Y && |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 58 | item->modifier == I915_FORMAT_MOD_Y_TILED) || |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 59 | (combo->metadata.tiling == I915_TILING_X && |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 60 | item->modifier == I915_FORMAT_MOD_X_TILED)) { |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 61 | combo->metadata.modifier = item->modifier; |
| 62 | combo->usage |= item->usage; |
| 63 | } else if (combo->metadata.tiling != I915_TILING_Y) { |
| 64 | combo->usage |= item->usage; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | static int i915_add_combinations(struct driver *drv) |
| 73 | { |
| 74 | int ret; |
| 75 | uint32_t i, num_items; |
| 76 | struct kms_item *items; |
| 77 | struct format_metadata metadata; |
| 78 | uint64_t flags = BO_COMMON_USE_MASK; |
| 79 | |
| 80 | metadata.tiling = I915_TILING_NONE; |
| 81 | metadata.priority = 1; |
| 82 | metadata.modifier = DRM_FORMAT_MOD_NONE; |
| 83 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 84 | ret = drv_add_combinations(drv, linear_only_formats, ARRAY_SIZE(linear_only_formats), |
| 85 | &metadata, flags); |
| 86 | if (ret) |
| 87 | return ret; |
| 88 | |
| 89 | ret = drv_add_combinations(drv, tileable_formats, ARRAY_SIZE(tileable_formats), &metadata, |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 90 | flags); |
| 91 | if (ret) |
| 92 | return ret; |
| 93 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 94 | drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT); |
| 95 | 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] | 96 | |
| 97 | flags &= ~BO_USE_SW_WRITE_OFTEN; |
| 98 | flags &= ~BO_USE_SW_READ_OFTEN; |
| 99 | flags &= ~BO_USE_LINEAR; |
| 100 | |
| 101 | metadata.tiling = I915_TILING_X; |
| 102 | metadata.priority = 2; |
| 103 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 104 | ret = drv_add_combinations(drv, tileable_formats, ARRAY_SIZE(tileable_formats), &metadata, |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 105 | flags); |
| 106 | if (ret) |
| 107 | return ret; |
| 108 | |
| 109 | metadata.tiling = I915_TILING_Y; |
| 110 | metadata.priority = 3; |
| 111 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 112 | ret = drv_add_combinations(drv, tileable_formats, ARRAY_SIZE(tileable_formats), &metadata, |
| 113 | flags); |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 114 | if (ret) |
| 115 | return ret; |
| 116 | |
| 117 | items = drv_query_kms(drv, &num_items); |
| 118 | if (!items || !num_items) |
| 119 | return 0; |
| 120 | |
| 121 | for (i = 0; i < num_items; i++) { |
| 122 | ret = i915_add_kms_item(drv, &items[i]); |
| 123 | if (ret) { |
| 124 | free(items); |
| 125 | return ret; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | free(items); |
| 130 | return 0; |
| 131 | } |
| 132 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 133 | static int i915_align_dimensions(struct bo *bo, uint32_t tiling, uint32_t *stride, |
| 134 | uint32_t *aligned_height) |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 135 | { |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 136 | struct i915_device *i915 = bo->drv->priv; |
| 137 | uint32_t horizontal_alignment = 4; |
| 138 | uint32_t vertical_alignment = 4; |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 139 | |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 140 | switch (tiling) { |
Gurchetan Singh | d6fb577 | 2016-08-29 19:13:51 -0700 | [diff] [blame] | 141 | default: |
| 142 | case I915_TILING_NONE: |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 143 | horizontal_alignment = 64; |
Gurchetan Singh | d6fb577 | 2016-08-29 19:13:51 -0700 | [diff] [blame] | 144 | break; |
Stéphane Marchesin | 5d867a4 | 2014-11-24 17:09:49 -0800 | [diff] [blame] | 145 | |
Gurchetan Singh | d6fb577 | 2016-08-29 19:13:51 -0700 | [diff] [blame] | 146 | case I915_TILING_X: |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 147 | horizontal_alignment = 512; |
| 148 | vertical_alignment = 8; |
Gurchetan Singh | d6fb577 | 2016-08-29 19:13:51 -0700 | [diff] [blame] | 149 | break; |
| 150 | |
| 151 | case I915_TILING_Y: |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 152 | if (i915->gen == 3) { |
| 153 | horizontal_alignment = 512; |
| 154 | vertical_alignment = 8; |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 155 | } else { |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 156 | horizontal_alignment = 128; |
| 157 | vertical_alignment = 32; |
Gurchetan Singh | d6fb577 | 2016-08-29 19:13:51 -0700 | [diff] [blame] | 158 | } |
| 159 | break; |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 160 | } |
Stéphane Marchesin | 5d867a4 | 2014-11-24 17:09:49 -0800 | [diff] [blame] | 161 | |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 162 | *aligned_height = ALIGN(bo->height, vertical_alignment); |
| 163 | if (i915->gen > 3) { |
| 164 | *stride = ALIGN(*stride, horizontal_alignment); |
Stéphane Marchesin | 5d867a4 | 2014-11-24 17:09:49 -0800 | [diff] [blame] | 165 | } else { |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 166 | while (*stride > horizontal_alignment) |
| 167 | horizontal_alignment <<= 1; |
| 168 | |
| 169 | *stride = horizontal_alignment; |
Stéphane Marchesin | 5d867a4 | 2014-11-24 17:09:49 -0800 | [diff] [blame] | 170 | } |
Stéphane Marchesin | 5d867a4 | 2014-11-24 17:09:49 -0800 | [diff] [blame] | 171 | |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 172 | if (i915->gen <= 3 && *stride > 8192) |
| 173 | return -EINVAL; |
Stéphane Marchesin | 5d867a4 | 2014-11-24 17:09:49 -0800 | [diff] [blame] | 174 | |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 175 | return 0; |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Gurchetan Singh | 3eb8d8f | 2017-01-03 13:36:13 -0800 | [diff] [blame] | 178 | static int i915_init(struct driver *drv) |
| 179 | { |
Gurchetan Singh | 3eb8d8f | 2017-01-03 13:36:13 -0800 | [diff] [blame] | 180 | int ret; |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 181 | int device_id; |
| 182 | struct i915_device *i915; |
| 183 | drm_i915_getparam_t get_param; |
Gurchetan Singh | 3eb8d8f | 2017-01-03 13:36:13 -0800 | [diff] [blame] | 184 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 185 | i915 = calloc(1, sizeof(*i915)); |
| 186 | if (!i915) |
| 187 | return -ENOMEM; |
Gurchetan Singh | 3eb8d8f | 2017-01-03 13:36:13 -0800 | [diff] [blame] | 188 | |
| 189 | memset(&get_param, 0, sizeof(get_param)); |
| 190 | get_param.param = I915_PARAM_CHIPSET_ID; |
| 191 | get_param.value = &device_id; |
| 192 | ret = drmIoctl(drv->fd, DRM_IOCTL_I915_GETPARAM, &get_param); |
| 193 | if (ret) { |
| 194 | fprintf(stderr, "drv: DRM_IOCTL_I915_GETPARAM failed\n"); |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 195 | free(i915); |
Gurchetan Singh | 82a8eed | 2017-01-03 13:01:37 -0800 | [diff] [blame] | 196 | return -EINVAL; |
Gurchetan Singh | 3eb8d8f | 2017-01-03 13:36:13 -0800 | [diff] [blame] | 197 | } |
| 198 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 199 | i915->gen = get_gen(device_id); |
| 200 | drv->priv = i915; |
Gurchetan Singh | 3eb8d8f | 2017-01-03 13:36:13 -0800 | [diff] [blame] | 201 | |
Gurchetan Singh | 6b41fb5 | 2017-03-01 20:14:39 -0800 | [diff] [blame] | 202 | return i915_add_combinations(drv); |
Gurchetan Singh | 3eb8d8f | 2017-01-03 13:36:13 -0800 | [diff] [blame] | 203 | } |
| 204 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 205 | static int i915_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format, |
| 206 | uint32_t flags) |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 207 | { |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 208 | int ret; |
Gurchetan Singh | 82a8eed | 2017-01-03 13:01:37 -0800 | [diff] [blame] | 209 | size_t plane; |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 210 | uint32_t stride; |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 211 | struct drm_i915_gem_create gem_create; |
| 212 | struct drm_i915_gem_set_tiling gem_set_tiling; |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 213 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 214 | if (flags & (BO_USE_CURSOR | BO_USE_LINEAR | BO_USE_SW_READ_OFTEN | BO_USE_SW_WRITE_OFTEN)) |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 215 | bo->tiling = I915_TILING_NONE; |
Gurchetan Singh | 458976f | 2016-11-23 17:32:33 -0800 | [diff] [blame] | 216 | else if (flags & BO_USE_SCANOUT) |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 217 | bo->tiling = I915_TILING_X; |
Gurchetan Singh | 6bab0c1 | 2016-10-13 19:08:48 -0700 | [diff] [blame] | 218 | else |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 219 | bo->tiling = I915_TILING_Y; |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 220 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 221 | stride = drv_stride_from_format(format, width, 0); |
Gurchetan Singh | 507f5dd | 2017-03-16 13:14:30 -0700 | [diff] [blame] | 222 | /* |
| 223 | * Align the Y plane to 128 bytes so the chroma planes would be aligned |
| 224 | * to 64 byte boundaries. This is an Intel HW requirement. |
| 225 | */ |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 226 | if (format == DRM_FORMAT_YVU420 || format == DRM_FORMAT_YVU420_ANDROID) { |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 227 | stride = ALIGN(stride, 128); |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 228 | bo->tiling = I915_TILING_NONE; |
Gurchetan Singh | 507f5dd | 2017-03-16 13:14:30 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 231 | ret = i915_align_dimensions(bo, bo->tiling, &stride, &height); |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 232 | if (ret) |
| 233 | return ret; |
Stéphane Marchesin | 5d867a4 | 2014-11-24 17:09:49 -0800 | [diff] [blame] | 234 | |
Gurchetan Singh | 6423ecb | 2017-03-29 08:23:40 -0700 | [diff] [blame] | 235 | drv_bo_from_format(bo, stride, height, format); |
Stéphane Marchesin | 5d867a4 | 2014-11-24 17:09:49 -0800 | [diff] [blame] | 236 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 237 | memset(&gem_create, 0, sizeof(gem_create)); |
| 238 | gem_create.size = bo->total_size; |
Stéphane Marchesin | 5d867a4 | 2014-11-24 17:09:49 -0800 | [diff] [blame] | 239 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 240 | ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_CREATE, &gem_create); |
| 241 | if (ret) { |
| 242 | fprintf(stderr, "drv: DRM_IOCTL_I915_GEM_CREATE failed (size=%llu)\n", |
| 243 | gem_create.size); |
| 244 | return ret; |
Ilja H. Friedel | f9d2ab7 | 2015-04-09 14:08:36 -0700 | [diff] [blame] | 245 | } |
Gurchetan Singh | 83dc4fb | 2016-07-19 15:52:33 -0700 | [diff] [blame] | 246 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 247 | for (plane = 0; plane < bo->num_planes; plane++) |
| 248 | bo->handles[plane].u32 = gem_create.handle; |
Daniel Nicoara | 1de26dc | 2014-09-25 18:53:19 -0400 | [diff] [blame] | 249 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 250 | memset(&gem_set_tiling, 0, sizeof(gem_set_tiling)); |
| 251 | gem_set_tiling.handle = bo->handles[0].u32; |
| 252 | gem_set_tiling.tiling_mode = bo->tiling; |
| 253 | gem_set_tiling.stride = bo->strides[0]; |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 254 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 255 | ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_SET_TILING, &gem_set_tiling); |
| 256 | if (ret) { |
| 257 | struct drm_gem_close gem_close; |
| 258 | memset(&gem_close, 0, sizeof(gem_close)); |
| 259 | gem_close.handle = bo->handles[0].u32; |
| 260 | drmIoctl(bo->drv->fd, DRM_IOCTL_GEM_CLOSE, &gem_close); |
Gurchetan Singh | 82a8eed | 2017-01-03 13:01:37 -0800 | [diff] [blame] | 261 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 262 | fprintf(stderr, "drv: DRM_IOCTL_I915_GEM_SET_TILING failed with %d", errno); |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 263 | return -errno; |
| 264 | } |
| 265 | |
| 266 | return 0; |
| 267 | } |
| 268 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 269 | static void i915_close(struct driver *drv) |
Gurchetan Singh | 82a8eed | 2017-01-03 13:01:37 -0800 | [diff] [blame] | 270 | { |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 271 | free(drv->priv); |
| 272 | drv->priv = NULL; |
Gurchetan Singh | 82a8eed | 2017-01-03 13:01:37 -0800 | [diff] [blame] | 273 | } |
| 274 | |
Gurchetan Singh | 1a31e60 | 2016-10-06 10:58:00 -0700 | [diff] [blame] | 275 | static void *i915_bo_map(struct bo *bo, struct map_info *data, size_t plane) |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 276 | { |
| 277 | int ret; |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 278 | struct drm_i915_gem_mmap_gtt gem_map; |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 279 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 280 | memset(&gem_map, 0, sizeof(gem_map)); |
| 281 | gem_map.handle = bo->handles[0].u32; |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 282 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 283 | ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &gem_map); |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 284 | if (ret) { |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 285 | fprintf(stderr, "drv: DRM_IOCTL_I915_GEM_MMAP_GTT failed\n"); |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 286 | return MAP_FAILED; |
| 287 | } |
| 288 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 289 | data->length = bo->total_size; |
Gurchetan Singh | 1a31e60 | 2016-10-06 10:58:00 -0700 | [diff] [blame] | 290 | |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 291 | return mmap(0, bo->total_size, PROT_READ | PROT_WRITE, MAP_SHARED, bo->drv->fd, |
| 292 | gem_map.offset); |
Gurchetan Singh | ef92053 | 2016-08-12 16:38:25 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Gurchetan Singh | f3b22da | 2016-11-21 10:46:38 -0800 | [diff] [blame] | 295 | static uint32_t i915_resolve_format(uint32_t format) |
Gurchetan Singh | bfba8c2 | 2016-08-16 17:57:10 -0700 | [diff] [blame] | 296 | { |
| 297 | switch (format) { |
Gurchetan Singh | f3b22da | 2016-11-21 10:46:38 -0800 | [diff] [blame] | 298 | case DRM_FORMAT_FLEX_IMPLEMENTATION_DEFINED: |
Gurchetan Singh | d6fb577 | 2016-08-29 19:13:51 -0700 | [diff] [blame] | 299 | /*HACK: See b/28671744 */ |
Gurchetan Singh | f3b22da | 2016-11-21 10:46:38 -0800 | [diff] [blame] | 300 | return DRM_FORMAT_XBGR8888; |
| 301 | case DRM_FORMAT_FLEX_YCbCr_420_888: |
Gurchetan Singh | 03f1356 | 2017-02-08 15:21:14 -0800 | [diff] [blame] | 302 | return DRM_FORMAT_YVU420_ANDROID; |
Gurchetan Singh | d6fb577 | 2016-08-29 19:13:51 -0700 | [diff] [blame] | 303 | default: |
| 304 | return format; |
Gurchetan Singh | bfba8c2 | 2016-08-16 17:57:10 -0700 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | |
Gurchetan Singh | 1b1d56a | 2017-03-10 16:25:23 -0800 | [diff] [blame] | 308 | struct backend backend_i915 = { |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 309 | .name = "i915", |
Gurchetan Singh | d7c84fd | 2016-08-16 18:18:24 -0700 | [diff] [blame] | 310 | .init = i915_init, |
| 311 | .close = i915_close, |
| 312 | .bo_create = i915_bo_create, |
Gurchetan Singh | cc015e8 | 2017-01-17 16:15:25 -0800 | [diff] [blame^] | 313 | .bo_destroy = drv_gem_bo_destroy, |
| 314 | .bo_import = drv_prime_bo_import, |
Gurchetan Singh | d7c84fd | 2016-08-16 18:18:24 -0700 | [diff] [blame] | 315 | .bo_map = i915_bo_map, |
Gurchetan Singh | bfba8c2 | 2016-08-16 17:57:10 -0700 | [diff] [blame] | 316 | .resolve_format = i915_resolve_format, |
Stéphane Marchesin | 25a2606 | 2014-09-12 16:18:59 -0700 | [diff] [blame] | 317 | }; |
| 318 | |
| 319 | #endif |