public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: "Li, Sun peng (Leo)" <Sunpeng.Li@amd.com>
To: "Kazlauskas, Nicholas" <Nicholas.Kazlauskas@amd.com>,
	"igt-dev@lists.freedesktop.org" <igt-dev@lists.freedesktop.org>
Subject: Re: [igt-dev] [PATCH i-g-t] lib/igt_fb: Create AMD YUV buffers with AMD GEM IOCTL
Date: Tue, 9 Apr 2019 13:32:55 +0000	[thread overview]
Message-ID: <14121ee0-66c4-fdfa-df3d-48eb32efe1fc@amd.com> (raw)
In-Reply-To: <20190402174522.19695-1-nicholas.kazlauskas@amd.com>



On 2019-04-02 1:45 p.m., Nicholas Kazlauskas wrote:
> The kmstest_dumb_create API isn't suitable for creating multi-planar
> buffers since it tries to calculate the size based on the first plane's
> pitch only.
> 
> AMDGPU requires that the luma pitch be aligned to 256 for YUV buffers
> which results in crashes on kms_plane@pixel-format-pipe-*-planes tests
> when using kmstest_dumb_create since the buffer returned is smaller than
> needed (16384 size returned, 24576 size required).
> 
> Create and map the buffer with the correct size by using the AMD helpers
> introduced by this patch: igt_amd_create_bo and igt_amd_mmap_bo.
> 
> Cc: Harry Wentland <harry.wentland@amd.com>
> Cc: Leo Li <sunpeng.li@amd.com>

Reviewed-by: Leo Li <sunpeng.li@amd.com>

Thanks,
Leo

