From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 00BFA10E7F8 for ; Wed, 2 Mar 2022 11:48:39 +0000 (UTC) Message-ID: <2928dc5c-eb45-e6d8-b572-09b0198161af@intel.com> Date: Wed, 2 Mar 2022 13:48:28 +0200 Content-Language: en-US To: =?UTF-8?Q?Zbigniew_Kempczy=c5=84ski?= , References: <20220301075803.117058-1-zbigniew.kempczynski@intel.com> <20220301075803.117058-2-zbigniew.kempczynski@intel.com> From: Gwan-gyeong Mun In-Reply-To: <20220301075803.117058-2-zbigniew.kempczynski@intel.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit MIME-Version: 1.0 Subject: Re: [igt-dev] [PATCH i-g-t 1/3] lib/intel_memory_regions: Add helper which creates supported dma-buf set List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" List-ID: Reviewed-by: Gwan-gyeong Mun Tested-by: Gwan-gyeong Mun If the https://patchwork.freedesktop.org/series/100737/ patch (currently under review) is applied to the i915, you can see that the igt@prime_mmap test works normally in dg1. On 3/1/22 9:58 AM, Zbigniew Kempczyński wrote: > As different systems support or not dma-buf add function helper which > will create set of supported by dma-buf memory regions. > > Signed-off-by: Zbigniew Kempczyński > Cc: Ashutosh Dixit > --- > lib/i915/intel_memory_region.c | 61 ++++++++++++++++++++++++++++++++++ > lib/i915/intel_memory_region.h | 3 ++ > 2 files changed, 64 insertions(+) > > diff --git a/lib/i915/intel_memory_region.c b/lib/i915/intel_memory_region.c > index a8759e069..a2db74566 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 > diff --git a/lib/i915/intel_memory_region.h b/lib/i915/intel_memory_region.h > index 936e7d1c8..bd92267b6 100644 > --- a/lib/i915/intel_memory_region.h > +++ b/lib/i915/intel_memory_region.h > @@ -111,6 +111,9 @@ __get_memory_region_set(struct drm_i915_query_memory_regions *regions, > __get_memory_region_set(regions, arr__, ARRAY_SIZE(arr__)); \ > }) > > +struct igt_collection * > +get_dma_buf_mmap_supported_set(int i915, struct igt_collection *set); > + > char *memregion_dynamic_subtest_name(struct igt_collection *set); > > void intel_dump_gpu_meminfo(const struct drm_i915_query_memory_regions *info); >