Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2008 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 | * Authors: |
| 24 | * Eric Anholt <eric@anholt.net> |
| 25 | * |
| 26 | */ |
| 27 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 28 | #include <linux/string.h> |
| 29 | #include <linux/bitops.h> |
| 30 | #include <drm/drmP.h> |
| 31 | #include <drm/i915_drm.h> |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 32 | #include "i915_drv.h" |
| 33 | |
Daniel Vetter | 3271dca | 2015-07-24 17:40:15 +0200 | [diff] [blame] | 34 | /** |
| 35 | * DOC: buffer object tiling |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 36 | * |
Daniel Vetter | 3271dca | 2015-07-24 17:40:15 +0200 | [diff] [blame] | 37 | * i915_gem_set_tiling() and i915_gem_get_tiling() is the userspace interface to |
| 38 | * declare fence register requirements. |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 39 | * |
Daniel Vetter | 3271dca | 2015-07-24 17:40:15 +0200 | [diff] [blame] | 40 | * In principle GEM doesn't care at all about the internal data layout of an |
| 41 | * object, and hence it also doesn't care about tiling or swizzling. There's two |
| 42 | * exceptions: |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 43 | * |
Daniel Vetter | 3271dca | 2015-07-24 17:40:15 +0200 | [diff] [blame] | 44 | * - For X and Y tiling the hardware provides detilers for CPU access, so called |
| 45 | * fences. Since there's only a limited amount of them the kernel must manage |
| 46 | * these, and therefore userspace must tell the kernel the object tiling if it |
| 47 | * wants to use fences for detiling. |
| 48 | * - On gen3 and gen4 platforms have a swizzling pattern for tiled objects which |
| 49 | * depends upon the physical page frame number. When swapping such objects the |
| 50 | * page frame number might change and the kernel must be able to fix this up |
| 51 | * and hence now the tiling. Note that on a subset of platforms with |
| 52 | * asymmetric memory channel population the swizzling pattern changes in an |
| 53 | * unknown way, and for those the kernel simply forbids swapping completely. |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 54 | * |
Daniel Vetter | 3271dca | 2015-07-24 17:40:15 +0200 | [diff] [blame] | 55 | * Since neither of this applies for new tiling layouts on modern platforms like |
| 56 | * W, Ys and Yf tiling GEM only allows object tiling to be set to X or Y tiled. |
| 57 | * Anything else can be handled in userspace entirely without the kernel's |
| 58 | * invovlement. |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 59 | */ |
| 60 | |
Jesse Barnes | 0f973f2 | 2009-01-26 17:10:45 -0800 | [diff] [blame] | 61 | /* Check pitch constriants for all chips & tiling formats */ |
Chris Wilson | a00b10c | 2010-09-24 21:15:47 +0100 | [diff] [blame] | 62 | static bool |
Jesse Barnes | 0f973f2 | 2009-01-26 17:10:45 -0800 | [diff] [blame] | 63 | i915_tiling_ok(struct drm_device *dev, int stride, int size, int tiling_mode) |
| 64 | { |
Chris Wilson | 0ee537a | 2011-03-06 09:03:16 +0000 | [diff] [blame] | 65 | int tile_width; |
Jesse Barnes | 0f973f2 | 2009-01-26 17:10:45 -0800 | [diff] [blame] | 66 | |
| 67 | /* Linear is always fine */ |
| 68 | if (tiling_mode == I915_TILING_NONE) |
| 69 | return true; |
| 70 | |
Chris Wilson | deeb151 | 2016-08-05 10:14:22 +0100 | [diff] [blame] | 71 | if (tiling_mode > I915_TILING_LAST) |
| 72 | return false; |
| 73 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 74 | if (IS_GEN2(dev) || |
Eric Anholt | e76a16d | 2009-05-26 17:44:56 -0700 | [diff] [blame] | 75 | (tiling_mode == I915_TILING_Y && HAS_128_BYTE_Y_TILING(dev))) |
Jesse Barnes | 0f973f2 | 2009-01-26 17:10:45 -0800 | [diff] [blame] | 76 | tile_width = 128; |
| 77 | else |
| 78 | tile_width = 512; |
| 79 | |
Daniel Vetter | 8d7773a | 2009-03-29 14:09:41 +0200 | [diff] [blame] | 80 | /* check maximum stride & object size */ |
Ville Syrjälä | 3a06247 | 2013-04-09 11:45:05 +0300 | [diff] [blame] | 81 | /* i965+ stores the end address of the gtt mapping in the fence |
| 82 | * reg, so dont bother to check the size */ |
| 83 | if (INTEL_INFO(dev)->gen >= 7) { |
| 84 | if (stride / 128 > GEN7_FENCE_MAX_PITCH_VAL) |
| 85 | return false; |
| 86 | } else if (INTEL_INFO(dev)->gen >= 4) { |
Daniel Vetter | 8d7773a | 2009-03-29 14:09:41 +0200 | [diff] [blame] | 87 | if (stride / 128 > I965_FENCE_MAX_PITCH_VAL) |
| 88 | return false; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 89 | } else { |
Daniel Vetter | c36a2a6 | 2010-04-17 15:12:03 +0200 | [diff] [blame] | 90 | if (stride > 8192) |
Daniel Vetter | 8d7773a | 2009-03-29 14:09:41 +0200 | [diff] [blame] | 91 | return false; |
Eric Anholt | e76a16d | 2009-05-26 17:44:56 -0700 | [diff] [blame] | 92 | |
Daniel Vetter | c36a2a6 | 2010-04-17 15:12:03 +0200 | [diff] [blame] | 93 | if (IS_GEN3(dev)) { |
| 94 | if (size > I830_FENCE_MAX_SIZE_VAL << 20) |
| 95 | return false; |
| 96 | } else { |
| 97 | if (size > I830_FENCE_MAX_SIZE_VAL << 19) |
| 98 | return false; |
| 99 | } |
Daniel Vetter | 8d7773a | 2009-03-29 14:09:41 +0200 | [diff] [blame] | 100 | } |
| 101 | |
Ville Syrjälä | fe48d8d | 2013-04-09 20:09:13 +0300 | [diff] [blame] | 102 | if (stride < tile_width) |
| 103 | return false; |
| 104 | |
Jesse Barnes | 0f973f2 | 2009-01-26 17:10:45 -0800 | [diff] [blame] | 105 | /* 965+ just needs multiples of tile width */ |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 106 | if (INTEL_INFO(dev)->gen >= 4) { |
Jesse Barnes | 0f973f2 | 2009-01-26 17:10:45 -0800 | [diff] [blame] | 107 | if (stride & (tile_width - 1)) |
| 108 | return false; |
| 109 | return true; |
| 110 | } |
| 111 | |
| 112 | /* Pre-965 needs power of two tile widths */ |
Jesse Barnes | 0f973f2 | 2009-01-26 17:10:45 -0800 | [diff] [blame] | 113 | if (stride & (stride - 1)) |
| 114 | return false; |
| 115 | |
Jesse Barnes | 0f973f2 | 2009-01-26 17:10:45 -0800 | [diff] [blame] | 116 | return true; |
| 117 | } |
| 118 | |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame^] | 119 | static bool i915_vma_fence_prepare(struct i915_vma *vma, int tiling_mode) |
| 120 | { |
| 121 | struct drm_i915_private *dev_priv = to_i915(vma->vm->dev); |
| 122 | u32 size; |
| 123 | |
| 124 | if (!i915_vma_is_map_and_fenceable(vma)) |
| 125 | return true; |
| 126 | |
| 127 | if (INTEL_GEN(dev_priv) == 3) { |
| 128 | if (vma->node.start & ~I915_FENCE_START_MASK) |
| 129 | return false; |
| 130 | } else { |
| 131 | if (vma->node.start & ~I830_FENCE_START_MASK) |
| 132 | return false; |
| 133 | } |
| 134 | |
| 135 | size = i915_gem_get_ggtt_size(dev_priv, vma->size, tiling_mode); |
| 136 | if (vma->node.size < size) |
| 137 | return false; |
| 138 | |
| 139 | if (vma->node.start & (size - 1)) |
| 140 | return false; |
| 141 | |
| 142 | return true; |
| 143 | } |
| 144 | |
Chris Wilson | f23eda8 | 2016-08-15 10:48:53 +0100 | [diff] [blame] | 145 | /* Make the current GTT allocation valid for the change in tiling. */ |
| 146 | static int |
| 147 | i915_gem_object_fence_prepare(struct drm_i915_gem_object *obj, int tiling_mode) |
Chris Wilson | 52dc7d3 | 2009-06-06 09:46:01 +0100 | [diff] [blame] | 148 | { |
Chris Wilson | a9f1481 | 2016-08-04 16:32:28 +0100 | [diff] [blame] | 149 | struct drm_i915_private *dev_priv = to_i915(obj->base.dev); |
Chris Wilson | f23eda8 | 2016-08-15 10:48:53 +0100 | [diff] [blame] | 150 | struct i915_vma *vma; |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame^] | 151 | int ret; |
Chris Wilson | 52dc7d3 | 2009-06-06 09:46:01 +0100 | [diff] [blame] | 152 | |
| 153 | if (tiling_mode == I915_TILING_NONE) |
Chris Wilson | f23eda8 | 2016-08-15 10:48:53 +0100 | [diff] [blame] | 154 | return 0; |
Chris Wilson | 52dc7d3 | 2009-06-06 09:46:01 +0100 | [diff] [blame] | 155 | |
Chris Wilson | a9f1481 | 2016-08-04 16:32:28 +0100 | [diff] [blame] | 156 | if (INTEL_GEN(dev_priv) >= 4) |
Chris Wilson | f23eda8 | 2016-08-15 10:48:53 +0100 | [diff] [blame] | 157 | return 0; |
| 158 | |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame^] | 159 | list_for_each_entry(vma, &obj->vma_list, obj_link) { |
| 160 | if (i915_vma_fence_prepare(vma, tiling_mode)) |
| 161 | continue; |
Chris Wilson | f23eda8 | 2016-08-15 10:48:53 +0100 | [diff] [blame] | 162 | |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame^] | 163 | ret = i915_vma_unbind(vma); |
| 164 | if (ret) |
| 165 | return ret; |
Chris Wilson | df15315 | 2010-11-15 05:25:58 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Chris Wilson | f23eda8 | 2016-08-15 10:48:53 +0100 | [diff] [blame] | 168 | return 0; |
Chris Wilson | 52dc7d3 | 2009-06-06 09:46:01 +0100 | [diff] [blame] | 169 | } |
| 170 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 171 | /** |
Daniel Vetter | 3271dca | 2015-07-24 17:40:15 +0200 | [diff] [blame] | 172 | * i915_gem_set_tiling - IOCTL handler to set tiling mode |
| 173 | * @dev: DRM device |
| 174 | * @data: data pointer for the ioctl |
| 175 | * @file: DRM file for the ioctl call |
| 176 | * |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 177 | * Sets the tiling mode of an object, returning the required swizzling of |
| 178 | * bit 6 of addresses in the object. |
Daniel Vetter | 3271dca | 2015-07-24 17:40:15 +0200 | [diff] [blame] | 179 | * |
| 180 | * Called by the user via ioctl. |
| 181 | * |
| 182 | * Returns: |
| 183 | * Zero on success, negative errno on failure. |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 184 | */ |
| 185 | int |
| 186 | i915_gem_set_tiling(struct drm_device *dev, void *data, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 187 | struct drm_file *file) |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 188 | { |
| 189 | struct drm_i915_gem_set_tiling *args = data; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 190 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 191 | struct drm_i915_gem_object *obj; |
Chris Wilson | f23eda8 | 2016-08-15 10:48:53 +0100 | [diff] [blame] | 192 | int err = 0; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 193 | |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 194 | /* Make sure we don't cross-contaminate obj->tiling_and_stride */ |
| 195 | BUILD_BUG_ON(I915_TILING_LAST & STRIDE_MASK); |
| 196 | |
Chris Wilson | 03ac064 | 2016-07-20 13:31:51 +0100 | [diff] [blame] | 197 | obj = i915_gem_object_lookup(file, args->handle); |
| 198 | if (!obj) |
Chris Wilson | bf79cb9 | 2010-08-04 14:19:46 +0100 | [diff] [blame] | 199 | return -ENOENT; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 200 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 201 | if (!i915_tiling_ok(dev, |
| 202 | args->stride, obj->base.size, args->tiling_mode)) { |
Chris Wilson | 34911fd | 2016-07-20 13:31:54 +0100 | [diff] [blame] | 203 | i915_gem_object_put_unlocked(obj); |
Jesse Barnes | 0f973f2 | 2009-01-26 17:10:45 -0800 | [diff] [blame] | 204 | return -EINVAL; |
Chris Wilson | 72daad4 | 2009-01-30 21:10:22 +0000 | [diff] [blame] | 205 | } |
Jesse Barnes | 0f973f2 | 2009-01-26 17:10:45 -0800 | [diff] [blame] | 206 | |
Imre Deak | e64e6bd | 2015-11-09 20:16:26 +0200 | [diff] [blame] | 207 | intel_runtime_pm_get(dev_priv); |
| 208 | |
Chris Wilson | 6c31a61 | 2015-02-12 07:53:18 +0000 | [diff] [blame] | 209 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 1f30a61 | 2015-04-15 16:39:59 +0100 | [diff] [blame] | 210 | if (obj->pin_display || obj->framebuffer_references) { |
Chris Wilson | f23eda8 | 2016-08-15 10:48:53 +0100 | [diff] [blame] | 211 | err = -EBUSY; |
Chris Wilson | 6c31a61 | 2015-02-12 07:53:18 +0000 | [diff] [blame] | 212 | goto err; |
Daniel Vetter | 31770bd | 2010-04-23 23:01:01 +0200 | [diff] [blame] | 213 | } |
| 214 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 215 | if (args->tiling_mode == I915_TILING_NONE) { |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 216 | args->swizzle_mode = I915_BIT_6_SWIZZLE_NONE; |
Chris Wilson | 52dc7d3 | 2009-06-06 09:46:01 +0100 | [diff] [blame] | 217 | args->stride = 0; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 218 | } else { |
| 219 | if (args->tiling_mode == I915_TILING_X) |
| 220 | args->swizzle_mode = dev_priv->mm.bit_6_swizzle_x; |
| 221 | else |
| 222 | args->swizzle_mode = dev_priv->mm.bit_6_swizzle_y; |
Eric Anholt | 280b713 | 2009-03-12 16:56:27 -0700 | [diff] [blame] | 223 | |
| 224 | /* Hide bit 17 swizzling from the user. This prevents old Mesa |
| 225 | * from aborting the application on sw fallbacks to bit 17, |
| 226 | * and we use the pread/pwrite bit17 paths to swizzle for it. |
| 227 | * If there was a user that was relying on the swizzle |
| 228 | * information for drm_intel_bo_map()ed reads/writes this would |
| 229 | * break it, but we don't have any of those. |
| 230 | */ |
| 231 | if (args->swizzle_mode == I915_BIT_6_SWIZZLE_9_17) |
| 232 | args->swizzle_mode = I915_BIT_6_SWIZZLE_9; |
| 233 | if (args->swizzle_mode == I915_BIT_6_SWIZZLE_9_10_17) |
| 234 | args->swizzle_mode = I915_BIT_6_SWIZZLE_9_10; |
| 235 | |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 236 | /* If we can't handle the swizzling, make it untiled. */ |
| 237 | if (args->swizzle_mode == I915_BIT_6_SWIZZLE_UNKNOWN) { |
| 238 | args->tiling_mode = I915_TILING_NONE; |
| 239 | args->swizzle_mode = I915_BIT_6_SWIZZLE_NONE; |
Chris Wilson | 52dc7d3 | 2009-06-06 09:46:01 +0100 | [diff] [blame] | 240 | args->stride = 0; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 241 | } |
| 242 | } |
Jesse Barnes | 0f973f2 | 2009-01-26 17:10:45 -0800 | [diff] [blame] | 243 | |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 244 | if (args->tiling_mode != i915_gem_object_get_tiling(obj) || |
| 245 | args->stride != i915_gem_object_get_stride(obj)) { |
Chris Wilson | 52dc7d3 | 2009-06-06 09:46:01 +0100 | [diff] [blame] | 246 | /* We need to rebind the object if its current allocation |
| 247 | * no longer meets the alignment restrictions for its new |
| 248 | * tiling mode. Otherwise we can just leave it alone, but |
Chris Wilson | 1869b62 | 2012-04-21 16:23:24 +0100 | [diff] [blame] | 249 | * need to ensure that any fence register is updated before |
| 250 | * the next fenced (either through the GTT or by the BLT unit |
| 251 | * on older GPUs) access. |
Chris Wilson | 5d82e3e | 2012-04-21 16:23:23 +0100 | [diff] [blame] | 252 | * |
| 253 | * After updating the tiling parameters, we then flag whether |
| 254 | * we need to update an associated fence register. Note this |
| 255 | * has to also include the unfenced register the GPU uses |
| 256 | * whilst executing a fenced command for an untiled object. |
Jesse Barnes | 0f973f2 | 2009-01-26 17:10:45 -0800 | [diff] [blame] | 257 | */ |
Chris Wilson | 467cffb | 2011-03-07 10:42:03 +0000 | [diff] [blame] | 258 | |
Chris Wilson | f23eda8 | 2016-08-15 10:48:53 +0100 | [diff] [blame] | 259 | err = i915_gem_object_fence_prepare(obj, args->tiling_mode); |
| 260 | if (!err) { |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame^] | 261 | struct i915_vma *vma; |
| 262 | |
Daniel Vetter | 656bfa3 | 2014-11-20 09:26:30 +0100 | [diff] [blame] | 263 | if (obj->pages && |
| 264 | obj->madv == I915_MADV_WILLNEED && |
| 265 | dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES) { |
| 266 | if (args->tiling_mode == I915_TILING_NONE) |
| 267 | i915_gem_object_unpin_pages(obj); |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 268 | if (!i915_gem_object_is_tiled(obj)) |
Daniel Vetter | 656bfa3 | 2014-11-20 09:26:30 +0100 | [diff] [blame] | 269 | i915_gem_object_pin_pages(obj); |
| 270 | } |
| 271 | |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame^] | 272 | list_for_each_entry(vma, &obj->vma_list, obj_link) { |
| 273 | if (!vma->fence) |
| 274 | continue; |
Chris Wilson | 5d82e3e | 2012-04-21 16:23:23 +0100 | [diff] [blame] | 275 | |
Chris Wilson | 49ef529 | 2016-08-18 17:17:00 +0100 | [diff] [blame^] | 276 | vma->fence->dirty = true; |
| 277 | } |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 278 | obj->tiling_and_stride = |
| 279 | args->stride | args->tiling_mode; |
Chris Wilson | 1869b62 | 2012-04-21 16:23:24 +0100 | [diff] [blame] | 280 | |
| 281 | /* Force the fence to be reacquired for GTT access */ |
| 282 | i915_gem_release_mmap(obj); |
Chris Wilson | 467cffb | 2011-03-07 10:42:03 +0000 | [diff] [blame] | 283 | } |
Chris Wilson | 52dc7d3 | 2009-06-06 09:46:01 +0100 | [diff] [blame] | 284 | } |
Chris Wilson | 467cffb | 2011-03-07 10:42:03 +0000 | [diff] [blame] | 285 | /* we have to maintain this existing ABI... */ |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 286 | args->stride = i915_gem_object_get_stride(obj); |
| 287 | args->tiling_mode = i915_gem_object_get_tiling(obj); |
Chris Wilson | e9b73c6 | 2012-12-03 21:03:14 +0000 | [diff] [blame] | 288 | |
| 289 | /* Try to preallocate memory required to save swizzling on put-pages */ |
| 290 | if (i915_gem_object_needs_bit17_swizzle(obj)) { |
| 291 | if (obj->bit_17 == NULL) { |
Daniel Vetter | a1e2265 | 2013-09-21 00:35:38 +0200 | [diff] [blame] | 292 | obj->bit_17 = kcalloc(BITS_TO_LONGS(obj->base.size >> PAGE_SHIFT), |
Chris Wilson | e9b73c6 | 2012-12-03 21:03:14 +0000 | [diff] [blame] | 293 | sizeof(long), GFP_KERNEL); |
| 294 | } |
| 295 | } else { |
| 296 | kfree(obj->bit_17); |
| 297 | obj->bit_17 = NULL; |
| 298 | } |
| 299 | |
Chris Wilson | 6c31a61 | 2015-02-12 07:53:18 +0000 | [diff] [blame] | 300 | err: |
Chris Wilson | f8c417c | 2016-07-20 13:31:53 +0100 | [diff] [blame] | 301 | i915_gem_object_put(obj); |
Chris Wilson | d687310 | 2009-02-08 19:07:51 +0000 | [diff] [blame] | 302 | mutex_unlock(&dev->struct_mutex); |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 303 | |
Imre Deak | e64e6bd | 2015-11-09 20:16:26 +0200 | [diff] [blame] | 304 | intel_runtime_pm_put(dev_priv); |
| 305 | |
Chris Wilson | f23eda8 | 2016-08-15 10:48:53 +0100 | [diff] [blame] | 306 | return err; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | /** |
Daniel Vetter | 3271dca | 2015-07-24 17:40:15 +0200 | [diff] [blame] | 310 | * i915_gem_get_tiling - IOCTL handler to get tiling mode |
| 311 | * @dev: DRM device |
| 312 | * @data: data pointer for the ioctl |
| 313 | * @file: DRM file for the ioctl call |
| 314 | * |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 315 | * Returns the current tiling mode and required bit 6 swizzling for the object. |
Daniel Vetter | 3271dca | 2015-07-24 17:40:15 +0200 | [diff] [blame] | 316 | * |
| 317 | * Called by the user via ioctl. |
| 318 | * |
| 319 | * Returns: |
| 320 | * Zero on success, negative errno on failure. |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 321 | */ |
| 322 | int |
| 323 | i915_gem_get_tiling(struct drm_device *dev, void *data, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 324 | struct drm_file *file) |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 325 | { |
| 326 | struct drm_i915_gem_get_tiling *args = data; |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 327 | struct drm_i915_private *dev_priv = to_i915(dev); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 328 | struct drm_i915_gem_object *obj; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 329 | |
Chris Wilson | 03ac064 | 2016-07-20 13:31:51 +0100 | [diff] [blame] | 330 | obj = i915_gem_object_lookup(file, args->handle); |
| 331 | if (!obj) |
Chris Wilson | bf79cb9 | 2010-08-04 14:19:46 +0100 | [diff] [blame] | 332 | return -ENOENT; |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 333 | |
Chris Wilson | 3e510a8 | 2016-08-05 10:14:23 +0100 | [diff] [blame] | 334 | args->tiling_mode = READ_ONCE(obj->tiling_and_stride) & TILING_MASK; |
Chris Wilson | 9ad3676 | 2016-08-05 10:14:21 +0100 | [diff] [blame] | 335 | switch (args->tiling_mode) { |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 336 | case I915_TILING_X: |
| 337 | args->swizzle_mode = dev_priv->mm.bit_6_swizzle_x; |
| 338 | break; |
| 339 | case I915_TILING_Y: |
| 340 | args->swizzle_mode = dev_priv->mm.bit_6_swizzle_y; |
| 341 | break; |
| 342 | case I915_TILING_NONE: |
| 343 | args->swizzle_mode = I915_BIT_6_SWIZZLE_NONE; |
| 344 | break; |
| 345 | default: |
| 346 | DRM_ERROR("unknown tiling mode\n"); |
| 347 | } |
| 348 | |
Eric Anholt | 280b713 | 2009-03-12 16:56:27 -0700 | [diff] [blame] | 349 | /* Hide bit 17 from the user -- see comment in i915_gem_set_tiling */ |
Chris Wilson | 5eb3e5a | 2015-06-28 09:19:26 +0100 | [diff] [blame] | 350 | if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES) |
| 351 | args->phys_swizzle_mode = I915_BIT_6_SWIZZLE_UNKNOWN; |
| 352 | else |
| 353 | args->phys_swizzle_mode = args->swizzle_mode; |
Eric Anholt | 280b713 | 2009-03-12 16:56:27 -0700 | [diff] [blame] | 354 | if (args->swizzle_mode == I915_BIT_6_SWIZZLE_9_17) |
| 355 | args->swizzle_mode = I915_BIT_6_SWIZZLE_9; |
| 356 | if (args->swizzle_mode == I915_BIT_6_SWIZZLE_9_10_17) |
| 357 | args->swizzle_mode = I915_BIT_6_SWIZZLE_9_10; |
| 358 | |
Chris Wilson | 9ad3676 | 2016-08-05 10:14:21 +0100 | [diff] [blame] | 359 | i915_gem_object_put_unlocked(obj); |
Eric Anholt | 673a394 | 2008-07-30 12:06:12 -0700 | [diff] [blame] | 360 | return 0; |
| 361 | } |