> Signed-off-by: Nicholas Kazlauskas <nicholas.kazlauskas@amd.com>
> ---
>   lib/Makefile.sources |  2 ++
>   lib/igt_amd.c        | 56 ++++++++++++++++++++++++++++++++++++++++++++
>   lib/igt_amd.h        | 31 ++++++++++++++++++++++++
>   lib/igt_fb.c         |  9 ++++++-
>   lib/meson.build      |  1 +
>   5 files changed, 98 insertions(+), 1 deletion(-)
>   create mode 100644 lib/igt_amd.c
>   create mode 100644 lib/igt_amd.h
> 
> diff --git a/lib/Makefile.sources b/lib/Makefile.sources
> index e00347f9..a1d25351 100644
> --- a/lib/Makefile.sources
> +++ b/lib/Makefile.sources
> @@ -115,6 +115,8 @@ lib_source_list =	 	\
>   	igt_v3d.h		\
>   	igt_vc4.c		\
>   	igt_vc4.h		\
> +	igt_amd.c		\
> +	igt_amd.h		\
>   	$(NULL)
>   
>   .PHONY: version.h.tmp
> diff --git a/lib/igt_amd.c b/lib/igt_amd.c
> new file mode 100644
> index 00000000..abd3ad96
> --- /dev/null
> +++ b/lib/igt_amd.c
> @@ -0,0 +1,56 @@
> +/*
> + * Copyright 2019 Advanced Micro Devices, Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#include "igt_amd.h"
> +#include "igt.h"
> +#include <amdgpu_drm.h>
> +
> +uint32_t igt_amd_create_bo(int fd, uint64_t size)
> +{
> +	union drm_amdgpu_gem_create create;
> +
> +	memset(&create, 0, sizeof(create));
> +	create.in.bo_size = size;
> +	create.in.alignment = 256;
> +	create.in.domains = AMDGPU_GEM_DOMAIN_VRAM;
> +	create.in.domain_flags = AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED
> +				 | AMDGPU_GEM_CREATE_VRAM_CLEARED;
> +
> +	do_ioctl(fd, DRM_IOCTL_AMDGPU_GEM_CREATE, &create);
> +	igt_assert(create.out.handle);
> +
> +	return create.out.handle;
> +}
> +
> +void *igt_amd_mmap_bo(int fd, uint32_t handle, uint64_t size, int prot)
> +{
> +	union drm_amdgpu_gem_mmap map;
> +	void *ptr;
> +
> +	memset(&map, 0, sizeof(map));
> +	map.in.handle = handle;
> +
> +	do_ioctl(fd, DRM_IOCTL_AMDGPU_GEM_MMAP, &map);
> +
> +	ptr = mmap(0, size, prot, MAP_SHARED, fd, map.out.addr_ptr);
> +	return ptr == MAP_FAILED ? NULL : ptr;
> +}
> diff --git a/lib/igt_amd.h b/lib/igt_amd.h
> new file mode 100644
> index 00000000..f63d26f4
> --- /dev/null
> +++ b/lib/igt_amd.h
> @@ -0,0 +1,31 @@
> +/*
> + * Copyright 2019 Advanced Micro Devices, Inc.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#ifndef IGT_AMD_H
> +#define IGT_AMD_H
> +
> +#include <stdint.h>
> +
> +uint32_t igt_amd_create_bo(int fd, uint64_t size);
> +void *igt_amd_mmap_bo(int fd, uint32_t handle, uint64_t size, int prot);
> +
> +#endif /* IGT_AMD_H */
> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> index 6adf4222..f5c9a9f1 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -38,6 +38,7 @@
>   #include "igt_kms.h"
>   #include "igt_matrix.h"
>   #include "igt_vc4.h"
> +#include "igt_amd.h"
>   #include "igt_x86.h"
>   #include "ioctl_wrappers.h"
>   #include "intel_batchbuffer.h"
> @@ -763,7 +764,8 @@ static int create_bo_for_fb(struct igt_fb *fb)
>   	 * them, so we need to make sure to use a device BO then.
>   	 */
>   	if (fb->modifier || fb->size || fb->strides[0] ||
> -	    (is_i915_device(fd) && igt_format_is_yuv(fb->drm_format)))
> +	    (is_i915_device(fd) && igt_format_is_yuv(fb->drm_format)) ||
> +	    (is_amdgpu_device(fd) && igt_format_is_yuv(fb->drm_format)))
>   		device_bo = true;
>   
>   	/* Sets offets and stride if necessary. */
> @@ -787,6 +789,8 @@ static int create_bo_for_fb(struct igt_fb *fb)
>   			if (fb->modifier == DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED)
>   				igt_vc4_set_tiling(fd, fb->gem_handle,
>   						   fb->modifier);
> +		} else if (is_amdgpu_device(fd)) {
> +			fb->gem_handle = igt_amd_create_bo(fd, fb->size);
>   		} else {
>   			igt_assert(false);
>   		}
> @@ -1832,6 +1836,9 @@ static void *map_bo(int fd, struct igt_fb *fb)
>   	else if (is_vc4_device(fd))
>   		ptr = igt_vc4_mmap_bo(fd, fb->gem_handle, fb->size,
>   				      PROT_READ | PROT_WRITE);
> +	else if (is_amdgpu_device(fd))
> +		ptr = igt_amd_mmap_bo(fd, fb->gem_handle, fb->size,
> +				      PROT_READ | PROT_WRITE);
>   	else
>   		igt_assert(false);
>   
> diff --git a/lib/meson.build b/lib/meson.build
> index 89de06e6..a8462933 100644
> --- a/lib/meson.build
> +++ b/lib/meson.build
> @@ -54,6 +54,7 @@ lib_sources = [
>   	'igt_v3d.c',
>   	'igt_vc4.c',
>   	'igt_psr.c',
> +	'igt_amd.c'
>   ]
>   
>   lib_deps = [
> 
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2019-04-09 13:32 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-02 17:45 [igt-dev] [PATCH i-g-t] lib/igt_fb: Create AMD YUV buffers with AMD GEM IOCTL Nicholas Kazlauskas
2019-04-02 18:23 ` [igt-dev] ✓ Fi.CI.BAT: success for " Patchwork
2019-04-03  6:44 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2019-04-09 13:32 ` Li, Sun peng (Leo) [this message]
2019-04-09 14:23 ` [igt-dev] ✓ Fi.CI.BAT: success for lib/igt_fb: Create AMD YUV buffers with AMD GEM IOCTL (rev2) Patchwork
2019-04-09 22:50 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=14121ee0-66c4-fdfa-df3d-48eb32efe1fc@amd.com \
    --to=sunpeng.li@amd.com \
    --cc=Nicholas.Kazlauskas@amd.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox