Daniel Vetter | 76aaf22 | 2010-11-05 22:23:30 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010 Daniel Vetter |
Ben Widawsky | c4ac524 | 2014-02-19 22:05:47 -0800 | [diff] [blame] | 3 | * Copyright © 2011-2014 Intel Corporation |
Daniel Vetter | 76aaf22 | 2010-11-05 22:23:30 +0100 | [diff] [blame] | 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the next |
| 13 | * paragraph) shall be included in all copies or substantial portions of the |
| 14 | * 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 DEALINGS |
| 22 | * IN THE SOFTWARE. |
| 23 | * |
| 24 | */ |
| 25 | |
Daniel Vetter | 0e46ce2 | 2014-01-08 16:10:27 +0100 | [diff] [blame] | 26 | #include <linux/seq_file.h> |
Chris Wilson | 5bab6f6 | 2015-10-23 18:43:32 +0100 | [diff] [blame] | 27 | #include <linux/stop_machine.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 28 | #include <drm/drmP.h> |
| 29 | #include <drm/i915_drm.h> |
Daniel Vetter | 76aaf22 | 2010-11-05 22:23:30 +0100 | [diff] [blame] | 30 | #include "i915_drv.h" |
Yu Zhang | 5dda8fa | 2015-02-10 19:05:48 +0800 | [diff] [blame] | 31 | #include "i915_vgpu.h" |
Daniel Vetter | 76aaf22 | 2010-11-05 22:23:30 +0100 | [diff] [blame] | 32 | #include "i915_trace.h" |
| 33 | #include "intel_drv.h" |
| 34 | |
Tvrtko Ursulin | 45f8f69 | 2014-12-10 17:27:59 +0000 | [diff] [blame] | 35 | /** |
| 36 | * DOC: Global GTT views |
| 37 | * |
| 38 | * Background and previous state |
| 39 | * |
| 40 | * Historically objects could exists (be bound) in global GTT space only as |
| 41 | * singular instances with a view representing all of the object's backing pages |
| 42 | * in a linear fashion. This view will be called a normal view. |
| 43 | * |
| 44 | * To support multiple views of the same object, where the number of mapped |
| 45 | * pages is not equal to the backing store, or where the layout of the pages |
| 46 | * is not linear, concept of a GGTT view was added. |
| 47 | * |
| 48 | * One example of an alternative view is a stereo display driven by a single |
| 49 | * image. In this case we would have a framebuffer looking like this |
| 50 | * (2x2 pages): |
| 51 | * |
| 52 | * 12 |
| 53 | * 34 |
| 54 | * |
| 55 | * Above would represent a normal GGTT view as normally mapped for GPU or CPU |
| 56 | * rendering. In contrast, fed to the display engine would be an alternative |
| 57 | * view which could look something like this: |
| 58 | * |
| 59 | * 1212 |
| 60 | * 3434 |
| 61 | * |
| 62 | * In this example both the size and layout of pages in the alternative view is |
| 63 | * different from the normal view. |
| 64 | * |
| 65 | * Implementation and usage |
| 66 | * |
| 67 | * GGTT views are implemented using VMAs and are distinguished via enum |
| 68 | * i915_ggtt_view_type and struct i915_ggtt_view. |
| 69 | * |
| 70 | * A new flavour of core GEM functions which work with GGTT bound objects were |
Joonas Lahtinen | ec7adb6 | 2015-03-16 14:11:13 +0200 | [diff] [blame] | 71 | * added with the _ggtt_ infix, and sometimes with _view postfix to avoid |
| 72 | * renaming in large amounts of code. They take the struct i915_ggtt_view |
| 73 | * parameter encapsulating all metadata required to implement a view. |
Tvrtko Ursulin | 45f8f69 | 2014-12-10 17:27:59 +0000 | [diff] [blame] | 74 | * |
| 75 | * As a helper for callers which are only interested in the normal view, |
| 76 | * globally const i915_ggtt_view_normal singleton instance exists. All old core |
| 77 | * GEM API functions, the ones not taking the view parameter, are operating on, |
| 78 | * or with the normal GGTT view. |
| 79 | * |
| 80 | * Code wanting to add or use a new GGTT view needs to: |
| 81 | * |
| 82 | * 1. Add a new enum with a suitable name. |
| 83 | * 2. Extend the metadata in the i915_ggtt_view structure if required. |
| 84 | * 3. Add support to i915_get_vma_pages(). |
| 85 | * |
| 86 | * New views are required to build a scatter-gather table from within the |
| 87 | * i915_get_vma_pages function. This table is stored in the vma.ggtt_view and |
| 88 | * exists for the lifetime of an VMA. |
| 89 | * |
| 90 | * Core API is designed to have copy semantics which means that passed in |
| 91 | * struct i915_ggtt_view does not need to be persistent (left around after |
| 92 | * calling the core API functions). |
| 93 | * |
| 94 | */ |
| 95 | |
Daniel Vetter | 70b9f6f | 2015-04-14 17:35:27 +0200 | [diff] [blame] | 96 | static int |
| 97 | i915_get_ggtt_vma_pages(struct i915_vma *vma); |
| 98 | |
Ville Syrjälä | b5e1698 | 2016-01-14 15:22:10 +0200 | [diff] [blame] | 99 | const struct i915_ggtt_view i915_ggtt_view_normal = { |
| 100 | .type = I915_GGTT_VIEW_NORMAL, |
| 101 | }; |
Joonas Lahtinen | 9abc464 | 2015-03-27 13:09:22 +0200 | [diff] [blame] | 102 | const struct i915_ggtt_view i915_ggtt_view_rotated = { |
Ville Syrjälä | b5e1698 | 2016-01-14 15:22:10 +0200 | [diff] [blame] | 103 | .type = I915_GGTT_VIEW_ROTATED, |
Joonas Lahtinen | 9abc464 | 2015-03-27 13:09:22 +0200 | [diff] [blame] | 104 | }; |
Tvrtko Ursulin | fe14d5f | 2014-12-10 17:27:58 +0000 | [diff] [blame] | 105 | |
Daniel Vetter | cfa7c86 | 2014-04-29 11:53:58 +0200 | [diff] [blame] | 106 | static int sanitize_enable_ppgtt(struct drm_device *dev, int enable_ppgtt) |
| 107 | { |
Chris Wilson | 1893a71 | 2014-09-19 11:56:27 +0100 | [diff] [blame] | 108 | bool has_aliasing_ppgtt; |
| 109 | bool has_full_ppgtt; |
Michel Thierry | 1f9a99e | 2015-09-30 15:36:19 +0100 | [diff] [blame] | 110 | bool has_full_48bit_ppgtt; |
Chris Wilson | 1893a71 | 2014-09-19 11:56:27 +0100 | [diff] [blame] | 111 | |
| 112 | has_aliasing_ppgtt = INTEL_INFO(dev)->gen >= 6; |
| 113 | has_full_ppgtt = INTEL_INFO(dev)->gen >= 7; |
Michel Thierry | 1f9a99e | 2015-09-30 15:36:19 +0100 | [diff] [blame] | 114 | has_full_48bit_ppgtt = IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9; |
Chris Wilson | 1893a71 | 2014-09-19 11:56:27 +0100 | [diff] [blame] | 115 | |
Yu Zhang | 71ba2d6 | 2015-02-10 19:05:54 +0800 | [diff] [blame] | 116 | if (intel_vgpu_active(dev)) |
| 117 | has_full_ppgtt = false; /* emulation is too hard */ |
| 118 | |
Damien Lespiau | 70ee45e | 2014-11-14 15:05:59 +0000 | [diff] [blame] | 119 | /* |
| 120 | * We don't allow disabling PPGTT for gen9+ as it's a requirement for |
| 121 | * execlists, the sole mechanism available to submit work. |
| 122 | */ |
| 123 | if (INTEL_INFO(dev)->gen < 9 && |
| 124 | (enable_ppgtt == 0 || !has_aliasing_ppgtt)) |
Daniel Vetter | cfa7c86 | 2014-04-29 11:53:58 +0200 | [diff] [blame] | 125 | return 0; |
| 126 | |
| 127 | if (enable_ppgtt == 1) |
| 128 | return 1; |
| 129 | |
Chris Wilson | 1893a71 | 2014-09-19 11:56:27 +0100 | [diff] [blame] | 130 | if (enable_ppgtt == 2 && has_full_ppgtt) |
Daniel Vetter | cfa7c86 | 2014-04-29 11:53:58 +0200 | [diff] [blame] | 131 | return 2; |
| 132 | |
Michel Thierry | 1f9a99e | 2015-09-30 15:36:19 +0100 | [diff] [blame] | 133 | if (enable_ppgtt == 3 && has_full_48bit_ppgtt) |
| 134 | return 3; |
| 135 | |
Daniel Vetter | 93a25a9 | 2014-03-06 09:40:43 +0100 | [diff] [blame] | 136 | #ifdef CONFIG_INTEL_IOMMU |
| 137 | /* Disable ppgtt on SNB if VT-d is on. */ |
| 138 | if (INTEL_INFO(dev)->gen == 6 && intel_iommu_gfx_mapped) { |
| 139 | DRM_INFO("Disabling PPGTT because VT-d is on\n"); |
Daniel Vetter | cfa7c86 | 2014-04-29 11:53:58 +0200 | [diff] [blame] | 140 | return 0; |
Daniel Vetter | 93a25a9 | 2014-03-06 09:40:43 +0100 | [diff] [blame] | 141 | } |
| 142 | #endif |
| 143 | |
Jesse Barnes | 62942ed | 2014-06-13 09:28:33 -0700 | [diff] [blame] | 144 | /* Early VLV doesn't have this */ |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 145 | if (IS_VALLEYVIEW(dev) && dev->pdev->revision < 0xb) { |
Jesse Barnes | 62942ed | 2014-06-13 09:28:33 -0700 | [diff] [blame] | 146 | DRM_DEBUG_DRIVER("disabling PPGTT on pre-B3 step VLV\n"); |
| 147 | return 0; |
| 148 | } |
| 149 | |
Michel Thierry | 2f82bbd | 2014-12-15 14:58:00 +0000 | [diff] [blame] | 150 | if (INTEL_INFO(dev)->gen >= 8 && i915.enable_execlists) |
Michel Thierry | 1f9a99e | 2015-09-30 15:36:19 +0100 | [diff] [blame] | 151 | return has_full_48bit_ppgtt ? 3 : 2; |
Michel Thierry | 2f82bbd | 2014-12-15 14:58:00 +0000 | [diff] [blame] | 152 | else |
| 153 | return has_aliasing_ppgtt ? 1 : 0; |
Daniel Vetter | 93a25a9 | 2014-03-06 09:40:43 +0100 | [diff] [blame] | 154 | } |
| 155 | |
Daniel Vetter | 70b9f6f | 2015-04-14 17:35:27 +0200 | [diff] [blame] | 156 | static int ppgtt_bind_vma(struct i915_vma *vma, |
| 157 | enum i915_cache_level cache_level, |
| 158 | u32 unused) |
Daniel Vetter | 4755265 | 2015-04-14 17:35:24 +0200 | [diff] [blame] | 159 | { |
| 160 | u32 pte_flags = 0; |
| 161 | |
| 162 | /* Currently applicable only to VLV */ |
| 163 | if (vma->obj->gt_ro) |
| 164 | pte_flags |= PTE_READ_ONLY; |
| 165 | |
| 166 | vma->vm->insert_entries(vma->vm, vma->obj->pages, vma->node.start, |
| 167 | cache_level, pte_flags); |
Daniel Vetter | 70b9f6f | 2015-04-14 17:35:27 +0200 | [diff] [blame] | 168 | |
| 169 | return 0; |
Daniel Vetter | 4755265 | 2015-04-14 17:35:24 +0200 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | static void ppgtt_unbind_vma(struct i915_vma *vma) |
| 173 | { |
| 174 | vma->vm->clear_range(vma->vm, |
| 175 | vma->node.start, |
| 176 | vma->obj->base.size, |
| 177 | true); |
| 178 | } |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 179 | |
Daniel Vetter | 2c642b0 | 2015-04-14 17:35:26 +0200 | [diff] [blame] | 180 | static gen8_pte_t gen8_pte_encode(dma_addr_t addr, |
| 181 | enum i915_cache_level level, |
| 182 | bool valid) |
Ben Widawsky | 94ec8f6 | 2013-11-02 21:07:18 -0700 | [diff] [blame] | 183 | { |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 184 | gen8_pte_t pte = valid ? _PAGE_PRESENT | _PAGE_RW : 0; |
Ben Widawsky | 94ec8f6 | 2013-11-02 21:07:18 -0700 | [diff] [blame] | 185 | pte |= addr; |
Ben Widawsky | 63c42e5 | 2014-04-18 18:04:27 -0300 | [diff] [blame] | 186 | |
| 187 | switch (level) { |
| 188 | case I915_CACHE_NONE: |
Ben Widawsky | fbe5d36 | 2013-11-04 19:56:49 -0800 | [diff] [blame] | 189 | pte |= PPAT_UNCACHED_INDEX; |
Ben Widawsky | 63c42e5 | 2014-04-18 18:04:27 -0300 | [diff] [blame] | 190 | break; |
| 191 | case I915_CACHE_WT: |
| 192 | pte |= PPAT_DISPLAY_ELLC_INDEX; |
| 193 | break; |
| 194 | default: |
| 195 | pte |= PPAT_CACHED_INDEX; |
| 196 | break; |
| 197 | } |
| 198 | |
Ben Widawsky | 94ec8f6 | 2013-11-02 21:07:18 -0700 | [diff] [blame] | 199 | return pte; |
| 200 | } |
| 201 | |
Mika Kuoppala | fe36f55 | 2015-06-25 18:35:16 +0300 | [diff] [blame] | 202 | static gen8_pde_t gen8_pde_encode(const dma_addr_t addr, |
| 203 | const enum i915_cache_level level) |
Ben Widawsky | b1fe667 | 2013-11-04 21:20:14 -0800 | [diff] [blame] | 204 | { |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 205 | gen8_pde_t pde = _PAGE_PRESENT | _PAGE_RW; |
Ben Widawsky | b1fe667 | 2013-11-04 21:20:14 -0800 | [diff] [blame] | 206 | pde |= addr; |
| 207 | if (level != I915_CACHE_NONE) |
| 208 | pde |= PPAT_CACHED_PDE_INDEX; |
| 209 | else |
| 210 | pde |= PPAT_UNCACHED_INDEX; |
| 211 | return pde; |
| 212 | } |
| 213 | |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 214 | #define gen8_pdpe_encode gen8_pde_encode |
| 215 | #define gen8_pml4e_encode gen8_pde_encode |
| 216 | |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 217 | static gen6_pte_t snb_pte_encode(dma_addr_t addr, |
| 218 | enum i915_cache_level level, |
| 219 | bool valid, u32 unused) |
Ben Widawsky | 54d1252 | 2012-09-24 16:44:32 -0700 | [diff] [blame] | 220 | { |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 221 | gen6_pte_t pte = valid ? GEN6_PTE_VALID : 0; |
Ben Widawsky | 54d1252 | 2012-09-24 16:44:32 -0700 | [diff] [blame] | 222 | pte |= GEN6_PTE_ADDR_ENCODE(addr); |
Ben Widawsky | e7210c3 | 2012-10-19 09:33:22 -0700 | [diff] [blame] | 223 | |
| 224 | switch (level) { |
Chris Wilson | 350ec88 | 2013-08-06 13:17:02 +0100 | [diff] [blame] | 225 | case I915_CACHE_L3_LLC: |
| 226 | case I915_CACHE_LLC: |
| 227 | pte |= GEN6_PTE_CACHE_LLC; |
| 228 | break; |
| 229 | case I915_CACHE_NONE: |
| 230 | pte |= GEN6_PTE_UNCACHED; |
| 231 | break; |
| 232 | default: |
Daniel Vetter | 5f77eeb | 2014-12-08 16:40:10 +0100 | [diff] [blame] | 233 | MISSING_CASE(level); |
Chris Wilson | 350ec88 | 2013-08-06 13:17:02 +0100 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | return pte; |
| 237 | } |
| 238 | |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 239 | static gen6_pte_t ivb_pte_encode(dma_addr_t addr, |
| 240 | enum i915_cache_level level, |
| 241 | bool valid, u32 unused) |
Chris Wilson | 350ec88 | 2013-08-06 13:17:02 +0100 | [diff] [blame] | 242 | { |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 243 | gen6_pte_t pte = valid ? GEN6_PTE_VALID : 0; |
Chris Wilson | 350ec88 | 2013-08-06 13:17:02 +0100 | [diff] [blame] | 244 | pte |= GEN6_PTE_ADDR_ENCODE(addr); |
| 245 | |
| 246 | switch (level) { |
| 247 | case I915_CACHE_L3_LLC: |
| 248 | pte |= GEN7_PTE_CACHE_L3_LLC; |
Ben Widawsky | e7210c3 | 2012-10-19 09:33:22 -0700 | [diff] [blame] | 249 | break; |
| 250 | case I915_CACHE_LLC: |
| 251 | pte |= GEN6_PTE_CACHE_LLC; |
| 252 | break; |
| 253 | case I915_CACHE_NONE: |
Kenneth Graunke | 9119708 | 2013-04-22 00:53:51 -0700 | [diff] [blame] | 254 | pte |= GEN6_PTE_UNCACHED; |
Ben Widawsky | e7210c3 | 2012-10-19 09:33:22 -0700 | [diff] [blame] | 255 | break; |
| 256 | default: |
Daniel Vetter | 5f77eeb | 2014-12-08 16:40:10 +0100 | [diff] [blame] | 257 | MISSING_CASE(level); |
Ben Widawsky | e7210c3 | 2012-10-19 09:33:22 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Ben Widawsky | 54d1252 | 2012-09-24 16:44:32 -0700 | [diff] [blame] | 260 | return pte; |
| 261 | } |
| 262 | |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 263 | static gen6_pte_t byt_pte_encode(dma_addr_t addr, |
| 264 | enum i915_cache_level level, |
| 265 | bool valid, u32 flags) |
Kenneth Graunke | 93c34e7 | 2013-04-22 00:53:50 -0700 | [diff] [blame] | 266 | { |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 267 | gen6_pte_t pte = valid ? GEN6_PTE_VALID : 0; |
Kenneth Graunke | 93c34e7 | 2013-04-22 00:53:50 -0700 | [diff] [blame] | 268 | pte |= GEN6_PTE_ADDR_ENCODE(addr); |
| 269 | |
Akash Goel | 24f3a8c | 2014-06-17 10:59:42 +0530 | [diff] [blame] | 270 | if (!(flags & PTE_READ_ONLY)) |
| 271 | pte |= BYT_PTE_WRITEABLE; |
Kenneth Graunke | 93c34e7 | 2013-04-22 00:53:50 -0700 | [diff] [blame] | 272 | |
| 273 | if (level != I915_CACHE_NONE) |
| 274 | pte |= BYT_PTE_SNOOPED_BY_CPU_CACHES; |
| 275 | |
| 276 | return pte; |
| 277 | } |
| 278 | |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 279 | static gen6_pte_t hsw_pte_encode(dma_addr_t addr, |
| 280 | enum i915_cache_level level, |
| 281 | bool valid, u32 unused) |
Kenneth Graunke | 9119708 | 2013-04-22 00:53:51 -0700 | [diff] [blame] | 282 | { |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 283 | gen6_pte_t pte = valid ? GEN6_PTE_VALID : 0; |
Ben Widawsky | 0d8ff15 | 2013-07-04 11:02:03 -0700 | [diff] [blame] | 284 | pte |= HSW_PTE_ADDR_ENCODE(addr); |
Kenneth Graunke | 9119708 | 2013-04-22 00:53:51 -0700 | [diff] [blame] | 285 | |
| 286 | if (level != I915_CACHE_NONE) |
Ben Widawsky | 87a6b68 | 2013-08-04 23:47:29 -0700 | [diff] [blame] | 287 | pte |= HSW_WB_LLC_AGE3; |
Kenneth Graunke | 9119708 | 2013-04-22 00:53:51 -0700 | [diff] [blame] | 288 | |
| 289 | return pte; |
| 290 | } |
| 291 | |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 292 | static gen6_pte_t iris_pte_encode(dma_addr_t addr, |
| 293 | enum i915_cache_level level, |
| 294 | bool valid, u32 unused) |
Ben Widawsky | 4d15c14 | 2013-07-04 11:02:06 -0700 | [diff] [blame] | 295 | { |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 296 | gen6_pte_t pte = valid ? GEN6_PTE_VALID : 0; |
Ben Widawsky | 4d15c14 | 2013-07-04 11:02:06 -0700 | [diff] [blame] | 297 | pte |= HSW_PTE_ADDR_ENCODE(addr); |
| 298 | |
Chris Wilson | 651d794 | 2013-08-08 14:41:10 +0100 | [diff] [blame] | 299 | switch (level) { |
| 300 | case I915_CACHE_NONE: |
| 301 | break; |
| 302 | case I915_CACHE_WT: |
Chris Wilson | c51e970 | 2013-11-22 10:37:53 +0000 | [diff] [blame] | 303 | pte |= HSW_WT_ELLC_LLC_AGE3; |
Chris Wilson | 651d794 | 2013-08-08 14:41:10 +0100 | [diff] [blame] | 304 | break; |
| 305 | default: |
Chris Wilson | c51e970 | 2013-11-22 10:37:53 +0000 | [diff] [blame] | 306 | pte |= HSW_WB_ELLC_LLC_AGE3; |
Chris Wilson | 651d794 | 2013-08-08 14:41:10 +0100 | [diff] [blame] | 307 | break; |
| 308 | } |
Ben Widawsky | 4d15c14 | 2013-07-04 11:02:06 -0700 | [diff] [blame] | 309 | |
| 310 | return pte; |
| 311 | } |
| 312 | |
Mika Kuoppala | c114f76 | 2015-06-25 18:35:13 +0300 | [diff] [blame] | 313 | static int __setup_page_dma(struct drm_device *dev, |
| 314 | struct i915_page_dma *p, gfp_t flags) |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 315 | { |
| 316 | struct device *device = &dev->pdev->dev; |
| 317 | |
Mika Kuoppala | c114f76 | 2015-06-25 18:35:13 +0300 | [diff] [blame] | 318 | p->page = alloc_page(flags); |
Mika Kuoppala | 44159dd | 2015-06-25 18:35:07 +0300 | [diff] [blame] | 319 | if (!p->page) |
Michel Thierry | 1266cdb | 2015-03-24 17:06:33 +0000 | [diff] [blame] | 320 | return -ENOMEM; |
| 321 | |
Mika Kuoppala | 44159dd | 2015-06-25 18:35:07 +0300 | [diff] [blame] | 322 | p->daddr = dma_map_page(device, |
| 323 | p->page, 0, 4096, PCI_DMA_BIDIRECTIONAL); |
| 324 | |
| 325 | if (dma_mapping_error(device, p->daddr)) { |
| 326 | __free_page(p->page); |
| 327 | return -EINVAL; |
| 328 | } |
| 329 | |
Michel Thierry | 1266cdb | 2015-03-24 17:06:33 +0000 | [diff] [blame] | 330 | return 0; |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Mika Kuoppala | c114f76 | 2015-06-25 18:35:13 +0300 | [diff] [blame] | 333 | static int setup_page_dma(struct drm_device *dev, struct i915_page_dma *p) |
| 334 | { |
| 335 | return __setup_page_dma(dev, p, GFP_KERNEL); |
| 336 | } |
| 337 | |
Mika Kuoppala | 44159dd | 2015-06-25 18:35:07 +0300 | [diff] [blame] | 338 | static void cleanup_page_dma(struct drm_device *dev, struct i915_page_dma *p) |
| 339 | { |
| 340 | if (WARN_ON(!p->page)) |
| 341 | return; |
| 342 | |
| 343 | dma_unmap_page(&dev->pdev->dev, p->daddr, 4096, PCI_DMA_BIDIRECTIONAL); |
| 344 | __free_page(p->page); |
| 345 | memset(p, 0, sizeof(*p)); |
| 346 | } |
| 347 | |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 348 | static void *kmap_page_dma(struct i915_page_dma *p) |
Mika Kuoppala | 73eeea5 | 2015-06-25 18:35:10 +0300 | [diff] [blame] | 349 | { |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 350 | return kmap_atomic(p->page); |
| 351 | } |
Mika Kuoppala | 73eeea5 | 2015-06-25 18:35:10 +0300 | [diff] [blame] | 352 | |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 353 | /* We use the flushing unmap only with ppgtt structures: |
| 354 | * page directories, page tables and scratch pages. |
| 355 | */ |
| 356 | static void kunmap_page_dma(struct drm_device *dev, void *vaddr) |
| 357 | { |
Mika Kuoppala | 73eeea5 | 2015-06-25 18:35:10 +0300 | [diff] [blame] | 358 | /* There are only few exceptions for gen >=6. chv and bxt. |
| 359 | * And we are not sure about the latter so play safe for now. |
| 360 | */ |
| 361 | if (IS_CHERRYVIEW(dev) || IS_BROXTON(dev)) |
| 362 | drm_clflush_virt_range(vaddr, PAGE_SIZE); |
| 363 | |
| 364 | kunmap_atomic(vaddr); |
| 365 | } |
| 366 | |
Mika Kuoppala | 567047b | 2015-06-25 18:35:12 +0300 | [diff] [blame] | 367 | #define kmap_px(px) kmap_page_dma(px_base(px)) |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 368 | #define kunmap_px(ppgtt, vaddr) kunmap_page_dma((ppgtt)->base.dev, (vaddr)) |
| 369 | |
Mika Kuoppala | 567047b | 2015-06-25 18:35:12 +0300 | [diff] [blame] | 370 | #define setup_px(dev, px) setup_page_dma((dev), px_base(px)) |
| 371 | #define cleanup_px(dev, px) cleanup_page_dma((dev), px_base(px)) |
| 372 | #define fill_px(dev, px, v) fill_page_dma((dev), px_base(px), (v)) |
| 373 | #define fill32_px(dev, px, v) fill_page_dma_32((dev), px_base(px), (v)) |
| 374 | |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 375 | static void fill_page_dma(struct drm_device *dev, struct i915_page_dma *p, |
| 376 | const uint64_t val) |
| 377 | { |
| 378 | int i; |
| 379 | uint64_t * const vaddr = kmap_page_dma(p); |
| 380 | |
| 381 | for (i = 0; i < 512; i++) |
| 382 | vaddr[i] = val; |
| 383 | |
| 384 | kunmap_page_dma(dev, vaddr); |
| 385 | } |
| 386 | |
Mika Kuoppala | 73eeea5 | 2015-06-25 18:35:10 +0300 | [diff] [blame] | 387 | static void fill_page_dma_32(struct drm_device *dev, struct i915_page_dma *p, |
| 388 | const uint32_t val32) |
| 389 | { |
| 390 | uint64_t v = val32; |
| 391 | |
| 392 | v = v << 32 | val32; |
| 393 | |
| 394 | fill_page_dma(dev, p, v); |
| 395 | } |
| 396 | |
Mika Kuoppala | 4ad2af1 | 2015-06-30 18:16:39 +0300 | [diff] [blame] | 397 | static struct i915_page_scratch *alloc_scratch_page(struct drm_device *dev) |
| 398 | { |
| 399 | struct i915_page_scratch *sp; |
| 400 | int ret; |
| 401 | |
| 402 | sp = kzalloc(sizeof(*sp), GFP_KERNEL); |
| 403 | if (sp == NULL) |
| 404 | return ERR_PTR(-ENOMEM); |
| 405 | |
| 406 | ret = __setup_page_dma(dev, px_base(sp), GFP_DMA32 | __GFP_ZERO); |
| 407 | if (ret) { |
| 408 | kfree(sp); |
| 409 | return ERR_PTR(ret); |
| 410 | } |
| 411 | |
| 412 | set_pages_uc(px_page(sp), 1); |
| 413 | |
| 414 | return sp; |
| 415 | } |
| 416 | |
| 417 | static void free_scratch_page(struct drm_device *dev, |
| 418 | struct i915_page_scratch *sp) |
| 419 | { |
| 420 | set_pages_wb(px_page(sp), 1); |
| 421 | |
| 422 | cleanup_px(dev, sp); |
| 423 | kfree(sp); |
| 424 | } |
| 425 | |
Mika Kuoppala | 8a1ebd7 | 2015-05-22 20:04:59 +0300 | [diff] [blame] | 426 | static struct i915_page_table *alloc_pt(struct drm_device *dev) |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 427 | { |
Michel Thierry | ec565b3 | 2015-04-08 12:13:23 +0100 | [diff] [blame] | 428 | struct i915_page_table *pt; |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 429 | const size_t count = INTEL_INFO(dev)->gen >= 8 ? |
| 430 | GEN8_PTES : GEN6_PTES; |
| 431 | int ret = -ENOMEM; |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 432 | |
| 433 | pt = kzalloc(sizeof(*pt), GFP_KERNEL); |
| 434 | if (!pt) |
| 435 | return ERR_PTR(-ENOMEM); |
| 436 | |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 437 | pt->used_ptes = kcalloc(BITS_TO_LONGS(count), sizeof(*pt->used_ptes), |
| 438 | GFP_KERNEL); |
| 439 | |
| 440 | if (!pt->used_ptes) |
| 441 | goto fail_bitmap; |
| 442 | |
Mika Kuoppala | 567047b | 2015-06-25 18:35:12 +0300 | [diff] [blame] | 443 | ret = setup_px(dev, pt); |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 444 | if (ret) |
Mika Kuoppala | 44159dd | 2015-06-25 18:35:07 +0300 | [diff] [blame] | 445 | goto fail_page_m; |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 446 | |
| 447 | return pt; |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 448 | |
Mika Kuoppala | 44159dd | 2015-06-25 18:35:07 +0300 | [diff] [blame] | 449 | fail_page_m: |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 450 | kfree(pt->used_ptes); |
| 451 | fail_bitmap: |
| 452 | kfree(pt); |
| 453 | |
| 454 | return ERR_PTR(ret); |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 455 | } |
| 456 | |
Mika Kuoppala | 2e906be | 2015-06-30 18:16:37 +0300 | [diff] [blame] | 457 | static void free_pt(struct drm_device *dev, struct i915_page_table *pt) |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 458 | { |
Mika Kuoppala | 2e906be | 2015-06-30 18:16:37 +0300 | [diff] [blame] | 459 | cleanup_px(dev, pt); |
| 460 | kfree(pt->used_ptes); |
| 461 | kfree(pt); |
| 462 | } |
| 463 | |
| 464 | static void gen8_initialize_pt(struct i915_address_space *vm, |
| 465 | struct i915_page_table *pt) |
| 466 | { |
| 467 | gen8_pte_t scratch_pte; |
| 468 | |
| 469 | scratch_pte = gen8_pte_encode(px_dma(vm->scratch_page), |
| 470 | I915_CACHE_LLC, true); |
| 471 | |
| 472 | fill_px(vm->dev, pt, scratch_pte); |
| 473 | } |
| 474 | |
| 475 | static void gen6_initialize_pt(struct i915_address_space *vm, |
| 476 | struct i915_page_table *pt) |
| 477 | { |
| 478 | gen6_pte_t scratch_pte; |
| 479 | |
| 480 | WARN_ON(px_dma(vm->scratch_page) == 0); |
| 481 | |
| 482 | scratch_pte = vm->pte_encode(px_dma(vm->scratch_page), |
| 483 | I915_CACHE_LLC, true, 0); |
| 484 | |
| 485 | fill32_px(vm->dev, pt, scratch_pte); |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Mika Kuoppala | 8a1ebd7 | 2015-05-22 20:04:59 +0300 | [diff] [blame] | 488 | static struct i915_page_directory *alloc_pd(struct drm_device *dev) |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 489 | { |
Michel Thierry | ec565b3 | 2015-04-08 12:13:23 +0100 | [diff] [blame] | 490 | struct i915_page_directory *pd; |
Michel Thierry | 33c8819 | 2015-04-08 12:13:33 +0100 | [diff] [blame] | 491 | int ret = -ENOMEM; |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 492 | |
| 493 | pd = kzalloc(sizeof(*pd), GFP_KERNEL); |
| 494 | if (!pd) |
| 495 | return ERR_PTR(-ENOMEM); |
| 496 | |
Michel Thierry | 33c8819 | 2015-04-08 12:13:33 +0100 | [diff] [blame] | 497 | pd->used_pdes = kcalloc(BITS_TO_LONGS(I915_PDES), |
| 498 | sizeof(*pd->used_pdes), GFP_KERNEL); |
| 499 | if (!pd->used_pdes) |
Mika Kuoppala | a08e111 | 2015-06-25 18:35:08 +0300 | [diff] [blame] | 500 | goto fail_bitmap; |
Michel Thierry | 33c8819 | 2015-04-08 12:13:33 +0100 | [diff] [blame] | 501 | |
Mika Kuoppala | 567047b | 2015-06-25 18:35:12 +0300 | [diff] [blame] | 502 | ret = setup_px(dev, pd); |
Michel Thierry | 33c8819 | 2015-04-08 12:13:33 +0100 | [diff] [blame] | 503 | if (ret) |
Mika Kuoppala | a08e111 | 2015-06-25 18:35:08 +0300 | [diff] [blame] | 504 | goto fail_page_m; |
Michel Thierry | e5815a2 | 2015-04-08 12:13:32 +0100 | [diff] [blame] | 505 | |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 506 | return pd; |
Michel Thierry | 33c8819 | 2015-04-08 12:13:33 +0100 | [diff] [blame] | 507 | |
Mika Kuoppala | a08e111 | 2015-06-25 18:35:08 +0300 | [diff] [blame] | 508 | fail_page_m: |
Michel Thierry | 33c8819 | 2015-04-08 12:13:33 +0100 | [diff] [blame] | 509 | kfree(pd->used_pdes); |
Mika Kuoppala | a08e111 | 2015-06-25 18:35:08 +0300 | [diff] [blame] | 510 | fail_bitmap: |
Michel Thierry | 33c8819 | 2015-04-08 12:13:33 +0100 | [diff] [blame] | 511 | kfree(pd); |
| 512 | |
| 513 | return ERR_PTR(ret); |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Mika Kuoppala | 2e906be | 2015-06-30 18:16:37 +0300 | [diff] [blame] | 516 | static void free_pd(struct drm_device *dev, struct i915_page_directory *pd) |
| 517 | { |
| 518 | if (px_page(pd)) { |
| 519 | cleanup_px(dev, pd); |
| 520 | kfree(pd->used_pdes); |
| 521 | kfree(pd); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | static void gen8_initialize_pd(struct i915_address_space *vm, |
| 526 | struct i915_page_directory *pd) |
| 527 | { |
| 528 | gen8_pde_t scratch_pde; |
| 529 | |
| 530 | scratch_pde = gen8_pde_encode(px_dma(vm->scratch_pt), I915_CACHE_LLC); |
| 531 | |
| 532 | fill_px(vm->dev, pd, scratch_pde); |
| 533 | } |
| 534 | |
Michel Thierry | 6ac1850 | 2015-07-29 17:23:46 +0100 | [diff] [blame] | 535 | static int __pdp_init(struct drm_device *dev, |
| 536 | struct i915_page_directory_pointer *pdp) |
| 537 | { |
| 538 | size_t pdpes = I915_PDPES_PER_PDP(dev); |
| 539 | |
| 540 | pdp->used_pdpes = kcalloc(BITS_TO_LONGS(pdpes), |
| 541 | sizeof(unsigned long), |
| 542 | GFP_KERNEL); |
| 543 | if (!pdp->used_pdpes) |
| 544 | return -ENOMEM; |
| 545 | |
| 546 | pdp->page_directory = kcalloc(pdpes, sizeof(*pdp->page_directory), |
| 547 | GFP_KERNEL); |
| 548 | if (!pdp->page_directory) { |
| 549 | kfree(pdp->used_pdpes); |
| 550 | /* the PDP might be the statically allocated top level. Keep it |
| 551 | * as clean as possible */ |
| 552 | pdp->used_pdpes = NULL; |
| 553 | return -ENOMEM; |
| 554 | } |
| 555 | |
| 556 | return 0; |
| 557 | } |
| 558 | |
| 559 | static void __pdp_fini(struct i915_page_directory_pointer *pdp) |
| 560 | { |
| 561 | kfree(pdp->used_pdpes); |
| 562 | kfree(pdp->page_directory); |
| 563 | pdp->page_directory = NULL; |
| 564 | } |
| 565 | |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 566 | static struct |
| 567 | i915_page_directory_pointer *alloc_pdp(struct drm_device *dev) |
| 568 | { |
| 569 | struct i915_page_directory_pointer *pdp; |
| 570 | int ret = -ENOMEM; |
| 571 | |
| 572 | WARN_ON(!USES_FULL_48BIT_PPGTT(dev)); |
| 573 | |
| 574 | pdp = kzalloc(sizeof(*pdp), GFP_KERNEL); |
| 575 | if (!pdp) |
| 576 | return ERR_PTR(-ENOMEM); |
| 577 | |
| 578 | ret = __pdp_init(dev, pdp); |
| 579 | if (ret) |
| 580 | goto fail_bitmap; |
| 581 | |
| 582 | ret = setup_px(dev, pdp); |
| 583 | if (ret) |
| 584 | goto fail_page_m; |
| 585 | |
| 586 | return pdp; |
| 587 | |
| 588 | fail_page_m: |
| 589 | __pdp_fini(pdp); |
| 590 | fail_bitmap: |
| 591 | kfree(pdp); |
| 592 | |
| 593 | return ERR_PTR(ret); |
| 594 | } |
| 595 | |
Michel Thierry | 6ac1850 | 2015-07-29 17:23:46 +0100 | [diff] [blame] | 596 | static void free_pdp(struct drm_device *dev, |
| 597 | struct i915_page_directory_pointer *pdp) |
| 598 | { |
| 599 | __pdp_fini(pdp); |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 600 | if (USES_FULL_48BIT_PPGTT(dev)) { |
| 601 | cleanup_px(dev, pdp); |
| 602 | kfree(pdp); |
| 603 | } |
| 604 | } |
| 605 | |
Michel Thierry | 69ab76f | 2015-07-29 17:23:55 +0100 | [diff] [blame] | 606 | static void gen8_initialize_pdp(struct i915_address_space *vm, |
| 607 | struct i915_page_directory_pointer *pdp) |
| 608 | { |
| 609 | gen8_ppgtt_pdpe_t scratch_pdpe; |
| 610 | |
| 611 | scratch_pdpe = gen8_pdpe_encode(px_dma(vm->scratch_pd), I915_CACHE_LLC); |
| 612 | |
| 613 | fill_px(vm->dev, pdp, scratch_pdpe); |
| 614 | } |
| 615 | |
| 616 | static void gen8_initialize_pml4(struct i915_address_space *vm, |
| 617 | struct i915_pml4 *pml4) |
| 618 | { |
| 619 | gen8_ppgtt_pml4e_t scratch_pml4e; |
| 620 | |
| 621 | scratch_pml4e = gen8_pml4e_encode(px_dma(vm->scratch_pdp), |
| 622 | I915_CACHE_LLC); |
| 623 | |
| 624 | fill_px(vm->dev, pml4, scratch_pml4e); |
| 625 | } |
| 626 | |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 627 | static void |
| 628 | gen8_setup_page_directory(struct i915_hw_ppgtt *ppgtt, |
| 629 | struct i915_page_directory_pointer *pdp, |
| 630 | struct i915_page_directory *pd, |
| 631 | int index) |
| 632 | { |
| 633 | gen8_ppgtt_pdpe_t *page_directorypo; |
| 634 | |
| 635 | if (!USES_FULL_48BIT_PPGTT(ppgtt->base.dev)) |
| 636 | return; |
| 637 | |
| 638 | page_directorypo = kmap_px(pdp); |
| 639 | page_directorypo[index] = gen8_pdpe_encode(px_dma(pd), I915_CACHE_LLC); |
| 640 | kunmap_px(ppgtt, page_directorypo); |
| 641 | } |
| 642 | |
| 643 | static void |
| 644 | gen8_setup_page_directory_pointer(struct i915_hw_ppgtt *ppgtt, |
| 645 | struct i915_pml4 *pml4, |
| 646 | struct i915_page_directory_pointer *pdp, |
| 647 | int index) |
| 648 | { |
| 649 | gen8_ppgtt_pml4e_t *pagemap = kmap_px(pml4); |
| 650 | |
| 651 | WARN_ON(!USES_FULL_48BIT_PPGTT(ppgtt->base.dev)); |
| 652 | pagemap[index] = gen8_pml4e_encode(px_dma(pdp), I915_CACHE_LLC); |
| 653 | kunmap_px(ppgtt, pagemap); |
Michel Thierry | 6ac1850 | 2015-07-29 17:23:46 +0100 | [diff] [blame] | 654 | } |
| 655 | |
Ben Widawsky | 94e409c | 2013-11-04 22:29:36 -0800 | [diff] [blame] | 656 | /* Broadwell Page Directory Pointer Descriptors */ |
John Harrison | e85b26d | 2015-05-29 17:43:56 +0100 | [diff] [blame] | 657 | static int gen8_write_pdp(struct drm_i915_gem_request *req, |
Michel Thierry | 7cb6d7a | 2015-04-08 12:13:29 +0100 | [diff] [blame] | 658 | unsigned entry, |
| 659 | dma_addr_t addr) |
Ben Widawsky | 94e409c | 2013-11-04 22:29:36 -0800 | [diff] [blame] | 660 | { |
John Harrison | e85b26d | 2015-05-29 17:43:56 +0100 | [diff] [blame] | 661 | struct intel_engine_cs *ring = req->ring; |
Ben Widawsky | 94e409c | 2013-11-04 22:29:36 -0800 | [diff] [blame] | 662 | int ret; |
| 663 | |
| 664 | BUG_ON(entry >= 4); |
| 665 | |
John Harrison | 5fb9de1 | 2015-05-29 17:44:07 +0100 | [diff] [blame] | 666 | ret = intel_ring_begin(req, 6); |
Ben Widawsky | 94e409c | 2013-11-04 22:29:36 -0800 | [diff] [blame] | 667 | if (ret) |
| 668 | return ret; |
| 669 | |
| 670 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); |
Ville Syrjälä | f92a916 | 2015-11-04 23:20:07 +0200 | [diff] [blame] | 671 | intel_ring_emit_reg(ring, GEN8_RING_PDP_UDW(ring, entry)); |
Michel Thierry | 7cb6d7a | 2015-04-08 12:13:29 +0100 | [diff] [blame] | 672 | intel_ring_emit(ring, upper_32_bits(addr)); |
Ben Widawsky | 94e409c | 2013-11-04 22:29:36 -0800 | [diff] [blame] | 673 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); |
Ville Syrjälä | f92a916 | 2015-11-04 23:20:07 +0200 | [diff] [blame] | 674 | intel_ring_emit_reg(ring, GEN8_RING_PDP_LDW(ring, entry)); |
Michel Thierry | 7cb6d7a | 2015-04-08 12:13:29 +0100 | [diff] [blame] | 675 | intel_ring_emit(ring, lower_32_bits(addr)); |
Ben Widawsky | 94e409c | 2013-11-04 22:29:36 -0800 | [diff] [blame] | 676 | intel_ring_advance(ring); |
| 677 | |
| 678 | return 0; |
| 679 | } |
| 680 | |
Michel Thierry | 2dba323 | 2015-07-30 11:06:23 +0100 | [diff] [blame] | 681 | static int gen8_legacy_mm_switch(struct i915_hw_ppgtt *ppgtt, |
| 682 | struct drm_i915_gem_request *req) |
Ben Widawsky | 94e409c | 2013-11-04 22:29:36 -0800 | [diff] [blame] | 683 | { |
Ben Widawsky | eeb9488 | 2013-12-06 14:11:10 -0800 | [diff] [blame] | 684 | int i, ret; |
Ben Widawsky | 94e409c | 2013-11-04 22:29:36 -0800 | [diff] [blame] | 685 | |
Michel Thierry | 7cb6d7a | 2015-04-08 12:13:29 +0100 | [diff] [blame] | 686 | for (i = GEN8_LEGACY_PDPES - 1; i >= 0; i--) { |
Mika Kuoppala | d852c7b | 2015-06-25 18:35:06 +0300 | [diff] [blame] | 687 | const dma_addr_t pd_daddr = i915_page_dir_dma_addr(ppgtt, i); |
| 688 | |
John Harrison | e85b26d | 2015-05-29 17:43:56 +0100 | [diff] [blame] | 689 | ret = gen8_write_pdp(req, i, pd_daddr); |
Ben Widawsky | eeb9488 | 2013-12-06 14:11:10 -0800 | [diff] [blame] | 690 | if (ret) |
| 691 | return ret; |
Ben Widawsky | 94e409c | 2013-11-04 22:29:36 -0800 | [diff] [blame] | 692 | } |
Ben Widawsky | d595bd4 | 2013-11-25 09:54:32 -0800 | [diff] [blame] | 693 | |
Ben Widawsky | eeb9488 | 2013-12-06 14:11:10 -0800 | [diff] [blame] | 694 | return 0; |
Ben Widawsky | 94e409c | 2013-11-04 22:29:36 -0800 | [diff] [blame] | 695 | } |
| 696 | |
Michel Thierry | 2dba323 | 2015-07-30 11:06:23 +0100 | [diff] [blame] | 697 | static int gen8_48b_mm_switch(struct i915_hw_ppgtt *ppgtt, |
| 698 | struct drm_i915_gem_request *req) |
| 699 | { |
| 700 | return gen8_write_pdp(req, 0, px_dma(&ppgtt->pml4)); |
| 701 | } |
| 702 | |
Michel Thierry | f9b5b78 | 2015-07-30 11:02:49 +0100 | [diff] [blame] | 703 | static void gen8_ppgtt_clear_pte_range(struct i915_address_space *vm, |
| 704 | struct i915_page_directory_pointer *pdp, |
| 705 | uint64_t start, |
| 706 | uint64_t length, |
| 707 | gen8_pte_t scratch_pte) |
Ben Widawsky | 459108b | 2013-11-02 21:07:23 -0700 | [diff] [blame] | 708 | { |
| 709 | struct i915_hw_ppgtt *ppgtt = |
| 710 | container_of(vm, struct i915_hw_ppgtt, base); |
Michel Thierry | f9b5b78 | 2015-07-30 11:02:49 +0100 | [diff] [blame] | 711 | gen8_pte_t *pt_vaddr; |
Michel Thierry | de5ba8e | 2015-08-03 09:53:27 +0100 | [diff] [blame] | 712 | unsigned pdpe = gen8_pdpe_index(start); |
| 713 | unsigned pde = gen8_pde_index(start); |
| 714 | unsigned pte = gen8_pte_index(start); |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 715 | unsigned num_entries = length >> PAGE_SHIFT; |
Ben Widawsky | 459108b | 2013-11-02 21:07:23 -0700 | [diff] [blame] | 716 | unsigned last_pte, i; |
| 717 | |
Michel Thierry | f9b5b78 | 2015-07-30 11:02:49 +0100 | [diff] [blame] | 718 | if (WARN_ON(!pdp)) |
| 719 | return; |
Ben Widawsky | 459108b | 2013-11-02 21:07:23 -0700 | [diff] [blame] | 720 | |
| 721 | while (num_entries) { |
Michel Thierry | ec565b3 | 2015-04-08 12:13:23 +0100 | [diff] [blame] | 722 | struct i915_page_directory *pd; |
| 723 | struct i915_page_table *pt; |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 724 | |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 725 | if (WARN_ON(!pdp->page_directory[pdpe])) |
Michel Thierry | 0024526 | 2015-06-25 12:59:38 +0100 | [diff] [blame] | 726 | break; |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 727 | |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 728 | pd = pdp->page_directory[pdpe]; |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 729 | |
| 730 | if (WARN_ON(!pd->page_table[pde])) |
Michel Thierry | 0024526 | 2015-06-25 12:59:38 +0100 | [diff] [blame] | 731 | break; |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 732 | |
| 733 | pt = pd->page_table[pde]; |
| 734 | |
Mika Kuoppala | 567047b | 2015-06-25 18:35:12 +0300 | [diff] [blame] | 735 | if (WARN_ON(!px_page(pt))) |
Michel Thierry | 0024526 | 2015-06-25 12:59:38 +0100 | [diff] [blame] | 736 | break; |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 737 | |
Ben Widawsky | 7ad47cf | 2014-02-20 11:51:21 -0800 | [diff] [blame] | 738 | last_pte = pte + num_entries; |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 739 | if (last_pte > GEN8_PTES) |
| 740 | last_pte = GEN8_PTES; |
Ben Widawsky | 459108b | 2013-11-02 21:07:23 -0700 | [diff] [blame] | 741 | |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 742 | pt_vaddr = kmap_px(pt); |
Ben Widawsky | 459108b | 2013-11-02 21:07:23 -0700 | [diff] [blame] | 743 | |
Ben Widawsky | 7ad47cf | 2014-02-20 11:51:21 -0800 | [diff] [blame] | 744 | for (i = pte; i < last_pte; i++) { |
Ben Widawsky | 459108b | 2013-11-02 21:07:23 -0700 | [diff] [blame] | 745 | pt_vaddr[i] = scratch_pte; |
Ben Widawsky | 7ad47cf | 2014-02-20 11:51:21 -0800 | [diff] [blame] | 746 | num_entries--; |
| 747 | } |
Ben Widawsky | 459108b | 2013-11-02 21:07:23 -0700 | [diff] [blame] | 748 | |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 749 | kunmap_px(ppgtt, pt); |
Ben Widawsky | 459108b | 2013-11-02 21:07:23 -0700 | [diff] [blame] | 750 | |
Ben Widawsky | 7ad47cf | 2014-02-20 11:51:21 -0800 | [diff] [blame] | 751 | pte = 0; |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 752 | if (++pde == I915_PDES) { |
Michel Thierry | de5ba8e | 2015-08-03 09:53:27 +0100 | [diff] [blame] | 753 | if (++pdpe == I915_PDPES_PER_PDP(vm->dev)) |
| 754 | break; |
Ben Widawsky | 7ad47cf | 2014-02-20 11:51:21 -0800 | [diff] [blame] | 755 | pde = 0; |
| 756 | } |
Ben Widawsky | 459108b | 2013-11-02 21:07:23 -0700 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | |
Michel Thierry | f9b5b78 | 2015-07-30 11:02:49 +0100 | [diff] [blame] | 760 | static void gen8_ppgtt_clear_range(struct i915_address_space *vm, |
| 761 | uint64_t start, |
| 762 | uint64_t length, |
| 763 | bool use_scratch) |
Ben Widawsky | 9df15b4 | 2013-11-02 21:07:24 -0700 | [diff] [blame] | 764 | { |
| 765 | struct i915_hw_ppgtt *ppgtt = |
| 766 | container_of(vm, struct i915_hw_ppgtt, base); |
Michel Thierry | f9b5b78 | 2015-07-30 11:02:49 +0100 | [diff] [blame] | 767 | gen8_pte_t scratch_pte = gen8_pte_encode(px_dma(vm->scratch_page), |
| 768 | I915_CACHE_LLC, use_scratch); |
| 769 | |
Michel Thierry | de5ba8e | 2015-08-03 09:53:27 +0100 | [diff] [blame] | 770 | if (!USES_FULL_48BIT_PPGTT(vm->dev)) { |
| 771 | gen8_ppgtt_clear_pte_range(vm, &ppgtt->pdp, start, length, |
| 772 | scratch_pte); |
| 773 | } else { |
Dave Gordon | e8ebd8e | 2015-12-08 13:30:51 +0000 | [diff] [blame] | 774 | uint64_t pml4e; |
Michel Thierry | de5ba8e | 2015-08-03 09:53:27 +0100 | [diff] [blame] | 775 | struct i915_page_directory_pointer *pdp; |
| 776 | |
Dave Gordon | e8ebd8e | 2015-12-08 13:30:51 +0000 | [diff] [blame] | 777 | gen8_for_each_pml4e(pdp, &ppgtt->pml4, start, length, pml4e) { |
Michel Thierry | de5ba8e | 2015-08-03 09:53:27 +0100 | [diff] [blame] | 778 | gen8_ppgtt_clear_pte_range(vm, pdp, start, length, |
| 779 | scratch_pte); |
| 780 | } |
| 781 | } |
Michel Thierry | f9b5b78 | 2015-07-30 11:02:49 +0100 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | static void |
| 785 | gen8_ppgtt_insert_pte_entries(struct i915_address_space *vm, |
| 786 | struct i915_page_directory_pointer *pdp, |
Michel Thierry | 3387d43 | 2015-08-03 09:52:47 +0100 | [diff] [blame] | 787 | struct sg_page_iter *sg_iter, |
Michel Thierry | f9b5b78 | 2015-07-30 11:02:49 +0100 | [diff] [blame] | 788 | uint64_t start, |
| 789 | enum i915_cache_level cache_level) |
| 790 | { |
| 791 | struct i915_hw_ppgtt *ppgtt = |
| 792 | container_of(vm, struct i915_hw_ppgtt, base); |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 793 | gen8_pte_t *pt_vaddr; |
Michel Thierry | de5ba8e | 2015-08-03 09:53:27 +0100 | [diff] [blame] | 794 | unsigned pdpe = gen8_pdpe_index(start); |
| 795 | unsigned pde = gen8_pde_index(start); |
| 796 | unsigned pte = gen8_pte_index(start); |
Ben Widawsky | 9df15b4 | 2013-11-02 21:07:24 -0700 | [diff] [blame] | 797 | |
Chris Wilson | 6f1cc99 | 2013-12-31 15:50:31 +0000 | [diff] [blame] | 798 | pt_vaddr = NULL; |
Ben Widawsky | 9df15b4 | 2013-11-02 21:07:24 -0700 | [diff] [blame] | 799 | |
Michel Thierry | 3387d43 | 2015-08-03 09:52:47 +0100 | [diff] [blame] | 800 | while (__sg_page_iter_next(sg_iter)) { |
Ben Widawsky | d7b3de9 | 2015-02-24 16:22:34 +0000 | [diff] [blame] | 801 | if (pt_vaddr == NULL) { |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 802 | struct i915_page_directory *pd = pdp->page_directory[pdpe]; |
Michel Thierry | ec565b3 | 2015-04-08 12:13:23 +0100 | [diff] [blame] | 803 | struct i915_page_table *pt = pd->page_table[pde]; |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 804 | pt_vaddr = kmap_px(pt); |
Ben Widawsky | d7b3de9 | 2015-02-24 16:22:34 +0000 | [diff] [blame] | 805 | } |
Ben Widawsky | 7ad47cf | 2014-02-20 11:51:21 -0800 | [diff] [blame] | 806 | |
| 807 | pt_vaddr[pte] = |
Michel Thierry | 3387d43 | 2015-08-03 09:52:47 +0100 | [diff] [blame] | 808 | gen8_pte_encode(sg_page_iter_dma_address(sg_iter), |
Chris Wilson | 6f1cc99 | 2013-12-31 15:50:31 +0000 | [diff] [blame] | 809 | cache_level, true); |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 810 | if (++pte == GEN8_PTES) { |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 811 | kunmap_px(ppgtt, pt_vaddr); |
Chris Wilson | 6f1cc99 | 2013-12-31 15:50:31 +0000 | [diff] [blame] | 812 | pt_vaddr = NULL; |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 813 | if (++pde == I915_PDES) { |
Michel Thierry | de5ba8e | 2015-08-03 09:53:27 +0100 | [diff] [blame] | 814 | if (++pdpe == I915_PDPES_PER_PDP(vm->dev)) |
| 815 | break; |
Ben Widawsky | 7ad47cf | 2014-02-20 11:51:21 -0800 | [diff] [blame] | 816 | pde = 0; |
| 817 | } |
| 818 | pte = 0; |
Ben Widawsky | 9df15b4 | 2013-11-02 21:07:24 -0700 | [diff] [blame] | 819 | } |
| 820 | } |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 821 | |
| 822 | if (pt_vaddr) |
| 823 | kunmap_px(ppgtt, pt_vaddr); |
Ben Widawsky | 9df15b4 | 2013-11-02 21:07:24 -0700 | [diff] [blame] | 824 | } |
| 825 | |
Michel Thierry | f9b5b78 | 2015-07-30 11:02:49 +0100 | [diff] [blame] | 826 | static void gen8_ppgtt_insert_entries(struct i915_address_space *vm, |
| 827 | struct sg_table *pages, |
| 828 | uint64_t start, |
| 829 | enum i915_cache_level cache_level, |
| 830 | u32 unused) |
| 831 | { |
| 832 | struct i915_hw_ppgtt *ppgtt = |
| 833 | container_of(vm, struct i915_hw_ppgtt, base); |
Michel Thierry | 3387d43 | 2015-08-03 09:52:47 +0100 | [diff] [blame] | 834 | struct sg_page_iter sg_iter; |
Michel Thierry | f9b5b78 | 2015-07-30 11:02:49 +0100 | [diff] [blame] | 835 | |
Michel Thierry | 3387d43 | 2015-08-03 09:52:47 +0100 | [diff] [blame] | 836 | __sg_page_iter_start(&sg_iter, pages->sgl, sg_nents(pages->sgl), 0); |
Michel Thierry | de5ba8e | 2015-08-03 09:53:27 +0100 | [diff] [blame] | 837 | |
| 838 | if (!USES_FULL_48BIT_PPGTT(vm->dev)) { |
| 839 | gen8_ppgtt_insert_pte_entries(vm, &ppgtt->pdp, &sg_iter, start, |
| 840 | cache_level); |
| 841 | } else { |
| 842 | struct i915_page_directory_pointer *pdp; |
Dave Gordon | e8ebd8e | 2015-12-08 13:30:51 +0000 | [diff] [blame] | 843 | uint64_t pml4e; |
Michel Thierry | de5ba8e | 2015-08-03 09:53:27 +0100 | [diff] [blame] | 844 | uint64_t length = (uint64_t)pages->orig_nents << PAGE_SHIFT; |
| 845 | |
Dave Gordon | e8ebd8e | 2015-12-08 13:30:51 +0000 | [diff] [blame] | 846 | gen8_for_each_pml4e(pdp, &ppgtt->pml4, start, length, pml4e) { |
Michel Thierry | de5ba8e | 2015-08-03 09:53:27 +0100 | [diff] [blame] | 847 | gen8_ppgtt_insert_pte_entries(vm, pdp, &sg_iter, |
| 848 | start, cache_level); |
| 849 | } |
| 850 | } |
Michel Thierry | f9b5b78 | 2015-07-30 11:02:49 +0100 | [diff] [blame] | 851 | } |
| 852 | |
Michel Thierry | f37c050 | 2015-06-10 17:46:39 +0100 | [diff] [blame] | 853 | static void gen8_free_page_tables(struct drm_device *dev, |
| 854 | struct i915_page_directory *pd) |
Ben Widawsky | b45a671 | 2014-02-12 14:28:44 -0800 | [diff] [blame] | 855 | { |
| 856 | int i; |
| 857 | |
Mika Kuoppala | 567047b | 2015-06-25 18:35:12 +0300 | [diff] [blame] | 858 | if (!px_page(pd)) |
Ben Widawsky | 7ad47cf | 2014-02-20 11:51:21 -0800 | [diff] [blame] | 859 | return; |
Ben Widawsky | b45a671 | 2014-02-12 14:28:44 -0800 | [diff] [blame] | 860 | |
Michel Thierry | 33c8819 | 2015-04-08 12:13:33 +0100 | [diff] [blame] | 861 | for_each_set_bit(i, pd->used_pdes, I915_PDES) { |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 862 | if (WARN_ON(!pd->page_table[i])) |
| 863 | continue; |
Ben Widawsky | 7ad47cf | 2014-02-20 11:51:21 -0800 | [diff] [blame] | 864 | |
Mika Kuoppala | a08e111 | 2015-06-25 18:35:08 +0300 | [diff] [blame] | 865 | free_pt(dev, pd->page_table[i]); |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 866 | pd->page_table[i] = NULL; |
| 867 | } |
Ben Widawsky | d7b3de9 | 2015-02-24 16:22:34 +0000 | [diff] [blame] | 868 | } |
| 869 | |
Mika Kuoppala | 8776f02 | 2015-06-30 18:16:40 +0300 | [diff] [blame] | 870 | static int gen8_init_scratch(struct i915_address_space *vm) |
| 871 | { |
| 872 | struct drm_device *dev = vm->dev; |
| 873 | |
| 874 | vm->scratch_page = alloc_scratch_page(dev); |
| 875 | if (IS_ERR(vm->scratch_page)) |
| 876 | return PTR_ERR(vm->scratch_page); |
| 877 | |
| 878 | vm->scratch_pt = alloc_pt(dev); |
| 879 | if (IS_ERR(vm->scratch_pt)) { |
| 880 | free_scratch_page(dev, vm->scratch_page); |
| 881 | return PTR_ERR(vm->scratch_pt); |
| 882 | } |
| 883 | |
| 884 | vm->scratch_pd = alloc_pd(dev); |
| 885 | if (IS_ERR(vm->scratch_pd)) { |
| 886 | free_pt(dev, vm->scratch_pt); |
| 887 | free_scratch_page(dev, vm->scratch_page); |
| 888 | return PTR_ERR(vm->scratch_pd); |
| 889 | } |
| 890 | |
Michel Thierry | 69ab76f | 2015-07-29 17:23:55 +0100 | [diff] [blame] | 891 | if (USES_FULL_48BIT_PPGTT(dev)) { |
| 892 | vm->scratch_pdp = alloc_pdp(dev); |
| 893 | if (IS_ERR(vm->scratch_pdp)) { |
| 894 | free_pd(dev, vm->scratch_pd); |
| 895 | free_pt(dev, vm->scratch_pt); |
| 896 | free_scratch_page(dev, vm->scratch_page); |
| 897 | return PTR_ERR(vm->scratch_pdp); |
| 898 | } |
| 899 | } |
| 900 | |
Mika Kuoppala | 8776f02 | 2015-06-30 18:16:40 +0300 | [diff] [blame] | 901 | gen8_initialize_pt(vm, vm->scratch_pt); |
| 902 | gen8_initialize_pd(vm, vm->scratch_pd); |
Michel Thierry | 69ab76f | 2015-07-29 17:23:55 +0100 | [diff] [blame] | 903 | if (USES_FULL_48BIT_PPGTT(dev)) |
| 904 | gen8_initialize_pdp(vm, vm->scratch_pdp); |
Mika Kuoppala | 8776f02 | 2015-06-30 18:16:40 +0300 | [diff] [blame] | 905 | |
| 906 | return 0; |
| 907 | } |
| 908 | |
Zhiyuan Lv | 650da34 | 2015-08-28 15:41:18 +0800 | [diff] [blame] | 909 | static int gen8_ppgtt_notify_vgt(struct i915_hw_ppgtt *ppgtt, bool create) |
| 910 | { |
| 911 | enum vgt_g2v_type msg; |
| 912 | struct drm_device *dev = ppgtt->base.dev; |
| 913 | struct drm_i915_private *dev_priv = dev->dev_private; |
Zhiyuan Lv | 650da34 | 2015-08-28 15:41:18 +0800 | [diff] [blame] | 914 | int i; |
| 915 | |
| 916 | if (USES_FULL_48BIT_PPGTT(dev)) { |
| 917 | u64 daddr = px_dma(&ppgtt->pml4); |
| 918 | |
Ville Syrjälä | ab75bb5 | 2015-11-04 23:20:12 +0200 | [diff] [blame] | 919 | I915_WRITE(vgtif_reg(pdp[0].lo), lower_32_bits(daddr)); |
| 920 | I915_WRITE(vgtif_reg(pdp[0].hi), upper_32_bits(daddr)); |
Zhiyuan Lv | 650da34 | 2015-08-28 15:41:18 +0800 | [diff] [blame] | 921 | |
| 922 | msg = (create ? VGT_G2V_PPGTT_L4_PAGE_TABLE_CREATE : |
| 923 | VGT_G2V_PPGTT_L4_PAGE_TABLE_DESTROY); |
| 924 | } else { |
| 925 | for (i = 0; i < GEN8_LEGACY_PDPES; i++) { |
| 926 | u64 daddr = i915_page_dir_dma_addr(ppgtt, i); |
| 927 | |
Ville Syrjälä | ab75bb5 | 2015-11-04 23:20:12 +0200 | [diff] [blame] | 928 | I915_WRITE(vgtif_reg(pdp[i].lo), lower_32_bits(daddr)); |
| 929 | I915_WRITE(vgtif_reg(pdp[i].hi), upper_32_bits(daddr)); |
Zhiyuan Lv | 650da34 | 2015-08-28 15:41:18 +0800 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | msg = (create ? VGT_G2V_PPGTT_L3_PAGE_TABLE_CREATE : |
| 933 | VGT_G2V_PPGTT_L3_PAGE_TABLE_DESTROY); |
| 934 | } |
| 935 | |
| 936 | I915_WRITE(vgtif_reg(g2v_notify), msg); |
| 937 | |
| 938 | return 0; |
| 939 | } |
| 940 | |
Mika Kuoppala | 8776f02 | 2015-06-30 18:16:40 +0300 | [diff] [blame] | 941 | static void gen8_free_scratch(struct i915_address_space *vm) |
| 942 | { |
| 943 | struct drm_device *dev = vm->dev; |
| 944 | |
Michel Thierry | 69ab76f | 2015-07-29 17:23:55 +0100 | [diff] [blame] | 945 | if (USES_FULL_48BIT_PPGTT(dev)) |
| 946 | free_pdp(dev, vm->scratch_pdp); |
Mika Kuoppala | 8776f02 | 2015-06-30 18:16:40 +0300 | [diff] [blame] | 947 | free_pd(dev, vm->scratch_pd); |
| 948 | free_pt(dev, vm->scratch_pt); |
| 949 | free_scratch_page(dev, vm->scratch_page); |
| 950 | } |
| 951 | |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 952 | static void gen8_ppgtt_cleanup_3lvl(struct drm_device *dev, |
| 953 | struct i915_page_directory_pointer *pdp) |
Ben Widawsky | 7ad47cf | 2014-02-20 11:51:21 -0800 | [diff] [blame] | 954 | { |
| 955 | int i; |
| 956 | |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 957 | for_each_set_bit(i, pdp->used_pdpes, I915_PDPES_PER_PDP(dev)) { |
| 958 | if (WARN_ON(!pdp->page_directory[i])) |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 959 | continue; |
| 960 | |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 961 | gen8_free_page_tables(dev, pdp->page_directory[i]); |
| 962 | free_pd(dev, pdp->page_directory[i]); |
Ben Widawsky | 7ad47cf | 2014-02-20 11:51:21 -0800 | [diff] [blame] | 963 | } |
Michel Thierry | 69876be | 2015-04-08 12:13:27 +0100 | [diff] [blame] | 964 | |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 965 | free_pdp(dev, pdp); |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | static void gen8_ppgtt_cleanup_4lvl(struct i915_hw_ppgtt *ppgtt) |
| 969 | { |
| 970 | int i; |
| 971 | |
| 972 | for_each_set_bit(i, ppgtt->pml4.used_pml4es, GEN8_PML4ES_PER_PML4) { |
| 973 | if (WARN_ON(!ppgtt->pml4.pdps[i])) |
| 974 | continue; |
| 975 | |
| 976 | gen8_ppgtt_cleanup_3lvl(ppgtt->base.dev, ppgtt->pml4.pdps[i]); |
| 977 | } |
| 978 | |
| 979 | cleanup_px(ppgtt->base.dev, &ppgtt->pml4); |
| 980 | } |
| 981 | |
| 982 | static void gen8_ppgtt_cleanup(struct i915_address_space *vm) |
| 983 | { |
| 984 | struct i915_hw_ppgtt *ppgtt = |
| 985 | container_of(vm, struct i915_hw_ppgtt, base); |
| 986 | |
Zhiyuan Lv | 650da34 | 2015-08-28 15:41:18 +0800 | [diff] [blame] | 987 | if (intel_vgpu_active(vm->dev)) |
| 988 | gen8_ppgtt_notify_vgt(ppgtt, false); |
| 989 | |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 990 | if (!USES_FULL_48BIT_PPGTT(ppgtt->base.dev)) |
| 991 | gen8_ppgtt_cleanup_3lvl(ppgtt->base.dev, &ppgtt->pdp); |
| 992 | else |
| 993 | gen8_ppgtt_cleanup_4lvl(ppgtt); |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 994 | |
Mika Kuoppala | 8776f02 | 2015-06-30 18:16:40 +0300 | [diff] [blame] | 995 | gen8_free_scratch(vm); |
Ben Widawsky | b45a671 | 2014-02-12 14:28:44 -0800 | [diff] [blame] | 996 | } |
| 997 | |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 998 | /** |
| 999 | * gen8_ppgtt_alloc_pagetabs() - Allocate page tables for VA range. |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1000 | * @vm: Master vm structure. |
| 1001 | * @pd: Page directory for this address range. |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1002 | * @start: Starting virtual address to begin allocations. |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1003 | * @length: Size of the allocations. |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1004 | * @new_pts: Bitmap set by function with new allocations. Likely used by the |
| 1005 | * caller to free on error. |
| 1006 | * |
| 1007 | * Allocate the required number of page tables. Extremely similar to |
| 1008 | * gen8_ppgtt_alloc_page_directories(). The main difference is here we are limited by |
| 1009 | * the page directory boundary (instead of the page directory pointer). That |
| 1010 | * boundary is 1GB virtual. Therefore, unlike gen8_ppgtt_alloc_page_directories(), it is |
| 1011 | * possible, and likely that the caller will need to use multiple calls of this |
| 1012 | * function to achieve the appropriate allocation. |
| 1013 | * |
| 1014 | * Return: 0 if success; negative error code otherwise. |
| 1015 | */ |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1016 | static int gen8_ppgtt_alloc_pagetabs(struct i915_address_space *vm, |
Michel Thierry | e5815a2 | 2015-04-08 12:13:32 +0100 | [diff] [blame] | 1017 | struct i915_page_directory *pd, |
Michel Thierry | 5441f0c | 2015-04-08 12:13:28 +0100 | [diff] [blame] | 1018 | uint64_t start, |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1019 | uint64_t length, |
| 1020 | unsigned long *new_pts) |
Ben Widawsky | d7b3de9 | 2015-02-24 16:22:34 +0000 | [diff] [blame] | 1021 | { |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1022 | struct drm_device *dev = vm->dev; |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1023 | struct i915_page_table *pt; |
Michel Thierry | 5441f0c | 2015-04-08 12:13:28 +0100 | [diff] [blame] | 1024 | uint32_t pde; |
Ben Widawsky | d7b3de9 | 2015-02-24 16:22:34 +0000 | [diff] [blame] | 1025 | |
Dave Gordon | e8ebd8e | 2015-12-08 13:30:51 +0000 | [diff] [blame] | 1026 | gen8_for_each_pde(pt, pd, start, length, pde) { |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1027 | /* Don't reallocate page tables */ |
Michel Thierry | 6ac1850 | 2015-07-29 17:23:46 +0100 | [diff] [blame] | 1028 | if (test_bit(pde, pd->used_pdes)) { |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1029 | /* Scratch is never allocated this way */ |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1030 | WARN_ON(pt == vm->scratch_pt); |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1031 | continue; |
| 1032 | } |
| 1033 | |
Mika Kuoppala | 8a1ebd7 | 2015-05-22 20:04:59 +0300 | [diff] [blame] | 1034 | pt = alloc_pt(dev); |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1035 | if (IS_ERR(pt)) |
Ben Widawsky | 06fda60 | 2015-02-24 16:22:36 +0000 | [diff] [blame] | 1036 | goto unwind_out; |
Michel Thierry | 5441f0c | 2015-04-08 12:13:28 +0100 | [diff] [blame] | 1037 | |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1038 | gen8_initialize_pt(vm, pt); |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1039 | pd->page_table[pde] = pt; |
Mika Kuoppala | 966082c | 2015-06-25 18:35:19 +0300 | [diff] [blame] | 1040 | __set_bit(pde, new_pts); |
Michel Thierry | 4c06ec8 | 2015-07-29 17:23:49 +0100 | [diff] [blame] | 1041 | trace_i915_page_table_entry_alloc(vm, pde, start, GEN8_PDE_SHIFT); |
Ben Widawsky | d7b3de9 | 2015-02-24 16:22:34 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | return 0; |
| 1045 | |
| 1046 | unwind_out: |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1047 | for_each_set_bit(pde, new_pts, I915_PDES) |
Mika Kuoppala | a08e111 | 2015-06-25 18:35:08 +0300 | [diff] [blame] | 1048 | free_pt(dev, pd->page_table[pde]); |
Ben Widawsky | d7b3de9 | 2015-02-24 16:22:34 +0000 | [diff] [blame] | 1049 | |
| 1050 | return -ENOMEM; |
| 1051 | } |
| 1052 | |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1053 | /** |
| 1054 | * gen8_ppgtt_alloc_page_directories() - Allocate page directories for VA range. |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1055 | * @vm: Master vm structure. |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1056 | * @pdp: Page directory pointer for this address range. |
| 1057 | * @start: Starting virtual address to begin allocations. |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1058 | * @length: Size of the allocations. |
| 1059 | * @new_pds: Bitmap set by function with new allocations. Likely used by the |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1060 | * caller to free on error. |
| 1061 | * |
| 1062 | * Allocate the required number of page directories starting at the pde index of |
| 1063 | * @start, and ending at the pde index @start + @length. This function will skip |
| 1064 | * over already allocated page directories within the range, and only allocate |
| 1065 | * new ones, setting the appropriate pointer within the pdp as well as the |
| 1066 | * correct position in the bitmap @new_pds. |
| 1067 | * |
| 1068 | * The function will only allocate the pages within the range for a give page |
| 1069 | * directory pointer. In other words, if @start + @length straddles a virtually |
| 1070 | * addressed PDP boundary (512GB for 4k pages), there will be more allocations |
| 1071 | * required by the caller, This is not currently possible, and the BUG in the |
| 1072 | * code will prevent it. |
| 1073 | * |
| 1074 | * Return: 0 if success; negative error code otherwise. |
| 1075 | */ |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1076 | static int |
| 1077 | gen8_ppgtt_alloc_page_directories(struct i915_address_space *vm, |
| 1078 | struct i915_page_directory_pointer *pdp, |
| 1079 | uint64_t start, |
| 1080 | uint64_t length, |
| 1081 | unsigned long *new_pds) |
Ben Widawsky | bf2b4ed | 2014-02-19 22:05:43 -0800 | [diff] [blame] | 1082 | { |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1083 | struct drm_device *dev = vm->dev; |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1084 | struct i915_page_directory *pd; |
Michel Thierry | 69876be | 2015-04-08 12:13:27 +0100 | [diff] [blame] | 1085 | uint32_t pdpe; |
Michel Thierry | 6ac1850 | 2015-07-29 17:23:46 +0100 | [diff] [blame] | 1086 | uint32_t pdpes = I915_PDPES_PER_PDP(dev); |
Ben Widawsky | bf2b4ed | 2014-02-19 22:05:43 -0800 | [diff] [blame] | 1087 | |
Michel Thierry | 6ac1850 | 2015-07-29 17:23:46 +0100 | [diff] [blame] | 1088 | WARN_ON(!bitmap_empty(new_pds, pdpes)); |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1089 | |
Dave Gordon | e8ebd8e | 2015-12-08 13:30:51 +0000 | [diff] [blame] | 1090 | gen8_for_each_pdpe(pd, pdp, start, length, pdpe) { |
Michel Thierry | 6ac1850 | 2015-07-29 17:23:46 +0100 | [diff] [blame] | 1091 | if (test_bit(pdpe, pdp->used_pdpes)) |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1092 | continue; |
Michel Thierry | 33c8819 | 2015-04-08 12:13:33 +0100 | [diff] [blame] | 1093 | |
Mika Kuoppala | 8a1ebd7 | 2015-05-22 20:04:59 +0300 | [diff] [blame] | 1094 | pd = alloc_pd(dev); |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1095 | if (IS_ERR(pd)) |
Ben Widawsky | d7b3de9 | 2015-02-24 16:22:34 +0000 | [diff] [blame] | 1096 | goto unwind_out; |
Michel Thierry | 69876be | 2015-04-08 12:13:27 +0100 | [diff] [blame] | 1097 | |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1098 | gen8_initialize_pd(vm, pd); |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1099 | pdp->page_directory[pdpe] = pd; |
Mika Kuoppala | 966082c | 2015-06-25 18:35:19 +0300 | [diff] [blame] | 1100 | __set_bit(pdpe, new_pds); |
Michel Thierry | 4c06ec8 | 2015-07-29 17:23:49 +0100 | [diff] [blame] | 1101 | trace_i915_page_directory_entry_alloc(vm, pdpe, start, GEN8_PDPE_SHIFT); |
Ben Widawsky | d7b3de9 | 2015-02-24 16:22:34 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
Ben Widawsky | bf2b4ed | 2014-02-19 22:05:43 -0800 | [diff] [blame] | 1104 | return 0; |
Ben Widawsky | d7b3de9 | 2015-02-24 16:22:34 +0000 | [diff] [blame] | 1105 | |
| 1106 | unwind_out: |
Michel Thierry | 6ac1850 | 2015-07-29 17:23:46 +0100 | [diff] [blame] | 1107 | for_each_set_bit(pdpe, new_pds, pdpes) |
Mika Kuoppala | a08e111 | 2015-06-25 18:35:08 +0300 | [diff] [blame] | 1108 | free_pd(dev, pdp->page_directory[pdpe]); |
Ben Widawsky | d7b3de9 | 2015-02-24 16:22:34 +0000 | [diff] [blame] | 1109 | |
| 1110 | return -ENOMEM; |
Ben Widawsky | bf2b4ed | 2014-02-19 22:05:43 -0800 | [diff] [blame] | 1111 | } |
| 1112 | |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 1113 | /** |
| 1114 | * gen8_ppgtt_alloc_page_dirpointers() - Allocate pdps for VA range. |
| 1115 | * @vm: Master vm structure. |
| 1116 | * @pml4: Page map level 4 for this address range. |
| 1117 | * @start: Starting virtual address to begin allocations. |
| 1118 | * @length: Size of the allocations. |
| 1119 | * @new_pdps: Bitmap set by function with new allocations. Likely used by the |
| 1120 | * caller to free on error. |
| 1121 | * |
| 1122 | * Allocate the required number of page directory pointers. Extremely similar to |
| 1123 | * gen8_ppgtt_alloc_page_directories() and gen8_ppgtt_alloc_pagetabs(). |
| 1124 | * The main difference is here we are limited by the pml4 boundary (instead of |
| 1125 | * the page directory pointer). |
| 1126 | * |
| 1127 | * Return: 0 if success; negative error code otherwise. |
| 1128 | */ |
| 1129 | static int |
| 1130 | gen8_ppgtt_alloc_page_dirpointers(struct i915_address_space *vm, |
| 1131 | struct i915_pml4 *pml4, |
| 1132 | uint64_t start, |
| 1133 | uint64_t length, |
| 1134 | unsigned long *new_pdps) |
| 1135 | { |
| 1136 | struct drm_device *dev = vm->dev; |
| 1137 | struct i915_page_directory_pointer *pdp; |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 1138 | uint32_t pml4e; |
| 1139 | |
| 1140 | WARN_ON(!bitmap_empty(new_pdps, GEN8_PML4ES_PER_PML4)); |
| 1141 | |
Dave Gordon | e8ebd8e | 2015-12-08 13:30:51 +0000 | [diff] [blame] | 1142 | gen8_for_each_pml4e(pdp, pml4, start, length, pml4e) { |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 1143 | if (!test_bit(pml4e, pml4->used_pml4es)) { |
| 1144 | pdp = alloc_pdp(dev); |
| 1145 | if (IS_ERR(pdp)) |
| 1146 | goto unwind_out; |
| 1147 | |
Michel Thierry | 69ab76f | 2015-07-29 17:23:55 +0100 | [diff] [blame] | 1148 | gen8_initialize_pdp(vm, pdp); |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 1149 | pml4->pdps[pml4e] = pdp; |
| 1150 | __set_bit(pml4e, new_pdps); |
| 1151 | trace_i915_page_directory_pointer_entry_alloc(vm, |
| 1152 | pml4e, |
| 1153 | start, |
| 1154 | GEN8_PML4E_SHIFT); |
| 1155 | } |
| 1156 | } |
| 1157 | |
| 1158 | return 0; |
| 1159 | |
| 1160 | unwind_out: |
| 1161 | for_each_set_bit(pml4e, new_pdps, GEN8_PML4ES_PER_PML4) |
| 1162 | free_pdp(dev, pml4->pdps[pml4e]); |
| 1163 | |
| 1164 | return -ENOMEM; |
| 1165 | } |
| 1166 | |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1167 | static void |
Michał Winiarski | 3a41a05 | 2015-09-03 19:22:18 +0200 | [diff] [blame] | 1168 | free_gen8_temp_bitmaps(unsigned long *new_pds, unsigned long *new_pts) |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1169 | { |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1170 | kfree(new_pts); |
| 1171 | kfree(new_pds); |
| 1172 | } |
| 1173 | |
| 1174 | /* Fills in the page directory bitmap, and the array of page tables bitmap. Both |
| 1175 | * of these are based on the number of PDPEs in the system. |
| 1176 | */ |
| 1177 | static |
| 1178 | int __must_check alloc_gen8_temp_bitmaps(unsigned long **new_pds, |
Michał Winiarski | 3a41a05 | 2015-09-03 19:22:18 +0200 | [diff] [blame] | 1179 | unsigned long **new_pts, |
Michel Thierry | 6ac1850 | 2015-07-29 17:23:46 +0100 | [diff] [blame] | 1180 | uint32_t pdpes) |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1181 | { |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1182 | unsigned long *pds; |
Michał Winiarski | 3a41a05 | 2015-09-03 19:22:18 +0200 | [diff] [blame] | 1183 | unsigned long *pts; |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1184 | |
Michał Winiarski | 3a41a05 | 2015-09-03 19:22:18 +0200 | [diff] [blame] | 1185 | pds = kcalloc(BITS_TO_LONGS(pdpes), sizeof(unsigned long), GFP_TEMPORARY); |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1186 | if (!pds) |
| 1187 | return -ENOMEM; |
| 1188 | |
Michał Winiarski | 3a41a05 | 2015-09-03 19:22:18 +0200 | [diff] [blame] | 1189 | pts = kcalloc(pdpes, BITS_TO_LONGS(I915_PDES) * sizeof(unsigned long), |
| 1190 | GFP_TEMPORARY); |
| 1191 | if (!pts) |
| 1192 | goto err_out; |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1193 | |
| 1194 | *new_pds = pds; |
| 1195 | *new_pts = pts; |
| 1196 | |
| 1197 | return 0; |
| 1198 | |
| 1199 | err_out: |
Michał Winiarski | 3a41a05 | 2015-09-03 19:22:18 +0200 | [diff] [blame] | 1200 | free_gen8_temp_bitmaps(pds, pts); |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1201 | return -ENOMEM; |
| 1202 | } |
| 1203 | |
Mika Kuoppala | 5b7e4c9 | 2015-06-25 18:35:03 +0300 | [diff] [blame] | 1204 | /* PDE TLBs are a pain to invalidate on GEN8+. When we modify |
| 1205 | * the page table structures, we mark them dirty so that |
| 1206 | * context switching/execlist queuing code takes extra steps |
| 1207 | * to ensure that tlbs are flushed. |
| 1208 | */ |
| 1209 | static void mark_tlbs_dirty(struct i915_hw_ppgtt *ppgtt) |
| 1210 | { |
| 1211 | ppgtt->pd_dirty_rings = INTEL_INFO(ppgtt->base.dev)->ring_mask; |
| 1212 | } |
| 1213 | |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 1214 | static int gen8_alloc_va_range_3lvl(struct i915_address_space *vm, |
| 1215 | struct i915_page_directory_pointer *pdp, |
| 1216 | uint64_t start, |
| 1217 | uint64_t length) |
Ben Widawsky | bf2b4ed | 2014-02-19 22:05:43 -0800 | [diff] [blame] | 1218 | { |
Michel Thierry | e5815a2 | 2015-04-08 12:13:32 +0100 | [diff] [blame] | 1219 | struct i915_hw_ppgtt *ppgtt = |
| 1220 | container_of(vm, struct i915_hw_ppgtt, base); |
Michał Winiarski | 3a41a05 | 2015-09-03 19:22:18 +0200 | [diff] [blame] | 1221 | unsigned long *new_page_dirs, *new_page_tables; |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1222 | struct drm_device *dev = vm->dev; |
Michel Thierry | 5441f0c | 2015-04-08 12:13:28 +0100 | [diff] [blame] | 1223 | struct i915_page_directory *pd; |
Michel Thierry | 33c8819 | 2015-04-08 12:13:33 +0100 | [diff] [blame] | 1224 | const uint64_t orig_start = start; |
| 1225 | const uint64_t orig_length = length; |
Michel Thierry | 5441f0c | 2015-04-08 12:13:28 +0100 | [diff] [blame] | 1226 | uint32_t pdpe; |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1227 | uint32_t pdpes = I915_PDPES_PER_PDP(dev); |
Ben Widawsky | bf2b4ed | 2014-02-19 22:05:43 -0800 | [diff] [blame] | 1228 | int ret; |
| 1229 | |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1230 | /* Wrap is never okay since we can only represent 48b, and we don't |
| 1231 | * actually use the other side of the canonical address space. |
| 1232 | */ |
| 1233 | if (WARN_ON(start + length < start)) |
Mika Kuoppala | a05d80e | 2015-06-25 18:35:04 +0300 | [diff] [blame] | 1234 | return -ENODEV; |
| 1235 | |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1236 | if (WARN_ON(start + length > vm->total)) |
Mika Kuoppala | a05d80e | 2015-06-25 18:35:04 +0300 | [diff] [blame] | 1237 | return -ENODEV; |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1238 | |
Michel Thierry | 6ac1850 | 2015-07-29 17:23:46 +0100 | [diff] [blame] | 1239 | ret = alloc_gen8_temp_bitmaps(&new_page_dirs, &new_page_tables, pdpes); |
Ben Widawsky | bf2b4ed | 2014-02-19 22:05:43 -0800 | [diff] [blame] | 1240 | if (ret) |
| 1241 | return ret; |
| 1242 | |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1243 | /* Do the allocations first so we can easily bail out */ |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1244 | ret = gen8_ppgtt_alloc_page_directories(vm, pdp, start, length, |
| 1245 | new_page_dirs); |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1246 | if (ret) { |
Michał Winiarski | 3a41a05 | 2015-09-03 19:22:18 +0200 | [diff] [blame] | 1247 | free_gen8_temp_bitmaps(new_page_dirs, new_page_tables); |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1248 | return ret; |
| 1249 | } |
| 1250 | |
| 1251 | /* For every page directory referenced, allocate page tables */ |
Dave Gordon | e8ebd8e | 2015-12-08 13:30:51 +0000 | [diff] [blame] | 1252 | gen8_for_each_pdpe(pd, pdp, start, length, pdpe) { |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1253 | ret = gen8_ppgtt_alloc_pagetabs(vm, pd, start, length, |
Michał Winiarski | 3a41a05 | 2015-09-03 19:22:18 +0200 | [diff] [blame] | 1254 | new_page_tables + pdpe * BITS_TO_LONGS(I915_PDES)); |
Michel Thierry | 5441f0c | 2015-04-08 12:13:28 +0100 | [diff] [blame] | 1255 | if (ret) |
| 1256 | goto err_out; |
Michel Thierry | 5441f0c | 2015-04-08 12:13:28 +0100 | [diff] [blame] | 1257 | } |
| 1258 | |
Michel Thierry | 33c8819 | 2015-04-08 12:13:33 +0100 | [diff] [blame] | 1259 | start = orig_start; |
| 1260 | length = orig_length; |
| 1261 | |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1262 | /* Allocations have completed successfully, so set the bitmaps, and do |
| 1263 | * the mappings. */ |
Dave Gordon | e8ebd8e | 2015-12-08 13:30:51 +0000 | [diff] [blame] | 1264 | gen8_for_each_pdpe(pd, pdp, start, length, pdpe) { |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 1265 | gen8_pde_t *const page_directory = kmap_px(pd); |
Michel Thierry | 33c8819 | 2015-04-08 12:13:33 +0100 | [diff] [blame] | 1266 | struct i915_page_table *pt; |
Michel Thierry | 09120d4 | 2015-07-29 17:23:45 +0100 | [diff] [blame] | 1267 | uint64_t pd_len = length; |
Michel Thierry | 33c8819 | 2015-04-08 12:13:33 +0100 | [diff] [blame] | 1268 | uint64_t pd_start = start; |
| 1269 | uint32_t pde; |
| 1270 | |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1271 | /* Every pd should be allocated, we just did that above. */ |
| 1272 | WARN_ON(!pd); |
| 1273 | |
Dave Gordon | e8ebd8e | 2015-12-08 13:30:51 +0000 | [diff] [blame] | 1274 | gen8_for_each_pde(pt, pd, pd_start, pd_len, pde) { |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1275 | /* Same reasoning as pd */ |
| 1276 | WARN_ON(!pt); |
| 1277 | WARN_ON(!pd_len); |
| 1278 | WARN_ON(!gen8_pte_count(pd_start, pd_len)); |
| 1279 | |
| 1280 | /* Set our used ptes within the page table */ |
| 1281 | bitmap_set(pt->used_ptes, |
| 1282 | gen8_pte_index(pd_start), |
| 1283 | gen8_pte_count(pd_start, pd_len)); |
| 1284 | |
| 1285 | /* Our pde is now pointing to the pagetable, pt */ |
Mika Kuoppala | 966082c | 2015-06-25 18:35:19 +0300 | [diff] [blame] | 1286 | __set_bit(pde, pd->used_pdes); |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1287 | |
| 1288 | /* Map the PDE to the page table */ |
Mika Kuoppala | fe36f55 | 2015-06-25 18:35:16 +0300 | [diff] [blame] | 1289 | page_directory[pde] = gen8_pde_encode(px_dma(pt), |
| 1290 | I915_CACHE_LLC); |
Michel Thierry | 4c06ec8 | 2015-07-29 17:23:49 +0100 | [diff] [blame] | 1291 | trace_i915_page_table_entry_map(&ppgtt->base, pde, pt, |
| 1292 | gen8_pte_index(start), |
| 1293 | gen8_pte_count(start, length), |
| 1294 | GEN8_PTES); |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1295 | |
| 1296 | /* NB: We haven't yet mapped ptes to pages. At this |
| 1297 | * point we're still relying on insert_entries() */ |
Michel Thierry | 33c8819 | 2015-04-08 12:13:33 +0100 | [diff] [blame] | 1298 | } |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1299 | |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 1300 | kunmap_px(ppgtt, page_directory); |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1301 | __set_bit(pdpe, pdp->used_pdpes); |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 1302 | gen8_setup_page_directory(ppgtt, pdp, pd, pdpe); |
Michel Thierry | 33c8819 | 2015-04-08 12:13:33 +0100 | [diff] [blame] | 1303 | } |
| 1304 | |
Michał Winiarski | 3a41a05 | 2015-09-03 19:22:18 +0200 | [diff] [blame] | 1305 | free_gen8_temp_bitmaps(new_page_dirs, new_page_tables); |
Mika Kuoppala | 5b7e4c9 | 2015-06-25 18:35:03 +0300 | [diff] [blame] | 1306 | mark_tlbs_dirty(ppgtt); |
Ben Widawsky | d7b3de9 | 2015-02-24 16:22:34 +0000 | [diff] [blame] | 1307 | return 0; |
| 1308 | |
| 1309 | err_out: |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1310 | while (pdpe--) { |
Dave Gordon | e8ebd8e | 2015-12-08 13:30:51 +0000 | [diff] [blame] | 1311 | unsigned long temp; |
| 1312 | |
Michał Winiarski | 3a41a05 | 2015-09-03 19:22:18 +0200 | [diff] [blame] | 1313 | for_each_set_bit(temp, new_page_tables + pdpe * |
| 1314 | BITS_TO_LONGS(I915_PDES), I915_PDES) |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1315 | free_pt(dev, pdp->page_directory[pdpe]->page_table[temp]); |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1316 | } |
| 1317 | |
Michel Thierry | 6ac1850 | 2015-07-29 17:23:46 +0100 | [diff] [blame] | 1318 | for_each_set_bit(pdpe, new_page_dirs, pdpes) |
Michel Thierry | d4ec9da | 2015-07-30 11:02:03 +0100 | [diff] [blame] | 1319 | free_pd(dev, pdp->page_directory[pdpe]); |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1320 | |
Michał Winiarski | 3a41a05 | 2015-09-03 19:22:18 +0200 | [diff] [blame] | 1321 | free_gen8_temp_bitmaps(new_page_dirs, new_page_tables); |
Mika Kuoppala | 5b7e4c9 | 2015-06-25 18:35:03 +0300 | [diff] [blame] | 1322 | mark_tlbs_dirty(ppgtt); |
Ben Widawsky | bf2b4ed | 2014-02-19 22:05:43 -0800 | [diff] [blame] | 1323 | return ret; |
| 1324 | } |
| 1325 | |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 1326 | static int gen8_alloc_va_range_4lvl(struct i915_address_space *vm, |
| 1327 | struct i915_pml4 *pml4, |
| 1328 | uint64_t start, |
| 1329 | uint64_t length) |
| 1330 | { |
| 1331 | DECLARE_BITMAP(new_pdps, GEN8_PML4ES_PER_PML4); |
| 1332 | struct i915_hw_ppgtt *ppgtt = |
| 1333 | container_of(vm, struct i915_hw_ppgtt, base); |
| 1334 | struct i915_page_directory_pointer *pdp; |
Dave Gordon | e8ebd8e | 2015-12-08 13:30:51 +0000 | [diff] [blame] | 1335 | uint64_t pml4e; |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 1336 | int ret = 0; |
| 1337 | |
| 1338 | /* Do the pml4 allocations first, so we don't need to track the newly |
| 1339 | * allocated tables below the pdp */ |
| 1340 | bitmap_zero(new_pdps, GEN8_PML4ES_PER_PML4); |
| 1341 | |
| 1342 | /* The pagedirectory and pagetable allocations are done in the shared 3 |
| 1343 | * and 4 level code. Just allocate the pdps. |
| 1344 | */ |
| 1345 | ret = gen8_ppgtt_alloc_page_dirpointers(vm, pml4, start, length, |
| 1346 | new_pdps); |
| 1347 | if (ret) |
| 1348 | return ret; |
| 1349 | |
| 1350 | WARN(bitmap_weight(new_pdps, GEN8_PML4ES_PER_PML4) > 2, |
| 1351 | "The allocation has spanned more than 512GB. " |
| 1352 | "It is highly likely this is incorrect."); |
| 1353 | |
Dave Gordon | e8ebd8e | 2015-12-08 13:30:51 +0000 | [diff] [blame] | 1354 | gen8_for_each_pml4e(pdp, pml4, start, length, pml4e) { |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 1355 | WARN_ON(!pdp); |
| 1356 | |
| 1357 | ret = gen8_alloc_va_range_3lvl(vm, pdp, start, length); |
| 1358 | if (ret) |
| 1359 | goto err_out; |
| 1360 | |
| 1361 | gen8_setup_page_directory_pointer(ppgtt, pml4, pdp, pml4e); |
| 1362 | } |
| 1363 | |
| 1364 | bitmap_or(pml4->used_pml4es, new_pdps, pml4->used_pml4es, |
| 1365 | GEN8_PML4ES_PER_PML4); |
| 1366 | |
| 1367 | return 0; |
| 1368 | |
| 1369 | err_out: |
| 1370 | for_each_set_bit(pml4e, new_pdps, GEN8_PML4ES_PER_PML4) |
| 1371 | gen8_ppgtt_cleanup_3lvl(vm->dev, pml4->pdps[pml4e]); |
| 1372 | |
| 1373 | return ret; |
| 1374 | } |
| 1375 | |
| 1376 | static int gen8_alloc_va_range(struct i915_address_space *vm, |
| 1377 | uint64_t start, uint64_t length) |
| 1378 | { |
| 1379 | struct i915_hw_ppgtt *ppgtt = |
| 1380 | container_of(vm, struct i915_hw_ppgtt, base); |
| 1381 | |
| 1382 | if (USES_FULL_48BIT_PPGTT(vm->dev)) |
| 1383 | return gen8_alloc_va_range_4lvl(vm, &ppgtt->pml4, start, length); |
| 1384 | else |
| 1385 | return gen8_alloc_va_range_3lvl(vm, &ppgtt->pdp, start, length); |
| 1386 | } |
| 1387 | |
Michel Thierry | ea91e40 | 2015-07-29 17:23:57 +0100 | [diff] [blame] | 1388 | static void gen8_dump_pdp(struct i915_page_directory_pointer *pdp, |
| 1389 | uint64_t start, uint64_t length, |
| 1390 | gen8_pte_t scratch_pte, |
| 1391 | struct seq_file *m) |
| 1392 | { |
| 1393 | struct i915_page_directory *pd; |
Michel Thierry | ea91e40 | 2015-07-29 17:23:57 +0100 | [diff] [blame] | 1394 | uint32_t pdpe; |
| 1395 | |
Dave Gordon | e8ebd8e | 2015-12-08 13:30:51 +0000 | [diff] [blame] | 1396 | gen8_for_each_pdpe(pd, pdp, start, length, pdpe) { |
Michel Thierry | ea91e40 | 2015-07-29 17:23:57 +0100 | [diff] [blame] | 1397 | struct i915_page_table *pt; |
| 1398 | uint64_t pd_len = length; |
| 1399 | uint64_t pd_start = start; |
| 1400 | uint32_t pde; |
| 1401 | |
| 1402 | if (!test_bit(pdpe, pdp->used_pdpes)) |
| 1403 | continue; |
| 1404 | |
| 1405 | seq_printf(m, "\tPDPE #%d\n", pdpe); |
Dave Gordon | e8ebd8e | 2015-12-08 13:30:51 +0000 | [diff] [blame] | 1406 | gen8_for_each_pde(pt, pd, pd_start, pd_len, pde) { |
Michel Thierry | ea91e40 | 2015-07-29 17:23:57 +0100 | [diff] [blame] | 1407 | uint32_t pte; |
| 1408 | gen8_pte_t *pt_vaddr; |
| 1409 | |
| 1410 | if (!test_bit(pde, pd->used_pdes)) |
| 1411 | continue; |
| 1412 | |
| 1413 | pt_vaddr = kmap_px(pt); |
| 1414 | for (pte = 0; pte < GEN8_PTES; pte += 4) { |
| 1415 | uint64_t va = |
| 1416 | (pdpe << GEN8_PDPE_SHIFT) | |
| 1417 | (pde << GEN8_PDE_SHIFT) | |
| 1418 | (pte << GEN8_PTE_SHIFT); |
| 1419 | int i; |
| 1420 | bool found = false; |
| 1421 | |
| 1422 | for (i = 0; i < 4; i++) |
| 1423 | if (pt_vaddr[pte + i] != scratch_pte) |
| 1424 | found = true; |
| 1425 | if (!found) |
| 1426 | continue; |
| 1427 | |
| 1428 | seq_printf(m, "\t\t0x%llx [%03d,%03d,%04d]: =", va, pdpe, pde, pte); |
| 1429 | for (i = 0; i < 4; i++) { |
| 1430 | if (pt_vaddr[pte + i] != scratch_pte) |
| 1431 | seq_printf(m, " %llx", pt_vaddr[pte + i]); |
| 1432 | else |
| 1433 | seq_puts(m, " SCRATCH "); |
| 1434 | } |
| 1435 | seq_puts(m, "\n"); |
| 1436 | } |
| 1437 | /* don't use kunmap_px, it could trigger |
| 1438 | * an unnecessary flush. |
| 1439 | */ |
| 1440 | kunmap_atomic(pt_vaddr); |
| 1441 | } |
| 1442 | } |
| 1443 | } |
| 1444 | |
| 1445 | static void gen8_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m) |
| 1446 | { |
| 1447 | struct i915_address_space *vm = &ppgtt->base; |
| 1448 | uint64_t start = ppgtt->base.start; |
| 1449 | uint64_t length = ppgtt->base.total; |
| 1450 | gen8_pte_t scratch_pte = gen8_pte_encode(px_dma(vm->scratch_page), |
| 1451 | I915_CACHE_LLC, true); |
| 1452 | |
| 1453 | if (!USES_FULL_48BIT_PPGTT(vm->dev)) { |
| 1454 | gen8_dump_pdp(&ppgtt->pdp, start, length, scratch_pte, m); |
| 1455 | } else { |
Dave Gordon | e8ebd8e | 2015-12-08 13:30:51 +0000 | [diff] [blame] | 1456 | uint64_t pml4e; |
Michel Thierry | ea91e40 | 2015-07-29 17:23:57 +0100 | [diff] [blame] | 1457 | struct i915_pml4 *pml4 = &ppgtt->pml4; |
| 1458 | struct i915_page_directory_pointer *pdp; |
| 1459 | |
Dave Gordon | e8ebd8e | 2015-12-08 13:30:51 +0000 | [diff] [blame] | 1460 | gen8_for_each_pml4e(pdp, pml4, start, length, pml4e) { |
Michel Thierry | ea91e40 | 2015-07-29 17:23:57 +0100 | [diff] [blame] | 1461 | if (!test_bit(pml4e, pml4->used_pml4es)) |
| 1462 | continue; |
| 1463 | |
| 1464 | seq_printf(m, " PML4E #%llu\n", pml4e); |
| 1465 | gen8_dump_pdp(pdp, start, length, scratch_pte, m); |
| 1466 | } |
| 1467 | } |
| 1468 | } |
| 1469 | |
Zhiyuan Lv | 331f38e | 2015-08-28 15:41:14 +0800 | [diff] [blame] | 1470 | static int gen8_preallocate_top_level_pdps(struct i915_hw_ppgtt *ppgtt) |
| 1471 | { |
Michał Winiarski | 3a41a05 | 2015-09-03 19:22:18 +0200 | [diff] [blame] | 1472 | unsigned long *new_page_dirs, *new_page_tables; |
Zhiyuan Lv | 331f38e | 2015-08-28 15:41:14 +0800 | [diff] [blame] | 1473 | uint32_t pdpes = I915_PDPES_PER_PDP(dev); |
| 1474 | int ret; |
| 1475 | |
| 1476 | /* We allocate temp bitmap for page tables for no gain |
| 1477 | * but as this is for init only, lets keep the things simple |
| 1478 | */ |
| 1479 | ret = alloc_gen8_temp_bitmaps(&new_page_dirs, &new_page_tables, pdpes); |
| 1480 | if (ret) |
| 1481 | return ret; |
| 1482 | |
| 1483 | /* Allocate for all pdps regardless of how the ppgtt |
| 1484 | * was defined. |
| 1485 | */ |
| 1486 | ret = gen8_ppgtt_alloc_page_directories(&ppgtt->base, &ppgtt->pdp, |
| 1487 | 0, 1ULL << 32, |
| 1488 | new_page_dirs); |
| 1489 | if (!ret) |
| 1490 | *ppgtt->pdp.used_pdpes = *new_page_dirs; |
| 1491 | |
Michał Winiarski | 3a41a05 | 2015-09-03 19:22:18 +0200 | [diff] [blame] | 1492 | free_gen8_temp_bitmaps(new_page_dirs, new_page_tables); |
Zhiyuan Lv | 331f38e | 2015-08-28 15:41:14 +0800 | [diff] [blame] | 1493 | |
| 1494 | return ret; |
| 1495 | } |
| 1496 | |
Daniel Vetter | eb0b44a | 2015-03-18 14:47:59 +0100 | [diff] [blame] | 1497 | /* |
Ben Widawsky | f3a964b | 2014-02-19 22:05:42 -0800 | [diff] [blame] | 1498 | * GEN8 legacy ppgtt programming is accomplished through a max 4 PDP registers |
| 1499 | * with a net effect resembling a 2-level page table in normal x86 terms. Each |
| 1500 | * PDP represents 1GB of memory 4 * 512 * 512 * 4096 = 4GB legacy 32b address |
| 1501 | * space. |
Ben Widawsky | 37aca44 | 2013-11-04 20:47:32 -0800 | [diff] [blame] | 1502 | * |
Ben Widawsky | f3a964b | 2014-02-19 22:05:42 -0800 | [diff] [blame] | 1503 | */ |
Daniel Vetter | 5c5f645 | 2015-04-14 17:35:14 +0200 | [diff] [blame] | 1504 | static int gen8_ppgtt_init(struct i915_hw_ppgtt *ppgtt) |
Ben Widawsky | 37aca44 | 2013-11-04 20:47:32 -0800 | [diff] [blame] | 1505 | { |
Mika Kuoppala | 8776f02 | 2015-06-30 18:16:40 +0300 | [diff] [blame] | 1506 | int ret; |
Michel Thierry | 69876be | 2015-04-08 12:13:27 +0100 | [diff] [blame] | 1507 | |
Mika Kuoppala | 8776f02 | 2015-06-30 18:16:40 +0300 | [diff] [blame] | 1508 | ret = gen8_init_scratch(&ppgtt->base); |
| 1509 | if (ret) |
| 1510 | return ret; |
Michel Thierry | 69876be | 2015-04-08 12:13:27 +0100 | [diff] [blame] | 1511 | |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1512 | ppgtt->base.start = 0; |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1513 | ppgtt->base.cleanup = gen8_ppgtt_cleanup; |
Daniel Vetter | 5c5f645 | 2015-04-14 17:35:14 +0200 | [diff] [blame] | 1514 | ppgtt->base.allocate_va_range = gen8_alloc_va_range; |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1515 | ppgtt->base.insert_entries = gen8_ppgtt_insert_entries; |
Daniel Vetter | c7e16f2 | 2015-04-14 17:35:11 +0200 | [diff] [blame] | 1516 | ppgtt->base.clear_range = gen8_ppgtt_clear_range; |
Daniel Vetter | 777dc5b | 2015-04-14 17:35:12 +0200 | [diff] [blame] | 1517 | ppgtt->base.unbind_vma = ppgtt_unbind_vma; |
| 1518 | ppgtt->base.bind_vma = ppgtt_bind_vma; |
Michel Thierry | ea91e40 | 2015-07-29 17:23:57 +0100 | [diff] [blame] | 1519 | ppgtt->debug_dump = gen8_dump_ppgtt; |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1520 | |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 1521 | if (USES_FULL_48BIT_PPGTT(ppgtt->base.dev)) { |
| 1522 | ret = setup_px(ppgtt->base.dev, &ppgtt->pml4); |
| 1523 | if (ret) |
| 1524 | goto free_scratch; |
Michel Thierry | 6ac1850 | 2015-07-29 17:23:46 +0100 | [diff] [blame] | 1525 | |
Michel Thierry | 69ab76f | 2015-07-29 17:23:55 +0100 | [diff] [blame] | 1526 | gen8_initialize_pml4(&ppgtt->base, &ppgtt->pml4); |
| 1527 | |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 1528 | ppgtt->base.total = 1ULL << 48; |
Michel Thierry | 2dba323 | 2015-07-30 11:06:23 +0100 | [diff] [blame] | 1529 | ppgtt->switch_mm = gen8_48b_mm_switch; |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 1530 | } else { |
Michel Thierry | 25f5033 | 2015-08-07 17:40:19 +0100 | [diff] [blame] | 1531 | ret = __pdp_init(ppgtt->base.dev, &ppgtt->pdp); |
Michel Thierry | 81ba8aef | 2015-08-03 09:52:01 +0100 | [diff] [blame] | 1532 | if (ret) |
| 1533 | goto free_scratch; |
| 1534 | |
| 1535 | ppgtt->base.total = 1ULL << 32; |
Michel Thierry | 2dba323 | 2015-07-30 11:06:23 +0100 | [diff] [blame] | 1536 | ppgtt->switch_mm = gen8_legacy_mm_switch; |
Michel Thierry | 762d993 | 2015-07-30 11:05:29 +0100 | [diff] [blame] | 1537 | trace_i915_page_directory_pointer_entry_alloc(&ppgtt->base, |
| 1538 | 0, 0, |
| 1539 | GEN8_PML4E_SHIFT); |
Zhiyuan Lv | 331f38e | 2015-08-28 15:41:14 +0800 | [diff] [blame] | 1540 | |
| 1541 | if (intel_vgpu_active(ppgtt->base.dev)) { |
| 1542 | ret = gen8_preallocate_top_level_pdps(ppgtt); |
| 1543 | if (ret) |
| 1544 | goto free_scratch; |
| 1545 | } |
Michel Thierry | 81ba8aef | 2015-08-03 09:52:01 +0100 | [diff] [blame] | 1546 | } |
Michel Thierry | 6ac1850 | 2015-07-29 17:23:46 +0100 | [diff] [blame] | 1547 | |
Zhiyuan Lv | 650da34 | 2015-08-28 15:41:18 +0800 | [diff] [blame] | 1548 | if (intel_vgpu_active(ppgtt->base.dev)) |
| 1549 | gen8_ppgtt_notify_vgt(ppgtt, true); |
| 1550 | |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1551 | return 0; |
Michel Thierry | 6ac1850 | 2015-07-29 17:23:46 +0100 | [diff] [blame] | 1552 | |
| 1553 | free_scratch: |
| 1554 | gen8_free_scratch(&ppgtt->base); |
| 1555 | return ret; |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1556 | } |
| 1557 | |
Ben Widawsky | 87d60b6 | 2013-12-06 14:11:29 -0800 | [diff] [blame] | 1558 | static void gen6_dump_ppgtt(struct i915_hw_ppgtt *ppgtt, struct seq_file *m) |
| 1559 | { |
Ben Widawsky | 87d60b6 | 2013-12-06 14:11:29 -0800 | [diff] [blame] | 1560 | struct i915_address_space *vm = &ppgtt->base; |
Michel Thierry | 09942c6 | 2015-04-08 12:13:30 +0100 | [diff] [blame] | 1561 | struct i915_page_table *unused; |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 1562 | gen6_pte_t scratch_pte; |
Ben Widawsky | 87d60b6 | 2013-12-06 14:11:29 -0800 | [diff] [blame] | 1563 | uint32_t pd_entry; |
Michel Thierry | 09942c6 | 2015-04-08 12:13:30 +0100 | [diff] [blame] | 1564 | uint32_t pte, pde, temp; |
| 1565 | uint32_t start = ppgtt->base.start, length = ppgtt->base.total; |
Ben Widawsky | 87d60b6 | 2013-12-06 14:11:29 -0800 | [diff] [blame] | 1566 | |
Mika Kuoppala | 79ab937 | 2015-06-25 18:35:17 +0300 | [diff] [blame] | 1567 | scratch_pte = vm->pte_encode(px_dma(vm->scratch_page), |
| 1568 | I915_CACHE_LLC, true, 0); |
Ben Widawsky | 87d60b6 | 2013-12-06 14:11:29 -0800 | [diff] [blame] | 1569 | |
Michel Thierry | 09942c6 | 2015-04-08 12:13:30 +0100 | [diff] [blame] | 1570 | gen6_for_each_pde(unused, &ppgtt->pd, start, length, temp, pde) { |
Ben Widawsky | 87d60b6 | 2013-12-06 14:11:29 -0800 | [diff] [blame] | 1571 | u32 expected; |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 1572 | gen6_pte_t *pt_vaddr; |
Mika Kuoppala | 567047b | 2015-06-25 18:35:12 +0300 | [diff] [blame] | 1573 | const dma_addr_t pt_addr = px_dma(ppgtt->pd.page_table[pde]); |
Michel Thierry | 09942c6 | 2015-04-08 12:13:30 +0100 | [diff] [blame] | 1574 | pd_entry = readl(ppgtt->pd_addr + pde); |
Ben Widawsky | 87d60b6 | 2013-12-06 14:11:29 -0800 | [diff] [blame] | 1575 | expected = (GEN6_PDE_ADDR_ENCODE(pt_addr) | GEN6_PDE_VALID); |
| 1576 | |
| 1577 | if (pd_entry != expected) |
| 1578 | seq_printf(m, "\tPDE #%d mismatch: Actual PDE: %x Expected PDE: %x\n", |
| 1579 | pde, |
| 1580 | pd_entry, |
| 1581 | expected); |
| 1582 | seq_printf(m, "\tPDE: %x\n", pd_entry); |
| 1583 | |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 1584 | pt_vaddr = kmap_px(ppgtt->pd.page_table[pde]); |
| 1585 | |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 1586 | for (pte = 0; pte < GEN6_PTES; pte+=4) { |
Ben Widawsky | 87d60b6 | 2013-12-06 14:11:29 -0800 | [diff] [blame] | 1587 | unsigned long va = |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 1588 | (pde * PAGE_SIZE * GEN6_PTES) + |
Ben Widawsky | 87d60b6 | 2013-12-06 14:11:29 -0800 | [diff] [blame] | 1589 | (pte * PAGE_SIZE); |
| 1590 | int i; |
| 1591 | bool found = false; |
| 1592 | for (i = 0; i < 4; i++) |
| 1593 | if (pt_vaddr[pte + i] != scratch_pte) |
| 1594 | found = true; |
| 1595 | if (!found) |
| 1596 | continue; |
| 1597 | |
| 1598 | seq_printf(m, "\t\t0x%lx [%03d,%04d]: =", va, pde, pte); |
| 1599 | for (i = 0; i < 4; i++) { |
| 1600 | if (pt_vaddr[pte + i] != scratch_pte) |
| 1601 | seq_printf(m, " %08x", pt_vaddr[pte + i]); |
| 1602 | else |
| 1603 | seq_puts(m, " SCRATCH "); |
| 1604 | } |
| 1605 | seq_puts(m, "\n"); |
| 1606 | } |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 1607 | kunmap_px(ppgtt, pt_vaddr); |
Ben Widawsky | 87d60b6 | 2013-12-06 14:11:29 -0800 | [diff] [blame] | 1608 | } |
| 1609 | } |
| 1610 | |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 1611 | /* Write pde (index) from the page directory @pd to the page table @pt */ |
Michel Thierry | ec565b3 | 2015-04-08 12:13:23 +0100 | [diff] [blame] | 1612 | static void gen6_write_pde(struct i915_page_directory *pd, |
| 1613 | const int pde, struct i915_page_table *pt) |
Ben Widawsky | 6197349 | 2013-04-08 18:43:54 -0700 | [diff] [blame] | 1614 | { |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 1615 | /* Caller needs to make sure the write completes if necessary */ |
| 1616 | struct i915_hw_ppgtt *ppgtt = |
| 1617 | container_of(pd, struct i915_hw_ppgtt, pd); |
| 1618 | u32 pd_entry; |
Ben Widawsky | 6197349 | 2013-04-08 18:43:54 -0700 | [diff] [blame] | 1619 | |
Mika Kuoppala | 567047b | 2015-06-25 18:35:12 +0300 | [diff] [blame] | 1620 | pd_entry = GEN6_PDE_ADDR_ENCODE(px_dma(pt)); |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 1621 | pd_entry |= GEN6_PDE_VALID; |
Ben Widawsky | 6197349 | 2013-04-08 18:43:54 -0700 | [diff] [blame] | 1622 | |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 1623 | writel(pd_entry, ppgtt->pd_addr + pde); |
| 1624 | } |
Ben Widawsky | 6197349 | 2013-04-08 18:43:54 -0700 | [diff] [blame] | 1625 | |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 1626 | /* Write all the page tables found in the ppgtt structure to incrementing page |
| 1627 | * directories. */ |
| 1628 | static void gen6_write_page_range(struct drm_i915_private *dev_priv, |
Michel Thierry | ec565b3 | 2015-04-08 12:13:23 +0100 | [diff] [blame] | 1629 | struct i915_page_directory *pd, |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 1630 | uint32_t start, uint32_t length) |
| 1631 | { |
Michel Thierry | ec565b3 | 2015-04-08 12:13:23 +0100 | [diff] [blame] | 1632 | struct i915_page_table *pt; |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 1633 | uint32_t pde, temp; |
| 1634 | |
| 1635 | gen6_for_each_pde(pt, pd, start, length, temp, pde) |
| 1636 | gen6_write_pde(pd, pde, pt); |
| 1637 | |
| 1638 | /* Make sure write is complete before other code can use this page |
| 1639 | * table. Also require for WC mapped PTEs */ |
| 1640 | readl(dev_priv->gtt.gsm); |
Ben Widawsky | 3e30254 | 2013-04-23 23:15:32 -0700 | [diff] [blame] | 1641 | } |
| 1642 | |
Ben Widawsky | b4a74e3 | 2013-12-06 14:11:09 -0800 | [diff] [blame] | 1643 | static uint32_t get_pd_offset(struct i915_hw_ppgtt *ppgtt) |
Ben Widawsky | 3e30254 | 2013-04-23 23:15:32 -0700 | [diff] [blame] | 1644 | { |
Mika Kuoppala | 44159dd | 2015-06-25 18:35:07 +0300 | [diff] [blame] | 1645 | BUG_ON(ppgtt->pd.base.ggtt_offset & 0x3f); |
Ben Widawsky | 3e30254 | 2013-04-23 23:15:32 -0700 | [diff] [blame] | 1646 | |
Mika Kuoppala | 44159dd | 2015-06-25 18:35:07 +0300 | [diff] [blame] | 1647 | return (ppgtt->pd.base.ggtt_offset / 64) << 16; |
Ben Widawsky | b4a74e3 | 2013-12-06 14:11:09 -0800 | [diff] [blame] | 1648 | } |
Ben Widawsky | 6197349 | 2013-04-08 18:43:54 -0700 | [diff] [blame] | 1649 | |
Ben Widawsky | 90252e5 | 2013-12-06 14:11:12 -0800 | [diff] [blame] | 1650 | static int hsw_mm_switch(struct i915_hw_ppgtt *ppgtt, |
John Harrison | e85b26d | 2015-05-29 17:43:56 +0100 | [diff] [blame] | 1651 | struct drm_i915_gem_request *req) |
Ben Widawsky | 90252e5 | 2013-12-06 14:11:12 -0800 | [diff] [blame] | 1652 | { |
John Harrison | e85b26d | 2015-05-29 17:43:56 +0100 | [diff] [blame] | 1653 | struct intel_engine_cs *ring = req->ring; |
Ben Widawsky | 90252e5 | 2013-12-06 14:11:12 -0800 | [diff] [blame] | 1654 | int ret; |
Ben Widawsky | 6197349 | 2013-04-08 18:43:54 -0700 | [diff] [blame] | 1655 | |
Ben Widawsky | 90252e5 | 2013-12-06 14:11:12 -0800 | [diff] [blame] | 1656 | /* NB: TLBs must be flushed and invalidated before a switch */ |
John Harrison | a84c3ae | 2015-05-29 17:43:57 +0100 | [diff] [blame] | 1657 | ret = ring->flush(req, I915_GEM_GPU_DOMAINS, I915_GEM_GPU_DOMAINS); |
Ben Widawsky | 90252e5 | 2013-12-06 14:11:12 -0800 | [diff] [blame] | 1658 | if (ret) |
| 1659 | return ret; |
| 1660 | |
John Harrison | 5fb9de1 | 2015-05-29 17:44:07 +0100 | [diff] [blame] | 1661 | ret = intel_ring_begin(req, 6); |
Ben Widawsky | 90252e5 | 2013-12-06 14:11:12 -0800 | [diff] [blame] | 1662 | if (ret) |
| 1663 | return ret; |
| 1664 | |
| 1665 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(2)); |
Ville Syrjälä | f92a916 | 2015-11-04 23:20:07 +0200 | [diff] [blame] | 1666 | intel_ring_emit_reg(ring, RING_PP_DIR_DCLV(ring)); |
Ben Widawsky | 90252e5 | 2013-12-06 14:11:12 -0800 | [diff] [blame] | 1667 | intel_ring_emit(ring, PP_DIR_DCLV_2G); |
Ville Syrjälä | f92a916 | 2015-11-04 23:20:07 +0200 | [diff] [blame] | 1668 | intel_ring_emit_reg(ring, RING_PP_DIR_BASE(ring)); |
Ben Widawsky | 90252e5 | 2013-12-06 14:11:12 -0800 | [diff] [blame] | 1669 | intel_ring_emit(ring, get_pd_offset(ppgtt)); |
| 1670 | intel_ring_emit(ring, MI_NOOP); |
| 1671 | intel_ring_advance(ring); |
| 1672 | |
| 1673 | return 0; |
| 1674 | } |
| 1675 | |
Yu Zhang | 71ba2d6 | 2015-02-10 19:05:54 +0800 | [diff] [blame] | 1676 | static int vgpu_mm_switch(struct i915_hw_ppgtt *ppgtt, |
John Harrison | e85b26d | 2015-05-29 17:43:56 +0100 | [diff] [blame] | 1677 | struct drm_i915_gem_request *req) |
Yu Zhang | 71ba2d6 | 2015-02-10 19:05:54 +0800 | [diff] [blame] | 1678 | { |
John Harrison | e85b26d | 2015-05-29 17:43:56 +0100 | [diff] [blame] | 1679 | struct intel_engine_cs *ring = req->ring; |
Yu Zhang | 71ba2d6 | 2015-02-10 19:05:54 +0800 | [diff] [blame] | 1680 | struct drm_i915_private *dev_priv = to_i915(ppgtt->base.dev); |
| 1681 | |
| 1682 | I915_WRITE(RING_PP_DIR_DCLV(ring), PP_DIR_DCLV_2G); |
| 1683 | I915_WRITE(RING_PP_DIR_BASE(ring), get_pd_offset(ppgtt)); |
| 1684 | return 0; |
| 1685 | } |
| 1686 | |
Ben Widawsky | 48a1038 | 2013-12-06 14:11:11 -0800 | [diff] [blame] | 1687 | static int gen7_mm_switch(struct i915_hw_ppgtt *ppgtt, |
John Harrison | e85b26d | 2015-05-29 17:43:56 +0100 | [diff] [blame] | 1688 | struct drm_i915_gem_request *req) |
Ben Widawsky | 48a1038 | 2013-12-06 14:11:11 -0800 | [diff] [blame] | 1689 | { |
John Harrison | e85b26d | 2015-05-29 17:43:56 +0100 | [diff] [blame] | 1690 | struct intel_engine_cs *ring = req->ring; |
Ben Widawsky | 48a1038 | 2013-12-06 14:11:11 -0800 | [diff] [blame] | 1691 | int ret; |
| 1692 | |
Ben Widawsky | 48a1038 | 2013-12-06 14:11:11 -0800 | [diff] [blame] | 1693 | /* NB: TLBs must be flushed and invalidated before a switch */ |
John Harrison | a84c3ae | 2015-05-29 17:43:57 +0100 | [diff] [blame] | 1694 | ret = ring->flush(req, I915_GEM_GPU_DOMAINS, I915_GEM_GPU_DOMAINS); |
Ben Widawsky | 48a1038 | 2013-12-06 14:11:11 -0800 | [diff] [blame] | 1695 | if (ret) |
| 1696 | return ret; |
| 1697 | |
John Harrison | 5fb9de1 | 2015-05-29 17:44:07 +0100 | [diff] [blame] | 1698 | ret = intel_ring_begin(req, 6); |
Ben Widawsky | 48a1038 | 2013-12-06 14:11:11 -0800 | [diff] [blame] | 1699 | if (ret) |
| 1700 | return ret; |
| 1701 | |
| 1702 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(2)); |
Ville Syrjälä | f92a916 | 2015-11-04 23:20:07 +0200 | [diff] [blame] | 1703 | intel_ring_emit_reg(ring, RING_PP_DIR_DCLV(ring)); |
Ben Widawsky | 48a1038 | 2013-12-06 14:11:11 -0800 | [diff] [blame] | 1704 | intel_ring_emit(ring, PP_DIR_DCLV_2G); |
Ville Syrjälä | f92a916 | 2015-11-04 23:20:07 +0200 | [diff] [blame] | 1705 | intel_ring_emit_reg(ring, RING_PP_DIR_BASE(ring)); |
Ben Widawsky | 48a1038 | 2013-12-06 14:11:11 -0800 | [diff] [blame] | 1706 | intel_ring_emit(ring, get_pd_offset(ppgtt)); |
| 1707 | intel_ring_emit(ring, MI_NOOP); |
| 1708 | intel_ring_advance(ring); |
| 1709 | |
Ben Widawsky | 90252e5 | 2013-12-06 14:11:12 -0800 | [diff] [blame] | 1710 | /* XXX: RCS is the only one to auto invalidate the TLBs? */ |
| 1711 | if (ring->id != RCS) { |
John Harrison | a84c3ae | 2015-05-29 17:43:57 +0100 | [diff] [blame] | 1712 | ret = ring->flush(req, I915_GEM_GPU_DOMAINS, I915_GEM_GPU_DOMAINS); |
Ben Widawsky | 90252e5 | 2013-12-06 14:11:12 -0800 | [diff] [blame] | 1713 | if (ret) |
| 1714 | return ret; |
| 1715 | } |
| 1716 | |
Ben Widawsky | 48a1038 | 2013-12-06 14:11:11 -0800 | [diff] [blame] | 1717 | return 0; |
| 1718 | } |
| 1719 | |
Ben Widawsky | eeb9488 | 2013-12-06 14:11:10 -0800 | [diff] [blame] | 1720 | static int gen6_mm_switch(struct i915_hw_ppgtt *ppgtt, |
John Harrison | e85b26d | 2015-05-29 17:43:56 +0100 | [diff] [blame] | 1721 | struct drm_i915_gem_request *req) |
Ben Widawsky | eeb9488 | 2013-12-06 14:11:10 -0800 | [diff] [blame] | 1722 | { |
John Harrison | e85b26d | 2015-05-29 17:43:56 +0100 | [diff] [blame] | 1723 | struct intel_engine_cs *ring = req->ring; |
Ben Widawsky | eeb9488 | 2013-12-06 14:11:10 -0800 | [diff] [blame] | 1724 | struct drm_device *dev = ppgtt->base.dev; |
| 1725 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1726 | |
Ben Widawsky | 48a1038 | 2013-12-06 14:11:11 -0800 | [diff] [blame] | 1727 | |
Ben Widawsky | eeb9488 | 2013-12-06 14:11:10 -0800 | [diff] [blame] | 1728 | I915_WRITE(RING_PP_DIR_DCLV(ring), PP_DIR_DCLV_2G); |
| 1729 | I915_WRITE(RING_PP_DIR_BASE(ring), get_pd_offset(ppgtt)); |
| 1730 | |
| 1731 | POSTING_READ(RING_PP_DIR_DCLV(ring)); |
| 1732 | |
| 1733 | return 0; |
| 1734 | } |
| 1735 | |
Daniel Vetter | 82460d9 | 2014-08-06 20:19:53 +0200 | [diff] [blame] | 1736 | static void gen8_ppgtt_enable(struct drm_device *dev) |
Ben Widawsky | eeb9488 | 2013-12-06 14:11:10 -0800 | [diff] [blame] | 1737 | { |
Ben Widawsky | eeb9488 | 2013-12-06 14:11:10 -0800 | [diff] [blame] | 1738 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 1739 | struct intel_engine_cs *ring; |
Daniel Vetter | 82460d9 | 2014-08-06 20:19:53 +0200 | [diff] [blame] | 1740 | int j; |
Ben Widawsky | eeb9488 | 2013-12-06 14:11:10 -0800 | [diff] [blame] | 1741 | |
| 1742 | for_each_ring(ring, dev_priv, j) { |
Michel Thierry | 2dba323 | 2015-07-30 11:06:23 +0100 | [diff] [blame] | 1743 | u32 four_level = USES_FULL_48BIT_PPGTT(dev) ? GEN8_GFX_PPGTT_48B : 0; |
Ben Widawsky | eeb9488 | 2013-12-06 14:11:10 -0800 | [diff] [blame] | 1744 | I915_WRITE(RING_MODE_GEN7(ring), |
Michel Thierry | 2dba323 | 2015-07-30 11:06:23 +0100 | [diff] [blame] | 1745 | _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE | four_level)); |
Ben Widawsky | eeb9488 | 2013-12-06 14:11:10 -0800 | [diff] [blame] | 1746 | } |
Ben Widawsky | eeb9488 | 2013-12-06 14:11:10 -0800 | [diff] [blame] | 1747 | } |
| 1748 | |
Daniel Vetter | 82460d9 | 2014-08-06 20:19:53 +0200 | [diff] [blame] | 1749 | static void gen7_ppgtt_enable(struct drm_device *dev) |
Ben Widawsky | b4a74e3 | 2013-12-06 14:11:09 -0800 | [diff] [blame] | 1750 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 1751 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 1752 | struct intel_engine_cs *ring; |
Ben Widawsky | b4a74e3 | 2013-12-06 14:11:09 -0800 | [diff] [blame] | 1753 | uint32_t ecochk, ecobits; |
| 1754 | int i; |
| 1755 | |
Ben Widawsky | b4a74e3 | 2013-12-06 14:11:09 -0800 | [diff] [blame] | 1756 | ecobits = I915_READ(GAC_ECO_BITS); |
| 1757 | I915_WRITE(GAC_ECO_BITS, ecobits | ECOBITS_PPGTT_CACHE64B); |
| 1758 | |
| 1759 | ecochk = I915_READ(GAM_ECOCHK); |
| 1760 | if (IS_HASWELL(dev)) { |
| 1761 | ecochk |= ECOCHK_PPGTT_WB_HSW; |
| 1762 | } else { |
| 1763 | ecochk |= ECOCHK_PPGTT_LLC_IVB; |
| 1764 | ecochk &= ~ECOCHK_PPGTT_GFDT_IVB; |
| 1765 | } |
| 1766 | I915_WRITE(GAM_ECOCHK, ecochk); |
Ben Widawsky | b4a74e3 | 2013-12-06 14:11:09 -0800 | [diff] [blame] | 1767 | |
Ben Widawsky | 6197349 | 2013-04-08 18:43:54 -0700 | [diff] [blame] | 1768 | for_each_ring(ring, dev_priv, i) { |
Ben Widawsky | eeb9488 | 2013-12-06 14:11:10 -0800 | [diff] [blame] | 1769 | /* GFX_MODE is per-ring on gen7+ */ |
Ben Widawsky | b4a74e3 | 2013-12-06 14:11:09 -0800 | [diff] [blame] | 1770 | I915_WRITE(RING_MODE_GEN7(ring), |
| 1771 | _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE)); |
Ben Widawsky | 6197349 | 2013-04-08 18:43:54 -0700 | [diff] [blame] | 1772 | } |
Ben Widawsky | b4a74e3 | 2013-12-06 14:11:09 -0800 | [diff] [blame] | 1773 | } |
| 1774 | |
Daniel Vetter | 82460d9 | 2014-08-06 20:19:53 +0200 | [diff] [blame] | 1775 | static void gen6_ppgtt_enable(struct drm_device *dev) |
Ben Widawsky | 6197349 | 2013-04-08 18:43:54 -0700 | [diff] [blame] | 1776 | { |
Jani Nikula | 50227e1 | 2014-03-31 14:27:21 +0300 | [diff] [blame] | 1777 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | b4a74e3 | 2013-12-06 14:11:09 -0800 | [diff] [blame] | 1778 | uint32_t ecochk, gab_ctl, ecobits; |
Ben Widawsky | 6197349 | 2013-04-08 18:43:54 -0700 | [diff] [blame] | 1779 | |
Ben Widawsky | b4a74e3 | 2013-12-06 14:11:09 -0800 | [diff] [blame] | 1780 | ecobits = I915_READ(GAC_ECO_BITS); |
| 1781 | I915_WRITE(GAC_ECO_BITS, ecobits | ECOBITS_SNB_BIT | |
| 1782 | ECOBITS_PPGTT_CACHE64B); |
Ben Widawsky | 6197349 | 2013-04-08 18:43:54 -0700 | [diff] [blame] | 1783 | |
Ben Widawsky | b4a74e3 | 2013-12-06 14:11:09 -0800 | [diff] [blame] | 1784 | gab_ctl = I915_READ(GAB_CTL); |
| 1785 | I915_WRITE(GAB_CTL, gab_ctl | GAB_CTL_CONT_AFTER_PAGEFAULT); |
Ben Widawsky | 6197349 | 2013-04-08 18:43:54 -0700 | [diff] [blame] | 1786 | |
Ben Widawsky | b4a74e3 | 2013-12-06 14:11:09 -0800 | [diff] [blame] | 1787 | ecochk = I915_READ(GAM_ECOCHK); |
| 1788 | I915_WRITE(GAM_ECOCHK, ecochk | ECOCHK_SNB_BIT | ECOCHK_PPGTT_CACHE64B); |
Ben Widawsky | 6197349 | 2013-04-08 18:43:54 -0700 | [diff] [blame] | 1789 | |
Ben Widawsky | b4a74e3 | 2013-12-06 14:11:09 -0800 | [diff] [blame] | 1790 | I915_WRITE(GFX_MODE, _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE)); |
Ben Widawsky | 6197349 | 2013-04-08 18:43:54 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 1793 | /* PPGTT support for Sandybdrige/Gen6 and later */ |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 1794 | static void gen6_ppgtt_clear_range(struct i915_address_space *vm, |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 1795 | uint64_t start, |
| 1796 | uint64_t length, |
Ben Widawsky | 828c790 | 2013-10-16 09:21:30 -0700 | [diff] [blame] | 1797 | bool use_scratch) |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 1798 | { |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 1799 | struct i915_hw_ppgtt *ppgtt = |
| 1800 | container_of(vm, struct i915_hw_ppgtt, base); |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 1801 | gen6_pte_t *pt_vaddr, scratch_pte; |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 1802 | unsigned first_entry = start >> PAGE_SHIFT; |
| 1803 | unsigned num_entries = length >> PAGE_SHIFT; |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 1804 | unsigned act_pt = first_entry / GEN6_PTES; |
| 1805 | unsigned first_pte = first_entry % GEN6_PTES; |
Daniel Vetter | 7bddb01 | 2012-02-09 17:15:47 +0100 | [diff] [blame] | 1806 | unsigned last_pte, i; |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 1807 | |
Mika Kuoppala | c114f76 | 2015-06-25 18:35:13 +0300 | [diff] [blame] | 1808 | scratch_pte = vm->pte_encode(px_dma(vm->scratch_page), |
| 1809 | I915_CACHE_LLC, true, 0); |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 1810 | |
Daniel Vetter | 7bddb01 | 2012-02-09 17:15:47 +0100 | [diff] [blame] | 1811 | while (num_entries) { |
| 1812 | last_pte = first_pte + num_entries; |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 1813 | if (last_pte > GEN6_PTES) |
| 1814 | last_pte = GEN6_PTES; |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 1815 | |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 1816 | pt_vaddr = kmap_px(ppgtt->pd.page_table[act_pt]); |
Daniel Vetter | 7bddb01 | 2012-02-09 17:15:47 +0100 | [diff] [blame] | 1817 | |
| 1818 | for (i = first_pte; i < last_pte; i++) |
| 1819 | pt_vaddr[i] = scratch_pte; |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 1820 | |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 1821 | kunmap_px(ppgtt, pt_vaddr); |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 1822 | |
Daniel Vetter | 7bddb01 | 2012-02-09 17:15:47 +0100 | [diff] [blame] | 1823 | num_entries -= last_pte - first_pte; |
| 1824 | first_pte = 0; |
Daniel Vetter | a15326a | 2013-03-19 23:48:39 +0100 | [diff] [blame] | 1825 | act_pt++; |
Daniel Vetter | 7bddb01 | 2012-02-09 17:15:47 +0100 | [diff] [blame] | 1826 | } |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 1827 | } |
| 1828 | |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 1829 | static void gen6_ppgtt_insert_entries(struct i915_address_space *vm, |
Daniel Vetter | def886c | 2013-01-24 14:44:56 -0800 | [diff] [blame] | 1830 | struct sg_table *pages, |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 1831 | uint64_t start, |
Akash Goel | 24f3a8c | 2014-06-17 10:59:42 +0530 | [diff] [blame] | 1832 | enum i915_cache_level cache_level, u32 flags) |
Daniel Vetter | def886c | 2013-01-24 14:44:56 -0800 | [diff] [blame] | 1833 | { |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 1834 | struct i915_hw_ppgtt *ppgtt = |
| 1835 | container_of(vm, struct i915_hw_ppgtt, base); |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 1836 | gen6_pte_t *pt_vaddr; |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 1837 | unsigned first_entry = start >> PAGE_SHIFT; |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 1838 | unsigned act_pt = first_entry / GEN6_PTES; |
| 1839 | unsigned act_pte = first_entry % GEN6_PTES; |
Imre Deak | 6e995e2 | 2013-02-18 19:28:04 +0200 | [diff] [blame] | 1840 | struct sg_page_iter sg_iter; |
Daniel Vetter | def886c | 2013-01-24 14:44:56 -0800 | [diff] [blame] | 1841 | |
Chris Wilson | cc79714 | 2013-12-31 15:50:30 +0000 | [diff] [blame] | 1842 | pt_vaddr = NULL; |
Imre Deak | 6e995e2 | 2013-02-18 19:28:04 +0200 | [diff] [blame] | 1843 | for_each_sg_page(pages->sgl, &sg_iter, pages->nents, 0) { |
Chris Wilson | cc79714 | 2013-12-31 15:50:30 +0000 | [diff] [blame] | 1844 | if (pt_vaddr == NULL) |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 1845 | pt_vaddr = kmap_px(ppgtt->pd.page_table[act_pt]); |
Daniel Vetter | def886c | 2013-01-24 14:44:56 -0800 | [diff] [blame] | 1846 | |
Chris Wilson | cc79714 | 2013-12-31 15:50:30 +0000 | [diff] [blame] | 1847 | pt_vaddr[act_pte] = |
| 1848 | vm->pte_encode(sg_page_iter_dma_address(&sg_iter), |
Akash Goel | 24f3a8c | 2014-06-17 10:59:42 +0530 | [diff] [blame] | 1849 | cache_level, true, flags); |
| 1850 | |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 1851 | if (++act_pte == GEN6_PTES) { |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 1852 | kunmap_px(ppgtt, pt_vaddr); |
Chris Wilson | cc79714 | 2013-12-31 15:50:30 +0000 | [diff] [blame] | 1853 | pt_vaddr = NULL; |
Daniel Vetter | a15326a | 2013-03-19 23:48:39 +0100 | [diff] [blame] | 1854 | act_pt++; |
Imre Deak | 6e995e2 | 2013-02-18 19:28:04 +0200 | [diff] [blame] | 1855 | act_pte = 0; |
Daniel Vetter | def886c | 2013-01-24 14:44:56 -0800 | [diff] [blame] | 1856 | } |
Daniel Vetter | def886c | 2013-01-24 14:44:56 -0800 | [diff] [blame] | 1857 | } |
Chris Wilson | cc79714 | 2013-12-31 15:50:30 +0000 | [diff] [blame] | 1858 | if (pt_vaddr) |
Mika Kuoppala | d1c54ac | 2015-06-25 18:35:11 +0300 | [diff] [blame] | 1859 | kunmap_px(ppgtt, pt_vaddr); |
Daniel Vetter | def886c | 2013-01-24 14:44:56 -0800 | [diff] [blame] | 1860 | } |
| 1861 | |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 1862 | static int gen6_alloc_va_range(struct i915_address_space *vm, |
Mika Kuoppala | a05d80e | 2015-06-25 18:35:04 +0300 | [diff] [blame] | 1863 | uint64_t start_in, uint64_t length_in) |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 1864 | { |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 1865 | DECLARE_BITMAP(new_page_tables, I915_PDES); |
| 1866 | struct drm_device *dev = vm->dev; |
| 1867 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 1868 | struct i915_hw_ppgtt *ppgtt = |
| 1869 | container_of(vm, struct i915_hw_ppgtt, base); |
Michel Thierry | ec565b3 | 2015-04-08 12:13:23 +0100 | [diff] [blame] | 1870 | struct i915_page_table *pt; |
Mika Kuoppala | a05d80e | 2015-06-25 18:35:04 +0300 | [diff] [blame] | 1871 | uint32_t start, length, start_save, length_save; |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 1872 | uint32_t pde, temp; |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 1873 | int ret; |
| 1874 | |
Mika Kuoppala | a05d80e | 2015-06-25 18:35:04 +0300 | [diff] [blame] | 1875 | if (WARN_ON(start_in + length_in > ppgtt->base.total)) |
| 1876 | return -ENODEV; |
| 1877 | |
| 1878 | start = start_save = start_in; |
| 1879 | length = length_save = length_in; |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 1880 | |
| 1881 | bitmap_zero(new_page_tables, I915_PDES); |
| 1882 | |
| 1883 | /* The allocation is done in two stages so that we can bail out with |
| 1884 | * minimal amount of pain. The first stage finds new page tables that |
| 1885 | * need allocation. The second stage marks use ptes within the page |
| 1886 | * tables. |
| 1887 | */ |
| 1888 | gen6_for_each_pde(pt, &ppgtt->pd, start, length, temp, pde) { |
Mika Kuoppala | 79ab937 | 2015-06-25 18:35:17 +0300 | [diff] [blame] | 1889 | if (pt != vm->scratch_pt) { |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 1890 | WARN_ON(bitmap_empty(pt->used_ptes, GEN6_PTES)); |
| 1891 | continue; |
| 1892 | } |
| 1893 | |
| 1894 | /* We've already allocated a page table */ |
| 1895 | WARN_ON(!bitmap_empty(pt->used_ptes, GEN6_PTES)); |
| 1896 | |
Mika Kuoppala | 8a1ebd7 | 2015-05-22 20:04:59 +0300 | [diff] [blame] | 1897 | pt = alloc_pt(dev); |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 1898 | if (IS_ERR(pt)) { |
| 1899 | ret = PTR_ERR(pt); |
| 1900 | goto unwind_out; |
| 1901 | } |
| 1902 | |
| 1903 | gen6_initialize_pt(vm, pt); |
| 1904 | |
| 1905 | ppgtt->pd.page_table[pde] = pt; |
Mika Kuoppala | 966082c | 2015-06-25 18:35:19 +0300 | [diff] [blame] | 1906 | __set_bit(pde, new_page_tables); |
Michel Thierry | 72744cb | 2015-03-24 15:46:23 +0000 | [diff] [blame] | 1907 | trace_i915_page_table_entry_alloc(vm, pde, start, GEN6_PDE_SHIFT); |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 1908 | } |
| 1909 | |
| 1910 | start = start_save; |
| 1911 | length = length_save; |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 1912 | |
| 1913 | gen6_for_each_pde(pt, &ppgtt->pd, start, length, temp, pde) { |
| 1914 | DECLARE_BITMAP(tmp_bitmap, GEN6_PTES); |
| 1915 | |
| 1916 | bitmap_zero(tmp_bitmap, GEN6_PTES); |
| 1917 | bitmap_set(tmp_bitmap, gen6_pte_index(start), |
| 1918 | gen6_pte_count(start, length)); |
| 1919 | |
Mika Kuoppala | 966082c | 2015-06-25 18:35:19 +0300 | [diff] [blame] | 1920 | if (__test_and_clear_bit(pde, new_page_tables)) |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 1921 | gen6_write_pde(&ppgtt->pd, pde, pt); |
| 1922 | |
Michel Thierry | 72744cb | 2015-03-24 15:46:23 +0000 | [diff] [blame] | 1923 | trace_i915_page_table_entry_map(vm, pde, pt, |
| 1924 | gen6_pte_index(start), |
| 1925 | gen6_pte_count(start, length), |
| 1926 | GEN6_PTES); |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 1927 | bitmap_or(pt->used_ptes, tmp_bitmap, pt->used_ptes, |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 1928 | GEN6_PTES); |
| 1929 | } |
| 1930 | |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 1931 | WARN_ON(!bitmap_empty(new_page_tables, I915_PDES)); |
| 1932 | |
| 1933 | /* Make sure write is complete before other code can use this page |
| 1934 | * table. Also require for WC mapped PTEs */ |
| 1935 | readl(dev_priv->gtt.gsm); |
| 1936 | |
Ben Widawsky | 563222a | 2015-03-19 12:53:28 +0000 | [diff] [blame] | 1937 | mark_tlbs_dirty(ppgtt); |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 1938 | return 0; |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 1939 | |
| 1940 | unwind_out: |
| 1941 | for_each_set_bit(pde, new_page_tables, I915_PDES) { |
Michel Thierry | ec565b3 | 2015-04-08 12:13:23 +0100 | [diff] [blame] | 1942 | struct i915_page_table *pt = ppgtt->pd.page_table[pde]; |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 1943 | |
Mika Kuoppala | 79ab937 | 2015-06-25 18:35:17 +0300 | [diff] [blame] | 1944 | ppgtt->pd.page_table[pde] = vm->scratch_pt; |
Mika Kuoppala | a08e111 | 2015-06-25 18:35:08 +0300 | [diff] [blame] | 1945 | free_pt(vm->dev, pt); |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | mark_tlbs_dirty(ppgtt); |
| 1949 | return ret; |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 1950 | } |
| 1951 | |
Mika Kuoppala | 8776f02 | 2015-06-30 18:16:40 +0300 | [diff] [blame] | 1952 | static int gen6_init_scratch(struct i915_address_space *vm) |
| 1953 | { |
| 1954 | struct drm_device *dev = vm->dev; |
| 1955 | |
| 1956 | vm->scratch_page = alloc_scratch_page(dev); |
| 1957 | if (IS_ERR(vm->scratch_page)) |
| 1958 | return PTR_ERR(vm->scratch_page); |
| 1959 | |
| 1960 | vm->scratch_pt = alloc_pt(dev); |
| 1961 | if (IS_ERR(vm->scratch_pt)) { |
| 1962 | free_scratch_page(dev, vm->scratch_page); |
| 1963 | return PTR_ERR(vm->scratch_pt); |
| 1964 | } |
| 1965 | |
| 1966 | gen6_initialize_pt(vm, vm->scratch_pt); |
| 1967 | |
| 1968 | return 0; |
| 1969 | } |
| 1970 | |
| 1971 | static void gen6_free_scratch(struct i915_address_space *vm) |
| 1972 | { |
| 1973 | struct drm_device *dev = vm->dev; |
| 1974 | |
| 1975 | free_pt(dev, vm->scratch_pt); |
| 1976 | free_scratch_page(dev, vm->scratch_page); |
| 1977 | } |
| 1978 | |
Daniel Vetter | 061dd49 | 2015-04-14 17:35:13 +0200 | [diff] [blame] | 1979 | static void gen6_ppgtt_cleanup(struct i915_address_space *vm) |
Ben Widawsky | a00d825 | 2014-02-19 22:05:48 -0800 | [diff] [blame] | 1980 | { |
Daniel Vetter | 061dd49 | 2015-04-14 17:35:13 +0200 | [diff] [blame] | 1981 | struct i915_hw_ppgtt *ppgtt = |
| 1982 | container_of(vm, struct i915_hw_ppgtt, base); |
Michel Thierry | 09942c6 | 2015-04-08 12:13:30 +0100 | [diff] [blame] | 1983 | struct i915_page_table *pt; |
| 1984 | uint32_t pde; |
Daniel Vetter | 3440d26 | 2013-01-24 13:49:56 -0800 | [diff] [blame] | 1985 | |
Daniel Vetter | 061dd49 | 2015-04-14 17:35:13 +0200 | [diff] [blame] | 1986 | drm_mm_remove_node(&ppgtt->node); |
| 1987 | |
Michel Thierry | 09942c6 | 2015-04-08 12:13:30 +0100 | [diff] [blame] | 1988 | gen6_for_all_pdes(pt, ppgtt, pde) { |
Mika Kuoppala | 79ab937 | 2015-06-25 18:35:17 +0300 | [diff] [blame] | 1989 | if (pt != vm->scratch_pt) |
Mika Kuoppala | a08e111 | 2015-06-25 18:35:08 +0300 | [diff] [blame] | 1990 | free_pt(ppgtt->base.dev, pt); |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 1991 | } |
| 1992 | |
Mika Kuoppala | 8776f02 | 2015-06-30 18:16:40 +0300 | [diff] [blame] | 1993 | gen6_free_scratch(vm); |
Daniel Vetter | 3440d26 | 2013-01-24 13:49:56 -0800 | [diff] [blame] | 1994 | } |
| 1995 | |
Ben Widawsky | b146520 | 2014-02-19 22:05:49 -0800 | [diff] [blame] | 1996 | static int gen6_ppgtt_allocate_page_directories(struct i915_hw_ppgtt *ppgtt) |
Daniel Vetter | 3440d26 | 2013-01-24 13:49:56 -0800 | [diff] [blame] | 1997 | { |
Mika Kuoppala | 8776f02 | 2015-06-30 18:16:40 +0300 | [diff] [blame] | 1998 | struct i915_address_space *vm = &ppgtt->base; |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 1999 | struct drm_device *dev = ppgtt->base.dev; |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 2000 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | e3cc199 | 2013-12-06 14:11:08 -0800 | [diff] [blame] | 2001 | bool retried = false; |
Ben Widawsky | b146520 | 2014-02-19 22:05:49 -0800 | [diff] [blame] | 2002 | int ret; |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 2003 | |
Ben Widawsky | c8d4c0d | 2013-12-06 14:11:07 -0800 | [diff] [blame] | 2004 | /* PPGTT PDEs reside in the GGTT and consists of 512 entries. The |
| 2005 | * allocator works in address space sizes, so it's multiplied by page |
| 2006 | * size. We allocate at the top of the GTT to avoid fragmentation. |
| 2007 | */ |
| 2008 | BUG_ON(!drm_mm_initialized(&dev_priv->gtt.base.mm)); |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 2009 | |
Mika Kuoppala | 8776f02 | 2015-06-30 18:16:40 +0300 | [diff] [blame] | 2010 | ret = gen6_init_scratch(vm); |
| 2011 | if (ret) |
| 2012 | return ret; |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 2013 | |
Ben Widawsky | e3cc199 | 2013-12-06 14:11:08 -0800 | [diff] [blame] | 2014 | alloc: |
Ben Widawsky | c8d4c0d | 2013-12-06 14:11:07 -0800 | [diff] [blame] | 2015 | ret = drm_mm_insert_node_in_range_generic(&dev_priv->gtt.base.mm, |
| 2016 | &ppgtt->node, GEN6_PD_SIZE, |
| 2017 | GEN6_PD_ALIGN, 0, |
| 2018 | 0, dev_priv->gtt.base.total, |
Ben Widawsky | 3e8b5ae | 2014-05-06 22:21:30 -0700 | [diff] [blame] | 2019 | DRM_MM_TOPDOWN); |
Ben Widawsky | e3cc199 | 2013-12-06 14:11:08 -0800 | [diff] [blame] | 2020 | if (ret == -ENOSPC && !retried) { |
| 2021 | ret = i915_gem_evict_something(dev, &dev_priv->gtt.base, |
| 2022 | GEN6_PD_SIZE, GEN6_PD_ALIGN, |
Chris Wilson | d23db88 | 2014-05-23 08:48:08 +0200 | [diff] [blame] | 2023 | I915_CACHE_NONE, |
| 2024 | 0, dev_priv->gtt.base.total, |
| 2025 | 0); |
Ben Widawsky | e3cc199 | 2013-12-06 14:11:08 -0800 | [diff] [blame] | 2026 | if (ret) |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 2027 | goto err_out; |
Ben Widawsky | e3cc199 | 2013-12-06 14:11:08 -0800 | [diff] [blame] | 2028 | |
| 2029 | retried = true; |
| 2030 | goto alloc; |
| 2031 | } |
Ben Widawsky | c8d4c0d | 2013-12-06 14:11:07 -0800 | [diff] [blame] | 2032 | |
Ben Widawsky | c8c2662 | 2015-01-22 17:01:25 +0000 | [diff] [blame] | 2033 | if (ret) |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 2034 | goto err_out; |
| 2035 | |
Ben Widawsky | c8c2662 | 2015-01-22 17:01:25 +0000 | [diff] [blame] | 2036 | |
Ben Widawsky | c8d4c0d | 2013-12-06 14:11:07 -0800 | [diff] [blame] | 2037 | if (ppgtt->node.start < dev_priv->gtt.mappable_end) |
| 2038 | DRM_DEBUG("Forced to use aperture for PDEs\n"); |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 2039 | |
Ben Widawsky | c8c2662 | 2015-01-22 17:01:25 +0000 | [diff] [blame] | 2040 | return 0; |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 2041 | |
| 2042 | err_out: |
Mika Kuoppala | 8776f02 | 2015-06-30 18:16:40 +0300 | [diff] [blame] | 2043 | gen6_free_scratch(vm); |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 2044 | return ret; |
Ben Widawsky | b146520 | 2014-02-19 22:05:49 -0800 | [diff] [blame] | 2045 | } |
| 2046 | |
Ben Widawsky | b146520 | 2014-02-19 22:05:49 -0800 | [diff] [blame] | 2047 | static int gen6_ppgtt_alloc(struct i915_hw_ppgtt *ppgtt) |
| 2048 | { |
kbuild test robot | 2f2cf68 | 2015-03-27 19:26:35 +0800 | [diff] [blame] | 2049 | return gen6_ppgtt_allocate_page_directories(ppgtt); |
Ben Widawsky | b146520 | 2014-02-19 22:05:49 -0800 | [diff] [blame] | 2050 | } |
| 2051 | |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 2052 | static void gen6_scratch_va_range(struct i915_hw_ppgtt *ppgtt, |
| 2053 | uint64_t start, uint64_t length) |
| 2054 | { |
Michel Thierry | ec565b3 | 2015-04-08 12:13:23 +0100 | [diff] [blame] | 2055 | struct i915_page_table *unused; |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 2056 | uint32_t pde, temp; |
| 2057 | |
| 2058 | gen6_for_each_pde(unused, &ppgtt->pd, start, length, temp, pde) |
Mika Kuoppala | 79ab937 | 2015-06-25 18:35:17 +0300 | [diff] [blame] | 2059 | ppgtt->pd.page_table[pde] = ppgtt->base.scratch_pt; |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 2060 | } |
| 2061 | |
Daniel Vetter | 5c5f645 | 2015-04-14 17:35:14 +0200 | [diff] [blame] | 2062 | static int gen6_ppgtt_init(struct i915_hw_ppgtt *ppgtt) |
Ben Widawsky | b146520 | 2014-02-19 22:05:49 -0800 | [diff] [blame] | 2063 | { |
| 2064 | struct drm_device *dev = ppgtt->base.dev; |
| 2065 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2066 | int ret; |
| 2067 | |
| 2068 | ppgtt->base.pte_encode = dev_priv->gtt.base.pte_encode; |
Ben Widawsky | 48a1038 | 2013-12-06 14:11:11 -0800 | [diff] [blame] | 2069 | if (IS_GEN6(dev)) { |
Ben Widawsky | 48a1038 | 2013-12-06 14:11:11 -0800 | [diff] [blame] | 2070 | ppgtt->switch_mm = gen6_mm_switch; |
Ben Widawsky | 90252e5 | 2013-12-06 14:11:12 -0800 | [diff] [blame] | 2071 | } else if (IS_HASWELL(dev)) { |
Ben Widawsky | 90252e5 | 2013-12-06 14:11:12 -0800 | [diff] [blame] | 2072 | ppgtt->switch_mm = hsw_mm_switch; |
Ben Widawsky | 48a1038 | 2013-12-06 14:11:11 -0800 | [diff] [blame] | 2073 | } else if (IS_GEN7(dev)) { |
Ben Widawsky | 48a1038 | 2013-12-06 14:11:11 -0800 | [diff] [blame] | 2074 | ppgtt->switch_mm = gen7_mm_switch; |
| 2075 | } else |
Ben Widawsky | b4a74e3 | 2013-12-06 14:11:09 -0800 | [diff] [blame] | 2076 | BUG(); |
Ben Widawsky | b146520 | 2014-02-19 22:05:49 -0800 | [diff] [blame] | 2077 | |
Yu Zhang | 71ba2d6 | 2015-02-10 19:05:54 +0800 | [diff] [blame] | 2078 | if (intel_vgpu_active(dev)) |
| 2079 | ppgtt->switch_mm = vgpu_mm_switch; |
| 2080 | |
Ben Widawsky | b146520 | 2014-02-19 22:05:49 -0800 | [diff] [blame] | 2081 | ret = gen6_ppgtt_alloc(ppgtt); |
| 2082 | if (ret) |
| 2083 | return ret; |
| 2084 | |
Daniel Vetter | 5c5f645 | 2015-04-14 17:35:14 +0200 | [diff] [blame] | 2085 | ppgtt->base.allocate_va_range = gen6_alloc_va_range; |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 2086 | ppgtt->base.clear_range = gen6_ppgtt_clear_range; |
| 2087 | ppgtt->base.insert_entries = gen6_ppgtt_insert_entries; |
Daniel Vetter | 777dc5b | 2015-04-14 17:35:12 +0200 | [diff] [blame] | 2088 | ppgtt->base.unbind_vma = ppgtt_unbind_vma; |
| 2089 | ppgtt->base.bind_vma = ppgtt_bind_vma; |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 2090 | ppgtt->base.cleanup = gen6_ppgtt_cleanup; |
Ben Widawsky | 686e1f6 | 2013-11-25 09:54:34 -0800 | [diff] [blame] | 2091 | ppgtt->base.start = 0; |
Michel Thierry | 09942c6 | 2015-04-08 12:13:30 +0100 | [diff] [blame] | 2092 | ppgtt->base.total = I915_PDES * GEN6_PTES * PAGE_SIZE; |
Ben Widawsky | b146520 | 2014-02-19 22:05:49 -0800 | [diff] [blame] | 2093 | ppgtt->debug_dump = gen6_dump_ppgtt; |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 2094 | |
Mika Kuoppala | 44159dd | 2015-06-25 18:35:07 +0300 | [diff] [blame] | 2095 | ppgtt->pd.base.ggtt_offset = |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 2096 | ppgtt->node.start / PAGE_SIZE * sizeof(gen6_pte_t); |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 2097 | |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 2098 | ppgtt->pd_addr = (gen6_pte_t __iomem *)dev_priv->gtt.gsm + |
Mika Kuoppala | 44159dd | 2015-06-25 18:35:07 +0300 | [diff] [blame] | 2099 | ppgtt->pd.base.ggtt_offset / sizeof(gen6_pte_t); |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 2100 | |
Daniel Vetter | 5c5f645 | 2015-04-14 17:35:14 +0200 | [diff] [blame] | 2101 | gen6_scratch_va_range(ppgtt, 0, ppgtt->base.total); |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 2102 | |
Ben Widawsky | 678d96f | 2015-03-16 16:00:56 +0000 | [diff] [blame] | 2103 | gen6_write_page_range(dev_priv, &ppgtt->pd, 0, ppgtt->base.total); |
| 2104 | |
Thierry Reding | 440fd52 | 2015-01-23 09:05:06 +0100 | [diff] [blame] | 2105 | DRM_DEBUG_DRIVER("Allocated pde space (%lldM) at GTT entry: %llx\n", |
Ben Widawsky | c8d4c0d | 2013-12-06 14:11:07 -0800 | [diff] [blame] | 2106 | ppgtt->node.size >> 20, |
| 2107 | ppgtt->node.start / PAGE_SIZE); |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 2108 | |
Daniel Vetter | fa76da3 | 2014-08-06 20:19:54 +0200 | [diff] [blame] | 2109 | DRM_DEBUG("Adding PPGTT at offset %x\n", |
Mika Kuoppala | 44159dd | 2015-06-25 18:35:07 +0300 | [diff] [blame] | 2110 | ppgtt->pd.base.ggtt_offset << 10); |
Daniel Vetter | fa76da3 | 2014-08-06 20:19:54 +0200 | [diff] [blame] | 2111 | |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 2112 | return 0; |
Daniel Vetter | 3440d26 | 2013-01-24 13:49:56 -0800 | [diff] [blame] | 2113 | } |
| 2114 | |
Daniel Vetter | 5c5f645 | 2015-04-14 17:35:14 +0200 | [diff] [blame] | 2115 | static int __hw_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt) |
Daniel Vetter | 3440d26 | 2013-01-24 13:49:56 -0800 | [diff] [blame] | 2116 | { |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 2117 | ppgtt->base.dev = dev; |
Daniel Vetter | 3440d26 | 2013-01-24 13:49:56 -0800 | [diff] [blame] | 2118 | |
Ben Widawsky | 3ed124b | 2013-04-08 18:43:53 -0700 | [diff] [blame] | 2119 | if (INTEL_INFO(dev)->gen < 8) |
Daniel Vetter | 5c5f645 | 2015-04-14 17:35:14 +0200 | [diff] [blame] | 2120 | return gen6_ppgtt_init(ppgtt); |
Ben Widawsky | 3ed124b | 2013-04-08 18:43:53 -0700 | [diff] [blame] | 2121 | else |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 2122 | return gen8_ppgtt_init(ppgtt); |
Daniel Vetter | fa76da3 | 2014-08-06 20:19:54 +0200 | [diff] [blame] | 2123 | } |
Mika Kuoppala | c114f76 | 2015-06-25 18:35:13 +0300 | [diff] [blame] | 2124 | |
Michał Winiarski | a2cad9d | 2015-09-16 11:49:00 +0200 | [diff] [blame] | 2125 | static void i915_address_space_init(struct i915_address_space *vm, |
| 2126 | struct drm_i915_private *dev_priv) |
| 2127 | { |
| 2128 | drm_mm_init(&vm->mm, vm->start, vm->total); |
| 2129 | vm->dev = dev_priv->dev; |
| 2130 | INIT_LIST_HEAD(&vm->active_list); |
| 2131 | INIT_LIST_HEAD(&vm->inactive_list); |
| 2132 | list_add_tail(&vm->global_link, &dev_priv->vm_list); |
| 2133 | } |
| 2134 | |
Daniel Vetter | fa76da3 | 2014-08-06 20:19:54 +0200 | [diff] [blame] | 2135 | int i915_ppgtt_init(struct drm_device *dev, struct i915_hw_ppgtt *ppgtt) |
| 2136 | { |
| 2137 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2138 | int ret = 0; |
Ben Widawsky | 3ed124b | 2013-04-08 18:43:53 -0700 | [diff] [blame] | 2139 | |
Daniel Vetter | 5c5f645 | 2015-04-14 17:35:14 +0200 | [diff] [blame] | 2140 | ret = __hw_ppgtt_init(dev, ppgtt); |
Daniel Vetter | fa76da3 | 2014-08-06 20:19:54 +0200 | [diff] [blame] | 2141 | if (ret == 0) { |
Ben Widawsky | c7c48df | 2013-12-06 14:11:15 -0800 | [diff] [blame] | 2142 | kref_init(&ppgtt->ref); |
Michał Winiarski | a2cad9d | 2015-09-16 11:49:00 +0200 | [diff] [blame] | 2143 | i915_address_space_init(&ppgtt->base, dev_priv); |
Ben Widawsky | 93bd864 | 2013-07-16 16:50:06 -0700 | [diff] [blame] | 2144 | } |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 2145 | |
| 2146 | return ret; |
| 2147 | } |
| 2148 | |
Daniel Vetter | 82460d9 | 2014-08-06 20:19:53 +0200 | [diff] [blame] | 2149 | int i915_ppgtt_init_hw(struct drm_device *dev) |
| 2150 | { |
Thomas Daniel | 671b5013 | 2014-08-20 16:24:50 +0100 | [diff] [blame] | 2151 | /* In the case of execlists, PPGTT is enabled by the context descriptor |
| 2152 | * and the PDPs are contained within the context itself. We don't |
| 2153 | * need to do anything here. */ |
| 2154 | if (i915.enable_execlists) |
| 2155 | return 0; |
| 2156 | |
Daniel Vetter | 82460d9 | 2014-08-06 20:19:53 +0200 | [diff] [blame] | 2157 | if (!USES_PPGTT(dev)) |
| 2158 | return 0; |
| 2159 | |
| 2160 | if (IS_GEN6(dev)) |
| 2161 | gen6_ppgtt_enable(dev); |
| 2162 | else if (IS_GEN7(dev)) |
| 2163 | gen7_ppgtt_enable(dev); |
| 2164 | else if (INTEL_INFO(dev)->gen >= 8) |
| 2165 | gen8_ppgtt_enable(dev); |
| 2166 | else |
Daniel Vetter | 5f77eeb | 2014-12-08 16:40:10 +0100 | [diff] [blame] | 2167 | MISSING_CASE(INTEL_INFO(dev)->gen); |
Daniel Vetter | 82460d9 | 2014-08-06 20:19:53 +0200 | [diff] [blame] | 2168 | |
John Harrison | 4ad2fd8 | 2015-06-18 13:11:20 +0100 | [diff] [blame] | 2169 | return 0; |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 2170 | } |
John Harrison | 4ad2fd8 | 2015-06-18 13:11:20 +0100 | [diff] [blame] | 2171 | |
John Harrison | b3dd6b9 | 2015-05-29 17:43:40 +0100 | [diff] [blame] | 2172 | int i915_ppgtt_init_ring(struct drm_i915_gem_request *req) |
John Harrison | 4ad2fd8 | 2015-06-18 13:11:20 +0100 | [diff] [blame] | 2173 | { |
John Harrison | b3dd6b9 | 2015-05-29 17:43:40 +0100 | [diff] [blame] | 2174 | struct drm_i915_private *dev_priv = req->ring->dev->dev_private; |
John Harrison | 4ad2fd8 | 2015-06-18 13:11:20 +0100 | [diff] [blame] | 2175 | struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt; |
| 2176 | |
| 2177 | if (i915.enable_execlists) |
| 2178 | return 0; |
| 2179 | |
| 2180 | if (!ppgtt) |
| 2181 | return 0; |
| 2182 | |
John Harrison | e85b26d | 2015-05-29 17:43:56 +0100 | [diff] [blame] | 2183 | return ppgtt->switch_mm(ppgtt, req); |
John Harrison | 4ad2fd8 | 2015-06-18 13:11:20 +0100 | [diff] [blame] | 2184 | } |
| 2185 | |
Daniel Vetter | 4d88470 | 2014-08-06 15:04:47 +0200 | [diff] [blame] | 2186 | struct i915_hw_ppgtt * |
| 2187 | i915_ppgtt_create(struct drm_device *dev, struct drm_i915_file_private *fpriv) |
| 2188 | { |
| 2189 | struct i915_hw_ppgtt *ppgtt; |
| 2190 | int ret; |
| 2191 | |
| 2192 | ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL); |
| 2193 | if (!ppgtt) |
| 2194 | return ERR_PTR(-ENOMEM); |
| 2195 | |
| 2196 | ret = i915_ppgtt_init(dev, ppgtt); |
| 2197 | if (ret) { |
| 2198 | kfree(ppgtt); |
| 2199 | return ERR_PTR(ret); |
| 2200 | } |
| 2201 | |
| 2202 | ppgtt->file_priv = fpriv; |
| 2203 | |
Daniele Ceraolo Spurio | 198c974 | 2014-11-10 13:44:31 +0000 | [diff] [blame] | 2204 | trace_i915_ppgtt_create(&ppgtt->base); |
| 2205 | |
Daniel Vetter | 4d88470 | 2014-08-06 15:04:47 +0200 | [diff] [blame] | 2206 | return ppgtt; |
| 2207 | } |
| 2208 | |
Daniel Vetter | ee960be | 2014-08-06 15:04:45 +0200 | [diff] [blame] | 2209 | void i915_ppgtt_release(struct kref *kref) |
| 2210 | { |
| 2211 | struct i915_hw_ppgtt *ppgtt = |
| 2212 | container_of(kref, struct i915_hw_ppgtt, ref); |
| 2213 | |
Daniele Ceraolo Spurio | 198c974 | 2014-11-10 13:44:31 +0000 | [diff] [blame] | 2214 | trace_i915_ppgtt_release(&ppgtt->base); |
| 2215 | |
Daniel Vetter | ee960be | 2014-08-06 15:04:45 +0200 | [diff] [blame] | 2216 | /* vmas should already be unbound */ |
| 2217 | WARN_ON(!list_empty(&ppgtt->base.active_list)); |
| 2218 | WARN_ON(!list_empty(&ppgtt->base.inactive_list)); |
| 2219 | |
Daniel Vetter | 19dd120 | 2014-08-06 15:04:55 +0200 | [diff] [blame] | 2220 | list_del(&ppgtt->base.global_link); |
| 2221 | drm_mm_takedown(&ppgtt->base.mm); |
| 2222 | |
Daniel Vetter | ee960be | 2014-08-06 15:04:45 +0200 | [diff] [blame] | 2223 | ppgtt->base.cleanup(&ppgtt->base); |
| 2224 | kfree(ppgtt); |
| 2225 | } |
Daniel Vetter | 1d2a314 | 2012-02-09 17:15:46 +0100 | [diff] [blame] | 2226 | |
Ben Widawsky | a81cc00 | 2013-01-18 12:30:31 -0800 | [diff] [blame] | 2227 | extern int intel_iommu_gfx_mapped; |
| 2228 | /* Certain Gen5 chipsets require require idling the GPU before |
| 2229 | * unmapping anything from the GTT when VT-d is enabled. |
| 2230 | */ |
Daniel Vetter | 2c642b0 | 2015-04-14 17:35:26 +0200 | [diff] [blame] | 2231 | static bool needs_idle_maps(struct drm_device *dev) |
Ben Widawsky | a81cc00 | 2013-01-18 12:30:31 -0800 | [diff] [blame] | 2232 | { |
| 2233 | #ifdef CONFIG_INTEL_IOMMU |
| 2234 | /* Query intel_iommu to see if we need the workaround. Presumably that |
| 2235 | * was loaded first. |
| 2236 | */ |
| 2237 | if (IS_GEN5(dev) && IS_MOBILE(dev) && intel_iommu_gfx_mapped) |
| 2238 | return true; |
| 2239 | #endif |
| 2240 | return false; |
| 2241 | } |
| 2242 | |
Ben Widawsky | 5c04228 | 2011-10-17 15:51:55 -0700 | [diff] [blame] | 2243 | static bool do_idling(struct drm_i915_private *dev_priv) |
| 2244 | { |
| 2245 | bool ret = dev_priv->mm.interruptible; |
| 2246 | |
Ben Widawsky | a81cc00 | 2013-01-18 12:30:31 -0800 | [diff] [blame] | 2247 | if (unlikely(dev_priv->gtt.do_idle_maps)) { |
Ben Widawsky | 5c04228 | 2011-10-17 15:51:55 -0700 | [diff] [blame] | 2248 | dev_priv->mm.interruptible = false; |
Ben Widawsky | b2da9fe | 2012-04-26 16:02:58 -0700 | [diff] [blame] | 2249 | if (i915_gpu_idle(dev_priv->dev)) { |
Ben Widawsky | 5c04228 | 2011-10-17 15:51:55 -0700 | [diff] [blame] | 2250 | DRM_ERROR("Couldn't idle GPU\n"); |
| 2251 | /* Wait a bit, in hopes it avoids the hang */ |
| 2252 | udelay(10); |
| 2253 | } |
| 2254 | } |
| 2255 | |
| 2256 | return ret; |
| 2257 | } |
| 2258 | |
| 2259 | static void undo_idling(struct drm_i915_private *dev_priv, bool interruptible) |
| 2260 | { |
Ben Widawsky | a81cc00 | 2013-01-18 12:30:31 -0800 | [diff] [blame] | 2261 | if (unlikely(dev_priv->gtt.do_idle_maps)) |
Ben Widawsky | 5c04228 | 2011-10-17 15:51:55 -0700 | [diff] [blame] | 2262 | dev_priv->mm.interruptible = interruptible; |
| 2263 | } |
| 2264 | |
Ben Widawsky | 828c790 | 2013-10-16 09:21:30 -0700 | [diff] [blame] | 2265 | void i915_check_and_clear_faults(struct drm_device *dev) |
| 2266 | { |
| 2267 | struct drm_i915_private *dev_priv = dev->dev_private; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 2268 | struct intel_engine_cs *ring; |
Ben Widawsky | 828c790 | 2013-10-16 09:21:30 -0700 | [diff] [blame] | 2269 | int i; |
| 2270 | |
| 2271 | if (INTEL_INFO(dev)->gen < 6) |
| 2272 | return; |
| 2273 | |
| 2274 | for_each_ring(ring, dev_priv, i) { |
| 2275 | u32 fault_reg; |
| 2276 | fault_reg = I915_READ(RING_FAULT_REG(ring)); |
| 2277 | if (fault_reg & RING_FAULT_VALID) { |
| 2278 | DRM_DEBUG_DRIVER("Unexpected fault\n" |
Paulo Zanoni | 59a5d29 | 2014-10-30 15:52:45 -0200 | [diff] [blame] | 2279 | "\tAddr: 0x%08lx\n" |
Ben Widawsky | 828c790 | 2013-10-16 09:21:30 -0700 | [diff] [blame] | 2280 | "\tAddress space: %s\n" |
| 2281 | "\tSource ID: %d\n" |
| 2282 | "\tType: %d\n", |
| 2283 | fault_reg & PAGE_MASK, |
| 2284 | fault_reg & RING_FAULT_GTTSEL_MASK ? "GGTT" : "PPGTT", |
| 2285 | RING_FAULT_SRCID(fault_reg), |
| 2286 | RING_FAULT_FAULT_TYPE(fault_reg)); |
| 2287 | I915_WRITE(RING_FAULT_REG(ring), |
| 2288 | fault_reg & ~RING_FAULT_VALID); |
| 2289 | } |
| 2290 | } |
| 2291 | POSTING_READ(RING_FAULT_REG(&dev_priv->ring[RCS])); |
| 2292 | } |
| 2293 | |
Chris Wilson | 91e5649 | 2014-09-25 10:13:12 +0100 | [diff] [blame] | 2294 | static void i915_ggtt_flush(struct drm_i915_private *dev_priv) |
| 2295 | { |
| 2296 | if (INTEL_INFO(dev_priv->dev)->gen < 6) { |
| 2297 | intel_gtt_chipset_flush(); |
| 2298 | } else { |
| 2299 | I915_WRITE(GFX_FLSH_CNTL_GEN6, GFX_FLSH_CNTL_EN); |
| 2300 | POSTING_READ(GFX_FLSH_CNTL_GEN6); |
| 2301 | } |
| 2302 | } |
| 2303 | |
Ben Widawsky | 828c790 | 2013-10-16 09:21:30 -0700 | [diff] [blame] | 2304 | void i915_gem_suspend_gtt_mappings(struct drm_device *dev) |
| 2305 | { |
| 2306 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2307 | |
| 2308 | /* Don't bother messing with faults pre GEN6 as we have little |
| 2309 | * documentation supporting that it's a good idea. |
| 2310 | */ |
| 2311 | if (INTEL_INFO(dev)->gen < 6) |
| 2312 | return; |
| 2313 | |
| 2314 | i915_check_and_clear_faults(dev); |
| 2315 | |
| 2316 | dev_priv->gtt.base.clear_range(&dev_priv->gtt.base, |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 2317 | dev_priv->gtt.base.start, |
| 2318 | dev_priv->gtt.base.total, |
Daniel Vetter | e568af1 | 2014-03-26 20:08:20 +0100 | [diff] [blame] | 2319 | true); |
Chris Wilson | 91e5649 | 2014-09-25 10:13:12 +0100 | [diff] [blame] | 2320 | |
| 2321 | i915_ggtt_flush(dev_priv); |
Ben Widawsky | 828c790 | 2013-10-16 09:21:30 -0700 | [diff] [blame] | 2322 | } |
| 2323 | |
Daniel Vetter | 7416390 | 2012-02-15 23:50:21 +0100 | [diff] [blame] | 2324 | int i915_gem_gtt_prepare_object(struct drm_i915_gem_object *obj) |
Daniel Vetter | 7c2e6fd | 2010-11-06 10:10:47 +0100 | [diff] [blame] | 2325 | { |
Chris Wilson | 9da3da6 | 2012-06-01 15:20:22 +0100 | [diff] [blame] | 2326 | if (!dma_map_sg(&obj->base.dev->pdev->dev, |
| 2327 | obj->pages->sgl, obj->pages->nents, |
| 2328 | PCI_DMA_BIDIRECTIONAL)) |
| 2329 | return -ENOSPC; |
| 2330 | |
| 2331 | return 0; |
Daniel Vetter | 7c2e6fd | 2010-11-06 10:10:47 +0100 | [diff] [blame] | 2332 | } |
| 2333 | |
Daniel Vetter | 2c642b0 | 2015-04-14 17:35:26 +0200 | [diff] [blame] | 2334 | static void gen8_set_pte(void __iomem *addr, gen8_pte_t pte) |
Ben Widawsky | 94ec8f6 | 2013-11-02 21:07:18 -0700 | [diff] [blame] | 2335 | { |
| 2336 | #ifdef writeq |
| 2337 | writeq(pte, addr); |
| 2338 | #else |
| 2339 | iowrite32((u32)pte, addr); |
| 2340 | iowrite32(pte >> 32, addr + 4); |
| 2341 | #endif |
| 2342 | } |
| 2343 | |
| 2344 | static void gen8_ggtt_insert_entries(struct i915_address_space *vm, |
| 2345 | struct sg_table *st, |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 2346 | uint64_t start, |
Akash Goel | 24f3a8c | 2014-06-17 10:59:42 +0530 | [diff] [blame] | 2347 | enum i915_cache_level level, u32 unused) |
Ben Widawsky | 94ec8f6 | 2013-11-02 21:07:18 -0700 | [diff] [blame] | 2348 | { |
| 2349 | struct drm_i915_private *dev_priv = vm->dev->dev_private; |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 2350 | unsigned first_entry = start >> PAGE_SHIFT; |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 2351 | gen8_pte_t __iomem *gtt_entries = |
| 2352 | (gen8_pte_t __iomem *)dev_priv->gtt.gsm + first_entry; |
Ben Widawsky | 94ec8f6 | 2013-11-02 21:07:18 -0700 | [diff] [blame] | 2353 | int i = 0; |
| 2354 | struct sg_page_iter sg_iter; |
Pavel Machek | 57007df | 2014-07-28 13:20:58 +0200 | [diff] [blame] | 2355 | dma_addr_t addr = 0; /* shut up gcc */ |
Imre Deak | be69459 | 2015-12-15 20:10:38 +0200 | [diff] [blame] | 2356 | int rpm_atomic_seq; |
| 2357 | |
| 2358 | rpm_atomic_seq = assert_rpm_atomic_begin(dev_priv); |
Ben Widawsky | 94ec8f6 | 2013-11-02 21:07:18 -0700 | [diff] [blame] | 2359 | |
| 2360 | for_each_sg_page(st->sgl, &sg_iter, st->nents, 0) { |
| 2361 | addr = sg_dma_address(sg_iter.sg) + |
| 2362 | (sg_iter.sg_pgoffset << PAGE_SHIFT); |
| 2363 | gen8_set_pte(>t_entries[i], |
| 2364 | gen8_pte_encode(addr, level, true)); |
| 2365 | i++; |
| 2366 | } |
| 2367 | |
| 2368 | /* |
| 2369 | * XXX: This serves as a posting read to make sure that the PTE has |
| 2370 | * actually been updated. There is some concern that even though |
| 2371 | * registers and PTEs are within the same BAR that they are potentially |
| 2372 | * of NUMA access patterns. Therefore, even with the way we assume |
| 2373 | * hardware should work, we must keep this posting read for paranoia. |
| 2374 | */ |
| 2375 | if (i != 0) |
| 2376 | WARN_ON(readq(>t_entries[i-1]) |
| 2377 | != gen8_pte_encode(addr, level, true)); |
| 2378 | |
Ben Widawsky | 94ec8f6 | 2013-11-02 21:07:18 -0700 | [diff] [blame] | 2379 | /* This next bit makes the above posting read even more important. We |
| 2380 | * want to flush the TLBs only after we're certain all the PTE updates |
| 2381 | * have finished. |
| 2382 | */ |
| 2383 | I915_WRITE(GFX_FLSH_CNTL_GEN6, GFX_FLSH_CNTL_EN); |
| 2384 | POSTING_READ(GFX_FLSH_CNTL_GEN6); |
Imre Deak | be69459 | 2015-12-15 20:10:38 +0200 | [diff] [blame] | 2385 | |
| 2386 | assert_rpm_atomic_end(dev_priv, rpm_atomic_seq); |
Ben Widawsky | 94ec8f6 | 2013-11-02 21:07:18 -0700 | [diff] [blame] | 2387 | } |
| 2388 | |
Chris Wilson | c140330 | 2015-11-18 15:19:39 +0000 | [diff] [blame] | 2389 | struct insert_entries { |
| 2390 | struct i915_address_space *vm; |
| 2391 | struct sg_table *st; |
| 2392 | uint64_t start; |
| 2393 | enum i915_cache_level level; |
| 2394 | u32 flags; |
| 2395 | }; |
| 2396 | |
| 2397 | static int gen8_ggtt_insert_entries__cb(void *_arg) |
| 2398 | { |
| 2399 | struct insert_entries *arg = _arg; |
| 2400 | gen8_ggtt_insert_entries(arg->vm, arg->st, |
| 2401 | arg->start, arg->level, arg->flags); |
| 2402 | return 0; |
| 2403 | } |
| 2404 | |
| 2405 | static void gen8_ggtt_insert_entries__BKL(struct i915_address_space *vm, |
| 2406 | struct sg_table *st, |
| 2407 | uint64_t start, |
| 2408 | enum i915_cache_level level, |
| 2409 | u32 flags) |
| 2410 | { |
| 2411 | struct insert_entries arg = { vm, st, start, level, flags }; |
| 2412 | stop_machine(gen8_ggtt_insert_entries__cb, &arg, NULL); |
| 2413 | } |
| 2414 | |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 2415 | /* |
| 2416 | * Binds an object into the global gtt with the specified cache level. The object |
| 2417 | * will be accessible to the GPU via commands whose operands reference offsets |
| 2418 | * within the global GTT as well as accessible by the GPU through the GMADR |
| 2419 | * mapped BAR (dev_priv->mm.gtt->gtt). |
| 2420 | */ |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 2421 | static void gen6_ggtt_insert_entries(struct i915_address_space *vm, |
Daniel Vetter | 7faf1ab | 2013-01-24 14:44:55 -0800 | [diff] [blame] | 2422 | struct sg_table *st, |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 2423 | uint64_t start, |
Akash Goel | 24f3a8c | 2014-06-17 10:59:42 +0530 | [diff] [blame] | 2424 | enum i915_cache_level level, u32 flags) |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 2425 | { |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 2426 | struct drm_i915_private *dev_priv = vm->dev->dev_private; |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 2427 | unsigned first_entry = start >> PAGE_SHIFT; |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 2428 | gen6_pte_t __iomem *gtt_entries = |
| 2429 | (gen6_pte_t __iomem *)dev_priv->gtt.gsm + first_entry; |
Imre Deak | 6e995e2 | 2013-02-18 19:28:04 +0200 | [diff] [blame] | 2430 | int i = 0; |
| 2431 | struct sg_page_iter sg_iter; |
Pavel Machek | 57007df | 2014-07-28 13:20:58 +0200 | [diff] [blame] | 2432 | dma_addr_t addr = 0; |
Imre Deak | be69459 | 2015-12-15 20:10:38 +0200 | [diff] [blame] | 2433 | int rpm_atomic_seq; |
| 2434 | |
| 2435 | rpm_atomic_seq = assert_rpm_atomic_begin(dev_priv); |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 2436 | |
Imre Deak | 6e995e2 | 2013-02-18 19:28:04 +0200 | [diff] [blame] | 2437 | for_each_sg_page(st->sgl, &sg_iter, st->nents, 0) { |
Imre Deak | 2db76d7 | 2013-03-26 15:14:18 +0200 | [diff] [blame] | 2438 | addr = sg_page_iter_dma_address(&sg_iter); |
Akash Goel | 24f3a8c | 2014-06-17 10:59:42 +0530 | [diff] [blame] | 2439 | iowrite32(vm->pte_encode(addr, level, true, flags), >t_entries[i]); |
Imre Deak | 6e995e2 | 2013-02-18 19:28:04 +0200 | [diff] [blame] | 2440 | i++; |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 2441 | } |
| 2442 | |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 2443 | /* XXX: This serves as a posting read to make sure that the PTE has |
| 2444 | * actually been updated. There is some concern that even though |
| 2445 | * registers and PTEs are within the same BAR that they are potentially |
| 2446 | * of NUMA access patterns. Therefore, even with the way we assume |
| 2447 | * hardware should work, we must keep this posting read for paranoia. |
| 2448 | */ |
Pavel Machek | 57007df | 2014-07-28 13:20:58 +0200 | [diff] [blame] | 2449 | if (i != 0) { |
| 2450 | unsigned long gtt = readl(>t_entries[i-1]); |
| 2451 | WARN_ON(gtt != vm->pte_encode(addr, level, true, flags)); |
| 2452 | } |
Ben Widawsky | 0f9b91c | 2012-11-04 09:21:30 -0800 | [diff] [blame] | 2453 | |
| 2454 | /* This next bit makes the above posting read even more important. We |
| 2455 | * want to flush the TLBs only after we're certain all the PTE updates |
| 2456 | * have finished. |
| 2457 | */ |
| 2458 | I915_WRITE(GFX_FLSH_CNTL_GEN6, GFX_FLSH_CNTL_EN); |
| 2459 | POSTING_READ(GFX_FLSH_CNTL_GEN6); |
Imre Deak | be69459 | 2015-12-15 20:10:38 +0200 | [diff] [blame] | 2460 | |
| 2461 | assert_rpm_atomic_end(dev_priv, rpm_atomic_seq); |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 2462 | } |
| 2463 | |
Ben Widawsky | 94ec8f6 | 2013-11-02 21:07:18 -0700 | [diff] [blame] | 2464 | static void gen8_ggtt_clear_range(struct i915_address_space *vm, |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 2465 | uint64_t start, |
| 2466 | uint64_t length, |
Ben Widawsky | 94ec8f6 | 2013-11-02 21:07:18 -0700 | [diff] [blame] | 2467 | bool use_scratch) |
| 2468 | { |
| 2469 | struct drm_i915_private *dev_priv = vm->dev->dev_private; |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 2470 | unsigned first_entry = start >> PAGE_SHIFT; |
| 2471 | unsigned num_entries = length >> PAGE_SHIFT; |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 2472 | gen8_pte_t scratch_pte, __iomem *gtt_base = |
| 2473 | (gen8_pte_t __iomem *) dev_priv->gtt.gsm + first_entry; |
Ben Widawsky | 94ec8f6 | 2013-11-02 21:07:18 -0700 | [diff] [blame] | 2474 | const int max_entries = gtt_total_entries(dev_priv->gtt) - first_entry; |
| 2475 | int i; |
Imre Deak | be69459 | 2015-12-15 20:10:38 +0200 | [diff] [blame] | 2476 | int rpm_atomic_seq; |
| 2477 | |
| 2478 | rpm_atomic_seq = assert_rpm_atomic_begin(dev_priv); |
Ben Widawsky | 94ec8f6 | 2013-11-02 21:07:18 -0700 | [diff] [blame] | 2479 | |
| 2480 | if (WARN(num_entries > max_entries, |
| 2481 | "First entry = %d; Num entries = %d (max=%d)\n", |
| 2482 | first_entry, num_entries, max_entries)) |
| 2483 | num_entries = max_entries; |
| 2484 | |
Mika Kuoppala | c114f76 | 2015-06-25 18:35:13 +0300 | [diff] [blame] | 2485 | scratch_pte = gen8_pte_encode(px_dma(vm->scratch_page), |
Ben Widawsky | 94ec8f6 | 2013-11-02 21:07:18 -0700 | [diff] [blame] | 2486 | I915_CACHE_LLC, |
| 2487 | use_scratch); |
| 2488 | for (i = 0; i < num_entries; i++) |
| 2489 | gen8_set_pte(>t_base[i], scratch_pte); |
| 2490 | readl(gtt_base); |
Imre Deak | be69459 | 2015-12-15 20:10:38 +0200 | [diff] [blame] | 2491 | |
| 2492 | assert_rpm_atomic_end(dev_priv, rpm_atomic_seq); |
Ben Widawsky | 94ec8f6 | 2013-11-02 21:07:18 -0700 | [diff] [blame] | 2493 | } |
| 2494 | |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 2495 | static void gen6_ggtt_clear_range(struct i915_address_space *vm, |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 2496 | uint64_t start, |
| 2497 | uint64_t length, |
Ben Widawsky | 828c790 | 2013-10-16 09:21:30 -0700 | [diff] [blame] | 2498 | bool use_scratch) |
Daniel Vetter | 7faf1ab | 2013-01-24 14:44:55 -0800 | [diff] [blame] | 2499 | { |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 2500 | struct drm_i915_private *dev_priv = vm->dev->dev_private; |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 2501 | unsigned first_entry = start >> PAGE_SHIFT; |
| 2502 | unsigned num_entries = length >> PAGE_SHIFT; |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 2503 | gen6_pte_t scratch_pte, __iomem *gtt_base = |
| 2504 | (gen6_pte_t __iomem *) dev_priv->gtt.gsm + first_entry; |
Ben Widawsky | a54c0c2 | 2013-01-24 14:45:00 -0800 | [diff] [blame] | 2505 | const int max_entries = gtt_total_entries(dev_priv->gtt) - first_entry; |
Daniel Vetter | 7faf1ab | 2013-01-24 14:44:55 -0800 | [diff] [blame] | 2506 | int i; |
Imre Deak | be69459 | 2015-12-15 20:10:38 +0200 | [diff] [blame] | 2507 | int rpm_atomic_seq; |
| 2508 | |
| 2509 | rpm_atomic_seq = assert_rpm_atomic_begin(dev_priv); |
Daniel Vetter | 7faf1ab | 2013-01-24 14:44:55 -0800 | [diff] [blame] | 2510 | |
| 2511 | if (WARN(num_entries > max_entries, |
| 2512 | "First entry = %d; Num entries = %d (max=%d)\n", |
| 2513 | first_entry, num_entries, max_entries)) |
| 2514 | num_entries = max_entries; |
| 2515 | |
Mika Kuoppala | c114f76 | 2015-06-25 18:35:13 +0300 | [diff] [blame] | 2516 | scratch_pte = vm->pte_encode(px_dma(vm->scratch_page), |
| 2517 | I915_CACHE_LLC, use_scratch, 0); |
Ben Widawsky | 828c790 | 2013-10-16 09:21:30 -0700 | [diff] [blame] | 2518 | |
Daniel Vetter | 7faf1ab | 2013-01-24 14:44:55 -0800 | [diff] [blame] | 2519 | for (i = 0; i < num_entries; i++) |
| 2520 | iowrite32(scratch_pte, >t_base[i]); |
| 2521 | readl(gtt_base); |
Imre Deak | be69459 | 2015-12-15 20:10:38 +0200 | [diff] [blame] | 2522 | |
| 2523 | assert_rpm_atomic_end(dev_priv, rpm_atomic_seq); |
Daniel Vetter | 7faf1ab | 2013-01-24 14:44:55 -0800 | [diff] [blame] | 2524 | } |
| 2525 | |
Daniel Vetter | d369d2d | 2015-04-14 17:35:25 +0200 | [diff] [blame] | 2526 | static void i915_ggtt_insert_entries(struct i915_address_space *vm, |
| 2527 | struct sg_table *pages, |
| 2528 | uint64_t start, |
| 2529 | enum i915_cache_level cache_level, u32 unused) |
Daniel Vetter | 7faf1ab | 2013-01-24 14:44:55 -0800 | [diff] [blame] | 2530 | { |
Imre Deak | be69459 | 2015-12-15 20:10:38 +0200 | [diff] [blame] | 2531 | struct drm_i915_private *dev_priv = vm->dev->dev_private; |
Daniel Vetter | 7faf1ab | 2013-01-24 14:44:55 -0800 | [diff] [blame] | 2532 | unsigned int flags = (cache_level == I915_CACHE_NONE) ? |
| 2533 | AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY; |
Imre Deak | be69459 | 2015-12-15 20:10:38 +0200 | [diff] [blame] | 2534 | int rpm_atomic_seq; |
| 2535 | |
| 2536 | rpm_atomic_seq = assert_rpm_atomic_begin(dev_priv); |
Daniel Vetter | 7faf1ab | 2013-01-24 14:44:55 -0800 | [diff] [blame] | 2537 | |
Daniel Vetter | d369d2d | 2015-04-14 17:35:25 +0200 | [diff] [blame] | 2538 | intel_gtt_insert_sg_entries(pages, start >> PAGE_SHIFT, flags); |
Daniel Vetter | 0875546 | 2015-04-20 09:04:05 -0700 | [diff] [blame] | 2539 | |
Imre Deak | be69459 | 2015-12-15 20:10:38 +0200 | [diff] [blame] | 2540 | assert_rpm_atomic_end(dev_priv, rpm_atomic_seq); |
| 2541 | |
Daniel Vetter | 7faf1ab | 2013-01-24 14:44:55 -0800 | [diff] [blame] | 2542 | } |
| 2543 | |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 2544 | static void i915_ggtt_clear_range(struct i915_address_space *vm, |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 2545 | uint64_t start, |
| 2546 | uint64_t length, |
Ben Widawsky | 828c790 | 2013-10-16 09:21:30 -0700 | [diff] [blame] | 2547 | bool unused) |
Daniel Vetter | 7faf1ab | 2013-01-24 14:44:55 -0800 | [diff] [blame] | 2548 | { |
Imre Deak | be69459 | 2015-12-15 20:10:38 +0200 | [diff] [blame] | 2549 | struct drm_i915_private *dev_priv = vm->dev->dev_private; |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 2550 | unsigned first_entry = start >> PAGE_SHIFT; |
| 2551 | unsigned num_entries = length >> PAGE_SHIFT; |
Imre Deak | be69459 | 2015-12-15 20:10:38 +0200 | [diff] [blame] | 2552 | int rpm_atomic_seq; |
| 2553 | |
| 2554 | rpm_atomic_seq = assert_rpm_atomic_begin(dev_priv); |
| 2555 | |
Daniel Vetter | 7faf1ab | 2013-01-24 14:44:55 -0800 | [diff] [blame] | 2556 | intel_gtt_clear_range(first_entry, num_entries); |
Imre Deak | be69459 | 2015-12-15 20:10:38 +0200 | [diff] [blame] | 2557 | |
| 2558 | assert_rpm_atomic_end(dev_priv, rpm_atomic_seq); |
Daniel Vetter | 7faf1ab | 2013-01-24 14:44:55 -0800 | [diff] [blame] | 2559 | } |
| 2560 | |
Daniel Vetter | 70b9f6f | 2015-04-14 17:35:27 +0200 | [diff] [blame] | 2561 | static int ggtt_bind_vma(struct i915_vma *vma, |
| 2562 | enum i915_cache_level cache_level, |
| 2563 | u32 flags) |
Daniel Vetter | 7c2e6fd | 2010-11-06 10:10:47 +0100 | [diff] [blame] | 2564 | { |
Daniel Vetter | 0a87871 | 2015-10-15 14:23:01 +0200 | [diff] [blame] | 2565 | struct drm_i915_gem_object *obj = vma->obj; |
| 2566 | u32 pte_flags = 0; |
| 2567 | int ret; |
| 2568 | |
| 2569 | ret = i915_get_ggtt_vma_pages(vma); |
| 2570 | if (ret) |
| 2571 | return ret; |
| 2572 | |
| 2573 | /* Currently applicable only to VLV */ |
| 2574 | if (obj->gt_ro) |
| 2575 | pte_flags |= PTE_READ_ONLY; |
| 2576 | |
| 2577 | vma->vm->insert_entries(vma->vm, vma->ggtt_view.pages, |
| 2578 | vma->node.start, |
| 2579 | cache_level, pte_flags); |
| 2580 | |
| 2581 | /* |
| 2582 | * Without aliasing PPGTT there's no difference between |
| 2583 | * GLOBAL/LOCAL_BIND, it's all the same ptes. Hence unconditionally |
| 2584 | * upgrade to both bound if we bind either to avoid double-binding. |
| 2585 | */ |
| 2586 | vma->bound |= GLOBAL_BIND | LOCAL_BIND; |
| 2587 | |
| 2588 | return 0; |
| 2589 | } |
| 2590 | |
| 2591 | static int aliasing_gtt_bind_vma(struct i915_vma *vma, |
| 2592 | enum i915_cache_level cache_level, |
| 2593 | u32 flags) |
| 2594 | { |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 2595 | struct drm_device *dev = vma->vm->dev; |
Daniel Vetter | 7faf1ab | 2013-01-24 14:44:55 -0800 | [diff] [blame] | 2596 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 2597 | struct drm_i915_gem_object *obj = vma->obj; |
Joonas Lahtinen | ec7adb6 | 2015-03-16 14:11:13 +0200 | [diff] [blame] | 2598 | struct sg_table *pages = obj->pages; |
Daniel Vetter | f329f5f | 2015-04-14 17:35:15 +0200 | [diff] [blame] | 2599 | u32 pte_flags = 0; |
Daniel Vetter | 70b9f6f | 2015-04-14 17:35:27 +0200 | [diff] [blame] | 2600 | int ret; |
| 2601 | |
| 2602 | ret = i915_get_ggtt_vma_pages(vma); |
| 2603 | if (ret) |
| 2604 | return ret; |
| 2605 | pages = vma->ggtt_view.pages; |
Daniel Vetter | 7faf1ab | 2013-01-24 14:44:55 -0800 | [diff] [blame] | 2606 | |
Akash Goel | 24f3a8c | 2014-06-17 10:59:42 +0530 | [diff] [blame] | 2607 | /* Currently applicable only to VLV */ |
| 2608 | if (obj->gt_ro) |
Daniel Vetter | f329f5f | 2015-04-14 17:35:15 +0200 | [diff] [blame] | 2609 | pte_flags |= PTE_READ_ONLY; |
Akash Goel | 24f3a8c | 2014-06-17 10:59:42 +0530 | [diff] [blame] | 2610 | |
Joonas Lahtinen | ec7adb6 | 2015-03-16 14:11:13 +0200 | [diff] [blame] | 2611 | |
Daniel Vetter | 0a87871 | 2015-10-15 14:23:01 +0200 | [diff] [blame] | 2612 | if (flags & GLOBAL_BIND) { |
Daniel Vetter | 0875546 | 2015-04-20 09:04:05 -0700 | [diff] [blame] | 2613 | vma->vm->insert_entries(vma->vm, pages, |
| 2614 | vma->node.start, |
| 2615 | cache_level, pte_flags); |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 2616 | } |
Daniel Vetter | 74898d7 | 2012-02-15 23:50:22 +0100 | [diff] [blame] | 2617 | |
Daniel Vetter | 0a87871 | 2015-10-15 14:23:01 +0200 | [diff] [blame] | 2618 | if (flags & LOCAL_BIND) { |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 2619 | struct i915_hw_ppgtt *appgtt = dev_priv->mm.aliasing_ppgtt; |
Joonas Lahtinen | ec7adb6 | 2015-03-16 14:11:13 +0200 | [diff] [blame] | 2620 | appgtt->base.insert_entries(&appgtt->base, pages, |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 2621 | vma->node.start, |
Daniel Vetter | f329f5f | 2015-04-14 17:35:15 +0200 | [diff] [blame] | 2622 | cache_level, pte_flags); |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 2623 | } |
Daniel Vetter | 70b9f6f | 2015-04-14 17:35:27 +0200 | [diff] [blame] | 2624 | |
| 2625 | return 0; |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 2626 | } |
| 2627 | |
| 2628 | static void ggtt_unbind_vma(struct i915_vma *vma) |
| 2629 | { |
| 2630 | struct drm_device *dev = vma->vm->dev; |
| 2631 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2632 | struct drm_i915_gem_object *obj = vma->obj; |
Joonas Lahtinen | 06615ee | 2015-04-24 15:09:03 +0300 | [diff] [blame] | 2633 | const uint64_t size = min_t(uint64_t, |
| 2634 | obj->base.size, |
| 2635 | vma->node.size); |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 2636 | |
Tvrtko Ursulin | aff4376 | 2014-10-24 12:42:33 +0100 | [diff] [blame] | 2637 | if (vma->bound & GLOBAL_BIND) { |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 2638 | vma->vm->clear_range(vma->vm, |
| 2639 | vma->node.start, |
Joonas Lahtinen | 06615ee | 2015-04-24 15:09:03 +0300 | [diff] [blame] | 2640 | size, |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 2641 | true); |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 2642 | } |
| 2643 | |
Daniel Vetter | 0875546 | 2015-04-20 09:04:05 -0700 | [diff] [blame] | 2644 | if (dev_priv->mm.aliasing_ppgtt && vma->bound & LOCAL_BIND) { |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 2645 | struct i915_hw_ppgtt *appgtt = dev_priv->mm.aliasing_ppgtt; |
Joonas Lahtinen | 06615ee | 2015-04-24 15:09:03 +0300 | [diff] [blame] | 2646 | |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 2647 | appgtt->base.clear_range(&appgtt->base, |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 2648 | vma->node.start, |
Joonas Lahtinen | 06615ee | 2015-04-24 15:09:03 +0300 | [diff] [blame] | 2649 | size, |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 2650 | true); |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 2651 | } |
Daniel Vetter | 7416390 | 2012-02-15 23:50:21 +0100 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | void i915_gem_gtt_finish_object(struct drm_i915_gem_object *obj) |
| 2655 | { |
Ben Widawsky | 5c04228 | 2011-10-17 15:51:55 -0700 | [diff] [blame] | 2656 | struct drm_device *dev = obj->base.dev; |
| 2657 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2658 | bool interruptible; |
| 2659 | |
| 2660 | interruptible = do_idling(dev_priv); |
| 2661 | |
Imre Deak | 5ec5b51 | 2015-07-08 19:18:59 +0300 | [diff] [blame] | 2662 | dma_unmap_sg(&dev->pdev->dev, obj->pages->sgl, obj->pages->nents, |
| 2663 | PCI_DMA_BIDIRECTIONAL); |
Ben Widawsky | 5c04228 | 2011-10-17 15:51:55 -0700 | [diff] [blame] | 2664 | |
| 2665 | undo_idling(dev_priv, interruptible); |
Daniel Vetter | 7c2e6fd | 2010-11-06 10:10:47 +0100 | [diff] [blame] | 2666 | } |
Daniel Vetter | 644ec02 | 2012-03-26 09:45:40 +0200 | [diff] [blame] | 2667 | |
Chris Wilson | 42d6ab4 | 2012-07-26 11:49:32 +0100 | [diff] [blame] | 2668 | static void i915_gtt_color_adjust(struct drm_mm_node *node, |
| 2669 | unsigned long color, |
Thierry Reding | 440fd52 | 2015-01-23 09:05:06 +0100 | [diff] [blame] | 2670 | u64 *start, |
| 2671 | u64 *end) |
Chris Wilson | 42d6ab4 | 2012-07-26 11:49:32 +0100 | [diff] [blame] | 2672 | { |
| 2673 | if (node->color != color) |
| 2674 | *start += 4096; |
| 2675 | |
| 2676 | if (!list_empty(&node->node_list)) { |
| 2677 | node = list_entry(node->node_list.next, |
| 2678 | struct drm_mm_node, |
| 2679 | node_list); |
| 2680 | if (node->allocated && node->color != color) |
| 2681 | *end -= 4096; |
| 2682 | } |
| 2683 | } |
Ben Widawsky | fbe5d36 | 2013-11-04 19:56:49 -0800 | [diff] [blame] | 2684 | |
Daniel Vetter | f548c0e | 2014-11-19 21:40:13 +0100 | [diff] [blame] | 2685 | static int i915_gem_setup_global_gtt(struct drm_device *dev, |
Michel Thierry | 088e0df | 2015-08-07 17:40:17 +0100 | [diff] [blame] | 2686 | u64 start, |
| 2687 | u64 mappable_end, |
| 2688 | u64 end) |
Daniel Vetter | 644ec02 | 2012-03-26 09:45:40 +0200 | [diff] [blame] | 2689 | { |
Ben Widawsky | e78891c | 2013-01-25 16:41:04 -0800 | [diff] [blame] | 2690 | /* Let GEM Manage all of the aperture. |
| 2691 | * |
| 2692 | * However, leave one page at the end still bound to the scratch page. |
| 2693 | * There are a number of places where the hardware apparently prefetches |
| 2694 | * past the end of the object, and we've seen multiple hangs with the |
| 2695 | * GPU head pointer stuck in a batchbuffer bound at the last page of the |
| 2696 | * aperture. One page should be enough to keep any prefetching inside |
| 2697 | * of the aperture. |
| 2698 | */ |
Ben Widawsky | 40d74980 | 2013-07-31 16:59:59 -0700 | [diff] [blame] | 2699 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2700 | struct i915_address_space *ggtt_vm = &dev_priv->gtt.base; |
Chris Wilson | ed2f345 | 2012-11-15 11:32:19 +0000 | [diff] [blame] | 2701 | struct drm_mm_node *entry; |
| 2702 | struct drm_i915_gem_object *obj; |
| 2703 | unsigned long hole_start, hole_end; |
Daniel Vetter | fa76da3 | 2014-08-06 20:19:54 +0200 | [diff] [blame] | 2704 | int ret; |
Daniel Vetter | 644ec02 | 2012-03-26 09:45:40 +0200 | [diff] [blame] | 2705 | |
Ben Widawsky | 35451cb | 2013-01-17 12:45:13 -0800 | [diff] [blame] | 2706 | BUG_ON(mappable_end > end); |
| 2707 | |
Michał Winiarski | a2cad9d | 2015-09-16 11:49:00 +0200 | [diff] [blame] | 2708 | ggtt_vm->start = start; |
Yu Zhang | 5dda8fa | 2015-02-10 19:05:48 +0800 | [diff] [blame] | 2709 | |
Michał Winiarski | a2cad9d | 2015-09-16 11:49:00 +0200 | [diff] [blame] | 2710 | /* Subtract the guard page before address space initialization to |
| 2711 | * shrink the range used by drm_mm */ |
| 2712 | ggtt_vm->total = end - start - PAGE_SIZE; |
| 2713 | i915_address_space_init(ggtt_vm, dev_priv); |
| 2714 | ggtt_vm->total += PAGE_SIZE; |
Yu Zhang | 5dda8fa | 2015-02-10 19:05:48 +0800 | [diff] [blame] | 2715 | |
| 2716 | if (intel_vgpu_active(dev)) { |
| 2717 | ret = intel_vgt_balloon(dev); |
| 2718 | if (ret) |
| 2719 | return ret; |
| 2720 | } |
| 2721 | |
Chris Wilson | 42d6ab4 | 2012-07-26 11:49:32 +0100 | [diff] [blame] | 2722 | if (!HAS_LLC(dev)) |
Michał Winiarski | a2cad9d | 2015-09-16 11:49:00 +0200 | [diff] [blame] | 2723 | ggtt_vm->mm.color_adjust = i915_gtt_color_adjust; |
Daniel Vetter | 644ec02 | 2012-03-26 09:45:40 +0200 | [diff] [blame] | 2724 | |
Chris Wilson | ed2f345 | 2012-11-15 11:32:19 +0000 | [diff] [blame] | 2725 | /* Mark any preallocated objects as occupied */ |
Ben Widawsky | 35c20a6 | 2013-05-31 11:28:48 -0700 | [diff] [blame] | 2726 | list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) { |
Ben Widawsky | 40d74980 | 2013-07-31 16:59:59 -0700 | [diff] [blame] | 2727 | struct i915_vma *vma = i915_gem_obj_to_vma(obj, ggtt_vm); |
Daniel Vetter | fa76da3 | 2014-08-06 20:19:54 +0200 | [diff] [blame] | 2728 | |
Michel Thierry | 088e0df | 2015-08-07 17:40:17 +0100 | [diff] [blame] | 2729 | DRM_DEBUG_KMS("reserving preallocated space: %llx + %zx\n", |
Ben Widawsky | c6cfb32 | 2013-07-05 14:41:06 -0700 | [diff] [blame] | 2730 | i915_gem_obj_ggtt_offset(obj), obj->base.size); |
Chris Wilson | ed2f345 | 2012-11-15 11:32:19 +0000 | [diff] [blame] | 2731 | |
Ben Widawsky | c6cfb32 | 2013-07-05 14:41:06 -0700 | [diff] [blame] | 2732 | WARN_ON(i915_gem_obj_ggtt_bound(obj)); |
Ben Widawsky | 40d74980 | 2013-07-31 16:59:59 -0700 | [diff] [blame] | 2733 | ret = drm_mm_reserve_node(&ggtt_vm->mm, &vma->node); |
Daniel Vetter | 6c5566a | 2014-08-06 15:04:50 +0200 | [diff] [blame] | 2734 | if (ret) { |
| 2735 | DRM_DEBUG_KMS("Reservation failed: %i\n", ret); |
| 2736 | return ret; |
| 2737 | } |
Tvrtko Ursulin | aff4376 | 2014-10-24 12:42:33 +0100 | [diff] [blame] | 2738 | vma->bound |= GLOBAL_BIND; |
Chris Wilson | d0710ab | 2015-11-20 14:16:39 +0000 | [diff] [blame] | 2739 | __i915_vma_set_map_and_fenceable(vma); |
Chris Wilson | 7c4a7d6 | 2015-09-24 11:57:45 +0100 | [diff] [blame] | 2740 | list_add_tail(&vma->mm_list, &ggtt_vm->inactive_list); |
Chris Wilson | ed2f345 | 2012-11-15 11:32:19 +0000 | [diff] [blame] | 2741 | } |
| 2742 | |
Chris Wilson | ed2f345 | 2012-11-15 11:32:19 +0000 | [diff] [blame] | 2743 | /* Clear any non-preallocated blocks */ |
Ben Widawsky | 40d74980 | 2013-07-31 16:59:59 -0700 | [diff] [blame] | 2744 | drm_mm_for_each_hole(entry, &ggtt_vm->mm, hole_start, hole_end) { |
Chris Wilson | ed2f345 | 2012-11-15 11:32:19 +0000 | [diff] [blame] | 2745 | DRM_DEBUG_KMS("clearing unused GTT space: [%lx, %lx]\n", |
| 2746 | hole_start, hole_end); |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 2747 | ggtt_vm->clear_range(ggtt_vm, hole_start, |
| 2748 | hole_end - hole_start, true); |
Chris Wilson | ed2f345 | 2012-11-15 11:32:19 +0000 | [diff] [blame] | 2749 | } |
| 2750 | |
| 2751 | /* And finally clear the reserved guard page */ |
Ben Widawsky | 782f149 | 2014-02-20 11:50:33 -0800 | [diff] [blame] | 2752 | ggtt_vm->clear_range(ggtt_vm, end - PAGE_SIZE, PAGE_SIZE, true); |
Daniel Vetter | 6c5566a | 2014-08-06 15:04:50 +0200 | [diff] [blame] | 2753 | |
Daniel Vetter | fa76da3 | 2014-08-06 20:19:54 +0200 | [diff] [blame] | 2754 | if (USES_PPGTT(dev) && !USES_FULL_PPGTT(dev)) { |
| 2755 | struct i915_hw_ppgtt *ppgtt; |
| 2756 | |
| 2757 | ppgtt = kzalloc(sizeof(*ppgtt), GFP_KERNEL); |
| 2758 | if (!ppgtt) |
| 2759 | return -ENOMEM; |
| 2760 | |
Daniel Vetter | 5c5f645 | 2015-04-14 17:35:14 +0200 | [diff] [blame] | 2761 | ret = __hw_ppgtt_init(dev, ppgtt); |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 2762 | if (ret) { |
Daniel Vetter | 061dd49 | 2015-04-14 17:35:13 +0200 | [diff] [blame] | 2763 | ppgtt->base.cleanup(&ppgtt->base); |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 2764 | kfree(ppgtt); |
Daniel Vetter | fa76da3 | 2014-08-06 20:19:54 +0200 | [diff] [blame] | 2765 | return ret; |
Michel Thierry | 4933d51 | 2015-03-24 15:46:22 +0000 | [diff] [blame] | 2766 | } |
Daniel Vetter | fa76da3 | 2014-08-06 20:19:54 +0200 | [diff] [blame] | 2767 | |
Daniel Vetter | 5c5f645 | 2015-04-14 17:35:14 +0200 | [diff] [blame] | 2768 | if (ppgtt->base.allocate_va_range) |
| 2769 | ret = ppgtt->base.allocate_va_range(&ppgtt->base, 0, |
| 2770 | ppgtt->base.total); |
| 2771 | if (ret) { |
| 2772 | ppgtt->base.cleanup(&ppgtt->base); |
| 2773 | kfree(ppgtt); |
| 2774 | return ret; |
| 2775 | } |
| 2776 | |
| 2777 | ppgtt->base.clear_range(&ppgtt->base, |
| 2778 | ppgtt->base.start, |
| 2779 | ppgtt->base.total, |
| 2780 | true); |
| 2781 | |
Daniel Vetter | fa76da3 | 2014-08-06 20:19:54 +0200 | [diff] [blame] | 2782 | dev_priv->mm.aliasing_ppgtt = ppgtt; |
Daniel Vetter | 0a87871 | 2015-10-15 14:23:01 +0200 | [diff] [blame] | 2783 | WARN_ON(dev_priv->gtt.base.bind_vma != ggtt_bind_vma); |
| 2784 | dev_priv->gtt.base.bind_vma = aliasing_gtt_bind_vma; |
Daniel Vetter | fa76da3 | 2014-08-06 20:19:54 +0200 | [diff] [blame] | 2785 | } |
| 2786 | |
Daniel Vetter | 6c5566a | 2014-08-06 15:04:50 +0200 | [diff] [blame] | 2787 | return 0; |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 2788 | } |
| 2789 | |
Ben Widawsky | d7e5008 | 2012-12-18 10:31:25 -0800 | [diff] [blame] | 2790 | void i915_gem_init_global_gtt(struct drm_device *dev) |
| 2791 | { |
| 2792 | struct drm_i915_private *dev_priv = dev->dev_private; |
Mika Kuoppala | c44ef60 | 2015-06-25 18:35:05 +0300 | [diff] [blame] | 2793 | u64 gtt_size, mappable_size; |
Ben Widawsky | d7e5008 | 2012-12-18 10:31:25 -0800 | [diff] [blame] | 2794 | |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 2795 | gtt_size = dev_priv->gtt.base.total; |
Ben Widawsky | 93d1879 | 2013-01-17 12:45:17 -0800 | [diff] [blame] | 2796 | mappable_size = dev_priv->gtt.mappable_end; |
Ben Widawsky | d7e5008 | 2012-12-18 10:31:25 -0800 | [diff] [blame] | 2797 | |
Ben Widawsky | e78891c | 2013-01-25 16:41:04 -0800 | [diff] [blame] | 2798 | i915_gem_setup_global_gtt(dev, 0, mappable_size, gtt_size); |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 2799 | } |
| 2800 | |
Daniel Vetter | 90d0a0e | 2014-08-06 15:04:56 +0200 | [diff] [blame] | 2801 | void i915_global_gtt_cleanup(struct drm_device *dev) |
| 2802 | { |
| 2803 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2804 | struct i915_address_space *vm = &dev_priv->gtt.base; |
| 2805 | |
Daniel Vetter | 70e3254 | 2014-08-06 15:04:57 +0200 | [diff] [blame] | 2806 | if (dev_priv->mm.aliasing_ppgtt) { |
| 2807 | struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt; |
| 2808 | |
| 2809 | ppgtt->base.cleanup(&ppgtt->base); |
| 2810 | } |
| 2811 | |
Imre Deak | a4eba47 | 2016-01-19 15:26:32 +0200 | [diff] [blame] | 2812 | i915_gem_cleanup_stolen(dev); |
| 2813 | |
Daniel Vetter | 90d0a0e | 2014-08-06 15:04:56 +0200 | [diff] [blame] | 2814 | if (drm_mm_initialized(&vm->mm)) { |
Yu Zhang | 5dda8fa | 2015-02-10 19:05:48 +0800 | [diff] [blame] | 2815 | if (intel_vgpu_active(dev)) |
| 2816 | intel_vgt_deballoon(); |
| 2817 | |
Daniel Vetter | 90d0a0e | 2014-08-06 15:04:56 +0200 | [diff] [blame] | 2818 | drm_mm_takedown(&vm->mm); |
| 2819 | list_del(&vm->global_link); |
| 2820 | } |
| 2821 | |
| 2822 | vm->cleanup(vm); |
| 2823 | } |
Daniel Vetter | 70e3254 | 2014-08-06 15:04:57 +0200 | [diff] [blame] | 2824 | |
Daniel Vetter | 2c642b0 | 2015-04-14 17:35:26 +0200 | [diff] [blame] | 2825 | static unsigned int gen6_get_total_gtt_size(u16 snb_gmch_ctl) |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 2826 | { |
| 2827 | snb_gmch_ctl >>= SNB_GMCH_GGMS_SHIFT; |
| 2828 | snb_gmch_ctl &= SNB_GMCH_GGMS_MASK; |
| 2829 | return snb_gmch_ctl << 20; |
| 2830 | } |
| 2831 | |
Daniel Vetter | 2c642b0 | 2015-04-14 17:35:26 +0200 | [diff] [blame] | 2832 | static unsigned int gen8_get_total_gtt_size(u16 bdw_gmch_ctl) |
Ben Widawsky | 9459d25 | 2013-11-03 16:53:55 -0800 | [diff] [blame] | 2833 | { |
| 2834 | bdw_gmch_ctl >>= BDW_GMCH_GGMS_SHIFT; |
| 2835 | bdw_gmch_ctl &= BDW_GMCH_GGMS_MASK; |
| 2836 | if (bdw_gmch_ctl) |
| 2837 | bdw_gmch_ctl = 1 << bdw_gmch_ctl; |
Ben Widawsky | 562d55d | 2014-05-27 16:53:08 -0700 | [diff] [blame] | 2838 | |
| 2839 | #ifdef CONFIG_X86_32 |
| 2840 | /* Limit 32b platforms to a 2GB GGTT: 4 << 20 / pte size * PAGE_SIZE */ |
| 2841 | if (bdw_gmch_ctl > 4) |
| 2842 | bdw_gmch_ctl = 4; |
| 2843 | #endif |
| 2844 | |
Ben Widawsky | 9459d25 | 2013-11-03 16:53:55 -0800 | [diff] [blame] | 2845 | return bdw_gmch_ctl << 20; |
| 2846 | } |
| 2847 | |
Daniel Vetter | 2c642b0 | 2015-04-14 17:35:26 +0200 | [diff] [blame] | 2848 | static unsigned int chv_get_total_gtt_size(u16 gmch_ctrl) |
Damien Lespiau | d7f25f2 | 2014-05-08 22:19:40 +0300 | [diff] [blame] | 2849 | { |
| 2850 | gmch_ctrl >>= SNB_GMCH_GGMS_SHIFT; |
| 2851 | gmch_ctrl &= SNB_GMCH_GGMS_MASK; |
| 2852 | |
| 2853 | if (gmch_ctrl) |
| 2854 | return 1 << (20 + gmch_ctrl); |
| 2855 | |
| 2856 | return 0; |
| 2857 | } |
| 2858 | |
Daniel Vetter | 2c642b0 | 2015-04-14 17:35:26 +0200 | [diff] [blame] | 2859 | static size_t gen6_get_stolen_size(u16 snb_gmch_ctl) |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 2860 | { |
| 2861 | snb_gmch_ctl >>= SNB_GMCH_GMS_SHIFT; |
| 2862 | snb_gmch_ctl &= SNB_GMCH_GMS_MASK; |
| 2863 | return snb_gmch_ctl << 25; /* 32 MB units */ |
| 2864 | } |
| 2865 | |
Daniel Vetter | 2c642b0 | 2015-04-14 17:35:26 +0200 | [diff] [blame] | 2866 | static size_t gen8_get_stolen_size(u16 bdw_gmch_ctl) |
Ben Widawsky | 9459d25 | 2013-11-03 16:53:55 -0800 | [diff] [blame] | 2867 | { |
| 2868 | bdw_gmch_ctl >>= BDW_GMCH_GMS_SHIFT; |
| 2869 | bdw_gmch_ctl &= BDW_GMCH_GMS_MASK; |
| 2870 | return bdw_gmch_ctl << 25; /* 32 MB units */ |
| 2871 | } |
| 2872 | |
Damien Lespiau | d7f25f2 | 2014-05-08 22:19:40 +0300 | [diff] [blame] | 2873 | static size_t chv_get_stolen_size(u16 gmch_ctrl) |
| 2874 | { |
| 2875 | gmch_ctrl >>= SNB_GMCH_GMS_SHIFT; |
| 2876 | gmch_ctrl &= SNB_GMCH_GMS_MASK; |
| 2877 | |
| 2878 | /* |
| 2879 | * 0x0 to 0x10: 32MB increments starting at 0MB |
| 2880 | * 0x11 to 0x16: 4MB increments starting at 8MB |
| 2881 | * 0x17 to 0x1d: 4MB increments start at 36MB |
| 2882 | */ |
| 2883 | if (gmch_ctrl < 0x11) |
| 2884 | return gmch_ctrl << 25; |
| 2885 | else if (gmch_ctrl < 0x17) |
| 2886 | return (gmch_ctrl - 0x11 + 2) << 22; |
| 2887 | else |
| 2888 | return (gmch_ctrl - 0x17 + 9) << 22; |
| 2889 | } |
| 2890 | |
Damien Lespiau | 6637501 | 2014-01-09 18:02:46 +0000 | [diff] [blame] | 2891 | static size_t gen9_get_stolen_size(u16 gen9_gmch_ctl) |
| 2892 | { |
| 2893 | gen9_gmch_ctl >>= BDW_GMCH_GMS_SHIFT; |
| 2894 | gen9_gmch_ctl &= BDW_GMCH_GMS_MASK; |
| 2895 | |
| 2896 | if (gen9_gmch_ctl < 0xf0) |
| 2897 | return gen9_gmch_ctl << 25; /* 32 MB units */ |
| 2898 | else |
| 2899 | /* 4MB increments starting at 0xf0 for 4MB */ |
| 2900 | return (gen9_gmch_ctl - 0xf0 + 1) << 22; |
| 2901 | } |
| 2902 | |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 2903 | static int ggtt_probe_common(struct drm_device *dev, |
| 2904 | size_t gtt_size) |
| 2905 | { |
| 2906 | struct drm_i915_private *dev_priv = dev->dev_private; |
Mika Kuoppala | 4ad2af1 | 2015-06-30 18:16:39 +0300 | [diff] [blame] | 2907 | struct i915_page_scratch *scratch_page; |
Bjorn Helgaas | 21c3460 | 2013-12-21 10:52:52 -0700 | [diff] [blame] | 2908 | phys_addr_t gtt_phys_addr; |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 2909 | |
| 2910 | /* For Modern GENs the PTEs and register space are split in the BAR */ |
Bjorn Helgaas | 21c3460 | 2013-12-21 10:52:52 -0700 | [diff] [blame] | 2911 | gtt_phys_addr = pci_resource_start(dev->pdev, 0) + |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 2912 | (pci_resource_len(dev->pdev, 0) / 2); |
| 2913 | |
Imre Deak | 2a073f89 | 2015-03-27 13:07:33 +0200 | [diff] [blame] | 2914 | /* |
| 2915 | * On BXT writes larger than 64 bit to the GTT pagetable range will be |
| 2916 | * dropped. For WC mappings in general we have 64 byte burst writes |
| 2917 | * when the WC buffer is flushed, so we can't use it, but have to |
| 2918 | * resort to an uncached mapping. The WC issue is easily caught by the |
| 2919 | * readback check when writing GTT PTE entries. |
| 2920 | */ |
| 2921 | if (IS_BROXTON(dev)) |
| 2922 | dev_priv->gtt.gsm = ioremap_nocache(gtt_phys_addr, gtt_size); |
| 2923 | else |
| 2924 | dev_priv->gtt.gsm = ioremap_wc(gtt_phys_addr, gtt_size); |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 2925 | if (!dev_priv->gtt.gsm) { |
| 2926 | DRM_ERROR("Failed to map the gtt page table\n"); |
| 2927 | return -ENOMEM; |
| 2928 | } |
| 2929 | |
Mika Kuoppala | 4ad2af1 | 2015-06-30 18:16:39 +0300 | [diff] [blame] | 2930 | scratch_page = alloc_scratch_page(dev); |
| 2931 | if (IS_ERR(scratch_page)) { |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 2932 | DRM_ERROR("Scratch setup failed\n"); |
| 2933 | /* iounmap will also get called at remove, but meh */ |
| 2934 | iounmap(dev_priv->gtt.gsm); |
Mika Kuoppala | 4ad2af1 | 2015-06-30 18:16:39 +0300 | [diff] [blame] | 2935 | return PTR_ERR(scratch_page); |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 2936 | } |
| 2937 | |
Mika Kuoppala | 4ad2af1 | 2015-06-30 18:16:39 +0300 | [diff] [blame] | 2938 | dev_priv->gtt.base.scratch_page = scratch_page; |
| 2939 | |
| 2940 | return 0; |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 2941 | } |
| 2942 | |
Ben Widawsky | fbe5d36 | 2013-11-04 19:56:49 -0800 | [diff] [blame] | 2943 | /* The GGTT and PPGTT need a private PPAT setup in order to handle cacheability |
| 2944 | * bits. When using advanced contexts each context stores its own PAT, but |
| 2945 | * writing this data shouldn't be harmful even in those cases. */ |
Ville Syrjälä | ee0ce47 | 2014-04-09 13:28:01 +0300 | [diff] [blame] | 2946 | static void bdw_setup_private_ppat(struct drm_i915_private *dev_priv) |
Ben Widawsky | fbe5d36 | 2013-11-04 19:56:49 -0800 | [diff] [blame] | 2947 | { |
Ben Widawsky | fbe5d36 | 2013-11-04 19:56:49 -0800 | [diff] [blame] | 2948 | uint64_t pat; |
| 2949 | |
| 2950 | pat = GEN8_PPAT(0, GEN8_PPAT_WB | GEN8_PPAT_LLC) | /* for normal objects, no eLLC */ |
| 2951 | GEN8_PPAT(1, GEN8_PPAT_WC | GEN8_PPAT_LLCELLC) | /* for something pointing to ptes? */ |
| 2952 | GEN8_PPAT(2, GEN8_PPAT_WT | GEN8_PPAT_LLCELLC) | /* for scanout with eLLC */ |
| 2953 | GEN8_PPAT(3, GEN8_PPAT_UC) | /* Uncached objects, mostly for scanout */ |
| 2954 | GEN8_PPAT(4, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(0)) | |
| 2955 | GEN8_PPAT(5, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(1)) | |
| 2956 | GEN8_PPAT(6, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(2)) | |
| 2957 | GEN8_PPAT(7, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(3)); |
| 2958 | |
Rodrigo Vivi | d6a8b72 | 2014-11-05 16:56:36 -0800 | [diff] [blame] | 2959 | if (!USES_PPGTT(dev_priv->dev)) |
| 2960 | /* Spec: "For GGTT, there is NO pat_sel[2:0] from the entry, |
| 2961 | * so RTL will always use the value corresponding to |
| 2962 | * pat_sel = 000". |
| 2963 | * So let's disable cache for GGTT to avoid screen corruptions. |
| 2964 | * MOCS still can be used though. |
| 2965 | * - System agent ggtt writes (i.e. cpu gtt mmaps) already work |
| 2966 | * before this patch, i.e. the same uncached + snooping access |
| 2967 | * like on gen6/7 seems to be in effect. |
| 2968 | * - So this just fixes blitter/render access. Again it looks |
| 2969 | * like it's not just uncached access, but uncached + snooping. |
| 2970 | * So we can still hold onto all our assumptions wrt cpu |
| 2971 | * clflushing on LLC machines. |
| 2972 | */ |
| 2973 | pat = GEN8_PPAT(0, GEN8_PPAT_UC); |
| 2974 | |
Ben Widawsky | fbe5d36 | 2013-11-04 19:56:49 -0800 | [diff] [blame] | 2975 | /* XXX: spec defines this as 2 distinct registers. It's unclear if a 64b |
| 2976 | * write would work. */ |
Ville Syrjälä | 7e435ad | 2015-09-18 20:03:25 +0300 | [diff] [blame] | 2977 | I915_WRITE(GEN8_PRIVATE_PAT_LO, pat); |
| 2978 | I915_WRITE(GEN8_PRIVATE_PAT_HI, pat >> 32); |
Ben Widawsky | fbe5d36 | 2013-11-04 19:56:49 -0800 | [diff] [blame] | 2979 | } |
| 2980 | |
Ville Syrjälä | ee0ce47 | 2014-04-09 13:28:01 +0300 | [diff] [blame] | 2981 | static void chv_setup_private_ppat(struct drm_i915_private *dev_priv) |
| 2982 | { |
| 2983 | uint64_t pat; |
| 2984 | |
| 2985 | /* |
| 2986 | * Map WB on BDW to snooped on CHV. |
| 2987 | * |
| 2988 | * Only the snoop bit has meaning for CHV, the rest is |
| 2989 | * ignored. |
| 2990 | * |
Ville Syrjälä | cf3d262 | 2014-11-14 21:02:44 +0200 | [diff] [blame] | 2991 | * The hardware will never snoop for certain types of accesses: |
| 2992 | * - CPU GTT (GMADR->GGTT->no snoop->memory) |
| 2993 | * - PPGTT page tables |
| 2994 | * - some other special cycles |
| 2995 | * |
| 2996 | * As with BDW, we also need to consider the following for GT accesses: |
| 2997 | * "For GGTT, there is NO pat_sel[2:0] from the entry, |
| 2998 | * so RTL will always use the value corresponding to |
| 2999 | * pat_sel = 000". |
| 3000 | * Which means we must set the snoop bit in PAT entry 0 |
| 3001 | * in order to keep the global status page working. |
Ville Syrjälä | ee0ce47 | 2014-04-09 13:28:01 +0300 | [diff] [blame] | 3002 | */ |
| 3003 | pat = GEN8_PPAT(0, CHV_PPAT_SNOOP) | |
| 3004 | GEN8_PPAT(1, 0) | |
| 3005 | GEN8_PPAT(2, 0) | |
| 3006 | GEN8_PPAT(3, 0) | |
| 3007 | GEN8_PPAT(4, CHV_PPAT_SNOOP) | |
| 3008 | GEN8_PPAT(5, CHV_PPAT_SNOOP) | |
| 3009 | GEN8_PPAT(6, CHV_PPAT_SNOOP) | |
| 3010 | GEN8_PPAT(7, CHV_PPAT_SNOOP); |
| 3011 | |
Ville Syrjälä | 7e435ad | 2015-09-18 20:03:25 +0300 | [diff] [blame] | 3012 | I915_WRITE(GEN8_PRIVATE_PAT_LO, pat); |
| 3013 | I915_WRITE(GEN8_PRIVATE_PAT_HI, pat >> 32); |
Ville Syrjälä | ee0ce47 | 2014-04-09 13:28:01 +0300 | [diff] [blame] | 3014 | } |
| 3015 | |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 3016 | static int gen8_gmch_probe(struct drm_device *dev, |
Mika Kuoppala | c44ef60 | 2015-06-25 18:35:05 +0300 | [diff] [blame] | 3017 | u64 *gtt_total, |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 3018 | size_t *stolen, |
| 3019 | phys_addr_t *mappable_base, |
Mika Kuoppala | c44ef60 | 2015-06-25 18:35:05 +0300 | [diff] [blame] | 3020 | u64 *mappable_end) |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 3021 | { |
| 3022 | struct drm_i915_private *dev_priv = dev->dev_private; |
Mika Kuoppala | c44ef60 | 2015-06-25 18:35:05 +0300 | [diff] [blame] | 3023 | u64 gtt_size; |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 3024 | u16 snb_gmch_ctl; |
| 3025 | int ret; |
| 3026 | |
| 3027 | /* TODO: We're not aware of mappable constraints on gen8 yet */ |
| 3028 | *mappable_base = pci_resource_start(dev->pdev, 2); |
| 3029 | *mappable_end = pci_resource_len(dev->pdev, 2); |
| 3030 | |
| 3031 | if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(39))) |
| 3032 | pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(39)); |
| 3033 | |
| 3034 | pci_read_config_word(dev->pdev, SNB_GMCH_CTRL, &snb_gmch_ctl); |
| 3035 | |
Damien Lespiau | 6637501 | 2014-01-09 18:02:46 +0000 | [diff] [blame] | 3036 | if (INTEL_INFO(dev)->gen >= 9) { |
| 3037 | *stolen = gen9_get_stolen_size(snb_gmch_ctl); |
| 3038 | gtt_size = gen8_get_total_gtt_size(snb_gmch_ctl); |
| 3039 | } else if (IS_CHERRYVIEW(dev)) { |
Damien Lespiau | d7f25f2 | 2014-05-08 22:19:40 +0300 | [diff] [blame] | 3040 | *stolen = chv_get_stolen_size(snb_gmch_ctl); |
| 3041 | gtt_size = chv_get_total_gtt_size(snb_gmch_ctl); |
| 3042 | } else { |
| 3043 | *stolen = gen8_get_stolen_size(snb_gmch_ctl); |
| 3044 | gtt_size = gen8_get_total_gtt_size(snb_gmch_ctl); |
| 3045 | } |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 3046 | |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 3047 | *gtt_total = (gtt_size / sizeof(gen8_pte_t)) << PAGE_SHIFT; |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 3048 | |
Sumit Singh | 5a4e33a | 2015-03-17 11:39:31 +0200 | [diff] [blame] | 3049 | if (IS_CHERRYVIEW(dev) || IS_BROXTON(dev)) |
Ville Syrjälä | ee0ce47 | 2014-04-09 13:28:01 +0300 | [diff] [blame] | 3050 | chv_setup_private_ppat(dev_priv); |
| 3051 | else |
| 3052 | bdw_setup_private_ppat(dev_priv); |
Ben Widawsky | fbe5d36 | 2013-11-04 19:56:49 -0800 | [diff] [blame] | 3053 | |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 3054 | ret = ggtt_probe_common(dev, gtt_size); |
| 3055 | |
Ben Widawsky | 94ec8f6 | 2013-11-02 21:07:18 -0700 | [diff] [blame] | 3056 | dev_priv->gtt.base.clear_range = gen8_ggtt_clear_range; |
| 3057 | dev_priv->gtt.base.insert_entries = gen8_ggtt_insert_entries; |
Daniel Vetter | 777dc5b | 2015-04-14 17:35:12 +0200 | [diff] [blame] | 3058 | dev_priv->gtt.base.bind_vma = ggtt_bind_vma; |
| 3059 | dev_priv->gtt.base.unbind_vma = ggtt_unbind_vma; |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 3060 | |
Chris Wilson | c140330 | 2015-11-18 15:19:39 +0000 | [diff] [blame] | 3061 | if (IS_CHERRYVIEW(dev_priv)) |
| 3062 | dev_priv->gtt.base.insert_entries = gen8_ggtt_insert_entries__BKL; |
Chris Wilson | 5bab6f6 | 2015-10-23 18:43:32 +0100 | [diff] [blame] | 3063 | |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 3064 | return ret; |
| 3065 | } |
| 3066 | |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3067 | static int gen6_gmch_probe(struct drm_device *dev, |
Mika Kuoppala | c44ef60 | 2015-06-25 18:35:05 +0300 | [diff] [blame] | 3068 | u64 *gtt_total, |
Ben Widawsky | 41907dd | 2013-02-08 11:32:47 -0800 | [diff] [blame] | 3069 | size_t *stolen, |
| 3070 | phys_addr_t *mappable_base, |
Mika Kuoppala | c44ef60 | 2015-06-25 18:35:05 +0300 | [diff] [blame] | 3071 | u64 *mappable_end) |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 3072 | { |
| 3073 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3074 | unsigned int gtt_size; |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 3075 | u16 snb_gmch_ctl; |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 3076 | int ret; |
| 3077 | |
Ben Widawsky | 41907dd | 2013-02-08 11:32:47 -0800 | [diff] [blame] | 3078 | *mappable_base = pci_resource_start(dev->pdev, 2); |
| 3079 | *mappable_end = pci_resource_len(dev->pdev, 2); |
| 3080 | |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3081 | /* 64/512MB is the current min/max we actually know of, but this is just |
| 3082 | * a coarse sanity check. |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 3083 | */ |
Ben Widawsky | 41907dd | 2013-02-08 11:32:47 -0800 | [diff] [blame] | 3084 | if ((*mappable_end < (64<<20) || (*mappable_end > (512<<20)))) { |
Mika Kuoppala | c44ef60 | 2015-06-25 18:35:05 +0300 | [diff] [blame] | 3085 | DRM_ERROR("Unknown GMADR size (%llx)\n", |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3086 | dev_priv->gtt.mappable_end); |
| 3087 | return -ENXIO; |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 3088 | } |
| 3089 | |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 3090 | if (!pci_set_dma_mask(dev->pdev, DMA_BIT_MASK(40))) |
| 3091 | pci_set_consistent_dma_mask(dev->pdev, DMA_BIT_MASK(40)); |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3092 | pci_read_config_word(dev->pdev, SNB_GMCH_CTRL, &snb_gmch_ctl); |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3093 | |
Ben Widawsky | c4ae25e | 2013-05-01 11:00:34 -0700 | [diff] [blame] | 3094 | *stolen = gen6_get_stolen_size(snb_gmch_ctl); |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3095 | |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 3096 | gtt_size = gen6_get_total_gtt_size(snb_gmch_ctl); |
Michel Thierry | 07749ef | 2015-03-16 16:00:54 +0000 | [diff] [blame] | 3097 | *gtt_total = (gtt_size / sizeof(gen6_pte_t)) << PAGE_SHIFT; |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3098 | |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 3099 | ret = ggtt_probe_common(dev, gtt_size); |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3100 | |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 3101 | dev_priv->gtt.base.clear_range = gen6_ggtt_clear_range; |
| 3102 | dev_priv->gtt.base.insert_entries = gen6_ggtt_insert_entries; |
Daniel Vetter | 777dc5b | 2015-04-14 17:35:12 +0200 | [diff] [blame] | 3103 | dev_priv->gtt.base.bind_vma = ggtt_bind_vma; |
| 3104 | dev_priv->gtt.base.unbind_vma = ggtt_unbind_vma; |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3105 | |
| 3106 | return ret; |
| 3107 | } |
| 3108 | |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 3109 | static void gen6_gmch_remove(struct i915_address_space *vm) |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3110 | { |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 3111 | |
| 3112 | struct i915_gtt *gtt = container_of(vm, struct i915_gtt, base); |
Ben Widawsky | 5ed1678 | 2013-11-25 09:54:43 -0800 | [diff] [blame] | 3113 | |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 3114 | iounmap(gtt->gsm); |
Mika Kuoppala | 4ad2af1 | 2015-06-30 18:16:39 +0300 | [diff] [blame] | 3115 | free_scratch_page(vm->dev, vm->scratch_page); |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3116 | } |
| 3117 | |
| 3118 | static int i915_gmch_probe(struct drm_device *dev, |
Mika Kuoppala | c44ef60 | 2015-06-25 18:35:05 +0300 | [diff] [blame] | 3119 | u64 *gtt_total, |
Ben Widawsky | 41907dd | 2013-02-08 11:32:47 -0800 | [diff] [blame] | 3120 | size_t *stolen, |
| 3121 | phys_addr_t *mappable_base, |
Mika Kuoppala | c44ef60 | 2015-06-25 18:35:05 +0300 | [diff] [blame] | 3122 | u64 *mappable_end) |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3123 | { |
| 3124 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3125 | int ret; |
| 3126 | |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3127 | ret = intel_gmch_probe(dev_priv->bridge_dev, dev_priv->dev->pdev, NULL); |
| 3128 | if (!ret) { |
| 3129 | DRM_ERROR("failed to set up gmch\n"); |
| 3130 | return -EIO; |
| 3131 | } |
| 3132 | |
Ben Widawsky | 41907dd | 2013-02-08 11:32:47 -0800 | [diff] [blame] | 3133 | intel_gtt_get(gtt_total, stolen, mappable_base, mappable_end); |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3134 | |
| 3135 | dev_priv->gtt.do_idle_maps = needs_idle_maps(dev_priv->dev); |
Daniel Vetter | d369d2d | 2015-04-14 17:35:25 +0200 | [diff] [blame] | 3136 | dev_priv->gtt.base.insert_entries = i915_ggtt_insert_entries; |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 3137 | dev_priv->gtt.base.clear_range = i915_ggtt_clear_range; |
Daniel Vetter | d369d2d | 2015-04-14 17:35:25 +0200 | [diff] [blame] | 3138 | dev_priv->gtt.base.bind_vma = ggtt_bind_vma; |
| 3139 | dev_priv->gtt.base.unbind_vma = ggtt_unbind_vma; |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3140 | |
Chris Wilson | c0a7f81 | 2013-12-30 12:16:15 +0000 | [diff] [blame] | 3141 | if (unlikely(dev_priv->gtt.do_idle_maps)) |
| 3142 | DRM_INFO("applying Ironlake quirks for intel_iommu\n"); |
| 3143 | |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3144 | return 0; |
| 3145 | } |
| 3146 | |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 3147 | static void i915_gmch_remove(struct i915_address_space *vm) |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3148 | { |
| 3149 | intel_gmch_remove(); |
| 3150 | } |
| 3151 | |
| 3152 | int i915_gem_gtt_init(struct drm_device *dev) |
| 3153 | { |
| 3154 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3155 | struct i915_gtt *gtt = &dev_priv->gtt; |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3156 | int ret; |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 3157 | |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3158 | if (INTEL_INFO(dev)->gen <= 5) { |
Ben Widawsky | b2f21b4 | 2013-06-27 16:30:20 -0700 | [diff] [blame] | 3159 | gtt->gtt_probe = i915_gmch_probe; |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 3160 | gtt->base.cleanup = i915_gmch_remove; |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 3161 | } else if (INTEL_INFO(dev)->gen < 8) { |
Ben Widawsky | b2f21b4 | 2013-06-27 16:30:20 -0700 | [diff] [blame] | 3162 | gtt->gtt_probe = gen6_gmch_probe; |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 3163 | gtt->base.cleanup = gen6_gmch_remove; |
Ben Widawsky | 4d15c14 | 2013-07-04 11:02:06 -0700 | [diff] [blame] | 3164 | if (IS_HASWELL(dev) && dev_priv->ellc_size) |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 3165 | gtt->base.pte_encode = iris_pte_encode; |
Ben Widawsky | 4d15c14 | 2013-07-04 11:02:06 -0700 | [diff] [blame] | 3166 | else if (IS_HASWELL(dev)) |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 3167 | gtt->base.pte_encode = hsw_pte_encode; |
Ben Widawsky | b2f21b4 | 2013-06-27 16:30:20 -0700 | [diff] [blame] | 3168 | else if (IS_VALLEYVIEW(dev)) |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 3169 | gtt->base.pte_encode = byt_pte_encode; |
Chris Wilson | 350ec88 | 2013-08-06 13:17:02 +0100 | [diff] [blame] | 3170 | else if (INTEL_INFO(dev)->gen >= 7) |
| 3171 | gtt->base.pte_encode = ivb_pte_encode; |
Ben Widawsky | b2f21b4 | 2013-06-27 16:30:20 -0700 | [diff] [blame] | 3172 | else |
Chris Wilson | 350ec88 | 2013-08-06 13:17:02 +0100 | [diff] [blame] | 3173 | gtt->base.pte_encode = snb_pte_encode; |
Ben Widawsky | 6334013 | 2013-11-04 19:32:22 -0800 | [diff] [blame] | 3174 | } else { |
| 3175 | dev_priv->gtt.gtt_probe = gen8_gmch_probe; |
| 3176 | dev_priv->gtt.base.cleanup = gen6_gmch_remove; |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 3177 | } |
| 3178 | |
Mika Kuoppala | c114f76 | 2015-06-25 18:35:13 +0300 | [diff] [blame] | 3179 | gtt->base.dev = dev; |
| 3180 | |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 3181 | ret = gtt->gtt_probe(dev, >t->base.total, >t->stolen_size, |
Ben Widawsky | b2f21b4 | 2013-06-27 16:30:20 -0700 | [diff] [blame] | 3182 | >t->mappable_base, >t->mappable_end); |
Ben Widawsky | a54c0c2 | 2013-01-24 14:45:00 -0800 | [diff] [blame] | 3183 | if (ret) |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3184 | return ret; |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 3185 | |
Imre Deak | a4eba47 | 2016-01-19 15:26:32 +0200 | [diff] [blame] | 3186 | /* |
| 3187 | * Initialise stolen early so that we may reserve preallocated |
| 3188 | * objects for the BIOS to KMS transition. |
| 3189 | */ |
| 3190 | ret = i915_gem_init_stolen(dev); |
| 3191 | if (ret) |
| 3192 | goto out_gtt_cleanup; |
| 3193 | |
Ben Widawsky | baa09f5 | 2013-01-24 13:49:57 -0800 | [diff] [blame] | 3194 | /* GMADR is the PCI mmio aperture into the global GTT. */ |
Mika Kuoppala | c44ef60 | 2015-06-25 18:35:05 +0300 | [diff] [blame] | 3195 | DRM_INFO("Memory usable by graphics device = %lluM\n", |
Ben Widawsky | 853ba5d | 2013-07-16 16:50:05 -0700 | [diff] [blame] | 3196 | gtt->base.total >> 20); |
Mika Kuoppala | c44ef60 | 2015-06-25 18:35:05 +0300 | [diff] [blame] | 3197 | DRM_DEBUG_DRIVER("GMADR size = %lldM\n", gtt->mappable_end >> 20); |
Ben Widawsky | b2f21b4 | 2013-06-27 16:30:20 -0700 | [diff] [blame] | 3198 | DRM_DEBUG_DRIVER("GTT stolen size = %zdM\n", gtt->stolen_size >> 20); |
Daniel Vetter | 5db6c73 | 2014-03-31 16:23:04 +0200 | [diff] [blame] | 3199 | #ifdef CONFIG_INTEL_IOMMU |
| 3200 | if (intel_iommu_gfx_mapped) |
| 3201 | DRM_INFO("VT-d active for gfx access\n"); |
| 3202 | #endif |
Daniel Vetter | cfa7c86 | 2014-04-29 11:53:58 +0200 | [diff] [blame] | 3203 | /* |
| 3204 | * i915.enable_ppgtt is read-only, so do an early pass to validate the |
| 3205 | * user's requested state against the hardware/driver capabilities. We |
| 3206 | * do this now so that we can print out any log messages once rather |
| 3207 | * than every time we check intel_enable_ppgtt(). |
| 3208 | */ |
| 3209 | i915.enable_ppgtt = sanitize_enable_ppgtt(dev, i915.enable_ppgtt); |
| 3210 | DRM_DEBUG_DRIVER("ppgtt mode: %i\n", i915.enable_ppgtt); |
Daniel Vetter | 7faf1ab | 2013-01-24 14:44:55 -0800 | [diff] [blame] | 3211 | |
Ben Widawsky | e76e9ae | 2012-11-04 09:21:27 -0800 | [diff] [blame] | 3212 | return 0; |
Imre Deak | a4eba47 | 2016-01-19 15:26:32 +0200 | [diff] [blame] | 3213 | |
| 3214 | out_gtt_cleanup: |
| 3215 | gtt->base.cleanup(&dev_priv->gtt.base); |
| 3216 | |
| 3217 | return ret; |
Daniel Vetter | 644ec02 | 2012-03-26 09:45:40 +0200 | [diff] [blame] | 3218 | } |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 3219 | |
Daniel Vetter | fa42331 | 2015-04-14 17:35:23 +0200 | [diff] [blame] | 3220 | void i915_gem_restore_gtt_mappings(struct drm_device *dev) |
| 3221 | { |
| 3222 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3223 | struct drm_i915_gem_object *obj; |
| 3224 | struct i915_address_space *vm; |
Tvrtko Ursulin | 2c3d998 | 2015-07-06 15:15:01 +0100 | [diff] [blame] | 3225 | struct i915_vma *vma; |
| 3226 | bool flush; |
Daniel Vetter | fa42331 | 2015-04-14 17:35:23 +0200 | [diff] [blame] | 3227 | |
| 3228 | i915_check_and_clear_faults(dev); |
| 3229 | |
| 3230 | /* First fill our portion of the GTT with scratch pages */ |
| 3231 | dev_priv->gtt.base.clear_range(&dev_priv->gtt.base, |
| 3232 | dev_priv->gtt.base.start, |
| 3233 | dev_priv->gtt.base.total, |
| 3234 | true); |
| 3235 | |
Tvrtko Ursulin | 2c3d998 | 2015-07-06 15:15:01 +0100 | [diff] [blame] | 3236 | /* Cache flush objects bound into GGTT and rebind them. */ |
| 3237 | vm = &dev_priv->gtt.base; |
Daniel Vetter | fa42331 | 2015-04-14 17:35:23 +0200 | [diff] [blame] | 3238 | list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) { |
Tvrtko Ursulin | 2c3d998 | 2015-07-06 15:15:01 +0100 | [diff] [blame] | 3239 | flush = false; |
| 3240 | list_for_each_entry(vma, &obj->vma_list, vma_link) { |
| 3241 | if (vma->vm != vm) |
| 3242 | continue; |
Daniel Vetter | fa42331 | 2015-04-14 17:35:23 +0200 | [diff] [blame] | 3243 | |
Tvrtko Ursulin | 2c3d998 | 2015-07-06 15:15:01 +0100 | [diff] [blame] | 3244 | WARN_ON(i915_vma_bind(vma, obj->cache_level, |
| 3245 | PIN_UPDATE)); |
| 3246 | |
| 3247 | flush = true; |
| 3248 | } |
| 3249 | |
| 3250 | if (flush) |
| 3251 | i915_gem_clflush_object(obj, obj->pin_display); |
Daniel Vetter | fa42331 | 2015-04-14 17:35:23 +0200 | [diff] [blame] | 3252 | } |
| 3253 | |
Daniel Vetter | fa42331 | 2015-04-14 17:35:23 +0200 | [diff] [blame] | 3254 | if (INTEL_INFO(dev)->gen >= 8) { |
| 3255 | if (IS_CHERRYVIEW(dev) || IS_BROXTON(dev)) |
| 3256 | chv_setup_private_ppat(dev_priv); |
| 3257 | else |
| 3258 | bdw_setup_private_ppat(dev_priv); |
| 3259 | |
| 3260 | return; |
| 3261 | } |
| 3262 | |
| 3263 | if (USES_PPGTT(dev)) { |
| 3264 | list_for_each_entry(vm, &dev_priv->vm_list, global_link) { |
| 3265 | /* TODO: Perhaps it shouldn't be gen6 specific */ |
| 3266 | |
| 3267 | struct i915_hw_ppgtt *ppgtt = |
| 3268 | container_of(vm, struct i915_hw_ppgtt, |
| 3269 | base); |
| 3270 | |
| 3271 | if (i915_is_ggtt(vm)) |
| 3272 | ppgtt = dev_priv->mm.aliasing_ppgtt; |
| 3273 | |
| 3274 | gen6_write_page_range(dev_priv, &ppgtt->pd, |
| 3275 | 0, ppgtt->base.total); |
| 3276 | } |
| 3277 | } |
| 3278 | |
| 3279 | i915_ggtt_flush(dev_priv); |
| 3280 | } |
| 3281 | |
Joonas Lahtinen | ec7adb6 | 2015-03-16 14:11:13 +0200 | [diff] [blame] | 3282 | static struct i915_vma * |
| 3283 | __i915_gem_vma_create(struct drm_i915_gem_object *obj, |
| 3284 | struct i915_address_space *vm, |
| 3285 | const struct i915_ggtt_view *ggtt_view) |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 3286 | { |
Dan Carpenter | dabde5c | 2015-03-18 11:21:58 +0300 | [diff] [blame] | 3287 | struct i915_vma *vma; |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 3288 | |
Joonas Lahtinen | ec7adb6 | 2015-03-16 14:11:13 +0200 | [diff] [blame] | 3289 | if (WARN_ON(i915_is_ggtt(vm) != !!ggtt_view)) |
| 3290 | return ERR_PTR(-EINVAL); |
Chris Wilson | e20d2ab | 2015-04-07 16:20:58 +0100 | [diff] [blame] | 3291 | |
| 3292 | vma = kmem_cache_zalloc(to_i915(obj->base.dev)->vmas, GFP_KERNEL); |
Dan Carpenter | dabde5c | 2015-03-18 11:21:58 +0300 | [diff] [blame] | 3293 | if (vma == NULL) |
| 3294 | return ERR_PTR(-ENOMEM); |
Joonas Lahtinen | ec7adb6 | 2015-03-16 14:11:13 +0200 | [diff] [blame] | 3295 | |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 3296 | INIT_LIST_HEAD(&vma->vma_link); |
| 3297 | INIT_LIST_HEAD(&vma->mm_list); |
| 3298 | INIT_LIST_HEAD(&vma->exec_list); |
| 3299 | vma->vm = vm; |
| 3300 | vma->obj = obj; |
| 3301 | |
Daniel Vetter | 777dc5b | 2015-04-14 17:35:12 +0200 | [diff] [blame] | 3302 | if (i915_is_ggtt(vm)) |
Joonas Lahtinen | ec7adb6 | 2015-03-16 14:11:13 +0200 | [diff] [blame] | 3303 | vma->ggtt_view = *ggtt_view; |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 3304 | |
Tvrtko Ursulin | f763566 | 2014-12-03 14:59:24 +0000 | [diff] [blame] | 3305 | list_add_tail(&vma->vma_link, &obj->vma_list); |
| 3306 | if (!i915_is_ggtt(vm)) |
Michel Thierry | e07f055 | 2014-08-19 15:49:41 +0100 | [diff] [blame] | 3307 | i915_ppgtt_get(i915_vm_to_ppgtt(vm)); |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 3308 | |
| 3309 | return vma; |
| 3310 | } |
| 3311 | |
| 3312 | struct i915_vma * |
Joonas Lahtinen | ec7adb6 | 2015-03-16 14:11:13 +0200 | [diff] [blame] | 3313 | i915_gem_obj_lookup_or_create_vma(struct drm_i915_gem_object *obj, |
| 3314 | struct i915_address_space *vm) |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 3315 | { |
| 3316 | struct i915_vma *vma; |
| 3317 | |
Joonas Lahtinen | ec7adb6 | 2015-03-16 14:11:13 +0200 | [diff] [blame] | 3318 | vma = i915_gem_obj_to_vma(obj, vm); |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 3319 | if (!vma) |
Joonas Lahtinen | ec7adb6 | 2015-03-16 14:11:13 +0200 | [diff] [blame] | 3320 | vma = __i915_gem_vma_create(obj, vm, |
| 3321 | i915_is_ggtt(vm) ? &i915_ggtt_view_normal : NULL); |
Ben Widawsky | 6f65e29 | 2013-12-06 14:10:56 -0800 | [diff] [blame] | 3322 | |
| 3323 | return vma; |
| 3324 | } |
Tvrtko Ursulin | fe14d5f | 2014-12-10 17:27:58 +0000 | [diff] [blame] | 3325 | |
Joonas Lahtinen | ec7adb6 | 2015-03-16 14:11:13 +0200 | [diff] [blame] | 3326 | struct i915_vma * |
| 3327 | i915_gem_obj_lookup_or_create_ggtt_vma(struct drm_i915_gem_object *obj, |
| 3328 | const struct i915_ggtt_view *view) |
| 3329 | { |
| 3330 | struct i915_address_space *ggtt = i915_obj_to_ggtt(obj); |
| 3331 | struct i915_vma *vma; |
| 3332 | |
| 3333 | if (WARN_ON(!view)) |
| 3334 | return ERR_PTR(-EINVAL); |
| 3335 | |
| 3336 | vma = i915_gem_obj_to_ggtt_view(obj, view); |
| 3337 | |
| 3338 | if (IS_ERR(vma)) |
| 3339 | return vma; |
| 3340 | |
| 3341 | if (!vma) |
| 3342 | vma = __i915_gem_vma_create(obj, ggtt, view); |
| 3343 | |
| 3344 | return vma; |
| 3345 | |
| 3346 | } |
| 3347 | |
Tvrtko Ursulin | 804beb4 | 2015-09-21 10:45:33 +0100 | [diff] [blame] | 3348 | static struct scatterlist * |
Ville Syrjälä | 2d7f3bd | 2016-01-14 15:22:11 +0200 | [diff] [blame] | 3349 | rotate_pages(const dma_addr_t *in, unsigned int offset, |
Tvrtko Ursulin | 804beb4 | 2015-09-21 10:45:33 +0100 | [diff] [blame] | 3350 | unsigned int width, unsigned int height, |
Ville Syrjälä | 8713025 | 2016-01-20 21:05:23 +0200 | [diff] [blame^] | 3351 | unsigned int stride, |
Tvrtko Ursulin | 804beb4 | 2015-09-21 10:45:33 +0100 | [diff] [blame] | 3352 | struct sg_table *st, struct scatterlist *sg) |
Tvrtko Ursulin | fe14d5f | 2014-12-10 17:27:58 +0000 | [diff] [blame] | 3353 | { |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3354 | unsigned int column, row; |
| 3355 | unsigned int src_idx; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3356 | |
Tvrtko Ursulin | 804beb4 | 2015-09-21 10:45:33 +0100 | [diff] [blame] | 3357 | if (!sg) { |
| 3358 | st->nents = 0; |
| 3359 | sg = st->sgl; |
| 3360 | } |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3361 | |
| 3362 | for (column = 0; column < width; column++) { |
Ville Syrjälä | 8713025 | 2016-01-20 21:05:23 +0200 | [diff] [blame^] | 3363 | src_idx = stride * (height - 1) + column; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3364 | for (row = 0; row < height; row++) { |
| 3365 | st->nents++; |
| 3366 | /* We don't need the pages, but need to initialize |
| 3367 | * the entries so the sg list can be happily traversed. |
| 3368 | * The only thing we need are DMA addresses. |
| 3369 | */ |
| 3370 | sg_set_page(sg, NULL, PAGE_SIZE, 0); |
Tvrtko Ursulin | 804beb4 | 2015-09-21 10:45:33 +0100 | [diff] [blame] | 3371 | sg_dma_address(sg) = in[offset + src_idx]; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3372 | sg_dma_len(sg) = PAGE_SIZE; |
| 3373 | sg = sg_next(sg); |
Ville Syrjälä | 8713025 | 2016-01-20 21:05:23 +0200 | [diff] [blame^] | 3374 | src_idx -= stride; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3375 | } |
| 3376 | } |
Tvrtko Ursulin | 804beb4 | 2015-09-21 10:45:33 +0100 | [diff] [blame] | 3377 | |
| 3378 | return sg; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3379 | } |
| 3380 | |
| 3381 | static struct sg_table * |
| 3382 | intel_rotate_fb_obj_pages(struct i915_ggtt_view *ggtt_view, |
| 3383 | struct drm_i915_gem_object *obj) |
| 3384 | { |
Ville Syrjälä | 7723f47d | 2016-01-20 21:05:22 +0200 | [diff] [blame] | 3385 | struct intel_rotation_info *rot_info = &ggtt_view->params.rotated; |
Tvrtko Ursulin | 84fe03f | 2015-06-23 14:26:46 +0100 | [diff] [blame] | 3386 | unsigned int size_pages = rot_info->size >> PAGE_SHIFT; |
Tvrtko Ursulin | 89e3e14 | 2015-09-21 10:45:34 +0100 | [diff] [blame] | 3387 | unsigned int size_pages_uv; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3388 | struct sg_page_iter sg_iter; |
| 3389 | unsigned long i; |
| 3390 | dma_addr_t *page_addr_list; |
| 3391 | struct sg_table *st; |
Tvrtko Ursulin | 89e3e14 | 2015-09-21 10:45:34 +0100 | [diff] [blame] | 3392 | unsigned int uv_start_page; |
| 3393 | struct scatterlist *sg; |
Tvrtko Ursulin | 1d00dad | 2015-03-25 10:15:26 +0000 | [diff] [blame] | 3394 | int ret = -ENOMEM; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3395 | |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3396 | /* Allocate a temporary list of source pages for random access. */ |
Tvrtko Ursulin | 84fe03f | 2015-06-23 14:26:46 +0100 | [diff] [blame] | 3397 | page_addr_list = drm_malloc_ab(obj->base.size / PAGE_SIZE, |
| 3398 | sizeof(dma_addr_t)); |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3399 | if (!page_addr_list) |
| 3400 | return ERR_PTR(ret); |
| 3401 | |
Tvrtko Ursulin | 89e3e14 | 2015-09-21 10:45:34 +0100 | [diff] [blame] | 3402 | /* Account for UV plane with NV12. */ |
| 3403 | if (rot_info->pixel_format == DRM_FORMAT_NV12) |
| 3404 | size_pages_uv = rot_info->size_uv >> PAGE_SHIFT; |
| 3405 | else |
| 3406 | size_pages_uv = 0; |
| 3407 | |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3408 | /* Allocate target SG list. */ |
| 3409 | st = kmalloc(sizeof(*st), GFP_KERNEL); |
| 3410 | if (!st) |
| 3411 | goto err_st_alloc; |
| 3412 | |
Tvrtko Ursulin | 89e3e14 | 2015-09-21 10:45:34 +0100 | [diff] [blame] | 3413 | ret = sg_alloc_table(st, size_pages + size_pages_uv, GFP_KERNEL); |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3414 | if (ret) |
| 3415 | goto err_sg_alloc; |
| 3416 | |
| 3417 | /* Populate source page list from the object. */ |
| 3418 | i = 0; |
| 3419 | for_each_sg_page(obj->pages->sgl, &sg_iter, obj->pages->nents, 0) { |
| 3420 | page_addr_list[i] = sg_page_iter_dma_address(&sg_iter); |
| 3421 | i++; |
| 3422 | } |
| 3423 | |
| 3424 | /* Rotate the pages. */ |
Tvrtko Ursulin | 89e3e14 | 2015-09-21 10:45:34 +0100 | [diff] [blame] | 3425 | sg = rotate_pages(page_addr_list, 0, |
Tvrtko Ursulin | 84fe03f | 2015-06-23 14:26:46 +0100 | [diff] [blame] | 3426 | rot_info->width_pages, rot_info->height_pages, |
Ville Syrjälä | 8713025 | 2016-01-20 21:05:23 +0200 | [diff] [blame^] | 3427 | rot_info->width_pages, |
Tvrtko Ursulin | 804beb4 | 2015-09-21 10:45:33 +0100 | [diff] [blame] | 3428 | st, NULL); |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3429 | |
Tvrtko Ursulin | 89e3e14 | 2015-09-21 10:45:34 +0100 | [diff] [blame] | 3430 | /* Append the UV plane if NV12. */ |
| 3431 | if (rot_info->pixel_format == DRM_FORMAT_NV12) { |
| 3432 | uv_start_page = size_pages; |
| 3433 | |
| 3434 | /* Check for tile-row un-alignment. */ |
| 3435 | if (offset_in_page(rot_info->uv_offset)) |
| 3436 | uv_start_page--; |
| 3437 | |
Tvrtko Ursulin | dedf278 | 2015-09-21 10:45:35 +0100 | [diff] [blame] | 3438 | rot_info->uv_start_page = uv_start_page; |
| 3439 | |
Tvrtko Ursulin | 89e3e14 | 2015-09-21 10:45:34 +0100 | [diff] [blame] | 3440 | rotate_pages(page_addr_list, uv_start_page, |
| 3441 | rot_info->width_pages_uv, |
| 3442 | rot_info->height_pages_uv, |
Ville Syrjälä | 8713025 | 2016-01-20 21:05:23 +0200 | [diff] [blame^] | 3443 | rot_info->width_pages_uv, |
Tvrtko Ursulin | 89e3e14 | 2015-09-21 10:45:34 +0100 | [diff] [blame] | 3444 | st, sg); |
| 3445 | } |
| 3446 | |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3447 | DRM_DEBUG_KMS( |
Tvrtko Ursulin | 89e3e14 | 2015-09-21 10:45:34 +0100 | [diff] [blame] | 3448 | "Created rotated page mapping for object size %zu (pitch=%u, height=%u, pixel_format=0x%x, %ux%u tiles, %u pages (%u plane 0)).\n", |
Tvrtko Ursulin | c9f8fd2 | 2015-06-24 09:55:20 +0100 | [diff] [blame] | 3449 | obj->base.size, rot_info->pitch, rot_info->height, |
Tvrtko Ursulin | 84fe03f | 2015-06-23 14:26:46 +0100 | [diff] [blame] | 3450 | rot_info->pixel_format, rot_info->width_pages, |
Tvrtko Ursulin | 89e3e14 | 2015-09-21 10:45:34 +0100 | [diff] [blame] | 3451 | rot_info->height_pages, size_pages + size_pages_uv, |
| 3452 | size_pages); |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3453 | |
| 3454 | drm_free_large(page_addr_list); |
| 3455 | |
| 3456 | return st; |
| 3457 | |
| 3458 | err_sg_alloc: |
| 3459 | kfree(st); |
| 3460 | err_st_alloc: |
| 3461 | drm_free_large(page_addr_list); |
| 3462 | |
| 3463 | DRM_DEBUG_KMS( |
Tvrtko Ursulin | 89e3e14 | 2015-09-21 10:45:34 +0100 | [diff] [blame] | 3464 | "Failed to create rotated mapping for object size %zu! (%d) (pitch=%u, height=%u, pixel_format=0x%x, %ux%u tiles, %u pages (%u plane 0))\n", |
Tvrtko Ursulin | c9f8fd2 | 2015-06-24 09:55:20 +0100 | [diff] [blame] | 3465 | obj->base.size, ret, rot_info->pitch, rot_info->height, |
Tvrtko Ursulin | 84fe03f | 2015-06-23 14:26:46 +0100 | [diff] [blame] | 3466 | rot_info->pixel_format, rot_info->width_pages, |
Tvrtko Ursulin | 89e3e14 | 2015-09-21 10:45:34 +0100 | [diff] [blame] | 3467 | rot_info->height_pages, size_pages + size_pages_uv, |
| 3468 | size_pages); |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3469 | return ERR_PTR(ret); |
| 3470 | } |
| 3471 | |
Joonas Lahtinen | 8bd7ef1 | 2015-05-06 14:35:38 +0300 | [diff] [blame] | 3472 | static struct sg_table * |
| 3473 | intel_partial_pages(const struct i915_ggtt_view *view, |
| 3474 | struct drm_i915_gem_object *obj) |
| 3475 | { |
| 3476 | struct sg_table *st; |
| 3477 | struct scatterlist *sg; |
| 3478 | struct sg_page_iter obj_sg_iter; |
| 3479 | int ret = -ENOMEM; |
| 3480 | |
| 3481 | st = kmalloc(sizeof(*st), GFP_KERNEL); |
| 3482 | if (!st) |
| 3483 | goto err_st_alloc; |
| 3484 | |
| 3485 | ret = sg_alloc_table(st, view->params.partial.size, GFP_KERNEL); |
| 3486 | if (ret) |
| 3487 | goto err_sg_alloc; |
| 3488 | |
| 3489 | sg = st->sgl; |
| 3490 | st->nents = 0; |
| 3491 | for_each_sg_page(obj->pages->sgl, &obj_sg_iter, obj->pages->nents, |
| 3492 | view->params.partial.offset) |
| 3493 | { |
| 3494 | if (st->nents >= view->params.partial.size) |
| 3495 | break; |
| 3496 | |
| 3497 | sg_set_page(sg, NULL, PAGE_SIZE, 0); |
| 3498 | sg_dma_address(sg) = sg_page_iter_dma_address(&obj_sg_iter); |
| 3499 | sg_dma_len(sg) = PAGE_SIZE; |
| 3500 | |
| 3501 | sg = sg_next(sg); |
| 3502 | st->nents++; |
| 3503 | } |
| 3504 | |
| 3505 | return st; |
| 3506 | |
| 3507 | err_sg_alloc: |
| 3508 | kfree(st); |
| 3509 | err_st_alloc: |
| 3510 | return ERR_PTR(ret); |
| 3511 | } |
| 3512 | |
Daniel Vetter | 70b9f6f | 2015-04-14 17:35:27 +0200 | [diff] [blame] | 3513 | static int |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3514 | i915_get_ggtt_vma_pages(struct i915_vma *vma) |
| 3515 | { |
| 3516 | int ret = 0; |
| 3517 | |
Tvrtko Ursulin | fe14d5f | 2014-12-10 17:27:58 +0000 | [diff] [blame] | 3518 | if (vma->ggtt_view.pages) |
| 3519 | return 0; |
| 3520 | |
| 3521 | if (vma->ggtt_view.type == I915_GGTT_VIEW_NORMAL) |
| 3522 | vma->ggtt_view.pages = vma->obj->pages; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3523 | else if (vma->ggtt_view.type == I915_GGTT_VIEW_ROTATED) |
| 3524 | vma->ggtt_view.pages = |
| 3525 | intel_rotate_fb_obj_pages(&vma->ggtt_view, vma->obj); |
Joonas Lahtinen | 8bd7ef1 | 2015-05-06 14:35:38 +0300 | [diff] [blame] | 3526 | else if (vma->ggtt_view.type == I915_GGTT_VIEW_PARTIAL) |
| 3527 | vma->ggtt_view.pages = |
| 3528 | intel_partial_pages(&vma->ggtt_view, vma->obj); |
Tvrtko Ursulin | fe14d5f | 2014-12-10 17:27:58 +0000 | [diff] [blame] | 3529 | else |
| 3530 | WARN_ONCE(1, "GGTT view %u not implemented!\n", |
| 3531 | vma->ggtt_view.type); |
| 3532 | |
| 3533 | if (!vma->ggtt_view.pages) { |
Joonas Lahtinen | ec7adb6 | 2015-03-16 14:11:13 +0200 | [diff] [blame] | 3534 | DRM_ERROR("Failed to get pages for GGTT view type %u!\n", |
Tvrtko Ursulin | fe14d5f | 2014-12-10 17:27:58 +0000 | [diff] [blame] | 3535 | vma->ggtt_view.type); |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3536 | ret = -EINVAL; |
| 3537 | } else if (IS_ERR(vma->ggtt_view.pages)) { |
| 3538 | ret = PTR_ERR(vma->ggtt_view.pages); |
| 3539 | vma->ggtt_view.pages = NULL; |
| 3540 | DRM_ERROR("Failed to get pages for VMA view type %u (%d)!\n", |
| 3541 | vma->ggtt_view.type, ret); |
Tvrtko Ursulin | fe14d5f | 2014-12-10 17:27:58 +0000 | [diff] [blame] | 3542 | } |
| 3543 | |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 3544 | return ret; |
Tvrtko Ursulin | fe14d5f | 2014-12-10 17:27:58 +0000 | [diff] [blame] | 3545 | } |
| 3546 | |
| 3547 | /** |
| 3548 | * i915_vma_bind - Sets up PTEs for an VMA in it's corresponding address space. |
| 3549 | * @vma: VMA to map |
| 3550 | * @cache_level: mapping cache level |
| 3551 | * @flags: flags like global or local mapping |
| 3552 | * |
| 3553 | * DMA addresses are taken from the scatter-gather table of this object (or of |
| 3554 | * this VMA in case of non-default GGTT views) and PTE entries set up. |
| 3555 | * Note that DMA addresses are also the only part of the SG table we care about. |
| 3556 | */ |
| 3557 | int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level, |
| 3558 | u32 flags) |
| 3559 | { |
Mika Kuoppala | 75d04a3 | 2015-04-28 17:56:17 +0300 | [diff] [blame] | 3560 | int ret; |
| 3561 | u32 bind_flags; |
Mika Kuoppala | 1d335d1 | 2015-04-10 15:54:58 +0300 | [diff] [blame] | 3562 | |
Mika Kuoppala | 75d04a3 | 2015-04-28 17:56:17 +0300 | [diff] [blame] | 3563 | if (WARN_ON(flags == 0)) |
| 3564 | return -EINVAL; |
Mika Kuoppala | 1d335d1 | 2015-04-10 15:54:58 +0300 | [diff] [blame] | 3565 | |
Mika Kuoppala | 75d04a3 | 2015-04-28 17:56:17 +0300 | [diff] [blame] | 3566 | bind_flags = 0; |
Daniel Vetter | 0875546 | 2015-04-20 09:04:05 -0700 | [diff] [blame] | 3567 | if (flags & PIN_GLOBAL) |
| 3568 | bind_flags |= GLOBAL_BIND; |
| 3569 | if (flags & PIN_USER) |
| 3570 | bind_flags |= LOCAL_BIND; |
| 3571 | |
| 3572 | if (flags & PIN_UPDATE) |
| 3573 | bind_flags |= vma->bound; |
| 3574 | else |
| 3575 | bind_flags &= ~vma->bound; |
| 3576 | |
Mika Kuoppala | 75d04a3 | 2015-04-28 17:56:17 +0300 | [diff] [blame] | 3577 | if (bind_flags == 0) |
| 3578 | return 0; |
| 3579 | |
| 3580 | if (vma->bound == 0 && vma->vm->allocate_va_range) { |
| 3581 | trace_i915_va_alloc(vma->vm, |
| 3582 | vma->node.start, |
| 3583 | vma->node.size, |
| 3584 | VM_TO_TRACE_NAME(vma->vm)); |
| 3585 | |
Mika Kuoppala | b2dd451 | 2015-06-25 18:35:15 +0300 | [diff] [blame] | 3586 | /* XXX: i915_vma_pin() will fix this +- hack */ |
| 3587 | vma->pin_count++; |
Mika Kuoppala | 75d04a3 | 2015-04-28 17:56:17 +0300 | [diff] [blame] | 3588 | ret = vma->vm->allocate_va_range(vma->vm, |
| 3589 | vma->node.start, |
| 3590 | vma->node.size); |
Mika Kuoppala | b2dd451 | 2015-06-25 18:35:15 +0300 | [diff] [blame] | 3591 | vma->pin_count--; |
Mika Kuoppala | 75d04a3 | 2015-04-28 17:56:17 +0300 | [diff] [blame] | 3592 | if (ret) |
| 3593 | return ret; |
| 3594 | } |
| 3595 | |
| 3596 | ret = vma->vm->bind_vma(vma, cache_level, bind_flags); |
Daniel Vetter | 70b9f6f | 2015-04-14 17:35:27 +0200 | [diff] [blame] | 3597 | if (ret) |
| 3598 | return ret; |
Daniel Vetter | 0875546 | 2015-04-20 09:04:05 -0700 | [diff] [blame] | 3599 | |
| 3600 | vma->bound |= bind_flags; |
Tvrtko Ursulin | fe14d5f | 2014-12-10 17:27:58 +0000 | [diff] [blame] | 3601 | |
| 3602 | return 0; |
| 3603 | } |
Joonas Lahtinen | 91e6711 | 2015-05-06 14:33:58 +0300 | [diff] [blame] | 3604 | |
| 3605 | /** |
| 3606 | * i915_ggtt_view_size - Get the size of a GGTT view. |
| 3607 | * @obj: Object the view is of. |
| 3608 | * @view: The view in question. |
| 3609 | * |
| 3610 | * @return The size of the GGTT view in bytes. |
| 3611 | */ |
| 3612 | size_t |
| 3613 | i915_ggtt_view_size(struct drm_i915_gem_object *obj, |
| 3614 | const struct i915_ggtt_view *view) |
| 3615 | { |
Tvrtko Ursulin | 9e759ff | 2015-06-23 12:57:43 +0100 | [diff] [blame] | 3616 | if (view->type == I915_GGTT_VIEW_NORMAL) { |
Joonas Lahtinen | 91e6711 | 2015-05-06 14:33:58 +0300 | [diff] [blame] | 3617 | return obj->base.size; |
Tvrtko Ursulin | 9e759ff | 2015-06-23 12:57:43 +0100 | [diff] [blame] | 3618 | } else if (view->type == I915_GGTT_VIEW_ROTATED) { |
Ville Syrjälä | 7723f47d | 2016-01-20 21:05:22 +0200 | [diff] [blame] | 3619 | return view->params.rotated.size; |
Joonas Lahtinen | 8bd7ef1 | 2015-05-06 14:35:38 +0300 | [diff] [blame] | 3620 | } else if (view->type == I915_GGTT_VIEW_PARTIAL) { |
| 3621 | return view->params.partial.size << PAGE_SHIFT; |
Joonas Lahtinen | 91e6711 | 2015-05-06 14:33:58 +0300 | [diff] [blame] | 3622 | } else { |
| 3623 | WARN_ONCE(1, "GGTT view %u not implemented!\n", view->type); |
| 3624 | return obj->base.size; |
| 3625 | } |
| 3626 | } |