diff options
author | Zbigniew Kempczyński <zbigniew.kempczynski@intel.com> | 2022-03-02 09:06:27 +0100 |
---|---|---|
committer | Zbigniew Kempczyński <zbigniew.kempczynski@intel.com> | 2022-03-03 11:00:19 +0100 |
commit | b1d1c0fd77f8bb3d59de2ee776bd6ca25bc1c811 (patch) | |
tree | e06d69e3206524d0bb1879133309b182803a5e9a /lib/i915/intel_memory_region.c | |
parent | 2372a4beb6a33c5f0799a4a8ccbb93794f52dbca (diff) |
lib/intel_memory_regions: Add helper which creates supported dma-buf set
Not all systems supports dma-buf or supports it partially thus tests which
relies on this functionality should be skipped. Partially means some
memory regions can support it whereas other not. Add a helper function
which will verify dma-buf support on memory regions and create a set of
those supported.
Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Ashutosh Dixit <ashutosh.dixit@intel.com>
Cc: Kamil Konieczny <kamil.konieczny@linux.intel.com>
Reviewed-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>
Reviewed-by: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
Tested-by: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
Diffstat (limited to 'lib/i915/intel_memory_region.c')
-rw-r--r-- | lib/i915/intel_memory_region.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/i915/intel_memory_region.c b/lib/i915/intel_memory_region.c index a8759e06..a2db7456 100644 --- a/lib/i915/intel_memory_region.c +++ b/lib/i915/intel_memory_region.c @@ -332,6 +332,67 @@ char *memregion_dynamic_subtest_name(struct igt_collection *set) return name; } +struct mmap_supported_region { + uint32_t region; + struct igt_list_head link; +}; + +/** + * get_dma_buf_mmap_supported_set: + * @i915: i915 drm file descriptor + * @set: memory regions set + * + * Function constructs set with regions which supports dma-buf mapping. + * + * Returns: set of regions which allows do dma-buf mmap or NULL otherwise. + * + * Note: set (igt_collection) need to be destroyed after use. + */ +struct igt_collection * +get_dma_buf_mmap_supported_set(int i915, struct igt_collection *set) +{ + struct igt_collection *region, *supported_set = NULL; + uint32_t reg; + int dma_buf_fd; + char *ptr; + uint32_t handle, bosize = 4096; + int count = 0; + struct mmap_supported_region *mreg, *tmp; + IGT_LIST_HEAD(region_list); + + for_each_combination(region, 1, set) { + reg = igt_collection_get_value(region, 0); + handle = gem_create_in_memory_regions(i915, bosize, reg); + + dma_buf_fd = prime_handle_to_fd(i915, handle); + ptr = mmap(NULL, bosize, PROT_READ, MAP_SHARED, dma_buf_fd, 0); + if (ptr != MAP_FAILED) { + mreg = malloc(sizeof(*mreg)); + igt_assert(mreg); + mreg->region = reg; + igt_list_add_tail(&mreg->link, ®ion_list); + count++; + } + munmap(ptr, bosize); + gem_close(i915, handle); + close(dma_buf_fd); + } + + if (count) { + int i = 0; + + supported_set = igt_collection_create(count); + + igt_list_for_each_entry_safe(mreg, tmp, ®ion_list, link) { + igt_collection_set_value(supported_set, i++, mreg->region); + igt_list_del(&mreg->link); + free(mreg); + } + } + + return supported_set; +} + /** * intel_dump_gpu_meminfo: * @info: pointer to drm_i915_query_memory_regions structure |