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

drm/xe: Introduce xe_ggtt_print_holes

Introduce a new xe_ggtt_print_holes helper that attends the SRIOV
demand and finishes the goal of limiting drm_mm access to xe_ggtt.

Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
Reviewed-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240821193842.352557-9-rodrigo.vivi@intel.com
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

+42 -24
+40
drivers/gpu/drm/xe/xe_ggtt.c
··· 682 682 mutex_unlock(&ggtt->lock); 683 683 return err; 684 684 } 685 + 686 + /** 687 + * xe_ggtt_print_holes - Print holes 688 + * @ggtt: the &xe_ggtt to be inspected 689 + * @alignment: min alignment 690 + * @p: the &drm_printer 691 + * 692 + * Print GGTT ranges that are available and return total size available. 693 + * 694 + * Return: Total available size. 695 + */ 696 + u64 xe_ggtt_print_holes(struct xe_ggtt *ggtt, u64 alignment, struct drm_printer *p) 697 + { 698 + const struct drm_mm *mm = &ggtt->mm; 699 + const struct drm_mm_node *entry; 700 + u64 hole_min_start = xe_wopcm_size(tile_to_xe(ggtt->tile)); 701 + u64 hole_start, hole_end, hole_size; 702 + u64 total; 703 + char buf[10]; 704 + 705 + mutex_lock(&ggtt->lock); 706 + 707 + drm_mm_for_each_hole(entry, mm, hole_start, hole_end) { 708 + hole_start = max(hole_start, hole_min_start); 709 + hole_start = ALIGN(hole_start, alignment); 710 + hole_end = ALIGN_DOWN(hole_end, alignment); 711 + if (hole_start >= hole_end) 712 + continue; 713 + hole_size = hole_end - hole_start; 714 + total += hole_size; 715 + 716 + string_get_size(hole_size, 1, STRING_UNITS_2, buf, sizeof(buf)); 717 + drm_printf(p, "range:\t%#llx-%#llx\t(%s)\n", 718 + hole_start, hole_end - 1, buf); 719 + } 720 + 721 + mutex_unlock(&ggtt->lock); 722 + 723 + return total; 724 + }
+1
drivers/gpu/drm/xe/xe_ggtt.h
··· 32 32 u64 xe_ggtt_largest_hole(struct xe_ggtt *ggtt, u64 alignment, u64 *spare); 33 33 34 34 int xe_ggtt_dump(struct xe_ggtt *ggtt, struct drm_printer *p); 35 + u64 xe_ggtt_print_holes(struct xe_ggtt *ggtt, u64 alignment, struct drm_printer *p); 35 36 36 37 #ifdef CONFIG_PCI_IOV 37 38 void xe_ggtt_assign(struct xe_ggtt *ggtt, const struct xe_ggtt_node *node, u16 vfid);
+1 -24
drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
··· 6 6 #include <linux/string_choices.h> 7 7 #include <linux/wordpart.h> 8 8 9 - /* FIXME: remove this after encapsulating all drm_mm_node access into xe_ggtt */ 10 - #include <drm/drm_mm.h> 11 - 12 9 #include "abi/guc_actions_sriov_abi.h" 13 10 #include "abi/guc_klvs_abi.h" 14 11 ··· 2100 2103 int xe_gt_sriov_pf_config_print_available_ggtt(struct xe_gt *gt, struct drm_printer *p) 2101 2104 { 2102 2105 struct xe_ggtt *ggtt = gt_to_tile(gt)->mem.ggtt; 2103 - const struct drm_mm *mm = &ggtt->mm; 2104 - const struct drm_mm_node *entry; 2105 2106 u64 alignment = pf_get_ggtt_alignment(gt); 2106 - u64 hole_min_start = xe_wopcm_size(gt_to_xe(gt)); 2107 - u64 hole_start, hole_end, hole_size; 2108 2107 u64 spare, avail, total = 0; 2109 2108 char buf[10]; 2110 2109 ··· 2109 2116 mutex_lock(xe_gt_sriov_pf_master_mutex(gt)); 2110 2117 2111 2118 spare = pf_get_spare_ggtt(gt); 2119 + total = xe_ggtt_print_holes(ggtt, alignment, p); 2112 2120 2113 - mutex_lock(&ggtt->lock); 2114 - 2115 - drm_mm_for_each_hole(entry, mm, hole_start, hole_end) { 2116 - hole_start = max(hole_start, hole_min_start); 2117 - hole_start = ALIGN(hole_start, alignment); 2118 - hole_end = ALIGN_DOWN(hole_end, alignment); 2119 - if (hole_start >= hole_end) 2120 - continue; 2121 - hole_size = hole_end - hole_start; 2122 - total += hole_size; 2123 - 2124 - string_get_size(hole_size, 1, STRING_UNITS_2, buf, sizeof(buf)); 2125 - drm_printf(p, "range:\t%#llx-%#llx\t(%s)\n", 2126 - hole_start, hole_end - 1, buf); 2127 - } 2128 - 2129 - mutex_unlock(&ggtt->lock); 2130 2121 mutex_unlock(xe_gt_sriov_pf_master_mutex(gt)); 2131 2122 2132 2123 string_get_size(total, 1, STRING_UNITS_2, buf, sizeof(buf));