Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'drm-intel-gt-next-2021-06-10' of git://anongit.freedesktop.org/drm/drm-intel into drm-next

UAPI Changes:

- Disable mmap ioctl for gen12+ (excl. TGL-LP)
- Start enabling HuC loading by default for upcoming Gen12+
platforms (excludes TGL and RKL)

Core Changes:

- Backmerge of drm-next

Driver Changes:

- Revert "i915: use io_mapping_map_user" (Eero, Matt A)
- Initialize the TTM device and memory managers (Thomas)
- Major rework to the GuC submission backend to prepare
for enabling on new platforms (Michal Wa., Daniele,
Matt B, Rodrigo)
- Fix i915_sg_page_sizes to record dma segments rather
than physical pages (Thomas)

- Locking rework to prep for TTM conversion (Thomas)
- Replace IS_GEN and friends with GRAPHICS_VER (Lucas)
- Use DEVICE_ATTR_RO macro (Yue)
- Static code checker fixes (Zhihao)

Signed-off-by: Dave Airlie <airlied@redhat.com>
From: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/YMHeDxg9VLiFtyn3@jlahtine-mobl.ger.corp.intel.com

+1919 -2745
+1 -1
drivers/gpu/drm/i915/Kconfig
··· 20 20 select INPUT if ACPI 21 21 select ACPI_VIDEO if ACPI 22 22 select ACPI_BUTTON if ACPI 23 - select IO_MAPPING 24 23 select SYNC_FILE 25 24 select IOSF_MBI 26 25 select CRC32 27 26 select SND_HDA_I915 if SND_HDA_CORE 28 27 select CEC_CORE if CEC_NOTIFIER 29 28 select VMAP_PFN 29 + select DRM_TTM 30 30 help 31 31 Choose this option if you have a system that has "Intel Graphics 32 32 Media Accelerator" or "HD Graphics" integrated graphics,
+1 -1
drivers/gpu/drm/i915/Makefile
··· 50 50 intel_memory_region.o \ 51 51 intel_pch.o \ 52 52 intel_pm.o \ 53 + intel_region_ttm.o \ 53 54 intel_runtime_pm.o \ 54 55 intel_sideband.o \ 55 56 intel_step.o \ ··· 161 160 i915-y += \ 162 161 $(gem-y) \ 163 162 i915_active.o \ 164 - i915_buddy.o \ 165 163 i915_cmd_parser.o \ 166 164 i915_gem_evict.o \ 167 165 i915_gem_gtt.o \
+3 -3
drivers/gpu/drm/i915/gem/i915_gem_context.c
··· 1190 1190 { 1191 1191 struct i915_address_space *old = data; 1192 1192 1193 - if (INTEL_GEN(old->i915) < 8) 1193 + if (GRAPHICS_VER(old->i915) < 8) 1194 1194 gen6_ppgtt_unpin_all(i915_vm_to_ppgtt(old)); 1195 1195 1196 1196 i915_vm_close(old); ··· 1436 1436 context->max_eus_per_subslice = user->max_eus_per_subslice; 1437 1437 1438 1438 /* Part specific restrictions. */ 1439 - if (IS_GEN(i915, 11)) { 1439 + if (GRAPHICS_VER(i915) == 11) { 1440 1440 unsigned int hw_s = hweight8(device->slice_mask); 1441 1441 unsigned int hw_ss_per_s = hweight8(device->subslice_mask[0]); 1442 1442 unsigned int req_s = hweight8(context->slice_mask); ··· 1503 1503 if (args->size < sizeof(user_sseu)) 1504 1504 return -EINVAL; 1505 1505 1506 - if (!IS_GEN(i915, 11)) 1506 + if (GRAPHICS_VER(i915) != 11) 1507 1507 return -ENODEV; 1508 1508 1509 1509 if (copy_from_user(&user_sseu, u64_to_user_ptr(args->value),
+1 -1
drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
··· 209 209 if (IS_ERR(pages)) 210 210 return PTR_ERR(pages); 211 211 212 - sg_page_sizes = i915_sg_page_sizes(pages->sgl); 212 + sg_page_sizes = i915_sg_dma_sizes(pages->sgl); 213 213 214 214 __i915_gem_object_set_pages(obj, pages, sg_page_sizes); 215 215
+5 -5
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
··· 500 500 * also covers all platforms with local memory. 501 501 */ 502 502 if (entry->relocation_count && 503 - INTEL_GEN(eb->i915) >= 12 && !IS_TIGERLAKE(eb->i915)) 503 + GRAPHICS_VER(eb->i915) >= 12 && !IS_TIGERLAKE(eb->i915)) 504 504 return -EINVAL; 505 505 506 506 if (unlikely(entry->flags & eb->invalid_flags)) ··· 1439 1439 1440 1440 static bool reloc_can_use_engine(const struct intel_engine_cs *engine) 1441 1441 { 1442 - return engine->class != VIDEO_DECODE_CLASS || !IS_GEN(engine->i915, 6); 1442 + return engine->class != VIDEO_DECODE_CLASS || GRAPHICS_VER(engine->i915) != 6; 1443 1443 } 1444 1444 1445 1445 static u32 *reloc_gpu(struct i915_execbuffer *eb, ··· 1671 1671 * batchbuffers. 1672 1672 */ 1673 1673 if (reloc->write_domain == I915_GEM_DOMAIN_INSTRUCTION && 1674 - IS_GEN(eb->i915, 6)) { 1674 + GRAPHICS_VER(eb->i915) == 6) { 1675 1675 err = i915_vma_bind(target->vma, 1676 1676 target->vma->obj->cache_level, 1677 1677 PIN_GLOBAL, NULL); ··· 2332 2332 u32 *cs; 2333 2333 int i; 2334 2334 2335 - if (!IS_GEN(rq->engine->i915, 7) || rq->engine->id != RCS0) { 2335 + if (GRAPHICS_VER(rq->engine->i915) != 7 || rq->engine->id != RCS0) { 2336 2336 drm_dbg(&rq->engine->i915->drm, "sol reset is gen7/rcs only\n"); 2337 2337 return -EINVAL; 2338 2338 } ··· 3375 3375 3376 3376 eb.batch_flags = 0; 3377 3377 if (args->flags & I915_EXEC_SECURE) { 3378 - if (INTEL_GEN(i915) >= 11) 3378 + if (GRAPHICS_VER(i915) >= 11) 3379 3379 return -ENODEV; 3380 3380 3381 3381 /* Return -EPERM to trigger fallback code on old binaries. */
+57 -2
drivers/gpu/drm/i915/gem/i915_gem_lmem.c
··· 4 4 */ 5 5 6 6 #include "intel_memory_region.h" 7 + #include "intel_region_ttm.h" 7 8 #include "gem/i915_gem_region.h" 8 9 #include "gem/i915_gem_lmem.h" 9 10 #include "i915_drv.h" 11 + 12 + static void lmem_put_pages(struct drm_i915_gem_object *obj, 13 + struct sg_table *pages) 14 + { 15 + intel_region_ttm_node_free(obj->mm.region, obj->mm.st_mm_node); 16 + obj->mm.dirty = false; 17 + sg_free_table(pages); 18 + kfree(pages); 19 + } 20 + 21 + static int lmem_get_pages(struct drm_i915_gem_object *obj) 22 + { 23 + unsigned int flags; 24 + struct sg_table *pages; 25 + 26 + flags = I915_ALLOC_MIN_PAGE_SIZE; 27 + if (obj->flags & I915_BO_ALLOC_CONTIGUOUS) 28 + flags |= I915_ALLOC_CONTIGUOUS; 29 + 30 + obj->mm.st_mm_node = intel_region_ttm_node_alloc(obj->mm.region, 31 + obj->base.size, 32 + flags); 33 + if (IS_ERR(obj->mm.st_mm_node)) 34 + return PTR_ERR(obj->mm.st_mm_node); 35 + 36 + /* Range manager is always contigous */ 37 + if (obj->mm.region->is_range_manager) 38 + obj->flags |= I915_BO_ALLOC_CONTIGUOUS; 39 + pages = intel_region_ttm_node_to_st(obj->mm.region, obj->mm.st_mm_node); 40 + if (IS_ERR(pages)) { 41 + intel_region_ttm_node_free(obj->mm.region, obj->mm.st_mm_node); 42 + return PTR_ERR(pages); 43 + } 44 + 45 + __i915_gem_object_set_pages(obj, pages, i915_sg_dma_sizes(pages->sgl)); 46 + 47 + if (obj->flags & I915_BO_ALLOC_CPU_CLEAR) { 48 + void __iomem *vaddr = 49 + i915_gem_object_lmem_io_map(obj, 0, obj->base.size); 50 + 51 + if (!vaddr) { 52 + struct sg_table *pages = 53 + __i915_gem_object_unset_pages(obj); 54 + 55 + if (!IS_ERR_OR_NULL(pages)) 56 + lmem_put_pages(obj, pages); 57 + } 58 + 59 + memset_io(vaddr, 0, obj->base.size); 60 + io_mapping_unmap(vaddr); 61 + } 62 + 63 + return 0; 64 + } 10 65 11 66 const struct drm_i915_gem_object_ops i915_gem_lmem_obj_ops = { 12 67 .name = "i915_gem_object_lmem", 13 68 .flags = I915_GEM_OBJECT_HAS_IOMEM, 14 69 15 - .get_pages = i915_gem_object_get_pages_buddy, 16 - .put_pages = i915_gem_object_put_pages_buddy, 70 + .get_pages = lmem_get_pages, 71 + .put_pages = lmem_put_pages, 17 72 .release = i915_gem_object_release_memory_region, 18 73 }; 19 74
+12 -4
drivers/gpu/drm/i915/gem/i915_gem_mman.c
··· 56 56 i915_gem_mmap_ioctl(struct drm_device *dev, void *data, 57 57 struct drm_file *file) 58 58 { 59 + struct drm_i915_private *i915 = to_i915(dev); 59 60 struct drm_i915_gem_mmap *args = data; 60 61 struct drm_i915_gem_object *obj; 61 62 unsigned long addr; 63 + 64 + /* mmap ioctl is disallowed for all platforms after TGL-LP. This also 65 + * covers all platforms with local memory. 66 + */ 67 + if (GRAPHICS_VER(i915) >= 12 && !IS_TIGERLAKE(i915)) 68 + return -EOPNOTSUPP; 62 69 63 70 if (args->flags & ~(I915_MMAP_WC)) 64 71 return -EINVAL; ··· 374 367 goto err_unpin; 375 368 376 369 /* Finally, remap it using the new GTT offset */ 377 - ret = io_mapping_map_user(&ggtt->iomap, area, area->vm_start + 378 - (vma->ggtt_view.partial.offset << PAGE_SHIFT), 379 - (ggtt->gmadr.start + vma->node.start) >> PAGE_SHIFT, 380 - min_t(u64, vma->size, area->vm_end - area->vm_start)); 370 + ret = remap_io_mapping(area, 371 + area->vm_start + (vma->ggtt_view.partial.offset << PAGE_SHIFT), 372 + (ggtt->gmadr.start + vma->node.start) >> PAGE_SHIFT, 373 + min_t(u64, vma->size, area->vm_end - area->vm_start), 374 + &ggtt->iomap); 381 375 if (ret) 382 376 goto err_fence; 383 377
+10
drivers/gpu/drm/i915/gem/i915_gem_object.c
··· 62 62 const struct drm_i915_gem_object_ops *ops, 63 63 struct lock_class_key *key, unsigned flags) 64 64 { 65 + /* 66 + * A gem object is embedded both in a struct ttm_buffer_object :/ and 67 + * in a drm_i915_gem_object. Make sure they are aliased. 68 + */ 69 + BUILD_BUG_ON(offsetof(typeof(*obj), base) != 70 + offsetof(typeof(*obj), __do_not_access.base)); 71 + 65 72 spin_lock_init(&obj->vma.lock); 66 73 INIT_LIST_HEAD(&obj->vma.list); 67 74 ··· 258 251 259 252 if (obj->mm.n_placements > 1) 260 253 kfree(obj->mm.placements); 254 + 255 + if (obj->shares_resv_from) 256 + i915_vm_resv_put(obj->shares_resv_from); 261 257 262 258 /* But keep the pointer alive for RCU-protected lookups */ 263 259 call_rcu(&obj->rcu, __i915_gem_free_object_rcu);
+4 -4
drivers/gpu/drm/i915/gem/i915_gem_object_blt.c
··· 72 72 73 73 GEM_BUG_ON(size >> PAGE_SHIFT > S16_MAX); 74 74 75 - if (INTEL_GEN(i915) >= 8) { 75 + if (GRAPHICS_VER(i915) >= 8) { 76 76 *cmd++ = XY_COLOR_BLT_CMD | BLT_WRITE_RGBA | (7 - 2); 77 77 *cmd++ = BLT_DEPTH_32 | BLT_ROP_COLOR_COPY | PAGE_SIZE; 78 78 *cmd++ = 0; ··· 232 232 { 233 233 u32 height = size >> PAGE_SHIFT; 234 234 235 - if (!IS_GEN(i915, 11)) 235 + if (GRAPHICS_VER(i915) != 11) 236 236 return false; 237 237 238 238 return height % 4 == 3 && height <= 8; ··· 297 297 size = min_t(u64, rem, block_size); 298 298 GEM_BUG_ON(size >> PAGE_SHIFT > S16_MAX); 299 299 300 - if (INTEL_GEN(i915) >= 9 && 300 + if (GRAPHICS_VER(i915) >= 9 && 301 301 !wa_1209644611_applies(i915, size)) { 302 302 *cmd++ = GEN9_XY_FAST_COPY_BLT_CMD | (10 - 2); 303 303 *cmd++ = BLT_DEPTH_32 | PAGE_SIZE; ··· 309 309 *cmd++ = PAGE_SIZE; 310 310 *cmd++ = lower_32_bits(src_offset); 311 311 *cmd++ = upper_32_bits(src_offset); 312 - } else if (INTEL_GEN(i915) >= 8) { 312 + } else if (GRAPHICS_VER(i915) >= 8) { 313 313 *cmd++ = XY_SRC_COPY_BLT_CMD | BLT_WRITE_RGBA | (10 - 2); 314 314 *cmd++ = BLT_DEPTH_32 | BLT_ROP_SRC_COPY | PAGE_SIZE; 315 315 *cmd++ = 0;
+19 -3
drivers/gpu/drm/i915/gem/i915_gem_object_types.h
··· 10 10 #include <linux/mmu_notifier.h> 11 11 12 12 #include <drm/drm_gem.h> 13 + #include <drm/ttm/ttm_bo_api.h> 13 14 #include <uapi/drm/i915_drm.h> 14 15 15 16 #include "i915_active.h" ··· 100 99 }; 101 100 102 101 struct drm_i915_gem_object { 103 - struct drm_gem_object base; 102 + /* 103 + * We might have reason to revisit the below since it wastes 104 + * a lot of space for non-ttm gem objects. 105 + * In any case, always use the accessors for the ttm_buffer_object 106 + * when accessing it. 107 + */ 108 + union { 109 + struct drm_gem_object base; 110 + struct ttm_buffer_object __do_not_access; 111 + }; 104 112 105 113 const struct drm_i915_gem_object_ops *ops; 106 114 ··· 159 149 * when i915_gem_ww_ctx_backoff() or i915_gem_ww_ctx_fini() are called. 160 150 */ 161 151 struct list_head obj_link; 152 + /** 153 + * @shared_resv_from: The object shares the resv from this vm. 154 + */ 155 + struct i915_address_space *shares_resv_from; 162 156 163 157 union { 164 158 struct rcu_head rcu; ··· 245 231 * Memory region for this object. 246 232 */ 247 233 struct intel_memory_region *region; 234 + 248 235 /** 249 - * List of memory region blocks allocated for this object. 236 + * Memory manager node allocated for this object. 250 237 */ 251 - struct list_head blocks; 238 + void *st_mm_node; 239 + 252 240 /** 253 241 * Element within memory_region->objects or region->purgeable 254 242 * if the object is marked as DONTNEED. Access is protected by
+2 -1
drivers/gpu/drm/i915/gem/i915_gem_pages.c
··· 475 475 476 476 might_sleep(); 477 477 GEM_BUG_ON(n >= obj->base.size >> PAGE_SHIFT); 478 - GEM_BUG_ON(!i915_gem_object_has_pinned_pages(obj)); 478 + if (!i915_gem_object_has_pinned_pages(obj)) 479 + assert_object_held(obj); 479 480 480 481 /* As we iterate forward through the sg, we record each entry in a 481 482 * radixtree for quick repeated (backwards) lookups. If we have seen
+1 -1
drivers/gpu/drm/i915/gem/i915_gem_phys.c
··· 207 207 208 208 err_xfer: 209 209 if (!IS_ERR_OR_NULL(pages)) { 210 - unsigned int sg_page_sizes = i915_sg_page_sizes(pages->sgl); 210 + unsigned int sg_page_sizes = i915_sg_dma_sizes(pages->sgl); 211 211 212 212 __i915_gem_object_set_pages(obj, pages, sg_page_sizes); 213 213 }
-120
drivers/gpu/drm/i915/gem/i915_gem_region.c
··· 8 8 #include "i915_drv.h" 9 9 #include "i915_trace.h" 10 10 11 - void 12 - i915_gem_object_put_pages_buddy(struct drm_i915_gem_object *obj, 13 - struct sg_table *pages) 14 - { 15 - __intel_memory_region_put_pages_buddy(obj->mm.region, &obj->mm.blocks); 16 - 17 - obj->mm.dirty = false; 18 - sg_free_table(pages); 19 - kfree(pages); 20 - } 21 - 22 - int 23 - i915_gem_object_get_pages_buddy(struct drm_i915_gem_object *obj) 24 - { 25 - const u64 max_segment = i915_sg_segment_size(); 26 - struct intel_memory_region *mem = obj->mm.region; 27 - struct list_head *blocks = &obj->mm.blocks; 28 - resource_size_t size = obj->base.size; 29 - resource_size_t prev_end; 30 - struct i915_buddy_block *block; 31 - unsigned int flags; 32 - struct sg_table *st; 33 - struct scatterlist *sg; 34 - unsigned int sg_page_sizes; 35 - int ret; 36 - 37 - st = kmalloc(sizeof(*st), GFP_KERNEL); 38 - if (!st) 39 - return -ENOMEM; 40 - 41 - if (sg_alloc_table(st, size >> PAGE_SHIFT, GFP_KERNEL)) { 42 - kfree(st); 43 - return -ENOMEM; 44 - } 45 - 46 - flags = I915_ALLOC_MIN_PAGE_SIZE; 47 - if (obj->flags & I915_BO_ALLOC_CONTIGUOUS) 48 - flags |= I915_ALLOC_CONTIGUOUS; 49 - 50 - ret = __intel_memory_region_get_pages_buddy(mem, size, flags, blocks); 51 - if (ret) 52 - goto err_free_sg; 53 - 54 - GEM_BUG_ON(list_empty(blocks)); 55 - 56 - sg = st->sgl; 57 - st->nents = 0; 58 - sg_page_sizes = 0; 59 - prev_end = (resource_size_t)-1; 60 - 61 - list_for_each_entry(block, blocks, link) { 62 - u64 block_size, offset; 63 - 64 - block_size = min_t(u64, size, 65 - i915_buddy_block_size(&mem->mm, block)); 66 - offset = i915_buddy_block_offset(block); 67 - 68 - while (block_size) { 69 - u64 len; 70 - 71 - if (offset != prev_end || sg->length >= max_segment) { 72 - if (st->nents) { 73 - sg_page_sizes |= sg->length; 74 - sg = __sg_next(sg); 75 - } 76 - 77 - sg_dma_address(sg) = mem->region.start + offset; 78 - sg_dma_len(sg) = 0; 79 - sg->length = 0; 80 - st->nents++; 81 - } 82 - 83 - len = min(block_size, max_segment - sg->length); 84 - sg->length += len; 85 - sg_dma_len(sg) += len; 86 - 87 - offset += len; 88 - block_size -= len; 89 - 90 - prev_end = offset; 91 - } 92 - } 93 - 94 - sg_page_sizes |= sg->length; 95 - sg_mark_end(sg); 96 - i915_sg_trim(st); 97 - 98 - /* Intended for kernel internal use only */ 99 - if (obj->flags & I915_BO_ALLOC_CPU_CLEAR) { 100 - struct scatterlist *sg; 101 - unsigned long i; 102 - 103 - for_each_sg(st->sgl, sg, st->nents, i) { 104 - unsigned int length; 105 - void __iomem *vaddr; 106 - dma_addr_t daddr; 107 - 108 - daddr = sg_dma_address(sg); 109 - daddr -= mem->region.start; 110 - length = sg_dma_len(sg); 111 - 112 - vaddr = io_mapping_map_wc(&mem->iomap, daddr, length); 113 - memset64((void __force *)vaddr, 0, length / sizeof(u64)); 114 - io_mapping_unmap(vaddr); 115 - } 116 - 117 - wmb(); 118 - } 119 - 120 - __i915_gem_object_set_pages(obj, st, sg_page_sizes); 121 - 122 - return 0; 123 - 124 - err_free_sg: 125 - sg_free_table(st); 126 - kfree(st); 127 - return ret; 128 - } 129 - 130 11 void i915_gem_object_init_memory_region(struct drm_i915_gem_object *obj, 131 12 struct intel_memory_region *mem) 132 13 { 133 - INIT_LIST_HEAD(&obj->mm.blocks); 134 14 obj->mm.region = intel_memory_region_get(mem); 135 15 136 16 if (obj->base.size <= mem->min_page_size)
-4
drivers/gpu/drm/i915/gem/i915_gem_region.h
··· 12 12 struct drm_i915_gem_object; 13 13 struct sg_table; 14 14 15 - int i915_gem_object_get_pages_buddy(struct drm_i915_gem_object *obj); 16 - void i915_gem_object_put_pages_buddy(struct drm_i915_gem_object *obj, 17 - struct sg_table *pages); 18 - 19 15 void i915_gem_object_init_memory_region(struct drm_i915_gem_object *obj, 20 16 struct intel_memory_region *mem); 21 17 void i915_gem_object_release_memory_region(struct drm_i915_gem_object *obj);
+3 -1
drivers/gpu/drm/i915/gem/i915_gem_shmem.c
··· 628 628 .init_object = shmem_object_init, 629 629 }; 630 630 631 - struct intel_memory_region *i915_gem_shmem_setup(struct drm_i915_private *i915) 631 + struct intel_memory_region *i915_gem_shmem_setup(struct drm_i915_private *i915, 632 + u16 type, u16 instance) 632 633 { 633 634 return intel_memory_region_create(i915, 0, 634 635 totalram_pages() << PAGE_SHIFT, 635 636 PAGE_SIZE, 0, 637 + type, instance, 636 638 &shmem_region_ops); 637 639 } 638 640
+14 -12
drivers/gpu/drm/i915/gem/i915_gem_stolen.c
··· 38 38 return -ENODEV; 39 39 40 40 /* WaSkipStolenMemoryFirstPage:bdw+ */ 41 - if (INTEL_GEN(i915) >= 8 && start < 4096) 41 + if (GRAPHICS_VER(i915) >= 8 && start < 4096) 42 42 start = 4096; 43 43 44 44 mutex_lock(&i915->mm.stolen_lock); ··· 84 84 */ 85 85 86 86 /* Make sure we don't clobber the GTT if it's within stolen memory */ 87 - if (INTEL_GEN(i915) <= 4 && 87 + if (GRAPHICS_VER(i915) <= 4 && 88 88 !IS_G33(i915) && !IS_PINEVIEW(i915) && !IS_G4X(i915)) { 89 89 struct resource stolen[2] = {*dsm, *dsm}; 90 90 struct resource ggtt_res; 91 91 resource_size_t ggtt_start; 92 92 93 93 ggtt_start = intel_uncore_read(uncore, PGTBL_CTL); 94 - if (IS_GEN(i915, 4)) 94 + if (GRAPHICS_VER(i915) == 4) 95 95 ggtt_start = (ggtt_start & PGTBL_ADDRESS_LO_MASK) | 96 96 (ggtt_start & PGTBL_ADDRESS_HI_MASK) << 28; 97 97 else ··· 156 156 * GEN3 firmware likes to smash pci bridges into the stolen 157 157 * range. Apparently this works. 158 158 */ 159 - if (!r && !IS_GEN(i915, 3)) { 159 + if (!r && GRAPHICS_VER(i915) != 3) { 160 160 drm_err(&i915->drm, 161 161 "conflict detected with stolen region: %pR\n", 162 162 dsm); ··· 197 197 * Whether ILK really reuses the ELK register for this is unclear. 198 198 * Let's see if we catch anyone with this supposedly enabled on ILK. 199 199 */ 200 - drm_WARN(&i915->drm, IS_GEN(i915, 5), 200 + drm_WARN(&i915->drm, GRAPHICS_VER(i915) == 5, 201 201 "ILK stolen reserved found? 0x%08x\n", 202 202 reg_val); 203 203 ··· 399 399 return 0; 400 400 } 401 401 402 - if (intel_vtd_active() && INTEL_GEN(i915) < 8) { 402 + if (intel_vtd_active() && GRAPHICS_VER(i915) < 8) { 403 403 drm_notice(&i915->drm, 404 404 "%s, disabling use of stolen memory\n", 405 405 "DMAR active"); ··· 421 421 reserved_base = stolen_top; 422 422 reserved_size = 0; 423 423 424 - switch (INTEL_GEN(i915)) { 424 + switch (GRAPHICS_VER(i915)) { 425 425 case 2: 426 426 case 3: 427 427 break; ··· 456 456 &reserved_base, &reserved_size); 457 457 break; 458 458 default: 459 - MISSING_CASE(INTEL_GEN(i915)); 459 + MISSING_CASE(GRAPHICS_VER(i915)); 460 460 fallthrough; 461 461 case 11: 462 462 case 12: ··· 772 772 }; 773 773 774 774 struct intel_memory_region * 775 - i915_gem_stolen_lmem_setup(struct drm_i915_private *i915) 775 + i915_gem_stolen_lmem_setup(struct drm_i915_private *i915, u16 type, 776 + u16 instance) 776 777 { 777 778 struct intel_uncore *uncore = &i915->uncore; 778 779 struct pci_dev *pdev = to_pci_dev(i915->drm.dev); ··· 791 790 792 791 mem = intel_memory_region_create(i915, lmem_base, lmem_size, 793 792 I915_GTT_PAGE_SIZE_4K, io_start, 793 + type, instance, 794 794 &i915_region_stolen_lmem_ops); 795 795 if (IS_ERR(mem)) 796 796 return mem; ··· 813 811 } 814 812 815 813 struct intel_memory_region* 816 - i915_gem_stolen_smem_setup(struct drm_i915_private *i915) 814 + i915_gem_stolen_smem_setup(struct drm_i915_private *i915, u16 type, 815 + u16 instance) 817 816 { 818 817 struct intel_memory_region *mem; 819 818 820 819 mem = intel_memory_region_create(i915, 821 820 intel_graphics_stolen_res.start, 822 821 resource_size(&intel_graphics_stolen_res), 823 - PAGE_SIZE, 0, 822 + PAGE_SIZE, 0, type, instance, 824 823 &i915_region_stolen_smem_ops); 825 824 if (IS_ERR(mem)) 826 825 return mem; ··· 829 826 intel_memory_region_set_name(mem, "stolen-system"); 830 827 831 828 mem->private = true; 832 - 833 829 return mem; 834 830 } 835 831
+7 -2
drivers/gpu/drm/i915/gem/i915_gem_stolen.h
··· 21 21 u64 end); 22 22 void i915_gem_stolen_remove_node(struct drm_i915_private *dev_priv, 23 23 struct drm_mm_node *node); 24 - struct intel_memory_region *i915_gem_stolen_smem_setup(struct drm_i915_private *i915); 25 - struct intel_memory_region *i915_gem_stolen_lmem_setup(struct drm_i915_private *i915); 24 + struct intel_memory_region * 25 + i915_gem_stolen_smem_setup(struct drm_i915_private *i915, u16 type, 26 + u16 instance); 27 + struct intel_memory_region * 28 + i915_gem_stolen_lmem_setup(struct drm_i915_private *i915, u16 type, 29 + u16 instance); 30 + 26 31 struct drm_i915_gem_object * 27 32 i915_gem_object_create_stolen(struct drm_i915_private *dev_priv, 28 33 resource_size_t size);
+6 -6
drivers/gpu/drm/i915/gem/i915_gem_tiling.c
··· 62 62 63 63 GEM_BUG_ON(!stride); 64 64 65 - if (INTEL_GEN(i915) >= 4) { 65 + if (GRAPHICS_VER(i915) >= 4) { 66 66 stride *= i915_gem_tile_height(tiling); 67 67 GEM_BUG_ON(!IS_ALIGNED(stride, I965_FENCE_PAGE)); 68 68 return roundup(size, stride); 69 69 } 70 70 71 71 /* Previous chips need a power-of-two fence region when tiling */ 72 - if (IS_GEN(i915, 3)) 72 + if (GRAPHICS_VER(i915) == 3) 73 73 ggtt_size = 1024*1024; 74 74 else 75 75 ggtt_size = 512*1024; ··· 102 102 if (tiling == I915_TILING_NONE) 103 103 return I915_GTT_MIN_ALIGNMENT; 104 104 105 - if (INTEL_GEN(i915) >= 4) 105 + if (GRAPHICS_VER(i915) >= 4) 106 106 return I965_FENCE_PAGE; 107 107 108 108 /* ··· 130 130 /* check maximum stride & object size */ 131 131 /* i965+ stores the end address of the gtt mapping in the fence 132 132 * reg, so dont bother to check the size */ 133 - if (INTEL_GEN(i915) >= 7) { 133 + if (GRAPHICS_VER(i915) >= 7) { 134 134 if (stride / 128 > GEN7_FENCE_MAX_PITCH_VAL) 135 135 return false; 136 - } else if (INTEL_GEN(i915) >= 4) { 136 + } else if (GRAPHICS_VER(i915) >= 4) { 137 137 if (stride / 128 > I965_FENCE_MAX_PITCH_VAL) 138 138 return false; 139 139 } else { ··· 144 144 return false; 145 145 } 146 146 147 - if (IS_GEN(i915, 2) || 147 + if (GRAPHICS_VER(i915) == 2 || 148 148 (tiling == I915_TILING_Y && HAS_128_BYTE_Y_TILING(i915))) 149 149 tile_width = 128; 150 150 else
+1 -1
drivers/gpu/drm/i915/gem/i915_gem_userptr.c
··· 173 173 goto err; 174 174 } 175 175 176 - sg_page_sizes = i915_sg_page_sizes(st->sgl); 176 + sg_page_sizes = i915_sg_dma_sizes(st->sgl); 177 177 178 178 __i915_gem_object_set_pages(obj, st, sg_page_sizes); 179 179
+5 -5
drivers/gpu/drm/i915/gem/selftests/i915_gem_client_blt.c
··· 152 152 struct blit_buffer *src, 153 153 struct drm_i915_gem_object *batch) 154 154 { 155 - const int gen = INTEL_GEN(to_i915(batch->base.dev)); 156 - bool use_64b_reloc = gen >= 8; 155 + const int ver = GRAPHICS_VER(to_i915(batch->base.dev)); 156 + bool use_64b_reloc = ver >= 8; 157 157 u32 src_pitch, dst_pitch; 158 158 u32 cmd, *cs; 159 159 ··· 171 171 *cs++ = cmd; 172 172 173 173 cmd = MI_FLUSH_DW; 174 - if (gen >= 8) 174 + if (ver >= 8) 175 175 cmd++; 176 176 *cs++ = cmd; 177 177 *cs++ = 0; ··· 179 179 *cs++ = 0; 180 180 181 181 cmd = XY_SRC_COPY_BLT_CMD | BLT_WRITE_RGBA | (8 - 2); 182 - if (gen >= 8) 182 + if (ver >= 8) 183 183 cmd += 2; 184 184 185 185 src_pitch = t->width * 4; ··· 666 666 int inst = 0; 667 667 668 668 /* Test requires explicit BLT tiling controls */ 669 - if (INTEL_GEN(i915) < 4) 669 + if (GRAPHICS_VER(i915) < 4) 670 670 return 0; 671 671 672 672 if (bad_swizzling(i915)) /* Requires sane (sub-page) swizzling */
+2 -2
drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c
··· 221 221 goto out_rq; 222 222 } 223 223 224 - if (INTEL_GEN(ctx->engine->i915) >= 8) { 224 + if (GRAPHICS_VER(ctx->engine->i915) >= 8) { 225 225 *cs++ = MI_STORE_DWORD_IMM_GEN4 | 1 << 22; 226 226 *cs++ = lower_32_bits(i915_ggtt_offset(vma) + offset); 227 227 *cs++ = upper_32_bits(i915_ggtt_offset(vma) + offset); 228 228 *cs++ = v; 229 - } else if (INTEL_GEN(ctx->engine->i915) >= 4) { 229 + } else if (GRAPHICS_VER(ctx->engine->i915) >= 4) { 230 230 *cs++ = MI_STORE_DWORD_IMM_GEN4 | MI_USE_GGTT; 231 231 *cs++ = 0; 232 232 *cs++ = i915_ggtt_offset(vma) + offset;
+8 -8
drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c
··· 897 897 { 898 898 u32 *cmd; 899 899 900 - GEM_BUG_ON(INTEL_GEN(vma->vm->i915) < 8); 900 + GEM_BUG_ON(GRAPHICS_VER(vma->vm->i915) < 8); 901 901 902 902 cmd = i915_gem_object_pin_map(rpcs, I915_MAP_WB); 903 903 if (IS_ERR(cmd)) ··· 932 932 933 933 GEM_BUG_ON(!intel_engine_can_store_dword(ce->engine)); 934 934 935 - if (INTEL_GEN(i915) < 8) 935 + if (GRAPHICS_VER(i915) < 8) 936 936 return -EINVAL; 937 937 938 938 vma = i915_vma_instance(obj, ce->vm, NULL); ··· 1100 1100 return ret; 1101 1101 } 1102 1102 1103 - if (INTEL_GEN(ce->engine->i915) >= 11) { 1103 + if (GRAPHICS_VER(ce->engine->i915) >= 11) { 1104 1104 s_mask = GEN11_RPCS_S_CNT_MASK; 1105 1105 s_shift = GEN11_RPCS_S_CNT_SHIFT; 1106 1106 } else { ··· 1229 1229 int inst = 0; 1230 1230 int ret = 0; 1231 1231 1232 - if (INTEL_GEN(i915) < 9) 1232 + if (GRAPHICS_VER(i915) < 9) 1233 1233 return 0; 1234 1234 1235 1235 if (flags & TEST_RESET) ··· 1518 1518 } 1519 1519 1520 1520 *cmd++ = MI_STORE_DWORD_IMM_GEN4; 1521 - if (INTEL_GEN(i915) >= 8) { 1521 + if (GRAPHICS_VER(i915) >= 8) { 1522 1522 *cmd++ = lower_32_bits(offset); 1523 1523 *cmd++ = upper_32_bits(offset); 1524 1524 } else { ··· 1608 1608 if (IS_ERR(obj)) 1609 1609 return PTR_ERR(obj); 1610 1610 1611 - if (INTEL_GEN(i915) >= 8) { 1611 + if (GRAPHICS_VER(i915) >= 8) { 1612 1612 const u32 GPR0 = engine->mmio_base + 0x600; 1613 1613 1614 1614 vm = i915_gem_context_get_vm_rcu(ctx); ··· 1776 1776 u32 expected; 1777 1777 int err; 1778 1778 1779 - if (INTEL_GEN(i915) < 7) 1779 + if (GRAPHICS_VER(i915) < 7) 1780 1780 return 0; 1781 1781 1782 1782 /* ··· 1830 1830 continue; 1831 1831 1832 1832 /* Not all engines have their own GPR! */ 1833 - if (INTEL_GEN(i915) < 8 && engine->class != RENDER_CLASS) 1833 + if (GRAPHICS_VER(i915) < 8 && engine->class != RENDER_CLASS) 1834 1834 continue; 1835 1835 1836 1836 while (!__igt_timeout(end_time, NULL)) {
+7 -7
drivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c
··· 273 273 static unsigned int 274 274 setup_tile_size(struct tile *tile, struct drm_i915_private *i915) 275 275 { 276 - if (INTEL_GEN(i915) <= 2) { 276 + if (GRAPHICS_VER(i915) <= 2) { 277 277 tile->height = 16; 278 278 tile->width = 128; 279 279 tile->size = 11; ··· 288 288 tile->size = 12; 289 289 } 290 290 291 - if (INTEL_GEN(i915) < 4) 291 + if (GRAPHICS_VER(i915) < 4) 292 292 return 8192 / tile->width; 293 - else if (INTEL_GEN(i915) < 7) 293 + else if (GRAPHICS_VER(i915) < 7) 294 294 return 128 * I965_FENCE_MAX_PITCH_VAL / tile->width; 295 295 else 296 296 return 128 * GEN7_FENCE_MAX_PITCH_VAL / tile->width; ··· 386 386 if (err) 387 387 goto out_unlock; 388 388 389 - if (pitch > 2 && INTEL_GEN(i915) >= 4) { 389 + if (pitch > 2 && GRAPHICS_VER(i915) >= 4) { 390 390 tile.stride = tile.width * (pitch - 1); 391 391 err = check_partial_mappings(obj, &tile, end); 392 392 if (err == -EINTR) ··· 395 395 goto out_unlock; 396 396 } 397 397 398 - if (pitch < max_pitch && INTEL_GEN(i915) >= 4) { 398 + if (pitch < max_pitch && GRAPHICS_VER(i915) >= 4) { 399 399 tile.stride = tile.width * (pitch + 1); 400 400 err = check_partial_mappings(obj, &tile, end); 401 401 if (err == -EINTR) ··· 405 405 } 406 406 } 407 407 408 - if (INTEL_GEN(i915) >= 4) { 408 + if (GRAPHICS_VER(i915) >= 4) { 409 409 for_each_prime_number(pitch, max_pitch) { 410 410 tile.stride = tile.width * pitch; 411 411 err = check_partial_mappings(obj, &tile, end); ··· 501 501 tile.stride = 502 502 i915_prandom_u32_max_state(max_pitch, &prng); 503 503 tile.stride = (1 + tile.stride) * tile.width; 504 - if (INTEL_GEN(i915) < 4) 504 + if (GRAPHICS_VER(i915) < 4) 505 505 tile.stride = rounddown_pow_of_two(tile.stride); 506 506 } 507 507
+5 -5
drivers/gpu/drm/i915/gem/selftests/igt_gem_utils.c
··· 44 44 u32 val) 45 45 { 46 46 struct drm_i915_gem_object *obj; 47 - const int gen = INTEL_GEN(vma->vm->i915); 47 + const int ver = GRAPHICS_VER(vma->vm->i915); 48 48 unsigned long n, size; 49 49 u32 *cmd; 50 50 int err; ··· 65 65 offset += vma->node.start; 66 66 67 67 for (n = 0; n < count; n++) { 68 - if (gen >= 8) { 68 + if (ver >= 8) { 69 69 *cmd++ = MI_STORE_DWORD_IMM_GEN4; 70 70 *cmd++ = lower_32_bits(offset); 71 71 *cmd++ = upper_32_bits(offset); 72 72 *cmd++ = val; 73 - } else if (gen >= 4) { 73 + } else if (ver >= 4) { 74 74 *cmd++ = MI_STORE_DWORD_IMM_GEN4 | 75 - (gen < 6 ? MI_USE_GGTT : 0); 75 + (ver < 6 ? MI_USE_GGTT : 0); 76 76 *cmd++ = 0; 77 77 *cmd++ = offset; 78 78 *cmd++ = val; ··· 146 146 goto skip_request; 147 147 148 148 flags = 0; 149 - if (INTEL_GEN(ce->vm->i915) <= 5) 149 + if (GRAPHICS_VER(ce->vm->i915) <= 5) 150 150 flags |= I915_DISPATCH_SECURE; 151 151 152 152 err = rq->engine->emit_bb_start(rq,
+20 -20
drivers/gpu/drm/i915/gt/debugfs_gt_pm.c
··· 85 85 gt_core_status = intel_uncore_read_fw(uncore, GEN6_GT_CORE_STATUS); 86 86 87 87 rcctl1 = intel_uncore_read(uncore, GEN6_RC_CONTROL); 88 - if (INTEL_GEN(i915) >= 9) { 88 + if (GRAPHICS_VER(i915) >= 9) { 89 89 gen9_powergate_enable = 90 90 intel_uncore_read(uncore, GEN9_PG_ENABLE); 91 91 gen9_powergate_status = 92 92 intel_uncore_read(uncore, GEN9_PWRGT_DOMAIN_STATUS); 93 93 } 94 94 95 - if (INTEL_GEN(i915) <= 7) 95 + if (GRAPHICS_VER(i915) <= 7) 96 96 sandybridge_pcode_read(i915, GEN6_PCODE_READ_RC6VIDS, 97 97 &rc6vids, NULL); 98 98 ··· 100 100 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE)); 101 101 seq_printf(m, "RC6 Enabled: %s\n", 102 102 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE)); 103 - if (INTEL_GEN(i915) >= 9) { 103 + if (GRAPHICS_VER(i915) >= 9) { 104 104 seq_printf(m, "Render Well Gating Enabled: %s\n", 105 105 yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE)); 106 106 seq_printf(m, "Media Well Gating Enabled: %s\n", ··· 134 134 135 135 seq_printf(m, "Core Power Down: %s\n", 136 136 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK)); 137 - if (INTEL_GEN(i915) >= 9) { 137 + if (GRAPHICS_VER(i915) >= 9) { 138 138 seq_printf(m, "Render Power Well: %s\n", 139 139 (gen9_powergate_status & 140 140 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down"); ··· 150 150 print_rc6_res(m, "RC6+ residency since boot:", GEN6_GT_GFX_RC6p); 151 151 print_rc6_res(m, "RC6++ residency since boot:", GEN6_GT_GFX_RC6pp); 152 152 153 - if (INTEL_GEN(i915) <= 7) { 153 + if (GRAPHICS_VER(i915) <= 7) { 154 154 seq_printf(m, "RC6 voltage: %dmV\n", 155 155 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff))); 156 156 seq_printf(m, "RC6+ voltage: %dmV\n", ··· 230 230 with_intel_runtime_pm(gt->uncore->rpm, wakeref) { 231 231 if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915)) 232 232 err = vlv_drpc(m); 233 - else if (INTEL_GEN(i915) >= 6) 233 + else if (GRAPHICS_VER(i915) >= 6) 234 234 err = gen6_drpc(m); 235 235 else 236 236 err = ilk_drpc(m); ··· 250 250 251 251 wakeref = intel_runtime_pm_get(uncore->rpm); 252 252 253 - if (IS_GEN(i915, 5)) { 253 + if (GRAPHICS_VER(i915) == 5) { 254 254 u16 rgvswctl = intel_uncore_read16(uncore, MEMSWCTL); 255 255 u16 rgvstat = intel_uncore_read16(uncore, MEMSTAT_ILK); 256 256 ··· 296 296 297 297 seq_printf(m, "efficient (RPe) frequency: %d MHz\n", 298 298 intel_gpu_freq(rps, rps->efficient_freq)); 299 - } else if (INTEL_GEN(i915) >= 6) { 299 + } else if (GRAPHICS_VER(i915) >= 6) { 300 300 u32 rp_state_limits; 301 301 u32 gt_perf_status; 302 302 u32 rp_state_cap; ··· 321 321 intel_uncore_forcewake_get(uncore, FORCEWAKE_ALL); 322 322 323 323 reqf = intel_uncore_read(uncore, GEN6_RPNSWREQ); 324 - if (INTEL_GEN(i915) >= 9) { 324 + if (GRAPHICS_VER(i915) >= 9) { 325 325 reqf >>= 23; 326 326 } else { 327 327 reqf &= ~GEN6_TURBO_DISABLE; ··· 354 354 355 355 intel_uncore_forcewake_put(uncore, FORCEWAKE_ALL); 356 356 357 - if (INTEL_GEN(i915) >= 11) { 357 + if (GRAPHICS_VER(i915) >= 11) { 358 358 pm_ier = intel_uncore_read(uncore, GEN11_GPM_WGBOXPERF_INTR_ENABLE); 359 359 pm_imr = intel_uncore_read(uncore, GEN11_GPM_WGBOXPERF_INTR_MASK); 360 360 /* ··· 363 363 */ 364 364 pm_isr = 0; 365 365 pm_iir = 0; 366 - } else if (INTEL_GEN(i915) >= 8) { 366 + } else if (GRAPHICS_VER(i915) >= 8) { 367 367 pm_ier = intel_uncore_read(uncore, GEN8_GT_IER(2)); 368 368 pm_imr = intel_uncore_read(uncore, GEN8_GT_IMR(2)); 369 369 pm_isr = intel_uncore_read(uncore, GEN8_GT_ISR(2)); ··· 386 386 387 387 seq_printf(m, "PM IER=0x%08x IMR=0x%08x, MASK=0x%08x\n", 388 388 pm_ier, pm_imr, pm_mask); 389 - if (INTEL_GEN(i915) <= 10) 389 + if (GRAPHICS_VER(i915) <= 10) 390 390 seq_printf(m, "PM ISR=0x%08x IIR=0x%08x\n", 391 391 pm_isr, pm_iir); 392 392 seq_printf(m, "pm_intrmsk_mbz: 0x%08x\n", 393 393 rps->pm_intrmsk_mbz); 394 394 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status); 395 395 seq_printf(m, "Render p-state ratio: %d\n", 396 - (gt_perf_status & (INTEL_GEN(i915) >= 9 ? 0x1ff00 : 0xff00)) >> 8); 396 + (gt_perf_status & (GRAPHICS_VER(i915) >= 9 ? 0x1ff00 : 0xff00)) >> 8); 397 397 seq_printf(m, "Render p-state VID: %d\n", 398 398 gt_perf_status & 0xff); 399 399 seq_printf(m, "Render p-state limit: %d\n", ··· 437 437 max_freq = (IS_GEN9_LP(i915) ? rp_state_cap >> 0 : 438 438 rp_state_cap >> 16) & 0xff; 439 439 max_freq *= (IS_GEN9_BC(i915) || 440 - INTEL_GEN(i915) >= 10 ? GEN9_FREQ_SCALER : 1); 440 + GRAPHICS_VER(i915) >= 10 ? GEN9_FREQ_SCALER : 1); 441 441 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n", 442 442 intel_gpu_freq(rps, max_freq)); 443 443 444 444 max_freq = (rp_state_cap & 0xff00) >> 8; 445 445 max_freq *= (IS_GEN9_BC(i915) || 446 - INTEL_GEN(i915) >= 10 ? GEN9_FREQ_SCALER : 1); 446 + GRAPHICS_VER(i915) >= 10 ? GEN9_FREQ_SCALER : 1); 447 447 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n", 448 448 intel_gpu_freq(rps, max_freq)); 449 449 450 450 max_freq = (IS_GEN9_LP(i915) ? rp_state_cap >> 16 : 451 451 rp_state_cap >> 0) & 0xff; 452 452 max_freq *= (IS_GEN9_BC(i915) || 453 - INTEL_GEN(i915) >= 10 ? GEN9_FREQ_SCALER : 1); 453 + GRAPHICS_VER(i915) >= 10 ? GEN9_FREQ_SCALER : 1); 454 454 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n", 455 455 intel_gpu_freq(rps, max_freq)); 456 456 seq_printf(m, "Max overclocked frequency: %dMHz\n", ··· 488 488 { 489 489 struct intel_gt *gt = m->private; 490 490 struct drm_i915_private *i915 = gt->i915; 491 - const bool edram = INTEL_GEN(i915) > 8; 491 + const bool edram = GRAPHICS_VER(i915) > 8; 492 492 struct intel_rps *rps = &gt->rps; 493 493 unsigned int max_gpu_freq, min_gpu_freq; 494 494 intel_wakeref_t wakeref; ··· 500 500 501 501 min_gpu_freq = rps->min_freq; 502 502 max_gpu_freq = rps->max_freq; 503 - if (IS_GEN9_BC(i915) || INTEL_GEN(i915) >= 10) { 503 + if (IS_GEN9_BC(i915) || GRAPHICS_VER(i915) >= 10) { 504 504 /* Convert GT frequency to 50 HZ units */ 505 505 min_gpu_freq /= GEN9_FREQ_SCALER; 506 506 max_gpu_freq /= GEN9_FREQ_SCALER; ··· 518 518 intel_gpu_freq(rps, 519 519 (gpu_freq * 520 520 (IS_GEN9_BC(i915) || 521 - INTEL_GEN(i915) >= 10 ? 521 + GRAPHICS_VER(i915) >= 10 ? 522 522 GEN9_FREQ_SCALER : 1))), 523 523 ((ia_freq >> 0) & 0xff) * 100, 524 524 ((ia_freq >> 8) & 0xff) * 100); ··· 580 580 581 581 seq_printf(m, "Wait boosts: %d\n", READ_ONCE(rps->boosts)); 582 582 583 - if (INTEL_GEN(i915) >= 6 && intel_rps_is_active(rps)) { 583 + if (GRAPHICS_VER(i915) >= 6 && intel_rps_is_active(rps)) { 584 584 struct intel_uncore *uncore = gt->uncore; 585 585 u32 rpup, rpupei; 586 586 u32 rpdown, rpdownei;
+1 -1
drivers/gpu/drm/i915/gt/gen2_engine_cs.c
··· 74 74 cmd = MI_FLUSH; 75 75 if (mode & EMIT_INVALIDATE) { 76 76 cmd |= MI_EXE_FLUSH; 77 - if (IS_G4X(rq->engine->i915) || IS_GEN(rq->engine->i915, 5)) 77 + if (IS_G4X(rq->engine->i915) || GRAPHICS_VER(rq->engine->i915) == 5) 78 78 cmd |= MI_INVALIDATE_ISP; 79 79 } 80 80
+1 -1
drivers/gpu/drm/i915/gt/gen8_engine_cs.c
··· 38 38 * On GEN9: before VF_CACHE_INVALIDATE we need to emit a NULL 39 39 * pipe control. 40 40 */ 41 - if (IS_GEN(rq->engine->i915, 9)) 41 + if (GRAPHICS_VER(rq->engine->i915) == 9) 42 42 vf_flush_wa = true; 43 43 44 44 /* WaForGAMHang:kbl */
+1 -1
drivers/gpu/drm/i915/gt/gen8_ppgtt.c
··· 709 709 * 710 710 * Gen12 has inherited the same read-only fault issue from gen11. 711 711 */ 712 - ppgtt->vm.has_read_only = !IS_GEN_RANGE(gt->i915, 11, 12); 712 + ppgtt->vm.has_read_only = !IS_GRAPHICS_VER(gt->i915, 11, 12); 713 713 714 714 if (HAS_LMEM(gt->i915)) 715 715 ppgtt->vm.alloc_pt_dma = alloc_pt_lmem;
+1 -1
drivers/gpu/drm/i915/gt/intel_context_sseu.c
··· 76 76 { 77 77 int ret; 78 78 79 - GEM_BUG_ON(INTEL_GEN(ce->engine->i915) < 8); 79 + GEM_BUG_ON(GRAPHICS_VER(ce->engine->i915) < 8); 80 80 81 81 ret = intel_context_lock_pinned(ce); 82 82 if (ret)
+31 -29
drivers/gpu/drm/i915/gt/intel_engine_cs.c
··· 240 240 * Though they added more rings on g4x/ilk, they did not add 241 241 * per-engine HWSTAM until gen6. 242 242 */ 243 - if (INTEL_GEN(engine->i915) < 6 && engine->class != RENDER_CLASS) 243 + if (GRAPHICS_VER(engine->i915) < 6 && engine->class != RENDER_CLASS) 244 244 return; 245 245 246 - if (INTEL_GEN(engine->i915) >= 3) 246 + if (GRAPHICS_VER(engine->i915) >= 3) 247 247 ENGINE_WRITE(engine, RING_HWSTAM, mask); 248 248 else 249 249 ENGINE_WRITE16(engine, RING_HWSTAM, mask); ··· 265 265 const struct engine_info *info = &intel_engines[id]; 266 266 struct drm_i915_private *i915 = gt->i915; 267 267 struct intel_engine_cs *engine; 268 + u8 guc_class; 268 269 269 270 BUILD_BUG_ON(MAX_ENGINE_CLASS >= BIT(GEN11_ENGINE_CLASS_WIDTH)); 270 271 BUILD_BUG_ON(MAX_ENGINE_INSTANCE >= BIT(GEN11_ENGINE_INSTANCE_WIDTH)); ··· 294 293 engine->i915 = i915; 295 294 engine->gt = gt; 296 295 engine->uncore = gt->uncore; 297 - engine->mmio_base = __engine_mmio_base(i915, info->mmio_bases); 298 296 engine->hw_id = info->hw_id; 299 - engine->guc_id = MAKE_GUC_ID(info->class, info->instance); 297 + guc_class = engine_class_to_guc_class(info->class); 298 + engine->guc_id = MAKE_GUC_ID(guc_class, info->instance); 299 + engine->mmio_base = __engine_mmio_base(i915, info->mmio_bases); 300 300 301 301 engine->irq_handler = nop_irq_handler; 302 302 ··· 317 315 CONFIG_DRM_I915_TIMESLICE_DURATION; 318 316 319 317 /* Override to uninterruptible for OpenCL workloads. */ 320 - if (INTEL_GEN(i915) == 12 && engine->class == RENDER_CLASS) 318 + if (GRAPHICS_VER(i915) == 12 && engine->class == RENDER_CLASS) 321 319 engine->props.preempt_timeout_ms = 0; 322 320 323 321 engine->defaults = engine->props; /* never to change again */ ··· 354 352 * HEVC support is present on first engine instance 355 353 * before Gen11 and on all instances afterwards. 356 354 */ 357 - if (INTEL_GEN(i915) >= 11 || 358 - (INTEL_GEN(i915) >= 9 && engine->instance == 0)) 355 + if (GRAPHICS_VER(i915) >= 11 || 356 + (GRAPHICS_VER(i915) >= 9 && engine->instance == 0)) 359 357 engine->uabi_capabilities |= 360 358 I915_VIDEO_CLASS_CAPABILITY_HEVC; 361 359 ··· 363 361 * SFC block is present only on even logical engine 364 362 * instances. 365 363 */ 366 - if ((INTEL_GEN(i915) >= 11 && 364 + if ((GRAPHICS_VER(i915) >= 11 && 367 365 (engine->gt->info.vdbox_sfc_access & 368 366 BIT(engine->instance))) || 369 - (INTEL_GEN(i915) >= 9 && engine->instance == 0)) 367 + (GRAPHICS_VER(i915) >= 9 && engine->instance == 0)) 370 368 engine->uabi_capabilities |= 371 369 I915_VIDEO_AND_ENHANCE_CLASS_CAPABILITY_SFC; 372 370 } else if (engine->class == VIDEO_ENHANCEMENT_CLASS) { 373 - if (INTEL_GEN(i915) >= 9) 371 + if (GRAPHICS_VER(i915) >= 9) 374 372 engine->uabi_capabilities |= 375 373 I915_VIDEO_AND_ENHANCE_CLASS_CAPABILITY_SFC; 376 374 } ··· 468 466 469 467 info->engine_mask = INTEL_INFO(i915)->platform_engine_mask; 470 468 471 - if (INTEL_GEN(i915) < 11) 469 + if (GRAPHICS_VER(i915) < 11) 472 470 return info->engine_mask; 473 471 474 472 media_fuse = ~intel_uncore_read(uncore, GEN11_GT_VEBOX_VDBOX_DISABLE); ··· 494 492 * hooked up to an SFC (Scaler & Format Converter) unit. 495 493 * In TGL each VDBOX has access to an SFC. 496 494 */ 497 - if (INTEL_GEN(i915) >= 12 || logical_vdbox++ % 2 == 0) 495 + if (GRAPHICS_VER(i915) >= 12 || logical_vdbox++ % 2 == 0) 498 496 gt->info.vdbox_sfc_access |= BIT(i); 499 497 } 500 498 drm_dbg(&i915->drm, "vdbox enable: %04x, instances: %04lx\n", ··· 731 729 intel_engine_init_whitelist(engine); 732 730 intel_engine_init_ctx_wa(engine); 733 731 734 - if (INTEL_GEN(engine->i915) >= 12) 732 + if (GRAPHICS_VER(engine->i915) >= 12) 735 733 engine->flags |= I915_ENGINE_HAS_RELATIVE_MMIO; 736 734 737 735 return 0; ··· 999 997 1000 998 u64 acthd; 1001 999 1002 - if (INTEL_GEN(i915) >= 8) 1000 + if (GRAPHICS_VER(i915) >= 8) 1003 1001 acthd = ENGINE_READ64(engine, RING_ACTHD, RING_ACTHD_UDW); 1004 - else if (INTEL_GEN(i915) >= 4) 1002 + else if (GRAPHICS_VER(i915) >= 4) 1005 1003 acthd = ENGINE_READ(engine, RING_ACTHD); 1006 1004 else 1007 1005 acthd = ENGINE_READ(engine, ACTHD); ··· 1013 1011 { 1014 1012 u64 bbaddr; 1015 1013 1016 - if (INTEL_GEN(engine->i915) >= 8) 1014 + if (GRAPHICS_VER(engine->i915) >= 8) 1017 1015 bbaddr = ENGINE_READ64(engine, RING_BBADDR, RING_BBADDR_UDW); 1018 1016 else 1019 1017 bbaddr = ENGINE_READ(engine, RING_BBADDR); ··· 1060 1058 { 1061 1059 int err = 0; 1062 1060 1063 - if (INTEL_GEN(engine->i915) < 3) 1061 + if (GRAPHICS_VER(engine->i915) < 3) 1064 1062 return -ENODEV; 1065 1063 1066 1064 ENGINE_TRACE(engine, "\n"); ··· 1110 1108 u32 mcr_mask, mcr_ss, mcr, old_mcr, val; 1111 1109 enum forcewake_domains fw_domains; 1112 1110 1113 - if (INTEL_GEN(i915) >= 11) { 1111 + if (GRAPHICS_VER(i915) >= 11) { 1114 1112 mcr_mask = GEN11_MCR_SLICE_MASK | GEN11_MCR_SUBSLICE_MASK; 1115 1113 mcr_ss = GEN11_MCR_SLICE(slice) | GEN11_MCR_SUBSLICE(subslice); 1116 1114 } else { ··· 1159 1157 1160 1158 memset(instdone, 0, sizeof(*instdone)); 1161 1159 1162 - switch (INTEL_GEN(i915)) { 1160 + switch (GRAPHICS_VER(i915)) { 1163 1161 default: 1164 1162 instdone->instdone = 1165 1163 intel_uncore_read(uncore, RING_INSTDONE(mmio_base)); ··· 1169 1167 1170 1168 instdone->slice_common = 1171 1169 intel_uncore_read(uncore, GEN7_SC_INSTDONE); 1172 - if (INTEL_GEN(i915) >= 12) { 1170 + if (GRAPHICS_VER(i915) >= 12) { 1173 1171 instdone->slice_common_extra[0] = 1174 1172 intel_uncore_read(uncore, GEN12_SC_INSTDONE_EXTRA); 1175 1173 instdone->slice_common_extra[1] = ··· 1232 1230 idle = false; 1233 1231 1234 1232 /* No bit for gen2, so assume the CS parser is idle */ 1235 - if (INTEL_GEN(engine->i915) > 2 && 1233 + if (GRAPHICS_VER(engine->i915) > 2 && 1236 1234 !(ENGINE_READ(engine, RING_MI_MODE) & MODE_IDLE)) 1237 1235 idle = false; 1238 1236 ··· 1329 1327 1330 1328 bool intel_engine_can_store_dword(struct intel_engine_cs *engine) 1331 1329 { 1332 - switch (INTEL_GEN(engine->i915)) { 1330 + switch (GRAPHICS_VER(engine->i915)) { 1333 1331 case 2: 1334 1332 return false; /* uses physical not virtual addresses */ 1335 1333 case 3: ··· 1434 1432 struct intel_engine_execlists * const execlists = &engine->execlists; 1435 1433 u64 addr; 1436 1434 1437 - if (engine->id == RENDER_CLASS && IS_GEN_RANGE(dev_priv, 4, 7)) 1435 + if (engine->id == RENDER_CLASS && IS_GRAPHICS_VER(dev_priv, 4, 7)) 1438 1436 drm_printf(m, "\tCCID: 0x%08x\n", ENGINE_READ(engine, CCID)); 1439 1437 if (HAS_EXECLISTS(dev_priv)) { 1440 1438 drm_printf(m, "\tEL_STAT_HI: 0x%08x\n", ··· 1451 1449 drm_printf(m, "\tRING_CTL: 0x%08x%s\n", 1452 1450 ENGINE_READ(engine, RING_CTL), 1453 1451 ENGINE_READ(engine, RING_CTL) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? " [waiting]" : ""); 1454 - if (INTEL_GEN(engine->i915) > 2) { 1452 + if (GRAPHICS_VER(engine->i915) > 2) { 1455 1453 drm_printf(m, "\tRING_MODE: 0x%08x%s\n", 1456 1454 ENGINE_READ(engine, RING_MI_MODE), 1457 1455 ENGINE_READ(engine, RING_MI_MODE) & (MODE_IDLE) ? " [idle]" : ""); 1458 1456 } 1459 1457 1460 - if (INTEL_GEN(dev_priv) >= 6) { 1458 + if (GRAPHICS_VER(dev_priv) >= 6) { 1461 1459 drm_printf(m, "\tRING_IMR: 0x%08x\n", 1462 1460 ENGINE_READ(engine, RING_IMR)); 1463 1461 drm_printf(m, "\tRING_ESR: 0x%08x\n", ··· 1474 1472 addr = intel_engine_get_last_batch_head(engine); 1475 1473 drm_printf(m, "\tBBADDR: 0x%08x_%08x\n", 1476 1474 upper_32_bits(addr), lower_32_bits(addr)); 1477 - if (INTEL_GEN(dev_priv) >= 8) 1475 + if (GRAPHICS_VER(dev_priv) >= 8) 1478 1476 addr = ENGINE_READ64(engine, RING_DMA_FADD, RING_DMA_FADD_UDW); 1479 - else if (INTEL_GEN(dev_priv) >= 4) 1477 + else if (GRAPHICS_VER(dev_priv) >= 4) 1480 1478 addr = ENGINE_READ(engine, RING_DMA_FADD); 1481 1479 else 1482 1480 addr = ENGINE_READ(engine, DMA_FADD_I8XX); 1483 1481 drm_printf(m, "\tDMA_FADDR: 0x%08x_%08x\n", 1484 1482 upper_32_bits(addr), lower_32_bits(addr)); 1485 - if (INTEL_GEN(dev_priv) >= 4) { 1483 + if (GRAPHICS_VER(dev_priv) >= 4) { 1486 1484 drm_printf(m, "\tIPEIR: 0x%08x\n", 1487 1485 ENGINE_READ(engine, RING_IPEIR)); 1488 1486 drm_printf(m, "\tIPEHR: 0x%08x\n", ··· 1561 1559 } 1562 1560 rcu_read_unlock(); 1563 1561 execlists_active_unlock_bh(execlists); 1564 - } else if (INTEL_GEN(dev_priv) > 6) { 1562 + } else if (GRAPHICS_VER(dev_priv) > 6) { 1565 1563 drm_printf(m, "\tPP_DIR_BASE: 0x%08x\n", 1566 1564 ENGINE_READ(engine, RING_PP_DIR_BASE)); 1567 1565 drm_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
+2 -2
drivers/gpu/drm/i915/gt/intel_engine_types.h
··· 606 606 } 607 607 608 608 #define instdone_has_slice(dev_priv___, sseu___, slice___) \ 609 - ((IS_GEN(dev_priv___, 7) ? 1 : ((sseu___)->slice_mask)) & BIT(slice___)) 609 + ((GRAPHICS_VER(dev_priv___) == 7 ? 1 : ((sseu___)->slice_mask)) & BIT(slice___)) 610 610 611 611 #define instdone_has_subslice(dev_priv__, sseu__, slice__, subslice__) \ 612 - (IS_GEN(dev_priv__, 7) ? (1 & BIT(subslice__)) : \ 612 + (GRAPHICS_VER(dev_priv__) == 7 ? (1 & BIT(subslice__)) : \ 613 613 intel_sseu_has_subslice(sseu__, 0, subslice__)) 614 614 615 615 #define for_each_instdone_slice_subslice(dev_priv_, sseu_, slice_, subslice_) \
+9 -9
drivers/gpu/drm/i915/gt/intel_execlists_submission.c
··· 1847 1847 ENGINE_TRACE(engine, "csb[%d]: status=0x%08x:0x%08x\n", 1848 1848 head, upper_32_bits(csb), lower_32_bits(csb)); 1849 1849 1850 - if (INTEL_GEN(engine->i915) >= 12) 1850 + if (GRAPHICS_VER(engine->i915) >= 12) 1851 1851 promote = gen12_csb_parse(csb); 1852 1852 else 1853 1853 promote = gen8_csb_parse(csb); ··· 2772 2772 2773 2773 intel_engine_set_hwsp_writemask(engine, ~0u); /* HWSTAM */ 2774 2774 2775 - if (INTEL_GEN(engine->i915) >= 11) 2775 + if (GRAPHICS_VER(engine->i915) >= 11) 2776 2776 mode = _MASKED_BIT_ENABLE(GEN11_GFX_DISABLE_LEGACY_MODE); 2777 2777 else 2778 2778 mode = _MASKED_BIT_ENABLE(GFX_RUN_LIST_ENABLE); ··· 3103 3103 3104 3104 static bool can_preempt(struct intel_engine_cs *engine) 3105 3105 { 3106 - if (INTEL_GEN(engine->i915) > 8) 3106 + if (GRAPHICS_VER(engine->i915) > 8) 3107 3107 return true; 3108 3108 3109 3109 /* GPGPU on bdw requires extra w/a; not implemented */ ··· 3156 3156 engine->emit_flush = gen8_emit_flush_xcs; 3157 3157 engine->emit_init_breadcrumb = gen8_emit_init_breadcrumb; 3158 3158 engine->emit_fini_breadcrumb = gen8_emit_fini_breadcrumb_xcs; 3159 - if (INTEL_GEN(engine->i915) >= 12) { 3159 + if (GRAPHICS_VER(engine->i915) >= 12) { 3160 3160 engine->emit_fini_breadcrumb = gen12_emit_fini_breadcrumb_xcs; 3161 3161 engine->emit_flush = gen12_emit_flush_xcs; 3162 3162 } 3163 3163 engine->set_default_submission = execlists_set_default_submission; 3164 3164 3165 - if (INTEL_GEN(engine->i915) < 11) { 3165 + if (GRAPHICS_VER(engine->i915) < 11) { 3166 3166 engine->irq_enable = gen8_logical_ring_enable_irq; 3167 3167 engine->irq_disable = gen8_logical_ring_disable_irq; 3168 3168 } else { ··· 3195 3195 { 3196 3196 unsigned int shift = 0; 3197 3197 3198 - if (INTEL_GEN(engine->i915) < 11) { 3198 + if (GRAPHICS_VER(engine->i915) < 11) { 3199 3199 const u8 irq_shifts[] = { 3200 3200 [RCS0] = GEN8_RCS_IRQ_SHIFT, 3201 3201 [BCS0] = GEN8_BCS_IRQ_SHIFT, ··· 3215 3215 3216 3216 static void rcs_submission_override(struct intel_engine_cs *engine) 3217 3217 { 3218 - switch (INTEL_GEN(engine->i915)) { 3218 + switch (GRAPHICS_VER(engine->i915)) { 3219 3219 case 12: 3220 3220 engine->emit_flush = gen12_emit_flush_rcs; 3221 3221 engine->emit_fini_breadcrumb = gen12_emit_fini_breadcrumb_rcs; ··· 3266 3266 execlists->csb_write = 3267 3267 &engine->status_page.addr[intel_hws_csb_write_index(i915)]; 3268 3268 3269 - if (INTEL_GEN(i915) < 11) 3269 + if (GRAPHICS_VER(i915) < 11) 3270 3270 execlists->csb_size = GEN8_CSB_ENTRIES; 3271 3271 else 3272 3272 execlists->csb_size = GEN11_CSB_ENTRIES; 3273 3273 3274 3274 engine->context_tag = GENMASK(BITS_PER_LONG - 2, 0); 3275 - if (INTEL_GEN(engine->i915) >= 11) { 3275 + if (GRAPHICS_VER(engine->i915) >= 11) { 3276 3276 execlists->ccid |= engine->instance << (GEN11_ENGINE_INSTANCE_SHIFT - 32); 3277 3277 execlists->ccid |= engine->class << (GEN11_ENGINE_CLASS_SHIFT - 32); 3278 3278 }
+25 -12
drivers/gpu/drm/i915/gt/intel_ggtt.c
··· 107 107 if (!intel_vtd_active()) 108 108 return false; 109 109 110 - if (IS_GEN(i915, 5) && IS_MOBILE(i915)) 110 + if (GRAPHICS_VER(i915) == 5 && IS_MOBILE(i915)) 111 111 return true; 112 112 113 - if (IS_GEN(i915, 12)) 113 + if (GRAPHICS_VER(i915) == 12) 114 114 return true; /* XXX DMAR fault reason 7 */ 115 115 116 116 return false; ··· 176 176 177 177 gen8_ggtt_invalidate(ggtt); 178 178 179 - if (INTEL_GEN(i915) >= 12) 179 + if (GRAPHICS_VER(i915) >= 12) 180 180 intel_uncore_write_fw(uncore, GEN12_GUC_TLB_INV_CR, 181 181 GEN12_GUC_TLB_INV_CR_INVALIDATE); 182 182 else ··· 746 746 747 747 mutex_unlock(&ggtt->vm.mutex); 748 748 i915_address_space_fini(&ggtt->vm); 749 - dma_resv_fini(&ggtt->vm.resv); 750 749 751 750 arch_phys_wc_del(ggtt->mtrr); 752 751 ··· 765 766 766 767 intel_ggtt_fini_fences(ggtt); 767 768 ggtt_cleanup_hw(ggtt); 769 + } 770 + 771 + /** 772 + * i915_ggtt_driver_late_release - Cleanup of GGTT that needs to be done after 773 + * all free objects have been drained. 774 + * @i915: i915 device 775 + */ 776 + void i915_ggtt_driver_late_release(struct drm_i915_private *i915) 777 + { 778 + struct i915_ggtt *ggtt = &i915->ggtt; 779 + 780 + GEM_WARN_ON(kref_read(&ggtt->vm.resv_ref) != 1); 781 + dma_resv_fini(&ggtt->vm._resv); 768 782 } 769 783 770 784 static unsigned int gen6_get_total_gtt_size(u16 snb_gmch_ctl) ··· 832 820 * resort to an uncached mapping. The WC issue is easily caught by the 833 821 * readback check when writing GTT PTE entries. 834 822 */ 835 - if (IS_GEN9_LP(i915) || INTEL_GEN(i915) >= 10) 823 + if (IS_GEN9_LP(i915) || GRAPHICS_VER(i915) >= 10) 836 824 ggtt->gsm = ioremap(phys_addr, size); 837 825 else 838 826 ggtt->gsm = ioremap_wc(phys_addr, size); ··· 841 829 return -ENOMEM; 842 830 } 843 831 832 + kref_init(&ggtt->vm.resv_ref); 844 833 ret = setup_scratch_page(&ggtt->vm); 845 834 if (ret) { 846 835 drm_err(&i915->drm, "Scratch setup failed\n"); ··· 1078 1065 ggtt->vm.pte_encode = hsw_pte_encode; 1079 1066 else if (IS_VALLEYVIEW(i915)) 1080 1067 ggtt->vm.pte_encode = byt_pte_encode; 1081 - else if (INTEL_GEN(i915) >= 7) 1068 + else if (GRAPHICS_VER(i915) >= 7) 1082 1069 ggtt->vm.pte_encode = ivb_pte_encode; 1083 1070 else 1084 1071 ggtt->vm.pte_encode = snb_pte_encode; ··· 1148 1135 ggtt->vm.gt = gt; 1149 1136 ggtt->vm.i915 = i915; 1150 1137 ggtt->vm.dma = i915->drm.dev; 1151 - dma_resv_init(&ggtt->vm.resv); 1138 + dma_resv_init(&ggtt->vm._resv); 1152 1139 1153 - if (INTEL_GEN(i915) <= 5) 1140 + if (GRAPHICS_VER(i915) <= 5) 1154 1141 ret = i915_gmch_probe(ggtt); 1155 - else if (INTEL_GEN(i915) < 8) 1142 + else if (GRAPHICS_VER(i915) < 8) 1156 1143 ret = gen6_gmch_probe(ggtt); 1157 1144 else 1158 1145 ret = gen8_gmch_probe(ggtt); 1159 1146 if (ret) { 1160 - dma_resv_fini(&ggtt->vm.resv); 1147 + dma_resv_fini(&ggtt->vm._resv); 1161 1148 return ret; 1162 1149 } 1163 1150 ··· 1209 1196 1210 1197 int i915_ggtt_enable_hw(struct drm_i915_private *i915) 1211 1198 { 1212 - if (INTEL_GEN(i915) < 6 && !intel_enable_gtt()) 1199 + if (GRAPHICS_VER(i915) < 6 && !intel_enable_gtt()) 1213 1200 return -EIO; 1214 1201 1215 1202 return 0; ··· 1274 1261 if (flush) 1275 1262 wbinvd_on_all_cpus(); 1276 1263 1277 - if (INTEL_GEN(ggtt->vm.i915) >= 8) 1264 + if (GRAPHICS_VER(ggtt->vm.i915) >= 8) 1278 1265 setup_private_pat(ggtt->vm.gt->uncore); 1279 1266 1280 1267 intel_ggtt_restore_fences(ggtt);
+17 -17
drivers/gpu/drm/i915/gt/intel_ggtt_fencing.c
··· 56 56 int fence_pitch_shift; 57 57 u64 val; 58 58 59 - if (INTEL_GEN(fence_to_i915(fence)) >= 6) { 59 + if (GRAPHICS_VER(fence_to_i915(fence)) >= 6) { 60 60 fence_reg_lo = FENCE_REG_GEN6_LO(fence->id); 61 61 fence_reg_hi = FENCE_REG_GEN6_HI(fence->id); 62 62 fence_pitch_shift = GEN6_FENCE_PITCH_SHIFT; ··· 173 173 * and explicitly managed for internal users. 174 174 */ 175 175 176 - if (IS_GEN(i915, 2)) 176 + if (GRAPHICS_VER(i915) == 2) 177 177 i830_write_fence_reg(fence); 178 - else if (IS_GEN(i915, 3)) 178 + else if (GRAPHICS_VER(i915) == 3) 179 179 i915_write_fence_reg(fence); 180 180 else 181 181 i965_write_fence_reg(fence); ··· 188 188 189 189 static bool gpu_uses_fence_registers(struct i915_fence_reg *fence) 190 190 { 191 - return INTEL_GEN(fence_to_i915(fence)) < 4; 191 + return GRAPHICS_VER(fence_to_i915(fence)) < 4; 192 192 } 193 193 194 194 static int fence_update(struct i915_fence_reg *fence, ··· 569 569 u32 swizzle_x = I915_BIT_6_SWIZZLE_UNKNOWN; 570 570 u32 swizzle_y = I915_BIT_6_SWIZZLE_UNKNOWN; 571 571 572 - if (INTEL_GEN(i915) >= 8 || IS_VALLEYVIEW(i915)) { 572 + if (GRAPHICS_VER(i915) >= 8 || IS_VALLEYVIEW(i915)) { 573 573 /* 574 574 * On BDW+, swizzling is not used. We leave the CPU memory 575 575 * controller in charge of optimizing memory accesses without ··· 579 579 */ 580 580 swizzle_x = I915_BIT_6_SWIZZLE_NONE; 581 581 swizzle_y = I915_BIT_6_SWIZZLE_NONE; 582 - } else if (INTEL_GEN(i915) >= 6) { 582 + } else if (GRAPHICS_VER(i915) >= 6) { 583 583 if (i915->preserve_bios_swizzle) { 584 584 if (intel_uncore_read(uncore, DISP_ARB_CTL) & 585 585 DISP_TILE_SURFACE_SWIZZLING) { ··· 611 611 swizzle_y = I915_BIT_6_SWIZZLE_NONE; 612 612 } 613 613 } 614 - } else if (IS_GEN(i915, 5)) { 614 + } else if (GRAPHICS_VER(i915) == 5) { 615 615 /* 616 616 * On Ironlake whatever DRAM config, GPU always do 617 617 * same swizzling setup. 618 618 */ 619 619 swizzle_x = I915_BIT_6_SWIZZLE_9_10; 620 620 swizzle_y = I915_BIT_6_SWIZZLE_9; 621 - } else if (IS_GEN(i915, 2)) { 621 + } else if (GRAPHICS_VER(i915) == 2) { 622 622 /* 623 623 * As far as we know, the 865 doesn't have these bit 6 624 624 * swizzling issues. ··· 697 697 } 698 698 699 699 /* check for L-shaped memory aka modified enhanced addressing */ 700 - if (IS_GEN(i915, 4) && 700 + if (GRAPHICS_VER(i915) == 4 && 701 701 !(intel_uncore_read(uncore, DCC2) & DCC2_MODIFIED_ENHANCED_DISABLE)) { 702 702 swizzle_x = I915_BIT_6_SWIZZLE_UNKNOWN; 703 703 swizzle_y = I915_BIT_6_SWIZZLE_UNKNOWN; ··· 844 844 845 845 if (!i915_ggtt_has_aperture(ggtt)) 846 846 num_fences = 0; 847 - else if (INTEL_GEN(i915) >= 7 && 847 + else if (GRAPHICS_VER(i915) >= 7 && 848 848 !(IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915))) 849 849 num_fences = 32; 850 - else if (INTEL_GEN(i915) >= 4 || 850 + else if (GRAPHICS_VER(i915) >= 4 || 851 851 IS_I945G(i915) || IS_I945GM(i915) || 852 852 IS_G33(i915) || IS_PINEVIEW(i915)) 853 853 num_fences = 16; ··· 895 895 struct drm_i915_private *i915 = gt->i915; 896 896 struct intel_uncore *uncore = gt->uncore; 897 897 898 - if (INTEL_GEN(i915) < 5 || 898 + if (GRAPHICS_VER(i915) < 5 || 899 899 i915->ggtt.bit_6_swizzle_x == I915_BIT_6_SWIZZLE_NONE) 900 900 return; 901 901 902 902 intel_uncore_rmw(uncore, DISP_ARB_CTL, 0, DISP_TILE_SURFACE_SWIZZLING); 903 903 904 - if (IS_GEN(i915, 5)) 904 + if (GRAPHICS_VER(i915) == 5) 905 905 return; 906 906 907 907 intel_uncore_rmw(uncore, TILECTL, 0, TILECTL_SWZCTL); 908 908 909 - if (IS_GEN(i915, 6)) 909 + if (GRAPHICS_VER(i915) == 6) 910 910 intel_uncore_write(uncore, 911 911 ARB_MODE, 912 912 _MASKED_BIT_ENABLE(ARB_MODE_SWIZZLE_SNB)); 913 - else if (IS_GEN(i915, 7)) 913 + else if (GRAPHICS_VER(i915) == 7) 914 914 intel_uncore_write(uncore, 915 915 ARB_MODE, 916 916 _MASKED_BIT_ENABLE(ARB_MODE_SWIZZLE_IVB)); 917 - else if (IS_GEN(i915, 8)) 917 + else if (GRAPHICS_VER(i915) == 8) 918 918 intel_uncore_write(uncore, 919 919 GAMTARBMODE, 920 920 _MASKED_BIT_ENABLE(ARB_MODE_SWIZZLE_BDW)); 921 921 else 922 - MISSING_CASE(INTEL_GEN(i915)); 922 + MISSING_CASE(GRAPHICS_VER(i915)); 923 923 }
+14 -15
drivers/gpu/drm/i915/gt/intel_gt.c
··· 68 68 id = INTEL_REGION_LMEM; 69 69 70 70 mem->id = id; 71 - mem->type = INTEL_MEMORY_LOCAL; 72 - mem->instance = 0; 73 71 74 72 intel_memory_region_set_name(mem, "local%u", mem->instance); 75 73 ··· 113 115 init_unused_ring(gt, SRB1_BASE); 114 116 init_unused_ring(gt, SRB2_BASE); 115 117 init_unused_ring(gt, SRB3_BASE); 116 - } else if (IS_GEN(i915, 2)) { 118 + } else if (GRAPHICS_VER(i915) == 2) { 117 119 init_unused_ring(gt, SRB0_BASE); 118 120 init_unused_ring(gt, SRB1_BASE); 119 - } else if (IS_GEN(i915, 3)) { 121 + } else if (GRAPHICS_VER(i915) == 3) { 120 122 init_unused_ring(gt, PRB1_BASE); 121 123 init_unused_ring(gt, PRB2_BASE); 122 124 } ··· 133 135 /* Double layer security blanket, see i915_gem_init() */ 134 136 intel_uncore_forcewake_get(uncore, FORCEWAKE_ALL); 135 137 136 - if (HAS_EDRAM(i915) && INTEL_GEN(i915) < 9) 138 + if (HAS_EDRAM(i915) && GRAPHICS_VER(i915) < 9) 137 139 intel_uncore_rmw(uncore, HSW_IDICR, 0, IDIHASHMSK(0xf)); 138 140 139 141 if (IS_HASWELL(i915)) ··· 206 208 struct intel_uncore *uncore = gt->uncore; 207 209 u32 eir; 208 210 209 - if (!IS_GEN(i915, 2)) 211 + if (GRAPHICS_VER(i915) != 2) 210 212 clear_register(uncore, PGTBL_ER); 211 213 212 - if (INTEL_GEN(i915) < 4) 214 + if (GRAPHICS_VER(i915) < 4) 213 215 clear_register(uncore, IPEIR(RENDER_RING_BASE)); 214 216 else 215 217 clear_register(uncore, IPEIR_I965); ··· 227 229 I915_MASTER_ERROR_INTERRUPT); 228 230 } 229 231 230 - if (INTEL_GEN(i915) >= 12) { 232 + if (GRAPHICS_VER(i915) >= 12) { 231 233 rmw_clear(uncore, GEN12_RING_FAULT_REG, RING_FAULT_VALID); 232 234 intel_uncore_posting_read(uncore, GEN12_RING_FAULT_REG); 233 - } else if (INTEL_GEN(i915) >= 8) { 235 + } else if (GRAPHICS_VER(i915) >= 8) { 234 236 rmw_clear(uncore, GEN8_RING_FAULT_REG, RING_FAULT_VALID); 235 237 intel_uncore_posting_read(uncore, GEN8_RING_FAULT_REG); 236 - } else if (INTEL_GEN(i915) >= 6) { 238 + } else if (GRAPHICS_VER(i915) >= 6) { 237 239 struct intel_engine_cs *engine; 238 240 enum intel_engine_id id; 239 241 ··· 271 273 i915_reg_t fault_reg, fault_data0_reg, fault_data1_reg; 272 274 u32 fault; 273 275 274 - if (INTEL_GEN(gt->i915) >= 12) { 276 + if (GRAPHICS_VER(gt->i915) >= 12) { 275 277 fault_reg = GEN12_RING_FAULT_REG; 276 278 fault_data0_reg = GEN12_FAULT_TLB_DATA0; 277 279 fault_data1_reg = GEN12_FAULT_TLB_DATA1; ··· 311 313 struct drm_i915_private *i915 = gt->i915; 312 314 313 315 /* From GEN8 onwards we only have one 'All Engine Fault Register' */ 314 - if (INTEL_GEN(i915) >= 8) 316 + if (GRAPHICS_VER(i915) >= 8) 315 317 gen8_check_faults(gt); 316 - else if (INTEL_GEN(i915) >= 6) 318 + else if (GRAPHICS_VER(i915) >= 6) 317 319 gen6_check_faults(gt); 318 320 else 319 321 return; ··· 365 367 void intel_gt_chipset_flush(struct intel_gt *gt) 366 368 { 367 369 wmb(); 368 - if (INTEL_GEN(gt->i915) < 6) 370 + if (GRAPHICS_VER(gt->i915) < 6) 369 371 intel_gtt_chipset_flush(); 370 372 } 371 373 ··· 589 591 */ 590 592 intel_uncore_forcewake_get(gt->uncore, FORCEWAKE_ALL); 591 593 592 - err = intel_gt_init_scratch(gt, IS_GEN(gt->i915, 2) ? SZ_256K : SZ_4K); 594 + err = intel_gt_init_scratch(gt, 595 + GRAPHICS_VER(gt->i915) == 2 ? SZ_256K : SZ_4K); 593 596 if (err) 594 597 goto out_fw; 595 598
+6 -6
drivers/gpu/drm/i915/gt/intel_gt_clock_utils.c
··· 76 76 u32 f19_2_mhz = 19200000; 77 77 u32 f24_mhz = 24000000; 78 78 79 - if (INTEL_GEN(uncore->i915) <= 4) { 79 + if (GRAPHICS_VER(uncore->i915) <= 4) { 80 80 /* 81 81 * PRMs say: 82 82 * ··· 85 85 * (“CLKCFG”) MCHBAR register) 86 86 */ 87 87 return RUNTIME_INFO(uncore->i915)->rawclk_freq * 1000 / 16; 88 - } else if (INTEL_GEN(uncore->i915) <= 8) { 88 + } else if (GRAPHICS_VER(uncore->i915) <= 8) { 89 89 /* 90 90 * PRMs say: 91 91 * ··· 94 94 * rolling over every 1.5 hours). 95 95 */ 96 96 return f12_5_mhz; 97 - } else if (INTEL_GEN(uncore->i915) <= 9) { 97 + } else if (GRAPHICS_VER(uncore->i915) <= 9) { 98 98 u32 ctc_reg = intel_uncore_read(uncore, CTC_MODE); 99 99 u32 freq = 0; 100 100 ··· 113 113 } 114 114 115 115 return freq; 116 - } else if (INTEL_GEN(uncore->i915) <= 12) { 116 + } else if (GRAPHICS_VER(uncore->i915) <= 12) { 117 117 u32 ctc_reg = intel_uncore_read(uncore, CTC_MODE); 118 118 u32 freq = 0; 119 119 ··· 128 128 } else { 129 129 u32 c0 = intel_uncore_read(uncore, RPM_CONFIG0); 130 130 131 - if (INTEL_GEN(uncore->i915) <= 10) 131 + if (GRAPHICS_VER(uncore->i915) <= 10) 132 132 freq = gen10_get_crystal_clock_freq(uncore, c0); 133 133 else 134 134 freq = gen11_get_crystal_clock_freq(uncore, c0); ··· 211 211 * frozen machine. 212 212 */ 213 213 val = div_u64_roundup(intel_gt_ns_to_clock_interval(gt, ns), 16); 214 - if (IS_GEN(gt->i915, 6)) 214 + if (GRAPHICS_VER(gt->i915) == 6) 215 215 val = div_u64_roundup(val, 25) * 25; 216 216 217 217 return val;
+14 -10
drivers/gpu/drm/i915/gt/intel_gt_irq.c
··· 194 194 195 195 void gen11_gt_irq_postinstall(struct intel_gt *gt) 196 196 { 197 - const u32 irqs = 198 - GT_CS_MASTER_ERROR_INTERRUPT | 199 - GT_RENDER_USER_INTERRUPT | 200 - GT_CONTEXT_SWITCH_INTERRUPT | 201 - GT_WAIT_SEMAPHORE_INTERRUPT; 202 197 struct intel_uncore *uncore = gt->uncore; 203 - const u32 dmask = irqs << 16 | irqs; 204 - const u32 smask = irqs << 16; 198 + u32 irqs = GT_RENDER_USER_INTERRUPT; 199 + u32 dmask; 200 + u32 smask; 201 + 202 + if (!intel_uc_wants_guc_submission(&gt->uc)) 203 + irqs |= GT_CS_MASTER_ERROR_INTERRUPT | 204 + GT_CONTEXT_SWITCH_INTERRUPT | 205 + GT_WAIT_SEMAPHORE_INTERRUPT; 206 + 207 + dmask = irqs << 16 | irqs; 208 + smask = irqs << 16; 205 209 206 210 BUILD_BUG_ON(irqs & 0xffff0000); 207 211 ··· 399 395 struct intel_uncore *uncore = gt->uncore; 400 396 401 397 GEN3_IRQ_RESET(uncore, GT); 402 - if (INTEL_GEN(gt->i915) >= 6) 398 + if (GRAPHICS_VER(gt->i915) >= 6) 403 399 GEN3_IRQ_RESET(uncore, GEN6_PM); 404 400 } 405 401 ··· 417 413 } 418 414 419 415 gt_irqs |= GT_RENDER_USER_INTERRUPT; 420 - if (IS_GEN(gt->i915, 5)) 416 + if (GRAPHICS_VER(gt->i915) == 5) 421 417 gt_irqs |= ILK_BSD_USER_INTERRUPT; 422 418 else 423 419 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT; 424 420 425 421 GEN3_IRQ_INIT(uncore, GT, gt->gt_imr, gt_irqs); 426 422 427 - if (INTEL_GEN(gt->i915) >= 6) { 423 + if (GRAPHICS_VER(gt->i915) >= 6) { 428 424 /* 429 425 * RPS interrupts will get enabled/disabled on demand when RPS 430 426 * itself is enabled/disabled.
+5 -5
drivers/gpu/drm/i915/gt/intel_gt_pm_irq.c
··· 16 16 u32 mask = gt->pm_imr; 17 17 i915_reg_t reg; 18 18 19 - if (INTEL_GEN(i915) >= 11) { 19 + if (GRAPHICS_VER(i915) >= 11) { 20 20 reg = GEN11_GPM_WGBOXPERF_INTR_MASK; 21 21 mask <<= 16; /* pm is in upper half */ 22 - } else if (INTEL_GEN(i915) >= 8) { 22 + } else if (GRAPHICS_VER(i915) >= 8) { 23 23 reg = GEN8_GT_IMR(2); 24 24 } else { 25 25 reg = GEN6_PMIMR; ··· 61 61 void gen6_gt_pm_reset_iir(struct intel_gt *gt, u32 reset_mask) 62 62 { 63 63 struct intel_uncore *uncore = gt->uncore; 64 - i915_reg_t reg = INTEL_GEN(gt->i915) >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR; 64 + i915_reg_t reg = GRAPHICS_VER(gt->i915) >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR; 65 65 66 66 lockdep_assert_held(&gt->irq_lock); 67 67 ··· 77 77 u32 mask = gt->pm_ier; 78 78 i915_reg_t reg; 79 79 80 - if (INTEL_GEN(i915) >= 11) { 80 + if (GRAPHICS_VER(i915) >= 11) { 81 81 reg = GEN11_GPM_WGBOXPERF_INTR_ENABLE; 82 82 mask <<= 16; /* pm is in upper half */ 83 - } else if (INTEL_GEN(i915) >= 8) { 83 + } else if (GRAPHICS_VER(i915) >= 8) { 84 84 reg = GEN8_GT_IER(2); 85 85 } else { 86 86 reg = GEN6_PMIER;
+44 -15
drivers/gpu/drm/i915/gt/intel_gtt.c
··· 22 22 * object underneath, with the idea that one object_lock() will lock 23 23 * them all at once. 24 24 */ 25 - if (!IS_ERR(obj)) 26 - obj->base.resv = &vm->resv; 25 + if (!IS_ERR(obj)) { 26 + obj->base.resv = i915_vm_resv_get(vm); 27 + obj->shares_resv_from = vm; 28 + } 29 + 27 30 return obj; 28 31 } 29 32 ··· 43 40 * object underneath, with the idea that one object_lock() will lock 44 41 * them all at once. 45 42 */ 46 - if (!IS_ERR(obj)) 47 - obj->base.resv = &vm->resv; 43 + if (!IS_ERR(obj)) { 44 + obj->base.resv = i915_vm_resv_get(vm); 45 + obj->shares_resv_from = vm; 46 + } 47 + 48 48 return obj; 49 49 } 50 50 ··· 108 102 int i915_vm_lock_objects(struct i915_address_space *vm, 109 103 struct i915_gem_ww_ctx *ww) 110 104 { 111 - if (vm->scratch[0]->base.resv == &vm->resv) { 105 + if (vm->scratch[0]->base.resv == &vm->_resv) { 112 106 return i915_gem_object_lock(vm->scratch[0], ww); 113 107 } else { 114 108 struct i915_ppgtt *ppgtt = i915_vm_to_ppgtt(vm); ··· 124 118 mutex_destroy(&vm->mutex); 125 119 } 126 120 121 + /** 122 + * i915_vm_resv_release - Final struct i915_address_space destructor 123 + * @kref: Pointer to the &i915_address_space.resv_ref member. 124 + * 125 + * This function is called when the last lock sharer no longer shares the 126 + * &i915_address_space._resv lock. 127 + */ 128 + void i915_vm_resv_release(struct kref *kref) 129 + { 130 + struct i915_address_space *vm = 131 + container_of(kref, typeof(*vm), resv_ref); 132 + 133 + dma_resv_fini(&vm->_resv); 134 + kfree(vm); 135 + } 136 + 127 137 static void __i915_vm_release(struct work_struct *work) 128 138 { 129 139 struct i915_address_space *vm = ··· 147 125 148 126 vm->cleanup(vm); 149 127 i915_address_space_fini(vm); 150 - dma_resv_fini(&vm->resv); 151 128 152 - kfree(vm); 129 + i915_vm_resv_put(vm); 153 130 } 154 131 155 132 void i915_vm_release(struct kref *kref) ··· 165 144 void i915_address_space_init(struct i915_address_space *vm, int subclass) 166 145 { 167 146 kref_init(&vm->ref); 147 + 148 + /* 149 + * Special case for GGTT that has already done an early 150 + * kref_init here. 151 + */ 152 + if (!kref_read(&vm->resv_ref)) 153 + kref_init(&vm->resv_ref); 154 + 168 155 INIT_RCU_WORK(&vm->rcu, __i915_vm_release); 169 156 atomic_set(&vm->open, 1); 170 157 ··· 199 170 might_alloc(GFP_KERNEL); 200 171 mutex_release(&vm->mutex.dep_map, _THIS_IP_); 201 172 } 202 - dma_resv_init(&vm->resv); 173 + dma_resv_init(&vm->_resv); 203 174 204 175 GEM_BUG_ON(!vm->total); 205 176 drm_mm_init(&vm->mm, 0, vm->total); ··· 356 327 intel_uncore_write(uncore, 357 328 GEN8_L3_LRA_1_GPGPU, 358 329 GEN9_L3_LRA_1_GPGPU_DEFAULT_VALUE_BXT); 359 - else if (INTEL_GEN(i915) >= 9 && INTEL_GEN(i915) <= 11) 330 + else if (GRAPHICS_VER(i915) >= 9 && GRAPHICS_VER(i915) <= 11) 360 331 intel_uncore_write(uncore, 361 332 GEN8_L3_LRA_1_GPGPU, 362 333 GEN9_L3_LRA_1_GPGPU_DEFAULT_VALUE_SKL); ··· 373 344 * driver. 374 345 */ 375 346 if (HAS_PAGE_SIZES(i915, I915_GTT_PAGE_SIZE_64K) && 376 - INTEL_GEN(i915) <= 10) 347 + GRAPHICS_VER(i915) <= 10) 377 348 intel_uncore_rmw(uncore, 378 349 GEN8_GAMW_ECO_DEV_RW_IA, 379 350 0, 380 351 GAMW_ECO_ENABLE_64K_IPS_FIELD); 381 352 382 - if (IS_GEN_RANGE(i915, 8, 11)) { 353 + if (IS_GRAPHICS_VER(i915, 8, 11)) { 383 354 bool can_use_gtt_cache = true; 384 355 385 356 /* ··· 461 432 GEN8_PPAT(7, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(3)); 462 433 463 434 /* for scanout with eLLC */ 464 - if (INTEL_GEN(i915) >= 9) 435 + if (GRAPHICS_VER(i915) >= 9) 465 436 pat |= GEN8_PPAT(2, GEN8_PPAT_WB | GEN8_PPAT_ELLC_OVERRIDE); 466 437 else 467 438 pat |= GEN8_PPAT(2, GEN8_PPAT_WT | GEN8_PPAT_LLCELLC); ··· 510 481 { 511 482 struct drm_i915_private *i915 = uncore->i915; 512 483 513 - GEM_BUG_ON(INTEL_GEN(i915) < 8); 484 + GEM_BUG_ON(GRAPHICS_VER(i915) < 8); 514 485 515 - if (INTEL_GEN(i915) >= 12) 486 + if (GRAPHICS_VER(i915) >= 12) 516 487 tgl_setup_private_ppat(uncore); 517 - else if (INTEL_GEN(i915) >= 10) 488 + else if (GRAPHICS_VER(i915) >= 10) 518 489 cnl_setup_private_ppat(uncore); 519 490 else if (IS_CHERRYVIEW(i915) || IS_GEN9_LP(i915)) 520 491 chv_setup_private_ppat(uncore);
+27 -1
drivers/gpu/drm/i915/gt/intel_gtt.h
··· 245 245 atomic_t open; 246 246 247 247 struct mutex mutex; /* protects vma and our lists */ 248 - struct dma_resv resv; /* reservation lock for all pd objects, and buffer pool */ 248 + 249 + struct kref resv_ref; /* kref to keep the reservation lock alive. */ 250 + struct dma_resv _resv; /* reservation lock for all pd objects, and buffer pool */ 249 251 #define VM_CLASS_GGTT 0 250 252 #define VM_CLASS_PPGTT 1 251 253 #define VM_CLASS_DPT 2 ··· 407 405 return vm; 408 406 } 409 407 408 + /** 409 + * i915_vm_resv_get - Obtain a reference on the vm's reservation lock 410 + * @vm: The vm whose reservation lock we want to share. 411 + * 412 + * Return: A pointer to the vm's reservation lock. 413 + */ 414 + static inline struct dma_resv *i915_vm_resv_get(struct i915_address_space *vm) 415 + { 416 + kref_get(&vm->resv_ref); 417 + return &vm->_resv; 418 + } 419 + 410 420 void i915_vm_release(struct kref *kref); 421 + 422 + void i915_vm_resv_release(struct kref *kref); 411 423 412 424 static inline void i915_vm_put(struct i915_address_space *vm) 413 425 { 414 426 kref_put(&vm->ref, i915_vm_release); 427 + } 428 + 429 + /** 430 + * i915_vm_resv_put - Release a reference on the vm's reservation lock 431 + * @resv: Pointer to a reservation lock obtained from i915_vm_resv_get() 432 + */ 433 + static inline void i915_vm_resv_put(struct i915_address_space *vm) 434 + { 435 + kref_put(&vm->resv_ref, i915_vm_resv_release); 415 436 } 416 437 417 438 static inline struct i915_address_space * ··· 532 507 void i915_ggtt_disable_guc(struct i915_ggtt *ggtt); 533 508 int i915_init_ggtt(struct drm_i915_private *i915); 534 509 void i915_ggtt_driver_release(struct drm_i915_private *i915); 510 + void i915_ggtt_driver_late_release(struct drm_i915_private *i915); 535 511 536 512 static inline bool i915_ggtt_has_aperture(const struct i915_ggtt *ggtt) 537 513 {
+3 -3
drivers/gpu/drm/i915/gt/intel_llc.c
··· 64 64 65 65 consts->min_gpu_freq = rps->min_freq; 66 66 consts->max_gpu_freq = rps->max_freq; 67 - if (INTEL_GEN(i915) >= 9) { 67 + if (GRAPHICS_VER(i915) >= 9) { 68 68 /* Convert GT frequency to 50 HZ units */ 69 69 consts->min_gpu_freq /= GEN9_FREQ_SCALER; 70 70 consts->max_gpu_freq /= GEN9_FREQ_SCALER; ··· 83 83 const int diff = consts->max_gpu_freq - gpu_freq; 84 84 unsigned int ia_freq = 0, ring_freq = 0; 85 85 86 - if (INTEL_GEN(i915) >= 9) { 86 + if (GRAPHICS_VER(i915) >= 9) { 87 87 /* 88 88 * ring_freq = 2 * GT. ring_freq is in 100MHz units 89 89 * No floor required for ring frequency on SKL. 90 90 */ 91 91 ring_freq = gpu_freq; 92 - } else if (INTEL_GEN(i915) >= 8) { 92 + } else if (GRAPHICS_VER(i915) >= 8) { 93 93 /* max(2 * GT, DDR). NB: GT is 50MHz units */ 94 94 ring_freq = max(consts->min_ring_freq, gpu_freq); 95 95 } else if (IS_HASWELL(i915)) {
+23 -23
drivers/gpu/drm/i915/gt/intel_lrc.c
··· 47 47 *regs = MI_LOAD_REGISTER_IMM(count); 48 48 if (flags & POSTED) 49 49 *regs |= MI_LRI_FORCE_POSTED; 50 - if (INTEL_GEN(engine->i915) >= 11) 50 + if (GRAPHICS_VER(engine->i915) >= 11) 51 51 *regs |= MI_LRI_LRM_CS_MMIO; 52 52 regs++; 53 53 ··· 70 70 if (close) { 71 71 /* Close the batch; used mainly by live_lrc_layout() */ 72 72 *regs = MI_BATCH_BUFFER_END; 73 - if (INTEL_GEN(engine->i915) >= 10) 73 + if (GRAPHICS_VER(engine->i915) >= 10) 74 74 *regs |= BIT(0); 75 75 } 76 76 } ··· 498 498 * addressing to automatic fixup the register state between the 499 499 * physical engines for virtual engine. 500 500 */ 501 - GEM_BUG_ON(INTEL_GEN(engine->i915) >= 12 && 501 + GEM_BUG_ON(GRAPHICS_VER(engine->i915) >= 12 && 502 502 !intel_engine_has_relative_mmio(engine)); 503 503 504 504 if (engine->class == RENDER_CLASS) { 505 - if (INTEL_GEN(engine->i915) >= 12) 505 + if (GRAPHICS_VER(engine->i915) >= 12) 506 506 return gen12_rcs_offsets; 507 - else if (INTEL_GEN(engine->i915) >= 11) 507 + else if (GRAPHICS_VER(engine->i915) >= 11) 508 508 return gen11_rcs_offsets; 509 - else if (INTEL_GEN(engine->i915) >= 9) 509 + else if (GRAPHICS_VER(engine->i915) >= 9) 510 510 return gen9_rcs_offsets; 511 511 else 512 512 return gen8_rcs_offsets; 513 513 } else { 514 - if (INTEL_GEN(engine->i915) >= 12) 514 + if (GRAPHICS_VER(engine->i915) >= 12) 515 515 return gen12_xcs_offsets; 516 - else if (INTEL_GEN(engine->i915) >= 9) 516 + else if (GRAPHICS_VER(engine->i915) >= 9) 517 517 return gen9_xcs_offsets; 518 518 else 519 519 return gen8_xcs_offsets; ··· 522 522 523 523 static int lrc_ring_mi_mode(const struct intel_engine_cs *engine) 524 524 { 525 - if (INTEL_GEN(engine->i915) >= 12) 525 + if (GRAPHICS_VER(engine->i915) >= 12) 526 526 return 0x60; 527 - else if (INTEL_GEN(engine->i915) >= 9) 527 + else if (GRAPHICS_VER(engine->i915) >= 9) 528 528 return 0x54; 529 529 else if (engine->class == RENDER_CLASS) 530 530 return 0x58; ··· 534 534 535 535 static int lrc_ring_gpr0(const struct intel_engine_cs *engine) 536 536 { 537 - if (INTEL_GEN(engine->i915) >= 12) 537 + if (GRAPHICS_VER(engine->i915) >= 12) 538 538 return 0x74; 539 - else if (INTEL_GEN(engine->i915) >= 9) 539 + else if (GRAPHICS_VER(engine->i915) >= 9) 540 540 return 0x68; 541 541 else if (engine->class == RENDER_CLASS) 542 542 return 0xd8; ··· 546 546 547 547 static int lrc_ring_wa_bb_per_ctx(const struct intel_engine_cs *engine) 548 548 { 549 - if (INTEL_GEN(engine->i915) >= 12) 549 + if (GRAPHICS_VER(engine->i915) >= 12) 550 550 return 0x12; 551 - else if (INTEL_GEN(engine->i915) >= 9 || engine->class == RENDER_CLASS) 551 + else if (GRAPHICS_VER(engine->i915) >= 9 || engine->class == RENDER_CLASS) 552 552 return 0x18; 553 553 else 554 554 return -1; ··· 581 581 if (engine->class != RENDER_CLASS) 582 582 return -1; 583 583 584 - if (INTEL_GEN(engine->i915) >= 12) 584 + if (GRAPHICS_VER(engine->i915) >= 12) 585 585 return 0xb6; 586 - else if (INTEL_GEN(engine->i915) >= 11) 586 + else if (GRAPHICS_VER(engine->i915) >= 11) 587 587 return 0xaa; 588 588 else 589 589 return -1; ··· 592 592 static u32 593 593 lrc_ring_indirect_offset_default(const struct intel_engine_cs *engine) 594 594 { 595 - switch (INTEL_GEN(engine->i915)) { 595 + switch (GRAPHICS_VER(engine->i915)) { 596 596 default: 597 - MISSING_CASE(INTEL_GEN(engine->i915)); 597 + MISSING_CASE(GRAPHICS_VER(engine->i915)); 598 598 fallthrough; 599 599 case 12: 600 600 return GEN12_CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT; ··· 637 637 ctl |= _MASKED_BIT_DISABLE(CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT); 638 638 if (inhibit) 639 639 ctl |= CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT; 640 - if (INTEL_GEN(engine->i915) < 11) 640 + if (GRAPHICS_VER(engine->i915) < 11) 641 641 ctl |= _MASKED_BIT_DISABLE(CTX_CTRL_ENGINE_CTX_SAVE_INHIBIT | 642 642 CTX_CTRL_RS_CTX_ENABLE); 643 643 regs[CTX_CONTEXT_CONTROL] = ctl; ··· 805 805 if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)) 806 806 context_size += I915_GTT_PAGE_SIZE; /* for redzone */ 807 807 808 - if (INTEL_GEN(engine->i915) == 12) { 808 + if (GRAPHICS_VER(engine->i915) == 12) { 809 809 ce->wa_bb_page = context_size / PAGE_SIZE; 810 810 context_size += PAGE_SIZE; 811 811 } ··· 1114 1114 desc <<= GEN8_CTX_ADDRESSING_MODE_SHIFT; 1115 1115 1116 1116 desc |= GEN8_CTX_VALID | GEN8_CTX_PRIVILEGE; 1117 - if (IS_GEN(ce->vm->i915, 8)) 1117 + if (GRAPHICS_VER(ce->vm->i915) == 8) 1118 1118 desc |= GEN8_CTX_L3LLC_COHERENT; 1119 1119 1120 1120 return i915_ggtt_offset(ce->state) | desc; ··· 1469 1469 if (engine->class != RENDER_CLASS) 1470 1470 return; 1471 1471 1472 - switch (INTEL_GEN(engine->i915)) { 1472 + switch (GRAPHICS_VER(engine->i915)) { 1473 1473 case 12: 1474 1474 case 11: 1475 1475 return; ··· 1486 1486 wa_bb_fn[1] = NULL; 1487 1487 break; 1488 1488 default: 1489 - MISSING_CASE(INTEL_GEN(engine->i915)); 1489 + MISSING_CASE(GRAPHICS_VER(engine->i915)); 1490 1490 return; 1491 1491 } 1492 1492
+4 -4
drivers/gpu/drm/i915/gt/intel_mocs.c
··· 344 344 table->size = ARRAY_SIZE(dg1_mocs_table); 345 345 table->table = dg1_mocs_table; 346 346 table->n_entries = GEN9_NUM_MOCS_ENTRIES; 347 - } else if (INTEL_GEN(i915) >= 12) { 347 + } else if (GRAPHICS_VER(i915) >= 12) { 348 348 table->size = ARRAY_SIZE(tgl_mocs_table); 349 349 table->table = tgl_mocs_table; 350 350 table->n_entries = GEN9_NUM_MOCS_ENTRIES; 351 - } else if (IS_GEN(i915, 11)) { 351 + } else if (GRAPHICS_VER(i915) == 11) { 352 352 table->size = ARRAY_SIZE(icl_mocs_table); 353 353 table->table = icl_mocs_table; 354 354 table->n_entries = GEN9_NUM_MOCS_ENTRIES; ··· 361 361 table->n_entries = GEN9_NUM_MOCS_ENTRIES; 362 362 table->table = broxton_mocs_table; 363 363 } else { 364 - drm_WARN_ONCE(&i915->drm, INTEL_GEN(i915) >= 9, 364 + drm_WARN_ONCE(&i915->drm, GRAPHICS_VER(i915) >= 9, 365 365 "Platform that should have a MOCS table does not.\n"); 366 366 return 0; 367 367 } ··· 370 370 return 0; 371 371 372 372 /* WaDisableSkipCaching:skl,bxt,kbl,glk */ 373 - if (IS_GEN(i915, 9)) { 373 + if (GRAPHICS_VER(i915) == 9) { 374 374 int i; 375 375 376 376 for (i = 0; i < table->size; i++)
+4 -4
drivers/gpu/drm/i915/gt/intel_ppgtt.c
··· 146 146 147 147 gtt_write_workarounds(gt); 148 148 149 - if (IS_GEN(i915, 6)) 149 + if (GRAPHICS_VER(i915) == 6) 150 150 gen6_ppgtt_enable(gt); 151 - else if (IS_GEN(i915, 7)) 151 + else if (GRAPHICS_VER(i915) == 7) 152 152 gen7_ppgtt_enable(gt); 153 153 154 154 return 0; ··· 157 157 static struct i915_ppgtt * 158 158 __ppgtt_create(struct intel_gt *gt) 159 159 { 160 - if (INTEL_GEN(gt->i915) < 8) 160 + if (GRAPHICS_VER(gt->i915) < 8) 161 161 return gen6_ppgtt_create(gt); 162 162 else 163 163 return gen8_ppgtt_create(gt); ··· 307 307 ppgtt->vm.dma = i915->drm.dev; 308 308 ppgtt->vm.total = BIT_ULL(INTEL_INFO(i915)->ppgtt_size); 309 309 310 - dma_resv_init(&ppgtt->vm.resv); 310 + dma_resv_init(&ppgtt->vm._resv); 311 311 i915_address_space_init(&ppgtt->vm, VM_CLASS_PPGTT); 312 312 313 313 ppgtt->vm.vma_ops.bind_vma = ppgtt_bind_vma;
+8 -8
drivers/gpu/drm/i915/gt/intel_rc6.c
··· 109 109 GEN9_MEDIA_PG_ENABLE | 110 110 GEN11_MEDIA_SAMPLER_PG_ENABLE; 111 111 112 - if (INTEL_GEN(gt->i915) >= 12) { 112 + if (GRAPHICS_VER(gt->i915) >= 12) { 113 113 for (i = 0; i < I915_MAX_VCS; i++) 114 114 if (HAS_ENGINE(gt, _VCS(i))) 115 115 pg_enable |= (VDN_HCP_POWERGATE_ENABLE(i) | ··· 126 126 enum intel_engine_id id; 127 127 128 128 /* 2b: Program RC6 thresholds.*/ 129 - if (INTEL_GEN(rc6_to_i915(rc6)) >= 10) { 129 + if (GRAPHICS_VER(rc6_to_i915(rc6)) >= 10) { 130 130 set(uncore, GEN6_RC6_WAKE_RATE_LIMIT, 54 << 16 | 85); 131 131 set(uncore, GEN10_MEDIA_WAKE_RATE_LIMIT, 150); 132 132 } else if (IS_SKYLAKE(rc6_to_i915(rc6))) { ··· 249 249 rc6vids = 0; 250 250 ret = sandybridge_pcode_read(i915, GEN6_PCODE_READ_RC6VIDS, 251 251 &rc6vids, NULL); 252 - if (IS_GEN(i915, 6) && ret) { 252 + if (GRAPHICS_VER(i915) == 6 && ret) { 253 253 drm_dbg(&i915->drm, "Couldn't check for BIOS workaround\n"); 254 - } else if (IS_GEN(i915, 6) && 254 + } else if (GRAPHICS_VER(i915) == 6 && 255 255 (GEN6_DECODE_RC6_VID(rc6vids & 0xff) < 450)) { 256 256 drm_dbg(&i915->drm, 257 257 "You should update your BIOS. Correcting minimum rc6 voltage (%dmV->%dmV)\n", ··· 515 515 struct intel_uncore *uncore = rc6_to_uncore(rc6); 516 516 517 517 intel_uncore_forcewake_get(uncore, FORCEWAKE_ALL); 518 - if (INTEL_GEN(i915) >= 9) 518 + if (GRAPHICS_VER(i915) >= 9) 519 519 set(uncore, GEN9_PG_ENABLE, 0); 520 520 set(uncore, GEN6_RC_CONTROL, 0); 521 521 set(uncore, GEN6_RC_STATE, 0); ··· 575 575 chv_rc6_enable(rc6); 576 576 else if (IS_VALLEYVIEW(i915)) 577 577 vlv_rc6_enable(rc6); 578 - else if (INTEL_GEN(i915) >= 11) 578 + else if (GRAPHICS_VER(i915) >= 11) 579 579 gen11_rc6_enable(rc6); 580 - else if (INTEL_GEN(i915) >= 9) 580 + else if (GRAPHICS_VER(i915) >= 9) 581 581 gen9_rc6_enable(rc6); 582 582 else if (IS_BROADWELL(i915)) 583 583 gen8_rc6_enable(rc6); 584 - else if (INTEL_GEN(i915) >= 6) 584 + else if (GRAPHICS_VER(i915) >= 6) 585 585 gen6_rc6_enable(rc6); 586 586 587 587 rc6->manual = rc6->ctl_enable & GEN6_RC_CTL_RC6_ENABLE;
+21 -6
drivers/gpu/drm/i915/gt/intel_region_lmem.c
··· 5 5 6 6 #include "i915_drv.h" 7 7 #include "intel_memory_region.h" 8 + #include "intel_region_lmem.h" 9 + #include "intel_region_ttm.h" 8 10 #include "gem/i915_gem_lmem.h" 9 11 #include "gem/i915_gem_region.h" 10 12 #include "intel_region_lmem.h" ··· 68 66 static void 69 67 region_lmem_release(struct intel_memory_region *mem) 70 68 { 71 - release_fake_lmem_bar(mem); 69 + intel_region_ttm_fini(mem); 72 70 io_mapping_fini(&mem->iomap); 73 - intel_memory_region_release_buddy(mem); 71 + release_fake_lmem_bar(mem); 74 72 } 75 73 76 74 static int ··· 85 83 86 84 if (!io_mapping_init_wc(&mem->iomap, 87 85 mem->io_start, 88 - resource_size(&mem->region))) 89 - return -EIO; 86 + resource_size(&mem->region))) { 87 + ret = -EIO; 88 + goto out_no_io; 89 + } 90 90 91 - ret = intel_memory_region_init_buddy(mem); 91 + ret = intel_region_ttm_init(mem); 92 92 if (ret) 93 - io_mapping_fini(&mem->iomap); 93 + goto out_no_buddy; 94 + 95 + return 0; 96 + 97 + out_no_buddy: 98 + io_mapping_fini(&mem->iomap); 99 + out_no_io: 100 + release_fake_lmem_bar(mem); 94 101 95 102 return ret; 96 103 } ··· 138 127 mappable_end, 139 128 PAGE_SIZE, 140 129 io_start, 130 + INTEL_MEMORY_LOCAL, 131 + 0, 141 132 &intel_region_lmem_ops); 142 133 if (!IS_ERR(mem)) { 143 134 drm_info(&i915->drm, "Intel graphics fake LMEM: %pR\n", ··· 211 198 lmem_size, 212 199 I915_GTT_PAGE_SIZE_4K, 213 200 io_start, 201 + INTEL_MEMORY_LOCAL, 202 + 0, 214 203 &intel_region_lmem_ops); 215 204 if (IS_ERR(mem)) 216 205 return mem;
+1 -1
drivers/gpu/drm/i915/gt/intel_renderstate.c
··· 15 15 if (engine->class != RENDER_CLASS) 16 16 return NULL; 17 17 18 - switch (INTEL_GEN(engine->i915)) { 18 + switch (GRAPHICS_VER(engine->i915)) { 19 19 case 6: 20 20 return &gen6_null_state; 21 21 case 7:
+7 -7
drivers/gpu/drm/i915/gt/intel_reset.c
··· 421 421 struct intel_engine_cs *paired_vecs; 422 422 423 423 if (engine->class != VIDEO_DECODE_CLASS || 424 - !IS_GEN(engine->i915, 12)) 424 + GRAPHICS_VER(engine->i915) != 12) 425 425 return 0; 426 426 427 427 /* ··· 633 633 */ 634 634 } 635 635 636 - if (INTEL_GEN(gt->i915) >= 11) 636 + if (GRAPHICS_VER(gt->i915) >= 11) 637 637 ret = gen11_reset_engines(gt, engine_mask, retry); 638 638 else 639 639 ret = gen6_reset_engines(gt, engine_mask, retry); ··· 662 662 663 663 if (is_mock_gt(gt)) 664 664 return mock_reset; 665 - else if (INTEL_GEN(i915) >= 8) 665 + else if (GRAPHICS_VER(i915) >= 8) 666 666 return gen8_reset_engines; 667 - else if (INTEL_GEN(i915) >= 6) 667 + else if (GRAPHICS_VER(i915) >= 6) 668 668 return gen6_reset_engines; 669 - else if (INTEL_GEN(i915) >= 5) 669 + else if (GRAPHICS_VER(i915) >= 5) 670 670 return ilk_do_reset; 671 671 else if (IS_G4X(i915)) 672 672 return g4x_do_reset; 673 673 else if (IS_G33(i915) || IS_PINEVIEW(i915)) 674 674 return g33_do_reset; 675 - else if (INTEL_GEN(i915) >= 3) 675 + else if (GRAPHICS_VER(i915) >= 3) 676 676 return i915_do_reset; 677 677 else 678 678 return NULL; ··· 724 724 int intel_reset_guc(struct intel_gt *gt) 725 725 { 726 726 u32 guc_domain = 727 - INTEL_GEN(gt->i915) >= 11 ? GEN11_GRDOM_GUC : GEN9_GRDOM_GUC; 727 + GRAPHICS_VER(gt->i915) >= 11 ? GEN11_GRDOM_GUC : GEN9_GRDOM_GUC; 728 728 int ret; 729 729 730 730 GEM_BUG_ON(!HAS_GT_UC(gt->i915));
+32 -32
drivers/gpu/drm/i915/gt/intel_ring_submission.c
··· 29 29 * lost interrupts following a reset. 30 30 */ 31 31 if (engine->class == RENDER_CLASS) { 32 - if (INTEL_GEN(engine->i915) >= 6) 32 + if (GRAPHICS_VER(engine->i915) >= 6) 33 33 mask &= ~BIT(0); 34 34 else 35 35 mask &= ~I915_USER_INTERRUPT; ··· 43 43 u32 addr; 44 44 45 45 addr = lower_32_bits(phys); 46 - if (INTEL_GEN(engine->i915) >= 4) 46 + if (GRAPHICS_VER(engine->i915) >= 4) 47 47 addr |= (phys >> 28) & 0xf0; 48 48 49 49 intel_uncore_write(engine->uncore, HWS_PGA, addr); ··· 71 71 * The ring status page addresses are no longer next to the rest of 72 72 * the ring registers as of gen7. 73 73 */ 74 - if (IS_GEN(engine->i915, 7)) { 74 + if (GRAPHICS_VER(engine->i915) == 7) { 75 75 switch (engine->id) { 76 76 /* 77 77 * No more rings exist on Gen7. Default case is only to shut up ··· 93 93 hwsp = VEBOX_HWS_PGA_GEN7; 94 94 break; 95 95 } 96 - } else if (IS_GEN(engine->i915, 6)) { 96 + } else if (GRAPHICS_VER(engine->i915) == 6) { 97 97 hwsp = RING_HWS_PGA_GEN6(engine->mmio_base); 98 98 } else { 99 99 hwsp = RING_HWS_PGA(engine->mmio_base); ··· 105 105 106 106 static void flush_cs_tlb(struct intel_engine_cs *engine) 107 107 { 108 - if (!IS_GEN_RANGE(engine->i915, 6, 7)) 108 + if (!IS_GRAPHICS_VER(engine->i915, 6, 7)) 109 109 return; 110 110 111 111 /* ring should be idle before issuing a sync flush*/ ··· 153 153 ENGINE_WRITE_FW(engine, RING_PP_DIR_DCLV, PP_DIR_DCLV_2G); 154 154 ENGINE_WRITE_FW(engine, RING_PP_DIR_BASE, pp_dir(vm)); 155 155 156 - if (INTEL_GEN(engine->i915) >= 7) { 156 + if (GRAPHICS_VER(engine->i915) >= 7) { 157 157 ENGINE_WRITE_FW(engine, 158 158 RING_MODE_GEN7, 159 159 _MASKED_BIT_ENABLE(GFX_PPGTT_ENABLE)); ··· 229 229 5000, 0, NULL)) 230 230 goto err; 231 231 232 - if (INTEL_GEN(engine->i915) > 2) 232 + if (GRAPHICS_VER(engine->i915) > 2) 233 233 ENGINE_WRITE_FW(engine, 234 234 RING_MI_MODE, _MASKED_BIT_DISABLE(STOP_RING)); 235 235 ··· 646 646 u32 *cs; 647 647 648 648 len = 4; 649 - if (IS_GEN(i915, 7)) 649 + if (GRAPHICS_VER(i915) == 7) 650 650 len += 2 + (num_engines ? 4 * num_engines + 6 : 0); 651 - else if (IS_GEN(i915, 5)) 651 + else if (GRAPHICS_VER(i915) == 5) 652 652 len += 2; 653 653 if (flags & MI_FORCE_RESTORE) { 654 654 GEM_BUG_ON(flags & MI_RESTORE_INHIBIT); ··· 662 662 return PTR_ERR(cs); 663 663 664 664 /* WaProgramMiArbOnOffAroundMiSetContext:ivb,vlv,hsw,bdw,chv */ 665 - if (IS_GEN(i915, 7)) { 665 + if (GRAPHICS_VER(i915) == 7) { 666 666 *cs++ = MI_ARB_ON_OFF | MI_ARB_DISABLE; 667 667 if (num_engines) { 668 668 struct intel_engine_cs *signaller; ··· 678 678 GEN6_PSMI_SLEEP_MSG_DISABLE); 679 679 } 680 680 } 681 - } else if (IS_GEN(i915, 5)) { 681 + } else if (GRAPHICS_VER(i915) == 5) { 682 682 /* 683 683 * This w/a is only listed for pre-production ilk a/b steppings, 684 684 * but is also mentioned for programming the powerctx. To be ··· 716 716 */ 717 717 *cs++ = MI_NOOP; 718 718 719 - if (IS_GEN(i915, 7)) { 719 + if (GRAPHICS_VER(i915) == 7) { 720 720 if (num_engines) { 721 721 struct intel_engine_cs *signaller; 722 722 i915_reg_t last_reg = {}; /* keep gcc quiet */ ··· 740 740 *cs++ = MI_NOOP; 741 741 } 742 742 *cs++ = MI_ARB_ON_OFF | MI_ARB_ENABLE; 743 - } else if (IS_GEN(i915, 5)) { 743 + } else if (GRAPHICS_VER(i915) == 5) { 744 744 *cs++ = MI_SUSPEND_FLUSH; 745 745 } 746 746 ··· 1001 1001 { 1002 1002 struct drm_i915_private *dev_priv = engine->i915; 1003 1003 1004 - drm_WARN_ON(&dev_priv->drm, INTEL_GEN(dev_priv) > 2 && 1004 + drm_WARN_ON(&dev_priv->drm, GRAPHICS_VER(dev_priv) > 2 && 1005 1005 (ENGINE_READ(engine, RING_MI_MODE) & MODE_IDLE) == 0); 1006 1006 1007 1007 intel_engine_cleanup_common(engine); ··· 1029 1029 1030 1030 intel_engine_set_irq_handler(engine, irq_handler); 1031 1031 1032 - if (INTEL_GEN(i915) >= 6) { 1032 + if (GRAPHICS_VER(i915) >= 6) { 1033 1033 engine->irq_enable = gen6_irq_enable; 1034 1034 engine->irq_disable = gen6_irq_disable; 1035 - } else if (INTEL_GEN(i915) >= 5) { 1035 + } else if (GRAPHICS_VER(i915) >= 5) { 1036 1036 engine->irq_enable = gen5_irq_enable; 1037 1037 engine->irq_disable = gen5_irq_disable; 1038 - } else if (INTEL_GEN(i915) >= 3) { 1038 + } else if (GRAPHICS_VER(i915) >= 3) { 1039 1039 engine->irq_enable = gen3_irq_enable; 1040 1040 engine->irq_disable = gen3_irq_disable; 1041 1041 } else { ··· 1049 1049 struct drm_i915_private *i915 = engine->i915; 1050 1050 1051 1051 /* gen8+ are only supported with execlists */ 1052 - GEM_BUG_ON(INTEL_GEN(i915) >= 8); 1052 + GEM_BUG_ON(GRAPHICS_VER(i915) >= 8); 1053 1053 1054 1054 setup_irq(engine); 1055 1055 ··· 1070 1070 * engine->emit_init_breadcrumb(). 1071 1071 */ 1072 1072 engine->emit_fini_breadcrumb = gen3_emit_breadcrumb; 1073 - if (IS_GEN(i915, 5)) 1073 + if (GRAPHICS_VER(i915) == 5) 1074 1074 engine->emit_fini_breadcrumb = gen5_emit_breadcrumb; 1075 1075 1076 1076 engine->set_default_submission = i9xx_set_default_submission; 1077 1077 1078 - if (INTEL_GEN(i915) >= 6) 1078 + if (GRAPHICS_VER(i915) >= 6) 1079 1079 engine->emit_bb_start = gen6_emit_bb_start; 1080 - else if (INTEL_GEN(i915) >= 4) 1080 + else if (GRAPHICS_VER(i915) >= 4) 1081 1081 engine->emit_bb_start = gen4_emit_bb_start; 1082 1082 else if (IS_I830(i915) || IS_I845G(i915)) 1083 1083 engine->emit_bb_start = i830_emit_bb_start; ··· 1094 1094 1095 1095 engine->irq_enable_mask = GT_RENDER_USER_INTERRUPT; 1096 1096 1097 - if (INTEL_GEN(i915) >= 7) { 1097 + if (GRAPHICS_VER(i915) >= 7) { 1098 1098 engine->emit_flush = gen7_emit_flush_rcs; 1099 1099 engine->emit_fini_breadcrumb = gen7_emit_breadcrumb_rcs; 1100 - } else if (IS_GEN(i915, 6)) { 1100 + } else if (GRAPHICS_VER(i915) == 6) { 1101 1101 engine->emit_flush = gen6_emit_flush_rcs; 1102 1102 engine->emit_fini_breadcrumb = gen6_emit_breadcrumb_rcs; 1103 - } else if (IS_GEN(i915, 5)) { 1103 + } else if (GRAPHICS_VER(i915) == 5) { 1104 1104 engine->emit_flush = gen4_emit_flush_rcs; 1105 1105 } else { 1106 - if (INTEL_GEN(i915) < 4) 1106 + if (GRAPHICS_VER(i915) < 4) 1107 1107 engine->emit_flush = gen2_emit_flush; 1108 1108 else 1109 1109 engine->emit_flush = gen4_emit_flush_rcs; ··· 1118 1118 { 1119 1119 struct drm_i915_private *i915 = engine->i915; 1120 1120 1121 - if (INTEL_GEN(i915) >= 6) { 1121 + if (GRAPHICS_VER(i915) >= 6) { 1122 1122 /* gen6 bsd needs a special wa for tail updates */ 1123 - if (IS_GEN(i915, 6)) 1123 + if (GRAPHICS_VER(i915) == 6) 1124 1124 engine->set_default_submission = gen6_bsd_set_default_submission; 1125 1125 engine->emit_flush = gen6_emit_flush_vcs; 1126 1126 engine->irq_enable_mask = GT_BSD_USER_INTERRUPT; 1127 1127 1128 - if (IS_GEN(i915, 6)) 1128 + if (GRAPHICS_VER(i915) == 6) 1129 1129 engine->emit_fini_breadcrumb = gen6_emit_breadcrumb_xcs; 1130 1130 else 1131 1131 engine->emit_fini_breadcrumb = gen7_emit_breadcrumb_xcs; 1132 1132 } else { 1133 1133 engine->emit_flush = gen4_emit_flush_vcs; 1134 - if (IS_GEN(i915, 5)) 1134 + if (GRAPHICS_VER(i915) == 5) 1135 1135 engine->irq_enable_mask = ILK_BSD_USER_INTERRUPT; 1136 1136 else 1137 1137 engine->irq_enable_mask = I915_BSD_USER_INTERRUPT; ··· 1145 1145 engine->emit_flush = gen6_emit_flush_xcs; 1146 1146 engine->irq_enable_mask = GT_BLT_USER_INTERRUPT; 1147 1147 1148 - if (IS_GEN(i915, 6)) 1148 + if (GRAPHICS_VER(i915) == 6) 1149 1149 engine->emit_fini_breadcrumb = gen6_emit_breadcrumb_xcs; 1150 1150 else 1151 1151 engine->emit_fini_breadcrumb = gen7_emit_breadcrumb_xcs; ··· 1155 1155 { 1156 1156 struct drm_i915_private *i915 = engine->i915; 1157 1157 1158 - GEM_BUG_ON(INTEL_GEN(i915) < 7); 1158 + GEM_BUG_ON(GRAPHICS_VER(i915) < 7); 1159 1159 1160 1160 engine->emit_flush = gen6_emit_flush_xcs; 1161 1161 engine->irq_enable_mask = PM_VEBOX_USER_INTERRUPT; ··· 1203 1203 struct i915_vma *vma; 1204 1204 int size, err; 1205 1205 1206 - if (!IS_GEN(engine->i915, 7) || engine->class != RENDER_CLASS) 1206 + if (GRAPHICS_VER(engine->i915) != 7 || engine->class != RENDER_CLASS) 1207 1207 return 0; 1208 1208 1209 1209 err = gen7_ctx_switch_bb_setup(engine, NULL /* probe size */);
+30 -30
drivers/gpu/drm/i915/gt/intel_rps.c
··· 196 196 struct intel_gt *gt = rps_to_gt(rps); 197 197 198 198 spin_lock_irq(&gt->irq_lock); 199 - if (INTEL_GEN(gt->i915) >= 11) 199 + if (GRAPHICS_VER(gt->i915) >= 11) 200 200 gen11_rps_reset_interrupts(rps); 201 201 else 202 202 gen6_rps_reset_interrupts(rps); ··· 630 630 * frequency, if the down threshold expires in that window we will not 631 631 * receive a down interrupt. 632 632 */ 633 - if (INTEL_GEN(rps_to_i915(rps)) >= 9) { 633 + if (GRAPHICS_VER(rps_to_i915(rps)) >= 9) { 634 634 limits = rps->max_freq_softlimit << 23; 635 635 if (val <= rps->min_freq_softlimit) 636 636 limits |= rps->min_freq_softlimit << 14; ··· 697 697 intel_gt_ns_to_pm_interval(gt, ei_down * threshold_down * 10)); 698 698 699 699 set(uncore, GEN6_RP_CONTROL, 700 - (INTEL_GEN(gt->i915) > 9 ? 0 : GEN6_RP_MEDIA_TURBO) | 700 + (GRAPHICS_VER(gt->i915) > 9 ? 0 : GEN6_RP_MEDIA_TURBO) | 701 701 GEN6_RP_MEDIA_HW_NORMAL_MODE | 702 702 GEN6_RP_MEDIA_IS_GFX | 703 703 GEN6_RP_ENABLE | ··· 771 771 struct drm_i915_private *i915 = rps_to_i915(rps); 772 772 u32 swreq; 773 773 774 - if (INTEL_GEN(i915) >= 9) 774 + if (GRAPHICS_VER(i915) >= 9) 775 775 swreq = GEN9_FREQUENCY(val); 776 776 else if (IS_HASWELL(i915) || IS_BROADWELL(i915)) 777 777 swreq = HSW_FREQUENCY(val); ··· 812 812 813 813 if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915)) 814 814 err = vlv_rps_set(rps, val); 815 - else if (INTEL_GEN(i915) >= 6) 815 + else if (GRAPHICS_VER(i915) >= 6) 816 816 err = gen6_rps_set(rps, val); 817 817 else 818 818 err = gen5_rps_set(rps, val); 819 819 if (err) 820 820 return err; 821 821 822 - if (update && INTEL_GEN(i915) >= 6) 822 + if (update && GRAPHICS_VER(i915) >= 6) 823 823 gen6_rps_set_thresholds(rps, val); 824 824 rps->last_freq = val; 825 825 ··· 853 853 if (intel_rps_uses_timer(rps)) 854 854 rps_start_timer(rps); 855 855 856 - if (IS_GEN(rps_to_i915(rps), 5)) 856 + if (GRAPHICS_VER(rps_to_i915(rps)) == 5) 857 857 gen5_rps_update(rps); 858 858 } 859 859 ··· 999 999 1000 1000 rps->efficient_freq = rps->rp1_freq; 1001 1001 if (IS_HASWELL(i915) || IS_BROADWELL(i915) || 1002 - IS_GEN9_BC(i915) || INTEL_GEN(i915) >= 10) { 1002 + IS_GEN9_BC(i915) || GRAPHICS_VER(i915) >= 10) { 1003 1003 u32 ddcc_status = 0; 1004 1004 1005 1005 if (sandybridge_pcode_read(i915, ··· 1012 1012 rps->max_freq); 1013 1013 } 1014 1014 1015 - if (IS_GEN9_BC(i915) || INTEL_GEN(i915) >= 10) { 1015 + if (IS_GEN9_BC(i915) || GRAPHICS_VER(i915) >= 10) { 1016 1016 /* Store the frequency values in 16.66 MHZ units, which is 1017 1017 * the natural hardware unit for SKL 1018 1018 */ ··· 1048 1048 struct intel_uncore *uncore = gt->uncore; 1049 1049 1050 1050 /* Program defaults and thresholds for RPS */ 1051 - if (IS_GEN(gt->i915, 9)) 1051 + if (GRAPHICS_VER(gt->i915) == 9) 1052 1052 intel_uncore_write_fw(uncore, GEN6_RC_VIDEO_FREQ, 1053 1053 GEN9_FREQUENCY(rps->rp1_freq)); 1054 1054 ··· 1365 1365 enabled = chv_rps_enable(rps); 1366 1366 else if (IS_VALLEYVIEW(i915)) 1367 1367 enabled = vlv_rps_enable(rps); 1368 - else if (INTEL_GEN(i915) >= 9) 1368 + else if (GRAPHICS_VER(i915) >= 9) 1369 1369 enabled = gen9_rps_enable(rps); 1370 - else if (INTEL_GEN(i915) >= 8) 1370 + else if (GRAPHICS_VER(i915) >= 8) 1371 1371 enabled = gen8_rps_enable(rps); 1372 - else if (INTEL_GEN(i915) >= 6) 1372 + else if (GRAPHICS_VER(i915) >= 6) 1373 1373 enabled = gen6_rps_enable(rps); 1374 1374 else if (IS_IRONLAKE_M(i915)) 1375 1375 enabled = gen5_rps_enable(rps); 1376 1376 else 1377 - MISSING_CASE(INTEL_GEN(i915)); 1377 + MISSING_CASE(GRAPHICS_VER(i915)); 1378 1378 intel_uncore_forcewake_put(uncore, FORCEWAKE_ALL); 1379 1379 if (!enabled) 1380 1380 return; ··· 1393 1393 1394 1394 if (has_busy_stats(rps)) 1395 1395 intel_rps_set_timer(rps); 1396 - else if (INTEL_GEN(i915) >= 6) 1396 + else if (GRAPHICS_VER(i915) >= 6) 1397 1397 intel_rps_set_interrupts(rps); 1398 1398 else 1399 1399 /* Ironlake currently uses intel_ips.ko */ {} ··· 1414 1414 intel_rps_clear_interrupts(rps); 1415 1415 intel_rps_clear_timer(rps); 1416 1416 1417 - if (INTEL_GEN(i915) >= 6) 1417 + if (GRAPHICS_VER(i915) >= 6) 1418 1418 gen6_rps_disable(rps); 1419 1419 else if (IS_IRONLAKE_M(i915)) 1420 1420 gen5_rps_disable(rps); ··· 1453 1453 { 1454 1454 struct drm_i915_private *i915 = rps_to_i915(rps); 1455 1455 1456 - if (INTEL_GEN(i915) >= 9) 1456 + if (GRAPHICS_VER(i915) >= 9) 1457 1457 return DIV_ROUND_CLOSEST(val * GT_FREQUENCY_MULTIPLIER, 1458 1458 GEN9_FREQ_SCALER); 1459 1459 else if (IS_CHERRYVIEW(i915)) 1460 1460 return chv_gpu_freq(rps, val); 1461 1461 else if (IS_VALLEYVIEW(i915)) 1462 1462 return byt_gpu_freq(rps, val); 1463 - else if (INTEL_GEN(i915) >= 6) 1463 + else if (GRAPHICS_VER(i915) >= 6) 1464 1464 return val * GT_FREQUENCY_MULTIPLIER; 1465 1465 else 1466 1466 return val; ··· 1470 1470 { 1471 1471 struct drm_i915_private *i915 = rps_to_i915(rps); 1472 1472 1473 - if (INTEL_GEN(i915) >= 9) 1473 + if (GRAPHICS_VER(i915) >= 9) 1474 1474 return DIV_ROUND_CLOSEST(val * GEN9_FREQ_SCALER, 1475 1475 GT_FREQUENCY_MULTIPLIER); 1476 1476 else if (IS_CHERRYVIEW(i915)) 1477 1477 return chv_freq_opcode(rps, val); 1478 1478 else if (IS_VALLEYVIEW(i915)) 1479 1479 return byt_freq_opcode(rps, val); 1480 - else if (INTEL_GEN(i915) >= 6) 1480 + else if (GRAPHICS_VER(i915) >= 6) 1481 1481 return DIV_ROUND_CLOSEST(val, GT_FREQUENCY_MULTIPLIER); 1482 1482 else 1483 1483 return val; ··· 1770 1770 spin_unlock(&gt->irq_lock); 1771 1771 } 1772 1772 1773 - if (INTEL_GEN(gt->i915) >= 8) 1773 + if (GRAPHICS_VER(gt->i915) >= 8) 1774 1774 return; 1775 1775 1776 1776 if (pm_iir & PM_VEBOX_USER_INTERRUPT) ··· 1833 1833 chv_rps_init(rps); 1834 1834 else if (IS_VALLEYVIEW(i915)) 1835 1835 vlv_rps_init(rps); 1836 - else if (INTEL_GEN(i915) >= 6) 1836 + else if (GRAPHICS_VER(i915) >= 6) 1837 1837 gen6_rps_init(rps); 1838 1838 else if (IS_IRONLAKE_M(i915)) 1839 1839 gen5_rps_init(rps); ··· 1843 1843 rps->min_freq_softlimit = rps->min_freq; 1844 1844 1845 1845 /* After setting max-softlimit, find the overclock max freq */ 1846 - if (IS_GEN(i915, 6) || IS_IVYBRIDGE(i915) || IS_HASWELL(i915)) { 1846 + if (GRAPHICS_VER(i915) == 6 || IS_IVYBRIDGE(i915) || IS_HASWELL(i915)) { 1847 1847 u32 params = 0; 1848 1848 1849 1849 sandybridge_pcode_read(i915, GEN6_READ_OC_PARAMS, ··· 1872 1872 * 1873 1873 * TODO: verify if this can be reproduced on VLV,CHV. 1874 1874 */ 1875 - if (INTEL_GEN(i915) <= 7) 1875 + if (GRAPHICS_VER(i915) <= 7) 1876 1876 rps->pm_intrmsk_mbz |= GEN6_PM_RP_UP_EI_EXPIRED; 1877 1877 1878 - if (INTEL_GEN(i915) >= 8 && INTEL_GEN(i915) < 11) 1878 + if (GRAPHICS_VER(i915) >= 8 && GRAPHICS_VER(i915) < 11) 1879 1879 rps->pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC; 1880 1880 } 1881 1881 1882 1882 void intel_rps_sanitize(struct intel_rps *rps) 1883 1883 { 1884 - if (INTEL_GEN(rps_to_i915(rps)) >= 6) 1884 + if (GRAPHICS_VER(rps_to_i915(rps)) >= 6) 1885 1885 rps_disable_interrupts(rps); 1886 1886 } 1887 1887 ··· 1892 1892 1893 1893 if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915)) 1894 1894 cagf = (rpstat >> 8) & 0xff; 1895 - else if (INTEL_GEN(i915) >= 9) 1895 + else if (GRAPHICS_VER(i915) >= 9) 1896 1896 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT; 1897 1897 else if (IS_HASWELL(i915) || IS_BROADWELL(i915)) 1898 1898 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT; 1899 - else if (INTEL_GEN(i915) >= 6) 1899 + else if (GRAPHICS_VER(i915) >= 6) 1900 1900 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT; 1901 1901 else 1902 1902 cagf = gen5_invert_freq(rps, (rpstat & MEMSTAT_PSTATE_MASK) >> ··· 1915 1915 vlv_punit_get(i915); 1916 1916 freq = vlv_punit_read(i915, PUNIT_REG_GPU_FREQ_STS); 1917 1917 vlv_punit_put(i915); 1918 - } else if (INTEL_GEN(i915) >= 6) { 1918 + } else if (GRAPHICS_VER(i915) >= 6) { 1919 1919 freq = intel_uncore_read(uncore, GEN6_RPSTAT1); 1920 1920 } else { 1921 1921 freq = intel_uncore_read(uncore, MEMSTAT_ILK); ··· 1968 1968 * We only register the i915 ips part with intel-ips once everything is 1969 1969 * set up, to avoid intel-ips sneaking in and reading bogus values. 1970 1970 */ 1971 - if (IS_GEN(gt->i915, 5)) { 1971 + if (GRAPHICS_VER(gt->i915) == 5) { 1972 1972 GEM_BUG_ON(ips_mchdev); 1973 1973 rcu_assign_pointer(ips_mchdev, gt->i915); 1974 1974 ips_ping_for_i915_load();
+7 -7
drivers/gpu/drm/i915/gt/intel_sseu.c
··· 590 590 cherryview_sseu_info_init(gt); 591 591 else if (IS_BROADWELL(i915)) 592 592 bdw_sseu_info_init(gt); 593 - else if (IS_GEN(i915, 9)) 593 + else if (GRAPHICS_VER(i915) == 9) 594 594 gen9_sseu_info_init(gt); 595 - else if (IS_GEN(i915, 10)) 595 + else if (GRAPHICS_VER(i915) == 10) 596 596 gen10_sseu_info_init(gt); 597 - else if (IS_GEN(i915, 11)) 597 + else if (GRAPHICS_VER(i915) == 11) 598 598 gen11_sseu_info_init(gt); 599 - else if (INTEL_GEN(i915) >= 12) 599 + else if (GRAPHICS_VER(i915) >= 12) 600 600 gen12_sseu_info_init(gt); 601 601 } 602 602 ··· 613 613 * No explicit RPCS request is needed to ensure full 614 614 * slice/subslice/EU enablement prior to Gen9. 615 615 */ 616 - if (INTEL_GEN(i915) < 9) 616 + if (GRAPHICS_VER(i915) < 9) 617 617 return 0; 618 618 619 619 /* ··· 651 651 * subslices are enabled, or a count between one and four on the first 652 652 * slice. 653 653 */ 654 - if (IS_GEN(i915, 11) && 654 + if (GRAPHICS_VER(i915) == 11 && 655 655 slices == 1 && 656 656 subslices > min_t(u8, 4, hweight8(sseu->subslice_mask[0]) / 2)) { 657 657 GEM_BUG_ON(subslices & 1); ··· 669 669 if (sseu->has_slice_pg) { 670 670 u32 mask, val = slices; 671 671 672 - if (INTEL_GEN(i915) >= 11) { 672 + if (GRAPHICS_VER(i915) >= 11) { 673 673 mask = GEN11_RPCS_S_CNT_MASK; 674 674 val <<= GEN11_RPCS_S_CNT_SHIFT; 675 675 } else {
+3 -3
drivers/gpu/drm/i915/gt/intel_sseu_debugfs.c
··· 248 248 struct sseu_dev_info sseu; 249 249 intel_wakeref_t wakeref; 250 250 251 - if (INTEL_GEN(i915) < 8) 251 + if (GRAPHICS_VER(i915) < 8) 252 252 return -ENODEV; 253 253 254 254 seq_puts(m, "SSEU Device Info\n"); ··· 265 265 cherryview_sseu_device_status(gt, &sseu); 266 266 else if (IS_BROADWELL(i915)) 267 267 bdw_sseu_device_status(gt, &sseu); 268 - else if (IS_GEN(i915, 9)) 268 + else if (GRAPHICS_VER(i915) == 9) 269 269 gen9_sseu_device_status(gt, &sseu); 270 - else if (INTEL_GEN(i915) >= 10) 270 + else if (GRAPHICS_VER(i915) >= 10) 271 271 gen10_sseu_device_status(gt, &sseu); 272 272 } 273 273
+33 -33
drivers/gpu/drm/i915/gt/intel_workarounds.c
··· 699 699 700 700 if (IS_DG1(i915)) 701 701 dg1_ctx_workarounds_init(engine, wal); 702 - else if (IS_GEN(i915, 12)) 702 + else if (GRAPHICS_VER(i915) == 12) 703 703 gen12_ctx_workarounds_init(engine, wal); 704 - else if (IS_GEN(i915, 11)) 704 + else if (GRAPHICS_VER(i915) == 11) 705 705 icl_ctx_workarounds_init(engine, wal); 706 706 else if (IS_CANNONLAKE(i915)) 707 707 cnl_ctx_workarounds_init(engine, wal); ··· 719 719 chv_ctx_workarounds_init(engine, wal); 720 720 else if (IS_BROADWELL(i915)) 721 721 bdw_ctx_workarounds_init(engine, wal); 722 - else if (IS_GEN(i915, 7)) 722 + else if (GRAPHICS_VER(i915) == 7) 723 723 gen7_ctx_workarounds_init(engine, wal); 724 - else if (IS_GEN(i915, 6)) 724 + else if (GRAPHICS_VER(i915) == 6) 725 725 gen6_ctx_workarounds_init(engine, wal); 726 - else if (INTEL_GEN(i915) < 8) 726 + else if (GRAPHICS_VER(i915) < 8) 727 727 ; 728 728 else 729 - MISSING_CASE(INTEL_GEN(i915)); 729 + MISSING_CASE(GRAPHICS_VER(i915)); 730 730 731 731 wa_init_finish(wal); 732 732 } ··· 950 950 unsigned int slice, subslice; 951 951 u32 l3_en, mcr, mcr_mask; 952 952 953 - GEM_BUG_ON(INTEL_GEN(i915) < 10); 953 + GEM_BUG_ON(GRAPHICS_VER(i915) < 10); 954 954 955 955 /* 956 956 * WaProgramMgsrForL3BankSpecificMmioReads: cnl,icl ··· 980 980 * of every MMIO read. 981 981 */ 982 982 983 - if (INTEL_GEN(i915) >= 10 && is_power_of_2(sseu->slice_mask)) { 983 + if (GRAPHICS_VER(i915) >= 10 && is_power_of_2(sseu->slice_mask)) { 984 984 u32 l3_fuse = 985 985 intel_uncore_read(&i915->uncore, GEN10_MIRROR_FUSE3) & 986 986 GEN10_L3BANK_MASK; ··· 1002 1002 } 1003 1003 subslice--; 1004 1004 1005 - if (INTEL_GEN(i915) >= 11) { 1005 + if (GRAPHICS_VER(i915) >= 11) { 1006 1006 mcr = GEN11_MCR_SLICE(slice) | GEN11_MCR_SUBSLICE(subslice); 1007 1007 mcr_mask = GEN11_MCR_SLICE_MASK | GEN11_MCR_SUBSLICE_MASK; 1008 1008 } else { ··· 1171 1171 dg1_gt_workarounds_init(i915, wal); 1172 1172 else if (IS_TIGERLAKE(i915)) 1173 1173 tgl_gt_workarounds_init(i915, wal); 1174 - else if (IS_GEN(i915, 12)) 1174 + else if (GRAPHICS_VER(i915) == 12) 1175 1175 gen12_gt_workarounds_init(i915, wal); 1176 - else if (IS_GEN(i915, 11)) 1176 + else if (GRAPHICS_VER(i915) == 11) 1177 1177 icl_gt_workarounds_init(i915, wal); 1178 1178 else if (IS_CANNONLAKE(i915)) 1179 1179 cnl_gt_workarounds_init(i915, wal); ··· 1193 1193 vlv_gt_workarounds_init(i915, wal); 1194 1194 else if (IS_IVYBRIDGE(i915)) 1195 1195 ivb_gt_workarounds_init(i915, wal); 1196 - else if (IS_GEN(i915, 6)) 1196 + else if (GRAPHICS_VER(i915) == 6) 1197 1197 snb_gt_workarounds_init(i915, wal); 1198 - else if (IS_GEN(i915, 5)) 1198 + else if (GRAPHICS_VER(i915) == 5) 1199 1199 ilk_gt_workarounds_init(i915, wal); 1200 1200 else if (IS_G4X(i915)) 1201 1201 g4x_gt_workarounds_init(i915, wal); 1202 - else if (IS_GEN(i915, 4)) 1202 + else if (GRAPHICS_VER(i915) == 4) 1203 1203 gen4_gt_workarounds_init(i915, wal); 1204 - else if (INTEL_GEN(i915) <= 8) 1204 + else if (GRAPHICS_VER(i915) <= 8) 1205 1205 ; 1206 1206 else 1207 - MISSING_CASE(INTEL_GEN(i915)); 1207 + MISSING_CASE(GRAPHICS_VER(i915)); 1208 1208 } 1209 1209 1210 1210 void intel_gt_init_workarounds(struct drm_i915_private *i915) ··· 1558 1558 1559 1559 if (IS_DG1(i915)) 1560 1560 dg1_whitelist_build(engine); 1561 - else if (IS_GEN(i915, 12)) 1561 + else if (GRAPHICS_VER(i915) == 12) 1562 1562 tgl_whitelist_build(engine); 1563 - else if (IS_GEN(i915, 11)) 1563 + else if (GRAPHICS_VER(i915) == 11) 1564 1564 icl_whitelist_build(engine); 1565 1565 else if (IS_CANNONLAKE(i915)) 1566 1566 cnl_whitelist_build(engine); ··· 1576 1576 bxt_whitelist_build(engine); 1577 1577 else if (IS_SKYLAKE(i915)) 1578 1578 skl_whitelist_build(engine); 1579 - else if (INTEL_GEN(i915) <= 8) 1579 + else if (GRAPHICS_VER(i915) <= 8) 1580 1580 ; 1581 1581 else 1582 - MISSING_CASE(INTEL_GEN(i915)); 1582 + MISSING_CASE(GRAPHICS_VER(i915)); 1583 1583 1584 1584 wa_init_finish(w); 1585 1585 } ··· 1695 1695 ENABLE_SMALLPL); 1696 1696 } 1697 1697 1698 - if (IS_GEN(i915, 11)) { 1698 + if (GRAPHICS_VER(i915) == 11) { 1699 1699 /* This is not an Wa. Enable for better image quality */ 1700 1700 wa_masked_en(wal, 1701 1701 _3D_CHICKEN3, ··· 1793 1793 FF_DOP_CLOCK_GATE_DISABLE); 1794 1794 } 1795 1795 1796 - if (IS_GEN_RANGE(i915, 9, 12)) { 1796 + if (IS_GRAPHICS_VER(i915, 9, 12)) { 1797 1797 /* FtrPerCtxtPreemptionGranularityControl:skl,bxt,kbl,cfl,cnl,icl,tgl */ 1798 1798 wa_masked_en(wal, 1799 1799 GEN7_FF_SLICE_CS_CHICKEN1, ··· 1817 1817 GEN9_POOLED_EU_LOAD_BALANCING_FIX_DISABLE); 1818 1818 } 1819 1819 1820 - if (IS_GEN(i915, 9)) { 1820 + if (GRAPHICS_VER(i915) == 9) { 1821 1821 /* WaContextSwitchWithConcurrentTLBInvalidate:skl,bxt,kbl,glk,cfl */ 1822 1822 wa_masked_en(wal, 1823 1823 GEN9_CSFE_CHICKEN1_RCS, ··· 1921 1921 GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE); 1922 1922 } 1923 1923 1924 - if (IS_GEN(i915, 7)) { 1924 + if (GRAPHICS_VER(i915) == 7) { 1925 1925 /* WaBCSVCSTlbInvalidationMode:ivb,vlv,hsw */ 1926 1926 wa_masked_en(wal, 1927 1927 GFX_MODE_GEN7, ··· 1953 1953 GEN6_WIZ_HASHING_16x4); 1954 1954 } 1955 1955 1956 - if (IS_GEN_RANGE(i915, 6, 7)) 1956 + if (IS_GRAPHICS_VER(i915, 6, 7)) 1957 1957 /* 1958 1958 * We need to disable the AsyncFlip performance optimisations in 1959 1959 * order to use MI_WAIT_FOR_EVENT within the CS. It should ··· 1965 1965 MI_MODE, 1966 1966 ASYNC_FLIP_PERF_DISABLE); 1967 1967 1968 - if (IS_GEN(i915, 6)) { 1968 + if (GRAPHICS_VER(i915) == 6) { 1969 1969 /* 1970 1970 * Required for the hardware to program scanline values for 1971 1971 * waiting ··· 2019 2019 CM0_STC_EVICT_DISABLE_LRA_SNB); 2020 2020 } 2021 2021 2022 - if (IS_GEN_RANGE(i915, 4, 6)) 2022 + if (IS_GRAPHICS_VER(i915, 4, 6)) 2023 2023 /* WaTimedSingleVertexDispatch:cl,bw,ctg,elk,ilk,snb */ 2024 2024 wa_add(wal, MI_MODE, 2025 2025 0, _MASKED_BIT_ENABLE(VS_TIMER_DISPATCH), 2026 2026 /* XXX bit doesn't stick on Broadwater */ 2027 2027 IS_I965G(i915) ? 0 : VS_TIMER_DISPATCH); 2028 2028 2029 - if (IS_GEN(i915, 4)) 2029 + if (GRAPHICS_VER(i915) == 4) 2030 2030 /* 2031 2031 * Disable CONSTANT_BUFFER before it is loaded from the context 2032 2032 * image. For as it is loaded, it is executed and the stored ··· 2058 2058 static void 2059 2059 engine_init_workarounds(struct intel_engine_cs *engine, struct i915_wa_list *wal) 2060 2060 { 2061 - if (I915_SELFTEST_ONLY(INTEL_GEN(engine->i915) < 4)) 2061 + if (I915_SELFTEST_ONLY(GRAPHICS_VER(engine->i915) < 4)) 2062 2062 return; 2063 2063 2064 2064 if (engine->class == RENDER_CLASS) ··· 2071 2071 { 2072 2072 struct i915_wa_list *wal = &engine->wa_list; 2073 2073 2074 - if (INTEL_GEN(engine->i915) < 4) 2074 + if (GRAPHICS_VER(engine->i915) < 4) 2075 2075 return; 2076 2076 2077 2077 wa_init_start(wal, "engine", engine->name); ··· 2112 2112 const struct mcr_range *mcr_ranges; 2113 2113 int i; 2114 2114 2115 - if (INTEL_GEN(i915) >= 12) 2115 + if (GRAPHICS_VER(i915) >= 12) 2116 2116 mcr_ranges = mcr_ranges_gen12; 2117 - else if (INTEL_GEN(i915) >= 8) 2117 + else if (GRAPHICS_VER(i915) >= 8) 2118 2118 mcr_ranges = mcr_ranges_gen8; 2119 2119 else 2120 2120 return false; ··· 2143 2143 u32 srm, *cs; 2144 2144 2145 2145 srm = MI_STORE_REGISTER_MEM | MI_SRM_LRM_GLOBAL_GTT; 2146 - if (INTEL_GEN(i915) >= 8) 2146 + if (GRAPHICS_VER(i915) >= 8) 2147 2147 srm++; 2148 2148 2149 2149 for (i = 0, wa = wal->list; i < wal->count; i++, wa++) {
+3 -3
drivers/gpu/drm/i915/gt/selftest_engine_cs.c
··· 52 52 return PTR_ERR(cs); 53 53 54 54 cmd = MI_STORE_REGISTER_MEM | MI_USE_GGTT; 55 - if (INTEL_GEN(rq->engine->i915) >= 8) 55 + if (GRAPHICS_VER(rq->engine->i915) >= 8) 56 56 cmd++; 57 57 *cs++ = cmd; 58 58 *cs++ = i915_mmio_reg_offset(RING_TIMESTAMP(rq->engine->mmio_base)); ··· 125 125 enum intel_engine_id id; 126 126 int err = 0; 127 127 128 - if (INTEL_GEN(gt->i915) < 7) /* for per-engine CS_TIMESTAMP */ 128 + if (GRAPHICS_VER(gt->i915) < 7) /* for per-engine CS_TIMESTAMP */ 129 129 return 0; 130 130 131 131 perf_begin(gt); ··· 249 249 enum intel_engine_id id; 250 250 int err = 0; 251 251 252 - if (INTEL_GEN(gt->i915) < 7) /* for per-engine CS_TIMESTAMP */ 252 + if (GRAPHICS_VER(gt->i915) < 7) /* for per-engine CS_TIMESTAMP */ 253 253 return 0; 254 254 255 255 perf_begin(gt);
+1 -1
drivers/gpu/drm/i915/gt/selftest_engine_pm.c
··· 198 198 * the same CS clock. 199 199 */ 200 200 201 - if (INTEL_GEN(gt->i915) < 8) 201 + if (GRAPHICS_VER(gt->i915) < 8) 202 202 return 0; 203 203 204 204 for_each_engine(engine, gt, id) {
+2 -2
drivers/gpu/drm/i915/gt/selftest_execlists.c
··· 3269 3269 if (!intel_engine_has_preemption(engine)) 3270 3270 continue; 3271 3271 3272 - if (IS_GEN(gt->i915, 8) && engine->class != RENDER_CLASS) 3272 + if (GRAPHICS_VER(gt->i915) == 8 && engine->class != RENDER_CLASS) 3273 3273 continue; /* we need per-context GPR */ 3274 3274 3275 3275 if (igt_live_test_begin(&t, gt->i915, __func__, engine->name)) { ··· 4293 4293 return 0; 4294 4294 4295 4295 /* As we use CS_GPR we cannot run before they existed on all engines. */ 4296 - if (INTEL_GEN(gt->i915) < 9) 4296 + if (GRAPHICS_VER(gt->i915) < 9) 4297 4297 return 0; 4298 4298 4299 4299 for (class = 0; class <= MAX_ENGINE_CLASS; class++) {
+4 -4
drivers/gpu/drm/i915/gt/selftest_gt_pm.c
··· 74 74 return 0; 75 75 } 76 76 77 - if (INTEL_GEN(gt->i915) < 4) /* Any CS_TIMESTAMP? */ 77 + if (GRAPHICS_VER(gt->i915) < 4) /* Any CS_TIMESTAMP? */ 78 78 return 0; 79 79 80 - if (IS_GEN(gt->i915, 5)) 80 + if (GRAPHICS_VER(gt->i915) == 5) 81 81 /* 82 82 * XXX CS_TIMESTAMP low dword is dysfunctional? 83 83 * ··· 86 86 */ 87 87 return 0; 88 88 89 - if (IS_GEN(gt->i915, 4)) 89 + if (GRAPHICS_VER(gt->i915) == 4) 90 90 /* 91 91 * XXX CS_TIMESTAMP appears gibberish 92 92 * ··· 105 105 u64 time; 106 106 u64 dt; 107 107 108 - if (INTEL_GEN(engine->i915) < 7 && engine->id != RCS0) 108 + if (GRAPHICS_VER(engine->i915) < 7 && engine->id != RCS0) 109 109 continue; 110 110 111 111 measure_clocks(engine, &cycles, &dt);
+4 -4
drivers/gpu/drm/i915/gt/selftest_hangcheck.c
··· 180 180 goto cancel_rq; 181 181 182 182 batch = h->batch; 183 - if (INTEL_GEN(gt->i915) >= 8) { 183 + if (GRAPHICS_VER(gt->i915) >= 8) { 184 184 *batch++ = MI_STORE_DWORD_IMM_GEN4; 185 185 *batch++ = lower_32_bits(hws_address(hws, rq)); 186 186 *batch++ = upper_32_bits(hws_address(hws, rq)); ··· 194 194 *batch++ = MI_BATCH_BUFFER_START | 1 << 8 | 1; 195 195 *batch++ = lower_32_bits(vma->node.start); 196 196 *batch++ = upper_32_bits(vma->node.start); 197 - } else if (INTEL_GEN(gt->i915) >= 6) { 197 + } else if (GRAPHICS_VER(gt->i915) >= 6) { 198 198 *batch++ = MI_STORE_DWORD_IMM_GEN4; 199 199 *batch++ = 0; 200 200 *batch++ = lower_32_bits(hws_address(hws, rq)); ··· 207 207 *batch++ = MI_NOOP; 208 208 *batch++ = MI_BATCH_BUFFER_START | 1 << 8; 209 209 *batch++ = lower_32_bits(vma->node.start); 210 - } else if (INTEL_GEN(gt->i915) >= 4) { 210 + } else if (GRAPHICS_VER(gt->i915) >= 4) { 211 211 *batch++ = MI_STORE_DWORD_IMM_GEN4 | MI_USE_GGTT; 212 212 *batch++ = 0; 213 213 *batch++ = lower_32_bits(hws_address(hws, rq)); ··· 243 243 } 244 244 245 245 flags = 0; 246 - if (INTEL_GEN(gt->i915) <= 5) 246 + if (GRAPHICS_VER(gt->i915) <= 5) 247 247 flags |= I915_DISPATCH_SECURE; 248 248 249 249 err = rq->engine->emit_bb_start(rq, vma->node.start, PAGE_SIZE, flags);
+2 -2
drivers/gpu/drm/i915/gt/selftest_llc.c
··· 44 44 if (found != ia_freq) { 45 45 pr_err("Min freq table(%d/[%d, %d]):%dMHz did not match expected CPU freq, found %d, expected %d\n", 46 46 gpu_freq, consts.min_gpu_freq, consts.max_gpu_freq, 47 - intel_gpu_freq(rps, gpu_freq * (INTEL_GEN(i915) >= 9 ? GEN9_FREQ_SCALER : 1)), 47 + intel_gpu_freq(rps, gpu_freq * (GRAPHICS_VER(i915) >= 9 ? GEN9_FREQ_SCALER : 1)), 48 48 found, ia_freq); 49 49 err = -EINVAL; 50 50 break; ··· 54 54 if (found != ring_freq) { 55 55 pr_err("Min freq table(%d/[%d, %d]):%dMHz did not match expected ring freq, found %d, expected %d\n", 56 56 gpu_freq, consts.min_gpu_freq, consts.max_gpu_freq, 57 - intel_gpu_freq(rps, gpu_freq * (INTEL_GEN(i915) >= 9 ? GEN9_FREQ_SCALER : 1)), 57 + intel_gpu_freq(rps, gpu_freq * (GRAPHICS_VER(i915) >= 9 ? GEN9_FREQ_SCALER : 1)), 58 58 found, ring_freq); 59 59 err = -EINVAL; 60 60 break;
+4 -4
drivers/gpu/drm/i915/gt/selftest_lrc.c
··· 584 584 int err; 585 585 int n; 586 586 587 - if (INTEL_GEN(engine->i915) < 9 && engine->class != RENDER_CLASS) 587 + if (GRAPHICS_VER(engine->i915) < 9 && engine->class != RENDER_CLASS) 588 588 return 0; /* GPR only on rcs0 for gen8 */ 589 589 590 590 err = gpr_make_dirty(engine->kernel_context); ··· 1389 1389 1390 1390 static bool skip_isolation(const struct intel_engine_cs *engine) 1391 1391 { 1392 - if (engine->class == COPY_ENGINE_CLASS && INTEL_GEN(engine->i915) == 9) 1392 + if (engine->class == COPY_ENGINE_CLASS && GRAPHICS_VER(engine->i915) == 9) 1393 1393 return true; 1394 1394 1395 - if (engine->class == RENDER_CLASS && INTEL_GEN(engine->i915) == 11) 1395 + if (engine->class == RENDER_CLASS && GRAPHICS_VER(engine->i915) == 11) 1396 1396 return true; 1397 1397 1398 1398 return false; ··· 1551 1551 /* We use the already reserved extra page in context state */ 1552 1552 if (!a->wa_bb_page) { 1553 1553 GEM_BUG_ON(b->wa_bb_page); 1554 - GEM_BUG_ON(INTEL_GEN(engine->i915) == 12); 1554 + GEM_BUG_ON(GRAPHICS_VER(engine->i915) == 12); 1555 1555 goto unpin_b; 1556 1556 } 1557 1557
+1 -1
drivers/gpu/drm/i915/gt/selftest_mocs.c
··· 183 183 * which only controls CPU initiated MMIO. Routing does not 184 184 * work for CS access so we cannot verify them on this path. 185 185 */ 186 - return INTEL_GEN(i915) >= 8 && offset >= 0xb000 && offset <= 0xb4ff; 186 + return GRAPHICS_VER(i915) >= 8 && offset >= 0xb000 && offset <= 0xb4ff; 187 187 } 188 188 189 189 static int check_l3cc_table(struct intel_engine_cs *engine,
+2 -2
drivers/gpu/drm/i915/gt/selftest_rc6.c
··· 140 140 } 141 141 142 142 cmd = MI_STORE_REGISTER_MEM | MI_USE_GGTT; 143 - if (INTEL_GEN(rq->engine->i915) >= 8) 143 + if (GRAPHICS_VER(rq->engine->i915) >= 8) 144 144 cmd++; 145 145 146 146 *cs++ = cmd; ··· 193 193 int err = 0; 194 194 195 195 /* A read of CTX_INFO upsets rc6. Poke the bear! */ 196 - if (INTEL_GEN(gt->i915) < 8) 196 + if (GRAPHICS_VER(gt->i915) < 8) 197 197 return 0; 198 198 199 199 engines = randomised_engines(gt, &prng, &count);
+3 -3
drivers/gpu/drm/i915/gt/selftest_ring_submission.c
··· 41 41 return ERR_CAST(cs); 42 42 } 43 43 44 - if (INTEL_GEN(engine->i915) >= 6) { 44 + if (GRAPHICS_VER(engine->i915) >= 6) { 45 45 *cs++ = MI_STORE_DWORD_IMM_GEN4; 46 46 *cs++ = 0; 47 - } else if (INTEL_GEN(engine->i915) >= 4) { 47 + } else if (GRAPHICS_VER(engine->i915) >= 4) { 48 48 *cs++ = MI_STORE_DWORD_IMM_GEN4 | MI_USE_GGTT; 49 49 *cs++ = 0; 50 50 } else { ··· 266 266 if (!intel_engine_can_store_dword(engine)) 267 267 continue; 268 268 269 - if (IS_GEN_RANGE(gt->i915, 4, 5)) 269 + if (IS_GRAPHICS_VER(gt->i915, 4, 5)) 270 270 continue; /* MI_STORE_DWORD is privileged! */ 271 271 272 272 saved_wa = fetch_and_zero(&engine->wa_ctx.vma);
+8 -8
drivers/gpu/drm/i915/gt/selftest_rps.c
··· 204 204 i915_mmio_reg_offset(BXT_RP_STATE_CAP), 205 205 intel_uncore_read(rps_to_uncore(rps), 206 206 BXT_RP_STATE_CAP)); 207 - } else if (IS_GEN(i915, 9)) { 207 + } else if (GRAPHICS_VER(i915) == 9) { 208 208 pr_info("P_STATE_LIMITS[%x]: 0x%08x\n", 209 209 i915_mmio_reg_offset(GEN9_RP_STATE_LIMITS), 210 210 intel_uncore_read(rps_to_uncore(rps), ··· 222 222 struct igt_spinner spin; 223 223 int err = 0; 224 224 225 - if (!intel_rps_is_enabled(rps) || INTEL_GEN(gt->i915) < 6) 225 + if (!intel_rps_is_enabled(rps) || GRAPHICS_VER(gt->i915) < 6) 226 226 return 0; 227 227 228 228 if (igt_spinner_init(&spin, gt)) ··· 506 506 507 507 min_gpu_freq = rps->min_freq; 508 508 max_gpu_freq = rps->max_freq; 509 - if (INTEL_GEN(i915) >= 9) { 509 + if (GRAPHICS_VER(i915) >= 9) { 510 510 /* Convert GT frequency to 50 HZ units */ 511 511 min_gpu_freq /= GEN9_FREQ_SCALER; 512 512 max_gpu_freq /= GEN9_FREQ_SCALER; ··· 614 614 if (!intel_rps_is_enabled(rps)) 615 615 return 0; 616 616 617 - if (INTEL_GEN(gt->i915) < 8) /* for CS simplicity */ 617 + if (GRAPHICS_VER(gt->i915) < 8) /* for CS simplicity */ 618 618 return 0; 619 619 620 620 if (CPU_LATENCY >= 0) ··· 755 755 if (!intel_rps_is_enabled(rps)) 756 756 return 0; 757 757 758 - if (INTEL_GEN(gt->i915) < 8) /* for CS simplicity */ 758 + if (GRAPHICS_VER(gt->i915) < 8) /* for CS simplicity */ 759 759 return 0; 760 760 761 761 if (CPU_LATENCY >= 0) ··· 1031 1031 * First, let's check whether or not we are receiving interrupts. 1032 1032 */ 1033 1033 1034 - if (!intel_rps_has_interrupts(rps) || INTEL_GEN(gt->i915) < 6) 1034 + if (!intel_rps_has_interrupts(rps) || GRAPHICS_VER(gt->i915) < 6) 1035 1035 return 0; 1036 1036 1037 1037 intel_gt_pm_get(gt); ··· 1136 1136 * that theory. 1137 1137 */ 1138 1138 1139 - if (!intel_rps_is_enabled(rps) || INTEL_GEN(gt->i915) < 6) 1139 + if (!intel_rps_is_enabled(rps) || GRAPHICS_VER(gt->i915) < 6) 1140 1140 return 0; 1141 1141 1142 1142 if (!librapl_supported(gt->i915)) ··· 1240 1240 * moving parts into dynamic reclocking based on load. 1241 1241 */ 1242 1242 1243 - if (!intel_rps_is_enabled(rps) || INTEL_GEN(gt->i915) < 6) 1243 + if (!intel_rps_is_enabled(rps) || GRAPHICS_VER(gt->i915) < 6) 1244 1244 return 0; 1245 1245 1246 1246 if (igt_spinner_init(&spin, gt))
+3 -3
drivers/gpu/drm/i915/gt/selftest_timeline.c
··· 457 457 if (IS_ERR(cs)) 458 458 return PTR_ERR(cs); 459 459 460 - if (INTEL_GEN(rq->engine->i915) >= 8) { 460 + if (GRAPHICS_VER(rq->engine->i915) >= 8) { 461 461 *cs++ = MI_STORE_DWORD_IMM_GEN4 | MI_USE_GGTT; 462 462 *cs++ = addr; 463 463 *cs++ = 0; 464 464 *cs++ = value; 465 - } else if (INTEL_GEN(rq->engine->i915) >= 4) { 465 + } else if (GRAPHICS_VER(rq->engine->i915) >= 4) { 466 466 *cs++ = MI_STORE_DWORD_IMM_GEN4 | MI_USE_GGTT; 467 467 *cs++ = 0; 468 468 *cs++ = addr; ··· 992 992 * even across multiple wraps. 993 993 */ 994 994 995 - if (INTEL_GEN(gt->i915) < 8) /* CS convenience [SRM/LRM] */ 995 + if (GRAPHICS_VER(gt->i915) < 8) /* CS convenience [SRM/LRM] */ 996 996 return 0; 997 997 998 998 tl = intel_timeline_create(gt);
+4 -4
drivers/gpu/drm/i915/gt/selftest_workarounds.c
··· 145 145 goto err_req; 146 146 147 147 srm = MI_STORE_REGISTER_MEM | MI_SRM_LRM_GLOBAL_GTT; 148 - if (INTEL_GEN(engine->i915) >= 8) 148 + if (GRAPHICS_VER(engine->i915) >= 8) 149 149 srm++; 150 150 151 151 cs = intel_ring_begin(rq, 4 * RING_MAX_NONPRIV_SLOTS); ··· 546 546 547 547 srm = MI_STORE_REGISTER_MEM; 548 548 lrm = MI_LOAD_REGISTER_MEM; 549 - if (INTEL_GEN(engine->i915) >= 8) 549 + if (GRAPHICS_VER(engine->i915) >= 8) 550 550 lrm++, srm++; 551 551 552 552 pr_debug("%s: Writing garbage to %x\n", ··· 749 749 750 750 /* Can the user write to the whitelisted registers? */ 751 751 752 - if (INTEL_GEN(gt->i915) < 7) /* minimum requirement for LRI, SRM, LRM */ 752 + if (GRAPHICS_VER(gt->i915) < 7) /* minimum requirement for LRI, SRM, LRM */ 753 753 return 0; 754 754 755 755 for_each_engine(engine, gt, id) { ··· 829 829 goto err_req; 830 830 831 831 srm = MI_STORE_REGISTER_MEM; 832 - if (INTEL_GEN(engine->i915) >= 8) 832 + if (GRAPHICS_VER(engine->i915) >= 8) 833 833 srm++; 834 834 835 835 cs = intel_ring_begin(rq, 4 * engine->whitelist.count);
+51
drivers/gpu/drm/i915/gt/uc/abi/guc_actions_abi.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2014-2021 Intel Corporation 4 + */ 5 + 6 + #ifndef _ABI_GUC_ACTIONS_ABI_H 7 + #define _ABI_GUC_ACTIONS_ABI_H 8 + 9 + enum intel_guc_action { 10 + INTEL_GUC_ACTION_DEFAULT = 0x0, 11 + INTEL_GUC_ACTION_REQUEST_PREEMPTION = 0x2, 12 + INTEL_GUC_ACTION_REQUEST_ENGINE_RESET = 0x3, 13 + INTEL_GUC_ACTION_ALLOCATE_DOORBELL = 0x10, 14 + INTEL_GUC_ACTION_DEALLOCATE_DOORBELL = 0x20, 15 + INTEL_GUC_ACTION_LOG_BUFFER_FILE_FLUSH_COMPLETE = 0x30, 16 + INTEL_GUC_ACTION_UK_LOG_ENABLE_LOGGING = 0x40, 17 + INTEL_GUC_ACTION_FORCE_LOG_BUFFER_FLUSH = 0x302, 18 + INTEL_GUC_ACTION_ENTER_S_STATE = 0x501, 19 + INTEL_GUC_ACTION_EXIT_S_STATE = 0x502, 20 + INTEL_GUC_ACTION_SLPC_REQUEST = 0x3003, 21 + INTEL_GUC_ACTION_AUTHENTICATE_HUC = 0x4000, 22 + INTEL_GUC_ACTION_REGISTER_COMMAND_TRANSPORT_BUFFER = 0x4505, 23 + INTEL_GUC_ACTION_DEREGISTER_COMMAND_TRANSPORT_BUFFER = 0x4506, 24 + INTEL_GUC_ACTION_LIMIT 25 + }; 26 + 27 + enum intel_guc_preempt_options { 28 + INTEL_GUC_PREEMPT_OPTION_DROP_WORK_Q = 0x4, 29 + INTEL_GUC_PREEMPT_OPTION_DROP_SUBMIT_Q = 0x8, 30 + }; 31 + 32 + enum intel_guc_report_status { 33 + INTEL_GUC_REPORT_STATUS_UNKNOWN = 0x0, 34 + INTEL_GUC_REPORT_STATUS_ACKED = 0x1, 35 + INTEL_GUC_REPORT_STATUS_ERROR = 0x2, 36 + INTEL_GUC_REPORT_STATUS_COMPLETE = 0x4, 37 + }; 38 + 39 + enum intel_guc_sleep_state_status { 40 + INTEL_GUC_SLEEP_STATE_SUCCESS = 0x1, 41 + INTEL_GUC_SLEEP_STATE_PREEMPT_TO_IDLE_FAILED = 0x2, 42 + INTEL_GUC_SLEEP_STATE_ENGINE_RESET_FAILED = 0x3 43 + #define INTEL_GUC_SLEEP_STATE_INVALID_MASK 0x80000000 44 + }; 45 + 46 + #define GUC_LOG_CONTROL_LOGGING_ENABLED (1 << 0) 47 + #define GUC_LOG_CONTROL_VERBOSITY_SHIFT 4 48 + #define GUC_LOG_CONTROL_VERBOSITY_MASK (0xF << GUC_LOG_CONTROL_VERBOSITY_SHIFT) 49 + #define GUC_LOG_CONTROL_DEFAULT_LOGGING (1 << 8) 50 + 51 + #endif /* _ABI_GUC_ACTIONS_ABI_H */
+106
drivers/gpu/drm/i915/gt/uc/abi/guc_communication_ctb_abi.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2014-2021 Intel Corporation 4 + */ 5 + 6 + #ifndef _ABI_GUC_COMMUNICATION_CTB_ABI_H 7 + #define _ABI_GUC_COMMUNICATION_CTB_ABI_H 8 + 9 + #include <linux/types.h> 10 + 11 + /** 12 + * DOC: CTB based communication 13 + * 14 + * The CTB (command transport buffer) communication between Host and GuC 15 + * is based on u32 data stream written to the shared buffer. One buffer can 16 + * be used to transmit data only in one direction (one-directional channel). 17 + * 18 + * Current status of the each buffer is stored in the buffer descriptor. 19 + * Buffer descriptor holds tail and head fields that represents active data 20 + * stream. The tail field is updated by the data producer (sender), and head 21 + * field is updated by the data consumer (receiver):: 22 + * 23 + * +------------+ 24 + * | DESCRIPTOR | +=================+============+========+ 25 + * +============+ | | MESSAGE(s) | | 26 + * | address |--------->+=================+============+========+ 27 + * +------------+ 28 + * | head | ^-----head--------^ 29 + * +------------+ 30 + * | tail | ^---------tail-----------------^ 31 + * +------------+ 32 + * | size | ^---------------size--------------------^ 33 + * +------------+ 34 + * 35 + * Each message in data stream starts with the single u32 treated as a header, 36 + * followed by optional set of u32 data that makes message specific payload:: 37 + * 38 + * +------------+---------+---------+---------+ 39 + * | MESSAGE | 40 + * +------------+---------+---------+---------+ 41 + * | msg[0] | [1] | ... | [n-1] | 42 + * +------------+---------+---------+---------+ 43 + * | MESSAGE | MESSAGE PAYLOAD | 44 + * + HEADER +---------+---------+---------+ 45 + * | | 0 | ... | n | 46 + * +======+=====+=========+=========+=========+ 47 + * | 31:16| code| | | | 48 + * +------+-----+ | | | 49 + * | 15:5|flags| | | | 50 + * +------+-----+ | | | 51 + * | 4:0| len| | | | 52 + * +------+-----+---------+---------+---------+ 53 + * 54 + * ^-------------len-------------^ 55 + * 56 + * The message header consists of: 57 + * 58 + * - **len**, indicates length of the message payload (in u32) 59 + * - **code**, indicates message code 60 + * - **flags**, holds various bits to control message handling 61 + */ 62 + 63 + /* 64 + * Describes single command transport buffer. 65 + * Used by both guc-master and clients. 66 + */ 67 + struct guc_ct_buffer_desc { 68 + u32 addr; /* gfx address */ 69 + u64 host_private; /* host private data */ 70 + u32 size; /* size in bytes */ 71 + u32 head; /* offset updated by GuC*/ 72 + u32 tail; /* offset updated by owner */ 73 + u32 is_in_error; /* error indicator */ 74 + u32 reserved1; 75 + u32 reserved2; 76 + u32 owner; /* id of the channel owner */ 77 + u32 owner_sub_id; /* owner-defined field for extra tracking */ 78 + u32 reserved[5]; 79 + } __packed; 80 + 81 + /* Type of command transport buffer */ 82 + #define INTEL_GUC_CT_BUFFER_TYPE_SEND 0x0u 83 + #define INTEL_GUC_CT_BUFFER_TYPE_RECV 0x1u 84 + 85 + /* 86 + * Definition of the command transport message header (DW0) 87 + * 88 + * bit[4..0] message len (in dwords) 89 + * bit[7..5] reserved 90 + * bit[8] response (G2H only) 91 + * bit[8] write fence to desc (H2G only) 92 + * bit[9] write status to H2G buff (H2G only) 93 + * bit[10] send status back via G2H (H2G only) 94 + * bit[15..11] reserved 95 + * bit[31..16] action code 96 + */ 97 + #define GUC_CT_MSG_LEN_SHIFT 0 98 + #define GUC_CT_MSG_LEN_MASK 0x1F 99 + #define GUC_CT_MSG_IS_RESPONSE (1 << 8) 100 + #define GUC_CT_MSG_WRITE_FENCE_TO_DESC (1 << 8) 101 + #define GUC_CT_MSG_WRITE_STATUS_TO_BUFF (1 << 9) 102 + #define GUC_CT_MSG_SEND_STATUS (1 << 10) 103 + #define GUC_CT_MSG_ACTION_SHIFT 16 104 + #define GUC_CT_MSG_ACTION_MASK 0xFFFF 105 + 106 + #endif /* _ABI_GUC_COMMUNICATION_CTB_ABI_H */
+52
drivers/gpu/drm/i915/gt/uc/abi/guc_communication_mmio_abi.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2014-2021 Intel Corporation 4 + */ 5 + 6 + #ifndef _ABI_GUC_COMMUNICATION_MMIO_ABI_H 7 + #define _ABI_GUC_COMMUNICATION_MMIO_ABI_H 8 + 9 + /** 10 + * DOC: MMIO based communication 11 + * 12 + * The MMIO based communication between Host and GuC uses software scratch 13 + * registers, where first register holds data treated as message header, 14 + * and other registers are used to hold message payload. 15 + * 16 + * For Gen9+, GuC uses software scratch registers 0xC180-0xC1B8, 17 + * but no H2G command takes more than 8 parameters and the GuC FW 18 + * itself uses an 8-element array to store the H2G message. 19 + * 20 + * +-----------+---------+---------+---------+ 21 + * | MMIO[0] | MMIO[1] | ... | MMIO[n] | 22 + * +-----------+---------+---------+---------+ 23 + * | header | optional payload | 24 + * +======+====+=========+=========+=========+ 25 + * | 31:28|type| | | | 26 + * +------+----+ | | | 27 + * | 27:16|data| | | | 28 + * +------+----+ | | | 29 + * | 15:0|code| | | | 30 + * +------+----+---------+---------+---------+ 31 + * 32 + * The message header consists of: 33 + * 34 + * - **type**, indicates message type 35 + * - **code**, indicates message code, is specific for **type** 36 + * - **data**, indicates message data, optional, depends on **code** 37 + * 38 + * The following message **types** are supported: 39 + * 40 + * - **REQUEST**, indicates Host-to-GuC request, requested GuC action code 41 + * must be priovided in **code** field. Optional action specific parameters 42 + * can be provided in remaining payload registers or **data** field. 43 + * 44 + * - **RESPONSE**, indicates GuC-to-Host response from earlier GuC request, 45 + * action response status will be provided in **code** field. Optional 46 + * response data can be returned in remaining payload registers or **data** 47 + * field. 48 + */ 49 + 50 + #define GUC_MAX_MMIO_MSG_LEN 8 51 + 52 + #endif /* _ABI_GUC_COMMUNICATION_MMIO_ABI_H */
+14
drivers/gpu/drm/i915/gt/uc/abi/guc_errors_abi.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2014-2021 Intel Corporation 4 + */ 5 + 6 + #ifndef _ABI_GUC_ERRORS_ABI_H 7 + #define _ABI_GUC_ERRORS_ABI_H 8 + 9 + enum intel_guc_response_status { 10 + INTEL_GUC_RESPONSE_STATUS_SUCCESS = 0x0, 11 + INTEL_GUC_RESPONSE_STATUS_GENERIC_FAIL = 0xF000, 12 + }; 13 + 14 + #endif /* _ABI_GUC_ERRORS_ABI_H */
+21
drivers/gpu/drm/i915/gt/uc/abi/guc_messages_abi.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2014-2021 Intel Corporation 4 + */ 5 + 6 + #ifndef _ABI_GUC_MESSAGES_ABI_H 7 + #define _ABI_GUC_MESSAGES_ABI_H 8 + 9 + #define INTEL_GUC_MSG_TYPE_SHIFT 28 10 + #define INTEL_GUC_MSG_TYPE_MASK (0xF << INTEL_GUC_MSG_TYPE_SHIFT) 11 + #define INTEL_GUC_MSG_DATA_SHIFT 16 12 + #define INTEL_GUC_MSG_DATA_MASK (0xFFF << INTEL_GUC_MSG_DATA_SHIFT) 13 + #define INTEL_GUC_MSG_CODE_SHIFT 0 14 + #define INTEL_GUC_MSG_CODE_MASK (0xFFFF << INTEL_GUC_MSG_CODE_SHIFT) 15 + 16 + enum intel_guc_msg_type { 17 + INTEL_GUC_MSG_TYPE_REQUEST = 0x0, 18 + INTEL_GUC_MSG_TYPE_RESPONSE = 0xF, 19 + }; 20 + 21 + #endif /* _ABI_GUC_MESSAGES_ABI_H */
+19 -44
drivers/gpu/drm/i915/gt/uc/intel_guc.c
··· 60 60 enum forcewake_domains fw_domains = 0; 61 61 unsigned int i; 62 62 63 - if (INTEL_GEN(gt->i915) >= 11) { 64 - guc->send_regs.base = 65 - i915_mmio_reg_offset(GEN11_SOFT_SCRATCH(0)); 66 - guc->send_regs.count = GEN11_SOFT_SCRATCH_COUNT; 67 - } else { 68 - guc->send_regs.base = i915_mmio_reg_offset(SOFT_SCRATCH(0)); 69 - guc->send_regs.count = GUC_MAX_MMIO_MSG_LEN; 70 - BUILD_BUG_ON(GUC_MAX_MMIO_MSG_LEN > SOFT_SCRATCH_COUNT); 71 - } 63 + GEM_BUG_ON(!guc->send_regs.base); 64 + GEM_BUG_ON(!guc->send_regs.count); 72 65 73 66 for (i = 0; i < guc->send_regs.count; i++) { 74 67 fw_domains |= intel_uncore_forcewake_for_reg(gt->uncore, ··· 89 96 assert_rpm_wakelock_held(&gt->i915->runtime_pm); 90 97 91 98 spin_lock_irq(&gt->irq_lock); 92 - if (!guc->interrupts.enabled) { 93 - WARN_ON_ONCE(intel_uncore_read(gt->uncore, GEN8_GT_IIR(2)) & 94 - gt->pm_guc_events); 95 - guc->interrupts.enabled = true; 96 - gen6_gt_pm_enable_irq(gt, gt->pm_guc_events); 97 - } 99 + WARN_ON_ONCE(intel_uncore_read(gt->uncore, GEN8_GT_IIR(2)) & 100 + gt->pm_guc_events); 101 + gen6_gt_pm_enable_irq(gt, gt->pm_guc_events); 98 102 spin_unlock_irq(&gt->irq_lock); 99 103 } 100 104 ··· 102 112 assert_rpm_wakelock_held(&gt->i915->runtime_pm); 103 113 104 114 spin_lock_irq(&gt->irq_lock); 105 - guc->interrupts.enabled = false; 106 115 107 116 gen6_gt_pm_disable_irq(gt, gt->pm_guc_events); 108 117 ··· 123 134 static void gen11_enable_guc_interrupts(struct intel_guc *guc) 124 135 { 125 136 struct intel_gt *gt = guc_to_gt(guc); 137 + u32 events = REG_FIELD_PREP(ENGINE1_MASK, GUC_INTR_GUC2HOST); 126 138 127 139 spin_lock_irq(&gt->irq_lock); 128 - if (!guc->interrupts.enabled) { 129 - u32 events = REG_FIELD_PREP(ENGINE1_MASK, GUC_INTR_GUC2HOST); 130 - 131 - WARN_ON_ONCE(gen11_gt_reset_one_iir(gt, 0, GEN11_GUC)); 132 - intel_uncore_write(gt->uncore, 133 - GEN11_GUC_SG_INTR_ENABLE, events); 134 - intel_uncore_write(gt->uncore, 135 - GEN11_GUC_SG_INTR_MASK, ~events); 136 - guc->interrupts.enabled = true; 137 - } 140 + WARN_ON_ONCE(gen11_gt_reset_one_iir(gt, 0, GEN11_GUC)); 141 + intel_uncore_write(gt->uncore, 142 + GEN11_GUC_SG_INTR_ENABLE, events); 143 + intel_uncore_write(gt->uncore, 144 + GEN11_GUC_SG_INTR_MASK, ~events); 138 145 spin_unlock_irq(&gt->irq_lock); 139 146 } 140 147 ··· 139 154 struct intel_gt *gt = guc_to_gt(guc); 140 155 141 156 spin_lock_irq(&gt->irq_lock); 142 - guc->interrupts.enabled = false; 143 157 144 158 intel_uncore_write(gt->uncore, GEN11_GUC_SG_INTR_MASK, ~0); 145 159 intel_uncore_write(gt->uncore, GEN11_GUC_SG_INTR_ENABLE, 0); ··· 160 176 161 177 mutex_init(&guc->send_mutex); 162 178 spin_lock_init(&guc->irq_lock); 163 - if (INTEL_GEN(i915) >= 11) { 179 + if (GRAPHICS_VER(i915) >= 11) { 164 180 guc->notify_reg = GEN11_GUC_HOST_INTERRUPT; 165 181 guc->interrupts.reset = gen11_reset_guc_interrupts; 166 182 guc->interrupts.enable = gen11_enable_guc_interrupts; 167 183 guc->interrupts.disable = gen11_disable_guc_interrupts; 184 + guc->send_regs.base = 185 + i915_mmio_reg_offset(GEN11_SOFT_SCRATCH(0)); 186 + guc->send_regs.count = GEN11_SOFT_SCRATCH_COUNT; 187 + 168 188 } else { 169 189 guc->notify_reg = GUC_SEND_INTERRUPT; 170 190 guc->interrupts.reset = gen9_reset_guc_interrupts; 171 191 guc->interrupts.enable = gen9_enable_guc_interrupts; 172 192 guc->interrupts.disable = gen9_disable_guc_interrupts; 193 + guc->send_regs.base = i915_mmio_reg_offset(SOFT_SCRATCH(0)); 194 + guc->send_regs.count = GUC_MAX_MMIO_MSG_LEN; 195 + BUILD_BUG_ON(GUC_MAX_MMIO_MSG_LEN > SOFT_SCRATCH_COUNT); 173 196 } 174 197 } 175 198 ··· 458 467 intel_guc_log_handle_flush_event(&guc->log); 459 468 460 469 return 0; 461 - } 462 - 463 - int intel_guc_sample_forcewake(struct intel_guc *guc) 464 - { 465 - struct drm_i915_private *dev_priv = guc_to_gt(guc)->i915; 466 - u32 action[2]; 467 - 468 - action[0] = INTEL_GUC_ACTION_SAMPLE_FORCEWAKE; 469 - /* WaRsDisableCoarsePowerGating:skl,cnl */ 470 - if (!HAS_RC6(dev_priv) || NEEDS_WaRsDisableCoarsePowerGating(dev_priv)) 471 - action[1] = 0; 472 - else 473 - /* bit 0 and 1 are for Render and Media domain separately */ 474 - action[1] = GUC_FORCEWAKE_RENDER | GUC_FORCEWAKE_MEDIA; 475 - 476 - return intel_guc_send(guc, action, ARRAY_SIZE(action)); 477 470 } 478 471 479 472 /**
-2
drivers/gpu/drm/i915/gt/uc/intel_guc.h
··· 33 33 unsigned int msg_enabled_mask; 34 34 35 35 struct { 36 - bool enabled; 37 36 void (*reset)(struct intel_guc *guc); 38 37 void (*enable)(struct intel_guc *guc); 39 38 void (*disable)(struct intel_guc *guc); ··· 127 128 u32 *response_buf, u32 response_buf_size); 128 129 int intel_guc_to_host_process_recv_msg(struct intel_guc *guc, 129 130 const u32 *payload, u32 len); 130 - int intel_guc_sample_forcewake(struct intel_guc *guc); 131 131 int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset); 132 132 int intel_guc_suspend(struct intel_guc *guc); 133 133 int intel_guc_resume(struct intel_guc *guc);
+13 -9
drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c
··· 6 6 #include "gt/intel_gt.h" 7 7 #include "gt/intel_lrc.h" 8 8 #include "intel_guc_ads.h" 9 + #include "intel_guc_fwif.h" 9 10 #include "intel_uc.h" 10 11 #include "i915_drv.h" 11 12 ··· 105 104 GUC_MAX_INSTANCES_PER_CLASS; 106 105 107 106 for_each_engine(engine, gt, id) { 108 - u8 guc_class = engine->class; 107 + u8 guc_class = engine_class_to_guc_class(engine->class); 109 108 110 109 system_info->mapping_table[guc_class][engine->instance] = 111 110 engine->instance; ··· 125 124 struct __guc_ads_blob *blob = guc->ads_blob; 126 125 const u32 skipped_size = LRC_PPHWSP_SZ * PAGE_SIZE + LR_HW_CONTEXT_SIZE; 127 126 u32 base; 128 - u8 engine_class; 127 + u8 engine_class, guc_class; 129 128 130 129 /* GuC scheduling policies */ 131 130 guc_policies_init(&blob->policies); ··· 141 140 for (engine_class = 0; engine_class <= MAX_ENGINE_CLASS; ++engine_class) { 142 141 if (engine_class == OTHER_CLASS) 143 142 continue; 143 + 144 + guc_class = engine_class_to_guc_class(engine_class); 145 + 144 146 /* 145 147 * TODO: Set context pointer to default state to allow 146 148 * GuC to re-init guilty contexts after internal reset. 147 149 */ 148 - blob->ads.golden_context_lrca[engine_class] = 0; 149 - blob->ads.eng_state_size[engine_class] = 150 + blob->ads.golden_context_lrca[guc_class] = 0; 151 + blob->ads.eng_state_size[guc_class] = 150 152 intel_engine_context_size(guc_to_gt(guc), 151 153 engine_class) - 152 154 skipped_size; 153 155 } 154 156 155 157 /* System info */ 156 - blob->system_info.engine_enabled_masks[RENDER_CLASS] = 1; 157 - blob->system_info.engine_enabled_masks[COPY_ENGINE_CLASS] = 1; 158 - blob->system_info.engine_enabled_masks[VIDEO_DECODE_CLASS] = VDBOX_MASK(gt); 159 - blob->system_info.engine_enabled_masks[VIDEO_ENHANCEMENT_CLASS] = VEBOX_MASK(gt); 158 + blob->system_info.engine_enabled_masks[GUC_RENDER_CLASS] = 1; 159 + blob->system_info.engine_enabled_masks[GUC_BLITTER_CLASS] = 1; 160 + blob->system_info.engine_enabled_masks[GUC_VIDEO_CLASS] = VDBOX_MASK(gt); 161 + blob->system_info.engine_enabled_masks[GUC_VIDEOENHANCE_CLASS] = VEBOX_MASK(gt); 160 162 161 163 blob->system_info.generic_gt_sysinfo[GUC_GENERIC_GT_SYSINFO_SLICE_ENABLED] = 162 164 hweight8(gt->info.sseu.slice_mask); 163 165 blob->system_info.generic_gt_sysinfo[GUC_GENERIC_GT_SYSINFO_VDBOX_SFC_SUPPORT_MASK] = 164 166 gt->info.vdbox_sfc_access; 165 167 166 - if (INTEL_GEN(i915) >= 12 && !IS_DGFX(i915)) { 168 + if (GRAPHICS_VER(i915) >= 12 && !IS_DGFX(i915)) { 167 169 u32 distdbreg = intel_uncore_read(gt->uncore, 168 170 GEN12_DIST_DBS_POPULATED); 169 171 blob->system_info.generic_gt_sysinfo[GUC_GENERIC_GT_SYSINFO_DOORBELL_COUNT_PER_SQIDI] =
+334 -236
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.c
··· 7 7 #include "intel_guc_ct.h" 8 8 #include "gt/intel_gt.h" 9 9 10 - #define CT_ERROR(_ct, _fmt, ...) \ 11 - DRM_DEV_ERROR(ct_to_dev(_ct), "CT: " _fmt, ##__VA_ARGS__) 12 - #ifdef CONFIG_DRM_I915_DEBUG_GUC 13 - #define CT_DEBUG(_ct, _fmt, ...) \ 14 - DRM_DEV_DEBUG_DRIVER(ct_to_dev(_ct), "CT: " _fmt, ##__VA_ARGS__) 15 - #else 16 - #define CT_DEBUG(...) do { } while (0) 17 - #endif 18 - 19 - struct ct_request { 20 - struct list_head link; 21 - u32 fence; 22 - u32 status; 23 - u32 response_len; 24 - u32 *response_buf; 25 - }; 26 - 27 - struct ct_incoming_request { 28 - struct list_head link; 29 - u32 msg[]; 30 - }; 31 - 32 - enum { CTB_SEND = 0, CTB_RECV = 1 }; 33 - 34 - enum { CTB_OWNER_HOST = 0 }; 35 - 36 - static void ct_incoming_request_worker_func(struct work_struct *w); 37 - 38 - /** 39 - * intel_guc_ct_init_early - Initialize CT state without requiring device access 40 - * @ct: pointer to CT struct 41 - */ 42 - void intel_guc_ct_init_early(struct intel_guc_ct *ct) 43 - { 44 - spin_lock_init(&ct->requests.lock); 45 - INIT_LIST_HEAD(&ct->requests.pending); 46 - INIT_LIST_HEAD(&ct->requests.incoming); 47 - INIT_WORK(&ct->requests.worker, ct_incoming_request_worker_func); 48 - } 49 - 50 10 static inline struct intel_guc *ct_to_guc(struct intel_guc_ct *ct) 51 11 { 52 12 return container_of(ct, struct intel_guc, ct); ··· 22 62 return ct_to_gt(ct)->i915; 23 63 } 24 64 25 - static inline struct device *ct_to_dev(struct intel_guc_ct *ct) 65 + static inline struct drm_device *ct_to_drm(struct intel_guc_ct *ct) 26 66 { 27 - return ct_to_i915(ct)->drm.dev; 67 + return &ct_to_i915(ct)->drm; 68 + } 69 + 70 + #define CT_ERROR(_ct, _fmt, ...) \ 71 + drm_err(ct_to_drm(_ct), "CT: " _fmt, ##__VA_ARGS__) 72 + #ifdef CONFIG_DRM_I915_DEBUG_GUC 73 + #define CT_DEBUG(_ct, _fmt, ...) \ 74 + drm_dbg(ct_to_drm(_ct), "CT: " _fmt, ##__VA_ARGS__) 75 + #else 76 + #define CT_DEBUG(...) do { } while (0) 77 + #endif 78 + #define CT_PROBE_ERROR(_ct, _fmt, ...) \ 79 + i915_probe_error(ct_to_i915(ct), "CT: " _fmt, ##__VA_ARGS__) 80 + 81 + /** 82 + * DOC: CTB Blob 83 + * 84 + * We allocate single blob to hold both CTB descriptors and buffers: 85 + * 86 + * +--------+-----------------------------------------------+------+ 87 + * | offset | contents | size | 88 + * +========+===============================================+======+ 89 + * | 0x0000 | H2G `CTB Descriptor`_ (send) | | 90 + * +--------+-----------------------------------------------+ 4K | 91 + * | 0x0800 | G2H `CTB Descriptor`_ (recv) | | 92 + * +--------+-----------------------------------------------+------+ 93 + * | 0x1000 | H2G `CT Buffer`_ (send) | n*4K | 94 + * | | | | 95 + * +--------+-----------------------------------------------+------+ 96 + * | 0x1000 | G2H `CT Buffer`_ (recv) | m*4K | 97 + * | + n*4K | | | 98 + * +--------+-----------------------------------------------+------+ 99 + * 100 + * Size of each `CT Buffer`_ must be multiple of 4K. 101 + * As we don't expect too many messages, for now use minimum sizes. 102 + */ 103 + #define CTB_DESC_SIZE ALIGN(sizeof(struct guc_ct_buffer_desc), SZ_2K) 104 + #define CTB_H2G_BUFFER_SIZE (SZ_4K) 105 + #define CTB_G2H_BUFFER_SIZE (SZ_4K) 106 + 107 + struct ct_request { 108 + struct list_head link; 109 + u32 fence; 110 + u32 status; 111 + u32 response_len; 112 + u32 *response_buf; 113 + }; 114 + 115 + struct ct_incoming_msg { 116 + struct list_head link; 117 + u32 size; 118 + u32 msg[]; 119 + }; 120 + 121 + enum { CTB_SEND = 0, CTB_RECV = 1 }; 122 + 123 + enum { CTB_OWNER_HOST = 0 }; 124 + 125 + static void ct_receive_tasklet_func(struct tasklet_struct *t); 126 + static void ct_incoming_request_worker_func(struct work_struct *w); 127 + 128 + /** 129 + * intel_guc_ct_init_early - Initialize CT state without requiring device access 130 + * @ct: pointer to CT struct 131 + */ 132 + void intel_guc_ct_init_early(struct intel_guc_ct *ct) 133 + { 134 + spin_lock_init(&ct->ctbs.send.lock); 135 + spin_lock_init(&ct->ctbs.recv.lock); 136 + spin_lock_init(&ct->requests.lock); 137 + INIT_LIST_HEAD(&ct->requests.pending); 138 + INIT_LIST_HEAD(&ct->requests.incoming); 139 + INIT_WORK(&ct->requests.worker, ct_incoming_request_worker_func); 140 + tasklet_setup(&ct->receive_tasklet, ct_receive_tasklet_func); 28 141 } 29 142 30 143 static inline const char *guc_ct_buffer_type_to_str(u32 type) ··· 121 88 desc->owner = CTB_OWNER_HOST; 122 89 } 123 90 124 - static void guc_ct_buffer_desc_reset(struct guc_ct_buffer_desc *desc) 91 + static void guc_ct_buffer_reset(struct intel_guc_ct_buffer *ctb, u32 cmds_addr) 125 92 { 126 - desc->head = 0; 127 - desc->tail = 0; 128 - desc->is_in_error = 0; 93 + guc_ct_buffer_desc_init(ctb->desc, cmds_addr, ctb->size); 94 + } 95 + 96 + static void guc_ct_buffer_init(struct intel_guc_ct_buffer *ctb, 97 + struct guc_ct_buffer_desc *desc, 98 + u32 *cmds, u32 size) 99 + { 100 + GEM_BUG_ON(size % 4); 101 + 102 + ctb->desc = desc; 103 + ctb->cmds = cmds; 104 + ctb->size = size; 105 + 106 + guc_ct_buffer_reset(ctb, 0); 129 107 } 130 108 131 109 static int guc_action_register_ct_buffer(struct intel_guc *guc, ··· 197 153 int intel_guc_ct_init(struct intel_guc_ct *ct) 198 154 { 199 155 struct intel_guc *guc = ct_to_guc(ct); 156 + struct guc_ct_buffer_desc *desc; 157 + u32 blob_size; 158 + u32 cmds_size; 200 159 void *blob; 160 + u32 *cmds; 201 161 int err; 202 - int i; 203 162 204 163 GEM_BUG_ON(ct->vma); 205 164 206 - /* We allocate 1 page to hold both descriptors and both buffers. 207 - * ___________..................... 208 - * |desc (SEND)| : 209 - * |___________| PAGE/4 210 - * :___________....................: 211 - * |desc (RECV)| : 212 - * |___________| PAGE/4 213 - * :_______________________________: 214 - * |cmds (SEND) | 215 - * | PAGE/4 216 - * |_______________________________| 217 - * |cmds (RECV) | 218 - * | PAGE/4 219 - * |_______________________________| 220 - * 221 - * Each message can use a maximum of 32 dwords and we don't expect to 222 - * have more than 1 in flight at any time, so we have enough space. 223 - * Some logic further ahead will rely on the fact that there is only 1 224 - * page and that it is always mapped, so if the size is changed the 225 - * other code will need updating as well. 226 - */ 227 - 228 - err = intel_guc_allocate_and_map_vma(guc, PAGE_SIZE, &ct->vma, &blob); 165 + blob_size = 2 * CTB_DESC_SIZE + CTB_H2G_BUFFER_SIZE + CTB_G2H_BUFFER_SIZE; 166 + err = intel_guc_allocate_and_map_vma(guc, blob_size, &ct->vma, &blob); 229 167 if (unlikely(err)) { 230 - CT_ERROR(ct, "Failed to allocate CT channel (err=%d)\n", err); 168 + CT_PROBE_ERROR(ct, "Failed to allocate %u for CTB data (%pe)\n", 169 + blob_size, ERR_PTR(err)); 231 170 return err; 232 171 } 233 172 234 - CT_DEBUG(ct, "vma base=%#x\n", intel_guc_ggtt_offset(guc, ct->vma)); 173 + CT_DEBUG(ct, "base=%#x size=%u\n", intel_guc_ggtt_offset(guc, ct->vma), blob_size); 235 174 236 - /* store pointers to desc and cmds */ 237 - for (i = 0; i < ARRAY_SIZE(ct->ctbs); i++) { 238 - GEM_BUG_ON((i != CTB_SEND) && (i != CTB_RECV)); 239 - ct->ctbs[i].desc = blob + PAGE_SIZE/4 * i; 240 - ct->ctbs[i].cmds = blob + PAGE_SIZE/4 * i + PAGE_SIZE/2; 241 - } 175 + /* store pointers to desc and cmds for send ctb */ 176 + desc = blob; 177 + cmds = blob + 2 * CTB_DESC_SIZE; 178 + cmds_size = CTB_H2G_BUFFER_SIZE; 179 + CT_DEBUG(ct, "%s desc %#tx cmds %#tx size %u\n", "send", 180 + ptrdiff(desc, blob), ptrdiff(cmds, blob), cmds_size); 181 + 182 + guc_ct_buffer_init(&ct->ctbs.send, desc, cmds, cmds_size); 183 + 184 + /* store pointers to desc and cmds for recv ctb */ 185 + desc = blob + CTB_DESC_SIZE; 186 + cmds = blob + 2 * CTB_DESC_SIZE + CTB_H2G_BUFFER_SIZE; 187 + cmds_size = CTB_G2H_BUFFER_SIZE; 188 + CT_DEBUG(ct, "%s desc %#tx cmds %#tx size %u\n", "recv", 189 + ptrdiff(desc, blob), ptrdiff(cmds, blob), cmds_size); 190 + 191 + guc_ct_buffer_init(&ct->ctbs.recv, desc, cmds, cmds_size); 242 192 243 193 return 0; 244 194 } ··· 247 209 { 248 210 GEM_BUG_ON(ct->enabled); 249 211 212 + tasklet_kill(&ct->receive_tasklet); 250 213 i915_vma_unpin_and_release(&ct->vma, I915_VMA_RELEASE_MAP); 251 214 memset(ct, 0, sizeof(*ct)); 252 215 } ··· 261 222 int intel_guc_ct_enable(struct intel_guc_ct *ct) 262 223 { 263 224 struct intel_guc *guc = ct_to_guc(ct); 264 - u32 base, cmds, size; 225 + u32 base, cmds; 226 + void *blob; 265 227 int err; 266 - int i; 267 228 268 229 GEM_BUG_ON(ct->enabled); 269 230 270 231 /* vma should be already allocated and map'ed */ 271 232 GEM_BUG_ON(!ct->vma); 233 + GEM_BUG_ON(!i915_gem_object_has_pinned_pages(ct->vma->obj)); 272 234 base = intel_guc_ggtt_offset(guc, ct->vma); 273 235 274 - /* (re)initialize descriptors 275 - * cmds buffers are in the second half of the blob page 276 - */ 277 - for (i = 0; i < ARRAY_SIZE(ct->ctbs); i++) { 278 - GEM_BUG_ON((i != CTB_SEND) && (i != CTB_RECV)); 279 - cmds = base + PAGE_SIZE / 4 * i + PAGE_SIZE / 2; 280 - size = PAGE_SIZE / 4; 281 - CT_DEBUG(ct, "%d: addr=%#x size=%u\n", i, cmds, size); 282 - guc_ct_buffer_desc_init(ct->ctbs[i].desc, cmds, size); 283 - } 236 + /* blob should start with send descriptor */ 237 + blob = __px_vaddr(ct->vma->obj); 238 + GEM_BUG_ON(blob != ct->ctbs.send.desc); 239 + 240 + /* (re)initialize descriptors */ 241 + cmds = base + ptrdiff(ct->ctbs.send.cmds, blob); 242 + guc_ct_buffer_reset(&ct->ctbs.send, cmds); 243 + 244 + cmds = base + ptrdiff(ct->ctbs.recv.cmds, blob); 245 + guc_ct_buffer_reset(&ct->ctbs.recv, cmds); 284 246 285 247 /* 286 248 * Register both CT buffers starting with RECV buffer. 287 249 * Descriptors are in first half of the blob. 288 250 */ 289 - err = ct_register_buffer(ct, base + PAGE_SIZE / 4 * CTB_RECV, 251 + err = ct_register_buffer(ct, base + ptrdiff(ct->ctbs.recv.desc, blob), 290 252 INTEL_GUC_CT_BUFFER_TYPE_RECV); 291 253 if (unlikely(err)) 292 254 goto err_out; 293 255 294 - err = ct_register_buffer(ct, base + PAGE_SIZE / 4 * CTB_SEND, 256 + err = ct_register_buffer(ct, base + ptrdiff(ct->ctbs.send.desc, blob), 295 257 INTEL_GUC_CT_BUFFER_TYPE_SEND); 296 258 if (unlikely(err)) 297 259 goto err_deregister; ··· 304 264 err_deregister: 305 265 ct_deregister_buffer(ct, INTEL_GUC_CT_BUFFER_TYPE_RECV); 306 266 err_out: 307 - CT_ERROR(ct, "Failed to open open CT channel (err=%d)\n", err); 267 + CT_PROBE_ERROR(ct, "Failed to enable CTB (%pe)\n", ERR_PTR(err)); 308 268 return err; 309 269 } 310 270 ··· 332 292 return ++ct->requests.last_fence; 333 293 } 334 294 295 + static void write_barrier(struct intel_guc_ct *ct) 296 + { 297 + struct intel_guc *guc = ct_to_guc(ct); 298 + struct intel_gt *gt = guc_to_gt(guc); 299 + 300 + if (i915_gem_object_is_lmem(guc->ct.vma->obj)) { 301 + GEM_BUG_ON(guc->send_regs.fw_domains); 302 + /* 303 + * This register is used by the i915 and GuC for MMIO based 304 + * communication. Once we are in this code CTBs are the only 305 + * method the i915 uses to communicate with the GuC so it is 306 + * safe to write to this register (a value of 0 is NOP for MMIO 307 + * communication). If we ever start mixing CTBs and MMIOs a new 308 + * register will have to be chosen. 309 + */ 310 + intel_uncore_write_fw(gt->uncore, GEN11_SOFT_SCRATCH(0), 0); 311 + } else { 312 + /* wmb() sufficient for a barrier if in smem */ 313 + wmb(); 314 + } 315 + } 316 + 335 317 /** 336 318 * DOC: CTB Host to GuC request 337 319 * ··· 375 313 static int ct_write(struct intel_guc_ct *ct, 376 314 const u32 *action, 377 315 u32 len /* in dwords */, 378 - u32 fence, 379 - bool want_response) 316 + u32 fence) 380 317 { 381 - struct intel_guc_ct_buffer *ctb = &ct->ctbs[CTB_SEND]; 318 + struct intel_guc_ct_buffer *ctb = &ct->ctbs.send; 382 319 struct guc_ct_buffer_desc *desc = ctb->desc; 383 320 u32 head = desc->head; 384 321 u32 tail = desc->tail; 385 - u32 size = desc->size; 322 + u32 size = ctb->size; 386 323 u32 used; 387 324 u32 header; 388 325 u32 *cmds = ctb->cmds; ··· 390 329 if (unlikely(desc->is_in_error)) 391 330 return -EPIPE; 392 331 393 - if (unlikely(!IS_ALIGNED(head | tail | size, 4) || 332 + if (unlikely(!IS_ALIGNED(head | tail, 4) || 394 333 (tail | head) >= size)) 395 334 goto corrupted; 396 335 ··· 419 358 * DW2+: action data 420 359 */ 421 360 header = (len << GUC_CT_MSG_LEN_SHIFT) | 422 - (GUC_CT_MSG_WRITE_FENCE_TO_DESC) | 423 - (want_response ? GUC_CT_MSG_SEND_STATUS : 0) | 361 + GUC_CT_MSG_SEND_STATUS | 424 362 (action[0] << GUC_CT_MSG_ACTION_SHIFT); 425 363 426 364 CT_DEBUG(ct, "writing %*ph %*ph %*ph\n", ··· 437 377 } 438 378 GEM_BUG_ON(tail > size); 439 379 380 + /* 381 + * make sure H2G buffer update and LRC tail update (if this triggering a 382 + * submission) are visible before updating the descriptor tail 383 + */ 384 + write_barrier(ct); 385 + 440 386 /* now update desc tail (back in bytes) */ 441 387 desc->tail = tail * 4; 442 388 return 0; ··· 452 386 desc->addr, desc->head, desc->tail, desc->size); 453 387 desc->is_in_error = 1; 454 388 return -EPIPE; 455 - } 456 - 457 - /** 458 - * wait_for_ctb_desc_update - Wait for the CT buffer descriptor update. 459 - * @desc: buffer descriptor 460 - * @fence: response fence 461 - * @status: placeholder for status 462 - * 463 - * Guc will update CT buffer descriptor with new fence and status 464 - * after processing the command identified by the fence. Wait for 465 - * specified fence and then read from the descriptor status of the 466 - * command. 467 - * 468 - * Return: 469 - * * 0 response received (status is valid) 470 - * * -ETIMEDOUT no response within hardcoded timeout 471 - * * -EPROTO no response, CT buffer is in error 472 - */ 473 - static int wait_for_ctb_desc_update(struct guc_ct_buffer_desc *desc, 474 - u32 fence, 475 - u32 *status) 476 - { 477 - int err; 478 - 479 - /* 480 - * Fast commands should complete in less than 10us, so sample quickly 481 - * up to that length of time, then switch to a slower sleep-wait loop. 482 - * No GuC command should ever take longer than 10ms. 483 - */ 484 - #define done (READ_ONCE(desc->fence) == fence) 485 - err = wait_for_us(done, 10); 486 - if (err) 487 - err = wait_for(done, 10); 488 - #undef done 489 - 490 - if (unlikely(err)) { 491 - DRM_ERROR("CT: fence %u failed; reported fence=%u\n", 492 - fence, desc->fence); 493 - 494 - if (WARN_ON(desc->is_in_error)) { 495 - /* Something went wrong with the messaging, try to reset 496 - * the buffer and hope for the best 497 - */ 498 - guc_ct_buffer_desc_reset(desc); 499 - err = -EPROTO; 500 - } 501 - } 502 - 503 - *status = desc->status; 504 - return err; 505 389 } 506 390 507 391 /** ··· 497 481 u32 response_buf_size, 498 482 u32 *status) 499 483 { 500 - struct intel_guc_ct_buffer *ctb = &ct->ctbs[CTB_SEND]; 501 - struct guc_ct_buffer_desc *desc = ctb->desc; 502 484 struct ct_request request; 503 485 unsigned long flags; 504 486 u32 fence; ··· 507 493 GEM_BUG_ON(len & ~GUC_CT_MSG_LEN_MASK); 508 494 GEM_BUG_ON(!response_buf && response_buf_size); 509 495 496 + spin_lock_irqsave(&ct->ctbs.send.lock, flags); 497 + 510 498 fence = ct_get_next_fence(ct); 511 499 request.fence = fence; 512 500 request.status = 0; 513 501 request.response_len = response_buf_size; 514 502 request.response_buf = response_buf; 515 503 516 - spin_lock_irqsave(&ct->requests.lock, flags); 504 + spin_lock(&ct->requests.lock); 517 505 list_add_tail(&request.link, &ct->requests.pending); 518 - spin_unlock_irqrestore(&ct->requests.lock, flags); 506 + spin_unlock(&ct->requests.lock); 519 507 520 - err = ct_write(ct, action, len, fence, !!response_buf); 508 + err = ct_write(ct, action, len, fence); 509 + 510 + spin_unlock_irqrestore(&ct->ctbs.send.lock, flags); 511 + 521 512 if (unlikely(err)) 522 513 goto unlink; 523 514 524 515 intel_guc_notify(ct_to_guc(ct)); 525 516 526 - if (response_buf) 527 - err = wait_for_ct_request_update(&request, status); 528 - else 529 - err = wait_for_ctb_desc_update(desc, fence, status); 517 + err = wait_for_ct_request_update(&request, status); 530 518 if (unlikely(err)) 531 519 goto unlink; 532 520 ··· 563 547 int intel_guc_ct_send(struct intel_guc_ct *ct, const u32 *action, u32 len, 564 548 u32 *response_buf, u32 response_buf_size) 565 549 { 566 - struct intel_guc *guc = ct_to_guc(ct); 567 550 u32 status = ~0; /* undefined */ 568 551 int ret; 569 552 ··· 570 555 WARN(1, "Unexpected send: action=%#x\n", *action); 571 556 return -ENODEV; 572 557 } 573 - 574 - mutex_lock(&guc->send_mutex); 575 558 576 559 ret = ct_send(ct, action, len, response_buf, response_buf_size, &status); 577 560 if (unlikely(ret < 0)) { ··· 580 567 action[0], ret, ret); 581 568 } 582 569 583 - mutex_unlock(&guc->send_mutex); 584 570 return ret; 585 571 } 586 572 ··· 598 586 return !!(header & GUC_CT_MSG_IS_RESPONSE); 599 587 } 600 588 601 - static int ct_read(struct intel_guc_ct *ct, u32 *data) 589 + static struct ct_incoming_msg *ct_alloc_msg(u32 num_dwords) 602 590 { 603 - struct intel_guc_ct_buffer *ctb = &ct->ctbs[CTB_RECV]; 591 + struct ct_incoming_msg *msg; 592 + 593 + msg = kmalloc(sizeof(*msg) + sizeof(u32) * num_dwords, GFP_ATOMIC); 594 + if (msg) 595 + msg->size = num_dwords; 596 + return msg; 597 + } 598 + 599 + static void ct_free_msg(struct ct_incoming_msg *msg) 600 + { 601 + kfree(msg); 602 + } 603 + 604 + /* 605 + * Return: number available remaining dwords to read (0 if empty) 606 + * or a negative error code on failure 607 + */ 608 + static int ct_read(struct intel_guc_ct *ct, struct ct_incoming_msg **msg) 609 + { 610 + struct intel_guc_ct_buffer *ctb = &ct->ctbs.recv; 604 611 struct guc_ct_buffer_desc *desc = ctb->desc; 605 612 u32 head = desc->head; 606 613 u32 tail = desc->tail; 607 - u32 size = desc->size; 614 + u32 size = ctb->size; 608 615 u32 *cmds = ctb->cmds; 609 616 s32 available; 610 617 unsigned int len; 611 618 unsigned int i; 619 + u32 header; 612 620 613 621 if (unlikely(desc->is_in_error)) 614 622 return -EPIPE; 615 623 616 - if (unlikely(!IS_ALIGNED(head | tail | size, 4) || 624 + if (unlikely(!IS_ALIGNED(head | tail, 4) || 617 625 (tail | head) >= size)) 618 626 goto corrupted; 619 627 ··· 644 612 645 613 /* tail == head condition indicates empty */ 646 614 available = tail - head; 647 - if (unlikely(available == 0)) 648 - return -ENODATA; 615 + if (unlikely(available == 0)) { 616 + *msg = NULL; 617 + return 0; 618 + } 649 619 650 620 /* beware of buffer wrap case */ 651 621 if (unlikely(available < 0)) ··· 655 621 CT_DEBUG(ct, "available %d (%u:%u)\n", available, head, tail); 656 622 GEM_BUG_ON(available < 0); 657 623 658 - data[0] = cmds[head]; 624 + header = cmds[head]; 659 625 head = (head + 1) % size; 660 626 661 627 /* message len with header */ 662 - len = ct_header_get_len(data[0]) + 1; 628 + len = ct_header_get_len(header) + 1; 663 629 if (unlikely(len > (u32)available)) { 664 630 CT_ERROR(ct, "Incomplete message %*ph %*ph %*ph\n", 665 - 4, data, 631 + 4, &header, 666 632 4 * (head + available - 1 > size ? 667 633 size - head : available - 1), &cmds[head], 668 634 4 * (head + available - 1 > size ? ··· 670 636 goto corrupted; 671 637 } 672 638 639 + *msg = ct_alloc_msg(len); 640 + if (!*msg) { 641 + CT_ERROR(ct, "No memory for message %*ph %*ph %*ph\n", 642 + 4, &header, 643 + 4 * (head + available - 1 > size ? 644 + size - head : available - 1), &cmds[head], 645 + 4 * (head + available - 1 > size ? 646 + available - 1 - size + head : 0), &cmds[0]); 647 + return available; 648 + } 649 + 650 + (*msg)->msg[0] = header; 651 + 673 652 for (i = 1; i < len; i++) { 674 - data[i] = cmds[head]; 653 + (*msg)->msg[i] = cmds[head]; 675 654 head = (head + 1) % size; 676 655 } 677 - CT_DEBUG(ct, "received %*ph\n", 4 * len, data); 656 + CT_DEBUG(ct, "received %*ph\n", 4 * len, (*msg)->msg); 678 657 679 658 desc->head = head * 4; 680 - return 0; 659 + return available - len; 681 660 682 661 corrupted: 683 662 CT_ERROR(ct, "Corrupted descriptor addr=%#x head=%u tail=%u size=%u\n", ··· 717 670 * ^-----------------------len-----------------------^ 718 671 */ 719 672 720 - static int ct_handle_response(struct intel_guc_ct *ct, const u32 *msg) 673 + static int ct_handle_response(struct intel_guc_ct *ct, struct ct_incoming_msg *response) 721 674 { 722 - u32 header = msg[0]; 675 + u32 header = response->msg[0]; 723 676 u32 len = ct_header_get_len(header); 724 - u32 msgsize = (len + 1) * sizeof(u32); /* msg size in bytes w/header */ 725 677 u32 fence; 726 678 u32 status; 727 679 u32 datalen; 728 680 struct ct_request *req; 681 + unsigned long flags; 729 682 bool found = false; 683 + int err = 0; 730 684 731 685 GEM_BUG_ON(!ct_header_is_response(header)); 732 - GEM_BUG_ON(!in_irq()); 733 686 734 687 /* Response payload shall at least include fence and status */ 735 688 if (unlikely(len < 2)) { 736 - CT_ERROR(ct, "Corrupted response %*ph\n", msgsize, msg); 689 + CT_ERROR(ct, "Corrupted response (len %u)\n", len); 737 690 return -EPROTO; 738 691 } 739 692 740 - fence = msg[1]; 741 - status = msg[2]; 693 + fence = response->msg[1]; 694 + status = response->msg[2]; 742 695 datalen = len - 2; 743 696 744 697 /* Format of the status follows RESPONSE message */ 745 698 if (unlikely(!INTEL_GUC_MSG_IS_RESPONSE(status))) { 746 - CT_ERROR(ct, "Corrupted response %*ph\n", msgsize, msg); 699 + CT_ERROR(ct, "Corrupted response (status %#x)\n", status); 747 700 return -EPROTO; 748 701 } 749 702 750 703 CT_DEBUG(ct, "response fence %u status %#x\n", fence, status); 751 704 752 - spin_lock(&ct->requests.lock); 705 + spin_lock_irqsave(&ct->requests.lock, flags); 753 706 list_for_each_entry(req, &ct->requests.pending, link) { 754 707 if (unlikely(fence != req->fence)) { 755 708 CT_DEBUG(ct, "request %u awaits response\n", ··· 757 710 continue; 758 711 } 759 712 if (unlikely(datalen > req->response_len)) { 760 - CT_ERROR(ct, "Response for %u is too long %*ph\n", 761 - req->fence, msgsize, msg); 762 - datalen = 0; 713 + CT_ERROR(ct, "Response %u too long (datalen %u > %u)\n", 714 + req->fence, datalen, req->response_len); 715 + datalen = min(datalen, req->response_len); 716 + err = -EMSGSIZE; 763 717 } 764 718 if (datalen) 765 - memcpy(req->response_buf, msg + 3, 4 * datalen); 719 + memcpy(req->response_buf, response->msg + 3, 4 * datalen); 766 720 req->response_len = datalen; 767 721 WRITE_ONCE(req->status, status); 768 722 found = true; 769 723 break; 770 724 } 771 - spin_unlock(&ct->requests.lock); 725 + spin_unlock_irqrestore(&ct->requests.lock, flags); 772 726 773 - if (!found) 774 - CT_ERROR(ct, "Unsolicited response %*ph\n", msgsize, msg); 727 + if (!found) { 728 + CT_ERROR(ct, "Unsolicited response (fence %u)\n", fence); 729 + return -ENOKEY; 730 + } 731 + 732 + if (unlikely(err)) 733 + return err; 734 + 735 + ct_free_msg(response); 775 736 return 0; 776 737 } 777 738 778 - static void ct_process_request(struct intel_guc_ct *ct, 779 - u32 action, u32 len, const u32 *payload) 739 + static int ct_process_request(struct intel_guc_ct *ct, struct ct_incoming_msg *request) 780 740 { 781 741 struct intel_guc *guc = ct_to_guc(ct); 742 + u32 header, action, len; 743 + const u32 *payload; 782 744 int ret; 745 + 746 + header = request->msg[0]; 747 + payload = &request->msg[1]; 748 + action = ct_header_get_action(header); 749 + len = ct_header_get_len(header); 783 750 784 751 CT_DEBUG(ct, "request %x %*ph\n", action, 4 * len, payload); 785 752 786 753 switch (action) { 787 754 case INTEL_GUC_ACTION_DEFAULT: 788 755 ret = intel_guc_to_host_process_recv_msg(guc, payload, len); 789 - if (unlikely(ret)) 790 - goto fail_unexpected; 791 756 break; 792 - 793 757 default: 794 - fail_unexpected: 795 - CT_ERROR(ct, "Unexpected request %x %*ph\n", 796 - action, 4 * len, payload); 758 + ret = -EOPNOTSUPP; 797 759 break; 798 760 } 761 + 762 + if (unlikely(ret)) { 763 + CT_ERROR(ct, "Failed to process request %04x (%pe)\n", 764 + action, ERR_PTR(ret)); 765 + return ret; 766 + } 767 + 768 + ct_free_msg(request); 769 + return 0; 799 770 } 800 771 801 772 static bool ct_process_incoming_requests(struct intel_guc_ct *ct) 802 773 { 803 774 unsigned long flags; 804 - struct ct_incoming_request *request; 805 - u32 header; 806 - u32 *payload; 775 + struct ct_incoming_msg *request; 807 776 bool done; 777 + int err; 808 778 809 779 spin_lock_irqsave(&ct->requests.lock, flags); 810 780 request = list_first_entry_or_null(&ct->requests.incoming, 811 - struct ct_incoming_request, link); 781 + struct ct_incoming_msg, link); 812 782 if (request) 813 783 list_del(&request->link); 814 784 done = !!list_empty(&ct->requests.incoming); ··· 834 770 if (!request) 835 771 return true; 836 772 837 - header = request->msg[0]; 838 - payload = &request->msg[1]; 839 - ct_process_request(ct, 840 - ct_header_get_action(header), 841 - ct_header_get_len(header), 842 - payload); 773 + err = ct_process_request(ct, request); 774 + if (unlikely(err)) { 775 + CT_ERROR(ct, "Failed to process CT message (%pe) %*ph\n", 776 + ERR_PTR(err), 4 * request->size, request->msg); 777 + ct_free_msg(request); 778 + } 843 779 844 - kfree(request); 845 780 return done; 846 781 } 847 782 ··· 873 810 * ^-----------------------len-----------------------^ 874 811 */ 875 812 876 - static int ct_handle_request(struct intel_guc_ct *ct, const u32 *msg) 813 + static int ct_handle_request(struct intel_guc_ct *ct, struct ct_incoming_msg *request) 877 814 { 878 - u32 header = msg[0]; 879 - u32 len = ct_header_get_len(header); 880 - u32 msgsize = (len + 1) * sizeof(u32); /* msg size in bytes w/header */ 881 - struct ct_incoming_request *request; 882 815 unsigned long flags; 883 816 884 - GEM_BUG_ON(ct_header_is_response(header)); 885 - 886 - request = kmalloc(sizeof(*request) + msgsize, GFP_ATOMIC); 887 - if (unlikely(!request)) { 888 - CT_ERROR(ct, "Dropping request %*ph\n", msgsize, msg); 889 - return 0; /* XXX: -ENOMEM ? */ 890 - } 891 - memcpy(request->msg, msg, msgsize); 817 + GEM_BUG_ON(ct_header_is_response(request->msg[0])); 892 818 893 819 spin_lock_irqsave(&ct->requests.lock, flags); 894 820 list_add_tail(&request->link, &ct->requests.incoming); ··· 887 835 return 0; 888 836 } 889 837 838 + static void ct_handle_msg(struct intel_guc_ct *ct, struct ct_incoming_msg *msg) 839 + { 840 + u32 header = msg->msg[0]; 841 + int err; 842 + 843 + if (ct_header_is_response(header)) 844 + err = ct_handle_response(ct, msg); 845 + else 846 + err = ct_handle_request(ct, msg); 847 + 848 + if (unlikely(err)) { 849 + CT_ERROR(ct, "Failed to process CT message (%pe) %*ph\n", 850 + ERR_PTR(err), 4 * msg->size, msg->msg); 851 + ct_free_msg(msg); 852 + } 853 + } 854 + 855 + /* 856 + * Return: number available remaining dwords to read (0 if empty) 857 + * or a negative error code on failure 858 + */ 859 + static int ct_receive(struct intel_guc_ct *ct) 860 + { 861 + struct ct_incoming_msg *msg = NULL; 862 + unsigned long flags; 863 + int ret; 864 + 865 + spin_lock_irqsave(&ct->ctbs.recv.lock, flags); 866 + ret = ct_read(ct, &msg); 867 + spin_unlock_irqrestore(&ct->ctbs.recv.lock, flags); 868 + if (ret < 0) 869 + return ret; 870 + 871 + if (msg) 872 + ct_handle_msg(ct, msg); 873 + 874 + return ret; 875 + } 876 + 877 + static void ct_try_receive_message(struct intel_guc_ct *ct) 878 + { 879 + int ret; 880 + 881 + if (GEM_WARN_ON(!ct->enabled)) 882 + return; 883 + 884 + ret = ct_receive(ct); 885 + if (ret > 0) 886 + tasklet_hi_schedule(&ct->receive_tasklet); 887 + } 888 + 889 + static void ct_receive_tasklet_func(struct tasklet_struct *t) 890 + { 891 + struct intel_guc_ct *ct = from_tasklet(ct, t, receive_tasklet); 892 + 893 + ct_try_receive_message(ct); 894 + } 895 + 890 896 /* 891 897 * When we're communicating with the GuC over CT, GuC uses events 892 898 * to notify us about new messages being posted on the RECV buffer. 893 899 */ 894 900 void intel_guc_ct_event_handler(struct intel_guc_ct *ct) 895 901 { 896 - u32 msg[GUC_CT_MSG_LEN_MASK + 1]; /* one extra dw for the header */ 897 - int err = 0; 898 - 899 902 if (unlikely(!ct->enabled)) { 900 903 WARN(1, "Unexpected GuC event received while CT disabled!\n"); 901 904 return; 902 905 } 903 906 904 - do { 905 - err = ct_read(ct, msg); 906 - if (err) 907 - break; 908 - 909 - if (ct_header_is_response(msg[0])) 910 - err = ct_handle_response(ct, msg); 911 - else 912 - err = ct_handle_request(ct, msg); 913 - } while (!err); 907 + ct_try_receive_message(ct); 914 908 }
+12 -2
drivers/gpu/drm/i915/gt/uc/intel_guc_ct.h
··· 6 6 #ifndef _INTEL_GUC_CT_H_ 7 7 #define _INTEL_GUC_CT_H_ 8 8 9 + #include <linux/interrupt.h> 9 10 #include <linux/spinlock.h> 10 11 #include <linux/workqueue.h> 11 12 ··· 28 27 * record (command transport buffer descriptor) and the actual buffer which 29 28 * holds the commands. 30 29 * 30 + * @lock: protects access to the commands buffer and buffer descriptor 31 31 * @desc: pointer to the buffer descriptor 32 32 * @cmds: pointer to the commands buffer 33 + * @size: size of the commands buffer 33 34 */ 34 35 struct intel_guc_ct_buffer { 36 + spinlock_t lock; 35 37 struct guc_ct_buffer_desc *desc; 36 38 u32 *cmds; 39 + u32 size; 37 40 }; 38 41 39 42 ··· 50 45 struct i915_vma *vma; 51 46 bool enabled; 52 47 53 - /* buffers for sending(0) and receiving(1) commands */ 54 - struct intel_guc_ct_buffer ctbs[2]; 48 + /* buffers for sending and receiving commands */ 49 + struct { 50 + struct intel_guc_ct_buffer send; 51 + struct intel_guc_ct_buffer recv; 52 + } ctbs; 53 + 54 + struct tasklet_struct receive_tasklet; 55 55 56 56 struct { 57 57 u32 last_fence; /* last fence used to send request */
+1 -1
drivers/gpu/drm/i915/gt/uc/intel_guc_fw.c
··· 30 30 else 31 31 intel_uncore_write(uncore, GEN9_GT_PM_CONFIG, GT_DOORBELL_ENABLE); 32 32 33 - if (IS_GEN(uncore->i915, 9)) { 33 + if (GRAPHICS_VER(uncore->i915) == 9) { 34 34 /* DOP Clock Gating Enable for GuC clocks */ 35 35 intel_uncore_rmw(uncore, GEN7_MISCCPCTL, 36 36 0, GEN8_DOP_CLOCK_GATE_GUC_ENABLE);
+32 -201
drivers/gpu/drm/i915/gt/uc/intel_guc_fwif.h
··· 9 9 #include <linux/bits.h> 10 10 #include <linux/compiler.h> 11 11 #include <linux/types.h> 12 + #include "gt/intel_engine_types.h" 13 + 14 + #include "abi/guc_actions_abi.h" 15 + #include "abi/guc_errors_abi.h" 16 + #include "abi/guc_communication_mmio_abi.h" 17 + #include "abi/guc_communication_ctb_abi.h" 18 + #include "abi/guc_messages_abi.h" 12 19 13 20 #define GUC_CLIENT_PRIORITY_KMD_HIGH 0 14 21 #define GUC_CLIENT_PRIORITY_HIGH 1 ··· 33 26 #define GUC_VIDEO_ENGINE2 4 34 27 #define GUC_MAX_ENGINES_NUM (GUC_VIDEO_ENGINE2 + 1) 35 28 29 + #define GUC_RENDER_CLASS 0 30 + #define GUC_VIDEO_CLASS 1 31 + #define GUC_VIDEOENHANCE_CLASS 2 32 + #define GUC_BLITTER_CLASS 3 33 + #define GUC_RESERVED_CLASS 4 34 + #define GUC_LAST_ENGINE_CLASS GUC_RESERVED_CLASS 36 35 #define GUC_MAX_ENGINE_CLASSES 16 37 36 #define GUC_MAX_INSTANCES_PER_CLASS 32 38 37 ··· 136 123 #define GUC_ID_TO_ENGINE_INSTANCE(guc_id) \ 137 124 (((guc_id) & GUC_ENGINE_INSTANCE_MASK) >> GUC_ENGINE_INSTANCE_SHIFT) 138 125 126 + static inline u8 engine_class_to_guc_class(u8 class) 127 + { 128 + BUILD_BUG_ON(GUC_RENDER_CLASS != RENDER_CLASS); 129 + BUILD_BUG_ON(GUC_BLITTER_CLASS != COPY_ENGINE_CLASS); 130 + BUILD_BUG_ON(GUC_VIDEO_CLASS != VIDEO_DECODE_CLASS); 131 + BUILD_BUG_ON(GUC_VIDEOENHANCE_CLASS != VIDEO_ENHANCEMENT_CLASS); 132 + GEM_BUG_ON(class > MAX_ENGINE_CLASS || class == OTHER_CLASS); 133 + 134 + return class; 135 + } 136 + 137 + static inline u8 guc_class_to_engine_class(u8 guc_class) 138 + { 139 + GEM_BUG_ON(guc_class > GUC_LAST_ENGINE_CLASS); 140 + GEM_BUG_ON(guc_class == GUC_RESERVED_CLASS); 141 + 142 + return guc_class; 143 + } 144 + 139 145 /* Work item for submitting workloads into work queue of GuC. */ 140 146 struct guc_wq_item { 141 147 u32 header; ··· 238 206 239 207 u64 desc_private; 240 208 } __packed; 241 - 242 - /** 243 - * DOC: CTB based communication 244 - * 245 - * The CTB (command transport buffer) communication between Host and GuC 246 - * is based on u32 data stream written to the shared buffer. One buffer can 247 - * be used to transmit data only in one direction (one-directional channel). 248 - * 249 - * Current status of the each buffer is stored in the buffer descriptor. 250 - * Buffer descriptor holds tail and head fields that represents active data 251 - * stream. The tail field is updated by the data producer (sender), and head 252 - * field is updated by the data consumer (receiver):: 253 - * 254 - * +------------+ 255 - * | DESCRIPTOR | +=================+============+========+ 256 - * +============+ | | MESSAGE(s) | | 257 - * | address |--------->+=================+============+========+ 258 - * +------------+ 259 - * | head | ^-----head--------^ 260 - * +------------+ 261 - * | tail | ^---------tail-----------------^ 262 - * +------------+ 263 - * | size | ^---------------size--------------------^ 264 - * +------------+ 265 - * 266 - * Each message in data stream starts with the single u32 treated as a header, 267 - * followed by optional set of u32 data that makes message specific payload:: 268 - * 269 - * +------------+---------+---------+---------+ 270 - * | MESSAGE | 271 - * +------------+---------+---------+---------+ 272 - * | msg[0] | [1] | ... | [n-1] | 273 - * +------------+---------+---------+---------+ 274 - * | MESSAGE | MESSAGE PAYLOAD | 275 - * + HEADER +---------+---------+---------+ 276 - * | | 0 | ... | n | 277 - * +======+=====+=========+=========+=========+ 278 - * | 31:16| code| | | | 279 - * +------+-----+ | | | 280 - * | 15:5|flags| | | | 281 - * +------+-----+ | | | 282 - * | 4:0| len| | | | 283 - * +------+-----+---------+---------+---------+ 284 - * 285 - * ^-------------len-------------^ 286 - * 287 - * The message header consists of: 288 - * 289 - * - **len**, indicates length of the message payload (in u32) 290 - * - **code**, indicates message code 291 - * - **flags**, holds various bits to control message handling 292 - */ 293 - 294 - /* 295 - * Describes single command transport buffer. 296 - * Used by both guc-master and clients. 297 - */ 298 - struct guc_ct_buffer_desc { 299 - u32 addr; /* gfx address */ 300 - u64 host_private; /* host private data */ 301 - u32 size; /* size in bytes */ 302 - u32 head; /* offset updated by GuC*/ 303 - u32 tail; /* offset updated by owner */ 304 - u32 is_in_error; /* error indicator */ 305 - u32 fence; /* fence updated by GuC */ 306 - u32 status; /* status updated by GuC */ 307 - u32 owner; /* id of the channel owner */ 308 - u32 owner_sub_id; /* owner-defined field for extra tracking */ 309 - u32 reserved[5]; 310 - } __packed; 311 - 312 - /* Type of command transport buffer */ 313 - #define INTEL_GUC_CT_BUFFER_TYPE_SEND 0x0u 314 - #define INTEL_GUC_CT_BUFFER_TYPE_RECV 0x1u 315 - 316 - /* 317 - * Definition of the command transport message header (DW0) 318 - * 319 - * bit[4..0] message len (in dwords) 320 - * bit[7..5] reserved 321 - * bit[8] response (G2H only) 322 - * bit[8] write fence to desc (H2G only) 323 - * bit[9] write status to H2G buff (H2G only) 324 - * bit[10] send status back via G2H (H2G only) 325 - * bit[15..11] reserved 326 - * bit[31..16] action code 327 - */ 328 - #define GUC_CT_MSG_LEN_SHIFT 0 329 - #define GUC_CT_MSG_LEN_MASK 0x1F 330 - #define GUC_CT_MSG_IS_RESPONSE (1 << 8) 331 - #define GUC_CT_MSG_WRITE_FENCE_TO_DESC (1 << 8) 332 - #define GUC_CT_MSG_WRITE_STATUS_TO_BUFF (1 << 9) 333 - #define GUC_CT_MSG_SEND_STATUS (1 << 10) 334 - #define GUC_CT_MSG_ACTION_SHIFT 16 335 - #define GUC_CT_MSG_ACTION_MASK 0xFFFF 336 - 337 - #define GUC_FORCEWAKE_RENDER (1 << 0) 338 - #define GUC_FORCEWAKE_MEDIA (1 << 1) 339 209 340 210 #define GUC_POWER_UNSPECIFIED 0 341 211 #define GUC_POWER_D0 1 ··· 414 480 struct guc_ctx_report preempt_ctx_report[GUC_MAX_ENGINES_NUM]; 415 481 } __packed; 416 482 417 - /** 418 - * DOC: MMIO based communication 419 - * 420 - * The MMIO based communication between Host and GuC uses software scratch 421 - * registers, where first register holds data treated as message header, 422 - * and other registers are used to hold message payload. 423 - * 424 - * For Gen9+, GuC uses software scratch registers 0xC180-0xC1B8, 425 - * but no H2G command takes more than 8 parameters and the GuC FW 426 - * itself uses an 8-element array to store the H2G message. 427 - * 428 - * +-----------+---------+---------+---------+ 429 - * | MMIO[0] | MMIO[1] | ... | MMIO[n] | 430 - * +-----------+---------+---------+---------+ 431 - * | header | optional payload | 432 - * +======+====+=========+=========+=========+ 433 - * | 31:28|type| | | | 434 - * +------+----+ | | | 435 - * | 27:16|data| | | | 436 - * +------+----+ | | | 437 - * | 15:0|code| | | | 438 - * +------+----+---------+---------+---------+ 439 - * 440 - * The message header consists of: 441 - * 442 - * - **type**, indicates message type 443 - * - **code**, indicates message code, is specific for **type** 444 - * - **data**, indicates message data, optional, depends on **code** 445 - * 446 - * The following message **types** are supported: 447 - * 448 - * - **REQUEST**, indicates Host-to-GuC request, requested GuC action code 449 - * must be priovided in **code** field. Optional action specific parameters 450 - * can be provided in remaining payload registers or **data** field. 451 - * 452 - * - **RESPONSE**, indicates GuC-to-Host response from earlier GuC request, 453 - * action response status will be provided in **code** field. Optional 454 - * response data can be returned in remaining payload registers or **data** 455 - * field. 456 - */ 457 - 458 - #define GUC_MAX_MMIO_MSG_LEN 8 459 - 460 - #define INTEL_GUC_MSG_TYPE_SHIFT 28 461 - #define INTEL_GUC_MSG_TYPE_MASK (0xF << INTEL_GUC_MSG_TYPE_SHIFT) 462 - #define INTEL_GUC_MSG_DATA_SHIFT 16 463 - #define INTEL_GUC_MSG_DATA_MASK (0xFFF << INTEL_GUC_MSG_DATA_SHIFT) 464 - #define INTEL_GUC_MSG_CODE_SHIFT 0 465 - #define INTEL_GUC_MSG_CODE_MASK (0xFFFF << INTEL_GUC_MSG_CODE_SHIFT) 466 - 467 483 #define __INTEL_GUC_MSG_GET(T, m) \ 468 484 (((m) & INTEL_GUC_MSG_ ## T ## _MASK) >> INTEL_GUC_MSG_ ## T ## _SHIFT) 469 485 #define INTEL_GUC_MSG_TO_TYPE(m) __INTEL_GUC_MSG_GET(TYPE, m) 470 486 #define INTEL_GUC_MSG_TO_DATA(m) __INTEL_GUC_MSG_GET(DATA, m) 471 487 #define INTEL_GUC_MSG_TO_CODE(m) __INTEL_GUC_MSG_GET(CODE, m) 472 488 473 - enum intel_guc_msg_type { 474 - INTEL_GUC_MSG_TYPE_REQUEST = 0x0, 475 - INTEL_GUC_MSG_TYPE_RESPONSE = 0xF, 476 - }; 477 - 478 489 #define __INTEL_GUC_MSG_TYPE_IS(T, m) \ 479 490 (INTEL_GUC_MSG_TO_TYPE(m) == INTEL_GUC_MSG_TYPE_ ## T) 480 491 #define INTEL_GUC_MSG_IS_REQUEST(m) __INTEL_GUC_MSG_TYPE_IS(REQUEST, m) 481 492 #define INTEL_GUC_MSG_IS_RESPONSE(m) __INTEL_GUC_MSG_TYPE_IS(RESPONSE, m) 482 - 483 - enum intel_guc_action { 484 - INTEL_GUC_ACTION_DEFAULT = 0x0, 485 - INTEL_GUC_ACTION_REQUEST_PREEMPTION = 0x2, 486 - INTEL_GUC_ACTION_REQUEST_ENGINE_RESET = 0x3, 487 - INTEL_GUC_ACTION_ALLOCATE_DOORBELL = 0x10, 488 - INTEL_GUC_ACTION_DEALLOCATE_DOORBELL = 0x20, 489 - INTEL_GUC_ACTION_LOG_BUFFER_FILE_FLUSH_COMPLETE = 0x30, 490 - INTEL_GUC_ACTION_UK_LOG_ENABLE_LOGGING = 0x40, 491 - INTEL_GUC_ACTION_FORCE_LOG_BUFFER_FLUSH = 0x302, 492 - INTEL_GUC_ACTION_ENTER_S_STATE = 0x501, 493 - INTEL_GUC_ACTION_EXIT_S_STATE = 0x502, 494 - INTEL_GUC_ACTION_SLPC_REQUEST = 0x3003, 495 - INTEL_GUC_ACTION_SAMPLE_FORCEWAKE = 0x3005, 496 - INTEL_GUC_ACTION_AUTHENTICATE_HUC = 0x4000, 497 - INTEL_GUC_ACTION_REGISTER_COMMAND_TRANSPORT_BUFFER = 0x4505, 498 - INTEL_GUC_ACTION_DEREGISTER_COMMAND_TRANSPORT_BUFFER = 0x4506, 499 - INTEL_GUC_ACTION_LIMIT 500 - }; 501 - 502 - enum intel_guc_preempt_options { 503 - INTEL_GUC_PREEMPT_OPTION_DROP_WORK_Q = 0x4, 504 - INTEL_GUC_PREEMPT_OPTION_DROP_SUBMIT_Q = 0x8, 505 - }; 506 - 507 - enum intel_guc_report_status { 508 - INTEL_GUC_REPORT_STATUS_UNKNOWN = 0x0, 509 - INTEL_GUC_REPORT_STATUS_ACKED = 0x1, 510 - INTEL_GUC_REPORT_STATUS_ERROR = 0x2, 511 - INTEL_GUC_REPORT_STATUS_COMPLETE = 0x4, 512 - }; 513 - 514 - enum intel_guc_sleep_state_status { 515 - INTEL_GUC_SLEEP_STATE_SUCCESS = 0x1, 516 - INTEL_GUC_SLEEP_STATE_PREEMPT_TO_IDLE_FAILED = 0x2, 517 - INTEL_GUC_SLEEP_STATE_ENGINE_RESET_FAILED = 0x3 518 - #define INTEL_GUC_SLEEP_STATE_INVALID_MASK 0x80000000 519 - }; 520 - 521 - #define GUC_LOG_CONTROL_LOGGING_ENABLED (1 << 0) 522 - #define GUC_LOG_CONTROL_VERBOSITY_SHIFT 4 523 - #define GUC_LOG_CONTROL_VERBOSITY_MASK (0xF << GUC_LOG_CONTROL_VERBOSITY_SHIFT) 524 - #define GUC_LOG_CONTROL_DEFAULT_LOGGING (1 << 8) 525 - 526 - enum intel_guc_response_status { 527 - INTEL_GUC_RESPONSE_STATUS_SUCCESS = 0x0, 528 - INTEL_GUC_RESPONSE_STATUS_GENERIC_FAIL = 0xF000, 529 - }; 530 493 531 494 #define INTEL_GUC_MSG_IS_RESPONSE_SUCCESS(m) \ 532 495 (typecheck(u32, (m)) && \
+3 -34
drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c
··· 432 432 } 433 433 } 434 434 435 - static void guc_interrupts_capture(struct intel_gt *gt) 436 - { 437 - struct intel_uncore *uncore = gt->uncore; 438 - u32 irqs = GT_CONTEXT_SWITCH_INTERRUPT; 439 - u32 dmask = irqs << 16 | irqs; 440 - 441 - GEM_BUG_ON(INTEL_GEN(gt->i915) < 11); 442 - 443 - /* Don't handle the ctx switch interrupt in GuC submission mode */ 444 - intel_uncore_rmw(uncore, GEN11_RENDER_COPY_INTR_ENABLE, dmask, 0); 445 - intel_uncore_rmw(uncore, GEN11_VCS_VECS_INTR_ENABLE, dmask, 0); 446 - } 447 - 448 - static void guc_interrupts_release(struct intel_gt *gt) 449 - { 450 - struct intel_uncore *uncore = gt->uncore; 451 - u32 irqs = GT_CONTEXT_SWITCH_INTERRUPT; 452 - u32 dmask = irqs << 16 | irqs; 453 - 454 - GEM_BUG_ON(INTEL_GEN(gt->i915) < 11); 455 - 456 - /* Handle ctx switch interrupts again */ 457 - intel_uncore_rmw(uncore, GEN11_RENDER_COPY_INTR_ENABLE, 0, dmask); 458 - intel_uncore_rmw(uncore, GEN11_VCS_VECS_INTR_ENABLE, 0, dmask); 459 - } 460 - 461 435 static int guc_context_alloc(struct intel_context *ce) 462 436 { 463 437 return lrc_alloc(ce, ce->engine); ··· 622 648 engine->emit_flush = gen8_emit_flush_xcs; 623 649 engine->emit_init_breadcrumb = gen8_emit_init_breadcrumb; 624 650 engine->emit_fini_breadcrumb = gen8_emit_fini_breadcrumb_xcs; 625 - if (INTEL_GEN(engine->i915) >= 12) { 651 + if (GRAPHICS_VER(engine->i915) >= 12) { 626 652 engine->emit_fini_breadcrumb = gen12_emit_fini_breadcrumb_xcs; 627 653 engine->emit_flush = gen12_emit_flush_xcs; 628 654 } ··· 644 670 645 671 static void rcs_submission_override(struct intel_engine_cs *engine) 646 672 { 647 - switch (INTEL_GEN(engine->i915)) { 673 + switch (GRAPHICS_VER(engine->i915)) { 648 674 case 12: 649 675 engine->emit_flush = gen12_emit_flush_rcs; 650 676 engine->emit_fini_breadcrumb = gen12_emit_fini_breadcrumb_rcs; ··· 674 700 * The setup relies on several assumptions (e.g. irqs always enabled) 675 701 * that are only valid on gen11+ 676 702 */ 677 - GEM_BUG_ON(INTEL_GEN(i915) < 11); 703 + GEM_BUG_ON(GRAPHICS_VER(i915) < 11); 678 704 679 705 tasklet_setup(&engine->execlists.tasklet, guc_submission_tasklet); 680 706 ··· 696 722 void intel_guc_submission_enable(struct intel_guc *guc) 697 723 { 698 724 guc_stage_desc_init(guc); 699 - 700 - /* Take over from manual control of ELSP (execlists) */ 701 - guc_interrupts_capture(guc_to_gt(guc)); 702 725 } 703 726 704 727 void intel_guc_submission_disable(struct intel_guc *guc) ··· 705 734 GEM_BUG_ON(gt->awake); /* GT should be parked first */ 706 735 707 736 /* Note: By the time we're here, GuC may have already been reset */ 708 - 709 - guc_interrupts_release(gt); 710 737 711 738 guc_stage_desc_fini(guc); 712 739 }
+1 -1
drivers/gpu/drm/i915/gt/uc/intel_huc.c
··· 43 43 44 44 intel_uc_fw_init_early(&huc->fw, INTEL_UC_FW_TYPE_HUC); 45 45 46 - if (INTEL_GEN(i915) >= 11) { 46 + if (GRAPHICS_VER(i915) >= 11) { 47 47 huc->status.reg = GEN11_HUC_KERNEL_LOAD_INFO; 48 48 huc->status.mask = HUC_LOAD_SUCCESSFUL; 49 49 huc->status.value = HUC_LOAD_SUCCESSFUL;
+2 -12
drivers/gpu/drm/i915/gt/uc/intel_uc.c
··· 23 23 return; 24 24 25 25 /* Don't enable GuC/HuC on pre-Gen12 */ 26 - if (INTEL_GEN(i915) < 12) { 26 + if (GRAPHICS_VER(i915) < 12) { 27 27 i915->params.enable_guc = 0; 28 28 return; 29 29 } ··· 467 467 468 468 /* WaEnableuKernelHeaderValidFix:skl */ 469 469 /* WaEnableGuCBootHashCheckNotSet:skl,bxt,kbl */ 470 - if (IS_GEN(i915, 9)) 470 + if (GRAPHICS_VER(i915) == 9) 471 471 attempts = 3; 472 472 else 473 473 attempts = 1; ··· 502 502 503 503 intel_huc_auth(huc); 504 504 505 - ret = intel_guc_sample_forcewake(guc); 506 - if (ret) 507 - goto err_communication; 508 - 509 505 if (intel_uc_uses_guc_submission(uc)) 510 506 intel_guc_submission_enable(guc); 511 507 ··· 525 529 /* 526 530 * We've failed to load the firmware :( 527 531 */ 528 - err_communication: 529 - guc_disable_communication(guc); 530 532 err_log_capture: 531 533 __uc_capture_load_err_log(uc); 532 534 err_out: ··· 552 558 if (intel_uc_uses_guc_submission(uc)) 553 559 intel_guc_submission_disable(guc); 554 560 555 - if (guc_communication_enabled(guc)) 556 - guc_disable_communication(guc); 557 - 558 561 __uc_sanitize(uc); 559 562 } 560 563 ··· 568 577 if (!intel_guc_is_ready(guc)) 569 578 return; 570 579 571 - guc_disable_communication(guc); 572 580 __uc_sanitize(uc); 573 581 } 574 582
-435
drivers/gpu/drm/i915/i915_buddy.c
··· 1 - // SPDX-License-Identifier: MIT 2 - /* 3 - * Copyright © 2019 Intel Corporation 4 - */ 5 - 6 - #include <linux/kmemleak.h> 7 - #include <linux/slab.h> 8 - 9 - #include "i915_buddy.h" 10 - 11 - #include "i915_gem.h" 12 - #include "i915_globals.h" 13 - #include "i915_utils.h" 14 - 15 - static struct i915_global_block { 16 - struct i915_global base; 17 - struct kmem_cache *slab_blocks; 18 - } global; 19 - 20 - static void i915_global_buddy_shrink(void) 21 - { 22 - kmem_cache_shrink(global.slab_blocks); 23 - } 24 - 25 - static void i915_global_buddy_exit(void) 26 - { 27 - kmem_cache_destroy(global.slab_blocks); 28 - } 29 - 30 - static struct i915_global_block global = { { 31 - .shrink = i915_global_buddy_shrink, 32 - .exit = i915_global_buddy_exit, 33 - } }; 34 - 35 - int __init i915_global_buddy_init(void) 36 - { 37 - global.slab_blocks = KMEM_CACHE(i915_buddy_block, SLAB_HWCACHE_ALIGN); 38 - if (!global.slab_blocks) 39 - return -ENOMEM; 40 - 41 - i915_global_register(&global.base); 42 - return 0; 43 - } 44 - 45 - static struct i915_buddy_block *i915_block_alloc(struct i915_buddy_block *parent, 46 - unsigned int order, 47 - u64 offset) 48 - { 49 - struct i915_buddy_block *block; 50 - 51 - GEM_BUG_ON(order > I915_BUDDY_MAX_ORDER); 52 - 53 - block = kmem_cache_zalloc(global.slab_blocks, GFP_KERNEL); 54 - if (!block) 55 - return NULL; 56 - 57 - block->header = offset; 58 - block->header |= order; 59 - block->parent = parent; 60 - 61 - GEM_BUG_ON(block->header & I915_BUDDY_HEADER_UNUSED); 62 - return block; 63 - } 64 - 65 - static void i915_block_free(struct i915_buddy_block *block) 66 - { 67 - kmem_cache_free(global.slab_blocks, block); 68 - } 69 - 70 - static void mark_allocated(struct i915_buddy_block *block) 71 - { 72 - block->header &= ~I915_BUDDY_HEADER_STATE; 73 - block->header |= I915_BUDDY_ALLOCATED; 74 - 75 - list_del(&block->link); 76 - } 77 - 78 - static void mark_free(struct i915_buddy_mm *mm, 79 - struct i915_buddy_block *block) 80 - { 81 - block->header &= ~I915_BUDDY_HEADER_STATE; 82 - block->header |= I915_BUDDY_FREE; 83 - 84 - list_add(&block->link, 85 - &mm->free_list[i915_buddy_block_order(block)]); 86 - } 87 - 88 - static void mark_split(struct i915_buddy_block *block) 89 - { 90 - block->header &= ~I915_BUDDY_HEADER_STATE; 91 - block->header |= I915_BUDDY_SPLIT; 92 - 93 - list_del(&block->link); 94 - } 95 - 96 - int i915_buddy_init(struct i915_buddy_mm *mm, u64 size, u64 chunk_size) 97 - { 98 - unsigned int i; 99 - u64 offset; 100 - 101 - if (size < chunk_size) 102 - return -EINVAL; 103 - 104 - if (chunk_size < PAGE_SIZE) 105 - return -EINVAL; 106 - 107 - if (!is_power_of_2(chunk_size)) 108 - return -EINVAL; 109 - 110 - size = round_down(size, chunk_size); 111 - 112 - mm->size = size; 113 - mm->chunk_size = chunk_size; 114 - mm->max_order = ilog2(size) - ilog2(chunk_size); 115 - 116 - GEM_BUG_ON(mm->max_order > I915_BUDDY_MAX_ORDER); 117 - 118 - mm->free_list = kmalloc_array(mm->max_order + 1, 119 - sizeof(struct list_head), 120 - GFP_KERNEL); 121 - if (!mm->free_list) 122 - return -ENOMEM; 123 - 124 - for (i = 0; i <= mm->max_order; ++i) 125 - INIT_LIST_HEAD(&mm->free_list[i]); 126 - 127 - mm->n_roots = hweight64(size); 128 - 129 - mm->roots = kmalloc_array(mm->n_roots, 130 - sizeof(struct i915_buddy_block *), 131 - GFP_KERNEL); 132 - if (!mm->roots) 133 - goto out_free_list; 134 - 135 - offset = 0; 136 - i = 0; 137 - 138 - /* 139 - * Split into power-of-two blocks, in case we are given a size that is 140 - * not itself a power-of-two. 141 - */ 142 - do { 143 - struct i915_buddy_block *root; 144 - unsigned int order; 145 - u64 root_size; 146 - 147 - root_size = rounddown_pow_of_two(size); 148 - order = ilog2(root_size) - ilog2(chunk_size); 149 - 150 - root = i915_block_alloc(NULL, order, offset); 151 - if (!root) 152 - goto out_free_roots; 153 - 154 - mark_free(mm, root); 155 - 156 - GEM_BUG_ON(i > mm->max_order); 157 - GEM_BUG_ON(i915_buddy_block_size(mm, root) < chunk_size); 158 - 159 - mm->roots[i] = root; 160 - 161 - offset += root_size; 162 - size -= root_size; 163 - i++; 164 - } while (size); 165 - 166 - return 0; 167 - 168 - out_free_roots: 169 - while (i--) 170 - i915_block_free(mm->roots[i]); 171 - kfree(mm->roots); 172 - out_free_list: 173 - kfree(mm->free_list); 174 - return -ENOMEM; 175 - } 176 - 177 - void i915_buddy_fini(struct i915_buddy_mm *mm) 178 - { 179 - int i; 180 - 181 - for (i = 0; i < mm->n_roots; ++i) { 182 - GEM_WARN_ON(!i915_buddy_block_is_free(mm->roots[i])); 183 - i915_block_free(mm->roots[i]); 184 - } 185 - 186 - kfree(mm->roots); 187 - kfree(mm->free_list); 188 - } 189 - 190 - static int split_block(struct i915_buddy_mm *mm, 191 - struct i915_buddy_block *block) 192 - { 193 - unsigned int block_order = i915_buddy_block_order(block) - 1; 194 - u64 offset = i915_buddy_block_offset(block); 195 - 196 - GEM_BUG_ON(!i915_buddy_block_is_free(block)); 197 - GEM_BUG_ON(!i915_buddy_block_order(block)); 198 - 199 - block->left = i915_block_alloc(block, block_order, offset); 200 - if (!block->left) 201 - return -ENOMEM; 202 - 203 - block->right = i915_block_alloc(block, block_order, 204 - offset + (mm->chunk_size << block_order)); 205 - if (!block->right) { 206 - i915_block_free(block->left); 207 - return -ENOMEM; 208 - } 209 - 210 - mark_free(mm, block->left); 211 - mark_free(mm, block->right); 212 - 213 - mark_split(block); 214 - 215 - return 0; 216 - } 217 - 218 - static struct i915_buddy_block * 219 - get_buddy(struct i915_buddy_block *block) 220 - { 221 - struct i915_buddy_block *parent; 222 - 223 - parent = block->parent; 224 - if (!parent) 225 - return NULL; 226 - 227 - if (parent->left == block) 228 - return parent->right; 229 - 230 - return parent->left; 231 - } 232 - 233 - static void __i915_buddy_free(struct i915_buddy_mm *mm, 234 - struct i915_buddy_block *block) 235 - { 236 - struct i915_buddy_block *parent; 237 - 238 - while ((parent = block->parent)) { 239 - struct i915_buddy_block *buddy; 240 - 241 - buddy = get_buddy(block); 242 - 243 - if (!i915_buddy_block_is_free(buddy)) 244 - break; 245 - 246 - list_del(&buddy->link); 247 - 248 - i915_block_free(block); 249 - i915_block_free(buddy); 250 - 251 - block = parent; 252 - } 253 - 254 - mark_free(mm, block); 255 - } 256 - 257 - void i915_buddy_free(struct i915_buddy_mm *mm, 258 - struct i915_buddy_block *block) 259 - { 260 - GEM_BUG_ON(!i915_buddy_block_is_allocated(block)); 261 - __i915_buddy_free(mm, block); 262 - } 263 - 264 - void i915_buddy_free_list(struct i915_buddy_mm *mm, struct list_head *objects) 265 - { 266 - struct i915_buddy_block *block, *on; 267 - 268 - list_for_each_entry_safe(block, on, objects, link) { 269 - i915_buddy_free(mm, block); 270 - cond_resched(); 271 - } 272 - INIT_LIST_HEAD(objects); 273 - } 274 - 275 - /* 276 - * Allocate power-of-two block. The order value here translates to: 277 - * 278 - * 0 = 2^0 * mm->chunk_size 279 - * 1 = 2^1 * mm->chunk_size 280 - * 2 = 2^2 * mm->chunk_size 281 - * ... 282 - */ 283 - struct i915_buddy_block * 284 - i915_buddy_alloc(struct i915_buddy_mm *mm, unsigned int order) 285 - { 286 - struct i915_buddy_block *block = NULL; 287 - unsigned int i; 288 - int err; 289 - 290 - for (i = order; i <= mm->max_order; ++i) { 291 - block = list_first_entry_or_null(&mm->free_list[i], 292 - struct i915_buddy_block, 293 - link); 294 - if (block) 295 - break; 296 - } 297 - 298 - if (!block) 299 - return ERR_PTR(-ENOSPC); 300 - 301 - GEM_BUG_ON(!i915_buddy_block_is_free(block)); 302 - 303 - while (i != order) { 304 - err = split_block(mm, block); 305 - if (unlikely(err)) 306 - goto out_free; 307 - 308 - /* Go low */ 309 - block = block->left; 310 - i--; 311 - } 312 - 313 - mark_allocated(block); 314 - kmemleak_update_trace(block); 315 - return block; 316 - 317 - out_free: 318 - if (i != order) 319 - __i915_buddy_free(mm, block); 320 - return ERR_PTR(err); 321 - } 322 - 323 - static inline bool overlaps(u64 s1, u64 e1, u64 s2, u64 e2) 324 - { 325 - return s1 <= e2 && e1 >= s2; 326 - } 327 - 328 - static inline bool contains(u64 s1, u64 e1, u64 s2, u64 e2) 329 - { 330 - return s1 <= s2 && e1 >= e2; 331 - } 332 - 333 - /* 334 - * Allocate range. Note that it's safe to chain together multiple alloc_ranges 335 - * with the same blocks list. 336 - * 337 - * Intended for pre-allocating portions of the address space, for example to 338 - * reserve a block for the initial framebuffer or similar, hence the expectation 339 - * here is that i915_buddy_alloc() is still the main vehicle for 340 - * allocations, so if that's not the case then the drm_mm range allocator is 341 - * probably a much better fit, and so you should probably go use that instead. 342 - */ 343 - int i915_buddy_alloc_range(struct i915_buddy_mm *mm, 344 - struct list_head *blocks, 345 - u64 start, u64 size) 346 - { 347 - struct i915_buddy_block *block; 348 - struct i915_buddy_block *buddy; 349 - LIST_HEAD(allocated); 350 - LIST_HEAD(dfs); 351 - u64 end; 352 - int err; 353 - int i; 354 - 355 - if (size < mm->chunk_size) 356 - return -EINVAL; 357 - 358 - if (!IS_ALIGNED(size | start, mm->chunk_size)) 359 - return -EINVAL; 360 - 361 - if (range_overflows(start, size, mm->size)) 362 - return -EINVAL; 363 - 364 - for (i = 0; i < mm->n_roots; ++i) 365 - list_add_tail(&mm->roots[i]->tmp_link, &dfs); 366 - 367 - end = start + size - 1; 368 - 369 - do { 370 - u64 block_start; 371 - u64 block_end; 372 - 373 - block = list_first_entry_or_null(&dfs, 374 - struct i915_buddy_block, 375 - tmp_link); 376 - if (!block) 377 - break; 378 - 379 - list_del(&block->tmp_link); 380 - 381 - block_start = i915_buddy_block_offset(block); 382 - block_end = block_start + i915_buddy_block_size(mm, block) - 1; 383 - 384 - if (!overlaps(start, end, block_start, block_end)) 385 - continue; 386 - 387 - if (i915_buddy_block_is_allocated(block)) { 388 - err = -ENOSPC; 389 - goto err_free; 390 - } 391 - 392 - if (contains(start, end, block_start, block_end)) { 393 - if (!i915_buddy_block_is_free(block)) { 394 - err = -ENOSPC; 395 - goto err_free; 396 - } 397 - 398 - mark_allocated(block); 399 - list_add_tail(&block->link, &allocated); 400 - continue; 401 - } 402 - 403 - if (!i915_buddy_block_is_split(block)) { 404 - err = split_block(mm, block); 405 - if (unlikely(err)) 406 - goto err_undo; 407 - } 408 - 409 - list_add(&block->right->tmp_link, &dfs); 410 - list_add(&block->left->tmp_link, &dfs); 411 - } while (1); 412 - 413 - list_splice_tail(&allocated, blocks); 414 - return 0; 415 - 416 - err_undo: 417 - /* 418 - * We really don't want to leave around a bunch of split blocks, since 419 - * bigger is better, so make sure we merge everything back before we 420 - * free the allocated blocks. 421 - */ 422 - buddy = get_buddy(block); 423 - if (buddy && 424 - (i915_buddy_block_is_free(block) && 425 - i915_buddy_block_is_free(buddy))) 426 - __i915_buddy_free(mm, block); 427 - 428 - err_free: 429 - i915_buddy_free_list(mm, &allocated); 430 - return err; 431 - } 432 - 433 - #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) 434 - #include "selftests/i915_buddy.c" 435 - #endif
-131
drivers/gpu/drm/i915/i915_buddy.h
··· 1 - /* SPDX-License-Identifier: MIT */ 2 - /* 3 - * Copyright © 2019 Intel Corporation 4 - */ 5 - 6 - #ifndef __I915_BUDDY_H__ 7 - #define __I915_BUDDY_H__ 8 - 9 - #include <linux/bitops.h> 10 - #include <linux/list.h> 11 - 12 - struct i915_buddy_block { 13 - #define I915_BUDDY_HEADER_OFFSET GENMASK_ULL(63, 12) 14 - #define I915_BUDDY_HEADER_STATE GENMASK_ULL(11, 10) 15 - #define I915_BUDDY_ALLOCATED (1 << 10) 16 - #define I915_BUDDY_FREE (2 << 10) 17 - #define I915_BUDDY_SPLIT (3 << 10) 18 - /* Free to be used, if needed in the future */ 19 - #define I915_BUDDY_HEADER_UNUSED GENMASK_ULL(9, 6) 20 - #define I915_BUDDY_HEADER_ORDER GENMASK_ULL(5, 0) 21 - u64 header; 22 - 23 - struct i915_buddy_block *left; 24 - struct i915_buddy_block *right; 25 - struct i915_buddy_block *parent; 26 - 27 - void *private; /* owned by creator */ 28 - 29 - /* 30 - * While the block is allocated by the user through i915_buddy_alloc*, 31 - * the user has ownership of the link, for example to maintain within 32 - * a list, if so desired. As soon as the block is freed with 33 - * i915_buddy_free* ownership is given back to the mm. 34 - */ 35 - struct list_head link; 36 - struct list_head tmp_link; 37 - }; 38 - 39 - /* Order-zero must be at least PAGE_SIZE */ 40 - #define I915_BUDDY_MAX_ORDER (63 - PAGE_SHIFT) 41 - 42 - /* 43 - * Binary Buddy System. 44 - * 45 - * Locking should be handled by the user, a simple mutex around 46 - * i915_buddy_alloc* and i915_buddy_free* should suffice. 47 - */ 48 - struct i915_buddy_mm { 49 - /* Maintain a free list for each order. */ 50 - struct list_head *free_list; 51 - 52 - /* 53 - * Maintain explicit binary tree(s) to track the allocation of the 54 - * address space. This gives us a simple way of finding a buddy block 55 - * and performing the potentially recursive merge step when freeing a 56 - * block. Nodes are either allocated or free, in which case they will 57 - * also exist on the respective free list. 58 - */ 59 - struct i915_buddy_block **roots; 60 - 61 - /* 62 - * Anything from here is public, and remains static for the lifetime of 63 - * the mm. Everything above is considered do-not-touch. 64 - */ 65 - unsigned int n_roots; 66 - unsigned int max_order; 67 - 68 - /* Must be at least PAGE_SIZE */ 69 - u64 chunk_size; 70 - u64 size; 71 - }; 72 - 73 - static inline u64 74 - i915_buddy_block_offset(struct i915_buddy_block *block) 75 - { 76 - return block->header & I915_BUDDY_HEADER_OFFSET; 77 - } 78 - 79 - static inline unsigned int 80 - i915_buddy_block_order(struct i915_buddy_block *block) 81 - { 82 - return block->header & I915_BUDDY_HEADER_ORDER; 83 - } 84 - 85 - static inline unsigned int 86 - i915_buddy_block_state(struct i915_buddy_block *block) 87 - { 88 - return block->header & I915_BUDDY_HEADER_STATE; 89 - } 90 - 91 - static inline bool 92 - i915_buddy_block_is_allocated(struct i915_buddy_block *block) 93 - { 94 - return i915_buddy_block_state(block) == I915_BUDDY_ALLOCATED; 95 - } 96 - 97 - static inline bool 98 - i915_buddy_block_is_free(struct i915_buddy_block *block) 99 - { 100 - return i915_buddy_block_state(block) == I915_BUDDY_FREE; 101 - } 102 - 103 - static inline bool 104 - i915_buddy_block_is_split(struct i915_buddy_block *block) 105 - { 106 - return i915_buddy_block_state(block) == I915_BUDDY_SPLIT; 107 - } 108 - 109 - static inline u64 110 - i915_buddy_block_size(struct i915_buddy_mm *mm, 111 - struct i915_buddy_block *block) 112 - { 113 - return mm->chunk_size << i915_buddy_block_order(block); 114 - } 115 - 116 - int i915_buddy_init(struct i915_buddy_mm *mm, u64 size, u64 chunk_size); 117 - 118 - void i915_buddy_fini(struct i915_buddy_mm *mm); 119 - 120 - struct i915_buddy_block * 121 - i915_buddy_alloc(struct i915_buddy_mm *mm, unsigned int order); 122 - 123 - int i915_buddy_alloc_range(struct i915_buddy_mm *mm, 124 - struct list_head *blocks, 125 - u64 start, u64 size); 126 - 127 - void i915_buddy_free(struct i915_buddy_mm *mm, struct i915_buddy_block *block); 128 - 129 - void i915_buddy_free_list(struct i915_buddy_mm *mm, struct list_head *objects); 130 - 131 - #endif
+13
drivers/gpu/drm/i915/i915_drv.c
··· 84 84 #include "intel_gvt.h" 85 85 #include "intel_memory_region.h" 86 86 #include "intel_pm.h" 87 + #include "intel_region_ttm.h" 87 88 #include "intel_sideband.h" 88 89 #include "vlv_suspend.h" 89 90 ··· 336 335 if (ret < 0) 337 336 goto err_workqueues; 338 337 338 + ret = intel_region_ttm_device_init(dev_priv); 339 + if (ret) 340 + goto err_ttm; 341 + 339 342 intel_wopcm_init_early(&dev_priv->wopcm); 340 343 341 344 intel_gt_init_early(&dev_priv->gt, dev_priv); ··· 364 359 err_gem: 365 360 i915_gem_cleanup_early(dev_priv); 366 361 intel_gt_driver_late_release(&dev_priv->gt); 362 + intel_region_ttm_device_fini(dev_priv); 363 + err_ttm: 367 364 vlv_suspend_cleanup(dev_priv); 368 365 err_workqueues: 369 366 i915_workqueues_cleanup(dev_priv); ··· 383 376 intel_power_domains_cleanup(dev_priv); 384 377 i915_gem_cleanup_early(dev_priv); 385 378 intel_gt_driver_late_release(&dev_priv->gt); 379 + intel_region_ttm_device_fini(dev_priv); 386 380 vlv_suspend_cleanup(dev_priv); 387 381 i915_workqueues_cleanup(dev_priv); 388 382 ··· 639 631 intel_memory_regions_driver_release(dev_priv); 640 632 err_ggtt: 641 633 i915_ggtt_driver_release(dev_priv); 634 + i915_gem_drain_freed_objects(dev_priv); 635 + i915_ggtt_driver_late_release(dev_priv); 642 636 err_perf: 643 637 i915_perf_fini(dev_priv); 644 638 return ret; ··· 890 880 i915_driver_hw_remove(i915); 891 881 intel_memory_regions_driver_release(i915); 892 882 i915_ggtt_driver_release(i915); 883 + i915_gem_drain_freed_objects(i915); 884 + i915_ggtt_driver_late_release(i915); 893 885 out_cleanup_mmio: 894 886 i915_driver_mmio_release(i915); 895 887 out_runtime_pm_put: ··· 948 936 intel_memory_regions_driver_release(dev_priv); 949 937 i915_ggtt_driver_release(dev_priv); 950 938 i915_gem_drain_freed_objects(dev_priv); 939 + i915_ggtt_driver_late_release(dev_priv); 951 940 952 941 i915_driver_mmio_release(dev_priv); 953 942
+10 -1
drivers/gpu/drm/i915/i915_drv.h
··· 59 59 #include <drm/drm_atomic.h> 60 60 #include <drm/drm_connector.h> 61 61 #include <drm/i915_mei_hdcp_interface.h> 62 + #include <drm/ttm/ttm_device.h> 62 63 63 64 #include "i915_params.h" 64 65 #include "i915_reg.h" ··· 763 762 764 763 struct i915_selftest_stash { 765 764 atomic_t counter; 765 + struct ida mock_region_instances; 766 766 }; 767 767 768 768 struct drm_i915_private { ··· 1155 1153 1156 1154 /* Mutex to protect the above hdcp component related values. */ 1157 1155 struct mutex hdcp_comp_mutex; 1156 + 1157 + /* The TTM device structure. */ 1158 + struct ttm_device bdev; 1158 1159 1159 1160 I915_SELFTEST_DECLARE(struct i915_selftest_stash selftest;) 1160 1161 ··· 1751 1746 void i915_gem_init_early(struct drm_i915_private *dev_priv); 1752 1747 void i915_gem_cleanup_early(struct drm_i915_private *dev_priv); 1753 1748 1754 - struct intel_memory_region *i915_gem_shmem_setup(struct drm_i915_private *i915); 1749 + struct intel_memory_region *i915_gem_shmem_setup(struct drm_i915_private *i915, 1750 + u16 type, u16 instance); 1755 1751 1756 1752 static inline void i915_gem_drain_freed_objects(struct drm_i915_private *i915) 1757 1753 { ··· 1930 1924 struct drm_file *file); 1931 1925 1932 1926 /* i915_mm.c */ 1927 + int remap_io_mapping(struct vm_area_struct *vma, 1928 + unsigned long addr, unsigned long pfn, unsigned long size, 1929 + struct io_mapping *iomap); 1933 1930 int remap_io_sg(struct vm_area_struct *vma, 1934 1931 unsigned long addr, unsigned long size, 1935 1932 struct scatterlist *sgl, resource_size_t iobase);
+1
drivers/gpu/drm/i915/i915_gem.c
··· 1108 1108 } 1109 1109 1110 1110 i915_gem_drain_freed_objects(dev_priv); 1111 + 1111 1112 return ret; 1112 1113 } 1113 1114
-1
drivers/gpu/drm/i915/i915_globals.c
··· 87 87 88 88 static __initconst int (* const initfn[])(void) = { 89 89 i915_global_active_init, 90 - i915_global_buddy_init, 91 90 i915_global_context_init, 92 91 i915_global_gem_context_init, 93 92 i915_global_objects_init,
-1
drivers/gpu/drm/i915/i915_globals.h
··· 27 27 28 28 /* constructors */ 29 29 int i915_global_active_init(void); 30 - int i915_global_buddy_init(void); 31 30 int i915_global_context_init(void); 32 31 int i915_global_gem_context_init(void); 33 32 int i915_global_objects_init(void);
+44
drivers/gpu/drm/i915/i915_mm.c
··· 37 37 resource_size_t iobase; 38 38 }; 39 39 40 + static int remap_pfn(pte_t *pte, unsigned long addr, void *data) 41 + { 42 + struct remap_pfn *r = data; 43 + 44 + /* Special PTE are not associated with any struct page */ 45 + set_pte_at(r->mm, addr, pte, pte_mkspecial(pfn_pte(r->pfn, r->prot))); 46 + r->pfn++; 47 + 48 + return 0; 49 + } 50 + 40 51 #define use_dma(io) ((io) != -1) 41 52 42 53 static inline unsigned long sgt_pfn(const struct remap_pfn *r) ··· 77 66 return 0; 78 67 } 79 68 69 + /** 70 + * remap_io_mapping - remap an IO mapping to userspace 71 + * @vma: user vma to map to 72 + * @addr: target user address to start at 73 + * @pfn: physical address of kernel memory 74 + * @size: size of map area 75 + * @iomap: the source io_mapping 76 + * 77 + * Note: this is only safe if the mm semaphore is held when called. 78 + */ 79 + int remap_io_mapping(struct vm_area_struct *vma, 80 + unsigned long addr, unsigned long pfn, unsigned long size, 81 + struct io_mapping *iomap) 82 + { 83 + struct remap_pfn r; 84 + int err; 85 + 80 86 #define EXPECTED_FLAGS (VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP) 87 + GEM_BUG_ON((vma->vm_flags & EXPECTED_FLAGS) != EXPECTED_FLAGS); 88 + 89 + /* We rely on prevalidation of the io-mapping to skip track_pfn(). */ 90 + r.mm = vma->vm_mm; 91 + r.pfn = pfn; 92 + r.prot = __pgprot((pgprot_val(iomap->prot) & _PAGE_CACHE_MASK) | 93 + (pgprot_val(vma->vm_page_prot) & ~_PAGE_CACHE_MASK)); 94 + 95 + err = apply_to_page_range(r.mm, addr, size, remap_pfn, &r); 96 + if (unlikely(err)) { 97 + zap_vma_ptes(vma, addr, (r.pfn - pfn) << PAGE_SHIFT); 98 + return err; 99 + } 100 + 101 + return 0; 102 + } 81 103 82 104 /** 83 105 * remap_io_sg - remap an IO mapping to userspace
+1 -1
drivers/gpu/drm/i915/i915_params.c
··· 160 160 i915_param_named_unsafe(enable_guc, int, 0400, 161 161 "Enable GuC load for GuC submission and/or HuC load. " 162 162 "Required functionality can be selected using bitmask values. " 163 - "(-1=auto, 0=disable [default], 1=GuC submission, 2=HuC load)"); 163 + "(-1=auto [default], 0=disable, 1=GuC submission, 2=HuC load)"); 164 164 165 165 i915_param_named(guc_log_level, int, 0400, 166 166 "GuC firmware logging level. Requires GuC to be loaded. "
+1 -1
drivers/gpu/drm/i915/i915_params.h
··· 59 59 param(int, disable_power_well, -1, 0400) \ 60 60 param(int, enable_ips, 1, 0600) \ 61 61 param(int, invert_brightness, 0, 0600) \ 62 - param(int, enable_guc, 0, 0400) \ 62 + param(int, enable_guc, -1, 0400) \ 63 63 param(int, guc_log_level, -1, 0400) \ 64 64 param(char *, guc_firmware_path, NULL, 0400) \ 65 65 param(char *, huc_firmware_path, NULL, 0400) \
+3 -5
drivers/gpu/drm/i915/i915_pmu.c
··· 836 836 return sprintf(buf, "config=0x%lx\n", eattr->val); 837 837 } 838 838 839 - static ssize_t 840 - i915_pmu_get_attr_cpumask(struct device *dev, 841 - struct device_attribute *attr, 842 - char *buf) 839 + static ssize_t cpumask_show(struct device *dev, 840 + struct device_attribute *attr, char *buf) 843 841 { 844 842 return cpumap_print_to_pagebuf(true, buf, &i915_pmu_cpumask); 845 843 } 846 844 847 - static DEVICE_ATTR(cpumask, 0444, i915_pmu_get_attr_cpumask, NULL); 845 + static DEVICE_ATTR_RO(cpumask); 848 846 849 847 static struct attribute *i915_cpumask_attrs[] = { 850 848 &dev_attr_cpumask.attr,
+70
drivers/gpu/drm/i915/i915_scatterlist.c
··· 6 6 7 7 #include "i915_scatterlist.h" 8 8 9 + #include <drm/drm_mm.h> 10 + 11 + #include <linux/slab.h> 12 + 9 13 bool i915_sg_trim(struct sg_table *orig_st) 10 14 { 11 15 struct sg_table new_st; ··· 36 32 37 33 *orig_st = new_st; 38 34 return true; 35 + } 36 + 37 + /** 38 + * i915_sg_from_mm_node - Create an sg_table from a struct drm_mm_node 39 + * @node: The drm_mm_node. 40 + * @region_start: An offset to add to the dma addresses of the sg list. 41 + * 42 + * Create a struct sg_table, initializing it from a struct drm_mm_node, 43 + * taking a maximum segment length into account, splitting into segments 44 + * if necessary. 45 + * 46 + * Return: A pointer to a kmalloced struct sg_table on success, negative 47 + * error code cast to an error pointer on failure. 48 + */ 49 + struct sg_table *i915_sg_from_mm_node(const struct drm_mm_node *node, 50 + u64 region_start) 51 + { 52 + const u64 max_segment = SZ_1G; /* Do we have a limit on this? */ 53 + u64 segment_pages = max_segment >> PAGE_SHIFT; 54 + u64 block_size, offset, prev_end; 55 + struct sg_table *st; 56 + struct scatterlist *sg; 57 + 58 + st = kmalloc(sizeof(*st), GFP_KERNEL); 59 + if (!st) 60 + return ERR_PTR(-ENOMEM); 61 + 62 + if (sg_alloc_table(st, DIV_ROUND_UP(node->size, segment_pages), 63 + GFP_KERNEL)) { 64 + kfree(st); 65 + return ERR_PTR(-ENOMEM); 66 + } 67 + 68 + sg = st->sgl; 69 + st->nents = 0; 70 + prev_end = (resource_size_t)-1; 71 + block_size = node->size << PAGE_SHIFT; 72 + offset = node->start << PAGE_SHIFT; 73 + 74 + while (block_size) { 75 + u64 len; 76 + 77 + if (offset != prev_end || sg->length >= max_segment) { 78 + if (st->nents) 79 + sg = __sg_next(sg); 80 + 81 + sg_dma_address(sg) = region_start + offset; 82 + sg_dma_len(sg) = 0; 83 + sg->length = 0; 84 + st->nents++; 85 + } 86 + 87 + len = min(block_size, max_segment - sg->length); 88 + sg->length += len; 89 + sg_dma_len(sg) += len; 90 + 91 + offset += len; 92 + block_size -= len; 93 + 94 + prev_end = offset; 95 + } 96 + 97 + sg_mark_end(sg); 98 + i915_sg_trim(st); 99 + 100 + return st; 39 101 } 40 102 41 103 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
+16 -4
drivers/gpu/drm/i915/i915_scatterlist.h
··· 13 13 14 14 #include "i915_gem.h" 15 15 16 + struct drm_mm_node; 17 + 16 18 /* 17 19 * Optimised SGL iterator for GEM objects 18 20 */ ··· 103 101 (((__iter).curr += PAGE_SIZE) >= (__iter).max) ? \ 104 102 (__iter) = __sgt_iter(__sg_next((__iter).sgp), false), 0 : 0) 105 103 106 - static inline unsigned int i915_sg_page_sizes(struct scatterlist *sg) 104 + /** 105 + * i915_sg_dma_sizes - Record the dma segment sizes of a scatterlist 106 + * @sg: The scatterlist 107 + * 108 + * Return: An unsigned int with segment sizes logically or'ed together. 109 + * A caller can use this information to determine what hardware page table 110 + * entry sizes can be used to map the memory represented by the scatterlist. 111 + */ 112 + static inline unsigned int i915_sg_dma_sizes(struct scatterlist *sg) 107 113 { 108 114 unsigned int page_sizes; 109 115 110 116 page_sizes = 0; 111 - while (sg) { 117 + while (sg && sg_dma_len(sg)) { 112 118 GEM_BUG_ON(sg->offset); 113 - GEM_BUG_ON(!IS_ALIGNED(sg->length, PAGE_SIZE)); 114 - page_sizes |= sg->length; 119 + GEM_BUG_ON(!IS_ALIGNED(sg_dma_len(sg), PAGE_SIZE)); 120 + page_sizes |= sg_dma_len(sg); 115 121 sg = __sg_next(sg); 116 122 } 117 123 ··· 143 133 144 134 bool i915_sg_trim(struct sg_table *orig_st); 145 135 136 + struct sg_table *i915_sg_from_mm_node(const struct drm_mm_node *node, 137 + u64 region_start); 146 138 #endif
+15 -15
drivers/gpu/drm/i915/i915_sysfs.c
··· 58 58 return DIV_ROUND_CLOSEST_ULL(res, 1000); 59 59 } 60 60 61 - static ssize_t 62 - show_rc6_mask(struct device *kdev, struct device_attribute *attr, char *buf) 61 + static ssize_t rc6_enable_show(struct device *kdev, 62 + struct device_attribute *attr, char *buf) 63 63 { 64 64 struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); 65 65 unsigned int mask; ··· 75 75 return sysfs_emit(buf, "%x\n", mask); 76 76 } 77 77 78 - static ssize_t 79 - show_rc6_ms(struct device *kdev, struct device_attribute *attr, char *buf) 78 + static ssize_t rc6_residency_ms_show(struct device *kdev, 79 + struct device_attribute *attr, char *buf) 80 80 { 81 81 struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); 82 82 u32 rc6_residency = calc_residency(dev_priv, GEN6_GT_GFX_RC6); 83 83 return sysfs_emit(buf, "%u\n", rc6_residency); 84 84 } 85 85 86 - static ssize_t 87 - show_rc6p_ms(struct device *kdev, struct device_attribute *attr, char *buf) 86 + static ssize_t rc6p_residency_ms_show(struct device *kdev, 87 + struct device_attribute *attr, char *buf) 88 88 { 89 89 struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); 90 90 u32 rc6p_residency = calc_residency(dev_priv, GEN6_GT_GFX_RC6p); 91 91 return sysfs_emit(buf, "%u\n", rc6p_residency); 92 92 } 93 93 94 - static ssize_t 95 - show_rc6pp_ms(struct device *kdev, struct device_attribute *attr, char *buf) 94 + static ssize_t rc6pp_residency_ms_show(struct device *kdev, 95 + struct device_attribute *attr, char *buf) 96 96 { 97 97 struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); 98 98 u32 rc6pp_residency = calc_residency(dev_priv, GEN6_GT_GFX_RC6pp); 99 99 return sysfs_emit(buf, "%u\n", rc6pp_residency); 100 100 } 101 101 102 - static ssize_t 103 - show_media_rc6_ms(struct device *kdev, struct device_attribute *attr, char *buf) 102 + static ssize_t media_rc6_residency_ms_show(struct device *kdev, 103 + struct device_attribute *attr, char *buf) 104 104 { 105 105 struct drm_i915_private *dev_priv = kdev_minor_to_i915(kdev); 106 106 u32 rc6_residency = calc_residency(dev_priv, VLV_GT_MEDIA_RC6); 107 107 return sysfs_emit(buf, "%u\n", rc6_residency); 108 108 } 109 109 110 - static DEVICE_ATTR(rc6_enable, S_IRUGO, show_rc6_mask, NULL); 111 - static DEVICE_ATTR(rc6_residency_ms, S_IRUGO, show_rc6_ms, NULL); 112 - static DEVICE_ATTR(rc6p_residency_ms, S_IRUGO, show_rc6p_ms, NULL); 113 - static DEVICE_ATTR(rc6pp_residency_ms, S_IRUGO, show_rc6pp_ms, NULL); 114 - static DEVICE_ATTR(media_rc6_residency_ms, S_IRUGO, show_media_rc6_ms, NULL); 110 + static DEVICE_ATTR_RO(rc6_enable); 111 + static DEVICE_ATTR_RO(rc6_residency_ms); 112 + static DEVICE_ATTR_RO(rc6p_residency_ms); 113 + static DEVICE_ATTR_RO(rc6pp_residency_ms); 114 + static DEVICE_ATTR_RO(media_rc6_residency_ms); 115 115 116 116 static struct attribute *rc6_attrs[] = { 117 117 &dev_attr_rc6_enable.attr,
+5
drivers/gpu/drm/i915/i915_utils.h
··· 201 201 __T; \ 202 202 }) 203 203 204 + static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b) 205 + { 206 + return a - b; 207 + } 208 + 204 209 /* 205 210 * container_of_user: Extract the superclass from a pointer to a member. 206 211 *
+17 -12
drivers/gpu/drm/i915/i915_vma.c
··· 800 800 static int vma_get_pages(struct i915_vma *vma) 801 801 { 802 802 int err = 0; 803 + bool pinned_pages = false; 803 804 804 805 if (atomic_add_unless(&vma->pages_count, 1, 0)) 805 806 return 0; 806 807 808 + if (vma->obj) { 809 + err = i915_gem_object_pin_pages(vma->obj); 810 + if (err) 811 + return err; 812 + pinned_pages = true; 813 + } 814 + 807 815 /* Allocations ahoy! */ 808 - if (mutex_lock_interruptible(&vma->pages_mutex)) 809 - return -EINTR; 816 + if (mutex_lock_interruptible(&vma->pages_mutex)) { 817 + err = -EINTR; 818 + goto unpin; 819 + } 810 820 811 821 if (!atomic_read(&vma->pages_count)) { 812 - if (vma->obj) { 813 - err = i915_gem_object_pin_pages(vma->obj); 814 - if (err) 815 - goto unlock; 816 - } 817 - 818 822 err = vma->ops->set_pages(vma); 819 - if (err) { 820 - if (vma->obj) 821 - i915_gem_object_unpin_pages(vma->obj); 823 + if (err) 822 824 goto unlock; 823 - } 825 + pinned_pages = false; 824 826 } 825 827 atomic_inc(&vma->pages_count); 826 828 827 829 unlock: 828 830 mutex_unlock(&vma->pages_mutex); 831 + unpin: 832 + if (pinned_pages) 833 + __i915_gem_object_unpin_pages(vma->obj); 829 834 830 835 return err; 831 836 }
-5
drivers/gpu/drm/i915/i915_vma.h
··· 151 151 i915_gem_object_put(vma->obj); 152 152 } 153 153 154 - static __always_inline ptrdiff_t ptrdiff(const void *a, const void *b) 155 - { 156 - return a - b; 157 - } 158 - 159 154 static inline long 160 155 i915_vma_compare(struct i915_vma *vma, 161 156 struct i915_address_space *vm,
+54 -132
drivers/gpu/drm/i915/intel_memory_region.c
··· 28 28 }, 29 29 }; 30 30 31 + struct intel_region_reserve { 32 + struct list_head link; 33 + struct ttm_resource *res; 34 + }; 35 + 31 36 struct intel_memory_region * 32 37 intel_memory_region_lookup(struct drm_i915_private *i915, 33 38 u16 class, u16 instance) ··· 63 58 return NULL; 64 59 } 65 60 66 - static u64 67 - intel_memory_region_free_pages(struct intel_memory_region *mem, 68 - struct list_head *blocks) 61 + /** 62 + * intel_memory_region_unreserve - Unreserve all previously reserved 63 + * ranges 64 + * @mem: The region containing the reserved ranges. 65 + */ 66 + void intel_memory_region_unreserve(struct intel_memory_region *mem) 69 67 { 70 - struct i915_buddy_block *block, *on; 71 - u64 size = 0; 68 + struct intel_region_reserve *reserve, *next; 72 69 73 - list_for_each_entry_safe(block, on, blocks, link) { 74 - size += i915_buddy_block_size(&mem->mm, block); 75 - i915_buddy_free(&mem->mm, block); 76 - } 77 - INIT_LIST_HEAD(blocks); 78 - 79 - return size; 80 - } 81 - 82 - void 83 - __intel_memory_region_put_pages_buddy(struct intel_memory_region *mem, 84 - struct list_head *blocks) 85 - { 86 - mutex_lock(&mem->mm_lock); 87 - mem->avail += intel_memory_region_free_pages(mem, blocks); 88 - mutex_unlock(&mem->mm_lock); 89 - } 90 - 91 - void 92 - __intel_memory_region_put_block_buddy(struct i915_buddy_block *block) 93 - { 94 - struct list_head blocks; 95 - 96 - INIT_LIST_HEAD(&blocks); 97 - list_add(&block->link, &blocks); 98 - __intel_memory_region_put_pages_buddy(block->private, &blocks); 99 - } 100 - 101 - int 102 - __intel_memory_region_get_pages_buddy(struct intel_memory_region *mem, 103 - resource_size_t size, 104 - unsigned int flags, 105 - struct list_head *blocks) 106 - { 107 - unsigned int min_order = 0; 108 - unsigned long n_pages; 109 - 110 - GEM_BUG_ON(!IS_ALIGNED(size, mem->mm.chunk_size)); 111 - GEM_BUG_ON(!list_empty(blocks)); 112 - 113 - if (flags & I915_ALLOC_MIN_PAGE_SIZE) { 114 - min_order = ilog2(mem->min_page_size) - 115 - ilog2(mem->mm.chunk_size); 116 - } 117 - 118 - if (flags & I915_ALLOC_CONTIGUOUS) { 119 - size = roundup_pow_of_two(size); 120 - min_order = ilog2(size) - ilog2(mem->mm.chunk_size); 121 - } 122 - 123 - if (size > mem->mm.size) 124 - return -E2BIG; 125 - 126 - n_pages = size >> ilog2(mem->mm.chunk_size); 70 + if (!mem->priv_ops || !mem->priv_ops->free) 71 + return; 127 72 128 73 mutex_lock(&mem->mm_lock); 129 - 130 - do { 131 - struct i915_buddy_block *block; 132 - unsigned int order; 133 - 134 - order = fls(n_pages) - 1; 135 - GEM_BUG_ON(order > mem->mm.max_order); 136 - GEM_BUG_ON(order < min_order); 137 - 138 - do { 139 - block = i915_buddy_alloc(&mem->mm, order); 140 - if (!IS_ERR(block)) 141 - break; 142 - 143 - if (order-- == min_order) 144 - goto err_free_blocks; 145 - } while (1); 146 - 147 - n_pages -= BIT(order); 148 - 149 - block->private = mem; 150 - list_add_tail(&block->link, blocks); 151 - 152 - if (!n_pages) 153 - break; 154 - } while (1); 155 - 156 - mem->avail -= size; 74 + list_for_each_entry_safe(reserve, next, &mem->reserved, link) { 75 + list_del(&reserve->link); 76 + mem->priv_ops->free(mem, reserve->res); 77 + kfree(reserve); 78 + } 157 79 mutex_unlock(&mem->mm_lock); 158 - return 0; 159 - 160 - err_free_blocks: 161 - intel_memory_region_free_pages(mem, blocks); 162 - mutex_unlock(&mem->mm_lock); 163 - return -ENXIO; 164 80 } 165 81 166 - struct i915_buddy_block * 167 - __intel_memory_region_get_block_buddy(struct intel_memory_region *mem, 168 - resource_size_t size, 169 - unsigned int flags) 170 - { 171 - struct i915_buddy_block *block; 172 - LIST_HEAD(blocks); 173 - int ret; 174 - 175 - ret = __intel_memory_region_get_pages_buddy(mem, size, flags, &blocks); 176 - if (ret) 177 - return ERR_PTR(ret); 178 - 179 - block = list_first_entry(&blocks, typeof(*block), link); 180 - list_del_init(&block->link); 181 - return block; 182 - } 183 - 184 - int intel_memory_region_init_buddy(struct intel_memory_region *mem) 185 - { 186 - return i915_buddy_init(&mem->mm, resource_size(&mem->region), 187 - PAGE_SIZE); 188 - } 189 - 190 - void intel_memory_region_release_buddy(struct intel_memory_region *mem) 191 - { 192 - i915_buddy_free_list(&mem->mm, &mem->reserved); 193 - i915_buddy_fini(&mem->mm); 194 - } 195 - 82 + /** 83 + * intel_memory_region_reserve - Reserve a memory range 84 + * @mem: The region for which we want to reserve a range. 85 + * @offset: Start of the range to reserve. 86 + * @size: The size of the range to reserve. 87 + * 88 + * Return: 0 on success, negative error code on failure. 89 + */ 196 90 int intel_memory_region_reserve(struct intel_memory_region *mem, 197 - u64 offset, u64 size) 91 + resource_size_t offset, 92 + resource_size_t size) 198 93 { 199 94 int ret; 95 + struct intel_region_reserve *reserve; 96 + 97 + if (!mem->priv_ops || !mem->priv_ops->reserve) 98 + return -EINVAL; 99 + 100 + reserve = kzalloc(sizeof(*reserve), GFP_KERNEL); 101 + if (!reserve) 102 + return -ENOMEM; 103 + 104 + reserve->res = mem->priv_ops->reserve(mem, offset, size); 105 + if (IS_ERR(reserve->res)) { 106 + ret = PTR_ERR(reserve->res); 107 + kfree(reserve); 108 + return ret; 109 + } 200 110 201 111 mutex_lock(&mem->mm_lock); 202 - ret = i915_buddy_alloc_range(&mem->mm, &mem->reserved, offset, size); 112 + list_add_tail(&reserve->link, &mem->reserved); 203 113 mutex_unlock(&mem->mm_lock); 204 114 205 - return ret; 115 + return 0; 206 116 } 207 117 208 118 struct intel_memory_region * ··· 126 206 resource_size_t size, 127 207 resource_size_t min_page_size, 128 208 resource_size_t io_start, 209 + u16 type, 210 + u16 instance, 129 211 const struct intel_memory_region_ops *ops) 130 212 { 131 213 struct intel_memory_region *mem; ··· 144 222 mem->ops = ops; 145 223 mem->total = size; 146 224 mem->avail = mem->total; 225 + mem->type = type; 226 + mem->instance = instance; 147 227 148 228 mutex_init(&mem->objects.lock); 149 229 INIT_LIST_HEAD(&mem->objects.list); ··· 183 259 struct intel_memory_region *mem = 184 260 container_of(kref, typeof(*mem), kref); 185 261 262 + intel_memory_region_unreserve(mem); 186 263 if (mem->ops->release) 187 264 mem->ops->release(mem); 188 265 ··· 221 296 instance = intel_region_map[i].instance; 222 297 switch (type) { 223 298 case INTEL_MEMORY_SYSTEM: 224 - mem = i915_gem_shmem_setup(i915); 299 + mem = i915_gem_shmem_setup(i915, type, instance); 225 300 break; 226 301 case INTEL_MEMORY_STOLEN_LOCAL: 227 - mem = i915_gem_stolen_lmem_setup(i915); 302 + mem = i915_gem_stolen_lmem_setup(i915, type, instance); 228 303 if (!IS_ERR(mem)) 229 304 i915->mm.stolen_region = mem; 230 305 break; 231 306 case INTEL_MEMORY_STOLEN_SYSTEM: 232 - mem = i915_gem_stolen_smem_setup(i915); 307 + mem = i915_gem_stolen_smem_setup(i915, type, instance); 233 308 if (!IS_ERR(mem)) 234 309 i915->mm.stolen_region = mem; 235 310 break; ··· 246 321 } 247 322 248 323 mem->id = i; 249 - mem->type = type; 250 - mem->instance = instance; 251 - 252 324 i915->mm.regions[i] = mem; 253 325 } 254 326
+24 -21
drivers/gpu/drm/i915/intel_memory_region.h
··· 13 13 #include <drm/drm_mm.h> 14 14 #include <drm/i915_drm.h> 15 15 16 - #include "i915_buddy.h" 17 - 18 16 struct drm_i915_private; 19 17 struct drm_i915_gem_object; 20 18 struct intel_memory_region; 21 19 struct sg_table; 20 + struct ttm_resource; 22 21 23 22 enum intel_memory_type { 24 23 INTEL_MEMORY_SYSTEM = I915_MEMORY_CLASS_SYSTEM, 25 24 INTEL_MEMORY_LOCAL = I915_MEMORY_CLASS_DEVICE, 26 25 INTEL_MEMORY_STOLEN_SYSTEM, 27 26 INTEL_MEMORY_STOLEN_LOCAL, 27 + INTEL_MEMORY_MOCK, 28 28 }; 29 29 30 30 enum intel_region_id { ··· 59 59 unsigned int flags); 60 60 }; 61 61 62 + struct intel_memory_region_private_ops { 63 + struct ttm_resource *(*reserve)(struct intel_memory_region *mem, 64 + resource_size_t offset, 65 + resource_size_t size); 66 + void (*free)(struct intel_memory_region *mem, 67 + struct ttm_resource *res); 68 + }; 69 + 62 70 struct intel_memory_region { 63 71 struct drm_i915_private *i915; 64 72 65 73 const struct intel_memory_region_ops *ops; 74 + const struct intel_memory_region_private_ops *priv_ops; 66 75 67 76 struct io_mapping iomap; 68 77 struct resource region; ··· 79 70 /* For fake LMEM */ 80 71 struct drm_mm_node fake_mappable; 81 72 82 - struct i915_buddy_mm mm; 83 73 struct mutex mm_lock; 84 74 85 75 struct kref kref; ··· 103 95 struct list_head list; 104 96 struct list_head purgeable; 105 97 } objects; 98 + 99 + size_t chunk_size; 100 + unsigned int max_order; 101 + bool is_range_manager; 102 + 103 + void *region_private; 106 104 }; 107 105 108 106 struct intel_memory_region * 109 107 intel_memory_region_lookup(struct drm_i915_private *i915, 110 108 u16 class, u16 instance); 111 - 112 - int intel_memory_region_init_buddy(struct intel_memory_region *mem); 113 - void intel_memory_region_release_buddy(struct intel_memory_region *mem); 114 - 115 - int __intel_memory_region_get_pages_buddy(struct intel_memory_region *mem, 116 - resource_size_t size, 117 - unsigned int flags, 118 - struct list_head *blocks); 119 - struct i915_buddy_block * 120 - __intel_memory_region_get_block_buddy(struct intel_memory_region *mem, 121 - resource_size_t size, 122 - unsigned int flags); 123 - void __intel_memory_region_put_pages_buddy(struct intel_memory_region *mem, 124 - struct list_head *blocks); 125 - void __intel_memory_region_put_block_buddy(struct i915_buddy_block *block); 126 - 127 - int intel_memory_region_reserve(struct intel_memory_region *mem, 128 - u64 offset, u64 size); 129 109 130 110 struct intel_memory_region * 131 111 intel_memory_region_create(struct drm_i915_private *i915, ··· 121 125 resource_size_t size, 122 126 resource_size_t min_page_size, 123 127 resource_size_t io_start, 128 + u16 type, 129 + u16 instance, 124 130 const struct intel_memory_region_ops *ops); 125 131 126 132 struct intel_memory_region * ··· 139 141 intel_memory_region_set_name(struct intel_memory_region *mem, 140 142 const char *fmt, ...); 141 143 144 + void intel_memory_region_unreserve(struct intel_memory_region *mem); 145 + 146 + int intel_memory_region_reserve(struct intel_memory_region *mem, 147 + resource_size_t offset, 148 + resource_size_t size); 142 149 #endif
+226
drivers/gpu/drm/i915/intel_region_ttm.c
··· 1 + // SPDX-License-Identifier: MIT 2 + /* 3 + * Copyright © 2021 Intel Corporation 4 + */ 5 + #include <drm/ttm/ttm_bo_driver.h> 6 + #include <drm/ttm/ttm_device.h> 7 + #include <drm/ttm/ttm_range_manager.h> 8 + 9 + #include "i915_drv.h" 10 + #include "i915_scatterlist.h" 11 + 12 + #include "intel_region_ttm.h" 13 + 14 + /** 15 + * DOC: TTM support structure 16 + * 17 + * The code in this file deals with setting up memory managers for TTM 18 + * LMEM and MOCK regions and converting the output from 19 + * the managers to struct sg_table, Basically providing the mapping from 20 + * i915 GEM regions to TTM memory types and resource managers. 21 + */ 22 + 23 + /* A Zero-initialized driver for now. We don't have a TTM backend yet. */ 24 + static struct ttm_device_funcs i915_ttm_bo_driver; 25 + 26 + /** 27 + * intel_region_ttm_device_init - Initialize a TTM device 28 + * @dev_priv: Pointer to an i915 device private structure. 29 + * 30 + * Return: 0 on success, negative error code on failure. 31 + */ 32 + int intel_region_ttm_device_init(struct drm_i915_private *dev_priv) 33 + { 34 + struct drm_device *drm = &dev_priv->drm; 35 + 36 + return ttm_device_init(&dev_priv->bdev, &i915_ttm_bo_driver, 37 + drm->dev, drm->anon_inode->i_mapping, 38 + drm->vma_offset_manager, false, false); 39 + } 40 + 41 + /** 42 + * intel_region_ttm_device_fini - Finalize a TTM device 43 + * @dev_priv: Pointer to an i915 device private structure. 44 + */ 45 + void intel_region_ttm_device_fini(struct drm_i915_private *dev_priv) 46 + { 47 + ttm_device_fini(&dev_priv->bdev); 48 + } 49 + 50 + /* 51 + * Map the i915 memory regions to TTM memory types. We use the 52 + * driver-private types for now, reserving TTM_PL_VRAM for stolen 53 + * memory and TTM_PL_TT for GGTT use if decided to implement this. 54 + */ 55 + static int intel_region_to_ttm_type(struct intel_memory_region *mem) 56 + { 57 + int type; 58 + 59 + GEM_BUG_ON(mem->type != INTEL_MEMORY_LOCAL && 60 + mem->type != INTEL_MEMORY_MOCK); 61 + 62 + type = mem->instance + TTM_PL_PRIV; 63 + GEM_BUG_ON(type >= TTM_NUM_MEM_TYPES); 64 + 65 + return type; 66 + } 67 + 68 + static struct ttm_resource * 69 + intel_region_ttm_node_reserve(struct intel_memory_region *mem, 70 + resource_size_t offset, 71 + resource_size_t size) 72 + { 73 + struct ttm_resource_manager *man = mem->region_private; 74 + struct ttm_place place = {}; 75 + struct ttm_buffer_object mock_bo = {}; 76 + struct ttm_resource *res; 77 + int ret; 78 + 79 + /* 80 + * Having to use a mock_bo is unfortunate but stems from some 81 + * drivers having private managers that insist to know what the 82 + * allocate memory is intended for, using it to send private 83 + * data to the manager. Also recently the bo has been used to send 84 + * alignment info to the manager. Assume that apart from the latter, 85 + * none of the managers we use will ever access the buffer object 86 + * members, hoping we can pass the alignment info in the 87 + * struct ttm_place in the future. 88 + */ 89 + 90 + place.fpfn = offset >> PAGE_SHIFT; 91 + place.lpfn = place.fpfn + (size >> PAGE_SHIFT); 92 + mock_bo.base.size = size; 93 + ret = man->func->alloc(man, &mock_bo, &place, &res); 94 + if (ret == -ENOSPC) 95 + ret = -ENXIO; 96 + 97 + return ret ? ERR_PTR(ret) : res; 98 + } 99 + 100 + /** 101 + * intel_region_ttm_node_free - Free a node allocated from a resource manager 102 + * @mem: The region the node was allocated from. 103 + * @node: The opaque node representing an allocation. 104 + */ 105 + void intel_region_ttm_node_free(struct intel_memory_region *mem, 106 + struct ttm_resource *res) 107 + { 108 + struct ttm_resource_manager *man = mem->region_private; 109 + 110 + man->func->free(man, res); 111 + } 112 + 113 + static const struct intel_memory_region_private_ops priv_ops = { 114 + .reserve = intel_region_ttm_node_reserve, 115 + .free = intel_region_ttm_node_free, 116 + }; 117 + 118 + int intel_region_ttm_init(struct intel_memory_region *mem) 119 + { 120 + struct ttm_device *bdev = &mem->i915->bdev; 121 + int mem_type = intel_region_to_ttm_type(mem); 122 + int ret; 123 + 124 + ret = ttm_range_man_init(bdev, mem_type, false, 125 + resource_size(&mem->region) >> PAGE_SHIFT); 126 + if (ret) 127 + return ret; 128 + 129 + mem->chunk_size = PAGE_SIZE; 130 + mem->max_order = 131 + get_order(rounddown_pow_of_two(resource_size(&mem->region))); 132 + mem->is_range_manager = true; 133 + mem->priv_ops = &priv_ops; 134 + mem->region_private = ttm_manager_type(bdev, mem_type); 135 + 136 + return 0; 137 + } 138 + 139 + /** 140 + * intel_region_ttm_fini - Finalize a TTM region. 141 + * @mem: The memory region 142 + * 143 + * This functions takes down the TTM resource manager associated with the 144 + * memory region, and if it was registered with the TTM device, 145 + * removes that registration. 146 + */ 147 + void intel_region_ttm_fini(struct intel_memory_region *mem) 148 + { 149 + int ret; 150 + 151 + ret = ttm_range_man_fini(&mem->i915->bdev, 152 + intel_region_to_ttm_type(mem)); 153 + GEM_WARN_ON(ret); 154 + mem->region_private = NULL; 155 + } 156 + 157 + /** 158 + * intel_region_ttm_node_to_st - Convert an opaque TTM resource manager node 159 + * to an sg_table. 160 + * @mem: The memory region. 161 + * @node: The resource manager node obtained from the TTM resource manager. 162 + * 163 + * The gem backends typically use sg-tables for operations on the underlying 164 + * io_memory. So provide a way for the backends to translate the 165 + * nodes they are handed from TTM to sg-tables. 166 + * 167 + * Return: A malloced sg_table on success, an error pointer on failure. 168 + */ 169 + struct sg_table *intel_region_ttm_node_to_st(struct intel_memory_region *mem, 170 + struct ttm_resource *res) 171 + { 172 + struct ttm_range_mgr_node *range_node = 173 + container_of(res, typeof(*range_node), base); 174 + 175 + GEM_WARN_ON(!mem->is_range_manager); 176 + return i915_sg_from_mm_node(&range_node->mm_nodes[0], 177 + mem->region.start); 178 + } 179 + 180 + /** 181 + * intel_region_ttm_node_alloc - Allocate memory resources from a region 182 + * @mem: The memory region, 183 + * @size: The requested size in bytes 184 + * @flags: Allocation flags 185 + * 186 + * This functionality is provided only for callers that need to allocate 187 + * memory from standalone TTM range managers, without the TTM eviction 188 + * functionality. Don't use if you are not completely sure that's the 189 + * case. The returned opaque node can be converted to an sg_table using 190 + * intel_region_ttm_node_to_st(), and can be freed using 191 + * intel_region_ttm_node_free(). 192 + * 193 + * Return: A valid pointer on success, an error pointer on failure. 194 + */ 195 + struct ttm_resource * 196 + intel_region_ttm_node_alloc(struct intel_memory_region *mem, 197 + resource_size_t size, 198 + unsigned int flags) 199 + { 200 + struct ttm_resource_manager *man = mem->region_private; 201 + struct ttm_place place = {}; 202 + struct ttm_buffer_object mock_bo = {}; 203 + struct ttm_resource *res; 204 + int ret; 205 + 206 + /* 207 + * We ignore the flags for now since we're using the range 208 + * manager and contigous and min page size would be fulfilled 209 + * by default if size is min page size aligned. 210 + */ 211 + mock_bo.base.size = size; 212 + 213 + if (mem->is_range_manager) { 214 + if (size >= SZ_1G) 215 + mock_bo.page_alignment = SZ_1G >> PAGE_SHIFT; 216 + else if (size >= SZ_2M) 217 + mock_bo.page_alignment = SZ_2M >> PAGE_SHIFT; 218 + else if (size >= SZ_64K) 219 + mock_bo.page_alignment = SZ_64K >> PAGE_SHIFT; 220 + } 221 + 222 + ret = man->func->alloc(man, &mock_bo, &place, &res); 223 + if (ret == -ENOSPC) 224 + ret = -ENXIO; 225 + return ret ? ERR_PTR(ret) : res; 226 + }
+34
drivers/gpu/drm/i915/intel_region_ttm.h
··· 1 + /* SPDX-License-Identifier: MIT */ 2 + /* 3 + * Copyright © 2021 Intel Corporation 4 + */ 5 + #ifndef _INTEL_REGION_TTM_H_ 6 + #define _INTEL_REGION_TTM_H_ 7 + 8 + #include <linux/types.h> 9 + 10 + #include "i915_selftest.h" 11 + 12 + struct drm_i915_private; 13 + struct intel_memory_region; 14 + struct ttm_resource; 15 + 16 + int intel_region_ttm_device_init(struct drm_i915_private *dev_priv); 17 + 18 + void intel_region_ttm_device_fini(struct drm_i915_private *dev_priv); 19 + 20 + int intel_region_ttm_init(struct intel_memory_region *mem); 21 + 22 + void intel_region_ttm_fini(struct intel_memory_region *mem); 23 + 24 + struct sg_table *intel_region_ttm_node_to_st(struct intel_memory_region *mem, 25 + struct ttm_resource *res); 26 + 27 + struct ttm_resource * 28 + intel_region_ttm_node_alloc(struct intel_memory_region *mem, 29 + resource_size_t size, 30 + unsigned int flags); 31 + 32 + void intel_region_ttm_node_free(struct intel_memory_region *mem, 33 + struct ttm_resource *node); 34 + #endif /* _INTEL_REGION_TTM_H_ */
-789
drivers/gpu/drm/i915/selftests/i915_buddy.c
··· 1 - // SPDX-License-Identifier: MIT 2 - /* 3 - * Copyright © 2019 Intel Corporation 4 - */ 5 - 6 - #include <linux/prime_numbers.h> 7 - 8 - #include "../i915_selftest.h" 9 - #include "i915_random.h" 10 - 11 - static void __igt_dump_block(struct i915_buddy_mm *mm, 12 - struct i915_buddy_block *block, 13 - bool buddy) 14 - { 15 - pr_err("block info: header=%llx, state=%u, order=%d, offset=%llx size=%llx root=%s buddy=%s\n", 16 - block->header, 17 - i915_buddy_block_state(block), 18 - i915_buddy_block_order(block), 19 - i915_buddy_block_offset(block), 20 - i915_buddy_block_size(mm, block), 21 - yesno(!block->parent), 22 - yesno(buddy)); 23 - } 24 - 25 - static void igt_dump_block(struct i915_buddy_mm *mm, 26 - struct i915_buddy_block *block) 27 - { 28 - struct i915_buddy_block *buddy; 29 - 30 - __igt_dump_block(mm, block, false); 31 - 32 - buddy = get_buddy(block); 33 - if (buddy) 34 - __igt_dump_block(mm, buddy, true); 35 - } 36 - 37 - static int igt_check_block(struct i915_buddy_mm *mm, 38 - struct i915_buddy_block *block) 39 - { 40 - struct i915_buddy_block *buddy; 41 - unsigned int block_state; 42 - u64 block_size; 43 - u64 offset; 44 - int err = 0; 45 - 46 - block_state = i915_buddy_block_state(block); 47 - 48 - if (block_state != I915_BUDDY_ALLOCATED && 49 - block_state != I915_BUDDY_FREE && 50 - block_state != I915_BUDDY_SPLIT) { 51 - pr_err("block state mismatch\n"); 52 - err = -EINVAL; 53 - } 54 - 55 - block_size = i915_buddy_block_size(mm, block); 56 - offset = i915_buddy_block_offset(block); 57 - 58 - if (block_size < mm->chunk_size) { 59 - pr_err("block size smaller than min size\n"); 60 - err = -EINVAL; 61 - } 62 - 63 - if (!is_power_of_2(block_size)) { 64 - pr_err("block size not power of two\n"); 65 - err = -EINVAL; 66 - } 67 - 68 - if (!IS_ALIGNED(block_size, mm->chunk_size)) { 69 - pr_err("block size not aligned to min size\n"); 70 - err = -EINVAL; 71 - } 72 - 73 - if (!IS_ALIGNED(offset, mm->chunk_size)) { 74 - pr_err("block offset not aligned to min size\n"); 75 - err = -EINVAL; 76 - } 77 - 78 - if (!IS_ALIGNED(offset, block_size)) { 79 - pr_err("block offset not aligned to block size\n"); 80 - err = -EINVAL; 81 - } 82 - 83 - buddy = get_buddy(block); 84 - 85 - if (!buddy && block->parent) { 86 - pr_err("buddy has gone fishing\n"); 87 - err = -EINVAL; 88 - } 89 - 90 - if (buddy) { 91 - if (i915_buddy_block_offset(buddy) != (offset ^ block_size)) { 92 - pr_err("buddy has wrong offset\n"); 93 - err = -EINVAL; 94 - } 95 - 96 - if (i915_buddy_block_size(mm, buddy) != block_size) { 97 - pr_err("buddy size mismatch\n"); 98 - err = -EINVAL; 99 - } 100 - 101 - if (i915_buddy_block_state(buddy) == block_state && 102 - block_state == I915_BUDDY_FREE) { 103 - pr_err("block and its buddy are free\n"); 104 - err = -EINVAL; 105 - } 106 - } 107 - 108 - return err; 109 - } 110 - 111 - static int igt_check_blocks(struct i915_buddy_mm *mm, 112 - struct list_head *blocks, 113 - u64 expected_size, 114 - bool is_contiguous) 115 - { 116 - struct i915_buddy_block *block; 117 - struct i915_buddy_block *prev; 118 - u64 total; 119 - int err = 0; 120 - 121 - block = NULL; 122 - prev = NULL; 123 - total = 0; 124 - 125 - list_for_each_entry(block, blocks, link) { 126 - err = igt_check_block(mm, block); 127 - 128 - if (!i915_buddy_block_is_allocated(block)) { 129 - pr_err("block not allocated\n"), 130 - err = -EINVAL; 131 - } 132 - 133 - if (is_contiguous && prev) { 134 - u64 prev_block_size; 135 - u64 prev_offset; 136 - u64 offset; 137 - 138 - prev_offset = i915_buddy_block_offset(prev); 139 - prev_block_size = i915_buddy_block_size(mm, prev); 140 - offset = i915_buddy_block_offset(block); 141 - 142 - if (offset != (prev_offset + prev_block_size)) { 143 - pr_err("block offset mismatch\n"); 144 - err = -EINVAL; 145 - } 146 - } 147 - 148 - if (err) 149 - break; 150 - 151 - total += i915_buddy_block_size(mm, block); 152 - prev = block; 153 - } 154 - 155 - if (!err) { 156 - if (total != expected_size) { 157 - pr_err("size mismatch, expected=%llx, found=%llx\n", 158 - expected_size, total); 159 - err = -EINVAL; 160 - } 161 - return err; 162 - } 163 - 164 - if (prev) { 165 - pr_err("prev block, dump:\n"); 166 - igt_dump_block(mm, prev); 167 - } 168 - 169 - if (block) { 170 - pr_err("bad block, dump:\n"); 171 - igt_dump_block(mm, block); 172 - } 173 - 174 - return err; 175 - } 176 - 177 - static int igt_check_mm(struct i915_buddy_mm *mm) 178 - { 179 - struct i915_buddy_block *root; 180 - struct i915_buddy_block *prev; 181 - unsigned int i; 182 - u64 total; 183 - int err = 0; 184 - 185 - if (!mm->n_roots) { 186 - pr_err("n_roots is zero\n"); 187 - return -EINVAL; 188 - } 189 - 190 - if (mm->n_roots != hweight64(mm->size)) { 191 - pr_err("n_roots mismatch, n_roots=%u, expected=%lu\n", 192 - mm->n_roots, hweight64(mm->size)); 193 - return -EINVAL; 194 - } 195 - 196 - root = NULL; 197 - prev = NULL; 198 - total = 0; 199 - 200 - for (i = 0; i < mm->n_roots; ++i) { 201 - struct i915_buddy_block *block; 202 - unsigned int order; 203 - 204 - root = mm->roots[i]; 205 - if (!root) { 206 - pr_err("root(%u) is NULL\n", i); 207 - err = -EINVAL; 208 - break; 209 - } 210 - 211 - err = igt_check_block(mm, root); 212 - 213 - if (!i915_buddy_block_is_free(root)) { 214 - pr_err("root not free\n"); 215 - err = -EINVAL; 216 - } 217 - 218 - order = i915_buddy_block_order(root); 219 - 220 - if (!i) { 221 - if (order != mm->max_order) { 222 - pr_err("max order root missing\n"); 223 - err = -EINVAL; 224 - } 225 - } 226 - 227 - if (prev) { 228 - u64 prev_block_size; 229 - u64 prev_offset; 230 - u64 offset; 231 - 232 - prev_offset = i915_buddy_block_offset(prev); 233 - prev_block_size = i915_buddy_block_size(mm, prev); 234 - offset = i915_buddy_block_offset(root); 235 - 236 - if (offset != (prev_offset + prev_block_size)) { 237 - pr_err("root offset mismatch\n"); 238 - err = -EINVAL; 239 - } 240 - } 241 - 242 - block = list_first_entry_or_null(&mm->free_list[order], 243 - struct i915_buddy_block, 244 - link); 245 - if (block != root) { 246 - pr_err("root mismatch at order=%u\n", order); 247 - err = -EINVAL; 248 - } 249 - 250 - if (err) 251 - break; 252 - 253 - prev = root; 254 - total += i915_buddy_block_size(mm, root); 255 - } 256 - 257 - if (!err) { 258 - if (total != mm->size) { 259 - pr_err("expected mm size=%llx, found=%llx\n", mm->size, 260 - total); 261 - err = -EINVAL; 262 - } 263 - return err; 264 - } 265 - 266 - if (prev) { 267 - pr_err("prev root(%u), dump:\n", i - 1); 268 - igt_dump_block(mm, prev); 269 - } 270 - 271 - if (root) { 272 - pr_err("bad root(%u), dump:\n", i); 273 - igt_dump_block(mm, root); 274 - } 275 - 276 - return err; 277 - } 278 - 279 - static void igt_mm_config(u64 *size, u64 *chunk_size) 280 - { 281 - I915_RND_STATE(prng); 282 - u32 s, ms; 283 - 284 - /* Nothing fancy, just try to get an interesting bit pattern */ 285 - 286 - prandom_seed_state(&prng, i915_selftest.random_seed); 287 - 288 - /* Let size be a random number of pages up to 8 GB (2M pages) */ 289 - s = 1 + i915_prandom_u32_max_state((BIT(33 - 12)) - 1, &prng); 290 - /* Let the chunk size be a random power of 2 less than size */ 291 - ms = BIT(i915_prandom_u32_max_state(ilog2(s), &prng)); 292 - /* Round size down to the chunk size */ 293 - s &= -ms; 294 - 295 - /* Convert from pages to bytes */ 296 - *chunk_size = (u64)ms << 12; 297 - *size = (u64)s << 12; 298 - } 299 - 300 - static int igt_buddy_alloc_smoke(void *arg) 301 - { 302 - struct i915_buddy_mm mm; 303 - IGT_TIMEOUT(end_time); 304 - I915_RND_STATE(prng); 305 - u64 chunk_size; 306 - u64 mm_size; 307 - int *order; 308 - int err, i; 309 - 310 - igt_mm_config(&mm_size, &chunk_size); 311 - 312 - pr_info("buddy_init with size=%llx, chunk_size=%llx\n", mm_size, chunk_size); 313 - 314 - err = i915_buddy_init(&mm, mm_size, chunk_size); 315 - if (err) { 316 - pr_err("buddy_init failed(%d)\n", err); 317 - return err; 318 - } 319 - 320 - order = i915_random_order(mm.max_order + 1, &prng); 321 - if (!order) 322 - goto out_fini; 323 - 324 - for (i = 0; i <= mm.max_order; ++i) { 325 - struct i915_buddy_block *block; 326 - int max_order = order[i]; 327 - bool timeout = false; 328 - LIST_HEAD(blocks); 329 - int order; 330 - u64 total; 331 - 332 - err = igt_check_mm(&mm); 333 - if (err) { 334 - pr_err("pre-mm check failed, abort\n"); 335 - break; 336 - } 337 - 338 - pr_info("filling from max_order=%u\n", max_order); 339 - 340 - order = max_order; 341 - total = 0; 342 - 343 - do { 344 - retry: 345 - block = i915_buddy_alloc(&mm, order); 346 - if (IS_ERR(block)) { 347 - err = PTR_ERR(block); 348 - if (err == -ENOMEM) { 349 - pr_info("buddy_alloc hit -ENOMEM with order=%d\n", 350 - order); 351 - } else { 352 - if (order--) { 353 - err = 0; 354 - goto retry; 355 - } 356 - 357 - pr_err("buddy_alloc with order=%d failed(%d)\n", 358 - order, err); 359 - } 360 - 361 - break; 362 - } 363 - 364 - list_add_tail(&block->link, &blocks); 365 - 366 - if (i915_buddy_block_order(block) != order) { 367 - pr_err("buddy_alloc order mismatch\n"); 368 - err = -EINVAL; 369 - break; 370 - } 371 - 372 - total += i915_buddy_block_size(&mm, block); 373 - 374 - if (__igt_timeout(end_time, NULL)) { 375 - timeout = true; 376 - break; 377 - } 378 - } while (total < mm.size); 379 - 380 - if (!err) 381 - err = igt_check_blocks(&mm, &blocks, total, false); 382 - 383 - i915_buddy_free_list(&mm, &blocks); 384 - 385 - if (!err) { 386 - err = igt_check_mm(&mm); 387 - if (err) 388 - pr_err("post-mm check failed\n"); 389 - } 390 - 391 - if (err || timeout) 392 - break; 393 - 394 - cond_resched(); 395 - } 396 - 397 - if (err == -ENOMEM) 398 - err = 0; 399 - 400 - kfree(order); 401 - out_fini: 402 - i915_buddy_fini(&mm); 403 - 404 - return err; 405 - } 406 - 407 - static int igt_buddy_alloc_pessimistic(void *arg) 408 - { 409 - const unsigned int max_order = 16; 410 - struct i915_buddy_block *block, *bn; 411 - struct i915_buddy_mm mm; 412 - unsigned int order; 413 - LIST_HEAD(blocks); 414 - int err; 415 - 416 - /* 417 - * Create a pot-sized mm, then allocate one of each possible 418 - * order within. This should leave the mm with exactly one 419 - * page left. 420 - */ 421 - 422 - err = i915_buddy_init(&mm, PAGE_SIZE << max_order, PAGE_SIZE); 423 - if (err) { 424 - pr_err("buddy_init failed(%d)\n", err); 425 - return err; 426 - } 427 - GEM_BUG_ON(mm.max_order != max_order); 428 - 429 - for (order = 0; order < max_order; order++) { 430 - block = i915_buddy_alloc(&mm, order); 431 - if (IS_ERR(block)) { 432 - pr_info("buddy_alloc hit -ENOMEM with order=%d\n", 433 - order); 434 - err = PTR_ERR(block); 435 - goto err; 436 - } 437 - 438 - list_add_tail(&block->link, &blocks); 439 - } 440 - 441 - /* And now the last remaining block available */ 442 - block = i915_buddy_alloc(&mm, 0); 443 - if (IS_ERR(block)) { 444 - pr_info("buddy_alloc hit -ENOMEM on final alloc\n"); 445 - err = PTR_ERR(block); 446 - goto err; 447 - } 448 - list_add_tail(&block->link, &blocks); 449 - 450 - /* Should be completely full! */ 451 - for (order = max_order; order--; ) { 452 - block = i915_buddy_alloc(&mm, order); 453 - if (!IS_ERR(block)) { 454 - pr_info("buddy_alloc unexpectedly succeeded at order %d, it should be full!", 455 - order); 456 - list_add_tail(&block->link, &blocks); 457 - err = -EINVAL; 458 - goto err; 459 - } 460 - } 461 - 462 - block = list_last_entry(&blocks, typeof(*block), link); 463 - list_del(&block->link); 464 - i915_buddy_free(&mm, block); 465 - 466 - /* As we free in increasing size, we make available larger blocks */ 467 - order = 1; 468 - list_for_each_entry_safe(block, bn, &blocks, link) { 469 - list_del(&block->link); 470 - i915_buddy_free(&mm, block); 471 - 472 - block = i915_buddy_alloc(&mm, order); 473 - if (IS_ERR(block)) { 474 - pr_info("buddy_alloc (realloc) hit -ENOMEM with order=%d\n", 475 - order); 476 - err = PTR_ERR(block); 477 - goto err; 478 - } 479 - i915_buddy_free(&mm, block); 480 - order++; 481 - } 482 - 483 - /* To confirm, now the whole mm should be available */ 484 - block = i915_buddy_alloc(&mm, max_order); 485 - if (IS_ERR(block)) { 486 - pr_info("buddy_alloc (realloc) hit -ENOMEM with order=%d\n", 487 - max_order); 488 - err = PTR_ERR(block); 489 - goto err; 490 - } 491 - i915_buddy_free(&mm, block); 492 - 493 - err: 494 - i915_buddy_free_list(&mm, &blocks); 495 - i915_buddy_fini(&mm); 496 - return err; 497 - } 498 - 499 - static int igt_buddy_alloc_optimistic(void *arg) 500 - { 501 - const int max_order = 16; 502 - struct i915_buddy_block *block; 503 - struct i915_buddy_mm mm; 504 - LIST_HEAD(blocks); 505 - int order; 506 - int err; 507 - 508 - /* 509 - * Create a mm with one block of each order available, and 510 - * try to allocate them all. 511 - */ 512 - 513 - err = i915_buddy_init(&mm, 514 - PAGE_SIZE * ((1 << (max_order + 1)) - 1), 515 - PAGE_SIZE); 516 - if (err) { 517 - pr_err("buddy_init failed(%d)\n", err); 518 - return err; 519 - } 520 - GEM_BUG_ON(mm.max_order != max_order); 521 - 522 - for (order = 0; order <= max_order; order++) { 523 - block = i915_buddy_alloc(&mm, order); 524 - if (IS_ERR(block)) { 525 - pr_info("buddy_alloc hit -ENOMEM with order=%d\n", 526 - order); 527 - err = PTR_ERR(block); 528 - goto err; 529 - } 530 - 531 - list_add_tail(&block->link, &blocks); 532 - } 533 - 534 - /* Should be completely full! */ 535 - block = i915_buddy_alloc(&mm, 0); 536 - if (!IS_ERR(block)) { 537 - pr_info("buddy_alloc unexpectedly succeeded, it should be full!"); 538 - list_add_tail(&block->link, &blocks); 539 - err = -EINVAL; 540 - goto err; 541 - } 542 - 543 - err: 544 - i915_buddy_free_list(&mm, &blocks); 545 - i915_buddy_fini(&mm); 546 - return err; 547 - } 548 - 549 - static int igt_buddy_alloc_pathological(void *arg) 550 - { 551 - const int max_order = 16; 552 - struct i915_buddy_block *block; 553 - struct i915_buddy_mm mm; 554 - LIST_HEAD(blocks); 555 - LIST_HEAD(holes); 556 - int order, top; 557 - int err; 558 - 559 - /* 560 - * Create a pot-sized mm, then allocate one of each possible 561 - * order within. This should leave the mm with exactly one 562 - * page left. Free the largest block, then whittle down again. 563 - * Eventually we will have a fully 50% fragmented mm. 564 - */ 565 - 566 - err = i915_buddy_init(&mm, PAGE_SIZE << max_order, PAGE_SIZE); 567 - if (err) { 568 - pr_err("buddy_init failed(%d)\n", err); 569 - return err; 570 - } 571 - GEM_BUG_ON(mm.max_order != max_order); 572 - 573 - for (top = max_order; top; top--) { 574 - /* Make room by freeing the largest allocated block */ 575 - block = list_first_entry_or_null(&blocks, typeof(*block), link); 576 - if (block) { 577 - list_del(&block->link); 578 - i915_buddy_free(&mm, block); 579 - } 580 - 581 - for (order = top; order--; ) { 582 - block = i915_buddy_alloc(&mm, order); 583 - if (IS_ERR(block)) { 584 - pr_info("buddy_alloc hit -ENOMEM with order=%d, top=%d\n", 585 - order, top); 586 - err = PTR_ERR(block); 587 - goto err; 588 - } 589 - list_add_tail(&block->link, &blocks); 590 - } 591 - 592 - /* There should be one final page for this sub-allocation */ 593 - block = i915_buddy_alloc(&mm, 0); 594 - if (IS_ERR(block)) { 595 - pr_info("buddy_alloc hit -ENOMEM for hole\n"); 596 - err = PTR_ERR(block); 597 - goto err; 598 - } 599 - list_add_tail(&block->link, &holes); 600 - 601 - block = i915_buddy_alloc(&mm, top); 602 - if (!IS_ERR(block)) { 603 - pr_info("buddy_alloc unexpectedly succeeded at top-order %d/%d, it should be full!", 604 - top, max_order); 605 - list_add_tail(&block->link, &blocks); 606 - err = -EINVAL; 607 - goto err; 608 - } 609 - } 610 - 611 - i915_buddy_free_list(&mm, &holes); 612 - 613 - /* Nothing larger than blocks of chunk_size now available */ 614 - for (order = 1; order <= max_order; order++) { 615 - block = i915_buddy_alloc(&mm, order); 616 - if (!IS_ERR(block)) { 617 - pr_info("buddy_alloc unexpectedly succeeded at order %d, it should be full!", 618 - order); 619 - list_add_tail(&block->link, &blocks); 620 - err = -EINVAL; 621 - goto err; 622 - } 623 - } 624 - 625 - err: 626 - list_splice_tail(&holes, &blocks); 627 - i915_buddy_free_list(&mm, &blocks); 628 - i915_buddy_fini(&mm); 629 - return err; 630 - } 631 - 632 - static int igt_buddy_alloc_range(void *arg) 633 - { 634 - struct i915_buddy_mm mm; 635 - unsigned long page_num; 636 - LIST_HEAD(blocks); 637 - u64 chunk_size; 638 - u64 offset; 639 - u64 size; 640 - u64 rem; 641 - int err; 642 - 643 - igt_mm_config(&size, &chunk_size); 644 - 645 - pr_info("buddy_init with size=%llx, chunk_size=%llx\n", size, chunk_size); 646 - 647 - err = i915_buddy_init(&mm, size, chunk_size); 648 - if (err) { 649 - pr_err("buddy_init failed(%d)\n", err); 650 - return err; 651 - } 652 - 653 - err = igt_check_mm(&mm); 654 - if (err) { 655 - pr_err("pre-mm check failed, abort, abort, abort!\n"); 656 - goto err_fini; 657 - } 658 - 659 - rem = mm.size; 660 - offset = 0; 661 - 662 - for_each_prime_number_from(page_num, 1, ULONG_MAX - 1) { 663 - struct i915_buddy_block *block; 664 - LIST_HEAD(tmp); 665 - 666 - size = min(page_num * mm.chunk_size, rem); 667 - 668 - err = i915_buddy_alloc_range(&mm, &tmp, offset, size); 669 - if (err) { 670 - if (err == -ENOMEM) { 671 - pr_info("alloc_range hit -ENOMEM with size=%llx\n", 672 - size); 673 - } else { 674 - pr_err("alloc_range with offset=%llx, size=%llx failed(%d)\n", 675 - offset, size, err); 676 - } 677 - 678 - break; 679 - } 680 - 681 - block = list_first_entry_or_null(&tmp, 682 - struct i915_buddy_block, 683 - link); 684 - if (!block) { 685 - pr_err("alloc_range has no blocks\n"); 686 - err = -EINVAL; 687 - break; 688 - } 689 - 690 - if (i915_buddy_block_offset(block) != offset) { 691 - pr_err("alloc_range start offset mismatch, found=%llx, expected=%llx\n", 692 - i915_buddy_block_offset(block), offset); 693 - err = -EINVAL; 694 - } 695 - 696 - if (!err) 697 - err = igt_check_blocks(&mm, &tmp, size, true); 698 - 699 - list_splice_tail(&tmp, &blocks); 700 - 701 - if (err) 702 - break; 703 - 704 - offset += size; 705 - 706 - rem -= size; 707 - if (!rem) 708 - break; 709 - 710 - cond_resched(); 711 - } 712 - 713 - if (err == -ENOMEM) 714 - err = 0; 715 - 716 - i915_buddy_free_list(&mm, &blocks); 717 - 718 - if (!err) { 719 - err = igt_check_mm(&mm); 720 - if (err) 721 - pr_err("post-mm check failed\n"); 722 - } 723 - 724 - err_fini: 725 - i915_buddy_fini(&mm); 726 - 727 - return err; 728 - } 729 - 730 - static int igt_buddy_alloc_limit(void *arg) 731 - { 732 - struct i915_buddy_block *block; 733 - struct i915_buddy_mm mm; 734 - const u64 size = U64_MAX; 735 - int err; 736 - 737 - err = i915_buddy_init(&mm, size, PAGE_SIZE); 738 - if (err) 739 - return err; 740 - 741 - if (mm.max_order != I915_BUDDY_MAX_ORDER) { 742 - pr_err("mm.max_order(%d) != %d\n", 743 - mm.max_order, I915_BUDDY_MAX_ORDER); 744 - err = -EINVAL; 745 - goto out_fini; 746 - } 747 - 748 - block = i915_buddy_alloc(&mm, mm.max_order); 749 - if (IS_ERR(block)) { 750 - err = PTR_ERR(block); 751 - goto out_fini; 752 - } 753 - 754 - if (i915_buddy_block_order(block) != mm.max_order) { 755 - pr_err("block order(%d) != %d\n", 756 - i915_buddy_block_order(block), mm.max_order); 757 - err = -EINVAL; 758 - goto out_free; 759 - } 760 - 761 - if (i915_buddy_block_size(&mm, block) != 762 - BIT_ULL(mm.max_order) * PAGE_SIZE) { 763 - pr_err("block size(%llu) != %llu\n", 764 - i915_buddy_block_size(&mm, block), 765 - BIT_ULL(mm.max_order) * PAGE_SIZE); 766 - err = -EINVAL; 767 - goto out_free; 768 - } 769 - 770 - out_free: 771 - i915_buddy_free(&mm, block); 772 - out_fini: 773 - i915_buddy_fini(&mm); 774 - return err; 775 - } 776 - 777 - int i915_buddy_mock_selftests(void) 778 - { 779 - static const struct i915_subtest tests[] = { 780 - SUBTEST(igt_buddy_alloc_pessimistic), 781 - SUBTEST(igt_buddy_alloc_optimistic), 782 - SUBTEST(igt_buddy_alloc_pathological), 783 - SUBTEST(igt_buddy_alloc_smoke), 784 - SUBTEST(igt_buddy_alloc_range), 785 - SUBTEST(igt_buddy_alloc_limit), 786 - }; 787 - 788 - return i915_subtests(tests, NULL); 789 - }
-1
drivers/gpu/drm/i915/selftests/i915_mock_selftests.h
··· 33 33 selftest(gtt, i915_gem_gtt_mock_selftests) 34 34 selftest(hugepages, i915_gem_huge_page_mock_selftests) 35 35 selftest(contexts, i915_gem_context_mock_selftests) 36 - selftest(buddy, i915_buddy_mock_selftests) 37 36 selftest(memory_region, intel_memory_region_mock_selftests)
+2 -2
drivers/gpu/drm/i915/selftests/i915_request.c
··· 1592 1592 1593 1593 for (n = 0; n < smoke[0].ncontexts; n++) { 1594 1594 smoke[0].contexts[n] = live_context(i915, file); 1595 - if (!smoke[0].contexts[n]) { 1596 - ret = -ENOMEM; 1595 + if (IS_ERR(smoke[0].contexts[n])) { 1596 + ret = PTR_ERR(smoke[0].contexts[n]); 1597 1597 goto out_contexts; 1598 1598 } 1599 1599 }
+40 -93
drivers/gpu/drm/i915/selftests/intel_memory_region.c
··· 57 57 LIST_HEAD(objects); 58 58 int err = 0; 59 59 60 - page_size = mem->mm.chunk_size; 61 - max_pages = div64_u64(total, page_size); 60 + page_size = mem->chunk_size; 62 61 rem = total; 62 + retry: 63 + max_pages = div64_u64(rem, page_size); 63 64 64 65 for_each_prime_number_from(page_num, 1, max_pages) { 65 66 resource_size_t size = page_num * page_size; ··· 86 85 err = 0; 87 86 if (err == -ENXIO) { 88 87 if (page_num * page_size <= rem) { 88 + if (mem->is_range_manager && max_pages > 1) { 89 + max_pages >>= 1; 90 + goto retry; 91 + } 92 + 89 93 pr_err("%s failed, space still left in region\n", 90 94 __func__); 91 95 err = -EINVAL; ··· 205 199 do { 206 200 u32 size = i915_prandom_u32_max_state(cur_avail, &prng); 207 201 202 + retry: 208 203 size = max_t(u32, round_up(size, PAGE_SIZE), PAGE_SIZE); 209 204 obj = igt_object_create(mem, &objects, size, 0); 210 205 if (IS_ERR(obj)) { 211 - if (PTR_ERR(obj) == -ENXIO) 206 + if (PTR_ERR(obj) == -ENXIO) { 207 + if (mem->is_range_manager && 208 + size > mem->chunk_size) { 209 + size >>= 1; 210 + goto retry; 211 + } 212 212 break; 213 - 213 + } 214 214 err = PTR_ERR(obj); 215 215 goto out_close; 216 216 } ··· 232 220 out_close: 233 221 kfree(order); 234 222 close_objects(mem, &objects); 235 - i915_buddy_free_list(&mem->mm, &mem->reserved); 223 + intel_memory_region_unreserve(mem); 236 224 return err; 237 225 } 238 226 ··· 252 240 total = resource_size(&mem->region); 253 241 254 242 /* Min size */ 255 - obj = igt_object_create(mem, &objects, mem->mm.chunk_size, 243 + obj = igt_object_create(mem, &objects, mem->chunk_size, 256 244 I915_BO_ALLOC_CONTIGUOUS); 257 245 if (IS_ERR(obj)) 258 246 return PTR_ERR(obj); ··· 333 321 min = target; 334 322 target = total >> 1; 335 323 336 - /* Make sure we can still allocate all the fragmented space */ 337 - obj = igt_object_create(mem, &objects, target, 0); 338 - if (IS_ERR(obj)) { 339 - err = PTR_ERR(obj); 340 - goto err_close_objects; 341 - } 324 + if (!mem->is_range_manager) { 325 + /* Make sure we can still allocate all the fragmented space */ 326 + obj = igt_object_create(mem, &objects, target, 0); 327 + if (IS_ERR(obj)) { 328 + err = PTR_ERR(obj); 329 + goto err_close_objects; 330 + } 342 331 343 - igt_object_release(obj); 332 + igt_object_release(obj); 333 + } 344 334 345 335 /* 346 336 * Even though we have enough free space, we don't have a big enough ··· 362 348 } 363 349 364 350 target >>= 1; 365 - } while (target >= mem->mm.chunk_size); 351 + } while (target >= mem->chunk_size); 366 352 367 353 err_close_objects: 368 354 list_splice_tail(&holes, &objects); ··· 382 368 383 369 /* 384 370 * Sanity check we can still allocate everything even if the 385 - * mm.max_order != mm.size. i.e our starting address space size is not a 371 + * max_order != mm.size. i.e our starting address space size is not a 386 372 * power-of-two. 387 373 */ 388 374 ··· 391 377 if (IS_ERR(mem)) 392 378 return PTR_ERR(mem); 393 379 394 - if (mem->mm.size != size) { 395 - pr_err("%s size mismatch(%llu != %llu)\n", 396 - __func__, mem->mm.size, size); 397 - err = -EINVAL; 398 - goto out_put; 399 - } 400 - 401 380 expected_order = get_order(rounddown_pow_of_two(size)); 402 - if (mem->mm.max_order != expected_order) { 381 + if (mem->max_order != expected_order) { 403 382 pr_err("%s order mismatch(%u != %u)\n", 404 - __func__, mem->mm.max_order, expected_order); 383 + __func__, mem->max_order, expected_order); 405 384 err = -EINVAL; 406 385 goto out_put; 407 386 } ··· 415 408 * sure that does indeed hold true. 416 409 */ 417 410 418 - obj = igt_object_create(mem, &objects, size, I915_BO_ALLOC_CONTIGUOUS); 419 - if (!IS_ERR(obj)) { 420 - pr_err("%s too large contiguous allocation was not rejected\n", 421 - __func__); 422 - err = -EINVAL; 423 - goto out_close; 411 + if (!mem->is_range_manager) { 412 + obj = igt_object_create(mem, &objects, size, 413 + I915_BO_ALLOC_CONTIGUOUS); 414 + if (!IS_ERR(obj)) { 415 + pr_err("%s too large contiguous allocation was not rejected\n", 416 + __func__); 417 + err = -EINVAL; 418 + goto out_close; 419 + } 424 420 } 425 421 426 422 obj = igt_object_create(mem, &objects, rounddown_pow_of_two(size), ··· 433 423 __func__); 434 424 err = PTR_ERR(obj); 435 425 goto out_close; 436 - } 437 - 438 - out_close: 439 - close_objects(mem, &objects); 440 - out_put: 441 - intel_memory_region_put(mem); 442 - return err; 443 - } 444 - 445 - #ifndef SZ_8G 446 - #define SZ_8G BIT_ULL(33) 447 - #endif 448 - 449 - static int igt_mock_max_segment(void *arg) 450 - { 451 - const unsigned int max_segment = i915_sg_segment_size(); 452 - struct intel_memory_region *mem = arg; 453 - struct drm_i915_private *i915 = mem->i915; 454 - struct drm_i915_gem_object *obj; 455 - struct i915_buddy_block *block; 456 - struct scatterlist *sg; 457 - LIST_HEAD(objects); 458 - u64 size; 459 - int err = 0; 460 - 461 - /* 462 - * While we may create very large contiguous blocks, we may need 463 - * to break those down for consumption elsewhere. In particular, 464 - * dma-mapping with scatterlist elements have an implicit limit of 465 - * UINT_MAX on each element. 466 - */ 467 - 468 - size = SZ_8G; 469 - mem = mock_region_create(i915, 0, size, PAGE_SIZE, 0); 470 - if (IS_ERR(mem)) 471 - return PTR_ERR(mem); 472 - 473 - obj = igt_object_create(mem, &objects, size, 0); 474 - if (IS_ERR(obj)) { 475 - err = PTR_ERR(obj); 476 - goto out_put; 477 - } 478 - 479 - size = 0; 480 - list_for_each_entry(block, &obj->mm.blocks, link) { 481 - if (i915_buddy_block_size(&mem->mm, block) > size) 482 - size = i915_buddy_block_size(&mem->mm, block); 483 - } 484 - if (size < max_segment) { 485 - pr_err("%s: Failed to create a huge contiguous block [> %u], largest block %lld\n", 486 - __func__, max_segment, size); 487 - err = -EINVAL; 488 - goto out_close; 489 - } 490 - 491 - for (sg = obj->mm.pages->sgl; sg; sg = sg_next(sg)) { 492 - if (sg->length > max_segment) { 493 - pr_err("%s: Created an oversized scatterlist entry, %u > %u\n", 494 - __func__, sg->length, max_segment); 495 - err = -EINVAL; 496 - goto out_close; 497 - } 498 426 } 499 427 500 428 out_close: ··· 1046 1098 SUBTEST(igt_mock_fill), 1047 1099 SUBTEST(igt_mock_contiguous), 1048 1100 SUBTEST(igt_mock_splintered_region), 1049 - SUBTEST(igt_mock_max_segment), 1050 1101 }; 1051 1102 struct intel_memory_region *mem; 1052 1103 struct drm_i915_private *i915;
+10
drivers/gpu/drm/i915/selftests/mock_gem_device.c
··· 32 32 #include "gt/intel_gt_requests.h" 33 33 #include "gt/mock_engine.h" 34 34 #include "intel_memory_region.h" 35 + #include "intel_region_ttm.h" 35 36 36 37 #include "mock_request.h" 37 38 #include "mock_gem_device.h" ··· 71 70 mock_fini_ggtt(&i915->ggtt); 72 71 destroy_workqueue(i915->wq); 73 72 73 + intel_region_ttm_device_fini(i915); 74 74 intel_gt_driver_late_release(&i915->gt); 75 75 intel_memory_regions_driver_release(i915); 76 76 ··· 118 116 #endif 119 117 struct drm_i915_private *i915; 120 118 struct pci_dev *pdev; 119 + int ret; 121 120 122 121 pdev = kzalloc(sizeof(*pdev), GFP_KERNEL); 123 122 if (!pdev) ··· 181 178 atomic_inc(&i915->gt.wakeref.count); /* disable; no hw support */ 182 179 i915->gt.awake = -ENODEV; 183 180 181 + ret = intel_region_ttm_device_init(i915); 182 + if (ret) 183 + goto err_ttm; 184 + 184 185 i915->wq = alloc_ordered_workqueue("mock", 0); 185 186 if (!i915->wq) 186 187 goto err_drv; ··· 208 201 intel_engines_driver_register(i915); 209 202 210 203 i915->do_release = true; 204 + ida_init(&i915->selftest.mock_region_instances); 211 205 212 206 return i915; 213 207 ··· 217 209 err_unlock: 218 210 destroy_workqueue(i915->wq); 219 211 err_drv: 212 + intel_region_ttm_device_fini(i915); 213 + err_ttm: 220 214 intel_gt_driver_late_release(&i915->gt); 221 215 intel_memory_regions_driver_release(i915); 222 216 drm_mode_config_cleanup(&i915->drm);
+63 -7
drivers/gpu/drm/i915/selftests/mock_region.c
··· 1 1 // SPDX-License-Identifier: MIT 2 2 /* 3 - * Copyright © 2019 Intel Corporation 3 + * Copyright © 2019-2021 Intel Corporation 4 4 */ 5 + 6 + #include <linux/scatterlist.h> 7 + 8 + #include <drm/ttm/ttm_placement.h> 5 9 6 10 #include "gem/i915_gem_region.h" 7 11 #include "intel_memory_region.h" 12 + #include "intel_region_ttm.h" 8 13 9 14 #include "mock_region.h" 10 15 16 + static void mock_region_put_pages(struct drm_i915_gem_object *obj, 17 + struct sg_table *pages) 18 + { 19 + intel_region_ttm_node_free(obj->mm.region, obj->mm.st_mm_node); 20 + sg_free_table(pages); 21 + kfree(pages); 22 + } 23 + 24 + static int mock_region_get_pages(struct drm_i915_gem_object *obj) 25 + { 26 + unsigned int flags; 27 + struct sg_table *pages; 28 + 29 + flags = I915_ALLOC_MIN_PAGE_SIZE; 30 + if (obj->flags & I915_BO_ALLOC_CONTIGUOUS) 31 + flags |= I915_ALLOC_CONTIGUOUS; 32 + 33 + obj->mm.st_mm_node = intel_region_ttm_node_alloc(obj->mm.region, 34 + obj->base.size, 35 + flags); 36 + if (IS_ERR(obj->mm.st_mm_node)) 37 + return PTR_ERR(obj->mm.st_mm_node); 38 + 39 + pages = intel_region_ttm_node_to_st(obj->mm.region, obj->mm.st_mm_node); 40 + if (IS_ERR(pages)) { 41 + intel_region_ttm_node_free(obj->mm.region, obj->mm.st_mm_node); 42 + return PTR_ERR(pages); 43 + } 44 + 45 + __i915_gem_object_set_pages(obj, pages, i915_sg_dma_sizes(pages->sgl)); 46 + 47 + return 0; 48 + } 49 + 11 50 static const struct drm_i915_gem_object_ops mock_region_obj_ops = { 12 51 .name = "mock-region", 13 - .get_pages = i915_gem_object_get_pages_buddy, 14 - .put_pages = i915_gem_object_put_pages_buddy, 52 + .get_pages = mock_region_get_pages, 53 + .put_pages = mock_region_put_pages, 15 54 .release = i915_gem_object_release_memory_region, 16 55 }; 17 56 ··· 62 23 static struct lock_class_key lock_class; 63 24 struct drm_i915_private *i915 = mem->i915; 64 25 65 - if (size > mem->mm.size) 26 + if (size > resource_size(&mem->region)) 66 27 return -E2BIG; 67 28 68 29 drm_gem_private_object_init(&i915->drm, &obj->base, size); ··· 77 38 return 0; 78 39 } 79 40 41 + static void mock_region_fini(struct intel_memory_region *mem) 42 + { 43 + struct drm_i915_private *i915 = mem->i915; 44 + int instance = mem->instance; 45 + 46 + intel_region_ttm_fini(mem); 47 + ida_free(&i915->selftest.mock_region_instances, instance); 48 + } 49 + 80 50 static const struct intel_memory_region_ops mock_region_ops = { 81 - .init = intel_memory_region_init_buddy, 82 - .release = intel_memory_region_release_buddy, 51 + .init = intel_region_ttm_init, 52 + .release = mock_region_fini, 83 53 .init_object = mock_object_init, 84 54 }; 85 55 ··· 99 51 resource_size_t min_page_size, 100 52 resource_size_t io_start) 101 53 { 54 + int instance = ida_alloc_max(&i915->selftest.mock_region_instances, 55 + TTM_NUM_MEM_TYPES - TTM_PL_PRIV - 1, 56 + GFP_KERNEL); 57 + 58 + if (instance < 0) 59 + return ERR_PTR(instance); 60 + 102 61 return intel_memory_region_create(i915, start, size, min_page_size, 103 - io_start, &mock_region_ops); 62 + io_start, INTEL_MEMORY_MOCK, instance, 63 + &mock_region_ops); 104 64 }